mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-05 17:55:45 +08:00
Check in readers "for shutdown"
* myself pattern * use read as function name
This commit is contained in:
committed by
Mat Sutcliffe
parent
a340167493
commit
f2b0417942
@@ -42,12 +42,17 @@ namespace BlackCore
|
|||||||
CThreadedReader(owner, "CVatsimMetarReader"),
|
CThreadedReader(owner, "CVatsimMetarReader"),
|
||||||
CEcosystemAware(CEcosystemAware::providerIfPossible(owner))
|
CEcosystemAware(CEcosystemAware::providerIfPossible(owner))
|
||||||
{
|
{
|
||||||
reloadSettings();
|
this->reloadSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CVatsimMetarReader::readInBackgroundThread()
|
void CVatsimMetarReader::readInBackgroundThread()
|
||||||
{
|
{
|
||||||
QTimer::singleShot(0, this, &CVatsimMetarReader::readMetars);
|
QPointer<CVatsimMetarReader> myself(this);
|
||||||
|
QTimer::singleShot(0, this, [ = ]
|
||||||
|
{
|
||||||
|
if (!myself) { return; }
|
||||||
|
myself->read();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
CMetarList CVatsimMetarReader::getMetars() const
|
CMetarList CVatsimMetarReader::getMetars() const
|
||||||
@@ -70,10 +75,10 @@ namespace BlackCore
|
|||||||
|
|
||||||
void CVatsimMetarReader::doWorkImpl()
|
void CVatsimMetarReader::doWorkImpl()
|
||||||
{
|
{
|
||||||
readMetars();
|
this->read();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CVatsimMetarReader::readMetars()
|
void CVatsimMetarReader::read()
|
||||||
{
|
{
|
||||||
this->threadAssertCheck();
|
this->threadAssertCheck();
|
||||||
if (!this->doWorkCheck()) { return; }
|
if (!this->doWorkCheck()) { return; }
|
||||||
@@ -122,7 +127,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
if (!this->doWorkCheck()) { return; }
|
if (!this->doWorkCheck()) { return; }
|
||||||
const QString line = lineReader.readLine();
|
const QString line = lineReader.readLine();
|
||||||
CMetar metar = m_metarDecoder.decode(line);
|
const CMetar metar = m_metarDecoder.decode(line);
|
||||||
if (metar != CMetar()) { metars.push_back(metar); }
|
if (metar != CMetar()) { metars.push_back(metar); }
|
||||||
else { invalidLines++; }
|
else { invalidLines++; }
|
||||||
}
|
}
|
||||||
@@ -142,7 +147,7 @@ namespace BlackCore
|
|||||||
// network error
|
// network error
|
||||||
CLogMessage(this).warning(u"Reading METARs failed '%1' for '%2'") << nwReply->errorString() << nwReply->url().toString();
|
CLogMessage(this).warning(u"Reading METARs failed '%1' for '%2'") << nwReply->errorString() << nwReply->url().toString();
|
||||||
nwReply->abort();
|
nwReply->abort();
|
||||||
emit dataRead(CEntityFlags::MetarEntity, CEntityFlags::ReadFailed, 0);
|
emit this->dataRead(CEntityFlags::MetarEntity, CEntityFlags::ReadFailed, 0);
|
||||||
}
|
}
|
||||||
} // method
|
} // method
|
||||||
|
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ namespace BlackCore
|
|||||||
void decodeMetars(QNetworkReply *nwReply);
|
void decodeMetars(QNetworkReply *nwReply);
|
||||||
|
|
||||||
//! Do reading
|
//! Do reading
|
||||||
void readMetars();
|
void read();
|
||||||
|
|
||||||
//! Reload settings
|
//! Reload settings
|
||||||
void reloadSettings();
|
void reloadSettings();
|
||||||
|
|||||||
@@ -47,9 +47,12 @@ namespace BlackCore
|
|||||||
|
|
||||||
void CVatsimStatusFileReader::readInBackgroundThread()
|
void CVatsimStatusFileReader::readInBackgroundThread()
|
||||||
{
|
{
|
||||||
const bool s = QMetaObject::invokeMethod(this, &CVatsimStatusFileReader::read);
|
QPointer<CVatsimStatusFileReader> myself(this);
|
||||||
Q_ASSERT_X(s, Q_FUNC_INFO, "Invoke failed");
|
QTimer::singleShot(0, this, [ = ]
|
||||||
Q_UNUSED(s);
|
{
|
||||||
|
if (!myself) { return; }
|
||||||
|
myself->read();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
CUrlList CVatsimStatusFileReader::getMetarFileUrls() const
|
CUrlList CVatsimStatusFileReader::getMetarFileUrls() const
|
||||||
|
|||||||
Reference in New Issue
Block a user