ROS 2 rclcpp + rcl - kilted  kilted
ROS 2 C++ Client Library with ROS Client Library
Classes | Typedefs | Enumerations | Functions
event.h File Reference
#include <rmw/event.h>
#include "rcl/client.h"
#include "rcl/event_callback.h"
#include "rcl/macros.h"
#include "rcl/publisher.h"
#include "rcl/service.h"
#include "rcl/subscription.h"
#include "rcl/visibility_control.h"
Include dependency graph for event.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  rcl_event_s
 Structure which encapsulates a ROS QoS event handle. More...
 

Typedefs

typedef enum rcl_publisher_event_type_e rcl_publisher_event_type_t
 Enumeration of all of the publisher events that may fire.
 
typedef enum rcl_subscription_event_type_e rcl_subscription_event_type_t
 Enumeration of all of the subscription events that may fire.
 
typedef struct rcl_event_impl_s rcl_event_impl_t
 Internal rcl implementation struct.
 
typedef struct rcl_event_s rcl_event_t
 Structure which encapsulates a ROS QoS event handle.
 

Enumerations

enum  rcl_publisher_event_type_e {
  RCL_PUBLISHER_OFFERED_DEADLINE_MISSED , RCL_PUBLISHER_LIVELINESS_LOST , RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS , RCL_PUBLISHER_INCOMPATIBLE_TYPE ,
  RCL_PUBLISHER_MATCHED
}
 Enumeration of all of the publisher events that may fire.
 
enum  rcl_subscription_event_type_e {
  RCL_SUBSCRIPTION_REQUESTED_DEADLINE_MISSED , RCL_SUBSCRIPTION_LIVELINESS_CHANGED , RCL_SUBSCRIPTION_REQUESTED_INCOMPATIBLE_QOS , RCL_SUBSCRIPTION_MESSAGE_LOST ,
  RCL_SUBSCRIPTION_INCOMPATIBLE_TYPE , RCL_SUBSCRIPTION_MATCHED
}
 Enumeration of all of the subscription events that may fire.
 

Functions

RCL_PUBLIC RCL_WARN_UNUSED rcl_event_t rcl_get_zero_initialized_event (void)
 Return a rcl_event_t struct with members set to NULL. More...
 
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_publisher_event_init (rcl_event_t *event, const rcl_publisher_t *publisher, const rcl_publisher_event_type_t event_type)
 Initialize an rcl_event_t with a publisher. More...
 
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_subscription_event_init (rcl_event_t *event, const rcl_subscription_t *subscription, const rcl_subscription_event_type_t event_type)
 Initialize an rcl_event_t with a subscription. More...
 
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_take_event (const rcl_event_t *event, void *event_info)
 
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_event_fini (rcl_event_t *event)
 
RCL_PUBLIC RCL_WARN_UNUSED rmw_event_t * rcl_event_get_rmw_handle (const rcl_event_t *event)
 Return the rmw event handle. More...
 
RCL_PUBLIC bool rcl_event_is_valid (const rcl_event_t *event)
 Check that the event is valid. More...
 
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_event_set_callback (const rcl_event_t *event, rcl_event_callback_t callback, const void *user_data)
 Set the callback function for the event. More...
 

Function Documentation

◆ rcl_event_fini()

RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_event_fini ( rcl_event_t event)

Finalize an event.

Parameters
[in]eventto finalize
Returns
RCL_RET_OK if successful, or
RCL_RET_EVENT_INVALID if event is null, or
RCL_RET_ERROR if an unexpected error occurs.

Definition at line 189 of file event.c.

References rcl_event_s::impl, RCL_RET_EVENT_INVALID, and RCL_RET_OK.

◆ rcl_event_get_rmw_handle()

RCL_PUBLIC RCL_WARN_UNUSED rmw_event_t* rcl_event_get_rmw_handle ( const rcl_event_t event)

Return the rmw event handle.

The handle returned is a pointer to the internally held rmw handle. This function can fail, and therefore return NULL, if the:

  • event is NULL
  • event is invalid (never called init, called fini, or invalid node)

The returned handle is made invalid if the event is finalized or if rcl_shutdown() is called. The returned handle is not guaranteed to be valid for the life time of the event as it may be finalized and recreated itself. Therefore it is recommended to get the handle from the event using this function each time it is needed and avoid use of the handle concurrently with functions that might change it.


Attribute Adherence
Allocates Memory Yes
Thread-Safe No
Uses Atomics No
Lock-Free Yes
Parameters
[in]eventpointer to the rcl event
Returns
rmw event handle if successful, otherwise NULL

Definition at line 211 of file event.c.

References rcl_event_is_valid().

Here is the call graph for this function:

◆ rcl_event_is_valid()

RCL_PUBLIC bool rcl_event_is_valid ( const rcl_event_t event)

Check that the event is valid.

The bool returned is false if event is invalid. The bool returned is true otherwise. In the case where false is to be returned, an error message is set. This function cannot fail.


Attribute Adherence
Allocates Memory No
Thread-Safe No
Uses Atomics No
Lock-Free Yes
Parameters
[in]eventpointer to the rcl event
Returns
true if event is valid, otherwise false

Definition at line 221 of file event.c.

References rcl_event_s::impl.

Referenced by rcl_event_get_rmw_handle(), rcl_event_set_callback(), and rcl_take_event().

Here is the caller graph for this function:

◆ rcl_event_set_callback()

RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_event_set_callback ( const rcl_event_t event,
rcl_event_callback_t  callback,
const void *  user_data 
)

Set the callback function for the event.

This API sets the callback function to be called whenever the event is notified about a new instance of the event.

See also
rmw_event_set_callback for more details about this function.

Attribute Adherence
Allocates Memory No
Thread-Safe Yes
Uses Atomics Maybe [1]
Lock-Free Maybe [1]

[1] rmw implementation defined

Parameters
[in]eventThe event on which to set the callback
[in]callbackThe callback to be called when new events occur, may be NULL
[in]user_dataGiven to the callback when called later, may be NULL
Returns
RCL_RET_OK if callback was set to the listener, or
RCL_RET_INVALID_ARGUMENT if event is NULL, or
RCL_RET_UNSUPPORTED if the API is not implemented in the dds implementation

Definition at line 235 of file event.c.

References rcl_event_s::impl, rcl_event_is_valid(), and RCL_RET_INVALID_ARGUMENT.

Here is the call graph for this function:

◆ rcl_get_zero_initialized_event()

RCL_PUBLIC RCL_WARN_UNUSED rcl_event_t rcl_get_zero_initialized_event ( void  )

Return a rcl_event_t struct with members set to NULL.

Should be called to get a null rcl_event_t before passing to rcl_event_init().

Returns
Zero initialized rcl_event_t.

Definition at line 39 of file event.c.

◆ rcl_publisher_event_init()

RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_publisher_event_init ( rcl_event_t event,
const rcl_publisher_t publisher,
const rcl_publisher_event_type_t  event_type 
)

Initialize an rcl_event_t with a publisher.

Fill the rcl_event_t with the publisher and desired event_type.

Parameters
[in,out]eventpointer to fill
[in]publisherto get events from
[in]event_typeto listen for
Returns
RCL_RET_OK if the rcl_event_t is filled, or
RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
RCL_RET_BAD_ALLOC if allocating memory fails, or
RCL_RET_UNSUPPORTED if event_type is not supported, or
RCL_RET_ERROR if an unspecified error occurs.

Definition at line 47 of file event.c.

References rcl_publisher_options_s::allocator, rcl_publisher_s::impl, RCL_CHECK_ALLOCATOR_WITH_MSG, RCL_RET_EVENT_INVALID, and RCL_RET_INVALID_ARGUMENT.

◆ rcl_subscription_event_init()

RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_subscription_event_init ( rcl_event_t event,
const rcl_subscription_t subscription,
const rcl_subscription_event_type_t  event_type 
)

Initialize an rcl_event_t with a subscription.

Fill the rcl_event_t with the subscription and desired event_type.

Parameters
[in,out]eventpointer to fill
[in]subscriptionto get events from
[in]event_typeto listen for
Returns
RCL_RET_OK if the rcl_event_t is filled, or
RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
RCL_RET_BAD_ALLOC if allocating memory fails, or
RCL_RET_UNSUPPORTED if event_type is not supported, or
RCL_RET_ERROR if an unspecified error occurs.

Definition at line 104 of file event.c.

References rcl_subscription_options_s::allocator, rcl_subscription_s::impl, RCL_CHECK_ALLOCATOR_WITH_MSG, RCL_RET_EVENT_INVALID, and RCL_RET_INVALID_ARGUMENT.

◆ rcl_take_event()

RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_take_event ( const rcl_event_t event,
void *  event_info 
)

Take an event from the event handle.

Parameters
[in]eventevent object to take from
[in,out]event_infoevent info object to write taken data into
Returns
RCL_RET_OK if successful, or
RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
RCL_RET_BAD_ALLOC if memory allocation failed, or
RCL_RET_EVENT_TAKE_FAILED if the take event failed, or
RCL_RET_ERROR if an unexpected error occurs.

Definition at line 164 of file event.c.

References rcl_event_s::impl, rcl_event_is_valid(), RCL_RET_EVENT_INVALID, RCL_RET_EVENT_TAKE_FAILED, and RCL_RET_INVALID_ARGUMENT.

Referenced by rclcpp::EventHandler< EventCallbackT, ParentHandleT >::take_data().

Here is the call graph for this function:
Here is the caller graph for this function: