refs #509,renamed CDownload to CUpdateInfo

* as discussed in meeting
* follow up adjustments (file renaming, msg. renaming)
This commit is contained in:
Klaus Basan
2015-11-19 03:12:03 +01:00
parent 502b41ff96
commit 025457c43b
14 changed files with 86 additions and 86 deletions

View File

@@ -6,7 +6,7 @@
#include "blackcorefreefunctions.h"
#include "blackcore/webreaderflags.h"
#include "blackcore/data/globalsetup.h"
#include "blackcore/data/download.h"
#include "blackcore/data/updateinfo.h"
#include "voice_channel.h"
@@ -29,7 +29,7 @@ namespace BlackCore
qDBusRegisterMetaType<BlackCore::CLogSubscriptionPair>();
BlackCore::Data::CGlobalSetup::registerMetadata();
BlackCore::Data::CDownload::registerMetadata();
BlackCore::Data::CUpdateInfo::registerMetadata();
BlackCore::CSetupReader::instance(); // kick off reader
}
} // namespace

View File

@@ -87,12 +87,12 @@ namespace BlackCore
CGlobalSetup::versionString() + "/productive/bootstrap/bootstrap.json");
}
CUrlList CGlobalSetup::downloadInfoUrls() const
CUrlList CGlobalSetup::updateInfoUrls() const
{
CUrlList urls(m_sharedUrls);
return urls.appendPath(isDevelopment() ?
CGlobalSetup::versionString() + "/development/download/download.json" :
CGlobalSetup::versionString() + "/productive/download/download.json");
CGlobalSetup::versionString() + "/development/updateinfo/updateinfo.json" :
CGlobalSetup::versionString() + "/productive/updateinfo/updateinfo.json");
}
CUrlList CGlobalSetup::swiftDbDataFileLocationUrls() const
@@ -117,8 +117,8 @@ namespace BlackCore
s.append(boolToYesNo(isDevelopment()));
s.append(separator);
s.append("Download URLs: ");
s.append(downloadInfoUrls().toQString(i18n));
s.append("Update info URLs: ");
s.append(updateInfoUrls().toQString(i18n));
s.append(separator);
s.append("Bootstrap URLs: ");
s.append(bootstrapUrls().toQString(i18n));
@@ -183,8 +183,8 @@ namespace BlackCore
return CVariant::fromValue(this->m_vatsimDataFileUrls);
case IndexVatsimMetars:
return CVariant::fromValue(this->m_vatsimMetarsUrl);
case IndexDownload:
return CVariant::fromValue(this->downloadInfoUrls());
case IndexUpdateInfo:
return CVariant::fromValue(this->updateInfoUrls());
case IndexBootstrap:
return CVariant::fromValue(this->bootstrapUrls());
case IndexSwiftDbFiles:

View File

@@ -24,7 +24,7 @@ namespace BlackCore
{
namespace Data
{
//! Settings for readers
//! Global settings for readers, debug flags, etc.
class BLACKCORE_EXPORT CGlobalSetup :
public BlackMisc::CValueObject<CGlobalSetup>,
public BlackMisc::ITimestampBased
@@ -42,7 +42,7 @@ namespace BlackCore
IndexVatsimData,
IndexSwiftDbFiles,
IndexBootstrap,
IndexDownload,
IndexUpdateInfo,
IndexShared
};
@@ -94,8 +94,8 @@ namespace BlackCore
//! Bootstrap URLs (where the data for the setup itself can be downloaded)
BlackMisc::Network::CUrlList bootstrapUrls() const;
//! Version files and download locations
BlackMisc::Network::CUrlList downloadInfoUrls() const;
//! Version and download locations
BlackMisc::Network::CUrlList updateInfoUrls() const;
//! Alternative locations of swift DB data files
BlackMisc::Network::CUrlList swiftDbDataFileLocationUrls() const;
@@ -149,7 +149,7 @@ namespace BlackCore
struct GlobalSetup : public BlackCore::CDataTrait<CGlobalSetup>
{
//! Key in data cache
static const char *key() { return "readers/global/bootstrap"; }
static const char *key() { return "readers/global/setup"; }
//! Default value
static const CGlobalSetup &defaultValue()

View File

@@ -7,7 +7,7 @@
* contained in the LICENSE file.
*/
#include "download.h"
#include "updateinfo.h"
#include "blackmisc/blackmiscfreefunctions.h"
#include "blackmisc/project.h"
#include <QStringList>
@@ -19,7 +19,7 @@ namespace BlackCore
{
namespace Data
{
CDownload::CDownload() :
CUpdateInfo::CUpdateInfo() :
ITimestampBased(0),
m_downloadsStableUrls(QStringList {"http://swift-project.org/"}),
m_downloadsBetaUrls(QStringList {"http://swift-project.org/"}),
@@ -29,27 +29,27 @@ namespace BlackCore
m_lastSupportedVersionBeta("0.6")
{ }
CUrlList CDownload::getDownloadUrls() const
CUrlList CUpdateInfo::getDownloadUrls() const
{
return CProject::isBetaTest() ? getDownloadUrlsBeta() : getDownloadUrlsStable();
}
QString CDownload::getLatestVersion() const
QString CUpdateInfo::getLatestVersion() const
{
return CProject::isBetaTest() ? getLatestVersionBeta() : getLatestVersionStable();
}
bool CDownload::hasSameType(const CDownload &otherDownload) const
bool CUpdateInfo::hasSameType(const CUpdateInfo &otherDownload) const
{
return this->isDevelopment() == otherDownload.isDevelopment();
}
QString CDownload::convertToQString(bool i18n) const
QString CUpdateInfo::convertToQString(bool i18n) const
{
return convertToQString(", ", i18n);
}
QString CDownload::convertToQString(const QString &separator, bool i18n) const
QString CUpdateInfo::convertToQString(const QString &separator, bool i18n) const
{
QString s("timestamp: ");
s.append(this->getFormattedUtcTimestampYmdhms());
@@ -75,7 +75,7 @@ namespace BlackCore
return s;
}
CVariant CDownload::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
CVariant CUpdateInfo::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
{
if (index.isMyself()) { return CVariant::from(*this); }
if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); }
@@ -100,9 +100,9 @@ namespace BlackCore
}
}
void CDownload::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index)
void CUpdateInfo::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index)
{
if (index.isMyself()) { (*this) = variant.to<CDownload>(); return; }
if (index.isMyself()) { (*this) = variant.to<CUpdateInfo>(); return; }
if (ITimestampBased::canHandleIndex(index))
{
ITimestampBased::setPropertyByIndex(variant, index);

View File

@@ -9,8 +9,8 @@
//! \file
#ifndef BLACKCORE_DATA_DOWNLOAD_H
#define BLACKCORE_DATA_DOWNLOAD_H
#ifndef BLACKCORE_DATA_UPDATEINFO_H
#define BLACKCORE_DATA_UPDATEINFO_H
#include "blackcore/blackcoreexport.h"
#include "blackcore/datacache.h"
@@ -23,15 +23,15 @@ namespace BlackCore
namespace Data
{
//! Download locations and versions
class BLACKCORE_EXPORT CDownload :
public BlackMisc::CValueObject<CDownload>,
class BLACKCORE_EXPORT CUpdateInfo :
public BlackMisc::CValueObject<CUpdateInfo>,
public BlackMisc::ITimestampBased
{
public:
//! Properties by index
enum ColumnIndex
{
IndexDownloadUrlsStable = BlackMisc::CPropertyIndex::GlobalIndexCDownload,
IndexDownloadUrlsStable = BlackMisc::CPropertyIndex::GlobalIndexCUpdateInfo,
IndexDownloadUrlsBeta,
IndexLatestVersionStable,
IndexLastSupportedVersionStable,
@@ -40,10 +40,10 @@ namespace BlackCore
};
//! Default constructor
CDownload();
CUpdateInfo();
//! Destructor.
~CDownload() {}
~CUpdateInfo() {}
//! Download URLs, ie here one can download installer
const BlackMisc::Network::CUrlList &getDownloadUrlsBeta() const { return m_downloadsBetaUrls; }
@@ -73,7 +73,7 @@ namespace BlackCore
bool isDevelopment() const { return m_development; }
//! Same type
bool hasSameType(const CDownload &otherDownload) const;
bool hasSameType(const CUpdateInfo &otherDownload) const;
//! Productive settings?
void setDevelopment(bool development) { m_development = development; }
@@ -91,7 +91,7 @@ namespace BlackCore
void setPropertyByIndex(const BlackMisc::CVariant &variant, const BlackMisc::CPropertyIndex &index);
private:
BLACK_ENABLE_TUPLE_CONVERSION(BlackCore::Data::CDownload)
BLACK_ENABLE_TUPLE_CONVERSION(BlackCore::Data::CUpdateInfo)
bool m_development = false; //!< for development
BlackMisc::Network::CUrlList m_downloadsStableUrls; //!< Download URLs, here I get the installer
@@ -103,15 +103,15 @@ namespace BlackCore
};
//! Trait for global setup data
struct Download : public BlackCore::CDataTrait<CDownload>
struct UpdateInfo : public BlackCore::CDataTrait<CUpdateInfo>
{
//! Key in data cache
static const char *key() { return "readers/global/download"; }
static const char *key() { return "readers/global/updateinfo"; }
//! Default value
static const CDownload &defaultValue()
static const CUpdateInfo &defaultValue()
{
static const CDownload defaultValue;
static const CUpdateInfo defaultValue;
return defaultValue;
}
};
@@ -119,8 +119,8 @@ namespace BlackCore
} // ns
} // ns
Q_DECLARE_METATYPE(BlackCore::Data::CDownload)
BLACK_DECLARE_TUPLE_CONVERSION(BlackCore::Data::CDownload, (
Q_DECLARE_METATYPE(BlackCore::Data::CUpdateInfo)
BLACK_DECLARE_TUPLE_CONVERSION(BlackCore::Data::CUpdateInfo, (
attr(o.m_timestampMSecsSinceEpoch),
attr(o.m_development),
attr(o.m_downloadsStableUrls),

View File

@@ -41,13 +41,13 @@ namespace BlackCore
else
{
this->m_bootstrapUrls.uniqueWrite()->push_back(m_setup.get().bootstrapUrls());
this->m_downloadUrls.uniqueWrite()->push_back(m_setup.get().downloadInfoUrls());
this->m_updateInfoUrls.uniqueWrite()->push_back(m_setup.get().updateInfoUrls());
this->m_networkManagerBootstrap = new QNetworkAccessManager(this);
this->connect(this->m_networkManagerBootstrap, &QNetworkAccessManager::finished, this, &CSetupReader::ps_parseSetupFile);
this->m_networkManagerDownload = new QNetworkAccessManager(this);
this->connect(this->m_networkManagerDownload, &QNetworkAccessManager::finished, this, &CSetupReader::ps_parseDownloadFile);
this->m_networkManagerUpdateInfo = new QNetworkAccessManager(this);
this->connect(this->m_networkManagerUpdateInfo, &QNetworkAccessManager::finished, this, &CSetupReader::ps_parseUpdateInfoFile);
this->start(QThread::LowPriority);
}
@@ -82,19 +82,19 @@ namespace BlackCore
this->m_networkManagerBootstrap->get(request);
}
void CSetupReader::ps_readDownload()
void CSetupReader::ps_readUpdateInfo()
{
this->threadAssertCheck();
Q_ASSERT_X(this->m_networkManagerDownload, Q_FUNC_INFO, "Missing network manager");
CUrl url(this->m_downloadUrls.uniqueWrite()->getNextWorkingUrl());
Q_ASSERT_X(this->m_networkManagerUpdateInfo, Q_FUNC_INFO, "Missing network manager");
CUrl url(this->m_updateInfoUrls.uniqueWrite()->getNextWorkingUrl());
if (url.isEmpty())
{
CLogMessage(this).warning("Cannot read download (info), failed URLs: %1") << this->m_downloadUrls.read()->getFailedUrls();
CLogMessage(this).warning("Cannot read update info, failed URLs: %1") << this->m_updateInfoUrls.read()->getFailedUrls();
return;
}
QNetworkRequest request(url);
CNetworkUtils::ignoreSslVerification(request);
this->m_networkManagerDownload->get(request);
this->m_networkManagerUpdateInfo->get(request);
}
void CSetupReader::ps_setupSyncronized(bool success)
@@ -102,8 +102,8 @@ namespace BlackCore
// trigger
if (success)
{
CLogMessage(this).info("Setup synchronized, will trigger read of download information");
QTimer::singleShot(500, this, &CSetupReader::ps_readDownload);
CLogMessage(this).info("Setup synchronized, will trigger read of update information");
QTimer::singleShot(500, this, &CSetupReader::ps_readUpdateInfo);
}
else
{
@@ -222,7 +222,7 @@ namespace BlackCore
}
}
void CSetupReader::ps_parseDownloadFile(QNetworkReply *nwReplyPtr)
void CSetupReader::ps_parseUpdateInfoFile(QNetworkReply *nwReplyPtr)
{
// wrap pointer, make sure any exit cleans up reply
// required to use delete later as object is created in a different thread
@@ -235,7 +235,7 @@ namespace BlackCore
if (this->isFinishedOrShutdown())
{
CLogMessage(this).debug() << Q_FUNC_INFO;
CLogMessage(this).info("Terminated loading download info");
CLogMessage(this).info("Terminated loading of update info");
nwReply->abort();
return; // stop, terminate straight away, ending thread
}
@@ -247,35 +247,35 @@ namespace BlackCore
nwReplyPtr->close();
if (setupJson.isEmpty())
{
CLogMessage(this).info("No download (info) file");
CLogMessage(this).info("No update info file");
// try next URL
}
else
{
CDownload currentDownload(m_download.get()); // from cache
CDownload loadedDownload;
loadedDownload.convertFromJson(Json::jsonObjectFromString(setupJson));
loadedDownload.setDevelopment(isForDevelopment()); // always update, regardless what persistent setting says
if (loadedDownload.getMSecsSinceEpoch() == 0 && lastModified > 0) { loadedDownload.setMSecsSinceEpoch(lastModified); }
qint64 currentVersionTimestamp = currentDownload.getMSecsSinceEpoch();
qint64 newVersionTimestamp = loadedDownload.getMSecsSinceEpoch();
bool sameVersionLoaded = (loadedDownload == currentDownload);
CUpdateInfo currentUpdateInfo(m_updateInfo.get()); // from cache
CUpdateInfo loadedUpdateInfo;
loadedUpdateInfo.convertFromJson(Json::jsonObjectFromString(setupJson));
loadedUpdateInfo.setDevelopment(isForDevelopment()); // always update, regardless what persistent setting says
if (loadedUpdateInfo.getMSecsSinceEpoch() == 0 && lastModified > 0) { loadedUpdateInfo.setMSecsSinceEpoch(lastModified); }
qint64 currentVersionTimestamp = currentUpdateInfo.getMSecsSinceEpoch();
qint64 newVersionTimestamp = loadedUpdateInfo.getMSecsSinceEpoch();
bool sameVersionLoaded = (loadedUpdateInfo == currentUpdateInfo);
if (sameVersionLoaded)
{
CLogMessage(this).info("Same download info loaded from %1 as already in data cache %2") << urlString << m_download.getFilename();
CLogMessage(this).info("Same update info loaded from %1 as already in data cache %2") << urlString << m_updateInfo.getFilename();
return; // success
}
bool sameType = loadedDownload.hasSameType(currentDownload);
bool sameType = loadedUpdateInfo.hasSameType(currentUpdateInfo);
bool outdatedVersionLoaded = sameType && (newVersionTimestamp < currentVersionTimestamp);
if (outdatedVersionLoaded)
{
CLogMessage(this).info("Download loaded from %1 outdated, older than version in data cache %2") << urlString << m_download.getFilename();
CLogMessage(this).info("Update info loaded from %1 outdated, older than version in data cache %2") << urlString << m_updateInfo.getFilename();
// try next URL
}
else
{
CStatusMessage m = m_download.set(loadedDownload);
CStatusMessage m = m_updateInfo.set(loadedUpdateInfo);
if (!m.isEmpty())
{
CLogMessage(this).preformatted(m);
@@ -283,7 +283,7 @@ namespace BlackCore
}
else
{
CLogMessage(this).info("Download info: Updated data cache in %1") << m_download.getFilename();
CLogMessage(this).info("Update info: Updated data cache in %1") << m_updateInfo.getFilename();
return; // success
} // cache
} // outdated?
@@ -293,12 +293,12 @@ namespace BlackCore
else
{
// network error
CLogMessage(this).warning("Reading download info failed %1 %2") << replyMessage << urlString;
CLogMessage(this).warning("Reading update info failed %1 %2") << replyMessage << urlString;
nwReply->abort();
}
// try next one if any
if (this->m_downloadUrls.uniqueWrite()->addFailedUrl(url))
if (this->m_updateInfoUrls.uniqueWrite()->addFailedUrl(url))
{
QTimer::singleShot(500, this, &CSetupReader::ps_readSetup);
}

View File

@@ -16,7 +16,7 @@
#include "blackmisc/threadedreader.h"
#include "blackmisc/lockfree.h"
#include "blackcore/data/globalsetup.h"
#include "blackcore/data/download.h"
#include "blackcore/data/updateinfo.h"
#include <QObject>
#include <QTimer>
@@ -46,26 +46,26 @@ namespace BlackCore
//! \threadsafe
void ps_parseSetupFile(QNetworkReply *nwReply);
//! Download has been read
//! Update info has been read
//! \threadsafe
void ps_parseDownloadFile(QNetworkReply *nwReplyPtr);
void ps_parseUpdateInfoFile(QNetworkReply *nwReplyPtr);
//! Do reading
void ps_readSetup();
//! Do reading
void ps_readDownload();
void ps_readUpdateInfo();
//! Setup has beem syncronized
void ps_setupSyncronized(bool success);
private:
QNetworkAccessManager *m_networkManagerBootstrap = nullptr;
QNetworkAccessManager *m_networkManagerDownload = nullptr;
QNetworkAccessManager *m_networkManagerUpdateInfo = nullptr;
BlackMisc::LockFree<BlackMisc::Network::CFailoverUrlList> m_bootstrapUrls;
BlackMisc::LockFree<BlackMisc::Network::CFailoverUrlList> m_downloadUrls;
CData<BlackCore::Data::GlobalSetup> m_setup {this}; //!< data cache setup
CData<BlackCore::Data::Download> m_download {this}; //!< data cache downloads
BlackMisc::LockFree<BlackMisc::Network::CFailoverUrlList> m_updateInfoUrls;
CData<BlackCore::Data::GlobalSetup> m_setup {this}; //!< data cache setup
CData<BlackCore::Data::UpdateInfo> m_updateInfo {this}; //!< data cache update info
//! Constructor
explicit CSetupReader(QObject *owner);