Skip to content

Commit

Permalink
use new error handling API from rcutils (#231)
Browse files Browse the repository at this point in the history
* use new error handling API from rcutils

Signed-off-by: William Woodall <william@osrfoundation.org>

* use semicolons after macros

Signed-off-by: William Woodall <william@osrfoundation.org>
  • Loading branch information
wjwwood authored Nov 2, 2018
1 parent fb92873 commit 8a85bfd
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 60 deletions.
10 changes: 5 additions & 5 deletions rmw_fastrtps_shared_cpp/src/rmw_node_names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ __rmw_get_node_names(
rcutils_ret_t rcutils_ret =
rcutils_string_array_init(node_names, participant_names.size() + 1, &allocator);
if (rcutils_ret != RCUTILS_RET_OK) {
RMW_SET_ERROR_MSG(rcutils_get_error_string_safe())
RMW_SET_ERROR_MSG(rcutils_get_error_string().str);
goto fail;
}

rcutils_ret =
rcutils_string_array_init(node_namespaces, participant_names.size() + 1, &allocator);
if (rcutils_ret != RCUTILS_RET_OK) {
RMW_SET_ERROR_MSG(rcutils_get_error_string_safe())
RMW_SET_ERROR_MSG(rcutils_get_error_string().str);
goto fail;
}

Expand All @@ -86,7 +86,7 @@ __rmw_get_node_names(
node_namespaces->data[i] = rcutils_strdup(participant_ns[i - 1].c_str(), allocator);
}
if (!node_names->data[i] || !node_namespaces->data[i]) {
RMW_SET_ERROR_MSG("failed to allocate memory for node name")
RMW_SET_ERROR_MSG("failed to allocate memory for node name");
goto fail;
}
}
Expand All @@ -97,7 +97,7 @@ __rmw_get_node_names(
if (rcutils_ret != RCUTILS_RET_OK) {
RCUTILS_LOG_ERROR_NAMED(
"rmw_connext_cpp",
"failed to cleanup during error handling: %s", rcutils_get_error_string_safe());
"failed to cleanup during error handling: %s", rcutils_get_error_string().str);
rcutils_reset_error();
}
}
Expand All @@ -106,7 +106,7 @@ __rmw_get_node_names(
if (rcutils_ret != RCUTILS_RET_OK) {
RCUTILS_LOG_ERROR_NAMED(
"rmw_connext_cpp",
"failed to cleanup during error handling: %s", rcutils_get_error_string_safe());
"failed to cleanup during error handling: %s", rcutils_get_error_string().str);
rcutils_reset_error();
}
}
Expand Down
19 changes: 6 additions & 13 deletions rmw_fastrtps_shared_cpp/src/rmw_publish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,17 @@ __rmw_publish(
const rmw_publisher_t * publisher,
const void * ros_message)
{
auto error_allocator = rcutils_get_default_allocator();
RCUTILS_CHECK_FOR_NULL_WITH_MSG(publisher, "publisher pointer is null", return RMW_RET_ERROR);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
publisher, "publisher pointer is null", return RMW_RET_ERROR, error_allocator);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
ros_message, "ros_message pointer is null", return RMW_RET_ERROR, error_allocator);
ros_message, "ros_message pointer is null", return RMW_RET_ERROR);

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

auto info = static_cast<CustomPublisherInfo *>(publisher->data);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
info, "publisher info pointer is null", return RMW_RET_ERROR, error_allocator);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(info, "publisher info pointer is null", return RMW_RET_ERROR);

rmw_fastrtps_shared_cpp::SerializedData data;
data.is_cdr_buffer = false;
Expand All @@ -63,21 +60,17 @@ __rmw_publish_serialized_message(
const rmw_publisher_t * publisher,
const rmw_serialized_message_t * serialized_message)
{
auto error_allocator = rcutils_get_default_allocator();
RCUTILS_CHECK_FOR_NULL_WITH_MSG(publisher, "publisher pointer is null", return RMW_RET_ERROR);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
publisher, "publisher pointer is null", return RMW_RET_ERROR, error_allocator);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
serialized_message, "serialized_message pointer is null",
return RMW_RET_ERROR, error_allocator);
serialized_message, "serialized_message pointer is null", return RMW_RET_ERROR);

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

auto info = static_cast<CustomPublisherInfo *>(publisher->data);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
info, "publisher info pointer is null", return RMW_RET_ERROR, error_allocator);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(info, "publisher info pointer is null", return RMW_RET_ERROR);

eprosima::fastcdr::FastBuffer buffer(
serialized_message->buffer, serialized_message->buffer_length);
Expand Down
14 changes: 7 additions & 7 deletions rmw_fastrtps_shared_cpp/src/rmw_service_names_and_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ __rmw_get_service_names_and_types(
rmw_names_and_types_t * service_names_and_types)
{
if (!allocator) {
RMW_SET_ERROR_MSG("allocator is null")
RMW_SET_ERROR_MSG("allocator is null");
return RMW_RET_INVALID_ARGUMENT;
}
if (!node) {
RMW_SET_ERROR_MSG_ALLOC("null node handle", *allocator)
RMW_SET_ERROR_MSG("null node handle");
return RMW_RET_INVALID_ARGUMENT;
}
rmw_ret_t ret = rmw_names_and_types_check_zero(service_names_and_types);
Expand All @@ -55,7 +55,7 @@ __rmw_get_service_names_and_types(

// Get participant pointer from node
if (node->implementation_identifier != identifier) {
RMW_SET_ERROR_MSG_ALLOC("node handle not from this implementation", *allocator);
RMW_SET_ERROR_MSG("node handle not from this implementation");
return RMW_RET_ERROR;
}

Expand Down Expand Up @@ -116,7 +116,7 @@ __rmw_get_service_names_and_types(
if (rmw_ret != RMW_RET_OK) {
RCUTILS_LOG_ERROR_NAMED(
"rmw_fastrtps_shared_cpp",
"error during report of error: %s", rmw_get_error_string_safe());
"error during report of error: %s", rmw_get_error_string().str);
}
};
// For each service, store the name, initialize the string array for types, and store all types
Expand All @@ -125,7 +125,7 @@ __rmw_get_service_names_and_types(
// Duplicate and store the service_name
char * service_name = rcutils_strdup(service_n_types.first.c_str(), *allocator);
if (!service_name) {
RMW_SET_ERROR_MSG_ALLOC("failed to allocate memory for service name", *allocator);
RMW_SET_ERROR_MSG("failed to allocate memory for service name");
fail_cleanup();
return RMW_RET_BAD_ALLOC;
}
Expand All @@ -137,7 +137,7 @@ __rmw_get_service_names_and_types(
service_n_types.second.size(),
allocator);
if (rcutils_ret != RCUTILS_RET_OK) {
RMW_SET_ERROR_MSG(rcutils_get_error_string_safe())
RMW_SET_ERROR_MSG(rcutils_get_error_string().str);
fail_cleanup();
return rmw_convert_rcutils_ret_to_rmw_ret(rcutils_ret);
}
Expand All @@ -147,7 +147,7 @@ __rmw_get_service_names_and_types(
for (const auto & type : service_n_types.second) {
char * type_name = rcutils_strdup(type.c_str(), *allocator);
if (!type_name) {
RMW_SET_ERROR_MSG_ALLOC("failed to allocate memory for type name", *allocator)
RMW_SET_ERROR_MSG("failed to allocate memory for type name");
fail_cleanup();
return RMW_RET_BAD_ALLOC;
}
Expand Down
44 changes: 16 additions & 28 deletions rmw_fastrtps_shared_cpp/src/rmw_take.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ _take(
}

CustomSubscriberInfo * info = static_cast<CustomSubscriberInfo *>(subscription->data);
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);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(info, "custom subscriber info is null", return RMW_RET_ERROR);

eprosima::fastrtps::SampleInfo_t sinfo;

Expand Down Expand Up @@ -89,13 +87,11 @@ __rmw_take(
void * ros_message,
bool * 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);
subscription, "subscription pointer is null", return RMW_RET_ERROR);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
taken, "boolean flag for taken is null", return RMW_RET_ERROR, error_msg_allocator);
ros_message, "ros_message pointer is null", return RMW_RET_ERROR);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(taken, "boolean flag for taken is null", return RMW_RET_ERROR);

return _take(identifier, subscription, ros_message, taken, nullptr);
}
Expand All @@ -108,15 +104,13 @@ __rmw_take_with_info(
bool * taken,
rmw_message_info_t * 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);
subscription, "subscription pointer is null", return RMW_RET_ERROR);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
taken, "boolean flag for taken is null", return RMW_RET_ERROR, error_msg_allocator);
ros_message, "ros_message pointer is null", return RMW_RET_ERROR);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(taken, "boolean flag for taken is null", return RMW_RET_ERROR);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
message_info, "message info pointer is null", return RMW_RET_ERROR, error_msg_allocator);
message_info, "message info pointer is null", return RMW_RET_ERROR);

return _take(identifier, subscription, ros_message, taken, message_info);
}
Expand All @@ -137,9 +131,7 @@ _take_serialized_message(
}

CustomSubscriberInfo * info = static_cast<CustomSubscriberInfo *>(subscription->data);
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);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(info, "custom subscriber info is null", return RMW_RET_ERROR);

eprosima::fastcdr::FastBuffer buffer;
eprosima::fastrtps::SampleInfo_t sinfo;
Expand Down Expand Up @@ -178,13 +170,11 @@ __rmw_take_serialized_message(
rmw_serialized_message_t * serialized_message,
bool * 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(
serialized_message, "ros_message pointer is null", return RMW_RET_ERROR, error_msg_allocator);
subscription, "subscription pointer is null", return RMW_RET_ERROR);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
taken, "boolean flag for taken is null", return RMW_RET_ERROR, error_msg_allocator);
serialized_message, "ros_message pointer is null", return RMW_RET_ERROR);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(taken, "boolean flag for taken is null", return RMW_RET_ERROR);

return _take_serialized_message(identifier, subscription, serialized_message, taken, nullptr);
}
Expand All @@ -197,15 +187,13 @@ __rmw_take_serialized_message_with_info(
bool * taken,
rmw_message_info_t * 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(
serialized_message, "ros_message pointer is null", return RMW_RET_ERROR, error_msg_allocator);
subscription, "subscription pointer is null", return RMW_RET_ERROR);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
taken, "boolean flag for taken is null", return RMW_RET_ERROR, error_msg_allocator);
serialized_message, "ros_message pointer is null", return RMW_RET_ERROR);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(taken, "boolean flag for taken is null", return RMW_RET_ERROR);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
message_info, "message info pointer is null", return RMW_RET_ERROR, error_msg_allocator);
message_info, "message info pointer is null", return RMW_RET_ERROR);

return _take_serialized_message(
identifier, subscription, serialized_message, taken, message_info);
Expand Down
14 changes: 7 additions & 7 deletions rmw_fastrtps_shared_cpp/src/rmw_topic_names_and_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ __rmw_get_topic_names_and_types(
rmw_names_and_types_t * topic_names_and_types)
{
if (!allocator) {
RMW_SET_ERROR_MSG("allocator is null")
RMW_SET_ERROR_MSG("allocator is null");
return RMW_RET_INVALID_ARGUMENT;
}
if (!node) {
RMW_SET_ERROR_MSG_ALLOC("null node handle", *allocator)
RMW_SET_ERROR_MSG("null node handle");
return RMW_RET_INVALID_ARGUMENT;
}

Expand All @@ -64,7 +64,7 @@ __rmw_get_topic_names_and_types(

// Get participant pointer from node
if (node->implementation_identifier != identifier) {
RMW_SET_ERROR_MSG_ALLOC("node handle not from this implementation", *allocator);
RMW_SET_ERROR_MSG("node handle not from this implementation");
return RMW_RET_ERROR;
}

Expand Down Expand Up @@ -116,7 +116,7 @@ __rmw_get_topic_names_and_types(
if (rmw_ret != RMW_RET_OK) {
RCUTILS_LOG_ERROR_NAMED(
"rmw_fastrtps_shared_cpp",
"error during report of error: %s", rmw_get_error_string_safe());
"error during report of error: %s", rmw_get_error_string().str);
}
};
// Setup demangling functions based on no_demangle option
Expand All @@ -135,7 +135,7 @@ __rmw_get_topic_names_and_types(
// Duplicate and store the topic_name
char * topic_name = rcutils_strdup(demangle_topic(topic_n_types.first).c_str(), *allocator);
if (!topic_name) {
RMW_SET_ERROR_MSG_ALLOC("failed to allocate memory for topic name", *allocator);
RMW_SET_ERROR_MSG("failed to allocate memory for topic name");
fail_cleanup();
return RMW_RET_BAD_ALLOC;
}
Expand All @@ -147,7 +147,7 @@ __rmw_get_topic_names_and_types(
topic_n_types.second.size(),
allocator);
if (rcutils_ret != RCUTILS_RET_OK) {
RMW_SET_ERROR_MSG(rcutils_get_error_string_safe())
RMW_SET_ERROR_MSG(rcutils_get_error_string().str);
fail_cleanup();
return rmw_convert_rcutils_ret_to_rmw_ret(rcutils_ret);
}
Expand All @@ -157,7 +157,7 @@ __rmw_get_topic_names_and_types(
for (const auto & type : topic_n_types.second) {
char * type_name = rcutils_strdup(demangle_type(type).c_str(), *allocator);
if (!type_name) {
RMW_SET_ERROR_MSG_ALLOC("failed to allocate memory for type name", *allocator)
RMW_SET_ERROR_MSG("failed to allocate memory for type name");
fail_cleanup();
return RMW_RET_BAD_ALLOC;
}
Expand Down

0 comments on commit 8a85bfd

Please sign in to comment.