@@ -143,97 +143,18 @@ __rmw_get_clients_info_by_service(
143143 return ret;
144144 }
145145 auto common_context = static_cast <rmw_dds_common::Context *>(node->context ->impl ->common );
146- std::string mangled_rq_topic_name, mangled_rp_topic_name;
147- mangled_rq_topic_name = mangled_rp_topic_name = service_name;
146+ std::string mangled_rp_topic_name = service_name;
148147 DemangleFunction demangle_type = _identity_demangle;
149148 if (!no_mangle) {
150- mangled_rq_topic_name = \
151- _mangle_topic_name (ros_service_requester_prefix, service_name, " Request" ).to_string ();
152149 mangled_rp_topic_name = \
153150 _mangle_topic_name (ros_service_response_prefix, service_name, " Reply" ).to_string ();
154151 demangle_type = _demangle_if_ros_type;
155152 }
156- rmw_topic_endpoint_info_array_t publishers_info = \
157- rmw_get_zero_initialized_topic_endpoint_info_array ();
158- ret = common_context->graph_cache .get_writers_info_by_topic (
159- mangled_rq_topic_name,
160- demangle_type,
161- allocator,
162- &publishers_info);
163- std::unique_ptr<
164- rmw_topic_endpoint_info_array_t ,
165- std::function<void (rmw_topic_endpoint_info_array_t *)>>
166- publishers_info_delete_on_error (
167- &publishers_info,
168- [allocator](rmw_topic_endpoint_info_array_t * p) {
169- rmw_ret_t ret = rmw_topic_endpoint_info_array_fini (
170- p,
171- allocator
172- );
173- if (RMW_RET_OK != ret) {
174- RCUTILS_SAFE_FWRITE_TO_STDERR (" Failed to destroy publishers_info when function failed." );
175- }
176- }
177- );
178- if (RMW_RET_OK != ret) {
179- return ret;
180- }
181- rmw_topic_endpoint_info_array_t subscriptions_info = \
182- rmw_get_zero_initialized_topic_endpoint_info_array ();
183- ret = common_context->graph_cache .get_readers_info_by_topic (
153+ return common_context->graph_cache .get_readers_info_by_topic (
184154 mangled_rp_topic_name,
185155 demangle_type,
186156 allocator,
187- &subscriptions_info);
188- std::unique_ptr<
189- rmw_topic_endpoint_info_array_t ,
190- std::function<void (rmw_topic_endpoint_info_array_t *)>>
191- subscriptions_info_delete_on_error (
192- &subscriptions_info,
193- [allocator](rmw_topic_endpoint_info_array_t * p) {
194- rmw_ret_t ret = rmw_topic_endpoint_info_array_fini (
195- p,
196- allocator
197- );
198- if (RMW_RET_OK != ret) {
199- RCUTILS_SAFE_FWRITE_TO_STDERR (" Failed to destroy subscriptions_info when function failed." );
200- }
201- }
202- );
203- if (RMW_RET_OK != ret) {
204- return ret;
205- }
206-
207- size_t total_size = publishers_info.size + subscriptions_info.size ;
208- ret = rmw_topic_endpoint_info_array_init_with_size (clients_info, total_size, allocator);
209- std::unique_ptr<
210- rmw_topic_endpoint_info_array_t ,
211- std::function<void (rmw_topic_endpoint_info_array_t *)>>
212- clients_info_delete_on_error (
213- clients_info,
214- [allocator](rmw_topic_endpoint_info_array_t * p) {
215- rmw_ret_t ret = rmw_topic_endpoint_info_array_fini (
216- p,
217- allocator
218- );
219- if (RMW_RET_OK != ret) {
220- RCUTILS_SAFE_FWRITE_TO_STDERR (" Failed to destroy clients_info when function failed." );
221- }
222- }
223- );
224- if (RMW_RET_OK != ret) {
225- return ret;
226- }
227- for (size_t i = 0 ; i < publishers_info.size ; ++i) {
228- clients_info->info_array [i] = publishers_info.info_array [i];
229- }
230- for (size_t i = 0 ; i < subscriptions_info.size ; ++i) {
231- clients_info->info_array [publishers_info.size + i] = subscriptions_info.info_array [i];
232- }
233- publishers_info_delete_on_error.release ();
234- subscriptions_info_delete_on_error.release ();
235- clients_info_delete_on_error.release ();
236- return RMW_RET_OK;
157+ clients_info);
237158}
238159
239160rmw_ret_t
@@ -255,96 +176,18 @@ __rmw_get_servers_info_by_service(
255176 return ret;
256177 }
257178 auto common_context = static_cast <rmw_dds_common::Context *>(node->context ->impl ->common );
258- std::string mangled_rq_topic_name, mangled_rp_topic_name;
259- mangled_rq_topic_name = mangled_rp_topic_name = service_name;
179+ std::string mangled_rp_topic_name = service_name;
260180 DemangleFunction demangle_type = _identity_demangle;
261181 if (!no_mangle) {
262- mangled_rq_topic_name = \
263- _mangle_topic_name (ros_service_requester_prefix, service_name, " Request" ).to_string ();
264182 mangled_rp_topic_name = \
265183 _mangle_topic_name (ros_service_response_prefix, service_name, " Reply" ).to_string ();
266184 demangle_type = _demangle_if_ros_type;
267185 }
268- rmw_topic_endpoint_info_array_t subscriptions_info = \
269- rmw_get_zero_initialized_topic_endpoint_info_array ();
270- ret = common_context->graph_cache .get_readers_info_by_topic (
271- mangled_rq_topic_name,
272- demangle_type,
273- allocator,
274- &subscriptions_info);
275- std::unique_ptr<
276- rmw_topic_endpoint_info_array_t ,
277- std::function<void (rmw_topic_endpoint_info_array_t *)>>
278- subscriptions_info_delete_on_error (
279- &subscriptions_info,
280- [allocator](rmw_topic_endpoint_info_array_t * p) {
281- rmw_ret_t ret = rmw_topic_endpoint_info_array_fini (
282- p,
283- allocator
284- );
285- if (RMW_RET_OK != ret) {
286- RCUTILS_SAFE_FWRITE_TO_STDERR (" Failed to destroy subscriptions_info when function failed." );
287- }
288- }
289- );
290- if (RMW_RET_OK != ret) {
291- return ret;
292- }
293- rmw_topic_endpoint_info_array_t publishers_info = \
294- rmw_get_zero_initialized_topic_endpoint_info_array ();
295- ret = common_context->graph_cache .get_writers_info_by_topic (
186+
187+ return common_context->graph_cache .get_writers_info_by_topic (
296188 mangled_rp_topic_name,
297189 demangle_type,
298190 allocator,
299- &publishers_info);
300- std::unique_ptr<
301- rmw_topic_endpoint_info_array_t ,
302- std::function<void (rmw_topic_endpoint_info_array_t *)>>
303- publishers_info_delete_on_error (
304- &publishers_info,
305- [allocator](rmw_topic_endpoint_info_array_t * p) {
306- rmw_ret_t ret = rmw_topic_endpoint_info_array_fini (
307- p,
308- allocator
309- );
310- if (RMW_RET_OK != ret) {
311- RCUTILS_SAFE_FWRITE_TO_STDERR (" Failed to destroy publishers_info when function failed." );
312- }
313- }
314- );
315- if (RMW_RET_OK != ret) {
316- return ret;
317- }
318-
319- size_t total_size = publishers_info.size + subscriptions_info.size ;
320- ret = rmw_topic_endpoint_info_array_init_with_size (servers_info, total_size, allocator);
321- std::unique_ptr<
322- rmw_topic_endpoint_info_array_t ,
323- std::function<void (rmw_topic_endpoint_info_array_t *)>>
324- servers_info_delete_on_error (
325- servers_info,
326- [allocator](rmw_topic_endpoint_info_array_t * p) {
327- rmw_ret_t ret = rmw_topic_endpoint_info_array_fini (
328- p,
329- allocator
330- );
331- if (RMW_RET_OK != ret) {
332- RCUTILS_SAFE_FWRITE_TO_STDERR (" Failed to destroy servers_info when function failed." );
333- }
334- }
335- );
336- if (RMW_RET_OK != ret) {
337- return ret;
338- }
339- for (size_t i = 0 ; i < publishers_info.size ; ++i) {
340- servers_info->info_array [i] = publishers_info.info_array [i];
341- }
342- for (size_t i = 0 ; i < subscriptions_info.size ; ++i) {
343- servers_info->info_array [publishers_info.size + i] = subscriptions_info.info_array [i];
344- }
345- publishers_info_delete_on_error.release ();
346- subscriptions_info_delete_on_error.release ();
347- servers_info_delete_on_error.release ();
348- return RMW_RET_OK;
191+ servers_info);
349192}
350193} // namespace rmw_fastrtps_shared_cpp
0 commit comments