forked from awwit/httpserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
51 lines (43 loc) · 1.2 KB
/
Main.cpp
File metadata and controls
51 lines (43 loc) · 1.2 KB
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
#include "Main.h"
#include "SignalsHandles.h"
#include <iostream>
int main(const int argc, const char *argv[])
{
const std::unordered_map<std::string, std::function<int(HttpServer::Server *, const int, const char *[])> > commands {
{"--help", std::mem_fn(&HttpServer::Server::command_help)},
{"--start", std::mem_fn(&HttpServer::Server::command_start)},
{"--restart", std::mem_fn(&HttpServer::Server::command_restart)},
{"--kill", std::mem_fn(&HttpServer::Server::command_terminate)},
{"--update-module", std::mem_fn(&HttpServer::Server::command_update_module)}
};
int exitcode = EXIT_FAILURE;
if (1 < argc)
{
auto command = commands.find(argv[1]);
if (commands.cend() != command)
{
HttpServer::Server server;
if (bindSignalsHandles(&server) )
{
exitcode = command->second(&server, argc, argv);
#ifdef WIN32
System::sendSignal(GetCurrentProcessId(), SIGINT);
threadMessageLoop.join();
#endif
}
}
else
{
std::cout << "Unknown command, see --help" << std::endl;
}
}
else if (1 == argc)
{
std::cout << "Try: " << argv[0] << " --help" << std::endl;
}
else
{
std::cout << "Arguments failure, see --help command" << std::endl;
}
return exitcode;
}