@@ -91,40 +91,36 @@ extract_type_identifier(const std::string & full_type)
9191 return std::make_tuple (package_name, middle_module, type_name);
9292}
9393
94- } // anonymous namespace
95-
96- std::shared_ptr<rcpputils::SharedLibrary>
97- get_typesupport_library (const std::string & type, const std::string & typesupport_identifier)
98- {
99- auto package_name = std::get<0 >(extract_type_identifier (type));
100- auto library_path = get_typesupport_library_path (package_name, typesupport_identifier);
101- return std::make_shared<rcpputils::SharedLibrary>(library_path);
102- }
103-
104- const rosidl_message_type_support_t *
105- get_typesupport_handle (
94+ const void * get_typesupport_handle_impl (
10695 const std::string & type,
10796 const std::string & typesupport_identifier,
97+ const std::string & typesupport_name,
98+ const std::string & symbol_part_name,
99+ const std::string & middle_module_additional,
108100 rcpputils::SharedLibrary & library)
109101{
110102 std::string package_name;
111103 std::string middle_module;
112104 std::string type_name;
113105 std::tie (package_name, middle_module, type_name) = extract_type_identifier (type);
114106
115- auto mk_error = [&package_name, &type_name](auto reason) {
107+ if (middle_module.empty ()) {
108+ middle_module = middle_module_additional;
109+ }
110+
111+ auto mk_error = [&package_name, &type_name, &typesupport_name](auto reason) {
116112 std::stringstream rcutils_dynamic_loading_error;
117113 rcutils_dynamic_loading_error <<
118- " Something went wrong loading the typesupport library for message type " << package_name <<
114+ " Something went wrong loading the typesupport library for " <<
115+ typesupport_name << " type " << package_name <<
119116 " /" << type_name << " . " << reason;
120117 return rcutils_dynamic_loading_error.str ();
121118 };
122119
123120 try {
124- std::string symbol_name = typesupport_identifier + " __get_message_type_support_handle__" +
125- package_name + " __" + (middle_module.empty () ? " msg" : middle_module) + " __" + type_name;
126-
127- const rosidl_message_type_support_t * (* get_ts)() = nullptr ;
121+ std::string symbol_name = typesupport_identifier + symbol_part_name +
122+ package_name + " __" + middle_module + " __" + type_name;
123+ const void * (* get_ts)() = nullptr ;
128124 // This will throw runtime_error if the symbol was not found.
129125 get_ts = reinterpret_cast <decltype (get_ts)>(library.get_symbol (symbol_name));
130126 return get_ts ();
@@ -133,4 +129,52 @@ get_typesupport_handle(
133129 }
134130}
135131
132+ } // anonymous namespace
133+
134+ std::shared_ptr<rcpputils::SharedLibrary>
135+ get_typesupport_library (const std::string & type, const std::string & typesupport_identifier)
136+ {
137+ auto package_name = std::get<0 >(extract_type_identifier (type));
138+ auto library_path = get_typesupport_library_path (package_name, typesupport_identifier);
139+ return std::make_shared<rcpputils::SharedLibrary>(library_path);
140+ }
141+
142+ const rosidl_message_type_support_t * get_typesupport_handle (
143+ const std::string & type,
144+ const std::string & typesupport_identifier,
145+ rcpputils::SharedLibrary & library)
146+ {
147+ return get_message_typesupport_handle (type, typesupport_identifier, library);
148+ }
149+
150+ const rosidl_message_type_support_t * get_message_typesupport_handle (
151+ const std::string & type,
152+ const std::string & typesupport_identifier,
153+ rcpputils::SharedLibrary & library)
154+ {
155+ static const std::string typesupport_name = " message" ;
156+ static const std::string symbol_part_name = " __get_message_type_support_handle__" ;
157+ static const std::string middle_module_additional = " msg" ;
158+
159+ return static_cast <const rosidl_message_type_support_t *>(get_typesupport_handle_impl (
160+ type, typesupport_identifier, typesupport_name, symbol_part_name,
161+ middle_module_additional, library
162+ ));
163+ }
164+
165+ const rosidl_service_type_support_t * get_service_typesupport_handle (
166+ const std::string & type,
167+ const std::string & typesupport_identifier,
168+ rcpputils::SharedLibrary & library)
169+ {
170+ static const std::string typesupport_name = " service" ;
171+ static const std::string symbol_part_name = " __get_service_type_support_handle__" ;
172+ static const std::string middle_module_additional = " srv" ;
173+
174+ return static_cast <const rosidl_service_type_support_t *>(get_typesupport_handle_impl (
175+ type, typesupport_identifier, typesupport_name, symbol_part_name,
176+ middle_module_additional, library
177+ ));
178+ }
179+
136180} // namespace rclcpp
0 commit comments