mirror of
https://github.com/overte-org/overte.git
synced 2025-04-23 15:13:41 +02:00
Log when attempting to connect and on failure. Wait a second before
attempting to reconnect.
This commit is contained in:
parent
734cb83e81
commit
b406dc7311
2 changed files with 21 additions and 1 deletions
|
@ -6,13 +6,16 @@
|
|||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
#include "Faceshift.h"
|
||||
|
||||
using namespace fs;
|
||||
|
||||
Faceshift::Faceshift() : _enabled(false) {
|
||||
connect(&_socket, SIGNAL(connected()), SLOT(noteConnected()));
|
||||
connect(&_socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(noteError(QAbstractSocket::SocketError)));
|
||||
connect(&_socket, SIGNAL(readyRead()), SLOT(readFromSocket()));
|
||||
connect(&_socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(connectSocket()));
|
||||
}
|
||||
|
||||
void Faceshift::setEnabled(bool enabled) {
|
||||
|
@ -26,11 +29,26 @@ void Faceshift::setEnabled(bool enabled) {
|
|||
|
||||
void Faceshift::connectSocket() {
|
||||
if (_enabled) {
|
||||
qDebug("Faceshift: Connecting...\n");
|
||||
|
||||
const quint16 FACESHIFT_PORT = 33433;
|
||||
_socket.connectToHost("localhost", FACESHIFT_PORT);
|
||||
}
|
||||
}
|
||||
|
||||
void Faceshift::noteConnected() {
|
||||
qDebug("Faceshift: Connected.\n");
|
||||
}
|
||||
|
||||
void Faceshift::noteError(QAbstractSocket::SocketError error) {
|
||||
qDebug() << "Faceshift: " << _socket.errorString() << "\n";
|
||||
|
||||
// reconnect after a delay
|
||||
if (_enabled) {
|
||||
QTimer::singleShot(1000, this, SLOT(connectSocket()));
|
||||
}
|
||||
}
|
||||
|
||||
void Faceshift::readFromSocket() {
|
||||
QByteArray buffer = _socket.readAll();
|
||||
_stream.received(buffer.size(), buffer.constData());
|
||||
|
|
|
@ -36,6 +36,8 @@ public slots:
|
|||
private slots:
|
||||
|
||||
void connectSocket();
|
||||
void noteConnected();
|
||||
void noteError(QAbstractSocket::SocketError error);
|
||||
void readFromSocket();
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in a new issue