Skip to content

Commit

Permalink
use rcutls macro
Browse files Browse the repository at this point in the history
  • Loading branch information
Karsten1987 committed May 22, 2018
1 parent 52d1868 commit 1185792
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 26 deletions.
8 changes: 0 additions & 8 deletions rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,4 @@
} \
};

// check the input pointer for null, sets the error msg accordingly and
// return RMW_RET_ERROR if null
#define RETURN_ERROR_ON_NULL(POINTER) \
if (POINTER == nullptr) { \
RMW_SET_ERROR_MSG("#POINTER pointer is null"); \
return RMW_RET_ERROR; \
} \

#endif // RMW_FASTRTPS_CPP__MACROS_HPP_
56 changes: 38 additions & 18 deletions rmw_fastrtps_cpp/src/rmw_take.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ _take(
}

CustomSubscriberInfo * info = static_cast<CustomSubscriberInfo *>(subscription->data);
RETURN_ERROR_ON_NULL(info);
auto error_msg_allocator = rcutils_get_default_allocator();
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
info, "custom subscriber info is null", return RMW_RET_ERROR, error_msg_allocator);

eprosima::fastcdr::FastBuffer buffer;
eprosima::fastrtps::SampleInfo_t sinfo;
Expand All @@ -85,9 +87,13 @@ _take(
rmw_ret_t
rmw_take(const rmw_subscription_t * subscription, void * ros_message, bool * taken)
{
RETURN_ERROR_ON_NULL(subscription);
RETURN_ERROR_ON_NULL(ros_message);
RETURN_ERROR_ON_NULL(taken);
auto error_msg_allocator = rcutils_get_default_allocator();
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
subscription, "subscription pointer is null", return RMW_RET_ERROR, error_msg_allocator);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
ros_message, "ros_message pointer is null", return RMW_RET_ERROR, error_msg_allocator);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
taken, "boolean flag for taken is null", return RMW_RET_ERROR, error_msg_allocator);

return _take(subscription, ros_message, taken, nullptr);
}
Expand All @@ -99,10 +105,15 @@ rmw_take_with_info(
bool * taken,
rmw_message_info_t * message_info)
{
RETURN_ERROR_ON_NULL(subscription);
RETURN_ERROR_ON_NULL(ros_message);
RETURN_ERROR_ON_NULL(taken);
RETURN_ERROR_ON_NULL(message_info);
auto error_msg_allocator = rcutils_get_default_allocator();
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
subscription, "subscription pointer is null", return RMW_RET_ERROR, error_msg_allocator);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
ros_message, "ros_message pointer is null", return RMW_RET_ERROR, error_msg_allocator);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
taken, "boolean flag for taken is null", return RMW_RET_ERROR, error_msg_allocator);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
message_info, "message info pointer is null", return RMW_RET_ERROR, error_msg_allocator);

return _take(subscription, ros_message, taken, message_info);
}
Expand All @@ -122,7 +133,9 @@ _take_raw(
}

CustomSubscriberInfo * info = static_cast<CustomSubscriberInfo *>(subscription->data);
RETURN_ERROR_ON_NULL(info);
auto error_msg_allocator = rcutils_get_default_allocator();
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
info, "custom subscriber info is null", return RMW_RET_ERROR, error_msg_allocator);

eprosima::fastcdr::FastBuffer buffer;
eprosima::fastrtps::SampleInfo_t sinfo;
Expand All @@ -137,8 +150,6 @@ _take_raw(
if (ret != RMW_RET_OK) {
return ret; // Error message already set
}
// TODO(karsten1987): Put that in RCUTILS_DEBUG_LOG()
fprintf(stderr, "had to resize to %u\n", buffer_size);
}
raw_message->buffer_length = buffer_size;
memcpy(raw_message->buffer, buffer.getBuffer(), raw_message->buffer_length);
Expand All @@ -159,9 +170,13 @@ rmw_take_raw(
rmw_message_raw_t * raw_message,
bool * taken)
{
RETURN_ERROR_ON_NULL(subscription);
RETURN_ERROR_ON_NULL(raw_message);
RETURN_ERROR_ON_NULL(taken);
auto error_msg_allocator = rcutils_get_default_allocator();
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
subscription, "subscription pointer is null", return RMW_RET_ERROR, error_msg_allocator);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
raw_message, "ros_message pointer is null", return RMW_RET_ERROR, error_msg_allocator);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
taken, "boolean flag for taken is null", return RMW_RET_ERROR, error_msg_allocator);

return _take_raw(subscription, raw_message, taken, nullptr);
}
Expand All @@ -173,10 +188,15 @@ rmw_take_raw_with_info(
bool * taken,
rmw_message_info_t * message_info)
{
RETURN_ERROR_ON_NULL(subscription);
RETURN_ERROR_ON_NULL(raw_message);
RETURN_ERROR_ON_NULL(taken);
RETURN_ERROR_ON_NULL(message_info);
auto error_msg_allocator = rcutils_get_default_allocator();
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
subscription, "subscription pointer is null", return RMW_RET_ERROR, error_msg_allocator);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
raw_message, "ros_message pointer is null", return RMW_RET_ERROR, error_msg_allocator);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
taken, "boolean flag for taken is null", return RMW_RET_ERROR, error_msg_allocator);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
message_info, "message info pointer is null", return RMW_RET_ERROR, error_msg_allocator);

return _take_raw(subscription, raw_message, taken, message_info);
}
Expand Down

0 comments on commit 1185792

Please sign in to comment.