From 7ccc7a7d47fef5719004340cb478816632381685 Mon Sep 17 00:00:00 2001 From: MRicoIE2C <43696963+MRicoIE2C@users.noreply.github.com> Date: Fri, 2 Sep 2022 08:10:14 +0200 Subject: [PATCH] Group set_qos_from_attributes free functions into a separate file (#2914) * Refs #15417: New QosConverters.hpp and .cpp in src/cpp/fastdds/utils folder. Signed-off-by: Mikel Rico * Refs 15417: set_qos_from_attributes imported from PublisherImpl. Signed-off-by: Mikel Rico * Refs 15417: set_qos_from_attributes commented in PublisherImpl, and #included. src/cpp/CMakeLists.txt modified to compile new source. Signed-off-by: Mikel Rico * Refs #15417: Some CMakeLists.txt from test/ modified to compile new source. Signed-off-by: Mikel Rico * Refs #15417: Commented function erased, and not-used using and #include erased. Signed-off-by: Mikel Rico * Refs #15417: set_qos_from_attributes imported from DomainParticipantFactory. Signed-off-by: Mikel Rico * Refs #15417: set_qos_from_attributes function in DomainParticipantFactory erased, and not-used #include erased.. Signed-off-by: Mikel Rico * Refs #15417: set_qos_from_attributes and set_attributes_from_qos imported from DomainParticipantImpl. Signed-off-by: Mikel Rico * Refs #15417: set_qos_from_attributes and set_attributes_from_qos functions in DomainParticipantImpl erased. Signed-off-by: Mikel Rico * Refs #15417: set_qos_from_attributes imported from SubscriberImpl. Signed-off-by: Mikel Rico * Refs #15417: set_qos_from_attributes function in SubscriberImpl erased. Signed-off-by: Mikel Rico * Refs #15417: Moved the new functions of QosConverters to namespace ::utils:: Signed-off-by: Mikel Rico * Refs #15417: Calling set_qos_from_attributes and set_attributes_from_qos pointing to ::utils:: namespace. Signed-off-by: Mikel Rico * Refs #15417: Documentation of the free functions. Signed-off-by: Mikel Rico * Refs #15417: Year change. Signed-off-by: Mikel Rico * Refs #15417: Move description to header file. Signed-off-by: Mikel Rico * Refs #15417: Blanc lines and guard condition. Signed-off-by: Mikel Rico * Refs #15417: Blanc lines and reference to each specific QoS and Attributes used on each method. Signed-off-by: Mikel Rico * Refs #15417: #includes. Signed-off-by: Mikel Rico * Refs #15417: using std::string. Signed-off-by: Mikel Rico * Refs #15417: uncrustify. Signed-off-by: Mikel Rico * Refs #15417: #includes order. Signed-off-by: Mikel Rico * Refs #15417: Doxygen comments. Signed-off-by: Mikel Rico * Refs #15417: Doxygen comments. Signed-off-by: Mikel Rico * Refs #15417: Got your blank line. Signed-off-by: Mikel Rico Signed-off-by: Mikel Rico --- src/cpp/CMakeLists.txt | 1 + .../domain/DomainParticipantFactory.cpp | 60 +---- .../fastdds/domain/DomainParticipantImpl.cpp | 77 ++---- src/cpp/fastdds/publisher/PublisherImpl.cpp | 63 +---- src/cpp/fastdds/subscriber/SubscriberImpl.cpp | 59 +---- src/cpp/fastdds/utils/QosConverters.cpp | 222 ++++++++++++++++++ src/cpp/fastdds/utils/QosConverters.hpp | 123 ++++++++++ test/unittest/dds/publisher/CMakeLists.txt | 1 + test/unittest/dds/status/CMakeLists.txt | 1 + test/unittest/statistics/dds/CMakeLists.txt | 1 + 10 files changed, 380 insertions(+), 228 deletions(-) create mode 100644 src/cpp/fastdds/utils/QosConverters.cpp create mode 100644 src/cpp/fastdds/utils/QosConverters.hpp diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt index 163358f6375..509e27c7964 100644 --- a/src/cpp/CMakeLists.txt +++ b/src/cpp/CMakeLists.txt @@ -176,6 +176,7 @@ set(${PROJECT_NAME}_source_files fastdds/core/policy/QosPolicyUtils.cpp fastdds/publisher/qos/WriterQos.cpp fastdds/subscriber/qos/ReaderQos.cpp + fastdds/utils/QosConverters.cpp rtps/builtin/BuiltinProtocols.cpp rtps/builtin/discovery/participant/DirectMessageSender.cpp rtps/builtin/discovery/participant/PDP.cpp diff --git a/src/cpp/fastdds/domain/DomainParticipantFactory.cpp b/src/cpp/fastdds/domain/DomainParticipantFactory.cpp index 3574021d356..69833f80ded 100644 --- a/src/cpp/fastdds/domain/DomainParticipantFactory.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantFactory.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -49,57 +50,6 @@ namespace eprosima { namespace fastdds { namespace dds { -/** - * @brief Fill DomainParticipantQos from a given attributes RTPSParticipantAttributes object - * - * For the case of the non-binary properties, instead of the RTPSParticipantAttributes overriding the - * property list in the DomainParticipantQos, a merge is performed in the following manner: - * - * - If any property from the RTPSParticipantAttributes is not in the DomainParticipantQos, then it is appended - * to the DomainParticipantQos. - * - If any property from the RTPSParticipantAttributes property is also in the DomainParticipantQos, then the - * value in the DomainParticipantQos is overridden with that of the RTPSParticipantAttributes. - * - * @param[in, out] qos The DomainParticipantQos to set - * @param[in] attr The RTPSParticipantAttributes from which the @c qos is set. - */ -static void set_qos_from_attributes( - DomainParticipantQos& qos, - const eprosima::fastrtps::rtps::RTPSParticipantAttributes& attr) -{ - qos.user_data().setValue(attr.userData); - qos.allocation() = attr.allocation; - qos.wire_protocol().prefix = attr.prefix; - qos.wire_protocol().participant_id = attr.participantID; - qos.wire_protocol().builtin = attr.builtin; - qos.wire_protocol().port = attr.port; - qos.wire_protocol().throughput_controller = attr.throughputController; - qos.wire_protocol().default_unicast_locator_list = attr.defaultUnicastLocatorList; - qos.wire_protocol().default_multicast_locator_list = attr.defaultMulticastLocatorList; - qos.transport().user_transports = attr.userTransports; - qos.transport().use_builtin_transports = attr.useBuiltinTransports; - qos.transport().send_socket_buffer_size = attr.sendSocketBufferSize; - qos.transport().listen_socket_buffer_size = attr.listenSocketBufferSize; - qos.name() = attr.getName(); - qos.flow_controllers() = attr.flow_controllers; - - // Merge attributes and qos properties - for (auto property : attr.properties.properties()) - { - std::string* property_value = fastrtps::rtps::PropertyPolicyHelper::find_property( - qos.properties(), property.name()); - if (nullptr == property_value) - { - qos.properties().properties().emplace_back(property); - } - else - { - *property_value = property.value(); - } - } - qos.properties().binary_properties() = attr.properties.binary_properties(); -} - DomainParticipantFactory::DomainParticipantFactory() : default_xml_profiles_loaded(false) , default_participant_qos_(PARTICIPANT_QOS_DEFAULT) @@ -270,7 +220,7 @@ DomainParticipant* DomainParticipantFactory::create_participant_with_profile( if (XMLP_ret::XML_OK == XMLProfileManager::fillParticipantAttributes(profile_name, attr)) { DomainParticipantQos qos = default_participant_qos_; - set_qos_from_attributes(qos, attr.rtps); + utils::set_qos_from_attributes(qos, attr.rtps); return create_participant(did, qos, listen, mask); } @@ -289,7 +239,7 @@ DomainParticipant* DomainParticipantFactory::create_participant_with_profile( if (XMLP_ret::XML_OK == XMLProfileManager::fillParticipantAttributes(profile_name, attr)) { DomainParticipantQos qos = default_participant_qos_; - set_qos_from_attributes(qos, attr.rtps); + utils::set_qos_from_attributes(qos, attr.rtps); return create_participant(attr.domainId, qos, listen, mask); } @@ -367,7 +317,7 @@ ReturnCode_t DomainParticipantFactory::get_participant_qos_from_profile( if (XMLP_ret::XML_OK == XMLProfileManager::fillParticipantAttributes(profile_name, attr)) { qos = default_participant_qos_; - set_qos_from_attributes(qos, attr.rtps); + utils::set_qos_from_attributes(qos, attr.rtps); return ReturnCode_t::RETCODE_OK; } @@ -459,7 +409,7 @@ void DomainParticipantFactory::reset_default_participant_qos() { eprosima::fastrtps::ParticipantAttributes attr; XMLProfileManager::getDefaultParticipantAttributes(attr); - set_qos_from_attributes(default_participant_qos_, attr.rtps); + 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 c72fdcc72ef..7d0e9b2cbee 100644 --- a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp @@ -60,6 +60,7 @@ #include #include #include +#include #include #include @@ -88,54 +89,6 @@ using fastrtps::rtps::EndpointKind_t; using fastrtps::rtps::ResourceEvent; using eprosima::fastdds::dds::Log; -static void set_attributes_from_qos( - fastrtps::rtps::RTPSParticipantAttributes& attr, - const DomainParticipantQos& qos) -{ - attr.allocation = qos.allocation(); - attr.properties = qos.properties(); - attr.setName(qos.name()); - attr.prefix = qos.wire_protocol().prefix; - attr.participantID = qos.wire_protocol().participant_id; - attr.builtin = qos.wire_protocol().builtin; - attr.port = qos.wire_protocol().port; - attr.throughputController = qos.wire_protocol().throughput_controller; - attr.defaultUnicastLocatorList = qos.wire_protocol().default_unicast_locator_list; - attr.defaultMulticastLocatorList = qos.wire_protocol().default_multicast_locator_list; - attr.userTransports = qos.transport().user_transports; - attr.useBuiltinTransports = qos.transport().use_builtin_transports; - attr.sendSocketBufferSize = qos.transport().send_socket_buffer_size; - attr.listenSocketBufferSize = qos.transport().listen_socket_buffer_size; - attr.userData = qos.user_data().data_vec(); - attr.flow_controllers = qos.flow_controllers(); -} - -static void set_qos_from_attributes( - TopicQos& qos, - const TopicAttributes& attr) -{ - qos.history() = attr.historyQos; - qos.resource_limits() = attr.resourceLimitsQos; -} - -static void set_qos_from_attributes( - SubscriberQos& qos, - const SubscriberAttributes& attr) -{ - qos.group_data().setValue(attr.qos.m_groupData); - qos.partition() = attr.qos.m_partition; - qos.presentation() = attr.qos.m_presentation; -} - -static void set_qos_from_attributes( - PublisherQos& qos, - const PublisherAttributes& attr) -{ - qos.group_data().setValue(attr.qos.m_groupData); - qos.partition() = attr.qos.m_partition; - qos.presentation() = attr.qos.m_presentation; -} - DomainParticipantImpl::DomainParticipantImpl( DomainParticipant* dp, DomainId_t did, @@ -157,15 +110,15 @@ DomainParticipantImpl::DomainParticipantImpl( PublisherAttributes pub_attr; XMLProfileManager::getDefaultPublisherAttributes(pub_attr); - set_qos_from_attributes(default_pub_qos_, pub_attr); + utils::set_qos_from_attributes(default_pub_qos_, pub_attr); SubscriberAttributes sub_attr; XMLProfileManager::getDefaultSubscriberAttributes(sub_attr); - set_qos_from_attributes(default_sub_qos_, sub_attr); + utils::set_qos_from_attributes(default_sub_qos_, sub_attr); TopicAttributes top_attr; XMLProfileManager::getDefaultTopicAttributes(top_attr); - set_qos_from_attributes(default_topic_qos_, top_attr); + utils::set_qos_from_attributes(default_topic_qos_, top_attr); // Pre calculate participant id and generated guid participant_id_ = qos_.wire_protocol().participant_id; @@ -295,7 +248,7 @@ ReturnCode_t DomainParticipantImpl::enable() assert(get_rtps_participant() == nullptr); fastrtps::rtps::RTPSParticipantAttributes rtps_attr; - set_attributes_from_qos(rtps_attr, qos_); + utils::set_attributes_from_qos(rtps_attr, qos_); rtps_attr.participantID = participant_id_; // If DEFAULT_ROS2_MASTER_URI is specified then try to create default client if @@ -406,7 +359,7 @@ ReturnCode_t DomainParticipantImpl::set_qos( if (qos_should_be_updated) { // Notify the participant that there is a QoS update - set_attributes_from_qos(patt, qos_); + utils::set_attributes_from_qos(patt, qos_); } else { @@ -847,7 +800,7 @@ Publisher* DomainParticipantImpl::create_publisher_with_profile( if (XMLP_ret::XML_OK == XMLProfileManager::fillPublisherAttributes(profile_name, attr)) { PublisherQos qos = default_pub_qos_; - set_qos_from_attributes(qos, attr); + utils::set_qos_from_attributes(qos, attr); return create_publisher(qos, listener, mask); } @@ -1043,7 +996,7 @@ void DomainParticipantImpl::reset_default_publisher_qos() PublisherImpl::set_qos(default_pub_qos_, PUBLISHER_QOS_DEFAULT, true); PublisherAttributes attr; XMLProfileManager::getDefaultPublisherAttributes(attr); - set_qos_from_attributes(default_pub_qos_, attr); + utils::set_qos_from_attributes(default_pub_qos_, attr); } const PublisherQos& DomainParticipantImpl::get_default_publisher_qos() const @@ -1059,7 +1012,7 @@ const ReturnCode_t DomainParticipantImpl::get_publisher_qos_from_profile( if (XMLP_ret::XML_OK == XMLProfileManager::fillPublisherAttributes(profile_name, attr)) { qos = default_pub_qos_; - set_qos_from_attributes(qos, attr); + utils::set_qos_from_attributes(qos, attr); return ReturnCode_t::RETCODE_OK; } @@ -1091,7 +1044,7 @@ void DomainParticipantImpl::reset_default_subscriber_qos() SubscriberImpl::set_qos(default_sub_qos_, SUBSCRIBER_QOS_DEFAULT, true); SubscriberAttributes attr; XMLProfileManager::getDefaultSubscriberAttributes(attr); - set_qos_from_attributes(default_sub_qos_, attr); + utils::set_qos_from_attributes(default_sub_qos_, attr); } const SubscriberQos& DomainParticipantImpl::get_default_subscriber_qos() const @@ -1107,7 +1060,7 @@ const ReturnCode_t DomainParticipantImpl::get_subscriber_qos_from_profile( if (XMLP_ret::XML_OK == XMLProfileManager::fillSubscriberAttributes(profile_name, attr)) { qos = default_sub_qos_; - set_qos_from_attributes(qos, attr); + utils::set_qos_from_attributes(qos, attr); return ReturnCode_t::RETCODE_OK; } @@ -1139,7 +1092,7 @@ void DomainParticipantImpl::reset_default_topic_qos() TopicImpl::set_qos(default_topic_qos_, TOPIC_QOS_DEFAULT, true); TopicAttributes attr; XMLProfileManager::getDefaultTopicAttributes(attr); - set_qos_from_attributes(default_topic_qos_, attr); + utils::set_qos_from_attributes(default_topic_qos_, attr); } const TopicQos& DomainParticipantImpl::get_default_topic_qos() const @@ -1155,7 +1108,7 @@ const ReturnCode_t DomainParticipantImpl::get_topic_qos_from_profile( if (XMLP_ret::XML_OK == XMLProfileManager::fillTopicAttributes(profile_name, attr)) { qos = default_topic_qos_; - set_qos_from_attributes(qos, attr); + utils::set_qos_from_attributes(qos, attr); return ReturnCode_t::RETCODE_OK; } @@ -1320,7 +1273,7 @@ Subscriber* DomainParticipantImpl::create_subscriber_with_profile( if (XMLP_ret::XML_OK == XMLProfileManager::fillSubscriberAttributes(profile_name, attr)) { SubscriberQos qos = default_sub_qos_; - set_qos_from_attributes(qos, attr); + utils::set_qos_from_attributes(qos, attr); return create_subscriber(qos, listener, mask); } @@ -1404,7 +1357,7 @@ Topic* DomainParticipantImpl::create_topic_with_profile( if (XMLP_ret::XML_OK == XMLProfileManager::fillTopicAttributes(profile_name, attr)) { TopicQos qos = default_topic_qos_; - set_qos_from_attributes(qos, attr); + utils::set_qos_from_attributes(qos, attr); return create_topic(topic_name, type_name, qos, listener, mask); } diff --git a/src/cpp/fastdds/publisher/PublisherImpl.cpp b/src/cpp/fastdds/publisher/PublisherImpl.cpp index b2ed69058b6..79c82c2f0d4 100644 --- a/src/cpp/fastdds/publisher/PublisherImpl.cpp +++ b/src/cpp/fastdds/publisher/PublisherImpl.cpp @@ -22,6 +22,8 @@ #include #include +#include + #include #include #include @@ -29,7 +31,6 @@ #include #include -#include #include #include @@ -46,61 +47,9 @@ namespace dds { using fastrtps::xmlparser::XMLProfileManager; using fastrtps::xmlparser::XMLP_ret; using fastrtps::rtps::InstanceHandle_t; -using fastrtps::rtps::Property; using fastrtps::Duration_t; using fastrtps::PublisherAttributes; -static void set_qos_from_attributes( - DataWriterQos& qos, - const PublisherAttributes& attr) -{ - qos.writer_resource_limits().matched_subscriber_allocation = attr.matched_subscriber_allocation; - qos.properties() = attr.properties; - qos.throughput_controller() = attr.throughputController; - qos.endpoint().unicast_locator_list = attr.unicastLocatorList; - qos.endpoint().multicast_locator_list = attr.multicastLocatorList; - qos.endpoint().remote_locator_list = attr.remoteLocatorList; - qos.endpoint().history_memory_policy = attr.historyMemoryPolicy; - qos.endpoint().user_defined_id = attr.getUserDefinedID(); - qos.endpoint().entity_id = attr.getEntityID(); - qos.reliable_writer_qos().times = attr.times; - qos.reliable_writer_qos().disable_positive_acks = attr.qos.m_disablePositiveACKs; - qos.durability() = attr.qos.m_durability; - qos.durability_service() = attr.qos.m_durabilityService; - qos.deadline() = attr.qos.m_deadline; - qos.latency_budget() = attr.qos.m_latencyBudget; - qos.liveliness() = attr.qos.m_liveliness; - qos.reliability() = attr.qos.m_reliability; - qos.lifespan() = attr.qos.m_lifespan; - qos.user_data().setValue(attr.qos.m_userData); - qos.ownership() = attr.qos.m_ownership; - qos.ownership_strength() = attr.qos.m_ownershipStrength; - qos.destination_order() = attr.qos.m_destinationOrder; - qos.representation() = attr.qos.representation; - qos.publish_mode() = attr.qos.m_publishMode; - qos.history() = attr.topic.historyQos; - qos.resource_limits() = attr.topic.resourceLimitsQos; - qos.data_sharing() = attr.qos.data_sharing; - qos.reliable_writer_qos().disable_heartbeat_piggyback = attr.qos.disable_heartbeat_piggyback; - - if (attr.qos.m_partition.size() > 0 ) - { - Property property; - property.name("partitions"); - std::string partitions; - bool is_first_partition = true; - - for (auto partition : attr.qos.m_partition.names()) - { - partitions += (is_first_partition ? "" : ";") + partition; - is_first_partition = false; - } - - property.value(std::move(partitions)); - qos.properties().properties().push_back(std::move(property)); - } -} - PublisherImpl::PublisherImpl( DomainParticipantImpl* p, const PublisherQos& qos, @@ -115,7 +64,7 @@ PublisherImpl::PublisherImpl( { PublisherAttributes pub_attr; XMLProfileManager::getDefaultPublisherAttributes(pub_attr); - set_qos_from_attributes(default_datawriter_qos_, pub_attr); + utils::set_qos_from_attributes(default_datawriter_qos_, pub_attr); } ReturnCode_t PublisherImpl::enable() @@ -327,7 +276,7 @@ DataWriter* PublisherImpl::create_datawriter_with_profile( if (XMLP_ret::XML_OK == XMLProfileManager::fillPublisherAttributes(profile_name, attr)) { DataWriterQos qos = default_datawriter_qos_; - set_qos_from_attributes(qos, attr); + utils::set_qos_from_attributes(qos, attr); return create_datawriter(topic, qos, listener, mask); } @@ -482,7 +431,7 @@ void PublisherImpl::reset_default_datawriter_qos() DataWriterImpl::set_qos(default_datawriter_qos_, DATAWRITER_QOS_DEFAULT, true); PublisherAttributes attr; XMLProfileManager::getDefaultPublisherAttributes(attr); - set_qos_from_attributes(default_datawriter_qos_, attr); + utils::set_qos_from_attributes(default_datawriter_qos_, attr); } const DataWriterQos& PublisherImpl::get_default_datawriter_qos() const @@ -498,7 +447,7 @@ const ReturnCode_t PublisherImpl::get_datawriter_qos_from_profile( if (XMLP_ret::XML_OK == XMLProfileManager::fillPublisherAttributes(profile_name, attr, false)) { qos = default_datawriter_qos_; - set_qos_from_attributes(qos, attr); + utils::set_qos_from_attributes(qos, attr); return ReturnCode_t::RETCODE_OK; } diff --git a/src/cpp/fastdds/subscriber/SubscriberImpl.cpp b/src/cpp/fastdds/subscriber/SubscriberImpl.cpp index 666b510bb52..9c8abe70f9f 100644 --- a/src/cpp/fastdds/subscriber/SubscriberImpl.cpp +++ b/src/cpp/fastdds/subscriber/SubscriberImpl.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -49,56 +50,6 @@ using fastrtps::rtps::Property; using fastrtps::Duration_t; using fastrtps::SubscriberAttributes; -static void set_qos_from_attributes( - DataReaderQos& qos, - const SubscriberAttributes& attr) -{ - qos.reader_resource_limits().matched_publisher_allocation = attr.matched_publisher_allocation; - qos.properties() = attr.properties; - qos.expects_inline_qos(attr.expectsInlineQos); - qos.endpoint().unicast_locator_list = attr.unicastLocatorList; - qos.endpoint().multicast_locator_list = attr.multicastLocatorList; - qos.endpoint().remote_locator_list = attr.remoteLocatorList; - qos.endpoint().history_memory_policy = attr.historyMemoryPolicy; - qos.endpoint().user_defined_id = attr.getUserDefinedID(); - qos.endpoint().entity_id = attr.getEntityID(); - qos.reliable_reader_qos().times = attr.times; - qos.reliable_reader_qos().disable_positive_ACKs = attr.qos.m_disablePositiveACKs; - qos.durability() = attr.qos.m_durability; - qos.durability_service() = attr.qos.m_durabilityService; - qos.deadline() = attr.qos.m_deadline; - qos.latency_budget() = attr.qos.m_latencyBudget; - qos.liveliness() = attr.qos.m_liveliness; - qos.reliability() = attr.qos.m_reliability; - qos.lifespan() = attr.qos.m_lifespan; - qos.user_data().setValue(attr.qos.m_userData); - qos.ownership() = attr.qos.m_ownership; - qos.destination_order() = attr.qos.m_destinationOrder; - qos.type_consistency().type_consistency = attr.qos.type_consistency; - qos.type_consistency().representation = attr.qos.representation; - qos.time_based_filter() = attr.qos.m_timeBasedFilter; - qos.history() = attr.topic.historyQos; - qos.resource_limits() = attr.topic.resourceLimitsQos; - qos.data_sharing() = attr.qos.data_sharing; - - if (attr.qos.m_partition.size() > 0 ) - { - Property property; - property.name("partitions"); - std::string partitions; - bool is_first_partition = true; - - for (auto partition : attr.qos.m_partition.names()) - { - partitions += (is_first_partition ? "" : ";") + partition; - is_first_partition = false; - } - - property.value(std::move(partitions)); - qos.properties().properties().push_back(std::move(property)); - } -} - SubscriberImpl::SubscriberImpl( DomainParticipantImpl* p, const SubscriberQos& qos, @@ -113,7 +64,7 @@ SubscriberImpl::SubscriberImpl( { SubscriberAttributes sub_attr; XMLProfileManager::getDefaultSubscriberAttributes(sub_attr); - set_qos_from_attributes(default_datareader_qos_, sub_attr); + utils::set_qos_from_attributes(default_datareader_qos_, sub_attr); } ReturnCode_t SubscriberImpl::enable() @@ -286,7 +237,7 @@ DataReader* SubscriberImpl::create_datareader_with_profile( if (XMLP_ret::XML_OK == XMLProfileManager::fillSubscriberAttributes(profile_name, attr)) { DataReaderQos qos = default_datareader_qos_; - set_qos_from_attributes(qos, attr); + utils::set_qos_from_attributes(qos, attr); return create_datareader(topic, qos, listener, mask); } @@ -418,7 +369,7 @@ void SubscriberImpl::reset_default_datareader_qos() DataReaderImpl::set_qos(default_datareader_qos_, DATAREADER_QOS_DEFAULT, true); SubscriberAttributes attr; XMLProfileManager::getDefaultSubscriberAttributes(attr); - set_qos_from_attributes(default_datareader_qos_, attr); + utils::set_qos_from_attributes(default_datareader_qos_, attr); } const DataReaderQos& SubscriberImpl::get_default_datareader_qos() const @@ -457,7 +408,7 @@ const ReturnCode_t SubscriberImpl::get_datareader_qos_from_profile( if (XMLP_ret::XML_OK == XMLProfileManager::fillSubscriberAttributes(profile_name, attr, false)) { qos = default_datareader_qos_; - set_qos_from_attributes(qos, attr); + utils::set_qos_from_attributes(qos, attr); return ReturnCode_t::RETCODE_OK; } diff --git a/src/cpp/fastdds/utils/QosConverters.cpp b/src/cpp/fastdds/utils/QosConverters.cpp new file mode 100644 index 00000000000..df6b3c7035f --- /dev/null +++ b/src/cpp/fastdds/utils/QosConverters.cpp @@ -0,0 +1,222 @@ +// 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. + +/* + * QosConverters.cpp + * + */ + +#include + +#include +#include + +namespace eprosima { +namespace fastdds { +namespace dds { +namespace utils { + +using fastrtps::rtps::Property; +using std::string; + +void set_qos_from_attributes( + DataWriterQos& qos, + const PublisherAttributes& attr) +{ + qos.writer_resource_limits().matched_subscriber_allocation = attr.matched_subscriber_allocation; + qos.properties() = attr.properties; + qos.throughput_controller() = attr.throughputController; + qos.endpoint().unicast_locator_list = attr.unicastLocatorList; + qos.endpoint().multicast_locator_list = attr.multicastLocatorList; + qos.endpoint().remote_locator_list = attr.remoteLocatorList; + qos.endpoint().history_memory_policy = attr.historyMemoryPolicy; + qos.endpoint().user_defined_id = attr.getUserDefinedID(); + qos.endpoint().entity_id = attr.getEntityID(); + qos.reliable_writer_qos().times = attr.times; + qos.reliable_writer_qos().disable_positive_acks = attr.qos.m_disablePositiveACKs; + qos.durability() = attr.qos.m_durability; + qos.durability_service() = attr.qos.m_durabilityService; + qos.deadline() = attr.qos.m_deadline; + qos.latency_budget() = attr.qos.m_latencyBudget; + qos.liveliness() = attr.qos.m_liveliness; + qos.reliability() = attr.qos.m_reliability; + qos.lifespan() = attr.qos.m_lifespan; + qos.user_data().setValue(attr.qos.m_userData); + qos.ownership() = attr.qos.m_ownership; + qos.ownership_strength() = attr.qos.m_ownershipStrength; + qos.destination_order() = attr.qos.m_destinationOrder; + qos.representation() = attr.qos.representation; + qos.publish_mode() = attr.qos.m_publishMode; + qos.history() = attr.topic.historyQos; + qos.resource_limits() = attr.topic.resourceLimitsQos; + qos.data_sharing() = attr.qos.data_sharing; + qos.reliable_writer_qos().disable_heartbeat_piggyback = attr.qos.disable_heartbeat_piggyback; + + if (attr.qos.m_partition.size() > 0 ) + { + Property property; + property.name("partitions"); + string partitions; + bool is_first_partition = true; + + for (auto partition : attr.qos.m_partition.names()) + { + partitions += (is_first_partition ? "" : ";") + partition; + is_first_partition = false; + } + + property.value(std::move(partitions)); + qos.properties().properties().push_back(std::move(property)); + } +} + +void set_qos_from_attributes( + DataReaderQos& qos, + const SubscriberAttributes& attr) +{ + qos.reader_resource_limits().matched_publisher_allocation = attr.matched_publisher_allocation; + qos.properties() = attr.properties; + qos.expects_inline_qos(attr.expectsInlineQos); + qos.endpoint().unicast_locator_list = attr.unicastLocatorList; + qos.endpoint().multicast_locator_list = attr.multicastLocatorList; + qos.endpoint().remote_locator_list = attr.remoteLocatorList; + qos.endpoint().history_memory_policy = attr.historyMemoryPolicy; + qos.endpoint().user_defined_id = attr.getUserDefinedID(); + qos.endpoint().entity_id = attr.getEntityID(); + qos.reliable_reader_qos().times = attr.times; + qos.reliable_reader_qos().disable_positive_ACKs = attr.qos.m_disablePositiveACKs; + qos.durability() = attr.qos.m_durability; + qos.durability_service() = attr.qos.m_durabilityService; + qos.deadline() = attr.qos.m_deadline; + qos.latency_budget() = attr.qos.m_latencyBudget; + qos.liveliness() = attr.qos.m_liveliness; + qos.reliability() = attr.qos.m_reliability; + qos.lifespan() = attr.qos.m_lifespan; + qos.user_data().setValue(attr.qos.m_userData); + qos.ownership() = attr.qos.m_ownership; + qos.destination_order() = attr.qos.m_destinationOrder; + qos.type_consistency().type_consistency = attr.qos.type_consistency; + qos.type_consistency().representation = attr.qos.representation; + qos.time_based_filter() = attr.qos.m_timeBasedFilter; + qos.history() = attr.topic.historyQos; + qos.resource_limits() = attr.topic.resourceLimitsQos; + qos.data_sharing() = attr.qos.data_sharing; + + if (attr.qos.m_partition.size() > 0 ) + { + Property property; + property.name("partitions"); + string partitions; + bool is_first_partition = true; + + for (auto partition : attr.qos.m_partition.names()) + { + partitions += (is_first_partition ? "" : ";") + partition; + is_first_partition = false; + } + + property.value(std::move(partitions)); + qos.properties().properties().push_back(std::move(property)); + } +} + +void set_qos_from_attributes( + DomainParticipantQos& qos, + const eprosima::fastrtps::rtps::RTPSParticipantAttributes& attr) +{ + qos.user_data().setValue(attr.userData); + qos.allocation() = attr.allocation; + qos.wire_protocol().prefix = attr.prefix; + qos.wire_protocol().participant_id = attr.participantID; + qos.wire_protocol().builtin = attr.builtin; + qos.wire_protocol().port = attr.port; + qos.wire_protocol().throughput_controller = attr.throughputController; + qos.wire_protocol().default_unicast_locator_list = attr.defaultUnicastLocatorList; + qos.wire_protocol().default_multicast_locator_list = attr.defaultMulticastLocatorList; + qos.transport().user_transports = attr.userTransports; + qos.transport().use_builtin_transports = attr.useBuiltinTransports; + qos.transport().send_socket_buffer_size = attr.sendSocketBufferSize; + qos.transport().listen_socket_buffer_size = attr.listenSocketBufferSize; + qos.name() = attr.getName(); + qos.flow_controllers() = attr.flow_controllers; + + // Merge attributes and qos properties + for (auto property : attr.properties.properties()) + { + string* property_value = fastrtps::rtps::PropertyPolicyHelper::find_property( + qos.properties(), property.name()); + if (nullptr == property_value) + { + qos.properties().properties().emplace_back(property); + } + else + { + *property_value = property.value(); + } + } + qos.properties().binary_properties() = attr.properties.binary_properties(); +} + +void set_attributes_from_qos( + fastrtps::rtps::RTPSParticipantAttributes& attr, + const DomainParticipantQos& qos) +{ + attr.allocation = qos.allocation(); + attr.properties = qos.properties(); + attr.setName(qos.name()); + attr.prefix = qos.wire_protocol().prefix; + attr.participantID = qos.wire_protocol().participant_id; + attr.builtin = qos.wire_protocol().builtin; + attr.port = qos.wire_protocol().port; + attr.throughputController = qos.wire_protocol().throughput_controller; + attr.defaultUnicastLocatorList = qos.wire_protocol().default_unicast_locator_list; + attr.defaultMulticastLocatorList = qos.wire_protocol().default_multicast_locator_list; + attr.userTransports = qos.transport().user_transports; + attr.useBuiltinTransports = qos.transport().use_builtin_transports; + attr.sendSocketBufferSize = qos.transport().send_socket_buffer_size; + attr.listenSocketBufferSize = qos.transport().listen_socket_buffer_size; + attr.userData = qos.user_data().data_vec(); + attr.flow_controllers = qos.flow_controllers(); +} + +void set_qos_from_attributes( + TopicQos& qos, + const TopicAttributes& attr) +{ + qos.history() = attr.historyQos; + qos.resource_limits() = attr.resourceLimitsQos; +} + +void set_qos_from_attributes( + SubscriberQos& qos, + const SubscriberAttributes& attr) +{ + qos.group_data().setValue(attr.qos.m_groupData); + qos.partition() = attr.qos.m_partition; + qos.presentation() = attr.qos.m_presentation; +} + +void set_qos_from_attributes( + PublisherQos& qos, + const PublisherAttributes& attr) +{ + qos.group_data().setValue(attr.qos.m_groupData); + qos.partition() = attr.qos.m_partition; + qos.presentation() = attr.qos.m_presentation; +} + +} /* namespace utils */ +} /* namespace dds */ +} /* namespace fastdds */ +} /* namespace eprosima */ diff --git a/src/cpp/fastdds/utils/QosConverters.hpp b/src/cpp/fastdds/utils/QosConverters.hpp new file mode 100644 index 00000000000..7b89defa50a --- /dev/null +++ b/src/cpp/fastdds/utils/QosConverters.hpp @@ -0,0 +1,123 @@ +// 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. + +/** + * @file QosConverters.h + */ + +#ifndef _FASTDDS_UTILS_QOS_CONVERTERS_HPP_ +#define _FASTDDS_UTILS_QOS_CONVERTERS_HPP_ +#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +#include +#include +#include +#include +#include +#include +#include + +namespace eprosima { +namespace fastdds { +namespace dds { +namespace utils { + +using fastrtps::PublisherAttributes; +using fastrtps::SubscriberAttributes; +using fastrtps::TopicAttributes; + +/** + * Obtains the DataWriterQos from the PublisherAttributes provided. + * + * @param[out] qos Pointer to the QoS to write on + * @param[in] attr Pointer to the attributes from which to obtain data + */ +void set_qos_from_attributes( + DataWriterQos& qos, + const PublisherAttributes& attr); + +/** + * Obtains the DataReaderQos from the SubscriberAttributes provided. + * + * @param[out] qos Pointer to the QoS to write on + * @param[in] attr Pointer to the attributes from which to obtain data + */ +void set_qos_from_attributes( + DataReaderQos& qos, + const SubscriberAttributes& attr); + +/** + * @brief Fill DomainParticipantQos from a given attributes RTPSParticipantAttributes object + * + * For the case of the non-binary properties, instead of the RTPSParticipantAttributes overriding the + * property list in the DomainParticipantQos, a merge is performed in the following manner: + * + * - If any property from the RTPSParticipantAttributes is not in the DomainParticipantQos, then it is appended + * to the DomainParticipantQos. + * - If any property from the RTPSParticipantAttributes property is also in the DomainParticipantQos, then the + * value in the DomainParticipantQos is overridden with that of the RTPSParticipantAttributes. + * + * @param[in, out] qos The DomainParticipantQos to set + * @param[in] attr The RTPSParticipantAttributes from which the @c qos is set. + */ +void set_qos_from_attributes( + DomainParticipantQos& qos, + const eprosima::fastrtps::rtps::RTPSParticipantAttributes& attr); + +/** + * Obtains the RTPSParticipantAttributes from the DomainParticipantQos provided. + * + * @param[out] attr Pointer to the attributes from which to obtain data + * @param[in] qos Pointer to the QoS to write on + */ +void set_attributes_from_qos( + fastrtps::rtps::RTPSParticipantAttributes& attr, + const DomainParticipantQos& qos); + +/** + * Obtains the TopicQos from the TopicAttributes provided. + * + * @param[out] qos Pointer to the QoS to write on + * @param[in] attr Pointer to the attributes from which to obtain data + */ +void set_qos_from_attributes( + TopicQos& qos, + const TopicAttributes& attr); + +/** + * Obtains the SubscriberQos from the SubscriberAttributes provided. + * + * @param[out] qos Pointer to the QoS to write on + * @param[in] attr Pointer to the attributes from which to obtain data + */ +void set_qos_from_attributes( + SubscriberQos& qos, + const SubscriberAttributes& attr); + +/** + * Obtains the PublisherQos from the PublisherAttributes provided. + * + * @param[out] qos Pointer to the QoS to write on + * @param[in] attr Pointer to the attributes from which to obtain data + */ +void set_qos_from_attributes( + PublisherQos& qos, + const PublisherAttributes& attr); + +} /* namespace utils */ +} /* namespace dds */ +} /* namespace fastdds */ +} /* namespace eprosima */ +#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC +#endif /* _FASTDDS_UTILS_QOS_CONVERTERS_HPP_ */ diff --git a/test/unittest/dds/publisher/CMakeLists.txt b/test/unittest/dds/publisher/CMakeLists.txt index d786e0f2388..df1e459d626 100644 --- a/test/unittest/dds/publisher/CMakeLists.txt +++ b/test/unittest/dds/publisher/CMakeLists.txt @@ -99,6 +99,7 @@ set(DATAWRITERTESTS_SOURCE DataWriterTests.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/fastdds/utils/QosConverters.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastrtps_deprecated/subscriber/SubscriberHistory.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/DataSharing/DataSharingListener.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/DataSharing/DataSharingNotification.cpp diff --git a/test/unittest/dds/status/CMakeLists.txt b/test/unittest/dds/status/CMakeLists.txt index 626ef35f06a..86ed776db15 100644 --- a/test/unittest/dds/status/CMakeLists.txt +++ b/test/unittest/dds/status/CMakeLists.txt @@ -83,6 +83,7 @@ set(LISTENERTESTS_SOURCE ListenerTests.cpp ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/topic/qos/TopicQos.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/attributes/PropertyPolicy.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/common/Time_t.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/fastdds/utils/QosConverters.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/FlowControllerConsts.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/flowcontrol/ThroughputControllerDescriptor.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/history/CacheChangePool.cpp diff --git a/test/unittest/statistics/dds/CMakeLists.txt b/test/unittest/statistics/dds/CMakeLists.txt index 1718f49ef45..23c49ea2536 100644 --- a/test/unittest/statistics/dds/CMakeLists.txt +++ b/test/unittest/statistics/dds/CMakeLists.txt @@ -147,6 +147,7 @@ if (SQLITE3_SUPPORT AND FASTDDS_STATISTICS) ${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/fastdds/utils/QosConverters.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/DataSharing/DataSharingListener.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/DataSharing/DataSharingNotification.cpp ${PROJECT_SOURCE_DIR}/src/cpp/rtps/DataSharing/DataSharingPayloadPool.cpp