Skip to content

Commit

Permalink
iox-#27 Fix finding ServiceDescription's whiche are used for both Pub…
Browse files Browse the repository at this point in the history
…Sub and ReqRes and restructure lambdas

Signed-off-by: Simon Hoinkis <[email protected]>
  • Loading branch information
mossmaurice committed Feb 21, 2022
1 parent febdc2a commit 27528c3
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions iceoryx_posh/source/runtime/service_discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,38 +45,40 @@ void ServiceDiscovery::findService(const cxx::optional<capro::IdString_t>& servi
return;
}

auto lambda = [&](const roudi::ServiceRegistry::ServiceDescriptionEntry& serviceEntry) {
switch (pattern)
{
case MessagingPattern::PUB_SUB:
{
if (serviceEntry.publisherCount > 0 && serviceEntry.serverCount == 0)
{
callableForEach(serviceEntry.serviceDescription);
}
break;
}
case MessagingPattern::REQ_RES:
{
if (serviceEntry.serverCount > 0 && serviceEntry.publisherCount == 0)
{
callableForEach(serviceEntry.serviceDescription);
}
break;
}
default:
{
LogWarn() << "ServiceDiscovery could not perform search due to unknown MessagingPattern!";
errorHandler(
Error::kPOSH__SERVICE_DISCOVERY_UNKNOWN_MESSAGE_PATTERN_PROVIDED, nullptr, ErrorLevel::MODERATE);
}
}
};

m_serviceRegistrySubscriber.take().and_then([&](popo::Sample<const roudi::ServiceRegistry>& serviceRegistrySample) {
m_serviceRegistry = *serviceRegistrySample;
});
m_serviceRegistry.find(service, instance, event, lambda);

switch (pattern)
{
case MessagingPattern::PUB_SUB:
{
m_serviceRegistry.find(
service, instance, event, [&](const roudi::ServiceRegistry::ServiceDescriptionEntry& serviceEntry) {
if (serviceEntry.publisherCount > 0)
{
callableForEach(serviceEntry.serviceDescription);
}
});
break;
}
case MessagingPattern::REQ_RES:
{
m_serviceRegistry.find(
service, instance, event, [&](const roudi::ServiceRegistry::ServiceDescriptionEntry& serviceEntry) {
if (serviceEntry.serverCount > 0)
{
callableForEach(serviceEntry.serviceDescription);
}
});
break;
}
default:
{
LogWarn() << "ServiceDiscovery could not perform search due to unknown MessagingPattern!";
errorHandler(Error::kPOSH__SERVICE_DISCOVERY_UNKNOWN_MESSAGE_PATTERN_PROVIDED, nullptr, ErrorLevel::MODERATE);
}
}
}

void ServiceDiscovery::enableEvent(popo::TriggerHandle&& triggerHandle, const ServiceDiscoveryEvent event) noexcept
Expand Down

0 comments on commit 27528c3

Please sign in to comment.