Expose get_fully_qualified_name in NodeBase API. (#662)

Signed-off-by: Michael Carroll <michael@openrobotics.org>
This commit is contained in:
Michael Carroll 2019-03-19 13:50:01 -05:00 committed by GitHub
parent 2929e4b133
commit d8d64e1efc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 56 additions and 0 deletions

View file

@ -115,6 +115,14 @@ public:
const char * const char *
get_namespace() const; get_namespace() const;
/// Get the fully-qualified name of the node.
/**
* The fully-qualified name includes the local namespace and name of the node.
*/
RCLCPP_PUBLIC
const char *
get_fully_qualified_name() const;
/// Get the logger of the node. /// Get the logger of the node.
/** \return The logger of the node. */ /** \return The logger of the node. */
RCLCPP_PUBLIC RCLCPP_PUBLIC

View file

@ -56,6 +56,11 @@ public:
const char * const char *
get_namespace() const; get_namespace() const;
RCLCPP_PUBLIC
virtual
const char *
get_fully_qualified_name() const;
RCLCPP_PUBLIC RCLCPP_PUBLIC
virtual virtual
rclcpp::Context::SharedPtr rclcpp::Context::SharedPtr

View file

@ -56,6 +56,13 @@ public:
const char * const char *
get_namespace() const = 0; get_namespace() const = 0;
/// Return the fully qualified name of the node.
/** \return The fully qualified name of the node. */
RCLCPP_PUBLIC
virtual
const char *
get_fully_qualified_name() const = 0;
/// Return the context of the node. /// Return the context of the node.
/** \return SharedPtr to the node's context. */ /** \return SharedPtr to the node's context. */
RCLCPP_PUBLIC RCLCPP_PUBLIC

View file

@ -190,6 +190,12 @@ Node::get_namespace() const
return node_base_->get_namespace(); return node_base_->get_namespace();
} }
const char *
Node::get_fully_qualified_name() const
{
return node_base_->get_fully_qualified_name();
}
rclcpp::Logger rclcpp::Logger
Node::get_logger() const Node::get_logger() const
{ {

View file

@ -161,6 +161,12 @@ NodeBase::get_namespace() const
return rcl_node_get_namespace(node_handle_.get()); return rcl_node_get_namespace(node_handle_.get());
} }
const char *
NodeBase::get_fully_qualified_name() const
{
return rcl_node_get_fully_qualified_name(node_handle_.get());
}
rclcpp::Context::SharedPtr rclcpp::Context::SharedPtr
NodeBase::get_context() NodeBase::get_context()
{ {

View file

@ -57,21 +57,45 @@ TEST_F(TestNode, get_name_and_namespace) {
auto node = std::make_shared<rclcpp::Node>("my_node", "/ns"); auto node = std::make_shared<rclcpp::Node>("my_node", "/ns");
EXPECT_STREQ("my_node", node->get_name()); EXPECT_STREQ("my_node", node->get_name());
EXPECT_STREQ("/ns", node->get_namespace()); EXPECT_STREQ("/ns", node->get_namespace());
EXPECT_STREQ("/ns/my_node", node->get_fully_qualified_name());
}
{
auto options = rclcpp::NodeOptions()
.arguments({"__ns:=/another_ns"});
auto node = std::make_shared<rclcpp::Node>("my_node", "/ns", options);
EXPECT_STREQ("my_node", node->get_name());
EXPECT_STREQ("/another_ns", node->get_namespace());
EXPECT_STREQ("/another_ns/my_node", node->get_fully_qualified_name());
} }
{ {
auto node = std::make_shared<rclcpp::Node>("my_node", "ns"); auto node = std::make_shared<rclcpp::Node>("my_node", "ns");
EXPECT_STREQ("my_node", node->get_name()); EXPECT_STREQ("my_node", node->get_name());
EXPECT_STREQ("/ns", node->get_namespace()); EXPECT_STREQ("/ns", node->get_namespace());
EXPECT_STREQ("/ns/my_node", node->get_fully_qualified_name());
}
{
auto node = std::make_shared<rclcpp::Node>("my_node");
EXPECT_STREQ("my_node", node->get_name());
EXPECT_STREQ("/", node->get_namespace());
EXPECT_STREQ("/my_node", node->get_fully_qualified_name());
}
{
auto node = std::make_shared<rclcpp::Node>("my_node", "");
EXPECT_STREQ("my_node", node->get_name());
EXPECT_STREQ("/", node->get_namespace());
EXPECT_STREQ("/my_node", node->get_fully_qualified_name());
} }
{ {
auto node = std::make_shared<rclcpp::Node>("my_node", "/my/ns"); auto node = std::make_shared<rclcpp::Node>("my_node", "/my/ns");
EXPECT_STREQ("my_node", node->get_name()); EXPECT_STREQ("my_node", node->get_name());
EXPECT_STREQ("/my/ns", node->get_namespace()); EXPECT_STREQ("/my/ns", node->get_namespace());
EXPECT_STREQ("/my/ns/my_node", node->get_fully_qualified_name());
} }
{ {
auto node = std::make_shared<rclcpp::Node>("my_node", "my/ns"); auto node = std::make_shared<rclcpp::Node>("my_node", "my/ns");
EXPECT_STREQ("my_node", node->get_name()); EXPECT_STREQ("my_node", node->get_name());
EXPECT_STREQ("/my/ns", node->get_namespace()); EXPECT_STREQ("/my/ns", node->get_namespace());
EXPECT_STREQ("/my/ns/my_node", node->get_fully_qualified_name());
} }
} }