ROS 2 rclcpp + rcl - jazzy  jazzy
ROS 2 C++ Client Library with ROS Client Library
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
rclcpp::experimental::SubscriptionIntraProcessBase Class Referenceabstract
Inheritance diagram for rclcpp::experimental::SubscriptionIntraProcessBase:
Inheritance graph
[legend]
Collaboration diagram for rclcpp::experimental::SubscriptionIntraProcessBase:
Collaboration graph
[legend]

Public Types

enum class  EntityType : std::size_t { Subscription }
 

Public Member Functions

RCLCPP_PUBLIC SubscriptionIntraProcessBase (rclcpp::Context::SharedPtr context, const std::string &topic_name, const rclcpp::QoS &qos_profile)
 
RCLCPP_PUBLIC size_t get_number_of_ready_guard_conditions () override
 Get the number of ready guard_conditions. More...
 
RCLCPP_PUBLIC void add_to_wait_set (rcl_wait_set_t &wait_set) override
 Add the Waitable to a wait set. More...
 
virtual RCLCPP_PUBLIC size_t available_capacity () const =0
 
RCLCPP_PUBLIC bool is_durability_transient_local () const
 
bool is_ready (const rcl_wait_set_t &wait_set) override=0
 Check if the Waitable is ready. More...
 
std::shared_ptr< void > take_data () override=0
 Take the data so that it can be consumed with execute. More...
 
std::shared_ptr< void > take_data_by_entity_id (size_t id) override
 Take the data so that it can be consumed with execute. More...
 
void execute (const std::shared_ptr< void > &data) override=0
 Execute data that is passed in. More...
 
virtual bool use_take_shared_method () const =0
 
RCLCPP_PUBLIC const char * get_topic_name () const
 
RCLCPP_PUBLIC QoS get_actual_qos () const
 
void set_on_ready_callback (std::function< void(size_t, int)> callback) override
 Set a callback to be called when each new message arrives. More...
 
void clear_on_ready_callback () override
 Unset the callback registered for new messages, if any.
 
- Public Member Functions inherited from rclcpp::Waitable
virtual RCLCPP_PUBLIC size_t get_number_of_ready_subscriptions ()
 Get the number of ready subscriptions. More...
 
virtual RCLCPP_PUBLIC size_t get_number_of_ready_timers ()
 Get the number of ready timers. More...
 
virtual RCLCPP_PUBLIC size_t get_number_of_ready_clients ()
 Get the number of ready clients. More...
 
virtual RCLCPP_PUBLIC size_t get_number_of_ready_events ()
 Get the number of ready events. More...
 
virtual RCLCPP_PUBLIC size_t get_number_of_ready_services ()
 Get the number of ready services. More...
 
virtual RCLCPP_PUBLIC void add_to_wait_set (rcl_wait_set_t *wait_set)
 Deprecated. More...
 
virtual RCLCPP_PUBLIC bool is_ready (rcl_wait_set_t *wait_set)
 Deprecated. More...
 
virtual RCLCPP_PUBLIC void execute (std::shared_ptr< void > &data)
 Deprecated. More...
 
RCLCPP_PUBLIC bool exchange_in_use_by_wait_set_state (bool in_use_state)
 Exchange the "in use by wait set" state for this timer. More...
 

Protected Member Functions

virtual void trigger_guard_condition ()=0
 
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_
 

Detailed Description

Definition at line 36 of file subscription_intra_process_base.hpp.

Member Function Documentation

◆ add_to_wait_set()

void SubscriptionIntraProcessBase::add_to_wait_set ( rcl_wait_set_t wait_set)
overridevirtual

Add the Waitable to a wait set.

Parameters
[in]wait_setA handle to the wait set to add the Waitable to.
Exceptions
rclcpp::execptions::RCLErrorfrom rcl_wait_set_add_*()

Reimplemented from rclcpp::Waitable.

Reimplemented in rclcpp::experimental::SubscriptionIntraProcessBuffer< SubscribedType, Alloc, Deleter, ROSMessageType >, and rclcpp::experimental::SubscriptionIntraProcessBuffer< SubscribedType, std::allocator< SubscribedType >, std::default_delete< SubscribedType >, SubscribedType >.

Definition at line 21 of file subscription_intra_process_base.cpp.

◆ execute()

void rclcpp::experimental::SubscriptionIntraProcessBase::execute ( const std::shared_ptr< void > &  data)
overridepure virtual

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);
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.
Definition: types.h:24
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_wait(rcl_wait_set_t *wait_set, int64_t timeout)
Block until the wait set is ready or until the timeout has been exceeded.
Definition: wait.c:522

Reimplemented from rclcpp::Waitable.

Implemented in rclcpp::experimental::SubscriptionIntraProcess< MessageT, SubscribedType, SubscribedTypeAlloc, SubscribedTypeDeleter, ROSMessageType, Alloc >.

◆ get_number_of_ready_guard_conditions()

RCLCPP_PUBLIC size_t rclcpp::experimental::SubscriptionIntraProcessBase::get_number_of_ready_guard_conditions ( )
inlineoverridevirtual

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.

Reimplemented from rclcpp::Waitable.

Definition at line 59 of file subscription_intra_process_base.hpp.

◆ is_ready()

bool rclcpp::experimental::SubscriptionIntraProcessBase::is_ready ( const rcl_wait_set_t wait_set)
overridepure virtual

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 with rcl_wait().

Parameters
[in]wait_setA handle to the wait set the Waitable was previously added to and that has been waited on.
Returns
true if the Waitable is ready, false otherwise.

Reimplemented from rclcpp::Waitable.

Implemented in rclcpp::experimental::SubscriptionIntraProcessBuffer< SubscribedType, Alloc, Deleter, ROSMessageType >, and rclcpp::experimental::SubscriptionIntraProcessBuffer< SubscribedType, std::allocator< SubscribedType >, std::default_delete< SubscribedType >, SubscribedType >.

◆ set_on_ready_callback()

void rclcpp::experimental::SubscriptionIntraProcessBase::set_on_ready_callback ( std::function< void(size_t, int)>  callback)
inlineoverridevirtual

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
[in]callbackfunctor to be called when a new message is received.

Reimplemented from rclcpp::Waitable.

Definition at line 131 of file subscription_intra_process_base.hpp.

References rclcpp::QoS::depth(), rclcpp::get_logger(), and rclcpp::QoS::history().

Here is the call graph for this function:

◆ take_data()

std::shared_ptr<void> rclcpp::experimental::SubscriptionIntraProcessBase::take_data ( )
overridepure virtual

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. The data can then be executed with the execute 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();

Implements rclcpp::Waitable.

Implemented in rclcpp::experimental::SubscriptionIntraProcess< MessageT, SubscribedType, SubscribedTypeAlloc, SubscribedTypeDeleter, ROSMessageType, Alloc >.

Referenced by take_data_by_entity_id().

Here is the caller graph for this function:

◆ take_data_by_entity_id()

std::shared_ptr<void> rclcpp::experimental::SubscriptionIntraProcessBase::take_data_by_entity_id ( size_t  id)
inlineoverridevirtual

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.

Parameters
[in]idthe id of the entity from which to take
Returns
the type-erased data taken from entity specified
See also
rclcpp::Waitable::take_data
rclcpp::Waitable::set_on_ready_callback

Reimplemented from rclcpp::Waitable.

Definition at line 81 of file subscription_intra_process_base.hpp.

References take_data().

Here is the call graph for this function:

The documentation for this class was generated from the following files: