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"
57 rmw_event_type_t rmw_event_type = RMW_EVENT_INVALID;
59 case RCL_PUBLISHER_OFFERED_DEADLINE_MISSED:
60 rmw_event_type = RMW_EVENT_OFFERED_DEADLINE_MISSED;
62 case RCL_PUBLISHER_LIVELINESS_LOST:
63 rmw_event_type = RMW_EVENT_LIVELINESS_LOST;
65 case RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS:
66 rmw_event_type = RMW_EVENT_OFFERED_QOS_INCOMPATIBLE;
68 case RCL_PUBLISHER_INCOMPATIBLE_TYPE:
69 rmw_event_type = RMW_EVENT_PUBLISHER_INCOMPATIBLE_TYPE;
71 case RCL_PUBLISHER_MATCHED:
72 rmw_event_type = RMW_EVENT_PUBLICATION_MATCHED;
75 RCL_SET_ERROR_MSG(
"Event type for publisher not supported");
82 RCL_CHECK_FOR_NULL_WITH_MSG(
85 event->impl->rmw_handle = rmw_get_zero_initialized_event();
86 event->impl->allocator = *allocator;
88 rmw_ret_t ret = rmw_publisher_event_init(
89 &event->
impl->rmw_handle,
90 publisher->
impl->rmw_handle,
92 if (ret != RMW_RET_OK) {
98 allocator->deallocate(event->
impl, allocator->state);
100 return rcl_convert_rmw_ret_to_rcl_ret(ret);
114 rmw_event_type_t rmw_event_type = RMW_EVENT_INVALID;
115 switch (event_type) {
116 case RCL_SUBSCRIPTION_REQUESTED_DEADLINE_MISSED:
117 rmw_event_type = RMW_EVENT_REQUESTED_DEADLINE_MISSED;
119 case RCL_SUBSCRIPTION_LIVELINESS_CHANGED:
120 rmw_event_type = RMW_EVENT_LIVELINESS_CHANGED;
122 case RCL_SUBSCRIPTION_REQUESTED_INCOMPATIBLE_QOS:
123 rmw_event_type = RMW_EVENT_REQUESTED_QOS_INCOMPATIBLE;
125 case RCL_SUBSCRIPTION_MESSAGE_LOST:
126 rmw_event_type = RMW_EVENT_MESSAGE_LOST;
128 case RCL_SUBSCRIPTION_INCOMPATIBLE_TYPE:
129 rmw_event_type = RMW_EVENT_SUBSCRIPTION_INCOMPATIBLE_TYPE;
131 case RCL_SUBSCRIPTION_MATCHED:
132 rmw_event_type = RMW_EVENT_SUBSCRIPTION_MATCHED;
135 RCL_SET_ERROR_MSG(
"Event type for subscription not supported");
142 RCL_CHECK_FOR_NULL_WITH_MSG(
145 event->impl->rmw_handle = rmw_get_zero_initialized_event();
146 event->impl->allocator = *allocator;
148 rmw_ret_t ret = rmw_subscription_event_init(
149 &event->
impl->rmw_handle,
150 subscription->
impl->rmw_handle,
152 if (ret != RMW_RET_OK) {
158 allocator->deallocate(event->
impl, allocator->state);
160 return rcl_convert_rmw_ret_to_rcl_ret(ret);
173 rmw_ret_t ret = rmw_take_event(&event->
impl->rmw_handle, event_info, &taken);
174 if (RMW_RET_OK != ret) {
175 RCL_SET_ERROR_MSG(rmw_get_error_string().str);
176 return rcl_convert_rmw_ret_to_rcl_ret(ret);
179 RCUTILS_LOG_DEBUG_NAMED(
180 ROS_PACKAGE_NAME,
"take_event request complete, unable to take event");
183 RCUTILS_LOG_DEBUG_NAMED(
184 ROS_PACKAGE_NAME,
"take_event request success");
185 return rcl_convert_rmw_ret_to_rcl_ret(ret);
194 RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME,
"Finalizing event");
195 if (NULL != event->
impl) {
197 rmw_ret_t ret = rmw_event_fini(&event->
impl->rmw_handle);
198 if (ret != RMW_RET_OK) {
199 RCL_SET_ERROR_MSG(rmw_get_error_string().str);
200 result = rcl_convert_rmw_ret_to_rcl_ret(ret);
202 allocator.deallocate(event->
impl, allocator.state);
205 RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME,
"Event finalized");
216 return &
event->impl->rmw_handle;
223 RCL_CHECK_FOR_NULL_WITH_MSG(event,
"event pointer is invalid",
return false);
224 RCL_CHECK_FOR_NULL_WITH_MSG(event->
impl,
"event's implementation is invalid",
return false);
225 if (event->
impl->rmw_handle.event_type == RMW_EVENT_INVALID) {
226 RCUTILS_SET_ERROR_MSG(
"event's implementation not init");
229 RCUTILS_CHECK_ALLOCATOR_WITH_MSG(
230 &event->
impl->allocator,
"not valid allocator",
return false);
237 rcl_event_callback_t callback,
238 const void * user_data)
245 return rmw_event_set_callback(
246 &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.