diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-05-25 23:54:36 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-05-25 23:54:36 +0200 |
commit | b25c71e0a42b18b02764719d32714f07ca241b3f (patch) | |
tree | c780b3cdca0fd6495d2285a8876220de3b9a51f8 /common/clientapi.h | |
parent | 3601ee575f833bf204540f4fac41d87a0d977a79 (diff) | |
download | sink-b25c71e0a42b18b02764719d32714f07ca241b3f.tar.gz sink-b25c71e0a42b18b02764719d32714f07ca241b3f.zip |
Moved ApplicationDomainType and BufferAdaptor to separate files
Diffstat (limited to 'common/clientapi.h')
-rw-r--r-- | common/clientapi.h | 152 |
1 files changed, 1 insertions, 151 deletions
diff --git a/common/clientapi.h b/common/clientapi.h index d26a2ad..38ec1ee 100644 --- a/common/clientapi.h +++ b/common/clientapi.h | |||
@@ -33,6 +33,7 @@ | |||
33 | 33 | ||
34 | #include "threadboundary.h" | 34 | #include "threadboundary.h" |
35 | #include "resultprovider.h" | 35 | #include "resultprovider.h" |
36 | #include "domain/applicationdomaintype.h" | ||
36 | 37 | ||
37 | namespace async { | 38 | namespace async { |
38 | //This should abstract if we execute from eventloop or in thread. | 39 | //This should abstract if we execute from eventloop or in thread. |
@@ -42,157 +43,6 @@ namespace async { | |||
42 | 43 | ||
43 | namespace Akonadi2 { | 44 | namespace Akonadi2 { |
44 | 45 | ||
45 | /** | ||
46 | * Standardized Application Domain Types | ||
47 | * | ||
48 | * They don't adhere to any standard and can be freely extended | ||
49 | * Their sole purpose is providing a standardized interface to access data. | ||
50 | * | ||
51 | * This is necessary to decouple resource-backends from application domain containers (otherwise each resource would have to provide a faceade for each application domain container). | ||
52 | * | ||
53 | * These types will be frequently modified (for every new feature that should be exposed to the any client) | ||
54 | */ | ||
55 | namespace ApplicationDomain { | ||
56 | |||
57 | /** | ||
58 | * This class has to be implemented by resources and can be used as generic interface to access the buffer properties | ||
59 | */ | ||
60 | class BufferAdaptor { | ||
61 | public: | ||
62 | virtual ~BufferAdaptor() {} | ||
63 | virtual QVariant getProperty(const QByteArray &key) const { return QVariant(); } | ||
64 | virtual void setProperty(const QByteArray &key, const QVariant &value) {} | ||
65 | virtual QList<QByteArray> availableProperties() const { return QList<QByteArray>(); } | ||
66 | }; | ||
67 | |||
68 | class MemoryBufferAdaptor : public BufferAdaptor { | ||
69 | public: | ||
70 | MemoryBufferAdaptor() | ||
71 | : BufferAdaptor() | ||
72 | { | ||
73 | } | ||
74 | |||
75 | MemoryBufferAdaptor(const BufferAdaptor &buffer) | ||
76 | : BufferAdaptor() | ||
77 | { | ||
78 | for(const auto &property : buffer.availableProperties()) { | ||
79 | mValues.insert(property, buffer.getProperty(property)); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | virtual ~MemoryBufferAdaptor() {} | ||
84 | |||
85 | virtual QVariant getProperty(const QByteArray &key) const { return mValues.value(key); } | ||
86 | virtual void setProperty(const QByteArray &key, const QVariant &value) { mValues.insert(key, value); } | ||
87 | virtual QByteArrayList availableProperties() const { return mValues.keys(); } | ||
88 | |||
89 | private: | ||
90 | QHash<QByteArray, QVariant> mValues; | ||
91 | }; | ||
92 | |||
93 | /** | ||
94 | * The domain type interface has two purposes: | ||
95 | * * provide a unified interface to read buffers (for zero-copy reading) | ||
96 | * * record changes to generate changesets for modifications | ||
97 | */ | ||
98 | class ApplicationDomainType { | ||
99 | public: | ||
100 | typedef QSharedPointer<ApplicationDomainType> Ptr; | ||
101 | |||
102 | ApplicationDomainType() | ||
103 | :mAdaptor(new MemoryBufferAdaptor()) | ||
104 | { | ||
105 | |||
106 | } | ||
107 | |||
108 | ApplicationDomainType(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier, qint64 revision, const QSharedPointer<BufferAdaptor> &adaptor) | ||
109 | : mAdaptor(adaptor), | ||
110 | mResourceInstanceIdentifier(resourceInstanceIdentifier), | ||
111 | mIdentifier(identifier), | ||
112 | mRevision(revision) | ||
113 | { | ||
114 | } | ||
115 | |||
116 | template <typename DomainType> | ||
117 | static typename DomainType::Ptr getInMemoryRepresentation(const ApplicationDomainType::Ptr &domainType) | ||
118 | { | ||
119 | //TODO only copy requested properties | ||
120 | auto memoryAdaptor = QSharedPointer<Akonadi2::ApplicationDomain::MemoryBufferAdaptor>::create(*(domainType->mAdaptor)); | ||
121 | return QSharedPointer<DomainType>::create(domainType->mResourceInstanceIdentifier, domainType->mIdentifier, domainType->mRevision, memoryAdaptor); | ||
122 | } | ||
123 | |||
124 | virtual ~ApplicationDomainType() {} | ||
125 | |||
126 | virtual QVariant getProperty(const QByteArray &key) const { return mAdaptor->getProperty(key); } | ||
127 | virtual void setProperty(const QByteArray &key, const QVariant &value){ mChangeSet.insert(key, value); mAdaptor->setProperty(key, value); } | ||
128 | virtual QByteArrayList changedProperties() const { return mChangeSet.keys(); } | ||
129 | qint64 revision() const { return mRevision; } | ||
130 | QByteArray resourceInstanceIdentifier() const { return mResourceInstanceIdentifier; } | ||
131 | QByteArray identifier() const { return mIdentifier; } | ||
132 | |||
133 | private: | ||
134 | QSharedPointer<BufferAdaptor> mAdaptor; | ||
135 | QHash<QByteArray, QVariant> mChangeSet; | ||
136 | /* | ||
137 | * Each domain object needs to store the resource, identifier, revision triple so we can link back to the storage location. | ||
138 | */ | ||
139 | QByteArray mResourceInstanceIdentifier; | ||
140 | QByteArray mIdentifier; | ||
141 | qint64 mRevision; | ||
142 | }; | ||
143 | |||
144 | struct Event : public ApplicationDomainType { | ||
145 | typedef QSharedPointer<Event> Ptr; | ||
146 | using ApplicationDomainType::ApplicationDomainType; | ||
147 | }; | ||
148 | |||
149 | struct Todo : public ApplicationDomainType { | ||
150 | typedef QSharedPointer<Todo> Ptr; | ||
151 | using ApplicationDomainType::ApplicationDomainType; | ||
152 | }; | ||
153 | |||
154 | struct Calendar : public ApplicationDomainType { | ||
155 | typedef QSharedPointer<Calendar> Ptr; | ||
156 | using ApplicationDomainType::ApplicationDomainType; | ||
157 | }; | ||
158 | |||
159 | class Mail : public ApplicationDomainType { | ||
160 | }; | ||
161 | |||
162 | class Folder : public ApplicationDomainType { | ||
163 | }; | ||
164 | |||
165 | /** | ||
166 | * Represents an akonadi resource. | ||
167 | * | ||
168 | * This type is used for configuration of resources, | ||
169 | * and for creating and removing resource instances. | ||
170 | */ | ||
171 | struct AkonadiResource : public ApplicationDomainType { | ||
172 | typedef QSharedPointer<AkonadiResource> Ptr; | ||
173 | using ApplicationDomainType::ApplicationDomainType; | ||
174 | }; | ||
175 | |||
176 | /** | ||
177 | * All types need to be registered here an MUST return a different name. | ||
178 | * | ||
179 | * Do not store these types to disk, they may change over time. | ||
180 | */ | ||
181 | |||
182 | template<class DomainType> | ||
183 | QByteArray getTypeName(); | ||
184 | |||
185 | template<> | ||
186 | QByteArray getTypeName<Event>(); | ||
187 | |||
188 | template<> | ||
189 | QByteArray getTypeName<Todo>(); | ||
190 | |||
191 | template<> | ||
192 | QByteArray getTypeName<AkonadiResource>(); | ||
193 | |||
194 | } | ||
195 | |||
196 | using namespace async; | 46 | using namespace async; |
197 | 47 | ||
198 | /** | 48 | /** |