Class Waitable

Inheritance Relationships

Derived Types

Class Documentation

class Waitable

Subclassed by rclcpp::EventHandlerBase, rclcpp::executors::ExecutorNotifyWaitable, rclcpp::experimental::SubscriptionIntraProcessBase

Public Functions

virtual ~Waitable() = default
virtual size_t get_number_of_ready_subscriptions()

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.

virtual size_t get_number_of_ready_timers()

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.

virtual size_t get_number_of_ready_clients()

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.

virtual size_t get_number_of_ready_events()

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.

virtual size_t get_number_of_ready_services()

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.

virtual size_t get_number_of_ready_guard_conditions()

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)

Deprecated.

virtual void add_to_wait_set(rcl_wait_set_t &wait_set)

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 bool is_ready(rcl_wait_set_t *wait_set)

Deprecated.

virtual bool is_ready(const rcl_wait_set_t &wait_set)

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:

wait_set[in] A 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.

virtual std::shared_ptr<void> take_data() = 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. 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();
virtual std::shared_ptr<void> take_data_by_entity_id(size_t id)

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:

id[in] the id of the entity from which to take

Returns:

the type-erased data taken from entity specified

virtual void execute(std::shared_ptr<void> &data)

Deprecated.

virtual void execute(const std::shared_ptr<void> &data)

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);
bool 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_use_state[in] the 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.

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

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.

Parameters:

callback[in] functor to be called when the waitable becomes ready

virtual void clear_on_ready_callback()

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.