summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGatis Paeglis <gatis.paeglis@qt.io>2016-12-20 11:42:45 +0100
committerGatis Paeglis <gatis.paeglis@qt.io>2016-12-21 11:35:41 +0000
commit1b30c228f653a712e884adcbb22750b5643c0452 (patch)
tree10c8a9c88b882e2d0b0299cb33868c4e4b8b3d90
parentffc7a483fba2b2e902550072780c87c6f066e947 (diff)
Remove impractical API from QOtaClient
These convenience methods do not provide any real convenience after all. This API is not practical and extenting it would be pain (each new json property would require a new accessor method for each *Metadata version). The reduced subset of API is still sufficient to be used in property bindings: Label { text: extractVersion(OtaClient.remoteMetadata, "version") } Label { text: extractVersion(OtaClient.remoteMetadata, "description") } Where extractVersion() parses JSON metadata. If the metadata file is huge (parsing takes long time), API users can subscribe to onRemoteMetadataChanage: onRemoteMetadataChanged: { // parse the whole metadata file only once and set // appropriate properties. } Change-Id: If095e8c17712fa7b06bd577364ec10ae6ca6d52e Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
-rw-r--r--doc/ota.qdoc4
-rwxr-xr-xqt-ostree/qt-ostree4
-rw-r--r--src/imports/pluginmain.cpp60
-rw-r--r--src/lib/qotaclient.cpp107
-rw-r--r--src/lib/qotaclient.h14
-rw-r--r--src/lib/qotaclient_p.h15
-rw-r--r--src/lib/qotaclientasync.cpp18
-rw-r--r--src/lib/qotaclientasync_p.h7
8 files changed, 30 insertions, 199 deletions
diff --git a/doc/ota.qdoc b/doc/ota.qdoc
index fcf5283..d8282b8 100644
--- a/doc/ota.qdoc
+++ b/doc/ota.qdoc
@@ -319,9 +319,7 @@
\li \b {\c --ota-json}
\list
\li A JSON file containing arbitrary metadata about the system.
- The following top-level fields have convenience methods in
- the Qt/QML OTA API: \c version and \c description. Use
- OtaClient::remoteMetadata to access the entire JSON file for
+ Use OtaClient::remoteMetadata to access the entire JSON file for
manual parsing.
\endlist
diff --git a/qt-ostree/qt-ostree b/qt-ostree/qt-ostree
index d436277..a5b4798 100755
--- a/qt-ostree/qt-ostree
+++ b/qt-ostree/qt-ostree
@@ -185,9 +185,7 @@ usage()
echo
echo "--ota-json FILE"
echo
- echo " JSON file containing an OTA update metadata, can be arbitrary formatted. The"
- echo " following top-level fields have convenience methods in the Qt/QML OTA API:"
- echo " version, description."
+ echo " JSON file containing an OTA update metadata."
echo
echo "--ostree-repo DIR"
echo
diff --git a/src/imports/pluginmain.cpp b/src/imports/pluginmain.cpp
index ab0f453..6112b3f 100644
--- a/src/imports/pluginmain.cpp
+++ b/src/imports/pluginmain.cpp
@@ -43,26 +43,6 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \qmlproperty string OtaClient::bootedVersion
- \readonly
-
- This is a convenience property that holds a string containing the booted
- system's version.
-
- \sa bootedMetadata
-*/
-
-/*!
- \qmlproperty string OtaClient::bootedDescription
- \readonly
-
- This is a convenience property that holds a string containing the booted
- system's description.
-
- \sa bootedMetadata
-*/
-
-/*!
\qmlproperty string OtaClient::bootedRevision
\readonly
@@ -79,26 +59,6 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \qmlproperty string OtaClient::remoteVersion
- \readonly
-
- This is a convenience property that holds a string containing the system's
- version on a server.
-
- \sa remoteMetadata
-*/
-
-/*!
- \qmlproperty string OtaClient::remoteDescription
- \readonly
-
- This is a convenience property that holds a string containing the system's
- description on a server.
-
- \sa remoteMetadata
-*/
-
-/*!
\qmlproperty string OtaClient::remoteRevision
\readonly
@@ -115,26 +75,6 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \qmlproperty string OtaClient::rollbackVersion
- \readonly
-
- This is a convenience property that holds a string containing the rollback
- system's version.
-
- \sa rollbackMetadata
-*/
-
-/*!
- \qmlproperty string OtaClient::rollbackDescription
- \readonly
-
- This is a convenience property that holds a string containing the rollback
- system's description.
-
- \sa rollbackMetadata
-*/
-
-/*!
\qmlproperty string OtaClient::rollbackRevision
\readonly
diff --git a/src/lib/qotaclient.cpp b/src/lib/qotaclient.cpp
index 00c4b2b..78821cd 100644
--- a/src/lib/qotaclient.cpp
+++ b/src/lib/qotaclient.cpp
@@ -71,17 +71,6 @@ QOtaClientPrivate::~QOtaClientPrivate()
}
}
-static void setMetadataMembers(const QJsonDocument &json, QByteArray *metadata, QString *version, QString *description)
-{
- if (json.isNull())
- return;
-
- *metadata = json.toJson();
- QJsonObject root = json.object();
- *version = root.value(QStringLiteral("version")).toString(QStringLiteral("unknown"));
- *description = root.value(QStringLiteral("description")).toString(QStringLiteral("unknown"));
-}
-
void QOtaClientPrivate::handleStateChanges()
{
Q_Q(QOtaClient);
@@ -99,11 +88,11 @@ void QOtaClientPrivate::handleStateChanges()
}
}
-void QOtaClientPrivate::setBootedMetadata(QString &bootedRev, const QJsonDocument &bootedMetadata)
+void QOtaClientPrivate::setBootedMetadata(QString &bootedRev, const QByteArray &bootedMetadata)
{
Q_Q(QOtaClient);
m_bootedRev = bootedRev;
- setMetadataMembers(bootedMetadata, &m_bootedMetadata, &m_bootedVersion, &m_bootedDescription);
+ m_bootedMetadata = bootedMetadata;
}
void QOtaClientPrivate::statusStringChanged(const QString &status)
@@ -129,26 +118,31 @@ bool QOtaClientPrivate::verifyPathExist(const QString &path)
return true;
}
-void QOtaClientPrivate::rollbackMetadataChanged(const QString &rollbackRev, const QJsonDocument &rollbackMetadata, int treeCount)
+void QOtaClientPrivate::rollbackMetadataChanged(const QString &rollbackRev, const QByteArray &rollbackMetadata, int treeCount)
{
Q_Q(QOtaClient);
+ if (m_rollbackRev == rollbackRev)
+ return;
+
if (!m_rollbackAvailable && treeCount > 1) {
m_rollbackAvailable = true;
emit q->rollbackAvailableChanged();
}
+
m_rollbackRev = rollbackRev;
- setMetadataMembers(rollbackMetadata, &m_rollbackMetadata, &m_rollbackVersion, &m_rollbackDescription);
+ m_rollbackMetadata = rollbackMetadata;
+
q->rollbackMetadataChanged();
}
-void QOtaClientPrivate::remoteMetadataChanged(const QString &remoteRev, const QJsonDocument &remoteMetadata)
+void QOtaClientPrivate::remoteMetadataChanged(const QString &remoteRev, const QByteArray &remoteMetadata)
{
Q_Q(QOtaClient);
if (m_remoteRev == remoteRev)
return;
m_remoteRev = remoteRev;
- setMetadataMembers(remoteMetadata, &m_remoteMetadata, &m_remoteVersion, &m_remoteDescription);
+ m_remoteMetadata = remoteMetadata;
handleStateChanges();
emit q->remoteMetadataChanged();
@@ -456,6 +450,7 @@ bool QOtaClient::updateRemoteMetadataOffline(const QString &packagePath)
/*!
//! [refresh-metadata]
Refreshes the instances view of the system's state from the local metadata cache.
+ Notifier signals are emitted for properties that depend on changed metadata.
Returns \c true if metadata is refreshed successfully; otherwise returns \c false.
Using this method is not required when only one process is responsible for all OTA tasks.
@@ -687,32 +682,6 @@ bool QOtaClient::restartRequired() const
}
/*!
- \property QOtaClient::bootedVersion
- \brief a QString containing the booted system's version.
-
- This is a convenience method.
-
- \sa bootedMetadata
-*/
-QString QOtaClient::bootedVersion() const
-{
- return d_func()->m_bootedVersion;
-}
-
-/*!
- \property QOtaClient::bootedDescription
- \brief a QString containing the booted system's description.
-
- This is a convenience method.
-
- \sa bootedMetadata
-*/
-QString QOtaClient::bootedDescription() const
-{
- return d_func()->m_bootedDescription;
-}
-
-/*!
\property QOtaClient::bootedRevision
\brief a QString containing the booted system's revision.
@@ -736,32 +705,6 @@ QByteArray QOtaClient::bootedMetadata() const
}
/*!
- \property QOtaClient::remoteVersion
- \brief a QString containing the system's version on a server.
-
- This is a convenience method.
-
- \sa remoteMetadata
-*/
-QString QOtaClient::remoteVersion() const
-{
- return d_func()->m_remoteVersion;
-}
-
-/*!
- \property QOtaClient::remoteDescription
- \brief a QString containing the system's description on a server.
-
- This is a convenience method.
-
- \sa remoteMetadata
-*/
-QString QOtaClient::remoteDescription() const
-{
- return d_func()->m_remoteDescription;
-}
-
-/*!
\property QOtaClient::remoteRevision
\brief a QString containing the system's revision on a server.
@@ -787,32 +730,6 @@ QByteArray QOtaClient::remoteMetadata() const
}
/*!
- \property QOtaClient::rollbackVersion
- \brief a QString containing the rollback system's version.
-
- This is a convenience method.
-
- \sa rollbackMetadata
-*/
-QString QOtaClient::rollbackVersion() const
-{
- return d_func()->m_rollbackVersion;
-}
-
-/*!
- \property QOtaClient::rollbackDescription
- \brief a QString containing the rollback system's description.
-
- This is a convenience method.
-
- \sa rollbackMetadata
-*/
-QString QOtaClient::rollbackDescription() const
-{
- return d_func()->m_rollbackDescription;
-}
-
-/*!
\property QOtaClient::rollbackRevision
\brief a QString containing the rollback system's revision.
diff --git a/src/lib/qotaclient.h b/src/lib/qotaclient.h
index 96632a7..ab3316e 100644
--- a/src/lib/qotaclient.h
+++ b/src/lib/qotaclient.h
@@ -47,16 +47,10 @@ class Q_DECL_EXPORT QOtaClient : public QObject
Q_PROPERTY(bool restartRequired READ restartRequired NOTIFY restartRequiredChanged)
Q_PROPERTY(QString error READ errorString NOTIFY errorOccurred)
Q_PROPERTY(QString status READ statusString NOTIFY statusStringChanged)
- Q_PROPERTY(QString bootedVersion READ bootedVersion)
- Q_PROPERTY(QString bootedDescription READ bootedDescription)
Q_PROPERTY(QString bootedRevision READ bootedRevision)
Q_PROPERTY(QByteArray bootedMetadata READ bootedMetadata)
- Q_PROPERTY(QString remoteVersion READ remoteVersion NOTIFY remoteMetadataChanged)
- Q_PROPERTY(QString remoteDescription READ remoteDescription NOTIFY remoteMetadataChanged)
Q_PROPERTY(QString remoteRevision READ remoteRevision NOTIFY remoteMetadataChanged)
Q_PROPERTY(QByteArray remoteMetadata READ remoteMetadata NOTIFY remoteMetadataChanged)
- Q_PROPERTY(QString rollbackVersion READ rollbackVersion NOTIFY rollbackMetadataChanged)
- Q_PROPERTY(QString rollbackDescription READ rollbackDescription NOTIFY rollbackMetadataChanged)
Q_PROPERTY(QString rollbackRevision READ rollbackRevision NOTIFY rollbackMetadataChanged)
Q_PROPERTY(QByteArray rollbackMetadata READ rollbackMetadata NOTIFY rollbackMetadataChanged)
public:
@@ -81,18 +75,10 @@ public:
Q_INVOKABLE bool isRepositoryConfigSet(QOtaRepositoryConfig *config) const;
Q_INVOKABLE QOtaRepositoryConfig *repositoryConfig() const;
- QString bootedVersion() const;
- QString bootedDescription() const;
QString bootedRevision() const;
QByteArray bootedMetadata() const;
-
- QString remoteVersion() const;
- QString remoteDescription() const;
QString remoteRevision() const;
QByteArray remoteMetadata() const;
-
- QString rollbackVersion() const;
- QString rollbackDescription() const;
QString rollbackRevision() const;
QByteArray rollbackMetadata() const;
diff --git a/src/lib/qotaclient_p.h b/src/lib/qotaclient_p.h
index 8f0a8dc..ced6621 100644
--- a/src/lib/qotaclient_p.h
+++ b/src/lib/qotaclient_p.h
@@ -33,7 +33,6 @@
#include <QtCore/QLoggingCategory>
#include <QtCore/QByteArray>
#include <QtCore/QScopedPointer>
-#include <QtCore/QJsonDocument>
QT_BEGIN_NAMESPACE
@@ -56,9 +55,9 @@ public:
void statusStringChanged(const QString &status);
void errorOccurred(const QString &error);
bool verifyPathExist(const QString &path);
- void setBootedMetadata(QString &bootedRev, const QJsonDocument &bootedMetadata);
- void rollbackMetadataChanged(const QString &rollbackRev, const QJsonDocument &rollbackMetadata, int treeCount);
- void remoteMetadataChanged(const QString &remoteRev, const QJsonDocument &remoteMetadata);
+ void setBootedMetadata(QString &bootedRev, const QByteArray &bootedMetadata);
+ void rollbackMetadataChanged(const QString &rollbackRev, const QByteArray &rollbackMetadata, int treeCount);
+ void remoteMetadataChanged(const QString &remoteRev, const QByteArray &remoteMetadata);
void defaultRevisionChanged(const QString &defaultRevision);
// members
@@ -73,18 +72,10 @@ public:
QScopedPointer<QOtaClientAsync> m_otaAsync;
QString m_defaultRev;
- QString m_bootedVersion;
- QString m_bootedDescription;
QString m_bootedRev;
QByteArray m_bootedMetadata;
-
- QString m_remoteVersion;
- QString m_remoteDescription;
QString m_remoteRev;
QByteArray m_remoteMetadata;
-
- QString m_rollbackVersion;
- QString m_rollbackDescription;
QString m_rollbackRev;
QByteArray m_rollbackMetadata;
};
diff --git a/src/lib/qotaclientasync.cpp b/src/lib/qotaclientasync.cpp
index d1ca6bc..51a9333 100644
--- a/src/lib/qotaclientasync.cpp
+++ b/src/lib/qotaclientasync.cpp
@@ -32,6 +32,8 @@
#include "qotaclientasync_p.h"
#include "qotaclient_p.h"
+#include <QtCore/QJsonDocument>
+
QT_BEGIN_NAMESPACE
#define OSTREE_STATIC_DELTA_META_ENTRY_FORMAT "(uayttay)"
@@ -123,12 +125,12 @@ OstreeSysroot* QOtaClientAsync::defaultSysroot()
return sysroot;
}
-QJsonDocument QOtaClientAsync::metadataFromRev(const QString &rev, bool *ok)
+QByteArray QOtaClientAsync::metadataFromRev(const QString &rev, bool *ok)
{
QString jsonData;
jsonData = ostree(QString(QStringLiteral("ostree cat %1 /usr/etc/qt-ota.json")).arg(rev), ok);
if (jsonData.isEmpty())
- return QJsonDocument();
+ return QByteArray();
QJsonParseError parseError;
QJsonDocument jsonMetadata = QJsonDocument::fromJson(jsonData.toLatin1(), &parseError);
@@ -139,7 +141,7 @@ QJsonDocument QOtaClientAsync::metadataFromRev(const QString &rev, bool *ok)
emit errorOccurred(error);
}
- return jsonMetadata;
+ return jsonMetadata.toJson();
}
bool QOtaClientAsync::refreshMetadata(QOtaClientPrivate *d)
@@ -154,7 +156,7 @@ bool QOtaClientAsync::refreshMetadata(QOtaClientPrivate *d)
// Booted revision can change only when a device is rebooted.
OstreeDeployment *bootedDeployment = (OstreeDeployment*)ostree_sysroot_get_booted_deployment (sysroot);
QString bootedRev = QLatin1String(ostree_deployment_get_csum (bootedDeployment));
- QJsonDocument bootedMetadata = metadataFromRev(bootedRev, &ok);
+ QByteArray bootedMetadata = metadataFromRev(bootedRev, &ok);
if (!ok)
return false;
d->setBootedMetadata(bootedRev, bootedMetadata);
@@ -162,7 +164,7 @@ bool QOtaClientAsync::refreshMetadata(QOtaClientPrivate *d)
// prepopulate with what we think is on the remote server (head of the local repo)
QString remoteRev = ostree(QStringLiteral("ostree rev-parse linux/qt"), &ok);
- QJsonDocument remoteMetadata;
+ QByteArray remoteMetadata;
if (ok) remoteMetadata = metadataFromRev(remoteRev, &ok);
if (!ok)
return false;
@@ -175,7 +177,7 @@ bool QOtaClientAsync::refreshMetadata(QOtaClientPrivate *d)
void QOtaClientAsync::_fetchRemoteMetadata()
{
QString remoteRev;
- QJsonDocument remoteMetadata;
+ QByteArray remoteMetadata;
bool ok = true;
ostree(QStringLiteral("ostree pull --commit-metadata-only --disable-static-deltas qt-os linux/qt"), &ok);
if (ok) remoteRev = ostree(QStringLiteral("ostree rev-parse linux/qt"), &ok);
@@ -263,7 +265,7 @@ bool QOtaClientAsync::handleRevisionChanges(OstreeSysroot *sysroot, bool reloadS
OstreeDeployment *rollbackDeployment = (OstreeDeployment*)deployments->pdata[index];
QString rollbackRev(QLatin1String(ostree_deployment_get_csum (rollbackDeployment)));
bool ok = true;
- QJsonDocument rollbackMetadata = metadataFromRev(rollbackRev, &ok);
+ QByteArray rollbackMetadata = metadataFromRev(rollbackRev, &ok);
if (!ok)
return false;
emit rollbackMetadataChanged(rollbackRev, rollbackMetadata, deployments->len);
@@ -376,7 +378,7 @@ bool QOtaClientAsync::extractPackage(const QString &packagePath, OstreeSysroot *
g_autofree char *toCsum = ostree_checksum_from_bytes_v (toCsumV);
*updateToRev = QString::fromLatin1(toCsum);
- QJsonDocument remoteMetadata;
+ QByteArray remoteMetadata;
ostree(QString(QStringLiteral("ostree reset qt-os:linux/qt %1")).arg(*updateToRev), &ok);
if (ok) remoteMetadata = metadataFromRev(*updateToRev, &ok);
if (ok) emit remoteMetadataChanged(*updateToRev, remoteMetadata);
diff --git a/src/lib/qotaclientasync_p.h b/src/lib/qotaclientasync_p.h
index c511507..61a6071 100644
--- a/src/lib/qotaclientasync_p.h
+++ b/src/lib/qotaclientasync_p.h
@@ -33,7 +33,6 @@
#include "qotaclient_p.h"
#include <QtCore/QObject>
-#include <QtCore/QJsonDocument>
#include <QtCore/QProcess>
QT_BEGIN_NAMESPACE
@@ -65,15 +64,15 @@ signals:
void updateOfflineFinished(bool success);
void updateRemoteMetadataOffline(const QString &packagePath);
void updateRemoteMetadataOfflineFinished(bool success);
- void rollbackMetadataChanged(const QString &rollbackRev, const QJsonDocument &rollbackMetadata, int treeCount);
+ void rollbackMetadataChanged(const QString &rollbackRev, const QByteArray &rollbackMetadata, int treeCount);
void errorOccurred(const QString &error);
void statusStringChanged(const QString &status);
- void remoteMetadataChanged(const QString &remoteRev, const QJsonDocument &remoteMetadata);
+ void remoteMetadataChanged(const QString &remoteRev, const QByteArray &remoteMetadata);
void defaultRevisionChanged(const QString &defaultRevision);
protected:
OstreeSysroot* defaultSysroot();
- QJsonDocument metadataFromRev(const QString &rev, bool *ok);
+ QByteArray metadataFromRev(const QString &rev, bool *ok);
int rollbackIndex(OstreeSysroot *sysroot);
bool handleRevisionChanges(OstreeSysroot *sysroot, bool reloadSysroot = false);
void emitGError(GError *error);