diff options
Diffstat (limited to 'common/clientapi.h')
-rw-r--r-- | common/clientapi.h | 97 |
1 files changed, 51 insertions, 46 deletions
diff --git a/common/clientapi.h b/common/clientapi.h index 63305ab..22448b3 100644 --- a/common/clientapi.h +++ b/common/clientapi.h | |||
@@ -163,7 +163,7 @@ namespace async { | |||
163 | namespace Akonadi2 { | 163 | namespace Akonadi2 { |
164 | 164 | ||
165 | /** | 165 | /** |
166 | * Standardized Domain Types | 166 | * Standardized Application Domain Types |
167 | * | 167 | * |
168 | * They don't adhere to any standard and can be freely extended | 168 | * They don't adhere to any standard and can be freely extended |
169 | * Their sole purpose is providing a standardized interface to access data. | 169 | * Their sole purpose is providing a standardized interface to access data. |
@@ -172,7 +172,7 @@ namespace Akonadi2 { | |||
172 | * | 172 | * |
173 | * These types will be frequently modified (for every new feature that should be exposed to the any client) | 173 | * These types will be frequently modified (for every new feature that should be exposed to the any client) |
174 | */ | 174 | */ |
175 | namespace Domain { | 175 | namespace ApplicationDomain { |
176 | 176 | ||
177 | /** | 177 | /** |
178 | * This class has to be implemented by resources and can be used as generic interface to access the buffer properties | 178 | * This class has to be implemented by resources and can be used as generic interface to access the buffer properties |
@@ -180,9 +180,9 @@ namespace Domain { | |||
180 | class BufferAdaptor { | 180 | class BufferAdaptor { |
181 | public: | 181 | public: |
182 | virtual ~BufferAdaptor() {} | 182 | virtual ~BufferAdaptor() {} |
183 | virtual QVariant getProperty(const QString &key) const { return QVariant(); } | 183 | virtual QVariant getProperty(const QByteArray &key) const { return QVariant(); } |
184 | virtual void setProperty(const QString &key, const QVariant &value) {} | 184 | virtual void setProperty(const QByteArray &key, const QVariant &value) {} |
185 | virtual QStringList availableProperties() const { return QStringList(); } | 185 | virtual QList<QByteArray> availableProperties() const { return QList<QByteArray>(); } |
186 | }; | 186 | }; |
187 | 187 | ||
188 | class MemoryBufferAdaptor : public BufferAdaptor { | 188 | class MemoryBufferAdaptor : public BufferAdaptor { |
@@ -202,12 +202,12 @@ public: | |||
202 | 202 | ||
203 | virtual ~MemoryBufferAdaptor() {} | 203 | virtual ~MemoryBufferAdaptor() {} |
204 | 204 | ||
205 | virtual QVariant getProperty(const QString &key) const { return mValues.value(key); } | 205 | virtual QVariant getProperty(const QByteArray &key) const { return mValues.value(key); } |
206 | virtual void setProperty(const QString &key, const QVariant &value) { mValues.insert(key, value); } | 206 | virtual void setProperty(const QByteArray &key, const QVariant &value) { mValues.insert(key, value); } |
207 | virtual QStringList availableProperties() const { return mValues.keys(); } | 207 | virtual QByteArrayList availableProperties() const { return mValues.keys(); } |
208 | 208 | ||
209 | private: | 209 | private: |
210 | QHash<QString, QVariant> mValues; | 210 | QHash<QByteArray, QVariant> mValues; |
211 | }; | 211 | }; |
212 | 212 | ||
213 | /** | 213 | /** |
@@ -215,14 +215,14 @@ private: | |||
215 | * * provide a unified interface to read buffers (for zero-copy reading) | 215 | * * provide a unified interface to read buffers (for zero-copy reading) |
216 | * * record changes to generate changesets for modifications | 216 | * * record changes to generate changesets for modifications |
217 | */ | 217 | */ |
218 | class AkonadiDomainType { | 218 | class ApplicationDomainType { |
219 | public: | 219 | public: |
220 | AkonadiDomainType() | 220 | ApplicationDomainType() |
221 | :mAdaptor(new MemoryBufferAdaptor()) | 221 | :mAdaptor(new MemoryBufferAdaptor()) |
222 | { | 222 | { |
223 | 223 | ||
224 | } | 224 | } |
225 | AkonadiDomainType(const QString &resourceName, const QString &identifier, qint64 revision, const QSharedPointer<BufferAdaptor> &adaptor) | 225 | ApplicationDomainType(const QByteArray &resourceName, const QByteArray &identifier, qint64 revision, const QSharedPointer<BufferAdaptor> &adaptor) |
226 | : mAdaptor(adaptor), | 226 | : mAdaptor(adaptor), |
227 | mResourceName(resourceName), | 227 | mResourceName(resourceName), |
228 | mIdentifier(identifier), | 228 | mIdentifier(identifier), |
@@ -230,41 +230,43 @@ public: | |||
230 | { | 230 | { |
231 | } | 231 | } |
232 | 232 | ||
233 | virtual ~AkonadiDomainType() {} | 233 | virtual ~ApplicationDomainType() {} |
234 | 234 | ||
235 | virtual QVariant getProperty(const QString &key) const { return mAdaptor->getProperty(key); } | 235 | virtual QVariant getProperty(const QByteArray &key) const { return mAdaptor->getProperty(key); } |
236 | virtual void setProperty(const QString &key, const QVariant &value){ mChangeSet.insert(key, value); mAdaptor->setProperty(key, value); } | 236 | virtual void setProperty(const QByteArray &key, const QVariant &value){ mChangeSet.insert(key, value); mAdaptor->setProperty(key, value); } |
237 | virtual QByteArrayList changedProperties() const { return mChangeSet.keys(); } | ||
238 | qint64 revision() const { return mRevision; } | ||
237 | 239 | ||
238 | private: | 240 | private: |
239 | QSharedPointer<BufferAdaptor> mAdaptor; | 241 | QSharedPointer<BufferAdaptor> mAdaptor; |
240 | QHash<QString, QVariant> mChangeSet; | 242 | QHash<QByteArray, QVariant> mChangeSet; |
241 | /* | 243 | /* |
242 | * Each domain object needs to store the resource, identifier, revision triple so we can link back to the storage location. | 244 | * Each domain object needs to store the resource, identifier, revision triple so we can link back to the storage location. |
243 | */ | 245 | */ |
244 | QString mResourceName; | 246 | QString mResourceName; |
245 | QString mIdentifier; | 247 | QByteArray mIdentifier; |
246 | qint64 mRevision; | 248 | qint64 mRevision; |
247 | }; | 249 | }; |
248 | 250 | ||
249 | struct Event : public AkonadiDomainType { | 251 | struct Event : public ApplicationDomainType { |
250 | typedef QSharedPointer<Event> Ptr; | 252 | typedef QSharedPointer<Event> Ptr; |
251 | using AkonadiDomainType::AkonadiDomainType; | 253 | using ApplicationDomainType::ApplicationDomainType; |
252 | }; | 254 | }; |
253 | 255 | ||
254 | struct Todo : public AkonadiDomainType { | 256 | struct Todo : public ApplicationDomainType { |
255 | typedef QSharedPointer<Todo> Ptr; | 257 | typedef QSharedPointer<Todo> Ptr; |
256 | using AkonadiDomainType::AkonadiDomainType; | 258 | using ApplicationDomainType::ApplicationDomainType; |
257 | }; | 259 | }; |
258 | 260 | ||
259 | struct Calendar : public AkonadiDomainType { | 261 | struct Calendar : public ApplicationDomainType { |
260 | typedef QSharedPointer<Calendar> Ptr; | 262 | typedef QSharedPointer<Calendar> Ptr; |
261 | using AkonadiDomainType::AkonadiDomainType; | 263 | using ApplicationDomainType::ApplicationDomainType; |
262 | }; | 264 | }; |
263 | 265 | ||
264 | class Mail : public AkonadiDomainType { | 266 | class Mail : public ApplicationDomainType { |
265 | }; | 267 | }; |
266 | 268 | ||
267 | class Folder : public AkonadiDomainType { | 269 | class Folder : public ApplicationDomainType { |
268 | }; | 270 | }; |
269 | 271 | ||
270 | /** | 272 | /** |
@@ -274,13 +276,13 @@ class Folder : public AkonadiDomainType { | |||
274 | */ | 276 | */ |
275 | 277 | ||
276 | template<class DomainType> | 278 | template<class DomainType> |
277 | QString getTypeName(); | 279 | QByteArray getTypeName(); |
278 | 280 | ||
279 | template<> | 281 | template<> |
280 | QString getTypeName<Event>(); | 282 | QByteArray getTypeName<Event>(); |
281 | 283 | ||
282 | template<> | 284 | template<> |
283 | QString getTypeName<Todo>(); | 285 | QByteArray getTypeName<Todo>(); |
284 | 286 | ||
285 | } | 287 | } |
286 | 288 | ||
@@ -298,19 +300,22 @@ using namespace async; | |||
298 | * * what resources to search | 300 | * * what resources to search |
299 | * * filters on various properties (parent collection, startDate range, ....) | 301 | * * filters on various properties (parent collection, startDate range, ....) |
300 | * * properties we need (for on-demand querying) | 302 | * * properties we need (for on-demand querying) |
303 | * | ||
304 | * syncOnDemand: Execute a source sync before executing the query | ||
305 | * processAll: Ensure all local messages are processed before querying to guarantee an up-to date dataset. | ||
301 | */ | 306 | */ |
302 | class Query | 307 | class Query |
303 | { | 308 | { |
304 | public: | 309 | public: |
305 | Query() : syncOnDemand(true), processAll(false) {} | 310 | Query() : syncOnDemand(true), processAll(false) {} |
306 | //Could also be a propertyFilter | 311 | //Could also be a propertyFilter |
307 | QStringList resources; | 312 | QByteArrayList resources; |
308 | //Could also be a propertyFilter | 313 | //Could also be a propertyFilter |
309 | QStringList ids; | 314 | QByteArrayList ids; |
310 | //Filters to apply | 315 | //Filters to apply |
311 | QHash<QString, QVariant> propertyFilter; | 316 | QHash<QByteArray, QVariant> propertyFilter; |
312 | //Properties to retrieve | 317 | //Properties to retrieve |
313 | QSet<QString> requestedProperties; | 318 | QSet<QByteArray> requestedProperties; |
314 | bool syncOnDemand; | 319 | bool syncOnDemand; |
315 | bool processAll; | 320 | bool processAll; |
316 | }; | 321 | }; |
@@ -328,7 +333,7 @@ template<class DomainType> | |||
328 | class StoreFacade { | 333 | class StoreFacade { |
329 | public: | 334 | public: |
330 | virtual ~StoreFacade(){}; | 335 | virtual ~StoreFacade(){}; |
331 | QString type() const { return Domain::getTypeName<DomainType>(); } | 336 | QByteArray type() const { return ApplicationDomain::getTypeName<DomainType>(); } |
332 | virtual Async::Job<void> create(const DomainType &domainObject) = 0; | 337 | virtual Async::Job<void> create(const DomainType &domainObject) = 0; |
333 | virtual Async::Job<void> modify(const DomainType &domainObject) = 0; | 338 | virtual Async::Job<void> modify(const DomainType &domainObject) = 0; |
334 | virtual Async::Job<void> remove(const DomainType &domainObject) = 0; | 339 | virtual Async::Job<void> remove(const DomainType &domainObject) = 0; |
@@ -351,15 +356,15 @@ public: | |||
351 | return factory; | 356 | return factory; |
352 | } | 357 | } |
353 | 358 | ||
354 | static QString key(const QString &resource, const QString &type) | 359 | static QByteArray key(const QByteArray &resource, const QByteArray &type) |
355 | { | 360 | { |
356 | return resource + type; | 361 | return resource + type; |
357 | } | 362 | } |
358 | 363 | ||
359 | template<class DomainType, class Facade> | 364 | template<class DomainType, class Facade> |
360 | void registerFacade(const QString &resource) | 365 | void registerFacade(const QByteArray &resource) |
361 | { | 366 | { |
362 | const QString typeName = Domain::getTypeName<DomainType>(); | 367 | const QByteArray typeName = ApplicationDomain::getTypeName<DomainType>(); |
363 | mFacadeRegistry.insert(key(resource, typeName), [](){ return new Facade; }); | 368 | mFacadeRegistry.insert(key(resource, typeName), [](){ return new Facade; }); |
364 | } | 369 | } |
365 | 370 | ||
@@ -373,16 +378,16 @@ public: | |||
373 | * FIXME the factory function should really be returning QSharedPointer<void>, which doesn't work (std::shared_pointer<void> would though). That way i.e. a test could keep the object alive until it's done. | 378 | * FIXME the factory function should really be returning QSharedPointer<void>, which doesn't work (std::shared_pointer<void> would though). That way i.e. a test could keep the object alive until it's done. |
374 | */ | 379 | */ |
375 | template<class DomainType, class Facade> | 380 | template<class DomainType, class Facade> |
376 | void registerFacade(const QString &resource, const std::function<void*(void)> &customFactoryFunction) | 381 | void registerFacade(const QByteArray &resource, const std::function<void*(void)> &customFactoryFunction) |
377 | { | 382 | { |
378 | const QString typeName = Domain::getTypeName<DomainType>(); | 383 | const QByteArray typeName = ApplicationDomain::getTypeName<DomainType>(); |
379 | mFacadeRegistry.insert(key(resource, typeName), customFactoryFunction); | 384 | mFacadeRegistry.insert(key(resource, typeName), customFactoryFunction); |
380 | } | 385 | } |
381 | 386 | ||
382 | template<class DomainType> | 387 | template<class DomainType> |
383 | QSharedPointer<StoreFacade<DomainType> > getFacade(const QString &resource) | 388 | QSharedPointer<StoreFacade<DomainType> > getFacade(const QByteArray &resource) |
384 | { | 389 | { |
385 | const QString typeName = Domain::getTypeName<DomainType>(); | 390 | const QByteArray typeName = ApplicationDomain::getTypeName<DomainType>(); |
386 | auto factoryFunction = mFacadeRegistry.value(key(resource, typeName)); | 391 | auto factoryFunction = mFacadeRegistry.value(key(resource, typeName)); |
387 | if (factoryFunction) { | 392 | if (factoryFunction) { |
388 | return QSharedPointer<StoreFacade<DomainType> >(static_cast<StoreFacade<DomainType>* >(factoryFunction())); | 393 | return QSharedPointer<StoreFacade<DomainType> >(static_cast<StoreFacade<DomainType>* >(factoryFunction())); |
@@ -392,7 +397,7 @@ public: | |||
392 | } | 397 | } |
393 | 398 | ||
394 | private: | 399 | private: |
395 | QHash<QString, std::function<void*(void)> > mFacadeRegistry; | 400 | QHash<QByteArray, std::function<void*(void)> > mFacadeRegistry; |
396 | }; | 401 | }; |
397 | 402 | ||
398 | /** | 403 | /** |
@@ -421,7 +426,7 @@ public: | |||
421 | // query tells us in which resources we're interested | 426 | // query tells us in which resources we're interested |
422 | // TODO: queries to individual resources could be parallelized | 427 | // TODO: queries to individual resources could be parallelized |
423 | Async::Job<void> job = Async::null<void>(); | 428 | Async::Job<void> job = Async::null<void>(); |
424 | for(const QString &resource : query.resources) { | 429 | for(const QByteArray &resource : query.resources) { |
425 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resource); | 430 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resource); |
426 | //We have to bind an instance to the function callback. Since we use a shared pointer this keeps the result provider instance (and thus also the emitter) alive. | 431 | //We have to bind an instance to the function callback. Since we use a shared pointer this keeps the result provider instance (and thus also the emitter) alive. |
427 | std::function<void(const typename DomainType::Ptr &)> addCallback = std::bind(&ResultProvider<typename DomainType::Ptr>::add, resultSet, std::placeholders::_1); | 432 | std::function<void(const typename DomainType::Ptr &)> addCallback = std::bind(&ResultProvider<typename DomainType::Ptr>::add, resultSet, std::placeholders::_1); |
@@ -460,7 +465,7 @@ public: | |||
460 | */ | 465 | */ |
461 | //TODO return job that tracks progress until resource has stored the message in it's queue? | 466 | //TODO return job that tracks progress until resource has stored the message in it's queue? |
462 | template <class DomainType> | 467 | template <class DomainType> |
463 | static void create(const DomainType &domainObject, const QString &resourceIdentifier) { | 468 | static void create(const DomainType &domainObject, const QByteArray &resourceIdentifier) { |
464 | //Potentially move to separate thread as well | 469 | //Potentially move to separate thread as well |
465 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceIdentifier); | 470 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceIdentifier); |
466 | auto job = facade->create(domainObject); | 471 | auto job = facade->create(domainObject); |
@@ -475,7 +480,7 @@ public: | |||
475 | * This includes moving etc. since these are also simple settings on a property. | 480 | * This includes moving etc. since these are also simple settings on a property. |
476 | */ | 481 | */ |
477 | template <class DomainType> | 482 | template <class DomainType> |
478 | static void modify(const DomainType &domainObject, const QString &resourceIdentifier) { | 483 | static void modify(const DomainType &domainObject, const QByteArray &resourceIdentifier) { |
479 | //Potentially move to separate thread as well | 484 | //Potentially move to separate thread as well |
480 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceIdentifier); | 485 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceIdentifier); |
481 | facade.modify(domainObject); | 486 | facade.modify(domainObject); |
@@ -485,13 +490,13 @@ public: | |||
485 | * Remove an entity. | 490 | * Remove an entity. |
486 | */ | 491 | */ |
487 | template <class DomainType> | 492 | template <class DomainType> |
488 | static void remove(const DomainType &domainObject, const QString &resourceIdentifier) { | 493 | static void remove(const DomainType &domainObject, const QByteArray &resourceIdentifier) { |
489 | //Potentially move to separate thread as well | 494 | //Potentially move to separate thread as well |
490 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceIdentifier); | 495 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceIdentifier); |
491 | facade.remove(domainObject); | 496 | facade.remove(domainObject); |
492 | } | 497 | } |
493 | 498 | ||
494 | static void shutdown(const QString &resourceIdentifier); | 499 | static void shutdown(const QByteArray &resourceIdentifier); |
495 | }; | 500 | }; |
496 | 501 | ||
497 | } | 502 | } |