summaryrefslogtreecommitdiffstats
path: root/dummyresource/facade.h
diff options
context:
space:
mode:
Diffstat (limited to 'dummyresource/facade.h')
-rw-r--r--dummyresource/facade.h50
1 files changed, 2 insertions, 48 deletions
diff --git a/dummyresource/facade.h b/dummyresource/facade.h
index 46b27ef..e01d254 100644
--- a/dummyresource/facade.h
+++ b/dummyresource/facade.h
@@ -21,62 +21,16 @@
21 21
22#include "common/clientapi.h" 22#include "common/clientapi.h"
23#include "common/storage.h" 23#include "common/storage.h"
24#include "resourcefactory.h"
24#include "entity_generated.h" 25#include "entity_generated.h"
25#include "event_generated.h" 26#include "event_generated.h"
26#include "dummycalendar_generated.h" 27#include "dummycalendar_generated.h"
28#include "common/domainadaptor.h"
27 29
28namespace Akonadi2 { 30namespace Akonadi2 {
29 class ResourceAccess; 31 class ResourceAccess;
30} 32}
31 33
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 34
81class DummyResourceFacade : public Akonadi2::StoreFacade<Akonadi2::Domain::Event> 35class DummyResourceFacade : public Akonadi2::StoreFacade<Akonadi2::Domain::Event>
82{ 36{