Skip to content

Commit f9457a2

Browse files
author
iRobot ROS
authored
Merge pull request #36 from mauropasse/mauro/update-events-executor
update APIs
2 parents d6660a8 + f3fa8cb commit f9457a2

File tree

6 files changed

+37
-19
lines changed

6 files changed

+37
-19
lines changed

rclcpp/include/rclcpp/executors/events_executor_entities_collector.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class EventsExecutor;
5050
* in the entities currently used by the executor.
5151
*/
5252
class EventsExecutorEntitiesCollector final
53-
: public EventWaitable,
53+
: public EventWaitable,
5454
public std::enable_shared_from_this<EventsExecutorEntitiesCollector>
5555
{
5656
public:
@@ -75,7 +75,7 @@ class EventsExecutorEntitiesCollector final
7575
// If a entity is removed from a node, we should unset its callback
7676
RCLCPP_PUBLIC
7777
void
78-
execute() override;
78+
execute(std::shared_ptr<void> & data) override;
7979

8080
RCLCPP_PUBLIC
8181
void
@@ -192,6 +192,14 @@ class EventsExecutorEntitiesCollector final
192192
void
193193
add_waitable(rclcpp::Waitable::SharedPtr waitable);
194194

195+
RCLCPP_PUBLIC
196+
std::shared_ptr<void>
197+
take_data()
198+
{
199+
// This waitable doesn't handle any data
200+
return nullptr;
201+
}
202+
195203
private:
196204
void
197205
set_callback_group_entities_callbacks(rclcpp::CallbackGroup::SharedPtr group);

rclcpp/include/rclcpp/executors/events_executor_notify_waitable.hpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define RCLCPP__EXECUTORS__EVENTS_EXECUTOR_NOTIFY_WAITABLE_HPP_
1717

1818
#include <list>
19+
#include <memory>
1920

2021
#include "rcl/guard_condition.h"
2122
#include "rclcpp/executors/event_waitable.hpp"
@@ -45,12 +46,14 @@ class EventsExecutorNotifyWaitable final : public EventWaitable
4546
// The function is a no-op, since we only care of waking up the executor
4647
RCLCPP_PUBLIC
4748
void
48-
execute() override
49-
{}
49+
execute(std::shared_ptr<void> & data) override
50+
{
51+
(void)data;
52+
}
5053

5154
RCLCPP_PUBLIC
5255
void
53-
add_guard_condition(rcl_guard_condition_t * guard_condition)
56+
add_guard_condition(const rcl_guard_condition_t * guard_condition)
5457
{
5558
notify_guard_conditions_.push_back(guard_condition);
5659
}
@@ -75,8 +78,16 @@ class EventsExecutorNotifyWaitable final : public EventWaitable
7578
}
7679
}
7780

81+
RCLCPP_PUBLIC
82+
std::shared_ptr<void>
83+
take_data()
84+
{
85+
// This waitable doesn't handle any data
86+
return nullptr;
87+
}
88+
7889
private:
79-
std::list<rcl_guard_condition_t *> notify_guard_conditions_;
90+
std::list<const rcl_guard_condition_t *> notify_guard_conditions_;
8091
};
8192

8293
} // namespace executors

rclcpp/include/rclcpp/executors/timers_manager.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ class TimersManager
200200
bool any_timer_destroyed = false;
201201

202202
auto it = weak_heap_.begin();
203-
auto end = weak_heap_.end();
204-
while (it != end) {
203+
204+
while (it != weak_heap_.end()) {
205205
if (auto timer_shared_ptr = it->lock()) {
206206
// This timer is valid, add it to the vector
207207
locked_heap.push_back(std::move(timer_shared_ptr));

rclcpp/src/rclcpp/executors/events_executor.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,10 @@ EventsExecutor::EventsExecutor(
3333
entities_collector_ = std::make_shared<EventsExecutorEntitiesCollector>(this);
3434
entities_collector_->init();
3535

36-
// This API uses the wait_set only as a token to identify different executors.
37-
auto context_interrupt_gc = options.context->get_interrupt_guard_condition(&wait_set_);
38-
3936
// Setup the executor notifier to wake up the executor when some guard conditions are tiggered.
4037
// The added guard conditions are guaranteed to not go out of scope before the executor itself.
4138
executor_notifier_ = std::make_shared<EventsExecutorNotifyWaitable>();
42-
executor_notifier_->add_guard_condition(context_interrupt_gc);
39+
executor_notifier_->add_guard_condition(&shutdown_guard_condition_->get_rcl_guard_condition());
4340
executor_notifier_->add_guard_condition(&interrupt_guard_condition_);
4441
executor_notifier_->set_events_executor_callback(this, &EventsExecutor::push_event);
4542
entities_collector_->add_waitable(executor_notifier_);
@@ -305,7 +302,8 @@ EventsExecutor::execute_event(const rmw_listener_event_t & event)
305302
auto waitable = entities_collector_->get_waitable(event.entity);
306303

307304
if (waitable) {
308-
waitable->execute();
305+
auto data = waitable->take_data();
306+
waitable->execute(data);
309307
}
310308
break;
311309
}

rclcpp/src/rclcpp/executors/events_executor_entities_collector.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include <memory>
1516
#include <string>
1617
#include <utility>
1718
#include <vector>
@@ -141,8 +142,7 @@ EventsExecutorEntitiesCollector::add_callback_group(
141142
set_guard_condition_callback(node_ptr->get_notify_guard_condition());
142143

143144
// Store node's notify guard condition
144-
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr node_weak_ptr(node_ptr);
145-
weak_nodes_to_guard_conditions_[node_weak_ptr] = node_ptr->get_notify_guard_condition();
145+
weak_nodes_to_guard_conditions_[node_ptr] = node_ptr->get_notify_guard_condition();
146146
}
147147

148148
// Add callback group to weak_groups_to_node
@@ -161,8 +161,9 @@ EventsExecutorEntitiesCollector::add_callback_group(
161161
}
162162

163163
void
164-
EventsExecutorEntitiesCollector::execute()
164+
EventsExecutorEntitiesCollector::execute(std::shared_ptr<void> & data)
165165
{
166+
(void)data;
166167
// This function is called when the associated executor is notified that something changed.
167168
// We do not know if an entity has been added or removed so we have to rebuild everything.
168169

rclcpp/test/rclcpp/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ if(TARGET test_executors)
559559
target_link_libraries(test_executors ${PROJECT_NAME})
560560
endif()
561561

562-
ament_add_gtest(test_events_executor rclcpp/executors/test_events_executor.cpp
562+
ament_add_gtest(test_events_executor executors/test_events_executor.cpp
563563
APPEND_LIBRARY_DIRS "${append_library_dirs}")
564564
if(TARGET test_events_executor)
565565
ament_target_dependencies(test_events_executor
@@ -568,7 +568,7 @@ if(TARGET test_events_executor)
568568
target_link_libraries(test_events_executor ${PROJECT_NAME} mimick)
569569
endif()
570570

571-
ament_add_gtest(test_events_executor_entities_collector rclcpp/executors/test_events_executor_entities_collector.cpp
571+
ament_add_gtest(test_events_executor_entities_collector executors/test_events_executor_entities_collector.cpp
572572
APPEND_LIBRARY_DIRS "${append_library_dirs}")
573573
if(TARGET test_events_executor_entities_collector)
574574
ament_target_dependencies(test_events_executor_entities_collector
@@ -602,7 +602,7 @@ if(TARGET test_static_executor_entities_collector)
602602
target_link_libraries(test_static_executor_entities_collector ${PROJECT_NAME} mimick)
603603
endif()
604604

605-
ament_add_gtest(test_timers_manager rclcpp/executors/test_timers_manager.cpp
605+
ament_add_gtest(test_timers_manager executors/test_timers_manager.cpp
606606
APPEND_LIBRARY_DIRS "${append_library_dirs}")
607607
if(TARGET test_timers_manager)
608608
ament_target_dependencies(test_timers_manager

0 commit comments

Comments
 (0)