-
Notifications
You must be signed in to change notification settings - Fork 2
/
exithandler.cpp
38 lines (32 loc) · 965 Bytes
/
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
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include "exithandler.h"
#include "signal.h"
#include <iostream>
QApplication* ExitHandler::_app = NULL;
int ExitHandler::_counter = 0;
ExitHandler::ExitHandler() {
}
void ExitHandler::setApplication(QApplication *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 << "\n[EXIT HANDLER] " << "Closing VSSReferee...\n";
// Close application
ExitHandler::_app->exit();
break;
case 2:
std::cout << "\n[EXIT HANDLER] " << "Halting VSSReferee....\n";
exit(EXIT_FAILURE);
break;
}
}