Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qctfserver_p.h
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QT_CTFSERVER_H
5#define QT_CTFSERVER_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17//
18
19#include <qbytearray.h>
20#include <qdatastream.h>
21#include <qthread.h>
22#include <qmutex.h>
23#include <qwaitcondition.h>
24#include <qeventloop.h>
25#include <QtNetwork/qtcpserver.h>
26#include <QtNetwork/qtcpsocket.h>
27#include <qcborstreamreader.h>
28#include <qcborstreamwriter.h>
29#include <qlist.h>
30
31typedef struct ZSTD_CCtx_s ZSTD_CCtx;
32
34
35class QCtfServer;
37{
38 static constexpr quint32 PacketMagicNumber = 0x100924da;
39 static constexpr quint32 PacketSize = 4096 + 9;
43
44 TracePacket() = default;
45
47 {
48 stream_name = t.stream_name;
49 stream_data = t.stream_data;
50 flags = t.flags;
51 }
53 {
54 stream_name = t.stream_name;
55 stream_data = t.stream_data;
56 flags = t.flags;
57 return *this;
58 }
60 {
61 stream_name = std::move(t.stream_name);
62 stream_data = std::move(t.stream_data);
63 flags = t.flags;
64 }
66 {
67 stream_name = std::move(t.stream_name);
68 stream_data = std::move(t.stream_data);
69 flags = t.flags;
70 return *this;
71 }
72};
73
74auto constexpr operator""_MB(quint64 s) -> quint64
75{
76 return s * 1024ul * 1024ul;
77}
78
80{
87
88 static constexpr quint32 MaxBufferSize = 1024_MB;
89
90 bool isValid() const
91 {
92 if (clientId != 0 && clientVersion != 0 && !sessionName.isEmpty()
94 return true;
95 return false;
96 }
97};
98
105
106class QCtfServer : public QThread
107{
109public:
118 {
120 DontBufferOnIdle = 256, // not set -> the server is buffering even without client connection
121 // set -> the server is buffering only when client is connected
122 };
133
135 {
136 virtual void handleSessionChange() = 0;
138 };
139 QCtfServer(QObject *parent = nullptr);
140 ~QCtfServer();
142 void setHost(const QString &address);
143 void setPort(int port);
144 void run() override;
145 void startServer();
146 void stopServer();
147 void bufferData(const QString &stream, const QByteArray &data, quint32 flags);
148 QString sessionName() const;
150 bool bufferOnIdle() const;
151 ServerStatus status() const;
152private:
153
154 void initWrite();
156 bool waitSocket();
157 void readCbor(QCborStreamReader &cbor);
158 void handleString(QCborStreamReader &cbor);
159 void handleFixedWidth(QCborStreamReader &cbor);
160 bool recognizedCompressionScheme() const;
161 void setStatusAndNotify(ServerStatus status);
162 void writePacket(TracePacket &packet, QCborStreamWriter &cbor);
163
164 QMutex m_mutex;
165 QWaitCondition m_bufferHasData;
166 QList<TracePacket> m_packets;
167 QString m_address;
168 QTcpServer *m_server = nullptr;
169 QTcpSocket *m_socket = nullptr;
170 QEventLoop *m_eventLoop = nullptr;
171 QList<QString> m_keySet;
172 TraceRequest m_req;
173 ServerCallback *m_cb = nullptr;
174 ServerStatus m_status = Uninitialized;
175 qint64 m_waitWriteSize = 0;
176 qint64 m_writtenSize = 0;
177 int m_port;
178 int m_compression = 0;
179 int m_maxPackets = DefaultMaxPackets;
180 QAtomicInt m_stopping;
181 bool m_bufferOnIdle = true;
182 QString m_currentKey;
183 QString m_requestedCompressionScheme;
184#if QT_CONFIG(zstd)
185 ZSTD_CCtx *m_zstdCCtx = nullptr;
186#endif
187
188 static constexpr quint32 ServerId = 1;
189 static constexpr quint32 DefaultMaxPackets = 256; // 1 MB
190};
191
193
194#endif
\inmodule QtCore
Definition qatomic.h:112
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
QString sessionTracepoints() const
QCtfServer(QObject *parent=nullptr)
@ RequestSessionTracepoints
@ RequestCompressionScheme
bool bufferOnIdle() const
void setCallback(ServerCallback *cb)
void startServer()
void stopServer()
void bufferData(const QString &stream, const QByteArray &data, quint32 flags)
void setPort(int port)
void run() override
ServerStatus status() const
QString sessionName() const
\inmodule QtCore
Definition qeventloop.h:16
\inmodule QtCore
Definition qmutex.h:281
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
The QTcpServer class provides a TCP-based server.
Definition qtcpserver.h:22
The QTcpSocket class provides a TCP socket.
Definition qtcpsocket.h:18
void setHost()
Combined button and popup list for selecting options.
struct ZSTD_CCtx_s ZSTD_CCtx
EGLStreamKHR stream
EGLOutputPortEXT port
GLenum GLsizei GLuint GLint * bytesWritten
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLbitfield flags
GLdouble s
[6]
Definition qopenglext.h:235
GLdouble GLdouble t
Definition qopenglext.h:243
GLuint GLuint64EXT address
SSL_CTX int(* cb)(SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)
#define Q_OBJECT
unsigned int quint32
Definition qtypes.h:50
unsigned long long quint64
Definition qtypes.h:61
long long qint64
Definition qtypes.h:60
virtual void handleSessionChange()=0
virtual void handleStatusChange(ServerStatus status)=0
TracePacket(TracePacket &&t)
TracePacket(const TracePacket &t)
static constexpr quint32 PacketSize
static constexpr quint32 PacketMagicNumber
TracePacket()=default
QByteArray stream_data
QByteArray stream_name
TracePacket & operator=(const TracePacket &t)
QString sessionName
quint32 clientVersion
quint32 bufferSize
quint32 clientId
quint32 flags
bool isValid() const
static constexpr quint32 MaxBufferSize
QString sessionTracepoints
QString serverName
quint32 serverVersion