diff --git a/rcl/include/rcl/init_options.h b/rcl/include/rcl/init_options.h index 1d33a0739e..a62d7e0ce5 100644 --- a/rcl/include/rcl/init_options.h +++ b/rcl/include/rcl/init_options.h @@ -34,6 +34,15 @@ typedef struct rcl_init_options_t { /// Implementation specific pointer. struct rcl_init_options_impl_t * impl; + + /// If set, then this value overrides the ROS_DOMAIN_ID environment variable. + /** + * It defaults to RCL_NODE_OPTIONS_DEFAULT_DOMAIN_ID, which will cause the + * context to use the ROS domain ID set in the ROS_DOMAIN_ID environment + * variable, or on some systems 0 if the environment variable is not set. + */ + size_t domain_id; + } rcl_init_options_t; /// Return a zero initialized rcl_init_options_t struct. diff --git a/rcl/src/rcl/init.c b/rcl/src/rcl/init.c index a18f675bb3..7174a7788b 100644 --- a/rcl/src/rcl/init.c +++ b/rcl/src/rcl/init.c @@ -143,7 +143,7 @@ rcl_init( rcutils_atomic_store((atomic_uint_least64_t *)(&context->instance_id_storage), next_instance_id); context->impl->init_options.impl->rmw_init_options.instance_id = next_instance_id; - size_t * domain_id = &context->impl->init_options.impl->rmw_init_options.domain_id; + size_t * domain_id = &context->impl->init_options.domain_id; if (RCL_DEFAULT_DOMAIN_ID == *domain_id) { // Get actual domain id based on environment variable. ret = rcl_get_default_domain_id(domain_id); @@ -152,6 +152,7 @@ rcl_init( goto fail; } } + context->impl->init_options.impl->rmw_init_options.domain_id = *domain_id; rmw_localhost_only_t * localhost_only = &context->impl->init_options.impl->rmw_init_options.localhost_only; diff --git a/rcl/src/rcl/init_options.c b/rcl/src/rcl/init_options.c index 713337d609..552fd0f264 100644 --- a/rcl/src/rcl/init_options.c +++ b/rcl/src/rcl/init_options.c @@ -17,6 +17,7 @@ extern "C" { #endif +#include "rcl/node_options.h" #include "rcl/init_options.h" #include "./common.h" @@ -30,6 +31,7 @@ rcl_get_zero_initialized_init_options(void) { return (const rcl_init_options_t) { .impl = 0, + .domain_id = 0, }; // NOLINT(readability/braces): false positive } @@ -55,6 +57,7 @@ rcl_init_options_init(rcl_init_options_t * init_options, rcl_allocator_t allocat RCL_SET_ERROR_MSG(rmw_get_error_string().str); return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret); } + init_options->domain_id = RCL_NODE_OPTIONS_DEFAULT_DOMAIN_ID; return RCL_RET_OK; } @@ -111,6 +114,8 @@ rcl_init_options_copy(const rcl_init_options_t * src, rcl_init_options_t * dst) RCL_SET_ERROR_MSG(error_string.str); return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret); } + // copy domain_id + dst->domain_id = src->domain_id; return RCL_RET_OK; } @@ -128,6 +133,7 @@ rcl_init_options_fini(rcl_init_options_t * init_options) return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret); } allocator.deallocate(init_options->impl, allocator.state); + init_options->domain_id = RCL_NODE_OPTIONS_DEFAULT_DOMAIN_ID; return RCL_RET_OK; }