summaryrefslogtreecommitdiffstats
path: root/common/domainadaptor.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/domainadaptor.h')
-rw-r--r--common/domainadaptor.h63
1 files changed, 18 insertions, 45 deletions
diff --git a/common/domainadaptor.h b/common/domainadaptor.h
index af5d5fc..f981a1f 100644
--- a/common/domainadaptor.h
+++ b/common/domainadaptor.h
@@ -29,21 +29,19 @@
29#include "domain/typeimplementations.h" 29#include "domain/typeimplementations.h"
30#include "bufferadaptor.h" 30#include "bufferadaptor.h"
31#include "entity_generated.h" 31#include "entity_generated.h"
32#include "metadata_generated.h"
33#include "entitybuffer.h" 32#include "entitybuffer.h"
34#include "propertymapper.h" 33#include "propertymapper.h"
35#include "log.h" 34#include "log.h"
36#include "dummy_generated.h"
37 35
38/** 36/**
39 * Create a buffer from a domain object using the provided mappings 37 * Create a buffer from a domain object using the provided mappings
40 */ 38 */
41template <class Builder, class Buffer> 39template <class Builder, class Buffer>
42flatbuffers::Offset<Buffer> 40flatbuffers::Offset<Buffer>
43createBufferPart(const Sink::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, const WritePropertyMapper<Builder> &mapper) 41createBufferPart(const Sink::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, const PropertyMapper &mapper)
44{ 42{
45 // First create a primitives such as strings using the mappings 43 // First create a primitives such as strings using the mappings
46 QList<std::function<void(Builder &)>> propertiesToAddToResource; 44 QList<std::function<void(void *builder)>> propertiesToAddToResource;
47 for (const auto &property : domainObject.changedProperties()) { 45 for (const auto &property : domainObject.changedProperties()) {
48 // SinkTrace() << "copying property " << property; 46 // SinkTrace() << "copying property " << property;
49 const auto value = domainObject.getProperty(property); 47 const auto value = domainObject.getProperty(property);
@@ -57,7 +55,7 @@ createBufferPart(const Sink::ApplicationDomain::ApplicationDomainType &domainObj
57 // Then create all porperties using the above generated builderCalls 55 // Then create all porperties using the above generated builderCalls
58 Builder builder(fbb); 56 Builder builder(fbb);
59 for (auto propertyBuilder : propertiesToAddToResource) { 57 for (auto propertyBuilder : propertiesToAddToResource) {
60 propertyBuilder(builder); 58 propertyBuilder(&builder);
61 } 59 }
62 return builder.Finish(); 60 return builder.Finish();
63} 61}
@@ -68,7 +66,7 @@ createBufferPart(const Sink::ApplicationDomain::ApplicationDomainType &domainObj
68 * After this the buffer can be extracted from the FlatBufferBuilder object. 66 * After this the buffer can be extracted from the FlatBufferBuilder object.
69 */ 67 */
70template <typename Buffer, typename BufferBuilder> 68template <typename Buffer, typename BufferBuilder>
71static void createBufferPartBuffer(const Sink::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, WritePropertyMapper<BufferBuilder> &mapper) 69static void createBufferPartBuffer(const Sink::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, PropertyMapper &mapper)
72{ 70{
73 auto pos = createBufferPart<BufferBuilder, Buffer>(domainObject, fbb, mapper); 71 auto pos = createBufferPart<BufferBuilder, Buffer>(domainObject, fbb, mapper);
74 // Because we cannot template the following call 72 // Because we cannot template the following call
@@ -120,10 +118,8 @@ private:
120/** 118/**
121 * A generic adaptor implementation that uses a property mapper to read/write values. 119 * A generic adaptor implementation that uses a property mapper to read/write values.
122 */ 120 */
123template <class LocalBuffer, class ResourceBuffer>
124class DatastoreBufferAdaptor : public Sink::ApplicationDomain::BufferAdaptor 121class DatastoreBufferAdaptor : public Sink::ApplicationDomain::BufferAdaptor
125{ 122{
126 SINK_DEBUG_AREA("bufferadaptor")
127public: 123public:
128 DatastoreBufferAdaptor() : BufferAdaptor() 124 DatastoreBufferAdaptor() : BufferAdaptor()
129 { 125 {
@@ -137,9 +133,7 @@ public:
137 133
138 virtual QVariant getProperty(const QByteArray &key) const Q_DECL_OVERRIDE 134 virtual QVariant getProperty(const QByteArray &key) const Q_DECL_OVERRIDE
139 { 135 {
140 if (mResourceBuffer && mResourceMapper->hasMapping(key)) { 136 if (mLocalBuffer && mLocalMapper->hasMapping(key)) {
141 return mResourceMapper->getProperty(key, mResourceBuffer);
142 } else if (mLocalBuffer && mLocalMapper->hasMapping(key)) {
143 return mLocalMapper->getProperty(key, mLocalBuffer); 137 return mLocalMapper->getProperty(key, mLocalBuffer);
144 } else if (mIndex && mIndexMapper->hasMapping(key)) { 138 } else if (mIndex && mIndexMapper->hasMapping(key)) {
145 return mIndexMapper->getProperty(key, *mIndex, *this); 139 return mIndexMapper->getProperty(key, *mIndex, *this);
@@ -152,23 +146,21 @@ public:
152 */ 146 */
153 virtual QList<QByteArray> availableProperties() const Q_DECL_OVERRIDE 147 virtual QList<QByteArray> availableProperties() const Q_DECL_OVERRIDE
154 { 148 {
155 return mResourceMapper->availableProperties() + mLocalMapper->availableProperties() + mIndexMapper->availableProperties(); 149 return mLocalMapper->availableProperties() + mIndexMapper->availableProperties();
156 } 150 }
157 151
158 LocalBuffer const *mLocalBuffer; 152 void const *mLocalBuffer;
159 ResourceBuffer const *mResourceBuffer; 153 QSharedPointer<PropertyMapper> mLocalMapper;
160 QSharedPointer<ReadPropertyMapper<LocalBuffer>> mLocalMapper;
161 QSharedPointer<ReadPropertyMapper<ResourceBuffer>> mResourceMapper;
162 QSharedPointer<IndexPropertyMapper> mIndexMapper; 154 QSharedPointer<IndexPropertyMapper> mIndexMapper;
163 TypeIndex *mIndex; 155 TypeIndex *mIndex;
164}; 156};
165 157
166/** 158/**
167 * The factory should define how to go from an entitybuffer (local + resource buffer), to a domain type adapter. 159 * The factory should define how to go from an entitybuffer (local buffer), to a domain type adapter.
168 * It defines how values are split accross local and resource buffer. 160 * It defines how values are split accross local and resource buffer.
169 * This is required by the facade the read the value, and by the pipeline preprocessors to access the domain values in a generic way. 161 * This is required by the facade the read the value, and by the pipeline preprocessors to access the domain values in a generic way.
170 */ 162 */
171template <typename DomainType, typename ResourceBuffer = Sink::ApplicationDomain::Buffer::Dummy, typename ResourceBuilder = Sink::ApplicationDomain::Buffer::DummyBuilder> 163template <typename DomainType>
172class SINK_EXPORT DomainTypeAdaptorFactory : public DomainTypeAdaptorFactoryInterface 164class SINK_EXPORT DomainTypeAdaptorFactory : public DomainTypeAdaptorFactoryInterface
173{ 165{
174 typedef typename Sink::ApplicationDomain::TypeImplementation<DomainType>::Buffer LocalBuffer; 166 typedef typename Sink::ApplicationDomain::TypeImplementation<DomainType>::Buffer LocalBuffer;
@@ -176,31 +168,25 @@ class SINK_EXPORT DomainTypeAdaptorFactory : public DomainTypeAdaptorFactoryInte
176 168
177public: 169public:
178 DomainTypeAdaptorFactory() 170 DomainTypeAdaptorFactory()
179 : mLocalMapper(QSharedPointer<ReadPropertyMapper<LocalBuffer>>::create()), 171 : mPropertyMapper(QSharedPointer<PropertyMapper>::create()),
180 mResourceMapper(QSharedPointer<ReadPropertyMapper<ResourceBuffer>>::create()),
181 mLocalWriteMapper(QSharedPointer<WritePropertyMapper<LocalBuilder>>::create()),
182 mResourceWriteMapper(QSharedPointer<WritePropertyMapper<ResourceBuilder>>::create()),
183 mIndexMapper(QSharedPointer<IndexPropertyMapper>::create()) 172 mIndexMapper(QSharedPointer<IndexPropertyMapper>::create())
184 { 173 {
185 Sink::ApplicationDomain::TypeImplementation<DomainType>::configure(*mLocalMapper); 174 Sink::ApplicationDomain::TypeImplementation<DomainType>::configure(*mPropertyMapper);
186 Sink::ApplicationDomain::TypeImplementation<DomainType>::configure(*mLocalWriteMapper);
187 Sink::ApplicationDomain::TypeImplementation<DomainType>::configure(*mIndexMapper); 175 Sink::ApplicationDomain::TypeImplementation<DomainType>::configure(*mIndexMapper);
188 } 176 }
189 177
190 virtual ~DomainTypeAdaptorFactory(){}; 178 virtual ~DomainTypeAdaptorFactory(){};
191 179
192 /** 180 /**
193 * Creates an adaptor for the given domain and resource types. 181 * Creates an adaptor for the given domain types.
194 * 182 *
195 * This returns by default a DatastoreBufferAdaptor initialized with the corresponding property mappers. 183 * This returns by default a DatastoreBufferAdaptor initialized with the corresponding property mappers.
196 */ 184 */
197 virtual QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> createAdaptor(const Sink::Entity &entity, TypeIndex *index = nullptr) Q_DECL_OVERRIDE 185 virtual QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> createAdaptor(const Sink::Entity &entity, TypeIndex *index = nullptr) Q_DECL_OVERRIDE
198 { 186 {
199 auto adaptor = QSharedPointer<DatastoreBufferAdaptor<LocalBuffer, ResourceBuffer>>::create(); 187 auto adaptor = QSharedPointer<DatastoreBufferAdaptor>::create();
200 adaptor->mLocalBuffer = Sink::EntityBuffer::readBuffer<LocalBuffer>(entity.local()); 188 adaptor->mLocalBuffer = Sink::EntityBuffer::readBuffer<LocalBuffer>(entity.local());
201 adaptor->mLocalMapper = mLocalMapper; 189 adaptor->mLocalMapper = mPropertyMapper;
202 adaptor->mResourceBuffer = Sink::EntityBuffer::readBuffer<ResourceBuffer>(entity.resource());
203 adaptor->mResourceMapper = mResourceMapper;
204 adaptor->mIndexMapper = mIndexMapper; 190 adaptor->mIndexMapper = mIndexMapper;
205 adaptor->mIndex = index; 191 adaptor->mIndex = index;
206 return adaptor; 192 return adaptor;
@@ -210,18 +196,8 @@ public:
210 createBuffer(const Sink::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, void const *metadataData = 0, size_t metadataSize = 0) Q_DECL_OVERRIDE 196 createBuffer(const Sink::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, void const *metadataData = 0, size_t metadataSize = 0) Q_DECL_OVERRIDE
211 { 197 {
212 flatbuffers::FlatBufferBuilder localFbb; 198 flatbuffers::FlatBufferBuilder localFbb;
213 if (mLocalWriteMapper) { 199 createBufferPartBuffer<LocalBuffer, LocalBuilder>(domainObject, localFbb, *mPropertyMapper);
214 // SinkTrace() << "Creating local buffer part"; 200 Sink::EntityBuffer::assembleEntityBuffer(fbb, metadataData, metadataSize, 0, 0, localFbb.GetBufferPointer(), localFbb.GetSize());
215 createBufferPartBuffer<LocalBuffer, LocalBuilder>(domainObject, localFbb, *mLocalWriteMapper);
216 }
217
218 flatbuffers::FlatBufferBuilder resFbb;
219 if (mResourceWriteMapper) {
220 // SinkTrace() << "Creating resouce buffer part";
221 createBufferPartBuffer<ResourceBuffer, ResourceBuilder>(domainObject, resFbb, *mResourceWriteMapper);
222 }
223
224 Sink::EntityBuffer::assembleEntityBuffer(fbb, metadataData, metadataSize, resFbb.GetBufferPointer(), resFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize());
225 return true; 201 return true;
226 } 202 }
227 203
@@ -236,10 +212,7 @@ public:
236 212
237 213
238protected: 214protected:
239 QSharedPointer<ReadPropertyMapper<LocalBuffer>> mLocalMapper; 215 QSharedPointer<PropertyMapper> mPropertyMapper;
240 QSharedPointer<ReadPropertyMapper<ResourceBuffer>> mResourceMapper;
241 QSharedPointer<WritePropertyMapper<LocalBuilder>> mLocalWriteMapper;
242 QSharedPointer<WritePropertyMapper<ResourceBuilder>> mResourceWriteMapper;
243 QSharedPointer<IndexPropertyMapper> mIndexMapper; 216 QSharedPointer<IndexPropertyMapper> mIndexMapper;
244}; 217};
245 218