Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 68 additions & 84 deletions src/DiscoveryServerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ DiscoveryServerManager::DiscoveryServerManager(
tinyxml2::XMLPrinter printer;
profiles->Accept(&printer);
std::string xmlString = R"(")" + std::string(printer.CStr()) + R"(")";
if (RETCODE_OK ==
DomainParticipantFactory::get_instance()->load_XML_profiles_string(xmlString.c_str(),
if (RETCODE_OK == DomainParticipantFactory::get_instance()->load_XML_profiles_string(xmlString.c_str(),
std::string(printer.CStr()).length()))
{
LOG_INFO("Profiles parsed successfully.");
Expand All @@ -134,7 +133,7 @@ DiscoveryServerManager::DiscoveryServerManager(
auto topic_desc_it = topic_description_profiles_map.find(topic_profile_name);
if (topic_desc_it == topic_description_profiles_map.end())
{
auto &topic_desc = topic_description_profiles_map[topic_profile_name];
auto& topic_desc = topic_description_profiles_map[topic_profile_name];
if (!fill_topic_description_profile(topic_profile, topic_desc))
{
LOG_ERROR("Error parsing topic profiles");
Expand Down Expand Up @@ -704,8 +703,8 @@ Topic* DiscoveryServerManager::getParticipantTopicByName(
}

bool DiscoveryServerManager::fill_topic_description_profile(
tinyxml2::XMLElement* elem,
TopicDescriptionItem& topic_description)
tinyxml2::XMLElement* elem,
TopicDescriptionItem& topic_description)
{
/*
<xs:complexType name="topicDescriptionType">
Expand All @@ -714,50 +713,50 @@ bool DiscoveryServerManager::fill_topic_description_profile(
<xs:element name="dataType" type="stringType" minOccurs="0"/>
</xs:all>
</xs:complexType>
*/
*/

bool ret = true;
tinyxml2::XMLElement* p_aux0 = elem->FirstChildElement();
const char* name = nullptr;
for (; p_aux0 != NULL; p_aux0 = p_aux0->NextSiblingElement())
{
name = p_aux0->Name();
name = p_aux0->Name();

if (strcmp(name, DSxmlparser::NAME) == 0)
if (strcmp(name, DSxmlparser::NAME) == 0)
{
// name - stringType
const char* text = p_aux0->GetText();
if (nullptr != text)
{
// name - stringType
const char* text = p_aux0->GetText();
if (nullptr != text)
{
topic_description.name = text;
}
else
{
LOG_ERROR("<" << p_aux0->Value() << "> GetText XML_ERROR");
ret = false;
break;
}
topic_description.name = text;
}
else if (strcmp(name, DSxmlparser::DATA_TYPE) == 0)
else
{
// dataType - stringType
const char* text = p_aux0->GetText();
if (nullptr != text)
{
topic_description.type_name = text;
}
else
{
LOG_ERROR("<" << p_aux0->Value() << "> GetText XML_ERROR");
ret = false;
break;
}
LOG_ERROR("<" << p_aux0->Value() << "> GetText XML_ERROR");
ret = false;
break;
}
}
else if (strcmp(name, DSxmlparser::DATA_TYPE) == 0)
{
// dataType - stringType
const char* text = p_aux0->GetText();
if (nullptr != text)
{
topic_description.type_name = text;
}
else
{
LOG_ERROR("Invalid element found into 'topicDescriptionType'. Name: " << name);
LOG_ERROR("<" << p_aux0->Value() << "> GetText XML_ERROR");
ret = false;
break;
}
}
else
{
LOG_ERROR("Invalid element found into 'topicDescriptionType'. Name: " << name);
ret = false;
}
}

return ret;
Expand Down Expand Up @@ -925,9 +924,7 @@ void DiscoveryServerManager::loadServer(
GuidPrefix_t& prefix = dpQOS.wire_protocol().prefix;
const char* cprefix = server->Attribute(DSxmlparser::PREFIX);

if (cprefix != nullptr &&
!(std::istringstream(cprefix) >> prefix) &&
(prefix == c_GuidPrefix_Unknown))
if (cprefix != nullptr && !(std::istringstream(cprefix) >> prefix) && (prefix == c_GuidPrefix_Unknown))
{
LOG_ERROR("Servers cannot have a framework provided prefix"); // at least for now
return;
Expand All @@ -936,8 +933,7 @@ void DiscoveryServerManager::loadServer(
GUID_t guid(prefix, c_EntityId_RTPSParticipant);

// Check if the guidPrefix is already in use (there is a mistake on config file)
if (enable_prefix_validation &&
servers.find(guid) != servers.end())
if (enable_prefix_validation && servers.find(guid) != servers.end())
{
LOG_ERROR("DiscoveryServerManager detected two servers sharing the same prefix " << prefix);
return;
Expand All @@ -946,8 +942,7 @@ void DiscoveryServerManager::loadServer(
// replace the DomainParticipantQOS builtin lists with the ones from server_locators (if present)
// note that a previous call to DiscoveryServerManager::MapServerInfo
serverLocator_map::mapped_type& lists = server_locators[guid];
if (!lists.first.empty() ||
!lists.second.empty())
if (!lists.first.empty() || !lists.second.empty())
{
// server elements take precedence over profile ones
// I copy them because other servers may need this values
Expand All @@ -967,7 +962,8 @@ void DiscoveryServerManager::loadServer(
// We define the PDP as external (when moved to fast library it would be SERVER)
DiscoverySettings& b = dpQOS.wire_protocol().builtin.discovery_config;
(void)b;
assert(b.discoveryProtocol == eprosima::fastdds::rtps::DiscoveryProtocol::SERVER || b.discoveryProtocol == eprosima::fastdds::rtps::DiscoveryProtocol::BACKUP);
assert(b.discoveryProtocol == eprosima::fastdds::rtps::DiscoveryProtocol::SERVER ||
b.discoveryProtocol == eprosima::fastdds::rtps::DiscoveryProtocol::BACKUP);

// Create the participant or the associated events
DelayedParticipantCreation event(creation_time, std::move(dpQOS), &DiscoveryServerManager::addServer);
Expand Down Expand Up @@ -1053,8 +1049,7 @@ void DiscoveryServerManager::loadClient(
if (dpQOS.wire_protocol().builtin.discovery_config.discoveryProtocol != DiscoveryProtocol::CLIENT &&
dpQOS.wire_protocol().builtin.discovery_config.discoveryProtocol != DiscoveryProtocol::SUPER_CLIENT)
{
LOG_ERROR(
"DiscoveryServerManager::loadClient try to create a client with an incompatible profile: " <<
LOG_ERROR("DiscoveryServerManager::loadClient try to create a client with an incompatible profile: " <<
profile_name);
return;
}
Expand Down Expand Up @@ -1103,7 +1098,7 @@ void DiscoveryServerManager::loadClient(
if (!p4)
{
// try to find a descriptor matching the listener port setup
if (p4 = std::dynamic_pointer_cast<TCPv4TransportDescriptor>(sp))
if ((p4 = std::dynamic_pointer_cast<TCPv4TransportDescriptor>(sp)))
{
continue;
}
Expand Down Expand Up @@ -1267,8 +1262,8 @@ void DiscoveryServerManager::loadSimple(
if (dpQOS.wire_protocol().builtin.discovery_config.discoveryProtocol != DiscoveryProtocol::SIMPLE)
{
LOG_ERROR(
"DiscoveryServerManager::loadSimple try to create a simple participant with an incompatible profile: " <<
profile_name);
"DiscoveryServerManager::loadSimple try to create a simple participant with an incompatible profile: "
<< profile_name);
return;
}

Expand Down Expand Up @@ -1419,9 +1414,8 @@ void DiscoveryServerManager::loadSubscriber(
endpoint_profile = std::string(profile_name);
}

DelayedEndpointCreation<DataReader> event(creation_time, topic_description.name,
topic_description.type_name, topic_name, endpoint_profile, part_guid, pDE,
participant_creation_event);
DelayedEndpointCreation<DataReader> event(creation_time, topic_description.name, topic_description.type_name,
topic_name, endpoint_profile, part_guid, pDE, participant_creation_event);

if (creation_time == getTime())
{
Expand Down Expand Up @@ -1525,9 +1519,8 @@ void DiscoveryServerManager::loadPublisher(
endpoint_profile = std::string(profile_name);
}

DelayedEndpointCreation<DataWriter> event(creation_time, topic_description.name,
topic_description.type_name, topic_name, endpoint_profile, part_guid, pDE,
participant_creation_event);
DelayedEndpointCreation<DataWriter> event(creation_time, topic_description.name, topic_description.type_name,
topic_name, endpoint_profile, part_guid, pDE, participant_creation_event);

if (creation_time == getTime())
{
Expand Down Expand Up @@ -1637,8 +1630,7 @@ void DiscoveryServerManager::MapServerInfo(
// I must load the prefix from the profile
// retrieve profile QOS
pqos = std::make_shared<DomainParticipantQos>();
if (RETCODE_OK !=
DomainParticipantFactory::get_instance()->get_participant_qos_from_profile(profile_name, *pqos))
if (RETCODE_OK != DomainParticipantFactory::get_instance()->get_participant_qos_from_profile(profile_name, *pqos))
{
LOG_ERROR("DiscoveryServerManager::loadServer couldn't load profile " << profile_name);
return;
Expand Down Expand Up @@ -1690,8 +1682,8 @@ void DiscoveryServerManager::on_participant_discovery(
return;
}

LOG_INFO("Participant " << participant->get_qos().name().to_string() << " reports a participant "
<< info.participant_name << " is " << status << ". Prefix " << partid);
LOG_INFO("Participant " << participant->get_qos().name().to_string() << " reports a participant " <<
info.participant_name << " is " << status << ". Prefix " << partid);

std::chrono::steady_clock::time_point callback_time = std::chrono::steady_clock::now();
{
Expand All @@ -1714,8 +1706,7 @@ void DiscoveryServerManager::on_participant_discovery(
{
case ParticipantDiscoveryStatus::DISCOVERED_PARTICIPANT:
{
state.AddParticipant(srcGuid, srcName, partid, info.participant_name.to_string(), callback_time,
server);
state.AddParticipant(srcGuid, srcName, partid, info.participant_name.to_string(), callback_time, server);
break;
}
case ParticipantDiscoveryStatus::REMOVED_PARTICIPANT:
Expand Down Expand Up @@ -1765,8 +1756,7 @@ void DiscoveryServerManager::on_data_reader_discovery(
if (!no_callbacks)
{
// is one of ours?
if ((it = servers.find(partid)) != servers.end() ||
(it = clients.find(partid)) != clients.end() ||
if ((it = servers.find(partid)) != servers.end() || (it = clients.find(partid)) != clients.end() ||
(it = simples.find(partid)) != simples.end())
{
part_name = it->second->get_qos().name().to_string();
Expand Down Expand Up @@ -1806,9 +1796,9 @@ void DiscoveryServerManager::on_data_reader_discovery(
break;
}

LOG_INFO("Participant " << participant->get_qos().name().to_string() << " reports a subscriber of participant "
<< part_name << " is " << reason << " with typename: " << info.type_name
<< " topic: " << info.topic_name << " GUID: " << subsid);
LOG_INFO("Participant " << participant->get_qos().name().to_string() << " reports a subscriber of participant " <<
part_name << " is " << reason << " with typename: " << info.type_name << " topic: " << info.topic_name <<
" GUID: " << subsid);
}

void DiscoveryServerManager::on_data_writer_discovery(
Expand Down Expand Up @@ -1847,8 +1837,7 @@ void DiscoveryServerManager::on_data_writer_discovery(
// is one of ours?
participant_map::iterator it;

if ((it = servers.find(partid)) != servers.end() ||
(it = clients.find(partid)) != clients.end() ||
if ((it = servers.find(partid)) != servers.end() || (it = clients.find(partid)) != clients.end() ||
(it = simples.find(partid)) != simples.end())
{
part_name = it->second->get_qos().name().to_string();
Expand Down Expand Up @@ -1879,13 +1868,8 @@ void DiscoveryServerManager::on_data_writer_discovery(
{
case DS::DISCOVERED_WRITER:

state.AddDataWriter(srcGuid,
srcName,
partid,
pubsid,
info.type_name.to_string(),
info.topic_name.to_string(),
callback_time);
state.AddDataWriter(srcGuid, srcName, partid, pubsid, info.type_name.to_string(),
info.topic_name.to_string(), callback_time);
break;
case DS::REMOVED_WRITER:

Expand All @@ -1895,9 +1879,9 @@ void DiscoveryServerManager::on_data_writer_discovery(
break;
}

LOG_INFO("Participant " << participant->get_qos().name().to_string() << " reports a publisher of participant "
<< part_name << " is " << reason << " with typename: " << info.type_name
<< " topic: " << info.topic_name << " GUID: " << pubsid);
LOG_INFO("Participant " << participant->get_qos().name().to_string() << " reports a publisher of participant " <<
part_name << " is " << reason << " with typename: " << info.type_name << " topic: " << info.topic_name <<
" GUID: " << pubsid);
}

void DiscoveryServerManager::on_liveliness_changed(
Expand Down Expand Up @@ -2002,15 +1986,15 @@ Snapshot& DiscoveryServerManager::takeSnapshot(
temp.insert(clients.begin(), clients.end());
temp.insert(simples.begin(), simples.end());

std::function<bool(const participant_map::value_type&, const Snapshot::value_type&)> pred(
[](const participant_map::value_type& p1, const Snapshot::value_type& p2)
{
return p1.first == p2.endpoint_guid;
}
);
std::function<bool(const participant_map::value_type&,
const Snapshot::value_type&)> pred([](const participant_map::value_type& p1, const Snapshot::value_type& p2)
{
return p1.first == p2.endpoint_guid;
}
);

std::pair<participant_map::const_iterator, Snapshot::const_iterator> res =
std::mismatch(temp.cbegin(), temp.cend(), shot.cbegin(), shot.cend(), pred);
std::pair<participant_map::const_iterator, Snapshot::const_iterator> res = std::mismatch(temp.cbegin(), temp.cend(),
shot.cbegin(), shot.cend(), pred);

while (res.first != temp.end())
{
Expand Down
Loading