getNumSubscribers and TopicManager
I am trying to limit the number of subscribers a topic can get to just 1.
However, I see that publisher.getNumSubscribers()
and subscriber.getNumPublishers()
only return either 0
or 1
!
I also tried to get the TopicManager
like auto manager = ros::TopicManager::instance(); // check for multi-instantiation of singleton modules
and using it to check the number of subscribers per topic like: manager->getNumSubscribers(from_topic)
but this ALWAYS returns 0
!
The code is pretty simple, I create subscribers and publishers to the same topics, in the same function call. Between each creation, I also call ros::spinOnce()
.
Eventually, getNumSubscribers()
increases from 0
to 1
but never to more.
Is this a feature or a bug?
can you tell us how you plan to do that?
I would just throw if I saw that 2 publishers or 2 subscribers are on the same topic. So programmer will know he mustn't do it. But seems this isn't possible in current Ros version. They don't go over 1 (maybe cause they are in same process)