ROS 2 rclcpp + rcl - kilted
kilted
ROS 2 C++ Client Library with ROS Client Library
|
Public Types | |
enum class | EntityType : std::size_t { Event } |
Public Member Functions | |
RCLCPP_PUBLIC size_t | get_number_of_ready_events () override |
Get the number of ready events. | |
RCLCPP_PUBLIC void | add_to_wait_set (rcl_wait_set_t &wait_set) override |
Add the Waitable to a wait set. | |
RCLCPP_PUBLIC bool | is_ready (const rcl_wait_set_t &wait_set) override |
Check if the Waitable is ready. | |
void | set_on_ready_callback (std::function< void(size_t, int)> callback) override |
Set a callback to be called when each new event instance occurs. More... | |
void | clear_on_ready_callback () override |
Unset the callback registered for new events, if any. | |
RCLCPP_PUBLIC std::vector< std::shared_ptr< rclcpp::TimerBase > > | get_timers () const override |
Returns all timers used by this waitable. More... | |
![]() | |
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_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 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)=0 |
Take the data so that it can be consumed with execute . More... | |
virtual RCLCPP_PUBLIC void | execute (const 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... | |
Protected Member Functions | |
RCLCPP_PUBLIC void | set_on_new_event_callback (rcl_event_callback_t callback, const void *user_data) |
Protected Attributes | |
std::recursive_mutex | callback_mutex_ |
std::function< void(size_t)> | on_new_event_callback_ {nullptr} |
rcl_event_t | event_handle_ |
size_t | wait_set_event_index_ |
Definition at line 102 of file event_handler.hpp.
|
inlineoverridevirtual |
Returns all timers used by this waitable.
Must return all timers used within the waitable. Note, it is not supported, that timers are added or removed over the lifetime of the waitable.
Implements rclcpp::Waitable.
Definition at line 227 of file event_handler.hpp.
|
inlineoverridevirtual |
Set a callback to be called when each new event instance occurs.
The callback receives a size_t which is the number of events that occurred since the last time this callback was called. Normally this is 1, but can be > 1 if events occurred 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.
Since this callback is called from the middleware, you should aim to make it fast and not blocking. If you need to do a lot of work or wait for some other event, you should spin it off to another thread, otherwise you risk blocking the middleware.
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 qos event or other information, you may use a lambda with captures or std::bind.
[in] | callback | functor to be called when a new event occurs |
Implements rclcpp::Waitable.
Definition at line 165 of file event_handler.hpp.
References rclcpp::get_logger().