Skip to content

Commit

Permalink
Updates for allocation in serialize methods.
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <michael@openrobotics.org>
  • Loading branch information
mjcarroll committed May 1, 2019
1 parent 08e4389 commit 92f9e43
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 15 deletions.
8 changes: 6 additions & 2 deletions rcl/include/rcl/publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ rcl_publisher_get_default_options(void);
*
* \param[in] publisher handle to the publisher which will do the publishing
* \param[in] ros_message type-erased pointer to the ROS message
* \param[in] publihser allocation structure pointer, used for memory preallocation
* \param[in] allocation structure pointer, used for memory preallocation (may be NULL)
* \return `RCL_RET_OK` if the message was published successfully, or
* \return `RCL_RET_INVALID_ARGUMENT` if any arguments are invalid, or
* \return `RCL_RET_PUBLISHER_INVALID` if the publisher is invalid, or
Expand Down Expand Up @@ -285,6 +285,7 @@ rcl_publish(
*
* \param[in] publisher handle to the publisher which will do the publishing
* \param[in] serialized_message pointer to the already serialized message in raw form
* \param[in] allocation structure pointer, used for memory preallocation (may be NULL)
* \return `RCL_RET_OK` if the message was published successfully, or
* \return `RCL_RET_INVALID_ARGUMENT` if any arguments are invalid, or
* \return `RCL_RET_PUBLISHER_INVALID` if the publisher is invalid, or
Expand All @@ -294,7 +295,10 @@ RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_publish_serialized_message(
const rcl_publisher_t * publisher, const rcl_serialized_message_t * serialized_message);
const rcl_publisher_t * publisher,
const rcl_serialized_message_t * serialized_message,
rmw_publisher_allocation_t * allocation
);

/// Get the topic name for the publisher.
/**
Expand Down
6 changes: 4 additions & 2 deletions rcl/include/rcl/subscription.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ rcl_subscription_get_default_options(void);
* \param[in] subscription the handle to the subscription from which to take
* \param[inout] ros_message type-erased ptr to a allocated ROS message
* \param[out] message_info rmw struct which contains meta-data for the message
* \param[in] subscription allocation structure pointer used for memory preallocation
* \param[in] allocation structure pointer used for memory preallocation (may be NULL)
* \return `RCL_RET_OK` if the message was published, or
* \return `RCL_RET_INVALID_ARGUMENT` if any arguments are invalid, or
* \return `RCL_RET_SUBSCRIPTION_INVALID` if the subscription is invalid, or
Expand Down Expand Up @@ -293,6 +293,7 @@ rcl_take(
* \param[in] subscription the handle to the subscription from which to take
* \param[inout] serialized_message pointer to a (pre-allocated) serialized message.
* \param[out] message_info rmw struct which contains meta-data for the message
* \param[in] allocation structure pointer used for memory preallocation (may be NULL)
* \return `RCL_RET_OK` if the message was published, or
* \return `RCL_RET_INVALID_ARGUMENT` if any arguments are invalid, or
* \return `RCL_RET_SUBSCRIPTION_INVALID` if the subscription is invalid, or
Expand All @@ -307,7 +308,8 @@ rcl_ret_t
rcl_take_serialized_message(
const rcl_subscription_t * subscription,
rcl_serialized_message_t * serialized_message,
rmw_message_info_t * message_info);
rmw_message_info_t * message_info,
rmw_subscription_allocation_t * allocation);

/// Get the topic name for the subscription.
/**
Expand Down
13 changes: 8 additions & 5 deletions rcl/src/rcl/publisher.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ rcl_publisher_init(
rcl_node_get_rmw_handle(node),
type_support,
remapped_topic_name,
&(options->qos)
);
&(options->qos));
RCL_CHECK_FOR_NULL_WITH_MSG(publisher->impl->rmw_handle,
rmw_get_error_string().str, goto fail);
// get actual qos, and store it
Expand Down Expand Up @@ -253,7 +252,8 @@ rcl_publisher_get_default_options()

rcl_ret_t
rcl_publish(
const rcl_publisher_t * publisher, const void * ros_message,
const rcl_publisher_t * publisher,
const void * ros_message,
rmw_publisher_allocation_t * allocation)
{
if (!rcl_publisher_is_valid(publisher)) {
Expand All @@ -269,13 +269,16 @@ rcl_publish(

rcl_ret_t
rcl_publish_serialized_message(
const rcl_publisher_t * publisher, const rcl_serialized_message_t * serialized_message)
const rcl_publisher_t * publisher,
const rcl_serialized_message_t * serialized_message,
rmw_publisher_allocation_t * allocation)
{
if (!rcl_publisher_is_valid(publisher)) {
return RCL_RET_PUBLISHER_INVALID; // error already set
}
RCL_CHECK_ARGUMENT_FOR_NULL(serialized_message, RCL_RET_INVALID_ARGUMENT);
rmw_ret_t ret = rmw_publish_serialized_message(publisher->impl->rmw_handle, serialized_message);
rmw_ret_t ret = rmw_publish_serialized_message(publisher->impl->rmw_handle, serialized_message,
allocation);
if (ret != RMW_RET_OK) {
RCL_SET_ERROR_MSG(rmw_get_error_string().str);
if (ret == RMW_RET_BAD_ALLOC) {
Expand Down
6 changes: 4 additions & 2 deletions rcl/src/rcl/subscription.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ rcl_ret_t
rcl_take_serialized_message(
const rcl_subscription_t * subscription,
rcl_serialized_message_t * serialized_message,
rmw_message_info_t * message_info)
rmw_message_info_t * message_info,
rmw_subscription_allocation_t * allocation
)
{
RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "Subscription taking serialized message");
if (!rcl_subscription_is_valid(subscription)) {
Expand All @@ -286,7 +288,7 @@ rcl_take_serialized_message(
// Call rmw_take_with_info.
bool taken = false;
rmw_ret_t ret = rmw_take_serialized_message_with_info(
subscription->impl->rmw_handle, serialized_message, &taken, message_info_local);
subscription->impl->rmw_handle, serialized_message, &taken, message_info_local, allocation);
if (ret != RMW_RET_OK) {
RCL_SET_ERROR_MSG(rmw_get_error_string().str);
if (RMW_RET_BAD_ALLOC == ret) {
Expand Down
2 changes: 1 addition & 1 deletion rcl_action/src/rcl_action/action_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ rcl_action_take_cancel_response(
RCL_CHECK_ARGUMENT_FOR_NULL(ros_ ## Type, RCL_RET_INVALID_ARGUMENT); \
rmw_message_info_t message_info; /* ignored */ \
rcl_ret_t ret = rcl_take( \
&action_client->impl->Type ## _subscription, ros_ ## Type, &message_info); \
&action_client->impl->Type ## _subscription, ros_ ## Type, &message_info, NULL); \
if (RCL_RET_OK != ret) { \
if (RCL_RET_SUBSCRIPTION_TAKE_FAILED == ret) { \
return RCL_RET_ACTION_CLIENT_TAKE_FAILED; \
Expand Down
4 changes: 2 additions & 2 deletions rcl_action/src/rcl_action/action_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ rcl_action_publish_feedback(
}
RCL_CHECK_ARGUMENT_FOR_NULL(ros_feedback, RCL_RET_INVALID_ARGUMENT);

rcl_ret_t ret = rcl_publish(&action_server->impl->feedback_publisher, ros_feedback);
rcl_ret_t ret = rcl_publish(&action_server->impl->feedback_publisher, ros_feedback, NULL);
if (RCL_RET_OK != ret) {
return RCL_RET_ERROR; // error already set
}
Expand Down Expand Up @@ -559,7 +559,7 @@ rcl_action_publish_status(
}
RCL_CHECK_ARGUMENT_FOR_NULL(status_message, RCL_RET_INVALID_ARGUMENT);

rcl_ret_t ret = rcl_publish(&action_server->impl->status_publisher, status_message);
rcl_ret_t ret = rcl_publish(&action_server->impl->status_publisher, status_message, NULL);
if (RCL_RET_OK != ret) {
return RCL_RET_ERROR; // error already set
}
Expand Down
2 changes: 1 addition & 1 deletion rcl_lifecycle/src/com_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ rcl_lifecycle_com_interface_publish_notification(
msg.goal_state.id = goal->id;
rosidl_generator_c__String__assign(&msg.goal_state.label, goal->label);

return rcl_publish(&com_interface->pub_transition_event, &msg);
return rcl_publish(&com_interface->pub_transition_event, &msg, NULL);
}

#ifdef __cplusplus
Expand Down

0 comments on commit 92f9e43

Please sign in to comment.