-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathserver.cpp
More file actions
71 lines (60 loc) · 1.68 KB
/
Copy pathserver.cpp
File metadata and controls
71 lines (60 loc) · 1.68 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include "server.hpp"
#include "subsystem.hpp"
namespace webcpp {
server::server() : helpRequested(false) {
this->addSubsystem(new webcpp::subsystem);
}
server::~server() {
}
void server::initialize(Poco::Util::Application& self) {
if (this->confFile.empty()) {
this->loadConfiguration();
} else {
this->loadConfiguration(this->confFile);
}
Poco::Util::ServerApplication::initialize(self);
}
void server::uninitialize() {
Poco::Util::ServerApplication::uninitialize();
}
void server::defineOptions(Poco::Util::OptionSet& options) {
Poco::Util::ServerApplication::defineOptions(options);
options.addOption(
Poco::Util::Option("help", "h",
"display help information on command line arguments")
.required(false)
.repeatable(false));
options.addOption(
Poco::Util::Option("conf", "c",
"configuration file")
.required(false)
.repeatable(false)
.argument("filename"));
}
void server::handleOption(const std::string& name, const std::string& value) {
Poco::Util::ServerApplication::handleOption(name, value);
if (name == "help") {
this->helpRequested = true;
this->stopOptionsProcessing();
} else if (name == "conf") {
this->confFile = value;
}
}
void server::displayHelp() {
Poco::Util::HelpFormatter hf(this->options());
hf.setCommand(commandName());
hf.setUsage("OPTIONS");
hf.setHeader("A web server, based on POCO C++ library.");
hf.format(std::cout);
}
int server::main(const std::vector<std::string>& args) {
if (helpRequested) {
this->displayHelp();
} else {
// wait for CTRL-C or kill
this->waitForTerminationRequest();
}
return Poco::Util::Application::EXIT_OK;
}
}