diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/genericresource.cpp | 6 | ||||
-rw-r--r-- | common/genericresource.h | 3 | ||||
-rw-r--r-- | common/indexupdater.h | 87 |
3 files changed, 96 insertions, 0 deletions
diff --git a/common/genericresource.cpp b/common/genericresource.cpp index 3655a63..4250a02 100644 --- a/common/genericresource.cpp +++ b/common/genericresource.cpp | |||
@@ -285,6 +285,12 @@ GenericResource::~GenericResource() | |||
285 | delete mSourceChangeReplay; | 285 | delete mSourceChangeReplay; |
286 | } | 286 | } |
287 | 287 | ||
288 | void GenericResource::addType(const QByteArray &type, DomainTypeAdaptorFactoryInterface::Ptr factory, const QVector<Akonadi2::Preprocessor*> &preprocessors) | ||
289 | { | ||
290 | mPipeline->setPreprocessors(type, preprocessors); | ||
291 | mPipeline->setAdaptorFactory(type, factory); | ||
292 | } | ||
293 | |||
288 | KAsync::Job<void> GenericResource::replay(const QByteArray &type, const QByteArray &key, const QByteArray &value) | 294 | KAsync::Job<void> GenericResource::replay(const QByteArray &type, const QByteArray &key, const QByteArray &value) |
289 | { | 295 | { |
290 | return KAsync::null<void>(); | 296 | return KAsync::null<void>(); |
diff --git a/common/genericresource.h b/common/genericresource.h index f756273..82c8a49 100644 --- a/common/genericresource.h +++ b/common/genericresource.h | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <resource.h> | 23 | #include <resource.h> |
24 | #include <messagequeue.h> | 24 | #include <messagequeue.h> |
25 | #include <flatbuffers/flatbuffers.h> | 25 | #include <flatbuffers/flatbuffers.h> |
26 | #include <domainadaptor.h> | ||
26 | #include <QTimer> | 27 | #include <QTimer> |
27 | 28 | ||
28 | class Processor; | 29 | class Processor; |
@@ -31,6 +32,7 @@ class ChangeReplay; | |||
31 | namespace Akonadi2 | 32 | namespace Akonadi2 |
32 | { | 33 | { |
33 | class Pipeline; | 34 | class Pipeline; |
35 | class Preprocessor; | ||
34 | 36 | ||
35 | /** | 37 | /** |
36 | * Generic Resource implementation. | 38 | * Generic Resource implementation. |
@@ -54,6 +56,7 @@ private Q_SLOTS: | |||
54 | void updateLowerBoundRevision(); | 56 | void updateLowerBoundRevision(); |
55 | 57 | ||
56 | protected: | 58 | protected: |
59 | void addType(const QByteArray &type, DomainTypeAdaptorFactoryInterface::Ptr factory, const QVector<Akonadi2::Preprocessor*> &preprocessors); | ||
57 | virtual KAsync::Job<void> replay(const QByteArray &type, const QByteArray &key, const QByteArray &value); | 60 | virtual KAsync::Job<void> replay(const QByteArray &type, const QByteArray &key, const QByteArray &value); |
58 | void onProcessorError(int errorCode, const QString &errorMessage); | 61 | void onProcessorError(int errorCode, const QString &errorMessage); |
59 | void enqueueCommand(MessageQueue &mq, int commandId, const QByteArray &data); | 62 | void enqueueCommand(MessageQueue &mq, int commandId, const QByteArray &data); |
diff --git a/common/indexupdater.h b/common/indexupdater.h new file mode 100644 index 0000000..48144e6 --- /dev/null +++ b/common/indexupdater.h | |||
@@ -0,0 +1,87 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2015 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 | #pragma once | ||
20 | |||
21 | #include <pipeline.h> | ||
22 | #include <index.h> | ||
23 | |||
24 | class IndexUpdater : public Akonadi2::Preprocessor { | ||
25 | public: | ||
26 | IndexUpdater(const QByteArray &index, const QByteArray &type, const QByteArray &property) | ||
27 | :mIndexIdentifier(index), | ||
28 | mBufferType(type), | ||
29 | mProperty(property) | ||
30 | { | ||
31 | |||
32 | } | ||
33 | |||
34 | void newEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE | ||
35 | { | ||
36 | add(newEntity.getProperty(mProperty), uid, transaction); | ||
37 | } | ||
38 | |||
39 | void modifiedEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE | ||
40 | { | ||
41 | remove(oldEntity.getProperty(mProperty), uid, transaction); | ||
42 | add(newEntity.getProperty(mProperty), uid, transaction); | ||
43 | } | ||
44 | |||
45 | void deletedEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE | ||
46 | { | ||
47 | remove(oldEntity.getProperty(mProperty), uid, transaction); | ||
48 | } | ||
49 | |||
50 | private: | ||
51 | void add(const QVariant &value, const QByteArray &uid, Akonadi2::Storage::Transaction &transaction) | ||
52 | { | ||
53 | if (value.isValid()) { | ||
54 | Index(mIndexIdentifier, transaction).add(value.toByteArray(), uid); | ||
55 | } | ||
56 | } | ||
57 | |||
58 | void remove(const QVariant &value, const QByteArray &uid, Akonadi2::Storage::Transaction &transaction) | ||
59 | { | ||
60 | //TODO hide notfound error | ||
61 | Index(mIndexIdentifier, transaction).remove(value.toByteArray(), uid); | ||
62 | } | ||
63 | |||
64 | QByteArray mIndexIdentifier; | ||
65 | QByteArray mBufferType; | ||
66 | QByteArray mProperty; | ||
67 | }; | ||
68 | |||
69 | template<typename DomainType> | ||
70 | class DefaultIndexUpdater : public Akonadi2::Preprocessor { | ||
71 | public: | ||
72 | void newEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE | ||
73 | { | ||
74 | Akonadi2::ApplicationDomain::TypeImplementation<DomainType>::index(uid, newEntity, transaction); | ||
75 | } | ||
76 | |||
77 | void modifiedEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE | ||
78 | { | ||
79 | Akonadi2::ApplicationDomain::TypeImplementation<DomainType>::removeIndex(uid, oldEntity, transaction); | ||
80 | Akonadi2::ApplicationDomain::TypeImplementation<DomainType>::index(uid, newEntity, transaction); | ||
81 | } | ||
82 | |||
83 | void deletedEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE | ||
84 | { | ||
85 | Akonadi2::ApplicationDomain::TypeImplementation<DomainType>::removeIndex(uid, oldEntity, transaction); | ||
86 | } | ||
87 | }; | ||