Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose domain_id to NodeOptions. #1155

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions rclcpp/include/rclcpp/node_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,21 @@ class NodeOptions
NodeOptions &
use_global_arguments(bool use_global_arguments);

/// Return the domain_id.
RCLCPP_PUBLIC
size_t
domain_id() const;

/// Set the domain id, return this for parameter idiom.
/**
* If set, this domain_id will be used in node.
*
* This can be used to override ROS_DOMAIN_ID environment variable.
*/
RCLCPP_PUBLIC
NodeOptions &
domain_id(size_t domain_id);

/// Return the enable_rosout flag.
RCLCPP_PUBLIC
bool
Expand Down Expand Up @@ -349,6 +364,8 @@ class NodeOptions

bool use_global_arguments_ {true};

size_t domain_id_ {get_domain_id_from_env()};

bool enable_rosout_ {true};

bool use_intra_process_comms_ {false};
Expand Down
17 changes: 16 additions & 1 deletion rclcpp/src/rclcpp/node_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ NodeOptions::operator=(const NodeOptions & other)
this->arguments_ = other.arguments_;
this->parameter_overrides_ = other.parameter_overrides_;
this->use_global_arguments_ = other.use_global_arguments_;
this->domain_id_ = other.domain_id_;
this->enable_rosout_ = other.enable_rosout_;
this->use_intra_process_comms_ = other.use_intra_process_comms_;
this->enable_topic_statistics_ = other.enable_topic_statistics_;
Expand All @@ -92,7 +93,7 @@ NodeOptions::get_rcl_node_options() const
*node_options_ = rcl_node_get_default_options();
node_options_->allocator = this->allocator_;
node_options_->use_global_arguments = this->use_global_arguments_;
node_options_->domain_id = this->get_domain_id_from_env();
node_options_->domain_id = this->domain_id_;
node_options_->enable_rosout = this->enable_rosout_;

int c_argc = 0;
Expand Down Expand Up @@ -187,6 +188,20 @@ NodeOptions::use_global_arguments(bool use_global_arguments)
return *this;
}

size_t
NodeOptions::domain_id() const
{
return this->domain_id_;
}

NodeOptions &
NodeOptions::domain_id(size_t domain_id)
{
this->node_options_.reset(); // reset node options to make it be recreated on next access.
this->domain_id_ = domain_id;
return *this;
}

bool
NodeOptions::enable_rosout() const
{
Expand Down