forked from MaracatronicsRobotics/Armorial-Suassuna-Legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexithandler.cpp
59 lines (52 loc) · 1.91 KB
/
exithandler.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
/***
* Maracatronics Robotics
* Federal University of Pernambuco (UFPE) at Recife
* http://www.maracatronics.com/
*
* This file is part of Armorial project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include "exithandler.h"
#include "signal.h"
#include <iostream>
QCoreApplication* ExitHandler::_app = NULL;
int ExitHandler::_counter = 0;
ExitHandler::ExitHandler() {
}
void ExitHandler::setApplication(QCoreApplication *app) {
ExitHandler::_app = app;
}
void ExitHandler::setup() {
struct sigaction sigIntHandler;
sigIntHandler.sa_handler = ExitHandler::run;
sigemptyset(&sigIntHandler.sa_mask);
sigIntHandler.sa_flags = 0;
sigaction(SIGINT, &sigIntHandler, NULL);
}
void ExitHandler::run(int s) {
ExitHandler::_counter++;
switch(ExitHandler::_counter) {
case 1:
std::cout << MRCConstants::defaultBold << "\n[EXIT HANDLER] " << MRCConstants::green << "Closing Armorial Suassuna...\n" << MRCConstants::reset;
// Close application
ExitHandler::_app->exit();
break;
case 2:
std::cout << MRCConstants::defaultBold << "\n[EXIT HANDLER] " << MRCConstants::red << "Halting Armorial Suassuna...\n" << MRCConstants::reset;
exit(EXIT_FAILURE);
break;
}
}