expose node namespace in API and pass to rcl (#316)

* expose node namespace in API and pass to rcl

* name_space -> namespace_
This commit is contained in:
William Woodall 2017-04-08 02:04:41 -07:00 committed by GitHub
parent dbe674deb7
commit e6e1848b97
6 changed files with 38 additions and 10 deletions

View file

@ -67,22 +67,29 @@ public:
/// Create a new node with the specified name. /// Create a new node with the specified name.
/** /**
* \param[in] node_name Name of the node. * \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 * \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. * pipeline to pass messages between nodes in the same process using shared memory.
*/ */
RCLCPP_PUBLIC 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. /// 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 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] 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 * \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. * pipeline to pass messages between nodes in the same process using shared memory.
*/ */
RCLCPP_PUBLIC RCLCPP_PUBLIC
Node( 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); bool use_intra_process_comms = false);
RCLCPP_PUBLIC RCLCPP_PUBLIC

View file

@ -36,7 +36,10 @@ public:
RCLCPP_SMART_PTR_ALIASES_ONLY(NodeBaseInterface) RCLCPP_SMART_PTR_ALIASES_ONLY(NodeBaseInterface)
RCLCPP_PUBLIC 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 RCLCPP_PUBLIC
virtual virtual

View file

@ -33,18 +33,23 @@
using rclcpp::node::Node; using rclcpp::node::Node;
using rclcpp::exceptions::throw_from_rcl_error; 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(
node_name, node_name,
namespace_,
rclcpp::contexts::default_context::get_global_default_context(), rclcpp::contexts::default_context::get_global_default_context(),
use_intra_process_comms) use_intra_process_comms)
{} {}
Node::Node( Node::Node(
const std::string & node_name, const std::string & node_name,
const std::string & namespace_,
rclcpp::context::Context::SharedPtr context, rclcpp::context::Context::SharedPtr context,
bool use_intra_process_comms) 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_graph_(new rclcpp::node_interfaces::NodeGraph(node_base_.get())),
node_timers_(new rclcpp::node_interfaces::NodeTimers(node_base_.get())), node_timers_(new rclcpp::node_interfaces::NodeTimers(node_base_.get())),
node_topics_(new rclcpp::node_interfaces::NodeTopics(node_base_.get())), node_topics_(new rclcpp::node_interfaces::NodeTopics(node_base_.get())),

View file

@ -27,6 +27,7 @@ using rclcpp::node_interfaces::NodeBase;
NodeBase::NodeBase( NodeBase::NodeBase(
const std::string & node_name, const std::string & node_name,
const std::string & namespace_,
rclcpp::context::Context::SharedPtr context) rclcpp::context::Context::SharedPtr context)
: context_(context), : context_(context),
node_handle_(nullptr), node_handle_(nullptr),
@ -84,7 +85,7 @@ NodeBase::NodeBase(
rcl_node_options_t options = rcl_node_get_default_options(); rcl_node_options_t options = rcl_node_get_default_options();
// TODO(wjwwood): pass the Allocator to the options // TODO(wjwwood): pass the Allocator to the options
options.domain_id = domain_id; 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) { if (ret != RCL_RET_OK) {
// Finalize the interrupt guard condition. // Finalize the interrupt guard condition.
finalize_notify_guard_condition(); finalize_notify_guard_condition();

View file

@ -68,22 +68,29 @@ public:
/// Create a new lifecycle node with the specified name. /// Create a new lifecycle node with the specified name.
/** /**
* \param[in] node_name Name of the node. * \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 * \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. * pipeline to pass messages between nodes in the same process using shared memory.
*/ */
RCLCPP_LIFECYCLE_PUBLIC 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. /// 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 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] 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 * \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. * pipeline to pass messages between nodes in the same process using shared memory.
*/ */
RCLCPP_LIFECYCLE_PUBLIC RCLCPP_LIFECYCLE_PUBLIC
LifecycleNode( 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); bool use_intra_process_comms = false);
RCLCPP_LIFECYCLE_PUBLIC RCLCPP_LIFECYCLE_PUBLIC

View file

@ -38,18 +38,23 @@
namespace rclcpp_lifecycle 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( : LifecycleNode(
node_name, node_name,
namespace_,
rclcpp::contexts::default_context::get_global_default_context(), rclcpp::contexts::default_context::get_global_default_context(),
use_intra_process_comms) use_intra_process_comms)
{} {}
LifecycleNode::LifecycleNode( LifecycleNode::LifecycleNode(
const std::string & node_name, const std::string & node_name,
const std::string & namespace_,
rclcpp::context::Context::SharedPtr context, rclcpp::context::Context::SharedPtr context,
bool use_intra_process_comms) 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_graph_(new rclcpp::node_interfaces::NodeGraph(node_base_.get())),
node_timers_(new rclcpp::node_interfaces::NodeTimers(node_base_.get())), node_timers_(new rclcpp::node_interfaces::NodeTimers(node_base_.get())),
node_topics_(new rclcpp::node_interfaces::NodeTopics(node_base_.get())), node_topics_(new rclcpp::node_interfaces::NodeTopics(node_base_.get())),