summaryrefslogtreecommitdiffstats
path: root/dummyresource/resourcefactory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dummyresource/resourcefactory.cpp')
-rw-r--r--dummyresource/resourcefactory.cpp56
1 files changed, 54 insertions, 2 deletions
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 @@
20#include "resourcefactory.h" 20#include "resourcefactory.h"
21#include "facade.h" 21#include "facade.h"
22#include "entitybuffer.h" 22#include "entitybuffer.h"
23#include "pipeline.h"
23#include "dummycalendar_generated.h" 24#include "dummycalendar_generated.h"
24#include "metadata_generated.h" 25#include "metadata_generated.h"
25#include <QUuid> 26#include <QUuid>
26 27
28/*
29 * Figure out how to implement various classes of processors:
30 * * read-only (index and such) => domain adapter
31 * * filter => provide means to move entity elsewhere, and also reflect change in source (I guess?)
32 * * flag extractors? => like read-only? Or write to local portion of buffer?
33 * ** $ISSPAM should become part of domain object and is written to the local part of the mail.
34 * ** => value could be calculated by the server directly
35 */
36// template <typename DomainType>
37class SimpleProcessor : public Akonadi2::Preprocessor
38{
39public:
40 SimpleProcessor(const std::function<void(const Akonadi2::PipelineState &state)> &f)
41 : Akonadi2::Preprocessor(),
42 mFunction(f)
43 {
44 }
45
46 void process(const Akonadi2::PipelineState &state) {
47 mFunction(state);
48 }
49
50protected:
51 std::function<void(const Akonadi2::PipelineState &state)> mFunction;
52};
53
54// template <typename DomainType>
55// class SimpleReadOnlyProcessor : public SimpleProcessor<DomainType>
56// {
57// public:
58// using SimpleProcessor::SimpleProcessor;
59// void process(Akonadi2::PipelineState state) {
60// mFunction();
61// }
62// };
63
64
27static std::string createEvent() 65static std::string createEvent()
28{ 66{
29 static const size_t attachmentSize = 1024*2; // 2KB 67 static const size_t attachmentSize = 1024*2; // 2KB
@@ -61,6 +99,20 @@ DummyResource::DummyResource()
61{ 99{
62} 100}
63 101
102void DummyResource::configurePipeline(Akonadi2::Pipeline *pipeline)
103{
104 //TODO setup preprocessors for each domain type and pipeline type allowing full customization
105 //Eventually the order should be self configuring, for now it's hardcoded.
106 auto eventIndexer = new SimpleProcessor([](const Akonadi2::PipelineState &state) {
107 //FIXME
108 // auto adaptor = QSharedPointer<DummyEventAdaptor>::create();
109 // adaptor->mLocalBuffer = localBuffer;
110 // adaptor->mResourceBuffer = resourceBuffer;
111 // adaptor->storage = storage;
112 });
113 pipeline->setPreprocessors<Akonadi2::Domain::Event>(Akonadi2::Pipeline::NewPipeline, QVector<Akonadi2::Preprocessor*>() << eventIndexer);
114}
115
64void findByRemoteId(QSharedPointer<Akonadi2::Storage> storage, const QString &rid, std::function<void(void *keyValue, int keySize, void *dataValue, int dataSize)> callback) 116void findByRemoteId(QSharedPointer<Akonadi2::Storage> storage, const QString &rid, std::function<void(void *keyValue, int keySize, void *dataValue, int dataSize)> callback)
65{ 117{
66 //TODO lookup in rid index instead of doing a full scan 118 //TODO lookup in rid index instead of doing a full scan
@@ -119,7 +171,7 @@ Async::Job<void> DummyResource::synchronizeWithSource(Akonadi2::Pipeline *pipeli
119 DummyCalendar::FinishDummyEventBuffer(m_fbb, buffer); 171 DummyCalendar::FinishDummyEventBuffer(m_fbb, buffer);
120 //TODO toRFC4122 would probably be more efficient, but results in non-printable keys. 172 //TODO toRFC4122 would probably be more efficient, but results in non-printable keys.
121 const auto key = QUuid::createUuid().toString().toUtf8(); 173 const auto key = QUuid::createUuid().toString().toUtf8();
122 pipeline->newEntity(key, m_fbb.GetBufferPointer(), m_fbb.GetSize()); 174 pipeline->newEntity<Akonadi2::Domain::Event>(key, m_fbb.GetBufferPointer(), m_fbb.GetSize());
123 } else { //modification 175 } else { //modification
124 //TODO diff and create modification if necessary 176 //TODO diff and create modification if necessary
125 } 177 }
@@ -139,7 +191,7 @@ void DummyResource::processCommand(int commandId, const QByteArray &data, uint s
139 builder .add_summary(m_fbb.CreateString("summary summary!")); 191 builder .add_summary(m_fbb.CreateString("summary summary!"));
140 auto buffer = builder.Finish(); 192 auto buffer = builder.Finish();
141 DummyCalendar::FinishDummyEventBuffer(m_fbb, buffer); 193 DummyCalendar::FinishDummyEventBuffer(m_fbb, buffer);
142 pipeline->newEntity("fakekey", m_fbb.GetBufferPointer(), m_fbb.GetSize()); 194 pipeline->newEntity<Akonadi2::Domain::Event>("fakekey", m_fbb.GetBufferPointer(), m_fbb.GetSize());
143 m_fbb.Clear(); 195 m_fbb.Clear();
144} 196}
145 197