Skip to content

Commit

Permalink
Merge pull request #38 from mauropasse/mauro/clean-events-executor
Browse files Browse the repository at this point in the history
Implement no-op on IPC subscription
  • Loading branch information
iRobot ROS authored Feb 8, 2021
2 parents 3d7deb8 + 51bd25c commit 89b07f6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
12 changes: 12 additions & 0 deletions rclcpp/include/rclcpp/any_subscription_callback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ class AnySubscriptionCallback
ConstMessageSharedPtr message, const rclcpp::MessageInfo & message_info)
{
TRACEPOINT(callback_start, static_cast<const void *>(this), true);

// If the message is not valid, return.
if(!message) {
return;
}

if (const_shared_ptr_callback_) {
const_shared_ptr_callback_(message);
} else if (const_shared_ptr_with_info_callback_) {
Expand All @@ -208,6 +214,12 @@ class AnySubscriptionCallback
MessageUniquePtr message, const rclcpp::MessageInfo & message_info)
{
TRACEPOINT(callback_start, static_cast<const void *>(this), true);

// If the message is not valid, return.
if(!message) {
return;
}

if (shared_ptr_callback_) {
typename std::shared_ptr<MessageT> shared_message = std::move(message);
shared_ptr_callback_(shared_message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ class RingBufferImplementation : public BufferImplementationBase<BufferT>

if (!has_data_()) {
RCLCPP_ERROR(rclcpp::get_logger("rclcpp"), "Calling dequeue on empty intra-process buffer");
throw std::runtime_error("Calling dequeue on empty intra-process buffer");
// This situation can happen on the EventsExecutor if we have more events in the queue
// than messages in the history cache (set by the qos_policies.depth of the subscription)
// For example if we set depth=1 and we get 2 messages really fast (so no time for processing),
// we could end up with 2 events in the queue but only 1 msg is actually stored on the buffer.
// In this case we return an empty buffer.
return BufferT();
}

auto request = std::move(ring_buffer_[read_index_]);
Expand Down

0 comments on commit 89b07f6

Please sign in to comment.