include
qb_device_utils
ros_sigint_handler.h
Go to the documentation of this file.
1
/***
2
* Software License Agreement: BSD 3-Clause License
3
*
4
* Copyright (c) 2016-2021, qbrobotics®
5
* All rights reserved.
6
*
7
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
8
* following conditions are met:
9
*
10
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
11
* following disclaimer.
12
*
13
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
14
* following disclaimer in the documentation and/or other materials provided with the distribution.
15
*
16
* * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
17
* products derived from this software without specific prior written permission.
18
*
19
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
*/
27
28
#ifndef QB_DEVICE_SIGINT_HANDLER_H
29
#define QB_DEVICE_SIGINT_HANDLER_H
30
31
// specific for custom SIGINT handler
32
#include <signal.h>
33
#include <
ros/xmlrpc_manager.h
>
34
35
namespace
ros_sigint_handler
{
36
// signal-safe flag for whether shutdown is requested
37
static
volatile
sig_atomic_t
g_request_shutdown
= 0;
38
39
// replacement SIGINT handler
40
static
void
mySigIntHandler
(
int
_) {
41
(void)_;
42
g_request_shutdown
= 1;
// set flag
43
}
44
45
// replacement "shutdown" XMLRPC callback
46
static
void
shutdownCallback
(
XmlRpc::XmlRpcValue
¶ms,
XmlRpc::XmlRpcValue
&result) {
47
int
num_params = 0;
48
if
(params.
getType
() ==
XmlRpc::XmlRpcValue::TypeArray
) {
49
num_params = params.
size
();
50
}
51
if
(num_params > 1) {
52
std::string reason = params[1];
53
ROS_WARN
(
"Shutdown request received. Reason: [%s]"
, reason.c_str());
54
g_request_shutdown
= 1;
// set flag
55
}
56
57
result =
ros::xmlrpc::responseInt
(1,
""
, 0);
58
}
59
60
int
isShuttingDown
() {
61
return
g_request_shutdown
;
62
}
63
64
void
overrideHandlers
() {
65
// override SIGINT handler
66
signal(SIGINT,
mySigIntHandler
);
67
// override XMLRPC shutdown
68
ros::XMLRPCManager::instance
()->unbind(
"shutdown"
);
69
ros::XMLRPCManager::instance
()->bind(
"shutdown"
,
shutdownCallback
);
70
}
71
}
// namespace ros_sigint_handler
72
73
#endif // QB_DEVICE_SIGINT_HANDLER_H
XmlRpc::XmlRpcValue::size
int size() const
ros_sigint_handler::g_request_shutdown
static volatile sig_atomic_t g_request_shutdown
Definition:
ros_sigint_handler.h:62
ros::xmlrpc::responseInt
ROSCPP_DECL XmlRpc::XmlRpcValue responseInt(int code, const std::string &msg, int response)
xmlrpc_manager.h
ros_sigint_handler::mySigIntHandler
static void mySigIntHandler(int _)
Definition:
ros_sigint_handler.h:65
ROS_WARN
#define ROS_WARN(...)
ros::XMLRPCManager::instance
static const XMLRPCManagerPtr & instance()
XmlRpc::XmlRpcValue::getType
const Type & getType() const
XmlRpc::XmlRpcValue::TypeArray
TypeArray
ros_sigint_handler
Definition:
ros_sigint_handler.h:35
ros_sigint_handler::isShuttingDown
int isShuttingDown()
Definition:
ros_sigint_handler.h:85
ros_sigint_handler::shutdownCallback
static void shutdownCallback(XmlRpc::XmlRpcValue ¶ms, XmlRpc::XmlRpcValue &result)
Definition:
ros_sigint_handler.h:71
XmlRpc::XmlRpcValue
ros_sigint_handler::overrideHandlers
void overrideHandlers()
Definition:
ros_sigint_handler.h:89
qb_device_utils
Author(s): qbrobotics®
autogenerated on Thu Apr 27 2023 02:36:29