Ref T232 clear remote aircraft data once network disconnects

* blackconfig in .pro
* verify function to detect dangling states
* clear remote data when disconnected from network
* there was one problem that the data where not correctly cleaned up and hence new aircraft where not added again after a disconnect/reconnect from network
* it is not yet clear why data happens (dangling data), that is what the debugVerify function is for
This commit is contained in:
Klaus Basan
2018-01-22 05:07:00 +01:00
parent 5f7842163b
commit d118ea402f
13 changed files with 98 additions and 34 deletions

View File

@@ -115,6 +115,9 @@ namespace BlackCore
//! A weather grid, requested with requestWeatherGrid(), is received
void weatherGridReceived(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier);
//! Relevant simulator messages to be explicitly displayed
void driverMessages(const BlackMisc::CStatusMessageList &messages);
public slots:
//! Simulator info, currently loaded plugin
virtual BlackMisc::Simulation::CSimulatorPluginInfo getSimulatorPluginInfo() const = 0;

View File

@@ -299,6 +299,8 @@ namespace BlackCore
Q_ASSERT(c);
c = connect(simulator, &ISimulator::airspaceSnapshotHandled, this, &IContextSimulator::airspaceSnapshotHandled);
Q_ASSERT(c);
c = connect(simulator, &ISimulator::driverMessages, this, &IContextSimulator::driverMessages);
Q_ASSERT(c);
// log from context to simulator
c = connect(CLogHandler::instance(), &CLogHandler::localMessageLogged, this, &CContextSimulator::relayStatusMessageToSimulator);
@@ -504,11 +506,19 @@ namespace BlackCore
{
m_networkSessionId = this->getIContextNetwork()->getConnectedServer().getServerSessionId();
}
else if (!m_networkSessionId.isEmpty())
else if (INetwork::isDisconnectedStatus(to))
{
m_networkSessionId.clear();
m_aircraftMatcher.clearMatchingStatistics();
m_matchingMessages.clear();
// check in case the plugin has been unloaded
if (m_simulatorPlugin.second)
{
const CStatusMessageList verifyMessages = m_simulatorPlugin.second->debugVerifyStateAfterAllAircraftRemoved();
m_simulatorPlugin.second->clearAllRemoteAircraftData();
if (!verifyMessages.isEmpty()) { emit this->driverMessages(verifyMessages); }
}
}
}

View File

@@ -225,7 +225,7 @@ namespace BlackCore
QMap<BlackMisc::Aviation::CCallsign, BlackMisc::CStatusMessageList> m_matchingMessages;
BlackMisc::CSettingReadOnly<BlackMisc::Simulation::Settings::TSimulatorMessages> m_messageSettings { this }; //!< settings for messages
BlackMisc::CSettingReadOnly<Application::TEnabledSimulators> m_enabledSimulators { this, &CContextSimulator::changeEnabledSimulators };
QString m_networkSessionId; //! Network session of CServer, if not connected empty
QString m_networkSessionId; //! Network session of CServer::getServerSessionId, if not connected empty
bool m_initallyAddAircrafts = false;
bool m_enableMatchingMessages = true;
bool m_isWeatherActivated = false;

View File

@@ -74,6 +74,10 @@ namespace BlackCore
s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(),
"addingRemoteModelFailed", this, SIGNAL(addingRemoteModelFailed(BlackMisc::Simulation::CSimulatedAircraft, BlackMisc::CStatusMessage)));
Q_ASSERT(s);
s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(),
"driverMessages", this, SIGNAL(driverMessages(BlackMisc::CStatusMessageList)));
Q_ASSERT(s);
Q_UNUSED(s);
this->relayBaseClassSignals(serviceName, connection, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName());
}

View File

@@ -160,6 +160,13 @@ namespace BlackCore
//! Driver will be unloaded
virtual void unload() = 0;
//! Clear all aircraft related data
virtual void clearAllRemoteAircraftData() = 0;
//! Debug function to check state after all aircraft have been removed
//! \remarks only in local developer builds
virtual BlackMisc::CStatusMessageList debugVerifyStateAfterAllAircraftRemoved() const = 0;
//! Is overall (swift) application shutting down
virtual bool isShuttingDown() const = 0;
@@ -202,6 +209,9 @@ namespace BlackCore
//! An airspace snapshot was handled
void airspaceSnapshotHandled();
//! Relevant simulator messages to be explicitly displayed
void driverMessages(const BlackMisc::CStatusMessageList &messages);
protected:
//! Default constructor
ISimulator(QObject *parent = nullptr);

View File

@@ -23,6 +23,7 @@
#include "blackmisc/logmessage.h"
#include "blackmisc/statusmessage.h"
#include "blackmisc/threadutils.h"
#include "blackconfig/buildconfig.h"
#include <QDateTime>
#include <QString>
@@ -32,6 +33,7 @@
#include <QDesktopServices>
#include <functional>
using namespace BlackConfig;
using namespace BlackMisc;
using namespace BlackMisc::Geo;
using namespace BlackMisc::Aviation;
@@ -121,7 +123,7 @@ namespace BlackCore
this->callPhysicallyRemoveRemoteAircraft(callsign); return true;
}
// will be added with next snapshot ps_recalculateRenderedAircraft
// will be added with next snapshot onRecalculatedRenderedAircraft
return false;
}
@@ -384,7 +386,10 @@ namespace BlackCore
{
// a default implementation, but normally overridden by the sims
const CCallsignSet callsigns = this->getAircraftInRangeCallsigns();
return this->physicallyRemoveMultipleRemoteAircraft(callsigns);
const int r = this->physicallyRemoveMultipleRemoteAircraft(callsigns);
this->debugVerifyStateAfterAllAircraftRemoved();
this->clearAllRemoteAircraftData();
return r;
}
bool CSimulatorCommon::parseCommandLine(const QString &commandLine, const CIdentifier &originator)
@@ -490,7 +495,7 @@ namespace BlackCore
CSimpleCommandParser::registerCommand({".drv spline|linear <callsign>", "set spline/linear interpolator for one/all callsign(s)"});
}
void CSimulatorCommon::resetStatistics()
void CSimulatorCommon::resetAircraftStatistics()
{
m_statsPhysicallyAddedAircraft = 0;
m_statsPhysicallyRemovedAircraft = 0;
@@ -498,6 +503,15 @@ namespace BlackCore
m_statsSituationAdded = 0;
}
CStatusMessageList CSimulatorCommon::debugVerifyStateAfterAllAircraftRemoved() const
{
CStatusMessageList msgs;
if (!CBuildConfig::isLocalDeveloperDebugBuild()) { return msgs; }
if (!m_addAgainAircraftWhenRemoved.isEmpty()) { msgs.push_back(CStatusMessage(this).error("m_addAgainAircraftWhenRemoved not empty: '%1'") << m_addAgainAircraftWhenRemoved.getCallsignStrings(true).join(", ")); }
if (!m_hints.isEmpty()) { msgs.push_back(CStatusMessage(this).error("m_hints not empty: '%1'") << CCallsignSet(m_hints.keys()).getCallsignStrings(true).join(", ")); }
return msgs;
}
void CSimulatorCommon::oneSecondTimerTimeout()
{
this->blinkHighlightedAircraft();
@@ -578,16 +592,16 @@ namespace BlackCore
m_statsUpdateAircraftTimeTotalMs = 0;
m_blinkCycle = false;
m_highlightEndTimeMsEpoch = false;
this->resetStatistics();
this->clearAllAircraft();
this->clearAllRemoteAircraftData();
}
void CSimulatorCommon::clearAllAircraft()
void CSimulatorCommon::clearAllRemoteAircraftData()
{
m_addAgainAircraftWhenRemoved.clear();
m_highlightedAircraft.clear();
m_callsignsToBeRendered.clear();
m_hints.clear();
this->resetAircraftStatistics();
}
CAirportList CSimulatorCommon::getWebServiceAirports() const

View File

@@ -86,6 +86,8 @@ namespace BlackCore
virtual bool isShuttingDown() const override;
virtual int physicallyRemoveMultipleRemoteAircraft(const BlackMisc::Aviation::CCallsignSet &callsigns) override;
virtual int physicallyRemoveAllRemoteAircraft() override;
virtual void clearAllRemoteAircraftData() override;
virtual BlackMisc::CStatusMessageList debugVerifyStateAfterAllAircraftRemoved() const override;
//! \addtogroup swiftdotcommands
//! @{
@@ -100,14 +102,13 @@ namespace BlackCore
//! @}
//! \copydoc ISimulator::parseCommandLine
virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override;
// --------- ISimulator implementations ------------
//! Register help
static void registerHelp();
// --------- ISimulator implementations ------------
//! Reset the statistics counters
void resetStatistics();
void resetAircraftStatistics();
//! Counter added aircraft
int getStatisticsPhysicallyAddedAircraft() const { return m_statsPhysicallyAddedAircraft; }
@@ -161,12 +162,11 @@ namespace BlackCore
//! Max.airports in range
int maxAirportsInRange() const;
//! Reset state
//! Full reset of state
//! \remark reset as it was unloaded without unloading
//! \sa ISimulator::clearAllRemoteAircraftData
virtual void reset();
//! Clear all aircraft related data
virtual void clearAllAircraft();
//! Inject weather grid to simulator
virtual void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid) { Q_UNUSED(weatherGrid); }
@@ -223,9 +223,9 @@ namespace BlackCore
// setup for debugging, logs ..
BlackMisc::Simulation::CInterpolationAndRenderingSetup m_interpolationRenderingSetup; //!< logging, rendering etc.
// some optional functionality which can be used by the sims as needed
// some optional functionality which can be used by the simulators as needed
BlackMisc::Simulation::CSimulatedAircraftList m_addAgainAircraftWhenRemoved; //!< add this model again when removed, normally used to change model
QHash<BlackMisc::Aviation::CCallsign, BlackMisc::Simulation::CInterpolationHints> m_hints; //!< last ground elevation fetched
QHash<BlackMisc::Aviation::CCallsign, BlackMisc::Simulation::CInterpolationHints> m_hints; //!< hints for callsign, contains last ground elevation fetched
bool m_isWeatherActivated = false; //!< Is simulator weather activated?
BlackMisc::Geo::CCoordinateGeodetic m_lastWeatherPosition; //!< Own aircraft position at which weather was fetched and injected last