Skip to content
This repository has been archived by the owner on Oct 7, 2021. It is now read-only.

strip 'Sample_' from reported types #234

Merged
merged 5 commits into from
Jun 23, 2018
Merged
Changes from 4 commits
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
14 changes: 13 additions & 1 deletion rmw_opensplice_cpp/src/rmw_service_names_and_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "types.hpp"
#include "demangle.hpp"

#define SAMPLE_PREFIX "/Sample_"
// The extern "C" here enforces that overloading is not used.
extern "C"
{
Expand Down Expand Up @@ -119,7 +120,18 @@ rmw_get_service_names_and_types(
// Duplicate and store each type for the service
size_t type_index = 0;
for (const auto & type : service_n_types.second) {
char * type_name = rcutils_strdup(type.c_str(), *allocator);
size_t n = type.find(SAMPLE_PREFIX);
if (std::string::npos == n) {
char * error_msg = rcutils_format_string(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The returned char * needs to be deallocated in order to not leak.

*allocator,
"failed to convert DDS type name to ROS service type name: '" SAMPLE_PREFIX
"' not found in type: '%s'", type.c_str());
RMW_SET_ERROR_MSG(error_msg)
fail_cleanup();
return RMW_RET_ERROR;
}
std::string stripped_type = type.substr(0, n + 1) + type.substr(n + strlen(SAMPLE_PREFIX));
char * type_name = rcutils_strdup(stripped_type.c_str(), *allocator);
if (!type_name) {
RMW_SET_ERROR_MSG_ALLOC("failed to allocate memory for type name", *allocator)
fail_cleanup();
Expand Down