| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
#ifndef QSERVICEDEBUGLOG_P_H |
| 40 |
#define QSERVICEDEBUGLOG_P_H |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 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 |