summaryrefslogtreecommitdiffstats
path: root/common/resultprovider.h
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-12-20 16:02:38 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-12-20 16:02:38 +0100
commit1864024012213dc0a17c76e9755bf50a19944ec7 (patch)
tree06690c35c05c29deec30a3dd412d4043e2c956a3 /common/resultprovider.h
parent6625bb5a2145008ad47ae963e1546714b7342bf0 (diff)
downloadsink-1864024012213dc0a17c76e9755bf50a19944ec7.tar.gz
sink-1864024012213dc0a17c76e9755bf50a19944ec7.zip
Report when we don't have any more to fetch.
... so we can use that information in fetchMore.
Diffstat (limited to 'common/resultprovider.h')
-rw-r--r--common/resultprovider.h27
1 files changed, 14 insertions, 13 deletions
diff --git a/common/resultprovider.h b/common/resultprovider.h
index defeb6a..cda4dac 100644
--- a/common/resultprovider.h
+++ b/common/resultprovider.h
@@ -46,7 +46,7 @@ public:
46 virtual void add(const T &value) = 0; 46 virtual void add(const T &value) = 0;
47 virtual void modify(const T &value) = 0; 47 virtual void modify(const T &value) = 0;
48 virtual void remove(const T &value) = 0; 48 virtual void remove(const T &value) = 0;
49 virtual void initialResultSetComplete(const T &parent) = 0; 49 virtual void initialResultSetComplete(const T &parent, bool) = 0;
50 virtual void complete() = 0; 50 virtual void complete() = 0;
51 virtual void clear() = 0; 51 virtual void clear() = 0;
52 virtual void setFetcher(const std::function<void(const T &parent)> &fetcher) = 0; 52 virtual void setFetcher(const std::function<void(const T &parent)> &fetcher) = 0;
@@ -100,10 +100,10 @@ public:
100 } 100 }
101 } 101 }
102 102
103 void initialResultSetComplete(const T &parent) 103 void initialResultSetComplete(const T &parent, bool replayedAll)
104 { 104 {
105 if (auto strongRef = mResultEmitter.toStrongRef()) { 105 if (auto strongRef = mResultEmitter.toStrongRef()) {
106 strongRef->initialResultSetComplete(parent); 106 strongRef->initialResultSetComplete(parent, replayedAll);
107 } 107 }
108 } 108 }
109 109
@@ -211,7 +211,7 @@ public:
211 removeHandler = handler; 211 removeHandler = handler;
212 } 212 }
213 213
214 void onInitialResultSetComplete(const std::function<void(const DomainType &)> &handler) 214 void onInitialResultSetComplete(const std::function<void(const DomainType &, bool)> &handler)
215 { 215 {
216 initialResultSetCompleteHandler = handler; 216 initialResultSetCompleteHandler = handler;
217 } 217 }
@@ -241,10 +241,10 @@ public:
241 removeHandler(value); 241 removeHandler(value);
242 } 242 }
243 243
244 void initialResultSetComplete(const DomainType &parent) 244 void initialResultSetComplete(const DomainType &parent, bool replayedAll)
245 { 245 {
246 if (initialResultSetCompleteHandler) { 246 if (initialResultSetCompleteHandler) {
247 initialResultSetCompleteHandler(parent); 247 initialResultSetCompleteHandler(parent, replayedAll);
248 } 248 }
249 } 249 }
250 250
@@ -280,7 +280,7 @@ private:
280 std::function<void(const DomainType &)> addHandler; 280 std::function<void(const DomainType &)> addHandler;
281 std::function<void(const DomainType &)> modifyHandler; 281 std::function<void(const DomainType &)> modifyHandler;
282 std::function<void(const DomainType &)> removeHandler; 282 std::function<void(const DomainType &)> removeHandler;
283 std::function<void(const DomainType &)> initialResultSetCompleteHandler; 283 std::function<void(const DomainType &, bool)> initialResultSetCompleteHandler;
284 std::function<void(void)> completeHandler; 284 std::function<void(void)> completeHandler;
285 std::function<void(void)> clearHandler; 285 std::function<void(void)> clearHandler;
286 286
@@ -300,30 +300,31 @@ public:
300 emitter->onModified([this](const DomainType &value) { this->modify(value); }); 300 emitter->onModified([this](const DomainType &value) { this->modify(value); });
301 emitter->onRemoved([this](const DomainType &value) { this->remove(value); }); 301 emitter->onRemoved([this](const DomainType &value) { this->remove(value); });
302 auto ptr = emitter.data(); 302 auto ptr = emitter.data();
303 emitter->onInitialResultSetComplete([this, ptr](const DomainType &parent) { 303 emitter->onInitialResultSetComplete([this, ptr](const DomainType &parent, bool replayedAll) {
304 auto hashValue = qHash(parent); 304 auto hashValue = qHash(parent);
305 mInitialResultSetInProgress.remove(hashValue, ptr); 305 mInitialResultSetInProgress.remove(hashValue, ptr);
306 callInitialResultCompleteIfDone(parent); 306 callInitialResultCompleteIfDone(parent, replayedAll);
307 }); 307 });
308 emitter->onComplete([this]() { this->complete(); }); 308 emitter->onComplete([this]() { this->complete(); });
309 emitter->onClear([this]() { this->clear(); }); 309 emitter->onClear([this]() { this->clear(); });
310 mEmitter << emitter; 310 mEmitter << emitter;
311 } 311 }
312 312
313 void callInitialResultCompleteIfDone(const DomainType &parent) 313 void callInitialResultCompleteIfDone(const DomainType &parent, bool replayedAll)
314 { 314 {
315 auto hashValue = qHash(parent); 315 auto hashValue = qHash(parent);
316 // Normally a parent is only in a single resource, except the toplevel (invalid) parent 316 // Normally a parent is only in a single resource, except the toplevel (invalid) parent
317 if (!mInitialResultSetInProgress.contains(hashValue) && mAllResultsFetched && !mResultEmitted) { 317 if (!mInitialResultSetInProgress.contains(hashValue) && mAllResultsFetched && !mResultEmitted) {
318 mResultEmitted = true; 318 mResultEmitted = true;
319 this->initialResultSetComplete(parent); 319 //FIXME set replayed all only to true if all had set it to true
320 this->initialResultSetComplete(parent, true);
320 } 321 }
321 } 322 }
322 323
323 void fetch(const DomainType &parent) Q_DECL_OVERRIDE 324 void fetch(const DomainType &parent) Q_DECL_OVERRIDE
324 { 325 {
325 if (mEmitter.isEmpty()) { 326 if (mEmitter.isEmpty()) {
326 this->initialResultSetComplete(parent); 327 this->initialResultSetComplete(parent, true);
327 } else { 328 } else {
328 mResultEmitted = false; 329 mResultEmitted = false;
329 mAllResultsFetched = false; 330 mAllResultsFetched = false;
@@ -332,7 +333,7 @@ public:
332 emitter->fetch(parent); 333 emitter->fetch(parent);
333 } 334 }
334 mAllResultsFetched = true; 335 mAllResultsFetched = true;
335 callInitialResultCompleteIfDone(parent); 336 callInitialResultCompleteIfDone(parent, true);
336 } 337 }
337 } 338 }
338 339