Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Add rmw_*_event_init() functions #397

Merged
merged 3 commits into from
Mar 19, 2020
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
37 changes: 28 additions & 9 deletions rmw_connext_cpp/src/rmw_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,34 @@

extern "C"
{
/// Take an event from the event handle.
/**
* \param event_handle event object to take from
* \param event_info event info object to write taken data into
* \param taken boolean flag indicating if an event was taken or not
* \return `RMW_RET_OK` if successful, or
* \return `RMW_RET_BAD_ALLOC` if memory allocation failed, or
* \return `RMW_RET_ERROR` if an unexpected error occurs.
*/
rmw_ret_t
rmw_publisher_event_init(
rmw_event_t * rmw_event,
const rmw_publisher_t * publisher,
rmw_event_type_t event_type)
{
return __rmw_init_event(
rti_connext_identifier,
rmw_event,
publisher->implementation_identifier,
publisher->data,
event_type);
}

rmw_ret_t
rmw_subscription_event_init(
rmw_event_t * rmw_event,
const rmw_subscription_t * subscription,
rmw_event_type_t event_type)
{
return __rmw_init_event(
rti_connext_identifier,
rmw_event,
subscription->implementation_identifier,
subscription->data,
event_type);
}

rmw_ret_t
rmw_take_event(
const rmw_event_t * event_handle,
Expand Down
20 changes: 20 additions & 0 deletions rmw_connext_shared_cpp/include/rmw_connext_shared_cpp/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@

#include "rmw_connext_shared_cpp/visibility_control.h"

/// Initialize a rmw_event_t.
/**
* \param[in|out] rmw_event to initialize
* \param topic_endpoint_impl_identifier implementation identifier of event's parent topic endpoint
* \param data to initialize with
* \param event_type for the event to handle
* \return `RMW_RET_OK` if successful, or
* \return `RMW_RET_INVALID_ARGUMENT` if invalid argument, or
* \return `RMW_RET_UNSUPPORTED` if event_type is not supported, or
* \return `RMW_RET_ERROR` if an unexpected error occurs.
*/
RMW_CONNEXT_SHARED_CPP_PUBLIC
rmw_ret_t
__rmw_init_event(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit unrelated because it's extensively used in this package, function names starting with a leading underscore or containing __ should be avoided, as those names are reserved by the standard.
See ros2/rcl#597 (comment).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do a separate pull request that changes all the function names in this repo consistently.

const char * identifier,
rmw_event_t * rmw_event,
const char * topic_endpoint_impl_identifier,
void * data,
rmw_event_type_t event_type);

/// Take an event from the event handle.
/**
*
Expand Down
29 changes: 29 additions & 0 deletions rmw_connext_shared_cpp/src/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,35 @@
#include "rmw_connext_shared_cpp/event_converter.hpp"
#include "rmw_connext_shared_cpp/types.hpp"

rmw_ret_t
__rmw_init_event(
const char * identifier,
rmw_event_t * rmw_event,
const char * topic_endpoint_impl_identifier,
void * data,
rmw_event_type_t event_type)
{
RMW_CHECK_ARGUMENT_FOR_NULL(identifier, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_ARGUMENT_FOR_NULL(rmw_event, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_ARGUMENT_FOR_NULL(topic_endpoint_impl_identifier, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_ARGUMENT_FOR_NULL(data, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
topic endpoint,
topic_endpoint_impl_identifier,
identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
if (!is_event_supported(event_type)) {
wjwwood marked this conversation as resolved.
Show resolved Hide resolved
RMW_SET_ERROR_MSG("provided event_type is not supported by rmw_fastrtps_cpp");
return RMW_RET_UNSUPPORTED;
}

rmw_event->implementation_identifier = topic_endpoint_impl_identifier;
rmw_event->data = data;
rmw_event->event_type = event_type;

return RMW_RET_OK;
}

rmw_ret_t
__rmw_take_event(
const char * implementation_identifier,
Expand Down