From a35acab8ecdadb5547c445a41ca2a67d978ed4a6 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sat, 18 Apr 2015 12:16:34 +0200 Subject: Log messages --- common/commands.cpp | 33 +++++++++++++++++++++++++++++++++ common/commands.h | 4 ++++ common/resourceaccess.cpp | 4 ++-- dummyresource/resourcefactory.cpp | 4 ++-- synchronizer/listener.cpp | 10 +++++----- 5 files changed, 46 insertions(+), 9 deletions(-) diff --git a/common/commands.cpp b/common/commands.cpp index 1dfeabe..99313b9 100644 --- a/common/commands.cpp +++ b/common/commands.cpp @@ -28,6 +28,39 @@ namespace Akonadi2 namespace Commands { +QByteArray name(int commandId) +{ + switch(commandId) { + case UnknownCommand: + return "Unknown"; + case CommandCompletion: + return "Completion"; + case HandshakeCommand: + return "Handshake"; + case RevisionUpdateCommand: + return "RevisionUpdate"; + case SynchronizeCommand: + return "Synchronize"; + case FetchEntityCommand: + return "FetchEntity"; + case DeleteEntityCommand: + return "DeleteEntity"; + case ModifyEntityCommand: + return "ModifyEntity"; + case CreateEntityCommand: + return "CreateEntity"; + case SearchSourceCommand: + return "SearchSource"; + case ShutdownCommand: + return "Shutdown"; + case NotificationCommand: + return "Notification"; + case CustomCommand: + return "Custom"; + }; + return QByteArray("Invalid commandId"); +} + int headerSize() { return sizeof(int) + (sizeof(uint) * 2); diff --git a/common/commands.h b/common/commands.h index 0007ffc..1baedcc 100644 --- a/common/commands.h +++ b/common/commands.h @@ -22,6 +22,7 @@ #include #include +#include class QIODevice; @@ -47,6 +48,9 @@ enum CommandIds { CustomCommand = 0xffff }; + +QByteArray name(int commandId); + int AKONADI2COMMON_EXPORT headerSize(); void AKONADI2COMMON_EXPORT write(QIODevice *device, int messageId, int commandId); void AKONADI2COMMON_EXPORT write(QIODevice *device, int messageId, int commandId, const char *buffer, uint size); diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp index 9ecdab1..1dba571 100644 --- a/common/resourceaccess.cpp +++ b/common/resourceaccess.cpp @@ -200,7 +200,7 @@ void ResourceAccess::sendCommand(const QSharedPointer &command) //TODO: we should have a timeout for commands d->messageId++; const auto messageId = d->messageId; - log(QString("Sending command %1 with messageId %2").arg(command->commandId).arg(d->messageId)); + log(QString("Sending command \"%1\" with messageId %2").arg(QString(Akonadi2::Commands::name(command->commandId))).arg(d->messageId)); if (command->callback) { registerCallback(d->messageId, [this, messageId, command](int number, QString foo) { d->pendingCommands.remove(messageId); @@ -215,7 +215,7 @@ void ResourceAccess::sendCommand(const QSharedPointer &command) void ResourceAccess::processCommandQueue() { //TODO: serialize instead of blast them all through the socket? - log(QString("We have %1 queued commands").arg(d->commandQueue.size())); + Trace() << "We have " << d->commandQueue.size() << " queued commands"; for (auto command: d->commandQueue) { sendCommand(command); } diff --git a/dummyresource/resourcefactory.cpp b/dummyresource/resourcefactory.cpp index 8f0a2bd..679bba2 100644 --- a/dummyresource/resourcefactory.cpp +++ b/dummyresource/resourcefactory.cpp @@ -151,7 +151,7 @@ private slots: Async::Job processQueuedCommand(const Akonadi2::QueuedCommand *queuedCommand) { - Log() << "Processing command: " << queuedCommand->commandId(); + Log() << "Processing command: " << Akonadi2::Commands::name(queuedCommand->commandId()); //Throw command into appropriate pipeline switch (queuedCommand->commandId()) { case Akonadi2::Commands::DeleteEntityCommand: @@ -191,7 +191,7 @@ private slots: return; } auto queuedCommand = Akonadi2::GetQueuedCommand(ptr); - Trace() << "Dequeued: " << queuedCommand->commandId(); + Trace() << "Dequeued Command: " << Akonadi2::Commands::name(queuedCommand->commandId()); //TODO JOBAPI: job lifetime management //Right now we're just leaking jobs. In this case we'd like jobs that are heap allocated and delete //themselves once done. In other cases we'd like jobs that only live as long as their handle though. diff --git a/synchronizer/listener.cpp b/synchronizer/listener.cpp index 64e9c21..c68bd9a 100644 --- a/synchronizer/listener.cpp +++ b/synchronizer/listener.cpp @@ -48,7 +48,7 @@ Listener::Listener(const QByteArray &resourceName, QObject *parent) this, &Listener::refreshRevision); connect(m_server, &QLocalServer::newConnection, this, &Listener::acceptConnection); - Log() << "Trying to open " << m_resourceName; + Trace() << "Trying to open " << m_resourceName; if (!m_server->listen(QString::fromLatin1(resourceName))) { // FIXME: multiple starts need to be handled here m_server->removeServer(resourceName); @@ -99,7 +99,7 @@ void Listener::closeAllConnections() void Listener::acceptConnection() { - Log() << QString("Accepting connection"); + Trace() << "Accepting connection"; QLocalSocket *socket = m_server->nextPendingConnection(); if (!socket) { @@ -154,7 +154,7 @@ void Listener::readFromSocket() return; } - Log() << "Reading from socket..."; + Trace() << "Reading from socket..."; for (Client &client: m_connections) { if (client.socket == socket) { client.commandBuffer += socket->readAll(); @@ -232,7 +232,7 @@ void Listener::processCommand(int commandId, uint messageId, Client &client, uin case Akonadi2::Commands::DeleteEntityCommand: case Akonadi2::Commands::ModifyEntityCommand: case Akonadi2::Commands::CreateEntityCommand: - Log() << QString("\tCommand id %1 of type %2 from %3").arg(messageId).arg(commandId).arg(client.name); + Log() << "\tCommand id " << messageId << " of type \"" << Akonadi2::Commands::name(commandId) << "\" from " << client.name; loadResource(); if (m_resource) { m_resource->processCommand(commandId, client.commandBuffer, size, m_pipeline); @@ -293,7 +293,7 @@ bool Listener::processClientBuffer(Client &client) auto socket = QPointer(client.socket); auto clientName = client.name; processCommand(commandId, messageId, client, size, [this, messageId, commandId, socket, clientName]() { - Log() << QString("\tCompleted command messageid %1 of type %2 from %3").arg(messageId).arg(commandId).arg(clientName); + 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); } else { -- cgit v1.2.3