Following the trace of the command line ros2 topic info
leads us here:
https://github.com/ros2/ros2cli/blob/...
From there we can see that the rclcpp Graph API contains the methods. I quickly tried something out:
launch this in a terminal: ros2 run demo_nodes_cpp talker
And run the following code:
#include <chrono>
#include <functional>
#include <memory>
#include <string>
#include "rclcpp/rclcpp.hpp"
class MinimalPublisher : public rclcpp::Node
{
public:
MinimalPublisher()
: Node("minimal_publisher"), count_(0)
{
timer_ = this->create_wall_timer(
500ms, std::bind(&MinimalPublisher::timer_callback, this));
}
private:
void timer_callback()
{
auto result = this->get_publishers_info_by_topic("/chatter");
for(const auto& node : result)
{
std::cout << node.node_name() << " topic type: " << node.topic_type() << " qos history: " << node.qos_profile().get_rmw_qos_profile().history << std::endl;
}
}
rclcpp::TimerBase::SharedPtr timer_;
};
int main(int argc, char * argv[])
{
rclcpp::init(argc, argv);
rclcpp::spin(std::make_shared<MinimalPublisher>());
rclcpp::shutdown();
return 0;
}
This outputs:
ros2 run graph_node graph_node
talker topic type: std_msgs/msg/String qos history: 3
talker topic type: std_msgs/msg/String qos history: 3
talker topic type: std_msgs/msg/String qos history: 3