24 #include "rcl/error_handling.h"
27 #include "rcutils/allocator.h"
28 #include "rcutils/logging_macros.h"
29 #include "rmw/error_handling.h"
30 #include "rmw/validate_full_topic_name.h"
31 #include "rmw/event.h"
34 #include "./event_impl.h"
35 #include "./publisher_impl.h"
36 #include "./subscription_impl.h"
56 rmw_event_type_t rmw_event_type = RMW_EVENT_INVALID;
58 case RCL_PUBLISHER_OFFERED_DEADLINE_MISSED:
59 rmw_event_type = RMW_EVENT_OFFERED_DEADLINE_MISSED;
61 case RCL_PUBLISHER_LIVELINESS_LOST:
62 rmw_event_type = RMW_EVENT_LIVELINESS_LOST;
64 case RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS:
65 rmw_event_type = RMW_EVENT_OFFERED_QOS_INCOMPATIBLE;
68 RCL_SET_ERROR_MSG(
"Event type for publisher not supported");
75 RCL_CHECK_FOR_NULL_WITH_MSG(
78 event->impl->rmw_handle = rmw_get_zero_initialized_event();
79 event->impl->allocator = *allocator;
81 rmw_ret_t ret = rmw_publisher_event_init(
82 &event->
impl->rmw_handle,
83 publisher->
impl->rmw_handle,
85 if (ret != RMW_RET_OK) {
91 allocator->deallocate(event->
impl, allocator->state);
93 return rcl_convert_rmw_ret_to_rcl_ret(ret);
107 rmw_event_type_t rmw_event_type = RMW_EVENT_INVALID;
108 switch (event_type) {
109 case RCL_SUBSCRIPTION_REQUESTED_DEADLINE_MISSED:
110 rmw_event_type = RMW_EVENT_REQUESTED_DEADLINE_MISSED;
112 case RCL_SUBSCRIPTION_LIVELINESS_CHANGED:
113 rmw_event_type = RMW_EVENT_LIVELINESS_CHANGED;
115 case RCL_SUBSCRIPTION_REQUESTED_INCOMPATIBLE_QOS:
116 rmw_event_type = RMW_EVENT_REQUESTED_QOS_INCOMPATIBLE;
118 case RCL_SUBSCRIPTION_MESSAGE_LOST:
119 rmw_event_type = RMW_EVENT_MESSAGE_LOST;
122 RCL_SET_ERROR_MSG(
"Event type for subscription not supported");
129 RCL_CHECK_FOR_NULL_WITH_MSG(
132 event->impl->rmw_handle = rmw_get_zero_initialized_event();
133 event->impl->allocator = *allocator;
135 rmw_ret_t ret = rmw_subscription_event_init(
136 &event->
impl->rmw_handle,
137 subscription->
impl->rmw_handle,
139 if (ret != RMW_RET_OK) {
145 allocator->deallocate(event->
impl, allocator->state);
147 return rcl_convert_rmw_ret_to_rcl_ret(ret);
160 rmw_ret_t ret = rmw_take_event(&event->
impl->rmw_handle, event_info, &taken);
161 if (RMW_RET_OK != ret) {
162 RCL_SET_ERROR_MSG(rmw_get_error_string().str);
163 return rcl_convert_rmw_ret_to_rcl_ret(ret);
166 RCUTILS_LOG_DEBUG_NAMED(
167 ROS_PACKAGE_NAME,
"take_event request complete, unable to take event");
170 RCUTILS_LOG_DEBUG_NAMED(
171 ROS_PACKAGE_NAME,
"take_event request success");
172 return rcl_convert_rmw_ret_to_rcl_ret(ret);
181 RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME,
"Finalizing event");
182 if (NULL != event->
impl) {
184 rmw_ret_t ret = rmw_event_fini(&event->
impl->rmw_handle);
185 if (ret != RMW_RET_OK) {
186 RCL_SET_ERROR_MSG(rmw_get_error_string().str);
187 result = rcl_convert_rmw_ret_to_rcl_ret(ret);
189 allocator.deallocate(event->
impl, allocator.state);
192 RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME,
"Event finalized");
203 return &
event->impl->rmw_handle;
210 RCL_CHECK_FOR_NULL_WITH_MSG(event,
"event pointer is invalid",
return false);
211 RCL_CHECK_FOR_NULL_WITH_MSG(event->
impl,
"event's implementation is invalid",
return false);
212 if (event->
impl->rmw_handle.event_type == RMW_EVENT_INVALID) {
213 RCUTILS_SET_ERROR_MSG(
"event's implementation not init");
216 RCUTILS_CHECK_ALLOCATOR_WITH_MSG(
217 &event->
impl->allocator,
"not valid allocator",
return false);
224 rcl_event_callback_t callback,
225 const void * user_data)
232 return rmw_event_set_callback(
233 &event->
impl->rmw_handle,
#define RCL_CHECK_ALLOCATOR_WITH_MSG(allocator, msg, fail_statement)
Check that the given allocator is initialized, or fail with a message.
rcutils_allocator_t rcl_allocator_t
Encapsulation of an allocator.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_take_event(const rcl_event_t *event, void *event_info)
enum rcl_publisher_event_type_e rcl_publisher_event_type_t
Enumeration of all of the publisher events that may fire.
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.
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.
enum rcl_subscription_event_type_e rcl_subscription_event_type_t
Enumeration of all of the subscription events that may fire.
RCL_PUBLIC RCL_WARN_UNUSED rmw_event_t * rcl_event_get_rmw_handle(const rcl_event_t *event)
Return the rmw event handle.
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.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_event_fini(rcl_event_t *event)
RCL_PUBLIC bool rcl_event_is_valid(const rcl_event_t *event)
Check that the event is valid.
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.
Structure which encapsulates a ROS QoS event handle.
rcl_event_impl_t * impl
Pointer to the event implementation.
rcl_allocator_t allocator
Custom allocator for the publisher, used for incidental allocations.
Structure which encapsulates a ROS Publisher.
rcl_publisher_impl_t * impl
Pointer to the publisher implementation.
rcl_allocator_t allocator
Custom allocator for the subscription, used for incidental allocations.
Structure which encapsulates a ROS Subscription.
rcl_subscription_impl_t * impl
Pointer to the subscription implementation.
#define RCL_RET_EVENT_TAKE_FAILED
Failed to take an event from the event handle.
#define RCL_RET_OK
Success return code.
#define RCL_RET_BAD_ALLOC
Failed to allocate memory return code.
#define RCL_RET_INVALID_ARGUMENT
Invalid argument return code.
#define RCL_RET_EVENT_INVALID
Invalid rcl_event_t given return code.
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.