summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernd Weimer <bernd.weimer@pelagicore.com>2018-01-11 10:35:46 +0100
committerRobert Griebl <robert.griebl@pelagicore.com>2018-01-15 15:47:16 +0000
commite099f6a81aa35890c2d73daa79b5b79907506599 (patch)
tree05fc929b807d25ef98049b740e8d91aa7d75f7c7
parent6015eb9f14c305375f0ee65d4172f48c7f015f6c (diff)
downloadqtapplicationmanager-e099f6a81aa35890c2d73daa79b5b79907506599.tar.gz
Make installation task state an enumeration
Changed installation task state from string to enumeration. On the DBus interface it is still a string. This brakes backwards compatibility. Change-Id: I2ed9bfcef24d3b578ce84c2eefb7c1d180ccf7de Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
-rw-r--r--doc/configuration.qdoc4
-rw-r--r--src/dbus-lib/applicationinstallerdbuscontextadaptor.cpp14
-rw-r--r--src/installer-lib/applicationinstaller.cpp53
-rw-r--r--src/installer-lib/applicationinstaller.h11
-rw-r--r--src/installer-lib/asynchronoustask.cpp20
-rw-r--r--src/installer-lib/asynchronoustask.h15
-rw-r--r--tests/qml/installer/tst_installer.qml23
7 files changed, 80 insertions, 60 deletions
diff --git a/doc/configuration.qdoc b/doc/configuration.qdoc
index 03479244..d6f01932 100644
--- a/doc/configuration.qdoc
+++ b/doc/configuration.qdoc
@@ -164,8 +164,8 @@ all your imports paths and file references relative to your main config file.
\li int
\li The non-interface key \c registrationDelay within the \c dbus object is an integer value,
which delays the registration of the global D-Bus interfaces by the field's value in
- milli-seconds: the default value of \c -1 will register them synchronously, while \c 0 will
- register them on the first run of the event loop.
+ milli-seconds. Values must be greater than or equal to 0, which is also the default value
+ (in this case registration will be done immediately after the event loop is executing).
\row
\li \b --fullscreen
\br \e ui/fullscreen
diff --git a/src/dbus-lib/applicationinstallerdbuscontextadaptor.cpp b/src/dbus-lib/applicationinstallerdbuscontextadaptor.cpp
index 45023133..14169630 100644
--- a/src/dbus-lib/applicationinstallerdbuscontextadaptor.cpp
+++ b/src/dbus-lib/applicationinstallerdbuscontextadaptor.cpp
@@ -46,8 +46,15 @@
#include "exception.h"
#include "logging.h"
+
QT_BEGIN_NAMESPACE_AM
+static QString taskStateToString(AsynchronousTask::TaskState state)
+{
+ const char *cstr = QMetaEnum::fromType<AsynchronousTask::TaskState>().valueToKey(state);
+ return QString::fromUtf8(cstr);
+}
+
ApplicationInstallerDBusContextAdaptor::ApplicationInstallerDBusContextAdaptor(ApplicationInstaller *ai)
: AbstractDBusContextAdaptor(ai)
{
@@ -82,7 +89,9 @@ ApplicationInstallerAdaptor::ApplicationInstallerAdaptor(QObject *parent)
connect(ai, &ApplicationInstaller::taskStarted,
this, &ApplicationInstallerAdaptor::taskStarted);
connect(ai, &ApplicationInstaller::taskStateChanged,
- this, &ApplicationInstallerAdaptor::taskStateChanged);
+ [this](const QString &taskId, AsynchronousTask::TaskState newState) {
+ emit taskStateChanged(taskId, taskStateToString(newState));
+ });
}
ApplicationInstallerAdaptor::~ApplicationInstallerAdaptor()
@@ -194,6 +203,5 @@ QString ApplicationInstallerAdaptor::startPackageInstallation(const QString &ins
QString ApplicationInstallerAdaptor::taskState(const QString &taskId)
{
AM_AUTHENTICATE_DBUS(QString)
- return ApplicationInstaller::instance()->taskState(taskId);
+ return taskStateToString(ApplicationInstaller::instance()->taskState(taskId));
}
-
diff --git a/src/installer-lib/applicationinstaller.cpp b/src/installer-lib/applicationinstaller.cpp
index f35979e6..02229569 100644
--- a/src/installer-lib/applicationinstaller.cpp
+++ b/src/installer-lib/applicationinstaller.cpp
@@ -75,40 +75,40 @@
\li Task State
\li Description
\row
- \li \c queued
+ \li \c Queued
\li The task was created and is now queued up for execution.
\row
- \li \c executing
+ \li \c Executing
\li The task is being executed.
\row
- \li \c finished
+ \li \c Finished
\li The task was executed successfully.
\row
- \li \c failed
+ \li \c Failed
\li The task failed to execute successfully.
\row
- \li \c awaitingAcknowledge
+ \li \c AwaitingAcknowledge
\li \e{Installation tasks only!} The task is currently halted, waiting for either
acknowledgePackageInstallation() or cancelTask() to continue. See startPackageInstallation()
for more information on the installation workflow.
\row
- \li \c installing
+ \li \c Installing
\li \e{Installation tasks only!} The installation was acknowledged via acknowledgePackageInstallation()
and the final installation phase is now running.
\row
- \li \c cleaningUp
+ \li \c CleaningUp
\li \e{Installation tasks only!} The installation has finished, and previous installations as
well as temporary files are being cleaned up.
\endtable
- The normal workflow for tasks is: \c queued \unicode{0x2192} \c active \unicode{0x2192} \c
- finished. The task can enter the \c failed state at any point though - either by being canceled via
+ The normal workflow for tasks is: \c Queued \unicode{0x2192} \c Executing \unicode{0x2192} \c
+ Finished. The task can enter the \c Failed state at any point though - either by being canceled via
cancelTask() or simply by failing due to an error.
- Installation tasks are a bit more complex due to the acknowledgment: \c queued \unicode{0x2192}
- \c executing \unicode{0x2192} \c awaitingAcknowledge (this state may be skipped if
- acknowledgePackageInstallation() was called already) \unicode{0x2192} \c installing
- \unicode{0x2192} \c cleanup \unicode{0x2192} \c finished. Again, the task can fail at any point.
+ Installation tasks are a bit more complex due to the acknowledgment: \c Queued \unicode{0x2192}
+ \c Executing \unicode{0x2192} \c AwaitingAcknowledge (this state may be skipped if
+ acknowledgePackageInstallation() was called already) \unicode{0x2192} \c Installing
+ \unicode{0x2192} \c Cleanup \unicode{0x2192} \c Finished. Again, the task can fail at any point.
*/
// THIS IS MISSING AN EXAMPLE!
@@ -125,7 +125,7 @@
/*!
\qmlsignal ApplicationInstaller::taskStarted(string taskId)
- This signal is emitted when the task identified by \a taskId enters the \c active state.
+ This signal is emitted when the task identified by \a taskId enters the \c Executing state.
\sa taskStateChanged()
*/
@@ -133,7 +133,7 @@
/*!
\qmlsignal ApplicationInstaller::taskFinished(string taskId)
- This signal is emitted when the task identified by \a taskId enters the \c finished state.
+ This signal is emitted when the task identified by \a taskId enters the \c Finished state.
\sa taskStateChanged()
*/
@@ -141,7 +141,7 @@
/*!
\qmlsignal ApplicationInstaller::taskFailed(string taskId)
- This signal is emitted when the task identified by \a taskId enters the \c failed state.
+ This signal is emitted when the task identified by \a taskId enters the \c Failed state.
\sa taskStateChanged()
*/
@@ -150,8 +150,8 @@
\qmlsignal ApplicationInstaller::taskRequestingInstallationAcknowledge(string taskId, object application)
This signal is emitted when the installation task identified by \a taskId has received enough
- meta-data to be able to emit this signal. The task may be in either \c executing or \c
- awaitingAcknowledge state.
+ meta-data to be able to emit this signal. The task may be in either \c Executing or \c
+ AwaitingAcknowledge state.
The contents of the package's manifest file are supplied via \a application as a JavaScript object.
Please see the \l {ApplicationManager Roles}{role names} for the expected object fields.
@@ -211,6 +211,7 @@ ApplicationInstaller *ApplicationInstaller::createInstance(const QVector<Install
qFatal("ApplicationInstaller::createInstance() was called a second time.");
qRegisterMetaType<AsynchronousTask *>();
+ qRegisterMetaType<AsynchronousTask::TaskState>();
if (Q_UNLIKELY(!manifestDir.exists())) {
if (error)
@@ -737,23 +738,23 @@ QString ApplicationInstaller::removePackage(const QString &id, bool keepDocument
/*!
- \qmlmethod string ApplicationInstaller::taskState(string taskId)
+ \qmlmethod enumeration ApplicationInstaller::taskState(string taskId)
- Returns a string describing the current state of the installation task identified by \a taskId.
+ Returns the current state of the installation task identified by \a taskId.
\l {TaskStates}{See here} for a list of valid task states.
- Returns an empty string if the \a taskId is invalid.
+ Returns \c ApplicationInstaller.Invalid if the \a taskId is invalid.
*/
-QString ApplicationInstaller::taskState(const QString &taskId)
+AsynchronousTask::TaskState ApplicationInstaller::taskState(const QString &taskId)
{
auto allTasks = d->taskQueue;
allTasks.append(d->activeTask);
for (const AsynchronousTask *task : qAsConst(allTasks)) {
if (task && (task->id() == taskId))
- return AsynchronousTask::stateToString(task->state());
+ return task->state();
}
- return QString();
+ return AsynchronousTask::Invalid;
}
/*!
@@ -1122,8 +1123,8 @@ void ApplicationInstaller::executeNextTask()
emit taskStarted(task->id());
});
- connect(task, &AsynchronousTask::stateChanged, this, [this, task](AsynchronousTask::State newState) {
- emit taskStateChanged(task->id(), AsynchronousTask::stateToString(newState));
+ connect(task, &AsynchronousTask::stateChanged, this, [this, task](AsynchronousTask::TaskState newState) {
+ emit taskStateChanged(task->id(), newState);
});
connect(task, &AsynchronousTask::progress, this, [this, task](qreal p) {
diff --git a/src/installer-lib/applicationinstaller.h b/src/installer-lib/applicationinstaller.h
index 08fc6a39..f6d2ced3 100644
--- a/src/installer-lib/applicationinstaller.h
+++ b/src/installer-lib/applicationinstaller.h
@@ -48,6 +48,7 @@
#include <QDir>
#include <QtAppManCommon/error.h>
#include <QtAppManInstaller/installationlocation.h>
+#include <QtAppManInstaller/asynchronoustask.h>
QT_FORWARD_DECLARE_CLASS(QQmlEngine)
QT_FORWARD_DECLARE_CLASS(QJSEngine)
@@ -56,7 +57,6 @@ QT_BEGIN_NAMESPACE_AM
class ApplicationManager;
class ApplicationInstallerPrivate;
-class AsynchronousTask;
class SudoClient;
@@ -75,6 +75,8 @@ class ApplicationInstaller : public QObject
public:
+ Q_ENUMS(QT_PREPEND_NAMESPACE_AM(AsynchronousTask::TaskState))
+
~ApplicationInstaller();
static ApplicationInstaller *createInstance(const QVector<InstallationLocation> &installationLocations,
const QDir &manifestDir, const QDir &imageMountDir,
@@ -117,7 +119,7 @@ public:
Q_SCRIPTABLE void acknowledgePackageInstallation(const QString &taskId);
Q_SCRIPTABLE QString removePackage(const QString &id, bool keepDocuments, bool force = false);
- Q_SCRIPTABLE QString taskState(const QString &taskId);
+ Q_SCRIPTABLE AsynchronousTask::TaskState taskState(const QString &taskId);
Q_SCRIPTABLE QString taskApplicationId(const QString &taskId);
Q_SCRIPTABLE bool cancelTask(const QString &taskId);
@@ -139,7 +141,8 @@ signals:
Q_SCRIPTABLE void taskProgressChanged(const QString &taskId, qreal progress);
Q_SCRIPTABLE void taskFinished(const QString &taskId);
Q_SCRIPTABLE void taskFailed(const QString &taskId, int errorCode, const QString &errorString);
- Q_SCRIPTABLE void taskStateChanged(const QString &taskId, const QString &newState);
+ Q_SCRIPTABLE void taskStateChanged(const QString &taskId,
+ QT_PREPEND_NAMESPACE_AM(AsynchronousTask::TaskState) newState);
// installation only
Q_SCRIPTABLE void taskRequestingInstallationAcknowledge(const QString &taskId, const QVariantMap &applicationAsVariantMap);
@@ -173,3 +176,5 @@ private:
};
QT_END_NAMESPACE_AM
+
+Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE_AM(AsynchronousTask::TaskState))
diff --git a/src/installer-lib/asynchronoustask.cpp b/src/installer-lib/asynchronoustask.cpp
index 4b73f791..83ee8a25 100644
--- a/src/installer-lib/asynchronoustask.cpp
+++ b/src/installer-lib/asynchronoustask.cpp
@@ -50,7 +50,7 @@ AsynchronousTask::AsynchronousTask(QObject *parent)
: QThread(parent)
, m_id(QUuid::createUuid().toString())
{
- static int once = qRegisterMetaType<AsynchronousTask::State>();
+ static int once = qRegisterMetaType<AsynchronousTask::TaskState>();
Q_UNUSED(once)
}
@@ -59,12 +59,12 @@ QString AsynchronousTask::id() const
return m_id;
}
-AsynchronousTask::State AsynchronousTask::state() const
+AsynchronousTask::TaskState AsynchronousTask::state() const
{
return m_state;
}
-void AsynchronousTask::setState(AsynchronousTask::State state)
+void AsynchronousTask::setState(AsynchronousTask::TaskState state)
{
if (m_state != state) {
m_state = state;
@@ -72,20 +72,6 @@ void AsynchronousTask::setState(AsynchronousTask::State state)
}
}
-QString AsynchronousTask::stateToString(State state)
-{
- switch (state) {
- case Queued: return qSL("queued");
- case Executing: return qSL("executing");
- case Failed: return qSL("failed");
- case Finished: return qSL("finished");
- case AwaitingAcknowledge: return qSL("awaitingAcknowledge");
- case Installing: return qSL("installing");
- case CleaningUp: return qSL("cleaningUp");
- default: return QString();
- }
-}
-
bool AsynchronousTask::hasFailed() const
{
return (m_state == Failed);
diff --git a/src/installer-lib/asynchronoustask.h b/src/installer-lib/asynchronoustask.h
index 93cb103f..a797272f 100644
--- a/src/installer-lib/asynchronoustask.h
+++ b/src/installer-lib/asynchronoustask.h
@@ -53,8 +53,9 @@ class AsynchronousTask : public QThread
Q_OBJECT
public:
- enum State
+ enum TaskState
{
+ Invalid,
Queued,
Executing,
Failed,
@@ -65,14 +66,14 @@ public:
Installing,
CleaningUp
};
+ Q_ENUM(TaskState)
AsynchronousTask(QObject *parent = nullptr);
QString id() const;
- State state() const;
- void setState(State state);
- static QString stateToString(State state);
+ TaskState state() const;
+ void setState(TaskState state);
bool hasFailed() const;
Error errorCode() const;
@@ -84,7 +85,7 @@ public:
QString applicationId() const; // convenience
signals:
- void stateChanged(QT_PREPEND_NAMESPACE_AM(AsynchronousTask::State) newState);
+ void stateChanged(QT_PREPEND_NAMESPACE_AM(AsynchronousTask::TaskState) newState);
void progress(qreal p);
protected:
@@ -97,11 +98,9 @@ protected:
QString m_id;
QString m_applicationId;
- State m_state = Queued;
+ TaskState m_state = Queued;
Error m_errorCode = Error::None;
QString m_errorString;
};
QT_END_NAMESPACE_AM
-
-Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE_AM(AsynchronousTask::State))
diff --git a/tests/qml/installer/tst_installer.qml b/tests/qml/installer/tst_installer.qml
index 1012f6d1..04f4607f 100644
--- a/tests/qml/installer/tst_installer.qml
+++ b/tests/qml/installer/tst_installer.qml
@@ -54,6 +54,12 @@ TestCase {
}
SignalSpy {
+ id: taskStateChangedSpy
+ target: AM.ApplicationInstaller
+ signalName: "taskStateChanged"
+ }
+
+ SignalSpy {
id: taskRequestingInstallationAcknowledgeSpy
target: AM.ApplicationInstaller
signalName: "taskRequestingInstallationAcknowledge"
@@ -70,7 +76,7 @@ TestCase {
signalName: "stateChanged"
}
- function test_application_state() {
+ function test_states() {
// App could potentially be installed already. Remove it.
if (AM.ApplicationInstaller.removePackage("test.install.app", false, true)) {
taskFinishedSpy.wait(2000);
@@ -111,5 +117,20 @@ TestCase {
stateChangedSpy.wait(2000);
compare(stateChangedSpy.signalArguments[3][0], AM.Application.BeingRemoved)
// Cannot compare app.state any more, since app might already be dead
+
+ verify(taskStateChangedSpy.count > 10);
+ var taskStates = [ AM.ApplicationInstaller.Executing,
+ AM.ApplicationInstaller.AwaitingAcknowledge,
+ AM.ApplicationInstaller.Installing,
+ AM.ApplicationInstaller.CleaningUp,
+ AM.ApplicationInstaller.Finished,
+ AM.ApplicationInstaller.Executing,
+ AM.ApplicationInstaller.AwaitingAcknowledge,
+ AM.ApplicationInstaller.Installing,
+ AM.ApplicationInstaller.CleaningUp,
+ AM.ApplicationInstaller.Finished,
+ AM.ApplicationInstaller.Executing ]
+ for (var i = 0; i < taskStates.length; i++)
+ compare(taskStateChangedSpy.signalArguments[i][1], taskStates[i]);
}
}