diff --git a/rclcpp/include/rclcpp/node.hpp b/rclcpp/include/rclcpp/node.hpp index 5dbfbc76b0..332193b1c7 100644 --- a/rclcpp/include/rclcpp/node.hpp +++ b/rclcpp/include/rclcpp/node.hpp @@ -1449,19 +1449,19 @@ class Node : public std::enable_shared_from_this rclcpp::node_interfaces::NodeTimeSourceInterface::SharedPtr get_node_time_source_interface(); - /// Return a NodeHandle bound with the Node's internal node interfaces. + /// Return a NodeInterfaceHandle bound with the Node's internal node interfaces. /** * This overload binds all interfaces, if you want to bind a subset of interfaces, specify them * in the template parameters of the templated method. * - * \return a NodeHandle bound with the Node's internal node interfaces. + * \return a NodeInterfaceHandle bound with the Node's internal node interfaces. */ RCLCPP_PUBLIC inline - rclcpp::NodeHandle::SharedPtr - get_node_handle() {return std::make_shared>(this);} + rclcpp::NodeInterfaceHandle::SharedPtr + get_node_handle() {return std::make_shared>(this);} - /// Return a NodeHandle bound with the Node's internal node interfaces. + /// Return a NodeInterfaceHandle bound with the Node's internal node interfaces. /** * Specify which interfaces you want to bind using the temlplate parameters. Any unbound * interfaces will be nullptr. @@ -1476,10 +1476,10 @@ class Node : public std::enable_shared_from_this * - ```node->get_node_handle()``` will bind all interfaces. * - ```node->get_node_handle()``` will bind all interfaces. * - * \return a NodeHandle bound with the Node's internal node interfaces. + * \return a NodeInterfaceHandle bound with the Node's internal node interfaces. */ template - typename rclcpp::NodeHandle::SharedPtr + typename rclcpp::NodeInterfaceHandle::SharedPtr get_node_handle(); /// Return the sub-namespace, if this is a sub-node, otherwise an empty string. diff --git a/rclcpp/include/rclcpp/node_handle.hpp b/rclcpp/include/rclcpp/node_handle.hpp index 8946592349..39a3b67705 100644 --- a/rclcpp/include/rclcpp/node_handle.hpp +++ b/rclcpp/include/rclcpp/node_handle.hpp @@ -46,14 +46,14 @@ struct AllInterfaces {}; /// A helper class for aggregating node interfaces template -class NodeHandle : public std::enable_shared_from_this> +class NodeInterfaceHandle : public std::enable_shared_from_this> { public: - RCLCPP_SMART_PTR_DEFINITIONS(NodeHandle) + RCLCPP_SMART_PTR_DEFINITIONS(NodeInterfaceHandle) /// Create a new node handle with no bound node interfaces. RCLCPP_PUBLIC - NodeHandle() + NodeInterfaceHandle() : base_(nullptr), clock_(nullptr), graph_(nullptr), @@ -74,13 +74,13 @@ class NodeHandle : public std::enable_shared_from_this(node)``` will bind no interfaces. - * - ```NodeHandle(node)``` will bind just the NodeBaseInterface. - * - ```NodeHandle(node)``` will bind all interfaces. + * - ```NodeInterfaceHandle<>(node)``` will bind no interfaces. + * - ```NodeInterfaceHandle(node)``` will bind just the NodeBaseInterface. + * - ```NodeInterfaceHandle(node)``` will bind all interfaces. * \param[in] node Node-like object to bind the interfaces of. */ template - explicit NodeHandle(const NodeT & node) + explicit NodeInterfaceHandle(const NodeT & node) { if constexpr (0 == sizeof ...(InterfaceTs)) { base_ = nullptr; @@ -237,7 +237,10 @@ class NodeHandle : public std::enable_shared_from_this::SharedPtr get_node_handle() {return std::make_shared>();} +inline NodeInterfaceHandle<>::SharedPtr get_node_handle() +{ + return std::make_shared>(); +} /// Create a new node handle bound with the passed in node-like object's interfaces. @@ -248,10 +251,10 @@ inline NodeHandle<>::SharedPtr get_node_handle() {return std::make_shared -typename NodeHandle<>::SharedPtr +typename NodeInterfaceHandle<>::SharedPtr get_node_handle(const NodeT & node) { - return std::make_shared>(node); + return std::make_shared>(node); } @@ -260,18 +263,18 @@ get_node_handle(const NodeT & node) * You may specify in the template parameters the interfaces to bind. Any unbound interfaces * will be nullptr. * - * For example: ```NodeHandle(node)``` will bind just the NodeBaseInterface. + * For example: ```NodeInterfaceHandle(node)``` will bind just the NodeBaseInterface. * * \param[in] node Node-like object to bind the interfaces of. */ template -typename NodeHandle::SharedPtr +typename NodeInterfaceHandle::SharedPtr get_node_handle(const NodeT & node) { if constexpr (0 == sizeof...(InterfaceTs)) { return get_node_handle(node); } else { - return std::make_shared>(node); + return std::make_shared>(node); } } diff --git a/rclcpp/include/rclcpp/node_impl.hpp b/rclcpp/include/rclcpp/node_impl.hpp index 46c0bdcee6..263013723c 100644 --- a/rclcpp/include/rclcpp/node_impl.hpp +++ b/rclcpp/include/rclcpp/node_impl.hpp @@ -395,10 +395,10 @@ Node::get_parameters( } template -typename rclcpp::NodeHandle::SharedPtr +typename rclcpp::NodeInterfaceHandle::SharedPtr Node::get_node_handle() { - return std::make_shared>(this); + return std::make_shared>(this); } } // namespace rclcpp diff --git a/rclcpp/test/rclcpp/test_node_handle.cpp b/rclcpp/test/rclcpp/test_node_handle.cpp index 213fbc0ec8..75b61b7718 100644 --- a/rclcpp/test/rclcpp/test_node_handle.cpp +++ b/rclcpp/test/rclcpp/test_node_handle.cpp @@ -16,7 +16,7 @@ #include "rclcpp/node.hpp" #include "rclcpp/node_handle.hpp" -class TestNodeHandle : public ::testing::Test +class TestNodeInterfaceHandle : public ::testing::Test { protected: static void SetUpTestCase() @@ -33,11 +33,11 @@ class TestNodeHandle : public ::testing::Test /* Testing node handle construction. */ -TEST_F(TestNodeHandle, nh_init) { +TEST_F(TestNodeInterfaceHandle, nh_init) { { auto node = std::make_shared("my_node", "/ns"); - auto empty_nh = std::make_shared>(); + auto empty_nh = std::make_shared>(); EXPECT_EQ(nullptr, empty_nh->base()); EXPECT_EQ(nullptr, empty_nh->clock()); EXPECT_EQ(nullptr, empty_nh->graph()); @@ -61,7 +61,7 @@ TEST_F(TestNodeHandle, nh_init) { EXPECT_EQ(nullptr, empty_nh_from_standalone->parameters()); EXPECT_EQ(nullptr, empty_nh_from_standalone->time_source()); - auto base_nh = std::make_shared>(node); + auto base_nh = std::make_shared>(node); EXPECT_NE(nullptr, base_nh->base()); EXPECT_STREQ("my_node", base_nh->base()->get_name()); EXPECT_EQ(nullptr, base_nh->clock()); @@ -88,7 +88,10 @@ TEST_F(TestNodeHandle, nh_init) { EXPECT_EQ(nullptr, base_nh_from_standalone->time_source()); auto base_clock_nh = - std::make_shared>(node); + std::make_shared>(node); EXPECT_NE(nullptr, base_clock_nh->base()); EXPECT_STREQ("my_node", base_clock_nh->base()->get_name()); EXPECT_NE(nullptr, base_clock_nh->clock()); @@ -103,7 +106,7 @@ TEST_F(TestNodeHandle, nh_init) { EXPECT_EQ(nullptr, base_clock_nh->time_source()); auto sans_base_clock_nh = std::make_shared< - rclcpp::NodeHandle< + rclcpp::NodeInterfaceHandle< rclcpp::GraphInterface, rclcpp::LoggingInterface, rclcpp::TimersInterface, @@ -124,7 +127,7 @@ TEST_F(TestNodeHandle, nh_init) { EXPECT_NE(nullptr, sans_base_clock_nh->parameters()); EXPECT_NE(nullptr, sans_base_clock_nh->time_source()); - auto all_nh = std::make_shared>(node); + auto all_nh = std::make_shared>(node); EXPECT_NE(nullptr, all_nh->base()); EXPECT_NE(nullptr, all_nh->clock()); EXPECT_NE(nullptr, all_nh->graph()); @@ -136,7 +139,7 @@ TEST_F(TestNodeHandle, nh_init) { EXPECT_NE(nullptr, all_nh->parameters()); EXPECT_NE(nullptr, all_nh->time_source()); - auto empty_nh_from_node = std::make_shared>(node); + auto empty_nh_from_node = std::make_shared>(node); EXPECT_EQ(nullptr, empty_nh_from_node->base()); EXPECT_EQ(nullptr, empty_nh_from_node->clock()); EXPECT_EQ(nullptr, empty_nh_from_node->graph()); @@ -153,11 +156,11 @@ TEST_F(TestNodeHandle, nh_init) { /* Testing node handle construction with alternate getters. */ -TEST_F(TestNodeHandle, nh_init_alternate_getters) { +TEST_F(TestNodeInterfaceHandle, nh_init_alternate_getters) { { auto node = std::make_shared("my_node", "/ns"); - auto base_nh = std::make_shared>(node); + auto base_nh = std::make_shared>(node); EXPECT_NE(nullptr, base_nh->get_node_base_interface()); EXPECT_STREQ("my_node", base_nh->get_node_base_interface()->get_name()); @@ -172,8 +175,10 @@ TEST_F(TestNodeHandle, nh_init_alternate_getters) { EXPECT_EQ(nullptr, base_nh->get_node_parameters_interface()); EXPECT_EQ(nullptr, base_nh->get_node_time_source_interface()); - auto base_clock_nh = - std::make_shared>(node); + auto base_clock_nh = std::make_shared>(node); EXPECT_NE(nullptr, base_clock_nh->get_node_base_interface()); EXPECT_STREQ("my_node", base_clock_nh->get_node_base_interface()->get_name()); @@ -191,17 +196,16 @@ TEST_F(TestNodeHandle, nh_init_alternate_getters) { EXPECT_EQ(nullptr, base_clock_nh->get_node_parameters_interface()); EXPECT_EQ(nullptr, base_clock_nh->get_node_time_source_interface()); - auto sans_base_clock_nh = std::make_shared< - rclcpp::NodeHandle< - rclcpp::GraphInterface, - rclcpp::LoggingInterface, - rclcpp::TimersInterface, - rclcpp::TopicsInterface, - rclcpp::ServicesInterface, - rclcpp::WaitablesInterface, - rclcpp::ParametersInterface, - rclcpp::TimeSourceInterface - >>(node); + auto sans_base_clock_nh = std::make_shared>(node); EXPECT_EQ(nullptr, sans_base_clock_nh->get_node_base_interface()); EXPECT_EQ(nullptr, sans_base_clock_nh->get_node_clock_interface()); @@ -219,11 +223,11 @@ TEST_F(TestNodeHandle, nh_init_alternate_getters) { /* Testing node handle setters. */ -TEST_F(TestNodeHandle, nh_setters) { +TEST_F(TestNodeInterfaceHandle, nh_setters) { { auto node = std::make_shared("my_node", "/ns"); - auto base_nh = std::make_shared>(node); + auto base_nh = std::make_shared>(node); EXPECT_NE(nullptr, base_nh->base()); EXPECT_STREQ("my_node", base_nh->base()->get_name()); @@ -241,11 +245,11 @@ TEST_F(TestNodeHandle, nh_setters) { /* Testing node handle alternate setters. */ -TEST_F(TestNodeHandle, nh_alternate_setters) { +TEST_F(TestNodeInterfaceHandle, nh_alternate_setters) { { auto node = std::make_shared("my_node", "/ns"); - auto base_nh = std::make_shared>(node); + auto base_nh = std::make_shared>(node); EXPECT_NE(nullptr, base_nh->base()); EXPECT_STREQ("my_node", base_nh->base()->get_name()); diff --git a/rclcpp_lifecycle/include/rclcpp_lifecycle/lifecycle_node.hpp b/rclcpp_lifecycle/include/rclcpp_lifecycle/lifecycle_node.hpp index 88814bcbf4..40203ce17e 100644 --- a/rclcpp_lifecycle/include/rclcpp_lifecycle/lifecycle_node.hpp +++ b/rclcpp_lifecycle/include/rclcpp_lifecycle/lifecycle_node.hpp @@ -823,19 +823,22 @@ class LifecycleNode : public node_interfaces::LifecycleNodeInterface, rclcpp::node_interfaces::NodeWaitablesInterface::SharedPtr get_node_waitables_interface(); - /// Return a NodeHandle bound with the LifecycleNode's internal node interfaces. + /// Return a NodeInterfaceHandle bound with the LifecycleNode's internal node interfaces. /** * This overload binds all interfaces, if you want to bind a subset of interfaces, specify them * in the template parameters of the templated method. * - * \return a NodeHandle bound with the LifecycleNode's internal node interfaces. + * \return a NodeInterfaceHandle bound with the LifecycleNode's internal node interfaces. */ RCLCPP_LIFECYCLE_PUBLIC inline - rclcpp::NodeHandle::SharedPtr - get_node_handle() {return std::make_shared>(this);} + rclcpp::NodeInterfaceHandle::SharedPtr + get_node_handle() + { + return std::make_shared>(this); + } - /// Return a NodeHandle bound with the LifecycleNode's internal node interfaces. + /// Return a NodeInterfaceHandle bound with the LifecycleNode's internal node interfaces. /** * Specify which interfaces you want to bind using the temlplate parameters. Any unbound * interfaces will be nullptr. @@ -850,10 +853,10 @@ class LifecycleNode : public node_interfaces::LifecycleNodeInterface, * - ```node->get_node_handle()``` will bind all interfaces. * - ```node->get_node_handle()``` will bind all interfaces. * - * \return a NodeHandle bound with the LifecycleNode's internal node interfaces. + * \return a NodeInterfaceHandle bound with the LifecycleNode's internal node interfaces. */ template - typename rclcpp::NodeHandle::SharedPtr + typename rclcpp::NodeInterfaceHandle::SharedPtr get_node_handle(); /// Return the NodeOptions used when creating this node. diff --git a/rclcpp_lifecycle/include/rclcpp_lifecycle/lifecycle_node_impl.hpp b/rclcpp_lifecycle/include/rclcpp_lifecycle/lifecycle_node_impl.hpp index 26c1a114b8..ff5aed1bcc 100644 --- a/rclcpp_lifecycle/include/rclcpp_lifecycle/lifecycle_node_impl.hpp +++ b/rclcpp_lifecycle/include/rclcpp_lifecycle/lifecycle_node_impl.hpp @@ -333,10 +333,10 @@ LifecycleNode::get_parameter_or( } template -typename rclcpp::NodeHandle::SharedPtr +typename rclcpp::NodeInterfaceHandle::SharedPtr LifecycleNode::get_node_handle() { - return std::make_shared>(this); + return std::make_shared>(this); } } // namespace rclcpp_lifecycle