From ef878b383547896e7396360f23715b10a92c9778 Mon Sep 17 00:00:00 2001 From: Brian Ezequiel Marchi Date: Tue, 24 Sep 2019 14:35:53 -0300 Subject: [PATCH] Support multiple participants for cyclone Signed-off-by: Brian Ezequiel Marchi --- .../cyclonedds_communicator.hpp | 14 ++++++++++---- .../resource_manager.cpp | 5 +++++ .../resource_manager.hpp | 3 +++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/performance_test/src/communication_abstractions/cyclonedds_communicator.hpp b/performance_test/src/communication_abstractions/cyclonedds_communicator.hpp index 164f6dee..2420ffb2 100644 --- a/performance_test/src/communication_abstractions/cyclonedds_communicator.hpp +++ b/performance_test/src/communication_abstractions/cyclonedds_communicator.hpp @@ -199,15 +199,20 @@ class CycloneDDSCommunicator : public Communicator } private: - /// Registers a topic to the participant. It makes sure that each topic is only registered once. + /// Registers a topic to the participant. It makes sure that each topic is only registered + /// once if resource manager is using a single participant. void register_topic() { - if (m_topic == 0) { + const bool is_single_participant = ResourceManager::get().is_using_single_participant(); + if (m_single_participant_topic == 0 || !is_single_participant) { m_topic = dds_create_topic(m_participant, Topic::CycloneDDSDesc(), Topic::topic_name().c_str(), nullptr, nullptr); + m_single_participant_topic = m_topic; if (m_topic < 0) { throw std::runtime_error("failed to create topic"); } + } else { + m_topic = m_single_participant_topic; } } @@ -219,11 +224,12 @@ class CycloneDDSCommunicator : public Communicator dds_entity_t m_waitset; dds_entity_t m_condition; - static dds_entity_t m_topic; + dds_entity_t m_topic; + static dds_entity_t m_single_participant_topic; }; template -dds_entity_t CycloneDDSCommunicator::m_topic = 0; +dds_entity_t CycloneDDSCommunicator::m_single_participant_topic = 0; } // namespace performance_test diff --git a/performance_test/src/communication_abstractions/resource_manager.cpp b/performance_test/src/communication_abstractions/resource_manager.cpp index 99d1b11e..9943e1b9 100644 --- a/performance_test/src/communication_abstractions/resource_manager.cpp +++ b/performance_test/src/communication_abstractions/resource_manager.cpp @@ -48,6 +48,11 @@ std::shared_ptr ResourceManager::ros2_node() const return rclcpp::Node::make_shared("performance_test" + rand_str, options); } +bool ResourceManager::is_using_single_participant() const +{ + return m_ec.use_single_participant(); +} + #ifdef PERFORMANCE_TEST_FASTRTPS_ENABLED eprosima::fastrtps::Participant * ResourceManager::fastrtps_participant() const { diff --git a/performance_test/src/communication_abstractions/resource_manager.hpp b/performance_test/src/communication_abstractions/resource_manager.hpp index 8268a324..431a1574 100644 --- a/performance_test/src/communication_abstractions/resource_manager.hpp +++ b/performance_test/src/communication_abstractions/resource_manager.hpp @@ -62,6 +62,9 @@ class ResourceManager /// Returns the ROS 2 node. std::shared_ptr ros2_node() const; + /// Returns true if a single participant is used. + bool is_using_single_participant() const; + #ifdef PERFORMANCE_TEST_FASTRTPS_ENABLED /// Returns FastRTPS participant. eprosima::fastrtps::Participant * fastrtps_participant() const;