-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
90 lines (82 loc) · 2.32 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
#include <QApplication>
#include <iostream>
#include "debug.h"
#include "config.h"
#include "jconfig.h"
#include "terminal.h"
#include "ipc.h"
#include "options.h"
#include "logger.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Options options;
JConfig conf(options.config());
if (conf.error() != JConfig::ErrorNone)
{
Log->fatal("main", "Config not found");
return 1;
}
Logger::instance(conf);
Ipc ipc(conf, (options.command().isNull() ? Ipc::ModeApplication : Ipc::ModeManager)); // Инициализация межпроцессного взаимодействия
if (ipc.error() == Ipc::ErrorNone)
switch (ipc.mode())
{
case Ipc::ModeManager:
if (options.command() == "pid")
ipc.cmd(Ipc::CmdPid);
else if (options.command() == "status")
ipc.cmd(Ipc::CmdStatus);
else if (options.command() == "stop")
ipc.cmd(Ipc::CmdStop);
else if (options.command() == "configRead")
ipc.cmd(Ipc::CmdConfigRead);
else if (options.command() == "logReopen")
ipc.cmd(Ipc::CmdLogReopen);
else if (options.command() == "stateSave")
ipc.cmd(Ipc::CmdStateSave);
else
{
std::cerr << "Unknown command" << std::endl;
options.showHelp(true, 2);
ipc.disable();
return 2;
}
QObject::connect(&app, SIGNAL(aboutToQuit()), &ipc, SLOT(disable()));
return app.exec();
case Ipc::ModeApplication:
{
QPalette p = app.palette();
p.setColor(QPalette::Window, "white");
p.setColor(QPalette::Active, QPalette::Button, *(new QColor(223, 128, 38)));
p.setColor(QPalette::Disabled, QPalette::Button, *(new QColor(225, 225, 225)));
p.setColor(QPalette::ButtonText, "white");
app.setPalette(p);
Terminal term(conf, ipc);
QObject::connect(&app, SIGNAL(aboutToQuit()), &term, SLOT(shutdown()));
return app.exec();
}
}
else
{
ipc.disable();
switch (ipc.error())
{
case Ipc::ErrorAlreadyExists:
std::cerr << "Aplication is already running" << std::endl;
return 3;
case Ipc::ErrorNotFound:
std::cerr << "Aplication is not running" << std::endl;
return 4;
case Ipc::ErrorShmem:
std::cerr << "Shared memory error" << std::endl;
return 5;
case Ipc::ErrorOther:
std::cerr << "Unknown IPC error" << std::endl;
return 6;
default:;
}
}
ipc.disable();
return -1;
}