@@ -318,6 +318,66 @@ Napi::Value ActionGetNamesAndTypes(const Napi::CallbackInfo& info) {
318318 return result_list;
319319}
320320
321+ Napi::Value CountPublishers (const Napi::CallbackInfo& info) {
322+ Napi::Env env = info.Env ();
323+
324+ RclHandle* node_handle = RclHandle::Unwrap (info[0 ].As <Napi::Object>());
325+ rcl_node_t * node = reinterpret_cast <rcl_node_t *>(node_handle->ptr ());
326+ std::string topic_name = info[1 ].As <Napi::String>().Utf8Value ();
327+
328+ size_t count = 0 ;
329+ THROW_ERROR_IF_NOT_EQUAL (
330+ RCL_RET_OK, rcl_count_publishers (node, topic_name.c_str (), &count),
331+ " Failed to count publishers." );
332+
333+ return Napi::Number::New (env, static_cast <int32_t >(count));
334+ }
335+
336+ Napi::Value CountSubscribers (const Napi::CallbackInfo& info) {
337+ Napi::Env env = info.Env ();
338+
339+ RclHandle* node_handle = RclHandle::Unwrap (info[0 ].As <Napi::Object>());
340+ rcl_node_t * node = reinterpret_cast <rcl_node_t *>(node_handle->ptr ());
341+ std::string topic_name = info[1 ].As <Napi::String>().Utf8Value ();
342+
343+ size_t count = 0 ;
344+ THROW_ERROR_IF_NOT_EQUAL (
345+ RCL_RET_OK, rcl_count_subscribers (node, topic_name.c_str (), &count),
346+ " Failed to count subscribers." );
347+
348+ return Napi::Number::New (env, static_cast <int32_t >(count));
349+ }
350+
351+ Napi::Value CountClients (const Napi::CallbackInfo& info) {
352+ Napi::Env env = info.Env ();
353+
354+ rcl_node_t * node = reinterpret_cast <rcl_node_t *>(
355+ RclHandle::Unwrap (info[0 ].As <Napi::Object>())->ptr ());
356+ std::string service_name = info[1 ].As <Napi::String>().Utf8Value ();
357+
358+ size_t count = 0 ;
359+ THROW_ERROR_IF_NOT_EQUAL (
360+ rcl_count_clients (node, service_name.c_str (), &count), RCL_RET_OK,
361+ rcl_get_error_string ().str );
362+
363+ return Napi::Number::New (env, count);
364+ }
365+
366+ Napi::Value CountServices (const Napi::CallbackInfo& info) {
367+ Napi::Env env = info.Env ();
368+
369+ rcl_node_t * node = reinterpret_cast <rcl_node_t *>(
370+ RclHandle::Unwrap (info[0 ].As <Napi::Object>())->ptr ());
371+ std::string service_name = info[1 ].As <Napi::String>().Utf8Value ();
372+
373+ size_t count = 0 ;
374+ THROW_ERROR_IF_NOT_EQUAL (
375+ rcl_count_services (node, service_name.c_str (), &count), RCL_RET_OK,
376+ rcl_get_error_string ().str );
377+
378+ return Napi::Number::New (env, count);
379+ }
380+
321381Napi::Object InitNodeBindings (Napi::Env env, Napi::Object exports) {
322382 exports.Set (" getParameterOverrides" ,
323383 Napi::Function::New (env, GetParameterOverrides));
@@ -331,6 +391,10 @@ Napi::Object InitNodeBindings(Napi::Env env, Napi::Object exports) {
331391 Napi::Function::New (env, ActionGetServerNamesAndTypesByNode));
332392 exports.Set (" actionGetNamesAndTypes" ,
333393 Napi::Function::New (env, ActionGetNamesAndTypes));
394+ exports.Set (" countPublishers" , Napi::Function::New (env, CountPublishers));
395+ exports.Set (" countSubscribers" , Napi::Function::New (env, CountSubscribers));
396+ exports.Set (" countClients" , Napi::Function::New (env, CountClients));
397+ exports.Set (" countServices" , Napi::Function::New (env, CountServices));
334398 return exports;
335399}
336400
0 commit comments