summaryrefslogtreecommitdiffstats
path: root/common/listener.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-11-28 23:04:59 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-11-28 23:04:59 +0100
commit3e7b8fe8b8cca75b546c8cac2c09ce231861f21b (patch)
tree36cf1849ff30a986de56d931d60ce1c88660ec83 /common/listener.cpp
parent7fdcc36a1a352bb869020ade8a8aa697c3e8b80c (diff)
downloadsink-3e7b8fe8b8cca75b546c8cac2c09ce231861f21b.tar.gz
sink-3e7b8fe8b8cca75b546c8cac2c09ce231861f21b.zip
Used the CommandProcessor as central place for all command processing.
Diffstat (limited to 'common/listener.cpp')
-rw-r--r--common/listener.cpp40
1 files changed, 3 insertions, 37 deletions
diff --git a/common/listener.cpp b/common/listener.cpp
index 9e80c45..d3ef0f1 100644
--- a/common/listener.cpp
+++ b/common/listener.cpp
@@ -30,15 +30,12 @@
30#include "common/commandcompletion_generated.h" 30#include "common/commandcompletion_generated.h"
31#include "common/handshake_generated.h" 31#include "common/handshake_generated.h"
32#include "common/revisionupdate_generated.h" 32#include "common/revisionupdate_generated.h"
33#include "common/synchronize_generated.h"
34#include "common/notification_generated.h" 33#include "common/notification_generated.h"
35#include "common/revisionreplayed_generated.h" 34#include "common/revisionreplayed_generated.h"
36 35
37#include <QLocalServer> 36#include <QLocalServer>
38#include <QLocalSocket> 37#include <QLocalSocket>
39#include <QTimer> 38#include <QTimer>
40#include <QTime>
41#include <QDataStream>
42 39
43Listener::Listener(const QByteArray &resourceInstanceIdentifier, const QByteArray &resourceType, QObject *parent) 40Listener::Listener(const QByteArray &resourceInstanceIdentifier, const QByteArray &resourceType, QObject *parent)
44 : QObject(parent), 41 : QObject(parent),
@@ -235,39 +232,7 @@ void Listener::processCommand(int commandId, uint messageId, const QByteArray &c
235 } 232 }
236 break; 233 break;
237 } 234 }
238 case Sink::Commands::SynchronizeCommand: { 235 case Sink::Commands::SynchronizeCommand:
239 flatbuffers::Verifier verifier((const uint8_t *)commandBuffer.constData(), commandBuffer.size());
240 if (Sink::Commands::VerifySynchronizeBuffer(verifier)) {
241 auto buffer = Sink::Commands::GetSynchronize(commandBuffer.constData());
242 SinkTrace() << QString("Synchronize request (id %1) from %2").arg(messageId).arg(client.name);
243 auto timer = QSharedPointer<QTime>::create();
244 timer->start();
245 auto job = KAsync::null<void>();
246 Sink::QueryBase query;
247 if (buffer->query()) {
248 auto data = QByteArray::fromStdString(buffer->query()->str());
249 QDataStream stream(&data, QIODevice::ReadOnly);
250 stream >> query;
251 }
252 job = loadResource().synchronizeWithSource(query);
253 job.then<void>([callback, timer](const KAsync::Error &error) {
254 if (error) {
255 SinkWarning() << "Sync failed: " << error.errorMessage;
256 callback(false);
257 return KAsync::error(error);
258 } else {
259 SinkTrace() << "Sync took " << Sink::Log::TraceTime(timer->elapsed());
260 callback(true);
261 return KAsync::null();
262 }
263 })
264 .exec();
265 return;
266 } else {
267 SinkWarning() << "received invalid command";
268 }
269 break;
270 }
271 case Sink::Commands::InspectionCommand: 236 case Sink::Commands::InspectionCommand:
272 case Sink::Commands::DeleteEntityCommand: 237 case Sink::Commands::DeleteEntityCommand:
273 case Sink::Commands::ModifyEntityCommand: 238 case Sink::Commands::ModifyEntityCommand:
@@ -293,7 +258,8 @@ void Listener::processCommand(int commandId, uint messageId, const QByteArray &c
293 SinkWarning() << "received invalid command"; 258 SinkWarning() << "received invalid command";
294 } 259 }
295 loadResource().setLowerBoundRevision(lowerBoundRevision()); 260 loadResource().setLowerBoundRevision(lowerBoundRevision());
296 } break; 261 }
262 break;
297 case Sink::Commands::RemoveFromDiskCommand: { 263 case Sink::Commands::RemoveFromDiskCommand: {
298 SinkLog() << QString("Received a remove from disk command from %1").arg(client.name); 264 SinkLog() << QString("Received a remove from disk command from %1").arg(client.name);
299 //Close the resource to ensure no transactions are open 265 //Close the resource to ensure no transactions are open