Ref T203, renamings to "update info" and "settings"

This commit is contained in:
Klaus Basan
2017-12-09 19:53:21 +01:00
parent 2589b6283b
commit 0daf4ba087
7 changed files with 102 additions and 107 deletions

View File

@@ -163,7 +163,7 @@ namespace BlackCore
// global setup // global setup
m_setupReader.reset(new CSetupReader(this)); m_setupReader.reset(new CSetupReader(this));
connect(m_setupReader.data(), &CSetupReader::setupHandlingCompleted, this, &CApplication::setupHandlingIsCompleted, Qt::QueuedConnection); connect(m_setupReader.data(), &CSetupReader::setupHandlingCompleted, this, &CApplication::setupHandlingIsCompleted, Qt::QueuedConnection);
connect(m_setupReader.data(), &CSetupReader::distributionInfoAvailable, this, &CApplication::distributionInfoAvailable, Qt::QueuedConnection); connect(m_setupReader.data(), &CSetupReader::updateInfoAvailable, this, &CApplication::updateInfoAvailable, Qt::QueuedConnection);
connect(m_setupReader.data(), &CSetupReader::successfullyReadSharedUrl, m_networkWatchDog.data(), &CNetworkWatchdog::setWorkingSharedUrl, Qt::QueuedConnection); connect(m_setupReader.data(), &CSetupReader::successfullyReadSharedUrl, m_networkWatchDog.data(), &CNetworkWatchdog::setWorkingSharedUrl, Qt::QueuedConnection);
this->addParserOptions(m_setupReader->getCmdLineOptions()); // add options from reader this->addParserOptions(m_setupReader->getCmdLineOptions()); // add options from reader
@@ -340,12 +340,12 @@ namespace BlackCore
return r->getSetup(); return r->getSetup();
} }
CDistributionList CApplication::getDistributionInfo() const CUpdateInfo CApplication::getUpdateInfo() const
{ {
if (m_shutdown) { return CDistributionList(); } if (m_shutdown) { return CUpdateInfo(); }
const CSetupReader *r = m_setupReader.data(); const CSetupReader *r = m_setupReader.data();
if (!r) { return CDistributionList(); } if (!r) { return CUpdateInfo(); }
return r->getDistributionInfo(); return r->getUpdateInfo();
} }
bool CApplication::start() bool CApplication::start()

View File

@@ -19,7 +19,7 @@
#include "blackcore/db/databasereaderconfig.h" #include "blackcore/db/databasereaderconfig.h"
#include "blackcore/application/applicationsettings.h" #include "blackcore/application/applicationsettings.h"
#include "blackcore/webreaderflags.h" #include "blackcore/webreaderflags.h"
#include "blackmisc/db/distributionlist.h" #include "blackmisc/db/updateinfo.h"
#include "blackmisc/network/urllist.h" #include "blackmisc/network/urllist.h"
#include "blackmisc/network/networkutils.h" #include "blackmisc/network/networkutils.h"
#include "blackmisc/slot.h" #include "blackmisc/slot.h"
@@ -154,9 +154,9 @@ namespace BlackCore
//! \threadsafe //! \threadsafe
BlackCore::Data::CGlobalSetup getGlobalSetup() const; BlackCore::Data::CGlobalSetup getGlobalSetup() const;
//! Distributions //! Update info
//! \threadsafe //! \threadsafe
BlackMisc::Db::CDistributionList getDistributionInfo() const; BlackMisc::Db::CUpdateInfo getUpdateInfo() const;
//! Delete all cookies from cookie manager //! Delete all cookies from cookie manager
void deleteAllCookies(); void deleteAllCookies();
@@ -471,7 +471,7 @@ namespace BlackCore
void setupHandlingCompleted(bool success); void setupHandlingCompleted(bool success);
//! Update info available (cache, web load) //! Update info available (cache, web load)
void distributionInfoAvailable(bool success); void updateInfoAvailable(bool success);
//! Startup has been completed //! Startup has been completed
//! \remark needs to be triggered by application when it think it is done //! \remark needs to be triggered by application when it think it is done

View File

@@ -14,6 +14,7 @@
#include "blackcore/application.h" #include "blackcore/application.h"
#include "blackconfig/buildconfig.h" #include "blackconfig/buildconfig.h"
#include "blackmisc/platform.h"
#include "blackmisc/settingscache.h" #include "blackmisc/settingscache.h"
#include <QStringList> #include <QStringList>
@@ -21,26 +22,26 @@ namespace BlackCore
{ {
namespace Application namespace Application
{ {
//! Distribution settings, QStringList with 2 values: channel/platform //! Update info settings, QStringList with 2 values: channel/platform
struct TDistribution : public BlackMisc::TSettingTrait<QStringList> struct TUpdatePreferences : public BlackMisc::TSettingTrait<QStringList>
{ {
//! \copydoc BlackMisc::TSettingTrait::key //! \copydoc BlackMisc::TSettingTrait::key
static const char *key() { return "distribution"; } static const char *key() { return "updatepreferences"; }
//! \copydoc BlackMisc::TSettingTrait::defaultValue //! \copydoc BlackMisc::TSettingTrait::defaultValue
static const QStringList &defaultValue() static const QStringList &defaultValue()
{ {
// guessing / preseting some default values // guessing / preseting some default values
static const QStringList d = (sApp && !sApp->getDistributionInfo().isEmpty()) ? static const QStringList d = (sApp && !sApp->getUpdateInfo().isEmpty()) ?
sApp->getDistributionInfo().guessMyDefaultChannelAndPlatform() : // from cached or loaded distribution data sApp->getUpdateInfo().anticipateMyDefaultChannelAndPlatform() : // from cached or loaded update info
QStringList({"ALPHA", BlackConfig::CBuildConfig::guessMyPlatformString()}); // guessing QStringList({ "STABLE", BlackMisc::CPlatform::currentPlatform().getPlatformName()});
return d; return d;
} }
//! \copydoc BlackMisc::TSettingTrait::humanReadable //! \copydoc BlackMisc::TSettingTrait::humanReadable
static const QString &humanReadable() static const QString &humanReadable()
{ {
static const QString name("Download channel/platform"); static const QString name("Updates channel/platform");
return name; return name;
} }
}; };

View File

@@ -93,9 +93,9 @@ namespace BlackCore
return getSwiftSharedUrls().withAppendedPath(CGlobalSetup::schemaVersionString() + "/bootstrap/bootstrap.json"); return getSwiftSharedUrls().withAppendedPath(CGlobalSetup::schemaVersionString() + "/bootstrap/bootstrap.json");
} }
CUrlList CGlobalSetup::getSwiftDistributionFileUrls() const CUrlList CGlobalSetup::getSwiftUpdateInfoFileUrls() const
{ {
return getSwiftSharedUrls().withAppendedPath(CGlobalSetup::schemaVersionString() + "/updateinfo/distribution.json"); return getSwiftSharedUrls().withAppendedPath(CGlobalSetup::schemaVersionString() + "/updateinfo/updateinfo.json");
} }
CUrl CGlobalSetup::getDbHomePageUrl() const CUrl CGlobalSetup::getDbHomePageUrl() const
@@ -271,7 +271,7 @@ namespace BlackCore
% separator % separator
% "Distribution URLs: " % "Distribution URLs: "
% getSwiftDistributionFileUrls().toQString(i18n) % getSwiftUpdateInfoFileUrls().toQString(i18n)
% separator % separator
% "Bootstrap URLs: " % "Bootstrap URLs: "
% getSwiftBootstrapFileUrls().toQString(i18n) % getSwiftBootstrapFileUrls().toQString(i18n)
@@ -345,7 +345,7 @@ namespace BlackCore
case IndexVatsimBookings: return CVariant::fromValue(m_vatsimDataFileUrls); case IndexVatsimBookings: return CVariant::fromValue(m_vatsimDataFileUrls);
case IndexVatsimMetars: return CVariant::fromValue(m_vatsimMetarsUrls); case IndexVatsimMetars: return CVariant::fromValue(m_vatsimMetarsUrls);
case IndexBootstrapFileUrls: return CVariant::fromValue(this->getSwiftBootstrapFileUrls()); case IndexBootstrapFileUrls: return CVariant::fromValue(this->getSwiftBootstrapFileUrls());
case IndexDistributionFileUrls: return CVariant::fromValue(this->getSwiftDistributionFileUrls()); case IndexUpdateInfoFileUrls: return CVariant::fromValue(this->getSwiftUpdateInfoFileUrls());
case IndexSharedUrls: return CVariant::fromValue(m_sharedUrls); case IndexSharedUrls: return CVariant::fromValue(m_sharedUrls);
case IndexNewsUrls: return CVariant::fromValue(m_newsUrls); case IndexNewsUrls: return CVariant::fromValue(m_newsUrls);
case IndexSwiftMapUrls: return CVariant::fromValue(m_mapUrls); case IndexSwiftMapUrls: return CVariant::fromValue(m_mapUrls);

View File

@@ -52,7 +52,7 @@ namespace BlackCore
IndexSwiftDbFiles, IndexSwiftDbFiles,
IndexSwiftMapUrls, IndexSwiftMapUrls,
IndexBootstrapFileUrls, IndexBootstrapFileUrls,
IndexDistributionFileUrls, IndexUpdateInfoFileUrls,
IndexNewsUrls, IndexNewsUrls,
IndexOnlineHelpUrls, IndexOnlineHelpUrls,
IndexCrashReportServerUrl, IndexCrashReportServerUrl,
@@ -142,7 +142,7 @@ namespace BlackCore
//! Distribution URLs //! Distribution URLs
//! \remark based on getSwiftSharedUrls //! \remark based on getSwiftSharedUrls
BlackMisc::Network::CUrlList getSwiftDistributionFileUrls() const; BlackMisc::Network::CUrlList getSwiftUpdateInfoFileUrls() const;
//! URL to read VATSIM bookings //! URL to read VATSIM bookings
const BlackMisc::Network::CUrl &getVatsimBookingsUrl() const { return m_vatsimBookingsUrl; } const BlackMisc::Network::CUrl &getVatsimBookingsUrl() const { return m_vatsimBookingsUrl; }
@@ -230,7 +230,7 @@ namespace BlackCore
BlackMisc::Network::CUrlList m_onlineHelpUrls; //!< online help URLs BlackMisc::Network::CUrlList m_onlineHelpUrls; //!< online help URLs
BlackMisc::Network::CUrlList m_mapUrls; //!< swift map URLs BlackMisc::Network::CUrlList m_mapUrls; //!< swift map URLs
BlackMisc::Network::CServerList m_fsdTestServers; //!< FSD test servers BlackMisc::Network::CServerList m_fsdTestServers; //!< FSD test servers
BlackMisc::Network::CUrl m_ncepGlobalForecastSystemUrl; //!< NCEP GFS url BlackMisc::Network::CUrl m_ncepGlobalForecastSystemUrl; //!< NCEP GFS url
// transient members, to be switched on/off via GUI or set from reader // transient members, to be switched on/off via GUI or set from reader
bool m_dbDebugFlag = false; //!< can trigger DEBUG on the server, so you need to know what you are doing bool m_dbDebugFlag = false; //!< can trigger DEBUG on the server, so you need to know what you are doing

View File

@@ -77,15 +77,14 @@ namespace BlackCore
const bool cacheAvailable = cachedSetup.wasLoaded(); const bool cacheAvailable = cachedSetup.wasLoaded();
msgs.push_back(cacheAvailable ? msgs.push_back(cacheAvailable ?
CStatusMessage(this, CStatusMessage::SeverityInfo , "Cached setup synchronized and contains data") : CStatusMessage(this, CStatusMessage::SeverityInfo , "Cached setup synchronized and contains data") :
CStatusMessage(this, CStatusMessage::SeverityInfo , "Cached setup synchronized, but no data in cache") CStatusMessage(this, CStatusMessage::SeverityInfo , "Cached setup synchronized, but no data in cache"));
);
if (m_bootstrapMode == CacheOnly) if (m_bootstrapMode == CacheOnly)
{ {
m_distributionUrls = cachedSetup.getSwiftDistributionFileUrls(); m_updateInfoUrls = cachedSetup.getSwiftUpdateInfoFileUrls(); // we use the info URLs from cached setup
msgs.push_back(cacheAvailable ? msgs.push_back(cacheAvailable ?
CStatusMessage(this, CStatusMessage::SeverityInfo, "Cache only setup, using it as it is") : CStatusMessage(this, CStatusMessage::SeverityInfo, "Cache only setup, using it as it is") :
CStatusMessage(this, CStatusMessage::SeverityError, "Cache only setup, but cache is empty") CStatusMessage(this, CStatusMessage::SeverityError, "Cache only setup, but cache is empty"));
);
msgs.push_back(this->manageSetupAvailability(false, false)); msgs.push_back(this->manageSetupAvailability(false, false));
return msgs; return msgs;
} }
@@ -247,23 +246,18 @@ namespace BlackCore
return m; return m;
} }
void CSetupReader::readDistributionInfo() void CSetupReader::readUpdateInfo()
{ {
const CUrl url(m_distributionUrls.obtainNextWorkingUrl()); const CUrl url(m_updateInfoUrls.obtainNextWorkingUrl());
if (url.isEmpty()) if (url.isEmpty())
{ {
CLogMessage(this).warning("Cannot read update info, URLs: '%1', failed URLs: '%2'") << m_distributionUrls << m_distributionUrls.getFailedUrls(); CLogMessage(this).warning("Cannot read update info, URLs: '%1', failed URLs: '%2'") << m_updateInfoUrls << m_updateInfoUrls.getFailedUrls();
CLogMessage::preformatted(CNetworkUtils::createNetworkReport(sApp->getNetworkAccessManager())); CLogMessage::preformatted(CNetworkUtils::createNetworkReport(sApp->getNetworkAccessManager()));
this->manageDistributionsInfoAvailability(false); this->manageUpdateInfoAvailability(false);
return; return;
} }
if (m_shutdown) { return; } if (m_shutdown) { return; }
sApp->getFromNetwork(url.toNetworkRequest(), { this, &CSetupReader::parseDistributionsFile}); sApp->getFromNetwork(url.toNetworkRequest(), { this, &CSetupReader::parseUpdateInfoFile});
}
void CSetupReader::setupChanged()
{
// settings have changed on disk
} }
CSetupReader::BootstrapMode CSetupReader::stringToEnum(const QString &s) CSetupReader::BootstrapMode CSetupReader::stringToEnum(const QString &s)
@@ -352,7 +346,7 @@ namespace BlackCore
bool sameVersionLoaded = (loadedSetup == currentSetup); bool sameVersionLoaded = (loadedSetup == currentSetup);
if (sameVersionLoaded) if (sameVersionLoaded)
{ {
m_distributionUrls = currentSetup.getSwiftDistributionFileUrls(); // defaults m_updateInfoUrls = currentSetup.getSwiftUpdateInfoFileUrls(); // defaults
CLogMessage(this).info("Same setup version loaded from '%1' as already in data cache '%2'") << urlString << m_setup.getFilename(); CLogMessage(this).info("Same setup version loaded from '%1' as already in data cache '%2'") << urlString << m_setup.getFilename();
CLogMessage::preformatted(this->manageSetupAvailability(true)); CLogMessage::preformatted(this->manageSetupAvailability(true));
return; // success return; // success
@@ -365,7 +359,7 @@ namespace BlackCore
if (m.isSeverityInfoOrLess()) if (m.isSeverityInfoOrLess())
{ {
// no issue with cache // no issue with cache
m_distributionUrls = loadedSetup.getSwiftDistributionFileUrls(); m_updateInfoUrls = loadedSetup.getSwiftUpdateInfoFileUrls();
CLogMessage(this).info("Loaded setup from '%1'") << urlString; CLogMessage(this).info("Loaded setup from '%1'") << urlString;
CLogMessage(this).info("Setup: Updated data cache in '%1'") << m_setup.getFilename(); CLogMessage(this).info("Setup: Updated data cache in '%1'") << m_setup.getFilename();
{ {
@@ -395,15 +389,16 @@ namespace BlackCore
// network error, log as warning as we will read again if possible // network error, log as warning as we will read again if possible
// however, store as error because this will be a possible root cause if nothing else is // however, store as error because this will be a possible root cause if nothing else is
nwReply->abort(); nwReply->abort();
const CStatusMessage msg = CStatusMessage(this).error("Reading setup failed '%1' '%2' (can possibly be fixed by reading from another server afterwards)") << replyMessage << urlString;
CLogMessage::preformatted(msg);
this->setLastSetupReadErrorMessages(msg);
} }
// try next one if any // try next one if any
if (m_bootstrapUrls.addFailedUrl(url)) if (m_bootstrapUrls.addFailedUrl(url))
{ {
m_distributionUrls.addFailedHost(url); // the same host will likely fail for distributions CStatusMessage msg = CStatusMessage(this).warning("Reading setup failed %1 %2 (can possibly be fixed by reading from another %3 servers afterwards)")
<< replyMessage << urlString
<< m_bootstrapUrls.numberOfStillValidUrls();
this->setLastSetupReadErrorMessages(msg);
CLogMessage::preformatted(msg);
QTimer::singleShot(500, this, &CSetupReader::readSetup); QTimer::singleShot(500, this, &CSetupReader::readSetup);
} }
else else
@@ -413,7 +408,7 @@ namespace BlackCore
} }
} }
void CSetupReader::parseDistributionsFile(QNetworkReply *nwReplyPtr) void CSetupReader::parseUpdateInfoFile(QNetworkReply *nwReplyPtr)
{ {
// wrap pointer, make sure any exit cleans up reply // wrap pointer, make sure any exit cleans up reply
// required to use delete later as object is created in a different thread // required to use delete later as object is created in a different thread
@@ -427,9 +422,9 @@ namespace BlackCore
if (nwReply->error() == QNetworkReply::NoError) if (nwReply->error() == QNetworkReply::NoError)
{ {
const qint64 lastModified = CNetworkUtils::lastModifiedMsSinceEpoch(nwReply.data()); const qint64 lastModified = CNetworkUtils::lastModifiedMsSinceEpoch(nwReply.data());
const QString distributionJson(nwReplyPtr->readAll()); const QString updateInfoJsonString(nwReplyPtr->readAll());
nwReplyPtr->close(); nwReplyPtr->close();
if (distributionJson.isEmpty()) if (updateInfoJsonString.isEmpty())
{ {
CLogMessage(this).info("No distribution file content"); CLogMessage(this).info("No distribution file content");
// try next URL // try next URL
@@ -438,30 +433,30 @@ namespace BlackCore
{ {
try try
{ {
const CDistributionList loadedDistributions = CDistributionList::fromDatabaseJson(distributionJson); const CUpdateInfo updateInfo = CUpdateInfo::fromDatabaseJson(updateInfoJsonString);
if (loadedDistributions.isEmpty()) if (updateInfo.isEmpty())
{ {
CLogMessage(this).error("Loading of distribution yielded no data"); CLogMessage(this).error("Loading of update info yielded no data");
this->manageDistributionsInfoAvailability(false); this->manageUpdateInfoAvailability(false);
} }
else else
{ {
CStatusMessage m = m_distributions.set(loadedDistributions, lastModified); CStatusMessage m = m_updateInfo.set(updateInfo, lastModified);
if (m.isFailure()) if (m.isFailure())
{ {
m.addCategories(getLogCategories()); m.addCategories(getLogCategories());
CLogMessage::preformatted(m); CLogMessage::preformatted(m);
this->manageDistributionsInfoAvailability(false); this->manageUpdateInfoAvailability(false);
} }
else else
{ {
{ {
QWriteLocker l(&m_lockDistribution); QWriteLocker l(&m_lockDistribution);
m_lastSuccessfulDistributionUrl = urlString; m_lastSuccessfulUpdateInfoUrl = urlString;
} }
CLogMessage(this).info("Distribution info loaded from '%1") << urlString; CLogMessage(this).info("Update info loaded from '%1") << urlString;
CLogMessage(this).info("Distribution info: Updated data cache in '%1'") << m_distributions.getFilename(); CLogMessage(this).info("Update info: Updated data cache in '%1', artifacts: %2, distributions: %3") << m_updateInfo.getFilename() << updateInfo.getArtifactsPilotClient().size() << updateInfo.getDistributions().size();
this->manageDistributionsInfoAvailability(true); this->manageUpdateInfoAvailability(true);
} // cache } // cache
} }
return; return;
@@ -481,20 +476,22 @@ namespace BlackCore
} // no error } // no error
else else
{ {
// network error // network error, try next URL
nwReply->abort(); nwReply->abort();
CLogMessage(this).error("Reading update info failed %1 %2 (can possibly be fixed by reading from another server afterwards)") << replyMessage << urlString;
} }
// try next one if any // try next one if any
if (m_distributionUrls.addFailedUrl(url)) if (m_updateInfoUrls.addFailedUrl(url))
{ {
QTimer::singleShot(500, this, &CSetupReader::readDistributionInfo); CLogMessage(this).warning("Reading update info failed %1 %2 (can possibly be fixed by reading from another %3 servers afterwards)")
<< replyMessage << urlString
<< m_updateInfoUrls.numberOfStillValidUrls();
QTimer::singleShot(500, this, &CSetupReader::readUpdateInfo);
} }
else else
{ {
const CStatusMessageList msgs = this->manageSetupAvailability(false); this->manageUpdateInfoAvailability(false);
CLogMessage::preformatted(msgs); CLogMessage(this).error("Reading update info failed %1 %2, failed URLs %3") << replyMessage << urlString << m_updateInfoUrls.getFailedUrlsSize();
} }
} }
@@ -561,26 +558,26 @@ namespace BlackCore
return m_lastSuccessfulSetupUrl; return m_lastSuccessfulSetupUrl;
} }
CDistributionList CSetupReader::getDistributionInfo() const CUpdateInfo CSetupReader::getUpdateInfo() const
{ {
return m_distributions.get(); return m_updateInfo.get();
} }
bool CSetupReader::hasCachedDistributionInfo() const bool CSetupReader::hasCachedUpdateInfo() const
{ {
const CDistributionList distributions = m_distributions.get(); const CUpdateInfo updateInfo = m_updateInfo.get();
return !distributions.isEmpty(); return !updateInfo.isEmpty();
} }
QDateTime CSetupReader::getDistributionCacheTimestamp() const QDateTime CSetupReader::getDistributionCacheTimestamp() const
{ {
return m_distributions.getTimestamp(); return m_updateInfo.getTimestamp();
} }
QString CSetupReader::getLastSuccessfulDistributionUrl() const QString CSetupReader::getLastSuccessfulDistributionUrl() const
{ {
QReadLocker l(&m_lockDistribution); QReadLocker l(&m_lockDistribution);
return m_lastSuccessfulDistributionUrl; return m_lastSuccessfulUpdateInfoUrl;
} }
CStatusMessageList CSetupReader::getLastSetupReadErrorMessages() const CStatusMessageList CSetupReader::getLastSetupReadErrorMessages() const
@@ -600,8 +597,8 @@ namespace BlackCore
switch (m_bootstrapMode) switch (m_bootstrapMode)
{ {
case CacheOnly: return "cache only"; case CacheOnly: return "cache only";
case Explicit: return "explicit"; case Explicit: return "explicit";
case Implicit: return "implicit"; case Implicit: return "implicit";
default: break; default: break;
} }
return ""; return "";
@@ -619,13 +616,13 @@ namespace BlackCore
CStatusMessageList msgs; CStatusMessageList msgs;
if (webRead) if (webRead)
{ {
msgs.push_back(CStatusMessage(this).info("Setup loaded from web, will trigger read of distribution information")); msgs.push_back(CStatusMessage(this).info("Setup loaded from web, will trigger read of update information"));
QTimer::singleShot(500, this, &CSetupReader::readDistributionInfo); QTimer::singleShot(500, this, &CSetupReader::readUpdateInfo);
} }
if (localRead) if (localRead)
{ {
msgs.push_back(CStatusMessage(this).info("Setup loaded locally, will trigger read of distribution information")); msgs.push_back(CStatusMessage(this).info("Setup loaded locally, will trigger read of update information"));
QTimer::singleShot(500, this, &CSetupReader::readDistributionInfo); QTimer::singleShot(500, this, &CSetupReader::readUpdateInfo);
} }
bool available = false; bool available = false;
@@ -635,7 +632,7 @@ namespace BlackCore
} }
else else
{ {
bool cacheAvailable = m_setup.get().wasLoaded(); const bool cacheAvailable = m_setup.get().wasLoaded();
available = cacheAvailable && m_bootstrapMode != Explicit; available = cacheAvailable && m_bootstrapMode != Explicit;
} }
@@ -657,23 +654,23 @@ namespace BlackCore
if (!webRead && !localRead) if (!webRead && !localRead)
{ {
msgs.push_back(CStatusMessage(this).warning("Since setup was not updated this time, will not start loading of update information")); msgs.push_back(CStatusMessage(this).warning("Since setup was not updated this time, will not start loading of update information"));
this->manageDistributionsInfoAvailability(false); this->manageUpdateInfoAvailability(false);
} }
return msgs; return msgs;
} }
void CSetupReader::manageDistributionsInfoAvailability(bool webRead) void CSetupReader::manageUpdateInfoAvailability(bool webRead)
{ {
if (webRead) if (webRead)
{ {
m_distributionInfoAvailable = true; m_updateInfoAvailable = true;
emit distributionInfoAvailable(true); emit updateInfoAvailable(true);
} }
else else
{ {
const bool cached = m_distributions.isSaved(); const bool cached = m_updateInfo.isSaved();
m_distributionInfoAvailable = cached; m_updateInfoAvailable = cached;
emit distributionInfoAvailable(cached); emit updateInfoAvailable(cached);
} }
} }
} // namespace } // namespace

View File

@@ -14,7 +14,7 @@
#include "blackcore/blackcoreexport.h" #include "blackcore/blackcoreexport.h"
#include "blackcore/data/globalsetup.h" #include "blackcore/data/globalsetup.h"
#include "blackmisc/db/distributionlist.h" #include "blackmisc/db/updateinfo.h"
#include "blackmisc/datacache.h" #include "blackmisc/datacache.h"
#include "blackmisc/network/urllist.h" #include "blackmisc/network/urllist.h"
#include "blackmisc/statusmessagelist.h" #include "blackmisc/statusmessagelist.h"
@@ -44,7 +44,7 @@ namespace BlackCore
//! Once the file is in place (i.e. in the cache) it can be automatically updated. //! Once the file is in place (i.e. in the cache) it can be automatically updated.
//! //!
//! \sa BlackCore::Data::TGlobalSetup //! \sa BlackCore::Data::TGlobalSetup
//! \sa BlackMisc::Db::TDistributionInfo //! \sa BlackMisc::Db::TUpdateInfo
class BLACKCORE_EXPORT CSetupReader : public QObject class BLACKCORE_EXPORT CSetupReader : public QObject
{ {
Q_OBJECT Q_OBJECT
@@ -91,13 +91,13 @@ namespace BlackCore
//! \threadsafe //! \threadsafe
QString getLastSuccessfulSetupUrl() const; QString getLastSuccessfulSetupUrl() const;
//! Distributions info (channel, version, platforms, download URLs) //! Update info (artifacts and distributions)
//! \threadsafe //! \threadsafe
BlackMisc::Db::CDistributionList getDistributionInfo() const; BlackMisc::Db::CUpdateInfo getUpdateInfo() const;
//! Has cached distribution info? //! Has cached distribution info?
//! \threadsafe //! \threadsafe
bool hasCachedDistributionInfo() const; bool hasCachedUpdateInfo() const;
//! Distribution cache timestamp //! Distribution cache timestamp
//! \threadsafe //! \threadsafe
@@ -120,8 +120,8 @@ namespace BlackCore
//! Setup fetched or failed (from web, cache, or local file) //! Setup fetched or failed (from web, cache, or local file)
void setupHandlingCompleted(bool available); void setupHandlingCompleted(bool available);
//! Setup avialable (from web, cache //! Update infao available (from web, cache)
void distributionInfoAvailable(bool available); void updateInfoAvailable(bool available);
//! A shared URL was successfully read //! A shared URL was successfully read
void successfullyReadSharedUrl(const BlackMisc::Network::CUrl &sharedUrl); void successfullyReadSharedUrl(const BlackMisc::Network::CUrl &sharedUrl);
@@ -148,7 +148,7 @@ namespace BlackCore
//! Version info available? //! Version info available?
//! \threadsafe //! \threadsafe
bool isUpdateInfoAvailable() const { return m_distributionInfoAvailable; } bool isUpdateInfoAvailable() const { return m_updateInfoAvailable; }
private: private:
//! Bootstrap mode //! Bootstrap mode
@@ -160,39 +160,36 @@ namespace BlackCore
}; };
std::atomic<bool> m_shutdown { false }; std::atomic<bool> m_shutdown { false };
std::atomic<bool> m_setupAvailable { false }; std::atomic<bool> m_setupAvailable { false }; //!< setup available
std::atomic<bool> m_distributionInfoAvailable { false }; std::atomic<bool> m_updateInfoAvailable { false }; //!< update info available
std::atomic<bool> m_ignoreCmdBootstrapUrl { false }; //!< ignore the explicitly set bootstrap URL std::atomic<bool> m_ignoreCmdBootstrapUrl { false }; //!< ignore the explicitly set bootstrap URL
std::atomic<bool> m_checkCmdBootstrapUrl { true }; //!< check connection on CMD bootstrap URL std::atomic<bool> m_checkCmdBootstrapUrl { true }; //!< check connection on CMD bootstrap URL
QString m_localSetupFileValue; //!< Local file for setup, passed by cmd line arguments QString m_localSetupFileValue; //!< Local file for setup, passed by cmd line arguments
QString m_bootstrapUrlFileValue; //!< Bootstrap URL if not local QString m_bootstrapUrlFileValue; //!< Bootstrap URL if not local
BootstrapMode m_bootstrapMode = Explicit; //!< How to bootstrap BootstrapMode m_bootstrapMode = Explicit; //!< How to bootstrap
BlackMisc::Network::CFailoverUrlList m_bootstrapUrls; //!< location of setup files BlackMisc::Network::CFailoverUrlList m_bootstrapUrls; //!< location of setup files
BlackMisc::Network::CFailoverUrlList m_distributionUrls; //!< location of info files BlackMisc::Network::CFailoverUrlList m_updateInfoUrls; //!< location of info files
QCommandLineOption m_cmdBootstrapUrl; //!< bootstrap URL QCommandLineOption m_cmdBootstrapUrl; //!< bootstrap URL
QCommandLineOption m_cmdBootstrapMode; //!< bootstrap mode QCommandLineOption m_cmdBootstrapMode; //!< bootstrap mode
mutable QReadWriteLock m_lockSetup; //!< lock for setup mutable QReadWriteLock m_lockSetup; //!< lock for setup
mutable QReadWriteLock m_lockDistribution; //!< lock for distribution mutable QReadWriteLock m_lockUpdateInfo; //!< lock for update info
QString m_lastSuccessfulSetupUrl; //!< last successful read setup URL QString m_lastSuccessfulSetupUrl; //!< last successful read setup URL
QString m_lastSuccessfulDistributionUrl; //!< last successful read distribution URL QString m_lastSuccessfulUpdateInfoUrl; //!< last successful read update info URL
BlackMisc::CStatusMessageList m_setupReadErrorMsgs; //!< last parsing error messages BlackMisc::CStatusMessageList m_setupReadErrorMsgs; //!< last parsing error messages
BlackMisc::CData<BlackCore::Data::TGlobalSetup> m_setup { this, &CSetupReader::setupChanged }; //!< data cache setup BlackMisc::CData<Data::TGlobalSetup> m_setup { this }; //!< data cache setup
BlackMisc::CData<BlackMisc::Db::TDistributionsInfo> m_distributions { this }; //!< data cache distributions BlackMisc::CData<BlackMisc::Db::TUpdateInfo> m_updateInfo { this }; //!< data cache distributions
//! Setup has been read (aka bootstrap file) //! Setup has been read (aka bootstrap file)
void parseSetupFile(QNetworkReply *nwReply); void parseBootstrapFile(QNetworkReply *nwReplyPtr);
//! Update info has been read //! Update info has been read
void parseDistributionsFile(QNetworkReply *nwReplyPtr); void parseUpdateInfoFile(QNetworkReply *nwReplyPtr);
//! Do reading //! Do reading
void readSetup(); void readSetup();
//! Do reading of distributions //! Do reading of distributions
void readDistributionInfo(); void readUpdateInfo();
//! Setup has been changed
void setupChanged();
//! Read by local individual file and update cache from that //! Read by local individual file and update cache from that
BlackMisc::CStatusMessageList readLocalBootstrapFile(const QString &fileName); BlackMisc::CStatusMessageList readLocalBootstrapFile(const QString &fileName);
@@ -206,12 +203,12 @@ namespace BlackCore
//! Emit the available signal //! Emit the available signal
//! \threadsafe //! \threadsafe
void manageDistributionsInfoAvailability(bool webRead); void manageUpdateInfoAvailability(bool webRead);
//! Set last setup parsing messages //! Set last setup parsing messages
void setLastSetupReadErrorMessages(const BlackMisc::CStatusMessageList &messages); void setLastSetupReadErrorMessages(const BlackMisc::CStatusMessageList &messages);
//! Convert string to mode //! Convert string to bootstrap mode
static BootstrapMode stringToEnum(const QString &s); static BootstrapMode stringToEnum(const QString &s);
//! Bootsrap URL used for unit tests //! Bootsrap URL used for unit tests