Skip to content

Commit

Permalink
add domain_id to rcl_init_options_t.
Browse files Browse the repository at this point in the history
Signed-off-by: Tomoya.Fujita <[email protected]>
  • Loading branch information
fujitatomoya committed Jun 11, 2020
1 parent 7723308 commit 15d5d5f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
9 changes: 9 additions & 0 deletions rcl/include/rcl/init_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion rcl/src/rcl/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions rcl/src/rcl/init_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern "C"
{
#endif

#include "rcl/node_options.h"
#include "rcl/init_options.h"

#include "./common.h"
Expand All @@ -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
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand Down

0 comments on commit 15d5d5f

Please sign in to comment.