diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/clientapi.cpp | 6 | ||||
-rw-r--r-- | common/clientapi.h | 66 | ||||
-rw-r--r-- | common/domainadaptor.h | 10 | ||||
-rw-r--r-- | common/resourceaccess.cpp | 10 | ||||
-rw-r--r-- | common/resourceaccess.h | 4 |
5 files changed, 48 insertions, 48 deletions
diff --git a/common/clientapi.cpp b/common/clientapi.cpp index 6f0b421..0281b79 100644 --- a/common/clientapi.cpp +++ b/common/clientapi.cpp | |||
@@ -18,20 +18,20 @@ namespace Domain | |||
18 | { | 18 | { |
19 | 19 | ||
20 | template<> | 20 | template<> |
21 | QString getTypeName<Event>() | 21 | QByteArray getTypeName<Event>() |
22 | { | 22 | { |
23 | return "event"; | 23 | return "event"; |
24 | } | 24 | } |
25 | 25 | ||
26 | template<> | 26 | template<> |
27 | QString getTypeName<Todo>() | 27 | QByteArray getTypeName<Todo>() |
28 | { | 28 | { |
29 | return "todo"; | 29 | return "todo"; |
30 | } | 30 | } |
31 | 31 | ||
32 | } // namespace Domain | 32 | } // namespace Domain |
33 | 33 | ||
34 | void Store::shutdown(const QString &identifier) | 34 | void Store::shutdown(const QByteArray &identifier) |
35 | { | 35 | { |
36 | Akonadi2::ResourceAccess resourceAccess(identifier); | 36 | Akonadi2::ResourceAccess resourceAccess(identifier); |
37 | //FIXME this starts the resource, just to shut it down again if it's not running in the first place. | 37 | //FIXME this starts the resource, just to shut it down again if it's not running in the first place. |
diff --git a/common/clientapi.h b/common/clientapi.h index 0ee934c..37fb185 100644 --- a/common/clientapi.h +++ b/common/clientapi.h | |||
@@ -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 | /** |
@@ -222,7 +222,7 @@ public: | |||
222 | { | 222 | { |
223 | 223 | ||
224 | } | 224 | } |
225 | AkonadiDomainType(const QString &resourceName, const QString &identifier, qint64 revision, const QSharedPointer<BufferAdaptor> &adaptor) | 225 | AkonadiDomainType(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), |
@@ -232,17 +232,17 @@ public: | |||
232 | 232 | ||
233 | virtual ~AkonadiDomainType() {} | 233 | virtual ~AkonadiDomainType() {} |
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 | 237 | ||
238 | private: | 238 | private: |
239 | QSharedPointer<BufferAdaptor> mAdaptor; | 239 | QSharedPointer<BufferAdaptor> mAdaptor; |
240 | QHash<QString, QVariant> mChangeSet; | 240 | QHash<QByteArray, QVariant> mChangeSet; |
241 | /* | 241 | /* |
242 | * Each domain object needs to store the resource, identifier, revision triple so we can link back to the storage location. | 242 | * Each domain object needs to store the resource, identifier, revision triple so we can link back to the storage location. |
243 | */ | 243 | */ |
244 | QString mResourceName; | 244 | QString mResourceName; |
245 | QString mIdentifier; | 245 | QByteArray mIdentifier; |
246 | qint64 mRevision; | 246 | qint64 mRevision; |
247 | }; | 247 | }; |
248 | 248 | ||
@@ -274,13 +274,13 @@ class Folder : public AkonadiDomainType { | |||
274 | */ | 274 | */ |
275 | 275 | ||
276 | template<class DomainType> | 276 | template<class DomainType> |
277 | QString getTypeName(); | 277 | QByteArray getTypeName(); |
278 | 278 | ||
279 | template<> | 279 | template<> |
280 | QString getTypeName<Event>(); | 280 | QByteArray getTypeName<Event>(); |
281 | 281 | ||
282 | template<> | 282 | template<> |
283 | QString getTypeName<Todo>(); | 283 | QByteArray getTypeName<Todo>(); |
284 | 284 | ||
285 | } | 285 | } |
286 | 286 | ||
@@ -307,13 +307,13 @@ class Query | |||
307 | public: | 307 | public: |
308 | Query() : syncOnDemand(true), processAll(false) {} | 308 | Query() : syncOnDemand(true), processAll(false) {} |
309 | //Could also be a propertyFilter | 309 | //Could also be a propertyFilter |
310 | QStringList resources; | 310 | QByteArrayList resources; |
311 | //Could also be a propertyFilter | 311 | //Could also be a propertyFilter |
312 | QStringList ids; | 312 | QByteArrayList ids; |
313 | //Filters to apply | 313 | //Filters to apply |
314 | QHash<QString, QVariant> propertyFilter; | 314 | QHash<QByteArray, QVariant> propertyFilter; |
315 | //Properties to retrieve | 315 | //Properties to retrieve |
316 | QSet<QString> requestedProperties; | 316 | QSet<QByteArray> requestedProperties; |
317 | bool syncOnDemand; | 317 | bool syncOnDemand; |
318 | bool processAll; | 318 | bool processAll; |
319 | }; | 319 | }; |
@@ -331,7 +331,7 @@ template<class DomainType> | |||
331 | class StoreFacade { | 331 | class StoreFacade { |
332 | public: | 332 | public: |
333 | virtual ~StoreFacade(){}; | 333 | virtual ~StoreFacade(){}; |
334 | QString type() const { return Domain::getTypeName<DomainType>(); } | 334 | QByteArray type() const { return Domain::getTypeName<DomainType>(); } |
335 | virtual Async::Job<void> create(const DomainType &domainObject) = 0; | 335 | virtual Async::Job<void> create(const DomainType &domainObject) = 0; |
336 | virtual Async::Job<void> modify(const DomainType &domainObject) = 0; | 336 | virtual Async::Job<void> modify(const DomainType &domainObject) = 0; |
337 | virtual Async::Job<void> remove(const DomainType &domainObject) = 0; | 337 | virtual Async::Job<void> remove(const DomainType &domainObject) = 0; |
@@ -354,15 +354,15 @@ public: | |||
354 | return factory; | 354 | return factory; |
355 | } | 355 | } |
356 | 356 | ||
357 | static QString key(const QString &resource, const QString &type) | 357 | static QByteArray key(const QByteArray &resource, const QByteArray &type) |
358 | { | 358 | { |
359 | return resource + type; | 359 | return resource + type; |
360 | } | 360 | } |
361 | 361 | ||
362 | template<class DomainType, class Facade> | 362 | template<class DomainType, class Facade> |
363 | void registerFacade(const QString &resource) | 363 | void registerFacade(const QByteArray &resource) |
364 | { | 364 | { |
365 | const QString typeName = Domain::getTypeName<DomainType>(); | 365 | const QByteArray typeName = Domain::getTypeName<DomainType>(); |
366 | mFacadeRegistry.insert(key(resource, typeName), [](){ return new Facade; }); | 366 | mFacadeRegistry.insert(key(resource, typeName), [](){ return new Facade; }); |
367 | } | 367 | } |
368 | 368 | ||
@@ -376,16 +376,16 @@ public: | |||
376 | * 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. | 376 | * 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. |
377 | */ | 377 | */ |
378 | template<class DomainType, class Facade> | 378 | template<class DomainType, class Facade> |
379 | void registerFacade(const QString &resource, const std::function<void*(void)> &customFactoryFunction) | 379 | void registerFacade(const QByteArray &resource, const std::function<void*(void)> &customFactoryFunction) |
380 | { | 380 | { |
381 | const QString typeName = Domain::getTypeName<DomainType>(); | 381 | const QByteArray typeName = Domain::getTypeName<DomainType>(); |
382 | mFacadeRegistry.insert(key(resource, typeName), customFactoryFunction); | 382 | mFacadeRegistry.insert(key(resource, typeName), customFactoryFunction); |
383 | } | 383 | } |
384 | 384 | ||
385 | template<class DomainType> | 385 | template<class DomainType> |
386 | QSharedPointer<StoreFacade<DomainType> > getFacade(const QString &resource) | 386 | QSharedPointer<StoreFacade<DomainType> > getFacade(const QByteArray &resource) |
387 | { | 387 | { |
388 | const QString typeName = Domain::getTypeName<DomainType>(); | 388 | const QByteArray typeName = Domain::getTypeName<DomainType>(); |
389 | auto factoryFunction = mFacadeRegistry.value(key(resource, typeName)); | 389 | auto factoryFunction = mFacadeRegistry.value(key(resource, typeName)); |
390 | if (factoryFunction) { | 390 | if (factoryFunction) { |
391 | return QSharedPointer<StoreFacade<DomainType> >(static_cast<StoreFacade<DomainType>* >(factoryFunction())); | 391 | return QSharedPointer<StoreFacade<DomainType> >(static_cast<StoreFacade<DomainType>* >(factoryFunction())); |
@@ -395,7 +395,7 @@ public: | |||
395 | } | 395 | } |
396 | 396 | ||
397 | private: | 397 | private: |
398 | QHash<QString, std::function<void*(void)> > mFacadeRegistry; | 398 | QHash<QByteArray, std::function<void*(void)> > mFacadeRegistry; |
399 | }; | 399 | }; |
400 | 400 | ||
401 | /** | 401 | /** |
@@ -424,7 +424,7 @@ public: | |||
424 | // query tells us in which resources we're interested | 424 | // query tells us in which resources we're interested |
425 | // TODO: queries to individual resources could be parallelized | 425 | // TODO: queries to individual resources could be parallelized |
426 | Async::Job<void> job = Async::null<void>(); | 426 | Async::Job<void> job = Async::null<void>(); |
427 | for(const QString &resource : query.resources) { | 427 | for(const QByteArray &resource : query.resources) { |
428 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resource); | 428 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resource); |
429 | //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. | 429 | //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. |
430 | std::function<void(const typename DomainType::Ptr &)> addCallback = std::bind(&ResultProvider<typename DomainType::Ptr>::add, resultSet, std::placeholders::_1); | 430 | std::function<void(const typename DomainType::Ptr &)> addCallback = std::bind(&ResultProvider<typename DomainType::Ptr>::add, resultSet, std::placeholders::_1); |
@@ -463,7 +463,7 @@ public: | |||
463 | */ | 463 | */ |
464 | //TODO return job that tracks progress until resource has stored the message in it's queue? | 464 | //TODO return job that tracks progress until resource has stored the message in it's queue? |
465 | template <class DomainType> | 465 | template <class DomainType> |
466 | static void create(const DomainType &domainObject, const QString &resourceIdentifier) { | 466 | static void create(const DomainType &domainObject, const QByteArray &resourceIdentifier) { |
467 | //Potentially move to separate thread as well | 467 | //Potentially move to separate thread as well |
468 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceIdentifier); | 468 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceIdentifier); |
469 | auto job = facade->create(domainObject); | 469 | auto job = facade->create(domainObject); |
@@ -478,7 +478,7 @@ public: | |||
478 | * This includes moving etc. since these are also simple settings on a property. | 478 | * This includes moving etc. since these are also simple settings on a property. |
479 | */ | 479 | */ |
480 | template <class DomainType> | 480 | template <class DomainType> |
481 | static void modify(const DomainType &domainObject, const QString &resourceIdentifier) { | 481 | static void modify(const DomainType &domainObject, const QByteArray &resourceIdentifier) { |
482 | //Potentially move to separate thread as well | 482 | //Potentially move to separate thread as well |
483 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceIdentifier); | 483 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceIdentifier); |
484 | facade.modify(domainObject); | 484 | facade.modify(domainObject); |
@@ -488,13 +488,13 @@ public: | |||
488 | * Remove an entity. | 488 | * Remove an entity. |
489 | */ | 489 | */ |
490 | template <class DomainType> | 490 | template <class DomainType> |
491 | static void remove(const DomainType &domainObject, const QString &resourceIdentifier) { | 491 | static void remove(const DomainType &domainObject, const QByteArray &resourceIdentifier) { |
492 | //Potentially move to separate thread as well | 492 | //Potentially move to separate thread as well |
493 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceIdentifier); | 493 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceIdentifier); |
494 | facade.remove(domainObject); | 494 | facade.remove(domainObject); |
495 | } | 495 | } |
496 | 496 | ||
497 | static void shutdown(const QString &resourceIdentifier); | 497 | static void shutdown(const QByteArray &resourceIdentifier); |
498 | }; | 498 | }; |
499 | 499 | ||
500 | } | 500 | } |
diff --git a/common/domainadaptor.h b/common/domainadaptor.h index e46e893..692c8c1 100644 --- a/common/domainadaptor.h +++ b/common/domainadaptor.h | |||
@@ -21,7 +21,7 @@ | |||
21 | 21 | ||
22 | #include "entity_generated.h" | 22 | #include "entity_generated.h" |
23 | #include <QVariant> | 23 | #include <QVariant> |
24 | #include <QString> | 24 | #include <QByteArray> |
25 | #include <functional> | 25 | #include <functional> |
26 | #include "clientapi.h" //for domain parts | 26 | #include "clientapi.h" //for domain parts |
27 | 27 | ||
@@ -35,7 +35,7 @@ template<typename BufferType> | |||
35 | class PropertyMapper | 35 | class PropertyMapper |
36 | { | 36 | { |
37 | public: | 37 | public: |
38 | void setProperty(const QString &key, const QVariant &value, BufferType *buffer) | 38 | void setProperty(const QByteArray &key, const QVariant &value, BufferType *buffer) |
39 | { | 39 | { |
40 | if (mWriteAccessors.contains(key)) { | 40 | if (mWriteAccessors.contains(key)) { |
41 | auto accessor = mWriteAccessors.value(key); | 41 | auto accessor = mWriteAccessors.value(key); |
@@ -43,7 +43,7 @@ public: | |||
43 | } | 43 | } |
44 | } | 44 | } |
45 | 45 | ||
46 | virtual QVariant getProperty(const QString &key, BufferType const *buffer) const | 46 | virtual QVariant getProperty(const QByteArray &key, BufferType const *buffer) const |
47 | { | 47 | { |
48 | if (mReadAccessors.contains(key)) { | 48 | if (mReadAccessors.contains(key)) { |
49 | auto accessor = mReadAccessors.value(key); | 49 | auto accessor = mReadAccessors.value(key); |
@@ -51,8 +51,8 @@ public: | |||
51 | } | 51 | } |
52 | return QVariant(); | 52 | return QVariant(); |
53 | } | 53 | } |
54 | QHash<QString, std::function<QVariant(BufferType const *)> > mReadAccessors; | 54 | QHash<QByteArray, std::function<QVariant(BufferType const *)> > mReadAccessors; |
55 | QHash<QString, std::function<void(const QVariant &, BufferType*)> > mWriteAccessors; | 55 | QHash<QByteArray, std::function<void(const QVariant &, BufferType*)> > mWriteAccessors; |
56 | }; | 56 | }; |
57 | 57 | ||
58 | //The factory should define how to go from an entitybuffer (local + resource buffer), to a domain type adapter. | 58 | //The factory should define how to go from an entitybuffer (local + resource buffer), to a domain type adapter. |
diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp index 7320e50..7a343f9 100644 --- a/common/resourceaccess.cpp +++ b/common/resourceaccess.cpp | |||
@@ -64,8 +64,8 @@ public: | |||
64 | class ResourceAccess::Private | 64 | class ResourceAccess::Private |
65 | { | 65 | { |
66 | public: | 66 | public: |
67 | Private(const QString &name, ResourceAccess *ra); | 67 | Private(const QByteArray &name, ResourceAccess *ra); |
68 | QString resourceName; | 68 | QByteArray resourceName; |
69 | QLocalSocket *socket; | 69 | QLocalSocket *socket; |
70 | QTimer *tryOpenTimer; | 70 | QTimer *tryOpenTimer; |
71 | bool startingProcess; | 71 | bool startingProcess; |
@@ -77,7 +77,7 @@ public: | |||
77 | uint messageId; | 77 | uint messageId; |
78 | }; | 78 | }; |
79 | 79 | ||
80 | ResourceAccess::Private::Private(const QString &name, ResourceAccess *q) | 80 | ResourceAccess::Private::Private(const QByteArray &name, ResourceAccess *q) |
81 | : resourceName(name), | 81 | : resourceName(name), |
82 | socket(new QLocalSocket(q)), | 82 | socket(new QLocalSocket(q)), |
83 | tryOpenTimer(new QTimer(q)), | 83 | tryOpenTimer(new QTimer(q)), |
@@ -87,7 +87,7 @@ ResourceAccess::Private::Private(const QString &name, ResourceAccess *q) | |||
87 | { | 87 | { |
88 | } | 88 | } |
89 | 89 | ||
90 | ResourceAccess::ResourceAccess(const QString &resourceName, QObject *parent) | 90 | ResourceAccess::ResourceAccess(const QByteArray &resourceName, QObject *parent) |
91 | : QObject(parent), | 91 | : QObject(parent), |
92 | d(new Private(resourceName, this)) | 92 | d(new Private(resourceName, this)) |
93 | { | 93 | { |
@@ -112,7 +112,7 @@ ResourceAccess::~ResourceAccess() | |||
112 | 112 | ||
113 | } | 113 | } |
114 | 114 | ||
115 | QString ResourceAccess::resourceName() const | 115 | QByteArray ResourceAccess::resourceName() const |
116 | { | 116 | { |
117 | return d->resourceName; | 117 | return d->resourceName; |
118 | } | 118 | } |
diff --git a/common/resourceaccess.h b/common/resourceaccess.h index a5a2547..088bf36 100644 --- a/common/resourceaccess.h +++ b/common/resourceaccess.h | |||
@@ -35,10 +35,10 @@ class ResourceAccess : public QObject | |||
35 | Q_OBJECT | 35 | Q_OBJECT |
36 | 36 | ||
37 | public: | 37 | public: |
38 | ResourceAccess(const QString &resourceName, QObject *parent = 0); | 38 | ResourceAccess(const QByteArray &resourceName, QObject *parent = 0); |
39 | ~ResourceAccess(); | 39 | ~ResourceAccess(); |
40 | 40 | ||
41 | QString resourceName() const; | 41 | QByteArray resourceName() const; |
42 | bool isReady() const; | 42 | bool isReady() const; |
43 | 43 | ||
44 | Async::Job<void> sendCommand(int commandId); | 44 | Async::Job<void> sendCommand(int commandId); |