-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.cpp
82 lines (63 loc) · 1.76 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
81
82
#include "view.h"
#include "util.h"
#include <Wt/WServer>
#include <signal.h>
#include "confparser.h"
#include "abstractrpm.h"
#include "rasprpm.h"
#include "dummy_rpm.h"
#include <memory>
std::shared_ptr<AbstractRPM> rpm;
bool createRPM(std::shared_ptr<Wt::WServer> server)
{
ConfParser parser;
Wt::WString backend = parser.rpmBackend();
#ifdef USE_RASPRPM
if (backend == "rasprpm") {
rpm.reset(new RaspRPM(server, parser.rpmBackendConfiguration()));
return true;
}
#endif
if (backend == "dummy_rpm") {
rpm.reset(new DummyRPM(server, parser.rpmBackendConfiguration()));
return true;
}
std::cerr << "Cannot allocate the RPM backend '" << backend.toUTF8() << "'" << std::endl;
return false;
}
Wt::WApplication *createApplication(const Wt::WEnvironment& env,
std::shared_ptr<Wt::WServer> server)
{
View *view = new View(env, server, rpm);
rpm->addView(view);
return view;
}
int main(int argc, char **argv)
{
signal(SIGSEGV, segv_handler);
try {
std::shared_ptr<Wt::WServer> server(new Wt::WServer(argv[0]));
server->setServerConfiguration(argc, argv, WTHTTP_CONFIGURATION);
server->addEntryPoint(Wt::Application,
boost::bind(createApplication, _1,
server));
/* change the CWD to the binary's folder */
chdir(getExeDirectory().c_str());
/* create a unique instance of the RPM */
if (!createRPM(server))
return 1;
if (server->start()) {
int sig = Wt::WServer::waitForShutdown(argv[0]);
std::cerr << "Shutdown (signal = " << sig << ")" << std::endl;
server->stop();
if (sig == SIGHUP)
Wt::WServer::restart(argc, argv, environ);
}
} catch (Wt::WServer::Exception& e) {
std::cerr << e.what() << "\n";
return 1;
} catch (std::exception& e) {
std::cerr << "exception: " << e.what() << "\n";
return 1;
}
}