diff options
Diffstat (limited to 'dummyresource/facade.h')
-rw-r--r-- | dummyresource/facade.h | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/dummyresource/facade.h b/dummyresource/facade.h index c76e62c..46b27ef 100644 --- a/dummyresource/facade.h +++ b/dummyresource/facade.h | |||
@@ -21,11 +21,63 @@ | |||
21 | 21 | ||
22 | #include "common/clientapi.h" | 22 | #include "common/clientapi.h" |
23 | #include "common/storage.h" | 23 | #include "common/storage.h" |
24 | #include "entity_generated.h" | ||
25 | #include "event_generated.h" | ||
26 | #include "dummycalendar_generated.h" | ||
24 | 27 | ||
25 | namespace Akonadi2 { | 28 | namespace Akonadi2 { |
26 | class ResourceAccess; | 29 | class ResourceAccess; |
27 | } | 30 | } |
28 | 31 | ||
32 | /** | ||
33 | * The property mapper holds accessor functions for all properties. | ||
34 | * | ||
35 | * It is by default initialized with accessors that access the local-only buffer, | ||
36 | * and resource simply have to overwrite those accessors. | ||
37 | */ | ||
38 | template<typename BufferType> | ||
39 | class PropertyMapper | ||
40 | { | ||
41 | public: | ||
42 | void setProperty(const QString &key, const QVariant &value, BufferType *buffer) | ||
43 | { | ||
44 | if (mWriteAccessors.contains(key)) { | ||
45 | auto accessor = mWriteAccessors.value(key); | ||
46 | return accessor(value, buffer); | ||
47 | } | ||
48 | } | ||
49 | |||
50 | virtual QVariant getProperty(const QString &key, BufferType const *buffer) const | ||
51 | { | ||
52 | if (mReadAccessors.contains(key)) { | ||
53 | auto accessor = mReadAccessors.value(key); | ||
54 | return accessor(buffer); | ||
55 | } | ||
56 | return QVariant(); | ||
57 | } | ||
58 | QHash<QString, std::function<QVariant(BufferType const *)> > mReadAccessors; | ||
59 | QHash<QString, std::function<void(const QVariant &, BufferType*)> > mWriteAccessors; | ||
60 | }; | ||
61 | |||
62 | //The factory should define how to go from an entitybuffer (local + resource buffer), to a domain type adapter. | ||
63 | //It defines how values are split accross local and resource buffer. | ||
64 | //This is required by the facade the read the value, and by the pipeline preprocessors to access the domain values in a generic way. | ||
65 | template<typename DomainType, typename LocalBuffer, typename ResourceBuffer> | ||
66 | class DomainTypeAdaptorFactory | ||
67 | { | ||
68 | }; | ||
69 | |||
70 | template<typename LocalBuffer, typename ResourceBuffer> | ||
71 | class DomainTypeAdaptorFactory<typename Akonadi2::Domain::Event, LocalBuffer, ResourceBuffer> | ||
72 | { | ||
73 | public: | ||
74 | QSharedPointer<Akonadi2::Domain::BufferAdaptor> createAdaptor(const Akonadi2::Entity &entity); | ||
75 | |||
76 | // private: | ||
77 | QSharedPointer<PropertyMapper<LocalBuffer> > mLocalMapper; | ||
78 | QSharedPointer<PropertyMapper<ResourceBuffer> > mResourceMapper; | ||
79 | }; | ||
80 | |||
29 | class DummyResourceFacade : public Akonadi2::StoreFacade<Akonadi2::Domain::Event> | 81 | class DummyResourceFacade : public Akonadi2::StoreFacade<Akonadi2::Domain::Event> |
30 | { | 82 | { |
31 | public: | 83 | public: |
@@ -39,4 +91,5 @@ public: | |||
39 | private: | 91 | private: |
40 | void synchronizeResource(const std::function<void()> &continuation); | 92 | void synchronizeResource(const std::function<void()> &continuation); |
41 | QSharedPointer<Akonadi2::ResourceAccess> mResourceAccess; | 93 | QSharedPointer<Akonadi2::ResourceAccess> mResourceAccess; |
94 | QSharedPointer<DomainTypeAdaptorFactory<Akonadi2::Domain::Event, Akonadi2::Domain::Buffer::Event, DummyCalendar::DummyEvent> > mFactory; | ||
42 | }; | 95 | }; |