From 099881914a165cc1eb8288c1d38a94bb21a35602 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Fri, 27 May 2022 12:14:06 +0200 Subject: [PATCH 01/33] Refs #14615. Added basic TopicProxy class. Signed-off-by: Miguel Company --- src/cpp/fastdds/topic/TopicProxy.hpp | 108 +++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src/cpp/fastdds/topic/TopicProxy.hpp diff --git a/src/cpp/fastdds/topic/TopicProxy.hpp b/src/cpp/fastdds/topic/TopicProxy.hpp new file mode 100644 index 00000000000..e97a8298b43 --- /dev/null +++ b/src/cpp/fastdds/topic/TopicProxy.hpp @@ -0,0 +1,108 @@ +// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// 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. + +/* + * TopicProxy.hpp + */ + +#ifndef _FASTDDS_TOPICPROXY_HPP_ +#define _FASTDDS_TOPICPROXY_HPP_ + +#include +#include +#include +#include +#include + +#include + +#include +#include + +using eprosima::fastrtps::types::ReturnCode_t; + +namespace eprosima { +namespace fastdds { +namespace dds { + +class DomainParticipant; + +class TopicProxy : public TopicDescriptionImpl +{ +public: + + explicit TopicProxy( + TopicImpl* impl) noexcept + : impl_(impl) + { + } + + const TopicQos& get_qos() const + { + return impl_->get_qos(); + } + + ReturnCode_t set_qos( + const TopicQos& qos) + { + return impl_->set_qos(qos); + } + + const TopicListener* get_listener() const + { + return impl_->get_listener(); + } + + ReturnCode_t set_listener( + TopicListener* listener) + { + return impl_->set_listener(listener); + } + + DomainParticipant* get_participant() const + { + return impl_->get_participant(); + } + + const TypeSupport& get_type() const + { + return impl_->get_type(); + } + + TopicListener* get_listener_for( + const StatusMask& status) + { + return impl_->get_listener_for(status); + } + + Topic* get_topic() const + { + return const_cast(impl_->get_topic()); + } + + const std::string& get_rtps_topic_name() const override + { + return get_topic()->get_name(); + } + +private: + + TopicImpl* impl_ = nullptr; +}; + +} // namespace dds +} // namespace fastdds +} // namespace eprosima + +#endif /* _FASTDDS_TOPICPROXY_HPP_ */ From 322e3022744a1df08b81f9a49d17df47bb503286 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Fri, 27 May 2022 13:08:24 +0200 Subject: [PATCH 02/33] Refs #14615. Topic holds TopicProxy, which is created by DomainParticipantImpl. Signed-off-by: Miguel Company --- include/dds/topic/Topic.hpp | 1 - include/fastdds/dds/topic/Topic.hpp | 8 ++++---- src/cpp/fastdds/domain/DomainParticipantImpl.cpp | 12 +++++++----- src/cpp/fastdds/domain/DomainParticipantImpl.hpp | 2 +- .../publisher/filtering/ReaderFilterCollection.hpp | 4 ++-- src/cpp/fastdds/topic/ContentFilteredTopicImpl.cpp | 3 ++- src/cpp/fastdds/topic/ContentFilteredTopicImpl.hpp | 1 - src/cpp/fastdds/topic/Topic.cpp | 4 ++-- .../fastdds/domain/DomainParticipantImpl.hpp | 10 ++++++---- 9 files changed, 24 insertions(+), 21 deletions(-) diff --git a/include/dds/topic/Topic.hpp b/include/dds/topic/Topic.hpp index de377ea4e15..645b34cc089 100644 --- a/include/dds/topic/Topic.hpp +++ b/include/dds/topic/Topic.hpp @@ -33,7 +33,6 @@ class TopicListener; class Topic : public dds::core::TEntity { - friend class TopicImpl; friend class DomainParticipantImpl; public: diff --git a/include/fastdds/dds/topic/Topic.hpp b/include/fastdds/dds/topic/Topic.hpp index da6acfc934f..3db760ae080 100644 --- a/include/fastdds/dds/topic/Topic.hpp +++ b/include/fastdds/dds/topic/Topic.hpp @@ -42,7 +42,7 @@ namespace dds { class DomainParticipant; class TopicListener; class DomainParticipantImpl; -class TopicImpl; +class TopicProxy; /** * Class Topic, represents the fact that both publications @@ -52,7 +52,7 @@ class TopicImpl; */ class Topic : public DomainEntity, public TopicDescription { - friend class TopicImpl; + friend class TopicProxy; friend class DomainParticipantImpl; /** @@ -62,7 +62,7 @@ class Topic : public DomainEntity, public TopicDescription Topic( const std::string& topic_name, const std::string& type_name, - TopicImpl* p, + TopicProxy* p, const StatusMask& mask = StatusMask::all()); Topic( @@ -143,7 +143,7 @@ class Topic : public DomainEntity, public TopicDescription protected: - TopicImpl* impl_; + TopicProxy* impl_; friend class ::dds::topic::Topic; diff --git a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp index a5155098770..94c10532c11 100644 --- a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp @@ -58,6 +58,7 @@ #include #include #include +#include #include #include @@ -327,7 +328,7 @@ ReturnCode_t DomainParticipantImpl::enable() for (auto topic : topics_) { - topic.second->user_topic_->enable(); + topic.second->get_topic()->enable(); } } @@ -537,7 +538,7 @@ ContentFilteredTopic* DomainParticipantImpl::create_contentfilteredtopic( return nullptr; } - TopicImpl* topic_impl = dynamic_cast(related_topic->get_impl()); + TopicProxy* topic_impl = dynamic_cast(related_topic->get_impl()); assert(nullptr != topic_impl); const TypeSupport& type = topic_impl->get_type(); LoanableSequence::size_type n_params; @@ -1302,13 +1303,14 @@ Topic* DomainParticipantImpl::create_topic( //TODO CONSTRUIR LA IMPLEMENTACION DENTRO DEL OBJETO DEL USUARIO. TopicImpl* topic_impl = new TopicImpl(this, type_support, qos, listener); - Topic* topic = new Topic(topic_name, type_name, topic_impl, mask); + TopicProxy* proxy = new TopicProxy(topic_impl); + Topic* topic = new Topic(topic_name, type_name, proxy, mask); topic_impl->user_topic_ = topic; topic->set_instance_handle(topic_handle); //SAVE THE TOPIC INTO MAPS topics_by_handle_[topic_handle] = topic; - topics_[topic_name] = topic_impl; + topics_[topic_name] = proxy; // Enable topic if appropriate if (enabled && qos_.entity_factory().autoenable_created_entities) @@ -1348,7 +1350,7 @@ TopicDescription* DomainParticipantImpl::lookup_topicdescription( auto it = topics_.find(topic_name); if (it != topics_.end()) { - return it->second->user_topic_; + return it->second->get_topic(); } auto filtered_it = filtered_topics_.find(topic_name); diff --git a/src/cpp/fastdds/domain/DomainParticipantImpl.hpp b/src/cpp/fastdds/domain/DomainParticipantImpl.hpp index 883bb81e437..617b5e4eb37 100644 --- a/src/cpp/fastdds/domain/DomainParticipantImpl.hpp +++ b/src/cpp/fastdds/domain/DomainParticipantImpl.hpp @@ -480,7 +480,7 @@ class DomainParticipantImpl mutable std::mutex mtx_types_; //!Topic map - std::map topics_; + std::map topics_; std::map topics_by_handle_; std::map> filtered_topics_; std::map filter_factories_; diff --git a/src/cpp/fastdds/publisher/filtering/ReaderFilterCollection.hpp b/src/cpp/fastdds/publisher/filtering/ReaderFilterCollection.hpp index 2cac63dd551..a1c6684f42b 100644 --- a/src/cpp/fastdds/publisher/filtering/ReaderFilterCollection.hpp +++ b/src/cpp/fastdds/publisher/filtering/ReaderFilterCollection.hpp @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include #include @@ -202,7 +202,7 @@ class ReaderFilterCollection DomainParticipantImpl* participant, Topic* topic) { - TopicImpl* writer_topic = static_cast(topic->get_impl()); + TopicProxy* writer_topic = static_cast(topic->get_impl()); if (0 == filter_info.filter_class_name.size() || 0 != writer_topic->get_rtps_topic_name().compare(filter_info.related_topic_name.c_str())) diff --git a/src/cpp/fastdds/topic/ContentFilteredTopicImpl.cpp b/src/cpp/fastdds/topic/ContentFilteredTopicImpl.cpp index 63c882554d9..d032429d9e0 100644 --- a/src/cpp/fastdds/topic/ContentFilteredTopicImpl.cpp +++ b/src/cpp/fastdds/topic/ContentFilteredTopicImpl.cpp @@ -27,6 +27,7 @@ #include #include #include +#include namespace eprosima { namespace fastdds { @@ -55,7 +56,7 @@ ReturnCode_t ContentFilteredTopicImpl::set_expression_parameters( const char* new_expression, const std::vector& new_expression_parameters) { - TopicImpl* topic_impl = dynamic_cast(related_topic->get_impl()); + TopicProxy* topic_impl = dynamic_cast(related_topic->get_impl()); assert(nullptr != topic_impl); const TypeSupport& type = topic_impl->get_type(); diff --git a/src/cpp/fastdds/topic/ContentFilteredTopicImpl.hpp b/src/cpp/fastdds/topic/ContentFilteredTopicImpl.hpp index c7cdcda14b7..f76a469312a 100644 --- a/src/cpp/fastdds/topic/ContentFilteredTopicImpl.hpp +++ b/src/cpp/fastdds/topic/ContentFilteredTopicImpl.hpp @@ -32,7 +32,6 @@ #include #include -#include namespace eprosima { namespace fastdds { diff --git a/src/cpp/fastdds/topic/Topic.cpp b/src/cpp/fastdds/topic/Topic.cpp index 8b21ded3d04..8f553bf38af 100644 --- a/src/cpp/fastdds/topic/Topic.cpp +++ b/src/cpp/fastdds/topic/Topic.cpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include @@ -30,7 +30,7 @@ namespace dds { Topic::Topic( const std::string& topic_name, const std::string& type_name, - TopicImpl* p, + TopicProxy* p, const StatusMask& mask) : DomainEntity(mask) , TopicDescription(topic_name, type_name) diff --git a/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp b/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp index f72eb85a96e..bdc82e18ec7 100644 --- a/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp +++ b/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp @@ -44,6 +44,7 @@ #include #include #include +#include using ReturnCode_t = eprosima::fastrtps::types::ReturnCode_t; @@ -264,9 +265,10 @@ class DomainParticipantImpl return nullptr; } TopicImpl* topic_impl = new TopicImpl(this, type_support, qos, listener); - Topic* topic = new Topic(topic_name, type_name, topic_impl, mask); + TopicProxy* proxy = new TopicProxy(topic_impl); + Topic* topic = new Topic(topic_name, type_name, proxy, mask); topic_impl->user_topic_ = topic; - topics_[topic_name] = topic_impl; + topics_[topic_name] = proxy; topic->enable(); return topic; } @@ -340,7 +342,7 @@ class DomainParticipantImpl auto it = topics_.find(topic_name); if (it != topics_.end()) { - return it->second->user_topic_; + return it->second->get_topic(); } return nullptr; } @@ -676,7 +678,7 @@ class DomainParticipantImpl std::map subscribers_; mutable std::mutex mtx_subs_; SubscriberQos default_sub_qos_; - std::map topics_; + std::map topics_; mutable std::mutex mtx_topics_; std::map types_; mutable std::mutex mtx_types_; From c976bc0a8dfc465576bce35d119a7d75feac58d8 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Tue, 31 May 2022 09:37:02 +0200 Subject: [PATCH 03/33] Refs #14615. TopicProxy constructs and owns Topic. Signed-off-by: Miguel Company --- src/cpp/fastdds/domain/DomainParticipantImpl.cpp | 5 ++--- src/cpp/fastdds/topic/TopicProxy.hpp | 14 +++++++++++--- .../fastdds/domain/DomainParticipantImpl.hpp | 5 ++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp index 94c10532c11..2b22d6251fd 100644 --- a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp @@ -1303,9 +1303,8 @@ Topic* DomainParticipantImpl::create_topic( //TODO CONSTRUIR LA IMPLEMENTACION DENTRO DEL OBJETO DEL USUARIO. TopicImpl* topic_impl = new TopicImpl(this, type_support, qos, listener); - TopicProxy* proxy = new TopicProxy(topic_impl); - Topic* topic = new Topic(topic_name, type_name, proxy, mask); - topic_impl->user_topic_ = topic; + TopicProxy* proxy = new TopicProxy(topic_name, type_name, mask, topic_impl); + Topic* topic = proxy->get_topic(); topic->set_instance_handle(topic_handle); //SAVE THE TOPIC INTO MAPS diff --git a/src/cpp/fastdds/topic/TopicProxy.hpp b/src/cpp/fastdds/topic/TopicProxy.hpp index e97a8298b43..c9b92315efd 100644 --- a/src/cpp/fastdds/topic/TopicProxy.hpp +++ b/src/cpp/fastdds/topic/TopicProxy.hpp @@ -19,6 +19,9 @@ #ifndef _FASTDDS_TOPICPROXY_HPP_ #define _FASTDDS_TOPICPROXY_HPP_ +#include +#include + #include #include #include @@ -42,9 +45,13 @@ class TopicProxy : public TopicDescriptionImpl { public: - explicit TopicProxy( + TopicProxy( + const std::string& topic_name, + const std::string& type_name, + const StatusMask& mask, TopicImpl* impl) noexcept : impl_(impl) + , user_topic_(new Topic(topic_name, type_name, this, mask)) { } @@ -88,17 +95,18 @@ class TopicProxy : public TopicDescriptionImpl Topic* get_topic() const { - return const_cast(impl_->get_topic()); + return user_topic_.get(); } const std::string& get_rtps_topic_name() const override { - return get_topic()->get_name(); + return user_topic_->get_name(); } private: TopicImpl* impl_ = nullptr; + std::unique_ptr user_topic_; }; } // namespace dds diff --git a/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp b/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp index bdc82e18ec7..0753e3e2853 100644 --- a/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp +++ b/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp @@ -265,9 +265,8 @@ class DomainParticipantImpl return nullptr; } TopicImpl* topic_impl = new TopicImpl(this, type_support, qos, listener); - TopicProxy* proxy = new TopicProxy(topic_impl); - Topic* topic = new Topic(topic_name, type_name, proxy, mask); - topic_impl->user_topic_ = topic; + TopicProxy* proxy = new TopicProxy(topic_name, type_name, mask, topic_impl); + Topic* topic = proxy->get_topic(); topics_[topic_name] = proxy; topic->enable(); return topic; From 637807fd95b9e365b217763ad2775a5cc0c85366 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Tue, 31 May 2022 09:48:37 +0200 Subject: [PATCH 04/33] Refs #14615. TopicImpl is not TopicDescriptionImpl and does not hold user topic pointer. Signed-off-by: Miguel Company --- src/cpp/fastdds/topic/TopicImpl.cpp | 12 +++--------- src/cpp/fastdds/topic/TopicImpl.hpp | 11 +++-------- src/cpp/fastdds/topic/TopicProxy.hpp | 2 +- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/src/cpp/fastdds/topic/TopicImpl.cpp b/src/cpp/fastdds/topic/TopicImpl.cpp index 7ccf492ae5d..1c94ee28ca5 100644 --- a/src/cpp/fastdds/topic/TopicImpl.cpp +++ b/src/cpp/fastdds/topic/TopicImpl.cpp @@ -41,13 +41,11 @@ TopicImpl::TopicImpl( , type_support_(type_support) , qos_(&qos == &TOPIC_QOS_DEFAULT ? participant_->get_default_topic_qos() : qos) , listener_(listen) - , user_topic_(nullptr) { } TopicImpl::~TopicImpl() { - delete user_topic_; } ReturnCode_t TopicImpl::check_qos( @@ -155,21 +153,17 @@ DomainParticipant* TopicImpl::get_participant() const return participant_->get_participant(); } -const Topic* TopicImpl::get_topic() const -{ - return user_topic_; -} - const TypeSupport& TopicImpl::get_type() const { return type_support_; } TopicListener* TopicImpl::get_listener_for( - const StatusMask& status) + const StatusMask& status, + const Topic* topic) { if (listener_ != nullptr && - user_topic_->get_status_mask().is_active(status)) + topic->get_status_mask().is_active(status)) { return listener_; } diff --git a/src/cpp/fastdds/topic/TopicImpl.hpp b/src/cpp/fastdds/topic/TopicImpl.hpp index 628da5f6afa..55f269bbdf0 100644 --- a/src/cpp/fastdds/topic/TopicImpl.hpp +++ b/src/cpp/fastdds/topic/TopicImpl.hpp @@ -40,7 +40,7 @@ class DomainParticipant; class TopicListener; class Topic; -class TopicImpl : public TopicDescriptionImpl +class TopicImpl { friend class DomainParticipantImpl; @@ -82,17 +82,13 @@ class TopicImpl : public TopicDescriptionImpl const TypeSupport& get_type() const; - const std::string& get_rtps_topic_name() const override - { - return user_topic_->get_name(); - } - /** * Returns the most appropriate listener to handle the callback for the given status, * or nullptr if there is no appropriate listener. */ TopicListener* get_listener_for( - const StatusMask& status); + const StatusMask& status, + const Topic* topic); protected: @@ -100,7 +96,6 @@ class TopicImpl : public TopicDescriptionImpl TypeSupport type_support_; TopicQos qos_; TopicListener* listener_; - Topic* user_topic_; }; diff --git a/src/cpp/fastdds/topic/TopicProxy.hpp b/src/cpp/fastdds/topic/TopicProxy.hpp index c9b92315efd..0bdcce4c298 100644 --- a/src/cpp/fastdds/topic/TopicProxy.hpp +++ b/src/cpp/fastdds/topic/TopicProxy.hpp @@ -90,7 +90,7 @@ class TopicProxy : public TopicDescriptionImpl TopicListener* get_listener_for( const StatusMask& status) { - return impl_->get_listener_for(status); + return impl_->get_listener_for(status, user_topic_.get()); } Topic* get_topic() const From 8ad653ae33e68cea7e2369d5e3c91a5c0f67d702 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Tue, 31 May 2022 09:50:10 +0200 Subject: [PATCH 05/33] Refs #14615. TopicImpl constructor is public. Signed-off-by: Miguel Company --- src/cpp/fastdds/topic/TopicImpl.hpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cpp/fastdds/topic/TopicImpl.hpp b/src/cpp/fastdds/topic/TopicImpl.hpp index 55f269bbdf0..f9705cee022 100644 --- a/src/cpp/fastdds/topic/TopicImpl.hpp +++ b/src/cpp/fastdds/topic/TopicImpl.hpp @@ -42,7 +42,7 @@ class Topic; class TopicImpl { - friend class DomainParticipantImpl; +public: TopicImpl( DomainParticipantImpl* p, @@ -50,8 +50,6 @@ class TopicImpl const TopicQos& qos, TopicListener* listen); -public: - static ReturnCode_t check_qos( const TopicQos& qos); From 9eb8c555a5976ebb28d072b6da677959ffacfb1e Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Tue, 31 May 2022 10:03:26 +0200 Subject: [PATCH 06/33] Refs #14615. TopicImpl header cleanup. Signed-off-by: Miguel Company --- src/cpp/fastdds/topic/TopicImpl.hpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/cpp/fastdds/topic/TopicImpl.hpp b/src/cpp/fastdds/topic/TopicImpl.hpp index f9705cee022..7166531e953 100644 --- a/src/cpp/fastdds/topic/TopicImpl.hpp +++ b/src/cpp/fastdds/topic/TopicImpl.hpp @@ -21,14 +21,12 @@ #define _FASTDDS_TOPICIMPL_HPP_ #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC -// #include -#include +#include +#include #include -#include +#include #include -#include - using eprosima::fastrtps::types::ReturnCode_t; namespace eprosima { @@ -76,8 +74,6 @@ class TopicImpl DomainParticipant* get_participant() const; - const Topic* get_topic() const; - const TypeSupport& get_type() const; /** From b0149c7b0cd74aa0c88ecf055be07d713b82f022 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Fri, 27 May 2022 12:35:30 +0200 Subject: [PATCH 07/33] Refs #14615. Added TopicProxyFactory class with basic interface. Signed-off-by: Miguel Company --- src/cpp/fastdds/topic/TopicProxyFactory.hpp | 72 +++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/cpp/fastdds/topic/TopicProxyFactory.hpp diff --git a/src/cpp/fastdds/topic/TopicProxyFactory.hpp b/src/cpp/fastdds/topic/TopicProxyFactory.hpp new file mode 100644 index 00000000000..5c81c1ae788 --- /dev/null +++ b/src/cpp/fastdds/topic/TopicProxyFactory.hpp @@ -0,0 +1,72 @@ +// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// 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. + +/* + * TopicProxyFactory.hpp + */ + +#ifndef _FASTDDS_TOPICPROXYFACTORY_HPP_ +#define _FASTDDS_TOPICPROXYFACTORY_HPP_ + +#include + +#include + +using eprosima::fastrtps::types::ReturnCode_t; + +namespace eprosima { +namespace fastdds { +namespace dds { + +/** + * A factory of TopicProxy objects for a specific topic. + */ +class TopicProxyFactory +{ +public: + + /** + * Create a new proxy object for the topic managed by the factory. + * + * @return Pointer to the created TopicProxy + */ + TopicProxy* create_topic(); + + /** + * Delete a proxy object for the topic managed by the factory. + * + * @param proxy Pointer to the TopicProxy object to be deleted. + * + * @return PRECONDITION_NOT_MET if the @c proxy was not created by this factory, or has already being deleted. + * @return PRECONDITION_NOT_MET if the @c proxy is still referenced. + * @return OK if the @c proxy is correctly deleted. + */ + ReturnCode_t delete_topic( + TopicProxy* proxy); + + /** + * Return whether this factory can be deleted. + * Will disallow deletion if it still owns some proxy objects. + * + * @return true if the factory owns no proxy objects + */ + bool can_be_deleted(); + +}; + +} // namespace dds +} // namespace fastdds +} // namespace eprosima + +#endif /* _FASTDDS_TOPICPROXYFACTORY_HPP_ */ From d6dde52c07da3b37b6442226c9c4718e5941d3ec Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Tue, 31 May 2022 10:12:50 +0200 Subject: [PATCH 08/33] Refs #14615. TopicProxyFactory empty implementation. Signed-off-by: Miguel Company --- src/cpp/CMakeLists.txt | 1 + src/cpp/fastdds/topic/TopicProxyFactory.cpp | 47 +++++++++++++++++++++ test/unittest/dds/publisher/CMakeLists.txt | 1 + test/unittest/dds/status/CMakeLists.txt | 1 + test/unittest/statistics/dds/CMakeLists.txt | 1 + 5 files changed, 51 insertions(+) create mode 100644 src/cpp/fastdds/topic/TopicProxyFactory.cpp diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt index af6a6a836bd..15694b57db2 100644 --- a/src/cpp/CMakeLists.txt +++ b/src/cpp/CMakeLists.txt @@ -96,6 +96,7 @@ set(${PROJECT_NAME}_source_files fastdds/topic/ContentFilteredTopicImpl.cpp fastdds/topic/Topic.cpp fastdds/topic/TopicImpl.cpp + fastdds/topic/TopicProxyFactory.cpp fastdds/topic/TypeSupport.cpp fastdds/topic/qos/TopicQos.cpp fastdds/publisher/qos/DataWriterQos.cpp diff --git a/src/cpp/fastdds/topic/TopicProxyFactory.cpp b/src/cpp/fastdds/topic/TopicProxyFactory.cpp new file mode 100644 index 00000000000..dbfa3025f54 --- /dev/null +++ b/src/cpp/fastdds/topic/TopicProxyFactory.cpp @@ -0,0 +1,47 @@ +// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// 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. + +/* + * TopicProxyFactory.cpp + */ + +#include + +#include + +namespace eprosima { +namespace fastdds { +namespace dds { + +TopicProxy* TopicProxyFactory::create_topic() +{ + return nullptr; +} + +ReturnCode_t TopicProxyFactory::delete_topic( + TopicProxy* proxy) +{ + static_cast(proxy); + + return ReturnCode_t::RETCODE_UNSUPPORTED; +} + +bool TopicProxyFactory::can_be_deleted() +{ + return true; +} + +} // namespace dds +} // namespace fastdds +} // namespace eprosima diff --git a/test/unittest/dds/publisher/CMakeLists.txt b/test/unittest/dds/publisher/CMakeLists.txt index 599f3314622..b810ad82c84 100644 --- a/test/unittest/dds/publisher/CMakeLists.txt +++ b/test/unittest/dds/publisher/CMakeLists.txt @@ -90,6 +90,7 @@ set(DATAWRITERTESTS_SOURCE DataWriterTests.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/ContentFilteredTopicImpl.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/Topic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicImpl.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicProxyFactory.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TypeSupport.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/qos/TopicQos.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastrtps_deprecated/subscriber/SubscriberHistory.cpp diff --git a/test/unittest/dds/status/CMakeLists.txt b/test/unittest/dds/status/CMakeLists.txt index 994b0b40385..2cb872f7b78 100644 --- a/test/unittest/dds/status/CMakeLists.txt +++ b/test/unittest/dds/status/CMakeLists.txt @@ -50,6 +50,7 @@ set(LISTENERTESTS_SOURCE ListenerTests.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/Topic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/qos/TopicQos.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicImpl.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicProxyFactory.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TypeSupport.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/core/policy/ParameterList.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/log/Log.cpp diff --git a/test/unittest/statistics/dds/CMakeLists.txt b/test/unittest/statistics/dds/CMakeLists.txt index 14c63f667b0..da51538e08c 100644 --- a/test/unittest/statistics/dds/CMakeLists.txt +++ b/test/unittest/statistics/dds/CMakeLists.txt @@ -140,6 +140,7 @@ if (SQLITE3_SUPPORT AND FASTDDS_STATISTICS) ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/ContentFilteredTopicImpl.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/Topic.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicImpl.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TopicProxyFactory.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/TypeSupport.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/qos/TopicQos.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/PropertyPolicy.cpp From f264f66c29bcefedeb40dbd5bc6d76eb62c63e63 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Tue, 31 May 2022 10:29:12 +0200 Subject: [PATCH 09/33] Refs #14615. TopicProxyFactory holds TopicImpl by composition. Signed-off-by: Miguel Company --- src/cpp/fastdds/topic/TopicProxyFactory.hpp | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/cpp/fastdds/topic/TopicProxyFactory.hpp b/src/cpp/fastdds/topic/TopicProxyFactory.hpp index 5c81c1ae788..a28d12fc0fa 100644 --- a/src/cpp/fastdds/topic/TopicProxyFactory.hpp +++ b/src/cpp/fastdds/topic/TopicProxyFactory.hpp @@ -19,8 +19,12 @@ #ifndef _FASTDDS_TOPICPROXYFACTORY_HPP_ #define _FASTDDS_TOPICPROXYFACTORY_HPP_ +#include +#include +#include #include +#include #include using eprosima::fastrtps::types::ReturnCode_t; @@ -29,6 +33,8 @@ namespace eprosima { namespace fastdds { namespace dds { +class DomainParticipantImpl; + /** * A factory of TopicProxy objects for a specific topic. */ @@ -36,6 +42,23 @@ class TopicProxyFactory { public: + /** + * Construct a TopicProxyFactory. + * + * @param participant Pointer to the DomainParticipantImpl creating this object. + * @param type_support TypeSupport to use for the topics created by this factory. + * @param qos TopicQos to use on the creation of the implementation object. + * @param listener TopicListener to use on the creation of the implementation object. + */ + TopicProxyFactory( + DomainParticipantImpl* participant, + TypeSupport type_support, + const TopicQos& qos, + TopicListener* listener) + : topic_impl_(participant, type_support, qos, listener) + { + } + /** * Create a new proxy object for the topic managed by the factory. * @@ -63,6 +86,11 @@ class TopicProxyFactory */ bool can_be_deleted(); +private: + + //! Implementation object for the topic managed by the factory. + TopicImpl topic_impl_; + }; } // namespace dds From 8f4654ae3026f1de295bb7a40a57b2a45c44fed6 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Tue, 31 May 2022 10:43:06 +0200 Subject: [PATCH 10/33] Refs #14615. TopicProxyFactory holds list of created proxy objects. Signed-off-by: Miguel Company --- src/cpp/fastdds/topic/TopicProxyFactory.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cpp/fastdds/topic/TopicProxyFactory.hpp b/src/cpp/fastdds/topic/TopicProxyFactory.hpp index a28d12fc0fa..626f204b211 100644 --- a/src/cpp/fastdds/topic/TopicProxyFactory.hpp +++ b/src/cpp/fastdds/topic/TopicProxyFactory.hpp @@ -19,6 +19,9 @@ #ifndef _FASTDDS_TOPICPROXYFACTORY_HPP_ #define _FASTDDS_TOPICPROXYFACTORY_HPP_ +#include +#include + #include #include #include @@ -90,6 +93,8 @@ class TopicProxyFactory //! Implementation object for the topic managed by the factory. TopicImpl topic_impl_; + //! List of TopicProxy objects created by this factory. + std::list> proxies_; }; From 520220f54510dae52e721cb7a6828ea71c15c037 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Tue, 31 May 2022 10:44:18 +0200 Subject: [PATCH 11/33] Refs #14615. Implementation of TopicProxyFactory::can_be_deleted. Signed-off-by: Miguel Company --- src/cpp/fastdds/topic/TopicProxyFactory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp/fastdds/topic/TopicProxyFactory.cpp b/src/cpp/fastdds/topic/TopicProxyFactory.cpp index dbfa3025f54..1889709bfa2 100644 --- a/src/cpp/fastdds/topic/TopicProxyFactory.cpp +++ b/src/cpp/fastdds/topic/TopicProxyFactory.cpp @@ -39,7 +39,7 @@ ReturnCode_t TopicProxyFactory::delete_topic( bool TopicProxyFactory::can_be_deleted() { - return true; + return proxies_.empty(); } } // namespace dds From b414a93a904d87124ed1afcb43b473b2388d9240 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Tue, 31 May 2022 10:54:00 +0200 Subject: [PATCH 12/33] Refs #14615. Implementation of TopicProxyFactory::delete_topic. Signed-off-by: Miguel Company --- src/cpp/fastdds/topic/TopicProxyFactory.cpp | 22 +++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/cpp/fastdds/topic/TopicProxyFactory.cpp b/src/cpp/fastdds/topic/TopicProxyFactory.cpp index 1889709bfa2..e51d730c17c 100644 --- a/src/cpp/fastdds/topic/TopicProxyFactory.cpp +++ b/src/cpp/fastdds/topic/TopicProxyFactory.cpp @@ -18,6 +18,8 @@ #include +#include + #include namespace eprosima { @@ -26,20 +28,28 @@ namespace dds { TopicProxy* TopicProxyFactory::create_topic() { - return nullptr; + return nullptr; } ReturnCode_t TopicProxyFactory::delete_topic( - TopicProxy* proxy) + TopicProxy* proxy) { - static_cast(proxy); - - return ReturnCode_t::RETCODE_UNSUPPORTED; + auto it = std::find_if(proxies_.begin(), proxies_.end(), [proxy](const auto& item) + { + return item.get() == proxy; + }); + if (it != proxies_.end() && !proxy->is_referenced()) + { + proxies_.erase(it); + return ReturnCode_t::RETCODE_OK; + } + + return ReturnCode_t::RETCODE_PRECONDITION_NOT_MET; } bool TopicProxyFactory::can_be_deleted() { - return proxies_.empty(); + return proxies_.empty(); } } // namespace dds From 652ce67cbb614438f858e91db6dd5e7beff7d798 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Tue, 31 May 2022 11:09:48 +0200 Subject: [PATCH 13/33] Refs #14615. Implementation of TopicProxyFactory::create_topic. Signed-off-by: Miguel Company --- src/cpp/fastdds/topic/TopicProxyFactory.cpp | 4 +++- src/cpp/fastdds/topic/TopicProxyFactory.hpp | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/cpp/fastdds/topic/TopicProxyFactory.cpp b/src/cpp/fastdds/topic/TopicProxyFactory.cpp index e51d730c17c..ced579aebc0 100644 --- a/src/cpp/fastdds/topic/TopicProxyFactory.cpp +++ b/src/cpp/fastdds/topic/TopicProxyFactory.cpp @@ -28,7 +28,9 @@ namespace dds { TopicProxy* TopicProxyFactory::create_topic() { - return nullptr; + TopicProxy* ret_val = new TopicProxy(topic_name_, topic_impl_.get_type()->getName(), status_mask_, &topic_impl_); + proxies_.emplace_back(ret_val); + return ret_val; } ReturnCode_t TopicProxyFactory::delete_topic( diff --git a/src/cpp/fastdds/topic/TopicProxyFactory.hpp b/src/cpp/fastdds/topic/TopicProxyFactory.hpp index 626f204b211..73a4a7ac4d1 100644 --- a/src/cpp/fastdds/topic/TopicProxyFactory.hpp +++ b/src/cpp/fastdds/topic/TopicProxyFactory.hpp @@ -19,9 +19,11 @@ #ifndef _FASTDDS_TOPICPROXYFACTORY_HPP_ #define _FASTDDS_TOPICPROXYFACTORY_HPP_ -#include #include +#include +#include +#include #include #include #include @@ -49,16 +51,22 @@ class TopicProxyFactory * Construct a TopicProxyFactory. * * @param participant Pointer to the DomainParticipantImpl creating this object. + * @param topic_name Name of the topic managed by this factory. + * @param status_mask Initial StatusMask of the topic managed by this factory. * @param type_support TypeSupport to use for the topics created by this factory. * @param qos TopicQos to use on the creation of the implementation object. * @param listener TopicListener to use on the creation of the implementation object. */ TopicProxyFactory( DomainParticipantImpl* participant, + const std::string& topic_name, + const StatusMask& status_mask, TypeSupport type_support, const TopicQos& qos, TopicListener* listener) - : topic_impl_(participant, type_support, qos, listener) + : topic_name_(topic_name) + , status_mask_(status_mask) + , topic_impl_(participant, type_support, qos, listener) { } @@ -91,11 +99,14 @@ class TopicProxyFactory private: + //! Name of the topic managed by the factory. + std::string topic_name_; + //! StatusMask of the topic managed by the factory. + StatusMask status_mask_; //! Implementation object for the topic managed by the factory. TopicImpl topic_impl_; //! List of TopicProxy objects created by this factory. std::list> proxies_; - }; } // namespace dds From 3655203c79e84364067883f698c187e9d8bbc3f1 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Tue, 31 May 2022 16:36:50 +0200 Subject: [PATCH 14/33] Refs #14615. Adding enable_topic and get_topic to TopicProxyFactory. Signed-off-by: Miguel Company --- src/cpp/fastdds/topic/TopicProxyFactory.cpp | 13 +++++++++++++ src/cpp/fastdds/topic/TopicProxyFactory.hpp | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/cpp/fastdds/topic/TopicProxyFactory.cpp b/src/cpp/fastdds/topic/TopicProxyFactory.cpp index ced579aebc0..47d801db360 100644 --- a/src/cpp/fastdds/topic/TopicProxyFactory.cpp +++ b/src/cpp/fastdds/topic/TopicProxyFactory.cpp @@ -49,11 +49,24 @@ ReturnCode_t TopicProxyFactory::delete_topic( return ReturnCode_t::RETCODE_PRECONDITION_NOT_MET; } +TopicProxy* TopicProxyFactory::get_topic() +{ + return proxies_.empty() ? nullptr : proxies_.front().get(); +} + bool TopicProxyFactory::can_be_deleted() { return proxies_.empty(); } +void TopicProxyFactory::enable_topic() +{ + for (auto& item : proxies_) + { + item->get_topic()->enable(); + } +} + } // namespace dds } // namespace fastdds } // namespace eprosima diff --git a/src/cpp/fastdds/topic/TopicProxyFactory.hpp b/src/cpp/fastdds/topic/TopicProxyFactory.hpp index 73a4a7ac4d1..c1f56334a83 100644 --- a/src/cpp/fastdds/topic/TopicProxyFactory.hpp +++ b/src/cpp/fastdds/topic/TopicProxyFactory.hpp @@ -89,6 +89,14 @@ class TopicProxyFactory ReturnCode_t delete_topic( TopicProxy* proxy); + /** + * Get one of the TopicProxy objects created by the factory. + * + * @return nullptr if the factory owns no proxy objects. + * @return Pointer to one of the proxies owned by the factory. + */ + TopicProxy* get_topic(); + /** * Return whether this factory can be deleted. * Will disallow deletion if it still owns some proxy objects. @@ -97,6 +105,11 @@ class TopicProxyFactory */ bool can_be_deleted(); + /** + * Enable the topic managed by the factory. + */ + void enable_topic(); + private: //! Name of the topic managed by the factory. From dc5cb1c3e6d4e500bb22adb427130c780644d734 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Tue, 31 May 2022 16:38:56 +0200 Subject: [PATCH 15/33] Refs #14615. DomainParticipantImpl uses TopicProxyFactory. Signed-off-by: Miguel Company --- .../fastdds/domain/DomainParticipantImpl.cpp | 39 +++++++++++-------- .../fastdds/domain/DomainParticipantImpl.hpp | 3 +- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp index 2b22d6251fd..8bd4db48e5d 100644 --- a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp @@ -59,6 +59,7 @@ #include #include #include +#include #include #include @@ -328,7 +329,7 @@ ReturnCode_t DomainParticipantImpl::enable() for (auto topic : topics_) { - topic.second->get_topic()->enable(); + topic.second->enable_topic(); } } @@ -483,23 +484,29 @@ ReturnCode_t DomainParticipantImpl::delete_topic( std::lock_guard lock(mtx_topics_); auto it = topics_.find(topic->get_name()); + auto handle = topic->get_instance_handle(); if (it != topics_.end()) { - assert(topic->get_instance_handle() == it->second->get_topic()->get_instance_handle() - && "The topic instance handle does not match the topic implementation instance handle"); - if (it->second->is_referenced()) + TopicProxy* proxy = dynamic_cast(topic->get_impl()); + auto ret_code = it->second->delete_topic(proxy); + if (ReturnCode_t::RETCODE_OK == ret_code) { - return ReturnCode_t::RETCODE_PRECONDITION_NOT_MET; + assert(topics_by_handle_.find(handle) != topics_by_handle_.end() + && "The topic instance handle does not match the topic implementation instance handle"); + topics_by_handle_.erase(handle); + + if (it->second->can_be_deleted()) + { + auto factory = it->second; + topics_.erase(it); + delete factory; + } } - it->second->set_listener(nullptr); - topics_by_handle_.erase(topic->get_instance_handle()); - delete it->second; - topics_.erase(it); return ReturnCode_t::RETCODE_OK; } - return ReturnCode_t::RETCODE_ERROR; + return ReturnCode_t::RETCODE_PRECONDITION_NOT_MET; } ContentFilteredTopic* DomainParticipantImpl::create_contentfilteredtopic( @@ -905,12 +912,11 @@ ReturnCode_t DomainParticipantImpl::delete_contained_entities() std::lock_guard lock_topics(mtx_topics_); filtered_topics_.clear(); + topics_by_handle_.clear(); auto it_topics = topics_.begin(); while (it_topics != topics_.end()) { - it_topics->second->set_listener(nullptr); - topics_by_handle_.erase(it_topics->second->get_topic()->get_instance_handle()); delete it_topics->second; it_topics = topics_.erase(it_topics); } @@ -1301,15 +1307,14 @@ Topic* DomainParticipantImpl::create_topic( InstanceHandle_t topic_handle; create_instance_handle(topic_handle); - //TODO CONSTRUIR LA IMPLEMENTACION DENTRO DEL OBJETO DEL USUARIO. - TopicImpl* topic_impl = new TopicImpl(this, type_support, qos, listener); - TopicProxy* proxy = new TopicProxy(topic_name, type_name, mask, topic_impl); + TopicProxyFactory* factory = new TopicProxyFactory(this, topic_name, mask, type_support, qos, listener); + TopicProxy* proxy = factory->create_topic(); Topic* topic = proxy->get_topic(); topic->set_instance_handle(topic_handle); //SAVE THE TOPIC INTO MAPS topics_by_handle_[topic_handle] = topic; - topics_[topic_name] = proxy; + topics_[topic_name] = factory; // Enable topic if appropriate if (enabled && qos_.entity_factory().autoenable_created_entities) @@ -1349,7 +1354,7 @@ TopicDescription* DomainParticipantImpl::lookup_topicdescription( auto it = topics_.find(topic_name); if (it != topics_.end()) { - return it->second->get_topic(); + return it->second->get_topic()->get_topic(); } auto filtered_it = filtered_topics_.find(topic_name); diff --git a/src/cpp/fastdds/domain/DomainParticipantImpl.hpp b/src/cpp/fastdds/domain/DomainParticipantImpl.hpp index 617b5e4eb37..14b5dfcc865 100644 --- a/src/cpp/fastdds/domain/DomainParticipantImpl.hpp +++ b/src/cpp/fastdds/domain/DomainParticipantImpl.hpp @@ -37,6 +37,7 @@ #include #include "fastdds/topic/DDSSQLFilter/DDSFilterFactory.hpp" +#include using eprosima::fastrtps::types::ReturnCode_t; @@ -480,7 +481,7 @@ class DomainParticipantImpl mutable std::mutex mtx_types_; //!Topic map - std::map topics_; + std::map topics_; std::map topics_by_handle_; std::map> filtered_topics_; std::map filter_factories_; From 53813722eb97033cd30da3365b994a56e2ad3754 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Wed, 1 Jun 2022 09:39:42 +0200 Subject: [PATCH 16/33] Refs #14615. Move find_topic to DomainParticipantImpl. Signed-off-by: Miguel Company --- src/cpp/fastdds/domain/DomainParticipant.cpp | 5 +---- src/cpp/fastdds/domain/DomainParticipantImpl.cpp | 10 ++++++++++ src/cpp/fastdds/domain/DomainParticipantImpl.hpp | 12 ++++++++++++ .../fastdds/domain/DomainParticipantImpl.hpp | 7 +++++++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/cpp/fastdds/domain/DomainParticipant.cpp b/src/cpp/fastdds/domain/DomainParticipant.cpp index c38ac8c6a13..12fdecf63b2 100644 --- a/src/cpp/fastdds/domain/DomainParticipant.cpp +++ b/src/cpp/fastdds/domain/DomainParticipant.cpp @@ -238,10 +238,7 @@ Topic* DomainParticipant::find_topic( const std::string& topic_name, const fastrtps::Duration_t& timeout) { - static_cast (topic_name); - static_cast (timeout); - logWarning(DOMAIN_PARTICIPANT, "find_topic method not implemented"); - return nullptr; + return impl_->find_topic(topic_name, timeout); } TopicDescription* DomainParticipant::lookup_topicdescription( diff --git a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp index 8bd4db48e5d..328d7976b33 100644 --- a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp @@ -469,6 +469,16 @@ ReturnCode_t DomainParticipantImpl::delete_subscriber( return ReturnCode_t::RETCODE_ERROR; } +Topic* DomainParticipantImpl::find_topic( + const std::string& topic_name, + const fastrtps::Duration_t& timeout) +{ + static_cast (topic_name); + static_cast (timeout); + logWarning(DOMAIN_PARTICIPANT, "find_topic method not implemented"); + return nullptr; +} + ReturnCode_t DomainParticipantImpl::delete_topic( const Topic* topic) { diff --git a/src/cpp/fastdds/domain/DomainParticipantImpl.hpp b/src/cpp/fastdds/domain/DomainParticipantImpl.hpp index 14b5dfcc865..6ec2a2d3b5c 100644 --- a/src/cpp/fastdds/domain/DomainParticipantImpl.hpp +++ b/src/cpp/fastdds/domain/DomainParticipantImpl.hpp @@ -214,6 +214,18 @@ class DomainParticipantImpl TopicListener* listener = nullptr, const StatusMask& mask = StatusMask::all()); + /** + * Gives access to an existing (or ready to exist) enabled Topic. + * Topics obtained by this method must be destroyed by delete_topic. + * + * @param topic_name Topic name + * @param timeout Maximum time to wait for the Topic + * @return Pointer to the existing Topic, nullptr in error case + */ + Topic* find_topic( + const std::string& topic_name, + const fastrtps::Duration_t& timeout); + ReturnCode_t delete_topic( const Topic* topic); diff --git a/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp b/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp index 0753e3e2853..2c7fac32854 100644 --- a/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp +++ b/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp @@ -282,6 +282,13 @@ class DomainParticipantImpl return create_topic(topic_name, type_name, TOPIC_QOS_DEFAULT, listener, mask); } + Topic* find_topic( + const std::string& /*topic_name*/, + const fastrtps::Duration_t& /*timeout*/) + { + return nullptr; + } + ReturnCode_t delete_topic( const Topic* topic) { From 49ea325a930d4e249e34b995e86d903b5c09548a Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Wed, 1 Jun 2022 11:59:25 +0200 Subject: [PATCH 17/33] Refs #14615. Notify a condition when a topic is created. Signed-off-by: Miguel Company --- src/cpp/fastdds/domain/DomainParticipantImpl.cpp | 2 ++ src/cpp/fastdds/domain/DomainParticipantImpl.hpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp index 328d7976b33..a53fbde1ae0 100644 --- a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp @@ -1334,6 +1334,8 @@ Topic* DomainParticipantImpl::create_topic( (void)ret_topic_enable; } + cond_topics_.notify_all(); + return topic; } diff --git a/src/cpp/fastdds/domain/DomainParticipantImpl.hpp b/src/cpp/fastdds/domain/DomainParticipantImpl.hpp index 6ec2a2d3b5c..666e8480d5c 100644 --- a/src/cpp/fastdds/domain/DomainParticipantImpl.hpp +++ b/src/cpp/fastdds/domain/DomainParticipantImpl.hpp @@ -20,6 +20,10 @@ #ifndef _FASTDDS_PARTICIPANTIMPL_HPP_ #define _FASTDDS_PARTICIPANTIMPL_HPP_ #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +#include +#include + #include #include #include @@ -499,6 +503,7 @@ class DomainParticipantImpl std::map filter_factories_; DDSSQLFilter::DDSFilterFactory dds_sql_filter_factory_; mutable std::mutex mtx_topics_; + std::condition_variable cond_topics_; TopicQos default_topic_qos_; From c019872151c549a1bee90b75199ad5f2e5e276bf Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Wed, 1 Jun 2022 13:01:55 +0200 Subject: [PATCH 18/33] Refs #14615. Implementation of DomainParticipantImpl::find_topic. Signed-off-by: Miguel Company --- .../fastdds/domain/DomainParticipantImpl.cpp | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp index a53fbde1ae0..bece2eddffe 100644 --- a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp @@ -473,10 +473,24 @@ Topic* DomainParticipantImpl::find_topic( const std::string& topic_name, const fastrtps::Duration_t& timeout) { - static_cast (topic_name); - static_cast (timeout); - logWarning(DOMAIN_PARTICIPANT, "find_topic method not implemented"); - return nullptr; + auto duration = std::chrono::seconds(timeout.seconds) + std::chrono::nanoseconds(timeout.nanosec); + Topic* ret_val = nullptr; + + std::unique_lock lock(mtx_topics_); + if (cond_topics_.wait_for(lock, duration, [this, &topic_name]() + { + return topics_.count(topic_name) > 0; + })) + { + ret_val = topics_[topic_name]->create_topic()->get_topic(); + + InstanceHandle_t topic_handle; + create_instance_handle(topic_handle); + ret_val->set_instance_handle(topic_handle); + topics_by_handle_[topic_handle] = ret_val; + } + + return ret_val; } ReturnCode_t DomainParticipantImpl::delete_topic( From 313221515937dbd3d100771e7d39064751780d4e Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Wed, 1 Jun 2022 13:03:03 +0200 Subject: [PATCH 19/33] Refs #14615. Fixed segfault on test. Signed-off-by: Miguel Company --- test/blackbox/common/DDSBlackboxTestsFindTopic.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/blackbox/common/DDSBlackboxTestsFindTopic.cpp b/test/blackbox/common/DDSBlackboxTestsFindTopic.cpp index aaa77def582..eb207896720 100644 --- a/test/blackbox/common/DDSBlackboxTestsFindTopic.cpp +++ b/test/blackbox/common/DDSBlackboxTestsFindTopic.cpp @@ -51,6 +51,13 @@ class DDSFindTopicTest : public testing::Test */ struct TestType : public TopicDataType { + TestType() + : TopicDataType() + { + m_isGetKeyDefined = false; + m_typeSize = 16; + } + bool serialize( void*, fastrtps::rtps::SerializedPayload_t*) override From 7932671ce40383b3001abbe8a40dfca886183bf0 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Wed, 1 Jun 2022 13:03:33 +0200 Subject: [PATCH 20/33] Refs #14615. Fixed return value on delete_topic. Signed-off-by: Miguel Company --- src/cpp/fastdds/domain/DomainParticipantImpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp index bece2eddffe..0ee03685fc0 100644 --- a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp @@ -527,7 +527,7 @@ ReturnCode_t DomainParticipantImpl::delete_topic( delete factory; } } - return ReturnCode_t::RETCODE_OK; + return ret_code; } return ReturnCode_t::RETCODE_PRECONDITION_NOT_MET; From 41c0783bb2e4c9c011dc2536ec9969157984f8c7 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Wed, 1 Jun 2022 14:15:17 +0200 Subject: [PATCH 21/33] Refs #14615. Avoid using input topic on delete_topic. Signed-off-by: Miguel Company --- .../fastdds/domain/DomainParticipantImpl.cpp | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp index 0ee03685fc0..febb516546e 100644 --- a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp @@ -501,23 +501,22 @@ ReturnCode_t DomainParticipantImpl::delete_topic( return ReturnCode_t::RETCODE_BAD_PARAMETER; } - if (participant_ != topic->get_participant()) - { - return ReturnCode_t::RETCODE_PRECONDITION_NOT_MET; - } - std::lock_guard lock(mtx_topics_); - auto it = topics_.find(topic->get_name()); - auto handle = topic->get_instance_handle(); - - if (it != topics_.end()) + auto handle_it = std::find_if(topics_by_handle_.begin(), topics_by_handle_.end(), + [topic](const auto& item) + { + return item.second == topic; + }); + if (handle_it != topics_by_handle_.end()) { + auto it = topics_.find(topic->get_name()); + assert(it != topics_.end() && "Topic found by handle but factory not found"); + TopicProxy* proxy = dynamic_cast(topic->get_impl()); auto ret_code = it->second->delete_topic(proxy); if (ReturnCode_t::RETCODE_OK == ret_code) { - assert(topics_by_handle_.find(handle) != topics_by_handle_.end() - && "The topic instance handle does not match the topic implementation instance handle"); + InstanceHandle_t handle = topic->get_instance_handle(); topics_by_handle_.erase(handle); if (it->second->can_be_deleted()) From 47f16a1431b7397137439229dadeaf7013928ddb Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Wed, 1 Jun 2022 16:30:57 +0200 Subject: [PATCH 22/33] Refs #14615. Always use input listener. Signed-off-by: Miguel Company --- src/cpp/fastdds/topic/Topic.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cpp/fastdds/topic/Topic.cpp b/src/cpp/fastdds/topic/Topic.cpp index 8f553bf38af..e85690acb30 100644 --- a/src/cpp/fastdds/topic/Topic.cpp +++ b/src/cpp/fastdds/topic/Topic.cpp @@ -82,8 +82,7 @@ ReturnCode_t Topic::set_listener( TopicListener* listener, const StatusMask& mask) { - TopicListener* value = mask.is_active(mask.inconsistent_topic()) ? listener : nullptr; - ReturnCode_t ret_val = impl_->set_listener(value); + ReturnCode_t ret_val = impl_->set_listener(listener); if (ret_val == ReturnCode_t::RETCODE_OK) { status_mask_ = mask; From b72309cfb52b2b3fd209a3df5c3e5912b2b0d241 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 2 Jun 2022 09:15:50 +0200 Subject: [PATCH 23/33] Refs #14615. Internal set_listener methods return void. Signed-off-by: Miguel Company --- src/cpp/fastdds/topic/Topic.cpp | 9 +++------ src/cpp/fastdds/topic/TopicImpl.cpp | 3 +-- src/cpp/fastdds/topic/TopicImpl.hpp | 2 +- src/cpp/fastdds/topic/TopicProxy.hpp | 4 ++-- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/cpp/fastdds/topic/Topic.cpp b/src/cpp/fastdds/topic/Topic.cpp index e85690acb30..5c128fbe2dc 100644 --- a/src/cpp/fastdds/topic/Topic.cpp +++ b/src/cpp/fastdds/topic/Topic.cpp @@ -82,13 +82,10 @@ ReturnCode_t Topic::set_listener( TopicListener* listener, const StatusMask& mask) { - ReturnCode_t ret_val = impl_->set_listener(listener); - if (ret_val == ReturnCode_t::RETCODE_OK) - { - status_mask_ = mask; - } + impl_->set_listener(listener); + status_mask_ = mask; - return ret_val; + return ReturnCode_t::RETCODE_OK; } DomainParticipant* Topic::get_participant() const diff --git a/src/cpp/fastdds/topic/TopicImpl.cpp b/src/cpp/fastdds/topic/TopicImpl.cpp index 1c94ee28ca5..1125e0c84f7 100644 --- a/src/cpp/fastdds/topic/TopicImpl.cpp +++ b/src/cpp/fastdds/topic/TopicImpl.cpp @@ -141,11 +141,10 @@ const TopicListener* TopicImpl::get_listener() const return listener_; } -ReturnCode_t TopicImpl::set_listener( +void TopicImpl::set_listener( TopicListener* listener) { listener_ = listener; - return ReturnCode_t::RETCODE_OK; } DomainParticipant* TopicImpl::get_participant() const diff --git a/src/cpp/fastdds/topic/TopicImpl.hpp b/src/cpp/fastdds/topic/TopicImpl.hpp index 7166531e953..55bf727325e 100644 --- a/src/cpp/fastdds/topic/TopicImpl.hpp +++ b/src/cpp/fastdds/topic/TopicImpl.hpp @@ -69,7 +69,7 @@ class TopicImpl const TopicListener* get_listener() const; - ReturnCode_t set_listener( + void set_listener( TopicListener* listener); DomainParticipant* get_participant() const; diff --git a/src/cpp/fastdds/topic/TopicProxy.hpp b/src/cpp/fastdds/topic/TopicProxy.hpp index 0bdcce4c298..05f0f889d44 100644 --- a/src/cpp/fastdds/topic/TopicProxy.hpp +++ b/src/cpp/fastdds/topic/TopicProxy.hpp @@ -71,10 +71,10 @@ class TopicProxy : public TopicDescriptionImpl return impl_->get_listener(); } - ReturnCode_t set_listener( + void set_listener( TopicListener* listener) { - return impl_->set_listener(listener); + impl_->set_listener(listener); } DomainParticipant* get_participant() const From 157d8362be887f70957faa63bd97bf3925ca9ca7 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 2 Jun 2022 09:29:37 +0200 Subject: [PATCH 24/33] Refs #14615. TopicProxyFactory::for_each. Signed-off-by: Miguel Company --- src/cpp/fastdds/topic/TopicProxyFactory.hpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/cpp/fastdds/topic/TopicProxyFactory.hpp b/src/cpp/fastdds/topic/TopicProxyFactory.hpp index c1f56334a83..7ef3bf7fe59 100644 --- a/src/cpp/fastdds/topic/TopicProxyFactory.hpp +++ b/src/cpp/fastdds/topic/TopicProxyFactory.hpp @@ -19,6 +19,7 @@ #ifndef _FASTDDS_TOPICPROXYFACTORY_HPP_ #define _FASTDDS_TOPICPROXYFACTORY_HPP_ +#include #include #include #include @@ -110,6 +111,15 @@ class TopicProxyFactory */ void enable_topic(); + /** + * Apply the given function to all the TopicProxy objects owned by the factory. + */ + template + void for_each(UnaryFunction f) const + { + std::for_each(proxies_.begin(), proxies_.end(), f); + } + private: //! Name of the topic managed by the factory. From afc7f3cdad6e4ffbd51469d26d868e20dfe955ad Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 2 Jun 2022 10:00:56 +0200 Subject: [PATCH 25/33] Refs #14615. TopicImpl holds pointer to TopicProxyFactory. Signed-off-by: Miguel Company --- src/cpp/fastdds/topic/TopicImpl.cpp | 4 +++- src/cpp/fastdds/topic/TopicImpl.hpp | 3 +++ src/cpp/fastdds/topic/TopicProxyFactory.hpp | 2 +- .../fastdds/domain/DomainParticipantImpl.hpp | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cpp/fastdds/topic/TopicImpl.cpp b/src/cpp/fastdds/topic/TopicImpl.cpp index 1125e0c84f7..daf4627c694 100644 --- a/src/cpp/fastdds/topic/TopicImpl.cpp +++ b/src/cpp/fastdds/topic/TopicImpl.cpp @@ -33,11 +33,13 @@ namespace fastdds { namespace dds { TopicImpl::TopicImpl( + TopicProxyFactory* factory, DomainParticipantImpl* p, TypeSupport type_support, const TopicQos& qos, TopicListener* listen) - : participant_(p) + : factory_(factory) + , participant_(p) , type_support_(type_support) , qos_(&qos == &TOPIC_QOS_DEFAULT ? participant_->get_default_topic_qos() : qos) , listener_(listen) diff --git a/src/cpp/fastdds/topic/TopicImpl.hpp b/src/cpp/fastdds/topic/TopicImpl.hpp index 55bf727325e..294ef1d88be 100644 --- a/src/cpp/fastdds/topic/TopicImpl.hpp +++ b/src/cpp/fastdds/topic/TopicImpl.hpp @@ -37,12 +37,14 @@ class DomainParticipantImpl; class DomainParticipant; class TopicListener; class Topic; +class TopicProxyFactory; class TopicImpl { public: TopicImpl( + TopicProxyFactory* factory, DomainParticipantImpl* p, TypeSupport type_support, const TopicQos& qos, @@ -86,6 +88,7 @@ class TopicImpl protected: + TopicProxyFactory* factory_; DomainParticipantImpl* participant_; TypeSupport type_support_; TopicQos qos_; diff --git a/src/cpp/fastdds/topic/TopicProxyFactory.hpp b/src/cpp/fastdds/topic/TopicProxyFactory.hpp index 7ef3bf7fe59..9a5615f6577 100644 --- a/src/cpp/fastdds/topic/TopicProxyFactory.hpp +++ b/src/cpp/fastdds/topic/TopicProxyFactory.hpp @@ -67,7 +67,7 @@ class TopicProxyFactory TopicListener* listener) : topic_name_(topic_name) , status_mask_(status_mask) - , topic_impl_(participant, type_support, qos, listener) + , topic_impl_(this, participant, type_support, qos, listener) { } diff --git a/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp b/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp index 2c7fac32854..eb40781105a 100644 --- a/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp +++ b/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp @@ -264,7 +264,7 @@ class DomainParticipantImpl { return nullptr; } - TopicImpl* topic_impl = new TopicImpl(this, type_support, qos, listener); + TopicImpl* topic_impl = new TopicImpl(nullptr, this, type_support, qos, listener); TopicProxy* proxy = new TopicProxy(topic_name, type_name, mask, topic_impl); Topic* topic = proxy->get_topic(); topics_[topic_name] = proxy; From 44a3425be8b4384920758085b7d39f8bb88b133e Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 2 Jun 2022 10:46:05 +0200 Subject: [PATCH 26/33] Refs #14615. DomainParticipantImpl::set_topic_listener. Signed-off-by: Miguel Company --- src/cpp/fastdds/domain/DomainParticipantImpl.cpp | 14 ++++++++++++++ src/cpp/fastdds/domain/DomainParticipantImpl.hpp | 14 ++++++++++++++ .../fastdds/domain/DomainParticipantImpl.hpp | 8 ++++++++ 3 files changed, 36 insertions(+) diff --git a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp index febb516546e..f45b8d77815 100644 --- a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp @@ -493,6 +493,20 @@ Topic* DomainParticipantImpl::find_topic( return ret_val; } +void DomainParticipantImpl::set_topic_listener( + const TopicProxyFactory* factory, + TopicImpl* impl, + TopicListener* listener, + const StatusMask& mask) +{ + std::lock_guard lock(mtx_topics_); + impl->set_listener(listener); + factory->for_each([mask](const auto& proxy) + { + proxy->get_topic()->status_mask_ = mask; + }); +} + ReturnCode_t DomainParticipantImpl::delete_topic( const Topic* topic) { diff --git a/src/cpp/fastdds/domain/DomainParticipantImpl.hpp b/src/cpp/fastdds/domain/DomainParticipantImpl.hpp index 666e8480d5c..a5448aa948c 100644 --- a/src/cpp/fastdds/domain/DomainParticipantImpl.hpp +++ b/src/cpp/fastdds/domain/DomainParticipantImpl.hpp @@ -230,6 +230,20 @@ class DomainParticipantImpl const std::string& topic_name, const fastrtps::Duration_t& timeout); + /** + * Implementation of Topic::set_listener that propagates the listener and mask to all the TopicProxy + * objects held by the same TopicProxy factory in a thread-safe way. + * + * @param factory TopicProxyFactory managing the topic on which the listener should be changed. + * @param listener Listener to assign to all the TopicProxy objects owned by the factory. + * @param mask StatusMask to assign to all the TopicProxy objects owned by the factory. + */ + void set_topic_listener( + const TopicProxyFactory* factory, + TopicImpl* topic, + TopicListener* listener, + const StatusMask& mask); + ReturnCode_t delete_topic( const Topic* topic); diff --git a/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp b/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp index eb40781105a..c6e882d05b8 100644 --- a/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp +++ b/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp @@ -289,6 +289,14 @@ class DomainParticipantImpl return nullptr; } + void set_topic_listener( + const TopicProxyFactory* /*factory*/, + TopicImpl* /*impl*/, + TopicListener* /*listener*/, + const StatusMask& /*mask*/) + { + } + ReturnCode_t delete_topic( const Topic* topic) { From 5785f76092c0eb72133d08b5c3789759a2da1f6d Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 2 Jun 2022 10:50:00 +0200 Subject: [PATCH 27/33] Refs #14615. TopicImpl::set_listener with mask. Signed-off-by: Miguel Company --- src/cpp/fastdds/topic/TopicImpl.cpp | 7 +++++++ src/cpp/fastdds/topic/TopicImpl.hpp | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/src/cpp/fastdds/topic/TopicImpl.cpp b/src/cpp/fastdds/topic/TopicImpl.cpp index daf4627c694..2b8c8a66cf7 100644 --- a/src/cpp/fastdds/topic/TopicImpl.cpp +++ b/src/cpp/fastdds/topic/TopicImpl.cpp @@ -149,6 +149,13 @@ void TopicImpl::set_listener( listener_ = listener; } +void TopicImpl::set_listener( + TopicListener* listener, + const StatusMask& mask) +{ + participant_->set_topic_listener(factory_, this, listener, mask); +} + DomainParticipant* TopicImpl::get_participant() const { return participant_->get_participant(); diff --git a/src/cpp/fastdds/topic/TopicImpl.hpp b/src/cpp/fastdds/topic/TopicImpl.hpp index 294ef1d88be..cd1de38fc79 100644 --- a/src/cpp/fastdds/topic/TopicImpl.hpp +++ b/src/cpp/fastdds/topic/TopicImpl.hpp @@ -74,6 +74,10 @@ class TopicImpl void set_listener( TopicListener* listener); + void set_listener( + TopicListener* listener, + const StatusMask& status); + DomainParticipant* get_participant() const; const TypeSupport& get_type() const; From 9262a425fc183d70c6a41e40dc9c1c5b6f859b69 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 2 Jun 2022 10:52:48 +0200 Subject: [PATCH 28/33] Refs #14615. Topic::set_listener propagates mask. Signed-off-by: Miguel Company --- src/cpp/fastdds/topic/Topic.cpp | 4 +--- src/cpp/fastdds/topic/TopicProxy.hpp | 5 +++-- .../fastdds/domain/DomainParticipantImpl.hpp | 1 - 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/cpp/fastdds/topic/Topic.cpp b/src/cpp/fastdds/topic/Topic.cpp index 5c128fbe2dc..ed8975170b5 100644 --- a/src/cpp/fastdds/topic/Topic.cpp +++ b/src/cpp/fastdds/topic/Topic.cpp @@ -82,9 +82,7 @@ ReturnCode_t Topic::set_listener( TopicListener* listener, const StatusMask& mask) { - impl_->set_listener(listener); - status_mask_ = mask; - + impl_->set_listener(listener, mask); return ReturnCode_t::RETCODE_OK; } diff --git a/src/cpp/fastdds/topic/TopicProxy.hpp b/src/cpp/fastdds/topic/TopicProxy.hpp index 05f0f889d44..1c455402fe9 100644 --- a/src/cpp/fastdds/topic/TopicProxy.hpp +++ b/src/cpp/fastdds/topic/TopicProxy.hpp @@ -72,9 +72,10 @@ class TopicProxy : public TopicDescriptionImpl } void set_listener( - TopicListener* listener) + TopicListener* listener, + const StatusMask& mask) { - impl_->set_listener(listener); + impl_->set_listener(listener, mask); } DomainParticipant* get_participant() const diff --git a/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp b/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp index c6e882d05b8..c3d2ca8b5b7 100644 --- a/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp +++ b/test/mock/dds/DomainParticipantImpl/fastdds/domain/DomainParticipantImpl.hpp @@ -659,7 +659,6 @@ class DomainParticipantImpl while (it_topics != topics_.end()) { - it_topics->second->set_listener(nullptr); delete it_topics->second; it_topics = topics_.erase(it_topics); } From fe4dee4a3244e18a3e652329f15452f8f439b675 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 2 Jun 2022 11:36:29 +0200 Subject: [PATCH 29/33] Refs #14615. Correctly handling infinite timeout. Signed-off-by: Miguel Company --- .../fastdds/domain/DomainParticipantImpl.cpp | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp index f45b8d77815..ec07678622b 100644 --- a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp @@ -473,23 +473,32 @@ Topic* DomainParticipantImpl::find_topic( const std::string& topic_name, const fastrtps::Duration_t& timeout) { - auto duration = std::chrono::seconds(timeout.seconds) + std::chrono::nanoseconds(timeout.nanosec); - Topic* ret_val = nullptr; + auto find_fn = [this, &topic_name]() + { + return topics_.count(topic_name) > 0; + }; std::unique_lock lock(mtx_topics_); - if (cond_topics_.wait_for(lock, duration, [this, &topic_name]() - { - return topics_.count(topic_name) > 0; - })) + if (timeout.is_infinite()) { - ret_val = topics_[topic_name]->create_topic()->get_topic(); - - InstanceHandle_t topic_handle; - create_instance_handle(topic_handle); - ret_val->set_instance_handle(topic_handle); - topics_by_handle_[topic_handle] = ret_val; + cond_topics_.wait(lock, find_fn); + } + else + { + auto duration = std::chrono::seconds(timeout.seconds) + std::chrono::nanoseconds(timeout.nanosec); + if (!cond_topics_.wait_for(lock, duration, find_fn)) + { + return nullptr; + } } + Topic* ret_val = topics_[topic_name]->create_topic()->get_topic(); + + InstanceHandle_t topic_handle; + create_instance_handle(topic_handle); + ret_val->set_instance_handle(topic_handle); + topics_by_handle_[topic_handle] = ret_val; + return ret_val; } From 0e9e5c83aea16e1bc52a4cffbb587b29e925b032 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 2 Jun 2022 11:44:24 +0200 Subject: [PATCH 30/33] Refs #14615. Uncrustify. Signed-off-by: Miguel Company --- include/dds/topic/Topic.hpp | 4 ++-- src/cpp/fastdds/domain/DomainParticipantImpl.cpp | 6 +++--- src/cpp/fastdds/topic/TopicProxyFactory.hpp | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/dds/topic/Topic.hpp b/include/dds/topic/Topic.hpp index 645b34cc089..068ef0643d9 100644 --- a/include/dds/topic/Topic.hpp +++ b/include/dds/topic/Topic.hpp @@ -38,12 +38,12 @@ class Topic : public dds::core::TEntity public: OMG_DDS_REF_TYPE_PROTECTED_DC( - Topic, + Topic, dds::core::TEntity, detail::Topic) OMG_DDS_IMPLICIT_REF_BASE( - Topic) + Topic) /** * Create a new Topic. diff --git a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp index ec07678622b..301bc74d30c 100644 --- a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp @@ -474,9 +474,9 @@ Topic* DomainParticipantImpl::find_topic( const fastrtps::Duration_t& timeout) { auto find_fn = [this, &topic_name]() - { - return topics_.count(topic_name) > 0; - }; + { + return topics_.count(topic_name) > 0; + }; std::unique_lock lock(mtx_topics_); if (timeout.is_infinite()) diff --git a/src/cpp/fastdds/topic/TopicProxyFactory.hpp b/src/cpp/fastdds/topic/TopicProxyFactory.hpp index 9a5615f6577..afd646be59d 100644 --- a/src/cpp/fastdds/topic/TopicProxyFactory.hpp +++ b/src/cpp/fastdds/topic/TopicProxyFactory.hpp @@ -115,7 +115,8 @@ class TopicProxyFactory * Apply the given function to all the TopicProxy objects owned by the factory. */ template - void for_each(UnaryFunction f) const + void for_each( + UnaryFunction f) const { std::for_each(proxies_.begin(), proxies_.end(), f); } From eadf8af31cd67f07f9edeeb300f9b194c6cca291 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 2 Jun 2022 13:08:37 +0200 Subject: [PATCH 31/33] Refs #14615. Fixed non-c++11 code. Signed-off-by: Miguel Company --- src/cpp/fastdds/domain/DomainParticipantImpl.cpp | 4 ++-- src/cpp/fastdds/topic/TopicProxyFactory.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp index 301bc74d30c..d97dda68538 100644 --- a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp @@ -510,7 +510,7 @@ void DomainParticipantImpl::set_topic_listener( { std::lock_guard lock(mtx_topics_); impl->set_listener(listener); - factory->for_each([mask](const auto& proxy) + factory->for_each([mask](const std::unique_ptr& proxy) { proxy->get_topic()->status_mask_ = mask; }); @@ -526,7 +526,7 @@ ReturnCode_t DomainParticipantImpl::delete_topic( std::lock_guard lock(mtx_topics_); auto handle_it = std::find_if(topics_by_handle_.begin(), topics_by_handle_.end(), - [topic](const auto& item) + [topic](const decltype(topics_by_handle_)::value_type& item) { return item.second == topic; }); diff --git a/src/cpp/fastdds/topic/TopicProxyFactory.cpp b/src/cpp/fastdds/topic/TopicProxyFactory.cpp index 47d801db360..dd1fc2853bc 100644 --- a/src/cpp/fastdds/topic/TopicProxyFactory.cpp +++ b/src/cpp/fastdds/topic/TopicProxyFactory.cpp @@ -36,7 +36,7 @@ TopicProxy* TopicProxyFactory::create_topic() ReturnCode_t TopicProxyFactory::delete_topic( TopicProxy* proxy) { - auto it = std::find_if(proxies_.begin(), proxies_.end(), [proxy](const auto& item) + auto it = std::find_if(proxies_.begin(), proxies_.end(), [proxy](const std::unique_ptr& item) { return item.get() == proxy; }); From 8af4751247f020a3fc6334ff80a5f0b7e0023038 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Tue, 21 Jun 2022 10:03:58 +0200 Subject: [PATCH 32/33] Refs #14615. Improve doxydoc. Signed-off-by: Miguel Company --- include/fastdds/dds/domain/DomainParticipant.hpp | 9 +++++++-- src/cpp/fastdds/domain/DomainParticipantImpl.hpp | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/fastdds/dds/domain/DomainParticipant.hpp b/include/fastdds/dds/domain/DomainParticipant.hpp index d61e1577bfe..cf12231b05c 100644 --- a/include/fastdds/dds/domain/DomainParticipant.hpp +++ b/include/fastdds/dds/domain/DomainParticipant.hpp @@ -354,11 +354,16 @@ class DomainParticipant : public Entity /** * Gives access to an existing (or ready to exist) enabled Topic. - * Topics obtained by this method must be destroyed by delete_topic. + * It should be noted that the returned Topic is a local object that acts as a proxy to designate the global + * concept of topic. + * Topics obtained by means of find_topic, must also be deleted by means of delete_topic so that the local + * resources can be released. + * If a Topic is obtained multiple times by means of find_topic or create_topic, it must also be deleted that same + * number of times using delete_topic. * * @param topic_name Topic name * @param timeout Maximum time to wait for the Topic - * @return Pointer to the existing Topic, nullptr in error case + * @return Pointer to the existing Topic, nullptr in case of error or timeout */ RTPS_DllAPI Topic* find_topic( const std::string& topic_name, diff --git a/src/cpp/fastdds/domain/DomainParticipantImpl.hpp b/src/cpp/fastdds/domain/DomainParticipantImpl.hpp index a5448aa948c..2f1cd373977 100644 --- a/src/cpp/fastdds/domain/DomainParticipantImpl.hpp +++ b/src/cpp/fastdds/domain/DomainParticipantImpl.hpp @@ -220,11 +220,16 @@ class DomainParticipantImpl /** * Gives access to an existing (or ready to exist) enabled Topic. - * Topics obtained by this method must be destroyed by delete_topic. + * It should be noted that the returned Topic is a local object that acts as a proxy to designate the global + * concept of topic. + * Topics obtained by means of find_topic, must also be deleted by means of delete_topic so that the local + * resources can be released. + * If a Topic is obtained multiple times by means of find_topic or create_topic, it must also be deleted that same + * number of times using delete_topic. * * @param topic_name Topic name * @param timeout Maximum time to wait for the Topic - * @return Pointer to the existing Topic, nullptr in error case + * @return Pointer to the existing Topic, nullptr in case of error or timeout */ Topic* find_topic( const std::string& topic_name, From 9ab899abe2508c44a1a97e25e822976e8adc1038 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Tue, 21 Jun 2022 10:07:13 +0200 Subject: [PATCH 33/33] Refs #14615. Assertion on dynamic_cast result. Signed-off-by: Miguel Company --- src/cpp/fastdds/domain/DomainParticipantImpl.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp index d97dda68538..f5ea6a59ac4 100644 --- a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp @@ -536,6 +536,7 @@ ReturnCode_t DomainParticipantImpl::delete_topic( assert(it != topics_.end() && "Topic found by handle but factory not found"); TopicProxy* proxy = dynamic_cast(topic->get_impl()); + assert(nullptr != proxy); auto ret_code = it->second->delete_topic(proxy); if (ReturnCode_t::RETCODE_OK == ret_code) {