From 7669eeecdd394e1dd9ee8c2fa06edb948a410f6b Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sat, 26 Aug 2017 09:32:23 -0600 Subject: Only return connected if there is any resource connected. --- common/resourcefacade.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'common/resourcefacade.cpp') diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp index dab6aed..829375c 100644 --- a/common/resourcefacade.cpp +++ b/common/resourcefacade.cpp @@ -391,7 +391,10 @@ QPair, typename Sink::ResultEmitter Date: Sat, 2 Sep 2017 15:59:51 -0600 Subject: Ensure we monitor resources for status changes that have been created after the query. This fixes status monitoring when creating a new account. --- common/resourcefacade.cpp | 48 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) (limited to 'common/resourcefacade.cpp') diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp index 829375c..0687bbc 100644 --- a/common/resourcefacade.cpp +++ b/common/resourcefacade.cpp @@ -24,6 +24,7 @@ #include "store.h" #include "resourceaccess.h" #include "resource.h" +#include "facadefactory.h" using namespace Sink; @@ -358,27 +359,50 @@ QPair, typename Sink::ResultEmitter(query, mIdentifier, mTypeName, sConfigNotifier, ctx); auto monitoredResources = QSharedPointer>::create(); - runner->setStatusUpdater([runner, monitoredResources, ctx](ApplicationDomain::SinkAccount &account) { - Query query; + auto monitorResource = [monitoredResources, runner, ctx] (const QByteArray &accountIdentifier, const ApplicationDomain::SinkResource &resource, const ResourceAccess::Ptr &resourceAccess) { + if (!monitoredResources->contains(resource.identifier())) { + auto ret = QObject::connect(resourceAccess.data(), &ResourceAccess::notification, runner->guard(), [resource, runner, resourceAccess, accountIdentifier, ctx](const Notification ¬ification) { + SinkTraceCtx(ctx) << "Received notification in facade: " << notification.type; + if (notification.type == Notification::Status) { + runner->statusChanged(accountIdentifier); + } + }); + Q_ASSERT(ret); + monitoredResources->insert(resource.identifier()); + } + }; + runner->setStatusUpdater([this, runner, monitoredResources, ctx, monitorResource](ApplicationDomain::SinkAccount &account) { + Query query{Query::LiveQuery}; query.filter(account.identifier()); query.request() .request(); const auto resources = Store::read(query); SinkTraceCtx(ctx) << "Found resource belonging to the account " << account.identifier() << " : " << resources; auto accountIdentifier = account.identifier(); + + //Monitor for new resources so they can be monitored as well + if (!runner->mResourceEmitter.contains(accountIdentifier)) { + auto facade = Sink::FacadeFactory::instance().getFacade(); + Q_ASSERT(facade); + + auto emitter = facade->load(query, ctx).second; + emitter->onAdded([=](const ApplicationDomain::SinkResource::Ptr &resource) { + auto resourceAccess = Sink::ResourceAccessFactory::instance().getAccess(resource->identifier(), ResourceConfig::getResourceType(resource->identifier())); + monitorResource(accountIdentifier, *resource, resourceAccess); + }); + emitter->onModified([](const ApplicationDomain::SinkResource::Ptr &) {}); + emitter->onRemoved([](const ApplicationDomain::SinkResource::Ptr &) {}); + emitter->onInitialResultSetComplete([](const ApplicationDomain::SinkResource::Ptr &, bool) {}); + emitter->onComplete([]() {}); + emitter->fetch({}); + runner->mResourceEmitter[accountIdentifier] = emitter; + } + QList states; + //Gather all resources and ensure they are monitored for (const auto &resource : resources) { auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource.identifier(), ResourceConfig::getResourceType(resource.identifier())); - if (!monitoredResources->contains(resource.identifier())) { - auto ret = QObject::connect(resourceAccess.data(), &ResourceAccess::notification, runner->guard(), [resource, runner, resourceAccess, accountIdentifier, ctx](const Notification ¬ification) { - SinkTraceCtx(ctx) << "Received notification in facade: " << notification.type; - if (notification.type == Notification::Status) { - runner->statusChanged(accountIdentifier); - } - }); - Q_ASSERT(ret); - monitoredResources->insert(resource.identifier()); - } + monitorResource(accountIdentifier, resource, resourceAccess); states << resourceAccess->getResourceStatus(); } const auto status = [&] { -- cgit v1.2.3