diff options
author | Aleksandar Kanchev <kanchev@itestra.com> | 2013-02-27 19:12:44 +0100 |
---|---|---|
committer | Aleksandar Kanchev <kanchev@itestra.com> | 2013-02-27 19:12:44 +0100 |
commit | 8b34ec2969ae17acad619819398805af1479ddd1 (patch) | |
tree | e7c16ef477c42eecf52b20cfe70c3ba9887a2921 | |
parent | 2440a20406ab5d263408963e254516196dd9323f (diff) | |
download | genivi-common-api-dbus-runtime-8b34ec2969ae17acad619819398805af1479ddd1.tar.gz |
correct getAvailableServiceInstances() wait logic
-rw-r--r-- | src/CommonAPI/DBus/DBusServiceRegistry.cpp | 11 | ||||
-rw-r--r-- | src/test/DBusProxyTest.cpp | 13 |
2 files changed, 15 insertions, 9 deletions
diff --git a/src/CommonAPI/DBus/DBusServiceRegistry.cpp b/src/CommonAPI/DBus/DBusServiceRegistry.cpp index 7b8ff19..f4ad413 100644 --- a/src/CommonAPI/DBus/DBusServiceRegistry.cpp +++ b/src/CommonAPI/DBus/DBusServiceRegistry.cpp @@ -149,17 +149,16 @@ std::vector<std::string> DBusServiceRegistry::getAvailableServiceInstances(const typedef std::chrono::high_resolution_clock clock; clock::time_point startTimePoint = clock::now(); - const bool dbusServicesResolved = dbusServiceChanged_.wait_for( + size_t wakeupCount = 0; + dbusServiceChanged_.wait_for( dbusServicesLock, timeout, [&] { - const bool done = dbusServiceResolvingCount == 0; - if (dbusServiceResolvingCount > 0) - dbusServiceResolvingCount--; - return done; + wakeupCount++; + return wakeupCount > dbusServiceResolvingCount; }); - if (!dbusServicesResolved) { + if (wakeupCount > 1) { getAvailableServiceInstances(serviceName, availableServiceInstances); break; } diff --git a/src/test/DBusProxyTest.cpp b/src/test/DBusProxyTest.cpp index fe09648..25b9a3b 100644 --- a/src/test/DBusProxyTest.cpp +++ b/src/test/DBusProxyTest.cpp @@ -175,9 +175,16 @@ TEST_F(ProxyTest, ServiceStatus) { registerTestStub(); std::vector<std::string> availableDBusServices; - availableDBusServices = proxyDBusConnection_->getDBusServiceRegistry()->getAvailableServiceInstances( - commonApiServiceName, - "local"); + + for (int i = 0; i < 5; i++) { + availableDBusServices = proxyDBusConnection_->getDBusServiceRegistry()->getAvailableServiceInstances( + commonApiServiceName, + "local"); + + if (!availableDBusServices.empty()) { + break; + } + } auto found = std::find(availableDBusServices.begin(), availableDBusServices.end(), commonApiAddress); |