25 #include "rcl/error_handling.h"
26 #include "rcutils/env.h"
27 #include "rcutils/logging_macros.h"
28 #include "rcutils/strdup.h"
42 #pragma section(".CRT$XCU", read)
43 #define INITIALIZER2_(f, p) \
44 static void f(void); \
45 __declspec(allocate(".CRT$XCU"))void(*f ## _)(void) = f; \
46 __pragma(comment(linker, "/include:" p #f "_")) \
49 #define INITIALIZER(f) INITIALIZER2_(f, "")
51 #define INITIALIZER(f) INITIALIZER2_(f, "_")
54 #define INITIALIZER(f) \
55 static void f(void) __attribute__((constructor)); \
68 char * expected_rmw_impl = NULL;
69 const char * expected_rmw_impl_env = NULL;
70 const char * get_env_error_str = rcutils_get_env(
72 &expected_rmw_impl_env);
73 if (NULL != get_env_error_str) {
74 RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
79 if (strlen(expected_rmw_impl_env) > 0) {
81 expected_rmw_impl = rcutils_strdup(expected_rmw_impl_env, allocator);
82 if (!expected_rmw_impl) {
83 RCL_SET_ERROR_MSG(
"allocation failed");
88 char * asserted_rmw_impl = NULL;
89 const char * asserted_rmw_impl_env = NULL;
90 get_env_error_str = rcutils_get_env(
92 if (NULL != get_env_error_str) {
93 RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
94 "Error getting env var '"
100 if (strlen(asserted_rmw_impl_env) > 0) {
102 asserted_rmw_impl = rcutils_strdup(asserted_rmw_impl_env, allocator);
103 if (!asserted_rmw_impl) {
104 RCL_SET_ERROR_MSG(
"allocation failed");
111 if (expected_rmw_impl && asserted_rmw_impl && strcmp(expected_rmw_impl, asserted_rmw_impl) != 0) {
112 RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
113 "Values of RMW_IMPLEMENTATION ('%s') and RCL_ASSERT_RMW_ID_MATCHES ('%s') environment "
114 "variables do not match, exiting with %d.",
123 if (expected_rmw_impl && asserted_rmw_impl) {
126 allocator.deallocate(asserted_rmw_impl, allocator.state);
127 asserted_rmw_impl = NULL;
131 if (asserted_rmw_impl) {
132 expected_rmw_impl = asserted_rmw_impl;
133 asserted_rmw_impl = NULL;
138 if (expected_rmw_impl) {
139 const char * actual_rmw_impl_id = rmw_get_implementation_identifier();
140 const rcutils_error_string_t rmw_error_msg = rcl_get_error_string();
142 if (!actual_rmw_impl_id) {
143 RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
144 "Error getting RMW implementation identifier / RMW implementation not installed "
145 "(expected identifier of '%s'), with error message '%s', exiting with %d.",
153 if (strcmp(actual_rmw_impl_id, expected_rmw_impl) != 0) {
154 RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
155 "Expected RMW implementation identifier of '%s' but instead found '%s', exiting with %d.",
167 allocator.deallocate(expected_rmw_impl, allocator.state);
168 allocator.deallocate(asserted_rmw_impl, allocator.state);
172 INITIALIZER(initialize) {
175 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.