From 44757d932abac6c8346366dfa3c0fb94e5ee0d06 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 3 Dec 2014 20:36:37 +0100 Subject: dummyresource that doesn't work yet --- dummyresource/CMakeLists.txt | 15 +++++++ dummyresource/dummycalendar.fbs | 12 ++++++ dummyresource/facade.cpp | 92 +++++++++++++++++++++++++++++++++++++++++ dummyresource/facade.h | 22 ++++++++++ dummyresource/syncronizer.cpp | 0 5 files changed, 141 insertions(+) create mode 100644 dummyresource/CMakeLists.txt create mode 100644 dummyresource/dummycalendar.fbs create mode 100644 dummyresource/facade.cpp create mode 100644 dummyresource/facade.h create mode 100644 dummyresource/syncronizer.cpp (limited to 'dummyresource') 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 @@ +project(akonadinext_dummyresource) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) + +generate_flatbuffers(dummycalendar) + +#Client plugin +add_library(${PROJECT_NAME}_facade SHARED facade.cpp) +target_link_libraries(${PROJECT_NAME}_facade akonadinextcommon) +qt5_use_modules(${PROJECT_NAME}_facade Widgets Network) +#install(TARGETS ${PROJECT_NAME}_facade DESTINATION bin) + +#Syncronizer + +#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 @@ +// example IDL file + +namespace DummyCalendar; + +table DummyEvent { + summary:string; + description:string; + attachment:[byte]; +} + +root_type DummyEvent; +file_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 @@ +#include "facade.h" + +#include +#include +#include "client/resourceaccess.h" +#include "dummycalendar_generated.h" + +using namespace DummyCalendar; +using namespace flatbuffers; + +DummyResourceFacade::DummyResourceFacade() + : Akonadi2::StoreFacade(), + mResourceAccess(new ResourceAccess("dummyresource")), + mDatabase(new Database("dummyresource")) +{ + // connect(mResourceAccess.data(), &ResourceAccess::ready, this, onReadyChanged); +} + +DummyResourceFacade::~DummyResourceFacade() +{ +} + +void DummyResourceFacade::create(const Akonadi2::Domain::Event &domainObject) +{ + //Create message buffer and send to resource +} + +void DummyResourceFacade::modify(const Akonadi2::Domain::Event &domainObject) +{ + //Create message buffer and send to resource +} + +void DummyResourceFacade::remove(const Akonadi2::Domain::Event &domainObject) +{ + //Create message buffer and send to resource +} + +//Key.value property map using enum or strings with qvariant, or rather typesafe API? +//typesafe is a shitload more work that we can avoid +// +//The Event base implementaiton could take a pointer to a single property mapper, +//and a void pointer to the mmapped region. => event is copyable and stack allocatable and we avoid large amounts of heap allocated objects +//-The mapper should in this case live in the other thread +//-default property mapper implementation can answer "is property X supported?" +//-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 +//-we could bind the lifetime to the query +//=> perhaps do heap allocate and use smart pointer? +class DummyEventAdaptor : public Akonadi2::Domain::Event { +public: + DummyEventAdaptor(const QString &resource, const QString &identifier, qint64 revision):Akonadi2::Domain::Event(resource, identifier, revision){}; + + // void setProperty(const QString &key, const QVariant &value) + // { + // //Record changes to send to resource? + // //The buffer is readonly + // } + + virtual QVariant getProperty(const QString &key) const + { + if (key == "summary") { + //FIXME how do we check availability for on-demand request? + return QString::fromStdString(buffer->summary()->c_str()); + } + return QVariant(); + } + + //Data is read-only + DummyEvent const *buffer; +}; + +static Akonadi2::Domain::Event::Ptr createEvent(const std::string &data) +{ + //We will have to buffers stored after each other + auto eventBuffer = GetDummyEvent(data.c_str()); + auto event = QSharedPointer::create("dummyresource", "key", 0); + event->buffer = eventBuffer; + // qDebug() << readEvent->summary()->c_str(); + return event; +} + +void DummyResourceFacade::load(const Akonadi2::Query &query, const std::function &resultCallback) +{ + qDebug() << "load called"; + //TODO only read values matching the query + //FIXME the interface should probably simply return a void pointer + size + mDatabase->read("", [resultCallback](const std::string &result) { + resultCallback(createEvent(result)); + }); +} + +//TODO call in plugin loader +// Akonadi2::FacadeFactory::instance().registerFacade("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 @@ +#pragma once + +#include "client/clientapi.h" +#include "store/database.h" + +class ResourceAccess; + +class DummyResourceFacade : public Akonadi2::StoreFacade +{ +public: + DummyResourceFacade(); + virtual ~DummyResourceFacade(); + virtual void create(const Akonadi2::Domain::Event &domainObject); + virtual void modify(const Akonadi2::Domain::Event &domainObject); + virtual void remove(const Akonadi2::Domain::Event &domainObject); + // virtual void load(const Akonadi2::Query &query, const std::function &resultCallback); + virtual void load(const Akonadi2::Query &query, const std::function &resultCallback); + +private: + QSharedPointer mResourceAccess; + QSharedPointer mDatabase; +}; diff --git a/dummyresource/syncronizer.cpp b/dummyresource/syncronizer.cpp new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3