diff options
author | Robert Griebl <robert.griebl@qt.io> | 2022-06-29 16:26:21 +0200 |
---|---|---|
committer | Robert Griebl <robert.griebl@qt.io> | 2022-06-30 14:26:17 +0200 |
commit | 8f4fbe0665f7e83c89364e44711f01c4408ff59f (patch) | |
tree | 2eee02b3964f69de3f0114db0aaadc5eb2e5b5aa /src/tools/controller/controller.cpp | |
parent | b6eca2f33af9b3b1721d367c0fdea60f18cb33d7 (diff) | |
download | qtapplicationmanager-8f4fbe0665f7e83c89364e44711f01c4408ff59f.tar.gz |
Add support for managing multiple instances from appman-controller
Added an optional instance-id, which can be set via command line option
or via am-config.yaml in the appman process.
appman-controller also gained a new option --instance-id to address
the given instance, instead of the default, unnamed one.
Change-Id: I582d0ea69ed0697ee9ac7353725f93c50df05e34
Pick-to: 6.4 5.15
Fixes: AUTOSUITE-1678
Reviewed-by: Dominik Holland <dominik.holland@qt.io>
Diffstat (limited to 'src/tools/controller/controller.cpp')
-rw-r--r-- | src/tools/controller/controller.cpp | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/src/tools/controller/controller.cpp b/src/tools/controller/controller.cpp index 2716df3e..2fade30d 100644 --- a/src/tools/controller/controller.cpp +++ b/src/tools/controller/controller.cpp @@ -14,6 +14,7 @@ #include <QDBusPendingReply> #include <QDBusError> #include <QMetaObject> +#include <QStringBuilder> #include <functional> @@ -39,6 +40,13 @@ public: registerDBusTypes(); } + void setInstanceId(const QString &instanceId) + { + m_instanceId = instanceId; + if (!m_instanceId.isEmpty()) + m_instanceId.append(u'-'); + } + void connectToManager() Q_DECL_NOEXCEPT_EXPR(false) { if (m_manager) @@ -62,7 +70,7 @@ private: { QDBusConnection conn(iface); - QFile f(QDir::temp().absoluteFilePath(QString(qSL("%1.dbus")).arg(iface))); + QFile f(QDir::temp().absoluteFilePath(m_instanceId % QString(qSL("%1.dbus")).arg(iface))); QString dbus; if (f.open(QFile::ReadOnly)) { dbus = QString::fromUtf8(f.readAll()); @@ -100,6 +108,7 @@ public: private: IoQtPackageManagerInterface *m_packager = nullptr; IoQtApplicationManagerInterface *m_manager = nullptr; + QString m_instanceId; }; static class DBus dbus; @@ -120,7 +129,8 @@ enum Command { ListInstallationTasks, CancelInstallationTask, ListInstallationLocations, - ShowInstallationLocation + ShowInstallationLocation, + ListInstances, }; // REMEMBER to update the completion file util/bash/appman-prompt, if you apply changes below! @@ -142,7 +152,8 @@ static struct { { ListInstallationTasks, "list-installation-tasks", "List all active installation tasks." }, { CancelInstallationTask, "cancel-installation-task", "Cancel an active installation task." }, { ListInstallationLocations, "list-installation-locations", "List all installaton locations." }, - { ShowInstallationLocation, "show-installation-location", "Show details for installation location." } + { ShowInstallationLocation, "show-installation-location", "Show details for installation location." }, + { ListInstances, "list-instances", "List all named application manager instances." }, }; static Command command(QCommandLineParser &clp) @@ -176,6 +187,7 @@ static void listInstallationTasks() Q_DECL_NOEXCEPT_EXPR(false); static void cancelInstallationTask(bool all, const QString &taskId) Q_DECL_NOEXCEPT_EXPR(false); static void listInstallationLocations() Q_DECL_NOEXCEPT_EXPR(false); static void showInstallationLocation(bool asJson = false) Q_DECL_NOEXCEPT_EXPR(false); +static void listInstances() Q_DECL_NOEXCEPT_EXPR(false); class ThrowingApplication : public QCoreApplication // clazy:exclude=missing-qobject-macro { @@ -232,10 +244,11 @@ int main(int argc, char *argv[]) } desc += "\nMore information about each command can be obtained by running\n" \ - " appman-controller <command> --help"; + " appman-controller <command> --help"; QCommandLineParser clp; + clp.addOption({ { qSL("instance-id") }, qSL("Connect to the named instance."), qSL("instance-id") }); clp.addHelpOption(); clp.addVersionOption(); @@ -250,6 +263,8 @@ int main(int argc, char *argv[]) clp.parse(QCoreApplication::arguments()); clp.setOptionsAfterPositionalArgumentsMode(QCommandLineParser::ParseAsOptions); + dbus.setInstanceId(clp.value(qSL("instance-id"))); + // REMEMBER to update the completion file util/bash/appman-prompt, if you apply changes below! try { switch (command(clp)) { @@ -450,6 +465,11 @@ int main(int argc, char *argv[]) a.runLater(std::bind(showInstallationLocation, clp.isSet(qSL("json")))); break; + + case ListInstances: + clp.process(a); + a.runLater(listInstances); + break; } int result = a.exec(); @@ -871,3 +891,24 @@ void showInstallationLocation(bool asJson) Q_DECL_NOEXCEPT_EXPR(false) : QtYaml::yamlFromVariantDocuments({ installationLocation }).constData()); qApp->quit(); } + +void listInstances() +{ + QString dir = QDir::temp().absolutePath() % u"/"; + QString suffix = qSL("io.qt.ApplicationManager.dbus"); + + QDirIterator dit(dir, { u"*" % suffix }); + while (dit.hasNext()) { + QByteArray name = dit.next().toLocal8Bit(); + name.chop(suffix.length()); + name = name.mid(dir.length()); + if (name.isEmpty()) { + name = "(no instance id)"; + } else { + name.chop(1); // remove the '-' separator + name = '"' % name % '"'; + } + fprintf(stdout, "%s\n", name.constData()); + } + qApp->quit(); +} |