Skip to content
This repository has been archived by the owner on Oct 7, 2021. It is now read-only.

Add function for getting clients by node #274

Merged
merged 1 commit into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions rmw_opensplice_cpp/src/rmw_node_info_and_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,53 @@ rmw_get_service_names_and_types_by_node(
return get_guid_err;
}

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

rmw_ret_t rmw_ret;
rmw_ret = copy_services_to_names_and_types(services, allocator, service_names_and_types);
if (rmw_ret != RMW_RET_OK) {
return rmw_ret;
}
return RMW_RET_OK;
}

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)
{
rmw_ret_t ret = validate_node(node, allocator);
if (ret != RMW_RET_OK) {
return ret;
}
ret = rmw_names_and_types_check_zero(service_names_and_types);
if (ret != RMW_RET_OK) {
return ret;
}
ret = validate_names_and_namespace(node_name, node_namespace);
if (ret != RMW_RET_OK) {
return ret;
}

auto node_info = static_cast<OpenSpliceStaticNodeInfo *>(node->data);
DDS::InstanceHandle_t key;
auto get_guid_err = __get_key(node_info, node_name, node_namespace, key);
if (get_guid_err != RMW_RET_OK) {
return get_guid_err;
}

std::map<std::string, std::set<std::string>> services;
node_info->subscriber_listener->fill_service_names_and_types_by_participant(
services,
key,
"Reply");

rmw_ret_t rmw_ret;
rmw_ret = copy_services_to_names_and_types(services, allocator, service_names_and_types);
Expand Down
12 changes: 11 additions & 1 deletion rmw_opensplice_cpp/src/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ void CustomDataReaderListener::fill_topic_names_and_types_by_participant(

void CustomDataReaderListener::fill_service_names_and_types_by_participant(
std::map<std::string, std::set<std::string>> & services,
DDS::InstanceHandle_t & participant)
DDS::InstanceHandle_t & participant,
const std::string & suffix)
{
std::lock_guard<std::mutex> lock(mutex_);
const auto & map = topic_cache.getTopicTypesByGuid(participant);
Expand All @@ -155,6 +156,15 @@ void CustomDataReaderListener::fill_service_names_and_types_by_participant(
// 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 ||
topic_name.length() - suffix_position - suffix.length() != 0)
{
continue;
}

for (auto & itt : it.second) {
std::string service_type = _demangle_service_type_only(itt);
if (service_type.length()) {
Expand Down
3 changes: 2 additions & 1 deletion rmw_opensplice_cpp/src/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ class CustomDataReaderListener

void fill_service_names_and_types_by_participant(
std::map<std::string, std::set<std::string>> & services,
DDS::InstanceHandle_t & participant);
DDS::InstanceHandle_t & participant,
const std::string & suffix);

size_t count_topic(const char * topic_name);

Expand Down