From 0ca674a313d43a06be8455f81619e79790fd5f5a Mon Sep 17 00:00:00 2001 From: Elias Steurer Date: Fri, 14 Aug 2020 11:28:58 +0200 Subject: [PATCH] Add another check if main application is still running The timeout of pipes is quite high so we need to ping them regularly --- ScreenPlaySDK/inc/screenplaysdk.h | 2 ++ ScreenPlaySDK/src/screenplaysdk.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/ScreenPlaySDK/inc/screenplaysdk.h b/ScreenPlaySDK/inc/screenplaysdk.h index 242e87fa..2eca5c6f 100644 --- a/ScreenPlaySDK/inc/screenplaysdk.h +++ b/ScreenPlaySDK/inc/screenplaysdk.h @@ -84,6 +84,7 @@ public slots: void readyRead(); void error(QLocalSocket::LocalSocketError socketError); void redirectMessage(QByteArray& msg); + void pingAlive(); void setType(QString type) { @@ -145,4 +146,5 @@ private: bool m_isConnected = false; QString m_appID; + QTimer m_pingAliveTimer; }; diff --git a/ScreenPlaySDK/src/screenplaysdk.cpp b/ScreenPlaySDK/src/screenplaysdk.cpp index 3df30d77..3cab342e 100644 --- a/ScreenPlaySDK/src/screenplaysdk.cpp +++ b/ScreenPlaySDK/src/screenplaysdk.cpp @@ -41,6 +41,9 @@ void ScreenPlaySDK::init() m_socket.disconnectFromServer(); emit sdkDisconnected(); } + + QObject::connect(&m_pingAliveTimer, &QTimer::timeout, this, &ScreenPlaySDK::pingAlive); + m_pingAliveTimer.start(5000); }); } @@ -152,6 +155,15 @@ void ScreenPlaySDK::redirectMessage(QByteArray& msg) } } +void ScreenPlaySDK::pingAlive() +{ + m_socket.write("ping"); + if (!m_socket.waitForBytesWritten(500)) { + qInfo() << "Cannot ping to main application. Closing!"; + emit sdkDisconnected(); + } +} + void ScreenPlaySDK::ScreenPlaySDK::redirectMessageOutputToMainWindow(QtMsgType type, const QMessageLogContext& context, const QString& msg) { Q_UNUSED(type)