Skip to content

Commit 32aa3db

Browse files
author
Mauro Passerino
committed
GuardCondition to have callback <WIP>
Signed-off-by: Mauro Passerino <[email protected]>
1 parent 1412e94 commit 32aa3db

File tree

9 files changed

+38
-26
lines changed

9 files changed

+38
-26
lines changed

rclcpp/include/rclcpp/executors/events_executor_entities_collector.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ class EventsExecutorEntitiesCollector final
215215
unset_guard_condition_callback(const rclcpp::GuardCondition * guard_condition);
216216

217217
std::function<void(size_t)>
218-
create_entity_callback(void * entity_id, ExecutorEventType type);
218+
create_entity_callback(void * exec_entity_id, ExecutorEventType type);
219+
220+
std::function<void(size_t, int)>
221+
create_waitable_callback(void * waitable_id);
219222

220223
/// Return true if the node belongs to the collector
221224
/**

rclcpp/include/rclcpp/executors/events_executor_event_types.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ enum ExecutorEventType
3030

3131
struct ExecutorEvent
3232
{
33-
const void * entity_id;
33+
const void * exec_entity_id;
34+
int gen_entity_id;
3435
ExecutorEventType type;
3536
size_t num_events;
3637
};

rclcpp/include/rclcpp/executors/events_executor_notify_waitable.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,12 @@ class EventsExecutorNotifyWaitable final : public EventWaitable
6060

6161
RCLCPP_PUBLIC
6262
void
63-
set_listener_callback(
64-
rmw_listener_callback_t callback,
65-
const void * user_data) override
63+
set_listener_callback(std::function<void(size_t, int)> callback) override
6664
{
67-
for (auto gc : notify_guard_conditions_) {
68-
// gc->set_listener_callback();
69-
}
65+
(void)callback;
66+
// for (auto gc : notify_guard_conditions_) {
67+
// gc->set_listener_callback();
68+
// }
7069
}
7170

7271
RCLCPP_PUBLIC

rclcpp/include/rclcpp/experimental/subscription_intra_process_base.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ class SubscriptionIntraProcessBase : public rclcpp::Waitable
7979

8080
RCLCPP_PUBLIC
8181
void
82-
set_listener_callback(
83-
rmw_listener_callback_t callback,
84-
const void * user_data) override;
82+
set_listener_callback(std::function<void(size_t, int)> callback) override;
8583

8684
protected:
8785
std::recursive_mutex reentrant_mutex_;

rclcpp/include/rclcpp/qos_event.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,7 @@ class QOSEventHandlerBase : public Waitable
171171

172172
RCLCPP_PUBLIC
173173
void
174-
set_listener_callback(
175-
rmw_listener_callback_t callback,
176-
const void * user_data) override;
174+
set_listener_callback(std::function<void(size_t, int)> callback) override;
177175

178176
protected:
179177
RCLCPP_PUBLIC

rclcpp/include/rclcpp/waitable.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,7 @@ class Waitable
207207
RCLCPP_PUBLIC
208208
virtual
209209
void
210-
set_listener_callback(
211-
rmw_listener_callback_t callback,
212-
const void * user_data);
210+
set_listener_callback(std::function<void(size_t, int)> callback);
213211

214212
private:
215213
std::atomic<bool> in_use_by_wait_set_{false};

rclcpp/src/rclcpp/executors/events_executor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ EventsExecutor::execute_event(const ExecutorEvent & event)
253253
switch (event.type) {
254254
case SUBSCRIPTION_EVENT:
255255
{
256-
auto subscription = entities_collector_->get_subscription(event.entity_id);
256+
auto subscription = entities_collector_->get_subscription(event.exec_entity_id);
257257

258258
if (subscription) {
259259
for (size_t i = 0; i < event.num_events; i++) {
@@ -265,7 +265,7 @@ EventsExecutor::execute_event(const ExecutorEvent & event)
265265

266266
case SERVICE_EVENT:
267267
{
268-
auto service = entities_collector_->get_service(event.entity_id);
268+
auto service = entities_collector_->get_service(event.exec_entity_id);
269269

270270
if (service) {
271271
for (size_t i = 0; i < event.num_events; i++) {
@@ -277,7 +277,7 @@ EventsExecutor::execute_event(const ExecutorEvent & event)
277277

278278
case CLIENT_EVENT:
279279
{
280-
auto client = entities_collector_->get_client(event.entity_id);
280+
auto client = entities_collector_->get_client(event.exec_entity_id);
281281

282282
if (client) {
283283
for (size_t i = 0; i < event.num_events; i++) {
@@ -289,7 +289,7 @@ EventsExecutor::execute_event(const ExecutorEvent & event)
289289

290290
case WAITABLE_EVENT:
291291
{
292-
auto waitable = entities_collector_->get_waitable(event.entity_id);
292+
auto waitable = entities_collector_->get_waitable(event.exec_entity_id);
293293

294294
if (waitable) {
295295
for (size_t i = 0; i < event.num_events; i++) {

rclcpp/src/rclcpp/executors/events_executor_entities_collector.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ void
478478
EventsExecutorEntitiesCollector::set_guard_condition_callback(
479479
const rclcpp::GuardCondition * guard_condition)
480480
{
481-
// create_entity_callback(this, WAITABLE_EVENT);
481+
create_waitable_callback(this);
482482
}
483483

484484
void
@@ -573,10 +573,25 @@ EventsExecutorEntitiesCollector::add_waitable(rclcpp::Waitable::SharedPtr waitab
573573

574574
std::function<void(size_t)>
575575
EventsExecutorEntitiesCollector::create_entity_callback(
576-
void * entity_id, ExecutorEventType event_type)
576+
void * exec_entity_id, ExecutorEventType event_type)
577577
{
578-
return [this, entity_id, event_type](size_t num_events) {
579-
ExecutorEvent event = {entity_id, event_type, num_events};
578+
return [this, exec_entity_id, event_type](size_t num_events) {
579+
ExecutorEvent event = {exec_entity_id, -1, event_type, num_events};
580+
// Event queue mutex scope
581+
{
582+
std::unique_lock<std::mutex> lock(associated_executor_->push_mutex_);
583+
associated_executor_->events_queue_->push(event);
584+
}
585+
// Notify that the event queue has some events in it.
586+
associated_executor_->events_queue_cv_.notify_one();
587+
};
588+
}
589+
590+
std::function<void(size_t, int)>
591+
EventsExecutorEntitiesCollector::create_waitable_callback(void * exec_entity_id)
592+
{
593+
return [this, exec_entity_id](size_t num_events, int gen_entity_id) {
594+
ExecutorEvent event = {exec_entity_id, gen_entity_id, WAITABLE_EVENT, num_events};
580595
// Event queue mutex scope
581596
{
582597
std::unique_lock<std::mutex> lock(associated_executor_->push_mutex_);

rclcpp/test/rclcpp/executors/test_events_queue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ TEST(TestEventsQueue, SimpleQueueTest)
6060
rclcpp::executors::ExecutorEvent front_event = simple_queue->front();
6161

6262
// The events should be equal
63-
EXPECT_EQ(push_event.entity_id, front_event.entity_id);
63+
EXPECT_EQ(push_event.exec_entity_id, front_event.exec_entity_id);
6464
EXPECT_EQ(push_event.type, front_event.type);
6565
}

0 commit comments

Comments
 (0)