Pool Video Switch v2
Software video switch for distributed remote display in a lecture environment
serverconnection.h
Go to the documentation of this file.
1 #ifndef _PVSSERVERCONNECTION_H_
2 #define _PVSSERVERCONNECTION_H_
3 
4 #include <QSslSocket>
5 #include <QElapsedTimer>
6 #include "../../shared/networkmessage.h"
7 #include "../connectwindow/connectwindow.h"
8 
9 class BlankScreen;
10 
11 class ServerConnection : public QObject
12 {
13  Q_OBJECT
14 
15 private:
16  QSslSocket *_socket;
20  int _authed;
23  qint64 _lastData;
24 
27  QString _passwd;
28  QByteArray _myChallenge;
29  QByteArray _sessionName;
30  QByteArray _certHash;
31  QString _host;
32  quint16 _port;
33  QElapsedTimer _connectionTimer;
34 
35  void handleMsg();
36  QString diagnosticContext(const QString& stage) const;
37 
38  void checkLocalConnection();
39 
40 public:
41  ServerConnection(const QString& host, quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect);
42  void disconnectFromServer();
43  ~ServerConnection() override;
44  inline bool isConnected() const
45  {
46  return _socket != nullptr && _socket->state() == QAbstractSocket::ConnectedState;
47  }
48 
49  QString getPeerAdress() const { return _socket->peerAddress().toString(); }
50 
52  if (_isLocalConnection == -1) {
54  }
55  return _isLocalConnection == 1;
56  }
57 
58  void sendMessage(NetworkMessage& message);
59  void sendAttention(bool on);
60 
61 protected:
62  void timerEvent(QTimerEvent *event) override;
63 
64 private slots:
65  void sslErrors(const QList<QSslError> & errors); // triggered for errors that occur during SSL negotiation
66  void sock_dataArrival(); // triggered if data is available for reading
67  void sock_closed(); // triggered if the socket is closed
68  void sock_error(QAbstractSocket::SocketError errcode); // triggered if an error occurs on the socket
69  void sock_connected(); // triggered if the connection is established and ready to use
70 
71  void onVncServerStartStop(int port, const QString &ropass, const QString &rwpass); // triggered if the local vnc server was started
72 
73 public slots:
74  void onVncViewerStartStop(bool started, int clientId);
75 
76 signals:
77  void openVnc(const QString& host, int port, const QString& passwd, bool ro, bool fullscreen, const QString& caption, const int clientId, const QByteArray& rawThumb);
78  void closeVnc();
80  void disconnected(ServerConnection* connection);
81  void attentionChanged(bool state);
82 };
83 
84 #endif
QString getPeerAdress() const
QByteArray _sessionName
QSslSocket * _socket
QByteArray _expectedFingerprint
~ServerConnection() override
void stateChange(ConnectWindow::ConnectionState state)
void sendMessage(NetworkMessage &message)
Send the given message to the server.
BlankScreen * _blank
NetworkMessage _toServer
QElapsedTimer _connectionTimer
void disconnectFromServer()
Disconnect from current server.
void attentionChanged(bool state)
NetworkMessage _fromServer
void disconnected(ServerConnection *connection)
void onVncServerStartStop(int port, const QString &ropass, const QString &rwpass)
This slot is triggered by the vnc server runner once the external VNC server was succesfully started...
void timerEvent(QTimerEvent *event) override
QByteArray _certHash
bool isConnected() const
void sock_error(QAbstractSocket::SocketError errcode)
void sslErrors(const QList< QSslError > &errors)
An ssl error happened.
QString diagnosticContext(const QString &stage) const
ServerConnection(const QString &host, quint16 port, const QByteArray &sessionName, const QByteArray &certHash, bool autoConnect)
void openVnc(const QString &host, int port, const QString &passwd, bool ro, bool fullscreen, const QString &caption, const int clientId, const QByteArray &rawThumb)
void handleMsg()
Handles an incoming message by the server.
void onVncViewerStartStop(bool started, int clientId)
This slot is triggered once the internal VNC viewer has started or stopped displaying a VNC stream...
QByteArray _myChallenge
void sendAttention(bool on)