-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
81 lines (64 loc) · 2.24 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <iostream>
#include <boost/program_options.hpp>
#include <signal.h>
#include "main.h"
#include "database.h"
#include "api.h"
#include "CRUD/crud.h"
void parseStartArguments(int argc, char* argv[])
{
namespace po = boost::program_options;
#pragma region Options-Description
po::options_description desc("Allowed options");
desc.add_options()
("help,h", "Produce help message")
("apiPort", po::value<int>(), "Set API-Port to listen at")
("apiAddress", po::value<std::string>(), "Set API-Address to listen at")
("dataPath", po::value<std::string>(), "Path to the data Folder");
#pragma endregion
// Parsing
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
#pragma region Valuating
if (vm.count("help")) {
std::cout << desc << "\n";
exit(0);
}
if (vm.count("dataPath")) {
DATA_PATH = vm["dataPath"].as<std::string>();
std::cout << "[VAR] dataPath was set to " << DATA_PATH << std::endl;
}
if (vm.count("apiPort")) {
API_PORT = vm["apiPort"].as<int>();
std::cout << "[VAR] apiPort was set to " << API_PORT << std::endl;
}
if (vm.count("apiAddress")) {
API_ADDRESS = vm["apiAddress"].as<std::string>();
std::cout << "[VAR] apiAddress was set to " << API_ADDRESS << std::endl;
}
#pragma endregion
}
int main(int argc, char* argv[]) {
// Init
parseStartArguments(argc, argv);
signal(SIGINT, [](int signal) { INTERRUPT = true; }); // Control-C Event
signal(SIGTERM, [](int signal) { INTERRUPT = true; }); // Docker-Stop Event
// Start Up
loadDatabase(DATA_PATH);
API::startAPI(API_PORT, API_ADDRESS);
CollectionFunctions::StartManagerThread();
// Main Loop
std::cout << " --- Everything is running fine --- " << std::endl;
while (!INTERRUPT) {
std::this_thread::sleep_for(std::chrono::minutes(3));
saveDatabase(DATA_PATH); // save Database
SELECT::cursor_t::removeLeftCursors();// remove left cursors
}
// Exit
std::cout << " --- Shutting Database down --- " << std::endl;
saveDatabase(DATA_PATH);
std::cout << "Good Bye" << std::endl;
exit(0);
return 0;
}