From 6fce18743841a03c82384705d70e0a19dac7cfe9 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 9 Jul 2015 23:07:47 +0200 Subject: Moved SimpleResourceProcessor Not really where it belongs, but at least more generic --- common/pipeline.h | 29 +++++++++++++++++++++ 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: Private * const d; }; +/** + * A simple processor that takes a single function + */ +class AKONADI2COMMON_EXPORT SimpleProcessor : public Akonadi2::Preprocessor +{ +public: + SimpleProcessor(const QString &id, const std::function &f) + : Akonadi2::Preprocessor(), + mFunction(f), + mId(id) + { + } + + void process(const Akonadi2::PipelineState &state, const Akonadi2::Entity &e) Q_DECL_OVERRIDE + { + mFunction(state, e); + processingCompleted(state); + } + + QString id() const + { + return mId; + } + +protected: + std::function mFunction; + QString mId; +}; + } // namespace Akonadi2 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 @@ #include "domain/event.h" #include "dummystore.h" #include -#include - - -/* - * Figure out how to implement various classes of processors: - * * read-only (index and such) => extractor function, probably using domain adaptor - * * filter => provide means to move entity elsewhere, and also reflect change in source (I guess?) - * * flag extractors? => like read-only? Or write to local portion of buffer? - * ** $ISSPAM should become part of domain object and is written to the local part of the mail. - * ** => value could be calculated by the server directly - */ -class SimpleProcessor : public Akonadi2::Preprocessor -{ -public: - SimpleProcessor(const QString &id, const std::function &f) - : Akonadi2::Preprocessor(), - mFunction(f), - mId(id) - { - } - - void process(const Akonadi2::PipelineState &state, const Akonadi2::Entity &e) Q_DECL_OVERRIDE - { - mFunction(state, e); - processingCompleted(state); - } - - QString id() const - { - return mId; - } - -protected: - std::function mFunction; - QString mId; -}; DummyResource::DummyResource(const QByteArray &instanceIdentifier) @@ -78,12 +42,9 @@ DummyResource::DummyResource(const QByteArray &instanceIdentifier) void DummyResource::configurePipeline(Akonadi2::Pipeline *pipeline) { - //TODO In case of a non 1:1 mapping between resource and domain types special handling is required. - //i.e. If a resource stores tags as part of each message it needs to update the tag index - auto eventFactory = QSharedPointer::create(); const auto resourceIdentifier = mResourceInstanceIdentifier; - auto eventIndexer = new SimpleProcessor("eventIndexer", [eventFactory, resourceIdentifier](const Akonadi2::PipelineState &state, const Akonadi2::Entity &entity) { + auto eventIndexer = new Akonadi2::SimpleProcessor("eventIndexer", [eventFactory, resourceIdentifier](const Akonadi2::PipelineState &state, const Akonadi2::Entity &entity) { auto adaptor = eventFactory->createAdaptor(entity); //FIXME set revision? Akonadi2::ApplicationDomain::Event event(resourceIdentifier, state.key(), -1, adaptor); -- cgit v1.2.3