diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-07-09 23:07:47 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-07-09 23:07:47 +0200 |
commit | 6fce18743841a03c82384705d70e0a19dac7cfe9 (patch) | |
tree | efc6672caf3878c1bac28c1615354604798fc540 | |
parent | 9fb535b4cdd6af360e3bbc5ce914e9a2c11ba047 (diff) | |
download | sink-6fce18743841a03c82384705d70e0a19dac7cfe9.tar.gz sink-6fce18743841a03c82384705d70e0a19dac7cfe9.zip |
Moved SimpleResourceProcessor
Not really where it belongs, but at least more generic
-rw-r--r-- | common/pipeline.h | 29 | ||||
-rw-r--r-- | examples/dummyresource/resourcefactory.cpp | 41 |
2 files changed, 30 insertions, 40 deletions
diff --git a/common/pipeline.h b/common/pipeline.h index b695bde..6df2d76 100644 --- a/common/pipeline.h +++ b/common/pipeline.h | |||
@@ -122,5 +122,34 @@ private: | |||
122 | Private * const d; | 122 | Private * const d; |
123 | }; | 123 | }; |
124 | 124 | ||
125 | /** | ||
126 | * A simple processor that takes a single function | ||
127 | */ | ||
128 | class AKONADI2COMMON_EXPORT SimpleProcessor : public Akonadi2::Preprocessor | ||
129 | { | ||
130 | public: | ||
131 | SimpleProcessor(const QString &id, const std::function<void(const Akonadi2::PipelineState &state, const Akonadi2::Entity &e)> &f) | ||
132 | : Akonadi2::Preprocessor(), | ||
133 | mFunction(f), | ||
134 | mId(id) | ||
135 | { | ||
136 | } | ||
137 | |||
138 | void process(const Akonadi2::PipelineState &state, const Akonadi2::Entity &e) Q_DECL_OVERRIDE | ||
139 | { | ||
140 | mFunction(state, e); | ||
141 | processingCompleted(state); | ||
142 | } | ||
143 | |||
144 | QString id() const | ||
145 | { | ||
146 | return mId; | ||
147 | } | ||
148 | |||
149 | protected: | ||
150 | std::function<void(const Akonadi2::PipelineState &state, const Akonadi2::Entity &e)> mFunction; | ||
151 | QString mId; | ||
152 | }; | ||
153 | |||
125 | } // namespace Akonadi2 | 154 | } // namespace Akonadi2 |
126 | 155 | ||
diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp index 3596a82..c746130 100644 --- a/examples/dummyresource/resourcefactory.cpp +++ b/examples/dummyresource/resourcefactory.cpp | |||
@@ -33,42 +33,6 @@ | |||
33 | #include "domain/event.h" | 33 | #include "domain/event.h" |
34 | #include "dummystore.h" | 34 | #include "dummystore.h" |
35 | #include <QUuid> | 35 | #include <QUuid> |
36 | #include <assert.h> | ||
37 | |||
38 | |||
39 | /* | ||
40 | * Figure out how to implement various classes of processors: | ||
41 | * * read-only (index and such) => extractor function, probably using domain adaptor | ||
42 | * * filter => provide means to move entity elsewhere, and also reflect change in source (I guess?) | ||
43 | * * flag extractors? => like read-only? Or write to local portion of buffer? | ||
44 | * ** $ISSPAM should become part of domain object and is written to the local part of the mail. | ||
45 | * ** => value could be calculated by the server directly | ||
46 | */ | ||
47 | class SimpleProcessor : public Akonadi2::Preprocessor | ||
48 | { | ||
49 | public: | ||
50 | SimpleProcessor(const QString &id, const std::function<void(const Akonadi2::PipelineState &state, const Akonadi2::Entity &e)> &f) | ||
51 | : Akonadi2::Preprocessor(), | ||
52 | mFunction(f), | ||
53 | mId(id) | ||
54 | { | ||
55 | } | ||
56 | |||
57 | void process(const Akonadi2::PipelineState &state, const Akonadi2::Entity &e) Q_DECL_OVERRIDE | ||
58 | { | ||
59 | mFunction(state, e); | ||
60 | processingCompleted(state); | ||
61 | } | ||
62 | |||
63 | QString id() const | ||
64 | { | ||
65 | return mId; | ||
66 | } | ||
67 | |||
68 | protected: | ||
69 | std::function<void(const Akonadi2::PipelineState &state, const Akonadi2::Entity &e)> mFunction; | ||
70 | QString mId; | ||
71 | }; | ||
72 | 36 | ||
73 | 37 | ||
74 | DummyResource::DummyResource(const QByteArray &instanceIdentifier) | 38 | DummyResource::DummyResource(const QByteArray &instanceIdentifier) |
@@ -78,12 +42,9 @@ DummyResource::DummyResource(const QByteArray &instanceIdentifier) | |||
78 | 42 | ||
79 | void DummyResource::configurePipeline(Akonadi2::Pipeline *pipeline) | 43 | void DummyResource::configurePipeline(Akonadi2::Pipeline *pipeline) |
80 | { | 44 | { |
81 | //TODO In case of a non 1:1 mapping between resource and domain types special handling is required. | ||
82 | //i.e. If a resource stores tags as part of each message it needs to update the tag index | ||
83 | |||
84 | auto eventFactory = QSharedPointer<DummyEventAdaptorFactory>::create(); | 45 | auto eventFactory = QSharedPointer<DummyEventAdaptorFactory>::create(); |
85 | const auto resourceIdentifier = mResourceInstanceIdentifier; | 46 | const auto resourceIdentifier = mResourceInstanceIdentifier; |
86 | auto eventIndexer = new SimpleProcessor("eventIndexer", [eventFactory, resourceIdentifier](const Akonadi2::PipelineState &state, const Akonadi2::Entity &entity) { | 47 | auto eventIndexer = new Akonadi2::SimpleProcessor("eventIndexer", [eventFactory, resourceIdentifier](const Akonadi2::PipelineState &state, const Akonadi2::Entity &entity) { |
87 | auto adaptor = eventFactory->createAdaptor(entity); | 48 | auto adaptor = eventFactory->createAdaptor(entity); |
88 | //FIXME set revision? | 49 | //FIXME set revision? |
89 | Akonadi2::ApplicationDomain::Event event(resourceIdentifier, state.key(), -1, adaptor); | 50 | Akonadi2::ApplicationDomain::Event event(resourceIdentifier, state.key(), -1, adaptor); |