Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions rcl/include/rcl/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,54 @@ RCL_PUBLIC
bool
rcl_event_is_valid(const rcl_event_t * event);

/// Check if a publisher event type is supported by the active RMW implementation.
/**
* This API allows application code to introspect at runtime whether a
* particular publisher event type is supported by the currently loaded
* RMW implementation, enabling portable code that adapts gracefully
* when switching between RMW implementations.
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | No
* Thread-Safe | Yes
* Uses Atomics | No
* Lock-Free | Yes
*
* \param[in] event_type the publisher event type to check
* \return `true` if the event type is supported, `false` otherwise
*/
Comment thread
fujitatomoya marked this conversation as resolved.
RCL_PUBLIC
RCL_WARN_UNUSED
bool
rcl_publisher_event_type_is_supported(
const rcl_publisher_event_type_t event_type);

/// Check if a subscription event type is supported by the active RMW implementation.
/**
* This API allows application code to introspect at runtime whether a
* particular subscription event type is supported by the currently loaded
* RMW implementation, enabling portable code that adapts gracefully
* when switching between RMW implementations.
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | No
* Thread-Safe | Yes
* Uses Atomics | No
* Lock-Free | Yes
*
* \param[in] event_type the subscription event type to check
* \return `true` if the event type is supported, `false` otherwise
*/
Comment thread
fujitatomoya marked this conversation as resolved.
RCL_PUBLIC
RCL_WARN_UNUSED
bool
rcl_subscription_event_type_is_supported(
const rcl_subscription_event_type_t event_type);

/// Set the callback function for the event.
/**
* This API sets the callback function to be called whenever the
Expand Down
59 changes: 59 additions & 0 deletions rcl/src/rcl/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,65 @@ rcl_event_is_valid(const rcl_event_t * event)
return true;
}

bool
rcl_publisher_event_type_is_supported(
const rcl_publisher_event_type_t event_type)
{
rmw_event_type_t rmw_event_type = RMW_EVENT_INVALID;
switch (event_type) {
case RCL_PUBLISHER_OFFERED_DEADLINE_MISSED:
rmw_event_type = RMW_EVENT_OFFERED_DEADLINE_MISSED;
break;
case RCL_PUBLISHER_LIVELINESS_LOST:
rmw_event_type = RMW_EVENT_LIVELINESS_LOST;
break;
case RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS:
rmw_event_type = RMW_EVENT_OFFERED_QOS_INCOMPATIBLE;
break;
case RCL_PUBLISHER_INCOMPATIBLE_TYPE:
rmw_event_type = RMW_EVENT_PUBLISHER_INCOMPATIBLE_TYPE;
break;
case RCL_PUBLISHER_MATCHED:
rmw_event_type = RMW_EVENT_PUBLICATION_MATCHED;
break;
}
if (rmw_event_type == RMW_EVENT_INVALID) {
return false;
}
return rmw_event_type_is_supported(rmw_event_type);
}
Comment thread
fujitatomoya marked this conversation as resolved.

bool
rcl_subscription_event_type_is_supported(
const rcl_subscription_event_type_t event_type)
{
rmw_event_type_t rmw_event_type = RMW_EVENT_INVALID;
Comment thread
fujitatomoya marked this conversation as resolved.
switch (event_type) {
case RCL_SUBSCRIPTION_REQUESTED_DEADLINE_MISSED:
rmw_event_type = RMW_EVENT_REQUESTED_DEADLINE_MISSED;
break;
case RCL_SUBSCRIPTION_LIVELINESS_CHANGED:
rmw_event_type = RMW_EVENT_LIVELINESS_CHANGED;
break;
case RCL_SUBSCRIPTION_REQUESTED_INCOMPATIBLE_QOS:
rmw_event_type = RMW_EVENT_REQUESTED_QOS_INCOMPATIBLE;
break;
case RCL_SUBSCRIPTION_MESSAGE_LOST:
rmw_event_type = RMW_EVENT_MESSAGE_LOST;
break;
case RCL_SUBSCRIPTION_INCOMPATIBLE_TYPE:
rmw_event_type = RMW_EVENT_SUBSCRIPTION_INCOMPATIBLE_TYPE;
break;
case RCL_SUBSCRIPTION_MATCHED:
rmw_event_type = RMW_EVENT_SUBSCRIPTION_MATCHED;
break;
}
Comment thread
fujitatomoya marked this conversation as resolved.
if (rmw_event_type == RMW_EVENT_INVALID) {
return false;
}
return rmw_event_type_is_supported(rmw_event_type);
}
Comment thread
fujitatomoya marked this conversation as resolved.

rcl_ret_t
rcl_event_set_callback(
const rcl_event_t * event,
Expand Down
51 changes: 50 additions & 1 deletion rcl/test/rcl/test_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ TEST_F(TestEventFixture, test_event_is_invalid) {
*/
TEST_F(TestEventFixture, test_sub_message_lost_event)
{
if (!rmw_event_type_is_supported(RMW_EVENT_MESSAGE_LOST)) {
if (!rcl_subscription_event_type_is_supported(RCL_SUBSCRIPTION_MESSAGE_LOST)) {
GTEST_SKIP();
}

Expand Down Expand Up @@ -1351,3 +1351,52 @@ TEST_F(TestEventFixture, test_sub_previous_matched_event)
// So check if event count >= 1.
EXPECT_GE(*matched_data.event_count, 1);
}

/*
* Test rcl_publisher_event_type_is_supported
*/
TEST_F(TestEventFixture, test_publisher_event_type_is_supported)
{
// Verify rcl results are consistent with the underlying rmw results
EXPECT_EQ(
rcl_publisher_event_type_is_supported(RCL_PUBLISHER_OFFERED_DEADLINE_MISSED),
rmw_event_type_is_supported(RMW_EVENT_OFFERED_DEADLINE_MISSED));
EXPECT_EQ(
rcl_publisher_event_type_is_supported(RCL_PUBLISHER_LIVELINESS_LOST),
rmw_event_type_is_supported(RMW_EVENT_LIVELINESS_LOST));
EXPECT_EQ(
rcl_publisher_event_type_is_supported(RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS),
rmw_event_type_is_supported(RMW_EVENT_OFFERED_QOS_INCOMPATIBLE));
EXPECT_EQ(
rcl_publisher_event_type_is_supported(RCL_PUBLISHER_INCOMPATIBLE_TYPE),
rmw_event_type_is_supported(RMW_EVENT_PUBLISHER_INCOMPATIBLE_TYPE));
EXPECT_EQ(
rcl_publisher_event_type_is_supported(RCL_PUBLISHER_MATCHED),
rmw_event_type_is_supported(RMW_EVENT_PUBLICATION_MATCHED));
}

/*
* Test rcl_subscription_event_type_is_supported
*/
TEST_F(TestEventFixture, test_subscription_event_type_is_supported)
{
// Verify rcl results are consistent with the underlying rmw results
EXPECT_EQ(
rcl_subscription_event_type_is_supported(RCL_SUBSCRIPTION_REQUESTED_DEADLINE_MISSED),
rmw_event_type_is_supported(RMW_EVENT_REQUESTED_DEADLINE_MISSED));
EXPECT_EQ(
rcl_subscription_event_type_is_supported(RCL_SUBSCRIPTION_LIVELINESS_CHANGED),
rmw_event_type_is_supported(RMW_EVENT_LIVELINESS_CHANGED));
EXPECT_EQ(
rcl_subscription_event_type_is_supported(RCL_SUBSCRIPTION_REQUESTED_INCOMPATIBLE_QOS),
rmw_event_type_is_supported(RMW_EVENT_REQUESTED_QOS_INCOMPATIBLE));
EXPECT_EQ(
rcl_subscription_event_type_is_supported(RCL_SUBSCRIPTION_MESSAGE_LOST),
rmw_event_type_is_supported(RMW_EVENT_MESSAGE_LOST));
EXPECT_EQ(
rcl_subscription_event_type_is_supported(RCL_SUBSCRIPTION_INCOMPATIBLE_TYPE),
rmw_event_type_is_supported(RMW_EVENT_SUBSCRIPTION_INCOMPATIBLE_TYPE));
EXPECT_EQ(
rcl_subscription_event_type_is_supported(RCL_SUBSCRIPTION_MATCHED),
rmw_event_type_is_supported(RMW_EVENT_SUBSCRIPTION_MATCHED));
}