refs #395, allow to disconnect SIGNAL/SLOTS from provider and gracefully shutdown airspace and analyzer

This commit is contained in:
Klaus Basan
2015-05-07 20:19:06 +02:00
committed by Mathew Sutcliffe
parent f18cfed087
commit a6591cfe2c
16 changed files with 87 additions and 30 deletions

View File

@@ -29,10 +29,9 @@ namespace BlackCore
this->setObjectName("CAirspaceAnalyzer"); this->setObjectName("CAirspaceAnalyzer");
// all in new thread from here on // all in new thread from here on
m_timer = new QTimer(this); m_timer.setObjectName(this->objectName().append(":m_timer"));
m_timer->setObjectName(this->objectName().append(":m_timer")); m_timer.start(5000);
m_timer->start(5000); bool c = connect(&m_timer, &QTimer::timeout, this, &CAirspaceAnalyzer::ps_timeout);
bool c = connect(m_timer, &QTimer::timeout, this, &CAirspaceAnalyzer::ps_timeout);
Q_ASSERT(c); Q_ASSERT(c);
// disconnect // disconnect
@@ -72,6 +71,11 @@ namespace BlackCore
this->m_simulatorMaxRenderedBoundary = maxRenderedBoundary; this->m_simulatorMaxRenderedBoundary = maxRenderedBoundary;
} }
void CAirspaceAnalyzer::gracefulShutdown()
{
this->m_timer.stop();
}
void CAirspaceAnalyzer::ps_watchdogTouchAircraftCallsign(const CAircraftSituation &situation, const CTransponder &transponder) void CAirspaceAnalyzer::ps_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");
@@ -93,11 +97,11 @@ namespace BlackCore
if (newStatus == INetwork::Disconnected) if (newStatus == INetwork::Disconnected)
{ {
this->clear(); this->clear();
this->m_timer->stop(); this->m_timer.stop();
} }
else if (newStatus == INetwork::Connected) else if (newStatus == INetwork::Connected)
{ {
this->m_timer->start(); this->m_timer.start();
} }
} }
@@ -129,7 +133,7 @@ namespace BlackCore
qint64 currentTimeMsEpoch = QDateTime::currentMSecsSinceEpoch(); qint64 currentTimeMsEpoch = QDateTime::currentMSecsSinceEpoch();
qint64 callDiffMs = currentTimeMsEpoch - m_lastWatchdogCallMsSinceEpoch; qint64 callDiffMs = currentTimeMsEpoch - m_lastWatchdogCallMsSinceEpoch;
qint64 callThresholdMs = m_timer->interval() * 1.5; qint64 callThresholdMs = m_timer.interval() * 1.5;
m_lastWatchdogCallMsSinceEpoch = currentTimeMsEpoch; m_lastWatchdogCallMsSinceEpoch = currentTimeMsEpoch;
// this is a trick to not remove everything while debugging // this is a trick to not remove everything while debugging

View File

@@ -55,6 +55,9 @@ namespace BlackCore
//! Render restrictions in simulator //! Render restrictions in simulator
void setSimulatorRenderRestrictionsChanged(bool restricted, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance, const BlackMisc::PhysicalQuantities::CLength &maxRenderedBoundary); void setSimulatorRenderRestrictionsChanged(bool restricted, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance, const BlackMisc::PhysicalQuantities::CLength &maxRenderedBoundary);
//! Gracefully shut down, e.g. for thread safety
void gracefulShutdown();
public slots: public slots:
//! Clear //! Clear
void clear(); void clear();
@@ -96,7 +99,7 @@ namespace BlackCore
//! Analyze the airspace //! Analyze the airspace
void analyzeAirspace(); void analyzeAirspace();
QTimer *m_timer = nullptr; //!< 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)

View File

@@ -148,6 +148,12 @@ namespace BlackCore
return s1 && s2 && s3 && s4; return s1 && s2 && s3 && s4;
} }
bool CAirspaceMonitor::disconnectRemoteAircraftProviderSignals(QObject *receiver)
{
if (!receiver) { return false; }
return this->disconnect(receiver);
}
bool CAirspaceMonitor::updateAircraftEnabled(const CCallsign &callsign, bool enabledForRedering, const QString &originator) bool CAirspaceMonitor::updateAircraftEnabled(const CCallsign &callsign, bool enabledForRedering, const QString &originator)
{ {
Q_UNUSED(originator); Q_UNUSED(originator);
@@ -404,11 +410,24 @@ namespace BlackCore
void CAirspaceMonitor::enableFastPositionSending(bool enable) void CAirspaceMonitor::enableFastPositionSending(bool enable)
{ {
if (enable) m_interimPositionUpdateTimer.start(); if (enable)
else m_interimPositionUpdateTimer.stop(); {
m_interimPositionUpdateTimer.start();
}
else
{
m_interimPositionUpdateTimer.stop();
}
m_sendInterimPositions = enable; m_sendInterimPositions = enable;
} }
void CAirspaceMonitor::gracefulShutdown()
{
if (this->m_analyzer) { this->m_analyzer->gracefulShutdown(); }
QObject::disconnect(this);
this->enableFastPositionSending(false);
}
bool CAirspaceMonitor::isFastPositionSendingEnabled() const bool CAirspaceMonitor::isFastPositionSendingEnabled() const
{ {
return m_sendInterimPositions; return m_sendInterimPositions;

View File

@@ -154,6 +154,9 @@ namespace BlackCore
std::function<void(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &)> aircraftSnapshotSlot std::function<void(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &)> aircraftSnapshotSlot
) override; ) override;
//! \copydoc IRemoteAircraftProvider::disconnectRemoteAircraftProviderSignals
virtual bool disconnectRemoteAircraftProviderSignals(QObject *receiver) override;
//! Is interim position sending enabled? //! Is interim position sending enabled?
bool isFastPositionSendingEnabled() const; bool isFastPositionSendingEnabled() const;
@@ -163,6 +166,9 @@ namespace BlackCore
//! Analyzer //! Analyzer
CAirspaceAnalyzer *analyzer() const { return m_analyzer; } CAirspaceAnalyzer *analyzer() const { return m_analyzer; }
//! Gracefully shut down, e.g. for thread safety
void gracefulShutdown();
static const qint64 AircraftSituationsRemovedOffsetMs = 30 * 1000; //!< situations older than now - offset will be removed static const qint64 AircraftSituationsRemovedOffsetMs = 30 * 1000; //!< situations older than now - offset will be removed
static const qint64 AircraftPartsRemoveOffsetMs = 30 * 1000; //!< parts older than now - offset will be removed static const qint64 AircraftPartsRemoveOffsetMs = 30 * 1000; //!< parts older than now - offset will be removed

View File

@@ -196,7 +196,7 @@ namespace BlackCore
//! Connect to Network //! Connect to Network
//! \return messages generated during connecting //! \return messages generated during connecting
//! \see INetwork::LoginMode //! \see INetwork::LoginMode
virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, uint loginMode) = 0; virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, int loginMode) = 0;
//! Server which is connected, if not connected empty default object. //! Server which is connected, if not connected empty default object.
virtual BlackMisc::Network::CServer getConnectedServer() const = 0; virtual BlackMisc::Network::CServer getConnectedServer() const = 0;

View File

@@ -82,7 +82,7 @@ namespace BlackCore
} }
//! \copydoc IContextNetwork::connectToNetwork //! \copydoc IContextNetwork::connectToNetwork
virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, uint mode) override virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, int mode) override
{ {
Q_UNUSED(mode); Q_UNUSED(mode);
Q_UNUSED(server); Q_UNUSED(server);

View File

@@ -135,14 +135,21 @@ namespace BlackCore
return this->m_airspace->connectRemoteAircraftProviderSignals(situationSlot, partsSlot, removedAircraftSlot, aircraftSnapshotSlot); return this->m_airspace->connectRemoteAircraftProviderSignals(situationSlot, partsSlot, removedAircraftSlot, aircraftSnapshotSlot);
} }
bool CContextNetwork::disconnectRemoteAircraftProviderSignals(QObject *receiver)
{
Q_ASSERT(this->m_airspace);
return this->m_airspace->disconnectRemoteAircraftProviderSignals(receiver);
}
void CContextNetwork::gracefulShutdown() void CContextNetwork::gracefulShutdown()
{ {
if (this->m_vatsimBookingReader) { this->m_vatsimBookingReader->requestStop(); this->m_vatsimBookingReader->quit(); } if (this->m_vatsimBookingReader) { this->m_vatsimBookingReader->requestStop(); this->m_vatsimBookingReader->quit(); }
if (this->m_vatsimDataFileReader) { this->m_vatsimDataFileReader->requestStop(); this->m_vatsimDataFileReader->quit(); } if (this->m_vatsimDataFileReader) { this->m_vatsimDataFileReader->requestStop(); this->m_vatsimDataFileReader->quit(); }
if (this->isConnected()) { this->disconnectFromNetwork(); } if (this->isConnected()) { this->disconnectFromNetwork(); }
if (this->m_airspace) { this->m_airspace->gracefulShutdown(); }
} }
CStatusMessage CContextNetwork::connectToNetwork(const CServer &server, uint loginMode) CStatusMessage CContextNetwork::connectToNetwork(const CServer &server, int loginMode)
{ {
if (this->isDebugEnabled()) {CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } if (this->isDebugEnabled()) {CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
QString msg; QString msg;

View File

@@ -80,6 +80,10 @@ namespace BlackCore
std::function<void(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &)> aircraftSnapshotSlot std::function<void(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &)> aircraftSnapshotSlot
) override; ) override;
//! \copydoc IRemoteAircraftProvider::disconnectRemoteAircraftProviderSignals
//! \ingroup remoteaircraftprovider
virtual bool disconnectRemoteAircraftProviderSignals(QObject *receiver) override;
//! \copydoc IRemoteAircraftProvider::updateAircraftRendered //! \copydoc IRemoteAircraftProvider::updateAircraftRendered
//! \ingroup remoteaircraftprovider //! \ingroup remoteaircraftprovider
virtual bool updateAircraftRendered(const BlackMisc::Aviation::CCallsign &callsign, bool rendered, const QString &originator) override; virtual bool updateAircraftRendered(const BlackMisc::Aviation::CCallsign &callsign, bool rendered, const QString &originator) override;
@@ -133,7 +137,7 @@ namespace BlackCore
virtual BlackMisc::Aviation::CAtcStation getOnlineStationForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override; virtual BlackMisc::Aviation::CAtcStation getOnlineStationForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override;
//! \copydoc IContextNetwork::connectToNetwork() //! \copydoc IContextNetwork::connectToNetwork()
virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, uint mode) override; virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, int mode) override;
//! \copydoc IContextNetwork::getConnectedServer //! \copydoc IContextNetwork::getConnectedServer
virtual BlackMisc::Network::CServer getConnectedServer() const override; virtual BlackMisc::Network::CServer getConnectedServer() const override;

View File

@@ -228,7 +228,7 @@ namespace BlackCore
this->m_dBusInterface->callDBus(QLatin1Literal("testAddAircraftParts"), parts, incremental); this->m_dBusInterface->callDBus(QLatin1Literal("testAddAircraftParts"), parts, incremental);
} }
CStatusMessage CContextNetworkProxy::connectToNetwork(const CServer &server, uint loginMode) CStatusMessage CContextNetworkProxy::connectToNetwork(const CServer &server, int loginMode)
{ {
return this->m_dBusInterface->callDBusRet<BlackMisc::CStatusMessage>(QLatin1Literal("connectToNetwork"), server, loginMode); return this->m_dBusInterface->callDBusRet<BlackMisc::CStatusMessage>(QLatin1Literal("connectToNetwork"), server, loginMode);
} }

View File

@@ -76,7 +76,7 @@ namespace BlackCore
virtual BlackMisc::Aviation::CAtcStation getOnlineStationForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override; virtual BlackMisc::Aviation::CAtcStation getOnlineStationForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override;
//! \copydoc IContextNetwork::connectToNetwork //! \copydoc IContextNetwork::connectToNetwork
virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, uint mode) override; virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, int mode) override;
//! \copydoc IContextNetwork::disconnectFromNetwork() //! \copydoc IContextNetwork::disconnectFromNetwork()
virtual BlackMisc::CStatusMessage disconnectFromNetwork() override; virtual BlackMisc::CStatusMessage disconnectFromNetwork() override;

View File

@@ -532,21 +532,22 @@ namespace BlackCore
// depending on shutdown order, network might already have been deleted // depending on shutdown order, network might already have been deleted
emit simulatorPluginChanged(CSimulatorPluginInfo()); emit simulatorPluginChanged(CSimulatorPluginInfo());
IContextNetwork *networkContext = this->getIContextNetwork(); Q_ASSERT(this->getIContextNetwork());
Q_ASSERT(networkContext); Q_ASSERT(this->getIContextNetwork()->isLocalObject());
Q_ASSERT(networkContext->isLocalObject());
Q_UNUSED(networkContext);
Q_ASSERT(m_simulatorPlugin->simulator); Q_ASSERT(m_simulatorPlugin->simulator);
// disconnect from simulator
if (m_simulatorPlugin->simulator->isConnected())
{
m_simulatorPlugin->simulator->disconnectFrom();
}
// disconnect signals
this->getRuntime()->getCContextNetwork()->disconnectRemoteAircraftProviderSignals(m_simulatorPlugin->simulator);
m_simulatorPlugin->simulator->disconnect(); m_simulatorPlugin->simulator->disconnect();
CLogHandler::instance()->disconnect(m_simulatorPlugin->simulator); CLogHandler::instance()->disconnect(m_simulatorPlugin->simulator);
this->disconnect(m_simulatorPlugin->simulator); this->disconnect(m_simulatorPlugin->simulator);
if (m_simulatorPlugin->simulator->isConnected())
{
m_simulatorPlugin->simulator->disconnectFrom(); // disconnect from simulator
}
m_simulatorPlugin->simulator->deleteLater(); m_simulatorPlugin->simulator->deleteLater();
m_simulatorPlugin->simulator = nullptr; m_simulatorPlugin->simulator = nullptr;
m_simulatorPlugin = nullptr; m_simulatorPlugin = nullptr;

View File

@@ -31,10 +31,9 @@ namespace BlackCore
m_simulatorPluginInfo(info) m_simulatorPluginInfo(info)
{ {
this->setObjectName(info.getIdentifier()); this->setObjectName(info.getIdentifier());
this->m_oneSecondTimer = new QTimer(this); this->m_oneSecondTimer.setObjectName(this->objectName().append(":m_oneSecondTimer"));
this->m_oneSecondTimer->setObjectName(this->objectName().append(":m_oneSecondTimer")); connect(&m_oneSecondTimer, &QTimer::timeout, this, &CSimulatorCommon::ps_oneSecondTimer);
connect(this->m_oneSecondTimer, &QTimer::timeout, this, &CSimulatorCommon::ps_oneSecondTimer); this->m_oneSecondTimer.start(1000);
this->m_oneSecondTimer->start(1000);
// provider signals // provider signals
bool c = remoteAircraftProvider->connectRemoteAircraftProviderSignals( bool c = remoteAircraftProvider->connectRemoteAircraftProviderSignals(

View File

@@ -135,7 +135,7 @@ namespace BlackCore
IInterpolator *m_interpolator = nullptr; //!< interpolator instance IInterpolator *m_interpolator = nullptr; //!< interpolator instance
qint64 m_highlightEndTimeMsEpoch = 0; //!< end highlighting qint64 m_highlightEndTimeMsEpoch = 0; //!< end highlighting
int m_timerCounter = 0; //!< allows to calculate n seconds int m_timerCounter = 0; //!< allows to calculate n seconds
QTimer *m_oneSecondTimer = nullptr; //!< timer QTimer m_oneSecondTimer{this}; //!< timer
BlackMisc::Simulation::CSimulatorPluginInfo m_simulatorPluginInfo; //!< info object BlackMisc::Simulation::CSimulatorPluginInfo m_simulatorPluginInfo; //!< info object
BlackMisc::Simulation::CSimulatorSetup m_simulatorSetup; //!< setup object BlackMisc::Simulation::CSimulatorSetup m_simulatorSetup; //!< setup object
BlackMisc::Simulation::CSimulatedAircraftList m_highlightedAircraft; //!< all other aircraft are to be ignored BlackMisc::Simulation::CSimulatedAircraftList m_highlightedAircraft; //!< all other aircraft are to be ignored

View File

@@ -27,6 +27,7 @@ namespace BlackMisc
//! Direct thread safe in memory access to remote aircraft //! Direct thread safe in memory access to remote aircraft
//! \note Can not be derived from QObject (as for the signals), as this would create multiple //! \note Can not be derived from QObject (as for the signals), as this would create multiple
//! inheritance. Hence Q_DECLARE_INTERFACE is used. //! inheritance. Hence Q_DECLARE_INTERFACE is used.
//! \ingroup remoteaircraftprovider
class BLACKMISC_EXPORT IRemoteAircraftProvider class BLACKMISC_EXPORT IRemoteAircraftProvider
{ {
public: public:
@@ -106,6 +107,10 @@ namespace BlackMisc
std::function<void(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &)> aircraftSnapshot std::function<void(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &)> aircraftSnapshot
) = 0; ) = 0;
//! Disconnect signals from receiver. As the interface is no QObject, slots can not be connected directly.
virtual bool disconnectRemoteAircraftProviderSignals(
QObject *receiver
) = 0;
}; };
//! Class which can be directly used to access an \sa IRemoteAircraftProvider object //! Class which can be directly used to access an \sa IRemoteAircraftProvider object

View File

@@ -80,6 +80,12 @@ namespace BlackMisc
return s1 && s2 && s3 && s4; return s1 && s2 && s3 && s4;
} }
bool CRemoteAircraftProviderDummy::disconnectRemoteAircraftProviderSignals(QObject *receiver)
{
if (!receiver) { return false; }
return this->disconnect(receiver);
}
bool CRemoteAircraftProviderDummy::updateAircraftEnabled(const CCallsign &callsign, bool enabledForRendering, const QString &originator) bool CRemoteAircraftProviderDummy::updateAircraftEnabled(const CCallsign &callsign, bool enabledForRendering, const QString &originator)
{ {
Q_UNUSED(originator); Q_UNUSED(originator);

View File

@@ -67,6 +67,9 @@ namespace BlackMisc
std::function<void(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &)> aircraftSnapshotSlot std::function<void(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &)> aircraftSnapshotSlot
) override; ) override;
//! \copydoc IRemoteAircraftProvider::disconnectRemoteAircraftProviderSignals
virtual bool disconnectRemoteAircraftProviderSignals(QObject *receiver) override;
//! \copydoc IRemoteAircraftProvider::updateAircraftEnabled //! \copydoc IRemoteAircraftProvider::updateAircraftEnabled
virtual bool updateAircraftEnabled(const BlackMisc::Aviation::CCallsign &callsign, bool enabledForRendering, const QString &originator) override; virtual bool updateAircraftEnabled(const BlackMisc::Aviation::CCallsign &callsign, bool enabledForRendering, const QString &originator) override;