From 5fe4ea303998ba3b48ae18c4eb814a8c4ce71c02 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Sun, 5 Oct 2014 20:03:32 +0200 Subject: [PATCH] refs #324 connect airspace watchdog to airspace monitor --- src/blackcore/airspace_monitor.cpp | 15 ++++++++++++++- src/blackcore/airspace_monitor.h | 3 +++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/blackcore/airspace_monitor.cpp b/src/blackcore/airspace_monitor.cpp index 2026cd3d1..2551fdbde 100644 --- a/src/blackcore/airspace_monitor.cpp +++ b/src/blackcore/airspace_monitor.cpp @@ -24,7 +24,8 @@ namespace BlackCore using namespace BlackMisc::PhysicalQuantities; CAirspaceMonitor::CAirspaceMonitor(QObject *parent, INetwork *network, CVatsimBookingReader *bookings, CVatsimDataFileReader *dataFile) - : QObject(parent), m_network(network), m_vatsimBookingReader(bookings), m_vatsimDataFileReader(dataFile) + : QObject(parent), m_network(network), m_vatsimBookingReader(bookings), m_vatsimDataFileReader(dataFile), + m_atcWatchdog(this), m_aircraftWatchdog(this) { this->connect(this->m_network, &INetwork::atcPositionUpdate, this, &CAirspaceMonitor::ps_atcPositionUpdate); this->connect(this->m_network, &INetwork::atisReplyReceived, this, &CAirspaceMonitor::ps_atisReceived); @@ -45,6 +46,12 @@ namespace BlackCore // AutoConnection: this should also avoid race conditions by updating the bookings this->connect(this->m_vatsimBookingReader, &CVatsimBookingReader::dataRead, this, &CAirspaceMonitor::ps_receivedBookings); this->connect(this->m_vatsimDataFileReader, &CVatsimDataFileReader::dataRead, this, &CAirspaceMonitor::ps_receivedDataFile); + + // Watchdog + // ATC stations send updates every 25 s. Configure timeout after 50 s. + m_atcWatchdog.setTimeout(CTime(50, CTimeUnit::s())); + this->connect(&this->m_aircraftWatchdog, &CAirspaceWatchdog::timeout, this, &CAirspaceMonitor::ps_pilotDisconnected); + this->connect(&this->m_atcWatchdog, &CAirspaceWatchdog::timeout, this, &CAirspaceMonitor::ps_atcControllerDisconnected); } CFlightPlan CAirspaceMonitor::loadFlightPlanFromNetwork(const CCallsign &callsign) @@ -388,6 +395,7 @@ namespace BlackCore emit this->m_network->sendServerQuery(callsign); } + this->m_atcWatchdog.addCallsign(callsign); emit this->changedAtcStationsOnline(); // Remark: this->changedAtcStationOnlineConnectionStatus(station, true); // will be sent in psFsdAtisVoiceRoomReceived @@ -401,6 +409,7 @@ namespace BlackCore vm.addValue(CAtcStation::IndexRange, range); int changed = this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm, true); if (changed > 0) { emit this->changedAtcStationsOnline(); } + this->m_atcWatchdog.resetCallsign(callsign); } } @@ -411,6 +420,7 @@ namespace BlackCore { CAtcStation removeStation = this->m_atcStationsOnline.findByCallsign(callsign).front(); this->m_atcStationsOnline.removeIf(&CAtcStation::getCallsign, callsign); + this->m_atcWatchdog.removeCallsign(callsign); emit this->changedAtcStationsOnline(); emit this->changedAtcStationOnlineConnectionStatus(removeStation, false); } @@ -535,6 +545,7 @@ namespace BlackCore this->sendFsipirCustomPacket(callsign); // own aircraft model } + this->m_aircraftWatchdog.addCallsign(callsign); emit this->addedAircraft(callsign, situation); } else @@ -549,6 +560,7 @@ namespace BlackCore // here I expect always a changed value this->m_aircraftsInRange.applyIf(&CAircraft::getCallsign, callsign, vm, false); + this->m_aircraftWatchdog.resetCallsign(callsign); emit this->changedAircraftSituation(callsign, situation); } @@ -559,6 +571,7 @@ namespace BlackCore { Q_ASSERT(BlackCore::isCurrentThreadCreatingThread(this)); bool contains = this->m_aircraftsInRange.contains(&CAircraft::getCallsign, callsign); + this->m_aircraftWatchdog.removeCallsign(callsign); if (contains) { this->m_aircraftsInRange.removeIf(&CAircraft::getCallsign, callsign); diff --git a/src/blackcore/airspace_monitor.h b/src/blackcore/airspace_monitor.h index 3d7d5f095..7fa294bd3 100644 --- a/src/blackcore/airspace_monitor.h +++ b/src/blackcore/airspace_monitor.h @@ -21,6 +21,7 @@ #include "network.h" #include "vatsimbookingreader.h" #include "vatsimdatafilereader.h" +#include "airspace_watchdog.h" namespace BlackCore { @@ -133,6 +134,8 @@ namespace BlackCore INetwork *m_network; CVatsimBookingReader *m_vatsimBookingReader; CVatsimDataFileReader *m_vatsimDataFileReader; + CAirspaceWatchdog m_atcWatchdog; + CAirspaceWatchdog m_aircraftWatchdog; // FIXME (MS) should be in INetwork void sendFsipiCustomPacket(const BlackMisc::Aviation::CCallsign &recipientCallsign) const;