Akonadi

tracer.h
1 /***************************************************************************
2  * Copyright (C) 2006 by Tobias Koenig <[email protected]> *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU Library General Public License as *
6  * published by the Free Software Foundation; either version 2 of the *
7  * License, or (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU Library General Public *
15  * License along with this program; if not, write to the *
16  * Free Software Foundation, Inc., *
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18  ***************************************************************************/
19 
20 #ifndef AKONADI_TRACER_H
21 #define AKONADI_TRACER_H
22 
23 #include <QObject>
24 #include <QMutex>
25 #include <QJsonObject>
26 #include <QJsonDocument>
27 
28 #include "tracerinterface.h"
29 #include <private/protocol_p.h>
30 
31 #include <memory>
32 
33 class QSettings;
34 
35 namespace Akonadi
36 {
37 
38 namespace Protocol
39 {
40 class Command;
41 using CommandPtr = QSharedPointer<Command>;
42 }
43 
44 namespace Server
45 {
46 
53 class Tracer : public QObject, public TracerInterface
54 {
55  Q_OBJECT
56 
57 public:
58  explicit Tracer();
59 
63  ~Tracer() override;
64 
65  template<typename T>
66  typename std::enable_if<std::is_base_of<Protocol::Command, T>::value>::type
67  connectionOutput(const QString &identifier, qint64 tag, const T &cmd) {
68  QByteArray msg;
69  if (mTracerBackend->connectionFormat() == TracerInterface::Json) {
70  QJsonObject json;
71  json[QStringLiteral("tag")] = tag;
72  cmd.toJson(json);
73  QJsonDocument doc(json);
74 
75  msg = doc.toJson(QJsonDocument::Indented);
76  } else {
77  msg = QByteArray::number(tag) + ' ' + Protocol::debugString(cmd).toUtf8();
78  }
79  connectionOutput(identifier, msg);
80  }
81 
82 public Q_SLOTS:
92  void beginConnection(const QString &identifier, const QString &msg) override;
93 
101  void endConnection(const QString &identifier, const QString &msg) override;
102 
111  void connectionInput(const QString &identifier, const QByteArray &msg) override;
112 
113  void connectionInput(const QString &identifier, qint64 tag, const Protocol::CommandPtr &cmd);
114 
122  void connectionOutput(const QString &identifier, const QByteArray &msg) override;
123 
124  void connectionOutput(const QString &identifier, qint64 tag, const Protocol::CommandPtr &cmd);
125 
132  void signal(const QString &signalName, const QString &msg) override;
133 
137  void signal(const char *signalName, const QString &msg);
138 
142  void warning(const QString &componentName, const QString &msg) override;
143 
147  void error(const QString &componentName, const QString &msg) override;
148 
152  void error(const char *componentName, const QString &msg);
153 
157  QString currentTracer() const;
158 
162  void activateTracer(const QString &type);
163 
164 private:
165  mutable QMutex mMutex;
166  std::unique_ptr<TracerInterface> mTracerBackend;
167  std::unique_ptr<QSettings> mSettings;
168 };
169 
170 } // namespace Server
171 } // namespace Akonadi
172 
173 #endif
QByteArray toJson() const const
The global tracer instance where all akonadi components can send their tracing information to...
Definition: tracer.h:53
QByteArray number(int n, int base)
Helper integration between Akonadi and Qt.
This interface can be reimplemented to deliver tracing information of the akonadi server to the outsi...
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed May 27 2020 22:43:41 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.