From e6e1848b97dbe45c773c36ee6223807c8097ac2c Mon Sep 17 00:00:00 2001 From: William Woodall Date: Sat, 8 Apr 2017 02:04:41 -0700 Subject: [PATCH] expose node namespace in API and pass to rcl (#316) * expose node namespace in API and pass to rcl * name_space -> namespace_ --- rclcpp/include/rclcpp/node.hpp | 11 +++++++++-- rclcpp/include/rclcpp/node_interfaces/node_base.hpp | 5 ++++- rclcpp/src/rclcpp/node.cpp | 9 +++++++-- rclcpp/src/rclcpp/node_interfaces/node_base.cpp | 3 ++- .../include/rclcpp_lifecycle/lifecycle_node.hpp | 11 +++++++++-- rclcpp_lifecycle/src/lifecycle_node.cpp | 9 +++++++-- 6 files changed, 38 insertions(+), 10 deletions(-) diff --git a/rclcpp/include/rclcpp/node.hpp b/rclcpp/include/rclcpp/node.hpp index 40679ff..aac5825 100644 --- a/rclcpp/include/rclcpp/node.hpp +++ b/rclcpp/include/rclcpp/node.hpp @@ -67,22 +67,29 @@ public: /// Create a new node with the specified name. /** * \param[in] node_name Name of the node. + * \param[in] namespace_ Namespace of the node. * \param[in] use_intra_process_comms True to use the optimized intra-process communication * pipeline to pass messages between nodes in the same process using shared memory. */ RCLCPP_PUBLIC - explicit Node(const std::string & node_name, bool use_intra_process_comms = false); + explicit Node( + const std::string & node_name, + const std::string & namespace_ = "", + bool use_intra_process_comms = false); /// Create a node based on the node name and a rclcpp::context::Context. /** * \param[in] node_name Name of the node. + * \param[in] namespace_ Namespace of the node. * \param[in] context The context for the node (usually represents the state of a process). * \param[in] use_intra_process_comms True to use the optimized intra-process communication * pipeline to pass messages between nodes in the same process using shared memory. */ RCLCPP_PUBLIC Node( - const std::string & node_name, rclcpp::context::Context::SharedPtr context, + const std::string & node_name, + const std::string & namespace_, + rclcpp::context::Context::SharedPtr context, bool use_intra_process_comms = false); RCLCPP_PUBLIC diff --git a/rclcpp/include/rclcpp/node_interfaces/node_base.hpp b/rclcpp/include/rclcpp/node_interfaces/node_base.hpp index d720e05..63d86d3 100644 --- a/rclcpp/include/rclcpp/node_interfaces/node_base.hpp +++ b/rclcpp/include/rclcpp/node_interfaces/node_base.hpp @@ -36,7 +36,10 @@ public: RCLCPP_SMART_PTR_ALIASES_ONLY(NodeBaseInterface) RCLCPP_PUBLIC - NodeBase(const std::string & node_name, rclcpp::context::Context::SharedPtr context); + NodeBase( + const std::string & node_name, + const std::string & namespace_, + rclcpp::context::Context::SharedPtr context); RCLCPP_PUBLIC virtual diff --git a/rclcpp/src/rclcpp/node.cpp b/rclcpp/src/rclcpp/node.cpp index e1a4aba..0630cfb 100644 --- a/rclcpp/src/rclcpp/node.cpp +++ b/rclcpp/src/rclcpp/node.cpp @@ -33,18 +33,23 @@ using rclcpp::node::Node; using rclcpp::exceptions::throw_from_rcl_error; -Node::Node(const std::string & node_name, bool use_intra_process_comms) +Node::Node( + const std::string & node_name, + const std::string & namespace_, + bool use_intra_process_comms) : Node( node_name, + namespace_, rclcpp::contexts::default_context::get_global_default_context(), use_intra_process_comms) {} Node::Node( const std::string & node_name, + const std::string & namespace_, rclcpp::context::Context::SharedPtr context, bool use_intra_process_comms) -: node_base_(new rclcpp::node_interfaces::NodeBase(node_name, context)), +: node_base_(new rclcpp::node_interfaces::NodeBase(node_name, namespace_, context)), node_graph_(new rclcpp::node_interfaces::NodeGraph(node_base_.get())), node_timers_(new rclcpp::node_interfaces::NodeTimers(node_base_.get())), node_topics_(new rclcpp::node_interfaces::NodeTopics(node_base_.get())), diff --git a/rclcpp/src/rclcpp/node_interfaces/node_base.cpp b/rclcpp/src/rclcpp/node_interfaces/node_base.cpp index 50f8801..d4160c4 100644 --- a/rclcpp/src/rclcpp/node_interfaces/node_base.cpp +++ b/rclcpp/src/rclcpp/node_interfaces/node_base.cpp @@ -27,6 +27,7 @@ using rclcpp::node_interfaces::NodeBase; NodeBase::NodeBase( const std::string & node_name, + const std::string & namespace_, rclcpp::context::Context::SharedPtr context) : context_(context), node_handle_(nullptr), @@ -84,7 +85,7 @@ NodeBase::NodeBase( rcl_node_options_t options = rcl_node_get_default_options(); // TODO(wjwwood): pass the Allocator to the options options.domain_id = domain_id; - ret = rcl_node_init(rcl_node, node_name.c_str(), &options); + ret = rcl_node_init(rcl_node, node_name.c_str(), namespace_.c_str(), &options); if (ret != RCL_RET_OK) { // Finalize the interrupt guard condition. finalize_notify_guard_condition(); diff --git a/rclcpp_lifecycle/include/rclcpp_lifecycle/lifecycle_node.hpp b/rclcpp_lifecycle/include/rclcpp_lifecycle/lifecycle_node.hpp index 039b5d7..c19a099 100644 --- a/rclcpp_lifecycle/include/rclcpp_lifecycle/lifecycle_node.hpp +++ b/rclcpp_lifecycle/include/rclcpp_lifecycle/lifecycle_node.hpp @@ -68,22 +68,29 @@ public: /// Create a new lifecycle node with the specified name. /** * \param[in] node_name Name of the node. + * \param[in] node_name Namespace of the node. * \param[in] use_intra_process_comms True to use the optimized intra-process communication * pipeline to pass messages between nodes in the same process using shared memory. */ RCLCPP_LIFECYCLE_PUBLIC - explicit LifecycleNode(const std::string & node_name, bool use_intra_process_comms = false); + explicit LifecycleNode( + const std::string & node_name, + const std::string & namespace_ = "", + bool use_intra_process_comms = false); /// Create a node based on the node name and a rclcpp::context::Context. /** * \param[in] node_name Name of the node. + * \param[in] node_name Namespace of the node. * \param[in] context The context for the node (usually represents the state of a process). * \param[in] use_intra_process_comms True to use the optimized intra-process communication * pipeline to pass messages between nodes in the same process using shared memory. */ RCLCPP_LIFECYCLE_PUBLIC LifecycleNode( - const std::string & node_name, rclcpp::context::Context::SharedPtr context, + const std::string & node_name, + const std::string & namespace_, + rclcpp::context::Context::SharedPtr context, bool use_intra_process_comms = false); RCLCPP_LIFECYCLE_PUBLIC diff --git a/rclcpp_lifecycle/src/lifecycle_node.cpp b/rclcpp_lifecycle/src/lifecycle_node.cpp index c20477f..09334cb 100644 --- a/rclcpp_lifecycle/src/lifecycle_node.cpp +++ b/rclcpp_lifecycle/src/lifecycle_node.cpp @@ -38,18 +38,23 @@ namespace rclcpp_lifecycle { -LifecycleNode::LifecycleNode(const std::string & node_name, bool use_intra_process_comms) +LifecycleNode::LifecycleNode( + const std::string & node_name, + const std::string & namespace_, + bool use_intra_process_comms) : LifecycleNode( node_name, + namespace_, rclcpp::contexts::default_context::get_global_default_context(), use_intra_process_comms) {} LifecycleNode::LifecycleNode( const std::string & node_name, + const std::string & namespace_, rclcpp::context::Context::SharedPtr context, bool use_intra_process_comms) -: node_base_(new rclcpp::node_interfaces::NodeBase(node_name, context)), +: node_base_(new rclcpp::node_interfaces::NodeBase(node_name, namespace_, context)), node_graph_(new rclcpp::node_interfaces::NodeGraph(node_base_.get())), node_timers_(new rclcpp::node_interfaces::NodeTimers(node_base_.get())), node_topics_(new rclcpp::node_interfaces::NodeTopics(node_base_.get())),