Pool Video Switch v2
Software video switch for distributed remote display in a lecture environment
client.h
Go to the documentation of this file.
1 #ifndef CLIENT_H_
2 #define CLIENT_H_
3 
4 #include "../../shared/networkmessage.h"
5 
6 #include <QByteArray>
7 
8 //class QSslSocket;
9 class QTcpSocket;
10 class Client;
11 
12 #define NO_SOURCE 0
13 
14 struct ClientLogin {
15  bool accept;
16  QString name;
17  QString host;
18  QString ip;
19  bool examMode;
20 };
21 
22 
23 class Client : public QObject
24 {
25  Q_OBJECT
26 
27 public:
28  explicit Client(QTcpSocket* socket);
29  ~Client() override;
30 
31  // Getters
32  bool isAuthed() const { return _authed == 2; }
33  const QString& name() const { return _name; }
34  const QString& host() const { return _host; }
35  QString ip() const;
36  int id() const { return _id; }
37  bool isActiveVncClient() const { return _isActiveVncClient; }
38  bool isActiveVncServer() const { return _vncPort > 0; }
39  bool isLocked() const { return _locked; }
40  int desiredProjectionSource() const { return _desiredSource; }
41  int projectionSource() const { return _projectionSource; }
42  int isExamMode() const { return _isExamMode; }
43  bool wantsAttention() const { return _wantsAttention; }
45 
46  // Setters
47  void setTutor(bool enable) { _isTutor = enable; }
49  void setExamMode(bool mode) { _isExamMode = mode; }
50 
51  //Send message stuff
52  void startVncServer();
53  void stopVncServer();
54  void startVncClient(const Client * to);
55  void stopVncClient();
56  void lockScreen(bool);
57  void requestThumb(const QSize& size);
58 
59 private:
60 
61  QTcpSocket * const _socket;
62  bool _locked{};
63  int _authed{}; // 0 = challenge sent, awaiting reply 1 = challenge ok, client challenge replied, awaiting login, 2 = ESTABLISHED
64  QString _name;
65  QString _host;
66  QByteArray _challenge;
67  qint64 _pingTimeout;
70  int _id; // this client's unique id
72  int _vncPort{}; // VNCserver state. Greater 0 -> active on this port. Equals 0 -> no server.
73  int _desiredSource; // The source the client shall be connected to
74  int _projectionSource{}; // The source the client was or is connected to (depends on _isActiveVncClient)
75  bool _isActiveVncClient{}; // VNCclient state. indicating that the client is displaying a remote screen via VNC
76  bool _isTutor{}; // Flag indicating that the client has been set as a tutor
77  bool _isExamMode{};
78  bool _wantsAttention{}; // Flag telling whether the client activated the "i want attention" button
79  QByteArray _rawRemoteScreen;
80 
81 
82  static int _clientIdCounter;
83 
84  bool isManagerMachine() const;
85 
86  void handleMsg();
87  void sendMessage(NetworkMessage& message);
89 
90 protected:
91  void timerEvent(QTimerEvent* event) override;
92 
93 signals:
94  void authenticating(Client* client, ClientLogin* request);
95  void authenticated(Client* client);
96  void thumbUpdated(Client* client, const QImage& thumb);
97  void vncServerStateChange(Client* client);
98  void vncClientStateChange(Client* client);
99  void stateChanged();
100  void disconnected();
101 
102 private slots:
103  void onDataArrival(); // triggered if data is available for reading
104  void disconnect(const char *errmsg);
105 
106 };
107 
108 #endif /* CLIENT_H_ */
void setExamMode(bool mode)
Definition: client.h:49
void setTutor(bool enable)
Definition: client.h:47
int id() const
Definition: client.h:36
bool isLocked() const
Definition: client.h:39
QString host
Definition: client.h:17
void authenticating(Client *client, ClientLogin *request)
const QString & host() const
Definition: client.h:34
void authenticated(Client *client)
QString ip() const
Definition: client.cpp:349
void stateChanged()
bool _isExamMode
Definition: client.h:77
QString ip
Definition: client.h:18
NetworkMessage _fromClient
Definition: client.h:68
void timerEvent(QTimerEvent *event) override
Definition: client.cpp:75
bool _wantsAttention
Definition: client.h:78
qint64 _pingTimeout
Definition: client.h:67
QString _host
Definition: client.h:65
void disconnected()
~Client() override
Definition: client.cpp:65
int _projectionSource
Definition: client.h:74
void handleMsg()
Definition: client.cpp:147
void startVncServer()
Definition: client.cpp:264
QTcpSocket *const _socket
Definition: client.h:61
bool wantsAttention() const
Definition: client.h:43
void disconnect(const char *errmsg)
Definition: client.cpp:335
bool examMode
Definition: client.h:19
bool _isActiveVncClient
Definition: client.h:75
void startVncClient(const Client *to)
Definition: client.cpp:280
void stopVncServer()
Definition: client.cpp:272
QByteArray _challenge
Definition: client.h:66
void setDesiredProjectionSource(int id)
Definition: client.h:48
int _timerIdAuthTimeout
Definition: client.h:69
void sendMessage(NetworkMessage &message)
Definition: client.cpp:91
bool isActiveVncClient() const
Definition: client.h:37
Definition: client.h:23
void removeAttention()
Definition: client.h:44
const QString & name() const
Definition: client.h:33
void thumbUpdated(Client *client, const QImage &thumb)
void removeAttentionInternal()
Definition: client.cpp:101
int projectionSource() const
Definition: client.h:41
void requestThumb(const QSize &size)
Definition: client.cpp:111
QString _vncRoPass
Definition: client.h:71
bool isActiveVncServer() const
Definition: client.h:38
Client(QTcpSocket *socket)
Definition: client.cpp:23
bool isManagerMachine() const
Checks if client and manager runs on same machine.
Definition: client.cpp:311
bool accept
Definition: client.h:15
void vncClientStateChange(Client *client)
QString _vncRwPass
Definition: client.h:71
bool _isTutor
Definition: client.h:76
QString _name
Definition: client.h:64
bool isAuthed() const
Definition: client.h:32
void vncServerStateChange(Client *client)
QString name
Definition: client.h:16
void lockScreen(bool)
Definition: client.cpp:320
static int _clientIdCounter
Definition: client.h:82
void stopVncClient()
Definition: client.cpp:297
int desiredProjectionSource() const
Definition: client.h:40
bool _locked
Definition: client.h:62
int isExamMode() const
Definition: client.h:42
QByteArray _rawRemoteScreen
Definition: client.h:79
int _vncPort
Definition: client.h:72
int _id
Definition: client.h:70
void onDataArrival()
Definition: client.cpp:124
int _authed
Definition: client.h:63
int _desiredSource
Definition: client.h:73
int _timerPingTimeout
Definition: client.h:69