Clean up topic namespace prefixes (#76)

Signed-off-by: Dan Rose <dan@digilabs.io>
This commit is contained in:
Dan Rose 2019-12-06 11:23:47 -06:00 committed by GitHub
parent b322f478de
commit 9b264c6480
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 68 deletions

View file

@ -49,7 +49,6 @@ ament_export_dependencies(rosidl_typesupport_introspection_c)
ament_export_dependencies(rosidl_typesupport_introspection_cpp) ament_export_dependencies(rosidl_typesupport_introspection_cpp)
add_library(rmw_cyclonedds_cpp add_library(rmw_cyclonedds_cpp
src/namespace_prefix.cpp
src/rmw_node.cpp src/rmw_node.cpp
src/serdata.cpp src/serdata.cpp
src/serdes.cpp src/serdes.cpp

View file

@ -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 <string>
#include <vector>
#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<std::string> _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 "";
}

View file

@ -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"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -15,20 +15,8 @@
#ifndef NAMESPACE_PREFIX_HPP_ #ifndef NAMESPACE_PREFIX_HPP_
#define NAMESPACE_PREFIX_HPP_ #define NAMESPACE_PREFIX_HPP_
#include <vector> static const char ROS_TOPIC_PREFIX[] = "rt";
#include <string> static const char ROS_SERVICE_REQUESTER_PREFIX[] = "rq";
static const char ROS_SERVICE_RESPONSE_PREFIX[] = "rr";
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<std::string> _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);
#endif // NAMESPACE_PREFIX_HPP_ #endif // NAMESPACE_PREFIX_HPP_

View file

@ -1210,7 +1210,7 @@ static CddsPublisher * create_cdds_publisher(
dds_entity_t topic; dds_entity_t topic;
dds_qos_t * qos; 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( auto sertopic = create_sertopic(
fqtopic_name.c_str(), type_support->typesupport_identifier, fqtopic_name.c_str(), type_support->typesupport_identifier,
@ -1432,7 +1432,7 @@ static CddsSubscription * create_cdds_subscription(
dds_entity_t topic; dds_entity_t topic;
dds_qos_t * qos; 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( auto sertopic = create_sertopic(
fqtopic_name.c_str(), type_support->typesupport_identifier, 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, pub_type_support = create_response_type_support(type_support->data,
type_support->typesupport_identifier); type_support->typesupport_identifier);
subtopic_name = subtopic_name =
make_fqtopic(ros_service_requester_prefix, service_name, "Request", 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); pubtopic_name = make_fqtopic(ROS_SERVICE_RESPONSE_PREFIX, service_name, "Reply", qos_policies);
} else { } else {
std::tie(pub_msg_ts, sub_msg_ts) = std::tie(pub_msg_ts, sub_msg_ts) =
rmw_cyclonedds_cpp::make_request_response_value_types(type_supports); 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, sub_type_support = create_response_type_support(type_support->data,
type_support->typesupport_identifier); type_support->typesupport_identifier);
pubtopic_name = pubtopic_name =
make_fqtopic(ros_service_requester_prefix, service_name, "Request", 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); subtopic_name = make_fqtopic(ROS_SERVICE_RESPONSE_PREFIX, service_name, "Reply", qos_policies);
} }
RCUTILS_LOG_DEBUG_NAMED("rmw_cyclonedds_cpp", "************ %s Details *********", 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; return ret;
} }
const auto re_tp = 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 re_typ = std::regex("^(.*::)dds_::(.*)_$", std::regex::extended);
const auto filter_and_map = const auto filter_and_map =
[re_tp, re_typ, guids, node_name, no_demangle](const dds_builtintopic_endpoint_t & sample, [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; return ret;
} }
const auto re_tp = std::regex( const auto re_tp = std::regex(
"^(" + std::string(ros_service_requester_prefix) + "|" + "^(" + std::string(ROS_SERVICE_REQUESTER_PREFIX) + "|" +
std::string(ros_service_response_prefix) + ")(/.*)(Request|Reply)$", std::string(ROS_SERVICE_RESPONSE_PREFIX) + ")(/.*)(Request|Reply)$",
std::regex::extended); std::regex::extended);
const auto re_typ = std::regex("^(.*::)dds_::(.*)_(Response|Request)_$", 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]( 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); RET_WRONG_IMPLID(node);
auto node_impl = static_cast<CddsNode *>(node->data); auto node_impl = static_cast<CddsNode *>(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; dds_entity_t rd;
if ((rd = dds_create_reader(node_impl->pp, builtin_topic, NULL, NULL)) < 0) { 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"); RMW_SET_ERROR_MSG("rmw_count_pubs_or_subs failed to create reader");