27 #include "rcl/error_handling.h"
30 #include "rcutils/error_handling.h"
33 #include "rmw/ret_types.h"
37 #include "./context_impl.h"
38 #include "rcutils/stdatomic_helper.h"
45 .instance_id_storage = {0},
51 sizeof(context.instance_id_storage) >=
sizeof(atomic_uint_least64_t),
52 "expected rcl_context_t's instance id storage to be >= size of atomic_uint_least64_t");
54 atomic_init((atomic_uint_least64_t *)(&context.instance_id_storage), 0);
69 RCL_SET_ERROR_MSG(
"rcl_shutdown() not called on the given context");
74 return __cleanup_context(context);
82 RCL_CHECK_ARGUMENT_FOR_NULL(context, NULL);
83 RCL_CHECK_FOR_NULL_WITH_MSG(context->
impl,
"context is zero-initialized",
return NULL);
90 RCL_CHECK_ARGUMENT_FOR_NULL(context, 0);
91 return rcutils_atomic_load_uint64_t((atomic_uint_least64_t *)(&context->instance_id_storage));
108 RCL_CHECK_ARGUMENT_FOR_NULL(context,
false);
115 RCL_CHECK_ARGUMENT_FOR_NULL(context, NULL);
116 RCL_CHECK_FOR_NULL_WITH_MSG(context->
impl,
"context is zero-initialized",
return NULL);
125 rcutils_atomic_store((atomic_uint_least64_t *)(&context->instance_id_storage), 0);
131 RCUTILS_SAFE_FWRITE_TO_STDERR(
132 "[rcl|context.c:" RCUTILS_STRINGIFY(__LINE__)
133 "] failed to finalize global arguments while cleaning up context, memory may be leaked: ");
134 RCUTILS_SAFE_FWRITE_TO_STDERR(rcl_get_error_string().str);
135 RCUTILS_SAFE_FWRITE_TO_STDERR(
"\n");
141 if (NULL != context->
impl) {
150 ret = init_options_fini_ret;
152 RCUTILS_SAFE_FWRITE_TO_STDERR(
153 "[rcl|context.c:" RCUTILS_STRINGIFY(__LINE__)
154 "] failed to finalize init options while cleaning up context, memory may be leaked: ");
155 RCUTILS_SAFE_FWRITE_TO_STDERR(rcl_get_error_string().str);
156 RCUTILS_SAFE_FWRITE_TO_STDERR(
"\n");
163 rmw_ret_t rmw_context_fini_ret = rmw_context_fini(&(context->
impl->
rmw_context));
164 if (RMW_RET_OK != rmw_context_fini_ret) {
166 ret = rcl_convert_rmw_ret_to_rcl_ret(rmw_context_fini_ret);
168 RCUTILS_SAFE_FWRITE_TO_STDERR(
169 "[rcl|context.c:" RCUTILS_STRINGIFY(__LINE__)
170 "] failed to finalize rmw context while cleaning up context, memory may be leaked: ");
171 RCUTILS_SAFE_FWRITE_TO_STDERR(rcutils_get_error_string().str);
172 RCUTILS_SAFE_FWRITE_TO_STDERR(
"\n");
173 rcutils_reset_error();
180 for (i = 0; i < context->
impl->
argc; ++i) {
181 if (NULL != context->
impl->
argv[i]) {
182 allocator.deallocate(context->
impl->
argv[i], allocator.state);
185 allocator.deallocate(context->
impl->
argv, allocator.state);
187 allocator.deallocate(context->
impl, allocator.state);
#define RCL_CHECK_ALLOCATOR_WITH_MSG(allocator, msg, fail_statement)
Check that the given allocator is initialized, or fail with a message.
rcutils_allocator_t rcl_allocator_t
Encapsulation of an allocator.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_arguments_fini(rcl_arguments_t *args)
Reclaim resources held inside rcl_arguments_t structure.
RCL_PUBLIC RCL_WARN_UNUSED rcl_arguments_t rcl_get_zero_initialized_arguments(void)
Return a rcl_arguments_t struct with members initialized to NULL.
RCL_PUBLIC RCL_WARN_UNUSED rcl_context_instance_id_t rcl_context_get_instance_id(const rcl_context_t *context)
Returns an unsigned integer that is unique to the given context, or 0 if invalid.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_context_fini(rcl_context_t *context)
Finalize a context.
RCL_PUBLIC RCL_WARN_UNUSED const rcl_init_options_t * rcl_context_get_init_options(const rcl_context_t *context)
Return the init options used during initialization for this context.
RCL_PUBLIC RCL_WARN_UNUSED rmw_context_t * rcl_context_get_rmw_context(rcl_context_t *context)
Return pointer to the rmw context if the given context is currently valid, otherwise NULL.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_context_get_domain_id(rcl_context_t *context, size_t *domain_id)
Returns the context domain id.
RCL_PUBLIC RCL_WARN_UNUSED bool rcl_context_is_valid(const rcl_context_t *context)
Return true if the given context is currently valid, otherwise false.
RCL_PUBLIC RCL_WARN_UNUSED rcl_context_t rcl_get_zero_initialized_context(void)
Return a zero initialization context object.
uint64_t rcl_context_instance_id_t
A unique ID per context instance.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_init_options_fini(rcl_init_options_t *init_options)
Finalize the given init_options.
rcl_arguments_impl_t * impl
Private implementation pointer.
char ** argv
Copy of argv used during init (may be NULL).
rmw_context_t rmw_context
rmw context.
int64_t argc
Length of argv (may be 0).
rcl_init_options_t init_options
Copy of init options given during init.
rcl_allocator_t allocator
Allocator used during init and shutdown.
Encapsulates the non-global state of an init/shutdown cycle.
rcl_context_impl_t * impl
Implementation specific pointer.
rcl_arguments_t global_arguments
Global arguments for all nodes which share this context.
Encapsulation of init options and implementation defined init options.
rcl_init_options_impl_t * impl
Implementation specific pointer.
#define RCL_RET_OK
Success return code.
#define RCL_RET_INVALID_ARGUMENT
Invalid argument return code.
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.