mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-26 02:35:38 +08:00
Some reader improvements
* Log when VATSIM status file has been read * fix: read VATSIM status file after initReaders completes * some private slots -> normal private functions * removed copy/paste error illegalIcaoCodes follow up of Ref T105
This commit is contained in:
committed by
Mathew Sutcliffe
parent
76b3b6c0b6
commit
880cedec5d
@@ -721,13 +721,13 @@ namespace BlackCore
|
|||||||
this->m_webDataServices.reset(
|
this->m_webDataServices.reset(
|
||||||
new CWebDataServices(this->m_webReadersUsed, this->m_dbReaderConfig, {}, this)
|
new CWebDataServices(this->m_webReadersUsed, this->m_dbReaderConfig, {}, this)
|
||||||
);
|
);
|
||||||
|
emit webDataServicesStarted(true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
msgs.push_back(CStatusMessage(this).info("Web data services already running"));
|
msgs.push_back(CStatusMessage(this).info("Web data services already running"));
|
||||||
}
|
}
|
||||||
|
|
||||||
emit webDataServicesStarted(true);
|
|
||||||
return msgs;
|
return msgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,6 @@ namespace BlackCore
|
|||||||
return; // stop, terminate straight away, ending thread
|
return; // stop, terminate straight away, ending thread
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList illegalIcaoCodes;
|
|
||||||
if (nwReply->error() == QNetworkReply::NoError)
|
if (nwReply->error() == QNetworkReply::NoError)
|
||||||
{
|
{
|
||||||
const QString dataFileData = nwReply->readAll();
|
const QString dataFileData = nwReply->readAll();
|
||||||
@@ -145,7 +144,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
// cache itself is thread safe, avoid writing with unchanged data
|
// cache itself is thread safe, avoid writing with unchanged data
|
||||||
CVatsimSetup vs(this->m_lastGoodSetup.get());
|
CVatsimSetup vs(this->m_lastGoodSetup.get());
|
||||||
bool changed = vs.setUrls(dataFileUrls, serverFileUrls, metarFileUrls);
|
const bool changed = vs.setUrls(dataFileUrls, serverFileUrls, metarFileUrls);
|
||||||
if (changed)
|
if (changed)
|
||||||
{
|
{
|
||||||
vs.setUtcTimestamp(QDateTime::currentDateTime());
|
vs.setUtcTimestamp(QDateTime::currentDateTime());
|
||||||
@@ -153,12 +152,6 @@ namespace BlackCore
|
|||||||
if (cacheMsg.isFailure()) { CLogMessage::preformatted(cacheMsg); }
|
if (cacheMsg.isFailure()) { CLogMessage::preformatted(cacheMsg); }
|
||||||
}
|
}
|
||||||
|
|
||||||
// warnings, if required
|
|
||||||
if (!illegalIcaoCodes.isEmpty())
|
|
||||||
{
|
|
||||||
CLogMessage(this).info("Illegal / ignored ICAO code(s) in VATSIM data file: %1") << illegalIcaoCodes.join(", ");
|
|
||||||
}
|
|
||||||
|
|
||||||
// data read finished
|
// data read finished
|
||||||
emit this->dataFileRead(lines.count());
|
emit this->dataFileRead(lines.count());
|
||||||
emit this->dataRead(CEntityFlags::VatsimStatusFile, CEntityFlags::ReadFinished, lines.count());
|
emit this->dataRead(CEntityFlags::VatsimStatusFile, CEntityFlags::ReadFinished, lines.count());
|
||||||
@@ -166,7 +159,7 @@ namespace BlackCore
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// network error
|
// network error
|
||||||
CLogMessage(this).warning("Reading VATSIM status file failed %1 %2") << nwReply->errorString() << nwReply->url().toString();
|
CLogMessage(this).warning("Reading VATSIM status file failed '%1' '%2'") << nwReply->errorString() << nwReply->url().toString();
|
||||||
nwReply->abort();
|
nwReply->abort();
|
||||||
emit this->dataRead(CEntityFlags::VatsimStatusFile, CEntityFlags::ReadFailed, 0);
|
emit this->dataRead(CEntityFlags::VatsimStatusFile, CEntityFlags::ReadFailed, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include "blackmisc/restricted.h"
|
#include "blackmisc/restricted.h"
|
||||||
#include "blackmisc/statusmessage.h"
|
#include "blackmisc/statusmessage.h"
|
||||||
#include "blackmisc/worker.h"
|
#include "blackmisc/worker.h"
|
||||||
|
#include "blackmisc/threadutils.h"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFlags>
|
#include <QFlags>
|
||||||
@@ -769,10 +770,11 @@ namespace BlackCore
|
|||||||
|
|
||||||
void CWebDataServices::initReaders(CWebReaderFlags::WebReader flags, CEntityFlags::Entity entities)
|
void CWebDataServices::initReaders(CWebReaderFlags::WebReader flags, CEntityFlags::Entity entities)
|
||||||
{
|
{
|
||||||
//
|
Q_ASSERT_X(CThreadUtils::isCurrentThreadApplicationThread(), Q_FUNC_INFO, "shall run in main application thread");
|
||||||
// ---- "metadata" reader, 1/2 will trigger read directly during init
|
|
||||||
//
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// ---- "metadata" reader, 1 will trigger read directly during init
|
||||||
|
//
|
||||||
CDatabaseReaderConfigList dbReaderConfig(this->m_dbReaderConfig);
|
CDatabaseReaderConfigList dbReaderConfig(this->m_dbReaderConfig);
|
||||||
const bool anyDbEntities = CEntityFlags::anySwiftDbEntity(entities);
|
const bool anyDbEntities = CEntityFlags::anySwiftDbEntity(entities);
|
||||||
const bool needsSharedInfoObjects = dbReaderConfig.needsSharedInfoObjects(entities);
|
const bool needsSharedInfoObjects = dbReaderConfig.needsSharedInfoObjects(entities);
|
||||||
@@ -806,12 +808,16 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2. Status file, updating the VATSIM related caches
|
// 2. Status file, updating the VATSIM related caches
|
||||||
|
// Read as soon as initReaders is done
|
||||||
if (flags.testFlag(CWebReaderFlags::VatsimStatusReader) || flags.testFlag(CWebReaderFlags::VatsimDataReader) || flags.testFlag(CWebReaderFlags::VatsimMetarReader))
|
if (flags.testFlag(CWebReaderFlags::VatsimStatusReader) || flags.testFlag(CWebReaderFlags::VatsimDataReader) || flags.testFlag(CWebReaderFlags::VatsimMetarReader))
|
||||||
{
|
{
|
||||||
this->m_vatsimStatusReader = new CVatsimStatusFileReader(this);
|
this->m_vatsimStatusReader = new CVatsimStatusFileReader(this);
|
||||||
|
c = connect(this->m_vatsimStatusReader, &CVatsimStatusFileReader::dataFileRead, this, &CWebDataServices::vatsimStatusFileRead);
|
||||||
|
CLogMessage(this).info("Trigger read of VATSIM status file");
|
||||||
this->m_vatsimStatusReader->start(QThread::LowPriority);
|
this->m_vatsimStatusReader->start(QThread::LowPriority);
|
||||||
// no timer updates from timer here
|
|
||||||
QTimer::singleShot(100, this->m_vatsimStatusReader, &CVatsimStatusFileReader::readInBackgroundThread);
|
// run single shot in main loop, so readInBackgroundThread is not called before initReaders completes
|
||||||
|
QTimer::singleShot(100, this, [this]() { this->m_vatsimStatusReader->readInBackgroundThread(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- "normal data", triggerRead will start read, not starting directly
|
// ---- "normal data", triggerRead will start read, not starting directly
|
||||||
@@ -820,7 +826,7 @@ namespace BlackCore
|
|||||||
if (flags.testFlag(CWebReaderFlags::WebReaderFlag::VatsimBookingReader))
|
if (flags.testFlag(CWebReaderFlags::WebReaderFlag::VatsimBookingReader))
|
||||||
{
|
{
|
||||||
this->m_vatsimBookingReader = new CVatsimBookingReader(this);
|
this->m_vatsimBookingReader = new CVatsimBookingReader(this);
|
||||||
c = connect(this->m_vatsimBookingReader, &CVatsimBookingReader::atcBookingsRead, this, &CWebDataServices::ps_receivedBookings);
|
c = connect(this->m_vatsimBookingReader, &CVatsimBookingReader::atcBookingsRead, this, &CWebDataServices::receivedBookings);
|
||||||
Q_ASSERT_X(c, Q_FUNC_INFO, "VATSIM booking reader signals");
|
Q_ASSERT_X(c, Q_FUNC_INFO, "VATSIM booking reader signals");
|
||||||
c = connect(this->m_vatsimBookingReader, &CVatsimBookingReader::dataRead, this, &CWebDataServices::dataRead);
|
c = connect(this->m_vatsimBookingReader, &CVatsimBookingReader::dataRead, this, &CWebDataServices::dataRead);
|
||||||
Q_ASSERT_X(c, Q_FUNC_INFO, "connect failed bookings");
|
Q_ASSERT_X(c, Q_FUNC_INFO, "connect failed bookings");
|
||||||
@@ -833,7 +839,7 @@ namespace BlackCore
|
|||||||
if (flags.testFlag(CWebReaderFlags::WebReaderFlag::VatsimDataReader))
|
if (flags.testFlag(CWebReaderFlags::WebReaderFlag::VatsimDataReader))
|
||||||
{
|
{
|
||||||
this->m_vatsimDataFileReader = new CVatsimDataFileReader(this);
|
this->m_vatsimDataFileReader = new CVatsimDataFileReader(this);
|
||||||
c = connect(this->m_vatsimDataFileReader, &CVatsimDataFileReader::dataFileRead, this, &CWebDataServices::ps_vatsimDataFileRead);
|
c = connect(this->m_vatsimDataFileReader, &CVatsimDataFileReader::dataFileRead, this, &CWebDataServices::vatsimDataFileRead);
|
||||||
Q_ASSERT_X(c, Q_FUNC_INFO, "VATSIM data reader signals");
|
Q_ASSERT_X(c, Q_FUNC_INFO, "VATSIM data reader signals");
|
||||||
c = connect(this->m_vatsimDataFileReader, &CVatsimDataFileReader::dataRead, this, &CWebDataServices::dataRead);
|
c = connect(this->m_vatsimDataFileReader, &CVatsimDataFileReader::dataRead, this, &CWebDataServices::dataRead);
|
||||||
Q_ASSERT_X(c, Q_FUNC_INFO, "connect failed VATSIM data file");
|
Q_ASSERT_X(c, Q_FUNC_INFO, "connect failed VATSIM data file");
|
||||||
@@ -846,7 +852,7 @@ namespace BlackCore
|
|||||||
if (flags.testFlag(CWebReaderFlags::WebReaderFlag::VatsimMetarReader))
|
if (flags.testFlag(CWebReaderFlags::WebReaderFlag::VatsimMetarReader))
|
||||||
{
|
{
|
||||||
this->m_vatsimMetarReader = new CVatsimMetarReader(this);
|
this->m_vatsimMetarReader = new CVatsimMetarReader(this);
|
||||||
c = connect(this->m_vatsimMetarReader, &CVatsimMetarReader::metarsRead, this, &CWebDataServices::ps_receivedMetars);
|
c = connect(this->m_vatsimMetarReader, &CVatsimMetarReader::metarsRead, this, &CWebDataServices::receivedMetars);
|
||||||
Q_ASSERT_X(c, Q_FUNC_INFO, "VATSIM METAR reader signals");
|
Q_ASSERT_X(c, Q_FUNC_INFO, "VATSIM METAR reader signals");
|
||||||
c = connect(this->m_vatsimMetarReader, &CVatsimMetarReader::dataRead, this, &CWebDataServices::dataRead);
|
c = connect(this->m_vatsimMetarReader, &CVatsimMetarReader::dataRead, this, &CWebDataServices::dataRead);
|
||||||
Q_ASSERT_X(c, Q_FUNC_INFO, "connect failed VATSIM METAR");
|
Q_ASSERT_X(c, Q_FUNC_INFO, "connect failed VATSIM METAR");
|
||||||
@@ -859,7 +865,7 @@ namespace BlackCore
|
|||||||
if (flags.testFlag(CWebReaderFlags::WebReaderFlag::IcaoDataReader))
|
if (flags.testFlag(CWebReaderFlags::WebReaderFlag::IcaoDataReader))
|
||||||
{
|
{
|
||||||
this->m_icaoDataReader = new CIcaoDataReader(this, dbReaderConfig);
|
this->m_icaoDataReader = new CIcaoDataReader(this, dbReaderConfig);
|
||||||
c = connect(this->m_icaoDataReader, &CIcaoDataReader::dataRead, this, &CWebDataServices::ps_readFromSwiftReader);
|
c = connect(this->m_icaoDataReader, &CIcaoDataReader::dataRead, this, &CWebDataServices::readFromSwiftReader);
|
||||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Cannot connect ICAO reader signals");
|
Q_ASSERT_X(c, Q_FUNC_INFO, "Cannot connect ICAO reader signals");
|
||||||
c = connect(this->m_icaoDataReader, &CIcaoDataReader::dataRead, this, &CWebDataServices::dataRead);
|
c = connect(this->m_icaoDataReader, &CIcaoDataReader::dataRead, this, &CWebDataServices::dataRead);
|
||||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Cannot connect ICAO reader signals");
|
Q_ASSERT_X(c, Q_FUNC_INFO, "Cannot connect ICAO reader signals");
|
||||||
@@ -870,7 +876,7 @@ namespace BlackCore
|
|||||||
if (flags.testFlag(CWebReaderFlags::WebReaderFlag::ModelReader))
|
if (flags.testFlag(CWebReaderFlags::WebReaderFlag::ModelReader))
|
||||||
{
|
{
|
||||||
this->m_modelDataReader = new CModelDataReader(this, dbReaderConfig);
|
this->m_modelDataReader = new CModelDataReader(this, dbReaderConfig);
|
||||||
c = connect(this->m_modelDataReader, &CModelDataReader::dataRead, this, &CWebDataServices::ps_readFromSwiftReader);
|
c = connect(this->m_modelDataReader, &CModelDataReader::dataRead, this, &CWebDataServices::readFromSwiftReader);
|
||||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Cannot connect Model reader signals");
|
Q_ASSERT_X(c, Q_FUNC_INFO, "Cannot connect Model reader signals");
|
||||||
c = connect(this->m_modelDataReader, &CModelDataReader::dataRead, this, &CWebDataServices::dataRead);
|
c = connect(this->m_modelDataReader, &CModelDataReader::dataRead, this, &CWebDataServices::dataRead);
|
||||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Cannot connect Model reader signals");
|
Q_ASSERT_X(c, Q_FUNC_INFO, "Cannot connect Model reader signals");
|
||||||
@@ -881,7 +887,7 @@ namespace BlackCore
|
|||||||
if (flags.testFlag(CWebReaderFlags::WebReaderFlag::AirportReader))
|
if (flags.testFlag(CWebReaderFlags::WebReaderFlag::AirportReader))
|
||||||
{
|
{
|
||||||
this->m_airportDataReader = new CAirportDataReader(this, dbReaderConfig);
|
this->m_airportDataReader = new CAirportDataReader(this, dbReaderConfig);
|
||||||
c = connect(this->m_airportDataReader, &CAirportDataReader::dataRead, this, &CWebDataServices::ps_readFromSwiftReader);
|
c = connect(this->m_airportDataReader, &CAirportDataReader::dataRead, this, &CWebDataServices::readFromSwiftReader);
|
||||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Cannot connect Model reader signals");
|
Q_ASSERT_X(c, Q_FUNC_INFO, "Cannot connect Model reader signals");
|
||||||
c = connect(this->m_airportDataReader, &CAirportDataReader::dataRead, this, &CWebDataServices::dataRead);
|
c = connect(this->m_airportDataReader, &CAirportDataReader::dataRead, this, &CWebDataServices::dataRead);
|
||||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Cannot connect Model reader signals");
|
Q_ASSERT_X(c, Q_FUNC_INFO, "Cannot connect Model reader signals");
|
||||||
@@ -896,7 +902,7 @@ namespace BlackCore
|
|||||||
if (!this->m_dbInfoDataReader)
|
if (!this->m_dbInfoDataReader)
|
||||||
{
|
{
|
||||||
this->m_dbInfoDataReader = new CInfoDataReader(this, m_dbReaderConfig, CDbFlags::DbReading);
|
this->m_dbInfoDataReader = new CInfoDataReader(this, m_dbReaderConfig, CDbFlags::DbReading);
|
||||||
bool c = connect(this->m_dbInfoDataReader, &CInfoDataReader::dataRead, this, &CWebDataServices::ps_readFromSwiftReader);
|
bool c = connect(this->m_dbInfoDataReader, &CInfoDataReader::dataRead, this, &CWebDataServices::readFromSwiftReader);
|
||||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Info reader connect failed");
|
Q_ASSERT_X(c, Q_FUNC_INFO, "Info reader connect failed");
|
||||||
|
|
||||||
// relay signal
|
// relay signal
|
||||||
@@ -917,7 +923,7 @@ namespace BlackCore
|
|||||||
if (!this->m_sharedInfoDataReader)
|
if (!this->m_sharedInfoDataReader)
|
||||||
{
|
{
|
||||||
this->m_sharedInfoDataReader = new CInfoDataReader(this, m_dbReaderConfig, CDbFlags::Shared);
|
this->m_sharedInfoDataReader = new CInfoDataReader(this, m_dbReaderConfig, CDbFlags::Shared);
|
||||||
bool c = connect(this->m_sharedInfoDataReader, &CInfoDataReader::dataRead, this, &CWebDataServices::ps_readFromSwiftReader);
|
bool c = connect(this->m_sharedInfoDataReader, &CInfoDataReader::dataRead, this, &CWebDataServices::readFromSwiftReader);
|
||||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Info reader connect failed");
|
Q_ASSERT_X(c, Q_FUNC_INFO, "Info reader connect failed");
|
||||||
|
|
||||||
// relay signal
|
// relay signal
|
||||||
@@ -980,22 +986,27 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWebDataServices::ps_receivedBookings(const CAtcStationList &stations)
|
void CWebDataServices::receivedBookings(const CAtcStationList &stations)
|
||||||
{
|
{
|
||||||
CLogMessage(this).info("Read %1 ATC bookings from network") << stations.size();
|
CLogMessage(this).info("Read %1 ATC bookings from network") << stations.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWebDataServices::ps_receivedMetars(const CMetarList &metars)
|
void CWebDataServices::receivedMetars(const CMetarList &metars)
|
||||||
{
|
{
|
||||||
CLogMessage(this).info("Read %1 METARs") << metars.size();
|
CLogMessage(this).info("Read %1 METARs") << metars.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWebDataServices::ps_vatsimDataFileRead(int lines)
|
void CWebDataServices::vatsimDataFileRead(int lines)
|
||||||
{
|
{
|
||||||
CLogMessage(this).info("Read VATSIM data file, %1 lines") << lines;
|
CLogMessage(this).info("Read VATSIM data file, %1 lines") << lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWebDataServices::ps_readFromSwiftReader(CEntityFlags::Entity entities, CEntityFlags::ReadState state, int number)
|
void CWebDataServices::vatsimStatusFileRead(int lines)
|
||||||
|
{
|
||||||
|
CLogMessage(this).info("Read VATSIM status file, %1 lines") << lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWebDataServices::readFromSwiftReader(CEntityFlags::Entity entities, CEntityFlags::ReadState state, int number)
|
||||||
{
|
{
|
||||||
static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::webservice()}));
|
static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::webservice()}));
|
||||||
|
|
||||||
|
|||||||
@@ -437,20 +437,22 @@ namespace BlackCore
|
|||||||
//! \remark ensures info objects (if and only if needed) are read upfront
|
//! \remark ensures info objects (if and only if needed) are read upfront
|
||||||
void readInBackground(BlackMisc::Network::CEntityFlags::Entity entities = BlackMisc::Network::CEntityFlags::AllEntities);
|
void readInBackground(BlackMisc::Network::CEntityFlags::Entity entities = BlackMisc::Network::CEntityFlags::AllEntities);
|
||||||
|
|
||||||
private slots:
|
private:
|
||||||
//! ATC bookings received
|
//! ATC bookings received
|
||||||
void ps_receivedBookings(const BlackMisc::Aviation::CAtcStationList &bookedStations);
|
void receivedBookings(const BlackMisc::Aviation::CAtcStationList &bookedStations);
|
||||||
|
|
||||||
//! Received METAR data
|
//! Received METAR data
|
||||||
void ps_receivedMetars(const BlackMisc::Weather::CMetarList &metars);
|
void receivedMetars(const BlackMisc::Weather::CMetarList &metars);
|
||||||
|
|
||||||
//! Data file has been read
|
//! VATSIM data file has been read
|
||||||
void ps_vatsimDataFileRead(int lines);
|
void vatsimDataFileRead(int lines);
|
||||||
|
|
||||||
|
//! VATSIM status file has been read
|
||||||
|
void vatsimStatusFileRead(int lines);
|
||||||
|
|
||||||
//! Read finished from reader
|
//! Read finished from reader
|
||||||
void ps_readFromSwiftReader(BlackMisc::Network::CEntityFlags::Entity entities, BlackMisc::Network::CEntityFlags::ReadState state, int number);
|
void readFromSwiftReader(BlackMisc::Network::CEntityFlags::Entity entities, BlackMisc::Network::CEntityFlags::ReadState state, int number);
|
||||||
|
|
||||||
private:
|
|
||||||
//! Init the readers
|
//! Init the readers
|
||||||
void initReaders(CWebReaderFlags::WebReader flags, BlackMisc::Network::CEntityFlags::Entity entities);
|
void initReaders(CWebReaderFlags::WebReader flags, BlackMisc::Network::CEntityFlags::Entity entities);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user