Skip to content

Commit

Permalink
Bugfix: Revert XML Flow controller names to const char* (#4911)
Browse files Browse the repository at this point in the history
* Refs #21054: Revert to const char* for flow controller names

Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>

* Refs #21054: Handle flow controller names in a XMLParser collection

Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>

* Refs #21054: Apply Miguel suggestion

Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>

* Refs #21054: Apply second suggestion

Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>

---------

Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
  • Loading branch information
Mario-DL authored and JesusPoderoso committed Jun 10, 2024
1 parent 88d88d2 commit 1960117
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 39 deletions.
4 changes: 2 additions & 2 deletions include/fastdds/dds/core/policy/QosPolicies.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2046,7 +2046,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
{
Expand All @@ -2058,7 +2058,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);
}

Expand Down
2 changes: 1 addition & 1 deletion include/fastdds/rtps/attributes/WriterAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#ifndef FASTDDS_RTPS_FLOWCONTROL_FLOWCONTROLLERDESCRIPTOR_HPP
#define FASTDDS_RTPS_FLOWCONTROL_FLOWCONTROLLERDESCRIPTOR_HPP

#include <string>

#include <fastdds/rtps/attributes/ThreadSettings.hpp>

#include "FlowControllerConsts.hpp"
Expand All @@ -35,7 +33,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.
//!
Expand Down
13 changes: 13 additions & 0 deletions include/fastrtps/xmlparser/XMLParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,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(
Expand Down Expand Up @@ -693,6 +701,11 @@ class XMLParser
tinyxml2::XMLElement* elem,
eprosima::fastdds::rtps::BuiltinTransports* bt,
uint8_t ident);

private:

static std::mutex collections_mtx_;
static std::set<std::string> flow_controller_descriptor_names_;
};

} // namespace xmlparser
Expand Down
31 changes: 25 additions & 6 deletions src/cpp/rtps/xmlparser/XMLElementParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ namespace eprosima {
namespace fastrtps {
namespace xmlparser {

std::mutex XMLParser::collections_mtx_;
std::set<std::string> XMLParser::flow_controller_descriptor_names_;

using namespace eprosima::fastrtps::rtps;
using namespace eprosima::fastdds::xml::detail;

Expand Down Expand Up @@ -1052,13 +1055,22 @@ XMLP_ret XMLParser::getXMLFlowControllerDescriptorList(

if (strcmp(name, NAME) == 0)
{
std::lock_guard<std::mutex> 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)
Expand Down Expand Up @@ -2838,13 +2850,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<std::mutex> 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
{
Expand Down
7 changes: 7 additions & 0 deletions src/cpp/rtps/xmlparser/XMLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2595,6 +2595,13 @@ XMLP_ret XMLParser::fillDataNode(
return XMLP_ret::XML_OK;
}

XMLP_ret XMLParser::clear()
{
std::lock_guard<std::mutex> lock(collections_mtx_);
flow_controller_descriptor_names_.clear();
return XMLP_ret::XML_OK;
}

} // namespace xmlparser
} // namespace fastrtps
} // namespace eprosima
3 changes: 3 additions & 0 deletions src/cpp/rtps/xmlparser/XMLProfileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,4 +854,7 @@ void XMLProfileManager::DeleteInstance()
}
dynamic_types_.clear();
}

// Clear XML Parser collections
XMLParser::clear();
}
2 changes: 1 addition & 1 deletion test/unittest/dds/publisher/PublisherTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,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())
{
Expand Down
16 changes: 4 additions & 12 deletions test/unittest/xmlparser/XMLProfileParserTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,7 @@ class XMLProfileParserTests : public XMLProfileParserBasicTests, public testing:

std::string xml_filename_ = "test_xml_profile.xml";

<<<<<<< HEAD
const std::pair<std::string, std::string> c_environment_values_[161]
=======
const std::pair<std::string, std::string> c_environment_values_[167]
>>>>>>> e6044e011 (Add XML configuration for FlowControllerDescriptor to 2.x (#4893))
{
{"XML_PROFILES_ENV_VAR_1", "123"},
{"XML_PROFILES_ENV_VAR_2", "4"},
Expand Down Expand Up @@ -296,17 +292,13 @@ class XMLProfileParserTests : public XMLProfileParserBasicTests, public testing:
{"XML_PROFILES_ENV_VAR_158", "-1"},
{"XML_PROFILES_ENV_VAR_159", "0"},
{"XML_PROFILES_ENV_VAR_160", "0"},
<<<<<<< HEAD
{"XML_PROFILES_ENV_VAR_161", "-1"}
=======
{"XML_PROFILES_ENV_VAR_161", "-1"},
{"XML_PROFILES_ENV_VAR_162", "ON"},
{"XML_PROFILES_ENV_VAR_163", "test_flow_controller"},
{"XML_PROFILES_ENV_VAR_164", "HIGH_PRIORITY"},
{"XML_PROFILES_ENV_VAR_165", "2048"},
{"XML_PROFILES_ENV_VAR_166", "45"},
{"XML_PROFILES_ENV_VAR_167", "test_flow_controller"}
>>>>>>> e6044e011 (Add XML configuration for FlowControllerDescriptor to 2.x (#4893))
};

};
Expand Down Expand Up @@ -889,7 +881,7 @@ TEST_P(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);
Expand Down Expand Up @@ -965,7 +957,7 @@ TEST_F(XMLProfileParserBasicTests, 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);
Expand Down Expand Up @@ -1039,7 +1031,7 @@ TEST_P(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);
Expand Down Expand Up @@ -1113,7 +1105,7 @@ TEST_F(XMLProfileParserBasicTests, 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);
Expand Down
15 changes: 1 addition & 14 deletions versions.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
Forthcoming
-----------

<<<<<<< HEAD
=======
* Added new `flow_controller_descriptor_list` XML configuration.

Version 2.14.0
--------------

* Added authentication handshake properties.
* Added methods OpenOutputChannels and CloseOutputChannels to TransportInterface with LocatorSelectorEntry argument.
* Added `netmask_filter`, `allowlist` and `blocklist` transport configuration options.
* Added extra configuration options for the builitin transports.
* Limit the amount of listening ports for TCP servers to 1.

>>>>>>> e6044e011 (Add XML configuration for FlowControllerDescriptor to 2.x (#4893))
Version 2.13.0
--------------

Expand All @@ -29,6 +15,7 @@ Version 2.13.0
* Enable support for DataRepresentationQos to select the CDR encoding.
* Added authentication handshake properties.
* Added `max_message_size` property to limit output datagrams size
* Added new `flow_controller_descriptor_list` XML configuration.

Version 2.12.0
--------------
Expand Down

0 comments on commit 1960117

Please sign in to comment.