20 #include <rcutils/logging_macros.h>
21 #include <rosidl_runtime_c/message_type_support_struct.h>
22 #include <rosidl_runtime_c/type_description/type_description__struct.h>
24 #include "rmw/dynamic_message_type_support.h"
27 #include "rcl/common.h"
28 #include "rcl/error_handling.h"
29 #include "rcl/dynamic_message_type_support.h"
30 #include "rcl/type_hash.h"
38 rcl_dynamic_message_type_support_handle_init(
39 const char * serialization_lib_name,
40 const rosidl_runtime_c__type_description__TypeDescription * description,
42 rosidl_message_type_support_t * ts)
44 RCUTILS_CHECK_ARGUMENT_FOR_NULL(ts, RCUTILS_RET_INVALID_ARGUMENT);
45 RCUTILS_CHECK_ARGUMENT_FOR_NULL(allocator, RCUTILS_RET_INVALID_ARGUMENT);
46 if (!rcutils_allocator_is_valid(allocator)) {
47 RCUTILS_SET_ERROR_MSG(
"allocator is invalid");
48 return RCUTILS_RET_INVALID_ARGUMENT;
52 if (description == NULL) {
53 RCUTILS_SET_ERROR_MSG(
54 "Deferred type description is not currently supported. You must provide a type description.");
55 return RCUTILS_RET_INVALID_ARGUMENT;
58 bool middleware_supports_type_discovery = rmw_feature_supported(
59 RMW_MIDDLEWARE_SUPPORTS_TYPE_DISCOVERY);
60 if (!middleware_supports_type_discovery && description == NULL) {
62 "Middleware does not support type discovery. Deferred dynamic type message type support will "
63 "never be populated. You must provide a type description.");
64 return RCUTILS_RET_INVALID_ARGUMENT;
67 if (description == NULL) {
69 "Deferred type description is not currently supported. You must provide a type description.");
70 return RCUTILS_RET_INVALID_ARGUMENT;
73 rosidl_dynamic_typesupport_serialization_support_t serialization_support;
74 rcl_ret_t ret = rcl_convert_rmw_ret_to_rcl_ret(
75 rmw_serialization_support_init(serialization_lib_name, allocator, &serialization_support));
77 RCL_SET_ERROR_MSG(
"failed to get serialization support");
85 rosidl_type_hash_t type_hash;
86 ret = rcl_calculate_type_hash(
89 (
const type_description_interfaces__msg__TypeDescription *) description, &type_hash);
91 RCL_SET_ERROR_MSG(
"failed to get type hash");
95 ret = rcl_convert_rcutils_ret_to_rcl_ret(
96 rosidl_dynamic_message_type_support_handle_init(
97 &serialization_support,
106 rcutils_error_string_t error_string = rcutils_get_error_string();
107 rcutils_reset_error();
108 RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
109 "failed to init rosidl_message_type_support:\n%s", error_string.str);
119 rcl_dynamic_message_type_support_handle_fini(rosidl_message_type_support_t * ts)
122 return rcl_convert_rcutils_ret_to_rcl_ret(rosidl_dynamic_message_type_support_handle_fini(ts));
rcutils_allocator_t rcl_allocator_t
Encapsulation of an allocator.
#define RCL_RET_OK
Success return code.
#define RCL_RET_INVALID_ARGUMENT
Invalid argument return code.
#define RCL_RET_ERROR
Unspecified error return code.
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.