-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
92 lines (83 loc) · 2.26 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
83
84
85
86
87
88
89
90
91
92
#include <QCoreApplication>
#include <QtNetwork>
#include <QString>
#include <QDebug>
#include "server.h"
#include "defs.h"
int server_port;
QString server_LOG_file;
QString server_SQL_file;
QString server_DB_file;
class Task : public QObject
{
Q_OBJECT
public:
Task(QObject *parent = 0) : QObject(parent) {}
QList<int> lwords;
double average;
public slots:
void run();
signals:
void finished();
};
void Task::run()
{
static server serv;
serv.set_logfile(server_LOG_file);
serv.set_port(server_port);
serv.set_dbfile(server_DB_file);
serv.init();
}
#include "main.moc"
int main(int argc, char *argv[])
{
#ifdef __linux__
#elif _WIN32
// force output utf8
system("chcp 65001");
#else
#endif
QCoreApplication a(argc, argv);
QCoreApplication::setApplicationName(APP_NAME);
QCoreApplication::setApplicationVersion(APP_VERSION);
QStringList arguments;
foreach (auto arg, a.arguments()) {
if (arg.startsWith('/')) {
arg.replace(0,1,"--");
}
arguments.append(arg);
}
QCommandLineParser parser;
parser.setApplicationDescription(APP_NAME " це сервер, що є частиною системи радіаційного моніторингу");
parser.addHelpOption();
parser.addVersionOption();
parser.addOptions({
{{ "p", "port"}, "порт", "значення" },
{{ "l", "logfile"}, "файл log", "значення" },
{{ "d", "sqlbd"}, "файл bd", "значення" }
}
);
parser.process(arguments);
QString port_s = parser.value("p");
int port = port_s.toInt();
if(port == 0) {
port = PORT_NUM_DEF;
}
server_port = port;
server_LOG_file = parser.value("l");
if(server_LOG_file.size() == 0) {
server_LOG_file = LOG_FILE_DEF;
}
// BD
server_DB_file = parser.value("d");
if(server_DB_file.size() == 0) {
server_DB_file = DB_FILE_DEF;
}
// creating task
Task *task = new Task(&a);
// connect signals to app
QObject::connect(task, SIGNAL(finished()), &a, SLOT(quit()));
// create task
QTimer::singleShot(0, task, SLOT(run()));
return a.exec();
}