From 52c83b860b4cc43d7cd70af4fad9c09924cac2fa Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 21 Oct 2013 02:06:01 +0200 Subject: [PATCH] DependencyFactory: remove the ability to restart a service explicitly We don't need this ability and it pushes us into using a central registry. This solution turned out to be problematic when loading dynamic libraries (plug-ins). --- src/lib/depend.hpp | 26 +++++------------------ src/lib/dependency-factory.cpp | 20 ----------------- src/lib/dependency-factory.hpp | 2 -- tests/40core.tests | 12 ++++------- tests/library/dependency-factory-test.cpp | 23 -------------------- 5 files changed, 9 insertions(+), 74 deletions(-) diff --git a/src/lib/depend.hpp b/src/lib/depend.hpp index 3d6fd5227..8fbfd77d2 100644 --- a/src/lib/depend.hpp +++ b/src/lib/depend.hpp @@ -169,31 +169,15 @@ namespace lib { /* === Management / Test support interface === */ - /** disable and destroy the actual service instance explicitly. - * Next access will re-invoke the factory to create a new instance. - * @warning this is a very dangerous operation. Concurrent accesses - * might get NULL or even a reference to the old instance, - * which, worse still, resides typically in the same memory - * location as the new instance. The only way to prevent this - * would be to synchronise any \em access (which is expensive) - * Thus it is the \em client's duty to ensure there is no such - * concurrent access, i.e. all clients of the old instance - * should be disabled prior to invoking this function. - */ - static void - shutdown() - { - SyncLock guard; - - factory.deconfigure (instance); - instance = NULL; - } - /** temporarily replace the service instance. * The purpose of this operation is to support unit testing. * @param mock reference to an existing service instance (mock). * @return reference to the currently active service instance. - * @warning not threadsafe. Same considerations as for \c shutdown() apply + * @warning this is a dangerous operation and not threadsafe. + * Concurrent accesses might still get the old reference; + * the only way to prevent this would be to synchronise + * \em any access (which is too expensive). + * This feature should only be used for unit tests thusly. * @remark the replacement is not actively managed by the DependencyFactory, * it remains in ownership of the calling client (unit test). Typically * this test will keep the returned original service reference and diff --git a/src/lib/dependency-factory.cpp b/src/lib/dependency-factory.cpp index 763f28b28..9ff456fb8 100644 --- a/src/lib/dependency-factory.cpp +++ b/src/lib/dependency-factory.cpp @@ -74,13 +74,6 @@ namespace lib { __lifecycleCheck(); instance().destructionExecutor_.manage (object, customDeleter); } - - static void - kill (void* object) - { - __lifecycleCheck(); - instance().destructionExecutor_.kill (object); - } }; bool AutoDestructor::shutdownLock = false; @@ -89,19 +82,6 @@ namespace lib { - /** explicitly shut down and destroy a service instance. - * This can be used to re-start a service; by default, all - * services are created on-demand and stay alive until - * application shutdown. But a service deconfigured - * through this function is destroyed right away. - */ - void - DependencyFactory::deconfigure (void* existingInstance) - { - AutoDestructor::kill (existingInstance); - } - - /** hook to install a deleter function to clean up a service object. * The standard constructor function uses this hook to schedule the * destructor invocation on application shutdown; custom constructors diff --git a/src/lib/dependency-factory.hpp b/src/lib/dependency-factory.hpp index a037a59d7..3ea25de28 100644 --- a/src/lib/dependency-factory.hpp +++ b/src/lib/dependency-factory.hpp @@ -111,8 +111,6 @@ namespace lib { return ctorFunction_(); } - void deconfigure (void* existingInstance); - static void scheduleDestruction (void*, KillFun); diff --git a/tests/40core.tests b/tests/40core.tests index de08344b2..73487887a 100644 --- a/tests/40core.tests +++ b/tests/40core.tests @@ -233,19 +233,15 @@ END TEST "Dependency injection" DependencyFactory_test < accessor1; - Depend accessor2; - uint id1 = accessor1().instanceID_; - CHECK (id1 == accessor2().instanceID_); - - Depend::shutdown(); - - Sub & o2 = accessor2(); - uint id2 = accessor2().instanceID_; - CHECK (id1 != id2); - - Sub & o1 = accessor1(); - CHECK (isSameObject (o1, o2)); - CHECK (id2 == accessor1().instanceID_); - } - - void verify_SubclassCreation() { @@ -164,8 +143,6 @@ namespace test{ SubSub& oSub = otherSpecialAccessor(); CHECK ( INSTANCEOF (SubSubSub, &oSub)); - Depend::shutdown(); - Depend yetAnotherSpecialAccessor; SubSub& yetAnotherInstance = yetAnotherSpecialAccessor();