From 74610b153e6929d33ef61ebe6443c81dfd32d8a1 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 7 Jul 2016 12:10:43 +0200 Subject: Disconnect one the object is gone. --- common/resourcefacade.cpp | 10 +++++++--- common/resourcefacade.h | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'common') diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp index 6e135b3..898e3ad 100644 --- a/common/resourcefacade.cpp +++ b/common/resourcefacade.cpp @@ -57,7 +57,7 @@ static bool matchesFilter(const QHash &filter, co template LocalStorageQueryRunner::LocalStorageQueryRunner(const Query &query, const QByteArray &identifier, ConfigNotifier &configNotifier) - : mResultProvider(new ResultProvider), mConfigStore(identifier) + : mResultProvider(new ResultProvider), mConfigStore(identifier), mGuard(new QObject) { QObject *guard = new QObject; mResultProvider->setFetcher([this, query, guard, &configNotifier](const QSharedPointer &) { @@ -139,6 +139,11 @@ LocalStorageQueryRunner::LocalStorageQueryRunner(const Query &query, // // } +template +QObject *LocalStorageQueryRunner::guard() const +{ + return mGuard.get(); +} template void LocalStorageQueryRunner::updateStatus(DomainType &entity) @@ -284,8 +289,7 @@ QPair, typename Sink::ResultEmittersetStatusUpdater([runner, monitoredResources](ApplicationDomain::SinkResource &resource) { auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource.identifier(), ResourceConfig::getResourceType(resource.identifier())); if (!monitoredResources->contains(resource.identifier())) { - //TODO disconnect at some point when the runner is done - auto ret = QObject::connect(resourceAccess.data(), &ResourceAccess::notification, [resource, runner, resourceAccess](const Notification ¬ification) { + auto ret = QObject::connect(resourceAccess.data(), &ResourceAccess::notification, runner->guard(), [resource, runner, resourceAccess](const Notification ¬ification) { Trace() << "Received notification in facade: " << notification.type; if (notification.type == Notification::Status) { runner->statusChanged(resource.identifier()); diff --git a/common/resourcefacade.h b/common/resourcefacade.h index 2573b31..64e082f 100644 --- a/common/resourcefacade.h +++ b/common/resourcefacade.h @@ -63,12 +63,14 @@ public: typename Sink::ResultEmitter::Ptr emitter(); void setStatusUpdater(const std::function &); void statusChanged(const QByteArray &identifier); + QObject *guard() const; private: void updateStatus(DomainType &entity); std::function mStatusUpdater; QSharedPointer> mResultProvider; ConfigStore mConfigStore; + std::unique_ptr mGuard; }; template -- cgit v1.2.3