From cf91df49d0eadfdc7dec23fd82da9e7b9a964ea6 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 21 Jan 2015 10:51:12 +0100 Subject: Create buffer with values from domain object --- common/clientapi.h | 2 +- common/domain/event.fbs | 1 + common/domainadaptor.h | 1 + dummyresource/domainadaptor.cpp | 31 ++++++++++++++++++++++++++++++- dummyresource/domainadaptor.h | 1 + dummyresource/facade.cpp | 21 +++------------------ 6 files changed, 37 insertions(+), 20 deletions(-) diff --git a/common/clientapi.h b/common/clientapi.h index dd11a0d..546f210 100644 --- a/common/clientapi.h +++ b/common/clientapi.h @@ -227,7 +227,7 @@ public: { } - virtual QVariant getProperty(const QString &key){ return mAdaptor->getProperty(key); } + virtual QVariant getProperty(const QString &key) const { return mAdaptor->getProperty(key); } virtual void setProperty(const QString &key, const QVariant &value){ mChangeSet.insert(key, value); } private: diff --git a/common/domain/event.fbs b/common/domain/event.fbs index 6865cc5..49ff270 100644 --- a/common/domain/event.fbs +++ b/common/domain/event.fbs @@ -1,6 +1,7 @@ namespace Akonadi2.Domain.Buffer; table Event { + uid:string; summary:string; description:string; attachment:[ubyte]; diff --git a/common/domainadaptor.h b/common/domainadaptor.h index e8f586b..164c749 100644 --- a/common/domainadaptor.h +++ b/common/domainadaptor.h @@ -68,6 +68,7 @@ class DomainTypeAdaptorFactory/* createAdaptor(const Akonadi2::Entity &entity) = 0; + virtual void createBuffer(const Akonadi2::Domain::Event &event, flatbuffers::FlatBufferBuilder &fbb) {}; protected: QSharedPointer > mLocalMapper; diff --git a/dummyresource/domainadaptor.cpp b/dummyresource/domainadaptor.cpp index 9bd3770..ec5e2be 100644 --- a/dummyresource/domainadaptor.cpp +++ b/dummyresource/domainadaptor.cpp @@ -70,7 +70,12 @@ DummyEventAdaptorFactory::DummyEventAdaptorFactory() return QString::fromStdString(buffer->summary()->c_str()); }); mLocalMapper = QSharedPointer >::create(); - //TODO set accessors for all properties + mLocalMapper->mReadAccessors.insert("summary", [](Akonadi2::Domain::Buffer::Event const *buffer) -> QVariant { + return QString::fromStdString(buffer->summary()->c_str()); + }); + mLocalMapper->mReadAccessors.insert("uid", [](Akonadi2::Domain::Buffer::Event const *buffer) -> QVariant { + return QString::fromStdString(buffer->uid()->c_str()); + }); } @@ -109,3 +114,27 @@ QSharedPointer DummyEventAdaptorFactory::create return adaptor; } +void DummyEventAdaptorFactory::createBuffer(const Akonadi2::Domain::Event &event, flatbuffers::FlatBufferBuilder &fbb) +{ + flatbuffers::FlatBufferBuilder eventFbb; + eventFbb.Clear(); + { + auto summary = eventFbb.CreateString(event.getProperty("summary").toString().toStdString()); + DummyCalendar::DummyEventBuilder eventBuilder(eventFbb); + eventBuilder.add_summary(summary); + auto eventLocation = eventBuilder.Finish(); + DummyCalendar::FinishDummyEventBuffer(eventFbb, eventLocation); + } + + flatbuffers::FlatBufferBuilder localFbb; + { + auto uid = localFbb.CreateString(event.getProperty("uid").toString().toStdString()); + auto localBuilder = Akonadi2::Domain::Buffer::EventBuilder(localFbb); + localBuilder.add_uid(uid); + auto location = localBuilder.Finish(); + Akonadi2::Domain::Buffer::FinishEventBuffer(localFbb, location); + } + + Akonadi2::EntityBuffer::assembleEntityBuffer(fbb, localFbb.GetBufferPointer(), localFbb.GetSize(), eventFbb.GetBufferPointer(), eventFbb.GetSize(), 0, 0); +} + diff --git a/dummyresource/domainadaptor.h b/dummyresource/domainadaptor.h index 881b7f3..239ceca 100644 --- a/dummyresource/domainadaptor.h +++ b/dummyresource/domainadaptor.h @@ -11,4 +11,5 @@ class DummyEventAdaptorFactory : public DomainTypeAdaptorFactory createAdaptor(const Akonadi2::Entity &entity); + virtual void createBuffer(const Akonadi2::Domain::Event &event, flatbuffers::FlatBufferBuilder &fbb); }; diff --git a/dummyresource/facade.cpp b/dummyresource/facade.cpp index b7ba2c2..cd930f6 100644 --- a/dummyresource/facade.cpp +++ b/dummyresource/facade.cpp @@ -48,29 +48,14 @@ DummyResourceFacade::~DummyResourceFacade() Async::Job DummyResourceFacade::create(const Akonadi2::Domain::Event &domainObject) { - //Create message buffer and send to resource - flatbuffers::FlatBufferBuilder eventFbb; - eventFbb.Clear(); - { - auto summary = eventFbb.CreateString("summary"); - // auto data = fbb.CreateUninitializedVector(attachmentSize); - DummyCalendar::DummyEventBuilder eventBuilder(eventFbb); - eventBuilder.add_summary(summary); - auto eventLocation = eventBuilder.Finish(); - DummyCalendar::FinishDummyEventBuffer(eventFbb, eventLocation); - // memcpy((void*)DummyCalendar::GetDummyEvent(fbb.GetBufferPointer())->attachment()->Data(), rawData, attachmentSize); - } flatbuffers::FlatBufferBuilder entityFbb; - Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), 0, 0); + mFactory->createBuffer(domainObject, entityFbb); flatbuffers::FlatBufferBuilder fbb; - //This is the resource type and not the domain type + //This is the resource buffer type and not the domain type auto type = fbb.CreateString("event"); auto delta = fbb.CreateVector(entityFbb.GetBufferPointer(), entityFbb.GetSize()); - Akonadi2::Commands::CreateEntityBuilder builder(fbb); - builder.add_domainType(type); - builder.add_delta(delta); - auto location = builder.Finish(); + auto location = Akonadi2::Commands::CreateCreateEntity(fbb, type, delta); Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); mResourceAccess->open(); return mResourceAccess->sendCommand(Akonadi2::Commands::CreateEntityCommand, fbb); -- cgit v1.2.3