diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-01-18 15:10:30 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-01-18 15:10:30 +0100 |
commit | 0d55900241772fa5cc5028934358cbcb28702c46 (patch) | |
tree | 1d64340a5fb81b9ee0b3884a3d77571b640dbe3a /common/listener.cpp | |
parent | 97fa1912a004c144ffb1392a6bfd0469e6047e3f (diff) | |
download | sink-0d55900241772fa5cc5028934358cbcb28702c46.tar.gz sink-0d55900241772fa5cc5028934358cbcb28702c46.zip |
Report success
Diffstat (limited to 'common/listener.cpp')
-rw-r--r-- | common/listener.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
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() | |||
203 | } | 203 | } |
204 | } | 204 | } |
205 | 205 | ||
206 | void Listener::processCommand(int commandId, uint messageId, const QByteArray &commandBuffer, Client &client, const std::function<void()> &callback) | 206 | void Listener::processCommand(int commandId, uint messageId, const QByteArray &commandBuffer, Client &client, const std::function<void(bool)> &callback) |
207 | { | 207 | { |
208 | bool success = true; | ||
208 | switch (commandId) { | 209 | switch (commandId) { |
209 | case Akonadi2::Commands::HandshakeCommand: { | 210 | case Akonadi2::Commands::HandshakeCommand: { |
210 | flatbuffers::Verifier verifier((const uint8_t *)commandBuffer.constData(), commandBuffer.size()); | 211 | flatbuffers::Verifier verifier((const uint8_t *)commandBuffer.constData(), commandBuffer.size()); |
@@ -232,7 +233,7 @@ void Listener::processCommand(int commandId, uint messageId, const QByteArray &c | |||
232 | } | 233 | } |
233 | job.then<void>([callback, timer]() { | 234 | job.then<void>([callback, timer]() { |
234 | Trace() << "Sync took " << timer->elapsed(); | 235 | Trace() << "Sync took " << timer->elapsed(); |
235 | callback(); | 236 | callback(true); |
236 | }).exec(); | 237 | }).exec(); |
237 | return; | 238 | return; |
238 | } else { | 239 | } else { |
@@ -273,11 +274,12 @@ void Listener::processCommand(int commandId, uint messageId, const QByteArray &c | |||
273 | Log() << QString("\tReceived custom command from %1: ").arg(client.name) << commandId; | 274 | Log() << QString("\tReceived custom command from %1: ").arg(client.name) << commandId; |
274 | loadResource()->processCommand(commandId, commandBuffer); | 275 | loadResource()->processCommand(commandId, commandBuffer); |
275 | } else { | 276 | } else { |
277 | success = false; | ||
276 | ErrorMsg() << QString("\tReceived invalid command from %1: ").arg(client.name) << commandId; | 278 | ErrorMsg() << QString("\tReceived invalid command from %1: ").arg(client.name) << commandId; |
277 | } | 279 | } |
278 | break; | 280 | break; |
279 | } | 281 | } |
280 | callback(); | 282 | callback(success); |
281 | } | 283 | } |
282 | 284 | ||
283 | qint64 Listener::lowerBoundRevision() | 285 | qint64 Listener::lowerBoundRevision() |
@@ -333,10 +335,10 @@ bool Listener::processClientBuffer(Client &client) | |||
333 | auto clientName = client.name; | 335 | auto clientName = client.name; |
334 | const QByteArray commandBuffer = client.commandBuffer.left(size); | 336 | const QByteArray commandBuffer = client.commandBuffer.left(size); |
335 | client.commandBuffer.remove(0, size); | 337 | client.commandBuffer.remove(0, size); |
336 | processCommand(commandId, messageId, commandBuffer, client, [this, messageId, commandId, socket, clientName]() { | 338 | processCommand(commandId, messageId, commandBuffer, client, [this, messageId, commandId, socket, clientName](bool success) { |
337 | Log() << QString("\tCompleted command messageid %1 of type \"%2\" from %3").arg(messageId).arg(QString(Akonadi2::Commands::name(commandId))).arg(clientName); | 339 | Log() << QString("\tCompleted command messageid %1 of type \"%2\" from %3").arg(messageId).arg(QString(Akonadi2::Commands::name(commandId))).arg(clientName); |
338 | if (socket) { | 340 | if (socket) { |
339 | sendCommandCompleted(socket.data(), messageId); | 341 | sendCommandCompleted(socket.data(), messageId, success); |
340 | } else { | 342 | } else { |
341 | Log() << QString("Socket became invalid before we could send a response. client: %1").arg(clientName); | 343 | Log() << QString("Socket became invalid before we could send a response. client: %1").arg(clientName); |
342 | } | 344 | } |
@@ -348,13 +350,13 @@ bool Listener::processClientBuffer(Client &client) | |||
348 | return false; | 350 | return false; |
349 | } | 351 | } |
350 | 352 | ||
351 | void Listener::sendCommandCompleted(QLocalSocket *socket, uint messageId) | 353 | void Listener::sendCommandCompleted(QLocalSocket *socket, uint messageId, bool success) |
352 | { | 354 | { |
353 | if (!socket || !socket->isValid()) { | 355 | if (!socket || !socket->isValid()) { |
354 | return; | 356 | return; |
355 | } | 357 | } |
356 | 358 | ||
357 | auto command = Akonadi2::CreateCommandCompletion(m_fbb, messageId); | 359 | auto command = Akonadi2::CreateCommandCompletion(m_fbb, messageId, success); |
358 | Akonadi2::FinishCommandCompletionBuffer(m_fbb, command); | 360 | Akonadi2::FinishCommandCompletionBuffer(m_fbb, command); |
359 | Akonadi2::Commands::write(socket, ++m_messageId, Akonadi2::Commands::CommandCompletion, m_fbb); | 361 | Akonadi2::Commands::write(socket, ++m_messageId, Akonadi2::Commands::CommandCompletion, m_fbb); |
360 | m_fbb.Clear(); | 362 | m_fbb.Clear(); |