Skip to content

Commit

Permalink
Add function for getting clients by node
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Perron <jacob@openrobotics.org>
  • Loading branch information
jacobperron committed Jun 12, 2019
1 parent 2a49da4 commit 04781d4
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 2 deletions.
13 changes: 13 additions & 0 deletions rmw_fastrtps_cpp/src/rmw_node_info_and_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,17 @@ rmw_get_service_names_and_types_by_node(
eprosima_fastrtps_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 rmw_fastrtps_shared_cpp::__rmw_get_client_names_and_types_by_node(
eprosima_fastrtps_identifier, node, allocator, node_name, node_namespace,
service_names_and_types);
}
} // extern "C"
17 changes: 17 additions & 0 deletions rmw_fastrtps_dynamic_cpp/src/rmw_node_info_and_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,21 @@ rmw_get_service_names_and_types_by_node(
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 rmw_fastrtps_shared_cpp::__rmw_get_client_names_and_types_by_node(
eprosima_fastrtps_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 @@ -226,6 +226,16 @@ __rmw_get_service_names_and_types_by_node(
const char * node_namespace,
rmw_names_and_types_t * service_names_and_types);

RMW_FASTRTPS_SHARED_CPP_PUBLIC
rmw_ret_t
__rmw_get_client_names_and_types_by_node(
const char * 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_FASTRTPS_SHARED_CPP_PUBLIC
rmw_ret_t
__rmw_get_subscriber_names_and_types_by_node(
Expand Down
55 changes: 53 additions & 2 deletions rmw_fastrtps_shared_cpp/src/rmw_node_info_and_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,15 +385,18 @@ __rmw_get_publisher_names_and_types_by_node(
node_namespace, no_demangle, retrieve_pub_cache, topic_names_and_types);
}

static
rmw_ret_t
__rmw_get_service_names_and_types_by_node(
__get_service_names_and_types_by_node(
const char * 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 * topic_suffix)
{
const std::string topic_suffix_stdstr(topic_suffix);
rmw_ret_t valid_input = __validate_input(identifier, node, allocator, node_name,
node_namespace, service_names_and_types);
if (valid_input != RMW_RET_OK) {
Expand All @@ -420,6 +423,15 @@ __rmw_get_service_names_and_types_by_node(
// not a service
continue;
}
// Check if the topic suffix matches and is at the end of the name
const std::string & topic_name = topic_pair.first;
auto suffix_position = topic_name.rfind(topic_suffix_stdstr);
if (suffix_position == std::string::npos ||
topic_name.length() - suffix_position - topic_suffix_stdstr.length() != 0)
{
continue;
}

for (auto & itt : topic_pair.second) {
std::string service_type = _demangle_service_type_only(itt);
if (!service_type.empty()) {
Expand Down Expand Up @@ -484,4 +496,43 @@ __rmw_get_service_names_and_types_by_node(
} // for each service
return RMW_RET_OK;
}

rmw_ret_t
__rmw_get_service_names_and_types_by_node(
const char * 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(
identifier,
node,
allocator,
node_name,
node_namespace,
service_names_and_types,
"Request");
}

rmw_ret_t
__rmw_get_client_names_and_types_by_node(
const char * 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(
identifier,
node,
allocator,
node_name,
node_namespace,
service_names_and_types,
"Reply");
}

} // namespace rmw_fastrtps_shared_cpp

0 comments on commit 04781d4

Please sign in to comment.