-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
126 lines (106 loc) · 3.82 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <QApplication>
#include <QCommandLineParser>
#include <src/player/player.h>
#include <src/player/gui/playergui.h>
#include <src/utils/exithandler/exithandler.h>
QCoreApplication *createApplication(int &argc, char *argv[]) {
// Try to found in args an '--gui'
bool foundArg = false;
for (int i = 0; i < argc; ++i) {
if (!qstrcmp(argv[i], "--gui")) {
foundArg = true;
break;
}
}
// if not found, call core application
if(!foundArg) {
return new QCoreApplication(argc, argv);
}
// otherwise, call gui application
else {
return new QApplication(argc, argv);
}
}
int main(int argc, char *argv[])
{
QScopedPointer<QCoreApplication> a(createApplication(argc, argv));
a->setApplicationName(APP_NAME);
a->setApplicationVersion(APP_VERSION);
// Setup command line parser
QCommandLineParser parser;
parser.addHelpOption();
parser.addVersionOption();
// Setup application options
// Use gui
QCommandLineOption useGuiOption("gui", "Enable GUI mode");
parser.addOption(useGuiOption);
// File name
QCommandLineOption fileName("fileName",
QCoreApplication::translate("main", "Set desired log fileName (e.g.: 2020-04-01_match)"),
QCoreApplication::translate("main", "fileName"));
parser.addOption(fileName);
// Vision network
QCommandLineOption visionNetwork("vision",
QCoreApplication::translate("main", "Set vision address:port (default is 224.0.0.1:10002)"),
QCoreApplication::translate("main", "address>:<port"));
parser.addOption(visionNetwork);
// Referee network
QCommandLineOption refereeNetwork("referee",
QCoreApplication::translate("main", "Set referee address:port (default is 224.5.23.2:10003)"),
QCoreApplication::translate("main", "address>:<port"));
parser.addOption(refereeNetwork);
// Process parser in application
parser.process((*a));
// Setup ExitHandler
ExitHandler::setApplication(a.data());
ExitHandler::setup();
// Parse
// File Name
QString logFileName = "";
if(parser.isSet(fileName)) {
logFileName = parser.value(fileName);
}
// Vision
QString visionAddress = "224.0.0.1";
quint16 visionPort = 10002;
if(parser.isSet(visionNetwork)) {
QString visionNetworkValue = parser.value(visionNetwork);
visionAddress = visionNetworkValue.split(":").at(0);
visionPort = visionNetworkValue.split(":").at(1).toUInt();
}
// Referee
QString refereeAddress = "224.5.23.2";
quint16 refereePort = 10003;
if(parser.isSet(refereeNetwork)) {
QString refereeNetworkValue = parser.value(refereeNetwork);
refereeAddress = refereeNetworkValue.split(":").at(0);
refereePort = refereeNetworkValue.split(":").at(1).toUInt();
}
if(!parser.isSet(useGuiOption) && !parser.isSet(fileName)) {
std::cout << Text::red("[ERROR] ", true) + Text::bold("If you don't use GUI you need to specify the file to open using --fileName argument.") + '\n';
return 0;
}
Player *player = new Player(visionAddress, visionPort, refereeAddress, refereePort, logFileName);
PlayerGUI *window = nullptr;
if(parser.isSet(useGuiOption)) {
window = new PlayerGUI(player);
window->show();
}
else{
player->start();
}
int exec = a->exec();
// Wait for thread to terminate
player->pauseExecution();
if(!player->isFinished()) {
player->terminate();
player->wait();
}
delete player;
// Close gui
if(parser.isSet(useGuiOption)) {
window->close();
delete window;
}
return exec;
}