Skip to content

Commit a191180

Browse files
author
Mauro Passerino
committed
Some fixes
Signed-off-by: Mauro Passerino <[email protected]>
1 parent 558569f commit a191180

File tree

6 files changed

+18
-83
lines changed

6 files changed

+18
-83
lines changed

rclcpp/include/rclcpp/executors/events_executor_notify_waitable.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class EventsExecutorNotifyWaitable final : public EventWaitable
6060

6161
RCLCPP_PUBLIC
6262
void
63-
set_listener_callback(std::function<void(size_t, int)> callback) override
63+
set_on_ready_callback(std::function<void(size_t, int)> callback) override
6464
{
6565
(void)callback;
6666
// for (auto gc : notify_guard_conditions_) {

rclcpp/include/rclcpp/experimental/subscription_intra_process_buffer.hpp

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -66,36 +66,13 @@ class SubscriptionIntraProcessBuffer : public SubscriptionIntraProcessBase
6666
const std::string & topic_name,
6767
rmw_qos_profile_t qos_profile,
6868
rclcpp::IntraProcessBufferType buffer_type)
69-
: SubscriptionIntraProcessBase(topic_name, qos_profile)
69+
: SubscriptionIntraProcessBase(context, topic_name, qos_profile)
7070
{
7171
// Create the intra-process buffer.
7272
buffer_ = rclcpp::experimental::create_intra_process_buffer<MessageT, Alloc, Deleter>(
7373
buffer_type,
7474
qos_profile,
7575
allocator);
76-
77-
// Create the guard condition.
78-
rcl_guard_condition_options_t guard_condition_options =
79-
rcl_guard_condition_get_default_options();
80-
81-
gc_ = rcl_get_zero_initialized_guard_condition();
82-
rcl_ret_t ret = rcl_guard_condition_init(
83-
&gc_, context->get_rcl_context().get(), guard_condition_options);
84-
85-
if (RCL_RET_OK != ret) {
86-
throw std::runtime_error(
87-
"SubscriptionIntraProcessBuffer init error initializing guard condition");
88-
}
89-
}
90-
91-
virtual ~SubscriptionIntraProcessBuffer()
92-
{
93-
if (rcl_guard_condition_fini(&gc_) != RCL_RET_OK) {
94-
RCUTILS_LOG_ERROR_NAMED(
95-
"rclcpp",
96-
"Failed to destroy guard condition: %s",
97-
rcutils_get_error_string().str);
98-
}
9976
}
10077

10178
bool
@@ -135,15 +112,15 @@ class SubscriptionIntraProcessBuffer : public SubscriptionIntraProcessBase
135112
if (on_new_message_callback_) {
136113
on_new_message_callback_(1);
137114
} else {
115+
gc_.trigger();
138116
unread_count_++;
139117
}
140118
}
141119

142120
void
143121
trigger_guard_condition()
144122
{
145-
rcl_ret_t ret = rcl_trigger_guard_condition(&gc_);
146-
(void)ret;
123+
gc_.trigger();
147124
}
148125

149126
BufferUniquePtr buffer_;

rclcpp/src/rclcpp/executor.cpp

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,6 @@ Executor::Executor(const rclcpp::ExecutorOptions & options)
7676
"rclcpp",
7777
"failed to create wait set: %s", rcl_get_error_string().str);
7878
rcl_reset_error();
79-
if (rcl_guard_condition_fini(&interrupt_guard_condition_) != RCL_RET_OK) {
80-
RCUTILS_LOG_ERROR_NAMED(
81-
"rclcpp",
82-
"failed to destroy guard condition: %s", rcl_get_error_string().str);
83-
rcl_reset_error();
84-
}
8579
throw_from_rcl_error(ret, "Failed to create wait set in Executor constructor");
8680
}
8781
}
@@ -214,17 +208,14 @@ Executor::add_callback_group_to_map(
214208
// Also add to the map that contains all callback groups
215209
weak_groups_to_nodes_.insert(std::make_pair(weak_group_ptr, node_ptr));
216210
if (is_new_node) {
217-
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr node_weak_ptr(node_ptr);
218-
weak_nodes_to_guard_conditions_[node_weak_ptr] = node_ptr->get_notify_guard_condition();
211+
const auto & node_gc = node_ptr->get_notify_rclcpp_guard_condition();
212+
weak_nodes_to_guard_conditions_[node_ptr] = node_gc;
219213
if (notify) {
220214
// Interrupt waiting to handle new node
221-
rcl_ret_t ret = rcl_trigger_guard_condition(&interrupt_guard_condition_);
222-
if (ret != RCL_RET_OK) {
223-
throw_from_rcl_error(ret, "Failed to trigger guard condition on callback group add");
224-
}
215+
interrupt_guard_condition_.trigger();
225216
}
226217
// Add the node's notify condition to the guard condition handles
227-
memory_strategy_->add_guard_condition(node_ptr->get_notify_guard_condition());
218+
memory_strategy_->add_guard_condition(node_gc);
228219
}
229220
}
230221

@@ -291,15 +282,11 @@ Executor::remove_callback_group_from_map(
291282
if (!has_node(node_ptr, weak_groups_to_nodes_associated_with_executor_) &&
292283
!has_node(node_ptr, weak_groups_associated_with_executor_to_nodes_))
293284
{
294-
rclcpp::node_interfaces::NodeBaseInterface::WeakPtr node_weak_ptr(node_ptr);
295-
weak_nodes_to_guard_conditions_.erase(node_weak_ptr);
285+
weak_nodes_to_guard_conditions_.erase(node_ptr);
296286
if (notify) {
297-
rcl_ret_t ret = rcl_trigger_guard_condition(&interrupt_guard_condition_);
298-
if (ret != RCL_RET_OK) {
299-
throw_from_rcl_error(ret, "Failed to trigger guard condition on callback group remove");
300-
}
287+
interrupt_guard_condition_.trigger();
301288
}
302-
memory_strategy_->remove_guard_condition(node_ptr->get_notify_guard_condition());
289+
memory_strategy_->remove_guard_condition(node_ptr->get_notify_rclcpp_guard_condition());
303290
}
304291
}
305292

@@ -470,10 +457,7 @@ void
470457
Executor::cancel()
471458
{
472459
spinning.store(false);
473-
rcl_ret_t ret = rcl_trigger_guard_condition(&interrupt_guard_condition_);
474-
if (ret != RCL_RET_OK) {
475-
throw_from_rcl_error(ret, "Failed to trigger guard condition in cancel");
476-
}
460+
interrupt_guard_condition_.trigger();
477461
}
478462

479463
void

rclcpp/src/rclcpp/executors/events_executor_entities_collector.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ EventsExecutorEntitiesCollector::set_callback_group_entities_callbacks(
267267
if (waitable) {
268268
weak_waitables_map_.emplace(waitable.get(), waitable);
269269

270-
waitable->set_listener_callback(
270+
waitable->set_on_ready_callback(
271271
create_waitable_callback(waitable.get()));
272272
}
273273
return false;
@@ -291,31 +291,31 @@ EventsExecutorEntitiesCollector::unset_callback_group_entities_callbacks(
291291
group->find_subscription_ptrs_if(
292292
[this](const rclcpp::SubscriptionBase::SharedPtr & subscription) {
293293
if (subscription) {
294-
subscription->set_on_new_message_callback(nullptr);
294+
subscription->clear_on_new_message_callback();
295295
weak_subscriptions_map_.erase(subscription.get());
296296
}
297297
return false;
298298
});
299299
group->find_service_ptrs_if(
300300
[this](const rclcpp::ServiceBase::SharedPtr & service) {
301301
if (service) {
302-
service->set_on_new_request_callback(nullptr);
302+
service->clear_on_new_request_callback();
303303
weak_services_map_.erase(service.get());
304304
}
305305
return false;
306306
});
307307
group->find_client_ptrs_if(
308308
[this](const rclcpp::ClientBase::SharedPtr & client) {
309309
if (client) {
310-
client->set_on_new_response_callback(nullptr);
310+
client->clear_on_new_response_callback();
311311
weak_clients_map_.erase(client.get());
312312
}
313313
return false;
314314
});
315315
group->find_waitable_ptrs_if(
316316
[this](const rclcpp::Waitable::SharedPtr & waitable) {
317317
if (waitable) {
318-
waitable->set_listener_callback(nullptr);
318+
waitable->clear_on_ready_callback();
319319
weak_waitables_map_.erase(waitable.get());
320320
}
321321
return false;
@@ -583,7 +583,7 @@ EventsExecutorEntitiesCollector::add_waitable(rclcpp::Waitable::SharedPtr waitab
583583
{
584584
weak_waitables_map_.emplace(waitable.get(), waitable);
585585

586-
waitable->set_listener_callback(
586+
waitable->set_on_ready_callback(
587587
create_waitable_callback(waitable.get()));
588588
}
589589

rclcpp/src/rclcpp/qos_event.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,4 @@ QOSEventHandlerBase::set_on_new_event_callback(
8484
}
8585
}
8686

87-
void
88-
QOSEventHandlerBase::set_listener_callback(std::function<void(size_t, int)> callback)
89-
{
90-
// set_on_new_event_callback(callback);
91-
}
92-
93-
9487
} // namespace rclcpp

rclcpp/src/rclcpp/subscription_intra_process_base.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,3 @@ SubscriptionIntraProcessBase::get_actual_qos() const
3939
{
4040
return qos_profile_;
4141
}
42-
43-
void
44-
SubscriptionIntraProcessBase::set_listener_callback(std::function<void(size_t, int)> callback)
45-
{
46-
if (callback) {
47-
on_new_message_callback_ = std::bind(callback, std::placeholders::_1, -1);
48-
if (unread_count_) {
49-
if (unread_count_ < qos_profile_.depth) {
50-
on_new_message_callback_(unread_count_);
51-
} else {
52-
on_new_message_callback_(qos_profile_.depth);
53-
}
54-
unread_count_ = 0;
55-
}
56-
return;
57-
}
58-
59-
on_new_message_callback_ = nullptr;
60-
}

0 commit comments

Comments
 (0)