rclcpp  master
C++ ROS Client Library API
Public Member Functions | List of all members
rclcpp::Waitable Class Referenceabstract

#include <waitable.hpp>

Inheritance diagram for rclcpp::Waitable:
Inheritance graph
[legend]

Public Member Functions

virtual ~Waitable ()=default
 
virtual size_t get_number_of_ready_subscriptions ()
 Get the number of ready subscriptions. More...
 
virtual size_t get_number_of_ready_timers ()
 Get the number of ready timers. More...
 
virtual size_t get_number_of_ready_clients ()
 Get the number of ready clients. More...
 
virtual size_t get_number_of_ready_events ()
 Get the number of ready events. More...
 
virtual size_t get_number_of_ready_services ()
 Get the number of ready services. More...
 
virtual size_t get_number_of_ready_guard_conditions ()
 Get the number of ready guard_conditions. More...
 
virtual bool add_to_wait_set (rcl_wait_set_t *wait_set)=0
 Add the Waitable to a wait set. More...
 
virtual bool is_ready (rcl_wait_set_t *wait_set)=0
 Check if the Waitable is ready. More...
 
virtual std::shared_ptr< void > take_data ()=0
 Take the data so that it can be consumed with execute. More...
 
virtual void execute (std::shared_ptr< void > &data)=0
 Execute data that is passed in. More...
 
bool exchange_in_use_by_wait_set_state (bool in_use_state)
 Exchange the "in use by wait set" state for this timer. More...
 

Constructor & Destructor Documentation

◆ ~Waitable()

virtual rclcpp::Waitable::~Waitable ( )
virtualdefault

Member Function Documentation

◆ get_number_of_ready_subscriptions()

virtual size_t rclcpp::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.

◆ get_number_of_ready_timers()

virtual size_t rclcpp::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.

◆ get_number_of_ready_clients()

virtual size_t rclcpp::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.

◆ get_number_of_ready_events()

virtual size_t rclcpp::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.

◆ get_number_of_ready_services()

virtual size_t rclcpp::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.

◆ get_number_of_ready_guard_conditions()

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

◆ add_to_wait_set()

virtual bool 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.
Returns
true if the Waitable is added successfully, false otherwise.
Exceptions
rclcpp::execptions::RCLErrorfrom rcl_wait_set_add_*()

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

◆ is_ready()

virtual 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::executors::StaticExecutorEntitiesCollector, rclcpp::QOSEventHandlerBase, and rclcpp::experimental::SubscriptionIntraProcess< MessageT, Alloc, Deleter, CallbackMessageT >.

◆ take_data()

virtual 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
bool add_ret = waitable.add_to_wait_set(wait_set);
// ... error handling
// 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::executors::StaticExecutorEntitiesCollector, and rclcpp::experimental::SubscriptionIntraProcess< MessageT, Alloc, Deleter, CallbackMessageT >.

◆ execute()

virtual 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
bool add_ret = waitable.add_to_wait_set(wait_set);
// ... error handling
// 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);

Implemented in rclcpp::experimental::SubscriptionIntraProcessBase, rclcpp::QOSEventHandler< EventCallbackT, ParentHandleT >, rclcpp::executors::StaticExecutorEntitiesCollector, and rclcpp::experimental::SubscriptionIntraProcess< MessageT, Alloc, Deleter, CallbackMessageT >.

◆ exchange_in_use_by_wait_set_state()

bool rclcpp::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.

The documentation for this class was generated from the following file:
std::shared_ptr< void >
rcl_ret_t
rmw_ret_t rcl_ret_t
rcl_wait
rcl_ret_t rcl_wait(rcl_wait_set_t *wait_set, int64_t timeout)