Skip to content

Commit

Permalink
Merge pull request ros2#12 from mauropasse/mauro-irobot/add-events-ex…
Browse files Browse the repository at this point in the history
…ecutor

void return on set_events_executor_callback
  • Loading branch information
iRobot ROS committed Oct 14, 2020
2 parents ab92918 + 24ccf6e commit 78adf05
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 52 deletions.
1 change: 1 addition & 0 deletions rclcpp/include/rclcpp/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#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: 2 additions & 5 deletions rclcpp/include/rclcpp/qos_event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#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 @@ -155,16 +156,12 @@ class QOSEventHandler : public QOSEventHandlerBase
void * executor_context,
ExecutorEventCallback executor_callback) const override
{
rcl_ret_t ret = rcl_event_set_events_executor_callback(
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: 1 addition & 5 deletions rclcpp/src/rclcpp/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,9 @@ ClientBase::set_events_executor_callback(
const void * executor_context,
ExecutorEventCallback executor_callback) const
{
rcl_ret_t ret = rcl_client_set_events_executor_callback(
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: 2 additions & 12 deletions rclcpp/src/rclcpp/executors/events_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,21 @@ 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
ret = rcl_guard_condition_set_events_executor_callback(
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
ret = rcl_guard_condition_set_events_executor_callback(
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: 2 additions & 10 deletions rclcpp/src/rclcpp/executors/events_executor_entities_collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,12 @@ EventsExecutorEntitiesCollector::add_node(

// Set node's guard condition callback, so if new entities are added while
// spinning we can set their callback.
rcl_ret_t ret = rcl_guard_condition_set_events_executor_callback(
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 @@ -95,15 +91,11 @@ EventsExecutorEntitiesCollector::remove_node(
bool matched = (node_it->lock() == node_ptr);
if (matched) {
// Node found: unset its entities callbacks
rcl_ret_t ret = rcl_guard_condition_set_events_executor_callback(
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: 1 addition & 5 deletions rclcpp/src/rclcpp/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,9 @@ ServiceBase::set_events_executor_callback(
const void * executor_context,
ExecutorEventCallback executor_callback) const
{
rcl_ret_t ret = rcl_service_set_events_executor_callback(
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: 1 addition & 5 deletions rclcpp/src/rclcpp/subscription_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,9 @@ SubscriptionBase::set_events_executor_callback(
const void * executor_context,
ExecutorEventCallback executor_callback) const
{
rcl_ret_t ret = rcl_subscription_set_events_executor_callback(
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: 1 addition & 5 deletions rclcpp/src/rclcpp/subscription_intra_process_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,10 @@ SubscriptionIntraProcessBase::set_events_executor_callback(
void * executor_context,
ExecutorEventCallback executor_callback) const
{
rcl_ret_t ret = rcl_guard_condition_set_events_executor_callback(
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: 1 addition & 5 deletions rclcpp/test/rclcpp/executors/test_executors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,16 +457,12 @@ class TestWaitable : public rclcpp::Waitable
void * executor_context,
ExecutorEventCallback executor_callback) const override
{
rcl_ret_t ret = rcl_guard_condition_set_events_executor_callback(
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 78adf05

Please sign in to comment.