Skip to content

Commit

Permalink
remove asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
Karsten1987 committed May 14, 2018
1 parent d5c2155 commit 3b43625
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 42 deletions.
8 changes: 8 additions & 0 deletions rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@
} \
};

// 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_
41 changes: 20 additions & 21 deletions rmw_fastrtps_cpp/src/rmw_publish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,72 +21,71 @@

#include "rmw_fastrtps_cpp/custom_publisher_info.hpp"
#include "rmw_fastrtps_cpp/identifier.hpp"
#include "ros_message_serialization.hpp"
#include "rmw_fastrtps_cpp/macros.hpp"

#include "./ros_message_serialization.hpp"

extern "C"
{
rmw_ret_t
rmw_publish(const rmw_publisher_t * publisher, const void * ros_message)
{
assert(publisher);
assert(ros_message);
rmw_ret_t returnedValue = RMW_RET_ERROR;
RETURN_ERROR_ON_NULL(publisher);
RETURN_ERROR_ON_NULL(ros_message);

if (publisher->implementation_identifier != eprosima_fastrtps_identifier) {
RMW_SET_ERROR_MSG("publisher handle not from this implementation");
return RMW_RET_ERROR;
}

auto info = static_cast<CustomPublisherInfo *>(publisher->data);
assert(info);
RETURN_ERROR_ON_NULL(info);

eprosima::fastcdr::FastBuffer buffer;
eprosima::fastcdr::Cdr ser(buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
eprosima::fastcdr::Cdr::DDS_CDR);

if (_serialize_ros_message(ros_message, ser, info->type_support_,
if (!_serialize_ros_message(ros_message, ser, info->type_support_,
info->typesupport_identifier_))
{
if (info->publisher_->write(&ser)) {
returnedValue = RMW_RET_OK;
} else {
RMW_SET_ERROR_MSG("cannot publish data");
}
} else {
RMW_SET_ERROR_MSG("cannot serialize data");
return RMW_RET_ERROR;
}
if (!info->publisher_->write(&ser)) {
RMW_SET_ERROR_MSG("cannot publish data");
return RMW_RET_ERROR;
}

return returnedValue;
return RMW_RET_OK;
}

rmw_ret_t
rmw_publish_raw(const rmw_publisher_t * publisher, const rmw_message_raw_t * raw_message)
{
assert(publisher);
assert(raw_message);
rmw_ret_t returnedValue = RMW_RET_ERROR;
RETURN_ERROR_ON_NULL(publisher);
RETURN_ERROR_ON_NULL(raw_message);

if (publisher->implementation_identifier != eprosima_fastrtps_identifier) {
RMW_SET_ERROR_MSG("publisher handle not from this implementation");
return RMW_RET_ERROR;
}

auto info = static_cast<CustomPublisherInfo *>(publisher->data);
assert(info);
RETURN_ERROR_ON_NULL(info);

eprosima::fastcdr::FastBuffer buffer(raw_message->buffer, raw_message->buffer_length);
eprosima::fastcdr::Cdr ser(
buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR);
if (!ser.jump(raw_message->buffer_length)) {
RMW_SET_ERROR_MSG("cannot correctly set raw buffer");
return RMW_RET_ERROR;
}

if (info->publisher_->write(&ser)) {
returnedValue = RMW_RET_OK;
} else {
if (!info->publisher_->write(&ser)) {
RMW_SET_ERROR_MSG("cannot publish data");
return RMW_RET_ERROR;
}

return returnedValue;
return RMW_RET_OK;
}
} // extern "C"
40 changes: 19 additions & 21 deletions rmw_fastrtps_cpp/src/rmw_take.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "rmw_fastrtps_cpp/custom_subscriber_info.hpp"
#include "rmw_fastrtps_cpp/identifier.hpp"
#include "rmw_fastrtps_cpp/macros.hpp"

#include "./ros_message_serialization.hpp"

Expand All @@ -34,9 +35,9 @@ extern "C"
rmw_ret_t
rmw_take(const rmw_subscription_t * subscription, void * ros_message, bool * taken)
{
assert(subscription);
assert(ros_message);
assert(taken);
RETURN_ERROR_ON_NULL(subscription);
RETURN_ERROR_ON_NULL(ros_message);
RETURN_ERROR_ON_NULL(subscription);

*taken = false;

Expand All @@ -46,7 +47,7 @@ rmw_take(const rmw_subscription_t * subscription, void * ros_message, bool * tak
}

CustomSubscriberInfo * info = static_cast<CustomSubscriberInfo *>(subscription->data);
assert(info);
RETURN_ERROR_ON_NULL(info);

eprosima::fastcdr::FastBuffer buffer;
eprosima::fastrtps::SampleInfo_t sinfo;
Expand All @@ -73,14 +74,10 @@ rmw_take_with_info(
bool * taken,
rmw_message_info_t * message_info)
{
assert(subscription);
assert(ros_message);
assert(taken);

if (!message_info) {
RMW_SET_ERROR_MSG("message info is null");
return RMW_RET_ERROR;
}
RETURN_ERROR_ON_NULL(subscription);
RETURN_ERROR_ON_NULL(ros_message);
RETURN_ERROR_ON_NULL(taken);
RETURN_ERROR_ON_NULL(message_info);

*taken = false;

Expand All @@ -90,7 +87,7 @@ rmw_take_with_info(
}

CustomSubscriberInfo * info = static_cast<CustomSubscriberInfo *>(subscription->data);
assert(info);
RETURN_ERROR_ON_NULL(info);

eprosima::fastcdr::FastBuffer buffer;
eprosima::fastrtps::SampleInfo_t sinfo;
Expand Down Expand Up @@ -121,9 +118,9 @@ rmw_take_raw(
rmw_message_raw_t * raw_message,
bool * taken)
{
assert(subscription);
assert(raw_message);
assert(taken);
RETURN_ERROR_ON_NULL(subscription);
RETURN_ERROR_ON_NULL(raw_message);
RETURN_ERROR_ON_NULL(taken);

*taken = false;

Expand All @@ -133,7 +130,7 @@ rmw_take_raw(
}

CustomSubscriberInfo * info = static_cast<CustomSubscriberInfo *>(subscription->data);
assert(info);
RETURN_ERROR_ON_NULL(info);

eprosima::fastcdr::FastBuffer buffer;
eprosima::fastrtps::SampleInfo_t sinfo;
Expand Down Expand Up @@ -167,9 +164,10 @@ rmw_take_raw_with_info(
bool * taken,
rmw_message_info_t * message_info)
{
assert(subscription);
assert(raw_message);
assert(taken);
RETURN_ERROR_ON_NULL(subscription);
RETURN_ERROR_ON_NULL(raw_message);
RETURN_ERROR_ON_NULL(taken);
RETURN_ERROR_ON_NULL(message_info);

*taken = false;

Expand All @@ -179,7 +177,7 @@ rmw_take_raw_with_info(
}

CustomSubscriberInfo * info = static_cast<CustomSubscriberInfo *>(subscription->data);
assert(info);
RETURN_ERROR_ON_NULL(info);

eprosima::fastcdr::FastBuffer buffer;
eprosima::fastrtps::SampleInfo_t sinfo;
Expand Down

0 comments on commit 3b43625

Please sign in to comment.