From 91d915a09b7d52c10edb1d4c1298fc2885b8a257 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 2 Jan 2015 22:39:25 +0100 Subject: DomainTypeAdaptor factory, per type preprocessor pipeline configuration. --- dummyresource/resourcefactory.cpp | 56 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) (limited to 'dummyresource/resourcefactory.cpp') diff --git a/dummyresource/resourcefactory.cpp b/dummyresource/resourcefactory.cpp index c9e4d7a..08222c0 100644 --- a/dummyresource/resourcefactory.cpp +++ b/dummyresource/resourcefactory.cpp @@ -20,10 +20,48 @@ #include "resourcefactory.h" #include "facade.h" #include "entitybuffer.h" +#include "pipeline.h" #include "dummycalendar_generated.h" #include "metadata_generated.h" #include +/* + * Figure out how to implement various classes of processors: + * * read-only (index and such) => domain adapter + * * 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 + */ +// template +class SimpleProcessor : public Akonadi2::Preprocessor +{ +public: + SimpleProcessor(const std::function &f) + : Akonadi2::Preprocessor(), + mFunction(f) + { + } + + void process(const Akonadi2::PipelineState &state) { + mFunction(state); + } + +protected: + std::function mFunction; +}; + +// template +// class SimpleReadOnlyProcessor : public SimpleProcessor +// { +// public: +// using SimpleProcessor::SimpleProcessor; +// void process(Akonadi2::PipelineState state) { +// mFunction(); +// } +// }; + + static std::string createEvent() { static const size_t attachmentSize = 1024*2; // 2KB @@ -61,6 +99,20 @@ DummyResource::DummyResource() { } +void DummyResource::configurePipeline(Akonadi2::Pipeline *pipeline) +{ + //TODO setup preprocessors for each domain type and pipeline type allowing full customization + //Eventually the order should be self configuring, for now it's hardcoded. + auto eventIndexer = new SimpleProcessor([](const Akonadi2::PipelineState &state) { + //FIXME + // auto adaptor = QSharedPointer::create(); + // adaptor->mLocalBuffer = localBuffer; + // adaptor->mResourceBuffer = resourceBuffer; + // adaptor->storage = storage; + }); + pipeline->setPreprocessors(Akonadi2::Pipeline::NewPipeline, QVector() << eventIndexer); +} + void findByRemoteId(QSharedPointer storage, const QString &rid, std::function callback) { //TODO lookup in rid index instead of doing a full scan @@ -119,7 +171,7 @@ Async::Job DummyResource::synchronizeWithSource(Akonadi2::Pipeline *pipeli DummyCalendar::FinishDummyEventBuffer(m_fbb, buffer); //TODO toRFC4122 would probably be more efficient, but results in non-printable keys. const auto key = QUuid::createUuid().toString().toUtf8(); - pipeline->newEntity(key, m_fbb.GetBufferPointer(), m_fbb.GetSize()); + pipeline->newEntity(key, m_fbb.GetBufferPointer(), m_fbb.GetSize()); } else { //modification //TODO diff and create modification if necessary } @@ -139,7 +191,7 @@ void DummyResource::processCommand(int commandId, const QByteArray &data, uint s builder .add_summary(m_fbb.CreateString("summary summary!")); auto buffer = builder.Finish(); DummyCalendar::FinishDummyEventBuffer(m_fbb, buffer); - pipeline->newEntity("fakekey", m_fbb.GetBufferPointer(), m_fbb.GetSize()); + pipeline->newEntity("fakekey", m_fbb.GetBufferPointer(), m_fbb.GetSize()); m_fbb.Clear(); } -- cgit v1.2.3