From 88c656ee61e06cf0857b9fad6b05d8df6bdd8a62 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 28 Jun 2014 02:26:12 +0200 Subject: [PATCH] refs #273, runtime context * added send status message for convenience * order in graceful shutdown --- src/blackcore/context_runtime.cpp | 68 ++++++++++++++++--------------- src/blackcore/context_runtime.h | 11 +++++ 2 files changed, 46 insertions(+), 33 deletions(-) diff --git a/src/blackcore/context_runtime.cpp b/src/blackcore/context_runtime.cpp index 10e16459b..30c6e39e3 100644 --- a/src/blackcore/context_runtime.cpp +++ b/src/blackcore/context_runtime.cpp @@ -444,18 +444,11 @@ namespace BlackCore Q_ASSERT(c); } - // connect local simulator and settings + // connect local simulator and settings and load plugin if (this->m_contextSettings) { connect(this->m_contextSettings, &IContextSettings::changedSettings, this->m_contextSimulator, &IContextSimulator::settingsChanged); - if (this->m_contextSimulator->loadSimulatorPluginFromSettings()) - { - qDebug() << "Simulator driver loaded"; - } - else - { - qWarning() << "No simulator driver loaded"; - } + this->m_contextSimulator->loadSimulatorPluginFromSettings(); } } @@ -486,26 +479,12 @@ namespace BlackCore if (this->m_dbusServer) this->m_dbusServer->unregisterAllObjects(); // handle contexts - if (this->getIContextApplication()) - { - disconnect(this->getIContextApplication()); - this->getIContextApplication()->setOutputRedirectionLevel(IContextApplication::RedirectNone); - this->getIContextApplication()->setStreamingForRedirectedOutputLevel(IContextApplication::RedirectNone); - IContextApplication::resetOutputRedirection(); - this->getIContextApplication()->deleteLater(); - } - - if (this->getIContextOwnAircraft()) - { - disconnect(this->getIContextOwnAircraft()); - this->getIContextOwnAircraft()->deleteLater(); - } - if (this->getIContextSimulator()) { - // TODO: disconnect from simulator disconnect(this->getIContextSimulator()); + this->getIContextSimulator()->disconnectFrom(); this->getIContextSimulator()->deleteLater(); + this->m_contextSimulator = nullptr; } // log off from network, if connected @@ -514,28 +493,51 @@ namespace BlackCore disconnect(this->getIContextNetwork()); this->getIContextNetwork()->disconnectFromNetwork(); this->getIContextNetwork()->deleteLater(); + this->m_contextNetwork = nullptr; } if (this->getIContextAudio()) { disconnect(this->getIContextAudio()); this->getIContextAudio()->deleteLater(); + this->m_contextAudio = nullptr; + } + + if (this->getIContextOwnAircraft()) + { + disconnect(this->getIContextOwnAircraft()); + this->getIContextOwnAircraft()->deleteLater(); + this->m_contextOwnAircraft = nullptr; } if (this->getIContextSettings()) { disconnect(this->getIContextSettings()); this->getIContextSettings()->deleteLater(); + this->m_contextSettings = nullptr; } - // mark contexts as invalid - // objects are already scheduled for deletion - this->m_contextApplication = nullptr; - this->m_contextAudio = nullptr; - this->m_contextNetwork = nullptr; - this->m_contextOwnAircraft = nullptr; - this->m_contextSettings = nullptr; - this->m_contextSimulator = nullptr; + if (this->getIContextApplication()) + { + disconnect(this->getIContextApplication()); + this->getIContextApplication()->setOutputRedirectionLevel(IContextApplication::RedirectNone); + this->getIContextApplication()->setStreamingForRedirectedOutputLevel(IContextApplication::RedirectNone); + IContextApplication::resetOutputRedirection(); + this->getIContextApplication()->deleteLater(); + this->m_contextApplication = nullptr; + } + } + + void CRuntime::sendStatusMessage(const CStatusMessage &message) + { + if (!this->getIContextApplication()) return; + this->getIContextApplication()->sendStatusMessage(message); + } + + void CRuntime::sendStatusMessages(const CStatusMessageList &messages) + { + if (!this->getIContextApplication()) return; + this->getIContextApplication()->sendStatusMessages(messages); } void CRuntime::disconnectLogSignals(const QString &name) diff --git a/src/blackcore/context_runtime.h b/src/blackcore/context_runtime.h index 426f800a4..7f7568f9e 100644 --- a/src/blackcore/context_runtime.h +++ b/src/blackcore/context_runtime.h @@ -2,10 +2,13 @@ #define BLACKCORE_CONTEXT_RUNTIME_H #include "blackcore/context_runtime_config.h" +#include "blackmisc/statusmessagelist.h" #include #include #include +using namespace BlackMisc; + namespace BlackCore { // forward declaration, see review @@ -142,6 +145,14 @@ namespace BlackCore //! Clean up (will be connected to signal QCoreApplication::aboutToQuit) void gracefulShutdown(); + //! \copydoc IContextApplication::sendStatusMessage + //! \remarks fail safe + void sendStatusMessage(const BlackMisc::CStatusMessage &message); + + //! \copydoc IContextApplication::sendStatusMessage + //! \remarks fail safe + void sendStatusMessages(const BlackMisc::CStatusMessageList &messages); + // ------- Context as interface, normal way to access a context //! Context for network