From f17172a018c518e5fe74ff41ec7aaf3dfff53542 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Thu, 21 Mar 2019 14:06:06 -0700 Subject: [PATCH 1/9] Support arbitrary message namespaces Message type namespaces are no longer restricted to 'msg' and 'srv'. Signed-off-by: Jacob Perron --- rmw_fastrtps_cpp/src/rmw_client.cpp | 4 ++-- rmw_fastrtps_cpp/src/rmw_publisher.cpp | 2 +- rmw_fastrtps_cpp/src/rmw_service.cpp | 4 ++-- rmw_fastrtps_cpp/src/rmw_subscription.cpp | 2 +- rmw_fastrtps_cpp/src/type_support_common.cpp | 17 +++++++---------- rmw_fastrtps_cpp/src/type_support_common.hpp | 14 ++++++++++---- 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/rmw_fastrtps_cpp/src/rmw_client.cpp b/rmw_fastrtps_cpp/src/rmw_client.cpp index 74048cb908..928d7b9d82 100644 --- a/rmw_fastrtps_cpp/src/rmw_client.cpp +++ b/rmw_fastrtps_cpp/src/rmw_client.cpp @@ -105,8 +105,8 @@ rmw_create_client( response_members = static_cast( service_members->response_members_->data); - std::string request_type_name = _create_type_name(request_members, "srv"); - std::string response_type_name = _create_type_name(response_members, "srv"); + std::string request_type_name = _create_type_name(request_members); + std::string response_type_name = _create_type_name(response_members); if (!Domain::getRegisteredType(participant, request_type_name.c_str(), reinterpret_cast(&info->request_type_support_))) diff --git a/rmw_fastrtps_cpp/src/rmw_publisher.cpp b/rmw_fastrtps_cpp/src/rmw_publisher.cpp index 2c299f0bb0..baea75454b 100644 --- a/rmw_fastrtps_cpp/src/rmw_publisher.cpp +++ b/rmw_fastrtps_cpp/src/rmw_publisher.cpp @@ -128,7 +128,7 @@ rmw_create_publisher( info->typesupport_identifier_ = type_support->typesupport_identifier; auto callbacks = static_cast(type_support->data); - std::string type_name = _create_type_name(callbacks, "msg"); + std::string type_name = _create_type_name(callbacks); if (!Domain::getRegisteredType(participant, type_name.c_str(), reinterpret_cast(&info->type_support_))) { diff --git a/rmw_fastrtps_cpp/src/rmw_service.cpp b/rmw_fastrtps_cpp/src/rmw_service.cpp index 54b61b3869..035efba011 100644 --- a/rmw_fastrtps_cpp/src/rmw_service.cpp +++ b/rmw_fastrtps_cpp/src/rmw_service.cpp @@ -115,8 +115,8 @@ rmw_create_service( response_members = static_cast( service_members->response_members_->data); - std::string request_type_name = _create_type_name(request_members, "srv"); - std::string response_type_name = _create_type_name(response_members, "srv"); + std::string request_type_name = _create_type_name(request_members); + std::string response_type_name = _create_type_name(response_members); if (!Domain::getRegisteredType(participant, request_type_name.c_str(), reinterpret_cast(&info->request_type_support_))) diff --git a/rmw_fastrtps_cpp/src/rmw_subscription.cpp b/rmw_fastrtps_cpp/src/rmw_subscription.cpp index f219950013..c3d6d7bee1 100644 --- a/rmw_fastrtps_cpp/src/rmw_subscription.cpp +++ b/rmw_fastrtps_cpp/src/rmw_subscription.cpp @@ -131,7 +131,7 @@ rmw_create_subscription( info->typesupport_identifier_ = type_support->typesupport_identifier; auto callbacks = static_cast(type_support->data); - std::string type_name = _create_type_name(callbacks, "msg"); + std::string type_name = _create_type_name(callbacks); if (!Domain::getRegisteredType(participant, type_name.c_str(), reinterpret_cast(&info->type_support_))) { diff --git a/rmw_fastrtps_cpp/src/type_support_common.cpp b/rmw_fastrtps_cpp/src/type_support_common.cpp index 5869535d13..d7b7d85a8c 100644 --- a/rmw_fastrtps_cpp/src/type_support_common.cpp +++ b/rmw_fastrtps_cpp/src/type_support_common.cpp @@ -100,8 +100,7 @@ MessageTypeSupport::MessageTypeSupport(const message_type_support_callbacks_t * { assert(members); - std::string name = std::string(members->package_name_) + "::msg::dds_::" + - members->message_name_ + "_"; + std::string name = _create_type_name(members); this->setName(name.c_str()); set_members(members); @@ -115,12 +114,11 @@ RequestTypeSupport::RequestTypeSupport(const service_type_support_callbacks_t * { assert(members); - std::string name = std::string(members->package_name_) + "::srv::dds_::" + - members->service_name_ + "_Request_"; - this->setName(name.c_str()); - auto msg = static_cast( members->request_members_->data); + std::string name = _create_type_name(msg); // + "Request_"; + this->setName(name.c_str()); + set_members(msg); } @@ -128,12 +126,11 @@ ResponseTypeSupport::ResponseTypeSupport(const service_type_support_callbacks_t { assert(members); - std::string name = std::string(members->package_name_) + "::srv::dds_::" + - members->service_name_ + "_Response_"; - this->setName(name.c_str()); - auto msg = static_cast( members->response_members_->data); + std::string name = _create_type_name(msg); // + "Response_"; + this->setName(name.c_str()); + set_members(msg); } diff --git a/rmw_fastrtps_cpp/src/type_support_common.hpp b/rmw_fastrtps_cpp/src/type_support_common.hpp index 75af57fd6f..39e8cc1973 100644 --- a/rmw_fastrtps_cpp/src/type_support_common.hpp +++ b/rmw_fastrtps_cpp/src/type_support_common.hpp @@ -15,6 +15,7 @@ #ifndef TYPE_SUPPORT_COMMON_HPP_ #define TYPE_SUPPORT_COMMON_HPP_ +#include #include #include "fastrtps/Domain.h" @@ -43,15 +44,20 @@ using ResponseTypeSupport_cpp = rmw_fastrtps_cpp::ResponseTypeSupport; inline std::string _create_type_name( - const message_type_support_callbacks_t * members, - const std::string & sep) + const message_type_support_callbacks_t * members) { if (!members) { RMW_SET_ERROR_MSG("members handle is null"); return ""; } - return - std::string(members->package_name_) + "::" + sep + "::dds_::" + members->message_name_ + "_"; + std::ostringstream ss; + ss << members->package_name_ + << "::" + << members->type_namespace_ + << "::dds_::" + << members->message_name_ + << "_"; + return ss.str(); } inline void From 54de9b08f299a57f2b5411dd3e2cf68f44c8255e Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Thu, 21 Mar 2019 16:01:06 -0700 Subject: [PATCH 2/9] Update demangling logic for handling arbitrary ROS namespaces Signed-off-by: Jacob Perron --- rmw_fastrtps_shared_cpp/src/demangle.cpp | 41 +++++++++++++++--------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/rmw_fastrtps_shared_cpp/src/demangle.cpp b/rmw_fastrtps_shared_cpp/src/demangle.cpp index c6cc8906d6..cd1b7d0d42 100644 --- a/rmw_fastrtps_shared_cpp/src/demangle.cpp +++ b/rmw_fastrtps_shared_cpp/src/demangle.cpp @@ -13,6 +13,8 @@ // limitations under the License. #include +#include +#include #include #include @@ -32,19 +34,24 @@ _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_::"; - size_t substring_position = dds_type_string.find(substring); + std::regex dds_namespace_pattern("[^:]+((::.+::)+dds_::).*"); + std::smatch match; if ( - dds_type_string[dds_type_string.size() - 1] == '_' && - substring_position != std::string::npos) + dds_type_string[dds_type_string.size() - 1] != '_' || + !std::regex_match(dds_type_string, match, dds_namespace_pattern)) { - 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; + + // The first submatch is the whole string and the second is the parenthesized expression + assert(2u == match.size()); + std::string substring = match[1].str(); + size_t substring_position = dds_type_string.find(substring); + 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; } /// Return the service name for a given topic if it is part of one, else "". @@ -106,12 +113,16 @@ _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_::"; - size_t ns_substring_position = dds_type_name.find(ns_substring); - if (std::string::npos == ns_substring_position) { + std::regex dds_namespace_pattern(".*(::.*::dds_::).*"); + std::smatch match; + if (!std::regex_match(dds_type_name, match, dds_namespace_pattern)) { // not a ROS service type return ""; } + // The first submatch is the whole string and the second is the parenthesized expression + assert(2u == match.size()); + std::string ns_substring = match[1].str(); + size_t ns_substring_position = dds_type_name.find(ns_substring); auto suffixes = { std::string("_Response_"), std::string("_Request_"), @@ -123,7 +134,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_fastrtps_shared_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; } @@ -133,7 +144,7 @@ _demangle_service_type_only(const std::string & dds_type_name) } if (std::string::npos == suffix_position) { RCUTILS_LOG_WARN_NAMED("rmw_fastrtps_shared_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 ""; } From e2b36ec39a7cac1f54b17b944f055b78bda41d62 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Thu, 21 Mar 2019 16:45:37 -0700 Subject: [PATCH 3/9] Rename struct member Signed-off-by: Jacob Perron --- rmw_fastrtps_cpp/src/type_support_common.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rmw_fastrtps_cpp/src/type_support_common.hpp b/rmw_fastrtps_cpp/src/type_support_common.hpp index 39e8cc1973..a6049125d6 100644 --- a/rmw_fastrtps_cpp/src/type_support_common.hpp +++ b/rmw_fastrtps_cpp/src/type_support_common.hpp @@ -53,7 +53,7 @@ _create_type_name( std::ostringstream ss; ss << members->package_name_ << "::" - << members->type_namespace_ + << members->message_namespace_ << "::dds_::" << members->message_name_ << "_"; From a1eeadf4861586a3ff544b3e4dde14a85736423a Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Thu, 21 Mar 2019 17:28:09 -0700 Subject: [PATCH 4/9] Update assertion Signed-off-by: Jacob Perron --- rmw_fastrtps_shared_cpp/src/demangle.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rmw_fastrtps_shared_cpp/src/demangle.cpp b/rmw_fastrtps_shared_cpp/src/demangle.cpp index cd1b7d0d42..f8456d05ef 100644 --- a/rmw_fastrtps_shared_cpp/src/demangle.cpp +++ b/rmw_fastrtps_shared_cpp/src/demangle.cpp @@ -44,8 +44,9 @@ _demangle_if_ros_type(const std::string & dds_type_string) return dds_type_string; } - // The first submatch is the whole string and the second is the parenthesized expression - assert(2u == match.size()); + // The first submatch is the whole string, the second is the outer parenthesized expression + // and the third is the inner parenthesized expression + assert(3u == match.size()); std::string substring = match[1].str(); size_t substring_position = dds_type_string.find(substring); std::string pkg = dds_type_string.substr(0, substring_position); From 03c1d620530223eb9f8ed97be5b27c617d94814f Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Fri, 22 Mar 2019 16:39:52 -0700 Subject: [PATCH 5/9] Support arbitrary message namespace in rmw_fastrtps_dynamic_cpp Signed-off-by: Jacob Perron --- .../MessageTypeSupport_impl.hpp | 4 ++-- .../ServiceTypeSupport_impl.hpp | 8 ++++---- rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp | 4 ++-- .../src/rmw_publisher.cpp | 2 +- rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp | 4 ++-- .../src/rmw_subscription.cpp | 2 +- .../src/type_support_common.hpp | 19 ++++++++++++------- 7 files changed, 24 insertions(+), 19 deletions(-) diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp index 782645b0c6..6bc4f78c22 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp @@ -34,8 +34,8 @@ MessageTypeSupport::MessageTypeSupport(const MembersType * members) assert(members); this->members_ = members; - std::string name = std::string(members->package_name_) + "::msg::dds_::" + - members->message_name_ + "_"; + std::string name = std::string(this->members_->package_name_) + "::" + + this->members_->message_namespace_ + "::dds_::" + this->members_->message_name_ + "_"; this->setName(name.c_str()); // Fully bound by default diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp index 3451577f8b..009ada3d26 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp @@ -38,8 +38,8 @@ RequestTypeSupport::RequestTypeSupport( assert(members); this->members_ = members->request_members_; - std::string name = std::string(members->package_name_) + "::srv::dds_::" + - members->service_name_ + "_Request_"; + std::string name = std::string(this->members_->package_name_) + "::" + + this->members_->message_namespace_ + "::dds_::" + this->members_->message_name_ + "_"; this->setName(name.c_str()); // Fully bound by default @@ -60,8 +60,8 @@ ResponseTypeSupport::ResponseTypeSupport assert(members); this->members_ = members->response_members_; - std::string name = std::string(members->package_name_) + "::srv::dds_::" + - members->service_name_ + "_Response_"; + std::string name = std::string(this->members_->package_name_) + "::" + + this->members_->message_namespace_ + "::dds_::" + this->members_->message_name_ + "_"; this->setName(name.c_str()); // Fully bound by default diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp index 3121319eb4..586182bab5 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp @@ -108,9 +108,9 @@ rmw_create_client( untyped_response_members = get_response_ptr(type_support->data, info->typesupport_identifier_); - std::string request_type_name = _create_type_name(untyped_request_members, "srv", + std::string request_type_name = _create_type_name(untyped_request_members, info->typesupport_identifier_); - std::string response_type_name = _create_type_name(untyped_response_members, "srv", + std::string response_type_name = _create_type_name(untyped_response_members, info->typesupport_identifier_); if (!Domain::getRegisteredType(participant, request_type_name.c_str(), diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_publisher.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_publisher.cpp index ea78585bc1..4b3f89508b 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_publisher.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_publisher.cpp @@ -127,7 +127,7 @@ rmw_create_publisher( info->typesupport_identifier_ = type_support->typesupport_identifier; std::string type_name = _create_type_name( - type_support->data, "msg", info->typesupport_identifier_); + type_support->data, info->typesupport_identifier_); if (!Domain::getRegisteredType(participant, type_name.c_str(), reinterpret_cast(&info->type_support_))) { diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp index 86db427977..7a34d8c302 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp @@ -118,9 +118,9 @@ rmw_create_service( untyped_response_members = get_response_ptr(type_support->data, info->typesupport_identifier_); - std::string request_type_name = _create_type_name(untyped_request_members, "srv", + std::string request_type_name = _create_type_name(untyped_request_members, info->typesupport_identifier_); - std::string response_type_name = _create_type_name(untyped_response_members, "srv", + std::string response_type_name = _create_type_name(untyped_response_members, info->typesupport_identifier_); if (!Domain::getRegisteredType(participant, request_type_name.c_str(), diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_subscription.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_subscription.cpp index 93e35ea033..c44dec3609 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_subscription.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_subscription.cpp @@ -130,7 +130,7 @@ rmw_create_subscription( info->typesupport_identifier_ = type_support->typesupport_identifier; std::string type_name = _create_type_name( - type_support->data, "msg", info->typesupport_identifier_); + type_support->data, info->typesupport_identifier_); if (!Domain::getRegisteredType(participant, type_name.c_str(), reinterpret_cast(&info->type_support_))) { diff --git a/rmw_fastrtps_dynamic_cpp/src/type_support_common.hpp b/rmw_fastrtps_dynamic_cpp/src/type_support_common.hpp index 2469d92e97..e35887d1a0 100644 --- a/rmw_fastrtps_dynamic_cpp/src/type_support_common.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/type_support_common.hpp @@ -15,6 +15,7 @@ #ifndef TYPE_SUPPORT_COMMON_HPP_ #define TYPE_SUPPORT_COMMON_HPP_ +#include #include #include "fastrtps/Domain.h" @@ -72,31 +73,35 @@ template ROSIDL_TYPESUPPORT_INTROSPECTION_CPP_LOCAL inline std::string _create_type_name( - const void * untyped_members, - const std::string & sep) + const void * untyped_members) { auto members = static_cast(untyped_members); if (!members) { RMW_SET_ERROR_MSG("members handle is null"); return ""; } - return - std::string(members->package_name_) + "::" + sep + "::dds_::" + members->message_name_ + "_"; + std::ostringstream ss; + ss << members->package_name_ + << "::" + << members->message_namespace_ + << "::dds_::" + << members->message_name_ + << "_"; + return ss.str(); } ROSIDL_TYPESUPPORT_INTROSPECTION_CPP_LOCAL inline std::string _create_type_name( const void * untyped_members, - const std::string & sep, const char * typesupport) { if (using_introspection_c_typesupport(typesupport)) { return _create_type_name( - untyped_members, sep); + untyped_members); } else if (using_introspection_cpp_typesupport(typesupport)) { return _create_type_name( - untyped_members, sep); + untyped_members); } RMW_SET_ERROR_MSG("Unknown typesupport identifier"); return ""; From b5256e57e36c3d415662a48cad8a8021f8c7eb0c Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Thu, 2 May 2019 16:53:10 -0700 Subject: [PATCH 6/9] Combine package name with message namespace Signed-off-by: Jacob Perron --- rmw_fastrtps_cpp/src/type_support_common.hpp | 13 ++++--- .../MessageTypeSupport_impl.hpp | 12 ++++-- .../ServiceTypeSupport_impl.hpp | 23 ++++++++--- .../src/type_support_common.hpp | 13 ++++--- rmw_fastrtps_shared_cpp/src/demangle.cpp | 38 ++++++++----------- 5 files changed, 56 insertions(+), 43 deletions(-) diff --git a/rmw_fastrtps_cpp/src/type_support_common.hpp b/rmw_fastrtps_cpp/src/type_support_common.hpp index a6049125d6..7e3874e602 100644 --- a/rmw_fastrtps_cpp/src/type_support_common.hpp +++ b/rmw_fastrtps_cpp/src/type_support_common.hpp @@ -50,13 +50,14 @@ _create_type_name( RMW_SET_ERROR_MSG("members handle is null"); return ""; } + std::ostringstream ss; - ss << members->package_name_ - << "::" - << members->message_namespace_ - << "::dds_::" - << members->message_name_ - << "_"; + std::string message_namespace(members->message_namespace_); + std::string message_name(members->message_name_); + if (!message_namespace.empty()) { + ss << message_namespace << "::"; + } + ss << "dds_::" << message_name << "_"; return ss.str(); } diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp index 6bc4f78c22..e2b0446494 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp @@ -20,6 +20,7 @@ #include #include +#include #include #include "rmw_fastrtps_dynamic_cpp/MessageTypeSupport.hpp" @@ -34,9 +35,14 @@ MessageTypeSupport::MessageTypeSupport(const MembersType * members) assert(members); this->members_ = members; - std::string name = std::string(this->members_->package_name_) + "::" + - this->members_->message_namespace_ + "::dds_::" + this->members_->message_name_ + "_"; - this->setName(name.c_str()); + std::ostringstream ss; + std::string message_namespace(this->members_->message_namespace_); + std::string message_name(this->members_->message_name_); + if (!message_namespace.empty()) { + ss << message_namespace << "::"; + } + ss << "dds_::" << message_name << "_"; + this->setName(ss.str().c_str()); // Fully bound by default this->max_size_bound_ = true; diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp index 009ada3d26..00554df004 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "rmw_fastrtps_dynamic_cpp/ServiceTypeSupport.hpp" @@ -38,9 +39,14 @@ RequestTypeSupport::RequestTypeSupport( assert(members); this->members_ = members->request_members_; - std::string name = std::string(this->members_->package_name_) + "::" + - this->members_->message_namespace_ + "::dds_::" + this->members_->message_name_ + "_"; - this->setName(name.c_str()); + std::ostringstream ss; + std::string message_namespace(this->members_->message_namespace_); + std::string message_name(this->members_->message_name_); + if (!message_namespace.empty()) { + ss << message_namespace << "::"; + } + ss << "dds_::" << message_name << "_"; + this->setName(ss.str().c_str()); // Fully bound by default this->max_size_bound_ = true; @@ -60,9 +66,14 @@ ResponseTypeSupport::ResponseTypeSupport assert(members); this->members_ = members->response_members_; - std::string name = std::string(this->members_->package_name_) + "::" + - this->members_->message_namespace_ + "::dds_::" + this->members_->message_name_ + "_"; - this->setName(name.c_str()); + std::ostringstream ss; + std::string message_namespace(this->members_->message_namespace_); + std::string message_name(this->members_->message_name_); + if (!message_namespace.empty()) { + ss << message_namespace << "::"; + } + ss << "dds_::" << message_name << "_"; + this->setName(ss.str().c_str()); // Fully bound by default this->max_size_bound_ = true; diff --git a/rmw_fastrtps_dynamic_cpp/src/type_support_common.hpp b/rmw_fastrtps_dynamic_cpp/src/type_support_common.hpp index e35887d1a0..6212b22115 100644 --- a/rmw_fastrtps_dynamic_cpp/src/type_support_common.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/type_support_common.hpp @@ -80,13 +80,14 @@ _create_type_name( RMW_SET_ERROR_MSG("members handle is null"); return ""; } + std::ostringstream ss; - ss << members->package_name_ - << "::" - << members->message_namespace_ - << "::dds_::" - << members->message_name_ - << "_"; + std::string message_namespace(members->message_namespace_); + std::string message_name(members->message_name_); + if (!message_namespace.empty()) { + ss << message_namespace << "::"; + } + ss << "dds_::" << message_name << "_"; return ss.str(); } diff --git a/rmw_fastrtps_shared_cpp/src/demangle.cpp b/rmw_fastrtps_shared_cpp/src/demangle.cpp index f8456d05ef..5c9f79e00d 100644 --- a/rmw_fastrtps_shared_cpp/src/demangle.cpp +++ b/rmw_fastrtps_shared_cpp/src/demangle.cpp @@ -34,25 +34,21 @@ _demangle_if_ros_topic(const std::string & topic_name) std::string _demangle_if_ros_type(const std::string & dds_type_string) { - std::regex dds_namespace_pattern("[^:]+((::.+::)+dds_::).*"); - std::smatch match; + std::string substring = "dds_::"; + size_t substring_position = dds_type_string.find(substring); if ( dds_type_string[dds_type_string.size() - 1] != '_' || - !std::regex_match(dds_type_string, match, dds_namespace_pattern)) + substring_position == std::string::npos) { // not a ROS type return dds_type_string; } - // The first submatch is the whole string, the second is the outer parenthesized expression - // and the third is the inner parenthesized expression - assert(3u == match.size()); - std::string substring = match[1].str(); - size_t substring_position = dds_type_string.find(substring); - std::string pkg = dds_type_string.substr(0, substring_position); + 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 pkg + "/" + type_name; + return type_namespace + type_name; } /// Return the service name for a given topic if it is part of one, else "". @@ -114,16 +110,12 @@ _demangle_service_from_topic(const std::string & topic_name) std::string _demangle_service_type_only(const std::string & dds_type_name) { - std::regex dds_namespace_pattern(".*(::.*::dds_::).*"); - std::smatch match; - if (!std::regex_match(dds_type_name, match, dds_namespace_pattern)) { + std::string ns_substring = "dds_::"; + size_t ns_substring_position = dds_type_name.find(ns_substring); + if (std::string::npos == ns_substring_position) { // not a ROS service type return ""; } - // The first submatch is the whole string and the second is the parenthesized expression - assert(2u == match.size()); - std::string ns_substring = match[1].str(); - size_t ns_substring_position = dds_type_name.find(ns_substring); auto suffixes = { std::string("_Response_"), std::string("_Request_"), @@ -135,7 +127,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_fastrtps_shared_cpp", - "service type contains '::*::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; } @@ -145,13 +137,15 @@ _demangle_service_type_only(const std::string & dds_type_name) } if (std::string::npos == suffix_position) { RCUTILS_LOG_WARN_NAMED("rmw_fastrtps_shared_cpp", - "service type contains '::*::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 '[type_namespace::]dds_::' + // to '[type_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; } From a29782d1c0a28a889975e995f7e101de6ace91c7 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Mon, 6 May 2019 14:08:06 -0700 Subject: [PATCH 7/9] Fix bugs Signed-off-by: Jacob Perron --- .../MessageTypeSupport_impl.hpp | 3 +++ .../ServiceTypeSupport_impl.hpp | 25 +++++++++++-------- .../src/type_support_common.hpp | 3 +++ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp index e2b0446494..ec94a8a786 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/MessageTypeSupport_impl.hpp @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -39,6 +40,8 @@ MessageTypeSupport::MessageTypeSupport(const MembersType * members) std::string message_namespace(this->members_->message_namespace_); std::string message_name(this->members_->message_name_); if (!message_namespace.empty()) { + // Find and replace C namespace separator with C++, in case this is using C typesupport + message_namespace = std::regex_replace(message_namespace, std::regex("__"), "::"); ss << message_namespace << "::"; } ss << "dds_::" << message_name << "_"; diff --git a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp index 00554df004..3d7363ef01 100644 --- a/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp +++ b/rmw_fastrtps_dynamic_cpp/include/rmw_fastrtps_dynamic_cpp/ServiceTypeSupport_impl.hpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -40,12 +41,14 @@ RequestTypeSupport::RequestTypeSupport( this->members_ = members->request_members_; std::ostringstream ss; - std::string message_namespace(this->members_->message_namespace_); - std::string message_name(this->members_->message_name_); - if (!message_namespace.empty()) { - ss << message_namespace << "::"; + std::string service_namespace(members->service_namespace_); + std::string service_name(members->service_name_); + if (!service_namespace.empty()) { + // Find and replace C namespace separator with C++, in case this is using C typesupport + service_namespace = std::regex_replace(service_namespace, std::regex("__"), "::"); + ss << service_namespace << "::"; } - ss << "dds_::" << message_name << "_"; + ss << "dds_::" << service_name << "_Request_"; this->setName(ss.str().c_str()); // Fully bound by default @@ -67,12 +70,14 @@ ResponseTypeSupport::ResponseTypeSupport this->members_ = members->response_members_; std::ostringstream ss; - std::string message_namespace(this->members_->message_namespace_); - std::string message_name(this->members_->message_name_); - if (!message_namespace.empty()) { - ss << message_namespace << "::"; + std::string service_namespace(members->service_namespace_); + std::string service_name(members->service_name_); + if (!service_namespace.empty()) { + // Find and replace C namespace separator with C++, in case this is using C typesupport + service_namespace = std::regex_replace(service_namespace, std::regex("__"), "::"); + ss << service_namespace << "::"; } - ss << "dds_::" << message_name << "_"; + ss << "dds_::" << service_name << "_Response_"; this->setName(ss.str().c_str()); // Fully bound by default diff --git a/rmw_fastrtps_dynamic_cpp/src/type_support_common.hpp b/rmw_fastrtps_dynamic_cpp/src/type_support_common.hpp index 6212b22115..3ace81127f 100644 --- a/rmw_fastrtps_dynamic_cpp/src/type_support_common.hpp +++ b/rmw_fastrtps_dynamic_cpp/src/type_support_common.hpp @@ -15,6 +15,7 @@ #ifndef TYPE_SUPPORT_COMMON_HPP_ #define TYPE_SUPPORT_COMMON_HPP_ +#include #include #include @@ -83,6 +84,8 @@ _create_type_name( std::ostringstream ss; std::string message_namespace(members->message_namespace_); + // Find and replace C namespace separator with C++, in case this is using C typesupport + message_namespace = std::regex_replace(message_namespace, std::regex("__"), "::"); std::string message_name(members->message_name_); if (!message_namespace.empty()) { ss << message_namespace << "::"; From 3f346677a643f5f87e0060319bccc7230733d427 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Tue, 7 May 2019 15:21:49 -0700 Subject: [PATCH 8/9] Address review Signed-off-by: Jacob Perron --- rmw_fastrtps_shared_cpp/src/demangle.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/rmw_fastrtps_shared_cpp/src/demangle.cpp b/rmw_fastrtps_shared_cpp/src/demangle.cpp index 5c9f79e00d..aaeee5a05b 100644 --- a/rmw_fastrtps_shared_cpp/src/demangle.cpp +++ b/rmw_fastrtps_shared_cpp/src/demangle.cpp @@ -13,7 +13,6 @@ // limitations under the License. #include -#include #include #include #include @@ -34,11 +33,14 @@ _demangle_if_ros_topic(const std::string & topic_name) std::string _demangle_if_ros_type(const std::string & dds_type_string) { + if (dds_type_string[dds_type_string.size() - 1] != '_') { + // not a ROS type + return dds_type_string; + } + 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) + if (substring_position == std::string::npos) { // not a ROS type return dds_type_string; From 419a3cf8c66286108d5e57c496ee0b054dec41cf Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Tue, 7 May 2019 22:21:24 -0700 Subject: [PATCH 9/9] fix style Signed-off-by: Dirk Thomas --- rmw_fastrtps_shared_cpp/src/demangle.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/rmw_fastrtps_shared_cpp/src/demangle.cpp b/rmw_fastrtps_shared_cpp/src/demangle.cpp index aaeee5a05b..e5c28e7655 100644 --- a/rmw_fastrtps_shared_cpp/src/demangle.cpp +++ b/rmw_fastrtps_shared_cpp/src/demangle.cpp @@ -34,14 +34,13 @@ std::string _demangle_if_ros_type(const std::string & dds_type_string) { if (dds_type_string[dds_type_string.size() - 1] != '_') { - // not a ROS type - return dds_type_string; + // not a ROS type + return dds_type_string; } std::string substring = "dds_::"; size_t substring_position = dds_type_string.find(substring); - if (substring_position == std::string::npos) - { + if (substring_position == std::string::npos) { // not a ROS type return dds_type_string; }