From 0d55900241772fa5cc5028934358cbcb28702c46 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 18 Jan 2016 15:10:30 +0100 Subject: Report success --- common/listener.cpp | 16 +++++++++------- common/listener.h | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'common') diff --git a/common/listener.cpp b/common/listener.cpp index 1b78f01..518aca9 100644 --- a/common/listener.cpp +++ b/common/listener.cpp @@ -203,8 +203,9 @@ void Listener::processClientBuffers() } } -void Listener::processCommand(int commandId, uint messageId, const QByteArray &commandBuffer, Client &client, const std::function &callback) +void Listener::processCommand(int commandId, uint messageId, const QByteArray &commandBuffer, Client &client, const std::function &callback) { + bool success = true; switch (commandId) { case Akonadi2::Commands::HandshakeCommand: { flatbuffers::Verifier verifier((const uint8_t *)commandBuffer.constData(), commandBuffer.size()); @@ -232,7 +233,7 @@ void Listener::processCommand(int commandId, uint messageId, const QByteArray &c } job.then([callback, timer]() { Trace() << "Sync took " << timer->elapsed(); - callback(); + callback(true); }).exec(); return; } else { @@ -273,11 +274,12 @@ void Listener::processCommand(int commandId, uint messageId, const QByteArray &c Log() << QString("\tReceived custom command from %1: ").arg(client.name) << commandId; loadResource()->processCommand(commandId, commandBuffer); } else { + success = false; ErrorMsg() << QString("\tReceived invalid command from %1: ").arg(client.name) << commandId; } break; } - callback(); + callback(success); } qint64 Listener::lowerBoundRevision() @@ -333,10 +335,10 @@ bool Listener::processClientBuffer(Client &client) auto clientName = client.name; const QByteArray commandBuffer = client.commandBuffer.left(size); client.commandBuffer.remove(0, size); - processCommand(commandId, messageId, commandBuffer, client, [this, messageId, commandId, socket, clientName]() { + processCommand(commandId, messageId, commandBuffer, client, [this, messageId, commandId, socket, clientName](bool success) { Log() << QString("\tCompleted command messageid %1 of type \"%2\" from %3").arg(messageId).arg(QString(Akonadi2::Commands::name(commandId))).arg(clientName); if (socket) { - sendCommandCompleted(socket.data(), messageId); + sendCommandCompleted(socket.data(), messageId, success); } else { Log() << QString("Socket became invalid before we could send a response. client: %1").arg(clientName); } @@ -348,13 +350,13 @@ bool Listener::processClientBuffer(Client &client) return false; } -void Listener::sendCommandCompleted(QLocalSocket *socket, uint messageId) +void Listener::sendCommandCompleted(QLocalSocket *socket, uint messageId, bool success) { if (!socket || !socket->isValid()) { return; } - auto command = Akonadi2::CreateCommandCompletion(m_fbb, messageId); + auto command = Akonadi2::CreateCommandCompletion(m_fbb, messageId, success); Akonadi2::FinishCommandCompletionBuffer(m_fbb, command); Akonadi2::Commands::write(socket, ++m_messageId, Akonadi2::Commands::CommandCompletion, m_fbb); m_fbb.Clear(); diff --git a/common/listener.h b/common/listener.h index 248a190..3db1937 100644 --- a/common/listener.h +++ b/common/listener.h @@ -79,9 +79,9 @@ private Q_SLOTS: void quit(); private: - void processCommand(int commandId, uint messageId, const QByteArray &commandBuffer, Client &client, const std::function &callback); + void processCommand(int commandId, uint messageId, const QByteArray &commandBuffer, Client &client, const std::function &callback); bool processClientBuffer(Client &client); - void sendCommandCompleted(QLocalSocket *socket, uint messageId); + void sendCommandCompleted(QLocalSocket *socket, uint messageId, bool success); void updateClientsWithRevision(qint64); Akonadi2::Resource *loadResource(); void readFromSocket(QLocalSocket *socket); -- cgit v1.2.3