-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.cpp
57 lines (43 loc) · 1.38 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
#include <stdio.h>
#include <QSettings>
#include <QFileInfo>
#include <QCoreApplication>
#include <QTimer>
#include "print.h"
#include "log.h"
#include "Wrapper.h"
FILE *logfile;
int ourpid = QCoreApplication::applicationPid();
int main(int argc, char *argv[])
{
if (argc != 2) {
our_log( (sprint "FATAL: Incorrect usage. Use: %s config.ini\n" % argv[0]) );
return 1;
}
QSettings settings(argv[1], QSettings::IniFormat);
switch (settings.status())
{
case QSettings::AccessError:
our_log("FATAL: Cannot access configuration file\n");
return 1;
case QSettings::FormatError:
our_log("FATAL: Format error while reading configuation file\n");
return 1;
default:
;
}
if (! settings.contains("command") ) {
our_log("FATAL: Configuration file does not contain command property");
return 1;
}
Wrapper wrapper;
wrapper.command = settings.value("command").toString();
wrapper.name = settings.value("name", QFileInfo(wrapper.command).baseName()).toString();
wrapper.ourpid = ourpid;
wrapper.timeout = settings.value("timeout", -1).toInt();
if (wrapper.timeout != -1)
wrapper.timeout *= 1000;
QTimer::singleShot(0, &wrapper, SLOT(start()));
QCoreApplication app(argc, argv);
QCoreApplication::exec();
}