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

Commit

Permalink
Add rmw_*_event_init() functions (#397)
Browse files Browse the repository at this point in the history
Signed-off-by: Miaofei <miaofei@amazon.com>
  • Loading branch information
mm318 committed Mar 19, 2020
1 parent aa0a135 commit f1d74a8
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 9 deletions.
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(
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)) {
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

0 comments on commit f1d74a8

Please sign in to comment.