25 #include "rcl/error_handling.h"
26 #include "rcutils/env.h"
27 #include "rcutils/logging_macros.h"
28 #include "rcutils/strdup.h"
40 #pragma section(".CRT$XCU", read)
41 #define INITIALIZER2_(f, p) \
42 static void f(void); \
43 __declspec(allocate(".CRT$XCU"))void(*f ## _)(void) = f; \
44 __pragma(comment(linker, "/include:" p #f "_")) \
47 #define INITIALIZER(f) INITIALIZER2_(f, "")
49 #define INITIALIZER(f) INITIALIZER2_(f, "_")
52 #define INITIALIZER(f) \
53 static void f(void) __attribute__((constructor)); \
64 char * expected_rmw_impl = NULL;
65 const char * expected_rmw_impl_env = NULL;
66 const char * get_env_error_str = rcutils_get_env(
68 &expected_rmw_impl_env);
69 if (NULL != get_env_error_str) {
70 RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
75 if (strlen(expected_rmw_impl_env) > 0) {
77 expected_rmw_impl = rcutils_strdup(expected_rmw_impl_env, allocator);
78 if (!expected_rmw_impl) {
79 RCL_SET_ERROR_MSG(
"allocation failed");
84 char * asserted_rmw_impl = NULL;
85 const char * asserted_rmw_impl_env = NULL;
86 get_env_error_str = rcutils_get_env(
88 if (NULL != get_env_error_str) {
89 RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
90 "Error getting env var '"
96 if (strlen(asserted_rmw_impl_env) > 0) {
98 asserted_rmw_impl = rcutils_strdup(asserted_rmw_impl_env, allocator);
99 if (!asserted_rmw_impl) {
100 RCL_SET_ERROR_MSG(
"allocation failed");
107 if (expected_rmw_impl && asserted_rmw_impl && strcmp(expected_rmw_impl, asserted_rmw_impl) != 0) {
108 RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
109 "Values of RMW_IMPLEMENTATION ('%s') and RCL_ASSERT_RMW_ID_MATCHES ('%s') environment "
110 "variables do not match, exiting with %d.",
119 if (expected_rmw_impl && asserted_rmw_impl) {
122 allocator.deallocate(asserted_rmw_impl, allocator.state);
123 asserted_rmw_impl = NULL;
127 if (asserted_rmw_impl) {
128 expected_rmw_impl = asserted_rmw_impl;
129 asserted_rmw_impl = NULL;
134 if (expected_rmw_impl) {
135 const char * actual_rmw_impl_id = rmw_get_implementation_identifier();
136 const rcutils_error_string_t rmw_error_msg = rcl_get_error_string();
138 if (!actual_rmw_impl_id) {
139 RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
140 "Error getting RMW implementation identifier / RMW implementation not installed "
141 "(expected identifier of '%s'), with error message '%s', exiting with %d.",
149 if (strcmp(actual_rmw_impl_id, expected_rmw_impl) != 0) {
150 RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
151 "Expected RMW implementation identifier of '%s' but instead found '%s', exiting with %d.",
163 allocator.deallocate(expected_rmw_impl, allocator.state);
164 allocator.deallocate(asserted_rmw_impl, allocator.state);
168 INITIALIZER(initialize) {
171 RCUTILS_LOG_ERROR_NAMED(ROS_PACKAGE_NAME,
"%s\n", rcl_get_error_string().str);
#define rcl_get_default_allocator
Return a properly initialized rcl_allocator_t with default values.
rcutils_allocator_t rcl_allocator_t
Encapsulation of an allocator.
#define RMW_IMPLEMENTATION_ENV_VAR_NAME
The environment variable name to control which RMW implementation is used.
#define RCL_ASSERT_RMW_ID_MATCHES_ENV_VAR_NAME
RCL_PUBLIC rcl_ret_t rcl_rmw_implementation_identifier_check(void)
Check whether the RMW implementation in use matches what the user requested.
#define RCL_RET_OK
Success return code.
#define RCL_RET_BAD_ALLOC
Failed to allocate memory return code.
#define RCL_RET_MISMATCHED_RMW_ID
Mismatched rmw identifier return code.
#define RCL_RET_ERROR
Unspecified error return code.
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.