diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-01-18 10:51:34 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-01-18 10:51:34 +0100 |
commit | 47b4442c585a25b2e4b857f2d9e3ab371d942c19 (patch) | |
tree | 4167c6cb75e3ee8072452585f1b433fb637e3389 /common/clientapi.h | |
parent | aef2ebc45a30d3c3b15b630648e8b37a551ce1ef (diff) | |
download | sink-47b4442c585a25b2e4b857f2d9e3ab371d942c19.tar.gz sink-47b4442c585a25b2e4b857f2d9e3ab371d942c19.zip |
Use jobs to track progress of write commands.
Diffstat (limited to 'common/clientapi.h')
-rw-r--r-- | common/clientapi.h | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/common/clientapi.h b/common/clientapi.h index d2b1c9c..2f1c127 100644 --- a/common/clientapi.h +++ b/common/clientapi.h | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <QtConcurrent/QtConcurrentRun> | 30 | #include <QtConcurrent/QtConcurrentRun> |
31 | #include <functional> | 31 | #include <functional> |
32 | #include "threadboundary.h" | 32 | #include "threadboundary.h" |
33 | #include "async/src/async.h" | ||
33 | 34 | ||
34 | namespace async { | 35 | namespace async { |
35 | //This should abstract if we execute from eventloop or in thread. | 36 | //This should abstract if we execute from eventloop or in thread. |
@@ -185,6 +186,11 @@ public: | |||
185 | 186 | ||
186 | class MemoryBufferAdaptor : public BufferAdaptor { | 187 | class MemoryBufferAdaptor : public BufferAdaptor { |
187 | public: | 188 | public: |
189 | MemoryBufferAdaptor() | ||
190 | : BufferAdaptor() | ||
191 | { | ||
192 | } | ||
193 | |||
188 | MemoryBufferAdaptor(const BufferAdaptor &buffer) | 194 | MemoryBufferAdaptor(const BufferAdaptor &buffer) |
189 | : BufferAdaptor() | 195 | : BufferAdaptor() |
190 | { | 196 | { |
@@ -208,6 +214,11 @@ private: | |||
208 | */ | 214 | */ |
209 | class AkonadiDomainType { | 215 | class AkonadiDomainType { |
210 | public: | 216 | public: |
217 | AkonadiDomainType() | ||
218 | :mAdaptor(new MemoryBufferAdaptor()) | ||
219 | { | ||
220 | |||
221 | } | ||
211 | AkonadiDomainType(const QString &resourceName, const QString &identifier, qint64 revision, const QSharedPointer<BufferAdaptor> &adaptor) | 222 | AkonadiDomainType(const QString &resourceName, const QString &identifier, qint64 revision, const QSharedPointer<BufferAdaptor> &adaptor) |
212 | : mAdaptor(adaptor), | 223 | : mAdaptor(adaptor), |
213 | mResourceName(resourceName), | 224 | mResourceName(resourceName), |
@@ -310,9 +321,9 @@ class StoreFacade { | |||
310 | public: | 321 | public: |
311 | virtual ~StoreFacade(){}; | 322 | virtual ~StoreFacade(){}; |
312 | QString type() const { return Domain::getTypeName<DomainType>(); } | 323 | QString type() const { return Domain::getTypeName<DomainType>(); } |
313 | virtual void create(const DomainType &domainObject) = 0; | 324 | virtual Async::Job<void> create(const DomainType &domainObject) = 0; |
314 | virtual void modify(const DomainType &domainObject) = 0; | 325 | virtual Async::Job<void> modify(const DomainType &domainObject) = 0; |
315 | virtual void remove(const DomainType &domainObject) = 0; | 326 | virtual Async::Job<void> remove(const DomainType &domainObject) = 0; |
316 | virtual void load(const Query &query, const std::function<void(const typename DomainType::Ptr &)> &resultCallback, const std::function<void()> &completeCallback) = 0; | 327 | virtual void load(const Query &query, const std::function<void(const typename DomainType::Ptr &)> &resultCallback, const std::function<void()> &completeCallback) = 0; |
317 | }; | 328 | }; |
318 | 329 | ||
@@ -440,11 +451,15 @@ public: | |||
440 | /** | 451 | /** |
441 | * Create a new entity. | 452 | * Create a new entity. |
442 | */ | 453 | */ |
454 | //TODO return job that tracks progress until resource has stored the message in it's queue? | ||
443 | template <class DomainType> | 455 | template <class DomainType> |
444 | static void create(const DomainType &domainObject, const QString &resourceIdentifier) { | 456 | static void create(const DomainType &domainObject, const QString &resourceIdentifier) { |
445 | //Potentially move to separate thread as well | 457 | //Potentially move to separate thread as well |
446 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceIdentifier); | 458 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceIdentifier); |
447 | facade.create(domainObject); | 459 | auto job = facade->create(domainObject); |
460 | auto future = job.exec(); | ||
461 | future.waitForFinished(); | ||
462 | //TODO return job? | ||
448 | } | 463 | } |
449 | 464 | ||
450 | /** | 465 | /** |