Skip to content

Commit

Permalink
can add multiple cbgs and check if callback is owned by another exec …
Browse files Browse the repository at this point in the history
…before adding
  • Loading branch information
peterpena committed Jul 9, 2020
1 parent e97dcd4 commit b06b526
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions rclcpp/include/rclcpp/executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ class Executor
rclcpp::CallbackGroup::SharedPtr group_ptr,
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, bool notify = true);


/// Add callback groups to an executor.
RCLCPP_PUBLIC
virtual void
add_callback_groups(
std::vector<rclcpp::CallbackGroup::SharedPtr> group_ptrs,
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, bool notify = true);

/// Remove a callback group from the executor.
RCLCPP_PUBLIC
virtual void
Expand Down
15 changes: 14 additions & 1 deletion rclcpp/src/rclcpp/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,25 @@ Executor::add_callback_group(
}
}

void
Executor::add_callback_groups(
std::vector<rclcpp::CallbackGroup::SharedPtr> group_ptrs,
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
bool notify)
{
for_each(group_ptrs.begin(), group_ptrs.end(),
[node_ptr, notify, this](rclcpp::CallbackGroup::SharedPtr group_ptr)
{
add_callback_group(group_ptr, node_ptr, notify);
});
}

void
Executor::add_node(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr, bool notify)
{
for (auto & weak_group : node_ptr->get_callback_groups()) {
auto group_ptr = weak_group.lock();
if (group_ptr != nullptr) {
if (group_ptr != nullptr && !group_ptr->get_associated_with_executor_atomic().load()) {
add_callback_group(group_ptr, node_ptr, notify);
}
}
Expand Down

0 comments on commit b06b526

Please sign in to comment.