From d1d6c0b908873498e1533648aae6e8dee380d7e0 Mon Sep 17 00:00:00 2001 From: Skycoder42 Date: Tue, 19 Jun 2018 12:14:29 +0200 Subject: [PATCH] change service registry semantics --- src/imports/mvvmcore/qqmlserviceregistry.cpp | 2 +- src/mvvmcore/qtmvvmcore_global.cpp | 2 +- src/mvvmcore/serviceregistry.cpp | 8 +-- src/mvvmcore/serviceregistry.h | 58 ++++++++++---------- src/mvvmquick/quickpresenter.cpp | 4 +- src/mvvmwidgets/widgetspresenter.cpp | 4 +- 6 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/imports/mvvmcore/qqmlserviceregistry.cpp b/src/imports/mvvmcore/qqmlserviceregistry.cpp index 43ff206..113773c 100644 --- a/src/imports/mvvmcore/qqmlserviceregistry.cpp +++ b/src/imports/mvvmcore/qqmlserviceregistry.cpp @@ -37,7 +37,7 @@ void QQmlServiceRegistry::registerObject(const QUrl &componentUrl, bool weak) Q_UNREACHABLE(); return nullptr; } - }, {}, weak, ServiceRegistry::DestroyOnAppQuit); + }, {}, ServiceRegistry::DestroyOnAppQuit, weak); } QObject *QQmlServiceRegistry::service(const QString &iid) diff --git a/src/mvvmcore/qtmvvmcore_global.cpp b/src/mvvmcore/qtmvvmcore_global.cpp index 6a7eb01..18f7c65 100644 --- a/src/mvvmcore/qtmvvmcore_global.cpp +++ b/src/mvvmcore/qtmvvmcore_global.cpp @@ -12,7 +12,7 @@ void qtMvvmCoreStartup() using namespace QtMvvm; registerInterfaceConverter(); try { - ServiceRegistry::instance()->registerInterface(true); + ServiceRegistry::instance()->registerInterface(ServiceRegistry::DestroyOnAppDestroy, true); } catch(ServiceExistsException &e) { logDebug() << "Unable to register default ISettingsSetupLoader with error:" << e.what(); } diff --git a/src/mvvmcore/serviceregistry.cpp b/src/mvvmcore/serviceregistry.cpp index 3ee2177..8b6ed84 100644 --- a/src/mvvmcore/serviceregistry.cpp +++ b/src/mvvmcore/serviceregistry.cpp @@ -40,7 +40,7 @@ bool ServiceRegistry::isRegistered(const QByteArray &iid) const return d->services.contains(iid); } -void ServiceRegistry::registerService(const QByteArray &iid, const QMetaObject *metaObject, bool weak, DestructionScope scope) +void ServiceRegistry::registerService(const QByteArray &iid, const QMetaObject *metaObject, DestructionScope scope, bool weak) { QMutexLocker _(&d->serviceMutex); if(d->serviceBlocked(iid)) @@ -50,10 +50,10 @@ void ServiceRegistry::registerService(const QByteArray &iid, const QMetaObject * void ServiceRegistry::registerService(const QByteArray &iid, const QMetaObject *metaObject, bool weak) { - registerService(iid, metaObject, weak, DestroyOnAppDestroy); + registerService(iid, metaObject, DestroyOnAppDestroy, weak); } -void ServiceRegistry::registerService(const QByteArray &iid, const std::function &fn, QByteArrayList injectables, bool weak, DestructionScope scope) +void ServiceRegistry::registerService(const QByteArray &iid, const std::function &fn, QByteArrayList injectables, DestructionScope scope, bool weak) { QMutexLocker _(&d->serviceMutex); if(d->serviceBlocked(iid)) @@ -63,7 +63,7 @@ void ServiceRegistry::registerService(const QByteArray &iid, const std::function void ServiceRegistry::registerService(const QByteArray &iid, const std::function &fn, QByteArrayList injectables, bool weak) { - registerService(iid, fn, std::move(injectables), weak, DestroyOnAppDestroy); + registerService(iid, fn, std::move(injectables), DestroyOnAppDestroy, weak); } QObject *ServiceRegistry::serviceObj(const QByteArray &iid) diff --git a/src/mvvmcore/serviceregistry.h b/src/mvvmcore/serviceregistry.h index f413e2e..884fe1b 100644 --- a/src/mvvmcore/serviceregistry.h +++ b/src/mvvmcore/serviceregistry.h @@ -40,41 +40,41 @@ public: //! Register a service for its interface via the type template - void registerInterface(bool weak = false, DestructionScope scope = DestroyOnAppDestroy); + void registerInterface(DestructionScope scope = DestroyOnAppDestroy, bool weak = false); //! Register a service for its interface via a constructor function template - void registerInterface(TFunc fn, bool weak = false, DestructionScope scope = DestroyOnAppDestroy); + void registerInterface(TFunc fn, DestructionScope scope = DestroyOnAppDestroy, bool weak = false); //! Register a service for its interface via an already existing instance template - void registerInterface(TService *service, bool weak = false, DestructionScope scope = DestroyOnAppDestroy); + void registerInterface(TService *service, DestructionScope scope = DestroyOnAppDestroy, bool weak = false); //! Register a service via its type template - void registerObject(bool weak = false, DestructionScope scope = DestroyOnAppDestroy); + void registerObject(DestructionScope scope = DestroyOnAppDestroy, bool weak = false); //! Register a service via a constructor function template - void registerObject(TFunc fn, bool weak = false, DestructionScope scope = DestroyOnAppDestroy); + void registerObject(TFunc fn, DestructionScope scope = DestroyOnAppDestroy, bool weak = false); //! Register a service via an already existing instance template - void registerObject(TService *service, bool weak = false, DestructionScope scope = DestroyOnAppDestroy); + void registerObject(TService *service, DestructionScope scope = DestroyOnAppDestroy, bool weak = false); //! Register a service by an iid via their metadata void registerService(const QByteArray &iid, const QMetaObject *metaObject, - bool weak, - DestructionScope scope); - void registerService(const QByteArray &iid, - const QMetaObject *metaObject, - bool weak = false); //MAJOR merge methods + DestructionScope scope = DestroyOnAppDestroy, + bool weak = false); + Q_DECL_DEPRECATED void registerService(const QByteArray &iid, + const QMetaObject *metaObject, + bool weak); //! Register a service by an iid via a generalized constructor function void registerService(const QByteArray &iid, const std::function &fn, QByteArrayList injectables, - bool weak, - DestructionScope scope); - void registerService(const QByteArray &iid, - const std::function &fn, - QByteArrayList injectables, - bool weak = false);//MAJOR merge methods + DestructionScope scope = DestroyOnAppDestroy, + bool weak = false); + Q_DECL_DEPRECATED void registerService(const QByteArray &iid, + const std::function &fn, + QByteArrayList injectables, + bool weak); //! Returns the service for the given interface template @@ -169,29 +169,29 @@ bool ServiceRegistry::isRegistered() const Q_ASSERT_X(qobject_interface_iid(), Q_FUNC_INFO, "TInterface must be registered with Q_DECLARE_INTERFACE"); template -void ServiceRegistry::registerInterface(bool weak, DestructionScope scope) +void ServiceRegistry::registerInterface(DestructionScope scope, bool weak) { QTMVVM_SERVICE_ASSERT(TInterface, TService) - registerService(qobject_interface_iid(), &TService::staticMetaObject, weak, scope); + registerService(qobject_interface_iid(), &TService::staticMetaObject, scope, weak); } template -void ServiceRegistry::registerInterface(TFunc fn, bool weak, DestructionScope scope) +void ServiceRegistry::registerInterface(TFunc fn, DestructionScope scope, bool weak) { QTMVVM_SERVICE_ASSERT(TInterface, TService) QByteArrayList injectables; auto packed_fn = __helpertypes::pack_function(std::move(fn), injectables); - registerService(qobject_interface_iid(), packed_fn, injectables, weak, scope); + registerService(qobject_interface_iid(), packed_fn, injectables, scope, weak); } template -void ServiceRegistry::registerInterface(TService *service, bool weak, DestructionScope scope) +void ServiceRegistry::registerInterface(TService *service, DestructionScope scope, bool weak) { QTMVVM_SERVICE_ASSERT(TInterface, TService) registerService(qobject_interface_iid(), [service](const QObjectList ¶ms) -> QObject* { Q_UNUSED(params); return service; - }, QByteArrayList(), weak, scope); + }, QByteArrayList(), scope, weak); } #undef QTMVVM_SERVICE_ASSERT @@ -199,29 +199,29 @@ void ServiceRegistry::registerInterface(TService *service, bool weak, Destructio static_assert(__helpertypes::is_qobj::value, "TService must be a qobject class"); template -void ServiceRegistry::registerObject(bool weak, DestructionScope scope) +void ServiceRegistry::registerObject(DestructionScope scope, bool weak) { QTMVVM_SERVICE_ASSERT(TService) - registerService(__helpertypes::qobject_iid(), &TService::staticMetaObject, weak, scope); + registerService(__helpertypes::qobject_iid(), &TService::staticMetaObject, scope, weak); } template -void ServiceRegistry::registerObject(TFunc fn, bool weak, DestructionScope scope) +void ServiceRegistry::registerObject(TFunc fn, DestructionScope scope, bool weak) { QTMVVM_SERVICE_ASSERT(TService) QByteArrayList injectables; auto packed_fn = __helpertypes::pack_function(std::move(fn), injectables); - registerService(__helpertypes::qobject_iid(), packed_fn, injectables, weak, scope); + registerService(__helpertypes::qobject_iid(), packed_fn, injectables, scope, weak); } template -void ServiceRegistry::registerObject(TService *service, bool weak, DestructionScope scope) +void ServiceRegistry::registerObject(TService *service, DestructionScope scope, bool weak) { QTMVVM_SERVICE_ASSERT(TService) registerService(__helpertypes::qobject_iid(), [service](const QObjectList ¶ms) -> QObject* { Q_UNUSED(params); return service; - }, QByteArrayList(), weak, scope); + }, QByteArrayList(), scope, weak); } #undef QTMVVM_SERVICE_ASSERT diff --git a/src/mvvmquick/quickpresenter.cpp b/src/mvvmquick/quickpresenter.cpp index 1e1b354..494b288 100644 --- a/src/mvvmquick/quickpresenter.cpp +++ b/src/mvvmquick/quickpresenter.cpp @@ -17,8 +17,8 @@ namespace { void qtMvvmQuickInit() { qmlRegisterType("de.skycoder42.QtMvvm.Quick.Private", 1, 0, "UrlValidator"); - QtMvvm::ServiceRegistry::instance()->registerObject(true); - QtMvvm::ServiceRegistry::instance()->registerInterface(true); + QtMvvm::ServiceRegistry::instance()->registerObject(QtMvvm::ServiceRegistry::DestroyOnAppDestroy, true); + QtMvvm::ServiceRegistry::instance()->registerInterface(QtMvvm::ServiceRegistry::DestroyOnAppDestroy, true); } void initResources() diff --git a/src/mvvmwidgets/widgetspresenter.cpp b/src/mvvmwidgets/widgetspresenter.cpp index e9161a2..9429a3f 100644 --- a/src/mvvmwidgets/widgetspresenter.cpp +++ b/src/mvvmwidgets/widgetspresenter.cpp @@ -28,8 +28,8 @@ namespace { void qtMvvmWidgetsInit() { - QtMvvm::ServiceRegistry::instance()->registerObject(true); - QtMvvm::ServiceRegistry::instance()->registerInterface(true); + QtMvvm::ServiceRegistry::instance()->registerObject(QtMvvm::ServiceRegistry::DestroyOnAppDestroy, true); + QtMvvm::ServiceRegistry::instance()->registerInterface(QtMvvm::ServiceRegistry::DestroyOnAppDestroy, true); } void initResources()