Rosnode list (#304)
* expose list of nodes * uncrustify * review comments * warn for memory leak * extend year of copyright
This commit is contained in:
parent
4d8b60feb5
commit
dc6b15983a
3 changed files with 46 additions and 2 deletions
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2016 Open Source Robotics Foundation, Inc.
|
||||
// Copyright 2016-2017 Open Source Robotics Foundation, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
|
@ -59,6 +59,11 @@ public:
|
|||
std::map<std::string, std::string>
|
||||
get_topic_names_and_types() const;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
virtual
|
||||
std::vector<std::string>
|
||||
get_node_names() const;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
virtual
|
||||
size_t
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2016 Open Source Robotics Foundation, Inc.
|
||||
// Copyright 2016-2017 Open Source Robotics Foundation, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
|
@ -18,6 +18,7 @@
|
|||
#include <chrono>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "rcl/guard_condition.h"
|
||||
|
||||
|
@ -46,6 +47,12 @@ public:
|
|||
std::map<std::string, std::string>
|
||||
get_topic_names_and_types() const = 0;
|
||||
|
||||
/// Return a vector of existing node names (string).
|
||||
RCLCPP_PUBLIC
|
||||
virtual
|
||||
std::vector<std::string>
|
||||
get_node_names() const = 0;
|
||||
|
||||
/// Return the number of publishers that are advertised on a given topic.
|
||||
RCLCPP_PUBLIC
|
||||
virtual
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "rcl/graph.h"
|
||||
#include "rclcpp/exceptions.hpp"
|
||||
|
@ -75,6 +76,37 @@ NodeGraph::get_topic_names_and_types() const
|
|||
return topics;
|
||||
}
|
||||
|
||||
std::vector<std::string>
|
||||
NodeGraph::get_node_names() const
|
||||
{
|
||||
rcl_string_array_t node_names_c =
|
||||
rcl_get_zero_initialized_string_array();
|
||||
|
||||
auto ret = rcl_get_node_names(node_base_->get_rcl_node_handle(),
|
||||
&node_names_c);
|
||||
if (ret != RMW_RET_OK) {
|
||||
if (rmw_destroy_node_names(&node_names_c) != RMW_RET_OK) {
|
||||
RMW_SET_ERROR_MSG("Fatal: Leaking node_name memory.");
|
||||
}
|
||||
// *INDENT-OFF*
|
||||
throw std::runtime_error(
|
||||
std::string("could not get node names: ") + rmw_get_error_string_safe());
|
||||
// *INDENT-ON*
|
||||
}
|
||||
|
||||
std::vector<std::string> node_names(&node_names_c.data[0],
|
||||
&node_names_c.data[0 + node_names_c.size]);
|
||||
ret = rmw_destroy_node_names(&node_names_c);
|
||||
if (ret != RMW_RET_OK) {
|
||||
// *INDENT-OFF*
|
||||
throw std::runtime_error(
|
||||
std::string("could not destroy node names: ") + rmw_get_error_string_safe());
|
||||
// *INDENT-ON*
|
||||
}
|
||||
|
||||
return node_names;
|
||||
}
|
||||
|
||||
size_t
|
||||
NodeGraph::count_publishers(const std::string & topic_name) const
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue