mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-13 07:35:41 +08:00
refs #132 , network context adjusted, reading of VATSIM bookings now in own reader class.
* Timer for bookings removed * Adjusted context slots for reader class * Consolidation of ATC online and ATC booked in booking receiver slot (CContextNetwork::psReceivedBookings)
This commit is contained in:
@@ -24,9 +24,10 @@ namespace BlackCore
|
|||||||
* Init this context
|
* Init this context
|
||||||
*/
|
*/
|
||||||
CContextNetwork::CContextNetwork(CCoreRuntime *runtime) :
|
CContextNetwork::CContextNetwork(CCoreRuntime *runtime) :
|
||||||
IContextNetwork(runtime), m_network(nullptr), m_networkManager(nullptr),
|
IContextNetwork(runtime), m_network(nullptr), m_bookingReader(nullptr), m_dataUpdateTimer(nullptr)
|
||||||
m_atcBookingTimer(nullptr), m_dataUpdateTimer(nullptr)
|
|
||||||
{
|
{
|
||||||
|
Q_ASSERT(this->getRuntime());
|
||||||
|
Q_ASSERT(this->getRuntime()->getIContextSettings());
|
||||||
|
|
||||||
// 1. Init by "network driver"
|
// 1. Init by "network driver"
|
||||||
this->m_network = new CNetworkVatlib(this);
|
this->m_network = new CNetworkVatlib(this);
|
||||||
@@ -34,12 +35,10 @@ namespace BlackCore
|
|||||||
// 2. Init own aircraft
|
// 2. Init own aircraft
|
||||||
this->initOwnAircraft();
|
this->initOwnAircraft();
|
||||||
|
|
||||||
// 3a. Init network access driver for XML data (bookings)
|
// 3a. Init VATSIM bookings
|
||||||
this->m_networkManager = new QNetworkAccessManager(this);
|
this->m_bookingReader = new CVatsimBookingReader(this->getRuntime()->getIContextSettings()->getNetworkSettings().getBookingServiceUrl(), this);
|
||||||
this->m_atcBookingTimer = new QTimer(this);
|
this->connect(this->m_bookingReader, &CVatsimBookingReader::bookingsRead, this, &CContextNetwork::psReceivedBookings);
|
||||||
this->connect(this->m_networkManager, &QNetworkAccessManager::finished, this, &CContextNetwork::psAtcBookingsRead);
|
this->m_bookingReader->setInterval(10 * 1000); // first read
|
||||||
this->connect(this->m_atcBookingTimer, &QTimer::timeout, this, &CContextNetwork::readAtcBookingsFromSource);
|
|
||||||
this->m_atcBookingTimer->start(10 * 1000); // will be reset in method to a longer time
|
|
||||||
|
|
||||||
// 3b. Update timer for data
|
// 3b. Update timer for data
|
||||||
this->m_dataUpdateTimer = new QTimer(this);
|
this->m_dataUpdateTimer = new QTimer(this);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "blackcore/dbus_server.h"
|
#include "blackcore/dbus_server.h"
|
||||||
#include "blackcore/network_vatlib.h"
|
#include "blackcore/network_vatlib.h"
|
||||||
#include "blackcore/coreruntime.h"
|
#include "blackcore/coreruntime.h"
|
||||||
|
#include "blackcore/vatsimbookingreader.h"
|
||||||
#include "blackcore/context_network_interface.h"
|
#include "blackcore/context_network_interface.h"
|
||||||
#include "blackcore/context_settings_interface.h"
|
#include "blackcore/context_settings_interface.h"
|
||||||
#include "blackmisc/avcallsignlist.h"
|
#include "blackmisc/avcallsignlist.h"
|
||||||
@@ -61,7 +62,7 @@ namespace BlackCore
|
|||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
//! \copydoc IContextNetwork::readAtcBookingsFromSource()
|
//! \copydoc IContextNetwork::readAtcBookingsFromSource()
|
||||||
virtual void readAtcBookingsFromSource();
|
virtual void readAtcBookingsFromSource() override;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \copydoc IContextNetwork::getAtcStationsOnline()
|
* \copydoc IContextNetwork::getAtcStationsOnline()
|
||||||
@@ -147,10 +148,8 @@ namespace BlackCore
|
|||||||
QMap<QString, BlackMisc::Aviation::CInformationMessage> m_metarCache /*!< Keep METARs for a while */;
|
QMap<QString, BlackMisc::Aviation::CInformationMessage> m_metarCache /*!< Keep METARs for a while */;
|
||||||
|
|
||||||
// for reading XML
|
// for reading XML
|
||||||
QNetworkAccessManager *m_networkManager;
|
CVatsimBookingReader *m_bookingReader;
|
||||||
QTimer *m_atcBookingTimer; //!< ATC stations bookings
|
|
||||||
QTimer *m_dataUpdateTimer; //!< general updates such as ATIS, frequencies, see requestDataUpdates()
|
QTimer *m_dataUpdateTimer; //!< general updates such as ATIS, frequencies, see requestDataUpdates()
|
||||||
QDateTime m_atcBookingsUpdateTimestamp;
|
|
||||||
|
|
||||||
//! \brief Replace value by new values
|
//! \brief Replace value by new values
|
||||||
void setAtcStationsBooked(const BlackMisc::Aviation::CAtcStationList &newStations);
|
void setAtcStationsBooked(const BlackMisc::Aviation::CAtcStationList &newStations);
|
||||||
@@ -182,6 +181,9 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
//! \brief ATC bookings received
|
||||||
|
void psReceivedBookings(BlackMisc::Aviation::CAtcStationList bookedStations);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Connection status changed?
|
* \brief Connection status changed?
|
||||||
* \param from old status
|
* \param from old status
|
||||||
@@ -235,13 +237,6 @@ namespace BlackCore
|
|||||||
|
|
||||||
//! \brief Radio text messages received
|
//! \brief Radio text messages received
|
||||||
void psFsdTextMessageReceived(const BlackMisc::Network::CTextMessageList &messages);
|
void psFsdTextMessageReceived(const BlackMisc::Network::CTextMessageList &messages);
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Bookings via XML read
|
|
||||||
* \todo encapsulate reading from WWW in some class
|
|
||||||
*/
|
|
||||||
void psAtcBookingsRead(QNetworkReply *nwReply);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,18 +26,27 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read bookings
|
* Reload bookings
|
||||||
*/
|
*/
|
||||||
void CContextNetwork::readAtcBookingsFromSource()
|
void CContextNetwork::readAtcBookingsFromSource()
|
||||||
{
|
{
|
||||||
const int updateTime = 60 * 1000; // 1min
|
Q_ASSERT(this->m_bookingReader);
|
||||||
if (!(this->m_atcBookingTimer->interval() == updateTime)) this->m_atcBookingTimer->setInterval(updateTime); // 1min
|
this->m_bookingReader->read();
|
||||||
|
}
|
||||||
|
|
||||||
QUrl url(this->getNetworkSettings().getBookingServiceUrl());
|
/*
|
||||||
if (url.isEmpty()) return;
|
* Update bookings
|
||||||
|
*/
|
||||||
QNetworkRequest request(url);
|
void CContextNetwork::psReceivedBookings(CAtcStationList bookedStations)
|
||||||
this->m_networkManager->get(request);
|
{
|
||||||
|
const int interval = 60 * 1000;
|
||||||
|
if (this->m_bookingReader->interval() < interval) this->m_bookingReader->setInterval(interval);
|
||||||
|
this->m_atcStationsBooked.clear();
|
||||||
|
foreach(CAtcStation bookedStation, bookedStations)
|
||||||
|
{
|
||||||
|
this->m_atcStationsOnline.mergeWithBooking(bookedStation);
|
||||||
|
this->m_atcStationsBooked.push_back(bookedStation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -322,85 +331,4 @@ namespace BlackCore
|
|||||||
this->m_metarCache.insert(icaoCode, metar);
|
this->m_metarCache.insert(icaoCode, metar);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Bookings read from XML
|
|
||||||
* TODO: encapsulate reading from WWW in some class
|
|
||||||
*/
|
|
||||||
void CContextNetwork::psAtcBookingsRead(QNetworkReply *nwReply)
|
|
||||||
{
|
|
||||||
if (nwReply->error() == QNetworkReply::NoError)
|
|
||||||
{
|
|
||||||
QString xmlData = nwReply->readAll();
|
|
||||||
QDomDocument doc;
|
|
||||||
|
|
||||||
if (doc.setContent(xmlData))
|
|
||||||
{
|
|
||||||
QDomNode atc = doc.elementsByTagName("atcs").at(0);
|
|
||||||
QDomNodeList bookingNodes = atc.toElement().elementsByTagName("booking");
|
|
||||||
int size = bookingNodes.size();
|
|
||||||
CSequence<CAtcStation> stations;
|
|
||||||
for (int i = 0; i < size; i++)
|
|
||||||
{
|
|
||||||
QDomNode bookingNode = bookingNodes.at(i);
|
|
||||||
QDomNodeList bookingNodeValues = bookingNode.childNodes();
|
|
||||||
CAtcStation bookedStation;
|
|
||||||
CUser user;
|
|
||||||
for (int v = 0; v < bookingNodeValues.size(); v++)
|
|
||||||
{
|
|
||||||
QDomNode bookingNodeValue = bookingNodeValues.at(v);
|
|
||||||
QString name = bookingNodeValue.nodeName().toLower();
|
|
||||||
QString value = bookingNodeValue.toElement().text();
|
|
||||||
if (name == "id")
|
|
||||||
{
|
|
||||||
// could be used as unique key
|
|
||||||
}
|
|
||||||
else if (name == "callsign")
|
|
||||||
{
|
|
||||||
bookedStation.setCallsign(CCallsign(value));
|
|
||||||
}
|
|
||||||
else if (name == "name")
|
|
||||||
{
|
|
||||||
user.setRealName(value);
|
|
||||||
}
|
|
||||||
else if (name == "cid")
|
|
||||||
{
|
|
||||||
user.setId(value);
|
|
||||||
}
|
|
||||||
else if (name == "time_end")
|
|
||||||
{
|
|
||||||
QDateTime t = QDateTime::fromString(value, "yyyy-MM-dd HH:mm:ss");
|
|
||||||
bookedStation.setBookedUntilUtc(t);
|
|
||||||
}
|
|
||||||
else if (name == "time_start")
|
|
||||||
{
|
|
||||||
QDateTime t = QDateTime::fromString(value, "yyyy-MM-dd HH:mm:ss");
|
|
||||||
bookedStation.setBookedFromUtc(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// time checks
|
|
||||||
QDateTime now = QDateTime::currentDateTimeUtc();
|
|
||||||
if (now.msecsTo(bookedStation.getBookedUntilUtc()) < (1000 * 60 * 15)) continue; // until n mins in past
|
|
||||||
if (now.msecsTo(bookedStation.getBookedFromUtc()) > (1000 * 60 * 60 * 24)) continue; // to far in the future, n hours
|
|
||||||
|
|
||||||
// booking does not have position, so distance cannot be calculated
|
|
||||||
// bookedStation.calculcateDistanceToPlane(this->m_ownAircraft.getPosition());
|
|
||||||
|
|
||||||
bookedStation.setController(user);
|
|
||||||
|
|
||||||
// consolidate and append
|
|
||||||
this->m_atcStationsOnline.mergeWithBooking(bookedStation);
|
|
||||||
stations.push_back(bookedStation);
|
|
||||||
}
|
|
||||||
nwReply->close();
|
|
||||||
nwReply->deleteLater();
|
|
||||||
|
|
||||||
// set the new values
|
|
||||||
if (this->getAtcStationsBooked() != stations)
|
|
||||||
{
|
|
||||||
this->atcStationsBooked() = stations;
|
|
||||||
emit this->changedAtcStationsBooked();
|
|
||||||
}
|
|
||||||
} // node
|
|
||||||
} // content
|
|
||||||
} // method
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -155,8 +155,7 @@ namespace BlackCore
|
|||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Read ATC bookings
|
* \brief Reload bookings from booking service
|
||||||
* \return
|
|
||||||
*/
|
*/
|
||||||
virtual void readAtcBookingsFromSource();
|
virtual void readAtcBookingsFromSource();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user