summaryrefslogtreecommitdiffstats
path: root/dummyresource/facade.h
diff options
context:
space:
mode:
Diffstat (limited to 'dummyresource/facade.h')
-rw-r--r--dummyresource/facade.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/dummyresource/facade.h b/dummyresource/facade.h
index c76e62c..46b27ef 100644
--- a/dummyresource/facade.h
+++ b/dummyresource/facade.h
@@ -21,11 +21,63 @@
21 21
22#include "common/clientapi.h" 22#include "common/clientapi.h"
23#include "common/storage.h" 23#include "common/storage.h"
24#include "entity_generated.h"
25#include "event_generated.h"
26#include "dummycalendar_generated.h"
24 27
25namespace Akonadi2 { 28namespace Akonadi2 {
26 class ResourceAccess; 29 class ResourceAccess;
27} 30}
28 31
32/**
33 * The property mapper holds accessor functions for all properties.
34 *
35 * It is by default initialized with accessors that access the local-only buffer,
36 * and resource simply have to overwrite those accessors.
37 */
38template<typename BufferType>
39class PropertyMapper
40{
41public:
42 void setProperty(const QString &key, const QVariant &value, BufferType *buffer)
43 {
44 if (mWriteAccessors.contains(key)) {
45 auto accessor = mWriteAccessors.value(key);
46 return accessor(value, buffer);
47 }
48 }
49
50 virtual QVariant getProperty(const QString &key, BufferType const *buffer) const
51 {
52 if (mReadAccessors.contains(key)) {
53 auto accessor = mReadAccessors.value(key);
54 return accessor(buffer);
55 }
56 return QVariant();
57 }
58 QHash<QString, std::function<QVariant(BufferType const *)> > mReadAccessors;
59 QHash<QString, std::function<void(const QVariant &, BufferType*)> > mWriteAccessors;
60};
61
62//The factory should define how to go from an entitybuffer (local + resource buffer), to a domain type adapter.
63//It defines how values are split accross local and resource buffer.
64//This is required by the facade the read the value, and by the pipeline preprocessors to access the domain values in a generic way.
65template<typename DomainType, typename LocalBuffer, typename ResourceBuffer>
66class DomainTypeAdaptorFactory
67{
68};
69
70template<typename LocalBuffer, typename ResourceBuffer>
71class DomainTypeAdaptorFactory<typename Akonadi2::Domain::Event, LocalBuffer, ResourceBuffer>
72{
73public:
74 QSharedPointer<Akonadi2::Domain::BufferAdaptor> createAdaptor(const Akonadi2::Entity &entity);
75
76// private:
77 QSharedPointer<PropertyMapper<LocalBuffer> > mLocalMapper;
78 QSharedPointer<PropertyMapper<ResourceBuffer> > mResourceMapper;
79};
80
29class DummyResourceFacade : public Akonadi2::StoreFacade<Akonadi2::Domain::Event> 81class DummyResourceFacade : public Akonadi2::StoreFacade<Akonadi2::Domain::Event>
30{ 82{
31public: 83public:
@@ -39,4 +91,5 @@ public:
39private: 91private:
40 void synchronizeResource(const std::function<void()> &continuation); 92 void synchronizeResource(const std::function<void()> &continuation);
41 QSharedPointer<Akonadi2::ResourceAccess> mResourceAccess; 93 QSharedPointer<Akonadi2::ResourceAccess> mResourceAccess;
94 QSharedPointer<DomainTypeAdaptorFactory<Akonadi2::Domain::Event, Akonadi2::Domain::Buffer::Event, DummyCalendar::DummyEvent> > mFactory;
42}; 95};