I ended up doing this by calling the master API directly.
std::string node_name = ros::this_node::getName();
XmlRpc::XmlRpcValue request(node_name);
XmlRpc::XmlRpcValue response;
XmlRpc::XmlRpcValue payload;
bool success = ros::master::execute("getSystemState", request,
response, payload, false);
ROS_ASSERT(payload.getType() == XmlRpc::XmlRpcValue::TypeArray);
ROS_ASSERT(payload.size() == 3);
bool published = false;
bool subscribed = false;
XmlRpc::XmlRpcValue & publishers = payload[0];
ROS_ASSERT(publishers.getType() == XmlRpc::XmlRpcValue::TypeArray);
for(int i=0; i<publishers.size(); i++) {
XmlRpc::XmlRpcValue & topic = publishers[i];
ROS_ASSERT(topic.getType() == XmlRpc::XmlRpcValue::TypeArray);
ROS_ASSERT(topic[0].getType() == XmlRpc::XmlRpcValue::TypeString);
std::string topic_name = topic[0];
if(topic_name == response_topic_) {
published = true;
}
}
XmlRpc::XmlRpcValue & subscribers = payload[1];
ROS_ASSERT(subscribers.getType() == XmlRpc::XmlRpcValue::TypeArray);
for(int i=0; i<subscribers.size(); i++) {
XmlRpc::XmlRpcValue & topic = subscribers[i];
ROS_ASSERT(topic.getType() == XmlRpc::XmlRpcValue::TypeArray);
ROS_ASSERT(topic[0].getType() == XmlRpc::XmlRpcValue::TypeString);
std::string topic_name = topic[0];
if(topic_name == request_topic_) {
subscribed = true;
}
}
Originally posted by ahendrix with karma: 47576 on 2015-01-26
This answer was ACCEPTED on the original site
Post score: 4