From a33f9f8de78b0db1695a3a446f448ee873739a7e Mon Sep 17 00:00:00 2001 From: Rohit Salem Date: Thu, 7 Jun 2018 14:13:17 -0700 Subject: [PATCH] Remove topic partitions (#192) * removed the use of partitions, use the complete topic_name directly Removed assign_partitions.hpp header trial: removal of topic partitions from services and client Modified readerinfo, writerinfo and added prefix to the topic names. * Changed topic namespacing in services and clients minor style changes Delete assign_partitions.hpp and removed anything related to partitons re-adding avoid_ros_namespace_conventions check for prefixing names Corrected indentation Added vertical space between the headers * remove unnecessary initializations --- .../include/rmw_fastrtps_cpp/reader_info.hpp | 7 +- .../include/rmw_fastrtps_cpp/writer_info.hpp | 7 +- rmw_fastrtps_cpp/src/assign_partitions.hpp | 76 ------------------- rmw_fastrtps_cpp/src/rmw_client.cpp | 27 ++----- rmw_fastrtps_cpp/src/rmw_publisher.cpp | 11 +-- rmw_fastrtps_cpp/src/rmw_service.cpp | 28 +++---- .../src/rmw_service_server_is_available.cpp | 28 +------ rmw_fastrtps_cpp/src/rmw_subscription.cpp | 11 +-- 8 files changed, 31 insertions(+), 164 deletions(-) delete mode 100644 rmw_fastrtps_cpp/src/assign_partitions.hpp diff --git a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/reader_info.hpp b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/reader_info.hpp index 5862af49f..733068624 100644 --- a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/reader_info.hpp +++ b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/reader_info.hpp @@ -71,12 +71,7 @@ class ReaderInfo : public eprosima::fastrtps::rtps::ReaderListener } } - auto partition_str = std::string(""); - // don't use std::accumulate - schlemiel O(n2) - for (const auto & partition : proxyData.m_qos.m_partition.getNames()) { - partition_str += partition; - } - auto fqdn = partition_str + "/" + proxyData.topicName(); + auto fqdn = proxyData.topicName(); bool trigger = false; mapmutex.lock(); diff --git a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/writer_info.hpp b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/writer_info.hpp index 8a6f1e46c..e51604380 100644 --- a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/writer_info.hpp +++ b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/writer_info.hpp @@ -69,12 +69,7 @@ class WriterInfo : public eprosima::fastrtps::rtps::ReaderListener } } - auto partition_str = std::string(""); - // don't use std::accumulate - schlemiel O(n2) - for (const auto & partition : proxyData.m_qos.m_partition.getNames()) { - partition_str += partition; - } - auto fqdn = partition_str + "/" + proxyData.topicName(); + auto fqdn = proxyData.topicName(); bool trigger = false; mapmutex.lock(); diff --git a/rmw_fastrtps_cpp/src/assign_partitions.hpp b/rmw_fastrtps_cpp/src/assign_partitions.hpp deleted file mode 100644 index c6c2fd764..000000000 --- a/rmw_fastrtps_cpp/src/assign_partitions.hpp +++ /dev/null @@ -1,76 +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. - -#ifndef ASSIGN_PARTITIONS_HPP_ -#define ASSIGN_PARTITIONS_HPP_ - -#include - -#include "rcutils/allocator.h" -#include "rcutils/error_handling.h" -#include "rcutils/logging_macros.h" -#include "rcutils/split.h" -#include "rcutils/types.h" - -#include "rmw/error_handling.h" - -template -inline -rcutils_ret_t -_assign_partitions_to_attributes( - const char * const topic_name, - const char * const prefix, - bool avoid_ros_namespace_conventions, - AttributeT * attributes) -{ - rcutils_ret_t ret = RCUTILS_RET_ERROR; - auto allocator = rcutils_get_default_allocator(); - - // set topic and partitions - rcutils_string_array_t name_tokens = rcutils_get_zero_initialized_string_array(); - ret = rcutils_split_last(topic_name, '/', allocator, &name_tokens); - if (ret != RCUTILS_RET_OK) { - RMW_SET_ERROR_MSG(rcutils_get_error_string_safe()); - return ret; - } - if (1 == name_tokens.size) { - if (!avoid_ros_namespace_conventions) { - attributes->qos.m_partition.push_back(prefix); - } - attributes->topic.topicName = name_tokens.data[0]; - ret = RCUTILS_RET_OK; - } else if (2 == name_tokens.size) { - std::string partition; - if (avoid_ros_namespace_conventions) { - // no prefix to be used, just assign the user's namespace - partition = name_tokens.data[0]; - } else { - // concat the prefix with the user's namespace - partition = std::string(prefix) + "/" + name_tokens.data[0]; - } - attributes->qos.m_partition.push_back(partition.c_str()); - attributes->topic.topicName = name_tokens.data[1]; - ret = RCUTILS_RET_OK; - } else { - RMW_SET_ERROR_MSG("Malformed topic name"); - ret = RCUTILS_RET_ERROR; - } - if (rcutils_string_array_fini(&name_tokens) != RCUTILS_RET_OK) { - RCUTILS_LOG_ERROR_NAMED("rmw_fastrtps_cpp", "Failed to destroy the token string array") - ret = RCUTILS_RET_ERROR; - } - return ret; -} - -#endif // ASSIGN_PARTITIONS_HPP_ diff --git a/rmw_fastrtps_cpp/src/rmw_client.cpp b/rmw_fastrtps_cpp/src/rmw_client.cpp index bf75d570c..e7f111285 100644 --- a/rmw_fastrtps_cpp/src/rmw_client.cpp +++ b/rmw_fastrtps_cpp/src/rmw_client.cpp @@ -23,7 +23,6 @@ #include "rosidl_typesupport_introspection_c/identifier.h" -#include "assign_partitions.hpp" #include "client_service_common.hpp" #include "rmw_fastrtps_cpp/identifier.hpp" #include "namespace_prefix.hpp" @@ -129,12 +128,10 @@ rmw_create_client( subscriberParam.topic.topicDataType = response_type_name; subscriberParam.historyMemoryPolicy = eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; - rcutils_ret_t ret = _assign_partitions_to_attributes( - service_name, ros_service_response_prefix, - qos_policies->avoid_ros_namespace_conventions, &subscriberParam); - if (ret != RCUTILS_RET_OK) { - // error msg already set - goto fail; + if (!qos_policies->avoid_ros_namespace_conventions) { + subscriberParam.topic.topicName = std::string(ros_service_response_prefix) + service_name; + } else { + subscriberParam.topic.topicName = service_name; } subscriberParam.topic.topicName += "Reply"; @@ -143,12 +140,10 @@ rmw_create_client( publisherParam.qos.m_publishMode.kind = eprosima::fastrtps::ASYNCHRONOUS_PUBLISH_MODE; publisherParam.historyMemoryPolicy = eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; - ret = _assign_partitions_to_attributes( - service_name, ros_service_requester_prefix, - qos_policies->avoid_ros_namespace_conventions, &publisherParam); - if (ret != RCUTILS_RET_OK) { - // error msg already set - goto fail; + if (!qos_policies->avoid_ros_namespace_conventions) { + publisherParam.topic.topicName = std::string(ros_service_requester_prefix) + service_name; + } else { + publisherParam.topic.topicName = service_name; } publisherParam.topic.topicName += "Request"; @@ -158,15 +153,9 @@ rmw_create_client( RCUTILS_LOG_DEBUG_NAMED( "rmw_fastrtps_cpp", "Sub Topic %s", subscriberParam.topic.topicName.c_str()) - RCUTILS_LOG_DEBUG_NAMED( - "rmw_fastrtps_cpp", - "Sub Partition %s", subscriberParam.qos.m_partition.getNames()[0].c_str()) RCUTILS_LOG_DEBUG_NAMED( "rmw_fastrtps_cpp", "Pub Topic %s", publisherParam.topic.topicName.c_str()) - RCUTILS_LOG_DEBUG_NAMED( - "rmw_fastrtps_cpp", - "Pub Partition %s", publisherParam.qos.m_partition.getNames()[0].c_str()) RCUTILS_LOG_DEBUG_NAMED("rmw_fastrtps_cpp", "***********") // Create Client Subscriber and set QoS diff --git a/rmw_fastrtps_cpp/src/rmw_publisher.cpp b/rmw_fastrtps_cpp/src/rmw_publisher.cpp index eeb292e4f..490569ec2 100644 --- a/rmw_fastrtps_cpp/src/rmw_publisher.cpp +++ b/rmw_fastrtps_cpp/src/rmw_publisher.cpp @@ -18,7 +18,6 @@ #include "rmw/error_handling.h" #include "rmw/rmw.h" -#include "assign_partitions.hpp" #include "rmw_fastrtps_cpp/identifier.hpp" #include "namespace_prefix.hpp" #include "qos.hpp" @@ -108,12 +107,10 @@ rmw_create_publisher( eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; publisherParam.topic.topicKind = eprosima::fastrtps::rtps::NO_KEY; publisherParam.topic.topicDataType = type_name; - rcutils_ret_t ret = _assign_partitions_to_attributes( - topic_name, ros_topic_prefix, - qos_policies->avoid_ros_namespace_conventions, &publisherParam); - if (ret != RCUTILS_RET_OK) { - // error msg already set - goto fail; + if (!qos_policies->avoid_ros_namespace_conventions) { + publisherParam.topic.topicName = std::string(ros_topic_prefix) + topic_name; + } else { + publisherParam.topic.topicName = topic_name; } // 1 Heartbeat every 10ms diff --git a/rmw_fastrtps_cpp/src/rmw_service.cpp b/rmw_fastrtps_cpp/src/rmw_service.cpp index 7f9cb1e58..161a0300c 100644 --- a/rmw_fastrtps_cpp/src/rmw_service.cpp +++ b/rmw_fastrtps_cpp/src/rmw_service.cpp @@ -31,9 +31,9 @@ #include "rmw/rmw.h" #include "rosidl_typesupport_introspection_cpp/identifier.hpp" + #include "rosidl_typesupport_introspection_c/identifier.h" -#include "assign_partitions.hpp" #include "client_service_common.hpp" #include "rmw_fastrtps_cpp/identifier.hpp" #include "namespace_prefix.hpp" @@ -139,12 +139,10 @@ rmw_create_service( subscriberParam.historyMemoryPolicy = eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; subscriberParam.topic.topicDataType = request_type_name; - rcutils_ret_t ret = _assign_partitions_to_attributes( - service_name, ros_service_requester_prefix, - qos_policies->avoid_ros_namespace_conventions, &subscriberParam); - if (ret != RCUTILS_RET_OK) { - // error msg already set - goto fail; + if (!qos_policies->avoid_ros_namespace_conventions) { + subscriberParam.topic.topicName = std::string(ros_service_requester_prefix) + service_name; + } else { + subscriberParam.topic.topicName = service_name; } subscriberParam.topic.topicName += "Request"; @@ -153,12 +151,10 @@ rmw_create_service( publisherParam.qos.m_publishMode.kind = eprosima::fastrtps::ASYNCHRONOUS_PUBLISH_MODE; publisherParam.historyMemoryPolicy = eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; - ret = _assign_partitions_to_attributes( - service_name, ros_service_response_prefix, - qos_policies->avoid_ros_namespace_conventions, &publisherParam); - if (ret != RCUTILS_RET_OK) { - // error msg already set - goto fail; + if (!qos_policies->avoid_ros_namespace_conventions) { + publisherParam.topic.topicName = std::string(ros_service_response_prefix) + service_name; + } else { + publisherParam.topic.topicName = service_name; } publisherParam.topic.topicName += "Reply"; @@ -168,15 +164,9 @@ rmw_create_service( RCUTILS_LOG_DEBUG_NAMED( "rmw_fastrtps_cpp", "Sub Topic %s", subscriberParam.topic.topicName.c_str()) - RCUTILS_LOG_DEBUG_NAMED( - "rmw_fastrtps_cpp", - "Sub Partition %s", subscriberParam.qos.m_partition.getNames()[0].c_str()) RCUTILS_LOG_DEBUG_NAMED( "rmw_fastrtps_cpp", "Pub Topic %s", publisherParam.topic.topicName.c_str()) - RCUTILS_LOG_DEBUG_NAMED( - "rmw_fastrtps_cpp", - "Pub Partition %s", publisherParam.qos.m_partition.getNames()[0].c_str()) RCUTILS_LOG_DEBUG_NAMED("rmw_fastrtps_cpp", "***********") // Create Service Subscriber and set QoS diff --git a/rmw_fastrtps_cpp/src/rmw_service_server_is_available.cpp b/rmw_fastrtps_cpp/src/rmw_service_server_is_available.cpp index 0aead8ffd..734f55551 100644 --- a/rmw_fastrtps_cpp/src/rmw_service_server_is_available.cpp +++ b/rmw_fastrtps_cpp/src/rmw_service_server_is_available.cpp @@ -64,33 +64,13 @@ rmw_service_server_is_available( auto pub_topic_name = client_info->request_publisher_->getAttributes().topic.getTopicName(); - auto pub_partitions = - client_info->request_publisher_->getAttributes().qos.m_partition.getNames(); - // every rostopic has exactly 1 partition field set - if (pub_partitions.size() != 1) { - RCUTILS_LOG_ERROR_NAMED( - "rmw_fastrtps_cpp", - "Topic %s is not a ros topic", pub_topic_name.c_str()) - RMW_SET_ERROR_MSG((std::string(pub_topic_name) + " is a non-ros topic\n").c_str()); - return RMW_RET_ERROR; - } - auto pub_fqdn = pub_partitions[0] + "/" + pub_topic_name; - pub_fqdn = _demangle_if_ros_topic(pub_fqdn); + + auto pub_fqdn = _demangle_if_ros_topic(pub_topic_name); auto sub_topic_name = client_info->response_subscriber_->getAttributes().topic.getTopicName(); - auto sub_partitions = - client_info->response_subscriber_->getAttributes().qos.m_partition.getNames(); - // every rostopic has exactly 1 partition field set - if (sub_partitions.size() != 1) { - RCUTILS_LOG_ERROR_NAMED( - "rmw_fastrtps_cpp", - "Topic %s is not a ros topic", pub_topic_name.c_str()) - RMW_SET_ERROR_MSG((std::string(sub_topic_name) + " is a non-ros topic\n").c_str()); - return RMW_RET_ERROR; - } - auto sub_fqdn = sub_partitions[0] + "/" + sub_topic_name; - sub_fqdn = _demangle_if_ros_topic(sub_fqdn); + + auto sub_fqdn = _demangle_if_ros_topic(sub_topic_name); *is_available = false; size_t number_of_request_subscribers = 0; diff --git a/rmw_fastrtps_cpp/src/rmw_subscription.cpp b/rmw_fastrtps_cpp/src/rmw_subscription.cpp index 17b8b6952..554ede4b7 100644 --- a/rmw_fastrtps_cpp/src/rmw_subscription.cpp +++ b/rmw_fastrtps_cpp/src/rmw_subscription.cpp @@ -22,7 +22,6 @@ #include "fastrtps/participant/Participant.h" #include "fastrtps/subscriber/Subscriber.h" -#include "assign_partitions.hpp" #include "rmw_fastrtps_cpp/identifier.hpp" #include "namespace_prefix.hpp" #include "qos.hpp" @@ -110,12 +109,10 @@ rmw_create_subscription( eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; subscriberParam.topic.topicKind = eprosima::fastrtps::rtps::NO_KEY; subscriberParam.topic.topicDataType = type_name; - rcutils_ret_t ret = _assign_partitions_to_attributes( - topic_name, ros_topic_prefix, - qos_policies->avoid_ros_namespace_conventions, &subscriberParam); - if (ret != RCUTILS_RET_OK) { - // error msg already set - goto fail; + if (!qos_policies->avoid_ros_namespace_conventions) { + subscriberParam.topic.topicName = std::string(ros_topic_prefix) + topic_name; + } else { + subscriberParam.topic.topicName = topic_name; } if (!get_datareader_qos(*qos_policies, subscriberParam)) {