mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
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:
committed by
Mathew Sutcliffe
parent
04e980a6ae
commit
1ced7f3c0b
@@ -181,6 +181,12 @@ namespace BlackCore
|
||||
{
|
||||
this->threadAssertCheck();
|
||||
if (this->isShuttingDown()) { return; }
|
||||
entity &= CEntityFlags::AirportEntity;
|
||||
if (!this->isNetworkConnectedAndAccessible())
|
||||
{
|
||||
emit this->dataRead(entity, CEntityFlags::ReadSkipped, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (entity.testFlag(CEntityFlags::AirportEntity))
|
||||
{
|
||||
|
||||
@@ -167,7 +167,7 @@ namespace BlackCore
|
||||
|
||||
// ps_read is implemented in the derived classes
|
||||
if (entities == CEntityFlags::NoEntity) { return; }
|
||||
if (!this->isNetworkAvailable())
|
||||
if (!this->isNetworkConnectedAndAccessible())
|
||||
{
|
||||
CLogMessage(this).warning("No network, will not read %1") << CEntityFlags::flagToString(entities);
|
||||
return;
|
||||
@@ -318,7 +318,7 @@ namespace BlackCore
|
||||
|
||||
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);
|
||||
return false;
|
||||
|
||||
@@ -132,6 +132,12 @@ namespace BlackCore
|
||||
{
|
||||
this->threadAssertCheck(); // runs in background thread
|
||||
if (this->isShuttingDown()) { return; }
|
||||
entities &= CEntityFlags::AllIcaoAndCountries;
|
||||
if (!this->isNetworkConnectedAndAccessible())
|
||||
{
|
||||
emit this->dataRead(entities, CEntityFlags::ReadSkipped, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
CEntityFlags::Entity entitiesTriggered = CEntityFlags::NoEntity;
|
||||
if (entities.testFlag(CEntityFlags::AircraftIcaoEntity))
|
||||
@@ -181,7 +187,7 @@ namespace BlackCore
|
||||
|
||||
if (entitiesTriggered != CEntityFlags::NoEntity)
|
||||
{
|
||||
emit dataRead(entitiesTriggered, CEntityFlags::StartRead, 0);
|
||||
emit this->dataRead(entitiesTriggered, CEntityFlags::StartRead, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -147,13 +147,19 @@ namespace BlackCore
|
||||
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();
|
||||
if (this->isShuttingDown()) { return; }
|
||||
entities &= CEntityFlags::DistributorLiveryModel;
|
||||
if (!this->isNetworkConnectedAndAccessible())
|
||||
{
|
||||
emit this->dataRead(entities, CEntityFlags::ReadSkipped, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
CEntityFlags::Entity triggeredRead = CEntityFlags::NoEntity;
|
||||
if (entity.testFlag(CEntityFlags::LiveryEntity))
|
||||
if (entities.testFlag(CEntityFlags::LiveryEntity))
|
||||
{
|
||||
CUrl url(getLiveryUrl(mode));
|
||||
if (!url.isEmpty())
|
||||
@@ -172,7 +178,7 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
if (entity.testFlag(CEntityFlags::DistributorEntity))
|
||||
if (entities.testFlag(CEntityFlags::DistributorEntity))
|
||||
{
|
||||
CUrl url(getDistributorUrl(mode));
|
||||
if (!url.isEmpty())
|
||||
@@ -191,7 +197,7 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
if (entity.testFlag(CEntityFlags::ModelEntity))
|
||||
if (entities.testFlag(CEntityFlags::ModelEntity))
|
||||
{
|
||||
CUrl url(getModelUrl(mode));
|
||||
if (!url.isEmpty())
|
||||
|
||||
@@ -136,6 +136,7 @@ namespace BlackCore
|
||||
virtual void invalidateCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
|
||||
virtual bool hasChangedUrl(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
||||
virtual BlackMisc::Network::CUrl getDbServiceBaseUrl() const override;
|
||||
|
||||
private slots:
|
||||
//! Liveries have been read
|
||||
void ps_parseLiveryData(QNetworkReply *nwReply);
|
||||
@@ -147,7 +148,7 @@ namespace BlackCore
|
||||
void ps_parseModelData(QNetworkReply *nwReply);
|
||||
|
||||
//! 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());
|
||||
|
||||
void ps_liveryCacheChanged();
|
||||
|
||||
@@ -69,10 +69,9 @@ namespace BlackCore
|
||||
return delta <= timeLastMs;
|
||||
}
|
||||
|
||||
bool CThreadedReader::isNetworkAvailable() const
|
||||
bool CThreadedReader::isNetworkConnectedAndAccessible() const
|
||||
{
|
||||
static const bool nw = CNetworkUtils::hasConnectedInterface();
|
||||
return nw;
|
||||
return sApp->isNetworkConnectedAndAccessible();
|
||||
}
|
||||
|
||||
void CThreadedReader::gracefulShutdown()
|
||||
@@ -98,9 +97,9 @@ namespace BlackCore
|
||||
|
||||
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 (this->m_shutdown) { return true; } // marked as shutdown
|
||||
if (this->isAbandoned()) { return true; } // worker abandoned
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace BlackCore
|
||||
bool updatedWithinLastMs(qint64 timeLastMs);
|
||||
|
||||
//! Network available
|
||||
bool isNetworkAvailable() const;
|
||||
bool isNetworkConnectedAndAccessible() const;
|
||||
|
||||
//! Is marked as read failed
|
||||
//! \threadsafe
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace BlackCore
|
||||
|
||||
void CVatsimBookingReader::ps_read()
|
||||
{
|
||||
if (!this->isNetworkAvailable())
|
||||
if (!this->isNetworkConnectedAndAccessible())
|
||||
{
|
||||
CLogMessage(this).warning("No network, cannot read VATSIM bookings");
|
||||
return;
|
||||
|
||||
@@ -185,7 +185,7 @@ namespace BlackCore
|
||||
|
||||
void CVatsimDataFileReader::ps_read()
|
||||
{
|
||||
if (!this->isNetworkAvailable())
|
||||
if (!this->isNetworkConnectedAndAccessible())
|
||||
{
|
||||
CLogMessage(this).warning("No network, cannot read VATSIM data file");
|
||||
return;
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace BlackCore
|
||||
void CVatsimMetarReader::readMetars()
|
||||
{
|
||||
if (this->isAbandoned()) { return; }
|
||||
if (!this->isNetworkAvailable())
|
||||
if (!this->isNetworkConnectedAndAccessible())
|
||||
{
|
||||
CLogMessage(this).warning("No network, cannot read METARs");
|
||||
return;
|
||||
|
||||
@@ -71,6 +71,7 @@ namespace BlackCore
|
||||
void CVatsimStatusFileReader::ps_read()
|
||||
{
|
||||
this->threadAssertCheck();
|
||||
if (!this->isNetworkConnectedAndAccessible()) { return; }
|
||||
|
||||
Q_ASSERT_X(sApp, Q_FUNC_INFO, "Missing application");
|
||||
CFailoverUrlList urls(sApp->getGlobalSetup().getVatsimStatusFileUrls());
|
||||
|
||||
@@ -79,6 +79,7 @@ namespace BlackMisc
|
||||
case ReadFinished: return "finished";
|
||||
case ReadFinishedRestricted: return "finished (restricted)";
|
||||
case ReadFailed: return "failed";
|
||||
case ReadSkipped: return "skipped";
|
||||
case StartRead: return "read started";
|
||||
default:
|
||||
BLACK_VERIFY_X(false, Q_FUNC_INFO, "wrong flags");
|
||||
@@ -94,6 +95,8 @@ namespace BlackMisc
|
||||
case ReadFinishedRestricted:
|
||||
case StartRead:
|
||||
return CStatusMessage::SeverityInfo;
|
||||
case ReadSkipped:
|
||||
return CStatusMessage::SeverityWarning;
|
||||
case ReadFailed:
|
||||
return CStatusMessage::SeverityError;
|
||||
default:
|
||||
|
||||
@@ -62,7 +62,8 @@ namespace BlackMisc
|
||||
StartRead, //!< reading has been started
|
||||
ReadFinished, //!< reading done
|
||||
ReadFinishedRestricted, //!< finished a timestamp restricted read
|
||||
ReadFailed //!< reading failed
|
||||
ReadFailed, //!< reading failed
|
||||
ReadSkipped //!< read skipped, e.g. because network is down
|
||||
};
|
||||
|
||||
//! Convert to string
|
||||
|
||||
@@ -65,9 +65,14 @@ namespace BlackWxPlugin
|
||||
m_maxRange = range;
|
||||
if (m_gribData.isEmpty())
|
||||
{
|
||||
CLogMessage(this).debug() << "Started to download GFS data...";
|
||||
QUrl url = getDownloadUrl();
|
||||
CLogMessage(this).debug() << "Download url:" << url.toString();
|
||||
if (!sApp->isNetworkConnectedAndAccessible())
|
||||
{
|
||||
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);
|
||||
sApp->getFromNetwork(request, { this, &CWeatherDataGfs::ps_parseGfsFile });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user