diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-06-17 17:34:34 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-06-17 17:34:34 +0200 |
commit | 207effdd7112141ad4fc5cdd46f332870a0c065c (patch) | |
tree | b750cbecda149b4a4ae86eb156e59f4a070bbb5c /common | |
parent | b2f52e3ffc5b2305f5275f18376daac7612f2e7b (diff) | |
download | sink-207effdd7112141ad4fc5cdd46f332870a0c065c.tar.gz sink-207effdd7112141ad4fc5cdd46f332870a0c065c.zip |
A working mailtransport resource
Diffstat (limited to 'common')
-rw-r--r-- | common/domain/applicationdomaintype.h | 1 | ||||
-rw-r--r-- | common/domain/mail.cpp | 2 | ||||
-rw-r--r-- | common/domain/mail.fbs | 1 | ||||
-rw-r--r-- | common/synchronizer.cpp | 20 | ||||
-rw-r--r-- | common/synchronizer.h | 7 |
5 files changed, 28 insertions, 3 deletions
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index 12a9e56..928ea58 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h | |||
@@ -211,6 +211,7 @@ struct SINK_EXPORT Mail : public Entity { | |||
211 | SINK_BLOB_PROPERTY(MimeMessage, mimeMessage); | 211 | SINK_BLOB_PROPERTY(MimeMessage, mimeMessage); |
212 | SINK_PROPERTY(bool, Draft, draft); | 212 | SINK_PROPERTY(bool, Draft, draft); |
213 | SINK_PROPERTY(bool, Trash, trash); | 213 | SINK_PROPERTY(bool, Trash, trash); |
214 | SINK_PROPERTY(bool, Sent, sent); | ||
214 | }; | 215 | }; |
215 | 216 | ||
216 | /** | 217 | /** |
diff --git a/common/domain/mail.cpp b/common/domain/mail.cpp index dd4eca8..5b35a9a 100644 --- a/common/domain/mail.cpp +++ b/common/domain/mail.cpp | |||
@@ -86,6 +86,7 @@ QSharedPointer<ReadPropertyMapper<TypeImplementation<Mail>::Buffer> > TypeImplem | |||
86 | propertyMapper->addMapping<Mail::MimeMessage, Buffer>(&Buffer::mimeMessage); | 86 | propertyMapper->addMapping<Mail::MimeMessage, Buffer>(&Buffer::mimeMessage); |
87 | propertyMapper->addMapping<Mail::Draft, Buffer>(&Buffer::draft); | 87 | propertyMapper->addMapping<Mail::Draft, Buffer>(&Buffer::draft); |
88 | propertyMapper->addMapping<Mail::Trash, Buffer>(&Buffer::trash); | 88 | propertyMapper->addMapping<Mail::Trash, Buffer>(&Buffer::trash); |
89 | propertyMapper->addMapping<Mail::Sent, Buffer>(&Buffer::sent); | ||
89 | return propertyMapper; | 90 | return propertyMapper; |
90 | } | 91 | } |
91 | 92 | ||
@@ -104,5 +105,6 @@ QSharedPointer<WritePropertyMapper<TypeImplementation<Mail>::BufferBuilder> > Ty | |||
104 | propertyMapper->addMapping<Mail::MimeMessage>(&BufferBuilder::add_mimeMessage); | 105 | propertyMapper->addMapping<Mail::MimeMessage>(&BufferBuilder::add_mimeMessage); |
105 | propertyMapper->addMapping<Mail::Draft>(&BufferBuilder::add_draft); | 106 | propertyMapper->addMapping<Mail::Draft>(&BufferBuilder::add_draft); |
106 | propertyMapper->addMapping<Mail::Trash>(&BufferBuilder::add_trash); | 107 | propertyMapper->addMapping<Mail::Trash>(&BufferBuilder::add_trash); |
108 | propertyMapper->addMapping<Mail::Sent>(&BufferBuilder::add_sent); | ||
107 | return propertyMapper; | 109 | return propertyMapper; |
108 | } | 110 | } |
diff --git a/common/domain/mail.fbs b/common/domain/mail.fbs index 3a84ca1..a0c0d82 100644 --- a/common/domain/mail.fbs +++ b/common/domain/mail.fbs | |||
@@ -12,6 +12,7 @@ table Mail { | |||
12 | mimeMessage:string; | 12 | mimeMessage:string; |
13 | draft:bool = false; | 13 | draft:bool = false; |
14 | trash:bool = false; | 14 | trash:bool = false; |
15 | sent:bool = false; | ||
15 | } | 16 | } |
16 | 17 | ||
17 | root_type Mail; | 18 | root_type Mail; |
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); |
diff --git a/common/synchronizer.h b/common/synchronizer.h index 6521876..6f98f35 100644 --- a/common/synchronizer.h +++ b/common/synchronizer.h | |||
@@ -86,6 +86,13 @@ protected: | |||
86 | template <typename DomainType> | 86 | template <typename DomainType> |
87 | void createOrModify(const QByteArray &bufferType, const QByteArray &remoteId, const DomainType &entity, const QHash<QByteArray, Sink::Query::Comparator> &mergeCriteria); | 87 | void createOrModify(const QByteArray &bufferType, const QByteArray &remoteId, const DomainType &entity, const QHash<QByteArray, Sink::Query::Comparator> &mergeCriteria); |
88 | 88 | ||
89 | // template <typename DomainType> | ||
90 | // void create(const DomainType &entity); | ||
91 | template <typename DomainType> | ||
92 | void modify(const DomainType &entity); | ||
93 | // template <typename DomainType> | ||
94 | // void remove(const DomainType &entity); | ||
95 | |||
89 | virtual KAsync::Job<void> synchronizeWithSource() = 0; | 96 | virtual KAsync::Job<void> synchronizeWithSource() = 0; |
90 | 97 | ||
91 | private: | 98 | private: |