summaryrefslogtreecommitdiffstats
path: root/dummyresource/facade.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dummyresource/facade.cpp')
-rw-r--r--dummyresource/facade.cpp92
1 files changed, 2 insertions, 90 deletions
diff --git a/dummyresource/facade.cpp b/dummyresource/facade.cpp
index c167297..b4d98c6 100644
--- a/dummyresource/facade.cpp
+++ b/dummyresource/facade.cpp
@@ -28,92 +28,17 @@
28#include "event_generated.h" 28#include "event_generated.h"
29#include "entity_generated.h" 29#include "entity_generated.h"
30#include "metadata_generated.h" 30#include "metadata_generated.h"
31#include "domainadaptor.h"
31#include <common/entitybuffer.h> 32#include <common/entitybuffer.h>
32 33
33using namespace DummyCalendar; 34using namespace DummyCalendar;
34using namespace flatbuffers; 35using namespace flatbuffers;
35 36
36//This will become a generic implementation that simply takes the resource buffer and local buffer pointer
37class DummyEventAdaptor : public Akonadi2::Domain::BufferAdaptor
38{
39public:
40 DummyEventAdaptor()
41 : BufferAdaptor()
42 {
43
44 }
45
46 void setProperty(const QString &key, const QVariant &value)
47 {
48 if (mResourceMapper->mWriteAccessors.contains(key)) {
49 // mResourceMapper.setProperty(key, value, mResourceBuffer);
50 } else {
51 // mLocalMapper.;
52 }
53 }
54
55 virtual QVariant getProperty(const QString &key) const
56 {
57 if (mResourceBuffer && mResourceMapper->mReadAccessors.contains(key)) {
58 return mResourceMapper->getProperty(key, mResourceBuffer);
59 } else if (mLocalBuffer) {
60 return mLocalMapper->getProperty(key, mLocalBuffer);
61 }
62 return QVariant();
63 }
64
65 Akonadi2::Domain::Buffer::Event const *mLocalBuffer;
66 DummyEvent const *mResourceBuffer;
67
68 QSharedPointer<PropertyMapper<Akonadi2::Domain::Buffer::Event> > mLocalMapper;
69 QSharedPointer<PropertyMapper<DummyEvent> > mResourceMapper;
70};
71
72template<>
73QSharedPointer<Akonadi2::Domain::BufferAdaptor> DomainTypeAdaptorFactory<typename Akonadi2::Domain::Event, typename Akonadi2::Domain::Buffer::Event, DummyEvent>::createAdaptor(const Akonadi2::Entity &entity)
74{
75 DummyEvent const *resourceBuffer = 0;
76 if (auto resourceData = entity.resource()) {
77 flatbuffers::Verifier verifyer(resourceData->Data(), resourceData->size());
78 if (VerifyDummyEventBuffer(verifyer)) {
79 resourceBuffer = GetDummyEvent(resourceData);
80 }
81 }
82
83 Akonadi2::Metadata const *metadataBuffer = 0;
84 if (auto metadataData = entity.metadata()) {
85 flatbuffers::Verifier verifyer(metadataData->Data(), metadataData->size());
86 if (Akonadi2::VerifyMetadataBuffer(verifyer)) {
87 metadataBuffer = Akonadi2::GetMetadata(metadataData);
88 }
89 }
90
91 Akonadi2::Domain::Buffer::Event const *localBuffer = 0;
92 if (auto localData = entity.local()) {
93 flatbuffers::Verifier verifyer(localData->Data(), localData->size());
94 if (Akonadi2::Domain::Buffer::VerifyEventBuffer(verifyer)) {
95 localBuffer = Akonadi2::Domain::Buffer::GetEvent(localData);
96 }
97 }
98
99 auto adaptor = QSharedPointer<DummyEventAdaptor>::create();
100 adaptor->mLocalBuffer = localBuffer;
101 adaptor->mResourceBuffer = resourceBuffer;
102 adaptor->mResourceMapper = mResourceMapper;
103 adaptor->mLocalMapper = mLocalMapper;
104 return adaptor;
105}
106
107DummyResourceFacade::DummyResourceFacade() 37DummyResourceFacade::DummyResourceFacade()
108 : Akonadi2::StoreFacade<Akonadi2::Domain::Event>(), 38 : Akonadi2::StoreFacade<Akonadi2::Domain::Event>(),
109 mResourceAccess(new Akonadi2::ResourceAccess("org.kde.dummy")), 39 mResourceAccess(new Akonadi2::ResourceAccess("org.kde.dummy")),
110 mFactory(new DomainTypeAdaptorFactory<Akonadi2::Domain::Event, Akonadi2::Domain::Buffer::Event, DummyCalendar::DummyEvent>()) 40 mFactory(new DummyEventAdaptorFactory)
111{ 41{
112 auto mapper = QSharedPointer<PropertyMapper<DummyEvent> >::create();
113 mapper->mReadAccessors.insert("summary", [](DummyEvent const *buffer) -> QVariant {
114 return QString::fromStdString(buffer->summary()->c_str());
115 });
116 mFactory->mResourceMapper = mapper;
117} 42}
118 43
119DummyResourceFacade::~DummyResourceFacade() 44DummyResourceFacade::~DummyResourceFacade()
@@ -135,19 +60,6 @@ void DummyResourceFacade::remove(const Akonadi2::Domain::Event &domainObject)
135 //Create message buffer and send to resource 60 //Create message buffer and send to resource
136} 61}
137 62
138//Key.value property map using enum or strings with qvariant, or rather typesafe API?
139//typesafe is a shitload more work that we can avoid
140//
141//The Event base implementaiton could take a pointer to a single property mapper,
142//and a void pointer to the mmapped region. => event is copyable and stack allocatable and we avoid large amounts of heap allocated objects
143//-The mapper should in this case live in the other thread
144//-default property mapper implementation can answer "is property X supported?"
145//-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
146//-we could bind the lifetime to the query
147//=> perhaps do heap allocate and use smart pointer?
148//
149
150
151static std::function<bool(const std::string &key, DummyEvent const *buffer)> prepareQuery(const Akonadi2::Query &query) 63static std::function<bool(const std::string &key, DummyEvent const *buffer)> prepareQuery(const Akonadi2::Query &query)
152{ 64{
153 //Compose some functions to make query matching fast. 65 //Compose some functions to make query matching fast.