From a6b7b1065153c8820204b61c7302707d50d5fed6 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 15 Nov 2018 03:50:38 +0100 Subject: [PATCH] Ref T420, signal when simulator no longer is vital --- src/blackcore/context/contextsimulator.cpp | 8 ++++++++ src/blackcore/context/contextsimulator.h | 6 ++++++ src/blackcore/context/contextsimulatorimpl.cpp | 9 +++++++++ src/blackcore/context/contextsimulatorimpl.h | 5 +++-- src/blackcore/context/contextsimulatorproxy.cpp | 3 +++ 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/blackcore/context/contextsimulator.cpp b/src/blackcore/context/contextsimulator.cpp index 30eee8b57..7e3c7fc14 100644 --- a/src/blackcore/context/contextsimulator.cpp +++ b/src/blackcore/context/contextsimulator.cpp @@ -71,5 +71,13 @@ namespace BlackCore if (!isSimulatorAvailable() || !getSimulatorStatusEnum().testFlag(ISimulator::Simulating)) { return false; } return true; } + + bool IContextSimulator::isSimulatorVital() const + { + if (!isSimulatorAvailable()) { return false; } // we cannot be vital + if (isSimulatorSimulating()) { return true; } // we are vital + if (getSimulatorStatusEnum().testFlag(ISimulator::Paused)) { return true; } + return false; + } } // namespace } // namespace diff --git a/src/blackcore/context/contextsimulator.h b/src/blackcore/context/contextsimulator.h index a605f7987..c4bad6c27 100644 --- a/src/blackcore/context/contextsimulator.h +++ b/src/blackcore/context/contextsimulator.h @@ -92,6 +92,9 @@ namespace BlackCore //! Simulator plugin loaded / unloaded (default info) void simulatorPluginChanged(const BlackMisc::Simulation::CSimulatorPluginInfo &info); + //! A formerly vital driver is no loner vital + void vitalityLost(); + //! Render restrictions have been changed void renderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance); @@ -224,6 +227,9 @@ namespace BlackCore //! Is available simulator simulating? Returns false if no simulator is available bool isSimulatorSimulating() const; + //! Used to decide if simulator is still alive, used for crash detection + bool isSimulatorVital() const; + //! Icon representing the model virtual BlackMisc::CPixmap iconForModel(const QString &modelString) const = 0; diff --git a/src/blackcore/context/contextsimulatorimpl.cpp b/src/blackcore/context/contextsimulatorimpl.cpp index ab22f9226..c5e51eeb7 100644 --- a/src/blackcore/context/contextsimulatorimpl.cpp +++ b/src/blackcore/context/contextsimulatorimpl.cpp @@ -412,6 +412,7 @@ namespace BlackCore // Once the simulator signaled it is ready to simulate, add all known aircraft m_initallyAddAircraft = true; + m_wasSimulating = false; m_matchingMessages.clear(); // try to connect to simulator @@ -525,6 +526,9 @@ namespace BlackCore simulator->deleteLater(); emit this->simulatorPluginChanged(CSimulatorPluginInfo()); } + + if (m_wasSimulating) { emit this->vitalityLost(); } + m_wasSimulating = false; } } @@ -580,6 +584,7 @@ namespace BlackCore void CContextSimulator::onSimulatorStatusChanged(ISimulator::SimulatorStatus status) { + m_wasSimulating = m_wasSimulating || status.testFlag(ISimulator::Simulating); if (m_initallyAddAircraft && status.testFlag(ISimulator::Simulating)) { // use network to initally add aircraft @@ -596,12 +601,16 @@ namespace BlackCore } m_initallyAddAircraft = false; } + if (!status.testFlag(ISimulator::Connected)) { // we got disconnected, plugin no longer needed this->updateMarkAllAsNotRendered(); // without plugin nothing can be rendered this->unloadSimulatorPlugin(); this->restoreSimulatorPlugins(); + + if (m_wasSimulating) { emit this->vitalityLost(); } + m_wasSimulating = false; } emit this->simulatorStatusChanged(status); diff --git a/src/blackcore/context/contextsimulatorimpl.h b/src/blackcore/context/contextsimulatorimpl.h index e1f47ea1d..ff5cd0baf 100644 --- a/src/blackcore/context/contextsimulatorimpl.h +++ b/src/blackcore/context/contextsimulatorimpl.h @@ -246,9 +246,10 @@ namespace BlackCore CAircraftMatcher m_aircraftMatcher { this }; //!< model matcher QMap m_matchingMessages; //!< all matching log messages per callsign - bool m_initallyAddAircraft = false; + bool m_wasSimulating = false; + bool m_initallyAddAircraft = false; bool m_enableMatchingMessages = true; - bool m_isWeatherActivated = false; + bool m_isWeatherActivated = false; QString m_networkSessionId; //!< Network session of CServer::getServerSessionId, if not connected empty (for statistics, ..) diff --git a/src/blackcore/context/contextsimulatorproxy.cpp b/src/blackcore/context/contextsimulatorproxy.cpp index 25a0cfd71..d326160ef 100644 --- a/src/blackcore/context/contextsimulatorproxy.cpp +++ b/src/blackcore/context/contextsimulatorproxy.cpp @@ -71,6 +71,9 @@ namespace BlackCore s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), "simulatorPluginChanged", this, SIGNAL(simulatorPluginChanged(BlackMisc::Simulation::CSimulatorPluginInfo))); Q_ASSERT(s); + s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), + "vitalityLost", this, SIGNAL(vitalityLost())); + Q_ASSERT(s); s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), "airspaceSnapshotHandled", this, SIGNAL(airspaceSnapshotHandled())); Q_ASSERT(s);