Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Registering multiple callbacks on the same topic seems to be a supported feature, and, thus, it should be safe.

The documentation for Subscriber states:

Once all copies of a specific Subscriber go out of scope, the subscription callback associated with that handle will stop being called. Once all Subscriber for a given topic go out of scope the topic will be unsubscribed.

This implies that there may be multiple Subscriber (i.e., multiple callbacks) on the same topic.

Indeed, looking at roscpp/topic_manager.cpp, we can see that subscribe first attempts to reuse an existing Subscription on the requested topic. If there is one, the new callback is appended to the Subscription's list of callbacks (std::vector<CallbackInfoPtr>).

Regarding any performance hits, the answer is likely within Subscription::handleMessage and Subscription::addCallback, although I still have not figured it out. It seems to matter only when the callbacks use different C++ types.