Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enforce unique node names #86

Merged
merged 2 commits into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,21 @@ using CountFunction = std::function<size_t(const std::string &)>;
class PublisherManager
{
public:
~PublisherManager()
{
publishers_.clear();
publisher_nodes_.clear();
}

template<class T>
void add_publisher(
const std::string & topic_name, std::shared_ptr<T> message, size_t expected_messages = 0)
{
static int counter = 0;
auto publisher_node = std::make_shared<rclcpp::Node>("publisher" + std::to_string(counter++));
auto node_name = std::string("publisher") + std::to_string(counter_++);
auto publisher_node = std::make_shared<rclcpp::Node>(node_name);
auto publisher = publisher_node->create_publisher<T>(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) {
Expand Down Expand Up @@ -72,6 +79,8 @@ class PublisherManager
}

private:
int counter_ = 1;
std::vector<std::shared_ptr<rclcpp::Node>> publisher_nodes_;
std::vector<std::function<void(CountFunction)>> publishers_;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <string>

#include "rclcpp/any_subscription_callback.hpp"
#include "rclcpp/macros.hpp"
#include "rclcpp/subscription.hpp"

namespace rosbag2_transport
Expand Down