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

Add function for getting clients by node #361

Merged
merged 2 commits 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
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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is the last review of the set, but I just considered that maybe the "Reply" and "Request" should be some sort of static const, so that we don't have to update them if something changes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a good idea. What about #define them in names_and_types_helpers.hpp?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're okay with it, I can do this refactoring in a follow-up set of PRs, since this can be done in all of the rmw implementations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with the followup.

}
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