diff options
author | kh <karsten.heimrich@theqtcompany.com> | 2014-11-27 14:30:56 +0100 |
---|---|---|
committer | Kai Koehne <kai.koehne@theqtcompany.com> | 2014-12-02 13:28:42 +0100 |
commit | d872d37e840d63d338ece1eb684aa9cd4b0d9fbc (patch) | |
tree | 58bfcdc1572c20ccbfea00e51e29d38fbd1b4086 /src/libs/installer/keepaliveobject.cpp | |
parent | 02698bfb3d6e2a0b403c360805c40605263d80f2 (diff) |
Move the KeepAliveObject class into its own source files.
Change-Id: Iaf8f397bdcaa4afb5432b826aa3fe238d54193c0
Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
Reviewed-by: Niels Weber <niels.weber@theqtcompany.com>
Diffstat (limited to 'src/libs/installer/keepaliveobject.cpp')
-rw-r--r-- | src/libs/installer/keepaliveobject.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/libs/installer/keepaliveobject.cpp b/src/libs/installer/keepaliveobject.cpp new file mode 100644 index 000000000..b9e07f333 --- /dev/null +++ b/src/libs/installer/keepaliveobject.cpp @@ -0,0 +1,85 @@ +/************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Installer Framework. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** +** $QT_END_LICENSE$ +** +**************************************************************************/ + +#include "keepaliveobject.h" +#include "remoteclient.h" + +#include <QCoreApplication> +#include <QElapsedTimer> +#include <QHostAddress> +#include <QTcpSocket> +#include <QTimer> + +namespace QInstaller { + +KeepAliveObject::KeepAliveObject() + : m_timer(0) + , m_quit(false) +{ +} + +void KeepAliveObject::start() +{ + m_timer = new QTimer(this); + connect(m_timer, SIGNAL(timeout()), this, SLOT(onTimeout())); + m_timer->start(5000); +} + +void KeepAliveObject::finish() +{ + m_quit = true; +} + +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. + QTcpSocket socket; + socket.connectToHost(RemoteClient::instance().address(), RemoteClient::instance().port()); + + QElapsedTimer stopWatch; + stopWatch.start(); + while ((socket.state() == QAbstractSocket::ConnectingState) + && (stopWatch.elapsed() < 10000) && (!m_quit)) { + if ((stopWatch.elapsed() % 2500) == 0) + QCoreApplication::processEvents(); + } + } + if (!m_quit) + m_timer->start(5000); +} + +} // namespace QInstaller |