summaryrefslogtreecommitdiffstats
path: root/common/sourcewriteback.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-07-11 11:55:29 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-07-11 11:55:29 +0200
commit3a3118e768e1447dc7524328e84b8d7faef81fe1 (patch)
treeaf5582170ed6164fffc9365f34b17bf449c0db40 /common/sourcewriteback.cpp
parentf9379318d801df204cc50385c5eca1f28e91755e (diff)
parentce2fd2666f084eebe443598f6f3740a02913091e (diff)
downloadsink-3a3118e768e1447dc7524328e84b8d7faef81fe1.tar.gz
sink-3a3118e768e1447dc7524328e84b8d7faef81fe1.zip
Merge branch 'feature/notifications' into develop
Diffstat (limited to 'common/sourcewriteback.cpp')
-rw-r--r--common/sourcewriteback.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/common/sourcewriteback.cpp b/common/sourcewriteback.cpp
index a277606..7d21ea6 100644
--- a/common/sourcewriteback.cpp
+++ b/common/sourcewriteback.cpp
@@ -26,6 +26,8 @@
26#define ENTITY_TYPE_MAIL "mail" 26#define ENTITY_TYPE_MAIL "mail"
27#define ENTITY_TYPE_FOLDER "folder" 27#define ENTITY_TYPE_FOLDER "folder"
28 28
29SINK_DEBUG_AREA("sourcewriteback")
30
29using namespace Sink; 31using namespace Sink;
30 32
31SourceWriteBack::SourceWriteBack(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier) 33SourceWriteBack::SourceWriteBack(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier)
@@ -55,14 +57,14 @@ RemoteIdMap &SourceWriteBack::syncStore()
55 57
56KAsync::Job<void> SourceWriteBack::replay(const QByteArray &type, const QByteArray &key, const QByteArray &value) 58KAsync::Job<void> SourceWriteBack::replay(const QByteArray &type, const QByteArray &key, const QByteArray &value)
57{ 59{
58 Trace() << "Replaying" << type << key; 60 SinkTrace() << "Replaying" << type << key;
59 61
60 Sink::EntityBuffer buffer(value); 62 Sink::EntityBuffer buffer(value);
61 const Sink::Entity &entity = buffer.entity(); 63 const Sink::Entity &entity = buffer.entity();
62 const auto metadataBuffer = Sink::EntityBuffer::readBuffer<Sink::Metadata>(entity.metadata()); 64 const auto metadataBuffer = Sink::EntityBuffer::readBuffer<Sink::Metadata>(entity.metadata());
63 Q_ASSERT(metadataBuffer); 65 Q_ASSERT(metadataBuffer);
64 if (!metadataBuffer->replayToSource()) { 66 if (!metadataBuffer->replayToSource()) {
65 Trace() << "Change is coming from the source"; 67 SinkTrace() << "Change is coming from the source";
66 return KAsync::null<void>(); 68 return KAsync::null<void>();
67 } 69 }
68 Q_ASSERT(!mSyncStore); 70 Q_ASSERT(!mSyncStore);
@@ -81,11 +83,11 @@ KAsync::Job<void> SourceWriteBack::replay(const QByteArray &type, const QByteArr
81 if (operation != Sink::Operation_Creation) { 83 if (operation != Sink::Operation_Creation) {
82 oldRemoteId = syncStore().resolveLocalId(type, uid); 84 oldRemoteId = syncStore().resolveLocalId(type, uid);
83 if (oldRemoteId.isEmpty()) { 85 if (oldRemoteId.isEmpty()) {
84 Warning() << "Couldn't find the remote id for: " << type << uid; 86 SinkWarning() << "Couldn't find the remote id for: " << type << uid;
85 return KAsync::error<void>(1, "Couldn't find the remote id."); 87 return KAsync::error<void>(1, "Couldn't find the remote id.");
86 } 88 }
87 } 89 }
88 Trace() << "Replaying " << key << type << uid << oldRemoteId; 90 SinkTrace() << "Replaying " << key << type << uid << oldRemoteId;
89 91
90 KAsync::Job<QByteArray> job = KAsync::null<QByteArray>(); 92 KAsync::Job<QByteArray> job = KAsync::null<QByteArray>();
91 if (type == ENTITY_TYPE_FOLDER) { 93 if (type == ENTITY_TYPE_FOLDER) {
@@ -98,24 +100,24 @@ KAsync::Job<void> SourceWriteBack::replay(const QByteArray &type, const QByteArr
98 100
99 return job.then<void, QByteArray>([this, operation, type, uid, oldRemoteId](const QByteArray &remoteId) { 101 return job.then<void, QByteArray>([this, operation, type, uid, oldRemoteId](const QByteArray &remoteId) {
100 if (operation == Sink::Operation_Creation) { 102 if (operation == Sink::Operation_Creation) {
101 Trace() << "Replayed creation with remote id: " << remoteId; 103 SinkTrace() << "Replayed creation with remote id: " << remoteId;
102 if (remoteId.isEmpty()) { 104 if (remoteId.isEmpty()) {
103 Warning() << "Returned an empty remoteId from the creation"; 105 SinkWarning() << "Returned an empty remoteId from the creation";
104 } else { 106 } else {
105 syncStore().recordRemoteId(type, uid, remoteId); 107 syncStore().recordRemoteId(type, uid, remoteId);
106 } 108 }
107 } else if (operation == Sink::Operation_Modification) { 109 } else if (operation == Sink::Operation_Modification) {
108 Trace() << "Replayed modification with remote id: " << remoteId; 110 SinkTrace() << "Replayed modification with remote id: " << remoteId;
109 if (remoteId.isEmpty()) { 111 if (remoteId.isEmpty()) {
110 Warning() << "Returned an empty remoteId from the creation"; 112 SinkWarning() << "Returned an empty remoteId from the creation";
111 } else { 113 } else {
112 syncStore().updateRemoteId(type, uid, remoteId); 114 syncStore().updateRemoteId(type, uid, remoteId);
113 } 115 }
114 } else if (operation == Sink::Operation_Removal) { 116 } else if (operation == Sink::Operation_Removal) {
115 Trace() << "Replayed removal with remote id: " << oldRemoteId; 117 SinkTrace() << "Replayed removal with remote id: " << oldRemoteId;
116 syncStore().removeRemoteId(type, uid, oldRemoteId); 118 syncStore().removeRemoteId(type, uid, oldRemoteId);
117 } else { 119 } else {
118 ErrorMsg() << "Unkown operation" << operation; 120 SinkError() << "Unkown operation" << operation;
119 } 121 }
120 122
121 mSyncStore.clear(); 123 mSyncStore.clear();
@@ -123,7 +125,7 @@ KAsync::Job<void> SourceWriteBack::replay(const QByteArray &type, const QByteArr
123 mTransaction.abort(); 125 mTransaction.abort();
124 mSyncTransaction.commit(); 126 mSyncTransaction.commit();
125 }, [this](int errorCode, const QString &errorMessage) { 127 }, [this](int errorCode, const QString &errorMessage) {
126 Warning() << "Failed to replay change: " << errorMessage; 128 SinkWarning() << "Failed to replay change: " << errorMessage;
127 mSyncStore.clear(); 129 mSyncStore.clear();
128 mEntityStore.clear(); 130 mEntityStore.clear();
129 mTransaction.abort(); 131 mTransaction.abort();