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"
36 rcl_dynamic_message_type_support_handle_init(
37 const char * serialization_lib_name,
38 const rosidl_runtime_c__type_description__TypeDescription * description,
40 rosidl_message_type_support_t * ts)
42 RCUTILS_CHECK_ARGUMENT_FOR_NULL(ts, RCUTILS_RET_INVALID_ARGUMENT);
43 RCUTILS_CHECK_ARGUMENT_FOR_NULL(allocator, RCUTILS_RET_INVALID_ARGUMENT);
44 if (!rcutils_allocator_is_valid(allocator)) {
45 RCUTILS_SET_ERROR_MSG(
"allocator is invalid");
46 return RCUTILS_RET_INVALID_ARGUMENT;
50 if (description == NULL) {
51 RCUTILS_SET_ERROR_MSG(
52 "Deferred type description is not currently supported. You must provide a type description.");
53 return RCUTILS_RET_INVALID_ARGUMENT;
56 bool middleware_supports_type_discovery = rmw_feature_supported(
57 RMW_MIDDLEWARE_SUPPORTS_TYPE_DISCOVERY);
58 if (!middleware_supports_type_discovery && description == NULL) {
60 "Middleware does not support type discovery. Deferred dynamic type message type support will "
61 "never be populated. You must provide a type description.");
62 return RCUTILS_RET_INVALID_ARGUMENT;
65 if (description == NULL) {
67 "Deferred type description is not currently supported. You must provide a type description.");
68 return RCUTILS_RET_INVALID_ARGUMENT;
71 rosidl_dynamic_typesupport_serialization_support_t serialization_support;
72 rcl_ret_t ret = rcl_convert_rmw_ret_to_rcl_ret(
73 rmw_serialization_support_init(serialization_lib_name, allocator, &serialization_support));
75 RCL_SET_ERROR_MSG(
"failed to get serialization support");
83 rosidl_type_hash_t type_hash;
84 ret = rcl_calculate_type_hash(
87 (
const type_description_interfaces__msg__TypeDescription *) description, &type_hash);
89 RCL_SET_ERROR_MSG(
"failed to get type hash");
93 ret = rcl_convert_rcutils_ret_to_rcl_ret(
94 rosidl_dynamic_message_type_support_handle_init(
95 &serialization_support,
104 rcutils_error_string_t error_string = rcutils_get_error_string();
105 rcutils_reset_error();
106 RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
107 "failed to init rosidl_message_type_support:\n%s", error_string.str);
115 rcl_dynamic_message_type_support_handle_fini(rosidl_message_type_support_t * ts)
118 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.