Ref T105, adjusted airspace analyzer

* removed private slots
* gracefulShutdown -> setEnabled
This commit is contained in:
Klaus Basan
2017-07-10 19:54:33 +02:00
committed by Mathew Sutcliffe
parent 4e4d33a755
commit cd15bdc506
3 changed files with 44 additions and 51 deletions

View File

@@ -37,30 +37,28 @@ namespace BlackCore
{
Q_ASSERT_X(network, Q_FUNC_INFO, "Network object required to connect");
// start in thread
this->setObjectName("CAirspaceAnalyzer");
// all in new thread from here on
this->setObjectName(getName());
m_timer.setObjectName(this->objectName().append(":m_timer"));
m_timer.start(7500);
m_lastWatchdogCallMsSinceEpoch = QDateTime::currentMSecsSinceEpoch();
bool c = connect(&m_timer, &QTimer::timeout, this, &CAirspaceAnalyzer::ps_timeout);
bool c = connect(&m_timer, &QTimer::timeout, this, &CAirspaceAnalyzer::onTimeout);
Q_ASSERT(c);
// disconnect
c = connect(network, &INetwork::pilotDisconnected, this, &CAirspaceAnalyzer::ps_watchdogRemoveAircraftCallsign);
c = connect(network, &INetwork::pilotDisconnected, this, &CAirspaceAnalyzer::watchdogRemoveAircraftCallsign);
Q_ASSERT(c);
c = connect(network, &INetwork::atcDisconnected, this, &CAirspaceAnalyzer::ps_watchdogRemoveAtcCallsign);
c = connect(network, &INetwork::atcDisconnected, this, &CAirspaceAnalyzer::watchdogRemoveAtcCallsign);
Q_ASSERT(c);
// update
c = connect(network, &INetwork::aircraftPositionUpdate, this, &CAirspaceAnalyzer::ps_watchdogTouchAircraftCallsign);
c = connect(network, &INetwork::aircraftPositionUpdate, this, &CAirspaceAnalyzer::watchdogTouchAircraftCallsign);
Q_ASSERT(c);
c = connect(network, &INetwork::atcPositionUpdate, this, &CAirspaceAnalyzer::ps_watchdogTouchAtcCallsign);
c = connect(network, &INetwork::atcPositionUpdate, this, &CAirspaceAnalyzer::watchdogTouchAtcCallsign);
Q_ASSERT(c);
// network
c = connect(network, &INetwork::connectionStatusChanged, this, &CAirspaceAnalyzer::ps_onConnectionStatusChanged);
c = connect(network, &INetwork::connectionStatusChanged, this, &CAirspaceAnalyzer::onConnectionStatusChanged);
Q_ASSERT(c);
Q_UNUSED(c);
@@ -83,26 +81,17 @@ namespace BlackCore
this->m_simulatorMaxRenderedDistance = maxRenderedDistance;
}
void CAirspaceAnalyzer::gracefulShutdown()
{
const bool s = QMetaObject::invokeMethod(&m_timer, "stop");
Q_ASSERT_X(s, Q_FUNC_INFO, "invoke failed");
Q_UNUSED(s);
}
CAirspaceAnalyzer::~CAirspaceAnalyzer()
{
gracefulShutdown();
}
{ }
void CAirspaceAnalyzer::ps_watchdogTouchAircraftCallsign(const CAircraftSituation &situation, const CTransponder &transponder)
void CAirspaceAnalyzer::watchdogTouchAircraftCallsign(const CAircraftSituation &situation, const CTransponder &transponder)
{
Q_ASSERT_X(!situation.getCallsign().isEmpty(), Q_FUNC_INFO, "No callsign in situaton");
Q_UNUSED(transponder);
m_aircraftCallsignTimestamps[situation.getCallsign()] = QDateTime::currentMSecsSinceEpoch();
}
void CAirspaceAnalyzer::ps_watchdogTouchAtcCallsign(const CCallsign &callsign, const CFrequency &frequency, const Geo::CCoordinateGeodetic &position, const CLength &range)
void CAirspaceAnalyzer::watchdogTouchAtcCallsign(const CCallsign &callsign, const CFrequency &frequency, const Geo::CCoordinateGeodetic &position, const CLength &range)
{
Q_UNUSED(frequency);
Q_UNUSED(position);
@@ -110,7 +99,7 @@ namespace BlackCore
m_atcCallsignTimestamps[callsign] = QDateTime::currentMSecsSinceEpoch();
}
void CAirspaceAnalyzer::ps_onConnectionStatusChanged(BlackCore::INetwork::ConnectionStatus oldStatus, BlackCore::INetwork::ConnectionStatus newStatus)
void CAirspaceAnalyzer::onConnectionStatusChanged(BlackCore::INetwork::ConnectionStatus oldStatus, BlackCore::INetwork::ConnectionStatus newStatus)
{
Q_UNUSED(oldStatus);
if (newStatus == INetwork::Disconnected)
@@ -124,8 +113,9 @@ namespace BlackCore
}
}
void CAirspaceAnalyzer::ps_timeout()
void CAirspaceAnalyzer::onTimeout()
{
if (!this->isEnabled()) { return; }
this->analyzeAirspace();
this->watchdogCheckTimeouts();
}
@@ -139,12 +129,17 @@ namespace BlackCore
m_latestAircraftSnapshot = CAirspaceAircraftSnapshot();
}
void CAirspaceAnalyzer::ps_watchdogRemoveAircraftCallsign(const CCallsign &callsign)
void CAirspaceAnalyzer::cleanup()
{
m_timer.stop();
}
void CAirspaceAnalyzer::watchdogRemoveAircraftCallsign(const CCallsign &callsign)
{
m_aircraftCallsignTimestamps.remove(callsign);
}
void CAirspaceAnalyzer::ps_watchdogRemoveAtcCallsign(const CCallsign &callsign)
void CAirspaceAnalyzer::watchdogRemoveAtcCallsign(const CCallsign &callsign)
{
m_atcCallsignTimestamps.remove(callsign);
}
@@ -222,5 +217,4 @@ namespace BlackCore
emit airspaceAircraftSnapshot(snapshot);
}
} // ns

View File

@@ -72,9 +72,6 @@ namespace BlackCore
//! Render restrictions in simulator
void setSimulatorRenderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance);
//! Gracefully shut down, e.g. for thread safety
void gracefulShutdown();
//! Destructor
virtual ~CAirspaceAnalyzer();
@@ -92,34 +89,37 @@ namespace BlackCore
//! New aircraft snapshot
void airspaceAircraftSnapshot(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &snapshot);
private slots:
//! Remove callsign from watch list
void ps_watchdogRemoveAircraftCallsign(const BlackMisc::Aviation::CCallsign &callsign);
//! Remove callsign from watch list
void ps_watchdogRemoveAtcCallsign(const BlackMisc::Aviation::CCallsign &callsign);
//! Reset timestamp for callsign
void ps_watchdogTouchAircraftCallsign(const BlackMisc::Aviation::CAircraftSituation &situation, const BlackMisc::Aviation::CTransponder &transponder);
//! Reset timestamp for callsign
void ps_watchdogTouchAtcCallsign(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::PhysicalQuantities::CFrequency &frequency,
const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::PhysicalQuantities::CLength &range);
//! Connection status of network changed
void ps_onConnectionStatusChanged(BlackCore::INetwork::ConnectionStatus oldStatus, BlackCore::INetwork::ConnectionStatus newStatus);
//! Run a check
void ps_timeout();
protected:
//! \copydoc BlackMisc::CContinuousWorker::cleanup
virtual void cleanup() override;
private:
//! Remove callsign from watch list
void watchdogRemoveAircraftCallsign(const BlackMisc::Aviation::CCallsign &callsign);
//! Remove callsign from watch list
void watchdogRemoveAtcCallsign(const BlackMisc::Aviation::CCallsign &callsign);
//! Reset timestamp for callsign
void watchdogTouchAircraftCallsign(const BlackMisc::Aviation::CAircraftSituation &situation, const BlackMisc::Aviation::CTransponder &transponder);
//! Reset timestamp for callsign
void watchdogTouchAtcCallsign(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::PhysicalQuantities::CFrequency &frequency,
const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::PhysicalQuantities::CLength &range);
//! Connection status of network changed
void onConnectionStatusChanged(BlackCore::INetwork::ConnectionStatus oldStatus, BlackCore::INetwork::ConnectionStatus newStatus);
//! Run a check
void onTimeout();
//! Check for time outs
void watchdogCheckTimeouts();
//! Analyze the airspace
void analyzeAirspace();
QTimer m_timer {this}; //!< multi purpose timer for snapshots and watchdog
QTimer m_timer { this }; //!< multi purpose timer for snapshots and watchdog
// watchdog
CCallsignTimestampSet m_aircraftCallsignTimestamps; //!< for watchdog (pilots)
@@ -137,7 +137,6 @@ namespace BlackCore
mutable QReadWriteLock m_lockSnapshot; //!< lock snapshot
mutable QReadWriteLock m_lockRestrictions; //!< lock simulator restrictions
};
} // namespace
#endif

View File

@@ -523,7 +523,7 @@ namespace BlackCore
void CAirspaceMonitor::gracefulShutdown()
{
if (this->m_analyzer) { this->m_analyzer->gracefulShutdown(); }
if (this->m_analyzer) { this->m_analyzer->setEnabled(false); }
QObject::disconnect(this);
}