add sigint singal handler chaining, err checking
This commit is contained in:
parent
f77e6d7d56
commit
d474d0e3b4
2 changed files with 32 additions and 29 deletions
|
@ -89,7 +89,6 @@ public:
|
||||||
|
|
||||||
void spin_node_some(rclcpp::node::Node::SharedPtr &node)
|
void spin_node_some(rclcpp::node::Node::SharedPtr &node)
|
||||||
{
|
{
|
||||||
reset_subscriber_handles();
|
|
||||||
this->add_node(node);
|
this->add_node(node);
|
||||||
// non-blocking = true
|
// non-blocking = true
|
||||||
std::shared_ptr<AnyExecutable> any_exec;
|
std::shared_ptr<AnyExecutable> any_exec;
|
||||||
|
@ -98,7 +97,6 @@ public:
|
||||||
execute_any_executable(any_exec);
|
execute_any_executable(any_exec);
|
||||||
}
|
}
|
||||||
this->remove_node(node);
|
this->remove_node(node);
|
||||||
reset_subscriber_handles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -163,29 +161,6 @@ protected:
|
||||||
timer->callback_();
|
timer->callback_();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** Reseting class storage ***/
|
|
||||||
|
|
||||||
void
|
|
||||||
reset_all_handles()
|
|
||||||
{
|
|
||||||
reset_subscriber_handles();
|
|
||||||
reset_guard_condition_handles();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
reset_subscriber_handles()
|
|
||||||
{
|
|
||||||
subscriber_handles_.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
reset_guard_condition_handles()
|
|
||||||
{
|
|
||||||
guard_condition_handles_.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************************/
|
|
||||||
|
|
||||||
/*** Populate class storage from stored weak node pointers and wait. ***/
|
/*** Populate class storage from stored weak node pointers and wait. ***/
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -283,6 +258,15 @@ protected:
|
||||||
ros_middleware_interface::wait(subscriber_handles,
|
ros_middleware_interface::wait(subscriber_handles,
|
||||||
guard_condition_handles,
|
guard_condition_handles,
|
||||||
nonblocking);
|
nonblocking);
|
||||||
|
// If ctrl-c guard condition, return directly
|
||||||
|
if (guard_condition_handles.guard_conditions_[0] != 0)
|
||||||
|
{
|
||||||
|
// Make sure to free memory
|
||||||
|
// TODO: Remove theses when "Avoid redundant malloc's" todo is addressed
|
||||||
|
std::free(subscriber_handles.subscribers_);
|
||||||
|
std::free(guard_condition_handles.guard_conditions_);
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Add the new work to the class's list of things waiting to be executed
|
// Add the new work to the class's list of things waiting to be executed
|
||||||
// Starting with the subscribers
|
// Starting with the subscribers
|
||||||
for (size_t i = 0; i < number_of_subscriptions; ++i)
|
for (size_t i = 0; i < number_of_subscriptions; ++i)
|
||||||
|
@ -587,15 +571,16 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
ros_middleware_interface::GuardConditionHandle interrupt_guard_condition_;
|
ros_middleware_interface::GuardConditionHandle interrupt_guard_condition_;
|
||||||
|
|
||||||
|
private:
|
||||||
|
RCLCPP_DISABLE_COPY(Executor);
|
||||||
|
|
||||||
std::vector<std::weak_ptr<rclcpp::node::Node>> weak_nodes_;
|
std::vector<std::weak_ptr<rclcpp::node::Node>> weak_nodes_;
|
||||||
typedef std::list<void*> SubscriberHandles;
|
typedef std::list<void*> SubscriberHandles;
|
||||||
SubscriberHandles subscriber_handles_;
|
SubscriberHandles subscriber_handles_;
|
||||||
typedef std::list<void*> GuardConditionHandles;
|
typedef std::list<void*> GuardConditionHandles;
|
||||||
GuardConditionHandles guard_condition_handles_;
|
GuardConditionHandles guard_condition_handles_;
|
||||||
|
|
||||||
private:
|
|
||||||
RCLCPP_DISABLE_COPY(Executor);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* executor */
|
} /* executor */
|
||||||
|
|
|
@ -16,11 +16,14 @@
|
||||||
#ifndef RCLCPP_RCLCPP_UTILITIES_HPP_
|
#ifndef RCLCPP_RCLCPP_UTILITIES_HPP_
|
||||||
#define RCLCPP_RCLCPP_UTILITIES_HPP_
|
#define RCLCPP_RCLCPP_UTILITIES_HPP_
|
||||||
|
|
||||||
|
// TODO: remove
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <cerrno>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
|
#include <cstring>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
@ -35,14 +38,21 @@ namespace
|
||||||
std::condition_variable g_interrupt_condition_variable;
|
std::condition_variable g_interrupt_condition_variable;
|
||||||
std::mutex g_interrupt_mutex;
|
std::mutex g_interrupt_mutex;
|
||||||
|
|
||||||
|
void (*old_signal_handler)(int) = 0;
|
||||||
|
|
||||||
void
|
void
|
||||||
signal_handler(int signal_value)
|
signal_handler(int signal_value)
|
||||||
{
|
{
|
||||||
|
// TODO: remove
|
||||||
std::cout << "signal_handler(" << signal_value << ")" << std::endl;
|
std::cout << "signal_handler(" << signal_value << ")" << std::endl;
|
||||||
g_signal_status = signal_value;
|
g_signal_status = signal_value;
|
||||||
using ros_middleware_interface::trigger_guard_condition;
|
using ros_middleware_interface::trigger_guard_condition;
|
||||||
trigger_guard_condition(g_sigint_guard_cond_handle);
|
trigger_guard_condition(g_sigint_guard_cond_handle);
|
||||||
g_interrupt_condition_variable.notify_all();
|
g_interrupt_condition_variable.notify_all();
|
||||||
|
if (old_signal_handler)
|
||||||
|
{
|
||||||
|
return old_signal_handler(signal_value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +67,15 @@ namespace utilities
|
||||||
void
|
void
|
||||||
init(int argc, char *argv[])
|
init(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
std::signal(SIGINT, ::signal_handler);
|
ros_middleware_interface::init();
|
||||||
|
::old_signal_handler = std::signal(SIGINT, ::signal_handler);
|
||||||
|
if (::old_signal_handler == SIG_ERR)
|
||||||
|
{
|
||||||
|
throw std::runtime_error(
|
||||||
|
std::string("Failed to set SIGINT signal handler: (" +
|
||||||
|
std::to_string(errno) + ")") +
|
||||||
|
std::strerror(errno));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue