25 #include "./context_impl.h"
26 #include "rcutils/stdatomic_helper.h"
33 .instance_id_storage = {0},
39 sizeof(context.instance_id_storage) >=
sizeof(atomic_uint_least64_t),
40 "expected rcl_context_t's instance id storage to be >= size of atomic_uint_least64_t");
42 atomic_init((atomic_uint_least64_t *)(&context.instance_id_storage), 0);
57 RCL_SET_ERROR_MSG(
"rcl_shutdown() not called on the given context");
62 return __cleanup_context(context);
70 RCL_CHECK_ARGUMENT_FOR_NULL(context, NULL);
71 RCL_CHECK_FOR_NULL_WITH_MSG(context->
impl,
"context is zero-initialized",
return NULL);
78 RCL_CHECK_ARGUMENT_FOR_NULL(context, 0);
79 return rcutils_atomic_load_uint64_t((atomic_uint_least64_t *)(&context->instance_id_storage));
96 RCL_CHECK_ARGUMENT_FOR_NULL(context,
false);
103 RCL_CHECK_ARGUMENT_FOR_NULL(context, NULL);
104 RCL_CHECK_FOR_NULL_WITH_MSG(context->
impl,
"context is zero-initialized",
return NULL);
113 rcutils_atomic_store((atomic_uint_least64_t *)(&context->instance_id_storage), 0);
119 RCUTILS_SAFE_FWRITE_TO_STDERR(
120 "[rcl|context.c:" RCUTILS_STRINGIFY(__LINE__)
121 "] failed to finalize global arguments while cleaning up context, memory may be leaked: ");
122 RCUTILS_SAFE_FWRITE_TO_STDERR(rcl_get_error_string().str);
123 RCUTILS_SAFE_FWRITE_TO_STDERR(
"\n");
129 if (NULL != context->
impl) {
138 ret = init_options_fini_ret;
140 RCUTILS_SAFE_FWRITE_TO_STDERR(
141 "[rcl|context.c:" RCUTILS_STRINGIFY(__LINE__)
142 "] failed to finalize init options while cleaning up context, memory may be leaked: ");
143 RCUTILS_SAFE_FWRITE_TO_STDERR(rcl_get_error_string().str);
144 RCUTILS_SAFE_FWRITE_TO_STDERR(
"\n");
151 rmw_ret_t rmw_context_fini_ret = rmw_context_fini(&(context->
impl->
rmw_context));
152 if (RMW_RET_OK != rmw_context_fini_ret) {
154 ret = rcl_convert_rmw_ret_to_rcl_ret(rmw_context_fini_ret);
156 RCUTILS_SAFE_FWRITE_TO_STDERR(
157 "[rcl|context.c:" RCUTILS_STRINGIFY(__LINE__)
158 "] failed to finalize rmw context while cleaning up context, memory may be leaked: ");
159 RCUTILS_SAFE_FWRITE_TO_STDERR(rcutils_get_error_string().str);
160 RCUTILS_SAFE_FWRITE_TO_STDERR(
"\n");
161 rcutils_reset_error();
168 for (i = 0; i < context->
impl->
argc; ++i) {
169 if (NULL != context->
impl->
argv[i]) {
170 allocator.deallocate(context->
impl->
argv[i], allocator.state);
173 allocator.deallocate(context->
impl->
argv, allocator.state);
175 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.