Get list of all topics within c++ node
I am trying to get a list of all topics (both published and subscribed) to see whether a topic is available or not.
Using method I can get list of all advertised topics but not the ones that are only subscribed to and don't have a publishers yet.
Is there a decent way to do it within a cpp node?
The Master API has a method called
getSystemState(..)
. That would return all publishers and subscribers. From that you should be able to derive the information you are looking for.that's a python API, I would prefer something in cpp so I can easily add it to my node, but might make a generic node out of it, thanks
That page documents the API, which is an XML-RPC API. It's language agnostic.
You can use any library capable of invoking XML-RPC methods. In ROS 1, xmlrpcpp is used.
There may already be some code that implements this, but I can't link you to a specific example.