diff --git a/iceoryx_posh/include/iceoryx_posh/internal/roudi/service_registry.hpp b/iceoryx_posh/include/iceoryx_posh/internal/roudi/service_registry.hpp index a384d2f5ae7..f0183e031bb 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/roudi/service_registry.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/roudi/service_registry.hpp @@ -75,6 +75,7 @@ class ServiceRegistry /// @todo #859 replace std::multimap with prefix tree ::std::multimap m_serviceMap; ::std::multimap m_instanceMap; + ::std::multimap m_eventMap; ServiceDescriptionVector_t m_serviceDescriptionVector; }; } // namespace roudi diff --git a/iceoryx_posh/source/roudi/service_registry.cpp b/iceoryx_posh/source/roudi/service_registry.cpp index 3971748deef..61d81d20abd 100644 --- a/iceoryx_posh/source/roudi/service_registry.cpp +++ b/iceoryx_posh/source/roudi/service_registry.cpp @@ -45,6 +45,7 @@ cxx::expected ServiceRegistry::add(const capro::ServiceD auto serviceIndex = m_serviceDescriptionVector.size() - 1; m_serviceMap.insert({serviceDescription.getServiceIDString(), serviceIndex}); m_instanceMap.insert({serviceDescription.getInstanceIDString(), serviceIndex}); + m_eventMap.insert({serviceDescription.getEventIDString(), serviceIndex}); return cxx::success<>(); } @@ -96,21 +97,21 @@ void ServiceRegistry::remove(const capro::ServiceDescription& serviceDescription { removeIndexFromMap(m_serviceMap, index); removeIndexFromMap(m_instanceMap, index); + removeIndexFromMap(m_eventMap, index); } } -/// @todo #415 add logic for event search once the prefix tree is integrated into the service registry void ServiceRegistry::find(ServiceDescriptionVector_t& searchResult, const cxx::optional& service, const cxx::optional& instance, - const cxx::optional& /*event*/) const noexcept + const cxx::optional& event) const noexcept { - cxx::vector intersection; - + ServiceDescriptionVector_t serviceInstanceResult; // Find (K1, K2) // O(log n + log n + max(#PossibleServices + #possiblesInstances) + #intersection) if (instance && service) { + cxx::vector intersection; cxx::vector possibleServices; cxx::vector possibleInstances; @@ -134,7 +135,7 @@ void ServiceRegistry::find(ServiceDescriptionVector_t& searchResult, for (auto& value : intersection) { - searchResult.push_back(m_serviceDescriptionVector[value]); + serviceInstanceResult.push_back(m_serviceDescriptionVector[value]); } } // Find (*, K2) @@ -144,7 +145,7 @@ void ServiceRegistry::find(ServiceDescriptionVector_t& searchResult, auto range = m_instanceMap.equal_range(instance.value()); for (auto entry = range.first; entry != range.second; ++entry) { - searchResult.push_back(m_serviceDescriptionVector[entry->second]); + serviceInstanceResult.push_back(m_serviceDescriptionVector[entry->second]); } } // Find (K1, *) @@ -154,14 +155,29 @@ void ServiceRegistry::find(ServiceDescriptionVector_t& searchResult, auto range = m_serviceMap.equal_range(service.value()); for (auto entry = range.first; entry != range.second; ++entry) { - searchResult.push_back(m_serviceDescriptionVector[entry->second]); + serviceInstanceResult.push_back(m_serviceDescriptionVector[entry->second]); } } else { // Find (*, *) // O(n) - searchResult = m_serviceDescriptionVector; + serviceInstanceResult = m_serviceDescriptionVector; + } + + if (event) + { + for (auto iterator = serviceInstanceResult.begin(); iterator != serviceInstanceResult.end(); iterator++) + { + if (iterator->serviceDescription.getEventIDString() == event.value()) + { + searchResult.push_back(*iterator); + } + } + } + else + { + searchResult = serviceInstanceResult; } } diff --git a/iceoryx_posh/test/integrationtests/test_service_discovery.cpp b/iceoryx_posh/test/integrationtests/test_service_discovery.cpp index 1d8ee0a74de..7ca1f620818 100644 --- a/iceoryx_posh/test/integrationtests/test_service_discovery.cpp +++ b/iceoryx_posh/test/integrationtests/test_service_discovery.cpp @@ -186,8 +186,7 @@ TEST_F(ServiceDiscovery_test, OfferDifferentServicesWithSameInstanceAndEvent) EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION3)); } -/// @todo #415 enable once the prefix tree is integrated into the service registry -TEST_F(ServiceDiscovery_test, DISABLED_FindServiceDoesNotReturnServiceWhenStringsDoNotMatch) +TEST_F(ServiceDiscovery_test, FindServiceDoesNotReturnServiceWhenStringsDoNotMatch) { ::testing::Test::RecordProperty("TEST_ID", "1984e907-e990-48b2-8cbd-eab3f67cd162"); const iox::capro::ServiceDescription SERVICE_DESCRIPTION1("service1", "instance1", "event1"); @@ -237,8 +236,7 @@ TEST_F(ServiceDiscovery_test, FindServiceWithInstanceAndEventWildcardReturnsAllM EXPECT_TRUE(serviceContainer.value() == serviceContainerExp); } -/// @todo #415 enable once the prefix tree is integrated into the service registry -TEST_F(ServiceDiscovery_test, DISABLED_FindServiceWithServiceWildcardReturnsCorrectServices) +TEST_F(ServiceDiscovery_test, FindServiceWithServiceWildcardReturnsCorrectServices) { ::testing::Test::RecordProperty("TEST_ID", "f4731a52-39d8-4d49-b247-008a2e9181f9"); const IdString_t INSTANCE = "instance"; @@ -286,8 +284,7 @@ TEST_F(ServiceDiscovery_test, FindServiceWithEventWildcardReturnsCorrectServices EXPECT_TRUE(serviceContainer.value() == serviceContainerExp); } -/// @todo #415 enable once the prefix tree is integrated into the service registry -TEST_F(ServiceDiscovery_test, DISABLED_FindServiceWithInstanceWildcardReturnsCorrectServices) +TEST_F(ServiceDiscovery_test, FindServiceWithInstanceWildcardReturnsCorrectServices) { ::testing::Test::RecordProperty("TEST_ID", "2ec4b422-3ded-4af3-9e72-3b870c55031c"); const IdString_t SERVICE = "service"; @@ -342,8 +339,7 @@ TEST_F(ServiceDiscovery_test, OfferSingleServiceMultiInstance) EXPECT_THAT(*serviceContainer.value().begin(), Eq(SERVICE_DESCRIPTION3)); } -/// @todo #415 enable once the prefix tree is integrated into the service registry -TEST_F(ServiceDiscovery_test, DISABLED_FindServiceReturnsCorrectServiceInstanceCombinations) +TEST_F(ServiceDiscovery_test, FindServiceReturnsCorrectServiceInstanceCombinations) { ::testing::Test::RecordProperty("TEST_ID", "360839a7-9309-4e7e-8e89-892097a87f7a"); @@ -423,8 +419,7 @@ TEST_F(ServiceDiscovery_test, FindServiceDoesNotReturnNotOfferedServices) EXPECT_THAT(serviceContainer.value().size(), Eq(0U)); } -/// @todo #415 enable once the prefix tree is integrated into the service registry -TEST_F(ServiceDiscovery_test, DISABLED_NonExistingServicesAreNotFound) +TEST_F(ServiceDiscovery_test, NonExistingServicesAreNotFound) { ::testing::Test::RecordProperty("TEST_ID", "86b87264-4df4-4d20-9357-06391ca1d57f"); const iox::capro::ServiceDescription SERVICE_DESCRIPTION("service", "instance", "event"); diff --git a/iceoryx_posh/test/moduletests/test_roudi_service_registry.cpp b/iceoryx_posh/test/moduletests/test_roudi_service_registry.cpp index 3ad66e9f3ca..fe9e7616cef 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_service_registry.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_service_registry.cpp @@ -183,16 +183,15 @@ TEST_F(ServiceRegistry_test, SingleServiceDescriptionCanBeFoundWithWildcardSearc EXPECT_THAT(searchResults[0].serviceDescription, Eq(ServiceDescription("Foo", "Bar", "Baz"))); } -/// @todo #415 enable once the prefix tree is integrated into the service registry -TEST_F(ServiceRegistry_test, DISABLED_SingleServiceDescriptionCanBeFoundWithEventName) +TEST_F(ServiceRegistry_test, SingleServiceDescriptionCanBeFoundWithEventName) { ::testing::Test::RecordProperty("TEST_ID", "6df8fd7d-e4d1-4c51-8ad7-2fbe82e4ed09"); - iox::capro::ServiceDescription service1("a", "b", "c"); - ASSERT_FALSE(sut.add(service1).has_error()); + iox::capro::ServiceDescription service("a", "b", "c"); + ASSERT_FALSE(sut.add(service).has_error()); sut.find(searchResults, iox::capro::Wildcard, iox::capro::Wildcard, iox::capro::IdString_t("c")); EXPECT_THAT(searchResults.size(), Eq(1)); - EXPECT_THAT(searchResults[0].serviceDescription, Eq(service1)); + EXPECT_THAT(searchResults[0].serviceDescription, Eq(service)); } TEST_F(ServiceRegistry_test, SingleServiceDescriptionCanBeFoundWithInstanceName) @@ -209,12 +208,12 @@ TEST_F(ServiceRegistry_test, SingleServiceDescriptionCanBeFoundWithInstanceName) TEST_F(ServiceRegistry_test, SingleServiceDescriptionCanBeFoundWithServiceName) { ::testing::Test::RecordProperty("TEST_ID", "0890013c-e14b-4ae2-89cb-757624c12b4e"); - iox::capro::ServiceDescription service1("a", "b", "c"); - ASSERT_FALSE(sut.add(service1).has_error()); + iox::capro::ServiceDescription service("a", "b", "c"); + ASSERT_FALSE(sut.add(service).has_error()); sut.find(searchResults, iox::capro::IdString_t("a"), iox::capro::Wildcard, iox::capro::Wildcard); EXPECT_THAT(searchResults.size(), Eq(1)); - EXPECT_THAT(searchResults[0].serviceDescription, Eq(service1)); + EXPECT_THAT(searchResults[0].serviceDescription, Eq(service)); } TEST_F(ServiceRegistry_test, EmptyAndNotEmptyServiceDescriptionsCanAllBeFoundWithWildcardSearch)