| 1 | // Copyright (C) 2016 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 QVNCCLIENT_H |
| 5 | #define QVNCCLIENT_H |
| 6 | |
| 7 | #include <QObject> |
| 8 | |
| 9 | #include "qvnc_p.h" |
| 10 | |
| 11 | QT_BEGIN_NAMESPACE |
| 12 | |
| 13 | class QTcpSocket; |
| 14 | class QVncServer; |
| 15 | |
| 16 | class QVncClient : public QObject |
| 17 | { |
| 18 | Q_OBJECT |
| 19 | public: |
| 20 | enum ClientMsg { |
| 21 | SetPixelFormat = 0, |
| 22 | FixColourMapEntries = 1, |
| 23 | SetEncodings = 2, |
| 24 | FramebufferUpdateRequest = 3, |
| 25 | KeyEvent = 4, |
| 26 | PointerEvent = 5, |
| 27 | ClientCutText = 6 |
| 28 | }; |
| 29 | |
| 30 | explicit QVncClient(QTcpSocket *clientSocket, QVncServer *server); |
| 31 | ~QVncClient(); |
| 32 | QTcpSocket *clientSocket() const; |
| 33 | QVncServer *server() const { return m_server; } |
| 34 | |
| 35 | void setDirty(const QRegion ®ion); |
| 36 | void setDirtyCursor() { m_dirtyCursor = true; scheduleUpdate(); } |
| 37 | QRegion dirtyRegion() const { return m_dirtyRegion; } |
| 38 | inline bool isConnected() const { return m_state == Connected; } |
| 39 | |
| 40 | inline int clientBytesPerPixel() const { |
| 41 | return m_pixelFormat.bitsPerPixel / 8; |
| 42 | } |
| 43 | |
| 44 | void convertPixels(char *dst, const char *src, int count, int depth) const; |
| 45 | inline bool doPixelConversion() const { return m_needConversion; } |
| 46 | |
| 47 | signals: |
| 48 | |
| 49 | private slots: |
| 50 | void readClient(); |
| 51 | void discardClient(); |
| 52 | void checkUpdate(); |
| 53 | void scheduleUpdate(); |
| 54 | |
| 55 | protected: |
| 56 | bool event(QEvent *event) override; |
| 57 | |
| 58 | private: |
| 59 | enum ClientState { |
| 60 | Disconnected, |
| 61 | Protocol, |
| 62 | Authentication, |
| 63 | Init, |
| 64 | Connected |
| 65 | }; |
| 66 | enum ProtocolVersion { |
| 67 | V3_3, |
| 68 | V3_7, |
| 69 | V3_8 |
| 70 | }; |
| 71 | |
| 72 | void setPixelFormat(); |
| 73 | void setEncodings(); |
| 74 | void frameBufferUpdateRequest(); |
| 75 | void pointerEvent(); |
| 76 | void keyEvent(); |
| 77 | void clientCutText(); |
| 78 | bool pixelConversionNeeded() const; |
| 79 | |
| 80 | QVncServer *m_server; |
| 81 | QTcpSocket *m_clientSocket; |
| 82 | QRfbEncoder *m_encoder; |
| 83 | |
| 84 | // Client State |
| 85 | ClientState m_state; |
| 86 | quint8 m_msgType; |
| 87 | bool m_handleMsg; |
| 88 | QRfbPixelFormat m_pixelFormat; |
| 89 | bool m_sameEndian; |
| 90 | bool m_needConversion; |
| 91 | int m_encodingsPending; |
| 92 | int m_cutTextPending; |
| 93 | uint m_supportCopyRect : 1; |
| 94 | uint m_supportRRE : 1; |
| 95 | uint m_supportCoRRE : 1; |
| 96 | uint m_supportHextile : 1; |
| 97 | uint m_supportZRLE : 1; |
| 98 | uint m_supportCursor : 1; |
| 99 | uint m_supportDesktopSize : 1; |
| 100 | bool m_wantUpdate; |
| 101 | Qt::KeyboardModifiers m_keymod; |
| 102 | bool m_dirtyCursor; |
| 103 | bool m_updatePending; |
| 104 | #if Q_BYTE_ORDER == Q_BIG_ENDIAN |
| 105 | bool m_swapBytes; |
| 106 | #endif |
| 107 | QRegion m_dirtyRegion; |
| 108 | ProtocolVersion m_protocolVersion; |
| 109 | }; |
| 110 | |
| 111 | QT_END_NAMESPACE |
| 112 | |
| 113 | #endif // QVNCCLIENT_H |
| 114 | |