summaryrefslogtreecommitdiffstats
path: root/common/resourcefacade.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-07-03 14:02:27 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-07-03 14:02:27 +0200
commit55fe06979ceebe67553135b43aa47e70d931304b (patch)
tree16b10a744879cc1872d6c07624b59ae64469ddbf /common/resourcefacade.cpp
parent56fae95f49a1ca8ca614bd9f89b0ea5f872765e9 (diff)
parent288946f1694c2abe1d2c5800c87339d1e8780e4b (diff)
downloadsink-55fe06979ceebe67553135b43aa47e70d931304b.tar.gz
sink-55fe06979ceebe67553135b43aa47e70d931304b.zip
Merge branch 'develop'
Diffstat (limited to 'common/resourcefacade.cpp')
-rw-r--r--common/resourcefacade.cpp53
1 files changed, 34 insertions, 19 deletions
diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp
index dee0711..dab6aed 100644
--- a/common/resourcefacade.cpp
+++ b/common/resourcefacade.cpp
@@ -21,16 +21,12 @@
21#include "resourceconfig.h" 21#include "resourceconfig.h"
22#include "query.h" 22#include "query.h"
23#include "definitions.h" 23#include "definitions.h"
24#include "storage.h"
25#include "store.h" 24#include "store.h"
26#include "resourceaccess.h" 25#include "resourceaccess.h"
27#include "resource.h" 26#include "resource.h"
28#include <QDir>
29 27
30using namespace Sink; 28using namespace Sink;
31 29
32SINK_DEBUG_AREA("ResourceFacade")
33
34template<typename DomainType> 30template<typename DomainType>
35ConfigNotifier LocalStorageFacade<DomainType>::sConfigNotifier; 31ConfigNotifier LocalStorageFacade<DomainType>::sConfigNotifier;
36 32
@@ -100,17 +96,24 @@ template<typename DomainType>
100LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query, const QByteArray &identifier, const QByteArray &typeName, ConfigNotifier &configNotifier, const Sink::Log::Context &ctx) 96LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query, const QByteArray &identifier, const QByteArray &typeName, ConfigNotifier &configNotifier, const Sink::Log::Context &ctx)
101 : mResultProvider(new ResultProvider<typename DomainType::Ptr>), mConfigStore(identifier, typeName), mGuard(new QObject), mLogCtx(ctx.subContext("config")) 97 : mResultProvider(new ResultProvider<typename DomainType::Ptr>), mConfigStore(identifier, typeName), mGuard(new QObject), mLogCtx(ctx.subContext("config"))
102{ 98{
99
100 auto matchesTypeAndIds = [query, this] (const QByteArray &type, const QByteArray &id) {
101 if (query.hasFilter(ApplicationDomain::SinkResource::ResourceType::name) && query.getFilter(ApplicationDomain::SinkResource::ResourceType::name).value.toByteArray() != type) {
102 SinkTraceCtx(mLogCtx) << "Skipping due to type.";
103 return false;
104 }
105 if (!query.ids().isEmpty() && !query.ids().contains(id)) {
106 return false;
107 }
108 return true;
109 };
110
103 QObject *guard = new QObject; 111 QObject *guard = new QObject;
104 mResultProvider->setFetcher([this, query, guard, &configNotifier](const QSharedPointer<DomainType> &) { 112 mResultProvider->setFetcher([this, query, guard, &configNotifier, matchesTypeAndIds](const QSharedPointer<DomainType> &) {
105 const auto entries = mConfigStore.getEntries(); 113 const auto entries = mConfigStore.getEntries();
106 for (const auto &res : entries.keys()) { 114 for (const auto &res : entries.keys()) {
107 const auto type = entries.value(res); 115 const auto type = entries.value(res);
108 116 if (!matchesTypeAndIds(type, res)){
109 if (query.hasFilter(ApplicationDomain::SinkResource::ResourceType::name) && query.getFilter(ApplicationDomain::SinkResource::ResourceType::name).value.toByteArray() != type) {
110 SinkTraceCtx(mLogCtx) << "Skipping due to type.";
111 continue;
112 }
113 if (!query.ids().isEmpty() && !query.ids().contains(res)) {
114 continue; 117 continue;
115 } 118 }
116 auto entity = readFromConfig<DomainType>(mConfigStore, res, type, query.requestedProperties); 119 auto entity = readFromConfig<DomainType>(mConfigStore, res, type, query.requestedProperties);
@@ -128,8 +131,14 @@ LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query,
128 }); 131 });
129 if (query.liveQuery()) { 132 if (query.liveQuery()) {
130 { 133 {
131 auto ret = QObject::connect(&configNotifier, &ConfigNotifier::added, guard, [this](const ApplicationDomain::ApplicationDomainType::Ptr &entry) { 134 auto ret = QObject::connect(&configNotifier, &ConfigNotifier::added, guard, [this, query, matchesTypeAndIds](const ApplicationDomain::ApplicationDomainType::Ptr &entry, const QByteArray &type) {
132 auto entity = entry.staticCast<DomainType>(); 135 auto entity = entry.staticCast<DomainType>();
136 if (!matchesTypeAndIds(type, entity->identifier())){
137 return;
138 }
139 if (!matchesFilter(query.getBaseFilters(), *entity)){
140 return;
141 }
133 SinkTraceCtx(mLogCtx) << "A new resource has been added: " << entity->identifier(); 142 SinkTraceCtx(mLogCtx) << "A new resource has been added: " << entity->identifier();
134 updateStatus(*entity); 143 updateStatus(*entity);
135 mResultProvider->add(entity); 144 mResultProvider->add(entity);
@@ -137,8 +146,14 @@ LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query,
137 Q_ASSERT(ret); 146 Q_ASSERT(ret);
138 } 147 }
139 { 148 {
140 auto ret = QObject::connect(&configNotifier, &ConfigNotifier::modified, guard, [this](const ApplicationDomain::ApplicationDomainType::Ptr &entry) { 149 auto ret = QObject::connect(&configNotifier, &ConfigNotifier::modified, guard, [this, query, matchesTypeAndIds](const ApplicationDomain::ApplicationDomainType::Ptr &entry, const QByteArray &type) {
141 auto entity = entry.staticCast<DomainType>(); 150 auto entity = entry.staticCast<DomainType>();
151 if (!matchesTypeAndIds(type, entity->identifier())){
152 return;
153 }
154 if (!matchesFilter(query.getBaseFilters(), *entity)){
155 return;
156 }
142 updateStatus(*entity); 157 updateStatus(*entity);
143 mResultProvider->modify(entity); 158 mResultProvider->modify(entity);
144 }); 159 });
@@ -222,7 +237,7 @@ KAsync::Job<void> LocalStorageFacade<DomainType>::create(const DomainType &domai
222 } 237 }
223 configStore.modify(identifier, configurationValues); 238 configStore.modify(identifier, configurationValues);
224 } 239 }
225 sConfigNotifier.add(::readFromConfig<DomainType>(configStore, identifier, type, QByteArrayList{})); 240 sConfigNotifier.add(::readFromConfig<DomainType>(configStore, identifier, type, QByteArrayList{}), type);
226 }); 241 });
227} 242}
228 243
@@ -251,7 +266,7 @@ KAsync::Job<void> LocalStorageFacade<DomainType>::modify(const DomainType &domai
251 } 266 }
252 267
253 const auto type = configStore.getEntries().value(identifier); 268 const auto type = configStore.getEntries().value(identifier);
254 sConfigNotifier.modify(::readFromConfig<DomainType>(configStore, identifier, type, QByteArrayList{})); 269 sConfigNotifier.modify(::readFromConfig<DomainType>(configStore, identifier, type, QByteArrayList{}), type);
255 }); 270 });
256} 271}
257 272
@@ -281,7 +296,7 @@ KAsync::Job<void> LocalStorageFacade<DomainType>::remove(const DomainType &domai
281 SinkTrace() << "Removing: " << identifier; 296 SinkTrace() << "Removing: " << identifier;
282 auto configStore = ConfigStore(configStoreIdentifier, typeName); 297 auto configStore = ConfigStore(configStoreIdentifier, typeName);
283 configStore.remove(identifier); 298 configStore.remove(identifier);
284 sConfigNotifier.remove(QSharedPointer<DomainType>::create(domainObject)); 299 sConfigNotifier.remove(QSharedPointer<DomainType>::create(domainObject), typeName);
285 }); 300 });
286} 301}
287 302
@@ -373,10 +388,10 @@ QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename ApplicationDomain
373 if (states.contains(ApplicationDomain::BusyStatus)) { 388 if (states.contains(ApplicationDomain::BusyStatus)) {
374 return ApplicationDomain::BusyStatus; 389 return ApplicationDomain::BusyStatus;
375 } 390 }
376 if (states.contains(ApplicationDomain::ConnectedStatus)) { 391 if (states.contains(ApplicationDomain::OfflineStatus)) {
377 return ApplicationDomain::ConnectedStatus; 392 return ApplicationDomain::OfflineStatus;
378 } 393 }
379 return ApplicationDomain::OfflineStatus; 394 return ApplicationDomain::ConnectedStatus;
380 }(); 395 }();
381 account.setStatusStatus(status); 396 account.setStatusStatus(status);
382 }); 397 });