Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use new error handling API from rcutils #231

Merged
merged 2 commits into from
Nov 2, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 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 @@ -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
12 changes: 6 additions & 6 deletions rmw_fastrtps_shared_cpp/src/rmw_service_names_and_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ __rmw_get_service_names_and_types(
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
12 changes: 6 additions & 6 deletions rmw_fastrtps_shared_cpp/src/rmw_topic_names_and_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ __rmw_get_topic_names_and_types(
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