diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2014-12-03 20:36:37 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2014-12-03 20:36:37 +0100 |
commit | 44757d932abac6c8346366dfa3c0fb94e5ee0d06 (patch) | |
tree | c9120c3b4faf1b8e33dc04fee7347bc91c956977 /dummyresource/facade.cpp | |
parent | 21138cfb7a4537626e11bdf084fcf9d672361059 (diff) | |
download | sink-44757d932abac6c8346366dfa3c0fb94e5ee0d06.tar.gz sink-44757d932abac6c8346366dfa3c0fb94e5ee0d06.zip |
dummyresource that doesn't work yet
Diffstat (limited to 'dummyresource/facade.cpp')
-rw-r--r-- | dummyresource/facade.cpp | 92 |
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 | |||
8 | using namespace DummyCalendar; | ||
9 | using namespace flatbuffers; | ||
10 | |||
11 | DummyResourceFacade::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 | |||
19 | DummyResourceFacade::~DummyResourceFacade() | ||
20 | { | ||
21 | } | ||
22 | |||
23 | void DummyResourceFacade::create(const Akonadi2::Domain::Event &domainObject) | ||
24 | { | ||
25 | //Create message buffer and send to resource | ||
26 | } | ||
27 | |||
28 | void DummyResourceFacade::modify(const Akonadi2::Domain::Event &domainObject) | ||
29 | { | ||
30 | //Create message buffer and send to resource | ||
31 | } | ||
32 | |||
33 | void 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? | ||
48 | class DummyEventAdaptor : public Akonadi2::Domain::Event { | ||
49 | public: | ||
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 | |||
71 | static 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 | |||
81 | void 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); }); | ||