diff options
author | Gatis Paeglis <gatis.paeglis@qt.io> | 2016-09-02 13:42:10 +0200 |
---|---|---|
committer | Gatis Paeglis <gatis.paeglis@qt.io> | 2016-09-02 14:22:07 +0000 |
commit | 7126a940e04692cd94dd722c3c54c597cb166250 (patch) | |
tree | 92ad36cc72340614e0a3dc923545d3851cb1d432 /src | |
parent | e96e8960fca9c54d35ba968878857d6b496b1bd5 (diff) |
Cleanup state verification
Change-Id: Iff1a3f0221717fc80c459831d67c2d6cb326dba9
Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/qotaclient.cpp | 39 | ||||
-rw-r--r-- | src/lib/qotaclient_p.h | 3 | ||||
-rw-r--r-- | src/lib/qotaclientasync.cpp | 10 |
3 files changed, 31 insertions, 21 deletions
diff --git a/src/lib/qotaclient.cpp b/src/lib/qotaclient.cpp index 131fa01..08606fe 100644 --- a/src/lib/qotaclient.cpp +++ b/src/lib/qotaclient.cpp @@ -33,7 +33,7 @@ #include <QtCore/QFile> #include <QtCore/QJsonObject> -Q_LOGGING_CATEGORY(otaLog, "qt.ota") +Q_LOGGING_CATEGORY(qota, "b2qt.ota") QT_BEGIN_NAMESPACE @@ -59,7 +59,7 @@ QOTAClientPrivate::~QOTAClientPrivate() if (m_otaAsyncThread->isRunning()) { m_otaAsyncThread->quit(); if (Q_UNLIKELY(m_otaAsyncThread->wait(4000))) - qCWarning(otaLog) << "Timed out waiting for worker thread to exit."; + qCWarning(qota) << "Timed out waiting for worker thread to exit."; } delete m_otaAsyncThread; } @@ -87,6 +87,19 @@ void QOTAClientPrivate::updateServerInfo(const QString &serverRev, const QJsonDo emit q->serverInfoChanged(); } +bool QOTAClientPrivate::isReady() const +{ + if (!m_otaEnabled) { + qCWarning(qota) << "over-the-air update functionality is not enabled for this device"; + return false; + } + if (!m_initialized) { + qCWarning(qota) << "initialization is not ready"; + return false; + } + return true; +} + void QOTAClientPrivate::refreshState() { Q_Q(QOTAClient); @@ -177,7 +190,7 @@ void QOTAClientPrivate::rollbackChanged(const QString &rollbackRev, const QJsonD QString QOTAClientPrivate::version(QueryTarget target) const { if (!m_otaEnabled) - return QStringLiteral("The OTA update capability is not enabled."); + return QString(); switch (target) { case QueryTarget::Client: @@ -194,7 +207,7 @@ QString QOTAClientPrivate::version(QueryTarget target) const QByteArray QOTAClientPrivate::info(QueryTarget target) const { if (!m_otaEnabled) - return QByteArray("unknown"); + return QByteArray(); switch (target) { case QueryTarget::Client: @@ -211,7 +224,7 @@ QByteArray QOTAClientPrivate::info(QueryTarget target) const QString QOTAClientPrivate::description(QueryTarget target) const { if (!m_otaEnabled) - return QStringLiteral("The OTA update capability is not enabled."); + return QString(); switch (target) { case QueryTarget::Client: @@ -228,7 +241,7 @@ QString QOTAClientPrivate::description(QueryTarget target) const QString QOTAClientPrivate::revision(QueryTarget target) const { if (!m_otaEnabled) - return QStringLiteral("The OTA update capability is not enabled."); + return QString(); switch (target) { case QueryTarget::Client: @@ -408,7 +421,7 @@ QOTAClient::~QOTAClient() bool QOTAClient::fetchServerInfo() const { Q_D(const QOTAClient); - if (!d->m_otaEnabled) + if (!d->isReady()) return false; d->m_otaAsync->fetchServerInfo(); @@ -428,7 +441,7 @@ bool QOTAClient::fetchServerInfo() const bool QOTAClient::update() const { Q_D(const QOTAClient); - if (!d->m_otaEnabled || !updateAvailable()) + if (!d->isReady() || !updateAvailable()) return false; d->m_otaAsync->update(d->m_serverRev); @@ -446,7 +459,7 @@ bool QOTAClient::update() const bool QOTAClient::rollback() const { Q_D(const QOTAClient); - if (!d->m_otaEnabled || !d->m_initialized) + if (!d->isReady()) return false; d->m_otaAsync->rollback(); @@ -517,9 +530,8 @@ QString QOTAClient::statusString() const bool QOTAClient::updateAvailable() const { Q_D(const QOTAClient); - if (!d->m_otaEnabled || d->m_serverRev.isEmpty()) - return false; - + if (d->m_updateAvailable) + Q_ASSERT(!d->m_serverRev.isEmpty()); return d->m_updateAvailable; } @@ -546,9 +558,6 @@ bool QOTAClient::rollbackAvailable() const bool QOTAClient::restartRequired() const { Q_D(const QOTAClient); - if (!d->m_otaEnabled) - return false; - return d->m_restartRequired; } diff --git a/src/lib/qotaclient_p.h b/src/lib/qotaclient_p.h index 86644c2..644c725 100644 --- a/src/lib/qotaclient_p.h +++ b/src/lib/qotaclient_p.h @@ -38,7 +38,7 @@ #include <QtCore/QScopedPointer> #include <QtCore/QJsonDocument> -Q_DECLARE_LOGGING_CATEGORY(otaLog) +Q_DECLARE_LOGGING_CATEGORY(qota) class QOTAClientAsync; @@ -75,6 +75,7 @@ public: QByteArray info(QueryTarget target) const; void updateServerInfo(const QString &serverRev, const QJsonDocument &serverInfo); + bool isReady() const; // members QOTAClient *const q_ptr; diff --git a/src/lib/qotaclientasync.cpp b/src/lib/qotaclientasync.cpp index 88b2742..f78949b 100644 --- a/src/lib/qotaclientasync.cpp +++ b/src/lib/qotaclientasync.cpp @@ -67,7 +67,7 @@ static void parseErrorString(QString *error) QString QOTAClientAsync::ostree(const QString &command, bool *ok, bool updateStatus) { - qCDebug(otaLog) << command; + qCDebug(qota) << command; if (!m_ostree) { m_ostree = new QProcess; m_ostree->setProcessChannelMode(QProcess::MergedChannels); @@ -81,7 +81,7 @@ QString QOTAClientAsync::ostree(const QString &command, bool *ok, bool updateSta QByteArray bytesRead = m_ostree->readAll().trimmed(); if (!bytesRead.isEmpty()) { QString line = QString::fromUtf8(bytesRead); - qCDebug(otaLog) << line; + qCDebug(qota) << line; if (line.startsWith(QStringLiteral("error:"))) { *ok = false; parseErrorString(&line); @@ -133,15 +133,15 @@ QJsonDocument QOTAClientAsync::info(QOTAClientPrivate::QueryTarget target, bool void QOTAClientAsync::multiprocessLock(const QString &method) { - qCDebug(otaLog) << QTime::currentTime() << method << "- waiting for lock..."; + qCDebug(qota) << QTime::currentTime() << method << "- waiting for lock..."; ostree_sysroot_lock (m_sysroot, 0); - qCDebug(otaLog) << QTime::currentTime() << " lock acquired"; + qCDebug(qota) << QTime::currentTime() << " lock acquired"; } void QOTAClientAsync::multiprocessUnlock() { ostree_sysroot_unlock (m_sysroot); - qCDebug(otaLog) << QTime::currentTime() << "lock released"; + qCDebug(qota) << QTime::currentTime() << "lock released"; } QString QOTAClientAsync::defaultRevision() |