There's currently no way to emulate the on connect or on disconnect SubscriberStatusCallback
(described here: https://docs.ros.org/api/roscpp/html/... ) in ROS 2. The underlying middlewares we support are capable of it, but we simply haven't exposed this information up to the ROS api yet. However it is on our roadmap, but not slated for inclusion into the next release:
Expose matched publisher / subscriber count (rather than only based on the topic name)
-- https://github.com/ros2/ros2/wiki/Roa...
This could be implemented by someone else in time for the release, but it would be a moderately complex set of changes.
However, the other half of this puzzle is the ros::SingleSubscriberPublisher
which allows you to publish a message to only the new subscriber and not the existing subscribers, and that's the argument of the SubscriberStatusCallback
. See:
https://answers.ros.org/question/1132...
I currently don't know of a simple way to do that with our current system. So the question is (please edit your question rather than making another answer) do you need that feature too, or just a callback to know when something has connected?