From 16b9c714afd3c203fb849ca73f04ca793605a285 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 2 Apr 2014 16:00:14 +0200 Subject: [PATCH] refs #199, direct access to other context convenience methods --- src/blackcore/context.cpp | 55 ++++++++++++++++++++++++ src/blackcore/context.h | 34 +++++++++++++++ src/blackcore/context_audio_impl.cpp | 8 ++-- src/blackcore/context_network_impl.cpp | 4 +- src/blackcore/context_simulator_impl.cpp | 4 +- 5 files changed, 96 insertions(+), 9 deletions(-) create mode 100644 src/blackcore/context.cpp diff --git a/src/blackcore/context.cpp b/src/blackcore/context.cpp new file mode 100644 index 000000000..eb1a03c5c --- /dev/null +++ b/src/blackcore/context.cpp @@ -0,0 +1,55 @@ +#include "context.h" + +namespace BlackCore +{ + + IContextNetwork *CContext::getIContextNetwork() + { + return this->getRuntime()->getIContextNetwork(); + } + + const IContextNetwork *CContext::getIContextNetwork() const + { + return this->getRuntime()->getIContextNetwork(); + } + + IContextAudio *CContext::getIContextAudio() + { + return this->getRuntime()->getIContextAudio(); + } + + const IContextAudio *CContext::getIContextAudio() const + { + return this->getRuntime()->getIContextAudio(); + } + + IContextApplication *CContext::getIContextApplication() + { + return this->getRuntime()->getIContextApplication(); + } + + const IContextApplication *CContext::getIContextApplication() const + { + return this->getRuntime()->getIContextApplication(); + } + + IContextSettings *CContext::getIContextSettings() + { + return this->getRuntime()->getIContextSettings(); + } + + const IContextSettings *CContext::getIContextSettings() const + { + return this->getRuntime()->getIContextSettings(); + } + + IContextSimulator *CContext::getIContextSimulator() + { + return this->getRuntime()->getIContextSimulator(); + } + + const IContextSimulator *CContext::getIContextSimulator() const + { + return this->getRuntime()->getIContextSimulator(); + } +} diff --git a/src/blackcore/context.h b/src/blackcore/context.h index c94e68a3e..7347adeeb 100644 --- a/src/blackcore/context.h +++ b/src/blackcore/context.h @@ -39,6 +39,40 @@ namespace BlackCore return static_cast(this->parent()); } + // + // cross context access + // + + //! Context for network + IContextNetwork *getIContextNetwork(); + + //! Context for network + const IContextNetwork *getIContextNetwork() const; + + //! Context for network + IContextAudio *getIContextAudio(); + + //! Context for network + const IContextAudio *getIContextAudio() const; + + //! Settings + IContextSettings *getIContextSettings(); + + //! Settings + const IContextSettings *getIContextSettings() const; + + //! Context for application + const IContextApplication *getIContextApplication() const; + + //! Application + IContextApplication *getIContextApplication(); + + //! Context for simulator + const IContextSimulator *getIContextSimulator() const; + + //! Simulator + IContextSimulator *getIContextSimulator(); + protected: //! Constructor CContext(CRuntimeConfig::ContextMode mode, QObject *parent) : QObject(parent), m_mode(mode) diff --git a/src/blackcore/context_audio_impl.cpp b/src/blackcore/context_audio_impl.cpp index 7aa4b37ab..9b1b3c9c5 100644 --- a/src/blackcore/context_audio_impl.cpp +++ b/src/blackcore/context_audio_impl.cpp @@ -209,9 +209,7 @@ namespace BlackCore { Q_ASSERT(this->m_voice); Q_ASSERT(this->getRuntime()); - Q_ASSERT(this->getRuntime()->getIContextNetwork()); - return this->getRuntime()->getIContextNetwork()-> - getUsersForCallsigns(this->getCom1RoomCallsigns()); + return this->getIContextNetwork()->getUsersForCallsigns(this->getCom1RoomCallsigns()); } /* @@ -283,11 +281,11 @@ namespace BlackCore void CContextAudio::settingsChanged(uint typeValue) { - if (!this->getRuntime()->getIContextSettings()) return; + if (!this->getIContextSettings()) return; IContextSettings::SettingsType type = static_cast(typeValue); if (type == IContextSettings::SettingsHotKeys) { - CKeyboardKeyList hotKeys = this->getRuntime()->getIContextSettings()->getHotkeys(); + CKeyboardKeyList hotKeys = this->getIContextSettings()->getHotkeys(); CKeyboardKey pttKey = hotKeys.findBy(&BlackMisc::Hardware::CKeyboardKey::getFunction, BlackMisc::Hardware::CKeyboardKey::HotkeyPtt).front(); m_keyboard->unregisterHotkey(m_handlePtt); m_handlePtt = m_keyboard->registerHotkey(pttKey, m_voice, &CVoiceVatlib::handlePushToTalk); diff --git a/src/blackcore/context_network_impl.cpp b/src/blackcore/context_network_impl.cpp index afaca1632..1526356c7 100644 --- a/src/blackcore/context_network_impl.cpp +++ b/src/blackcore/context_network_impl.cpp @@ -99,7 +99,7 @@ namespace BlackCore CAltitude(312, CAltitude::MeanSeaLevel, CLengthUnit::ft()) ); this->m_ownAircraft.setSituation(situation); - this->m_ownAircraft.setPilot(this->getRuntime()->getIContextSettings()->getNetworkSettings().getCurrentTrafficNetworkServer().getUser()); + this->m_ownAircraft.setPilot(this->getIContextSettings()->getNetworkSettings().getCurrentTrafficNetworkServer().getUser()); // TODO: This would need to come from somewhere (mappings) // Own callsign, plane ICAO status, model used @@ -114,7 +114,7 @@ namespace BlackCore { // this->log(Q_FUNC_INFO); CStatusMessageList msgs; - CServer currentServer = this->getRuntime()->getIContextSettings()->getNetworkSettings().getCurrentTrafficNetworkServer(); + CServer currentServer = this->getIContextSettings()->getNetworkSettings().getCurrentTrafficNetworkServer(); if (!currentServer.getUser().isValid()) { diff --git a/src/blackcore/context_simulator_impl.cpp b/src/blackcore/context_simulator_impl.cpp index a2707ffdb..df5789172 100644 --- a/src/blackcore/context_simulator_impl.cpp +++ b/src/blackcore/context_simulator_impl.cpp @@ -44,8 +44,8 @@ namespace BlackCore void CContextSimulator::updateOwnAircraft() { m_ownAircraft = m_simulator->getOwnAircraft(); - getRuntime()->getIContextNetwork()->updateOwnSituation(m_ownAircraft.getSituation()); - getRuntime()->getIContextNetwork()->updateOwnCockpit(m_ownAircraft.getCom1System(), m_ownAircraft.getCom2System(), m_ownAircraft.getTransponder()); + getIContextNetwork()->updateOwnSituation(m_ownAircraft.getSituation()); + getIContextNetwork()->updateOwnCockpit(m_ownAircraft.getCom1System(), m_ownAircraft.getCom2System(), m_ownAircraft.getTransponder()); } void CContextSimulator::setConnectionStatus(bool value)