Skip to content

Commit

Permalink
Expose get_fully_qualified_name in NodeBase API. (#662)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <michael@openrobotics.org>
  • Loading branch information
mjcarroll committed Mar 19, 2019
1 parent 2929e4b commit d8d64e1
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 0 deletions.
8 changes: 8 additions & 0 deletions rclcpp/include/rclcpp/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ class Node : public std::enable_shared_from_this<Node>
const char *
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.
/** \return The logger of the node. */
RCLCPP_PUBLIC
Expand Down
5 changes: 5 additions & 0 deletions rclcpp/include/rclcpp/node_interfaces/node_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ class NodeBase : public NodeBaseInterface
const char *
get_namespace() const;

RCLCPP_PUBLIC
virtual
const char *
get_fully_qualified_name() const;

RCLCPP_PUBLIC
virtual
rclcpp::Context::SharedPtr
Expand Down
7 changes: 7 additions & 0 deletions rclcpp/include/rclcpp/node_interfaces/node_base_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ class NodeBaseInterface
const char *
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 SharedPtr to the node's context. */
RCLCPP_PUBLIC
Expand Down
6 changes: 6 additions & 0 deletions rclcpp/src/rclcpp/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ Node::get_namespace() const
return node_base_->get_namespace();
}

const char *
Node::get_fully_qualified_name() const
{
return node_base_->get_fully_qualified_name();
}

rclcpp::Logger
Node::get_logger() const
{
Expand Down
6 changes: 6 additions & 0 deletions rclcpp/src/rclcpp/node_interfaces/node_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ NodeBase::get_namespace() const
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
NodeBase::get_context()
{
Expand Down
24 changes: 24 additions & 0 deletions rclcpp/test/test_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,45 @@ TEST_F(TestNode, get_name_and_namespace) {
auto node = std::make_shared<rclcpp::Node>("my_node", "/ns");
EXPECT_STREQ("my_node", node->get_name());
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");
EXPECT_STREQ("my_node", node->get_name());
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");
EXPECT_STREQ("my_node", node->get_name());
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");
EXPECT_STREQ("my_node", node->get_name());
EXPECT_STREQ("/my/ns", node->get_namespace());
EXPECT_STREQ("/my/ns/my_node", node->get_fully_qualified_name());
}
}

Expand Down

0 comments on commit d8d64e1

Please sign in to comment.