@@ -33,6 +33,13 @@ typedef rcl_ret_t (*rcl_get_info_by_topic_func_t)(
3333 const char * topic_name, bool no_mangle,
3434 rcl_topic_endpoint_info_array_t * info_array);
3535
36+ #if ROS_VERSION > 2505
37+ typedef rcl_ret_t (*rcl_get_info_by_service_func_t )(
38+ const rcl_node_t * node, rcutils_allocator_t * allocator,
39+ const char * service_name, bool no_mangle,
40+ rcl_service_endpoint_info_array_t * info_array);
41+ #endif // ROS_VERSION > 2505
42+
3643Napi::Value GetPublisherNamesAndTypesByNode (const Napi::CallbackInfo& info) {
3744 Napi::Env env = info.Env ();
3845
@@ -257,6 +264,66 @@ Napi::Value GetSubscriptionsInfoByTopic(const Napi::CallbackInfo& info) {
257264 " subscriptions" , rcl_get_subscriptions_info_by_topic);
258265}
259266
267+ #if ROS_VERSION > 2505
268+ Napi::Value GetInfoByService (
269+ Napi::Env env, rcl_node_t * node, const char * service_name, bool no_mangle,
270+ const char * type, rcl_get_info_by_service_func_t rcl_get_info_by_service) {
271+ rcutils_allocator_t allocator = rcutils_get_default_allocator ();
272+ rcl_service_endpoint_info_array_t info_array =
273+ rcl_get_zero_initialized_service_endpoint_info_array ();
274+
275+ RCPPUTILS_SCOPE_EXIT ({
276+ rcl_ret_t fini_ret =
277+ rcl_service_endpoint_info_array_fini (&info_array, &allocator);
278+ if (RCL_RET_OK != fini_ret) {
279+ Napi::Error::New (env, rcl_get_error_string ().str )
280+ .ThrowAsJavaScriptException ();
281+ rcl_reset_error ();
282+ }
283+ });
284+
285+ rcl_ret_t ret = rcl_get_info_by_service (node, &allocator, service_name,
286+ no_mangle, &info_array);
287+ if (RCL_RET_OK != ret) {
288+ if (RCL_RET_UNSUPPORTED == ret) {
289+ Napi::Error::New (
290+ env, std::string (" Failed to get information by service for " ) + type +
291+ " : function not supported by RMW_IMPLEMENTATION" )
292+ .ThrowAsJavaScriptException ();
293+ return env.Undefined ();
294+ }
295+ Napi::Error::New (
296+ env, std::string (" Failed to get information by service for " ) + type)
297+ .ThrowAsJavaScriptException ();
298+ return env.Undefined ();
299+ }
300+
301+ return ConvertToJSServiceEndpointInfoList (env, &info_array);
302+ }
303+ #endif // ROS_VERSION > 2505
304+
305+ #if ROS_VERSION > 2505
306+ Napi::Value GetClientsInfoByService (const Napi::CallbackInfo& info) {
307+ RclHandle* node_handle = RclHandle::Unwrap (info[0 ].As <Napi::Object>());
308+ rcl_node_t * node = reinterpret_cast <rcl_node_t *>(node_handle->ptr ());
309+ std::string service_name = info[1 ].As <Napi::String>().Utf8Value ();
310+ bool no_mangle = info[2 ].As <Napi::Boolean>();
311+
312+ return GetInfoByService (info.Env (), node, service_name.c_str (), no_mangle,
313+ " clients" , rcl_get_clients_info_by_service);
314+ }
315+
316+ Napi::Value GetServersInfoByService (const Napi::CallbackInfo& info) {
317+ RclHandle* node_handle = RclHandle::Unwrap (info[0 ].As <Napi::Object>());
318+ rcl_node_t * node = reinterpret_cast <rcl_node_t *>(node_handle->ptr ());
319+ std::string service_name = info[1 ].As <Napi::String>().Utf8Value ();
320+ bool no_mangle = info[2 ].As <Napi::Boolean>();
321+
322+ return GetInfoByService (info.Env (), node, service_name.c_str (), no_mangle,
323+ " servers" , rcl_get_servers_info_by_service);
324+ }
325+ #endif // ROS_VERSION > 2505
326+
260327Napi::Object InitGraphBindings (Napi::Env env, Napi::Object exports) {
261328 exports.Set (" getPublisherNamesAndTypesByNode" ,
262329 Napi::Function::New (env, GetPublisherNamesAndTypesByNode));
@@ -274,6 +341,12 @@ Napi::Object InitGraphBindings(Napi::Env env, Napi::Object exports) {
274341 Napi::Function::New (env, GetPublishersInfoByTopic));
275342 exports.Set (" getSubscriptionsInfoByTopic" ,
276343 Napi::Function::New (env, GetSubscriptionsInfoByTopic));
344+ #if ROS_VERSION > 2505
345+ exports.Set (" getClientsInfoByService" ,
346+ Napi::Function::New (env, GetClientsInfoByService));
347+ exports.Set (" getServersInfoByService" ,
348+ Napi::Function::New (env, GetServersInfoByService));
349+ #endif // ROS_VERSION > 2505
277350 return exports;
278351}
279352
0 commit comments