Ref T420, signal when simulator no longer is vital

This commit is contained in:
Klaus Basan
2018-11-15 03:50:38 +01:00
parent b452cd7530
commit a6b7b10651
5 changed files with 29 additions and 2 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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);

View File

@@ -246,9 +246,10 @@ namespace BlackCore
CAircraftMatcher m_aircraftMatcher { this }; //!< model matcher
QMap<BlackMisc::Aviation::CCallsign, BlackMisc::CStatusMessageList> 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, ..)

View File

@@ -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);