refs #857, check if network is accessible in readers

* new read state "skipped"
* renamed to "isNetworkConnectedAndAccessible"
* checking before reading, which would only fail if network is not accessible
This commit is contained in:
Klaus Basan
2017-01-12 18:07:35 +01:00
committed by Mathew Sutcliffe
parent 04e980a6ae
commit 1ced7f3c0b
14 changed files with 49 additions and 21 deletions

View File

@@ -181,6 +181,12 @@ namespace BlackCore
{ {
this->threadAssertCheck(); this->threadAssertCheck();
if (this->isShuttingDown()) { return; } if (this->isShuttingDown()) { return; }
entity &= CEntityFlags::AirportEntity;
if (!this->isNetworkConnectedAndAccessible())
{
emit this->dataRead(entity, CEntityFlags::ReadSkipped, 0);
return;
}
if (entity.testFlag(CEntityFlags::AirportEntity)) if (entity.testFlag(CEntityFlags::AirportEntity))
{ {

View File

@@ -167,7 +167,7 @@ namespace BlackCore
// ps_read is implemented in the derived classes // ps_read is implemented in the derived classes
if (entities == CEntityFlags::NoEntity) { return; } if (entities == CEntityFlags::NoEntity) { return; }
if (!this->isNetworkAvailable()) if (!this->isNetworkConnectedAndAccessible())
{ {
CLogMessage(this).warning("No network, will not read %1") << CEntityFlags::flagToString(entities); CLogMessage(this).warning("No network, will not read %1") << CEntityFlags::flagToString(entities);
return; return;
@@ -318,7 +318,7 @@ namespace BlackCore
bool CDatabaseReader::requestHeadersOfSharedFiles(const CEntityFlags::Entity &entities) bool CDatabaseReader::requestHeadersOfSharedFiles(const CEntityFlags::Entity &entities)
{ {
if (!this->isNetworkAvailable()) if (!this->isNetworkConnectedAndAccessible())
{ {
CLogMessage(this).warning("No network, will not read shared file headers for %1") << CEntityFlags::flagToString(entities); CLogMessage(this).warning("No network, will not read shared file headers for %1") << CEntityFlags::flagToString(entities);
return false; return false;

View File

@@ -132,6 +132,12 @@ namespace BlackCore
{ {
this->threadAssertCheck(); // runs in background thread this->threadAssertCheck(); // runs in background thread
if (this->isShuttingDown()) { return; } if (this->isShuttingDown()) { return; }
entities &= CEntityFlags::AllIcaoAndCountries;
if (!this->isNetworkConnectedAndAccessible())
{
emit this->dataRead(entities, CEntityFlags::ReadSkipped, 0);
return;
}
CEntityFlags::Entity entitiesTriggered = CEntityFlags::NoEntity; CEntityFlags::Entity entitiesTriggered = CEntityFlags::NoEntity;
if (entities.testFlag(CEntityFlags::AircraftIcaoEntity)) if (entities.testFlag(CEntityFlags::AircraftIcaoEntity))
@@ -181,7 +187,7 @@ namespace BlackCore
if (entitiesTriggered != CEntityFlags::NoEntity) if (entitiesTriggered != CEntityFlags::NoEntity)
{ {
emit dataRead(entitiesTriggered, CEntityFlags::StartRead, 0); emit this->dataRead(entitiesTriggered, CEntityFlags::StartRead, 0);
} }
} }

View File

@@ -147,13 +147,19 @@ namespace BlackCore
getDistributorsCount() > 0; getDistributorsCount() > 0;
} }
void CModelDataReader::ps_read(CEntityFlags::Entity entity, CDbFlags::DataRetrievalModeFlag mode, const QDateTime &newerThan) void CModelDataReader::ps_read(CEntityFlags::Entity entities, CDbFlags::DataRetrievalModeFlag mode, const QDateTime &newerThan)
{ {
this->threadAssertCheck(); this->threadAssertCheck();
if (this->isShuttingDown()) { return; } if (this->isShuttingDown()) { return; }
entities &= CEntityFlags::DistributorLiveryModel;
if (!this->isNetworkConnectedAndAccessible())
{
emit this->dataRead(entities, CEntityFlags::ReadSkipped, 0);
return;
}
CEntityFlags::Entity triggeredRead = CEntityFlags::NoEntity; CEntityFlags::Entity triggeredRead = CEntityFlags::NoEntity;
if (entity.testFlag(CEntityFlags::LiveryEntity)) if (entities.testFlag(CEntityFlags::LiveryEntity))
{ {
CUrl url(getLiveryUrl(mode)); CUrl url(getLiveryUrl(mode));
if (!url.isEmpty()) if (!url.isEmpty())
@@ -172,7 +178,7 @@ namespace BlackCore
} }
} }
if (entity.testFlag(CEntityFlags::DistributorEntity)) if (entities.testFlag(CEntityFlags::DistributorEntity))
{ {
CUrl url(getDistributorUrl(mode)); CUrl url(getDistributorUrl(mode));
if (!url.isEmpty()) if (!url.isEmpty())
@@ -191,7 +197,7 @@ namespace BlackCore
} }
} }
if (entity.testFlag(CEntityFlags::ModelEntity)) if (entities.testFlag(CEntityFlags::ModelEntity))
{ {
CUrl url(getModelUrl(mode)); CUrl url(getModelUrl(mode));
if (!url.isEmpty()) if (!url.isEmpty())

View File

@@ -136,6 +136,7 @@ namespace BlackCore
virtual void invalidateCaches(BlackMisc::Network::CEntityFlags::Entity entities) override; virtual void invalidateCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
virtual bool hasChangedUrl(BlackMisc::Network::CEntityFlags::Entity entity) const override; virtual bool hasChangedUrl(BlackMisc::Network::CEntityFlags::Entity entity) const override;
virtual BlackMisc::Network::CUrl getDbServiceBaseUrl() const override; virtual BlackMisc::Network::CUrl getDbServiceBaseUrl() const override;
private slots: private slots:
//! Liveries have been read //! Liveries have been read
void ps_parseLiveryData(QNetworkReply *nwReply); void ps_parseLiveryData(QNetworkReply *nwReply);
@@ -147,7 +148,7 @@ namespace BlackCore
void ps_parseModelData(QNetworkReply *nwReply); void ps_parseModelData(QNetworkReply *nwReply);
//! Read / re-read data file //! Read / re-read data file
void ps_read(BlackMisc::Network::CEntityFlags::Entity entity = BlackMisc::Network::CEntityFlags::DistributorLiveryModel, void ps_read(BlackMisc::Network::CEntityFlags::Entity entities = BlackMisc::Network::CEntityFlags::DistributorLiveryModel,
BlackMisc::Db::CDbFlags::DataRetrievalModeFlag mode = BlackMisc::Db::CDbFlags::DbReading, const QDateTime &newerThan = QDateTime()); BlackMisc::Db::CDbFlags::DataRetrievalModeFlag mode = BlackMisc::Db::CDbFlags::DbReading, const QDateTime &newerThan = QDateTime());
void ps_liveryCacheChanged(); void ps_liveryCacheChanged();

View File

@@ -69,10 +69,9 @@ namespace BlackCore
return delta <= timeLastMs; return delta <= timeLastMs;
} }
bool CThreadedReader::isNetworkAvailable() const bool CThreadedReader::isNetworkConnectedAndAccessible() const
{ {
static const bool nw = CNetworkUtils::hasConnectedInterface(); return sApp->isNetworkConnectedAndAccessible();
return nw;
} }
void CThreadedReader::gracefulShutdown() void CThreadedReader::gracefulShutdown()
@@ -98,9 +97,9 @@ namespace BlackCore
bool CThreadedReader::isShuttingDown() const bool CThreadedReader::isShuttingDown() const
{ {
if (this->m_shutdown) { return true; }
if (this->isAbandoned()) { return true; }
if (!sApp) { return true; } // sApp object is gone, whole system shutdown if (!sApp) { return true; } // sApp object is gone, whole system shutdown
if (this->m_shutdown) { return true; } // marked as shutdown
if (this->isAbandoned()) { return true; } // worker abandoned
return false; return false;
} }

View File

@@ -53,7 +53,7 @@ namespace BlackCore
bool updatedWithinLastMs(qint64 timeLastMs); bool updatedWithinLastMs(qint64 timeLastMs);
//! Network available //! Network available
bool isNetworkAvailable() const; bool isNetworkConnectedAndAccessible() const;
//! Is marked as read failed //! Is marked as read failed
//! \threadsafe //! \threadsafe

View File

@@ -67,7 +67,7 @@ namespace BlackCore
void CVatsimBookingReader::ps_read() void CVatsimBookingReader::ps_read()
{ {
if (!this->isNetworkAvailable()) if (!this->isNetworkConnectedAndAccessible())
{ {
CLogMessage(this).warning("No network, cannot read VATSIM bookings"); CLogMessage(this).warning("No network, cannot read VATSIM bookings");
return; return;

View File

@@ -185,7 +185,7 @@ namespace BlackCore
void CVatsimDataFileReader::ps_read() void CVatsimDataFileReader::ps_read()
{ {
if (!this->isNetworkAvailable()) if (!this->isNetworkConnectedAndAccessible())
{ {
CLogMessage(this).warning("No network, cannot read VATSIM data file"); CLogMessage(this).warning("No network, cannot read VATSIM data file");
return; return;

View File

@@ -80,7 +80,7 @@ namespace BlackCore
void CVatsimMetarReader::readMetars() void CVatsimMetarReader::readMetars()
{ {
if (this->isAbandoned()) { return; } if (this->isAbandoned()) { return; }
if (!this->isNetworkAvailable()) if (!this->isNetworkConnectedAndAccessible())
{ {
CLogMessage(this).warning("No network, cannot read METARs"); CLogMessage(this).warning("No network, cannot read METARs");
return; return;

View File

@@ -71,6 +71,7 @@ namespace BlackCore
void CVatsimStatusFileReader::ps_read() void CVatsimStatusFileReader::ps_read()
{ {
this->threadAssertCheck(); this->threadAssertCheck();
if (!this->isNetworkConnectedAndAccessible()) { return; }
Q_ASSERT_X(sApp, Q_FUNC_INFO, "Missing application"); Q_ASSERT_X(sApp, Q_FUNC_INFO, "Missing application");
CFailoverUrlList urls(sApp->getGlobalSetup().getVatsimStatusFileUrls()); CFailoverUrlList urls(sApp->getGlobalSetup().getVatsimStatusFileUrls());

View File

@@ -79,6 +79,7 @@ namespace BlackMisc
case ReadFinished: return "finished"; case ReadFinished: return "finished";
case ReadFinishedRestricted: return "finished (restricted)"; case ReadFinishedRestricted: return "finished (restricted)";
case ReadFailed: return "failed"; case ReadFailed: return "failed";
case ReadSkipped: return "skipped";
case StartRead: return "read started"; case StartRead: return "read started";
default: default:
BLACK_VERIFY_X(false, Q_FUNC_INFO, "wrong flags"); BLACK_VERIFY_X(false, Q_FUNC_INFO, "wrong flags");
@@ -94,6 +95,8 @@ namespace BlackMisc
case ReadFinishedRestricted: case ReadFinishedRestricted:
case StartRead: case StartRead:
return CStatusMessage::SeverityInfo; return CStatusMessage::SeverityInfo;
case ReadSkipped:
return CStatusMessage::SeverityWarning;
case ReadFailed: case ReadFailed:
return CStatusMessage::SeverityError; return CStatusMessage::SeverityError;
default: default:

View File

@@ -62,7 +62,8 @@ namespace BlackMisc
StartRead, //!< reading has been started StartRead, //!< reading has been started
ReadFinished, //!< reading done ReadFinished, //!< reading done
ReadFinishedRestricted, //!< finished a timestamp restricted read ReadFinishedRestricted, //!< finished a timestamp restricted read
ReadFailed //!< reading failed ReadFailed, //!< reading failed
ReadSkipped //!< read skipped, e.g. because network is down
}; };
//! Convert to string //! Convert to string

View File

@@ -65,9 +65,14 @@ namespace BlackWxPlugin
m_maxRange = range; m_maxRange = range;
if (m_gribData.isEmpty()) if (m_gribData.isEmpty())
{ {
CLogMessage(this).debug() << "Started to download GFS data..."; if (!sApp->isNetworkConnectedAndAccessible())
QUrl url = getDownloadUrl(); {
CLogMessage(this).debug() << "Download url:" << url.toString(); CLogMessage(this).error("No wether download since network not accessible");
return;
}
const QUrl url = getDownloadUrl();
CLogMessage(this).debug() << "Started to download GFS data from" << url.toString();
QNetworkRequest request(url); QNetworkRequest request(url);
sApp->getFromNetwork(request, { this, &CWeatherDataGfs::ps_parseGfsFile }); sApp->getFromNetwork(request, { this, &CWeatherDataGfs::ps_parseGfsFile });
} }