From ed8442ccc801cf802154014b2be8fa6a099e99d6 Mon Sep 17 00:00:00 2001 From: Karsten Knese Date: Tue, 5 Feb 2019 21:12:50 -0800 Subject: [PATCH] enforce unique node names --- .../rosbag2_test_common/publisher_manager.hpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/rosbag2_test_common/include/rosbag2_test_common/publisher_manager.hpp b/rosbag2_test_common/include/rosbag2_test_common/publisher_manager.hpp index a75baf689f..3b03222303 100644 --- a/rosbag2_test_common/include/rosbag2_test_common/publisher_manager.hpp +++ b/rosbag2_test_common/include/rosbag2_test_common/publisher_manager.hpp @@ -33,14 +33,21 @@ using CountFunction = std::function; class PublisherManager { public: + ~PublisherManager() + { + publishers_.clear(); + publisher_nodes_.clear(); + } + template void add_publisher( const std::string & topic_name, std::shared_ptr message, size_t expected_messages = 0) { - static int counter = 0; - auto publisher_node = std::make_shared("publisher" + std::to_string(counter++)); + auto node_name = std::string("publisher") + std::to_string(counter_++); + auto publisher_node = std::make_shared(node_name); auto publisher = publisher_node->create_publisher(topic_name); + publisher_nodes_.push_back(publisher_node); publishers_.push_back([publisher, topic_name, message, expected_messages]( CountFunction count_stored_messages) { if (expected_messages != 0) { @@ -72,6 +79,8 @@ class PublisherManager } private: + int counter_ = 1; + std::vector> publisher_nodes_; std::vector> publishers_; };