diff --git a/spec/spec.md b/spec/spec.md index 15fc1ad..dd32a76 100644 --- a/spec/spec.md +++ b/spec/spec.md @@ -249,6 +249,12 @@ mandatory: optional:{default} emailServerPort={587} emailAddressDisplay={Cavecomm Automated Management System} + regularTaskExecution={false} + regularTaskExecutionIntervalSeconds={900} 15min + regularTaskExecutionModules={} + options separated by "|": + reeeprint: test module + counter: test module diff --git a/src/default-cavecomm.conf b/src/default-cavecomm.conf index 4631418..4ad6aba 100644 --- a/src/default-cavecomm.conf +++ b/src/default-cavecomm.conf @@ -12,6 +12,9 @@ # Optional: {default} # emailServerPort={587} # emailAddressDisplay={Cavecomm Automated Management System} +# regularTaskExecution={false} +# regularTaskExecutionIntervalSeconds={900} 15min +# regularTaskExecutionModules={} # options separated by "|": reeeprint|counter @@ -34,4 +37,10 @@ sslKeyPath=/media/sf_cavecommRemote/example.key; domain=192.168.56.1:18080; +regularTaskExecution=true; + +regularTaskExecutionIntervalSeconds=2; + +regularTaskExecutionModules=reeeprint|counter; + #configend# diff --git a/src/main.cpp b/src/main.cpp index 8cf457e..0c32218 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,11 +1,15 @@ -#include "crow.h" -#include "crow/middlewares/cookie_parser.h" -#include "database.cpp" -#include "utilities.cpp" -#include #include #include -#include +#include + +#include + +#include "crow.h" +#include "crow/middlewares/cookie_parser.h" + +#include "database.cpp" +#include "utilities.cpp" +#include "regularTaskExecution.cpp" using namespace std; @@ -23,6 +27,9 @@ int main(int argc, char *argv[]) { // Create app with Middleware crow::App app; + // starts thread that executes modules + thread threadRegularExecution(RegularTaskExecution::regularExecution, configuration); + /* * Freelancer Profile listing for customers */ diff --git a/src/regularTaskExecution.cpp b/src/regularTaskExecution.cpp new file mode 100644 index 0000000..cb5ee18 --- /dev/null +++ b/src/regularTaskExecution.cpp @@ -0,0 +1,46 @@ +#ifndef REGULAR_TASK_EXECUTION_CPP +#define REGULAR_TASK_EXECUTION_CPP + +#include +#include +#include + +#include "utilities.cpp" + +using namespace std::chrono_literals; + +/* + * RegularTaskExecution manager + */ +namespace RegularTaskExecution { + /* + * print test + * todo::remove + */ + void reeePrint() { + std::cout << "reeee" << std::endl; + } + + /* + * print test + * todo::remove + */ + void counterPrint(size_t& counter) { + std::cout << counter << std::endl; + counter++; + } + + void regularExecution(const Utilities::config& configuration) { + std::chrono::seconds seconds(configuration.regularTaskExecutionIntervalSeconds); + size_t counter = 0; + while (configuration.regularTaskExecution) { + if (configuration.regularTaskExecutionModules.at(Utilities::MODULE_NAME_REEE_PRINT)) + reeePrint(); // print test todo::remove + if (configuration.regularTaskExecutionModules.at(Utilities::MODULE_NAME_REEE_PRINT)) + counterPrint(counter); // print test todo::remove + + std::this_thread::sleep_for(seconds); + } + } +} +#endif \ No newline at end of file diff --git a/src/utilities.cpp b/src/utilities.cpp index becbd25..0796634 100644 --- a/src/utilities.cpp +++ b/src/utilities.cpp @@ -22,7 +22,10 @@ using namespace DatabaseStatementConstCollection; namespace Utilities { const static std::map HTML_URL_CODES = {{"%20", " "}, {"%21", "!"}, {"%22", "\""}, {"%23", "#"}, {"%24", "$"}, {"%25", "%"}, {"%26", "&"}, {"%27", "'"}, {"%28", "("}, {"%29", ")"}, {"%2A", "*"}, {"%2B", "+"}, {"%2C", ","}, {"%2D", "-"}, {"%2E", "."}, {"%2F", "/"}, {"%30", "0"}, {"%31", "1"}, {"%32", "2"}, {"%33", "3"}, {"%34", "4"}, {"%35", "5"}, {"%36", "6"}, {"%37", "7"}, {"%38", "8"}, {"%39", "9"}, {"%3A", ":"}, {"%3B", ";"}, {"%3C", "<"}, {"%3D", "="}, {"%3E", ">"}, {"%3F", "?"}, {"%40", "@"}, {"%5B", "["}, {"%5C", "\\"}, {"%5D", "]"}, {"%5E", "^"}, {"%5F", "_"}, {"%60", "`"}, {"%7B", "{"}, {"%7C", "|"}, {"%7D", "}"}, {"%7E", "~"}, {"%7F", " "}, {"%80", "€"}, {"%82", "‚"}, {"%83", "ƒ"}, {"%84", "„"}, {"%85", "…"}, {"%86", "†"}, {"%87", "‡"}, {"%88", "ˆ"}, {"%89", "‰"}, {"%8A", "Š"}, {"%8B", "‹"}, {"%8C", "Œ"}, {"%8E", "Ž"}, {"%91", "‘"}, {"%92", "’"}, {"%93", "“"}, {"%94", "”"}, {"%95", "•"}, {"%96", "–"}, {"%97", "—"}, {"%98", "˜"}, {"%99", "™"}, {"%9A", "š"}, {"%9B", "›"}, {"%9C", "œ"}, {"%9E", "ž"}, {"%9F", "Ÿ"}, {"%A1", "¡"}, {"%A2", "¢"}, {"%A3", "£"}, {"%A4", "¤"}, {"%A5", "¥"}, {"%A6", "¦"}, {"%A7", "§"}, {"%A8", "¨"}, {"%A9", "©"}, {"%AA", "ª"}, {"%AB", "«"}, {"%AC", "¬"}, {"%AE", "®"}, {"%AF", "¯"}, {"%B0", "°"}, {"%B1", "±"}, {"%B2", "²"}, {"%B3", "³"}, {"%B4", "´"}, {"%B5", "µ"}, {"%B6", "¶"}, {"%B7", "·"}, {"%B8", "¸"}, {"%B9", "¹"}, {"%BA", "º"}, {"%BB", "»"}, {"%BC", "¼"}, {"%BD", "½"}, {"%BE", "¾"}, {"%BF", "¿"}, {"%C0", "À"}, {"%C1", "Á"}, {"%C2", "Â"}, {"%C3", "Ã"}, {"%C4", "Ä"}, {"%C5", "Å"}, {"%C6", "Æ"}, {"%C7", "Ç"}, {"%C8", "È"}, {"%C9", "É"}, {"%CA", "Ê"}, {"%CB", "Ë"}, {"%CC", "Ì"}, {"%CD", "Í"}, {"%CE", "Î"}, {"%CF", "Ï"}, {"%D0", "Ð"}, {"%D1", "Ñ"}, {"%D2", "Ò"}, {"%D3", "Ó"}, {"%D4", "Ô"}, {"%D5", "Õ"}, {"%D6", "Ö"}, {"%D7", "×"}, {"%D8", "Ø"}, {"%D9", "Ù"}, {"%DA", "Ú"}, {"%DB", "Û"}, {"%DC", "Ü"}, {"%DD", "Ý"}, {"%DE", "Þ"}, {"%DF", "ß"}, {"%E0", "à"}, {"%E1", "á"}, {"%E2", "â"}, {"%E3", "ã"}, {"%E4", "ä"}, {"%E5", "å"}, {"%E6", "æ"}, {"%E7", "ç"}, {"%E8", "è"}, {"%E9", "é"}, {"%EA", "ê"}, {"%EB", "ë"}, {"%EC", "ì"}, {"%ED", "í"}, {"%EE", "î"}, {"%EF", "ï"}, {"%F0", "ð"}, {"%F1", "ñ"}, {"%F2", "ò"}, {"%F3", "ó"}, {"%F4", "ô"}, {"%F5", "õ"}, {"%F6", "ö"}, {"%F7", "÷"}, {"%F8", "ø"}, {"%F9", "ù"}, {"%FA", "ú"}, {"%FB", "û"}, {"%FC", "ü"}, {"%FD", "ý"}, {"%FE", "þ"}, {"%FF", "ÿ"}}; const static int SALT_SIZE = 32; - const std::string SALT_CHAR_SET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + const static std::string SALT_CHAR_SET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + + const static std::string MODULE_NAME_REEE_PRINT = "reeeprint"; + const static std::string MODULE_NAME_COUNTER_PRINT = "counter"; /* * Takes string to split it into a vector based on a given delimiter @@ -59,6 +62,12 @@ namespace Utilities { std::string sslCrtPath; std::string sslKeyPath; std::string domain; + bool regularTaskExecution = false; + int regularTaskExecutionIntervalSeconds = 900; + std::map regularTaskExecutionModules = { + {MODULE_NAME_REEE_PRINT, false}, + {MODULE_NAME_COUNTER_PRINT, false} + }; /* * validates existence of mandatory variables in config @@ -159,6 +168,21 @@ namespace Utilities { domain = trimFromDelimiter(lineVector.at(1), ';'); continue; } + if (lineVector.at(0) == "regularTaskExecution") { + regularTaskExecution = (trimFromDelimiter(lineVector.at(1), ';') == "true"); + continue; + } + if (lineVector.at(0) == "regularTaskExecutionIntervalSeconds") { + regularTaskExecutionIntervalSeconds = std::stoi(trimFromDelimiter(lineVector.at(1), ';')); + continue; + } + if (lineVector.at(0) == "regularTaskExecutionModules") { + std::vector modules = Utilities::splitStringIntoVector(trimFromDelimiter(lineVector.at(1), ';'), '|'); + for (const std::string& module : modules) { + regularTaskExecutionModules.at(module) = true; + } + continue; + } } } }