summaryrefslogtreecommitdiffstats
path: root/src/libs
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@theqtcompany.com>2015-02-19 08:54:23 +0100
committerKai Koehne <kai.koehne@theqtcompany.com>2015-03-05 14:57:27 +0000
commit739fb83870fefbeeb3d92e92670c6cbe65f5c963 (patch)
tree26a4325ea8c0e222afa111270f88738793ac508f /src/libs
parenta4a19844d2e14003e21352506ba067e11a94de2b (diff)
Simplify KeepAliveObject implementation
Change-Id: I5c647510a8aa001183c9bf63ac0e1cae5ec32ce9 Reviewed-by: Karsten Heimrich <karsten.heimrich@theqtcompany.com> Reviewed-by: Niels Weber <niels.weber@theqtcompany.com>
Diffstat (limited to 'src/libs')
-rw-r--r--src/libs/installer/keepaliveobject.cpp41
-rw-r--r--src/libs/installer/keepaliveobject.h7
-rw-r--r--src/libs/installer/remoteclient_p.h20
3 files changed, 19 insertions, 49 deletions
diff --git a/src/libs/installer/keepaliveobject.cpp b/src/libs/installer/keepaliveobject.cpp
index 514ca5a7a..226181120 100644
--- a/src/libs/installer/keepaliveobject.cpp
+++ b/src/libs/installer/keepaliveobject.cpp
@@ -35,9 +35,6 @@
#include "keepaliveobject.h"
#include "remoteclient.h"
-#include <QCoreApplication>
-#include <QElapsedTimer>
-#include <QHostAddress>
#include <QLocalSocket>
#include <QTimer>
@@ -45,41 +42,27 @@ namespace QInstaller {
KeepAliveObject::KeepAliveObject()
: m_timer(0)
- , m_quit(false)
+ , m_socket(0)
{
}
void KeepAliveObject::start()
{
m_timer = new QTimer(this);
- connect(m_timer, SIGNAL(timeout()), this, SLOT(onTimeout()));
- m_timer->start(5000);
-}
+ m_socket = new QLocalSocket(this);
-void KeepAliveObject::finish()
-{
- m_quit = true;
-}
+ connect(m_timer, &QTimer::timeout, [this]() {
+ if (m_socket->state() != QLocalSocket::UnconnectedState)
+ return;
+ m_socket->connectToServer(RemoteClient::instance().socketName());
+ });
-void KeepAliveObject::onTimeout()
-{
- m_timer->stop();
- {
- // Try to connect to the privileged running server. If we succeed the server side
- // watchdog gets restarted and the server keeps running for another 30 seconds.
- QLocalSocket socket;
- socket.connectToServer(RemoteClient::instance().socketName());
+ connect(m_socket, &QLocalSocket::connected, [this]() {
+ m_socket->close();
+ });
- QElapsedTimer stopWatch;
- stopWatch.start();
- while ((socket.state() == QLocalSocket::ConnectingState)
- && (stopWatch.elapsed() < 10000) && (!m_quit)) {
- if ((stopWatch.elapsed() % 2500) == 0)
- QCoreApplication::processEvents();
- }
- }
- if (!m_quit)
- m_timer->start(5000);
+ m_timer->setInterval(5000);
+ m_timer->start();
}
} // namespace QInstaller
diff --git a/src/libs/installer/keepaliveobject.h b/src/libs/installer/keepaliveobject.h
index eca6819e2..534fc1f7c 100644
--- a/src/libs/installer/keepaliveobject.h
+++ b/src/libs/installer/keepaliveobject.h
@@ -39,6 +39,7 @@
QT_BEGIN_NAMESPACE
class QTimer;
+class QLocalSocket;
QT_END_NAMESPACE
namespace QInstaller {
@@ -53,14 +54,10 @@ public:
public slots:
void start();
- void finish();
-
-private slots:
- void onTimeout();
private:
QTimer *m_timer;
- QAtomicInt m_quit;
+ QLocalSocket *m_socket;
};
} // namespace QInstaller
diff --git a/src/libs/installer/remoteclient_p.h b/src/libs/installer/remoteclient_p.h
index aed18d56e..9baef7aa9 100644
--- a/src/libs/installer/remoteclient_p.h
+++ b/src/libs/installer/remoteclient_p.h
@@ -65,7 +65,6 @@ public:
, m_active(false)
, m_key(QLatin1String(Protocol::DefaultAuthorizationKey))
, m_mode(Protocol::Mode::Debug)
- , m_object(0)
{
m_thread.setObjectName(QLatin1String("KeepAlive"));
}
@@ -77,10 +76,6 @@ public:
void shutdown()
{
- if (m_object)
- m_object->finish();
- m_object = 0;
-
m_thread.quit();
m_thread.wait();
maybeStopServer();
@@ -101,15 +96,11 @@ public:
.arg(socketName)
.arg(key);
- if (!m_object) {
- m_object = new KeepAliveObject;
- m_object->moveToThread(&m_thread);
- QObject::connect(&m_thread, SIGNAL(started()), m_object, SLOT(start()));
- QObject::connect(&m_thread, SIGNAL(finished()), m_object, SLOT(deleteLater()));
- m_thread.start();
- } else {
- Q_ASSERT_X(false, Q_FUNC_INFO, "Keep alive thread already started.");
- }
+ KeepAliveObject *object = new KeepAliveObject;
+ object->moveToThread(&m_thread);
+ QObject::connect(&m_thread, &QThread::started, object, &KeepAliveObject::start);
+ QObject::connect(&m_thread, &QThread::finished, object, &QObject::deleteLater);
+ m_thread.start();
} else if (mode == Protocol::Mode::Debug) {
// To be able to debug the client-server connection start and stop the server manually,
// e.g. installer --startserver DEBUG.
@@ -194,7 +185,6 @@ private:
QString m_key;
QThread m_thread;
Protocol::Mode m_mode;
- KeepAliveObject *m_object;
};
} // namespace QInstaller