refs #334 VATSIM threaded reader classes using CContinuousWorker.

This commit is contained in:
Mathew Sutcliffe
2014-11-16 00:43:08 +00:00
committed by Roland Winklmeier
parent 195c909ca0
commit 54e883c322
6 changed files with 27 additions and 56 deletions

View File

@@ -50,17 +50,19 @@ namespace BlackCore
connect(this->m_network, &INetwork::textMessagesReceived, this, &CContextNetwork::ps_fsdTextMessageReceived);
// 2. VATSIM bookings
this->m_vatsimBookingReader = new CVatsimBookingReader(this->getRuntime()->getIContextSettings()->getNetworkSettings().getBookingServiceUrl(), this);
this->m_vatsimBookingReader = new CVatsimBookingReader(this, this->getRuntime()->getIContextSettings()->getNetworkSettings().getBookingServiceUrl());
connect(this->m_vatsimBookingReader, &CVatsimBookingReader::dataRead, this, &CContextNetwork::ps_receivedBookings);
this->m_vatsimBookingReader->read(); // first read
this->m_vatsimBookingReader->setInterval(180 * 1000);
this->m_vatsimBookingReader->start();
// 3. VATSIM data file
const QStringList dataFileUrls = { "http://info.vroute.net/vatsim-data.txt" };
this->m_vatsimDataFileReader = new CVatsimDataFileReader(dataFileUrls, this);
this->m_vatsimDataFileReader = new CVatsimDataFileReader(this, dataFileUrls);
connect(this->m_vatsimDataFileReader, &CVatsimDataFileReader::dataRead, this, &CContextNetwork::ps_dataFileRead);
this->m_vatsimDataFileReader->read(); // first read
this->m_vatsimDataFileReader->setInterval(90 * 1000);
this->m_vatsimDataFileReader->start();
// 4. Update timer for data (network data such as frequency)
this->m_dataUpdateTimer = new QTimer(this);
@@ -91,8 +93,8 @@ namespace BlackCore
*/
void CContextNetwork::gracefulShutdown()
{
if (this->m_vatsimBookingReader) this->m_vatsimBookingReader->stop();
if (this->m_vatsimDataFileReader) this->m_vatsimDataFileReader->stop();
if (this->m_vatsimBookingReader) this->m_vatsimBookingReader->quit();
if (this->m_vatsimDataFileReader) this->m_vatsimDataFileReader->quit();
if (this->isConnected()) this->disconnectFromNetwork();
}

View File

@@ -22,8 +22,8 @@ using namespace BlackMisc::Network;
namespace BlackCore
{
CVatsimBookingReader::CVatsimBookingReader(const QString &url, QObject *parent) :
QObject(parent), CThreadedReader(),
CVatsimBookingReader::CVatsimBookingReader(QObject *owner, const QString &url) :
CThreadedReader(owner),
m_serviceUrl(url), m_networkManager(nullptr)
{
this->m_networkManager = new QNetworkAccessManager(this);
@@ -47,7 +47,7 @@ namespace BlackCore
void CVatsimBookingReader::ps_loadFinished(QNetworkReply *nwReply)
{
this->setPendingNetworkReply(nullptr);
if (!this->isStopped())
if (!this->isFinished())
{
QFuture<void> f = QtConcurrent::run(this, &CVatsimBookingReader::parseBookings, nwReply);
this->setPendingFuture(f);
@@ -64,7 +64,7 @@ namespace BlackCore
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
// Worker thread, make sure to write no members here!
if (this->isStopped())
if (this->isFinished())
{
CLogMessage(this).debug() << Q_FUNC_INFO;
CLogMessage(this).info("terminated booking parsing process"); // for users
@@ -100,7 +100,7 @@ namespace BlackCore
CAtcStationList bookedStations;
for (int i = 0; i < size; i++)
{
if (this->isStopped())
if (this->isFinished())
{
CLogMessage(this).debug() << Q_FUNC_INFO;
CLogMessage(this).info("terminated booking parsing process"); // for users

View File

@@ -25,13 +25,13 @@ namespace BlackCore
/*!
* Read bookings from VATSIM
*/
class CVatsimBookingReader : public QObject, public BlackMisc::CThreadedReader<void>
class CVatsimBookingReader : public BlackMisc::CThreadedReader<void>
{
Q_OBJECT
public:
//! Constructor
explicit CVatsimBookingReader(const QString &url, QObject *parent = nullptr);
explicit CVatsimBookingReader(QObject *owner, const QString &url);
//! Read / re-read bookings
void read();

View File

@@ -25,8 +25,8 @@ using namespace BlackMisc::PhysicalQuantities;
namespace BlackCore
{
CVatsimDataFileReader::CVatsimDataFileReader(const QStringList &urls, QObject *parent) :
QObject(parent), CThreadedReader(),
CVatsimDataFileReader::CVatsimDataFileReader(QObject *owner, const QStringList &urls) :
CThreadedReader(owner),
m_serviceUrls(urls), m_currentUrlIndex(0), m_networkManager(nullptr)
{
this->m_networkManager = new QNetworkAccessManager(this);
@@ -149,7 +149,7 @@ namespace BlackCore
void CVatsimDataFileReader::ps_loadFinished(QNetworkReply *nwReply)
{
this->setPendingNetworkReply(nullptr);
if (!this->isStopped())
if (!this->isFinished())
{
QFuture<void> f = QtConcurrent::run(this, &CVatsimDataFileReader::parseVatsimFileInBackground, nwReply);
this->setPendingFuture(f);
@@ -167,7 +167,7 @@ namespace BlackCore
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
// Worker thread, make sure to write only synced here!
if (this->isStopped())
if (this->isFinished())
{
CLogMessage(this).debug() << Q_FUNC_INFO;
CLogMessage(this).info("terminated VATSIM file parsing process"); // for users
@@ -196,7 +196,7 @@ namespace BlackCore
Section section = SectionNone;
foreach(QString currentLine, lines)
{
if (this->isStopped())
if (this->isFinished())
{
CLogMessage(this).debug() << Q_FUNC_INFO;
CLogMessage(this).info("terminated booking parsing process"); // for users

View File

@@ -30,13 +30,13 @@ namespace BlackCore
/*!
* Read bookings from VATSIM
*/
class CVatsimDataFileReader : public QObject, public BlackMisc::CThreadedReader<void>
class CVatsimDataFileReader : public BlackMisc::CThreadedReader<void>
{
Q_OBJECT
public:
//! Constructor
explicit CVatsimDataFileReader(const QStringList &urls, QObject *parent = nullptr);
explicit CVatsimDataFileReader(QObject *owner, const QStringList &urls);
//! Read / re-read data file
void read();