summaryrefslogtreecommitdiffstats
path: root/dummyresource
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2014-12-03 20:36:37 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2014-12-03 20:36:37 +0100
commit44757d932abac6c8346366dfa3c0fb94e5ee0d06 (patch)
treec9120c3b4faf1b8e33dc04fee7347bc91c956977 /dummyresource
parent21138cfb7a4537626e11bdf084fcf9d672361059 (diff)
downloadsink-44757d932abac6c8346366dfa3c0fb94e5ee0d06.tar.gz
sink-44757d932abac6c8346366dfa3c0fb94e5ee0d06.zip
dummyresource that doesn't work yet
Diffstat (limited to 'dummyresource')
-rw-r--r--dummyresource/CMakeLists.txt15
-rw-r--r--dummyresource/dummycalendar.fbs12
-rw-r--r--dummyresource/facade.cpp92
-rw-r--r--dummyresource/facade.h22
-rw-r--r--dummyresource/syncronizer.cpp0
5 files changed, 141 insertions, 0 deletions
diff --git a/dummyresource/CMakeLists.txt b/dummyresource/CMakeLists.txt
new file mode 100644
index 0000000..9d28c0b
--- /dev/null
+++ b/dummyresource/CMakeLists.txt
@@ -0,0 +1,15 @@
1project(akonadinext_dummyresource)
2
3include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
4
5generate_flatbuffers(dummycalendar)
6
7#Client plugin
8add_library(${PROJECT_NAME}_facade SHARED facade.cpp)
9target_link_libraries(${PROJECT_NAME}_facade akonadinextcommon)
10qt5_use_modules(${PROJECT_NAME}_facade Widgets Network)
11#install(TARGETS ${PROJECT_NAME}_facade DESTINATION bin)
12
13#Syncronizer
14
15#add_subdirectory(test)
diff --git a/dummyresource/dummycalendar.fbs b/dummyresource/dummycalendar.fbs
new file mode 100644
index 0000000..551f5cb
--- /dev/null
+++ b/dummyresource/dummycalendar.fbs
@@ -0,0 +1,12 @@
1// example IDL file
2
3namespace DummyCalendar;
4
5table DummyEvent {
6 summary:string;
7 description:string;
8 attachment:[byte];
9}
10
11root_type DummyEvent;
12file_identifier "AKFB";
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); });
diff --git a/dummyresource/facade.h b/dummyresource/facade.h
new file mode 100644
index 0000000..7a516de
--- /dev/null
+++ b/dummyresource/facade.h
@@ -0,0 +1,22 @@
1#pragma once
2
3#include "client/clientapi.h"
4#include "store/database.h"
5
6class ResourceAccess;
7
8class DummyResourceFacade : public Akonadi2::StoreFacade<Akonadi2::Domain::Event>
9{
10public:
11 DummyResourceFacade();
12 virtual ~DummyResourceFacade();
13 virtual void create(const Akonadi2::Domain::Event &domainObject);
14 virtual void modify(const Akonadi2::Domain::Event &domainObject);
15 virtual void remove(const Akonadi2::Domain::Event &domainObject);
16 // virtual void load(const Akonadi2::Query &query, const std::function<void(const Akonadi2::Domain::Event &)> &resultCallback);
17 virtual void load(const Akonadi2::Query &query, const std::function<void(const Akonadi2::Domain::Event::Ptr &)> &resultCallback);
18
19private:
20 QSharedPointer<ResourceAccess> mResourceAccess;
21 QSharedPointer<Database> mDatabase;
22};
diff --git a/dummyresource/syncronizer.cpp b/dummyresource/syncronizer.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/dummyresource/syncronizer.cpp