fixed some XBMC checker reconnection

Former-commit-id: ec9c327965597b4b552d939cfb664ca95e2f1786
This commit is contained in:
johan 2013-12-21 17:20:02 +01:00
parent efcb8ec179
commit 3d3c8c93b8
3 changed files with 37 additions and 9 deletions

View File

@ -1 +1 @@
a975349d4d5b010597f15b5efa6363f43434627f
27dcc318ae9a9226676fb33626500e57703d7b6d

View File

@ -65,6 +65,9 @@ private slots:
/// Called when disconnected from XBMC
void disconnected();
/// reconnect to XBMC
void reconnect();
/// Called when a connection error was encountered
void connectionError(QAbstractSocket::SocketError error);

View File

@ -44,7 +44,7 @@ XBMCVideoChecker::XBMCVideoChecker(const std::string & address, uint16_t port, b
void XBMCVideoChecker::start()
{
disconnected();
reconnect();
}
void XBMCVideoChecker::receiveReply()
@ -157,17 +157,42 @@ void XBMCVideoChecker::connected()
void XBMCVideoChecker::disconnected()
{
std::cout << "XBMC Disconnected" << std::endl;
// try to connect
_socket.connectToHost(_address, _port);
reconnect();
}
void XBMCVideoChecker::connectionError(QAbstractSocket::SocketError)
void XBMCVideoChecker::reconnect()
{
std::cout << "XBMC Connection error" << std::endl;
if (_socket.state() == QTcpSocket::ConnectedState)
{
return;
}
// try to connect again in 1 second
QTimer::singleShot(1000, this, SLOT(disconnected()));
// try to connect
switch (_socket.state())
{
case QTcpSocket::ConnectingState:
// Somehow when XBMC restarts we get stuck in connecting state
// If we get here we tried to connect already for 5 seconds. abort and try again in 1 second.
_socket.reset();
_socket.waitForDisconnected(50);
QTimer::singleShot(1000, this, SLOT(reconnect()));
break;
case QTcpSocket::UnconnectedState:
_socket.connectToHost(_address, _port);
QTimer::singleShot(10000, this, SLOT(reconnect()));
break;
default:
QTimer::singleShot(10000, this, SLOT(reconnect()));
break;
}
}
void XBMCVideoChecker::connectionError(QAbstractSocket::SocketError error)
{
std::cout << "XBMC Connection error (" << error << ")" << std::endl;
// close the socket
_socket.close();
}
void XBMCVideoChecker::setGrabbingMode(GrabbingMode newGrabbingMode)