diff options
author | Stefan Laner <laner@itestra.de> | 2013-12-04 19:57:20 +0100 |
---|---|---|
committer | Stefan Laner <laner@itestra.de> | 2013-12-04 20:02:27 +0100 |
commit | 0b6e26e261510c01af95ea3ee225815ad28750f7 (patch) | |
tree | 5088167c73c53cd6f5b448d998473a3b108c1197 | |
parent | 8b93559fdcd3bf76526287bba288fbc8b6a77050 (diff) | |
download | genivi-common-api-dbus-runtime-0b6e26e261510c01af95ea3ee225815ad28750f7.tar.gz |
Broke shared_ptr cycle between generated stub, DBusStubAdapter and
DBusStubAdapterHelper by using a weak_ptr. Also removed some cout calls
in tests and updated generated code for tests.
Change-Id: I54399dabeedb2960b91df36772d64d1efc6030d6
10 files changed, 20 insertions, 26 deletions
diff --git a/src/CommonAPI/DBus/DBusStubAdapterHelper.h b/src/CommonAPI/DBus/DBusStubAdapterHelper.h index 7030637..4448f32 100644 --- a/src/CommonAPI/DBus/DBusStubAdapterHelper.h +++ b/src/CommonAPI/DBus/DBusStubAdapterHelper.h @@ -67,7 +67,7 @@ class DBusStubAdapterHelper: public virtual DBusStubAdapter { virtual void init(std::shared_ptr<DBusStubAdapter> instance) { DBusStubAdapter::init(instance); std::shared_ptr<StubAdapterType> stubAdapter = std::dynamic_pointer_cast<StubAdapterType>(instance); - remoteEventHandler_ = stub_->initStubAdapter(stubAdapter); + remoteEventHandler_ = stub_.lock()->initStubAdapter(stubAdapter); } virtual void deinit() { @@ -94,7 +94,7 @@ class DBusStubAdapterHelper: public virtual DBusStubAdapter { bool dbusMessageHandled = false; //To prevent the destruction of the stub whilst still handling a message - auto stubSafety = stub_; + auto stubSafety = stub_.lock(); if (stubSafety && foundInterfaceMemberHandler) { StubDispatcher* stubDispatcher = static_cast<StubDispatcher*>(findIterator->second); dbusMessageHandled = stubDispatcher->dispatchDBusMessage(dbusMessage, stubSafety, *this); @@ -105,7 +105,7 @@ class DBusStubAdapterHelper: public virtual DBusStubAdapter { virtual const StubDispatcherTable& getStubDispatcherTable() = 0; - std::shared_ptr<_StubClass> stub_; + std::weak_ptr<_StubClass> stub_; RemoteEventHandlerType* remoteEventHandler_; }; diff --git a/src/test/DBusConnectionTest.cpp b/src/test/DBusConnectionTest.cpp index b1e7f51..c16f32c 100644 --- a/src/test/DBusConnectionTest.cpp +++ b/src/test/DBusConnectionTest.cpp @@ -318,7 +318,6 @@ void noPartnerCallback(DBusPendingCall*, void* data) { } void noPartnerCleanup(void* data) { - std::cout << "Cleanup" << std::endl; promise3.set_value(true); } diff --git a/src/test/DBusProxyTest.cpp b/src/test/DBusProxyTest.cpp index 95948d0..e767913 100644 --- a/src/test/DBusProxyTest.cpp +++ b/src/test/DBusProxyTest.cpp @@ -87,7 +87,7 @@ protected: bool isTestStubAdapterRegistered_ = runtime_->getServicePublisher()->registerService<commonapi::tests::TestInterfaceStub>(stubDefault_, commonApiAddress, serviceFactory_); ASSERT_TRUE(isTestStubAdapterRegistered_); - usleep(500000); + usleep(100000); } void registerExtendedStub() { @@ -96,7 +96,7 @@ protected: bool isExtendedStubAdapterRegistered_ = runtime_->getServicePublisher()->registerService<commonapi::tests::ExtendedInterfaceStub>(stubExtended_, commonApiAddressExtended, serviceFactory_); ASSERT_TRUE(isExtendedStubAdapterRegistered_); - usleep(500000); + usleep(100000); } void deregisterTestStub() { @@ -306,7 +306,7 @@ TEST_F(ProxyTest, CallMethodFromExtendedInterface) { auto extendedProxy = serviceFactory_->buildProxy<commonapi::tests::ExtendedInterfaceProxy>(commonApiAddressExtended); // give the proxy time to become available - for (uint32_t i = 0; !extendedProxy->isAvailable() && i < 500; ++i) { + for (uint32_t i = 0; !extendedProxy->isAvailable() && i < 200; ++i) { usleep(20 * 1000); } @@ -320,7 +320,7 @@ TEST_F(ProxyTest, CallMethodFromExtendedInterface) { ASSERT_EQ(callStatus, CommonAPI::CallStatus::SUCCESS); wasCalled = true; }); - usleep(500000); + usleep(100000); EXPECT_TRUE(wasCalled); deregisterExtendedStub(); @@ -331,7 +331,7 @@ TEST_F(ProxyTest, CallMethodFromParentInterface) { auto extendedProxy = serviceFactory_->buildProxy<commonapi::tests::ExtendedInterfaceProxy>(commonApiAddressExtended); - for (uint32_t i = 0; !extendedProxy->isAvailable() && i < 500; ++i) { + for (uint32_t i = 0; !extendedProxy->isAvailable() && i < 200; ++i) { usleep(20 * 1000); } EXPECT_TRUE(extendedProxy->isAvailable()); @@ -342,7 +342,7 @@ TEST_F(ProxyTest, CallMethodFromParentInterface) { ASSERT_EQ(callStatus, CommonAPI::CallStatus::SUCCESS); wasCalled = true; }); - usleep(500000); + usleep(100000); EXPECT_TRUE(wasCalled); deregisterExtendedStub(); @@ -353,7 +353,7 @@ TEST_F(ProxyTest, ProxyCanFetchVersionAttributeFromInheritedInterfaceStub) { auto extendedProxy = serviceFactory_->buildProxy<commonapi::tests::TestInterfaceProxy>(commonApiAddressExtended); - for (uint32_t i = 0; !extendedProxy->isAvailable() && i < 800; ++i) { + for (uint32_t i = 0; !extendedProxy->isAvailable() && i < 200; ++i) { usleep(20 * 1000); } EXPECT_TRUE(extendedProxy->isAvailable()); diff --git a/src/test/DBusServiceRegistryTest.cpp b/src/test/DBusServiceRegistryTest.cpp index 2f1043e..855d5ff 100644 --- a/src/test/DBusServiceRegistryTest.cpp +++ b/src/test/DBusServiceRegistryTest.cpp @@ -641,9 +641,6 @@ TEST_F(DBusServiceDiscoveryTestWithPredefinedRemote, DISABLED_ServiceRegistryUse double speedRatio = durationWithColdCache / durationWithHotCache; - std::cout << "cold " << durationWithColdCache << "\n"; - std::cout << "hot " << durationWithHotCache << "\n"; - EXPECT_GE(speedRatio, 100); } diff --git a/src/test/commonapi/tests/ExtendedInterfaceDBusStubAdapter.cpp b/src/test/commonapi/tests/ExtendedInterfaceDBusStubAdapter.cpp index 83b7042..95b89a1 100644 --- a/src/test/commonapi/tests/ExtendedInterfaceDBusStubAdapter.cpp +++ b/src/test/commonapi/tests/ExtendedInterfaceDBusStubAdapter.cpp @@ -34,7 +34,6 @@ __attribute__((constructor)) void registerExtendedInterfaceDBusStubAdapter(void) ExtendedInterfaceDBusStubAdapterInternal::~ExtendedInterfaceDBusStubAdapterInternal() { deactivateManagedInstances(); ExtendedInterfaceDBusStubAdapterHelper::deinit(); - ExtendedInterfaceDBusStubAdapterHelper::stub_.reset(); } void ExtendedInterfaceDBusStubAdapterInternal::deactivateManagedInstances() { diff --git a/src/test/commonapi/tests/TestInterfaceDBusStubAdapter.cpp b/src/test/commonapi/tests/TestInterfaceDBusStubAdapter.cpp index f371d5a..9678322 100644 --- a/src/test/commonapi/tests/TestInterfaceDBusStubAdapter.cpp +++ b/src/test/commonapi/tests/TestInterfaceDBusStubAdapter.cpp @@ -34,7 +34,6 @@ __attribute__((constructor)) void registerTestInterfaceDBusStubAdapter(void) { TestInterfaceDBusStubAdapterInternal::~TestInterfaceDBusStubAdapterInternal() { deactivateManagedInstances(); TestInterfaceDBusStubAdapterHelper::deinit(); - TestInterfaceDBusStubAdapterHelper::stub_.reset(); } void TestInterfaceDBusStubAdapterInternal::deactivateManagedInstances() { @@ -302,10 +301,11 @@ void TestInterfaceDBusStubAdapterInternal::sendTestSelectiveBroadcastSelective(c } void TestInterfaceDBusStubAdapterInternal::subscribeForTestSelectiveBroadcastSelective(const std::shared_ptr<CommonAPI::ClientId> clientId, bool& success) { - bool ok = stub_->onTestSelectiveBroadcastSelectiveSubscriptionRequested(clientId); + auto stub = stub_.lock(); + bool ok = stub->onTestSelectiveBroadcastSelectiveSubscriptionRequested(clientId); if (ok) { subscribersForTestSelectiveBroadcastSelective_->insert(clientId); - stub_->onTestSelectiveBroadcastSelectiveSubscriptionChanged(clientId, CommonAPI::SelectiveBroadcastSubscriptionEvent::SUBSCRIBED); + stub->onTestSelectiveBroadcastSelectiveSubscriptionChanged(clientId, CommonAPI::SelectiveBroadcastSubscriptionEvent::SUBSCRIBED); success = true; } else { success = false; @@ -315,7 +315,8 @@ void TestInterfaceDBusStubAdapterInternal::subscribeForTestSelectiveBroadcastSel void TestInterfaceDBusStubAdapterInternal::unsubscribeFromTestSelectiveBroadcastSelective(const std::shared_ptr<CommonAPI::ClientId> clientId) { subscribersForTestSelectiveBroadcastSelective_->erase(clientId); - stub_->onTestSelectiveBroadcastSelectiveSubscriptionChanged(clientId, CommonAPI::SelectiveBroadcastSubscriptionEvent::UNSUBSCRIBED); + auto stub = stub_.lock(); + stub->onTestSelectiveBroadcastSelectiveSubscriptionChanged(clientId, CommonAPI::SelectiveBroadcastSubscriptionEvent::UNSUBSCRIBED); } std::shared_ptr<CommonAPI::ClientIdList> const TestInterfaceDBusStubAdapterInternal::getSubscribersForTestSelectiveBroadcastSelective() { @@ -370,10 +371,11 @@ void TestInterfaceDBusStubAdapterInternal::sendTestBroadcastWithOutArgsSelective } void TestInterfaceDBusStubAdapterInternal::subscribeForTestBroadcastWithOutArgsSelective(const std::shared_ptr<CommonAPI::ClientId> clientId, bool& success) { - bool ok = stub_->onTestBroadcastWithOutArgsSelectiveSubscriptionRequested(clientId); + auto stub = stub_.lock(); + bool ok = stub->onTestBroadcastWithOutArgsSelectiveSubscriptionRequested(clientId); if (ok) { subscribersForTestBroadcastWithOutArgsSelective_->insert(clientId); - stub_->onTestBroadcastWithOutArgsSelectiveSubscriptionChanged(clientId, CommonAPI::SelectiveBroadcastSubscriptionEvent::SUBSCRIBED); + stub->onTestBroadcastWithOutArgsSelectiveSubscriptionChanged(clientId, CommonAPI::SelectiveBroadcastSubscriptionEvent::SUBSCRIBED); success = true; } else { success = false; @@ -383,7 +385,8 @@ void TestInterfaceDBusStubAdapterInternal::subscribeForTestBroadcastWithOutArgsS void TestInterfaceDBusStubAdapterInternal::unsubscribeFromTestBroadcastWithOutArgsSelective(const std::shared_ptr<CommonAPI::ClientId> clientId) { subscribersForTestBroadcastWithOutArgsSelective_->erase(clientId); - stub_->onTestBroadcastWithOutArgsSelectiveSubscriptionChanged(clientId, CommonAPI::SelectiveBroadcastSubscriptionEvent::UNSUBSCRIBED); + auto stub = stub_.lock(); + stub->onTestBroadcastWithOutArgsSelectiveSubscriptionChanged(clientId, CommonAPI::SelectiveBroadcastSubscriptionEvent::UNSUBSCRIBED); } std::shared_ptr<CommonAPI::ClientIdList> const TestInterfaceDBusStubAdapterInternal::getSubscribersForTestBroadcastWithOutArgsSelective() { diff --git a/src/test/commonapi/tests/managed/BranchInterfaceDBusStubAdapter.cpp b/src/test/commonapi/tests/managed/BranchInterfaceDBusStubAdapter.cpp index 3c14d6b..50047b5 100644 --- a/src/test/commonapi/tests/managed/BranchInterfaceDBusStubAdapter.cpp +++ b/src/test/commonapi/tests/managed/BranchInterfaceDBusStubAdapter.cpp @@ -35,7 +35,6 @@ __attribute__((constructor)) void registerBranchInterfaceDBusStubAdapter(void) { BranchInterfaceDBusStubAdapterInternal::~BranchInterfaceDBusStubAdapterInternal() { deactivateManagedInstances(); BranchInterfaceDBusStubAdapterHelper::deinit(); - BranchInterfaceDBusStubAdapterHelper::stub_.reset(); } void BranchInterfaceDBusStubAdapterInternal::deactivateManagedInstances() { diff --git a/src/test/commonapi/tests/managed/LeafInterfaceDBusStubAdapter.cpp b/src/test/commonapi/tests/managed/LeafInterfaceDBusStubAdapter.cpp index 21441a3..91565fb 100644 --- a/src/test/commonapi/tests/managed/LeafInterfaceDBusStubAdapter.cpp +++ b/src/test/commonapi/tests/managed/LeafInterfaceDBusStubAdapter.cpp @@ -35,7 +35,6 @@ __attribute__((constructor)) void registerLeafInterfaceDBusStubAdapter(void) { LeafInterfaceDBusStubAdapterInternal::~LeafInterfaceDBusStubAdapterInternal() { deactivateManagedInstances(); LeafInterfaceDBusStubAdapterHelper::deinit(); - LeafInterfaceDBusStubAdapterHelper::stub_.reset(); } void LeafInterfaceDBusStubAdapterInternal::deactivateManagedInstances() { diff --git a/src/test/commonapi/tests/managed/RootInterfaceDBusStubAdapter.cpp b/src/test/commonapi/tests/managed/RootInterfaceDBusStubAdapter.cpp index 0ae8c1f..38335f3 100644 --- a/src/test/commonapi/tests/managed/RootInterfaceDBusStubAdapter.cpp +++ b/src/test/commonapi/tests/managed/RootInterfaceDBusStubAdapter.cpp @@ -35,7 +35,6 @@ __attribute__((constructor)) void registerRootInterfaceDBusStubAdapter(void) { RootInterfaceDBusStubAdapterInternal::~RootInterfaceDBusStubAdapterInternal() { deactivateManagedInstances(); RootInterfaceDBusStubAdapterHelper::deinit(); - RootInterfaceDBusStubAdapterHelper::stub_.reset(); } void RootInterfaceDBusStubAdapterInternal::deactivateManagedInstances() { diff --git a/src/test/commonapi/tests/managed/SecondRootDBusStubAdapter.cpp b/src/test/commonapi/tests/managed/SecondRootDBusStubAdapter.cpp index a6c7c6d..57c12b1 100644 --- a/src/test/commonapi/tests/managed/SecondRootDBusStubAdapter.cpp +++ b/src/test/commonapi/tests/managed/SecondRootDBusStubAdapter.cpp @@ -35,7 +35,6 @@ __attribute__((constructor)) void registerSecondRootDBusStubAdapter(void) { SecondRootDBusStubAdapterInternal::~SecondRootDBusStubAdapterInternal() { deactivateManagedInstances(); SecondRootDBusStubAdapterHelper::deinit(); - SecondRootDBusStubAdapterHelper::stub_.reset(); } void SecondRootDBusStubAdapterInternal::deactivateManagedInstances() { |