mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-21 04:45:31 +08:00
refs #259, parsing VATSIM files in background
This commit is contained in:
@@ -2,7 +2,9 @@
|
|||||||
#include "blackmisc/avatcstation.h"
|
#include "blackmisc/avatcstation.h"
|
||||||
#include "blackmisc/nwuser.h"
|
#include "blackmisc/nwuser.h"
|
||||||
#include "vatsimbookingreader.h"
|
#include "vatsimbookingreader.h"
|
||||||
|
|
||||||
#include <QtXml/QDomElement>
|
#include <QtXml/QDomElement>
|
||||||
|
#include <QtConcurrent/QtConcurrent>
|
||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
using namespace BlackMisc::Aviation;
|
using namespace BlackMisc::Aviation;
|
||||||
@@ -41,6 +43,14 @@ namespace BlackCore
|
|||||||
* Bookings read from XML
|
* Bookings read from XML
|
||||||
*/
|
*/
|
||||||
void CVatsimBookingReader::loadFinished(QNetworkReply *nwReply)
|
void CVatsimBookingReader::loadFinished(QNetworkReply *nwReply)
|
||||||
|
{
|
||||||
|
QtConcurrent::run(this, &CVatsimBookingReader::parseBookings, nwReply);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Parse bookings
|
||||||
|
*/
|
||||||
|
void CVatsimBookingReader::parseBookings(QNetworkReply *nwReply)
|
||||||
{
|
{
|
||||||
if (nwReply->error() == QNetworkReply::NoError)
|
if (nwReply->error() == QNetworkReply::NoError)
|
||||||
{
|
{
|
||||||
@@ -100,10 +110,12 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
m_updateTimestamp = QDateTime::currentDateTimeUtc();
|
m_updateTimestamp = QDateTime::currentDateTimeUtc();
|
||||||
emit this->dataRead(bookedStations);
|
emit this->dataRead(bookedStations);
|
||||||
nwReply->close();
|
|
||||||
nwReply->deleteLater();
|
|
||||||
|
|
||||||
} // node
|
} // node
|
||||||
} // content
|
} // content
|
||||||
|
|
||||||
|
nwReply->close();
|
||||||
|
nwReply->deleteLater();
|
||||||
|
|
||||||
} // method
|
} // method
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -49,9 +49,12 @@ namespace BlackCore
|
|||||||
QDateTime m_updateTimestamp;
|
QDateTime m_updateTimestamp;
|
||||||
QTimer *m_updateTimer;
|
QTimer *m_updateTimer;
|
||||||
|
|
||||||
|
//! Parse received bookings
|
||||||
|
void parseBookings(QNetworkReply *nwReply);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
//! \brief Bookings have been read and converted to BlackMisc::Aviation::CAtcStationList
|
//! Bookings have been read and converted to BlackMisc::Aviation::CAtcStationList
|
||||||
void dataRead(BlackMisc::Aviation::CAtcStationList bookedStations);
|
void dataRead(const BlackMisc::Aviation::CAtcStationList &bookedStations);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "vatsimdatafilereader.h"
|
#include "vatsimdatafilereader.h"
|
||||||
|
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
#include <QtConcurrent/QtConcurrent>
|
||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
using namespace BlackMisc::Aviation;
|
using namespace BlackMisc::Aviation;
|
||||||
@@ -27,9 +28,13 @@ namespace BlackCore
|
|||||||
void CVatsimDataFileReader::read()
|
void CVatsimDataFileReader::read()
|
||||||
{
|
{
|
||||||
if (this->m_serviceUrls.isEmpty()) return;
|
if (this->m_serviceUrls.isEmpty()) return;
|
||||||
|
|
||||||
|
// round robin for load distribution
|
||||||
this->m_currentUrlIndex++;
|
this->m_currentUrlIndex++;
|
||||||
if (this->m_serviceUrls.size() >= this->m_currentUrlIndex) this->m_currentUrlIndex = 0;
|
if (this->m_serviceUrls.size() >= this->m_currentUrlIndex) this->m_currentUrlIndex = 0;
|
||||||
|
|
||||||
|
// remark: Don't use QThread to run network operations in the background
|
||||||
|
// see http://qt-project.org/doc/qt-4.7/qnetworkaccessmanager.html
|
||||||
QUrl url(this->m_serviceUrls.at(this->m_currentUrlIndex));
|
QUrl url(this->m_serviceUrls.at(this->m_currentUrlIndex));
|
||||||
if (url.isEmpty()) return;
|
if (url.isEmpty()) return;
|
||||||
Q_ASSERT(this->m_networkManager);
|
Q_ASSERT(this->m_networkManager);
|
||||||
@@ -111,6 +116,14 @@ namespace BlackCore
|
|||||||
* Data file read from XML
|
* Data file read from XML
|
||||||
*/
|
*/
|
||||||
void CVatsimDataFileReader::loadFinished(QNetworkReply *nwReply)
|
void CVatsimDataFileReader::loadFinished(QNetworkReply *nwReply)
|
||||||
|
{
|
||||||
|
QtConcurrent::run(this, &CVatsimDataFileReader::parseVatsimFileInBackground, nwReply);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Data file read from XML
|
||||||
|
*/
|
||||||
|
void CVatsimDataFileReader::parseVatsimFileInBackground(QNetworkReply *nwReply)
|
||||||
{
|
{
|
||||||
// Example: http://info.vroute.net/vatsim-data.txt
|
// Example: http://info.vroute.net/vatsim-data.txt
|
||||||
if (nwReply->error() == QNetworkReply::NoError)
|
if (nwReply->error() == QNetworkReply::NoError)
|
||||||
@@ -248,6 +261,9 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
} // for each
|
} // for each
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nwReply->close();
|
||||||
|
nwReply->deleteLater(); // we are responsible for reading this
|
||||||
emit this->dataRead();
|
emit this->dataRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -98,6 +98,9 @@ namespace BlackCore
|
|||||||
SectionGeneral
|
SectionGeneral
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//! Parse the VATSIM data file in backgroun
|
||||||
|
void parseVatsimFileInBackground(QNetworkReply *nwReply);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
//! Data have been read
|
//! Data have been read
|
||||||
void dataRead();
|
void dataRead();
|
||||||
|
|||||||
Reference in New Issue
Block a user