diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-05-25 23:14:57 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-05-25 23:14:57 +0200 |
commit | 3601ee575f833bf204540f4fac41d87a0d977a79 (patch) | |
tree | 740e62969ba7cd6384161b40d499fd63b2029f5f /examples/dummyresource/resourcefactory.cpp | |
parent | 9e3bcbdd45ec05d0a1fd423e6219ac6443feed1c (diff) | |
download | sink-3601ee575f833bf204540f4fac41d87a0d977a79.tar.gz sink-3601ee575f833bf204540f4fac41d87a0d977a79.zip |
Centralized type specific code.
Diffstat (limited to 'examples/dummyresource/resourcefactory.cpp')
-rw-r--r-- | examples/dummyresource/resourcefactory.cpp | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp index e16a693..71a4ac5 100644 --- a/examples/dummyresource/resourcefactory.cpp +++ b/examples/dummyresource/resourcefactory.cpp | |||
@@ -30,6 +30,7 @@ | |||
30 | #include "clientapi.h" | 30 | #include "clientapi.h" |
31 | #include "index.h" | 31 | #include "index.h" |
32 | #include "log.h" | 32 | #include "log.h" |
33 | #include "domain/event.h" | ||
33 | #include <QUuid> | 34 | #include <QUuid> |
34 | #include <assert.h> | 35 | #include <assert.h> |
35 | 36 | ||
@@ -106,35 +107,26 @@ static QMap<QString, QString> s_dataSource = populate(); | |||
106 | 107 | ||
107 | //FIXME We need to pass the resource-instance name to generic resource, not the plugin name | 108 | //FIXME We need to pass the resource-instance name to generic resource, not the plugin name |
108 | DummyResource::DummyResource() | 109 | DummyResource::DummyResource() |
109 | : Akonadi2::GenericResource(PLUGIN_NAME) | 110 | : Akonadi2::GenericResource(PLUGIN_NAME ".instance1") |
110 | { | 111 | { |
111 | } | 112 | } |
112 | 113 | ||
113 | void DummyResource::configurePipeline(Akonadi2::Pipeline *pipeline) | 114 | void DummyResource::configurePipeline(Akonadi2::Pipeline *pipeline) |
114 | { | 115 | { |
115 | auto eventFactory = QSharedPointer<DummyEventAdaptorFactory>::create(); | 116 | //TODO In case of a non 1:1 mapping between resource and domain types special handling is required. |
116 | //FIXME we should setup for each resource entity type, not for each domain type | ||
117 | //i.e. If a resource stores tags as part of each message it needs to update the tag index | 117 | //i.e. If a resource stores tags as part of each message it needs to update the tag index |
118 | //TODO setup preprocessors for each resource entity type and pipeline type allowing full customization | ||
119 | //Eventually the order should be self configuring, for now it's hardcoded. | ||
120 | auto eventIndexer = new SimpleProcessor("summaryprocessor", [eventFactory](const Akonadi2::PipelineState &state, const Akonadi2::Entity &entity) { | ||
121 | auto adaptor = eventFactory->createAdaptor(entity); | ||
122 | // Log() << "Summary preprocessor: " << adaptor->getProperty("summary").toString(); | ||
123 | }); | ||
124 | 118 | ||
125 | auto uidIndexer = new SimpleProcessor("uidIndexer", [eventFactory](const Akonadi2::PipelineState &state, const Akonadi2::Entity &entity) { | 119 | auto eventFactory = QSharedPointer<DummyEventAdaptorFactory>::create(); |
126 | static Index uidIndex(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/storage", "org.kde.dummy.index.uid", Akonadi2::Storage::ReadWrite); | 120 | const auto resourceIdentifier = mResourceInstanceIdentifier; |
127 | 121 | auto eventIndexer = new SimpleProcessor("eventIndexer", [eventFactory, resourceIdentifier](const Akonadi2::PipelineState &state, const Akonadi2::Entity &entity) { | |
128 | //TODO: Benchmark if this is performance wise acceptable, or if we have to access the buffer directly | ||
129 | auto adaptor = eventFactory->createAdaptor(entity); | 122 | auto adaptor = eventFactory->createAdaptor(entity); |
130 | const auto uid = adaptor->getProperty("uid"); | 123 | //FIXME set revision? |
131 | if (uid.isValid()) { | 124 | Akonadi2::ApplicationDomain::Event event(resourceIdentifier, state.key(), -1, adaptor); |
132 | uidIndex.add(uid.toByteArray(), state.key()); | 125 | Akonadi2::ApplicationDomain::EventImplementation::index(event); |
133 | } | ||
134 | }); | 126 | }); |
135 | 127 | ||
136 | //event is the entitytype and not the domain type | 128 | //event is the entitytype and not the domain type |
137 | pipeline->setPreprocessors("event", Akonadi2::Pipeline::NewPipeline, QVector<Akonadi2::Preprocessor*>() << eventIndexer << uidIndexer); | 129 | pipeline->setPreprocessors("event", Akonadi2::Pipeline::NewPipeline, QVector<Akonadi2::Preprocessor*>() << eventIndexer); |
138 | GenericResource::configurePipeline(pipeline); | 130 | GenericResource::configurePipeline(pipeline); |
139 | } | 131 | } |
140 | 132 | ||