diff --git a/include/fastdds/dds/core/policy/QosPolicies.hpp b/include/fastdds/dds/core/policy/QosPolicies.hpp index fbe56380197..3b0bc1569ed 100644 --- a/include/fastdds/dds/core/policy/QosPolicies.hpp +++ b/include/fastdds/dds/core/policy/QosPolicies.hpp @@ -2047,7 +2047,7 @@ class PublishModeQosPolicy : public QosPolicy * * @since 2.4.0 */ - std::string flow_controller_name = fastdds::rtps::FASTDDS_FLOW_CONTROLLER_DEFAULT; + const char* flow_controller_name = fastdds::rtps::FASTDDS_FLOW_CONTROLLER_DEFAULT; inline void clear() override { @@ -2059,7 +2059,7 @@ class PublishModeQosPolicy : public QosPolicy const PublishModeQosPolicy& b) const { return (this->kind == b.kind) && - flow_controller_name == b.flow_controller_name.c_str() && + 0 == strcmp(flow_controller_name, b.flow_controller_name) && QosPolicy::operator ==(b); } diff --git a/include/fastdds/rtps/attributes/WriterAttributes.h b/include/fastdds/rtps/attributes/WriterAttributes.h index 3e1d4f33cf9..7c9dd2d5ac1 100644 --- a/include/fastdds/rtps/attributes/WriterAttributes.h +++ b/include/fastdds/rtps/attributes/WriterAttributes.h @@ -143,7 +143,7 @@ class WriterAttributes Duration_t keep_duration; //! Flow controller name. Default: fastdds::rtps::FASTDDS_FLOW_CONTROLLER_DEFAULT. - std::string flow_controller_name = fastdds::rtps::FASTDDS_FLOW_CONTROLLER_DEFAULT; + const char* flow_controller_name = fastdds::rtps::FASTDDS_FLOW_CONTROLLER_DEFAULT; }; } /* namespace rtps */ diff --git a/include/fastdds/rtps/flowcontrol/FlowControllerDescriptor.hpp b/include/fastdds/rtps/flowcontrol/FlowControllerDescriptor.hpp index 9291d00ec23..bf06b40812c 100644 --- a/include/fastdds/rtps/flowcontrol/FlowControllerDescriptor.hpp +++ b/include/fastdds/rtps/flowcontrol/FlowControllerDescriptor.hpp @@ -15,8 +15,6 @@ #ifndef FASTDDS_RTPS_FLOWCONTROL_FLOWCONTROLLERDESCRIPTOR_HPP #define FASTDDS_RTPS_FLOWCONTROL_FLOWCONTROLLERDESCRIPTOR_HPP -#include - #include "FlowControllerConsts.hpp" #include "FlowControllerSchedulerPolicy.hpp" @@ -33,7 +31,7 @@ namespace rtps { struct FlowControllerDescriptor { //! Name of the flow controller. - std::string name = FASTDDS_FLOW_CONTROLLER_DEFAULT; + const char* name = FASTDDS_FLOW_CONTROLLER_DEFAULT; //! Scheduler policy used by the flow controller. //! diff --git a/include/fastrtps/xmlparser/XMLParser.h b/include/fastrtps/xmlparser/XMLParser.h index 49fe3e0779e..99eae23c38e 100644 --- a/include/fastrtps/xmlparser/XMLParser.h +++ b/include/fastrtps/xmlparser/XMLParser.h @@ -162,6 +162,14 @@ class XMLParser RTPS_DllAPI static XMLP_ret loadXMLDynamicTypes( tinyxml2::XMLElement& types); + + /** + * Clears the private static collections. + * + * @return XMLP_ret::XML_OK on success, XMLP_ret::XML_ERROR in other case. + */ + RTPS_DllAPI static XMLP_ret clear(); + protected: RTPS_DllAPI static XMLP_ret parseXML( @@ -627,6 +635,11 @@ class XMLParser tinyxml2::XMLElement* elem, eprosima::fastdds::rtps::BuiltinTransports* bt, uint8_t ident); + +private: + + static std::mutex collections_mtx_; + static std::set flow_controller_descriptor_names_; }; } // namespace xmlparser diff --git a/src/cpp/rtps/xmlparser/XMLElementParser.cpp b/src/cpp/rtps/xmlparser/XMLElementParser.cpp index 0e0d0e55ae6..8a7886d3e7f 100644 --- a/src/cpp/rtps/xmlparser/XMLElementParser.cpp +++ b/src/cpp/rtps/xmlparser/XMLElementParser.cpp @@ -27,6 +27,9 @@ #include +std::mutex XMLParser::collections_mtx_; +std::set XMLParser::flow_controller_descriptor_names_; + using namespace eprosima::fastrtps; using namespace eprosima::fastrtps::rtps; using namespace eprosima::fastrtps::xmlparser; @@ -848,13 +851,22 @@ XMLP_ret XMLParser::getXMLFlowControllerDescriptorList( if (strcmp(name, NAME) == 0) { + std::lock_guard lock(collections_mtx_); // name - stringType - flow_controller_descriptor->name = get_element_text(p_aux1); - if (flow_controller_descriptor->name.empty()) + std::string element = get_element_text(p_aux1); + if (element.empty()) { - EPROSIMA_LOG_ERROR(XMLPARSER, "<" << p_aux1->Value() << "> getXMLString XML_ERROR!"); + EPROSIMA_LOG_ERROR(XMLPARSER, "Node '" << NAME << "' without content"); + return XMLP_ret::XML_ERROR; + } + auto element_inserted = flow_controller_descriptor_names_.insert(element); + if (element_inserted.first == flow_controller_descriptor_names_.end()) + { + EPROSIMA_LOG_ERROR(XMLPARSER, + "Insertion error for flow controller node '" << FLOW_CONTROLLER_NAME << "'"); return XMLP_ret::XML_ERROR; } + flow_controller_descriptor->name = element_inserted.first->c_str(); name_defined = true; } else if (strcmp(name, SCHEDULER) == 0) @@ -2663,13 +2675,20 @@ XMLP_ret XMLParser::getXMLPublishModeQos( } else if (strcmp(name, FLOW_CONTROLLER_NAME) == 0) { - - publishMode.flow_controller_name = get_element_text(p_aux0); - if (publishMode.flow_controller_name.empty()) + std::lock_guard lock(collections_mtx_); + std::string element = get_element_text(p_aux0); + if (element.empty()) { EPROSIMA_LOG_ERROR(XMLPARSER, "Node '" << FLOW_CONTROLLER_NAME << "' without content"); return XMLP_ret::XML_ERROR; } + auto element_inserted = flow_controller_descriptor_names_.insert(element); + if (element_inserted.first == flow_controller_descriptor_names_.end()) + { + EPROSIMA_LOG_ERROR(XMLPARSER, "Insertion error for node '" << FLOW_CONTROLLER_NAME << "'"); + return XMLP_ret::XML_ERROR; + } + publishMode.flow_controller_name = element_inserted.first->c_str(); } else { diff --git a/src/cpp/rtps/xmlparser/XMLParser.cpp b/src/cpp/rtps/xmlparser/XMLParser.cpp index 880d9348ee4..59cefeb632b 100644 --- a/src/cpp/rtps/xmlparser/XMLParser.cpp +++ b/src/cpp/rtps/xmlparser/XMLParser.cpp @@ -2328,6 +2328,13 @@ XMLP_ret XMLParser::fillDataNode( return XMLP_ret::XML_OK; } +XMLP_ret XMLParser::clear() +{ + std::lock_guard lock(collections_mtx_); + flow_controller_descriptor_names_.clear(); + return XMLP_ret::XML_OK; +} + } // namespace xmlparser } // namespace fastrtps } // namespace eprosima diff --git a/src/cpp/rtps/xmlparser/XMLProfileManager.cpp b/src/cpp/rtps/xmlparser/XMLProfileManager.cpp index 01440054415..cb9118e4964 100644 --- a/src/cpp/rtps/xmlparser/XMLProfileManager.cpp +++ b/src/cpp/rtps/xmlparser/XMLProfileManager.cpp @@ -779,4 +779,7 @@ void XMLProfileManager::DeleteInstance() } dynamic_types_.clear(); } + + // Clear XML Parser collections + XMLParser::clear(); } diff --git a/test/unittest/dds/publisher/PublisherTests.cpp b/test/unittest/dds/publisher/PublisherTests.cpp index f25e75a7d40..d1671125c29 100644 --- a/test/unittest/dds/publisher/PublisherTests.cpp +++ b/test/unittest/dds/publisher/PublisherTests.cpp @@ -361,7 +361,7 @@ TEST(PublisherTests, ChangeDefaultDataWriterQos) EXPECT_FALSE(wqos.writer_data_lifecycle().autodispose_unregistered_instances); // .publish_mode EXPECT_EQ(eprosima::fastdds::dds::ASYNCHRONOUS_PUBLISH_MODE, wqos.publish_mode().kind); - EXPECT_EQ(true, wqos.publish_mode().flow_controller_name == "Prueba"); + EXPECT_EQ(0, strcmp(wqos.publish_mode().flow_controller_name, "Prueba")); count = 1; for (auto prop : wqos.properties().properties()) { diff --git a/test/unittest/xmlparser/XMLProfileParserTests.cpp b/test/unittest/xmlparser/XMLProfileParserTests.cpp index ea5b2cdbd9d..700c4495800 100644 --- a/test/unittest/xmlparser/XMLProfileParserTests.cpp +++ b/test/unittest/xmlparser/XMLProfileParserTests.cpp @@ -648,7 +648,7 @@ TEST_F(XMLProfileParserTests, XMLParserPublisher) EXPECT_EQ(pub_qos.m_partition.names()[0], "partition_name_a"); EXPECT_EQ(pub_qos.m_partition.names()[1], "partition_name_b"); EXPECT_EQ(pub_qos.m_publishMode.kind, ASYNCHRONOUS_PUBLISH_MODE); - EXPECT_EQ(pub_qos.m_publishMode.flow_controller_name, "test_flow_controller"); + EXPECT_EQ(0, strcmp(pub_qos.m_publishMode.flow_controller_name, "test_flow_controller")); EXPECT_EQ(pub_times.initialHeartbeatDelay, c_TimeZero); EXPECT_EQ(pub_times.heartbeatPeriod.seconds, 11); EXPECT_EQ(pub_times.heartbeatPeriod.nanosec, 32u); @@ -724,7 +724,7 @@ TEST_F(XMLProfileParserTests, XMLParserPublisherDeprecated) EXPECT_EQ(pub_qos.m_partition.names()[0], "partition_name_a"); EXPECT_EQ(pub_qos.m_partition.names()[1], "partition_name_b"); EXPECT_EQ(pub_qos.m_publishMode.kind, ASYNCHRONOUS_PUBLISH_MODE); - EXPECT_EQ(pub_qos.m_publishMode.flow_controller_name, "test_flow_controller"); + EXPECT_EQ(0, strcmp(pub_qos.m_publishMode.flow_controller_name, "test_flow_controller")); EXPECT_EQ(pub_times.initialHeartbeatDelay, c_TimeZero); EXPECT_EQ(pub_times.heartbeatPeriod.seconds, 11); EXPECT_EQ(pub_times.heartbeatPeriod.nanosec, 32u); @@ -798,7 +798,7 @@ TEST_F(XMLProfileParserTests, XMLParserDefaultPublisherProfile) EXPECT_EQ(pub_qos.m_partition.names()[0], "partition_name_a"); EXPECT_EQ(pub_qos.m_partition.names()[1], "partition_name_b"); EXPECT_EQ(pub_qos.m_publishMode.kind, ASYNCHRONOUS_PUBLISH_MODE); - EXPECT_EQ(pub_qos.m_publishMode.flow_controller_name, "test_flow_controller"); + EXPECT_EQ(0, strcmp(pub_qos.m_publishMode.flow_controller_name, "test_flow_controller")); EXPECT_EQ(pub_times.initialHeartbeatDelay, c_TimeZero); EXPECT_EQ(pub_times.heartbeatPeriod.seconds, 11); EXPECT_EQ(pub_times.heartbeatPeriod.nanosec, 32u); @@ -872,7 +872,7 @@ TEST_F(XMLProfileParserTests, XMLParserDefaultPublisherProfileDeprecated) EXPECT_EQ(pub_qos.m_partition.names()[0], "partition_name_a"); EXPECT_EQ(pub_qos.m_partition.names()[1], "partition_name_b"); EXPECT_EQ(pub_qos.m_publishMode.kind, ASYNCHRONOUS_PUBLISH_MODE); - EXPECT_EQ(pub_qos.m_publishMode.flow_controller_name, "test_flow_controller"); + EXPECT_EQ(0, strcmp(pub_qos.m_publishMode.flow_controller_name, "test_flow_controller")); EXPECT_EQ(pub_times.initialHeartbeatDelay, c_TimeZero); EXPECT_EQ(pub_times.heartbeatPeriod.seconds, 11); EXPECT_EQ(pub_times.heartbeatPeriod.nanosec, 32u);