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

Stubs for rmw_get_publishers_info_by_topic and rmw_get_subscriptions_info_by_topic #377

Merged
merged 7 commits into from
Jan 14, 2020
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
3 changes: 2 additions & 1 deletion rmw_connext_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ add_library(
src/rmw_trigger_guard_condition.cpp
src/rmw_wait.cpp
src/rmw_wait_set.cpp
src/serialization_format.cpp)
src/serialization_format.cpp
src/rmw_get_topic_endpoint_info.cpp)
ament_target_dependencies(rmw_connext_cpp
"rcutils"
"rmw"
Expand Down
55 changes: 55 additions & 0 deletions rmw_connext_cpp/src/rmw_get_topic_endpoint_info.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "rmw/get_topic_endpoint_info.h"
#include "rmw/topic_endpoint_info_array.h"
#include "rmw_connext_shared_cpp/topic_endpoint_info.hpp"
#include "rmw_connext_cpp/identifier.hpp"

extern "C"
{
rmw_ret_t
rmw_get_publishers_info_by_topic(
const rmw_node_t * node,
rcutils_allocator_t * allocator,
const char * topic_name,
bool no_mangle,
rmw_topic_endpoint_info_array_t * publishers_info)
{
return get_publishers_info_by_topic(
rti_connext_identifier,
node,
allocator,
topic_name,
no_mangle,
publishers_info);
}

rmw_ret_t
rmw_get_subscriptions_info_by_topic(
const rmw_node_t * node,
rcutils_allocator_t * allocator,
const char * topic_name,
bool no_mangle,
rmw_topic_endpoint_info_array_t * subscriptions_info)
{
return get_subscriptions_info_by_topic(
rti_connext_identifier,
node,
allocator,
topic_name,
no_mangle,
subscriptions_info);
}
} // extern "C"
25 changes: 25 additions & 0 deletions rmw_connext_dynamic_cpp/src/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@
#include "rmw/allocators.h"
#include "rmw/error_handling.h"
#include "rmw/get_service_names_and_types.h"
#include "rmw/get_topic_endpoint_info.h"
#include "rmw/get_topic_names_and_types.h"
#include "rmw/init.h"
#include "rmw/rmw.h"
#include "rmw/topic_endpoint_info_array.h"
#include "rmw/types.h"

ivanpauno marked this conversation as resolved.
Show resolved Hide resolved
#include "rosidl_generator_c/primitives_sequence_functions.h"
Expand All @@ -75,6 +77,7 @@
#include "rosidl_typesupport_introspection_c/visibility_control.h"

#include "rmw_connext_shared_cpp/shared_functions.hpp"
#include "rmw_connext_shared_cpp/topic_endpoint_info.hpp"
#include "rmw_connext_shared_cpp/types.hpp"

#include "./macros.hpp"
Expand Down Expand Up @@ -2704,6 +2707,28 @@ rmw_count_subscribers(
return count_subscribers(rti_connext_dynamic_identifier, node, topic_name, count);
}

rmw_ret_t
rmw_get_publishers_info_by_topic(
const rmw_node_t * node,
rcutils_allocator_t * allocator,
const char * topic_name,
bool no_mangle,
rmw_topic_endpoint_info_array_t * publishers_info)
{
return get_publishers_info_by_topic(rti_connext_dynamic_identifier, node, allocator, topic_name, no_mangle, publishers_info);
}

rmw_ret_t
rmw_get_subscriptions_info_by_topic(
const rmw_node_t * node,
rcutils_allocator_t * allocator,
const char * topic_name,
bool no_mangle,
rmw_topic_endpoint_info_array_t * subscriptions_info)
{
return get_subscriptions_info_by_topic(rti_connext_dynamic_identifier, node, allocator, topic_name, no_mangle, subscriptions_info);
}

rmw_ret_t
rmw_get_gid_for_publisher(const rmw_publisher_t * publisher, rmw_gid_t * gid)
{
Expand Down
3 changes: 2 additions & 1 deletion rmw_connext_shared_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ add_library(
src/wait_set.cpp
src/types/custom_data_reader_listener.cpp
src/types/custom_publisher_listener.cpp
src/types/custom_subscriber_listener.cpp)
src/types/custom_subscriber_listener.cpp
src/topic_endpoint_info.cpp)
ament_target_dependencies(rmw_connext_shared_cpp
"rcpputils"
"rcutils"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@
#include "types.hpp"
#include "wait.hpp"
#include "wait_set.hpp"
#include "topic_endpoint_info.hpp"

#endif // RMW_CONNEXT_SHARED_CPP__SHARED_FUNCTIONS_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ class TopicCache
/**
* Helper function to initialize the set inside a participant map.
*
* @param map
* @param participant_guid
* \param map
* \param participant_guid
*/
void initialize_participant_map(
ParticipantToTopicGuidMap & map,
Expand All @@ -87,15 +87,15 @@ class TopicCache

public:
/**
* @return a map of topic name to the vector of topic types used.
* \return a map of topic name to the vector of topic types used.
*/
const TopicGuidToInfo & get_topic_guid_to_info() const
{
return topic_guid_to_info_;
}

/**
* @return a map of participant guid to the vector of topic names used.
* \return a map of participant guid to the vector of topic names used.
*/
const ParticipantToTopicGuidMap & get_participant_to_topic_guid_map() const
{
Expand All @@ -105,10 +105,10 @@ class TopicCache
/**
* Add a topic based on discovery.
*
* @param participant_guid
* @param topic_name
* @param type_name
* @return true if a change has been recorded
* \param participant_guid
* \param topic_name
* \param type_name
* \return true if a change has been recorded
*/
bool add_topic(
const GUID_t & participant_guid,
Expand All @@ -127,8 +127,8 @@ class TopicCache
"Adding topic '%s' with type '%s' for node '%s'",
topic_name.c_str(), type_name.c_str(), guid_stream.str().c_str());
}
auto topic_info_it = topic_guid_to_info_.find(topic_guid);
if (topic_info_it != topic_guid_to_info_.end()) {
auto topic_endpoint_info_it = topic_guid_to_info_.find(topic_guid);
if (topic_endpoint_info_it != topic_guid_to_info_.end()) {
RCUTILS_LOG_WARN_NAMED(
"rmw_connext_shared_cpp",
"unique topic attempted to be added twice, ignoring");
Expand All @@ -143,23 +143,23 @@ class TopicCache
/**
* Remove a topic based on discovery.
*
* @param guid
* @return true if a change has been recorded
* \param guid
* \return true if a change has been recorded
*/
bool remove_topic(const GUID_t & topic_guid)
{
auto topic_info_it = topic_guid_to_info_.find(topic_guid);
if (topic_info_it == topic_guid_to_info_.end()) {
auto topic_endpoint_info_it = topic_guid_to_info_.find(topic_guid);
if (topic_endpoint_info_it == topic_guid_to_info_.end()) {
RCUTILS_LOG_WARN_NAMED(
"rmw_connext_shared_cpp",
"unexpected topic removal.");
return false;
}

std::string topic_name = topic_info_it->second.name;
std::string type_name = topic_info_it->second.type;
std::string topic_name = topic_endpoint_info_it->second.name;
std::string type_name = topic_endpoint_info_it->second.type;

auto participant_guid = topic_info_it->second.participant_guid;
auto participant_guid = topic_endpoint_info_it->second.participant_guid;
auto participant_to_topic_guid = participant_to_topic_guids_.find(participant_guid);
if (participant_to_topic_guid == participant_to_topic_guids_.end()) {
RCUTILS_LOG_WARN_NAMED(
Expand All @@ -179,7 +179,7 @@ class TopicCache
return false;
}

topic_guid_to_info_.erase(topic_info_it);
topic_guid_to_info_.erase(topic_endpoint_info_it);
participant_to_topic_guid->second.erase(topic_guid_to_remove);
if (participant_to_topic_guids_.empty()) {
participant_to_topic_guids_.erase(participant_to_topic_guid);
Expand All @@ -190,8 +190,8 @@ class TopicCache
/**
* Get topic types by guid.
*
* @param participant_guid to find topic types
* @return topic types corresponding to that guid
* \param participant_guid to find topic types
* \return topic types corresponding to that guid
*/
TopicsTypes get_topic_types_by_guid(const GUID_t & participant_guid)
{
Expand All @@ -203,16 +203,16 @@ class TopicCache
}

for (auto & topic_guid : participant_to_topic_guids->second) {
auto topic_info = topic_guid_to_info_.find(topic_guid);
if (topic_info == topic_guid_to_info_.end()) {
auto topic_endpoint_info = topic_guid_to_info_.find(topic_guid);
if (topic_endpoint_info == topic_guid_to_info_.end()) {
continue;
}
auto topic_name = topic_info->second.name;
auto topic_name = topic_endpoint_info->second.name;
auto topic_entry = topics_types.find(topic_name);
if (topic_entry == topics_types.end()) {
topics_types[topic_name] = std::set<std::string>();
}
topics_types[topic_name].insert(topic_info->second.type);
topics_types[topic_name].insert(topic_endpoint_info->second.type);
}
return topics_types;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef RMW_CONNEXT_SHARED_CPP__TOPIC_ENDPOINT_INFO_HPP_
#define RMW_CONNEXT_SHARED_CPP__TOPIC_ENDPOINT_INFO_HPP_

#include "rmw/topic_endpoint_info_array.h"
#include "rmw_connext_shared_cpp/visibility_control.h"

RMW_CONNEXT_SHARED_CPP_PUBLIC
rmw_ret_t
get_publishers_info_by_topic(
const char * identifier,
const rmw_node_t * node,
rcutils_allocator_t * allocator,
const char * topic_name,
bool no_mangle,
rmw_topic_endpoint_info_array_t * publishers_info);

RMW_CONNEXT_SHARED_CPP_PUBLIC
rmw_ret_t
get_subscriptions_info_by_topic(
const char * identifier,
const rmw_node_t * node,
rcutils_allocator_t * allocator,
const char * topic_name,
bool no_mangle,
rmw_topic_endpoint_info_array_t * subscriptions_info);

#endif // RMW_CONNEXT_SHARED_CPP__TOPIC_ENDPOINT_INFO_HPP_
18 changes: 9 additions & 9 deletions rmw_connext_shared_cpp/src/node_info_and_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@
* Check to see if a node name and namespace match the user data QoS policy
* of a node.
*
* @param user_data_qos to inspect
* @param node_name to match
* @param node_namespace to match
* @return true if match
* \param user_data_qos to inspect
* \param node_name to match
* \param node_namespace to match
* \return true if match
*/
bool
__is_node_match(
Expand Down Expand Up @@ -76,12 +76,12 @@ __is_node_match(
* Get a DDS GUID key for the discovered participant which matches the
* node_name and node_namepace supplied.
*
* @param node_info to discover nodes
* @param node_name to match
* @param node_namespace to match
* @param key [out] guid key that matches the node name and namespace
* \param node_info to discover nodes
* \param node_name to match
* \param node_namespace to match
* \param key [out] guid key that matches the node name and namespace
*
* @return RMW_RET_OK if success, ERROR otherwise
* \return RMW_RET_OK if success, ERROR otherwise
*/
rmw_ret_t
__get_key(
Expand Down
43 changes: 43 additions & 0 deletions rmw_connext_shared_cpp/src/topic_endpoint_info.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <map>

#include "rmw_connext_shared_cpp/topic_endpoint_info.hpp"

#include "rmw/error_handling.h"

rmw_ret_t
get_publishers_info_by_topic(
const char * /* unused_param */,
const rmw_node_t * /* unused_param */,
rcutils_allocator_t * /* unused_param */,
const char * /* unused_param */,
bool /* unused_param */,
rmw_topic_endpoint_info_array_t * /* unused_param */)
{
return RMW_RET_UNSUPPORTED;
}

rmw_ret_t
get_subscriptions_info_by_topic(
const char * /* unused_param */,
const rmw_node_t * /* unused_param */,
rcutils_allocator_t * /* unused_param */,
const char * /* unused_param */,
bool /* unused_param */,
rmw_topic_endpoint_info_array_t * /* unused_param */)
{
return RMW_RET_UNSUPPORTED;
}