summaryrefslogtreecommitdiffstats
path: root/dummyresource/facade.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dummyresource/facade.cpp')
-rw-r--r--dummyresource/facade.cpp92
1 files changed, 92 insertions, 0 deletions
diff --git a/dummyresource/facade.cpp b/dummyresource/facade.cpp
new file mode 100644
index 0000000..288552c
--- /dev/null
+++ b/dummyresource/facade.cpp
@@ -0,0 +1,92 @@
1#include "facade.h"
2
3#include <QDebug>
4#include <functional>
5#include "client/resourceaccess.h"
6#include "dummycalendar_generated.h"
7
8using namespace DummyCalendar;
9using namespace flatbuffers;
10
11DummyResourceFacade::DummyResourceFacade()
12 : Akonadi2::StoreFacade<Akonadi2::Domain::Event>(),
13 mResourceAccess(new ResourceAccess("dummyresource")),
14 mDatabase(new Database("dummyresource"))
15{
16 // connect(mResourceAccess.data(), &ResourceAccess::ready, this, onReadyChanged);
17}
18
19DummyResourceFacade::~DummyResourceFacade()
20{
21}
22
23void DummyResourceFacade::create(const Akonadi2::Domain::Event &domainObject)
24{
25 //Create message buffer and send to resource
26}
27
28void DummyResourceFacade::modify(const Akonadi2::Domain::Event &domainObject)
29{
30 //Create message buffer and send to resource
31}
32
33void DummyResourceFacade::remove(const Akonadi2::Domain::Event &domainObject)
34{
35 //Create message buffer and send to resource
36}
37
38//Key.value property map using enum or strings with qvariant, or rather typesafe API?
39//typesafe is a shitload more work that we can avoid
40//
41//The Event base implementaiton could take a pointer to a single property mapper,
42//and a void pointer to the mmapped region. => event is copyable and stack allocatable and we avoid large amounts of heap allocated objects
43//-The mapper should in this case live in the other thread
44//-default property mapper implementation can answer "is property X supported?"
45//-how do we free/munmap the data if we don't know when no one references it any longer? => no munmap needed, but read transaction to keep pointer alive
46//-we could bind the lifetime to the query
47//=> perhaps do heap allocate and use smart pointer?
48class DummyEventAdaptor : public Akonadi2::Domain::Event {
49public:
50 DummyEventAdaptor(const QString &resource, const QString &identifier, qint64 revision):Akonadi2::Domain::Event(resource, identifier, revision){};
51
52 // void setProperty(const QString &key, const QVariant &value)
53 // {
54 // //Record changes to send to resource?
55 // //The buffer is readonly
56 // }
57
58 virtual QVariant getProperty(const QString &key) const
59 {
60 if (key == "summary") {
61 //FIXME how do we check availability for on-demand request?
62 return QString::fromStdString(buffer->summary()->c_str());
63 }
64 return QVariant();
65 }
66
67 //Data is read-only
68 DummyEvent const *buffer;
69};
70
71static Akonadi2::Domain::Event::Ptr createEvent(const std::string &data)
72{
73 //We will have to buffers stored after each other
74 auto eventBuffer = GetDummyEvent(data.c_str());
75 auto event = QSharedPointer<DummyEventAdaptor>::create("dummyresource", "key", 0);
76 event->buffer = eventBuffer;
77 // qDebug() << readEvent->summary()->c_str();
78 return event;
79}
80
81void DummyResourceFacade::load(const Akonadi2::Query &query, const std::function<void(const Akonadi2::Domain::Event::Ptr &)> &resultCallback)
82{
83 qDebug() << "load called";
84 //TODO only read values matching the query
85 //FIXME the interface should probably simply return a void pointer + size
86 mDatabase->read("", [resultCallback](const std::string &result) {
87 resultCallback(createEvent(result));
88 });
89}
90
91//TODO call in plugin loader
92// Akonadi2::FacadeFactory::instance().registerFacade<Akonadi2::Domain::Event, DummyResourceFacade>("dummyresource", [facade](){ return new DummyResourceFacade(facade); });