From 6adf9a4734f15a2c0fa199897f76ded4659b83b7 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 4 May 2017 11:40:24 +0200 Subject: Added progress notification --- common/commands/notification.fbs | 2 ++ common/listener.cpp | 2 ++ common/notification.h | 2 ++ common/resourceaccess.cpp | 2 ++ common/synchronizer.cpp | 18 ++++++++++++++++-- common/synchronizer.h | 10 ++++++++++ 6 files changed, 34 insertions(+), 2 deletions(-) (limited to 'common') diff --git a/common/commands/notification.fbs b/common/commands/notification.fbs index 517111c..7ced666 100644 --- a/common/commands/notification.fbs +++ b/common/commands/notification.fbs @@ -5,6 +5,8 @@ table Notification { identifier: string; //An identifier that links back to the something related to the notification (e.g. a command id) message: string; code: int = 0; //See notification.h + progress: int = 0; //See notification.h + total: int = 0; //See notification.h entities: [string]; //A list of entities this applies to } diff --git a/common/listener.cpp b/common/listener.cpp index 983e438..ec2bedb 100644 --- a/common/listener.cpp +++ b/common/listener.cpp @@ -420,6 +420,8 @@ void Listener::notify(const Sink::Notification ¬ification) builder.add_identifier(idString); builder.add_message(messageString); builder.add_entities(entities); + builder.add_progress(notification.progress); + builder.add_total(notification.total); auto command = builder.Finish(); Sink::Commands::FinishNotificationBuffer(m_fbb, command); for (Client &client : m_connections) { diff --git a/common/notification.h b/common/notification.h index f5379fd..30e240c 100644 --- a/common/notification.h +++ b/common/notification.h @@ -56,6 +56,8 @@ public: QString message; //A return code. Zero typically indicates success. int code = 0; + int progress = 0; + int total = 0; QByteArray resource; }; } diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp index ad8cae9..cf8b2e0 100644 --- a/common/resourceaccess.cpp +++ b/common/resourceaccess.cpp @@ -547,6 +547,8 @@ static Sink::Notification getNotification(const Sink::Commands::Notification *bu } n.type = buffer->type(); n.code = buffer->code(); + n.progress = buffer->progress(); + n.total = buffer->total(); n.entities = BufferUtils::fromVector(*buffer->entities()); return n; } diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp index 3e7bd30..58e5e7a 100644 --- a/common/synchronizer.cpp +++ b/common/synchronizer.cpp @@ -304,9 +304,21 @@ void Synchronizer::emitNotification(Notification::NoticationType type, int code, emit notify(n); } +void Synchronizer::emitProgressNotification(Notification::NoticationType type, int progress, int total, const QByteArray &id, const QByteArrayList &entities) +{ + Sink::Notification n; + n.id = id; + n.type = type; + n.progress = progress; + n.total = total; + n.entities = entities; + emit notify(n); +} + void Synchronizer::reportProgress(int progress, int total) { SinkLogCtx(mLogCtx) << "Progress: " << progress << " out of " << total; + emitProgressNotification(Notification::Progress, progress, total, mCurrentRequest.requestId, mCurrentRequest.applicableEntities); } void Synchronizer::setStatusFromResult(const KAsync::Error &error, const QString &s, const QByteArray &requestId) @@ -465,13 +477,15 @@ KAsync::Job Synchronizer::processSyncQueue() if (request.requestType == Synchronizer::SyncRequest::Synchronization) { setBusy(true, "Synchronization has started.", request.requestId); } else if (request.requestType == Synchronizer::SyncRequest::ChangeReplay) { - setBusy(true, "ChangeReplay has started.", "changereplay"); + setBusy(true, "ChangeReplay has started.", request.requestId); } + mCurrentRequest = request; }) .then(processRequest(request)) .then([this, request](const KAsync::Error &error) { SinkTraceCtx(mLogCtx) << "Sync request processed"; setBusy(false, {}, request.requestId); + mCurrentRequest = {}; mEntityStore->abortTransaction(); mSyncTransaction.abort(); mMessageQueue->commit(); @@ -516,7 +530,7 @@ void Synchronizer::revisionChanged() return; } } - mSyncRequestQueue << Synchronizer::SyncRequest{Synchronizer::SyncRequest::ChangeReplay}; + mSyncRequestQueue << Synchronizer::SyncRequest{Synchronizer::SyncRequest::ChangeReplay, "changereplay"}; processSyncQueue().exec(); } diff --git a/common/synchronizer.h b/common/synchronizer.h index b1ee122..bb24c2b 100644 --- a/common/synchronizer.h +++ b/common/synchronizer.h @@ -131,6 +131,8 @@ protected: RequestFlush }; + SyncRequest() = default; + SyncRequest(const Sink::QueryBase &q, const QByteArray &requestId_ = QByteArray(), RequestOptions o = NoOptions) : requestId(requestId_), requestType(Synchronization), @@ -145,6 +147,12 @@ protected: { } + SyncRequest(RequestType type, const QByteArray &requestId_) + : requestId(requestId_), + requestType(type) + { + } + SyncRequest(RequestType type, int flushType_, const QByteArray &requestId_) : flushType(flushType_), requestId(requestId_), @@ -184,6 +192,7 @@ protected: virtual void mergeIntoQueue(const Synchronizer::SyncRequest &request, QList &queue); void emitNotification(Notification::NoticationType type, int code, const QString &message, const QByteArray &id = QByteArray{}, const QByteArrayList &entiteis = QByteArrayList{}); + void emitProgressNotification(Notification::NoticationType type, int progress, int total, const QByteArray &id, const QByteArrayList &entities); /** * Report progress for current task @@ -211,6 +220,7 @@ private: Sink::Storage::DataStore::Transaction mSyncTransaction; std::function mEnqueue; QList mSyncRequestQueue; + SyncRequest mCurrentRequest; MessageQueue *mMessageQueue; bool mSyncInProgress; QMultiHash mPendingSyncRequests; -- cgit v1.2.3