22 #include "rcl/error_handling.h"
23 #include "rcutils/allocator.h"
24 #include "rcutils/logging_macros.h"
25 #include "rmw/error_handling.h"
26 #include "rmw/validate_full_topic_name.h"
27 #include "rmw/event.h"
30 #include "./event_impl.h"
31 #include "./publisher_impl.h"
32 #include "./subscription_impl.h"
53 rmw_event_type_t rmw_event_type = RMW_EVENT_INVALID;
55 case RCL_PUBLISHER_OFFERED_DEADLINE_MISSED:
56 rmw_event_type = RMW_EVENT_OFFERED_DEADLINE_MISSED;
58 case RCL_PUBLISHER_LIVELINESS_LOST:
59 rmw_event_type = RMW_EVENT_LIVELINESS_LOST;
61 case RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS:
62 rmw_event_type = RMW_EVENT_OFFERED_QOS_INCOMPATIBLE;
64 case RCL_PUBLISHER_INCOMPATIBLE_TYPE:
65 rmw_event_type = RMW_EVENT_PUBLISHER_INCOMPATIBLE_TYPE;
67 case RCL_PUBLISHER_MATCHED:
68 rmw_event_type = RMW_EVENT_PUBLICATION_MATCHED;
71 if (rmw_event_type == RMW_EVENT_INVALID) {
72 RCL_SET_ERROR_MSG(
"Event type for publisher not supported");
79 RCL_CHECK_FOR_NULL_WITH_MSG(
82 event->impl->rmw_handle = rmw_get_zero_initialized_event();
83 event->impl->allocator = *allocator;
85 rmw_ret_t ret = rmw_publisher_event_init(
86 &event->
impl->rmw_handle,
87 publisher->
impl->rmw_handle,
89 if (ret != RMW_RET_OK) {
95 allocator->deallocate(event->
impl, allocator->state);
97 return rcl_convert_rmw_ret_to_rcl_ret(ret);
111 rmw_event_type_t rmw_event_type = RMW_EVENT_INVALID;
112 switch (event_type) {
113 case RCL_SUBSCRIPTION_REQUESTED_DEADLINE_MISSED:
114 rmw_event_type = RMW_EVENT_REQUESTED_DEADLINE_MISSED;
116 case RCL_SUBSCRIPTION_LIVELINESS_CHANGED:
117 rmw_event_type = RMW_EVENT_LIVELINESS_CHANGED;
119 case RCL_SUBSCRIPTION_REQUESTED_INCOMPATIBLE_QOS:
120 rmw_event_type = RMW_EVENT_REQUESTED_QOS_INCOMPATIBLE;
122 case RCL_SUBSCRIPTION_MESSAGE_LOST:
123 rmw_event_type = RMW_EVENT_MESSAGE_LOST;
125 case RCL_SUBSCRIPTION_INCOMPATIBLE_TYPE:
126 rmw_event_type = RMW_EVENT_SUBSCRIPTION_INCOMPATIBLE_TYPE;
128 case RCL_SUBSCRIPTION_MATCHED:
129 rmw_event_type = RMW_EVENT_SUBSCRIPTION_MATCHED;
132 if (rmw_event_type == RMW_EVENT_INVALID) {
133 RCL_SET_ERROR_MSG(
"Event type for subscription not supported");
140 RCL_CHECK_FOR_NULL_WITH_MSG(
143 event->impl->rmw_handle = rmw_get_zero_initialized_event();
144 event->impl->allocator = *allocator;
146 rmw_ret_t ret = rmw_subscription_event_init(
147 &event->
impl->rmw_handle,
148 subscription->
impl->rmw_handle,
150 if (ret != RMW_RET_OK) {
156 allocator->deallocate(event->
impl, allocator->state);
158 return rcl_convert_rmw_ret_to_rcl_ret(ret);
171 rmw_ret_t ret = rmw_take_event(&event->
impl->rmw_handle, event_info, &taken);
172 if (RMW_RET_OK != ret) {
173 RCL_SET_ERROR_MSG(rmw_get_error_string().str);
174 return rcl_convert_rmw_ret_to_rcl_ret(ret);
177 RCUTILS_LOG_DEBUG_NAMED(
178 ROS_PACKAGE_NAME,
"take_event request complete, unable to take event");
181 RCUTILS_LOG_DEBUG_NAMED(
182 ROS_PACKAGE_NAME,
"take_event request success");
183 return rcl_convert_rmw_ret_to_rcl_ret(ret);
192 RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME,
"Finalizing event");
193 if (NULL != event->
impl) {
195 rmw_ret_t ret = rmw_event_fini(&event->
impl->rmw_handle);
196 if (ret != RMW_RET_OK) {
197 RCL_SET_ERROR_MSG(rmw_get_error_string().str);
198 result = rcl_convert_rmw_ret_to_rcl_ret(ret);
200 allocator.deallocate(event->
impl, allocator.state);
203 RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME,
"Event finalized");
214 return &
event->impl->rmw_handle;
221 RCL_CHECK_FOR_NULL_WITH_MSG(event,
"event pointer is invalid",
return false);
222 RCL_CHECK_FOR_NULL_WITH_MSG(event->
impl,
"event's implementation is invalid",
return false);
223 if (event->
impl->rmw_handle.event_type == RMW_EVENT_INVALID) {
224 RCUTILS_SET_ERROR_MSG(
"event's implementation not init");
227 RCUTILS_CHECK_ALLOCATOR_WITH_MSG(
228 &event->
impl->allocator,
"not valid allocator",
return false);
236 rmw_event_type_t rmw_event_type = RMW_EVENT_INVALID;
237 switch (event_type) {
238 case RCL_PUBLISHER_OFFERED_DEADLINE_MISSED:
239 rmw_event_type = RMW_EVENT_OFFERED_DEADLINE_MISSED;
241 case RCL_PUBLISHER_LIVELINESS_LOST:
242 rmw_event_type = RMW_EVENT_LIVELINESS_LOST;
244 case RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS:
245 rmw_event_type = RMW_EVENT_OFFERED_QOS_INCOMPATIBLE;
247 case RCL_PUBLISHER_INCOMPATIBLE_TYPE:
248 rmw_event_type = RMW_EVENT_PUBLISHER_INCOMPATIBLE_TYPE;
250 case RCL_PUBLISHER_MATCHED:
251 rmw_event_type = RMW_EVENT_PUBLICATION_MATCHED;
254 if (rmw_event_type == RMW_EVENT_INVALID) {
257 return rmw_event_type_is_supported(rmw_event_type);
264 rmw_event_type_t rmw_event_type = RMW_EVENT_INVALID;
265 switch (event_type) {
266 case RCL_SUBSCRIPTION_REQUESTED_DEADLINE_MISSED:
267 rmw_event_type = RMW_EVENT_REQUESTED_DEADLINE_MISSED;
269 case RCL_SUBSCRIPTION_LIVELINESS_CHANGED:
270 rmw_event_type = RMW_EVENT_LIVELINESS_CHANGED;
272 case RCL_SUBSCRIPTION_REQUESTED_INCOMPATIBLE_QOS:
273 rmw_event_type = RMW_EVENT_REQUESTED_QOS_INCOMPATIBLE;
275 case RCL_SUBSCRIPTION_MESSAGE_LOST:
276 rmw_event_type = RMW_EVENT_MESSAGE_LOST;
278 case RCL_SUBSCRIPTION_INCOMPATIBLE_TYPE:
279 rmw_event_type = RMW_EVENT_SUBSCRIPTION_INCOMPATIBLE_TYPE;
281 case RCL_SUBSCRIPTION_MATCHED:
282 rmw_event_type = RMW_EVENT_SUBSCRIPTION_MATCHED;
285 if (rmw_event_type == RMW_EVENT_INVALID) {
288 return rmw_event_type_is_supported(rmw_event_type);
294 rcl_event_callback_t callback,
295 const void * user_data)
302 return rmw_event_set_callback(
303 &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.