Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement functions to get publisher and subcription informations like QoS policies from topic name #336

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6721292
Simpled test for topic_cache
jaisontj Oct 17, 2019
944e1f3
Moved qos_converter to include/ since it needs to be accessible to
jaisontj Oct 18, 2019
e7a4a7e
- Modified topic_cache to include qos policies
jaisontj Oct 18, 2019
d0ac7e0
Stubs for rmw_get_publishers_info_by_topic and
jaisontj Oct 16, 2019
e640479
Implemented rmw_get_publishers_info_by_topic and
jaisontj Oct 23, 2019
1a80e44
- Addressing code review changes: Using const auto instead of auto
jaisontj Nov 14, 2019
30a2a56
- Alpha sorted cmakelist.txt
jaisontj Nov 16, 2019
dbfe0b4
- Alphasort
jaisontj Nov 16, 2019
04b29c8
- Refactor to accomodate change in rmw_topic_info_set* functions.
jaisontj Nov 22, 2019
af1e536
Refactor to accomodate change of gid from const char * to uint8_t[]
jaisontj Nov 22, 2019
e87e83c
Moved dds_qos_to_rmw_qos from qos_converter to qos.hpp
jaisontj Nov 22, 2019
16fcaed
- Modified topic cache to store participant guid and
jaisontj Nov 23, 2019
fea85a6
- Handled changes in headers from rmw
jaisontj Nov 27, 2019
1a4d9fa
Better error handling.
jaisontj Nov 27, 2019
169f218
fix error handling in _handle_topic_info_fini()
mm318 Dec 11, 2019
36e9718
address PR comments
mm318 Dec 14, 2019
8152876
address PR comments
mm318 Dec 18, 2019
642d9ed
conditionally demangle type name
mm318 Dec 19, 2019
38dec2a
reverse condition for demangling type name
mm318 Dec 28, 2019
c231f14
properly initialize history and history depth in topic info
mm318 Jan 2, 2020
a1a5e79
address more PR comments
mm318 Jan 10, 2020
354cae2
rename *topic_info* to *topic_endpoint_info*
mm318 Jan 10, 2020
1fe66ed
fix formatting
mm318 Jan 10, 2020
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
1 change: 1 addition & 0 deletions rmw_fastrtps_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ add_library(rmw_fastrtps_cpp
src/rmw_get_gid_for_publisher.cpp
src/rmw_get_implementation_identifier.cpp
src/rmw_get_serialization_format.cpp
src/rmw_get_topic_info.cpp
src/rmw_guard_condition.cpp
src/rmw_init.cpp
src/rmw_node.cpp
Expand Down
45 changes: 45 additions & 0 deletions rmw_fastrtps_cpp/src/rmw_get_topic_info.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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/rmw.h"
#include "rmw/types.h"
#include "rmw_fastrtps_shared_cpp/rmw_common.hpp"
#include "rmw_fastrtps_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_info_array_t * publishers_info)
{
return rmw_fastrtps_shared_cpp::__rmw_get_publishers_info_by_topic(
eprosima_fastrtps_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_info_array_t * subscriptions_info)
{
return rmw_fastrtps_shared_cpp::__rmw_get_subscriptions_info_by_topic(
eprosima_fastrtps_identifier, node, allocator, topic_name, no_mangle, subscriptions_info);
}
} // extern "C"
1 change: 1 addition & 0 deletions rmw_fastrtps_dynamic_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ add_library(rmw_fastrtps_dynamic_cpp
src/rmw_get_gid_for_publisher.cpp
src/rmw_get_implementation_identifier.cpp
src/rmw_get_serialization_format.cpp
src/rmw_get_topic_info.cpp
src/rmw_guard_condition.cpp
src/rmw_init.cpp
src/rmw_node.cpp
Expand Down
45 changes: 45 additions & 0 deletions rmw_fastrtps_dynamic_cpp/src/rmw_get_topic_info.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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/rmw.h"
#include "rmw/types.h"
#include "rmw_fastrtps_shared_cpp/rmw_common.hpp"
#include "rmw_fastrtps_dynamic_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_info_array_t * publishers_info)
{
return rmw_fastrtps_shared_cpp::__rmw_get_publishers_info_by_topic(
eprosima_fastrtps_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_info_array_t * subscriptions_info)
{
return rmw_fastrtps_shared_cpp::__rmw_get_subscriptions_info_by_topic(
eprosima_fastrtps_identifier, node, allocator, topic_name, no_mangle, subscriptions_info);
}
} // extern "C"
1 change: 1 addition & 0 deletions rmw_fastrtps_shared_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ add_library(rmw_fastrtps_shared_cpp
src/rmw_compare_gids_equal.cpp
src/rmw_count.cpp
src/rmw_get_gid_for_publisher.cpp
src/rmw_get_topic_info.cpp
src/rmw_guard_condition.cpp
src/rmw_logging.cpp
src/rmw_node.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,20 @@ class ParticipantListener : public eprosima::fastrtps::ParticipantListener
{
auto & topic_cache =
is_reader ? reader_topic_cache : writer_topic_cache;

bool trigger;
{
std::lock_guard<std::mutex> guard(topic_cache.getMutex());
if (is_alive) {
trigger = topic_cache().addTopic(proxyData.RTPSParticipantKey(),
proxyData.topicName().to_string(), proxyData.typeName().to_string());
trigger = topic_cache().addTopic(
proxyData.RTPSParticipantKey(),
proxyData.topicName().to_string(),
proxyData.typeName().to_string(),
proxyData.m_qos);
} else {
trigger = topic_cache().removeTopic(proxyData.RTPSParticipantKey(),
proxyData.topicName().to_string(), proxyData.typeName().to_string());
trigger = topic_cache().removeTopic(
proxyData.RTPSParticipantKey(),
proxyData.topicName().to_string(),
proxyData.typeName().to_string());
}
}
if (trigger) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016-2018 Proyectos y Sistemas de Mantenimiento SL (eProsima).
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
ivanpauno marked this conversation as resolved.
Show resolved Hide resolved
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -13,8 +13,8 @@
// limitations under the License.


#ifndef QOS_CONVERTER_HPP_
#define QOS_CONVERTER_HPP_
#ifndef RMW_FASTRTPS_SHARED_CPP__QOS_CONVERTER_HPP_
jaisontj marked this conversation as resolved.
Show resolved Hide resolved
#define RMW_FASTRTPS_SHARED_CPP__QOS_CONVERTER_HPP_

#include "rmw/types.h"

Expand Down Expand Up @@ -83,4 +83,4 @@ dds_qos_to_rmw_qos(
qos->liveliness_lease_duration.nsec = dds_qos.m_liveliness.lease_duration.nanosec;
}

#endif // QOS_CONVERTER_HPP_
#endif // RMW_FASTRTPS_SHARED_CPP__QOS_CONVERTER_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,26 @@ RMW_FASTRTPS_SHARED_CPP_PUBLIC
rmw_ret_t
__rmw_destroy_wait_set(const char * identifier, rmw_wait_set_t * wait_set);

RMW_FASTRTPS_SHARED_CPP_PUBLIC
rmw_ret_t
__rmw_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_info_array_t * publishers_info);

RMW_FASTRTPS_SHARED_CPP_PUBLIC
rmw_ret_t
__rmw_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_info_array_t * subscriptions_info);

} // namespace rmw_fastrtps_shared_cpp

#endif // RMW_FASTRTPS_SHARED_CPP__RMW_COMMON_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
#include <set>
#include <sstream>
#include <string>
#include <tuple>
wjwwood marked this conversation as resolved.
Show resolved Hide resolved
#include <unordered_map>
#include <utility>
#include <vector>

#include "fastrtps/participant/Participant.h"
#include "fastrtps/rtps/common/Guid.h"
#include "fastrtps/rtps/common/InstanceHandle.h"
#include "qos_converter.hpp"
#include "rcpputils/thread_safety_annotations.hpp"
#include "rcutils/logging_macros.h"

Expand All @@ -39,31 +41,48 @@ typedef eprosima::fastrtps::rtps::GUID_t GUID_t;
class TopicCache
{
private:
typedef std::map<GUID_t,
std::unordered_map<std::string, std::vector<std::string>>> ParticipantTopicMap;
typedef std::unordered_map<std::string, std::vector<std::string>> TopicToTypes;
using TopicToTypes = std::unordered_map<std::string, std::vector<std::string>>;
using ParticipantTopicMap = std::map<GUID_t, TopicToTypes>;
jaisontj marked this conversation as resolved.
Show resolved Hide resolved
using TopicData = std::vector<std::tuple<GUID_t, std::string, rmw_qos_profile_t>>;
using TopicNameToTopicData = std::unordered_map<std::string, TopicData>;

/**
* Map of topic names to a vector of types that topic may use.
* Map of topic names to TopicData. Where topic data is vector of tuples containing
* participant GUID, topic type and the qos policy of the respective participant.
* Topics here are represented as one to many, DDS XTypes 1.2
* specifies application code 'generally' uses a 1-1 relationship.
* specifies application code that 'generally' uses a 1-1 relationship.
* However, generic services such as logger and monitor, can discover
* multiple types on the same topic.
*
*/
TopicToTypes topic_to_types_;
TopicNameToTopicData topic_name_to_topic_data_;

/**
* Map of participant GUIDS to a set of topic-type.
*/
ParticipantTopicMap participant_to_topics_;

/**
* Helper function to initialize a topic vector.
* Helper function to initialize an empty TopicData for a topic name.
*
* @param topic_name
* @param topic_name the topic name for which the TopicNameToTopicData map should be initialised.
* @param topic_name_to_topic_data the map to initialise.
ivanpauno marked this conversation as resolved.
Show resolved Hide resolved
*/
void initializeTopic(const std::string & topic_name, TopicToTypes & topic_to_types)
void initializeTopicDataMap(
const std::string & topic_name,
TopicNameToTopicData & topic_name_to_topic_data)
{
if (topic_name_to_topic_data.find(topic_name) == topic_name_to_topic_data.end()) {
topic_name_to_topic_data[topic_name] = TopicData();
}
}

/**
* Helper function to initialize a topic vector.
*
* @param topic_name the topic name for which the TopicToTypes map should be initialised.
* @param topic_to_types the map to initialise.
*/
void initializeTopicTypesMap(const std::string & topic_name, TopicToTypes & topic_to_types)
{
if (topic_to_types.find(topic_name) == topic_to_types.end()) {
topic_to_types[topic_name] = std::vector<std::string>();
Expand All @@ -89,9 +108,16 @@ class TopicCache
/**
* @return a map of topic name to the vector of topic types used.
*/
const TopicToTypes & getTopicToTypes() const
const TopicToTypes getTopicToTypes() const
jaisontj marked this conversation as resolved.
Show resolved Hide resolved
{
return topic_to_types_;
TopicToTypes topic_to_types;
for (const auto & it : topic_name_to_topic_data_) {
topic_to_types[it.first] = std::vector<std::string>();
for (const auto & mit : it.second) {
topic_to_types[it.first].push_back(std::get<1>(mit));
}
}
return topic_to_types;
}

/**
Expand All @@ -102,23 +128,34 @@ class TopicCache
return participant_to_topics_;
}

/**
* @return a map of topic name to a vector of GUID_t, type name and qos profile tuple.
*/
const TopicNameToTopicData & getTopicNameToTopicData() const
{
return topic_name_to_topic_data_;
}

/**
* Add a topic based on discovery.
*
* @param rtpsParticipantKey
* @param topic_name
* @param type_name
* @param dds_qos the dds qos policy of the participant
* @return true if a change has been recorded
*/
template<class T>
ivanpauno marked this conversation as resolved.
Show resolved Hide resolved
bool addTopic(
const eprosima::fastrtps::rtps::InstanceHandle_t & rtpsParticipantKey,
const std::string & topic_name,
const std::string & type_name)
const std::string & type_name,
const T & dds_qos)
{
initializeTopic(topic_name, topic_to_types_);
initializeTopicDataMap(topic_name, topic_name_to_topic_data_);
auto guid = iHandle2GUID(rtpsParticipantKey);
initializeParticipantMap(participant_to_topics_, guid);
initializeTopic(topic_name, participant_to_topics_[guid]);
initializeTopicTypesMap(topic_name, participant_to_topics_[guid]);
if (rcutils_logging_logger_is_enabled_for("rmw_fastrtps_shared_cpp",
RCUTILS_LOG_SEVERITY_DEBUG))
{
Expand All @@ -129,7 +166,9 @@ class TopicCache
"Adding topic '%s' with type '%s' for node '%s'",
topic_name.c_str(), type_name.c_str(), guid_stream.str().c_str());
}
topic_to_types_[topic_name].push_back(type_name);
auto qos_profile = rmw_qos_profile_t();
jaisontj marked this conversation as resolved.
Show resolved Hide resolved
dds_qos_to_rmw_qos(dds_qos, &qos_profile);
ivanpauno marked this conversation as resolved.
Show resolved Hide resolved
topic_name_to_topic_data_[topic_name].push_back(std::make_tuple(guid, type_name, qos_profile));
jaisontj marked this conversation as resolved.
Show resolved Hide resolved
participant_to_topics_[guid][topic_name].push_back(type_name);
return true;
}
Expand All @@ -147,22 +186,26 @@ class TopicCache
const std::string & topic_name,
const std::string & type_name)
{
if (topic_to_types_.find(topic_name) == topic_to_types_.end()) {
if (topic_name_to_topic_data_.find(topic_name) == topic_name_to_topic_data_.end()) {
RCUTILS_LOG_DEBUG_NAMED(
"rmw_fastrtps_shared_cpp",
"unexpected removal on topic '%s' with type '%s'",
topic_name.c_str(), type_name.c_str());
return false;
}
auto guid = iHandle2GUID(rtpsParticipantKey);
{
auto & type_vec = topic_to_types_[topic_name];
type_vec.erase(std::find(type_vec.begin(), type_vec.end(), type_name));
auto & type_vec = topic_name_to_topic_data_[topic_name];
type_vec.erase(std::find_if(type_vec.begin(), type_vec.end(),
[type_name, guid](const auto & topic_info) {
return type_name.compare(std::get<1>(topic_info)) == 0 &&
guid == std::get<0>(topic_info);
jaisontj marked this conversation as resolved.
Show resolved Hide resolved
}));
if (type_vec.empty()) {
topic_to_types_.erase(topic_name);
topic_name_to_topic_data_.erase(topic_name);
}
}

auto guid = iHandle2GUID(rtpsParticipantKey);
auto guid_topics_pair = participant_to_topics_.find(guid);
if (guid_topics_pair != participant_to_topics_.end() &&
guid_topics_pair->second.find(topic_name) != guid_topics_pair->second.end())
Expand All @@ -180,6 +223,7 @@ class TopicCache
"rmw_fastrtps_shared_cpp",
"Unable to remove topic, does not exist '%s' with type '%s'",
topic_name.c_str(), type_name.c_str());
return false;
wjwwood marked this conversation as resolved.
Show resolved Hide resolved
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion rmw_fastrtps_shared_cpp/src/qos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <limits>

#include "qos_converter.hpp"
#include "rmw_fastrtps_shared_cpp/qos_converter.hpp"
#include "rmw_fastrtps_shared_cpp/qos.hpp"

#include "fastrtps/attributes/PublisherAttributes.h"
Expand Down
Loading