Skip to content

Commit

Permalink
Merge pull request ros2#15 from irobot-ros/revert-12-mauro-irobot/add…
Browse files Browse the repository at this point in the history
…-events-executor

Revert "void return on set_events_executor_callback"
  • Loading branch information
iRobot ROS authored Oct 14, 2020
2 parents 78adf05 + 6f32325 commit 419054b
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 12 deletions.
1 change: 0 additions & 1 deletion rclcpp/include/rclcpp/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "rclcpp/expand_topic_or_service_name.hpp"
#include "rclcpp/visibility_control.hpp"

#include "rcutils/executor_event_types.h"
#include "rcutils/logging_macros.h"

#include "rmw/error_handling.h"
Expand Down
7 changes: 5 additions & 2 deletions rclcpp/include/rclcpp/qos_event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "rcl/error_handling.h"
#include "rmw/incompatible_qos_events_statuses.h"

#include "rcutils/executor_event_types.h"
#include "rcutils/logging_macros.h"

#include "rclcpp/exceptions.hpp"
Expand Down Expand Up @@ -156,12 +155,16 @@ class QOSEventHandler : public QOSEventHandlerBase
void * executor_context,
ExecutorEventCallback executor_callback) const override
{
rcl_event_set_events_executor_callback(
rcl_ret_t ret = rcl_event_set_events_executor_callback(
executor_context,
executor_callback,
this,
&event_handle_,
false /* Discard previous events */);

if (RCL_RET_OK != ret) {
throw std::runtime_error("Couldn't set EventsExecutor's callback to event");
}
}

private:
Expand Down
6 changes: 5 additions & 1 deletion rclcpp/src/rclcpp/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,13 @@ ClientBase::set_events_executor_callback(
const void * executor_context,
ExecutorEventCallback executor_callback) const
{
rcl_client_set_events_executor_callback(
rcl_ret_t ret = rcl_client_set_events_executor_callback(
executor_context,
executor_callback,
this,
client_handle_.get());

if (RCL_RET_OK != ret) {
throw std::runtime_error("Couldn't set the EventsExecutor's callback to client");
}
}
14 changes: 12 additions & 2 deletions rclcpp/src/rclcpp/executors/events_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,31 @@ EventsExecutor::EventsExecutor(
timers_manager_ = std::make_shared<TimersManager>(context_);
entities_collector_ = std::make_shared<EventsExecutorEntitiesCollector>(this, timers_manager_);

rcl_ret_t ret;

// Set the global ctrl-c guard condition callback
rcl_guard_condition_set_events_executor_callback(
ret = rcl_guard_condition_set_events_executor_callback(
this,
&EventsExecutor::push_event,
entities_collector_.get(),
options.context->get_interrupt_guard_condition(&wait_set_),
false /* Discard previous events */);

if (ret != RCL_RET_OK) {
throw std::runtime_error("Couldn't set ctrl-c guard condition callback");
}

// Set the executor interrupt guard condition callback
rcl_guard_condition_set_events_executor_callback(
ret = rcl_guard_condition_set_events_executor_callback(
this,
&EventsExecutor::push_event,
entities_collector_.get(),
&interrupt_guard_condition_,
false /* Discard previous events */);

if (ret != RCL_RET_OK) {
throw std::runtime_error("Couldn't set interrupt guard condition callback");
}
}

EventsExecutor::~EventsExecutor() {}
Expand Down
12 changes: 10 additions & 2 deletions rclcpp/src/rclcpp/executors/events_executor_entities_collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,16 @@ EventsExecutorEntitiesCollector::add_node(

// Set node's guard condition callback, so if new entities are added while
// spinning we can set their callback.
rcl_guard_condition_set_events_executor_callback(
rcl_ret_t ret = rcl_guard_condition_set_events_executor_callback(
associated_executor_,
&EventsExecutor::push_event,
this,
node_ptr->get_notify_guard_condition(),
false /* Discard previous events */);

if (ret != RCL_RET_OK) {
throw std::runtime_error("Couldn't set node guard condition callback");
}
}

void
Expand All @@ -91,11 +95,15 @@ EventsExecutorEntitiesCollector::remove_node(
bool matched = (node_it->lock() == node_ptr);
if (matched) {
// Node found: unset its entities callbacks
rcl_guard_condition_set_events_executor_callback(
rcl_ret_t ret = rcl_guard_condition_set_events_executor_callback(
nullptr, nullptr, nullptr,
node_ptr->get_notify_guard_condition(),
false);

if (ret != RCL_RET_OK) {
throw std::runtime_error(std::string("Couldn't set guard condition callback"));
}

// Unset entities callbacks
for (auto & weak_group : node_ptr->get_callback_groups()) {
auto group = weak_group.lock();
Expand Down
6 changes: 5 additions & 1 deletion rclcpp/src/rclcpp/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,13 @@ ServiceBase::set_events_executor_callback(
const void * executor_context,
ExecutorEventCallback executor_callback) const
{
rcl_service_set_events_executor_callback(
rcl_ret_t ret = rcl_service_set_events_executor_callback(
executor_context,
executor_callback,
this,
service_handle_.get());

if (RCL_RET_OK != ret) {
throw std::runtime_error("Couldn't set the EventsExecutor's callback to service");
}
}
6 changes: 5 additions & 1 deletion rclcpp/src/rclcpp/subscription_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,13 @@ SubscriptionBase::set_events_executor_callback(
const void * executor_context,
ExecutorEventCallback executor_callback) const
{
rcl_subscription_set_events_executor_callback(
rcl_ret_t ret = rcl_subscription_set_events_executor_callback(
executor_context,
executor_callback,
this,
subscription_handle_.get());

if (RCL_RET_OK != ret) {
throw std::runtime_error("Couldn't set the EventsExecutor's callback to subscription");
}
}
6 changes: 5 additions & 1 deletion rclcpp/src/rclcpp/subscription_intra_process_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ SubscriptionIntraProcessBase::set_events_executor_callback(
void * executor_context,
ExecutorEventCallback executor_callback) const
{
rcl_guard_condition_set_events_executor_callback(
rcl_ret_t ret = rcl_guard_condition_set_events_executor_callback(
executor_context,
executor_callback,
this,
&gc_,
true /*Use previous events*/);

if (RCL_RET_OK != ret) {
throw std::runtime_error(std::string("Couldn't set guard condition callback"));
}
}
6 changes: 5 additions & 1 deletion rclcpp/test/rclcpp/executors/test_executors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,16 @@ class TestWaitable : public rclcpp::Waitable
void * executor_context,
ExecutorEventCallback executor_callback) const override
{
rcl_guard_condition_set_events_executor_callback(
rcl_ret_t ret = rcl_guard_condition_set_events_executor_callback(
executor_context,
executor_callback,
this,
&gc_,
true /*Use previous events*/);

if (RCL_RET_OK != ret) {
throw std::runtime_error(std::string("Couldn't set guard condition callback"));
}
}

private:
Expand Down

0 comments on commit 419054b

Please sign in to comment.