From 9b264c64801467767f039bef664a61f77e11e084 Mon Sep 17 00:00:00 2001 From: Dan Rose Date: Fri, 6 Dec 2019 11:23:47 -0600 Subject: [PATCH] Clean up topic namespace prefixes (#76) Signed-off-by: Dan Rose --- rmw_cyclonedds_cpp/CMakeLists.txt | 1 - rmw_cyclonedds_cpp/src/namespace_prefix.cpp | 41 --------------------- rmw_cyclonedds_cpp/src/namespace_prefix.hpp | 20 ++-------- rmw_cyclonedds_cpp/src/rmw_node.cpp | 20 +++++----- 4 files changed, 14 insertions(+), 68 deletions(-) delete mode 100644 rmw_cyclonedds_cpp/src/namespace_prefix.cpp diff --git a/rmw_cyclonedds_cpp/CMakeLists.txt b/rmw_cyclonedds_cpp/CMakeLists.txt index 66daf8d..fe819f1 100644 --- a/rmw_cyclonedds_cpp/CMakeLists.txt +++ b/rmw_cyclonedds_cpp/CMakeLists.txt @@ -49,7 +49,6 @@ ament_export_dependencies(rosidl_typesupport_introspection_c) ament_export_dependencies(rosidl_typesupport_introspection_cpp) add_library(rmw_cyclonedds_cpp - src/namespace_prefix.cpp src/rmw_node.cpp src/serdata.cpp src/serdes.cpp diff --git a/rmw_cyclonedds_cpp/src/namespace_prefix.cpp b/rmw_cyclonedds_cpp/src/namespace_prefix.cpp deleted file mode 100644 index 16600fd..0000000 --- a/rmw_cyclonedds_cpp/src/namespace_prefix.cpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include - -#include "namespace_prefix.hpp" - -extern "C" -{ -// static for internal linkage -const char * const ros_topic_prefix = "rt"; -const char * const ros_service_requester_prefix = "rq"; -const char * const ros_service_response_prefix = "rr"; - -const std::vector _ros_prefixes = -{ros_topic_prefix, ros_service_requester_prefix, ros_service_response_prefix}; -} // extern "C" - -/// Return the ROS specific prefix if it exists, otherwise "". -std::string -_get_ros_prefix_if_exists(const std::string & topic_name) -{ - for (auto prefix : _ros_prefixes) { - if (topic_name.rfind(std::string(prefix) + "/", 0) == 0) { - return prefix; - } - } - return ""; -} diff --git a/rmw_cyclonedds_cpp/src/namespace_prefix.hpp b/rmw_cyclonedds_cpp/src/namespace_prefix.hpp index 8f8172f..ebe40d4 100644 --- a/rmw_cyclonedds_cpp/src/namespace_prefix.hpp +++ b/rmw_cyclonedds_cpp/src/namespace_prefix.hpp @@ -1,4 +1,4 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// Copyright 2019 ADLINK Technology Limited. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,20 +15,8 @@ #ifndef NAMESPACE_PREFIX_HPP_ #define NAMESPACE_PREFIX_HPP_ -#include -#include - -extern "C" -{ -extern const char * const ros_topic_prefix; -extern const char * const ros_service_requester_prefix; -extern const char * const ros_service_response_prefix; - -extern const std::vector _ros_prefixes; -} // extern "C" - -/// Return the ROS specific prefix if it exists, otherwise "". -std::string -_get_ros_prefix_if_exists(const std::string & topic_name); +static const char ROS_TOPIC_PREFIX[] = "rt"; +static const char ROS_SERVICE_REQUESTER_PREFIX[] = "rq"; +static const char ROS_SERVICE_RESPONSE_PREFIX[] = "rr"; #endif // NAMESPACE_PREFIX_HPP_ diff --git a/rmw_cyclonedds_cpp/src/rmw_node.cpp b/rmw_cyclonedds_cpp/src/rmw_node.cpp index 0bdf5c0..de8ae00 100644 --- a/rmw_cyclonedds_cpp/src/rmw_node.cpp +++ b/rmw_cyclonedds_cpp/src/rmw_node.cpp @@ -1210,7 +1210,7 @@ static CddsPublisher * create_cdds_publisher( dds_entity_t topic; dds_qos_t * qos; - std::string fqtopic_name = make_fqtopic(ros_topic_prefix, topic_name, "", qos_policies); + std::string fqtopic_name = make_fqtopic(ROS_TOPIC_PREFIX, topic_name, "", qos_policies); auto sertopic = create_sertopic( fqtopic_name.c_str(), type_support->typesupport_identifier, @@ -1432,7 +1432,7 @@ static CddsSubscription * create_cdds_subscription( dds_entity_t topic; dds_qos_t * qos; - std::string fqtopic_name = make_fqtopic(ros_topic_prefix, topic_name, "", qos_policies); + std::string fqtopic_name = make_fqtopic(ROS_TOPIC_PREFIX, topic_name, "", qos_policies); auto sertopic = create_sertopic( fqtopic_name.c_str(), type_support->typesupport_identifier, @@ -2333,8 +2333,8 @@ static rmw_ret_t rmw_init_cs( pub_type_support = create_response_type_support(type_support->data, type_support->typesupport_identifier); subtopic_name = - make_fqtopic(ros_service_requester_prefix, service_name, "Request", qos_policies); - pubtopic_name = make_fqtopic(ros_service_response_prefix, service_name, "Reply", qos_policies); + make_fqtopic(ROS_SERVICE_REQUESTER_PREFIX, service_name, "Request", qos_policies); + pubtopic_name = make_fqtopic(ROS_SERVICE_RESPONSE_PREFIX, service_name, "Reply", qos_policies); } else { std::tie(pub_msg_ts, sub_msg_ts) = rmw_cyclonedds_cpp::make_request_response_value_types(type_supports); @@ -2344,8 +2344,8 @@ static rmw_ret_t rmw_init_cs( sub_type_support = create_response_type_support(type_support->data, type_support->typesupport_identifier); pubtopic_name = - make_fqtopic(ros_service_requester_prefix, service_name, "Request", qos_policies); - subtopic_name = make_fqtopic(ros_service_response_prefix, service_name, "Reply", qos_policies); + make_fqtopic(ROS_SERVICE_REQUESTER_PREFIX, service_name, "Request", qos_policies); + subtopic_name = make_fqtopic(ROS_SERVICE_RESPONSE_PREFIX, service_name, "Reply", qos_policies); } RCUTILS_LOG_DEBUG_NAMED("rmw_cyclonedds_cpp", "************ %s Details *********", @@ -2781,7 +2781,7 @@ static rmw_ret_t get_endpoint_names_and_types_by_node( return ret; } const auto re_tp = - std::regex("^" + std::string(ros_topic_prefix) + "(/.*)", std::regex::extended); + std::regex("^" + std::string(ROS_TOPIC_PREFIX) + "(/.*)", std::regex::extended); const auto re_typ = std::regex("^(.*::)dds_::(.*)_$", std::regex::extended); const auto filter_and_map = [re_tp, re_typ, guids, node_name, no_demangle](const dds_builtintopic_endpoint_t & sample, @@ -2872,8 +2872,8 @@ static rmw_ret_t get_cs_names_and_types_by_node( return ret; } const auto re_tp = std::regex( - "^(" + std::string(ros_service_requester_prefix) + "|" + - std::string(ros_service_response_prefix) + ")(/.*)(Request|Reply)$", + "^(" + std::string(ROS_SERVICE_REQUESTER_PREFIX) + "|" + + std::string(ROS_SERVICE_RESPONSE_PREFIX) + ")(/.*)(Request|Reply)$", std::regex::extended); const auto re_typ = std::regex("^(.*::)dds_::(.*)_(Response|Request)_$", std::regex::extended); const auto filter_and_map = [re_tp, re_typ, guids, node_name, looking_for_services]( @@ -2966,7 +2966,7 @@ static rmw_ret_t rmw_count_pubs_or_subs( RET_WRONG_IMPLID(node); auto node_impl = static_cast(node->data); - std::string fqtopic_name = make_fqtopic(ros_topic_prefix, topic_name, "", false); + std::string fqtopic_name = make_fqtopic(ROS_TOPIC_PREFIX, topic_name, "", false); dds_entity_t rd; if ((rd = dds_create_reader(node_impl->pp, builtin_topic, NULL, NULL)) < 0) { RMW_SET_ERROR_MSG("rmw_count_pubs_or_subs failed to create reader");