ROS 2 rclcpp + rcl - humble  humble
ROS 2 C++ Client Library with ROS Client Library
Public Member Functions | List of all members
rclcpp::Waitable Class Referenceabstract
Inheritance diagram for rclcpp::Waitable:
Inheritance graph
[legend]

Public Member Functions

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 size_t get_number_of_ready_guard_conditions ()
 Get the number of ready guard_conditions. More...
 
virtual RCLCPP_PUBLIC void add_to_wait_set (rcl_wait_set_t *wait_set)=0
 Add the Waitable to a wait set. More...
 
virtual RCLCPP_PUBLIC bool is_ready (rcl_wait_set_t *wait_set)=0
 Check if the Waitable is ready. More...
 
virtual RCLCPP_PUBLIC std::shared_ptr< void > take_data ()=0
 Take the data so that it can be consumed with execute. More...
 
virtual RCLCPP_PUBLIC std::shared_ptr< void > take_data_by_entity_id (size_t id)
 Take the data so that it can be consumed with execute. More...
 
virtual RCLCPP_PUBLIC void execute (std::shared_ptr< void > &data)=0
 Execute data that is passed in. 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...
 
virtual RCLCPP_PUBLIC void set_on_ready_callback (std::function< void(size_t, int)> callback)
 Set a callback to be called whenever the waitable becomes ready. More...
 
virtual RCLCPP_PUBLIC void clear_on_ready_callback ()
 Unset any callback registered via set_on_ready_callback. More...
 

Detailed Description

Definition at line 30 of file waitable.hpp.

Member Function Documentation

◆ add_to_wait_set()

virtual RCLCPP_PUBLIC void rclcpp::Waitable::add_to_wait_set ( rcl_wait_set_t wait_set)
pure virtual

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_*()

Implemented in rclcpp::QOSEventHandlerBase, rclcpp::experimental::SubscriptionIntraProcessBase, and rclcpp::executors::StaticExecutorEntitiesCollector.

Referenced by rclcpp::wait_set_policies::detail::StoragePolicyCommon< HasStrongOwnership >::storage_rebuild_rcl_wait_set_with_sets().

Here is the caller graph for this function:

◆ clear_on_ready_callback()

void Waitable::clear_on_ready_callback ( )
virtual

Unset any callback registered via set_on_ready_callback.

Note: this function must be overridden with a proper implementation by the custom classes who inherit from rclcpp::Waitable if they want to use it.

Reimplemented in rclcpp::QOSEventHandlerBase, and rclcpp::experimental::SubscriptionIntraProcessBase.

Definition at line 83 of file waitable.cpp.

◆ exchange_in_use_by_wait_set_state()

bool Waitable::exchange_in_use_by_wait_set_state ( bool  in_use_state)

Exchange the "in use by wait set" state for this timer.

This is used to ensure this timer is not used by multiple wait sets at the same time.

Parameters
[in]in_use_statethe new state to exchange into the state, true indicates it is now in use by a wait set, and false is that it is no longer in use by a wait set.
Returns
the previous state.

Definition at line 67 of file waitable.cpp.

◆ execute()

virtual RCLCPP_PUBLIC void rclcpp::Waitable::execute ( std::shared_ptr< void > &  data)
pure 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:23
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

Implemented in rclcpp::experimental::SubscriptionIntraProcessBase, rclcpp::QOSEventHandler< EventCallbackT, ParentHandleT >, rclcpp::experimental::SubscriptionIntraProcess< MessageT, SubscribedType, SubscribedTypeAlloc, SubscribedTypeDeleter, ROSMessageType, Alloc >, and rclcpp::executors::StaticExecutorEntitiesCollector.

◆ get_number_of_ready_clients()

size_t Waitable::get_number_of_ready_clients ( )
virtual

Get the number of ready clients.

Returns a value of 0 by default. This should be overridden if the Waitable contains one or more clients.

Returns
The number of clients associated with the Waitable.

Definition at line 34 of file waitable.cpp.

Referenced by rclcpp::wait_set_policies::detail::StoragePolicyCommon< HasStrongOwnership >::storage_rebuild_rcl_wait_set_with_sets().

Here is the caller graph for this function:

◆ get_number_of_ready_events()

size_t Waitable::get_number_of_ready_events ( )
virtual

Get the number of ready events.

Returns a value of 0 by default. This should be overridden if the Waitable contains one or more events.

Returns
The number of events associated with the Waitable.

Reimplemented in rclcpp::QOSEventHandlerBase.

Definition at line 40 of file waitable.cpp.

Referenced by rclcpp::wait_set_policies::detail::StoragePolicyCommon< HasStrongOwnership >::storage_rebuild_rcl_wait_set_with_sets().

Here is the caller graph for this function:

◆ get_number_of_ready_guard_conditions()

size_t Waitable::get_number_of_ready_guard_conditions ( )
virtual

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 in rclcpp::experimental::SubscriptionIntraProcessBase, and rclcpp::executors::StaticExecutorEntitiesCollector.

Definition at line 52 of file waitable.cpp.

Referenced by rclcpp::wait_set_policies::detail::StoragePolicyCommon< HasStrongOwnership >::storage_rebuild_rcl_wait_set_with_sets().

Here is the caller graph for this function:

◆ get_number_of_ready_services()

size_t Waitable::get_number_of_ready_services ( )
virtual

Get the number of ready services.

Returns a value of 0 by default. This should be overridden if the Waitable contains one or more services.

Returns
The number of services associated with the Waitable.

Definition at line 46 of file waitable.cpp.

Referenced by rclcpp::wait_set_policies::detail::StoragePolicyCommon< HasStrongOwnership >::storage_rebuild_rcl_wait_set_with_sets().

Here is the caller graph for this function:

◆ get_number_of_ready_subscriptions()

size_t Waitable::get_number_of_ready_subscriptions ( )
virtual

Get the number of ready subscriptions.

Returns a value of 0 by default. This should be overridden if the Waitable contains one or more subscriptions.

Returns
The number of subscriptions associated with the Waitable.

Definition at line 22 of file waitable.cpp.

Referenced by rclcpp::wait_set_policies::detail::StoragePolicyCommon< HasStrongOwnership >::storage_rebuild_rcl_wait_set_with_sets().

Here is the caller graph for this function:

◆ get_number_of_ready_timers()

size_t Waitable::get_number_of_ready_timers ( )
virtual

Get the number of ready timers.

Returns a value of 0 by default. This should be overridden if the Waitable contains one or more timers.

Returns
The number of timers associated with the Waitable.

Definition at line 28 of file waitable.cpp.

Referenced by rclcpp::wait_set_policies::detail::StoragePolicyCommon< HasStrongOwnership >::storage_rebuild_rcl_wait_set_with_sets().

Here is the caller graph for this function:

◆ is_ready()

virtual RCLCPP_PUBLIC bool rclcpp::Waitable::is_ready ( rcl_wait_set_t wait_set)
pure 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.

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

◆ set_on_ready_callback()

void Waitable::set_on_ready_callback ( std::function< void(size_t, int)>  callback)
virtual

Set a callback to be called whenever the waitable becomes ready.

The callback receives a size_t which is the number of times the waitable was ready since the last time this callback was called. Normally this is 1, but can be > 1 if waitable was triggered 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 bond 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.

Note: this function must be overridden with a proper implementation by the custom classes who inherit from rclcpp::Waitable if they want to use it.

See also
rclcpp::Waitable::clear_on_ready_callback
Parameters
[in]callbackfunctor to be called when the waitable becomes ready

Reimplemented in rclcpp::QOSEventHandlerBase, and rclcpp::experimental::SubscriptionIntraProcessBase.

Definition at line 73 of file waitable.cpp.

◆ take_data()

virtual RCLCPP_PUBLIC std::shared_ptr<void> rclcpp::Waitable::take_data ( )
pure 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();

Implemented in rclcpp::experimental::SubscriptionIntraProcessBase, rclcpp::QOSEventHandler< EventCallbackT, ParentHandleT >, rclcpp::experimental::SubscriptionIntraProcess< MessageT, SubscribedType, SubscribedTypeAlloc, SubscribedTypeDeleter, ROSMessageType, Alloc >, and rclcpp::executors::StaticExecutorEntitiesCollector.

◆ take_data_by_entity_id()

std::shared_ptr< void > Waitable::take_data_by_entity_id ( size_t  id)
virtual

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 in rclcpp::QOSEventHandler< EventCallbackT, ParentHandleT >, and rclcpp::experimental::SubscriptionIntraProcessBase.

Definition at line 58 of file waitable.cpp.


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