summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsr2013-02-06 19:21:04 +0100
committersr2013-02-06 19:21:04 +0100
commit49f3903f316ab7363b4543615d3231e1407a67ab (patch)
tree9f6ec082403f388c0e791de68b1743000a12bc49 /src
parent... (diff)
downloadpvs2-49f3903f316ab7363b4543615d3231e1407a67ab.tar.gz
pvs2-49f3903f316ab7363b4543615d3231e1407a67ab.tar.xz
pvs2-49f3903f316ab7363b4543615d3231e1407a67ab.zip
[SERVER] Add "stop projection" button
[SERVER] Don't show error message when VNC server stops as expected [SERVER/CLIENT] Implement connection timeout of 15 seconds
Diffstat (limited to 'src')
-rw-r--r--src/client/connectwindow/connectwindow.cpp5
-rw-r--r--src/client/connectwindow/connectwindow.h1
-rw-r--r--src/client/net/serverconnection.cpp14
-rw-r--r--src/client/net/serverconnection.h3
-rw-r--r--src/client/vnc/vncwindow.cpp15
-rw-r--r--src/client/vnc/vncwindow.h2
-rw-r--r--src/server/mainwindow/mainwindow.cpp21
-rw-r--r--src/server/mainwindow/mainwindow.h1
-rw-r--r--src/server/net/client.cpp16
-rw-r--r--src/server/net/client.h2
10 files changed, 72 insertions, 8 deletions
diff --git a/src/client/connectwindow/connectwindow.cpp b/src/client/connectwindow/connectwindow.cpp
index bc4e9b2..abc33e8 100644
--- a/src/client/connectwindow/connectwindow.cpp
+++ b/src/client/connectwindow/connectwindow.cpp
@@ -183,6 +183,11 @@ void ConnectWindow::closeEvent(QCloseEvent *e)
this->hide();
}
+void ConnectWindow::showEvent(QShowEvent* event)
+{
+ txtName->setFocus();
+}
+
/**
* Slots
*/
diff --git a/src/client/connectwindow/connectwindow.h b/src/client/connectwindow/connectwindow.h
index d8f9ab9..2bc2f86 100644
--- a/src/client/connectwindow/connectwindow.h
+++ b/src/client/connectwindow/connectwindow.h
@@ -77,6 +77,7 @@ protected:
*/
void timerEvent(QTimerEvent* event);
void closeEvent(QCloseEvent *e);
+ void showEvent(QShowEvent* event);
protected slots:
void onOkClick();
diff --git a/src/client/net/serverconnection.cpp b/src/client/net/serverconnection.cpp
index 6858f54..3ccb11e 100644
--- a/src/client/net/serverconnection.cpp
+++ b/src/client/net/serverconnection.cpp
@@ -10,6 +10,7 @@
#include "../vnc/vncserver.h"
#include "../../shared/util.h"
+#include "../../shared/settings.h"
#include "../util/platform/blankscreen.h"
#define CHALLENGE_LEN 20
@@ -31,6 +32,8 @@ ServerConnection::ServerConnection(const QString& host, const quint16 port, cons
qDebug("Connecting to %s on port %d", host.toUtf8().data(), (int)port);
_socket->connectToHostEncrypted(host, port);
_timerId = startTimer(4000);
+ _lastData = QDateTime::currentMSecsSinceEpoch() + PING_TIMEOUT_MS;
+ _timerConnectionCheck = startTimer(5000);
// Connect the vnc start/stop signal to this class, so we can tell the server about successful vnc server startup
connect(VncServer::instance(), SIGNAL(started(int, QString&, QString&)), this, SLOT(onVncServerStartStop(int, QString&, QString&)));
}
@@ -78,6 +81,7 @@ void ServerConnection::disconnectFromServer()
void ServerConnection::handleMsg()
{
+ _lastData = QDateTime::currentMSecsSinceEpoch() + PING_TIMEOUT_MS;
const QString &id = _fromServer.getFieldString(_ID);
if (_authed == 0)
@@ -244,7 +248,15 @@ void ServerConnection::handleMsg()
void ServerConnection::timerEvent(QTimerEvent *event)
{
- if (event->timerId() == _timerId)
+ if (event->timerId() == _timerConnectionCheck)
+ {
+ if (_lastData < QDateTime::currentMSecsSinceEpoch())
+ {
+ this->disconnectFromServer();
+ killTimer(_timerConnectionCheck);
+ }
+ }
+ else if (event->timerId() == _timerId)
{
killTimer(_timerId);
_timerId = 0;
diff --git a/src/client/net/serverconnection.h b/src/client/net/serverconnection.h
index 7dddf5e..6af2b15 100644
--- a/src/client/net/serverconnection.h
+++ b/src/client/net/serverconnection.h
@@ -14,9 +14,10 @@ Q_OBJECT
private:
QSslSocket *_socket;
BlankScreen *_blank;
- int _timerId, _timerDelete;
+ int _timerId, _timerDelete, _timerConnectionCheck;
int _jpegQuality;
int _authed;
+ qint64 _lastData;
NetworkMessage _fromServer, _toServer;
QByteArray _expectedFingerprint;
diff --git a/src/client/vnc/vncwindow.cpp b/src/client/vnc/vncwindow.cpp
index d4f6d40..aea2362 100644
--- a/src/client/vnc/vncwindow.cpp
+++ b/src/client/vnc/vncwindow.cpp
@@ -19,7 +19,7 @@
#include "vncthread.h"
VncWindow::VncWindow(QWidget *parent) :
- QDialog(parent), _vncWorker(NULL), _viewOnly(true), _buttonMask(0), _clientId(0)
+ QDialog(parent), _vncWorker(NULL), _viewOnly(true), _buttonMask(0), _clientId(0), _redrawTimer(0)
{
//
}
@@ -108,11 +108,23 @@ void VncWindow::onThreadFinished()
void VncWindow::onProjectionStarted()
{
emit running(true, _clientId);
+ _redrawTimer = startTimer(200);
}
////////////////////////////////////////////////////////////////////////////////
// Protected
+void VncWindow::timerEvent(QTimerEvent *event)
+{
+ killTimer(event->timerId());
+ if (event->timerId() == _redrawTimer)
+ {
+ _redrawTimer = 0;
+ if (this->isVisible())
+ this->repaint();
+ }
+}
+
void VncWindow::paintEvent(QPaintEvent *event)
{
const QRect &r = event->rect();
@@ -123,6 +135,7 @@ void VncWindow::paintEvent(QPaintEvent *event)
void VncWindow::resizeEvent(QResizeEvent* event)
{
_vncWorker->setTargetSize(event->size());
+ this->repaint();
}
void VncWindow::draw(const int x, const int y, const int w, const int h)
diff --git a/src/client/vnc/vncwindow.h b/src/client/vnc/vncwindow.h
index 3a73a8e..396e2de 100644
--- a/src/client/vnc/vncwindow.h
+++ b/src/client/vnc/vncwindow.h
@@ -51,6 +51,7 @@ protected:
void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent* event);
void closeEvent(QCloseEvent *e);
+ void timerEvent(QTimerEvent *event);
//bool event(QEvent *event);
//bool eventFilter(QObject *obj, QEvent *event);
@@ -60,6 +61,7 @@ private:
int _buttonMask;
QMap<unsigned int, bool> _modkeys;
int _clientId;
+ int _redrawTimer;
bool eventFilter(QObject *obj, QEvent *event);
void keyPressEvent(QKeyEvent* event);
diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp
index 710da3f..74e1e7d 100644
--- a/src/server/mainwindow/mainwindow.cpp
+++ b/src/server/mainwindow/mainwindow.cpp
@@ -65,6 +65,7 @@ MainWindow::MainWindow(QWidget* parent) :
connect(ui->action_TutorToAll, SIGNAL(triggered()), this, SLOT(onButtonTutorToAll()));
connect(ui->action_StudentToTutor, SIGNAL(triggered()), this, SLOT(onButtonStudentToTutor()));
connect(ui->action_TutorToStudent, SIGNAL(triggered()), this, SLOT(onButtonTutorToStudent()));
+ connect(ui->action_StopProjection, SIGNAL(triggered()), this, SLOT(onButtonStopProjection()));
connect(ui->action_Lock, SIGNAL(toggled(bool)), this, SLOT(onButtonLock(bool)));
// Clicking the session name label shows the edit field for it
connect(_sessionNameLabel, SIGNAL(clicked()), this, SLOT(onSessionNameClick()));
@@ -565,6 +566,24 @@ void MainWindow::onButtonTutorToStudent()
prepareForProjection(from, to);
}
+void MainWindow::onButtonStopProjection()
+{
+ const qint64 now = QDateTime::currentMSecsSinceEpoch();
+ if (now < _buttonBlockTime)
+ return;
+ _buttonBlockTime = now + 3000;
+ //
+ NetworkMessage msg;
+ msg.setField(_ID, _VNCCLIENT);
+ for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
+ {
+ Client *c = (**it).client();
+ if (c == NULL)
+ continue;
+ c->sendMessage(msg);
+ }
+}
+
void MainWindow::onButtonLock(bool checked)
{
NetworkMessage msg;
@@ -769,7 +788,7 @@ void MainWindow::onVncServerStateChange(Client* client)
c->setDesiredProjectionSource(0);
}
}
- if (wasInterested)
+ if (wasInterested && QDateTime::currentMSecsSinceEpoch() < _buttonBlockTime)
{
QMessageBox::information(this,
tr("Projection Error"),
diff --git a/src/server/mainwindow/mainwindow.h b/src/server/mainwindow/mainwindow.h
index 0cc6abc..9b6c6d3 100644
--- a/src/server/mainwindow/mainwindow.h
+++ b/src/server/mainwindow/mainwindow.h
@@ -62,6 +62,7 @@ protected slots:
void onButtonStudentToTutor();
void onButtonTutorToAll();
void onButtonTutorToStudent();
+ void onButtonStopProjection();
void onButtonLock(bool checked);
void onButtonExit();
// connection frame
diff --git a/src/server/net/client.cpp b/src/server/net/client.cpp
index d6002a6..3adeeaa 100644
--- a/src/server/net/client.cpp
+++ b/src/server/net/client.cpp
@@ -24,7 +24,6 @@ Client::Client(QSslSocket* socket) :
{
assert(socket != NULL);
_id = ++_clientIdCounter;
- _pingTimeout = QDateTime::currentMSecsSinceEpoch() + PING_TIMEOUT_MS;
_ip = _socket->peerAddress().toString();
qDebug("*** Client %s created.", qPrintable(_ip));
// Connect important signals
@@ -42,6 +41,8 @@ Client::Client(QSslSocket* socket) :
_toClient.writeMessage(_socket);
// give client 3 seconds to complete handshake
_timerIdAuthTimeout = startTimer(3000);
+ _timerPingTimeout = startTimer(5000);
+ _pingTimeout = QDateTime::currentMSecsSinceEpoch() + PING_TIMEOUT_MS;
}
Client::~Client()
@@ -56,7 +57,16 @@ Client::~Client()
void Client::timerEvent(QTimerEvent* event)
{
- if (event->timerId() == _timerIdAuthTimeout)
+ if (event->timerId() == _timerPingTimeout)
+ {
+ if (_pingTimeout < QDateTime::currentMSecsSinceEpoch())
+ {
+ qDebug() << "Client" << _ip << "has a ping timeout.";
+ killTimer(_timerPingTimeout);
+ this->disconnect();
+ }
+ }
+ else if (event->timerId() == _timerIdAuthTimeout)
{
// Client did not send login request within 3 seconds
killTimer(_timerIdAuthTimeout);
@@ -108,7 +118,6 @@ void Client::requestThumb(const int width, const int height)
void Client::onDataArrival()
{
- _pingTimeout = QDateTime::currentMSecsSinceEpoch() + PING_TIMEOUT_MS;
//
if (_socket == NULL || _socket->state() != QAbstractSocket::ConnectedState)
{
@@ -153,6 +162,7 @@ void Client::onError(QAbstractSocket::SocketError errcode)
void Client::handleMsg()
{
+ _pingTimeout = QDateTime::currentMSecsSinceEpoch() + PING_TIMEOUT_MS;
const QString &id = _fromClient.getFieldString(_ID);
if (id.isEmpty())
{
diff --git a/src/server/net/client.h b/src/server/net/client.h
index ce17c18..32ce69f 100644
--- a/src/server/net/client.h
+++ b/src/server/net/client.h
@@ -31,7 +31,7 @@ private:
QByteArray _challenge;
qint64 _pingTimeout;
NetworkMessage _toClient, _fromClient;
- int _timerIdAuthTimeout, _timerDelete;
+ int _timerIdAuthTimeout, _timerDelete, _timerPingTimeout;
int _id; // this client's unique id