summaryrefslogtreecommitdiffstats
path: root/common/synchronizer.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-03-17 15:29:28 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-03-17 15:29:28 +0100
commitefc3ca52c338a6b8fca8c523dec86f2c9e84f1c0 (patch)
tree6d090e5b23ec06dd3f42931cc3995dc19e820d53 /common/synchronizer.cpp
parentf4cba9977d46bd94b19586e31f1bea250f211c0c (diff)
downloadsink-efc3ca52c338a6b8fca8c523dec86f2c9e84f1c0.tar.gz
sink-efc3ca52c338a6b8fca8c523dec86f2c9e84f1c0.zip
emitNotification function
Diffstat (limited to 'common/synchronizer.cpp')
-rw-r--r--common/synchronizer.cpp36
1 files changed, 14 insertions, 22 deletions
diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp
index c7c0af5..ff13783 100644
--- a/common/synchronizer.cpp
+++ b/common/synchronizer.cpp
@@ -292,6 +292,16 @@ void Synchronizer::flushComplete(const QByteArray &flushId)
292 } 292 }
293} 293}
294 294
295void Synchronizer::emitNotification(Notification::NoticationType type, int code, const QString &message, const QByteArray &id)
296{
297 Sink::Notification n;
298 n.id = id;
299 n.type = type;
300 n.message = message;
301 n.code = code;
302 emit notify(n);
303}
304
295KAsync::Job<void> Synchronizer::processRequest(const SyncRequest &request) 305KAsync::Job<void> Synchronizer::processRequest(const SyncRequest &request)
296{ 306{
297 if (request.options & SyncRequest::RequestFlush) { 307 if (request.options & SyncRequest::RequestFlush) {
@@ -316,13 +326,8 @@ KAsync::Job<void> Synchronizer::processRequest(const SyncRequest &request)
316 }); 326 });
317 } else if (request.requestType == Synchronizer::SyncRequest::Synchronization) { 327 } else if (request.requestType == Synchronizer::SyncRequest::Synchronization) {
318 return KAsync::start([this, request] { 328 return KAsync::start([this, request] {
319 Sink::Notification n;
320 n.id = request.requestId;
321 n.type = Notification::Status;
322 n.message = "Synchronization has started.";
323 n.code = ApplicationDomain::BusyStatus;
324 emit notify(n);
325 SinkLogCtx(mLogCtx) << "Synchronizing: " << request.query; 329 SinkLogCtx(mLogCtx) << "Synchronizing: " << request.query;
330 emitNotification(Notification::Status, ApplicationDomain::BusyStatus, "Synchronization has started.", request.requestId);
326 }).then(synchronizeWithSource(request.query)).then([this] { 331 }).then(synchronizeWithSource(request.query)).then([this] {
327 //Commit after every request, so implementations only have to commit more if they add a lot of data. 332 //Commit after every request, so implementations only have to commit more if they add a lot of data.
328 commit(); 333 commit();
@@ -330,21 +335,11 @@ KAsync::Job<void> Synchronizer::processRequest(const SyncRequest &request)
330 if (error) { 335 if (error) {
331 //Emit notification with error 336 //Emit notification with error
332 SinkWarningCtx(mLogCtx) << "Synchronization failed: " << error.errorMessage; 337 SinkWarningCtx(mLogCtx) << "Synchronization failed: " << error.errorMessage;
333 Sink::Notification n; 338 emitNotification(Notification::Status, ApplicationDomain::ErrorStatus, "Synchronization has ended.", request.requestId);
334 n.id = request.requestId;
335 n.type = Notification::Status;
336 n.message = "Synchronization has ended.";
337 n.code = ApplicationDomain::ErrorStatus;
338 emit notify(n);
339 return KAsync::error(error); 339 return KAsync::error(error);
340 } else { 340 } else {
341 SinkLogCtx(mLogCtx) << "Done Synchronizing"; 341 SinkLogCtx(mLogCtx) << "Done Synchronizing";
342 Sink::Notification n; 342 emitNotification(Notification::Status, ApplicationDomain::ConnectedStatus, "Synchronization has ended.", request.requestId);
343 n.id = request.requestId;
344 n.type = Notification::Status;
345 n.message = "Synchronization has ended.";
346 n.code = ApplicationDomain::ConnectedStatus;
347 emit notify(n);
348 return KAsync::null(); 343 return KAsync::null();
349 } 344 }
350 }); 345 });
@@ -354,10 +349,7 @@ KAsync::Job<void> Synchronizer::processRequest(const SyncRequest &request)
354 //FIXME it looks like this is emitted before the replay actually finishes 349 //FIXME it looks like this is emitted before the replay actually finishes
355 if (request.flushType == Flush::FlushReplayQueue) { 350 if (request.flushType == Flush::FlushReplayQueue) {
356 SinkTraceCtx(mLogCtx) << "Emitting flush completion: " << request.requestId; 351 SinkTraceCtx(mLogCtx) << "Emitting flush completion: " << request.requestId;
357 Sink::Notification n; 352 emitNotification(Notification::FlushCompletion, 0, "", request.requestId);
358 n.type = Sink::Notification::FlushCompletion;
359 n.id = request.requestId;
360 emit notify(n);
361 } else { 353 } else {
362 flatbuffers::FlatBufferBuilder fbb; 354 flatbuffers::FlatBufferBuilder fbb;
363 auto flushId = fbb.CreateString(request.requestId.toStdString()); 355 auto flushId = fbb.CreateString(request.requestId.toStdString());