summaryrefslogtreecommitdiffstats
path: root/src/sdk
diff options
context:
space:
mode:
Diffstat (limited to 'src/sdk')
-rw-r--r--src/sdk/commandlineparser.cpp9
-rw-r--r--src/sdk/constants.h1
-rw-r--r--src/sdk/installerbase.cpp21
-rw-r--r--src/sdk/main.cpp37
4 files changed, 49 insertions, 19 deletions
diff --git a/src/sdk/commandlineparser.cpp b/src/sdk/commandlineparser.cpp
index 23d903bd3..9c4200b3e 100644
--- a/src/sdk/commandlineparser.cpp
+++ b/src/sdk/commandlineparser.cpp
@@ -94,7 +94,14 @@ CommandLineParser::CommandLineParser()
"https://, http:// or ftp://."), QLatin1String("URI,...")));
m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::StartServer),
- QLatin1String("Starts the application as headless process waiting for commands to execute."),
+ QLatin1String("Starts the application as headless process waiting for commands to execute."
+ " Mode can be DEBUG or PRODUCTION. In DEBUG mode, the option values can be omitted."
+ "Note: The server will not shutdown on his own, you need to quit the process by hand."),
+ QLatin1String("mode,port,key")));
+ m_parser.addOption(QCommandLineOption(QLatin1String(CommandLineOptions::StartClient),
+ QString::fromLatin1("Starts the application to debug the client-server communication. If "
+ "a value is omitted, the client will use a default instead. Note: The server process is "
+ "not started by the client application in that case, you need to start it on your own."),
QLatin1String("port,key")));
m_parser.addPositionalArgument(QLatin1String(CommandLineOptions::KeyValue),
diff --git a/src/sdk/constants.h b/src/sdk/constants.h
index 1d4f5b5e8..44fe1f598 100644
--- a/src/sdk/constants.h
+++ b/src/sdk/constants.h
@@ -55,6 +55,7 @@ const char AddRepository[] = "addRepository";
const char AddTmpRepository[] = "addTempRepository";
const char SetTmpRepository[] = "setTempRepository";
const char StartServer[] = "startserver";
+const char StartClient[] = "startclient";
} // namespace CommandLineOptions
diff --git a/src/sdk/installerbase.cpp b/src/sdk/installerbase.cpp
index 306b37223..6253f3e25 100644
--- a/src/sdk/installerbase.cpp
+++ b/src/sdk/installerbase.cpp
@@ -47,6 +47,7 @@
#include <packagemanagercore.h>
#include <packagemanagerproxyfactory.h>
#include <qprocesswrapper.h>
+#include <protocol.h>
#include <productkeycheck.h>
#include <settings.h>
#include <utils.h>
@@ -57,6 +58,7 @@
#include <QDirIterator>
#include <QTemporaryFile>
#include <QTranslator>
+#include <QUuid>
InstallerBase::InstallerBase(int &argc, char *argv[])
: SDKApp<QApplication>(argc, argv)
@@ -109,8 +111,22 @@ int InstallerBase::run()
qDebug() << "Arguments: " << arguments().join(QLatin1String(", ")).toUtf8().constData();
}
+ CommandLineParser parser;
+ parser.parse(arguments());
+
SDKApp::registerMetaResources(manager.collectionByName("QResources"));
- m_core = new QInstaller::PackageManagerCore(magicMarker, oldOperations);
+ if (parser.isSet(QLatin1String(CommandLineOptions::StartClient))) {
+ const QStringList arguments = parser.value(QLatin1String(CommandLineOptions::StartServer))
+ .split(QLatin1Char(','), QString::SkipEmptyParts);
+ m_core = new QInstaller::PackageManagerCore(magicMarker, oldOperations, QString(arguments
+ .value(0, QString::number(QInstaller::Protocol::DefaultPort))).toInt(),
+ arguments.value(1, QLatin1String(QInstaller::Protocol::DefaultAuthorizationKey)),
+ QInstaller::Protocol::Mode::Debug);
+ } else {
+ m_core = new QInstaller::PackageManagerCore(magicMarker, oldOperations,
+ 30000 + qrand() % 100, QUuid::createUuid().toString());
+ }
+
{
using namespace QInstaller;
ProductKeyCheck::instance()->init(m_core);
@@ -120,9 +136,6 @@ int InstallerBase::run()
if (QInstaller::isVerbose())
dumpResourceTree();
- CommandLineParser parser;
- parser.parse(arguments());
-
QString controlScript;
if (parser.isSet(QLatin1String(CommandLineOptions::Script))) {
controlScript = parser.value(QLatin1String(CommandLineOptions::Script));
diff --git a/src/sdk/main.cpp b/src/sdk/main.cpp
index a5565fe5a..e67ee6662 100644
--- a/src/sdk/main.cpp
+++ b/src/sdk/main.cpp
@@ -116,30 +116,39 @@ int main(int argc, char *argv[])
}
if (parser.isSet(QLatin1String(CommandLineOptions::StartServer))) {
- const QString argument = parser.value(QLatin1String(CommandLineOptions::StartServer));
- const QString port = argument.section(QLatin1Char(','), 0, 0);
- const QString key = argument.section(QLatin1Char(','), 1, 1);
+ const QStringList arguments = parser.value(QLatin1String(CommandLineOptions::StartServer))
+ .split(QLatin1Char(','), QString::SkipEmptyParts);
+
+ QString port, key;
+ const QString mode = arguments.value(0);
+ bool argumentsValid = (mode.compare(QLatin1String(QInstaller::Protocol::ModeDebug),
+ Qt::CaseInsensitive) == 0);
+ if (argumentsValid) {
+ port = arguments.value(1, QString::number(QInstaller::Protocol::DefaultPort));
+ key = arguments.value(2, QLatin1String(QInstaller::Protocol::DefaultAuthorizationKey));
+ } else {
+ port = arguments.value(1);
+ key = arguments.value(2);
+ }
- QStringList missing;
- if (port.isEmpty())
- missing << QLatin1String("Port");
- if (key.isEmpty())
- missing << QLatin1String("Key");
+ const bool production = (mode.compare(QLatin1String(QInstaller::Protocol::ModeProduction),
+ Qt::CaseInsensitive) == 0);
+ if (production)
+ argumentsValid = (!key.isEmpty()) && (!port.isEmpty());
SDKApp<QCoreApplication> app(argc, argv);
- if (missing.count()) {
+ if (!argumentsValid) {
Console c;
- std::cerr << qPrintable(QString::fromLatin1("Missing argument(s) for option "
- "'startserver': %2").arg(missing.join(QLatin1String(", ")))) << std::endl;
std::cout << qPrintable(parser.helpText()) << std::endl;
+ std::cerr << "Wrong argument(s) for option --startserver." << std::endl;
return EXIT_FAILURE;
}
QInstaller::RemoteServer *server = new QInstaller::RemoteServer;
QObject::connect(server, SIGNAL(destroyed()), &app, SLOT(quit()));
- server->init(port.toInt(), QHostAddress(QLatin1String(QInstaller::Protocol
- ::DefaultHostAddress)), QInstaller::Protocol::Mode::Release);
- server->setAuthorizationKey(key);
+ server->init(port.toInt(), key, (production ? QInstaller::Protocol::Mode::Production
+ : QInstaller::Protocol::Mode::Debug));
+
server->start();
return app.exec();
}