From 1a72b4b691df239f39a86854f6ec4d5a5ebcfc72 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 7 Feb 2014 21:30:04 +0100 Subject: [PATCH] refs #93, update network data such as ATIS or pilot frequencies from time to time, as these data are not actively pushed from network when changing * timer in network context * update methods, one specific method for ATIS as this can also be manually re-read(from GUI) --- src/blackcore/context_network.cpp | 7 ++++- src/blackcore/context_network.h | 10 ++++++- src/blackcore/context_network_atc.cpp | 29 +++++++++++++++++++++ src/blackcore/context_network_interface.cpp | 10 +++++++ src/blackcore/context_network_interface.h | 10 +++++++ 5 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/blackcore/context_network.cpp b/src/blackcore/context_network.cpp index acc37ac45..f7d6eeadf 100644 --- a/src/blackcore/context_network.cpp +++ b/src/blackcore/context_network.cpp @@ -33,13 +33,18 @@ namespace BlackCore // 2. Init own aircraft this->initOwnAircraft(); - // 3. Init network access driver for XML data (bookings) + // 3a. Init network access driver for XML data (bookings) this->m_networkManager = new QNetworkAccessManager(this); this->m_atcBookingTimer = new QTimer(this); this->connect(this->m_networkManager, &QNetworkAccessManager::finished, this, &CContextNetwork::psAtcBookingsRead); 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 + this->m_dataUpdateTimer = new QTimer(this); + this->connect(this->m_dataUpdateTimer, &QTimer::timeout, this, &CContextNetwork::requestDataUpdates); + this->m_dataUpdateTimer->start(30 * 1000); + // 4. connect signals and slots this->connect(this->m_network, &INetwork::connectionStatusChanged, this, &CContextNetwork::psFsdConnectionStatusChanged); this->connect(this->m_network, &INetwork::atcPositionUpdate, this, &CContextNetwork::psFsdAtcPositionUpdate); diff --git a/src/blackcore/context_network.h b/src/blackcore/context_network.h index 06ab3e7b2..8e4a9ff7c 100644 --- a/src/blackcore/context_network.h +++ b/src/blackcore/context_network.h @@ -159,6 +159,12 @@ namespace BlackCore //! \copydoc IContextNetwork::getUsersForCallsigns virtual BlackMisc::Network::CUserList getUsersForCallsigns(const BlackMisc::Aviation::CCallsignList &callsigns) const; + //! \copydoc IContextNetwork::requestDataUpdates + virtual void requestDataUpdates(); + + //! \copydoc IContextNetwork::requestAtisUpdates + virtual void requestAtisUpdates(); + private: BlackMisc::Aviation::CAtcStationList m_atcStationsOnline; BlackMisc::Aviation::CAtcStationList m_atcStationsBooked; @@ -169,7 +175,8 @@ namespace BlackCore // for reading XML QNetworkAccessManager *m_networkManager; - QTimer *m_atcBookingTimer; + QTimer *m_atcBookingTimer; //!< ATC stations bookings + QTimer *m_dataUpdateTimer; //!< general updates such as ATIS, frequencies, see requestDataUpdates() QDateTime m_atcBookingsUpdateTimestamp; /*! @@ -291,6 +298,7 @@ namespace BlackCore * \todo encapsulate reading from WWW in some class */ void psAtcBookingsRead(QNetworkReply *nwReply); + }; } diff --git a/src/blackcore/context_network_atc.cpp b/src/blackcore/context_network_atc.cpp index dd84b6e49..16b734e8b 100644 --- a/src/blackcore/context_network_atc.cpp +++ b/src/blackcore/context_network_atc.cpp @@ -40,6 +40,35 @@ namespace BlackCore this->m_networkManager->get(request); } + /* + * Update data + */ + void CContextNetwork::requestDataUpdates() + { + Q_ASSERT(this->m_network); + if (!this->isConnected()) return; + this->requestAtisUpdates(); + + // other updates + foreach(CAircraft aircraft, this->m_aircraftsInRange) + { + this->m_network->sendFrequencyQuery(aircraft.getCallsign()); + } + } + + /* + * Request new ATIS data + */ + void CContextNetwork::requestAtisUpdates() + { + Q_ASSERT(this->m_network); + if (!this->isConnected()) return; + foreach(CAtcStation station, this->m_atcStationsOnline) + { + this->m_network->sendAtisQuery(station.getCallsign()); + } + } + /* * Booked stations */ diff --git a/src/blackcore/context_network_interface.cpp b/src/blackcore/context_network_interface.cpp index fd3e9f7e9..7a74287e9 100644 --- a/src/blackcore/context_network_interface.cpp +++ b/src/blackcore/context_network_interface.cpp @@ -101,6 +101,16 @@ namespace BlackCore return this->m_dBusInterface->callDBusRet(QLatin1Literal("getSelectedAtcStations")); } + void IContextNetwork::requestDataUpdates() + { + this->m_dBusInterface->callDBus(QLatin1Literal("requestDataUpdates")); + } + + void IContextNetwork::requestAtisUpdates() + { + this->m_dBusInterface->callDBus(QLatin1Literal("requestAtisUpdates")); + } + BlackMisc::Aviation::CAircraft IContextNetwork::getOwnAircraft() const { return this->m_dBusInterface->callDBusRet(QLatin1Literal("getOwnAircraft")); diff --git a/src/blackcore/context_network_interface.h b/src/blackcore/context_network_interface.h index 15abea1b4..970dcafd8 100644 --- a/src/blackcore/context_network_interface.h +++ b/src/blackcore/context_network_interface.h @@ -252,6 +252,16 @@ namespace BlackCore * \brief Use the selected COM1/2 frequencies, and get the corresponding ATC stations for it */ virtual BlackMisc::Aviation::CAtcStationList getSelectedAtcStations() const; + + /*! + * \brief Request data updates (pilot' frequencies, ATIS, ..) + */ + virtual void requestDataUpdates(); + + /*! + * \brief Request ATIS updates (for all stations) + */ + virtual void requestAtisUpdates(); }; }