diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-01-21 10:51:12 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-01-21 10:51:12 +0100 |
commit | cf91df49d0eadfdc7dec23fd82da9e7b9a964ea6 (patch) | |
tree | 33cdbf0e1f5148baeb050f34ae82d85ef557fcad | |
parent | 4f1edeb042b9d4cfe8efe5baa0f57f4eb950fd86 (diff) | |
download | sink-cf91df49d0eadfdc7dec23fd82da9e7b9a964ea6.tar.gz sink-cf91df49d0eadfdc7dec23fd82da9e7b9a964ea6.zip |
Create buffer with values from domain object
-rw-r--r-- | common/clientapi.h | 2 | ||||
-rw-r--r-- | common/domain/event.fbs | 1 | ||||
-rw-r--r-- | common/domainadaptor.h | 1 | ||||
-rw-r--r-- | dummyresource/domainadaptor.cpp | 31 | ||||
-rw-r--r-- | dummyresource/domainadaptor.h | 1 | ||||
-rw-r--r-- | 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: | |||
227 | { | 227 | { |
228 | } | 228 | } |
229 | 229 | ||
230 | virtual QVariant getProperty(const QString &key){ return mAdaptor->getProperty(key); } | 230 | virtual QVariant getProperty(const QString &key) const { return mAdaptor->getProperty(key); } |
231 | virtual void setProperty(const QString &key, const QVariant &value){ mChangeSet.insert(key, value); } | 231 | virtual void setProperty(const QString &key, const QVariant &value){ mChangeSet.insert(key, value); } |
232 | 232 | ||
233 | private: | 233 | 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 @@ | |||
1 | namespace Akonadi2.Domain.Buffer; | 1 | namespace Akonadi2.Domain.Buffer; |
2 | 2 | ||
3 | table Event { | 3 | table Event { |
4 | uid:string; | ||
4 | summary:string; | 5 | summary:string; |
5 | description:string; | 6 | description:string; |
6 | attachment:[ubyte]; | 7 | 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/* <typename DomainType, LocalBuffer, ResourceBuff | |||
68 | { | 68 | { |
69 | public: | 69 | public: |
70 | virtual QSharedPointer<Akonadi2::Domain::BufferAdaptor> createAdaptor(const Akonadi2::Entity &entity) = 0; | 70 | virtual QSharedPointer<Akonadi2::Domain::BufferAdaptor> createAdaptor(const Akonadi2::Entity &entity) = 0; |
71 | virtual void createBuffer(const Akonadi2::Domain::Event &event, flatbuffers::FlatBufferBuilder &fbb) {}; | ||
71 | 72 | ||
72 | protected: | 73 | protected: |
73 | QSharedPointer<PropertyMapper<LocalBuffer> > mLocalMapper; | 74 | QSharedPointer<PropertyMapper<LocalBuffer> > 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() | |||
70 | return QString::fromStdString(buffer->summary()->c_str()); | 70 | return QString::fromStdString(buffer->summary()->c_str()); |
71 | }); | 71 | }); |
72 | mLocalMapper = QSharedPointer<PropertyMapper<Akonadi2::Domain::Buffer::Event> >::create(); | 72 | mLocalMapper = QSharedPointer<PropertyMapper<Akonadi2::Domain::Buffer::Event> >::create(); |
73 | //TODO set accessors for all properties | 73 | mLocalMapper->mReadAccessors.insert("summary", [](Akonadi2::Domain::Buffer::Event const *buffer) -> QVariant { |
74 | return QString::fromStdString(buffer->summary()->c_str()); | ||
75 | }); | ||
76 | mLocalMapper->mReadAccessors.insert("uid", [](Akonadi2::Domain::Buffer::Event const *buffer) -> QVariant { | ||
77 | return QString::fromStdString(buffer->uid()->c_str()); | ||
78 | }); | ||
74 | 79 | ||
75 | } | 80 | } |
76 | 81 | ||
@@ -109,3 +114,27 @@ QSharedPointer<Akonadi2::Domain::BufferAdaptor> DummyEventAdaptorFactory::create | |||
109 | return adaptor; | 114 | return adaptor; |
110 | } | 115 | } |
111 | 116 | ||
117 | void DummyEventAdaptorFactory::createBuffer(const Akonadi2::Domain::Event &event, flatbuffers::FlatBufferBuilder &fbb) | ||
118 | { | ||
119 | flatbuffers::FlatBufferBuilder eventFbb; | ||
120 | eventFbb.Clear(); | ||
121 | { | ||
122 | auto summary = eventFbb.CreateString(event.getProperty("summary").toString().toStdString()); | ||
123 | DummyCalendar::DummyEventBuilder eventBuilder(eventFbb); | ||
124 | eventBuilder.add_summary(summary); | ||
125 | auto eventLocation = eventBuilder.Finish(); | ||
126 | DummyCalendar::FinishDummyEventBuffer(eventFbb, eventLocation); | ||
127 | } | ||
128 | |||
129 | flatbuffers::FlatBufferBuilder localFbb; | ||
130 | { | ||
131 | auto uid = localFbb.CreateString(event.getProperty("uid").toString().toStdString()); | ||
132 | auto localBuilder = Akonadi2::Domain::Buffer::EventBuilder(localFbb); | ||
133 | localBuilder.add_uid(uid); | ||
134 | auto location = localBuilder.Finish(); | ||
135 | Akonadi2::Domain::Buffer::FinishEventBuffer(localFbb, location); | ||
136 | } | ||
137 | |||
138 | Akonadi2::EntityBuffer::assembleEntityBuffer(fbb, localFbb.GetBufferPointer(), localFbb.GetSize(), eventFbb.GetBufferPointer(), eventFbb.GetSize(), 0, 0); | ||
139 | } | ||
140 | |||
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<Akonadi2::Domai | |||
11 | public: | 11 | public: |
12 | DummyEventAdaptorFactory(); | 12 | DummyEventAdaptorFactory(); |
13 | virtual QSharedPointer<Akonadi2::Domain::BufferAdaptor> createAdaptor(const Akonadi2::Entity &entity); | 13 | virtual QSharedPointer<Akonadi2::Domain::BufferAdaptor> createAdaptor(const Akonadi2::Entity &entity); |
14 | virtual void createBuffer(const Akonadi2::Domain::Event &event, flatbuffers::FlatBufferBuilder &fbb); | ||
14 | }; | 15 | }; |
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() | |||
48 | 48 | ||
49 | Async::Job<void> DummyResourceFacade::create(const Akonadi2::Domain::Event &domainObject) | 49 | Async::Job<void> DummyResourceFacade::create(const Akonadi2::Domain::Event &domainObject) |
50 | { | 50 | { |
51 | //Create message buffer and send to resource | ||
52 | flatbuffers::FlatBufferBuilder eventFbb; | ||
53 | eventFbb.Clear(); | ||
54 | { | ||
55 | auto summary = eventFbb.CreateString("summary"); | ||
56 | // auto data = fbb.CreateUninitializedVector<uint8_t>(attachmentSize); | ||
57 | DummyCalendar::DummyEventBuilder eventBuilder(eventFbb); | ||
58 | eventBuilder.add_summary(summary); | ||
59 | auto eventLocation = eventBuilder.Finish(); | ||
60 | DummyCalendar::FinishDummyEventBuffer(eventFbb, eventLocation); | ||
61 | // memcpy((void*)DummyCalendar::GetDummyEvent(fbb.GetBufferPointer())->attachment()->Data(), rawData, attachmentSize); | ||
62 | } | ||
63 | flatbuffers::FlatBufferBuilder entityFbb; | 51 | flatbuffers::FlatBufferBuilder entityFbb; |
64 | Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), 0, 0); | 52 | mFactory->createBuffer(domainObject, entityFbb); |
65 | 53 | ||
66 | flatbuffers::FlatBufferBuilder fbb; | 54 | flatbuffers::FlatBufferBuilder fbb; |
67 | //This is the resource type and not the domain type | 55 | //This is the resource buffer type and not the domain type |
68 | auto type = fbb.CreateString("event"); | 56 | auto type = fbb.CreateString("event"); |
69 | auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize()); | 57 | auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize()); |
70 | Akonadi2::Commands::CreateEntityBuilder builder(fbb); | 58 | auto location = Akonadi2::Commands::CreateCreateEntity(fbb, type, delta); |
71 | builder.add_domainType(type); | ||
72 | builder.add_delta(delta); | ||
73 | auto location = builder.Finish(); | ||
74 | Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); | 59 | Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); |
75 | mResourceAccess->open(); | 60 | mResourceAccess->open(); |
76 | return mResourceAccess->sendCommand(Akonadi2::Commands::CreateEntityCommand, fbb); | 61 | return mResourceAccess->sendCommand(Akonadi2::Commands::CreateEntityCommand, fbb); |