1 |
|
|
/** |
2 |
|
|
* @file |
3 |
|
|
* @copyright 2020, New York University, Max Planck Gesellschaft. All rights |
4 |
|
|
* reserved. |
5 |
|
|
* @license BSD 3-clause |
6 |
|
|
*/ |
7 |
|
|
#include <csignal> |
8 |
|
|
#include <robot_interfaces/global_signal_handler.hpp> |
9 |
|
|
|
10 |
|
|
namespace robot_interfaces |
11 |
|
|
{ |
12 |
|
|
bool GlobalSignalHandler::received_sigint_ = false; |
13 |
|
|
|
14 |
|
|
void GlobalSignalHandler::initialize() |
15 |
|
|
{ |
16 |
|
|
static bool is_initialized = false; |
17 |
|
|
|
18 |
|
|
if (!is_initialized) |
19 |
|
|
{ |
20 |
|
|
std::signal(SIGINT, &GlobalSignalHandler::signal_handler); |
21 |
|
|
received_sigint_ = false; |
22 |
|
|
is_initialized = true; |
23 |
|
|
} |
24 |
|
|
} |
25 |
|
|
|
26 |
|
|
void GlobalSignalHandler::signal_handler(int signal) |
27 |
|
|
{ |
28 |
|
|
if (signal == SIGINT) |
29 |
|
|
{ |
30 |
|
|
received_sigint_ = true; |
31 |
|
|
} |
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
bool GlobalSignalHandler::has_received_sigint() |
35 |
|
|
{ |
36 |
|
|
return received_sigint_; |
37 |
|
|
} |
38 |
|
|
|
39 |
|
|
} // namespace robot_interfaces |