blob: ec8c26dc98afd82137f34d8802b3592a0801a21e (
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
53
54
|
/**
* @file JettingProxy.h
* @brief Transparent TCP relay between one controller and N clients.
*/
#pragma once
#include <QList>
#include <QObject>
#include <QTcpServer>
#include <QTcpSocket>
#include <QTimer>
class JettingProxy : public QObject
{
Q_OBJECT
public:
explicit JettingProxy (quint16 controllerPortBase, quint16 clientPortBase,
QObject *parent = nullptr);
static void enableWireDebug ();
private slots:
void onControllerConnected ();
void onControllerDisconnected ();
void onControllerDataReady ();
void onClientConnected ();
void onClientDisconnected ();
void onClientDataReady ();
/* Send KA_PING to all connected clients on all channels. */
void tick ();
private:
struct Channel
{
const char *name = nullptr;
QTcpServer controllerServer;
QTcpSocket *controllerSocket = nullptr;
QTcpServer clientServer;
QList<QTcpSocket *> clientSockets;
};
void setupChannel (Channel &channel, const char *name,
quint16 controllerPort, quint16 clientPort);
Channel *channelForControllerServer (QTcpServer *server);
Channel *channelForControllerSocket (QTcpSocket *socket);
Channel *channelForClientSocket (QTcpSocket *socket);
QString logTag (const Channel &channel) const;
Channel m_command;
Channel m_imaging;
Channel m_status;
QTimer m_tickTimer;
static bool s_wireDebug;
};
|