ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

One possible solution would be to modify shutdown as such:

Publisher::shutdown(bool sendQueuedMessages = false).

Calling shutdown with true would "kill" the instance as usual, but the TopicManager would not call Publication::drop() but rather mark the Publication as isShuttingDown=true.

At the next call to processPublishQueues(), after sending all messages, the TopicManager would call drop() on all Publication instances marked to be shut down.

In the case where a new publisher for the same topic gets created in the mean time (after shutdown but before processPublishQueues), the TopicManager would simply unmark the Publication as shutting down.

click to hide/show revision 2
Added an alternative solution

Solution #1

One possible solution would be to modify shutdown as such:

Publisher::shutdown(bool sendQueuedMessages = false).

Calling shutdown with true would "kill" the instance as usual, but the TopicManager would not call Publication::drop() but rather mark the Publication as isShuttingDown=true.

At the next call to processPublishQueues(), after sending all messages, the TopicManager would call drop() on all Publication instances marked to be shut down.

In the case where a new publisher for the same topic gets created in the mean time (after shutdown but before processPublishQueues), the TopicManager would simply unmark the Publication as shutting down.

Solution #2

Another possibility would be to create a method Publisher::areQueuesEmpty(). The Publisher would ask the TopicManager, which would ask the Publication, which would ask all SubscriberLinks. Only if all queues for all subscribers are empty would the method return true. The developers would then have to manually manage when they shut down the publisher.