Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function rcl_event_is_valid #720

Merged
merged 6 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 22 additions & 0 deletions rcl/include/rcl/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,28 @@ RCL_WARN_UNUSED
rmw_event_t *
rcl_event_get_rmw_handle(const rcl_event_t * event);

/// Check that the event is valid.
/**
* The bool returned is `false` if `event` is invalid.
* The bool returned is `true` otherwise.
* In the case where `false` is to be returned, an error message is set.
* This function cannot fail.
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | No
* Thread-Safe | No
* Uses Atomics | No
* Lock-Free | Yes
*
* \param[in] event pointer to the rcl event
* \return `true` if `event` is valid, otherwise `false`
*/
RCL_PUBLIC
bool
rcl_event_is_valid(const rcl_event_t * event);

#ifdef __cplusplus
}
#endif
Expand Down
14 changes: 14 additions & 0 deletions rcl/src/rcl/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,20 @@ rcl_event_get_rmw_handle(const rcl_event_t * event)
}
}

bool
rcl_event_is_valid(const rcl_event_t * event)
Blast545 marked this conversation as resolved.
Show resolved Hide resolved
{
RCL_CHECK_FOR_NULL_WITH_MSG(event, "event pointer is invalid", return false);
RCL_CHECK_FOR_NULL_WITH_MSG(event->impl, "event's implementation is invalid", return false);
/*
if (event->impl->rmw_handle.event_type == RMW_EVENT_INVALID) {
ivanpauno marked this conversation as resolved.
Show resolved Hide resolved
RCUTILS_SET_ERROR_MSG("event's implementation not init");
return false;
}
*/
return true;
}

#ifdef __cplusplus
}
#endif
21 changes: 21 additions & 0 deletions rcl/test/rcl/test_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,27 @@ TEST_F(TestEventFixture, test_bad_get_handle)
EXPECT_EQ(NULL, rcl_event_get_rmw_handle(NULL));
}

/*
* Test cases for the event_is_valid function
*/
TEST_F(TestEventFixture, test_event_is_valid)
{
EXPECT_FALSE(rcl_event_is_valid(nullptr));

setup_publisher_subscriber(default_qos_profile, default_qos_profile);
rcl_event_t publisher_event_test = rcl_get_zero_initialized_event();
EXPECT_FALSE(rcl_event_is_valid(&publisher_event_test));

rcl_ret_t ret = rcl_publisher_event_init(
&publisher_event_test, &publisher, RCL_PUBLISHER_OFFERED_DEADLINE_MISSED);
ASSERT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
EXPECT_TRUE(rcl_event_is_valid(&publisher_event_test));

ret = rcl_event_fini(&publisher_event_test);
EXPECT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
tear_down_publisher_subscriber();
}

static
std::array<TestIncompatibleQosEventParams, 5>
get_test_pubsub_incompatible_qos_inputs()
Expand Down