-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
64 lines (52 loc) · 1.34 KB
/
main.cpp
File metadata and controls
64 lines (52 loc) · 1.34 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
#include <QCoreApplication>
#include <QStringList>
#include "DLockManager.hpp"
#include "DLockLocal.hpp"
static DLockManager *dlm;
void sighandler(int signum) {
static bool exiting = false;
switch(signum) {
case SIGINT:
case SIGTERM:
if (exiting) {
qDebug("emergency exit");
exit(1);
}
exiting = true;
QMetaObject::invokeMethod(dlm, "terminate", Qt::QueuedConnection);
break;
case SIGHUP:
QMetaObject::invokeMethod(dlm, "reload", Qt::QueuedConnection);
break;
}
}
int main(int argc, char *argv[]) {
QCoreApplication app(argc, argv);
QStringList args = QCoreApplication::arguments();
int remote_port = 55822; // for online access
int local_port = 22855; // for localhost
if (args.size() >= 2) {
QStringList p = args.at(1).split(":");
remote_port = p.at(0).toInt();
if ((remote_port < 1024) || (remote_port > 65535)) {
qDebug("invalid remote port %d", remote_port);
return 1;
}
if (p.size() > 1) {
local_port = p.at(1).toInt();
} else {
local_port = remote_port+1;
}
if ((local_port < 1024) || (local_port > 65535)) {
qDebug("invalid local port %d", local_port);
return 1;
}
}
DLockManager m(remote_port);
dlm = &m;
DLockLocal l(m, QHostAddress::LocalHost, local_port);
signal(SIGINT, sighandler);
signal(SIGTERM, sighandler);
signal(SIGHUP, sighandler);
return app.exec();
}