summaryrefslogtreecommitdiffstats
path: root/common/facade.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/facade.h')
-rw-r--r--common/facade.h52
1 files changed, 48 insertions, 4 deletions
diff --git a/common/facade.h b/common/facade.h
index 6c1ad67..a5858d5 100644
--- a/common/facade.h
+++ b/common/facade.h
@@ -84,14 +84,29 @@ namespace Akonadi2 {
84 class ResourceAccess; 84 class ResourceAccess;
85/** 85/**
86 * Default facade implementation for resources that are implemented in a separate process using the ResourceAccess class. 86 * Default facade implementation for resources that are implemented in a separate process using the ResourceAccess class.
87 *
88 * Ideally a basic resource has no implementation effort for the facades and can simply instanciate default implementations (meaning it only has to implement the factory with all supported types).
89 * A resource has to implement:
90 * * A facade factory registering all available facades
91 * * An adaptor factory if it uses special resource buffers (default implementation can be used otherwise)
92 * * A mapping between resource and buffertype if default can't be used.
93 *
94 * Additionally a resource only has to provide a synchronizer plugin to execute the synchronization
87 */ 95 */
88template <typename DomainType> 96template <typename DomainType>
89class GenericFacade: public Akonadi2::StoreFacade<DomainType> 97class GenericFacade: public Akonadi2::StoreFacade<DomainType>
90{ 98{
91public: 99public:
92 GenericFacade(const QByteArray &resourceIdentifier) 100 /**
101 * Create a new GenericFacade
102 *
103 * @param resourceIdentifier is the identifier of the resource instance
104 * @param adaptorFactory is the adaptor factory used to generate the mappings from domain to resource types and vice versa
105 */
106 GenericFacade(const QByteArray &resourceIdentifier, const QSharedPointer<DomainTypeAdaptorFactoryInterface<DomainType> > &adaptorFactory = QSharedPointer<DomainTypeAdaptorFactoryInterface<DomainType> >())
93 : Akonadi2::StoreFacade<DomainType>(), 107 : Akonadi2::StoreFacade<DomainType>(),
94 mResourceAccess(new ResourceAccess(resourceIdentifier)) 108 mResourceAccess(new ResourceAccess(resourceIdentifier)),
109 mDomainTypeAdaptorFactory(adaptorFactory)
95 { 110 {
96 } 111 }
97 112
@@ -99,6 +114,34 @@ public:
99 { 114 {
100 } 115 }
101 116
117 static QByteArray bufferTypeForDomainType()
118 {
119 //We happen to have a one to one mapping
120 return Akonadi2::ApplicationDomain::getTypeName<DomainType>();
121 }
122
123 Async::Job<void> create(const Akonadi2::ApplicationDomain::Event &domainObject) Q_DECL_OVERRIDE
124 {
125 if (!mDomainTypeAdaptorFactory) {
126 Warning() << "No domain type adaptor factory available";
127 }
128 flatbuffers::FlatBufferBuilder entityFbb;
129 mDomainTypeAdaptorFactory->createBuffer(domainObject, entityFbb);
130 return sendCreateCommand(bufferTypeForDomainType(), QByteArray::fromRawData(reinterpret_cast<const char*>(entityFbb.GetBufferPointer()), entityFbb.GetSize()));
131 }
132
133 Async::Job<void> modify(const Akonadi2::ApplicationDomain::Event &domainObject) Q_DECL_OVERRIDE
134 {
135 //TODO
136 return Async::null<void>();
137 }
138
139 Async::Job<void> remove(const Akonadi2::ApplicationDomain::Event &domainObject) Q_DECL_OVERRIDE
140 {
141 //TODO
142 return Async::null<void>();
143 }
144
102 //TODO JOBAPI return job from sync continuation to execute it as subjob? 145 //TODO JOBAPI return job from sync continuation to execute it as subjob?
103 Async::Job<void> load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<typename DomainType::Ptr> > &resultProvider) Q_DECL_OVERRIDE 146 Async::Job<void> load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<typename DomainType::Ptr> > &resultProvider) Q_DECL_OVERRIDE
104 { 147 {
@@ -142,11 +185,11 @@ public:
142 } 185 }
143 186
144protected: 187protected:
145 Async::Job<void> sendCreateCommand(const QByteArray &t, const QByteArray &buffer) 188 Async::Job<void> sendCreateCommand(const QByteArray &resourceBufferType, const QByteArray &buffer)
146 { 189 {
147 flatbuffers::FlatBufferBuilder fbb; 190 flatbuffers::FlatBufferBuilder fbb;
148 //This is the resource buffer type and not the domain type 191 //This is the resource buffer type and not the domain type
149 auto type = fbb.CreateString(t.constData()); 192 auto type = fbb.CreateString(resourceBufferType.constData());
150 auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, buffer.constData(), buffer.size()); 193 auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, buffer.constData(), buffer.size());
151 auto location = Akonadi2::Commands::CreateCreateEntity(fbb, type, delta); 194 auto location = Akonadi2::Commands::CreateCreateEntity(fbb, type, delta);
152 Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); 195 Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location);
@@ -177,6 +220,7 @@ protected:
177protected: 220protected:
178 //TODO use one resource access instance per application => make static 221 //TODO use one resource access instance per application => make static
179 QSharedPointer<Akonadi2::ResourceAccess> mResourceAccess; 222 QSharedPointer<Akonadi2::ResourceAccess> mResourceAccess;
223 QSharedPointer<DomainTypeAdaptorFactoryInterface<DomainType> > mDomainTypeAdaptorFactory;
180}; 224};
181 225
182} 226}