Class SubscriptionIntraProcessBase
Defined in File subscription_intra_process_base.hpp
Inheritance Relationships
Base Type
public rclcpp::Waitable
(Class Waitable)
Derived Types
public rclcpp::experimental::SubscriptionROSMsgIntraProcessBuffer< SubscribedType, allocator::AllocRebind< SubscribedType, std::allocator< SubscribedType > >::allocator_type, allocator::Deleter< allocator::AllocRebind< SubscribedType, std::allocator< SubscribedType > >::allocator_type, SubscribedType > >
(Template Class SubscriptionROSMsgIntraProcessBuffer)public rclcpp::experimental::SubscriptionROSMsgIntraProcessBuffer< RosMessageT, Alloc, Deleter >
(Template Class SubscriptionROSMsgIntraProcessBuffer)
Class Documentation
-
class SubscriptionIntraProcessBase : public rclcpp::Waitable
Subclassed by rclcpp::experimental::SubscriptionROSMsgIntraProcessBuffer< SubscribedType, allocator::AllocRebind< SubscribedType, std::allocator< SubscribedType > >::allocator_type, allocator::Deleter< allocator::AllocRebind< SubscribedType, std::allocator< SubscribedType > >::allocator_type, SubscribedType > >, rclcpp::experimental::SubscriptionROSMsgIntraProcessBuffer< RosMessageT, Alloc, Deleter >
Public Functions
-
virtual ~SubscriptionIntraProcessBase() = default
-
inline virtual size_t get_number_of_ready_guard_conditions() override
Get the number of ready guard_conditions.
Returns a value of 0 by default. This should be overridden if the Waitable contains one or more guard_conditions.
- Returns:
The number of guard_conditions associated with the Waitable.
-
virtual void add_to_wait_set(rcl_wait_set_t &wait_set) override
Add the Waitable to a wait set.
- Parameters:
wait_set – [in] A handle to the wait set to add the Waitable to.
- Throws:
rclcpp::execptions::RCLError – from rcl_wait_set_add_*()
-
virtual size_t available_capacity() const = 0
-
bool is_durability_transient_local() const
-
virtual bool is_ready(const rcl_wait_set_t &wait_set) override = 0
Check if the Waitable is ready.
The input wait set should be the same that was used in a previously call to
add_to_wait_set()
. The wait set should also have been previously waited on withrcl_wait()
.
-
virtual std::shared_ptr<void> take_data() override = 0
Take the data so that it can be consumed with
execute
.NOTE: take_data is a partial fix to a larger design issue with the multithreaded executor. This method is likely to be removed when a more permanent fix is implemented. A longterm fix is currently being discussed here: https://github.com/ros2/rclcpp/pull/1276
This method takes the data from the underlying data structure and writes it to the void shared pointer
data
that is passed into the method. Thedata
can then be executed with theexecute
method.Before calling this method, the Waitable should be added to a wait set, waited on, and then updated.
Example usage:
// ... create a wait set and a Waitable // Add the Waitable to the wait set waitable.add_to_wait_set(wait_set); // Wait rcl_ret_t wait_ret = rcl_wait(wait_set); // ... error handling // Update the Waitable waitable.update(wait_set); // Execute any entities of the Waitable that may be ready std::shared_ptr<void> data = waitable.take_data();
-
inline virtual std::shared_ptr<void> take_data_by_entity_id(size_t id) override
Take the data so that it can be consumed with
execute
.This function allows to specify an entity ID to take the data from. Entity IDs are identifiers that can be defined by waitable-derived classes that are composed of several distinct entities. The main use-case is in conjunction with the listener APIs.
See also
- Parameters:
id – [in] the id of the entity from which to take
- Returns:
the type-erased data taken from entity specified
Execute data that is passed in.
Before calling this method, the Waitable should be added to a wait set, waited on, and then updated - and the
take_data
method should be called.Example usage:
// ... create a wait set and a Waitable // Add the Waitable to the wait set waitable.add_to_wait_set(wait_set); // Wait rcl_ret_t wait_ret = rcl_wait(wait_set); // ... error handling // Update the Waitable waitable.update(wait_set); // Execute any entities of the Waitable that may be ready std::shared_ptr<void> data = waitable.take_data(); waitable.execute(data);
-
const char *get_topic_name() const
-
inline virtual void set_on_ready_callback(std::function<void(size_t, int)> callback) override
Set a callback to be called when each new message arrives.
The callback receives a size_t which is the number of messages received since the last time this callback was called. Normally this is 1, but can be > 1 if messages were received before any callback was set.
The callback also receives an int identifier argument. This is needed because a Waitable may be composed of several distinct entities, such as subscriptions, services, etc. The application should provide a generic callback function that will be then forwarded by the waitable to all of its entities. Before forwarding, a different value for the identifier argument will be bound to the function. This implies that the provided callback can use the identifier to behave differently depending on which entity triggered the waitable to become ready.
Calling it again will clear any previously set callback.
An exception will be thrown if the callback is not callable.
This function is thread-safe.
If you want more information available in the callback, like the subscription or other information, you may use a lambda with captures or std::bind.
- Parameters:
callback – [in] functor to be called when a new message is received.
-
inline virtual void clear_on_ready_callback() override
Unset the callback registered for new messages, if any.
Protected Functions
-
virtual void trigger_guard_condition() = 0
-
inline void invoke_on_new_message()
Protected Attributes
-
std::recursive_mutex callback_mutex_
-
std::function<void(size_t)> on_new_message_callback_ = {nullptr}
-
size_t unread_count_ = {0}
-
rclcpp::GuardCondition gc_
-
virtual ~SubscriptionIntraProcessBase() = default