From 76134ddbe4551ec4d293916ccdfcbb4a22ae6c7a Mon Sep 17 00:00:00 2001 From: EduPonz Date: Thu, 7 Mar 2024 11:00:10 +0100 Subject: [PATCH 01/22] Refs #20567: Include what you use in latency test Signed-off-by: EduPonz --- test/performance/latency/LatencyTestTypes.hpp | 12 ++++++++---- test/performance/latency/main_LatencyTest.cpp | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/test/performance/latency/LatencyTestTypes.hpp b/test/performance/latency/LatencyTestTypes.hpp index e5a5d51e838..43dda2e36d9 100644 --- a/test/performance/latency/LatencyTestTypes.hpp +++ b/test/performance/latency/LatencyTestTypes.hpp @@ -17,13 +17,17 @@ * */ -#include -#include - #ifndef LATENCYTESTTYPES_H_ #define LATENCYTESTTYPES_H_ -#include "fastrtps/fastrtps_all.h" +#include +#include +#include + +#include +#include +#include +#include #define MAX_TYPE_SIZE 10 * 1024 * 1024 diff --git a/test/performance/latency/main_LatencyTest.cpp b/test/performance/latency/main_LatencyTest.cpp index 39693cc19e1..93a71039bde 100644 --- a/test/performance/latency/main_LatencyTest.cpp +++ b/test/performance/latency/main_LatencyTest.cpp @@ -186,6 +186,7 @@ int main( char** argv) { + using Log = eprosima::fastdds::dds::Log; Log::SetVerbosity(Log::Kind::Info); Log::SetCategoryFilter(std::regex("LatencyTest")); From 9c0a79ec892060842c085c41555f26ef3b584d47 Mon Sep 17 00:00:00 2001 From: EduPonz Date: Thu, 7 Mar 2024 11:01:11 +0100 Subject: [PATCH 02/22] Refs #20567: Remove unnecesary and deprecated headers Signed-off-by: EduPonz --- include/fastrtps/attributes/all_attributes.h | 29 ------------ include/fastrtps/fastrtps_all.h | 45 ------------------- test/performance/latency/LatencyTestTypes.hpp | 2 +- 3 files changed, 1 insertion(+), 75 deletions(-) delete mode 100644 include/fastrtps/attributes/all_attributes.h delete mode 100644 include/fastrtps/fastrtps_all.h diff --git a/include/fastrtps/attributes/all_attributes.h b/include/fastrtps/attributes/all_attributes.h deleted file mode 100644 index 4377f2eb3f6..00000000000 --- a/include/fastrtps/attributes/all_attributes.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2016 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. - -/** - * @file all_attributes.h - */ - -#ifndef ALL_ATTRIBUTES_H_ -#define ALL_ATTRIBUTES_H_ - -#include -#include -#include -#include -#include -#include - -#endif /* ALL_ATTRIBUTES_H_ */ diff --git a/include/fastrtps/fastrtps_all.h b/include/fastrtps/fastrtps_all.h deleted file mode 100644 index f40573d056b..00000000000 --- a/include/fastrtps/fastrtps_all.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2016 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. - -/** - * @file rtps_all.h - * - */ - -#ifndef FASTRTPS_ALL_H_ -#define FASTRTPS_ALL_H_ - -//USER THIS HEADER TO CREATE RAPID PROTOTYPES AND TESTS -//DO NOT INCLUDE IN PROJETCTS WERE COMPILATION TIME OR SIZE IS REVELANT -//SINCE IT INCLUDES ALL NECESSARY HEADERS. - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#endif /* FASTRTPS_ALL_H_ */ diff --git a/test/performance/latency/LatencyTestTypes.hpp b/test/performance/latency/LatencyTestTypes.hpp index 43dda2e36d9..2b4b314c862 100644 --- a/test/performance/latency/LatencyTestTypes.hpp +++ b/test/performance/latency/LatencyTestTypes.hpp @@ -164,7 +164,7 @@ class LatencyDataType : public eprosima::fastdds::dds::TopicDataType private: - using eprosima::fastrtps::TopicDataType::is_plain; + using eprosima::fastdds::dds::TopicDataType::is_plain; }; enum TESTCOMMAND : uint32_t From 47ce65a7fa247de60dab21221c42adb79304c77b Mon Sep 17 00:00:00 2001 From: EduPonz Date: Thu, 7 Mar 2024 13:00:11 +0100 Subject: [PATCH 03/22] Refs #20567: Migrate allocations test to DDS Signed-off-by: EduPonz --- .../profiling/allocations/AllocTestCommon.cpp | 3 +- .../allocations/AllocTestPublisher.cpp | 179 +++++++++------- .../allocations/AllocTestPublisher.h | 70 ------ .../allocations/AllocTestPublisher.hpp | 99 +++++++++ .../allocations/AllocTestSubscriber.cpp | 200 ++++++++++-------- .../allocations/AllocTestSubscriber.h | 104 --------- .../allocations/AllocTestSubscriber.hpp | 103 +++++++++ test/profiling/allocations/AllocTest_main.cpp | 4 +- test/profiling/allocations/CMakeLists.txt | 2 +- 9 files changed, 424 insertions(+), 340 deletions(-) delete mode 100644 test/profiling/allocations/AllocTestPublisher.h create mode 100644 test/profiling/allocations/AllocTestPublisher.hpp delete mode 100644 test/profiling/allocations/AllocTestSubscriber.h create mode 100644 test/profiling/allocations/AllocTestSubscriber.hpp diff --git a/test/profiling/allocations/AllocTestCommon.cpp b/test/profiling/allocations/AllocTestCommon.cpp index 44935a25d18..4c395124d96 100644 --- a/test/profiling/allocations/AllocTestCommon.cpp +++ b/test/profiling/allocations/AllocTestCommon.cpp @@ -23,7 +23,8 @@ #include #include #include -#include "osrf_testing_tools_cpp/memory_tools/memory_tools.hpp" + +#include using MemoryToolsService = osrf_testing_tools_cpp::memory_tools::MemoryToolsService; diff --git a/test/profiling/allocations/AllocTestPublisher.cpp b/test/profiling/allocations/AllocTestPublisher.cpp index c681f02e2b0..0bc00fc4340 100644 --- a/test/profiling/allocations/AllocTestPublisher.cpp +++ b/test/profiling/allocations/AllocTestPublisher.cpp @@ -17,129 +17,152 @@ * */ -#include "AllocTestPublisher.h" +#include "AllocTestPublisher.hpp" #include +#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include "AllocTestCommon.h" +#include "AllocTestTypePubSubTypes.h" -using namespace eprosima::fastrtps; -using namespace eprosima::fastrtps::rtps; +using namespace eprosima::fastdds::dds; + +#define CHECK_RETURN_CODE(ret) \ + if (ReturnCode_t::RETCODE_OK != ret) \ + { \ + return false; \ + } + +#define CHECK_ENTITY_CREATION(entity) \ + if (nullptr != entity) \ + { \ + return false; \ + } AllocTestPublisher::AllocTestPublisher() - : mp_participant(nullptr) - , mp_publisher(nullptr) + : type_(new AllocTestTypePubSubType()) + , participant_(nullptr) + , topic_(nullptr) + , publisher_(nullptr) + , writer_(nullptr) + , profile_("") + , output_file_("") + , matched_(0) { +} - +AllocTestPublisher::~AllocTestPublisher() +{ + if (participant_ != nullptr) + { + participant_->delete_contained_entities(); + DomainParticipantFactory::get_shared_instance()->delete_participant(participant_); + participant_ = nullptr; + } } bool AllocTestPublisher::init( const char* profile, - int domainId, - const std::string& outputFile) + uint32_t domain_id, + const std::string& output_file) { - m_data.index(0); + data_.index(0); - m_profile = profile; - m_outputFile = outputFile; - Domain::loadXMLProfilesFile("test_xml_profile.xml"); + profile_ = profile; + output_file_ = output_file; - ParticipantAttributes participant_att; - // TODO(jlbueno): migrate to DomainParticipantFactory::get_participant_qos_from_profile - if (eprosima::fastrtps::xmlparser::XMLP_ret::XML_OK == - eprosima::fastrtps::xmlparser::XMLProfileManager::fillParticipantAttributes("test_participant_profile", - participant_att)) - { - participant_att.domainId = domainId; - mp_participant = Domain::createParticipant(participant_att); - } + ReturnCode_t ret = ReturnCode_t::RETCODE_OK; - if (mp_participant == nullptr) - { - return false; - } + std::shared_ptr factory = DomainParticipantFactory::get_shared_instance(); + ret = factory->load_XML_profiles_file("test_xml_profile.xml"); + CHECK_RETURN_CODE(ret); - //REGISTER THE TYPE - Domain::registerType(mp_participant, &m_type); + DomainParticipantQos pqos; + ret = factory->get_participant_qos_from_profile("test_participant_profile", pqos); + CHECK_RETURN_CODE(ret); - //CREATE THE PUBLISHER - std::string prof("test_publisher_profile_"); - prof.append(profile); - mp_publisher = Domain::createPublisher(mp_participant, prof, (PublisherListener*)&m_listener); - if (mp_publisher == nullptr) - { - return false; - } + participant_ = factory->create_participant(domain_id, pqos); + CHECK_ENTITY_CREATION(participant_); - bool show_allocation_traces = std::getenv("FASTDDS_PROFILING_PRINT_TRACES") != nullptr; - eprosima_profiling::entities_created(show_allocation_traces); - return true; + ret = type_.register_type(participant_); + CHECK_RETURN_CODE(ret); -} + topic_ = participant_->create_topic("AllocTestTopic", type_.get_type_name(), TOPIC_QOS_DEFAULT); + CHECK_ENTITY_CREATION(topic_); -AllocTestPublisher::~AllocTestPublisher() -{ - Domain::removeParticipant(mp_participant); + publisher_ = participant_->create_publisher(PUBLISHER_QOS_DEFAULT); + CHECK_ENTITY_CREATION(publisher_); + + std::string prof = "test_publisher_profile_" + profile_; + writer_ = publisher_->create_datawriter_with_profile(topic_, prof, this); + CHECK_ENTITY_CREATION(writer_); + + bool show_allocation_traces = std::getenv("FASTDDS_PROFILING_PRINT_TRACES") != nullptr; + eprosima_profiling::entities_created(show_allocation_traces); + return ret == ReturnCode_t::RETCODE_OK; } -void AllocTestPublisher::PubListener::onPublicationMatched( - Publisher* /*pub*/, - MatchingInfo& info) +void AllocTestPublisher::on_publication_matched( + DataWriter* /*writer*/, + const PublicationMatchedStatus& status) { - std::unique_lock lock(mtx); - if (info.status == MATCHED_MATCHING) + if (status.current_count_change == 1) { - n_matched++; + matched_++; std::cout << "Publisher matched" << std::endl; } - else + else if (status.current_count_change == -1) { - n_matched--; + matched_--; std::cout << "Publisher unmatched" << std::endl; } - cv.notify_all(); + else + { + std::cout << status.current_count_change + << " is not a valid value for PublicationMatchedStatus current count change" << std::endl; + } + cv_.notify_all(); } -bool AllocTestPublisher::PubListener::is_matched() +bool AllocTestPublisher::is_matched() { - std::unique_lock lock(mtx); - return n_matched > 0; + return matched_ > 0; } -void AllocTestPublisher::PubListener::wait_match() +void AllocTestPublisher::wait_match() { - std::unique_lock lock(mtx); - cv.wait(lock, [this]() + std::unique_lock lck(mtx_); + cv_.wait(lck, [this]() { - return n_matched > 0; + return matched_ > 0; }); } -void AllocTestPublisher::PubListener::wait_unmatch() +void AllocTestPublisher::wait_unmatch() { - std::unique_lock lock(mtx); - cv.wait(lock, [this]() + std::unique_lock lck(mtx_); + cv_.wait(lck, [this]() { - return n_matched <= 0; + return matched_ <= 0; }); } void AllocTestPublisher::run( uint32_t samples, - bool wait_unmatch) + bool wait_unmatching) { // Restart callgrind graph eprosima_profiling::callgrind_zero_count(); std::cout << "Publisher waiting for subscriber..." << std::endl; - m_listener.wait_match(); + wait_match(); // Flush callgrind graph eprosima_profiling::callgrind_dump(); @@ -156,7 +179,7 @@ void AllocTestPublisher::run( } else { - std::cout << "Message with index: " << m_data.index() << " SENT" << std::endl; + std::cout << "Message with index: " << data_.index() << " SENT" << std::endl; } std::this_thread::sleep_for(std::chrono::milliseconds(500)); @@ -175,10 +198,10 @@ void AllocTestPublisher::run( eprosima_profiling::callgrind_dump(); eprosima_profiling::all_samples_exchanged(); - if (wait_unmatch) + if (wait_unmatching) { std::cout << "All messages have been sent. Waiting for subscriber to stop." << std::endl; - m_listener.wait_unmatch(); + wait_unmatch(); } else { @@ -189,16 +212,16 @@ void AllocTestPublisher::run( // Flush callgrind graph eprosima_profiling::callgrind_dump(); eprosima_profiling::undiscovery_finished(); - eprosima_profiling::print_results(m_outputFile, "publisher", m_profile); + eprosima_profiling::print_results(output_file_, "publisher", profile_); } bool AllocTestPublisher::publish() { - if (m_listener.is_matched()) + bool ret = false; + if (is_matched()) { - m_data.index(m_data.index() + 1); - mp_publisher->write((void*)&m_data); - return true; + data_.index(data_.index() + 1); + ret = writer_->write(&data_); } - return false; + return ret; } diff --git a/test/profiling/allocations/AllocTestPublisher.h b/test/profiling/allocations/AllocTestPublisher.h deleted file mode 100644 index 577c19f0ba5..00000000000 --- a/test/profiling/allocations/AllocTestPublisher.h +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2016 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. - -/** - * @file AllocTestPublisher.h - * - */ - -#ifndef ALLOCTESTPUBLISHER_H_ -#define ALLOCTESTPUBLISHER_H_ - -#include "AllocTestTypePubSubTypes.h" - -#include -#include -#include -#include -#include -#include -#include "AllocTestType.h" - -class AllocTestPublisher { -public: - AllocTestPublisher(); - virtual ~AllocTestPublisher(); - //!Initialize - bool init(const char* profile, int domainId, const std::string& outputFile); - //!Publish a sample - bool publish(); - //!Run for number samples - void run(uint32_t number, bool wait_unmatch = false); -private: - AllocTestTypePubSubType m_type; - AllocTestType m_data; - eprosima::fastrtps::Participant* mp_participant; - eprosima::fastrtps::Publisher* mp_publisher; - std::string m_profile; - std::string m_outputFile; - class PubListener:public eprosima::fastrtps::PublisherListener - { - public: - PubListener():n_matched(0){}; - ~PubListener(){}; - void onPublicationMatched(eprosima::fastrtps::Publisher* pub, eprosima::fastrtps::rtps::MatchingInfo& info); - - bool is_matched(); - void wait_match(); - void wait_unmatch(); - - private: - int n_matched; - std::mutex mtx; - std::condition_variable cv; - }m_listener; -}; - - - -#endif /* ALLOCTESTPUBLISHER_H_ */ diff --git a/test/profiling/allocations/AllocTestPublisher.hpp b/test/profiling/allocations/AllocTestPublisher.hpp new file mode 100644 index 00000000000..14d17dfd08e --- /dev/null +++ b/test/profiling/allocations/AllocTestPublisher.hpp @@ -0,0 +1,99 @@ +// Copyright 2016 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. + +/** + * @file AllocTestPublisher.h + * + */ + +#ifndef _FASTDDS_ALLOCTESTPUBLISHER_H_ +#define _FASTDDS_ALLOCTESTPUBLISHER_H_ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "AllocTestType.h" + +class AllocTestPublisher : public eprosima::fastdds::dds::DataWriterListener +{ +public: + + AllocTestPublisher(); + + virtual ~AllocTestPublisher(); + + //! Initialize + bool init( + const char* profile, + uint32_t domain_id, + const std::string& output_file); + + //! Publish a sample + bool publish(); + + //! Run for number samples + void run( + uint32_t number, + bool wait_unmatching); + + void on_publication_matched( + eprosima::fastdds::dds::DataWriter* writer, + const eprosima::fastdds::dds::PublicationMatchedStatus& status) override; + +private: + + bool is_matched(); + + void wait_match(); + + void wait_unmatch(); + + eprosima::fastdds::dds::TypeSupport type_; + + AllocTestType data_; + + eprosima::fastdds::dds::DomainParticipant* participant_; + + eprosima::fastdds::dds::Topic* topic_; + + eprosima::fastdds::dds::Publisher* publisher_; + + eprosima::fastdds::dds::DataWriter* writer_; + + std::string profile_; + + std::string output_file_; + + std::atomic matched_; + + mutable std::mutex mtx_; + + std::condition_variable cv_; + +}; + + + +#endif /* _FASTDDS_ALLOCTESTPUBLISHER_H_ */ diff --git a/test/profiling/allocations/AllocTestSubscriber.cpp b/test/profiling/allocations/AllocTestSubscriber.cpp index e1ab3198678..9e9887e87e9 100644 --- a/test/profiling/allocations/AllocTestSubscriber.cpp +++ b/test/profiling/allocations/AllocTestSubscriber.cpp @@ -17,134 +17,166 @@ * */ -#include "AllocTestSubscriber.h" - +#include "AllocTestSubscriber.hpp" + +#include +#include +#include +#include +#include +#include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include "AllocTestCommon.h" +#include "AllocTestTypePubSubTypes.h" + +using namespace eprosima::fastdds::dds; + +#define CHECK_RETURN_CODE(ret) \ + if (ReturnCode_t::RETCODE_OK != ret) \ + { \ + return false; \ + } -using namespace eprosima::fastrtps; -using namespace eprosima::fastrtps::rtps; +#define CHECK_ENTITY_CREATION(entity) \ + if (nullptr != entity) \ + { \ + return false; \ + } AllocTestSubscriber::AllocTestSubscriber() - : mp_participant(nullptr) - , mp_subscriber(nullptr) + : type_(new AllocTestTypePubSubType()) + , participant_(nullptr) + , topic_(nullptr) + , subscriber_(nullptr) + , reader_(nullptr) + , profile_("") + , output_file_("") + , matched_(0) + , samples_(0) { } -bool AllocTestSubscriber::init( - const char* profile, - int domainId, - const std::string& outputFile) +AllocTestSubscriber::~AllocTestSubscriber() { - m_profile = profile; - m_outputFile = outputFile; - Domain::loadXMLProfilesFile("test_xml_profile.xml"); - - ParticipantAttributes participant_att; - // TODO(jlbueno): migrate to DomainParticipantFactory::get_participant_qos_from_profile - if (eprosima::fastrtps::xmlparser::XMLP_ret::XML_OK == - eprosima::fastrtps::xmlparser::XMLProfileManager::fillParticipantAttributes("test_participant_profile", - participant_att)) + if (participant_ != nullptr) { - participant_att.domainId = domainId; - mp_participant = Domain::createParticipant(participant_att); + participant_->delete_contained_entities(); + DomainParticipantFactory::get_shared_instance()->delete_participant(participant_); + participant_ = nullptr; } +} - if (mp_participant == nullptr) - { - return false; - } +bool AllocTestSubscriber::init( + const char* profile, + uint32_t domain_id, + const std::string& output_file) +{ + profile_ = profile; + output_file_ = output_file; - //REGISTER THE TYPE - Domain::registerType(mp_participant, &m_type); + ReturnCode_t ret = ReturnCode_t::RETCODE_OK; - //CREATE THE SUBSCRIBER - std::string prof("test_subscriber_profile_"); - prof.append(profile); - mp_subscriber = Domain::createSubscriber(mp_participant, prof, &m_listener); + std::shared_ptr factory = DomainParticipantFactory::get_shared_instance(); + ret = factory->load_XML_profiles_file("test_xml_profile.xml"); + CHECK_RETURN_CODE(ret); - if (mp_subscriber == nullptr) - { - return false; - } + DomainParticipantQos pqos; + ret = factory->get_participant_qos_from_profile("test_participant_profile", pqos); + CHECK_RETURN_CODE(ret); + + participant_ = factory->create_participant(domain_id, pqos); + CHECK_ENTITY_CREATION(participant_); + + ret = type_.register_type(participant_); + CHECK_RETURN_CODE(ret); + + topic_ = participant_->create_topic("AllocTestTopic", type_.get_type_name(), TOPIC_QOS_DEFAULT); + CHECK_ENTITY_CREATION(topic_); + + subscriber_ = participant_->create_subscriber(SUBSCRIBER_QOS_DEFAULT); + CHECK_ENTITY_CREATION(subscriber_); + + std::string prof = "test_subscriber_profile_" + profile_; + reader_ = subscriber_->create_datareader_with_profile(topic_, prof, this); + CHECK_ENTITY_CREATION(reader_); bool show_allocation_traces = std::getenv("FASTDDS_PROFILING_PRINT_TRACES") != nullptr; eprosima_profiling::entities_created(show_allocation_traces); - return true; + return ret == ReturnCode_t::RETCODE_OK; } -AllocTestSubscriber::~AllocTestSubscriber() +void AllocTestSubscriber::on_subscription_matched( + DataReader* /*reader*/, + const SubscriptionMatchedStatus& status) { - Domain::removeParticipant(mp_participant); -} - -void AllocTestSubscriber::SubListener::onSubscriptionMatched( - Subscriber* /*sub*/, - MatchingInfo& info) -{ - std::unique_lock lock(mtx); - if (info.status == MATCHED_MATCHING) + if (status.current_count_change == 1) { - n_matched++; + matched_++; std::cout << "Subscriber matched" << std::endl; } - else + else if (status.current_count_change == -1) { - n_matched--; + matched_--; std::cout << "Subscriber unmatched" << std::endl; } - cv.notify_all(); + else + { + std::cout << status.current_count_change + << " is not a valid value for SubscriptionMatchedStatus current count change" << std::endl; + } + cv_.notify_all(); } -void AllocTestSubscriber::SubListener::onNewDataMessage( - Subscriber* sub) +void AllocTestSubscriber::on_data_available( + DataReader* reader) { - if (sub->takeNextData((void*)&m_Hello, &m_info)) + SampleInfo info; + if (ReturnCode_t::RETCODE_OK == reader->take_next_sample(&data_, &info)) { - if (m_info.sampleKind == ALIVE) + if ((info.instance_state == ALIVE_INSTANCE_STATE) && (info.valid_data) && + (reader->is_sample_valid(&data_, &info))) { - std::unique_lock lock(mtx); - this->n_samples++; - // Print your structure data here. - std::cout << "Message " << m_Hello.index() << " RECEIVED" << std::endl; - cv.notify_all(); + samples_++; + std::cout << "Message " << data_.index() << " RECEIVED" << std::endl; + cv_.notify_all(); } } - } -void AllocTestSubscriber::SubListener::wait_match() +void AllocTestSubscriber::wait_match() { - std::unique_lock lock(mtx); - cv.wait(lock, [this]() + std::unique_lock lck(mtx_); + cv_.wait(lck, [this]() { - return n_matched > 0; + return matched_ > 0; }); } -void AllocTestSubscriber::SubListener::wait_unmatch() +void AllocTestSubscriber::wait_unmatch() { - std::unique_lock lock(mtx); - cv.wait(lock, [this]() + std::unique_lock lck(mtx_); + cv_.wait(lck, [this]() { - return n_matched <= 0; + return matched_ <= 0; }); } -void AllocTestSubscriber::SubListener::wait_until_total_received_at_least( +void AllocTestSubscriber::wait_until_total_received_at_least( uint32_t n) { - std::unique_lock lock(mtx); - cv.wait(lock, [this, n]() + std::unique_lock lock(mtx_); + cv_.wait(lock, [this, n]() { - return n_samples >= n; + return samples_ >= n; }); } @@ -156,36 +188,36 @@ void AllocTestSubscriber::run( void AllocTestSubscriber::run( uint32_t number, - bool wait_unmatch) + bool wait_unmatching) { // Restart callgrind graph eprosima_profiling::callgrind_zero_count(); std::cout << "Subscriber waiting for publisher..." << std::endl; - m_listener.wait_match(); + wait_match(); // Flush callgrind graph eprosima_profiling::callgrind_dump(); eprosima_profiling::discovery_finished(); std::cout << "Subscriber matched. Waiting for first sample..." << std::endl; - m_listener.wait_until_total_received_at_least(1ul); + wait_until_total_received_at_least(1ul); // Flush callgrind graph eprosima_profiling::callgrind_dump(); eprosima_profiling::first_sample_exchanged(); std::cout << "First sample received. Waiting for rest of samples..." << std::endl; - m_listener.wait_until_total_received_at_least(number); + wait_until_total_received_at_least(number); // Flush callgrind graph eprosima_profiling::callgrind_dump(); eprosima_profiling::all_samples_exchanged(); - if (wait_unmatch) + if (wait_unmatching) { std::cout << "All messages received. Waiting for publisher to stop." << std::endl; - m_listener.wait_unmatch(); + wait_unmatch(); } else { @@ -196,5 +228,5 @@ void AllocTestSubscriber::run( // Flush callgrind graph eprosima_profiling::callgrind_dump(); eprosima_profiling::undiscovery_finished(); - eprosima_profiling::print_results(m_outputFile, "subscriber", m_profile); + eprosima_profiling::print_results(output_file_, "subscriber", profile_); } diff --git a/test/profiling/allocations/AllocTestSubscriber.h b/test/profiling/allocations/AllocTestSubscriber.h deleted file mode 100644 index 64a53fa82c7..00000000000 --- a/test/profiling/allocations/AllocTestSubscriber.h +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright 2016 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. - -/** - * @file AllocTestSubscriber.h - * - */ - -#ifndef ALLOCTESTSUBSCRIBER_H_ -#define ALLOCTESTSUBSCRIBER_H_ - -#include "AllocTestTypePubSubTypes.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include "AllocTestType.h" - -class AllocTestSubscriber -{ -public: - - AllocTestSubscriber(); - virtual ~AllocTestSubscriber(); - //!Initialize the subscriber - bool init( - const char* profile, - int domainId, - const std::string& outputFile); - //!RUN the subscriber - void run( - bool wait_unmatch = false); - //!Run the subscriber until number samples have been received. - void run( - uint32_t number, - bool wait_unmatch = false); - -private: - - eprosima::fastrtps::Participant* mp_participant; - eprosima::fastrtps::Subscriber* mp_subscriber; - std::string m_profile; - std::string m_outputFile; - -public: - - class SubListener : public eprosima::fastrtps::SubscriberListener - { - public: - - SubListener() - : n_matched(0) - , n_samples(0) - { - } - - ~SubListener() - { - } - - void onSubscriptionMatched( - eprosima::fastrtps::Subscriber* sub, - eprosima::fastrtps::rtps::MatchingInfo& info); - void onNewDataMessage( - eprosima::fastrtps::Subscriber* sub); - - void wait_match(); - void wait_unmatch(); - void wait_until_total_received_at_least( - uint32_t n); - - private: - - AllocTestType m_Hello; - eprosima::fastrtps::SampleInfo_t m_info; - int n_matched; - uint32_t n_samples; - std::mutex mtx; - std::condition_variable cv; - } - m_listener; - -private: - - AllocTestTypePubSubType m_type; -}; - -#endif /* ALLOCTESTSUBSCRIBER_H_ */ diff --git a/test/profiling/allocations/AllocTestSubscriber.hpp b/test/profiling/allocations/AllocTestSubscriber.hpp new file mode 100644 index 00000000000..6473235d630 --- /dev/null +++ b/test/profiling/allocations/AllocTestSubscriber.hpp @@ -0,0 +1,103 @@ +// Copyright 2016 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. + +/** + * @file AllocTestSubscriber.h + * + */ + +#ifndef _FASTDDS_ALLOCTESTSUBSCRIBER_H_ +#define _FASTDDS_ALLOCTESTSUBSCRIBER_H_ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "AllocTestType.h" + +class AllocTestSubscriber : public eprosima::fastdds::dds::DataReaderListener +{ +public: + + AllocTestSubscriber(); + + virtual ~AllocTestSubscriber(); + + //! Initialize the subscriber + bool init( + const char* profile, + uint32_t domain_id, + const std::string& output_file); + + //! RUN the subscriber + void run( + bool wait_unmatch); + + void run( + uint32_t number, + bool wait_unmatching); + + void on_subscription_matched( + eprosima::fastdds::dds::DataReader* reader, + const eprosima::fastdds::dds::SubscriptionMatchedStatus& status) override; + + void on_data_available( + eprosima::fastdds::dds::DataReader* reader) override; + +private: + + void wait_match(); + + void wait_unmatch(); + + void wait_until_total_received_at_least( + uint32_t n); + + eprosima::fastdds::dds::TypeSupport type_; + + AllocTestType data_; + + eprosima::fastdds::dds::DomainParticipant* participant_; + + eprosima::fastdds::dds::Topic* topic_; + + eprosima::fastdds::dds::Subscriber* subscriber_; + + eprosima::fastdds::dds::DataReader* reader_; + + std::string profile_; + + std::string output_file_; + + std::atomic matched_; + + std::atomic samples_; + + mutable std::mutex mtx_; + + std::condition_variable cv_; + +}; + +#endif /* _FASTDDS_ALLOCTESTSUBSCRIBER_H_ */ diff --git a/test/profiling/allocations/AllocTest_main.cpp b/test/profiling/allocations/AllocTest_main.cpp index a79f259dea9..933317510d2 100644 --- a/test/profiling/allocations/AllocTest_main.cpp +++ b/test/profiling/allocations/AllocTest_main.cpp @@ -19,8 +19,8 @@ #include -#include "AllocTestPublisher.h" -#include "AllocTestSubscriber.h" +#include "AllocTestPublisher.hpp" +#include "AllocTestSubscriber.hpp" using namespace eprosima; using namespace fastrtps; diff --git a/test/profiling/allocations/CMakeLists.txt b/test/profiling/allocations/CMakeLists.txt index a4b3cb94f1a..b422176e11b 100644 --- a/test/profiling/allocations/CMakeLists.txt +++ b/test/profiling/allocations/CMakeLists.txt @@ -25,7 +25,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic -Werror) endif() -# Find requirements +# Find requirements (Version 1.4 is required, but their CMake does not set the version correctly) find_package(osrf_testing_tools_cpp) if (osrf_testing_tools_cpp_FOUND) From d07f80a483170fdae9ce09533e3849460ee3cac8 Mon Sep 17 00:00:00 2001 From: EduPonz Date: Thu, 7 Mar 2024 11:01:42 +0100 Subject: [PATCH 04/22] Refs #20567: Make ParticipantAttributes private Signed-off-by: EduPonz --- .../fastdds/dds/domain/DomainParticipant.hpp | 1 - include/fastrtps/Domain.h | 251 ------------------ include/fastrtps/participant/Participant.h | 105 -------- .../participant/ParticipantListener.h | 88 ------ .../domain/DomainParticipantFactory.cpp | 3 +- .../fastdds/domain/DomainParticipantImpl.cpp | 1 - src/cpp/xmlparser/XMLParser.cpp | 4 +- src/cpp/xmlparser/XMLParser.h | 8 +- src/cpp/xmlparser/XMLProfileManager.h | 6 +- .../attributes/ParticipantAttributes.hpp | 12 +- test/blackbox/api/dds-pim/PubSubReader.hpp | 2 +- .../dds/participant/ParticipantTests.cpp | 1 - .../xmlparser/XMLElementParserTests.cpp | 4 +- test/unittest/xmlparser/XMLParserTests.hpp | 3 +- .../xmlparser/XMLProfileParserTests.cpp | 5 +- .../xmlparser/wrapper/XMLParserTest.hpp | 1 + 16 files changed, 25 insertions(+), 470 deletions(-) delete mode 100644 include/fastrtps/Domain.h delete mode 100644 include/fastrtps/participant/Participant.h delete mode 100644 include/fastrtps/participant/ParticipantListener.h rename include/fastrtps/attributes/ParticipantAttributes.h => src/cpp/xmlparser/attributes/ParticipantAttributes.hpp (87%) diff --git a/include/fastdds/dds/domain/DomainParticipant.hpp b/include/fastdds/dds/domain/DomainParticipant.hpp index 5cca4358a0b..463ed87ef56 100644 --- a/include/fastdds/dds/domain/DomainParticipant.hpp +++ b/include/fastdds/dds/domain/DomainParticipant.hpp @@ -60,7 +60,6 @@ namespace types { class TypeInformation; } // namespace types -class ParticipantAttributes; class PublisherAttributes; class SubscriberAttributes; diff --git a/include/fastrtps/Domain.h b/include/fastrtps/Domain.h deleted file mode 100644 index 27511afe8cd..00000000000 --- a/include/fastrtps/Domain.h +++ /dev/null @@ -1,251 +0,0 @@ -// Copyright 2016 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. - -/** - * @file Domain.h - * - */ - -#ifndef DOMAIN_H_ -#define DOMAIN_H_ - -#include -#include -#include - -#ifdef USE_DEPRECATION -#if defined(__GNUC__) || defined(__clang__) -#define DEPRECATED __attribute__ ((deprecated)) -#elif defined(_MSC_VER) -#define DEPRECATED __declspec(deprecated) -#else -#define DEPRECATED /** --Deprecated-- */ -#endif // if defined(__GNUC__) || defined(__clang__) -#else -#define DEPRECATED -#endif // ifdef USE_DEPRECATION - -namespace eprosima { -namespace fastrtps { - -class ParticipantListener; -class Participant; -class ParticipantImpl; -class Publisher; -class PublisherAttributes; -class PublisherListener; -class Subscriber; -class SubscriberAttributes; -class SubscriberListener; - -namespace types { -class DynamicPubSubType; -} // namespace types - -/** - * Class Domain, use to interact with the Publisher Subscriber API of the Fast RTPS implementation. - * @ingroup FASTRTPS_MODULE - */ -class Domain -{ -public: - - /** - * Create a Participant from a profile name. - * @param participant_profile Participant profile name. - * @param listen ParticipantListener Pointer. - * @return Participant pointer. (nullptr if not created.) - */ - FASTDDS_EXPORTED_API DEPRECATED static Participant* createParticipant( - const std::string& participant_profile, - ParticipantListener* listen = nullptr); - - /** - * Create a Participant. - * @param att Participant Attributes. - * @param listen ParticipantListener Pointer. - * @return Participant pointer. (nullptr if not created.) - */ - FASTDDS_EXPORTED_API DEPRECATED static Participant* createParticipant( - const ParticipantAttributes& att, - ParticipantListener* listen = nullptr); - - //!Fills participant_attributes with the default values. - FASTDDS_EXPORTED_API static void getDefaultParticipantAttributes( - ParticipantAttributes& participant_attributes); - - /** - * Create a Publisher in a Participant from a profile name. - * @param part Pointer to the participant where you want to create the Publisher. - * @param publisher_profile Publisher profile name. - * @param listen Pointer to the PublisherListener. - * @return Pointer to the created Publisher (nullptr if not created). - */ - FASTDDS_EXPORTED_API static Publisher* createPublisher( - Participant* part, - const std::string& publisher_profile, - PublisherListener* listen = nullptr); - - /** - * Create a Publisher in a Participant. - * @param part Pointer to the participant where you want to create the Publisher. - * @param att PublisherAttributes. - * @param listen Pointer to the PublisherListener. - * @return Pointer to the created Publisher (nullptr if not created). - */ - FASTDDS_EXPORTED_API static Publisher* createPublisher( - Participant* part, - const PublisherAttributes& att, - PublisherListener* listen = nullptr); - - //!Fills publisher_attributes with the default values. - FASTDDS_EXPORTED_API static void getDefaultPublisherAttributes( - PublisherAttributes& publisher_attributes); - - /** - * Create a Subscriber in a Participant from a profile name. - * @param part Pointer to the participant where you want to create the Publisher. - * @param subscriber_profile Subscriber profile name. - * @param listen Pointer to the SubscriberListener. - * @return Pointer to the created Subscriber (nullptr if not created). - */ - FASTDDS_EXPORTED_API static Subscriber* createSubscriber( - Participant* part, - const std::string& subscriber_profile, - SubscriberListener* listen = nullptr); - - /** - * Create a Subscriber in a Participant. - * @param part Pointer to the participant where you want to create the Publisher. - * @param att SubscriberAttributes. - * @param listen Pointer to the SubscriberListener. - * @return Pointer to the created Subscriber (nullptr if not created). - */ - FASTDDS_EXPORTED_API static Subscriber* createSubscriber( - Participant* part, - const SubscriberAttributes& att, - SubscriberListener* listen = nullptr); - - //!Fills subscriber_attributes with the default values. - FASTDDS_EXPORTED_API static void getDefaultSubscriberAttributes( - SubscriberAttributes& subscriber_attributes); - - /** - * Remove a Participant and all associated publishers and subscribers. - * @param part Pointer to the participant. - * @return True if correctly removed. - */ - FASTDDS_EXPORTED_API static bool removeParticipant( - Participant* part); - - /** - * Remove a Publisher. - * @param pub Pointer to the Publisher. - * @return True if correctly removed. - */ - FASTDDS_EXPORTED_API static bool removePublisher( - Publisher* pub); - - /** - * Remove a Subscriber. - * @param sub Pointer to the Subscriber. - * @return True if correctly removed. - */ - FASTDDS_EXPORTED_API static bool removeSubscriber( - Subscriber* sub); - - /** - * Return a registered type. - * @param part Pointer to the Participant. - * @param typeName Name of the type. - * @param type Returned type. - * @return True if type was found. - */ - FASTDDS_EXPORTED_API static bool getRegisteredType( - Participant* part, - const char* typeName, - fastdds::dds::TopicDataType** type); - - /** - * Register a type in a participant. - * @param part Pointer to the Participant. - * @param type Pointer to the Type. - * @return True if correctly registered. - */ - FASTDDS_EXPORTED_API static bool registerType( - Participant* part, - fastdds::dds::TopicDataType* type); - - /** - * Register a type in a participant. - * @param part Pointer to the Participant. - * @param type Pointer to the Type. - * @return True if correctly registered. - */ - FASTDDS_EXPORTED_API static bool registerDynamicType( - Participant* part, - types::DynamicPubSubType* type); - - /** - * Unregister a type in a participant. - * @param part Pointer to the Participant. - * @param typeName Name of the type. - * @return True if correctly unregistered. - */ - FASTDDS_EXPORTED_API static bool unregisterType( - Participant* part, - const char* typeName); - - /** - * Stop and remove all participants, publishers and subscribers in this Domain. - */ - FASTDDS_EXPORTED_API static void stopAll(); - - /** - * Load profiles from XML file. - * @param xml_profile_file XML profile file. - * @return True if correctly loaded. - */ - FASTDDS_EXPORTED_API static bool loadXMLProfilesFile( - const std::string& xml_profile_file); - - /** - * Load profiles from XML string. - * @param data buffer containing XML data. - * @param length length of data. - * @return True if correctly loaded. - */ - FASTDDS_EXPORTED_API static bool loadXMLProfilesString( - const char* data, - size_t length); - -private: - - typedef std::pair t_p_Participant; - - Domain(); - - virtual ~Domain(); - - static std::mutex m_mutex; - - static std::vector m_participants; - - static bool default_xml_profiles_loaded; -}; - -} /* namespace */ -} /* namespace eprosima */ - -#endif /* DOMAIN_H_ */ diff --git a/include/fastrtps/participant/Participant.h b/include/fastrtps/participant/Participant.h deleted file mode 100644 index d79557cf6f4..00000000000 --- a/include/fastrtps/participant/Participant.h +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright 2016 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. - -/** - * @file Participant.h - * - */ - -#ifndef PARTICIPANT_H_ -#define PARTICIPANT_H_ - -#include -#include - -#include - -namespace eprosima { -namespace fastrtps { - -class ParticipantImpl; -class ParticipantAttributes; - -namespace rtps { -class WriterProxyData; -class ReaderProxyData; -class ResourceEvent; -class RTPSParticipant; -} // namespace rtps - -/** - * Class Participant used to group Publishers and Subscribers into a single working unit. - * @ingroup FASTRTPS_MODULE - */ -class FASTDDS_EXPORTED_API Participant -{ -public: - - /** - * Get the rtps::GUID_t of the associated RTPSParticipant. - * @return rtps::GUID_t - */ - const rtps::GUID_t& getGuid() const; - - /** - * Get the ParticipantAttributes. - * @return ParticipantAttributes. - */ - const ParticipantAttributes& getAttributes() const; - - /** - * Called when using a StaticEndpointDiscovery mechanism different that the one - * included in FastRTPS, for example when communicating with other implementations. - * It indicates to the Participant that an Endpoint from the XML has been discovered and - * should be activated. - * @param partguid Participant rtps::GUID_t. - * @param userId User defined ID as shown in the XML file. - * @param kind EndpointKind (WRITER or READER) - * @return True if correctly found and activated. - */ - bool newRemoteEndpointDiscovered( - const rtps::GUID_t& partguid, - uint16_t userId, - rtps::EndpointKind_t kind); - - /** - * Returns a list with the participant names. - * @return list of participant names. - */ - std::vector getParticipantNames() const; - - /** - * @brief Asserts liveliness of manual by participant publishers - */ - void assert_liveliness(); - - rtps::ResourceEvent& get_resource_event() const; - -private: - - Participant(); - - virtual ~Participant(); - - ParticipantImpl* mp_impl; - - friend class Domain; - - friend class ParticipantImpl; -}; - -} // namespace fastrtps -} /* namespace eprosima */ - -#endif /* PARTICIPANT_H_ */ diff --git a/include/fastrtps/participant/ParticipantListener.h b/include/fastrtps/participant/ParticipantListener.h deleted file mode 100644 index cde1fec1602..00000000000 --- a/include/fastrtps/participant/ParticipantListener.h +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2016 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. - -/** - * @file ParticipantListener.h - * - */ - -#ifndef __PARTICIPANT_PARTICIPANTLISTENER_H__ -#define __PARTICIPANT_PARTICIPANTLISTENER_H__ - -#include -#include -#include - -namespace eprosima { -namespace fastrtps { - -class Participant; - -/** - * Class ParticipantListener, overrides behaviour towards certain events. - * @ingroup FASTRTPS_MODULE - */ -class ParticipantListener -{ - public: - - ParticipantListener() {} - - virtual ~ParticipantListener() {} - - /*! - * This method is called when a new Participant is discovered, or a previously discovered participant changes - * its QOS or is removed. - * @param participant Pointer to the Participant which discovered the remote participant. - * @param info Remote participant information. User can take ownership of the object. - */ - virtual void onParticipantDiscovery(Participant* participant, rtps::ParticipantDiscoveryInfo&& info) - { - (void)participant, (void)info; - } - -#if HAVE_SECURITY - virtual void onParticipantAuthentication(Participant* participant, rtps::ParticipantAuthenticationInfo&& info) - { - (void)participant, (void)info; - } -#endif - - /*! - * This method is called when a new Subscriber is discovered, or a previously discovered subscriber changes - * its QOS or is removed. - * @param participant Pointer to the Participant which discovered the remote subscriber. - * @param info Remote subscriber information. User can take ownership of the object. - */ - virtual void onSubscriberDiscovery(Participant* participant, rtps::ReaderDiscoveryInfo&& info) - { - (void)participant, (void)info; - } - - /*! - * This method is called when a new Publisher is discovered, or a previously discovered publisher changes - * its QOS or is removed. - * @param participant Pointer to the Participant which discovered the remote publisher. - * @param info Remote publisher information. User can take ownership of the object. - */ - virtual void onPublisherDiscovery(Participant* participant, rtps::WriterDiscoveryInfo&& info) - { - (void)participant, (void)info; - } -}; - -} // namespace fastrtps -} // namespace eprosima - -#endif // __PARTICIPANT_PARTICIPANTLISTENER_H__ diff --git a/src/cpp/fastdds/domain/DomainParticipantFactory.cpp b/src/cpp/fastdds/domain/DomainParticipantFactory.cpp index c5a31e2aac5..de7c65fc57c 100644 --- a/src/cpp/fastdds/domain/DomainParticipantFactory.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantFactory.cpp @@ -43,7 +43,6 @@ using namespace eprosima::fastrtps::xmlparser; -using eprosima::fastrtps::ParticipantAttributes; using eprosima::fastdds::dds::Log; using eprosima::fastrtps::rtps::RTPSDomain; @@ -421,7 +420,7 @@ void DomainParticipantFactory::reset_default_participant_qos() DomainParticipantImpl::set_qos(default_participant_qos_, PARTICIPANT_QOS_DEFAULT, true); if (true == default_xml_profiles_loaded) { - eprosima::fastrtps::ParticipantAttributes attr; + ParticipantAttributes attr; XMLProfileManager::getDefaultParticipantAttributes(attr); utils::set_qos_from_attributes(default_participant_qos_, attr.rtps); } diff --git a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp index 6a500351e0f..9018be11cd2 100644 --- a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp @@ -73,7 +73,6 @@ namespace dds { using fastrtps::xmlparser::XMLProfileManager; using fastrtps::xmlparser::XMLP_ret; -using fastrtps::ParticipantAttributes; using fastrtps::TopicAttributes; using fastrtps::SubscriberAttributes; using fastrtps::PublisherAttributes; diff --git a/src/cpp/xmlparser/XMLParser.cpp b/src/cpp/xmlparser/XMLParser.cpp index 25c09cca609..527e74df4d2 100644 --- a/src/cpp/xmlparser/XMLParser.cpp +++ b/src/cpp/xmlparser/XMLParser.cpp @@ -1558,7 +1558,7 @@ XMLP_ret XMLParser::parseXMLParticipantProf( BaseNode& rootNode) { XMLP_ret ret = XMLP_ret::XML_OK; - up_participant_t participant_atts{new ParticipantAttributes}; + up_participant_t participant_atts{new fastdds::ParticipantAttributes}; up_node_participant_t participant_node{new node_participant_t{NodeType::PARTICIPANT, std::move(participant_atts)}}; if (XMLP_ret::XML_OK == fillDataNode(p_root, *participant_node)) { @@ -2189,7 +2189,7 @@ XMLP_ret XMLParser::fillDataNode( XMLP_ret XMLParser::fillDataNode( tinyxml2::XMLElement* p_profile, - DataNode& participant_node) + DataNode& participant_node) { /* diff --git a/src/cpp/xmlparser/XMLParser.h b/src/cpp/xmlparser/XMLParser.h index 44b00de01c9..c0d6444bae5 100644 --- a/src/cpp/xmlparser/XMLParser.h +++ b/src/cpp/xmlparser/XMLParser.h @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -35,6 +34,7 @@ #include #include +#include #include namespace tinyxml2 { @@ -65,8 +65,8 @@ typedef DataNode node_particip typedef node_participantfactory_t* p_node_participantfactory_t; typedef std::unique_ptr up_node_participantfactory_t; -typedef std::unique_ptr up_participant_t; -typedef DataNode node_participant_t; +typedef std::unique_ptr up_participant_t; +typedef DataNode node_participant_t; typedef node_participant_t* p_node_participant_t; typedef std::unique_ptr up_node_participant_t; @@ -330,7 +330,7 @@ class XMLParser static XMLP_ret fillDataNode( tinyxml2::XMLElement* p_profile, - DataNode& participant_node); + DataNode& participant_node); static XMLP_ret fillDataNode( tinyxml2::XMLElement* p_profile, diff --git a/src/cpp/xmlparser/XMLProfileManager.h b/src/cpp/xmlparser/XMLProfileManager.h index 353f3ade898..64eef4680a3 100644 --- a/src/cpp/xmlparser/XMLProfileManager.h +++ b/src/cpp/xmlparser/XMLProfileManager.h @@ -21,13 +21,13 @@ #include #include -#include #include #include #include #include #include +#include #include #include @@ -133,12 +133,12 @@ class XMLProfileManager */ static XMLP_ret fillParticipantAttributes( const std::string& profile_name, - ParticipantAttributes& atts, + fastdds::ParticipantAttributes& atts, bool log_error = true); //!Fills participant_attributes with the default values. static void getDefaultParticipantAttributes( - ParticipantAttributes& participant_attributes); + fastdds::ParticipantAttributes& participant_attributes); /** * Search for the profile specified and fill the structure. diff --git a/include/fastrtps/attributes/ParticipantAttributes.h b/src/cpp/xmlparser/attributes/ParticipantAttributes.hpp similarity index 87% rename from include/fastrtps/attributes/ParticipantAttributes.h rename to src/cpp/xmlparser/attributes/ParticipantAttributes.hpp index 2ba001c0860..4d46726d05c 100644 --- a/include/fastrtps/attributes/ParticipantAttributes.h +++ b/src/cpp/xmlparser/attributes/ParticipantAttributes.hpp @@ -17,13 +17,13 @@ * */ -#ifndef PARTICIPANTATTRIBUTES_H_ -#define PARTICIPANTATTRIBUTES_H_ +#ifndef _FASTDDS_PARTICIPANTATTRIBUTES_H_ +#define _FASTDDS_PARTICIPANTATTRIBUTES_H_ #include namespace eprosima { -namespace fastrtps { +namespace fastdds { /** * Class ParticipantAttributes, used by the user to define the attributes of a Participant. @@ -39,7 +39,7 @@ class ParticipantAttributes uint32_t domainId = 0; //!Attributes of the associated RTPSParticipant. - rtps::RTPSParticipantAttributes rtps; + fastrtps::rtps::RTPSParticipantAttributes rtps; ParticipantAttributes() { @@ -57,7 +57,7 @@ class ParticipantAttributes }; -} // namespace fastrtps +} // namespace fastdds } // namespace eprosima -#endif /* PARTICIPANTATTRIBUTES_H_ */ +#endif /* _FASTDDS_PARTICIPANTATTRIBUTES_H_ */ diff --git a/test/blackbox/api/dds-pim/PubSubReader.hpp b/test/blackbox/api/dds-pim/PubSubReader.hpp index 9525aa49c53..e159f55aa15 100644 --- a/test/blackbox/api/dds-pim/PubSubReader.hpp +++ b/test/blackbox/api/dds-pim/PubSubReader.hpp @@ -1471,7 +1471,7 @@ class PubSubReader if (profile->getType() == eprosima::fastrtps::xmlparser::NodeType::PARTICIPANT) { participant_attr_ = - *(dynamic_cast + *(dynamic_cast *>( profile.get())->get()); } diff --git a/test/unittest/dds/participant/ParticipantTests.cpp b/test/unittest/dds/participant/ParticipantTests.cpp index 2912c82aaa4..c7f8129b766 100644 --- a/test/unittest/dds/participant/ParticipantTests.cpp +++ b/test/unittest/dds/participant/ParticipantTests.cpp @@ -78,7 +78,6 @@ namespace eprosima { namespace fastdds { namespace dds { -using fastrtps::ParticipantAttributes; using fastrtps::PublisherAttributes; using fastrtps::SubscriberAttributes; using fastrtps::types::DynamicData_ptr; diff --git a/test/unittest/xmlparser/XMLElementParserTests.cpp b/test/unittest/xmlparser/XMLElementParserTests.cpp index f1325cd6f3d..80f0b4c1b49 100644 --- a/test/unittest/xmlparser/XMLElementParserTests.cpp +++ b/test/unittest/xmlparser/XMLElementParserTests.cpp @@ -1772,7 +1772,7 @@ TEST_F(XMLParserTests, getXMLWriterReaderUnsupportedQosPolicies) TEST_F(XMLParserTests, ParticipantAllocationAttributesDataLimits) { uint8_t ident = 1; - rtps::RTPSParticipantAllocationAttributes allocation; + eprosima::fastrtps::rtps::RTPSParticipantAllocationAttributes allocation; tinyxml2::XMLDocument xml_doc; tinyxml2::XMLElement* titleElement; @@ -1811,7 +1811,7 @@ TEST_F(XMLParserTests, ParticipantAllocationAttributesDataLimits) TEST_F(XMLParserTests, getXMLDiscoverySettingsStaticEDP) { uint8_t ident = 1; - rtps::DiscoverySettings settings; + eprosima::fastrtps::rtps::DiscoverySettings settings; tinyxml2::XMLDocument xml_doc; tinyxml2::XMLElement* titleElement; diff --git a/test/unittest/xmlparser/XMLParserTests.hpp b/test/unittest/xmlparser/XMLParserTests.hpp index 7050bcf5f31..7e3be090639 100644 --- a/test/unittest/xmlparser/XMLParserTests.hpp +++ b/test/unittest/xmlparser/XMLParserTests.hpp @@ -15,12 +15,13 @@ #include #include -#include +#include #include #include "../logging/mock/MockConsumer.h" +using namespace eprosima::fastdds; using namespace eprosima::fastrtps; using namespace eprosima::fastrtps::rtps; using namespace eprosima::fastrtps::xmlparser; diff --git a/test/unittest/xmlparser/XMLProfileParserTests.cpp b/test/unittest/xmlparser/XMLProfileParserTests.cpp index cce6ba7e003..d4abc6fee9a 100644 --- a/test/unittest/xmlparser/XMLProfileParserTests.cpp +++ b/test/unittest/xmlparser/XMLProfileParserTests.cpp @@ -41,6 +41,7 @@ #include "../common/env_var_utils.hpp" +using namespace eprosima::fastdds; using namespace eprosima::fastrtps; using namespace eprosima::fastrtps::rtps; using namespace eprosima::testing; @@ -574,9 +575,9 @@ TEST_F(XMLProfileParserBasicTests, XMLParserParticipantDeprecated) std::string participant_profile = std::string("test_participant_profile"); ParticipantAttributes participant_atts; - ASSERT_EQ( xmlparser::XMLP_ret::XML_OK, + ASSERT_EQ(xmlparser::XMLP_ret::XML_OK, xmlparser::XMLProfileManager::loadXMLFile("test_xml_deprecated.xml")); - EXPECT_EQ( xmlparser::XMLP_ret::XML_OK, + EXPECT_EQ(xmlparser::XMLP_ret::XML_OK, xmlparser::XMLProfileManager::fillParticipantAttributes(participant_profile, participant_atts)); EXPECT_EQ(participant_atts.domainId, 2019102u); diff --git a/test/unittest/xmlparser/wrapper/XMLParserTest.hpp b/test/unittest/xmlparser/wrapper/XMLParserTest.hpp index de9f2259256..14ba59964cb 100644 --- a/test/unittest/xmlparser/wrapper/XMLParserTest.hpp +++ b/test/unittest/xmlparser/wrapper/XMLParserTest.hpp @@ -19,6 +19,7 @@ #include +using namespace eprosima::fastdds; using namespace eprosima::fastrtps; using namespace eprosima::fastrtps::rtps; From 32a639729eb2ebd9822dfd32906b08bf65f50a20 Mon Sep 17 00:00:00 2001 From: EduPonz Date: Sat, 9 Mar 2024 08:00:52 +0100 Subject: [PATCH 05/22] Refs #20567: Make ReplierAttributes & RequesterAttributes private Signed-off-by: EduPonz --- .../fastdds/dds/domain/DomainParticipant.hpp | 30 +++++- include/fastdds/dds/domain/qos/ReplierQos.hpp | 80 ++++++++++++++++ .../fastdds/dds/domain/qos/RequesterQos.hpp | 80 ++++++++++++++++ resources/xsd/fastdds_profiles.xsd | 91 ++++++++++++++++--- src/cpp/fastdds/domain/DomainParticipant.cpp | 14 +++ .../fastdds/domain/DomainParticipantImpl.cpp | 64 ++++++++++--- .../fastdds/domain/DomainParticipantImpl.hpp | 31 ++++--- src/cpp/fastdds/utils/QosConverters.cpp | 26 ++++++ src/cpp/fastdds/utils/QosConverters.hpp | 27 ++++++ src/cpp/xmlparser/XMLParser.cpp | 56 ++++++------ src/cpp/xmlparser/XMLParser.h | 16 ++-- src/cpp/xmlparser/XMLProfileManager.h | 4 +- .../attributes/ReplierAttributes.hpp | 22 +++-- .../attributes/RequesterAttributes.hpp | 22 +++-- .../fastdds/domain/DomainParticipantImpl.hpp | 25 ++++- .../dds/participant/ParticipantTests.cpp | 49 +++++++++- .../dds/profiles/test_xml_profile.xml | 44 +++++++++ test/unittest/xmlparser/test_xml_profile.xml | 42 +++++++++ 18 files changed, 616 insertions(+), 107 deletions(-) create mode 100644 include/fastdds/dds/domain/qos/ReplierQos.hpp create mode 100644 include/fastdds/dds/domain/qos/RequesterQos.hpp rename {include/fastrtps => src/cpp/xmlparser}/attributes/ReplierAttributes.hpp (74%) rename {include/fastrtps => src/cpp/xmlparser}/attributes/RequesterAttributes.hpp (73%) diff --git a/include/fastdds/dds/domain/DomainParticipant.hpp b/include/fastdds/dds/domain/DomainParticipant.hpp index 463ed87ef56..0ec09be0255 100644 --- a/include/fastdds/dds/domain/DomainParticipant.hpp +++ b/include/fastdds/dds/domain/DomainParticipant.hpp @@ -27,20 +27,22 @@ #include #include -#include #include +#include #include +#include +#include #include #include -#include #include #include +#include #include #include #include #include -#include #include +#include using eprosima::fastrtps::types::ReturnCode_t; @@ -667,6 +669,28 @@ class DomainParticipant : public Entity const std::string& profile_name, TopicQos& qos) const; + /** + * Fills the ReplierQos with the values of the XML profile. + * + * @param profile_name Replier profile name. + * @param qos ReplierQos object where the qos is returned. + * @return RETCODE_OK if the profile exists. RETCODE_BAD_PARAMETER otherwise. + */ + FASTDDS_EXPORTED_API ReturnCode_t get_replier_qos_from_profile( + const std::string& profile_name, + ReplierQos& qos) const; + + /** + * Fills the RequesterQos with the values of the XML profile. + * + * @param profile_name Requester profile name. + * @param qos RequesterQos object where the qos is returned. + * @return RETCODE_OK if the profile exists. RETCODE_BAD_PARAMETER otherwise. + */ + FASTDDS_EXPORTED_API ReturnCode_t get_requester_qos_from_profile( + const std::string& profile_name, + RequesterQos& qos) const; + /** * Retrieves the list of DomainParticipants that have been discovered in the domain and are not "ignored". * diff --git a/include/fastdds/dds/domain/qos/ReplierQos.hpp b/include/fastdds/dds/domain/qos/ReplierQos.hpp new file mode 100644 index 00000000000..8a1394265ed --- /dev/null +++ b/include/fastdds/dds/domain/qos/ReplierQos.hpp @@ -0,0 +1,80 @@ +// Copyright 2024 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. + +/** + * @file ReplierQos.hpp + */ + +#ifndef _FASTDDS_REPLIERQOS_HPP_ +#define _FASTDDS_REPLIERQOS_HPP_ + +#include + +#include +#include +#include + +namespace eprosima { +namespace fastdds { +namespace dds { + +class FASTDDS_EXPORTED_API ReplierQos +{ +public: + + /** + * @brief Constructor + */ + ReplierQos() = default; + + /** + * @brief Equal comparison operator + */ + bool operator ==( + const ReplierQos& b) const + { + return (this->service_name == b.service_name) && + (this->request_topic_name == b.request_topic_name) && + (this->reply_topic_name == b.reply_topic_name) && + (this->writer_qos == b.writer_qos) && + (this->reader_qos == b.reader_qos); + } + + //! Service name + std::string service_name; + + //! Request type + std::string request_type; + + //! Reply type + std::string reply_type; + + //! Request topic name + std::string request_topic_name; + + //! Reply topic name + std::string reply_topic_name; + + //! DataWriter QoS for the reply writer + DataWriterQos writer_qos; + + //! DataReader QoS for the reply reader + DataReaderQos reader_qos; +}; + +} /* namespace dds */ +} /* namespace fastdds */ +} /* namespace eprosima */ + +#endif /* _FASTDDS_REPLIERQOS_HPP_ */ diff --git a/include/fastdds/dds/domain/qos/RequesterQos.hpp b/include/fastdds/dds/domain/qos/RequesterQos.hpp new file mode 100644 index 00000000000..2fd7d64b676 --- /dev/null +++ b/include/fastdds/dds/domain/qos/RequesterQos.hpp @@ -0,0 +1,80 @@ +// Copyright 2024 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. + +/** + * @file RequesterQos.hpp + */ + +#ifndef _FASTDDS_REQUESTERQOS_HPP_ +#define _FASTDDS_REQUESTERQOS_HPP_ + +#include + +#include +#include +#include + +namespace eprosima { +namespace fastdds { +namespace dds { + +class FASTDDS_EXPORTED_API RequesterQos +{ +public: + + /** + * @brief Constructor + */ + RequesterQos() = default; + + /** + * @brief Equal comparison operator + */ + bool operator ==( + const RequesterQos& b) const + { + return (this->service_name == b.service_name) && + (this->request_topic_name == b.request_topic_name) && + (this->reply_topic_name == b.reply_topic_name) && + (this->writer_qos == b.writer_qos) && + (this->reader_qos == b.reader_qos); + } + + //! Service name + std::string service_name; + + //! Request type + std::string request_type; + + //! Reply type + std::string reply_type; + + //! Request topic name + std::string request_topic_name; + + //! Reply topic name + std::string reply_topic_name; + + //! DataWriter QoS for the request writer + DataWriterQos writer_qos; + + //! DataReader QoS for the request reader + DataReaderQos reader_qos; +}; + +} /* namespace dds */ +} /* namespace fastdds */ +} /* namespace eprosima */ + +#endif /* _FASTDDS_REQUESTERQOS_HPP_ */ diff --git a/resources/xsd/fastdds_profiles.xsd b/resources/xsd/fastdds_profiles.xsd index 854a42da1de..b8a526287a1 100644 --- a/resources/xsd/fastdds_profiles.xsd +++ b/resources/xsd/fastdds_profiles.xsd @@ -50,6 +50,8 @@ + + @@ -211,10 +213,7 @@ - - + @@ -242,14 +241,34 @@ - - - + + + + + + + + + + - + @@ -279,8 +298,32 @@ - - + + + + + + + + + + + + + + + + + + + + + + + ├ topic [0~1], + ├ replier [0~1], + └ requester [0~*] --> From 425929866c2c47d7fc6b571661cdf14a4a7c0559 Mon Sep 17 00:00:00 2001 From: EduPonz Date: Tue, 26 Mar 2024 16:02:07 +0100 Subject: [PATCH 22/22] Refs #20567: Correctly export API in Windows for ReplierQos and RequesterQos Signed-off-by: EduPonz --- include/fastdds/dds/domain/qos/ReplierQos.hpp | 6 +++--- include/fastdds/dds/domain/qos/RequesterQos.hpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/fastdds/dds/domain/qos/ReplierQos.hpp b/include/fastdds/dds/domain/qos/ReplierQos.hpp index 8a1394265ed..3b992a202b3 100644 --- a/include/fastdds/dds/domain/qos/ReplierQos.hpp +++ b/include/fastdds/dds/domain/qos/ReplierQos.hpp @@ -29,19 +29,19 @@ namespace eprosima { namespace fastdds { namespace dds { -class FASTDDS_EXPORTED_API ReplierQos +class ReplierQos { public: /** * @brief Constructor */ - ReplierQos() = default; + FASTDDS_EXPORTED_API ReplierQos() = default; /** * @brief Equal comparison operator */ - bool operator ==( + FASTDDS_EXPORTED_API bool operator ==( const ReplierQos& b) const { return (this->service_name == b.service_name) && diff --git a/include/fastdds/dds/domain/qos/RequesterQos.hpp b/include/fastdds/dds/domain/qos/RequesterQos.hpp index 2fd7d64b676..fb31447c4bc 100644 --- a/include/fastdds/dds/domain/qos/RequesterQos.hpp +++ b/include/fastdds/dds/domain/qos/RequesterQos.hpp @@ -29,19 +29,19 @@ namespace eprosima { namespace fastdds { namespace dds { -class FASTDDS_EXPORTED_API RequesterQos +class RequesterQos { public: /** * @brief Constructor */ - RequesterQos() = default; + FASTDDS_EXPORTED_API RequesterQos() = default; /** * @brief Equal comparison operator */ - bool operator ==( + FASTDDS_EXPORTED_API bool operator ==( const RequesterQos& b) const { return (this->service_name == b.service_name) &&