26 #include "rcl/error_handling.h"
28 #include "rcutils/allocator.h"
29 #include "rcutils/error_handling.h"
30 #include "rcutils/logging_macros.h"
31 #include "rmw/error_handling.h"
32 #include "rmw/event.h"
33 #include "rmw/ret_types.h"
37 #include "./event_impl.h"
38 #include "./publisher_impl.h"
39 #include "./subscription_impl.h"
60 rmw_event_type_t rmw_event_type = RMW_EVENT_INVALID;
62 case RCL_PUBLISHER_OFFERED_DEADLINE_MISSED:
63 rmw_event_type = RMW_EVENT_OFFERED_DEADLINE_MISSED;
65 case RCL_PUBLISHER_LIVELINESS_LOST:
66 rmw_event_type = RMW_EVENT_LIVELINESS_LOST;
68 case RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS:
69 rmw_event_type = RMW_EVENT_OFFERED_QOS_INCOMPATIBLE;
71 case RCL_PUBLISHER_INCOMPATIBLE_TYPE:
72 rmw_event_type = RMW_EVENT_PUBLISHER_INCOMPATIBLE_TYPE;
74 case RCL_PUBLISHER_MATCHED:
75 rmw_event_type = RMW_EVENT_PUBLICATION_MATCHED;
78 if (rmw_event_type == RMW_EVENT_INVALID) {
79 RCL_SET_ERROR_MSG(
"Event type for publisher not supported");
86 RCL_CHECK_FOR_NULL_WITH_MSG(
89 event->impl->rmw_handle = rmw_get_zero_initialized_event();
90 event->impl->allocator = *allocator;
92 rmw_ret_t ret = rmw_publisher_event_init(
93 &event->
impl->rmw_handle,
94 publisher->
impl->rmw_handle,
96 if (ret != RMW_RET_OK) {
102 allocator->deallocate(event->
impl, allocator->state);
104 return rcl_convert_rmw_ret_to_rcl_ret(ret);
118 rmw_event_type_t rmw_event_type = RMW_EVENT_INVALID;
119 switch (event_type) {
120 case RCL_SUBSCRIPTION_REQUESTED_DEADLINE_MISSED:
121 rmw_event_type = RMW_EVENT_REQUESTED_DEADLINE_MISSED;
123 case RCL_SUBSCRIPTION_LIVELINESS_CHANGED:
124 rmw_event_type = RMW_EVENT_LIVELINESS_CHANGED;
126 case RCL_SUBSCRIPTION_REQUESTED_INCOMPATIBLE_QOS:
127 rmw_event_type = RMW_EVENT_REQUESTED_QOS_INCOMPATIBLE;
129 case RCL_SUBSCRIPTION_MESSAGE_LOST:
130 rmw_event_type = RMW_EVENT_MESSAGE_LOST;
132 case RCL_SUBSCRIPTION_INCOMPATIBLE_TYPE:
133 rmw_event_type = RMW_EVENT_SUBSCRIPTION_INCOMPATIBLE_TYPE;
135 case RCL_SUBSCRIPTION_MATCHED:
136 rmw_event_type = RMW_EVENT_SUBSCRIPTION_MATCHED;
139 if (rmw_event_type == RMW_EVENT_INVALID) {
140 RCL_SET_ERROR_MSG(
"Event type for subscription not supported");
147 RCL_CHECK_FOR_NULL_WITH_MSG(
150 event->impl->rmw_handle = rmw_get_zero_initialized_event();
151 event->impl->allocator = *allocator;
153 rmw_ret_t ret = rmw_subscription_event_init(
154 &event->
impl->rmw_handle,
155 subscription->
impl->rmw_handle,
157 if (ret != RMW_RET_OK) {
163 allocator->deallocate(event->
impl, allocator->state);
165 return rcl_convert_rmw_ret_to_rcl_ret(ret);
178 rmw_ret_t ret = rmw_take_event(&event->
impl->rmw_handle, event_info, &taken);
179 if (RMW_RET_OK != ret) {
180 RCL_SET_ERROR_MSG(rmw_get_error_string().str);
181 return rcl_convert_rmw_ret_to_rcl_ret(ret);
184 RCUTILS_LOG_DEBUG_NAMED(
185 ROS_PACKAGE_NAME,
"take_event request complete, unable to take event");
188 RCUTILS_LOG_DEBUG_NAMED(
189 ROS_PACKAGE_NAME,
"take_event request success");
190 return rcl_convert_rmw_ret_to_rcl_ret(ret);
199 RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME,
"Finalizing event");
200 if (NULL != event->
impl) {
202 rmw_ret_t ret = rmw_event_fini(&event->
impl->rmw_handle);
203 if (ret != RMW_RET_OK) {
204 RCL_SET_ERROR_MSG(rmw_get_error_string().str);
205 result = rcl_convert_rmw_ret_to_rcl_ret(ret);
207 allocator.deallocate(event->
impl, allocator.state);
210 RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME,
"Event finalized");
221 return &
event->impl->rmw_handle;
228 RCL_CHECK_FOR_NULL_WITH_MSG(event,
"event pointer is invalid",
return false);
229 RCL_CHECK_FOR_NULL_WITH_MSG(event->
impl,
"event's implementation is invalid",
return false);
230 if (event->
impl->rmw_handle.event_type == RMW_EVENT_INVALID) {
231 RCUTILS_SET_ERROR_MSG(
"event's implementation not init");
234 RCUTILS_CHECK_ALLOCATOR_WITH_MSG(
235 &event->
impl->allocator,
"not valid allocator",
return false);
243 rmw_event_type_t rmw_event_type = RMW_EVENT_INVALID;
244 switch (event_type) {
245 case RCL_PUBLISHER_OFFERED_DEADLINE_MISSED:
246 rmw_event_type = RMW_EVENT_OFFERED_DEADLINE_MISSED;
248 case RCL_PUBLISHER_LIVELINESS_LOST:
249 rmw_event_type = RMW_EVENT_LIVELINESS_LOST;
251 case RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS:
252 rmw_event_type = RMW_EVENT_OFFERED_QOS_INCOMPATIBLE;
254 case RCL_PUBLISHER_INCOMPATIBLE_TYPE:
255 rmw_event_type = RMW_EVENT_PUBLISHER_INCOMPATIBLE_TYPE;
257 case RCL_PUBLISHER_MATCHED:
258 rmw_event_type = RMW_EVENT_PUBLICATION_MATCHED;
261 if (rmw_event_type == RMW_EVENT_INVALID) {
264 return rmw_event_type_is_supported(rmw_event_type);
271 rmw_event_type_t rmw_event_type = RMW_EVENT_INVALID;
272 switch (event_type) {
273 case RCL_SUBSCRIPTION_REQUESTED_DEADLINE_MISSED:
274 rmw_event_type = RMW_EVENT_REQUESTED_DEADLINE_MISSED;
276 case RCL_SUBSCRIPTION_LIVELINESS_CHANGED:
277 rmw_event_type = RMW_EVENT_LIVELINESS_CHANGED;
279 case RCL_SUBSCRIPTION_REQUESTED_INCOMPATIBLE_QOS:
280 rmw_event_type = RMW_EVENT_REQUESTED_QOS_INCOMPATIBLE;
282 case RCL_SUBSCRIPTION_MESSAGE_LOST:
283 rmw_event_type = RMW_EVENT_MESSAGE_LOST;
285 case RCL_SUBSCRIPTION_INCOMPATIBLE_TYPE:
286 rmw_event_type = RMW_EVENT_SUBSCRIPTION_INCOMPATIBLE_TYPE;
288 case RCL_SUBSCRIPTION_MATCHED:
289 rmw_event_type = RMW_EVENT_SUBSCRIPTION_MATCHED;
292 if (rmw_event_type == RMW_EVENT_INVALID) {
295 return rmw_event_type_is_supported(rmw_event_type);
301 rcl_event_callback_t callback,
302 const void * user_data)
309 return rmw_event_set_callback(
310 &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 bool rcl_subscription_event_type_is_supported(const rcl_subscription_event_type_t event_type)
Check if a subscription event type is supported by the active RMW implementation.
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.
RCL_PUBLIC RCL_WARN_UNUSED bool rcl_publisher_event_type_is_supported(const rcl_publisher_event_type_t event_type)
Check if a publisher event type is supported by the active RMW implementation.
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.