15 #ifndef RCLCPP__SIGNAL_HANDLER_HPP_
16 #define RCLCPP__SIGNAL_HANDLER_HPP_
23 #include "rclcpp/logging.hpp"
24 #include "rclcpp/utilities.hpp"
29 #elif defined(__APPLE__)
30 #include <dispatch/dispatch.h>
32 #include <semaphore.h>
36 #if __APPLE__ || _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE
37 #define RCLCPP_HAS_SIGACTION
99 #if defined(RCLCPP_HAS_SIGACTION)
100 using signal_handler_type =
struct sigaction;
102 using signal_handler_type = void (*)(int);
119 signal_handler_common();
121 #if defined(RCLCPP_HAS_SIGACTION)
125 signal_handler(
int signal_value, siginfo_t * siginfo,
void * context);
130 signal_handler(
int signal_value);
135 deferred_signal_handler();
143 setup_wait_for_signal();
152 teardown_wait_for_signal() noexcept;
171 notify_signal_handler() noexcept;
177 const signal_handler_type & signal_handler);
180 get_old_signal_handler(
int signum);
184 signal_handler_type old_sigint_handler_;
185 signal_handler_type old_sigterm_handler_;
191 std::atomic_bool signal_received_ =
false;
193 std::thread signal_handler_thread_;
196 std::mutex install_mutex_;
198 std::atomic_bool installed_ =
false;
201 std::atomic_bool wait_for_signal_is_setup_;
204 HANDLE signal_handler_sem_;
205 #elif defined(__APPLE__)
206 dispatch_semaphore_t signal_handler_sem_;
208 sem_t signal_handler_sem_;
Responsible for managing the SIGINT/SIGTERM signal handling.
static rclcpp::Logger & get_logger()
Return a global singleton logger to avoid needing to create it everywhere.
bool is_installed()
Return true if installed, false otherwise.
static SignalHandler & get_global_signal_handler()
Return the global singleton of this class.
bool install(SignalHandlerOptions signal_handler_options=SignalHandlerOptions::All)
Install the signal handler for SIGINT/SIGTERM and start the dedicated signal handling thread.
rclcpp::SignalHandlerOptions get_current_signal_handler_options()
Get the current signal handler options.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
SignalHandlerOptions
Option to indicate which signal handlers rclcpp should install.
@ None
Do not install any signal handler.
@ All
Install both sigint and sigterm, this is the default behavior.
RCLCPP_PUBLIC Logger get_logger(const std::string &name)
Return a named logger.