summaryrefslogtreecommitdiffstats
path: root/common/commandprocessor.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-11-29 11:27:04 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-11-29 11:27:04 +0100
commit6a072b2dcf23cbcdb210f2bd5c273ea0f425b188 (patch)
treecc2789c59e04018743aa0d575ee51a6f10869ffc /common/commandprocessor.cpp
parent81b459c0f013704e95fb5933525c82a6ca46f13f (diff)
downloadsink-6a072b2dcf23cbcdb210f2bd5c273ea0f425b188.tar.gz
sink-6a072b2dcf23cbcdb210f2bd5c273ea0f425b188.zip
The synchronization call can be sync.
... because we really just enqueue the request and then wait for the notification.
Diffstat (limited to 'common/commandprocessor.cpp')
-rw-r--r--common/commandprocessor.cpp48
1 files changed, 5 insertions, 43 deletions
diff --git a/common/commandprocessor.cpp b/common/commandprocessor.cpp
index fccff22..8eb0ef1 100644
--- a/common/commandprocessor.cpp
+++ b/common/commandprocessor.cpp
@@ -128,17 +128,7 @@ void CommandProcessor::processSynchronizeCommand(const QByteArray &data)
128 QDataStream stream(&data, QIODevice::ReadOnly); 128 QDataStream stream(&data, QIODevice::ReadOnly);
129 stream >> query; 129 stream >> query;
130 } 130 }
131 synchronizeWithSource(query) 131 mSynchronizer->synchronize(query);
132 .then<void>([timer](const KAsync::Error &error) {
133 if (error) {
134 SinkWarning() << "Sync failed: " << error.errorMessage;
135 return KAsync::error(error);
136 } else {
137 SinkTrace() << "Sync took " << Sink::Log::TraceTime(timer->elapsed());
138 return KAsync::null();
139 }
140 })
141 .exec();
142 } else { 132 } else {
143 SinkWarning() << "received invalid command"; 133 SinkWarning() << "received invalid command";
144 } 134 }
@@ -156,34 +146,6 @@ void CommandProcessor::processSynchronizeCommand(const QByteArray &data)
156// loadResource().setLowerBoundRevision(lowerBoundRevision()); 146// loadResource().setLowerBoundRevision(lowerBoundRevision());
157// } 147// }
158 148
159KAsync::Job<void> CommandProcessor::synchronizeWithSource(const Sink::QueryBase &query)
160{
161 return KAsync::start<void>([this, query] {
162 Sink::Notification n;
163 n.id = "sync";
164 n.type = Sink::Notification::Status;
165 n.message = "Synchronization has started.";
166 n.code = Sink::ApplicationDomain::BusyStatus;
167 emit notify(n);
168
169 SinkLog() << " Synchronizing";
170 return mSynchronizer->synchronize(query)
171 .then<void>([this](const KAsync::Error &error) {
172 if (!error) {
173 SinkLog() << "Done Synchronizing";
174 Sink::Notification n;
175 n.id = "sync";
176 n.type = Sink::Notification::Status;
177 n.message = "Synchronization has ended.";
178 n.code = Sink::ApplicationDomain::ConnectedStatus;
179 emit notify(n);
180 return KAsync::null();
181 }
182 return KAsync::error(error);
183 });
184 });
185}
186
187void CommandProcessor::setOldestUsedRevision(qint64 revision) 149void CommandProcessor::setOldestUsedRevision(qint64 revision)
188{ 150{
189 mLowerBoundRevision = revision; 151 mLowerBoundRevision = revision;
@@ -337,17 +299,17 @@ void CommandProcessor::setSynchronizer(const QSharedPointer<Synchronizer> &synch
337 QObject::connect(mSynchronizer.data(), &Synchronizer::replayingChanges, [this]() { 299 QObject::connect(mSynchronizer.data(), &Synchronizer::replayingChanges, [this]() {
338 Sink::Notification n; 300 Sink::Notification n;
339 n.id = "changereplay"; 301 n.id = "changereplay";
340 n.type = Sink::Notification::Status; 302 n.type = Notification::Status;
341 n.message = "Replaying changes."; 303 n.message = "Replaying changes.";
342 n.code = Sink::ApplicationDomain::BusyStatus; 304 n.code = ApplicationDomain::BusyStatus;
343 emit notify(n); 305 emit notify(n);
344 }); 306 });
345 QObject::connect(mSynchronizer.data(), &Synchronizer::changesReplayed, [this]() { 307 QObject::connect(mSynchronizer.data(), &Synchronizer::changesReplayed, [this]() {
346 Sink::Notification n; 308 Sink::Notification n;
347 n.id = "changereplay"; 309 n.id = "changereplay";
348 n.type = Sink::Notification::Status; 310 n.type = Notification::Status;
349 n.message = "All changes have been replayed."; 311 n.message = "All changes have been replayed.";
350 n.code = Sink::ApplicationDomain::ConnectedStatus; 312 n.code = ApplicationDomain::ConnectedStatus;
351 emit notify(n); 313 emit notify(n);
352 }); 314 });
353 315