25 #include "./init_options_impl.h"
28 #include "rcl/error_handling.h"
31 #include "rcutils/logging_macros.h"
33 #include "rmw/error_handling.h"
35 #include "rmw/ret_types.h"
51 RCL_CHECK_FOR_NULL_WITH_MSG(
53 "failed to allocate memory for init options impl",
55 init_options->
impl->allocator = allocator;
56 init_options->
impl->rmw_init_options = rmw_get_zero_initialized_init_options();
70 if (NULL != init_options->
impl) {
71 RCL_SET_ERROR_MSG(
"given init_options (rcl_init_options_t) is already initialized");
76 rcl_ret_t ret = _rcl_init_options_zero_init(init_options, allocator);
80 rmw_ret_t rmw_ret = rmw_init_options_init(&(init_options->
impl->rmw_init_options), allocator);
81 if (RMW_RET_OK != rmw_ret) {
82 allocator.deallocate(init_options->
impl, allocator.state);
83 RCL_SET_ERROR_MSG(rmw_get_error_string().str);
84 return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret);
90 init_options->
impl->rmw_init_options.discovery_options.automatic_discovery_range =
91 RMW_AUTOMATIC_DISCOVERY_RANGE_NOT_SET;
107 if (NULL != dst->
impl) {
108 RCL_SET_ERROR_MSG(
"given dst (rcl_init_options_t) is already initialized");
113 rcl_ret_t ret = _rcl_init_options_zero_init(dst, src->
impl->allocator);
120 rmw_init_options_copy(&(src->
impl->rmw_init_options), &(dst->
impl->rmw_init_options));
121 if (RMW_RET_OK != rmw_ret) {
122 rmw_error_string_t error_string = rmw_get_error_string();
126 RCUTILS_LOG_ERROR_NAMED(
128 "failed to finalize dst rcl_init_options while handling failure to "
129 "copy rmw_init_options, original ret '%d' and error: %s", rmw_ret, error_string.str);
132 RCL_SET_ERROR_MSG(error_string.str);
133 return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret);
146 rmw_ret_t rmw_ret = rmw_init_options_fini(&(init_options->
impl->rmw_init_options));
147 if (RMW_RET_OK != rmw_ret) {
148 RCL_SET_ERROR_MSG(rmw_get_error_string().str);
149 return rcl_convert_rmw_ret_to_rcl_ret(rmw_ret);
151 allocator.deallocate(init_options->
impl, allocator.state);
161 *domain_id = init_options->
impl->rmw_init_options.domain_id;
170 init_options->
impl->rmw_init_options.domain_id = domain_id;
177 RCL_CHECK_ARGUMENT_FOR_NULL(init_options, NULL);
178 RCL_CHECK_ARGUMENT_FOR_NULL(init_options->
impl, NULL);
179 return &(init_options->
impl->rmw_init_options);
185 RCL_CHECK_ARGUMENT_FOR_NULL(init_options, NULL);
186 RCL_CHECK_ARGUMENT_FOR_NULL(init_options->
impl, NULL);
187 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.