summaryrefslogtreecommitdiffstats
path: root/src/libs
diff options
context:
space:
mode:
authorkh <karsten.heimrich@theqtcompany.com>2014-11-24 17:39:06 +0100
committerKarsten Heimrich <karsten.heimrich@theqtcompany.com>2014-11-26 14:49:23 +0100
commit64d49f097f25dd019345a7e913e1c4cf8188e168 (patch)
treeda6670298b59bd04db7d1f5dc62a9ceb79082b7b /src/libs
parentd18b9696e573aa7b3f38784f6c5764b9fe6fd81b (diff)
Implement a way to start the server in debug mode and API cleanup.
1; Passing debug as first argument to the starting server does not start the server side so the server keeps running in an endless loop. This makes it far easier to attach a debugger. 2; API cleanup and unify init function to take port, key, and mode. The address was never able to be changed anyway, so stop passing them around. Change-Id: I2a847f009ed1557a5e136e2b0006de5c62426da2 Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
Diffstat (limited to 'src/libs')
-rw-r--r--src/libs/installer/packagemanagercore.cpp8
-rw-r--r--src/libs/installer/packagemanagercore.h6
-rw-r--r--src/libs/installer/packagemanagercore_p.cpp12
-rw-r--r--src/libs/installer/protocol.h4
-rw-r--r--src/libs/installer/remoteclient.cpp43
-rw-r--r--src/libs/installer/remoteclient.h8
-rw-r--r--src/libs/installer/remoteclient_p.h34
-rw-r--r--src/libs/installer/remoteserver.cpp44
-rw-r--r--src/libs/installer/remoteserver.h4
9 files changed, 76 insertions, 87 deletions
diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp
index 494b8b486..abff0bafa 100644
--- a/src/libs/installer/packagemanagercore.cpp
+++ b/src/libs/installer/packagemanagercore.cpp
@@ -690,15 +690,19 @@ PackageManagerCore::PackageManagerCore()
qRegisterMetaType<QInstaller::PackageManagerCore::WizardPage>("QInstaller::PackageManagerCore::WizardPage");
}
-PackageManagerCore::PackageManagerCore(qint64 magicmaker, const QList<OperationBlob> &operations)
+PackageManagerCore::PackageManagerCore(qint64 magicmaker, const QList<OperationBlob> &operations,
+ quint16 port, const QString &key, Protocol::Mode mode)
: d(new PackageManagerCorePrivate(this, magicmaker, operations))
{
Repository::registerMetaType(); // register, cause we stream the type as QVariant
qRegisterMetaType<QInstaller::PackageManagerCore::Status>("QInstaller::PackageManagerCore::Status");
qRegisterMetaType<QInstaller::PackageManagerCore::WizardPage>("QInstaller::PackageManagerCore::WizardPage");
- d->initialize(QHash<QString, QString>());
+ // Creates and initializes a remote client, makes us get admin rights for QFile, QSettings
+ // and QProcess operations. Init needs to called to set the server side authorization key.
+ RemoteClient::instance().init(port, key, mode, Protocol::StartAs::SuperUser);
+ d->initialize(QHash<QString, QString>());
//
// Sanity check to detect a broken installations with missing operations.
diff --git a/src/libs/installer/packagemanagercore.h b/src/libs/installer/packagemanagercore.h
index 10e39f0f8..df7ac5557 100644
--- a/src/libs/installer/packagemanagercore.h
+++ b/src/libs/installer/packagemanagercore.h
@@ -35,6 +35,7 @@
#define PACKAGEMANAGERCORE_H
#include "binaryformat.h"
+#include "protocol.h"
#include "repository.h"
#include "qinstallerglobal.h"
@@ -64,7 +65,10 @@ class INSTALLER_EXPORT PackageManagerCore : public QObject
public:
PackageManagerCore();
- PackageManagerCore(qint64 magicmaker, const QList<OperationBlob> &ops);
+ PackageManagerCore(qint64 magicmaker, const QList<OperationBlob> &ops,
+ quint16 port = Protocol::DefaultPort,
+ const QString &key = QLatin1String(Protocol::DefaultAuthorizationKey),
+ Protocol::Mode mode = Protocol::Mode::Production);
~PackageManagerCore();
// status
diff --git a/src/libs/installer/packagemanagercore_p.cpp b/src/libs/installer/packagemanagercore_p.cpp
index 3c1c8b674..45a41d301 100644
--- a/src/libs/installer/packagemanagercore_p.cpp
+++ b/src/libs/installer/packagemanagercore_p.cpp
@@ -50,7 +50,6 @@
#include "qprocesswrapper.h"
#include "protocol.h"
#include "qsettingswrapper.h"
-#include "remoteclient.h"
#include "installercalculator.h"
#include "uninstallercalculator.h"
@@ -242,17 +241,6 @@ PackageManagerCorePrivate::PackageManagerCorePrivate(PackageManagerCore *core, q
m_performedOperationsOld.append(op.take());
}
- // Creates and initializes a remote client, makes us get admin rights for QFile, QSettings
- // and QProcess operations. Init needs to called before we can get the real authorization key.
- int port = 30000 + qrand() % 1000;
- RemoteClient::instance().init(port,
- QHostAddress(QLatin1String(Protocol::DefaultHostAddress)), Protocol::Mode::Release);
- RemoteClient::instance().setStartServerCommand(QCoreApplication::applicationFilePath(),
- QStringList() << QLatin1String("--startserver") << QString::fromLatin1("%1,%2")
- .arg(port)
- .arg(RemoteClient::instance().authorizationKey()),
- Protocol::StartAs::SuperUser);
-
connect(this, SIGNAL(installationStarted()), m_core, SIGNAL(installationStarted()));
connect(this, SIGNAL(installationFinished()), m_core, SIGNAL(installationFinished()));
connect(this, SIGNAL(uninstallationStarted()), m_core, SIGNAL(uninstallationStarted()));
diff --git a/src/libs/installer/protocol.h b/src/libs/installer/protocol.h
index 2aee34769..a4e58774f 100644
--- a/src/libs/installer/protocol.h
+++ b/src/libs/installer/protocol.h
@@ -40,8 +40,10 @@ namespace Protocol {
enum struct Mode {
Debug,
- Release
+ Production
};
+const char ModeDebug[] = "DEBUG";
+const char ModeProduction[] = "PRODUCTION";
enum struct StartAs {
User,
diff --git a/src/libs/installer/remoteclient.cpp b/src/libs/installer/remoteclient.cpp
index ce317847f..d8c8478b6 100644
--- a/src/libs/installer/remoteclient.cpp
+++ b/src/libs/installer/remoteclient.cpp
@@ -39,14 +39,6 @@
namespace QInstaller {
-class RemoteClientGuard
-{
-public:
- RemoteClient client;
-};
-Q_GLOBAL_STATIC(RemoteClientGuard, remoteClientGuard);
-static RemoteClientGuard *gGuard = remoteClientGuard();
-
RemoteClient::RemoteClient()
: d_ptr(new RemoteClientPrivate(this))
{
@@ -60,7 +52,8 @@ RemoteClient::~RemoteClient()
RemoteClient &RemoteClient::instance()
{
- return gGuard->client;
+ static RemoteClient instance;
+ return instance;
}
quint16 RemoteClient::port() const
@@ -81,18 +74,15 @@ QString RemoteClient::authorizationKey() const
return d->m_key;
}
-void RemoteClient::setAuthorizationKey(const QString &key)
-{
- Q_D(RemoteClient);
- if (d->m_serverStarted)
- return;
- d->m_key = key;
-}
-
-void RemoteClient::init(quint16 port, const QHostAddress &address, Protocol::Mode mode)
+/*!
+ Initializes the client with \a port, the port to write to, with \a key, the key the client
+ sends to authenticate with the server, \a mode and \a startAs.
+*/
+void RemoteClient::init(quint16 port, const QString &key, Protocol::Mode mode,
+ Protocol::StartAs startAs)
{
Q_D(RemoteClient);
- d->init(port, address, mode);
+ d->init(port, key, mode, startAs);
}
void RemoteClient::shutdown()
@@ -155,19 +145,4 @@ void RemoteClient::setActive(bool active)
}
}
-void RemoteClient::setStartServerCommand(const QString &command, Protocol::StartAs startAs)
-{
- setStartServerCommand(command, QStringList(), startAs);
-}
-
-void RemoteClient::setStartServerCommand(const QString &command, const QStringList &arguments,
- Protocol::StartAs startAs)
-{
- Q_D(RemoteClient);
- d->maybeStopServer();
- d->m_serverCommand = command;
- d->m_serverArguments = arguments;
- d->m_startServerAs = startAs;
-}
-
} // namespace QInstaller
diff --git a/src/libs/installer/remoteclient.h b/src/libs/installer/remoteclient.h
index f4bec7534..f8e9faf86 100644
--- a/src/libs/installer/remoteclient.h
+++ b/src/libs/installer/remoteclient.h
@@ -54,11 +54,10 @@ class INSTALLER_EXPORT RemoteClient : public QObject
Q_OBJECT
Q_DISABLE_COPY(RemoteClient)
Q_DECLARE_PRIVATE(RemoteClient)
- friend class RemoteClientGuard;
public:
static RemoteClient &instance();
- void init(quint16 port, const QHostAddress &address, Protocol::Mode mode);
+ void init(quint16 port, const QString &key, Protocol::Mode mode, Protocol::StartAs startAs);
void shutdown();
bool connect(QTcpSocket *socket) const;
@@ -66,15 +65,10 @@ public:
quint16 port() const;
QHostAddress address() const;
QString authorizationKey() const;
- void setAuthorizationKey(const QString &key);
bool isActive() const;
void setActive(bool active);
- void setStartServerCommand(const QString &command, Protocol::StartAs startAs);
- void setStartServerCommand(const QString &command, const QStringList &arguments,
- Protocol::StartAs start);
-
private:
RemoteClient();
~RemoteClient();
diff --git a/src/libs/installer/remoteclient_p.h b/src/libs/installer/remoteclient_p.h
index 6405b5fe8..fdcfabb64 100644
--- a/src/libs/installer/remoteclient_p.h
+++ b/src/libs/installer/remoteclient_p.h
@@ -48,7 +48,6 @@
#include <QTcpSocket>
#include <QThread>
#include <QTimer>
-#include <QUuid>
namespace QInstaller {
@@ -142,17 +141,21 @@ public:
m_thread.wait();
}
- void init(quint16 port, const QHostAddress &address, Protocol::Mode mode)
+ void init(quint16 port, const QString &key, Protocol::Mode mode, Protocol::StartAs startAs)
{
- m_port = port;
m_mode = mode;
- m_address = address;
+ if (mode == Protocol::Mode::Production) {
+ m_key = key;
+ m_port = port;
+ m_mode = mode;
+ m_startServerAs = startAs;
+ m_serverCommand = QCoreApplication::applicationFilePath();
+ m_serverArguments = QStringList() << QLatin1String("--startserver")
+ << QString::fromLatin1("%1,%2,%3")
+ .arg(QLatin1String(Protocol::ModeProduction))
+ .arg(port)
+ .arg(key);
- if (mode == Protocol::Mode::Debug) {
- m_active = true;
- m_serverStarted = true;
- } else if (m_mode == Protocol::Mode::Release) {
- m_key = QUuid::createUuid().toString();
if (!m_object) {
m_object = new KeepAliveObject;
m_object->moveToThread(&m_thread);
@@ -162,13 +165,17 @@ public:
} else {
Q_ASSERT_X(false, Q_FUNC_INFO, "Keep alive thread already started.");
}
- } else {
- Q_ASSERT_X(false, Q_FUNC_INFO, "RemoteClient mode not set properly.");
+ } 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. The server is listening on localhost:39999 then.
}
}
void maybeStartServer() {
- if (m_serverStarted || m_serverCommand.isEmpty())
+ if (m_mode == Protocol::Mode::Debug)
+ m_serverStarted = true; // we expect the server to be started by the developer
+
+ if (m_serverStarted)
return;
const QMutexLocker ml(&m_mutex);
@@ -218,6 +225,9 @@ public:
void maybeStopServer()
{
+ if (m_mode == Protocol::Mode::Debug)
+ m_serverStarted = false; // we never started the server in debug mode
+
if (!m_serverStarted)
return;
diff --git a/src/libs/installer/remoteserver.cpp b/src/libs/installer/remoteserver.cpp
index f47cb30ab..c3ec93c85 100644
--- a/src/libs/installer/remoteserver.cpp
+++ b/src/libs/installer/remoteserver.cpp
@@ -39,6 +39,9 @@
namespace QInstaller {
+/*!
+ Constructs an remote server object with \a parent.
+*/
RemoteServer::RemoteServer(QObject *parent)
: QObject(parent)
, d_ptr(new RemoteServerPrivate(this))
@@ -46,6 +49,9 @@ RemoteServer::RemoteServer(QObject *parent)
Repository::registerMetaType(); // register, cause we stream the type as QVariant
}
+/*!
+ Destroys the remote server object.
+*/
RemoteServer::~RemoteServer()
{
Q_D(RemoteServer);
@@ -54,8 +60,10 @@ RemoteServer::~RemoteServer()
}
/*!
- Starts the server. If started in debug mode, the watchdog that kills the server after
- 30 seconds without usage is not started. The authorization key is set to "DebugMode".
+ Starts the server.
+
+ \note If running in debug mode, the timer that kills the server after 30 seconds without
+ usage is not started, so the server runs in an endless loop.
*/
void RemoteServer::start()
{
@@ -69,36 +77,40 @@ void RemoteServer::start()
connect (d->m_tcpServer, SIGNAL(newIncomingConnection()), this, SLOT(restartWatchdog()));
d->m_thread.start();
- if (d->m_mode == Protocol::Mode::Release) {
+ if (d->m_mode == Protocol::Mode::Production) {
connect(d->m_watchdog.data(), SIGNAL(timeout()), this, SLOT(deleteLater()));
d->m_watchdog->start();
}
}
/*!
- Returns the authorization key.
+ Initializes the server with \a port, the port to listen on, with \a key, the key the client
+ needs to send to authenticate with the server, and \a mode.
*/
-QString RemoteServer::authorizationKey() const
+void RemoteServer::init(quint16 port, const QString &key, Protocol::Mode mode)
{
- Q_D(const RemoteServer);
- return d->m_key;
+ Q_D(RemoteServer);
+ d->m_port = port;
+ d->m_key = key;
+ d->m_mode = mode;
}
/*!
- Sets the authorization key \a authorizationKey this server is asking the clients for.
+ Returns the port the server is listening on.
*/
-void RemoteServer::setAuthorizationKey(const QString &authorizationKey)
+quint16 RemoteServer::port() const
{
- Q_D(RemoteServer);
- d->m_key = authorizationKey;
+ Q_D(const RemoteServer);
+ return d->m_port;
}
-void RemoteServer::init(quint16 port, const QHostAddress &address, Protocol::Mode mode)
+/*!
+ Returns the authorization key.
+*/
+QString RemoteServer::authorizationKey() const
{
- Q_D(RemoteServer);
- d->m_port = port;
- d->m_address = address;
- d->m_mode = mode;
+ Q_D(const RemoteServer);
+ return d->m_key;
}
/*!
diff --git a/src/libs/installer/remoteserver.h b/src/libs/installer/remoteserver.h
index c4235a178..9a4fbdd34 100644
--- a/src/libs/installer/remoteserver.h
+++ b/src/libs/installer/remoteserver.h
@@ -59,10 +59,10 @@ public:
~RemoteServer();
void start();
- void init(quint16 port, const QHostAddress &address, Protocol::Mode mode);
+ void init(quint16 port, const QString &authorizationKey, Protocol::Mode mode);
+ quint16 port() const;
QString authorizationKey() const;
- void setAuthorizationKey(const QString &key);
private slots:
void restartWatchdog();