mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-27 19:25:49 +08:00
Ref T105, adjusted airspace analyzer
* removed private slots * gracefulShutdown -> setEnabled
This commit is contained in:
committed by
Mathew Sutcliffe
parent
4e4d33a755
commit
cd15bdc506
@@ -37,30 +37,28 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
Q_ASSERT_X(network, Q_FUNC_INFO, "Network object required to connect");
|
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
|
// all in new thread from here on
|
||||||
|
this->setObjectName(getName());
|
||||||
m_timer.setObjectName(this->objectName().append(":m_timer"));
|
m_timer.setObjectName(this->objectName().append(":m_timer"));
|
||||||
m_timer.start(7500);
|
m_timer.start(7500);
|
||||||
m_lastWatchdogCallMsSinceEpoch = QDateTime::currentMSecsSinceEpoch();
|
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);
|
Q_ASSERT(c);
|
||||||
|
|
||||||
// disconnect
|
// disconnect
|
||||||
c = connect(network, &INetwork::pilotDisconnected, this, &CAirspaceAnalyzer::ps_watchdogRemoveAircraftCallsign);
|
c = connect(network, &INetwork::pilotDisconnected, this, &CAirspaceAnalyzer::watchdogRemoveAircraftCallsign);
|
||||||
Q_ASSERT(c);
|
Q_ASSERT(c);
|
||||||
c = connect(network, &INetwork::atcDisconnected, this, &CAirspaceAnalyzer::ps_watchdogRemoveAtcCallsign);
|
c = connect(network, &INetwork::atcDisconnected, this, &CAirspaceAnalyzer::watchdogRemoveAtcCallsign);
|
||||||
Q_ASSERT(c);
|
Q_ASSERT(c);
|
||||||
|
|
||||||
// update
|
// update
|
||||||
c = connect(network, &INetwork::aircraftPositionUpdate, this, &CAirspaceAnalyzer::ps_watchdogTouchAircraftCallsign);
|
c = connect(network, &INetwork::aircraftPositionUpdate, this, &CAirspaceAnalyzer::watchdogTouchAircraftCallsign);
|
||||||
Q_ASSERT(c);
|
Q_ASSERT(c);
|
||||||
c = connect(network, &INetwork::atcPositionUpdate, this, &CAirspaceAnalyzer::ps_watchdogTouchAtcCallsign);
|
c = connect(network, &INetwork::atcPositionUpdate, this, &CAirspaceAnalyzer::watchdogTouchAtcCallsign);
|
||||||
Q_ASSERT(c);
|
Q_ASSERT(c);
|
||||||
|
|
||||||
// network
|
// network
|
||||||
c = connect(network, &INetwork::connectionStatusChanged, this, &CAirspaceAnalyzer::ps_onConnectionStatusChanged);
|
c = connect(network, &INetwork::connectionStatusChanged, this, &CAirspaceAnalyzer::onConnectionStatusChanged);
|
||||||
Q_ASSERT(c);
|
Q_ASSERT(c);
|
||||||
Q_UNUSED(c);
|
Q_UNUSED(c);
|
||||||
|
|
||||||
@@ -83,26 +81,17 @@ namespace BlackCore
|
|||||||
this->m_simulatorMaxRenderedDistance = maxRenderedDistance;
|
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()
|
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_ASSERT_X(!situation.getCallsign().isEmpty(), Q_FUNC_INFO, "No callsign in situaton");
|
||||||
Q_UNUSED(transponder);
|
Q_UNUSED(transponder);
|
||||||
m_aircraftCallsignTimestamps[situation.getCallsign()] = QDateTime::currentMSecsSinceEpoch();
|
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(frequency);
|
||||||
Q_UNUSED(position);
|
Q_UNUSED(position);
|
||||||
@@ -110,7 +99,7 @@ namespace BlackCore
|
|||||||
m_atcCallsignTimestamps[callsign] = QDateTime::currentMSecsSinceEpoch();
|
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);
|
Q_UNUSED(oldStatus);
|
||||||
if (newStatus == INetwork::Disconnected)
|
if (newStatus == INetwork::Disconnected)
|
||||||
@@ -124,8 +113,9 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAirspaceAnalyzer::ps_timeout()
|
void CAirspaceAnalyzer::onTimeout()
|
||||||
{
|
{
|
||||||
|
if (!this->isEnabled()) { return; }
|
||||||
this->analyzeAirspace();
|
this->analyzeAirspace();
|
||||||
this->watchdogCheckTimeouts();
|
this->watchdogCheckTimeouts();
|
||||||
}
|
}
|
||||||
@@ -139,12 +129,17 @@ namespace BlackCore
|
|||||||
m_latestAircraftSnapshot = CAirspaceAircraftSnapshot();
|
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);
|
m_aircraftCallsignTimestamps.remove(callsign);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAirspaceAnalyzer::ps_watchdogRemoveAtcCallsign(const CCallsign &callsign)
|
void CAirspaceAnalyzer::watchdogRemoveAtcCallsign(const CCallsign &callsign)
|
||||||
{
|
{
|
||||||
m_atcCallsignTimestamps.remove(callsign);
|
m_atcCallsignTimestamps.remove(callsign);
|
||||||
}
|
}
|
||||||
@@ -222,5 +217,4 @@ namespace BlackCore
|
|||||||
|
|
||||||
emit airspaceAircraftSnapshot(snapshot);
|
emit airspaceAircraftSnapshot(snapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -72,9 +72,6 @@ namespace BlackCore
|
|||||||
//! Render restrictions in simulator
|
//! Render restrictions in simulator
|
||||||
void setSimulatorRenderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance);
|
void setSimulatorRenderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance);
|
||||||
|
|
||||||
//! Gracefully shut down, e.g. for thread safety
|
|
||||||
void gracefulShutdown();
|
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
virtual ~CAirspaceAnalyzer();
|
virtual ~CAirspaceAnalyzer();
|
||||||
|
|
||||||
@@ -92,34 +89,37 @@ namespace BlackCore
|
|||||||
//! New aircraft snapshot
|
//! New aircraft snapshot
|
||||||
void airspaceAircraftSnapshot(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &snapshot);
|
void airspaceAircraftSnapshot(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &snapshot);
|
||||||
|
|
||||||
private slots:
|
protected:
|
||||||
//! Remove callsign from watch list
|
//! \copydoc BlackMisc::CContinuousWorker::cleanup
|
||||||
void ps_watchdogRemoveAircraftCallsign(const BlackMisc::Aviation::CCallsign &callsign);
|
virtual void cleanup() override;
|
||||||
|
|
||||||
//! 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();
|
|
||||||
|
|
||||||
private:
|
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
|
//! Check for time outs
|
||||||
void watchdogCheckTimeouts();
|
void watchdogCheckTimeouts();
|
||||||
|
|
||||||
//! Analyze the airspace
|
//! Analyze the airspace
|
||||||
void analyzeAirspace();
|
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
|
// watchdog
|
||||||
CCallsignTimestampSet m_aircraftCallsignTimestamps; //!< for watchdog (pilots)
|
CCallsignTimestampSet m_aircraftCallsignTimestamps; //!< for watchdog (pilots)
|
||||||
@@ -137,7 +137,6 @@ namespace BlackCore
|
|||||||
mutable QReadWriteLock m_lockSnapshot; //!< lock snapshot
|
mutable QReadWriteLock m_lockSnapshot; //!< lock snapshot
|
||||||
mutable QReadWriteLock m_lockRestrictions; //!< lock simulator restrictions
|
mutable QReadWriteLock m_lockRestrictions; //!< lock simulator restrictions
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -523,7 +523,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
void CAirspaceMonitor::gracefulShutdown()
|
void CAirspaceMonitor::gracefulShutdown()
|
||||||
{
|
{
|
||||||
if (this->m_analyzer) { this->m_analyzer->gracefulShutdown(); }
|
if (this->m_analyzer) { this->m_analyzer->setEnabled(false); }
|
||||||
QObject::disconnect(this);
|
QObject::disconnect(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user