summaryrefslogtreecommitdiffstats
path: root/common/listener.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/listener.cpp')
-rw-r--r--common/listener.cpp34
1 files changed, 32 insertions, 2 deletions
diff --git a/common/listener.cpp b/common/listener.cpp
index 9773835..16da770 100644
--- a/common/listener.cpp
+++ b/common/listener.cpp
@@ -30,6 +30,7 @@
30#include "common/revisionupdate_generated.h" 30#include "common/revisionupdate_generated.h"
31#include "common/synchronize_generated.h" 31#include "common/synchronize_generated.h"
32#include "common/notification_generated.h" 32#include "common/notification_generated.h"
33#include "common/revisionreplayed_generated.h"
33 34
34#include <QLocalServer> 35#include <QLocalServer>
35#include <QLocalSocket> 36#include <QLocalSocket>
@@ -250,6 +251,21 @@ void Listener::processCommand(int commandId, uint messageId, const QByteArray &c
250 case Akonadi2::Commands::PingCommand: 251 case Akonadi2::Commands::PingCommand:
251 Log() << QString("\tReceived ping command from %1").arg(client.name); 252 Log() << QString("\tReceived ping command from %1").arg(client.name);
252 break; 253 break;
254 case Akonadi2::Commands::RevisionReplayedCommand: {
255 Log() << QString("\tReceived revision replayed command from %1").arg(client.name);
256 flatbuffers::Verifier verifier((const uint8_t *)commandBuffer.constData(), commandBuffer.size());
257 if (Akonadi2::Commands::VerifyRevisionReplayedBuffer(verifier)) {
258 auto buffer = Akonadi2::Commands::GetRevisionReplayed(commandBuffer.constData());
259 client.currentRevision = buffer->revision();
260 } else {
261 Warning() << "received invalid command";
262 }
263 loadResource();
264 if (m_resource) {
265 m_resource->setLowerBoundRevision(lowerBoundRevision());
266 }
267 }
268 break;
253 default: 269 default:
254 if (commandId > Akonadi2::Commands::CustomCommand) { 270 if (commandId > Akonadi2::Commands::CustomCommand) {
255 Log() << QString("\tReceived custom command from %1: ").arg(client.name) << commandId; 271 Log() << QString("\tReceived custom command from %1: ").arg(client.name) << commandId;
@@ -258,14 +274,28 @@ void Listener::processCommand(int commandId, uint messageId, const QByteArray &c
258 m_resource->processCommand(commandId, commandBuffer); 274 m_resource->processCommand(commandId, commandBuffer);
259 } 275 }
260 } else { 276 } else {
261 Warning() << QString("\tReceived invalid command from %1: ").arg(client.name) << commandId; 277 ErrorMsg() << QString("\tReceived invalid command from %1: ").arg(client.name) << commandId;
262 //TODO: handle error: we don't know wtf this command is
263 } 278 }
264 break; 279 break;
265 } 280 }
266 callback(); 281 callback();
267} 282}
268 283
284qint64 Listener::lowerBoundRevision()
285{
286 qint64 lowerBound = 0;
287 for (const Client &c : m_connections) {
288 if (c.currentRevision > 0) {
289 if (lowerBound == 0) {
290 lowerBound = c.currentRevision;
291 } else {
292 lowerBound = qMin(c.currentRevision, lowerBound);
293 }
294 }
295 }
296 return lowerBound;
297}
298
269void Listener::quit() 299void Listener::quit()
270{ 300{
271 //Broadcast shutdown notifications to open clients, so they don't try to restart the resource 301 //Broadcast shutdown notifications to open clients, so they don't try to restart the resource