Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Add function for getting clients by node (#361)
Browse files Browse the repository at this point in the history
* Add function for getting clients by node

Signed-off-by: Jacob Perron <[email protected]>

* Fix lint

Signed-off-by: Jacob Perron <[email protected]>
  • Loading branch information
jacobperron authored Jul 9, 2019
1 parent 980667f commit 70881fc
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 6 deletions.
12 changes: 12 additions & 0 deletions rmw_connext_cpp/src/rmw_node_info_and_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,16 @@ rmw_get_service_names_and_types_by_node(
return get_service_names_and_types_by_node(
rti_connext_identifier, node, allocator, node_name, node_namespace, service_names_and_types);
}

rmw_ret_t
rmw_get_client_names_and_types_by_node(
const rmw_node_t * node,
rcutils_allocator_t * allocator,
const char * node_name,
const char * node_namespace,
rmw_names_and_types_t * service_names_and_types)
{
return get_client_names_and_types_by_node(
rti_connext_identifier, node, allocator, node_name, node_namespace, service_names_and_types);
}
} // extern "C"
12 changes: 12 additions & 0 deletions rmw_connext_dynamic_cpp/src/rmw_node_info_and_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,16 @@ get_service_names_and_types_by_node(
return rmw_connext_shared_cpp::get_service_names_and_types_by_node(
rti_connext_identifier, node, allocator, node_name, node_namespace, service_names_and_types);
}

rmw_ret_t
get_client_names_and_types_by_node(
const rmw_node_t * node,
rcutils_allocator_t * allocator,
const char * node_name,
const char * node_namespace,
rmw_names_and_types_t * service_names_and_types)
{
return rmw_connext_shared_cpp::get_client_names_and_types_by_node(
rti_connext_identifier, node, allocator, node_name, node_namespace, service_names_and_types);
}
} // extern "C"
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@

#include "rmw_connext_shared_cpp/visibility_control.h"

RMW_CONNEXT_SHARED_CPP_PUBLIC
rmw_ret_t
get_client_names_and_types_by_node(
const char * implementation_identifier,
const rmw_node_t * node,
rcutils_allocator_t * allocator,
const char * node_name,
const char * node_namespace,
rmw_names_and_types_t * service_names_and_types);

RMW_CONNEXT_SHARED_CPP_PUBLIC
rmw_ret_t
get_publisher_names_and_types_by_node(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ class CustomDataReaderListener

void fill_service_names_and_types_by_guid(
std::map<std::string, std::set<std::string>> & services,
DDS_GUID_t & participant_guid);
DDS_GUID_t & participant_guid,
const std::string & suffix);

protected:
std::mutex mutex_;
Expand Down
48 changes: 44 additions & 4 deletions rmw_connext_shared_cpp/src/node_info_and_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,16 @@ get_publisher_names_and_types_by_node(
return copy_topics_names_and_types(topics, allocator, no_demangle, topic_names_and_types);
}

static
rmw_ret_t
get_service_names_and_types_by_node(
__get_service_names_and_types_by_node(
const char * implementation_identifier,
const rmw_node_t * node,
rcutils_allocator_t * allocator,
const char * node_name,
const char * node_namespace,
rmw_names_and_types_t * service_names_and_types)
rmw_names_and_types_t * service_names_and_types,
const char * suffix)
{
if (!node) {
RMW_SET_ERROR_MSG("null node handle");
Expand Down Expand Up @@ -282,7 +284,7 @@ get_service_names_and_types_by_node(

// combine publisher and subscriber information
std::map<std::string, std::set<std::string>> services;
node_info->subscriber_listener->fill_service_names_and_types_by_guid(services, key);
node_info->subscriber_listener->fill_service_names_and_types_by_guid(services, key, suffix);

rmw_ret_t rmw_ret =
copy_services_to_names_and_types(services, allocator, service_names_and_types);
Expand All @@ -291,4 +293,42 @@ get_service_names_and_types_by_node(
}

return RMW_RET_OK;
} // extern "C"
}

rmw_ret_t
get_service_names_and_types_by_node(
const char * implementation_identifier,
const rmw_node_t * node,
rcutils_allocator_t * allocator,
const char * node_name,
const char * node_namespace,
rmw_names_and_types_t * service_names_and_types)
{
return __get_service_names_and_types_by_node(
implementation_identifier,
node,
allocator,
node_name,
node_namespace,
service_names_and_types,
"Request");
}

rmw_ret_t
get_client_names_and_types_by_node(
const char * implementation_identifier,
const rmw_node_t * node,
rcutils_allocator_t * allocator,
const char * node_name,
const char * node_namespace,
rmw_names_and_types_t * service_names_and_types)
{
return __get_service_names_and_types_by_node(
implementation_identifier,
node,
allocator,
node_name,
node_namespace,
service_names_and_types,
"Reply");
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ void CustomDataReaderListener::fill_topic_names_and_types_by_guid(

void CustomDataReaderListener::fill_service_names_and_types_by_guid(
std::map<std::string, std::set<std::string>> & services,
DDS::GUID_t & participant_guid)
DDS::GUID_t & participant_guid,
const std::string & suffix)
{
std::lock_guard<std::mutex> lock(mutex_);
const auto & map = topic_cache.get_topic_types_by_guid(participant_guid);
Expand All @@ -190,6 +191,13 @@ void CustomDataReaderListener::fill_service_names_and_types_by_guid(
// not a service
continue;
}
// Check if the topic suffix matches and is at the end of the name
const std::string & topic_name = it.first;
auto suffix_position = topic_name.rfind(suffix);
if (suffix_position == std::string::npos) {
continue;
}

for (auto & itt : it.second) {
std::string service_type = _demangle_service_type_only(itt);
if (!service_type.empty()) {
Expand Down

0 comments on commit 70881fc

Please sign in to comment.