mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +08:00
Ref T515, implemented added failover strategy and try again <n> times
This commit is contained in:
committed by
Mat Sutcliffe
parent
6470c61d0a
commit
2f450ec9c5
@@ -451,6 +451,7 @@ namespace BlackCore
|
||||
m_initallyAddAircraft = true;
|
||||
m_wasSimulating = false;
|
||||
m_matchingMessages.clear();
|
||||
m_failoverAddingCounts.clear();
|
||||
|
||||
// try to connect to simulator
|
||||
const bool connected = simulator->connectTo();
|
||||
@@ -623,6 +624,7 @@ namespace BlackCore
|
||||
{
|
||||
if (!this->isSimulatorAvailable()) { return; }
|
||||
m_simulatorPlugin.second->logicallyRemoveRemoteAircraft(callsign);
|
||||
m_failoverAddingCounts.remove(callsign);
|
||||
}
|
||||
|
||||
void CContextSimulator::onSimulatorStatusChanged(ISimulator::SimulatorStatus status)
|
||||
@@ -703,6 +705,7 @@ namespace BlackCore
|
||||
m_networkSessionId.clear();
|
||||
m_aircraftMatcher.clearMatchingStatistics();
|
||||
m_matchingMessages.clear();
|
||||
m_failoverAddingCounts.clear();
|
||||
|
||||
if (m_simulatorPlugin.second) // check in case the plugin has been unloaded
|
||||
{
|
||||
@@ -712,11 +715,35 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
void CContextSimulator::onAddingRemoteAircraftFailed(const CSimulatedAircraft &remoteAircraft, bool disabled, const CStatusMessage &message)
|
||||
void CContextSimulator::onAddingRemoteAircraftFailed(const CSimulatedAircraft &remoteAircraft, bool disabled, bool requestFailover, const CStatusMessage &message)
|
||||
{
|
||||
if (!this->isSimulatorAvailable()) { return; }
|
||||
if (disabled) { m_aircraftMatcher.addingRemoteModelFailed(remoteAircraft); }
|
||||
emit this->addingRemoteModelFailed(remoteAircraft, disabled, message);
|
||||
|
||||
const CCallsign cs = remoteAircraft.getCallsign();
|
||||
if (cs.isEmpty()) { return; }
|
||||
|
||||
bool failover = requestFailover;
|
||||
if (requestFailover)
|
||||
{
|
||||
const CAircraftMatcherSetup setup = m_aircraftMatcher.getSetup();
|
||||
if (setup.doModelAddFailover())
|
||||
{
|
||||
const CCallsign cs = remoteAircraft.getCallsign();
|
||||
const int trial = m_failoverAddingCounts.value(cs, 0);
|
||||
if (trial < MaxModelAddedFailoverTrials)
|
||||
{
|
||||
m_failoverAddingCounts[cs] = trial + 1;
|
||||
this->doMatchingAgain(cs); // has its own single shot logic
|
||||
}
|
||||
else
|
||||
{
|
||||
failover = false;
|
||||
CLogMessage(this).warning(u"Model for '%1' failed adding, tried %2 times to resolve, giving up") << cs.toQString(true) << (trial + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
emit this->addingRemoteModelFailed(remoteAircraft, disabled, failover, message);
|
||||
}
|
||||
|
||||
void CContextSimulator::xCtxUpdateSimulatorCockpitFromContext(const CSimulatedAircraft &ownAircraft, const CIdentifier &originator)
|
||||
@@ -992,6 +1019,7 @@ namespace BlackCore
|
||||
if (!aircraft.hasCallsign()) { return; } // no longer valid
|
||||
CSimulatedAircraft resetAircraft(aircraft);
|
||||
resetAircraft.resetToNetworkModel();
|
||||
resetAircraft.setEnabled(true);
|
||||
this->xCtxAddedRemoteAircraftReadyForModelMatching(resetAircraft);
|
||||
});
|
||||
return true;
|
||||
|
||||
@@ -170,7 +170,8 @@ namespace BlackCore
|
||||
CContextSimulator *registerWithDBus(BlackMisc::CDBusServer *server);
|
||||
|
||||
private:
|
||||
static constexpr int MatchingLogMaxModelSetSize = 125; //!< default value for switching matching log on
|
||||
static constexpr int MatchingLogMaxModelSetSize = 250; //!< default value for switching matching log on
|
||||
static constexpr int MaxModelAddedFailoverTrials = 3; //!< if model cannot be added, try again max <n> times
|
||||
|
||||
// ------------ slots connected with network or other contexts ---------
|
||||
//! \ingroup crosscontextfunction
|
||||
@@ -215,7 +216,7 @@ namespace BlackCore
|
||||
void onOwnSimulatorModelChanged(const BlackMisc::Simulation::CAircraftModel &model);
|
||||
|
||||
//! Failed adding remote aircraft
|
||||
void onAddingRemoteAircraftFailed(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft, bool disabled, const BlackMisc::CStatusMessage &message);
|
||||
void onAddingRemoteAircraftFailed(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft, bool disabled, bool requestFailover, const BlackMisc::CStatusMessage &message);
|
||||
|
||||
//! Relay status message to simulator under consideration of settings
|
||||
void relayStatusMessageToSimulator(const BlackMisc::CStatusMessage &message);
|
||||
@@ -255,6 +256,7 @@ namespace BlackCore
|
||||
|
||||
QPair<BlackMisc::Simulation::CSimulatorPluginInfo, QPointer<ISimulator>> m_simulatorPlugin; //!< Currently loaded simulator plugin
|
||||
QMap<BlackMisc::Aviation::CCallsign, BlackMisc::CStatusMessageList> m_matchingMessages; //!< all matching log messages per callsign
|
||||
QMap<BlackMisc::Aviation::CCallsign, int> m_failoverAddingCounts;
|
||||
CPluginManagerSimulator *m_plugins = nullptr; //!< plugin manager
|
||||
BlackMisc::CRegularThread m_listenersThread; //!< waiting for plugin
|
||||
CWeatherManager m_weatherManager { this }; //!< weather management
|
||||
|
||||
Reference in New Issue
Block a user