diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-05-04 11:40:24 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-05-04 11:40:24 +0200 |
commit | 6adf9a4734f15a2c0fa199897f76ded4659b83b7 (patch) | |
tree | 9f9c22c28e897f973d70dba29ae41bc92be51ce6 /common | |
parent | feef3bd5c1562a52c274fa07af51c716e5362054 (diff) | |
download | sink-6adf9a4734f15a2c0fa199897f76ded4659b83b7.tar.gz sink-6adf9a4734f15a2c0fa199897f76ded4659b83b7.zip |
Added progress notification
Diffstat (limited to 'common')
-rw-r--r-- | common/commands/notification.fbs | 2 | ||||
-rw-r--r-- | common/listener.cpp | 2 | ||||
-rw-r--r-- | common/notification.h | 2 | ||||
-rw-r--r-- | common/resourceaccess.cpp | 2 | ||||
-rw-r--r-- | common/synchronizer.cpp | 18 | ||||
-rw-r--r-- | common/synchronizer.h | 10 |
6 files changed, 34 insertions, 2 deletions
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 { | |||
5 | identifier: string; //An identifier that links back to the something related to the notification (e.g. a command id) | 5 | identifier: string; //An identifier that links back to the something related to the notification (e.g. a command id) |
6 | message: string; | 6 | message: string; |
7 | code: int = 0; //See notification.h | 7 | code: int = 0; //See notification.h |
8 | progress: int = 0; //See notification.h | ||
9 | total: int = 0; //See notification.h | ||
8 | entities: [string]; //A list of entities this applies to | 10 | entities: [string]; //A list of entities this applies to |
9 | } | 11 | } |
10 | 12 | ||
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) | |||
420 | builder.add_identifier(idString); | 420 | builder.add_identifier(idString); |
421 | builder.add_message(messageString); | 421 | builder.add_message(messageString); |
422 | builder.add_entities(entities); | 422 | builder.add_entities(entities); |
423 | builder.add_progress(notification.progress); | ||
424 | builder.add_total(notification.total); | ||
423 | auto command = builder.Finish(); | 425 | auto command = builder.Finish(); |
424 | Sink::Commands::FinishNotificationBuffer(m_fbb, command); | 426 | Sink::Commands::FinishNotificationBuffer(m_fbb, command); |
425 | for (Client &client : m_connections) { | 427 | 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: | |||
56 | QString message; | 56 | QString message; |
57 | //A return code. Zero typically indicates success. | 57 | //A return code. Zero typically indicates success. |
58 | int code = 0; | 58 | int code = 0; |
59 | int progress = 0; | ||
60 | int total = 0; | ||
59 | QByteArray resource; | 61 | QByteArray resource; |
60 | }; | 62 | }; |
61 | } | 63 | } |
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 | |||
547 | } | 547 | } |
548 | n.type = buffer->type(); | 548 | n.type = buffer->type(); |
549 | n.code = buffer->code(); | 549 | n.code = buffer->code(); |
550 | n.progress = buffer->progress(); | ||
551 | n.total = buffer->total(); | ||
550 | n.entities = BufferUtils::fromVector(*buffer->entities()); | 552 | n.entities = BufferUtils::fromVector(*buffer->entities()); |
551 | return n; | 553 | return n; |
552 | } | 554 | } |
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, | |||
304 | emit notify(n); | 304 | emit notify(n); |
305 | } | 305 | } |
306 | 306 | ||
307 | void Synchronizer::emitProgressNotification(Notification::NoticationType type, int progress, int total, const QByteArray &id, const QByteArrayList &entities) | ||
308 | { | ||
309 | Sink::Notification n; | ||
310 | n.id = id; | ||
311 | n.type = type; | ||
312 | n.progress = progress; | ||
313 | n.total = total; | ||
314 | n.entities = entities; | ||
315 | emit notify(n); | ||
316 | } | ||
317 | |||
307 | void Synchronizer::reportProgress(int progress, int total) | 318 | void Synchronizer::reportProgress(int progress, int total) |
308 | { | 319 | { |
309 | SinkLogCtx(mLogCtx) << "Progress: " << progress << " out of " << total; | 320 | SinkLogCtx(mLogCtx) << "Progress: " << progress << " out of " << total; |
321 | emitProgressNotification(Notification::Progress, progress, total, mCurrentRequest.requestId, mCurrentRequest.applicableEntities); | ||
310 | } | 322 | } |
311 | 323 | ||
312 | void Synchronizer::setStatusFromResult(const KAsync::Error &error, const QString &s, const QByteArray &requestId) | 324 | void Synchronizer::setStatusFromResult(const KAsync::Error &error, const QString &s, const QByteArray &requestId) |
@@ -465,13 +477,15 @@ KAsync::Job<void> Synchronizer::processSyncQueue() | |||
465 | if (request.requestType == Synchronizer::SyncRequest::Synchronization) { | 477 | if (request.requestType == Synchronizer::SyncRequest::Synchronization) { |
466 | setBusy(true, "Synchronization has started.", request.requestId); | 478 | setBusy(true, "Synchronization has started.", request.requestId); |
467 | } else if (request.requestType == Synchronizer::SyncRequest::ChangeReplay) { | 479 | } else if (request.requestType == Synchronizer::SyncRequest::ChangeReplay) { |
468 | setBusy(true, "ChangeReplay has started.", "changereplay"); | 480 | setBusy(true, "ChangeReplay has started.", request.requestId); |
469 | } | 481 | } |
482 | mCurrentRequest = request; | ||
470 | }) | 483 | }) |
471 | .then(processRequest(request)) | 484 | .then(processRequest(request)) |
472 | .then<void>([this, request](const KAsync::Error &error) { | 485 | .then<void>([this, request](const KAsync::Error &error) { |
473 | SinkTraceCtx(mLogCtx) << "Sync request processed"; | 486 | SinkTraceCtx(mLogCtx) << "Sync request processed"; |
474 | setBusy(false, {}, request.requestId); | 487 | setBusy(false, {}, request.requestId); |
488 | mCurrentRequest = {}; | ||
475 | mEntityStore->abortTransaction(); | 489 | mEntityStore->abortTransaction(); |
476 | mSyncTransaction.abort(); | 490 | mSyncTransaction.abort(); |
477 | mMessageQueue->commit(); | 491 | mMessageQueue->commit(); |
@@ -516,7 +530,7 @@ void Synchronizer::revisionChanged() | |||
516 | return; | 530 | return; |
517 | } | 531 | } |
518 | } | 532 | } |
519 | mSyncRequestQueue << Synchronizer::SyncRequest{Synchronizer::SyncRequest::ChangeReplay}; | 533 | mSyncRequestQueue << Synchronizer::SyncRequest{Synchronizer::SyncRequest::ChangeReplay, "changereplay"}; |
520 | processSyncQueue().exec(); | 534 | processSyncQueue().exec(); |
521 | } | 535 | } |
522 | 536 | ||
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: | |||
131 | RequestFlush | 131 | RequestFlush |
132 | }; | 132 | }; |
133 | 133 | ||
134 | SyncRequest() = default; | ||
135 | |||
134 | SyncRequest(const Sink::QueryBase &q, const QByteArray &requestId_ = QByteArray(), RequestOptions o = NoOptions) | 136 | SyncRequest(const Sink::QueryBase &q, const QByteArray &requestId_ = QByteArray(), RequestOptions o = NoOptions) |
135 | : requestId(requestId_), | 137 | : requestId(requestId_), |
136 | requestType(Synchronization), | 138 | requestType(Synchronization), |
@@ -145,6 +147,12 @@ protected: | |||
145 | { | 147 | { |
146 | } | 148 | } |
147 | 149 | ||
150 | SyncRequest(RequestType type, const QByteArray &requestId_) | ||
151 | : requestId(requestId_), | ||
152 | requestType(type) | ||
153 | { | ||
154 | } | ||
155 | |||
148 | SyncRequest(RequestType type, int flushType_, const QByteArray &requestId_) | 156 | SyncRequest(RequestType type, int flushType_, const QByteArray &requestId_) |
149 | : flushType(flushType_), | 157 | : flushType(flushType_), |
150 | requestId(requestId_), | 158 | requestId(requestId_), |
@@ -184,6 +192,7 @@ protected: | |||
184 | virtual void mergeIntoQueue(const Synchronizer::SyncRequest &request, QList<Synchronizer::SyncRequest> &queue); | 192 | virtual void mergeIntoQueue(const Synchronizer::SyncRequest &request, QList<Synchronizer::SyncRequest> &queue); |
185 | 193 | ||
186 | void emitNotification(Notification::NoticationType type, int code, const QString &message, const QByteArray &id = QByteArray{}, const QByteArrayList &entiteis = QByteArrayList{}); | 194 | void emitNotification(Notification::NoticationType type, int code, const QString &message, const QByteArray &id = QByteArray{}, const QByteArrayList &entiteis = QByteArrayList{}); |
195 | void emitProgressNotification(Notification::NoticationType type, int progress, int total, const QByteArray &id, const QByteArrayList &entities); | ||
187 | 196 | ||
188 | /** | 197 | /** |
189 | * Report progress for current task | 198 | * Report progress for current task |
@@ -211,6 +220,7 @@ private: | |||
211 | Sink::Storage::DataStore::Transaction mSyncTransaction; | 220 | Sink::Storage::DataStore::Transaction mSyncTransaction; |
212 | std::function<void(int commandId, const QByteArray &data)> mEnqueue; | 221 | std::function<void(int commandId, const QByteArray &data)> mEnqueue; |
213 | QList<SyncRequest> mSyncRequestQueue; | 222 | QList<SyncRequest> mSyncRequestQueue; |
223 | SyncRequest mCurrentRequest; | ||
214 | MessageQueue *mMessageQueue; | 224 | MessageQueue *mMessageQueue; |
215 | bool mSyncInProgress; | 225 | bool mSyncInProgress; |
216 | QMultiHash<QByteArray, SyncRequest> mPendingSyncRequests; | 226 | QMultiHash<QByteArray, SyncRequest> mPendingSyncRequests; |