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
50 lines (41 loc) · 1.19 KB
/
Main.cpp
File metadata and controls
50 lines (41 loc) · 1.19 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
#include "Main.h"
#include "server/Server.h"
#include "SignalHandlers.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 const command = commands.find(argv[1]);
if (commands.cend() != command)
{
HttpServer::Server server;
if (bindSignalHandlers(&server) )
{
exitcode = command->second(&server, argc, argv);
stopSignalHandlers();
}
}
else
{
std::cout << "Unknown parameter, see --help" << std::endl;
}
}
else if (1 == argc)
{
std::cout << "Try to run with the parameter --help" << std::endl;
}
else
{
std::cout << "The number of arguments cannot be equal to zero. Enter the parameter --help" << std::endl;
}
return exitcode;
}