Skip to content

Commit

Permalink
rcl_take_raw function
Browse files Browse the repository at this point in the history
  • Loading branch information
Karsten1987 committed Nov 14, 2017
1 parent 01a3112 commit 29af54b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
8 changes: 8 additions & 0 deletions rcl/include/rcl/subscription.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,14 @@ rcl_take(
void * ros_message,
rmw_message_info_t * message_info);

RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_take_raw(
const rcl_subscription_t * subscription,
rcl_message_raw_t * raw_message,
rmw_message_info_t * message_info);

/// Get the topic name for the subscription.
/**
* This function returns the subscription's internal topic name string.
Expand Down
35 changes: 35 additions & 0 deletions rcl/src/rcl/subscription.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,41 @@ rcl_take(
return RCL_RET_OK;
}

rcl_ret_t
rcl_take_raw(
const rcl_subscription_t * subscription,
rcl_message_raw_t * raw_message,
rmw_message_info_t * message_info)
{
RCL_CHECK_ARGUMENT_FOR_NULL(subscription, RCL_RET_INVALID_ARGUMENT, rcl_get_default_allocator());
const rcl_subscription_options_t * options = rcl_subscription_get_options(subscription);
if (!options) {
return RCL_RET_SUBSCRIPTION_INVALID;
}
RCL_CHECK_ARGUMENT_FOR_NULL(raw_message, RCL_RET_INVALID_ARGUMENT, options->allocator);
RCL_CHECK_FOR_NULL_WITH_MSG(
subscription->impl, "subscription is invalid",
return RCL_RET_SUBSCRIPTION_INVALID, options->allocator);
RCL_CHECK_FOR_NULL_WITH_MSG(
subscription->impl->rmw_handle,
"subscription is invalid", return RCL_RET_SUBSCRIPTION_INVALID, options->allocator);
// If message_info is NULL, use a place holder which can be discarded.
rmw_message_info_t dummy_message_info;
rmw_message_info_t * message_info_local = message_info ? message_info : &dummy_message_info;
// Call rmw_take_with_info.
bool taken = false;
rmw_ret_t ret =
rmw_take_raw_with_info(subscription->impl->rmw_handle, raw_message, &taken, message_info_local);
if (ret != RMW_RET_OK) {
RCL_SET_ERROR_MSG(rmw_get_error_string_safe(), options->allocator);
return RCL_RET_ERROR;
}
if (!taken) {
return RCL_RET_SUBSCRIPTION_TAKE_FAILED;
}
return RCL_RET_OK;
}

const char *
rcl_subscription_get_topic_name(const rcl_subscription_t * subscription)
{
Expand Down

0 comments on commit 29af54b

Please sign in to comment.