From 9e967283190d36510fbcf73a79cc239dc696ec85 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 7 Jul 2015 03:13:12 +0200 Subject: Remove externallyManaged hack now that we use std::shared_ptr --- common/clientapi.h | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) (limited to 'common') diff --git a/common/clientapi.h b/common/clientapi.h index 4948c59..748baa6 100644 --- a/common/clientapi.h +++ b/common/clientapi.h @@ -108,7 +108,7 @@ public: class FacadeFactory { public: - typedef std::function FactoryFunction; + typedef std::function()> FactoryFunction; //FIXME: proper singleton implementation static FacadeFactory &instance() @@ -126,17 +126,13 @@ public: void registerFacade(const QByteArray &resource) { const QByteArray typeName = ApplicationDomain::getTypeName(); - mFacadeRegistry.insert(key(resource, typeName), [](bool &externallyManaged){ return new Facade; }); + mFacadeRegistry.insert(key(resource, typeName), [](){ return std::shared_ptr(new Facade); }); } /* * Allows the registrar to register a specific instance. * * Primarily for testing. - * The facade factory takes ovnership of the pointer and typically deletes the instance via shared pointer. - * Supplied factory functions should therefore always return a new pointer (i.e. via clone()) - * - * FIXME the factory function should really be returning QSharedPointer, which doesn't work (std::shared_pointer would though). That way i.e. a test could keep the object alive until it's done. As a workaround the factory function can define wether it manages the lifetime of the facade itself. */ template void registerFacade(const QByteArray &resource, const FactoryFunction &customFactoryFunction) @@ -155,25 +151,12 @@ public: mFacadeRegistry.clear(); } - static void doNothingDeleter(void *) - { - qWarning() << "Do nothing"; - } - template std::shared_ptr > getFacade(const QByteArray &resource) { const QByteArray typeName = ApplicationDomain::getTypeName(); - auto factoryFunction = mFacadeRegistry.value(key(resource, typeName)); - if (factoryFunction) { - bool externallyManaged = false; - auto ptr = static_cast* >(factoryFunction(externallyManaged)); - if (externallyManaged) { - //Allows tests to manage the lifetime of injected facades themselves - return std::shared_ptr >(ptr, doNothingDeleter); - } else { - return std::shared_ptr >(ptr); - } + if (auto factoryFunction = mFacadeRegistry.value(key(resource, typeName))) { + return std::static_pointer_cast >(factoryFunction()); } qWarning() << "Failed to find facade for resource: " << resource << " and type: " << typeName; return std::shared_ptr >(); -- cgit v1.2.3