From 64d49f097f25dd019345a7e913e1c4cf8188e168 Mon Sep 17 00:00:00 2001 From: kh Date: Mon, 24 Nov 2014 17:39:06 +0100 Subject: 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 --- src/sdk/commandlineparser.cpp | 9 ++++++++- src/sdk/constants.h | 1 + src/sdk/installerbase.cpp | 21 +++++++++++++++++---- src/sdk/main.cpp | 37 +++++++++++++++++++++++-------------- 4 files changed, 49 insertions(+), 19 deletions(-) (limited to 'src/sdk') 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 #include #include +#include #include #include #include @@ -57,6 +58,7 @@ #include #include #include +#include InstallerBase::InstallerBase(int &argc, char *argv[]) : SDKApp(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 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(); } -- cgit v1.2.3