25 #include "rcl/error_handling.h"
26 #include "rcutils/env.h"
27 #include "rcutils/error_handling.h"
28 #include "rcutils/logging_macros.h"
29 #include "rcutils/strdup.h"
43 #pragma section(".CRT$XCU", read)
44 #define INITIALIZER2_(f, p) \
45 static void f(void); \
46 __declspec(allocate(".CRT$XCU"))void(*f ## _)(void) = f; \
47 __pragma(comment(linker, "/include:" p #f "_")) \
50 #define INITIALIZER(f) INITIALIZER2_(f, "")
52 #define INITIALIZER(f) INITIALIZER2_(f, "_")
55 #define INITIALIZER(f) \
56 static void f(void) __attribute__((constructor)); \
69 char * expected_rmw_impl = NULL;
70 const char * expected_rmw_impl_env = NULL;
71 const char * get_env_error_str = rcutils_get_env(
73 &expected_rmw_impl_env);
74 if (NULL != get_env_error_str) {
75 RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
80 if (strlen(expected_rmw_impl_env) > 0) {
82 expected_rmw_impl = rcutils_strdup(expected_rmw_impl_env, allocator);
83 if (!expected_rmw_impl) {
84 RCL_SET_ERROR_MSG(
"allocation failed");
89 char * asserted_rmw_impl = NULL;
90 const char * asserted_rmw_impl_env = NULL;
91 get_env_error_str = rcutils_get_env(
93 if (NULL != get_env_error_str) {
94 RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
95 "Error getting env var '"
101 if (strlen(asserted_rmw_impl_env) > 0) {
103 asserted_rmw_impl = rcutils_strdup(asserted_rmw_impl_env, allocator);
104 if (!asserted_rmw_impl) {
105 RCL_SET_ERROR_MSG(
"allocation failed");
112 if (expected_rmw_impl && asserted_rmw_impl && strcmp(expected_rmw_impl, asserted_rmw_impl) != 0) {
113 RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
114 "Values of RMW_IMPLEMENTATION ('%s') and RCL_ASSERT_RMW_ID_MATCHES ('%s') environment "
115 "variables do not match, exiting with %d.",
124 if (expected_rmw_impl && asserted_rmw_impl) {
127 allocator.deallocate(asserted_rmw_impl, allocator.state);
128 asserted_rmw_impl = NULL;
132 if (asserted_rmw_impl) {
133 expected_rmw_impl = asserted_rmw_impl;
134 asserted_rmw_impl = NULL;
139 if (expected_rmw_impl) {
140 const char * actual_rmw_impl_id = rmw_get_implementation_identifier();
141 const rcutils_error_string_t rmw_error_msg = rcl_get_error_string();
143 if (!actual_rmw_impl_id) {
144 RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
145 "Error getting RMW implementation identifier / RMW implementation not installed "
146 "(expected identifier of '%s'), with error message '%s', exiting with %d.",
154 if (strcmp(actual_rmw_impl_id, expected_rmw_impl) != 0) {
155 RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
156 "Expected RMW implementation identifier of '%s' but instead found '%s', exiting with %d.",
168 allocator.deallocate(expected_rmw_impl, allocator.state);
169 allocator.deallocate(asserted_rmw_impl, allocator.state);
173 INITIALIZER(initialize) {
176 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.