Ref T105, use new style with threaded readers

* use doWorkCheck
* relaxed doWorkCheck in unit tests
* removed isShuttingDown, gracefulShutdown
* set timer object name (in case something is wrong, we might see the name in the log)
This commit is contained in:
Klaus Basan
2017-07-10 18:13:44 +02:00
committed by Mathew Sutcliffe
parent 2fbd2c6382
commit b6b1b96ec4
14 changed files with 86 additions and 84 deletions

View File

@@ -67,14 +67,14 @@ namespace BlackCore
void CVatsimBookingReader::ps_read()
{
this->threadAssertCheck();
if (!this->doWorkCheck()) { return; }
if (!this->isNetworkAccessible())
{
CLogMessage(this).warning("No network, cannot read VATSIM bookings");
return;
}
this->threadAssertCheck();
Q_ASSERT_X(sApp, Q_FUNC_INFO, "No application");
const QUrl url(sApp->getGlobalSetup().getVatsimBookingsUrl());
if (url.isEmpty()) { return; }
@@ -90,7 +90,7 @@ namespace BlackCore
this->threadAssertCheck();
// Worker thread, make sure to write no members here od do it threadsafe
if (this->isShuttingDown())
if (!this->doWorkCheck())
{
CLogMessage(this).debug() << Q_FUNC_INFO;
CLogMessage(this).info("Terminated booking parsing process");
@@ -135,7 +135,7 @@ namespace BlackCore
CAtcStationList bookedStations;
for (int i = 0; i < size; i++)
{
if (this->isAbandoned())
if (!this->doWorkCheck())
{
CLogMessage(this).debug() << Q_FUNC_INFO;
CLogMessage(this).info("Terminated booking parsing process"); // for users

View File

@@ -186,12 +186,13 @@ namespace BlackCore
void CVatsimDataFileReader::ps_read()
{
this->threadAssertCheck();
if (!this->doWorkCheck()) { return; }
if (!this->isNetworkAccessible())
{
CLogMessage(this).warning("No network, cannot read VATSIM data file");
return;
}
this->threadAssertCheck();
// round robin for load balancing
// remark: Don't use QThread to run network operations in the background
@@ -209,10 +210,9 @@ namespace BlackCore
// required to use delete later as object is created in a different thread
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
this->threadAssertCheck();
// Worker thread, make sure to write only synced here!
if (this->isAbandoned())
this->threadAssertCheck();
if (!this->doWorkCheck())
{
CLogMessage(this).debug() << Q_FUNC_INFO;
CLogMessage(this).info("Terminated VATSIM file parsing process");
@@ -249,7 +249,7 @@ namespace BlackCore
QString currentLine; // declared outside of the for loop, to amortize the cost of allocation
for (const QStringRef &clRef : lines)
{
if (this->isAbandoned())
if (!this->doWorkCheck())
{
CLogMessage(this).debug() << Q_FUNC_INFO;
CLogMessage(this).info("Terminated VATSIM file parsing process"); // for users

View File

@@ -79,13 +79,13 @@ namespace BlackCore
void CVatsimMetarReader::readMetars()
{
if (this->isAbandoned()) { return; }
this->threadAssertCheck();
if (!this->doWorkCheck()) { return; }
if (!this->isNetworkAccessible())
{
CLogMessage(this).warning("No network, cannot read METARs");
return;
}
this->threadAssertCheck();
CFailoverUrlList urls(sApp->getVatsimMetarUrls());
const CUrl url(urls.obtainNextWorkingUrl(true));
@@ -100,10 +100,9 @@ namespace BlackCore
// required to use delete later as object is created in a different thread
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
this->threadAssertCheck();
// Worker thread, make sure to write thread safe!
if (this->isAbandoned())
this->threadAssertCheck();
if (!this->doWorkCheck())
{
CLogMessage(this).debug() << Q_FUNC_INFO;
CLogMessage(this).info("terminated METAR decoding process"); // for users
@@ -126,7 +125,7 @@ namespace BlackCore
QTextStream lineReader(&metarData);
while (!lineReader.atEnd())
{
if (this->isAbandoned()) { return; }
if (!this->doWorkCheck()) { return; }
QString line = lineReader.readLine();
CMetar metar = m_metarDecoder.decode(line);
if (metar != CMetar()) { metars.push_back(metar); }
@@ -157,6 +156,5 @@ namespace BlackCore
CReaderSettings s = m_settings.get();
setInitialAndPeriodicTime(s.getInitialTime().toMs(), s.getPeriodicTime().toMs());
}
} // ns
} // ns

View File

@@ -74,6 +74,7 @@ namespace BlackCore
//! Do reading
void readMetars();
//! Reload settings
void reloadSettings();
private:

View File

@@ -47,7 +47,7 @@ namespace BlackCore
void CVatsimStatusFileReader::readInBackgroundThread()
{
bool s = QMetaObject::invokeMethod(this, "ps_read");
const bool s = QMetaObject::invokeMethod(this, "ps_read");
Q_ASSERT_X(s, Q_FUNC_INFO, "Invoke failed");
Q_UNUSED(s);
}
@@ -70,7 +70,12 @@ namespace BlackCore
void CVatsimStatusFileReader::ps_read()
{
this->threadAssertCheck();
if (!this->isNetworkAccessible()) { return; }
if (!this->doWorkCheck()) { return; }
if (!this->isNetworkAccessible())
{
CLogMessage(this).warning("No network, cannot read VATSIM status file");
return;
}
Q_ASSERT_X(sApp, Q_FUNC_INFO, "Missing application");
CFailoverUrlList urls(sApp->getGlobalSetup().getVatsimStatusFileUrls());
@@ -85,10 +90,9 @@ namespace BlackCore
// required to use delete later as object is created in a different thread
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
this->threadAssertCheck();
// Worker thread, make sure to write only synced here!
if (this->isAbandoned())
this->threadAssertCheck();
if (!this->doWorkCheck())
{
CLogMessage(this).debug() << Q_FUNC_INFO;
CLogMessage(this).info("Terminated VATSIM status file parsing process"); // for users
@@ -112,7 +116,7 @@ namespace BlackCore
QString currentLine; // declared outside of the for loop, to amortize the cost of allocation
for (const QStringRef &clRef : lines)
{
if (this->isAbandoned())
if (!this->doWorkCheck())
{
CLogMessage(this).debug() << Q_FUNC_INFO;
CLogMessage(this).info("Terminated status parsing process"); // for users