23 #include "./init_options_impl.h"
24 #include "rcutils/macros.h"
25 #include "rcl/error_handling.h"
26 #include "rmw/error_handling.h"
27 #include "rcutils/logging_macros.h"
43 RCL_CHECK_FOR_NULL_WITH_MSG(
45 "failed to allocate memory for init options impl",
47 init_options->
impl->allocator = allocator;
48 init_options->
impl->rmw_init_options = rmw_get_zero_initialized_init_options();
62 if (NULL != init_options->
impl) {
63 RCL_SET_ERROR_MSG(
"given init_options (rcl_init_options_t) is already initialized");
68 rcl_ret_t ret = _rcl_init_options_zero_init(init_options, allocator);
72 rmw_ret_t rmw_ret = rmw_init_options_init(&(init_options->
impl->rmw_init_options), allocator);
73 if (RMW_RET_OK != rmw_ret) {
74 allocator.deallocate(init_options->
impl, allocator.state);
75 RCL_SET_ERROR_MSG(rmw_get_error_string().str);
76 return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret);
82 init_options->
impl->rmw_init_options.discovery_options.automatic_discovery_range =
83 RMW_AUTOMATIC_DISCOVERY_RANGE_NOT_SET;
99 if (NULL != dst->
impl) {
100 RCL_SET_ERROR_MSG(
"given dst (rcl_init_options_t) is already initialized");
105 rcl_ret_t ret = _rcl_init_options_zero_init(dst, src->
impl->allocator);
112 rmw_init_options_copy(&(src->
impl->rmw_init_options), &(dst->
impl->rmw_init_options));
113 if (RMW_RET_OK != rmw_ret) {
114 rmw_error_string_t error_string = rmw_get_error_string();
118 RCUTILS_LOG_ERROR_NAMED(
120 "failed to finalize dst rcl_init_options while handling failure to "
121 "copy rmw_init_options, original ret '%d' and error: %s", rmw_ret, error_string.str);
124 RCL_SET_ERROR_MSG(error_string.str);
125 return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret);
138 rmw_ret_t rmw_ret = rmw_init_options_fini(&(init_options->
impl->rmw_init_options));
139 if (RMW_RET_OK != rmw_ret) {
140 RCL_SET_ERROR_MSG(rmw_get_error_string().str);
141 return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret);
143 allocator.deallocate(init_options->
impl, allocator.state);
153 *domain_id = init_options->
impl->rmw_init_options.domain_id;
162 init_options->
impl->rmw_init_options.domain_id = domain_id;
169 RCL_CHECK_ARGUMENT_FOR_NULL(init_options, NULL);
170 RCL_CHECK_ARGUMENT_FOR_NULL(init_options->
impl, NULL);
171 return &(init_options->
impl->rmw_init_options);
177 RCL_CHECK_ARGUMENT_FOR_NULL(init_options, NULL);
178 RCL_CHECK_ARGUMENT_FOR_NULL(init_options->
impl, NULL);
179 return &(init_options->
impl->allocator);
#define RCL_CHECK_ALLOCATOR(allocator, fail_statement)
Check that the given allocator is initialized.
rcutils_allocator_t rcl_allocator_t
Encapsulation of an allocator.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_init_options_init(rcl_init_options_t *init_options, rcl_allocator_t allocator)
Initialize given init_options with the default values and implementation specific values.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_init_options_set_domain_id(rcl_init_options_t *init_options, size_t domain_id)
Set a domain id in the init options provided.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_init_options_copy(const rcl_init_options_t *src, rcl_init_options_t *dst)
Copy the given source init_options to the destination init_options.
RCL_PUBLIC RCL_WARN_UNUSED rcl_init_options_t rcl_get_zero_initialized_init_options(void)
Return a zero initialized rcl_init_options_t struct.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_init_options_get_domain_id(const rcl_init_options_t *init_options, size_t *domain_id)
Return the domain_id stored in the init options.
RCL_PUBLIC RCL_WARN_UNUSED const rcl_allocator_t * rcl_init_options_get_allocator(const rcl_init_options_t *init_options)
Return the allocator stored in the init_options.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_init_options_fini(rcl_init_options_t *init_options)
Finalize the given init_options.
RCL_PUBLIC RCL_WARN_UNUSED rmw_init_options_t * rcl_init_options_get_rmw_init_options(rcl_init_options_t *init_options)
Return the rmw init options which are stored internally.
Encapsulation of init options and implementation defined init options.
rcl_init_options_impl_t * impl
Implementation specific pointer.
#define RCL_RET_ALREADY_INIT
rcl_init() already called return code.
#define RCL_RET_OK
Success return code.
#define RCL_RET_BAD_ALLOC
Failed to allocate memory return code.
#define RCL_RET_INVALID_ARGUMENT
Invalid argument return code.
#define RCL_RET_ERROR
Unspecified error return code.
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.