blob: 13bb2cd3b5dd8936613acdb6bbabbd43b2b0102e (
plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
|
/**
* @file MockServer.h
* @brief Mock XPL2 server — listens on all three protocol ports.
*/
#pragma once
#include <QList>
#include <QObject>
#include <QTcpServer>
#include <QTimer>
class QTcpSocket;
class MockServer : public QObject
{
Q_OBJECT
public:
explicit MockServer (QObject *parent = nullptr);
static void enableWireDebug ();
private slots:
void onNewConnection ();
void onClientMessageReady ();
void onClientDisconnected ();
/* Send KA_PING keepalive to all connected clients. */
void sendKaPing ();
private:
struct Port
{
QTcpServer server;
const char *name = nullptr;
quint16 number = 0;
};
void setupPort (Port &port, const char *name, quint16 number);
/* Return a fixed-width "[Name:port]" tag for log lines. */
QString logTag (quint16 localPort) const;
/* Parse incoming line, log RX, and dispatch to the matching handler. */
void handleCommand (QTcpSocket *client, const QByteArray &line);
void sendReply (QTcpSocket *client, const QByteArray &data);
void handleKaPing (QTcpSocket *client, const QByteArray ¶ms);
void handleGsJcVersion (QTcpSocket *client);
Port m_command;
Port m_imaging;
Port m_status;
QList<QTcpSocket *> m_clients;
QTimer m_pingTimer;
static bool s_wireDebug;
};
|