mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-26 10:45:37 +08:00
Model reader refactorings
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
using namespace BlackMisc::Aviation;
|
using namespace BlackMisc::Aviation;
|
||||||
@@ -38,12 +39,12 @@ namespace BlackCore
|
|||||||
|
|
||||||
CAirport CAirportDataReader::getAirportForIcaoDesignator(const QString &designator) const
|
CAirport CAirportDataReader::getAirportForIcaoDesignator(const QString &designator) const
|
||||||
{
|
{
|
||||||
return getAirports().findFirstByIcao(CAirportIcaoCode(designator));
|
return this->getAirports().findFirstByIcao(CAirportIcaoCode(designator));
|
||||||
}
|
}
|
||||||
|
|
||||||
CAirport CAirportDataReader::getAirportForNameOrLocation(const QString &nameOrLocation) const
|
CAirport CAirportDataReader::getAirportForNameOrLocation(const QString &nameOrLocation) const
|
||||||
{
|
{
|
||||||
return getAirports().findFirstByNameOrLocation(nameOrLocation);
|
return this->getAirports().findFirstByNameOrLocation(nameOrLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CAirportDataReader::getAirportsCount() const
|
int CAirportDataReader::getAirportsCount() const
|
||||||
@@ -54,8 +55,11 @@ namespace BlackCore
|
|||||||
bool CAirportDataReader::readFromJsonFilesInBackground(const QString &dir, CEntityFlags::Entity whatToRead, bool overrideNewerOnly)
|
bool CAirportDataReader::readFromJsonFilesInBackground(const QString &dir, CEntityFlags::Entity whatToRead, bool overrideNewerOnly)
|
||||||
{
|
{
|
||||||
if (dir.isEmpty() || whatToRead == CEntityFlags::NoEntity) { return false; }
|
if (dir.isEmpty() || whatToRead == CEntityFlags::NoEntity) { return false; }
|
||||||
|
|
||||||
|
QPointer<CAirportDataReader> myself(this);
|
||||||
QTimer::singleShot(0, this, [ = ]()
|
QTimer::singleShot(0, this, [ = ]()
|
||||||
{
|
{
|
||||||
|
if (!myself) { return; }
|
||||||
const CStatusMessageList msgs = this->readFromJsonFiles(dir, whatToRead, overrideNewerOnly);
|
const CStatusMessageList msgs = this->readFromJsonFiles(dir, whatToRead, overrideNewerOnly);
|
||||||
if (msgs.isFailure())
|
if (msgs.isFailure())
|
||||||
{
|
{
|
||||||
@@ -179,7 +183,7 @@ namespace BlackCore
|
|||||||
return this->getBaseUrl(mode).withAppendedPath(fileNameForMode(CEntityFlags::AirportEntity, mode));
|
return this->getBaseUrl(mode).withAppendedPath(fileNameForMode(CEntityFlags::AirportEntity, mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAirportDataReader::ps_parseAirportData(QNetworkReply *nwReplyPtr)
|
void CAirportDataReader::parseAirportData(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
|
||||||
@@ -190,7 +194,7 @@ namespace BlackCore
|
|||||||
if (res.hasErrorMessage())
|
if (res.hasErrorMessage())
|
||||||
{
|
{
|
||||||
CLogMessage::preformatted(res.lastWarningOrAbove());
|
CLogMessage::preformatted(res.lastWarningOrAbove());
|
||||||
emit dataRead(CEntityFlags::AirportEntity, CEntityFlags::ReadFailed, 0);
|
emit this->dataRead(CEntityFlags::AirportEntity, CEntityFlags::ReadFailed, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,7 +251,7 @@ namespace BlackCore
|
|||||||
if (!url.isEmpty())
|
if (!url.isEmpty())
|
||||||
{
|
{
|
||||||
url.appendQuery(queryLatestTimestamp(newerThan));
|
url.appendQuery(queryLatestTimestamp(newerThan));
|
||||||
this->getFromNetworkAndLog(url, { this, &CAirportDataReader::ps_parseAirportData });
|
this->getFromNetworkAndLog(url, { this, &CAirportDataReader::parseAirportData });
|
||||||
emit dataRead(CEntityFlags::AirportEntity, CEntityFlags::StartRead, 0);
|
emit dataRead(CEntityFlags::AirportEntity, CEntityFlags::StartRead, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -68,9 +68,6 @@ namespace BlackCore
|
|||||||
virtual BlackMisc::Network::CUrl getDbServiceBaseUrl() const override;
|
virtual BlackMisc::Network::CUrl getDbServiceBaseUrl() const override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
//! Parse downloaded JSON file
|
|
||||||
void ps_parseAirportData(QNetworkReply *nwReplyPtr);
|
|
||||||
|
|
||||||
//! 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 entity = 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());
|
||||||
@@ -81,6 +78,9 @@ namespace BlackCore
|
|||||||
//! Reader URL (we read from where?) used to detect changes of location
|
//! Reader URL (we read from where?) used to detect changes of location
|
||||||
BlackMisc::CData<BlackCore::Data::TDbModelReaderBaseUrl> m_readerUrlCache {this, &CAirportDataReader::baseUrlCacheChanged };
|
BlackMisc::CData<BlackCore::Data::TDbModelReaderBaseUrl> m_readerUrlCache {this, &CAirportDataReader::baseUrlCacheChanged };
|
||||||
|
|
||||||
|
//! Parse downloaded JSON file
|
||||||
|
void parseAirportData(QNetworkReply *nwReplyPtr);
|
||||||
|
|
||||||
//! Airport cache changed
|
//! Airport cache changed
|
||||||
void airportCacheChanged();
|
void airportCacheChanged();
|
||||||
|
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ namespace BlackCore
|
|||||||
if (!url.isEmpty())
|
if (!url.isEmpty())
|
||||||
{
|
{
|
||||||
url.appendQuery(queryLatestTimestamp(newerThan));
|
url.appendQuery(queryLatestTimestamp(newerThan));
|
||||||
this->getFromNetworkAndLog(url, { this, &CIcaoDataReader::ps_parseAircraftIcaoData });
|
this->getFromNetworkAndLog(url, { this, &CIcaoDataReader::parseAircraftIcaoData });
|
||||||
entitiesTriggered |= CEntityFlags::AircraftIcaoEntity;
|
entitiesTriggered |= CEntityFlags::AircraftIcaoEntity;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -193,7 +193,7 @@ namespace BlackCore
|
|||||||
if (!url.isEmpty())
|
if (!url.isEmpty())
|
||||||
{
|
{
|
||||||
url.appendQuery(queryLatestTimestamp(newerThan));
|
url.appendQuery(queryLatestTimestamp(newerThan));
|
||||||
this->getFromNetworkAndLog(url, { this, &CIcaoDataReader::ps_parseAirlineIcaoData });
|
this->getFromNetworkAndLog(url, { this, &CIcaoDataReader::parseAirlineIcaoData });
|
||||||
entitiesTriggered |= CEntityFlags::AirlineIcaoEntity;
|
entitiesTriggered |= CEntityFlags::AirlineIcaoEntity;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -208,7 +208,7 @@ namespace BlackCore
|
|||||||
if (!url.isEmpty())
|
if (!url.isEmpty())
|
||||||
{
|
{
|
||||||
url.appendQuery(queryLatestTimestamp(newerThan));
|
url.appendQuery(queryLatestTimestamp(newerThan));
|
||||||
this->getFromNetworkAndLog(url, { this, &CIcaoDataReader::ps_parseCountryData });
|
this->getFromNetworkAndLog(url, { this, &CIcaoDataReader::parseCountryData });
|
||||||
entitiesTriggered |= CEntityFlags::CountryEntity;
|
entitiesTriggered |= CEntityFlags::CountryEntity;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -254,7 +254,7 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CIcaoDataReader::ps_parseAircraftIcaoData(QNetworkReply *nwReplyPtr)
|
void CIcaoDataReader::parseAircraftIcaoData(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
|
||||||
@@ -307,7 +307,7 @@ namespace BlackCore
|
|||||||
this->emitAndLogDataRead(CEntityFlags::AircraftIcaoEntity, n, res);
|
this->emitAndLogDataRead(CEntityFlags::AircraftIcaoEntity, n, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CIcaoDataReader::ps_parseAirlineIcaoData(QNetworkReply *nwReplyPtr)
|
void CIcaoDataReader::parseAirlineIcaoData(QNetworkReply *nwReplyPtr)
|
||||||
{
|
{
|
||||||
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
|
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
|
||||||
if (!this->doWorkCheck()) { return; }
|
if (!this->doWorkCheck()) { return; }
|
||||||
@@ -358,7 +358,7 @@ namespace BlackCore
|
|||||||
this->emitAndLogDataRead(CEntityFlags::AirlineIcaoEntity, n, res);
|
this->emitAndLogDataRead(CEntityFlags::AirlineIcaoEntity, n, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CIcaoDataReader::ps_parseCountryData(QNetworkReply *nwReplyPtr)
|
void CIcaoDataReader::parseCountryData(QNetworkReply *nwReplyPtr)
|
||||||
{
|
{
|
||||||
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
|
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
|
||||||
const CDatabaseReader::JsonDatastoreResponse res = this->setStatusAndTransformReplyIntoDatastoreResponse(nwReply.data());
|
const CDatabaseReader::JsonDatastoreResponse res = this->setStatusAndTransformReplyIntoDatastoreResponse(nwReply.data());
|
||||||
|
|||||||
@@ -154,15 +154,6 @@ namespace BlackCore
|
|||||||
virtual BlackMisc::Network::CUrl getDbServiceBaseUrl() const override;
|
virtual BlackMisc::Network::CUrl getDbServiceBaseUrl() const override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
//! Aircraft have been read
|
|
||||||
void ps_parseAircraftIcaoData(QNetworkReply *nwReply);
|
|
||||||
|
|
||||||
//! Airlines have been read
|
|
||||||
void ps_parseAirlineIcaoData(QNetworkReply *nwReply);
|
|
||||||
|
|
||||||
//! Countries have been read
|
|
||||||
void ps_parseCountryData(QNetworkReply *nwReply);
|
|
||||||
|
|
||||||
//! Read / re-read data
|
//! Read / re-read data
|
||||||
void ps_read(BlackMisc::Network::CEntityFlags::Entity entities,
|
void ps_read(BlackMisc::Network::CEntityFlags::Entity entities,
|
||||||
BlackMisc::Db::CDbFlags::DataRetrievalModeFlag mode, const QDateTime &newerThan);
|
BlackMisc::Db::CDbFlags::DataRetrievalModeFlag mode, const QDateTime &newerThan);
|
||||||
@@ -175,9 +166,25 @@ namespace BlackCore
|
|||||||
//! Reader URL (we read from where?) used to detect changes of location
|
//! Reader URL (we read from where?) used to detect changes of location
|
||||||
BlackMisc::CData<BlackCore::Data::TDbIcaoReaderBaseUrl> m_readerUrlCache {this, &CIcaoDataReader::baseUrlCacheChanged };
|
BlackMisc::CData<BlackCore::Data::TDbIcaoReaderBaseUrl> m_readerUrlCache {this, &CIcaoDataReader::baseUrlCacheChanged };
|
||||||
|
|
||||||
|
//! Aircraft have been read
|
||||||
|
void parseAircraftIcaoData(QNetworkReply *nwReply);
|
||||||
|
|
||||||
|
//! Airlines have been read
|
||||||
|
void parseAirlineIcaoData(QNetworkReply *nwReply);
|
||||||
|
|
||||||
|
//! Countries have been read
|
||||||
|
void parseCountryData(QNetworkReply *nwReply);
|
||||||
|
|
||||||
|
//! Cache has changed elsewhere
|
||||||
void aircraftIcaoCacheChanged();
|
void aircraftIcaoCacheChanged();
|
||||||
|
|
||||||
|
//! Cache has changed elsewhere
|
||||||
void airlineIcaoCacheChanged();
|
void airlineIcaoCacheChanged();
|
||||||
|
|
||||||
|
//! Cache has changed elsewhere
|
||||||
void countryCacheChanged();
|
void countryCacheChanged();
|
||||||
|
|
||||||
|
//! Cache has changed elsewhere
|
||||||
void baseUrlCacheChanged();
|
void baseUrlCacheChanged();
|
||||||
|
|
||||||
//! Update reader URL
|
//! Update reader URL
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ namespace BlackCore
|
|||||||
if (!url.isEmpty())
|
if (!url.isEmpty())
|
||||||
{
|
{
|
||||||
url.appendQuery(queryLatestTimestamp(newerThan));
|
url.appendQuery(queryLatestTimestamp(newerThan));
|
||||||
this->getFromNetworkAndLog(url, { this, &CModelDataReader::ps_parseLiveryData});
|
this->getFromNetworkAndLog(url, { this, &CModelDataReader::parseLiveryData});
|
||||||
triggeredRead |= CEntityFlags::LiveryEntity;
|
triggeredRead |= CEntityFlags::LiveryEntity;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -211,7 +211,7 @@ namespace BlackCore
|
|||||||
if (!url.isEmpty())
|
if (!url.isEmpty())
|
||||||
{
|
{
|
||||||
url.appendQuery(queryLatestTimestamp(newerThan));
|
url.appendQuery(queryLatestTimestamp(newerThan));
|
||||||
this->getFromNetworkAndLog(url, { this, &CModelDataReader::ps_parseDistributorData});
|
this->getFromNetworkAndLog(url, { this, &CModelDataReader::parseDistributorData});
|
||||||
triggeredRead |= CEntityFlags::DistributorEntity;
|
triggeredRead |= CEntityFlags::DistributorEntity;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -226,7 +226,7 @@ namespace BlackCore
|
|||||||
if (!url.isEmpty())
|
if (!url.isEmpty())
|
||||||
{
|
{
|
||||||
url.appendQuery(queryLatestTimestamp(newerThan));
|
url.appendQuery(queryLatestTimestamp(newerThan));
|
||||||
this->getFromNetworkAndLog(url, { this, &CModelDataReader::ps_parseModelData});
|
this->getFromNetworkAndLog(url, { this, &CModelDataReader::parseModelData});
|
||||||
triggeredRead |= CEntityFlags::ModelEntity;
|
triggeredRead |= CEntityFlags::ModelEntity;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -272,7 +272,7 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CModelDataReader::ps_parseLiveryData(QNetworkReply *nwReplyPtr)
|
void CModelDataReader::parseLiveryData(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
|
||||||
@@ -315,7 +315,7 @@ namespace BlackCore
|
|||||||
this->emitAndLogDataRead(CEntityFlags::LiveryEntity, n, res);
|
this->emitAndLogDataRead(CEntityFlags::LiveryEntity, n, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CModelDataReader::ps_parseDistributorData(QNetworkReply *nwReplyPtr)
|
void CModelDataReader::parseDistributorData(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
|
||||||
@@ -358,7 +358,7 @@ namespace BlackCore
|
|||||||
this->emitAndLogDataRead(CEntityFlags::DistributorEntity, n, res);
|
this->emitAndLogDataRead(CEntityFlags::DistributorEntity, n, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CModelDataReader::ps_parseModelData(QNetworkReply *nwReplyPtr)
|
void CModelDataReader::parseModelData(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
|
||||||
|
|||||||
@@ -155,14 +155,6 @@ namespace BlackCore
|
|||||||
virtual BlackMisc::Network::CUrl getDbServiceBaseUrl() const override;
|
virtual BlackMisc::Network::CUrl getDbServiceBaseUrl() const override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
//! Liveries have been read
|
|
||||||
void ps_parseLiveryData(QNetworkReply *nwReply);
|
|
||||||
|
|
||||||
//! Distributors have been read
|
|
||||||
void ps_parseDistributorData(QNetworkReply *nwReply);
|
|
||||||
|
|
||||||
//! Models have been read
|
|
||||||
void ps_parseModelData(QNetworkReply *nwReply);
|
|
||||||
|
|
||||||
//! Read / re-read data file
|
//! Read / re-read data file
|
||||||
void ps_read(BlackMisc::Network::CEntityFlags::Entity entities = BlackMisc::Network::CEntityFlags::DistributorLiveryModel,
|
void ps_read(BlackMisc::Network::CEntityFlags::Entity entities = BlackMisc::Network::CEntityFlags::DistributorLiveryModel,
|
||||||
@@ -170,16 +162,32 @@ namespace BlackCore
|
|||||||
const QDateTime &newerThan = QDateTime());
|
const QDateTime &newerThan = QDateTime());
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BlackMisc::CData<BlackCore::Data::TDbLiveryCache> m_liveryCache {this, &CModelDataReader::liveryCacheChanged };
|
BlackMisc::CData<BlackCore::Data::TDbLiveryCache> m_liveryCache { this, &CModelDataReader::liveryCacheChanged };
|
||||||
BlackMisc::CData<BlackCore::Data::TDbModelCache> m_modelCache {this, &CModelDataReader::modelCacheChanged };
|
BlackMisc::CData<BlackCore::Data::TDbModelCache> m_modelCache { this, &CModelDataReader::modelCacheChanged };
|
||||||
BlackMisc::CData<BlackCore::Data::TDbDistributorCache> m_distributorCache {this, &CModelDataReader::distributorCacheChanged };
|
BlackMisc::CData<BlackCore::Data::TDbDistributorCache> m_distributorCache { this, &CModelDataReader::distributorCacheChanged };
|
||||||
|
|
||||||
//! Reader URL (we read from where?) used to detect changes of location
|
//! Reader URL (we read from where?) used to detect changes of location
|
||||||
BlackMisc::CData<BlackCore::Data::TDbModelReaderBaseUrl> m_readerUrlCache {this, &CModelDataReader::baseUrlCacheChanged };
|
BlackMisc::CData<BlackCore::Data::TDbModelReaderBaseUrl> m_readerUrlCache { this, &CModelDataReader::baseUrlCacheChanged };
|
||||||
|
|
||||||
|
//! Liveries have been read
|
||||||
|
void parseLiveryData(QNetworkReply *nwReply);
|
||||||
|
|
||||||
|
//! Distributors have been read
|
||||||
|
void parseDistributorData(QNetworkReply *nwReply);
|
||||||
|
|
||||||
|
//! Models have been read
|
||||||
|
void parseModelData(QNetworkReply *nwReply);
|
||||||
|
|
||||||
|
//! Livery cache changed elsewhere
|
||||||
void liveryCacheChanged();
|
void liveryCacheChanged();
|
||||||
|
|
||||||
|
//! Model cache changed elsewhere
|
||||||
void modelCacheChanged();
|
void modelCacheChanged();
|
||||||
|
|
||||||
|
//! Distributor cache changed elsewhere
|
||||||
void distributorCacheChanged();
|
void distributorCacheChanged();
|
||||||
|
|
||||||
|
//! Base URL cache changed
|
||||||
void baseUrlCacheChanged();
|
void baseUrlCacheChanged();
|
||||||
|
|
||||||
//! Update reader URL
|
//! Update reader URL
|
||||||
|
|||||||
Reference in New Issue
Block a user