Skip to content

Commit

Permalink
Fix log category name macro collision in MacOS (#5585)
Browse files Browse the repository at this point in the history
* Refs #22657: BB test

Signed-off-by: Mario Domínguez López <mariodominguez@eprosima.com>

* Refs #22657: Fix

Signed-off-by: Mario Domínguez López <mariodominguez@eprosima.com>

* Refs #22657: Make test available in all platforms

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

* Refs #22657: Apply missing Miguels suggestion

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

---------

Signed-off-by: Mario Domínguez López <mariodominguez@eprosima.com>
Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
(cherry picked from commit a59d32f)

# Conflicts:
#	src/cpp/fastdds/domain/DomainParticipantFactory.cpp
#	src/cpp/rtps/RTPSDomain.cpp
  • Loading branch information
Mario-DL authored and mergify[bot] committed Jan 24, 2025
1 parent 859ebab commit 5141ebf
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 6 deletions.
117 changes: 114 additions & 3 deletions src/cpp/fastdds/domain/DomainParticipantFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,61 @@ ReturnCode_t DomainParticipantFactory::get_participant_qos_from_profile(
return RETCODE_BAD_PARAMETER;
}

<<<<<<< HEAD
=======
ReturnCode_t DomainParticipantFactory::get_participant_qos_from_xml(
const std::string& xml,
DomainParticipantQos& qos) const
{
ParticipantAttributes attr;
if (XMLP_ret::XML_OK == XMLProfileManager::fill_participant_attributes_from_xml(xml, attr, false))
{
qos = default_participant_qos_;
utils::set_qos_from_attributes(qos, attr.rtps);
return RETCODE_OK;
}

return RETCODE_BAD_PARAMETER;
}

ReturnCode_t DomainParticipantFactory::get_participant_qos_from_xml(
const std::string& xml,
DomainParticipantQos& qos,
const std::string& profile_name) const
{
if (profile_name.empty())
{
EPROSIMA_LOG_ERROR(DDS_DOMAIN, "Provided profile name must be non-empty");
return RETCODE_BAD_PARAMETER;
}

ParticipantAttributes attr;
if (XMLP_ret::XML_OK == XMLProfileManager::fill_participant_attributes_from_xml(xml, attr, true, 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_default_participant_qos_from_xml(
const std::string& xml,
DomainParticipantQos& qos) const
{
ParticipantAttributes attr;
if (XMLP_ret::XML_OK == XMLProfileManager::fill_default_participant_attributes_from_xml(xml, attr, true))
{
qos = default_participant_qos_;
utils::set_qos_from_attributes(qos, attr.rtps);
return RETCODE_OK;
}

return RETCODE_BAD_PARAMETER;
}

>>>>>>> a59d32fc (Fix log category name macro collision in `MacOS` (#5585))
ReturnCode_t DomainParticipantFactory::get_participant_extended_qos_from_profile(
const std::string& profile_name,
DomainParticipantExtendedQos& extended_qos) const
Expand All @@ -349,6 +404,62 @@ ReturnCode_t DomainParticipantFactory::get_participant_extended_qos_from_profile
ParticipantAttributes attr;
if (XMLP_ret::XML_OK == XMLProfileManager::fillParticipantAttributes(profile_name, attr, false))
{
<<<<<<< HEAD
=======
extended_qos = default_participant_qos_;
utils::set_extended_qos_from_attributes(extended_qos, attr);
return RETCODE_OK;
}

return RETCODE_BAD_PARAMETER;
}

ReturnCode_t DomainParticipantFactory::get_participant_extended_qos_from_xml(
const std::string& xml,
DomainParticipantExtendedQos& extended_qos) const
{
ParticipantAttributes attr;
if (XMLP_ret::XML_OK == XMLProfileManager::fill_participant_attributes_from_xml(xml, attr, false))
{
extended_qos = default_participant_qos_;
utils::set_extended_qos_from_attributes(extended_qos, attr);
return RETCODE_OK;
}

return RETCODE_BAD_PARAMETER;
}

ReturnCode_t DomainParticipantFactory::get_participant_extended_qos_from_xml(
const std::string& xml,
DomainParticipantExtendedQos& extended_qos,
const std::string& profile_name) const
{
if (profile_name.empty())
{
EPROSIMA_LOG_ERROR(DDS_DOMAIN, "Provided profile name must be non-empty");
return RETCODE_BAD_PARAMETER;
}

ParticipantAttributes attr;
if (XMLP_ret::XML_OK == XMLProfileManager::fill_participant_attributes_from_xml(xml, attr, true, profile_name))
{
extended_qos = default_participant_qos_;
utils::set_extended_qos_from_attributes(extended_qos, attr);
return RETCODE_OK;
}

return RETCODE_BAD_PARAMETER;
}

ReturnCode_t DomainParticipantFactory::get_default_participant_extended_qos_from_xml(
const std::string& xml,
DomainParticipantExtendedQos& extended_qos) const
{
ParticipantAttributes attr;
if (XMLP_ret::XML_OK == XMLProfileManager::fill_default_participant_attributes_from_xml(xml, attr, true))
{
extended_qos = default_participant_qos_;
>>>>>>> a59d32fc (Fix log category name macro collision in `MacOS` (#5585))
utils::set_extended_qos_from_attributes(extended_qos, attr);
return RETCODE_OK;
}
Expand Down Expand Up @@ -407,7 +518,7 @@ ReturnCode_t DomainParticipantFactory::load_XML_profiles_file(
{
if (XMLP_ret::XML_ERROR == XMLProfileManager::loadXMLFile(xml_profile_file))
{
EPROSIMA_LOG_ERROR(DOMAIN, "Problem loading XML file '" << xml_profile_file << "'");
EPROSIMA_LOG_ERROR(DDS_DOMAIN, "Problem loading XML file '" << xml_profile_file << "'");
return RETCODE_ERROR;
}
return RETCODE_OK;
Expand All @@ -419,7 +530,7 @@ ReturnCode_t DomainParticipantFactory::load_XML_profiles_string(
{
if (XMLP_ret::XML_ERROR == XMLProfileManager::loadXMLString(data, length))
{
EPROSIMA_LOG_ERROR(DOMAIN, "Problem loading XML string");
EPROSIMA_LOG_ERROR(DDS_DOMAIN, "Problem loading XML string");
return RETCODE_ERROR;
}
return RETCODE_OK;
Expand All @@ -431,7 +542,7 @@ ReturnCode_t DomainParticipantFactory::check_xml_static_discovery(
xmlparser::XMLEndpointParser parser;
if (XMLP_ret::XML_OK != parser.loadXMLFile(xml_file))
{
EPROSIMA_LOG_ERROR(DOMAIN, "Error parsing xml file");
EPROSIMA_LOG_ERROR(DDS_DOMAIN, "Error parsing xml file");
return RETCODE_ERROR;
}
return RETCODE_OK;
Expand Down
63 changes: 60 additions & 3 deletions src/cpp/rtps/RTPSDomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ RTPSParticipant* RTPSDomainImpl::clientServerEnvironmentCreationOverride(
// Check the specified discovery protocol: if other than simple it has priority over ros environment variable
if (att.builtin.discovery_config.discoveryProtocol != DiscoveryProtocol::SIMPLE)
{
EPROSIMA_LOG_INFO(DOMAIN, "Detected non simple discovery protocol attributes."
EPROSIMA_LOG_INFO(RTPS_DOMAIN, "Detected non simple discovery protocol attributes."
<< " Ignoring auto default client-server setup.");
return nullptr;
}
Expand All @@ -522,9 +522,66 @@ RTPSParticipant* RTPSDomainImpl::clientServerEnvironmentCreationOverride(
LocatorList_t& server_list = client_att.builtin.discovery_config.m_DiscoveryServers;
if (load_environment_server_info(server_list) && server_list.empty())
{
<<<<<<< HEAD
// It's not an error, the environment variable may not be set. Any issue with environment
// variable syntax is EPROSIMA_LOG_ERROR already
return nullptr;
=======
// Retrieve the info from the environment variable
LocatorList_t& server_list = client_att.builtin.discovery_config.m_DiscoveryServers;
if (load_environment_server_info(server_list) && server_list.empty())
{
// It's not an error, the environment variable may not be set. Any issue with environment
// variable syntax is EPROSIMA_LOG_ERROR already
return nullptr;
}

// Check if some address requires the UDPv6, TCPv4 or TCPv6 transport
if (server_list.has_kind<LOCATOR_KIND_UDPv6>() &&
!has_user_transport<fastdds::rtps::UDPv6TransportDescriptor>(client_att))
{
// Extend builtin transports with the UDPv6 transport
auto descriptor = std::make_shared<fastdds::rtps::UDPv6TransportDescriptor>();
descriptor->sendBufferSize = client_att.sendSocketBufferSize;
descriptor->receiveBufferSize = client_att.listenSocketBufferSize;
client_att.userTransports.push_back(std::move(descriptor));
}
if (server_list.has_kind<LOCATOR_KIND_TCPv4>() &&
!has_user_transport<fastdds::rtps::TCPv4TransportDescriptor>(client_att))
{
// Extend builtin transports with the TCPv4 transport
auto descriptor = std::make_shared<fastdds::rtps::TCPv4TransportDescriptor>();
// Add automatic port
descriptor->add_listener_port(0);
descriptor->sendBufferSize = client_att.sendSocketBufferSize;
descriptor->receiveBufferSize = client_att.listenSocketBufferSize;
client_att.userTransports.push_back(std::move(descriptor));
}
if (server_list.has_kind<LOCATOR_KIND_TCPv6>() &&
!has_user_transport<fastdds::rtps::TCPv6TransportDescriptor>(client_att))
{
// Extend builtin transports with the TCPv6 transport
auto descriptor = std::make_shared<fastdds::rtps::TCPv6TransportDescriptor>();
// Add automatic port
descriptor->add_listener_port(0);
descriptor->sendBufferSize = client_att.sendSocketBufferSize;
descriptor->receiveBufferSize = client_att.listenSocketBufferSize;
client_att.userTransports.push_back(std::move(descriptor));
}

EPROSIMA_LOG_INFO(RTPS_DOMAIN, "Detected auto client-server environment variable."
<< "Trying to create client with the default server setup: "
<< client_att.builtin.discovery_config.m_DiscoveryServers);

client_att.builtin.discovery_config.discoveryProtocol = DiscoveryProtocol::CLIENT;
// RemoteServerAttributes already fill in above

// Check if the client must become a super client
if (ros_super_client_env())
{
client_att.builtin.discovery_config.discoveryProtocol = DiscoveryProtocol::SUPER_CLIENT;
}
>>>>>>> a59d32fc (Fix log category name macro collision in `MacOS` (#5585))
}

// Check if some address requires the UDPv6, TCPv4 or TCPv6 transport
Expand Down Expand Up @@ -577,13 +634,13 @@ RTPSParticipant* RTPSDomainImpl::clientServerEnvironmentCreationOverride(
if (nullptr != part)
{
// Client successfully created
EPROSIMA_LOG_INFO(DOMAIN, "Auto default server-client setup. Default client created.");
EPROSIMA_LOG_INFO(RTPS_DOMAIN, "Auto default server-client setup. Default client created.");
part->mp_impl->client_override(true);
return part;
}

// Unable to create auto server-client default participants
EPROSIMA_LOG_ERROR(DOMAIN, "Auto default server-client setup. Unable to create the client.");
EPROSIMA_LOG_ERROR(RTPS_DOMAIN, "Auto default server-client setup. Unable to create the client.");
return nullptr;
}

Expand Down
40 changes: 40 additions & 0 deletions test/blackbox/common/DDSBlackboxTestsBasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,46 @@ TEST(DDSBasic, reliable_volatile_writer_secure_builtin_no_potential_deadlock)
writer.destroy();
}

TEST(DDSBasic, participant_factory_output_log_error_no_macro_collision)
{
using Log = eprosima::fastdds::dds::Log;
using LogConsumer = eprosima::fastdds::dds::LogConsumer;

// A LogConsumer that just counts the number of entries consumed
struct TestConsumer : public LogConsumer
{
TestConsumer(
std::atomic_size_t& n_logs_ref)
: n_logs_(n_logs_ref)
{
}

void Consume(
const Log::Entry&) override
{
++n_logs_;
}

private:

std::atomic_size_t& n_logs_;
};

// Counter for log entries
std::atomic<size_t>n_logs{};

// Prepare Log module to check that no SECURITY errors are produced
Log::SetCategoryFilter(std::regex("DOMAIN"));
Log::SetVerbosity(Log::Kind::Error);
Log::RegisterConsumer(std::unique_ptr<LogConsumer>(new TestConsumer(n_logs)));

auto dpf = DomainParticipantFactory::get_shared_instance();
DomainParticipantQos qos;
dpf->get_participant_qos_from_xml("", qos, "");
Log::Flush();
ASSERT_GE(n_logs.load(), 1u);
}

} // namespace dds
} // namespace fastdds
} // namespace eprosima

0 comments on commit 5141ebf

Please sign in to comment.