diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-01-03 00:08:44 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-01-03 00:08:44 +0100 |
commit | 4067462b0a27984df84b0379c19122d574253dfb (patch) | |
tree | e6a413a575b7fd4062da6474907bffd68155706f /common | |
parent | 91d915a09b7d52c10edb1d4c1298fc2885b8a257 (diff) | |
download | sink-4067462b0a27984df84b0379c19122d574253dfb.tar.gz sink-4067462b0a27984df84b0379c19122d574253dfb.zip |
Shared domain adaptors between resource and facade.
Diffstat (limited to 'common')
-rw-r--r-- | common/domainadaptor.h | 77 | ||||
-rw-r--r-- | common/pipeline.cpp | 6 | ||||
-rw-r--r-- | common/pipeline.h | 3 |
3 files changed, 86 insertions, 0 deletions
diff --git a/common/domainadaptor.h b/common/domainadaptor.h new file mode 100644 index 0000000..e8f586b --- /dev/null +++ b/common/domainadaptor.h | |||
@@ -0,0 +1,77 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014 Christian Mollekopf <chrigi_1@fastmail.fm> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | */ | ||
19 | |||
20 | #pragma once | ||
21 | |||
22 | #include "entity_generated.h" | ||
23 | #include <QVariant> | ||
24 | #include <QString> | ||
25 | #include <functional> | ||
26 | #include "clientapi.h" //for domain parts | ||
27 | |||
28 | /** | ||
29 | * The property mapper holds accessor functions for all properties. | ||
30 | * | ||
31 | * It is by default initialized with accessors that access the local-only buffer, | ||
32 | * and resource simply have to overwrite those accessors. | ||
33 | */ | ||
34 | template<typename BufferType> | ||
35 | class PropertyMapper | ||
36 | { | ||
37 | public: | ||
38 | void setProperty(const QString &key, const QVariant &value, BufferType *buffer) | ||
39 | { | ||
40 | if (mWriteAccessors.contains(key)) { | ||
41 | auto accessor = mWriteAccessors.value(key); | ||
42 | return accessor(value, buffer); | ||
43 | } | ||
44 | } | ||
45 | |||
46 | virtual QVariant getProperty(const QString &key, BufferType const *buffer) const | ||
47 | { | ||
48 | if (mReadAccessors.contains(key)) { | ||
49 | auto accessor = mReadAccessors.value(key); | ||
50 | return accessor(buffer); | ||
51 | } | ||
52 | return QVariant(); | ||
53 | } | ||
54 | QHash<QString, std::function<QVariant(BufferType const *)> > mReadAccessors; | ||
55 | QHash<QString, std::function<void(const QVariant &, BufferType*)> > mWriteAccessors; | ||
56 | }; | ||
57 | |||
58 | //The factory should define how to go from an entitybuffer (local + resource buffer), to a domain type adapter. | ||
59 | //It defines how values are split accross local and resource buffer. | ||
60 | //This is required by the facade the read the value, and by the pipeline preprocessors to access the domain values in a generic way. | ||
61 | // template<typename DomainType, typename LocalBuffer, typename ResourceBuffer> | ||
62 | // class DomainTypeAdaptorFactory | ||
63 | // { | ||
64 | // }; | ||
65 | |||
66 | template<typename DomainType, typename LocalBuffer, typename ResourceBuffer> | ||
67 | class DomainTypeAdaptorFactory/* <typename DomainType, LocalBuffer, ResourceBuffer> */ | ||
68 | { | ||
69 | public: | ||
70 | virtual QSharedPointer<Akonadi2::Domain::BufferAdaptor> createAdaptor(const Akonadi2::Entity &entity) = 0; | ||
71 | |||
72 | protected: | ||
73 | QSharedPointer<PropertyMapper<LocalBuffer> > mLocalMapper; | ||
74 | QSharedPointer<PropertyMapper<ResourceBuffer> > mResourceMapper; | ||
75 | }; | ||
76 | |||
77 | |||
diff --git a/common/pipeline.cpp b/common/pipeline.cpp index 8d00480..18b6d51 100644 --- a/common/pipeline.cpp +++ b/common/pipeline.cpp | |||
@@ -189,6 +189,7 @@ public: | |||
189 | Pipeline *pipeline; | 189 | Pipeline *pipeline; |
190 | Pipeline::Type type; | 190 | Pipeline::Type type; |
191 | QByteArray key; | 191 | QByteArray key; |
192 | Akonadi2::Entity *entity; | ||
192 | QVectorIterator<Preprocessor *> filterIt; | 193 | QVectorIterator<Preprocessor *> filterIt; |
193 | bool idle; | 194 | bool idle; |
194 | }; | 195 | }; |
@@ -239,6 +240,11 @@ Pipeline::Type PipelineState::type() const | |||
239 | return d->type; | 240 | return d->type; |
240 | } | 241 | } |
241 | 242 | ||
243 | const Akonadi2::Entity &PipelineState::entity() const | ||
244 | { | ||
245 | return *d->entity; | ||
246 | } | ||
247 | |||
242 | void PipelineState::step() | 248 | void PipelineState::step() |
243 | { | 249 | { |
244 | if (!d->pipeline) { | 250 | if (!d->pipeline) { |
diff --git a/common/pipeline.h b/common/pipeline.h index 8373899..6005331 100644 --- a/common/pipeline.h +++ b/common/pipeline.h | |||
@@ -29,6 +29,8 @@ | |||
29 | #include <storage.h> | 29 | #include <storage.h> |
30 | #include <clientapi.h> //For domain types | 30 | #include <clientapi.h> //For domain types |
31 | 31 | ||
32 | #include "entity_generated.h" | ||
33 | |||
32 | namespace Akonadi2 | 34 | namespace Akonadi2 |
33 | { | 35 | { |
34 | 36 | ||
@@ -112,6 +114,7 @@ public: | |||
112 | bool isIdle() const; | 114 | bool isIdle() const; |
113 | QByteArray key() const; | 115 | QByteArray key() const; |
114 | Pipeline::Type type() const; | 116 | Pipeline::Type type() const; |
117 | const Akonadi2::Entity &entity() const; | ||
115 | 118 | ||
116 | void step(); | 119 | void step(); |
117 | void processingCompleted(Preprocessor *filter); | 120 | void processingCompleted(Preprocessor *filter); |