From b406dc7311c362d867662be0bfc43d7b3d5b58a0 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 3 Sep 2013 14:20:47 -0700 Subject: [PATCH] Log when attempting to connect and on failure. Wait a second before attempting to reconnect. --- interface/src/devices/Faceshift.cpp | 20 +++++++++++++++++++- interface/src/devices/Faceshift.h | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/interface/src/devices/Faceshift.cpp b/interface/src/devices/Faceshift.cpp index f9f2a64d46..9d75418e5e 100644 --- a/interface/src/devices/Faceshift.cpp +++ b/interface/src/devices/Faceshift.cpp @@ -6,13 +6,16 @@ // Copyright (c) 2013 High Fidelity, Inc. All rights reserved. // +#include + #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()); diff --git a/interface/src/devices/Faceshift.h b/interface/src/devices/Faceshift.h index c8cc07951a..d89e68b04a 100644 --- a/interface/src/devices/Faceshift.h +++ b/interface/src/devices/Faceshift.h @@ -36,6 +36,8 @@ public slots: private slots: void connectSocket(); + void noteConnected(); + void noteError(QAbstractSocket::SocketError error); void readFromSocket(); private: