Class QOSEventHandlerBase
Defined in File qos_event.hpp
Inheritance Relationships
Base Type
public rclcpp::Waitable
(Class Waitable)
Derived Type
public rclcpp::QOSEventHandler< EventCallbackT, ParentHandleT >
(Template Class QOSEventHandler)
Class Documentation
-
class QOSEventHandlerBase : public rclcpp::Waitable
Subclassed by rclcpp::QOSEventHandler< EventCallbackT, ParentHandleT >
Public Functions
-
virtual ~QOSEventHandlerBase()
-
virtual size_t get_number_of_ready_events() override
Get the number of ready events.
-
inline virtual 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.
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.
See also
rmw_event_set_callback
See also
rcl_event_set_callback
- Parameters:
callback – [in] functor to be called when a new event occurs
-
inline virtual void clear_on_ready_callback() override
Unset the callback registered for new events, if any.
Protected Functions
-
void set_on_new_event_callback(rcl_event_callback_t callback, const void *user_data)
-
virtual ~QOSEventHandlerBase()