Debian Codegraph @

src/serviceframework/qservicedebuglog_p.h

raw symbols SCIP
1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 The Qt Company Ltd and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtSystems module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 #ifndef QSERVICEDEBUGLOG_P_H
40 #define QSERVICEDEBUGLOG_P_H
41
42 //
43 // W A R N I N G
44 // -------------
45 //
46 // This file is not part of the Qt API. It exists purely as an
47 // implementation detail. This header file may change from version to
48 // version without notice, or even be removed.
49 //
50 // We mean it.
51 //
52
53 #include <QString>
54 #include <QStringList>
55 #include <QBuffer>
56 #include <QDataStream>
57 #include <QSharedPointer>
58 #include <QMutex>
59 #include <QVector>
60
61 QT_BEGIN_NAMESPACE
62
63 class QServiceDebugMessage
64 {
65 public:
66 enum DataType {
67 Int32Type = 1,
68 FloatType = 2,
69 StringType = 3
70 };
71
72 QServiceDebugMessage();
73 ~QServiceDebugMessage();
74
75 #ifdef QT_SFW_IPC_DEBUG
76 QBuffer *buffer;
77 QDataStream ds;
78 #endif
79 };
80
81 class QServiceDebugValue;
82 class QServiceDebugKey;
83 class QUdpSocket;
84
85 class QServiceDebugLog
86 {
87 public:
88 QServiceDebugLog();
89
90 static QServiceDebugLog* instance();
91
92 QServiceDebugValue operator<<(const char *key);
93 void logMessage(QServiceDebugMessage *msg);
94
95 private:
96 QList<QBuffer *> queue;
97 QVector<QUdpSocket *> sockets;
98 void makeSockets();
99 QMutex socketLock;
100 };
101
102 inline QServiceDebugLog &qServiceLog()
103 {
104 return (*QServiceDebugLog::instance());
105 }
106
107 class QServiceDebugKey
108 {
109 public:
110 #ifdef QT_SFW_IPC_DEBUG
111 inline QServiceDebugKey(const QSharedPointer<QServiceDebugMessage> &ptr)
112 : ptr(ptr) {}
113
114 #else
115 inline QServiceDebugKey() {}
116 #endif
117 QServiceDebugValue operator<<(const char *key);
118 private:
119 #ifdef QT_SFW_IPC_DEBUG
120 QSharedPointer<QServiceDebugMessage> ptr;
121 #endif
122 };
123
124 class QServiceDebugValue
125 {
126 public:
127 #ifdef QT_SFW_IPC_DEBUG
128 inline QServiceDebugValue(const QSharedPointer<QServiceDebugMessage> &ptr)
129 : ptr(ptr) {}
130 #else
131 inline QServiceDebugValue() {}
132 #endif
133 QServiceDebugKey operator<<(const qint32 &val);
134 QServiceDebugKey operator<<(const float &val);
135 QServiceDebugKey operator<<(const QString &val);
136 QServiceDebugKey operator<<(const char *val);
137 private:
138 #ifdef QT_SFW_IPC_DEBUG
139 QSharedPointer<QServiceDebugMessage> ptr;
140 #endif
141 };
142
143 inline QServiceDebugValue QServiceDebugKey::operator<<(const char *key)
144 {
145 #ifdef QT_SFW_IPC_DEBUG
146 ptr->ds.writeBytes(key, ::strlen(key));
147 return QServiceDebugValue(ptr);
148 #else
149 Q_UNUSED(key)
150 return QServiceDebugValue();
151 #endif
152 }
153
154 inline QServiceDebugKey QServiceDebugValue::operator<<(const qint32 &val)
155 {
156 #ifdef QT_SFW_IPC_DEBUG
157 ptr->ds << (qint8)QServiceDebugMessage::Int32Type;
158 ptr->ds << val;
159 return QServiceDebugKey(ptr);
160 #else
161 Q_UNUSED(val)
162 return QServiceDebugKey();
163 #endif
164 }
165
166 inline QServiceDebugKey QServiceDebugValue::operator<<(const float &val)
167 {
168 #ifdef QT_SFW_IPC_DEBUG
169 ptr->ds << (qint8)QServiceDebugMessage::FloatType;
170 ptr->ds << val;
171 return QServiceDebugKey(ptr);
172 #else
173 Q_UNUSED(val)
174 return QServiceDebugKey();
175 #endif
176 }
177
178 inline QServiceDebugKey QServiceDebugValue::operator<<(const QString &val)
179 {
180 #ifdef QT_SFW_IPC_DEBUG
181 ptr->ds << (qint8)QServiceDebugMessage::StringType;
182 QByteArray ba = val.toLatin1();
183 ptr->ds.writeBytes(ba.constData(), ba.size());
184 return QServiceDebugKey(ptr);
185 #else
186 Q_UNUSED(val)
187 return QServiceDebugKey();
188 #endif
189 }
190
191 inline QServiceDebugKey QServiceDebugValue::operator<<(const char *val)
192 {
193 #ifdef QT_SFW_IPC_DEBUG
194 ptr->ds << (qint8)QServiceDebugMessage::StringType;
195 ptr->ds.writeBytes(val, ::strlen(val));
196 return QServiceDebugKey(ptr);
197 #else
198 Q_UNUSED(val)
199 return QServiceDebugKey();
200 #endif
201 }
202
203 inline QServiceDebugValue QServiceDebugLog::operator<<(const char *key)
204 {
205 #ifdef QT_SFW_IPC_DEBUG
206 QSharedPointer<QServiceDebugMessage> msg(new QServiceDebugMessage());
207 return (QServiceDebugKey(msg) << key);
208 #else
209 Q_UNUSED(key)
210 return QServiceDebugValue();
211 #endif
212 }
213
214 QT_END_NAMESPACE
215
216 #endif // QSERVICEDEBUGLOG_P_H