From 2c56ae4c07aebe6d667ca90302f7a0bbd4255aa7 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Tue, 7 May 2019 22:47:47 -0700 Subject: [PATCH] Combine package name with message namespace in type support struct (#268) * Combine package name with message namespace in type support struct Signed-off-by: Jacob Perron * Update demangle logic for services Signed-off-by: Jacob Perron * fix lint Signed-off-by: Jacob Perron --- rmw_opensplice_cpp/src/demangle.cpp | 37 ++++++++++++--------- rmw_opensplice_cpp/src/rmw_publisher.cpp | 2 +- rmw_opensplice_cpp/src/rmw_subscription.cpp | 2 +- rmw_opensplice_cpp/src/types.cpp | 7 ++-- rmw_opensplice_cpp/src/types.hpp | 4 +-- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/rmw_opensplice_cpp/src/demangle.cpp b/rmw_opensplice_cpp/src/demangle.cpp index b6145511..e1047044 100644 --- a/rmw_opensplice_cpp/src/demangle.cpp +++ b/rmw_opensplice_cpp/src/demangle.cpp @@ -12,8 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include +#include +#include #include #include "rcutils/logging_macros.h" @@ -36,19 +37,21 @@ _demangle_if_ros_topic(const std::string & topic_name) std::string _demangle_if_ros_type(const std::string & dds_type_string) { - std::string substring = "::msg::dds_::"; + std::string substring = "dds_::"; size_t substring_position = dds_type_string.find(substring); if ( - dds_type_string[dds_type_string.size() - 1] == '_' && - substring_position != std::string::npos) + dds_type_string[dds_type_string.size() - 1] != '_' || + substring_position == std::string::npos) { - std::string pkg = dds_type_string.substr(0, substring_position); - size_t start = substring_position + substring.size(); - std::string type_name = dds_type_string.substr(start, dds_type_string.length() - 1 - start); - return pkg + "/" + type_name; + // not a ROS type + return dds_type_string; } - // not a ROS type - return dds_type_string; + + std::string type_namespace = dds_type_string.substr(0, substring_position); + type_namespace = std::regex_replace(type_namespace, std::regex("::"), "/"); + size_t start = substring_position + substring.size(); + std::string type_name = dds_type_string.substr(start, dds_type_string.length() - 1 - start); + return type_namespace + type_name; } std::string @@ -108,7 +111,7 @@ _demangle_service_from_topic(const std::string & topic_name) std::string _demangle_service_type_only(const std::string & dds_type_name) { - std::string ns_substring = "::srv::dds_::"; + std::string ns_substring = "dds_::"; size_t ns_substring_position = dds_type_name.find(ns_substring); if (ns_substring_position == std::string::npos) { // not a ROS service type @@ -125,7 +128,7 @@ _demangle_service_type_only(const std::string & dds_type_name) if (suffix_position != std::string::npos) { if (dds_type_name.length() - suffix_position - suffix.length() != 0) { RCUTILS_LOG_WARN_NAMED("rmw_opensplice_cpp", - "service type contains '::srv::dds_::' and a suffix, but not at the end" + "service type contains 'dds_::' and a suffix, but not at the end" ", report this: '%s'", dds_type_name.c_str()); continue; } @@ -135,13 +138,15 @@ _demangle_service_type_only(const std::string & dds_type_name) } if (suffix_position == std::string::npos) { RCUTILS_LOG_WARN_NAMED("rmw_opensplice_cpp", - "service type contains '::srv::dds_::' but does not have a suffix" + "service type contains 'dds_::' but does not have a suffix" ", report this: '%s'", dds_type_name.c_str()); return ""; } - // everything checks out, reformat it from '::srv::dds_::' to '/' - std::string pkg = dds_type_name.substr(0, ns_substring_position); + // everything checks out, reformat it from '[namespace::]dds_::' + // to '[namespace/]' + std::string type_namespace = dds_type_name.substr(0, ns_substring_position); + type_namespace = std::regex_replace(type_namespace, std::regex("::"), "/"); size_t start = ns_substring_position + ns_substring.length(); std::string type_name = dds_type_name.substr(start, suffix_position - start); - return pkg + "/" + type_name; + return type_namespace + type_name; } diff --git a/rmw_opensplice_cpp/src/rmw_publisher.cpp b/rmw_opensplice_cpp/src/rmw_publisher.cpp index 900ba6bb..115270cc 100644 --- a/rmw_opensplice_cpp/src/rmw_publisher.cpp +++ b/rmw_opensplice_cpp/src/rmw_publisher.cpp @@ -126,7 +126,7 @@ rmw_create_publisher( RMW_SET_ERROR_MSG("callbacks handle is null"); return NULL; } - std::string type_name = create_type_name(callbacks, "msg"); + std::string type_name = create_type_name(callbacks); const char * error_string = callbacks->register_type(participant, type_name.c_str()); if (error_string) { diff --git a/rmw_opensplice_cpp/src/rmw_subscription.cpp b/rmw_opensplice_cpp/src/rmw_subscription.cpp index deca15b0..6626b4f1 100644 --- a/rmw_opensplice_cpp/src/rmw_subscription.cpp +++ b/rmw_opensplice_cpp/src/rmw_subscription.cpp @@ -126,7 +126,7 @@ rmw_create_subscription( RMW_SET_ERROR_MSG("callbacks handle is null"); return NULL; } - std::string type_name = create_type_name(callbacks, "msg"); + std::string type_name = create_type_name(callbacks); const char * error_string = callbacks->register_type(participant, type_name.c_str()); if (error_string) { diff --git a/rmw_opensplice_cpp/src/types.cpp b/rmw_opensplice_cpp/src/types.cpp index 20935dab..c64ded75 100644 --- a/rmw_opensplice_cpp/src/types.cpp +++ b/rmw_opensplice_cpp/src/types.cpp @@ -30,12 +30,9 @@ #include "namespace_prefix.hpp" std::string -create_type_name( - const message_type_support_callbacks_t * callbacks, - const std::string & sep) +create_type_name(const message_type_support_callbacks_t * callbacks) { - return std::string(callbacks->package_name) + - "::" + sep + "::dds_::" + callbacks->message_name + "_"; + return std::string(callbacks->message_namespace) + "::dds_::" + callbacks->message_name + "_"; } CustomDataReaderListener::CustomDataReaderListener() diff --git a/rmw_opensplice_cpp/src/types.hpp b/rmw_opensplice_cpp/src/types.hpp index d401fd5f..62168042 100644 --- a/rmw_opensplice_cpp/src/types.hpp +++ b/rmw_opensplice_cpp/src/types.hpp @@ -49,9 +49,7 @@ RMW_LOCAL std::string -create_type_name( - const message_type_support_callbacks_t * callbacks, - const std::string & sep); +create_type_name(const message_type_support_callbacks_t * callbacks); // The extern "C" here enforces that overloading is not used. extern "C"