From 37c3e8f2d98f07c02dd192e26dfc8ff60f209eac Mon Sep 17 00:00:00 2001 From: Juan Lopez Fernandez Date: Tue, 24 Sep 2024 10:03:01 +0200 Subject: [PATCH] Add QoS getters from raw XML Signed-off-by: Juan Lopez Fernandez --- .../fastdds/dds/domain/DomainParticipant.hpp | 25 +++ .../dds/domain/DomainParticipantFactory.hpp | 5 + include/fastdds/dds/publisher/Publisher.hpp | 6 + include/fastdds/dds/subscriber/Subscriber.hpp | 6 + src/cpp/fastdds/domain/DomainParticipant.cpp | 48 ++++- .../domain/DomainParticipantFactory.cpp | 16 ++ .../fastdds/domain/DomainParticipantImpl.cpp | 78 ++++++++ .../fastdds/domain/DomainParticipantImpl.hpp | 25 +++ src/cpp/fastdds/publisher/Publisher.cpp | 9 + src/cpp/fastdds/publisher/PublisherImpl.cpp | 18 ++ src/cpp/fastdds/publisher/PublisherImpl.hpp | 6 + src/cpp/fastdds/subscriber/Subscriber.cpp | 9 + src/cpp/fastdds/subscriber/SubscriberImpl.cpp | 18 ++ src/cpp/fastdds/subscriber/SubscriberImpl.hpp | 6 + src/cpp/xmlparser/XMLProfileManager.cpp | 183 ++++++++++++++++++ src/cpp/xmlparser/XMLProfileManager.h | 30 +++ 16 files changed, 484 insertions(+), 4 deletions(-) diff --git a/include/fastdds/dds/domain/DomainParticipant.hpp b/include/fastdds/dds/domain/DomainParticipant.hpp index 5fae640695d..e0c45256645 100644 --- a/include/fastdds/dds/domain/DomainParticipant.hpp +++ b/include/fastdds/dds/domain/DomainParticipant.hpp @@ -547,6 +547,11 @@ class DomainParticipant : public Entity const std::string& profile_name, PublisherQos& qos) const; + FASTDDS_EXPORTED_API ReturnCode_t get_publisher_qos_from_xml( + const std::string& xml, + PublisherQos& qos, + const std::string& profile_name = "") const; + /** * This operation sets a default value of the Subscriber QoS policies that will be used for newly created * Subscriber entities in the case where the QoS policies are defaulted in the create_subscriber operation. @@ -601,6 +606,11 @@ class DomainParticipant : public Entity const std::string& profile_name, SubscriberQos& qos) const; + FASTDDS_EXPORTED_API ReturnCode_t get_subscriber_qos_from_xml( + const std::string& xml, + SubscriberQos& qos, + const std::string& profile_name = "") const; + /** * This operation sets a default value of the Topic QoS policies which will be used for newly created * Topic entities in the case where the QoS policies are defaulted in the create_topic operation. @@ -655,6 +665,11 @@ class DomainParticipant : public Entity const std::string& profile_name, TopicQos& qos) const; + FASTDDS_EXPORTED_API ReturnCode_t get_topic_qos_from_xml( + const std::string& xml, + TopicQos& qos, + const std::string& profile_name = "") const; + /** * Fills the ReplierQos with the values of the XML profile. * @@ -666,6 +681,11 @@ class DomainParticipant : public Entity const std::string& profile_name, ReplierQos& qos) const; + FASTDDS_EXPORTED_API ReturnCode_t get_replier_qos_from_xml( + const std::string& xml, + ReplierQos& qos, + const std::string& profile_name = "") const; + /** * Fills the RequesterQos with the values of the XML profile. * @@ -677,6 +697,11 @@ class DomainParticipant : public Entity const std::string& profile_name, RequesterQos& qos) const; + FASTDDS_EXPORTED_API ReturnCode_t get_requester_qos_from_xml( + const std::string& xml, + RequesterQos& qos, + const std::string& profile_name = "") const; + /** * Retrieves the list of DomainParticipants that have been discovered in the domain and are not "ignored". * diff --git a/include/fastdds/dds/domain/DomainParticipantFactory.hpp b/include/fastdds/dds/domain/DomainParticipantFactory.hpp index a492fce1e09..e381aee05c1 100644 --- a/include/fastdds/dds/domain/DomainParticipantFactory.hpp +++ b/include/fastdds/dds/domain/DomainParticipantFactory.hpp @@ -229,6 +229,11 @@ class DomainParticipantFactory const std::string& profile_name, DomainParticipantQos& qos) const; + FASTDDS_EXPORTED_API ReturnCode_t get_participant_qos_from_xml( + const std::string& xml, + DomainParticipantQos& qos, + const std::string& profile_name = "") const; + /** * Fills the DomainParticipantExtendedQos with the values of the XML profile. * diff --git a/include/fastdds/dds/publisher/Publisher.hpp b/include/fastdds/dds/publisher/Publisher.hpp index a29deab4541..58a2274e4c4 100644 --- a/include/fastdds/dds/publisher/Publisher.hpp +++ b/include/fastdds/dds/publisher/Publisher.hpp @@ -342,6 +342,12 @@ class Publisher : public DomainEntity const std::string& profile_name, DataWriterQos& qos) const; + FASTDDS_EXPORTED_API ReturnCode_t get_datawriter_qos_from_xml( + const std::string& xml, + DataWriterQos& qos, + std::string& topic_name, + const std::string& profile_name = "") const; + /** * Returns the Publisher's handle. * diff --git a/include/fastdds/dds/subscriber/Subscriber.hpp b/include/fastdds/dds/subscriber/Subscriber.hpp index eba91b2c44d..373de4ecf18 100644 --- a/include/fastdds/dds/subscriber/Subscriber.hpp +++ b/include/fastdds/dds/subscriber/Subscriber.hpp @@ -355,6 +355,12 @@ class Subscriber : public DomainEntity const std::string& profile_name, DataReaderQos& qos) const; + FASTDDS_EXPORTED_API ReturnCode_t get_datareader_qos_from_xml( + const std::string& xml, + DataReaderQos& qos, + std::string& topic_name, + const std::string& profile_name = "") const; + /** * @brief Copies TopicQos into the corresponding DataReaderQos * diff --git a/src/cpp/fastdds/domain/DomainParticipant.cpp b/src/cpp/fastdds/domain/DomainParticipant.cpp index a3839843894..e73d520a011 100644 --- a/src/cpp/fastdds/domain/DomainParticipant.cpp +++ b/src/cpp/fastdds/domain/DomainParticipant.cpp @@ -336,6 +336,14 @@ ReturnCode_t DomainParticipant::get_publisher_qos_from_profile( return impl_->get_publisher_qos_from_profile(profile_name, qos); } +ReturnCode_t DomainParticipant::get_publisher_qos_from_xml( + const std::string& xml, + PublisherQos& qos, + const std::string& profile_name) const +{ + return impl_->get_publisher_qos_from_xml(xml, qos, profile_name); +} + ReturnCode_t DomainParticipant::set_default_subscriber_qos( const SubscriberQos& qos) { @@ -361,6 +369,14 @@ ReturnCode_t DomainParticipant::get_subscriber_qos_from_profile( return impl_->get_subscriber_qos_from_profile(profile_name, qos); } +ReturnCode_t DomainParticipant::get_subscriber_qos_from_xml( + const std::string& xml, + SubscriberQos& qos, + const std::string& profile_name) const +{ + return impl_->get_subscriber_qos_from_xml(xml, qos, profile_name); +} + ReturnCode_t DomainParticipant::set_default_topic_qos( const TopicQos& qos) { @@ -386,11 +402,12 @@ ReturnCode_t DomainParticipant::get_topic_qos_from_profile( return impl_->get_topic_qos_from_profile(profile_name, qos); } -ReturnCode_t DomainParticipant::get_replier_qos_from_profile( - const std::string& profile_name, - ReplierQos& qos) const +ReturnCode_t DomainParticipant::get_topic_qos_from_xml( + const std::string& xml, + TopicQos& qos, + const std::string& profile_name) const { - return impl_->get_replier_qos_from_profile(profile_name, qos); + return impl_->get_topic_qos_from_xml(xml, qos, profile_name); } ReturnCode_t DomainParticipant::get_requester_qos_from_profile( @@ -400,6 +417,29 @@ ReturnCode_t DomainParticipant::get_requester_qos_from_profile( return impl_->get_requester_qos_from_profile(profile_name, qos); } +ReturnCode_t DomainParticipant::get_requester_qos_from_xml( + const std::string& xml, + RequesterQos& qos, + const std::string& profile_name) const +{ + return impl_->get_requester_qos_from_xml(xml, qos, profile_name); +} + +ReturnCode_t DomainParticipant::get_replier_qos_from_profile( + const std::string& profile_name, + ReplierQos& qos) const +{ + return impl_->get_replier_qos_from_profile(profile_name, qos); +} + +ReturnCode_t DomainParticipant::get_replier_qos_from_xml( + const std::string& xml, + ReplierQos& qos, + const std::string& profile_name) const +{ + return impl_->get_replier_qos_from_xml(xml, qos, profile_name); +} + ReturnCode_t DomainParticipant::get_discovered_participants( std::vector& participant_handles) const { diff --git a/src/cpp/fastdds/domain/DomainParticipantFactory.cpp b/src/cpp/fastdds/domain/DomainParticipantFactory.cpp index eb6f9b65ffe..f596dc8a148 100644 --- a/src/cpp/fastdds/domain/DomainParticipantFactory.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantFactory.cpp @@ -341,6 +341,22 @@ ReturnCode_t DomainParticipantFactory::get_participant_qos_from_profile( return RETCODE_BAD_PARAMETER; } +ReturnCode_t DomainParticipantFactory::get_participant_qos_from_xml( + const std::string& xml, + DomainParticipantQos& qos, + const std::string& profile_name) const +{ + ParticipantAttributes attr; + if (XMLP_ret::XML_OK == XMLProfileManager::fill_participant_attributes_from_xml(xml, attr, profile_name)) + { + qos = default_participant_qos_; + utils::set_qos_from_attributes(qos, attr.rtps); + return RETCODE_OK; + } + + return RETCODE_BAD_PARAMETER; +} + ReturnCode_t DomainParticipantFactory::get_participant_extended_qos_from_profile( const std::string& profile_name, DomainParticipantExtendedQos& extended_qos) const diff --git a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp index 8bef8e5ee16..3603be63b6c 100644 --- a/src/cpp/fastdds/domain/DomainParticipantImpl.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantImpl.cpp @@ -1044,6 +1044,22 @@ ReturnCode_t DomainParticipantImpl::get_publisher_qos_from_profile( return RETCODE_BAD_PARAMETER; } +ReturnCode_t DomainParticipantImpl::get_publisher_qos_from_xml( + const std::string& xml, + PublisherQos& qos, + const std::string& profile_name) const +{ + xmlparser::PublisherAttributes attr; + if (XMLP_ret::XML_OK == XMLProfileManager::fill_publisher_attributes_from_xml(xml, attr, profile_name)) + { + qos = default_pub_qos_; + utils::set_qos_from_attributes(qos, attr); + return RETCODE_OK; + } + + return RETCODE_BAD_PARAMETER; +} + ReturnCode_t DomainParticipantImpl::set_default_subscriber_qos( const SubscriberQos& qos) { @@ -1092,6 +1108,22 @@ ReturnCode_t DomainParticipantImpl::get_subscriber_qos_from_profile( return RETCODE_BAD_PARAMETER; } +ReturnCode_t DomainParticipantImpl::get_subscriber_qos_from_xml( + const std::string& xml, + SubscriberQos& qos, + const std::string& profile_name) const +{ + xmlparser::SubscriberAttributes attr; + if (XMLP_ret::XML_OK == XMLProfileManager::fill_subscriber_attributes_from_xml(xml, attr, profile_name)) + { + qos = default_sub_qos_; + utils::set_qos_from_attributes(qos, attr); + return RETCODE_OK; + } + + return RETCODE_BAD_PARAMETER; +} + ReturnCode_t DomainParticipantImpl::set_default_topic_qos( const TopicQos& qos) { @@ -1140,6 +1172,22 @@ ReturnCode_t DomainParticipantImpl::get_topic_qos_from_profile( return RETCODE_BAD_PARAMETER; } +ReturnCode_t DomainParticipantImpl::get_topic_qos_from_xml( + const std::string& profile_name, + TopicQos& qos, + const std::string& xml) const +{ + xmlparser::TopicAttributes attr; + if (XMLP_ret::XML_OK == XMLProfileManager::fill_topic_attributes_from_xml(xml, attr, profile_name)) + { + qos = default_topic_qos_; + utils::set_qos_from_attributes(qos, attr); + return RETCODE_OK; + } + + return RETCODE_BAD_PARAMETER; +} + ReturnCode_t DomainParticipantImpl::get_replier_qos_from_profile( const std::string& profile_name, ReplierQos& qos) const @@ -1154,6 +1202,21 @@ ReturnCode_t DomainParticipantImpl::get_replier_qos_from_profile( return RETCODE_BAD_PARAMETER; } +ReturnCode_t DomainParticipantImpl::get_replier_qos_from_xml( + const std::string& xml, + ReplierQos& qos, + const std::string& profile_name) const +{ + xmlparser::ReplierAttributes attr; + if (XMLP_ret::XML_OK == XMLProfileManager::fill_replier_attributes_from_xml(xml, attr, profile_name)) + { + utils::set_qos_from_attributes(qos, attr); + return RETCODE_OK; + } + + return RETCODE_BAD_PARAMETER; +} + ReturnCode_t DomainParticipantImpl::get_requester_qos_from_profile( const std::string& profile_name, RequesterQos& qos) const @@ -1168,6 +1231,21 @@ ReturnCode_t DomainParticipantImpl::get_requester_qos_from_profile( return RETCODE_BAD_PARAMETER; } +ReturnCode_t DomainParticipantImpl::get_requester_qos_from_xml( + const std::string& xml, + RequesterQos& qos, + const std::string& profile_name) const +{ + xmlparser::RequesterAttributes attr; + if (XMLP_ret::XML_OK == XMLProfileManager::fill_requester_attributes_from_xml(xml, attr, profile_name)) + { + utils::set_qos_from_attributes(qos, attr); + return RETCODE_OK; + } + + return RETCODE_BAD_PARAMETER; +} + /* TODO bool DomainParticipantImpl::get_discovered_participants( std::vector& participant_handles) const diff --git a/src/cpp/fastdds/domain/DomainParticipantImpl.hpp b/src/cpp/fastdds/domain/DomainParticipantImpl.hpp index 803f6a2b6c4..abd2a94c1f9 100644 --- a/src/cpp/fastdds/domain/DomainParticipantImpl.hpp +++ b/src/cpp/fastdds/domain/DomainParticipantImpl.hpp @@ -375,6 +375,11 @@ class DomainParticipantImpl const std::string& profile_name, PublisherQos& qos) const; + ReturnCode_t get_publisher_qos_from_xml( + const std::string& xml, + PublisherQos& qos, + const std::string& profile_name = "") const; + ReturnCode_t set_default_subscriber_qos( const SubscriberQos& qos); @@ -386,6 +391,11 @@ class DomainParticipantImpl const std::string& profile_name, SubscriberQos& qos) const; + ReturnCode_t get_subscriber_qos_from_xml( + const std::string& xml, + SubscriberQos& qos, + const std::string& profile_name = "") const; + ReturnCode_t set_default_topic_qos( const TopicQos& qos); @@ -397,14 +407,29 @@ class DomainParticipantImpl const std::string& profile_name, TopicQos& qos) const; + ReturnCode_t get_topic_qos_from_xml( + const std::string& xml, + TopicQos& qos, + const std::string& profile_name = "") const; + ReturnCode_t get_replier_qos_from_profile( const std::string& profile_name, ReplierQos& qos) const; + ReturnCode_t get_replier_qos_from_xml( + const std::string& xml, + ReplierQos& qos, + const std::string& profile_name = "") const; + ReturnCode_t get_requester_qos_from_profile( const std::string& profile_name, RequesterQos& qos) const; + ReturnCode_t get_requester_qos_from_xml( + const std::string& xml, + RequesterQos& qos, + const std::string& profile_name = "") const; + /* TODO bool get_discovered_participants( std::vector& participant_handles) const; diff --git a/src/cpp/fastdds/publisher/Publisher.cpp b/src/cpp/fastdds/publisher/Publisher.cpp index d42517581dd..f80642c6111 100644 --- a/src/cpp/fastdds/publisher/Publisher.cpp +++ b/src/cpp/fastdds/publisher/Publisher.cpp @@ -237,6 +237,15 @@ ReturnCode_t Publisher::get_datawriter_qos_from_profile( return impl_->get_datawriter_qos_from_profile(profile_name, qos); } +ReturnCode_t Publisher::get_datawriter_qos_from_xml( + const std::string& xml, + DataWriterQos& qos, + std::string& topic_name, + const std::string& profile_name) const +{ + return impl_->get_datawriter_qos_from_xml(xml, qos, topic_name, profile_name); +} + } // namespace dds } // namespace fastdds } // namespace eprosima diff --git a/src/cpp/fastdds/publisher/PublisherImpl.cpp b/src/cpp/fastdds/publisher/PublisherImpl.cpp index 30a32558942..234732be004 100644 --- a/src/cpp/fastdds/publisher/PublisherImpl.cpp +++ b/src/cpp/fastdds/publisher/PublisherImpl.cpp @@ -474,6 +474,24 @@ ReturnCode_t PublisherImpl::get_datawriter_qos_from_profile( return RETCODE_BAD_PARAMETER; } +ReturnCode_t PublisherImpl::get_datawriter_qos_from_xml( + const std::string& xml, + DataWriterQos& qos, + std::string& topic_name, + const std::string& profile_name) const +{ + xmlparser::PublisherAttributes attr; + if (XMLP_ret::XML_OK == XMLProfileManager::fill_publisher_attributes_from_xml(xml, attr, profile_name)) + { + qos = default_datawriter_qos_; + utils::set_qos_from_attributes(qos, attr); + topic_name = attr.topic.getTopicName(); + return RETCODE_OK; + } + + return RETCODE_BAD_PARAMETER; +} + ReturnCode_t PublisherImpl::copy_from_topic_qos( DataWriterQos& writer_qos, const TopicQos& topic_qos) diff --git a/src/cpp/fastdds/publisher/PublisherImpl.hpp b/src/cpp/fastdds/publisher/PublisherImpl.hpp index b8b9fdea226..6fc42a976b9 100644 --- a/src/cpp/fastdds/publisher/PublisherImpl.hpp +++ b/src/cpp/fastdds/publisher/PublisherImpl.hpp @@ -169,6 +169,12 @@ class PublisherImpl const std::string& profile_name, DataWriterQos& qos) const; + ReturnCode_t get_datawriter_qos_from_xml( + const std::string& xml, + DataWriterQos& qos, + std::string& topic_name, + const std::string& profile_name = "") const; + ReturnCode_t static copy_from_topic_qos( DataWriterQos& writer_qos, const TopicQos& topic_qos); diff --git a/src/cpp/fastdds/subscriber/Subscriber.cpp b/src/cpp/fastdds/subscriber/Subscriber.cpp index 88b058f3c4f..ad71e8134f4 100644 --- a/src/cpp/fastdds/subscriber/Subscriber.cpp +++ b/src/cpp/fastdds/subscriber/Subscriber.cpp @@ -218,6 +218,15 @@ ReturnCode_t Subscriber::get_datareader_qos_from_profile( return impl_->get_datareader_qos_from_profile(profile_name, qos); } +ReturnCode_t Subscriber::get_datareader_qos_from_xml( + const std::string& xml, + DataReaderQos& qos, + std::string& topic_name, + const std::string& profile_name) const +{ + return impl_->get_datareader_qos_from_xml(xml, qos, topic_name, profile_name); +} + ReturnCode_t Subscriber::copy_from_topic_qos( DataReaderQos& reader_qos, const TopicQos& topic_qos) diff --git a/src/cpp/fastdds/subscriber/SubscriberImpl.cpp b/src/cpp/fastdds/subscriber/SubscriberImpl.cpp index 077e0ca323c..55bf9b287e0 100644 --- a/src/cpp/fastdds/subscriber/SubscriberImpl.cpp +++ b/src/cpp/fastdds/subscriber/SubscriberImpl.cpp @@ -436,6 +436,24 @@ ReturnCode_t SubscriberImpl::get_datareader_qos_from_profile( return RETCODE_BAD_PARAMETER; } +ReturnCode_t SubscriberImpl::get_datareader_qos_from_xml( + const std::string& xml, + DataReaderQos& qos, + std::string& topic_name, + const std::string& profile_name) const +{ + xmlparser::SubscriberAttributes attr; + if (XMLP_ret::XML_OK == XMLProfileManager::fill_subscriber_attributes_from_xml(xml, attr, profile_name)) + { + qos = default_datareader_qos_; + utils::set_qos_from_attributes(qos, attr); + topic_name = attr.topic.getTopicName(); + return RETCODE_OK; + } + + return RETCODE_BAD_PARAMETER; +} + ReturnCode_t SubscriberImpl::copy_from_topic_qos( DataReaderQos& reader_qos, const TopicQos& topic_qos) diff --git a/src/cpp/fastdds/subscriber/SubscriberImpl.hpp b/src/cpp/fastdds/subscriber/SubscriberImpl.hpp index 9966ace8e51..3da722b915a 100644 --- a/src/cpp/fastdds/subscriber/SubscriberImpl.hpp +++ b/src/cpp/fastdds/subscriber/SubscriberImpl.hpp @@ -147,6 +147,12 @@ class SubscriberImpl const std::string& profile_name, DataReaderQos& qos) const; + ReturnCode_t get_datareader_qos_from_xml( + const std::string& xml, + DataReaderQos& qos, + std::string& topic_name, + const std::string& profile_name) const; + ReturnCode_t static copy_from_topic_qos( DataReaderQos& reader_qos, const TopicQos& topic_qos); diff --git a/src/cpp/xmlparser/XMLProfileManager.cpp b/src/cpp/xmlparser/XMLProfileManager.cpp index 145eeeb0c94..d10116d9568 100644 --- a/src/cpp/xmlparser/XMLProfileManager.cpp +++ b/src/cpp/xmlparser/XMLProfileManager.cpp @@ -49,6 +49,141 @@ sp_transport_map_t XMLProfileManager::transport_profiles_; p_dynamictype_map_t XMLProfileManager::dynamic_types_; BaseNode* XMLProfileManager::root = nullptr; +template +struct AttributesTraits; + +template<> +struct AttributesTraits +{ + static constexpr NodeType node_type = NodeType::PARTICIPANT; + using NodePtrType = p_node_participant_t; + using NodeUniquePtrType = up_participant_t; + + static std::string name() + { + return "Participant"; + } +}; + +template<> +struct AttributesTraits +{ + static constexpr NodeType node_type = NodeType::PUBLISHER; + using NodePtrType = p_node_publisher_t; + using NodeUniquePtrType = up_publisher_t; + + static std::string name() + { + return "Publisher"; + } +}; + +template<> +struct AttributesTraits +{ + static constexpr NodeType node_type = NodeType::SUBSCRIBER; + using NodePtrType = p_node_subscriber_t; + using NodeUniquePtrType = up_subscriber_t; + + static std::string name() + { + return "Subscriber"; + } +}; + +template<> +struct AttributesTraits +{ + static constexpr NodeType node_type = NodeType::TOPIC; + using NodePtrType = p_node_topic_t; + using NodeUniquePtrType = up_topic_t; + + static std::string name() + { + return "Topic"; + } +}; + +template<> +struct AttributesTraits +{ + static constexpr NodeType node_type = NodeType::REQUESTER; + using NodePtrType = p_node_requester_t; + using NodeUniquePtrType = up_requester_t; + + static std::string name() + { + return "Requester"; + } +}; + +template<> +struct AttributesTraits +{ + static constexpr NodeType node_type = NodeType::REPLIER; + using NodePtrType = p_node_replier_t; + using NodeUniquePtrType = up_replier_t; + + static std::string name() + { + return "Replier"; + } +}; + +template +XMLP_ret fill_attributes_from_xml( + const std::string& xml, + AttributesType& atts, + const std::string& profile_name) +{ + using Traits = AttributesTraits; + + up_base_node_t root_node; + XMLP_ret loaded_ret = XMLParser::loadXML(xml.c_str(), xml.size(), root_node); + + if (!root_node || loaded_ret != XMLP_ret::XML_OK) + { + EPROSIMA_LOG_ERROR(XMLPARSER, "Error parsing string"); + return XMLP_ret::XML_ERROR; + } + + for (auto&& child: root_node->getChildren()) + { + if (Traits::node_type == child.get()->getType()) + { + typename Traits::NodePtrType node_part = dynamic_cast(child.get()); + + if (!node_part) + { + EPROSIMA_LOG_ERROR(XMLPARSER, "Error casting node part"); + return XMLP_ret::XML_ERROR; + } + + if (profile_name != "") + { + node_att_map_cit_t it = node_part->getAttributes().find(PROFILE_NAME); + if (it != node_part->getAttributes().end() && it->second != profile_name) + { + continue; + } + } + + typename Traits::NodeUniquePtrType node_data = node_part->getData(); + if (!node_data) + { + EPROSIMA_LOG_ERROR(XMLPARSER, "Error retrieving node data"); + return XMLP_ret::XML_ERROR; + } + + atts = *node_data; + return XMLP_ret::XML_OK; + } + } + + EPROSIMA_LOG_ERROR(XMLPARSER, Traits::name() << "profile not found"); + return XMLP_ret::XML_ERROR; +} + XMLP_ret XMLProfileManager::fillParticipantAttributes( const std::string& profile_name, ParticipantAttributes& atts, @@ -67,6 +202,14 @@ XMLP_ret XMLProfileManager::fillParticipantAttributes( return XMLP_ret::XML_OK; } +XMLP_ret XMLProfileManager::fill_participant_attributes_from_xml( + const std::string& xml, + ParticipantAttributes& atts, + const std::string& profile_name) +{ + return fill_attributes_from_xml(xml, atts, profile_name); +} + XMLP_ret XMLProfileManager::fillPublisherAttributes( const std::string& profile_name, PublisherAttributes& atts, @@ -85,6 +228,14 @@ XMLP_ret XMLProfileManager::fillPublisherAttributes( return XMLP_ret::XML_OK; } +XMLP_ret XMLProfileManager::fill_publisher_attributes_from_xml( + const std::string& xml, + PublisherAttributes& atts, + const std::string& profile_name) +{ + return fill_attributes_from_xml(xml, atts, profile_name); +} + XMLP_ret XMLProfileManager::fillSubscriberAttributes( const std::string& profile_name, SubscriberAttributes& atts, @@ -103,6 +254,14 @@ XMLP_ret XMLProfileManager::fillSubscriberAttributes( return XMLP_ret::XML_OK; } +XMLP_ret XMLProfileManager::fill_subscriber_attributes_from_xml( + const std::string& xml, + SubscriberAttributes& atts, + const std::string& profile_name) +{ + return fill_attributes_from_xml(xml, atts, profile_name); +} + XMLP_ret XMLProfileManager::fillTopicAttributes( const std::string& profile_name, TopicAttributes& atts) @@ -117,6 +276,14 @@ XMLP_ret XMLProfileManager::fillTopicAttributes( return XMLP_ret::XML_OK; } +XMLP_ret XMLProfileManager::fill_topic_attributes_from_xml( + const std::string& xml, + TopicAttributes& atts, + const std::string& profile_name) +{ + return fill_attributes_from_xml(xml, atts, profile_name); +} + XMLP_ret XMLProfileManager::fillRequesterAttributes( const std::string& profile_name, RequesterAttributes& atts) @@ -131,6 +298,14 @@ XMLP_ret XMLProfileManager::fillRequesterAttributes( return XMLP_ret::XML_OK; } +XMLP_ret XMLProfileManager::fill_requester_attributes_from_xml( + const std::string& xml, + RequesterAttributes& atts, + const std::string& profile_name) +{ + return fill_attributes_from_xml(xml, atts, profile_name); +} + XMLP_ret XMLProfileManager::fillReplierAttributes( const std::string& profile_name, ReplierAttributes& atts) @@ -145,6 +320,14 @@ XMLP_ret XMLProfileManager::fillReplierAttributes( return XMLP_ret::XML_OK; } +XMLP_ret XMLProfileManager::fill_replier_attributes_from_xml( + const std::string& xml, + ReplierAttributes& atts, + const std::string& profile_name) +{ + return fill_attributes_from_xml(xml, atts, profile_name); +} + void XMLProfileManager::getDefaultParticipantAttributes( ParticipantAttributes& participant_attributes) { diff --git a/src/cpp/xmlparser/XMLProfileManager.h b/src/cpp/xmlparser/XMLProfileManager.h index 7534690994d..93c29e7b902 100644 --- a/src/cpp/xmlparser/XMLProfileManager.h +++ b/src/cpp/xmlparser/XMLProfileManager.h @@ -148,6 +148,11 @@ class XMLProfileManager fastdds::xmlparser::ParticipantAttributes& atts, bool log_error = true); + static XMLP_ret fill_participant_attributes_from_xml( + const std::string& xml, + fastdds::xmlparser::ParticipantAttributes& atts, + const std::string& profile_name = ""); + //!Fills participant_attributes with the default values. static void getDefaultParticipantAttributes( fastdds::xmlparser::ParticipantAttributes& participant_attributes); @@ -183,6 +188,11 @@ class XMLProfileManager fastdds::xmlparser::PublisherAttributes& atts, bool log_error = true); + static XMLP_ret fill_publisher_attributes_from_xml( + const std::string& xml, + fastdds::xmlparser::PublisherAttributes& atts, + const std::string& profile_name = ""); + //!Fills publisher_attributes with the default values. static void getDefaultPublisherAttributes( fastdds::xmlparser::PublisherAttributes& publisher_attributes); @@ -199,6 +209,11 @@ class XMLProfileManager fastdds::xmlparser::SubscriberAttributes& atts, bool log_error = true); + static XMLP_ret fill_subscriber_attributes_from_xml( + const std::string& xml, + fastdds::xmlparser::SubscriberAttributes& atts, + const std::string& profile_name = ""); + //!Fills subscriber_attributes with the default values. static void getDefaultSubscriberAttributes( fastdds::xmlparser::SubscriberAttributes& subscriber_attributes); @@ -222,6 +237,11 @@ class XMLProfileManager const std::string& profile_name, TopicAttributes& atts); + static XMLP_ret fill_topic_attributes_from_xml( + const std::string& xml, + fastdds::xmlparser::TopicAttributes& atts, + const std::string& profile_name = ""); + //!Fills topic_attributes with the default values. static void getDefaultTopicAttributes( TopicAttributes& topic_attributes); @@ -245,6 +265,11 @@ class XMLProfileManager const std::string& profile_name, fastdds::xmlparser::RequesterAttributes& atts); + static XMLP_ret fill_requester_attributes_from_xml( + const std::string& xml, + fastdds::xmlparser::RequesterAttributes& atts, + const std::string& profile_name = ""); + /** * Search for the profile specified and fill the structure. * @param profile_name Name for the profile to be used to fill the structure. @@ -255,6 +280,11 @@ class XMLProfileManager const std::string& profile_name, fastdds::xmlparser::ReplierAttributes& atts); + static XMLP_ret fill_replier_attributes_from_xml( + const std::string& xml, + fastdds::xmlparser::ReplierAttributes& atts, + const std::string& profile_name = ""); + /** * Deletes the XMLProfileManager instance. * FastDDS's Domain calls this method automatically on its destructor, but