From acafd14ec2015932372defc95fc17b685b940053 Mon Sep 17 00:00:00 2001 From: kevin Date: Sun, 23 Jun 2019 01:02:34 -0400 Subject: [PATCH] Properly reconnect to Hyperion server on disconnects. --- .gitignore | 1 + hgx11.cpp | 2 +- hgx11net.cpp | 21 ++++++++------------- hgx11net.h | 7 ++----- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index d9e1de7..9b3f415 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ cmake_install.cmake CMakeCache.txt Makefile Hyperion_Grabber_X11_QT +CMakeLists.txt.user diff --git a/hgx11.cpp b/hgx11.cpp index efc360d..1f09df6 100644 --- a/hgx11.cpp +++ b/hgx11.cpp @@ -11,7 +11,7 @@ hgx11::hgx11(QString addr, QString port, QString scale, QString frameskip, QStri _inactiveTime_m = (inactiveTime.toInt() > 0 ? QString::number(inactiveTime.toInt() * 1000) : "0"); _grabber_p = new hgx11grab(_scale_m.toInt(), _frameskip_m.toUShort()); - _hclient_p = new hgx11net(_addr_m.toStdString().c_str(), _port_m.toUShort()); + _hclient_p = new hgx11net(_addr_m, _port_m.toUShort()); _damage_p = new hgx11damage(); _hclient_p->imgWidth = QString::number(_grabber_p->getDest_width()); diff --git a/hgx11net.cpp b/hgx11net.cpp index 0c2779a..b515f32 100644 --- a/hgx11net.cpp +++ b/hgx11net.cpp @@ -2,10 +2,9 @@ // public -hgx11net::hgx11net(const char *host, ushort port) +hgx11net::hgx11net(QString host, ushort port) { _sock_p = new QTcpSocket(this); - connect(_sock_p, SIGNAL(disconnected()), this, SLOT(_disconnected())); _host_m = host; _port_m = port; this->_connectHost(); @@ -45,7 +44,13 @@ void hgx11net::setLedColor(quint8 R, quint8 G, quint8 B) bool hgx11net::_isConnected() { - return (_sock_p->state() == QAbstractSocket::ConnectedState); + bool connected = (_sock_p->state() == QAbstractSocket::ConnectedState); + if (!connected) { + _sock_p->reset(); + _connectHost(); + connected = (_sock_p->state() == QAbstractSocket::ConnectedState); + } + return connected; } void hgx11net::_connectHost() @@ -74,13 +79,3 @@ void hgx11net::sendImage(QByteArray *imgdata) _cmd_m.append(",\"priority\":100}\n"); _sock_p->write(_cmd_m); } - -// private slots - -void hgx11net::_disconnected() -{ - while (!_isConnected()) { - _connectHost(); - } -} - diff --git a/hgx11net.h b/hgx11net.h index 2cce20f..7713fe1 100644 --- a/hgx11net.h +++ b/hgx11net.h @@ -14,7 +14,7 @@ public: QString imgWidth; QString imgHeight; - hgx11net(const char *, ushort); + hgx11net(QString, ushort); ~hgx11net(); void clearLeds(); @@ -23,7 +23,7 @@ public: private: QTcpSocket *_sock_p; QByteArray _cmd_m; - const char *_host_m; + QString _host_m; quint16 _port_m; void _connectHost(); @@ -31,9 +31,6 @@ private: public slots: void sendImage(QByteArray *); - -private slots: - void _disconnected(); }; #endif // HGX11NET_H