Hold onto the rcl_{subscription,publisher}_t shared_ptr.
This keeps it from going out of scope while the executor is still dealing with QoSEvents. Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
This commit is contained in:
parent
4efcfdc16b
commit
5632fa03ae
3 changed files with 11 additions and 7 deletions
|
@ -200,10 +200,11 @@ protected:
|
||||||
const EventCallbackT & callback,
|
const EventCallbackT & callback,
|
||||||
const rcl_publisher_event_type_t event_type)
|
const rcl_publisher_event_type_t event_type)
|
||||||
{
|
{
|
||||||
auto handler = std::make_shared<QOSEventHandler<EventCallbackT>>(
|
auto handler = std::make_shared<QOSEventHandler<EventCallbackT,
|
||||||
|
std::shared_ptr<rcl_publisher_t>>>(
|
||||||
callback,
|
callback,
|
||||||
rcl_publisher_event_init,
|
rcl_publisher_event_init,
|
||||||
publisher_handle_.get(),
|
publisher_handle_,
|
||||||
event_type);
|
event_type);
|
||||||
event_handlers_.emplace_back(handler);
|
event_handlers_.emplace_back(handler);
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,11 +102,11 @@ protected:
|
||||||
size_t wait_set_event_index_;
|
size_t wait_set_event_index_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename EventCallbackT>
|
template<typename EventCallbackT, typename ParentHandleT>
|
||||||
class QOSEventHandler : public QOSEventHandlerBase
|
class QOSEventHandler : public QOSEventHandlerBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
template<typename InitFuncT, typename ParentHandleT, typename EventTypeEnum>
|
template<typename InitFuncT, typename EventTypeEnum>
|
||||||
QOSEventHandler(
|
QOSEventHandler(
|
||||||
const EventCallbackT & callback,
|
const EventCallbackT & callback,
|
||||||
InitFuncT init_func,
|
InitFuncT init_func,
|
||||||
|
@ -114,8 +114,9 @@ public:
|
||||||
EventTypeEnum event_type)
|
EventTypeEnum event_type)
|
||||||
: event_callback_(callback)
|
: event_callback_(callback)
|
||||||
{
|
{
|
||||||
|
parent_handle_ = parent_handle;
|
||||||
event_handle_ = rcl_get_zero_initialized_event();
|
event_handle_ = rcl_get_zero_initialized_event();
|
||||||
rcl_ret_t ret = init_func(&event_handle_, parent_handle, event_type);
|
rcl_ret_t ret = init_func(&event_handle_, parent_handle.get(), event_type);
|
||||||
if (ret != RCL_RET_OK) {
|
if (ret != RCL_RET_OK) {
|
||||||
if (ret == RCL_RET_UNSUPPORTED) {
|
if (ret == RCL_RET_UNSUPPORTED) {
|
||||||
UnsupportedEventTypeException exc(ret, rcl_get_error_state(), "Failed to initialize event");
|
UnsupportedEventTypeException exc(ret, rcl_get_error_state(), "Failed to initialize event");
|
||||||
|
@ -148,6 +149,7 @@ private:
|
||||||
using EventCallbackInfoT = typename std::remove_reference<typename
|
using EventCallbackInfoT = typename std::remove_reference<typename
|
||||||
rclcpp::function_traits::function_traits<EventCallbackT>::template argument_type<0>>::type;
|
rclcpp::function_traits::function_traits<EventCallbackT>::template argument_type<0>>::type;
|
||||||
|
|
||||||
|
ParentHandleT parent_handle_;
|
||||||
EventCallbackT event_callback_;
|
EventCallbackT event_callback_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -270,10 +270,11 @@ protected:
|
||||||
const EventCallbackT & callback,
|
const EventCallbackT & callback,
|
||||||
const rcl_subscription_event_type_t event_type)
|
const rcl_subscription_event_type_t event_type)
|
||||||
{
|
{
|
||||||
auto handler = std::make_shared<QOSEventHandler<EventCallbackT>>(
|
auto handler = std::make_shared<QOSEventHandler<EventCallbackT,
|
||||||
|
std::shared_ptr<rcl_subscription_t>>>(
|
||||||
callback,
|
callback,
|
||||||
rcl_subscription_event_init,
|
rcl_subscription_event_init,
|
||||||
get_subscription_handle().get(),
|
get_subscription_handle(),
|
||||||
event_type);
|
event_type);
|
||||||
qos_events_in_use_by_wait_set_.insert(std::make_pair(handler.get(), false));
|
qos_events_in_use_by_wait_set_.insert(std::make_pair(handler.get(), false));
|
||||||
event_handlers_.emplace_back(handler);
|
event_handlers_.emplace_back(handler);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue