diff options
Diffstat (limited to 'common/synchronizer.cpp')
-rw-r--r-- | common/synchronizer.cpp | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp index be969d2..ee7a7ba 100644 --- a/common/synchronizer.cpp +++ b/common/synchronizer.cpp | |||
@@ -92,17 +92,20 @@ void Synchronizer::createEntity(const QByteArray &sinkId, const QByteArray &buff | |||
92 | void Synchronizer::modifyEntity(const QByteArray &sinkId, qint64 revision, const QByteArray &bufferType, const Sink::ApplicationDomain::ApplicationDomainType &domainObject, | 92 | void Synchronizer::modifyEntity(const QByteArray &sinkId, qint64 revision, const QByteArray &bufferType, const Sink::ApplicationDomain::ApplicationDomainType &domainObject, |
93 | DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function<void(const QByteArray &)> callback) | 93 | DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function<void(const QByteArray &)> callback) |
94 | { | 94 | { |
95 | // FIXME removals | ||
96 | QByteArrayList deletedProperties; | ||
95 | // These changes are coming from the source | 97 | // These changes are coming from the source |
96 | const auto replayToSource = false; | 98 | const auto replayToSource = false; |
97 | flatbuffers::FlatBufferBuilder entityFbb; | 99 | flatbuffers::FlatBufferBuilder entityFbb; |
98 | adaptorFactory.createBuffer(domainObject, entityFbb); | 100 | adaptorFactory.createBuffer(domainObject, entityFbb); |
99 | flatbuffers::FlatBufferBuilder fbb; | 101 | flatbuffers::FlatBufferBuilder fbb; |
100 | auto entityId = fbb.CreateString(sinkId.toStdString()); | 102 | auto entityId = fbb.CreateString(sinkId.toStdString()); |
103 | auto modifiedProperties = BufferUtils::toVector(fbb, domainObject.changedProperties()); | ||
104 | auto deletions = BufferUtils::toVector(fbb, deletedProperties); | ||
101 | // This is the resource type and not the domain type | 105 | // This is the resource type and not the domain type |
102 | auto type = fbb.CreateString(bufferType.toStdString()); | 106 | auto type = fbb.CreateString(bufferType.toStdString()); |
103 | auto delta = Sink::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); | 107 | auto delta = Sink::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); |
104 | // FIXME removals | 108 | auto location = Sink::Commands::CreateModifyEntity(fbb, revision, entityId, deletions, type, delta, replayToSource, modifiedProperties); |
105 | auto location = Sink::Commands::CreateModifyEntity(fbb, revision, entityId, 0, type, delta, replayToSource); | ||
106 | Sink::Commands::FinishModifyEntityBuffer(fbb, location); | 109 | Sink::Commands::FinishModifyEntityBuffer(fbb, location); |
107 | callback(BufferUtils::extractBuffer(fbb)); | 110 | callback(BufferUtils::extractBuffer(fbb)); |
108 | } | 111 | } |
@@ -223,6 +226,16 @@ void Synchronizer::createOrModify(const QByteArray &bufferType, const QByteArray | |||
223 | } | 226 | } |
224 | } | 227 | } |
225 | 228 | ||
229 | template<typename DomainType> | ||
230 | void Synchronizer::modify(const DomainType &entity) | ||
231 | { | ||
232 | const auto bufferType = ApplicationDomain::getTypeName<DomainType>(); | ||
233 | const auto adaptorFactory = Sink::AdaptorFactoryRegistry::instance().getFactory(mResourceType, bufferType); | ||
234 | Q_ASSERT(adaptorFactory); | ||
235 | modifyEntity(entity.identifier(), entity.revision(), bufferType, entity, *adaptorFactory, | ||
236 | [this](const QByteArray &buffer) { enqueueCommand(Sink::Commands::ModifyEntityCommand, buffer); }); | ||
237 | } | ||
238 | |||
226 | KAsync::Job<void> Synchronizer::synchronize() | 239 | KAsync::Job<void> Synchronizer::synchronize() |
227 | { | 240 | { |
228 | Trace() << "Synchronizing"; | 241 | Trace() << "Synchronizing"; |
@@ -263,7 +276,8 @@ Sink::Storage::Transaction &Synchronizer::syncTransaction() | |||
263 | } | 276 | } |
264 | 277 | ||
265 | #define REGISTER_TYPE(T) \ | 278 | #define REGISTER_TYPE(T) \ |
266 | template void Synchronizer::createOrModify(const QByteArray &bufferType, const QByteArray &remoteId, const T &entity, const QHash<QByteArray, Sink::Query::Comparator> &mergeCriteria) | 279 | template void Synchronizer::createOrModify(const QByteArray &bufferType, const QByteArray &remoteId, const T &entity, const QHash<QByteArray, Sink::Query::Comparator> &mergeCriteria); \ |
280 | template void Synchronizer::modify(const T &entity); | ||
267 | 281 | ||
268 | REGISTER_TYPE(ApplicationDomain::Event); | 282 | REGISTER_TYPE(ApplicationDomain::Event); |
269 | REGISTER_TYPE(ApplicationDomain::Mail); | 283 | REGISTER_TYPE(ApplicationDomain::Mail); |