Akonadi

tracer.h
1/***************************************************************************
2 * SPDX-FileCopyrightText: 2006 Tobias Koenig <tokoe@kde.org> *
3 * *
4 * SPDX-License-Identifier: LGPL-2.0-or-later *
5 ***************************************************************************/
6
7#pragma once
8
9#include <QJsonDocument>
10#include <QJsonObject>
11#include <QMutex>
12#include <QObject>
13
14#include "private/protocol_p.h"
15#include "tracerinterface.h"
16
17#include <memory>
18
19class QSettings;
20
21namespace Akonadi
22{
23namespace Protocol
24{
25class Command;
26using CommandPtr = QSharedPointer<Command>;
27}
28
29namespace Server
30{
31/**
32 * The global tracer instance where all akonadi components can
33 * send their tracing information to.
34 *
35 * The tracer will forward these information to the configured backends.
36 */
37class Tracer : public QObject, public TracerInterface
38{
40
41public:
42 explicit Tracer();
43
44 /**
45 * Destroys the global tracer instance.
46 */
47 ~Tracer() override;
48
49 template<typename T>
50 typename std::enable_if<std::is_base_of<Protocol::Command, T>::value>::type connectionOutput(const QString &identifier, qint64 tag, const T &cmd)
51 {
52 QByteArray msg;
53 if (mTracerBackend->connectionFormat() == TracerInterface::Json) {
54 QJsonObject json;
55 json[QStringLiteral("tag")] = tag;
56 cmd.toJson(json);
57 QJsonDocument doc(json);
58
59 msg = doc.toJson(QJsonDocument::Indented);
60 } else {
61 msg = QByteArray::number(tag) + ' ' + Protocol::debugString(cmd).toUtf8();
62 }
63 connectionOutput(identifier, msg);
64 }
65
66 /**
67 * Returns the currently activated tracer type.
68 */
69 QString currentTracer() const;
70
71public Q_SLOTS:
72 /**
73 * This method is called whenever a new data (imap) connection to the akonadi server
74 * is established.
75 *
76 * @param identifier The unique identifier for this connection. All input and output
77 * messages for this connection will have the same identifier.
78 *
79 * @param msg A message specific string.
80 */
81 void beginConnection(const QString &identifier, const QString &msg) override;
82
83 /**
84 * This method is called whenever a data (imap) connection to akonadi server is
85 * closed.
86 *
87 * @param identifier The unique identifier of this connection.
88 * @param msg A message specific string.
89 */
90 void endConnection(const QString &identifier, const QString &msg) override;
91
92 /**
93 * This method is called whenever the akonadi server retrieves some data from the
94 * outside.
95 *
96 * @param identifier The unique identifier of the connection on which the data
97 * is retrieved.
98 * @param msg A message specific string.
99 */
100 void connectionInput(const QString &identifier, const QByteArray &msg) override;
101
102 void connectionInput(const QString &identifier, qint64 tag, const Protocol::CommandPtr &cmd);
103
104 /**
105 * This method is called whenever the akonadi server sends some data out to a client.
106 *
107 * @param identifier The unique identifier of the connection on which the
108 * data is send.
109 * @param msg A message specific string.
110 */
111 void connectionOutput(const QString &identifier, const QByteArray &msg) override;
112
113 void connectionOutput(const QString &identifier, qint64 tag, const Protocol::CommandPtr &cmd);
114
115 /**
116 * This method is called whenever a dbus signal is emitted on the bus.
117 *
118 * @param signalName The name of the signal being sent.
119 * @param msg A message specific string.
120 */
121 void signal(const QString &signalName, const QString &msg) override;
122
123 /**
124 Convenience method with internal toLatin1 cast to compile with QT_NO_CAST_FROM_ASCII.
125 */
126 void signal(const char *signalName, const QString &msg);
127
128 /**
129 * This method is called whenever a component wants to output a warning.
130 */
131 void warning(const QString &componentName, const QString &msg) override;
132
133 /**
134 * This method is called whenever a component wants to output an error.
135 */
136 void error(const QString &componentName, const QString &msg) override;
137
138 /**
139 * Convenience method for QT_NO_CAST_FROM_ASCII usage.
140 */
141 void error(const char *componentName, const QString &msg);
142
143 /**
144 * Activates the given tracer type.
145 */
146 void activateTracer(const QString &type);
147
148private:
149 mutable QMutex mMutex;
150 std::unique_ptr<TracerInterface> mTracerBackend;
151 std::unique_ptr<QSettings> mSettings;
152};
153
154} // namespace Server
155} // namespace Akonadi
This interface can be reimplemented to deliver tracing information of the akonadi server to the outsi...
The global tracer instance where all akonadi components can send their tracing information to.
Definition tracer.h:38
void activateTracer(const QString &type)
Activates the given tracer type.
Definition tracer.cpp:144
void connectionInput(const QString &identifier, const QByteArray &msg) override
This method is called whenever the akonadi server retrieves some data from the outside.
Definition tracer.cpp:53
void signal(const QString &signalName, const QString &msg) override
This method is called whenever a dbus signal is emitted on the bus.
Definition tracer.cpp:104
void beginConnection(const QString &identifier, const QString &msg) override
This method is called whenever a new data (imap) connection to the akonadi server is established.
Definition tracer.cpp:37
void endConnection(const QString &identifier, const QString &msg) override
This method is called whenever a data (imap) connection to akonadi server is closed.
Definition tracer.cpp:45
void warning(const QString &componentName, const QString &msg) override
This method is called whenever a component wants to output a warning.
Definition tracer.cpp:117
void error(const QString &componentName, const QString &msg) override
This method is called whenever a component wants to output an error.
Definition tracer.cpp:125
QString currentTracer() const
Returns the currently activated tracer type.
Definition tracer.cpp:138
~Tracer() override
Destroys the global tracer instance.
Helper integration between Akonadi and Qt.
QByteArray number(double n, char format, int precision)
Q_OBJECTQ_OBJECT
Q_SLOTSQ_SLOTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.