From 679b34c7f4f708df23fcbe791b88d00692269bac Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 1 Apr 2014 22:16:26 +0200 Subject: [PATCH] refs #199, cleaned up contexts a bit after rebasing to current master * friend CRuntime on top * fixed some public constructors (made protected) * Also made registerWithDBus protected * Fixed some copy/paste issues in getIContextXXX * Reordered private/public sections --- src/blackcore/context_application.h | 2 - src/blackcore/context_application_impl.h | 15 ++++--- src/blackcore/context_application_proxy.h | 20 ++++----- src/blackcore/context_audio_impl.h | 18 ++++---- src/blackcore/context_audio_proxy.h | 2 +- src/blackcore/context_network.h | 9 +--- src/blackcore/context_network_impl.h | 33 ++++----------- src/blackcore/context_network_proxy.h | 5 +-- src/blackcore/context_runtime.cpp | 50 ++++++++++++++++++----- src/blackcore/context_runtime.h | 49 +++++++++++----------- src/blackcore/context_settings.h | 1 - src/blackcore/context_settings_impl.h | 10 ++--- src/blackcore/context_settings_proxy.h | 4 +- src/blackcore/context_simulator.h | 3 -- src/blackcore/context_simulator_impl.h | 24 +++++------ src/blackcore/context_simulator_proxy.h | 3 +- 16 files changed, 123 insertions(+), 125 deletions(-) diff --git a/src/blackcore/context_application.h b/src/blackcore/context_application.h index 490ab077d..150aa90cf 100644 --- a/src/blackcore/context_application.h +++ b/src/blackcore/context_application.h @@ -24,8 +24,6 @@ namespace BlackCore Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME) protected: - friend class CRuntime; - //! Constructor IContextApplication(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : CContext(mode, runtime) {} diff --git a/src/blackcore/context_application_impl.h b/src/blackcore/context_application_impl.h index 2c895f266..9b448c89d 100644 --- a/src/blackcore/context_application_impl.h +++ b/src/blackcore/context_application_impl.h @@ -21,14 +21,11 @@ namespace BlackCore { Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME) Q_OBJECT + friend class CRuntime; - public: - + protected: //! Constructor - CContextApplication(CRuntimeConfig::ContextMode mode, CRuntime *runtime = nullptr); - - //! Destructor - virtual ~CContextApplication() {} + CContextApplication(CRuntimeConfig::ContextMode mode, CRuntime *runtime); //! Register myself in DBus CContextApplication *registerWithDBus(CDBusServer *server) @@ -37,11 +34,13 @@ namespace BlackCore return this; } - public slots: + public: + //! Destructor + virtual ~CContextApplication() {} + public slots: //! \copydoc IContextApplication::ping() virtual qint64 ping(qint64 token) const override; - }; } diff --git a/src/blackcore/context_application_proxy.h b/src/blackcore/context_application_proxy.h index 8504f409e..d7f123814 100644 --- a/src/blackcore/context_application_proxy.h +++ b/src/blackcore/context_application_proxy.h @@ -18,18 +18,15 @@ namespace BlackCore class CContextApplicationProxy : public IContextApplication { Q_OBJECT + friend class CRuntime; public: //! Destructor virtual ~CContextApplicationProxy() {} - private: - friend class CRuntime; - BlackMisc::CGenericDBusInterface *m_dBusInterface; - - //! Relay connection signals to local signals - //! No idea why this has to be wired and is not done automatically - void relaySignals(const QString &serviceName, QDBusConnection &connection); + public slots: + //! \copydoc IContextApplication::ping() + virtual qint64 ping(qint64 token) const override; protected: //! Constructor @@ -38,11 +35,12 @@ namespace BlackCore //! DBus version constructor CContextApplicationProxy(const QString &serviceName, QDBusConnection &connection, CRuntimeConfig::ContextMode mode, CRuntime *runtime); - public slots: - - //! \copydoc IContextApplication::ping() - virtual qint64 ping(qint64 token) const override; + private: + BlackMisc::CGenericDBusInterface *m_dBusInterface; + //! Relay connection signals to local signals + //! No idea why this has to be wired and is not done automatically + void relaySignals(const QString &serviceName, QDBusConnection &connection); }; } diff --git a/src/blackcore/context_audio_impl.h b/src/blackcore/context_audio_impl.h index 649975c1e..19f3bcedb 100644 --- a/src/blackcore/context_audio_impl.h +++ b/src/blackcore/context_audio_impl.h @@ -20,20 +20,13 @@ namespace BlackCore { Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAUDIO_INTERFACENAME) Q_OBJECT + friend class CRuntime; public: //! \brief Destructor virtual ~CContextAudio(); - //! \brief Register myself in DBus - CContextAudio *registerWithDBus(CDBusServer *server) - { - Q_ASSERT(server); - server->addObject(IContextAudio::ObjectPath(), this); - return this; - } - public slots: //! \copydoc IContextAudio::setOwnAircraft() virtual void setOwnAircraft(const BlackMisc::Aviation::CAircraft &ownAircraft) override; @@ -105,8 +98,15 @@ namespace BlackCore //! \brief Constructor CContextAudio(CRuntimeConfig::ContextMode mode, CRuntime *runtime); + //! \brief Register myself in DBus + CContextAudio *registerWithDBus(CDBusServer *server) + { + Q_ASSERT(server); + server->addObject(IContextAudio::ObjectPath(), this); + return this; + } + private slots: - friend class CRuntime; void settingsChanged(uint typeValue); private: diff --git a/src/blackcore/context_audio_proxy.h b/src/blackcore/context_audio_proxy.h index 5e58f1525..734fe145a 100644 --- a/src/blackcore/context_audio_proxy.h +++ b/src/blackcore/context_audio_proxy.h @@ -22,6 +22,7 @@ namespace BlackCore { Q_OBJECT Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAUDIO_INTERFACENAME) + friend class CRuntime; public: @@ -29,7 +30,6 @@ namespace BlackCore virtual ~CContextAudioProxy() {} private: - friend class CRuntime; BlackMisc::CGenericDBusInterface *m_dBusInterface; //! Relay connection signals to local signals diff --git a/src/blackcore/context_network.h b/src/blackcore/context_network.h index d85865561..5565f7430 100644 --- a/src/blackcore/context_network.h +++ b/src/blackcore/context_network.h @@ -45,9 +45,6 @@ namespace BlackCore //! Destructor virtual ~IContextNetwork() {} - //! \brief Using local objects? - virtual bool usingLocalObjects() const = 0; - signals: //! Send status message @@ -170,12 +167,8 @@ namespace BlackCore virtual void requestAtisUpdates() = 0; protected: - friend class CRuntime; - //! Constructor - IContextNetwork(CRuntimeConfig::ContextMode mode, CRuntime *runtime = nullptr) : CContext(mode, runtime) {} - - + IContextNetwork(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : CContext(mode, runtime) {} }; } diff --git a/src/blackcore/context_network_impl.h b/src/blackcore/context_network_impl.h index 93e42070e..d72e15036 100644 --- a/src/blackcore/context_network_impl.h +++ b/src/blackcore/context_network_impl.h @@ -28,34 +28,12 @@ namespace BlackCore { Q_OBJECT Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTNETWORK_INTERFACENAME) + friend class CRuntime; public: //! Destructor virtual ~CContextNetwork(); - //! Register myself in DBus - CContextNetwork *registerWithDBus(CDBusServer *server) - { - Q_ASSERT(server); - server->addObject(IContextNetwork::ObjectPath(), this); - return this; - } - - //! Runtime - CRuntime *getRuntime() - { - return static_cast(this->parent()); - } - - //! \brief Const runtime - const CRuntime *getRuntime() const - { - return static_cast(this->parent()); - } - - //! \copydoc IContextNetwork::usingLocalObjects() - virtual bool usingLocalObjects() const override { return true; } - public slots: // IContextNetwork overrides //! \copydoc IContextNetwork::readAtcBookingsFromSource() @@ -134,8 +112,15 @@ namespace BlackCore //! Constructor, with link to runtime CContextNetwork(CRuntimeConfig::ContextMode, CRuntime *runtime); + //! Register myself in DBus + CContextNetwork *registerWithDBus(CDBusServer *server) + { + Q_ASSERT(server); + server->addObject(IContextNetwork::ObjectPath(), this); + return this; + } + private: - friend class CRuntime; BlackMisc::Aviation::CAtcStationList m_atcStationsOnline; BlackMisc::Aviation::CAtcStationList m_atcStationsBooked; BlackMisc::Aviation::CAircraftList m_aircraftsInRange; diff --git a/src/blackcore/context_network_proxy.h b/src/blackcore/context_network_proxy.h index 0089af803..c0136169e 100644 --- a/src/blackcore/context_network_proxy.h +++ b/src/blackcore/context_network_proxy.h @@ -24,17 +24,14 @@ namespace BlackCore class CContextNetworkProxy : public IContextNetwork { Q_OBJECT + friend class CRuntime; public: //! Destructor virtual ~CContextNetworkProxy() {} - //! \copydoc IContextNetwork::usingLocalObjects() - virtual bool usingLocalObjects() const override { return false; } - private: - friend class CRuntime; BlackMisc::CGenericDBusInterface *m_dBusInterface; /*!< DBus interface */ //! \brief Relay connection signals to local signals. diff --git a/src/blackcore/context_runtime.cpp b/src/blackcore/context_runtime.cpp index fe58f62ef..2b74fdddd 100644 --- a/src/blackcore/context_runtime.cpp +++ b/src/blackcore/context_runtime.cpp @@ -157,6 +157,15 @@ namespace BlackCore connect(this->m_contextSettings, &IContextSettings::changedSettings, this->getCContextAudio(), &CContextAudio::settingsChanged); } + + if (this->m_contextSimulator && this->m_contextSimulator->usingLocalObjects() && this->m_contextNetwork) + { + if (this->getCContextSimulator()->m_simulator) + { + connect(this->m_contextNetwork, SIGNAL(aircraftSituationUpdate(BlackMisc::Aviation::CCallsign, BlackMisc::Aviation::CAircraftSituation)), + this->getCContextSimulator()->m_simulator, SLOT(addAircraftSituation(BlackMisc::Aviation::CCallsign, BlackMisc::Aviation::CAircraftSituation))); + } + } } void CRuntime::initDBusConnection() @@ -167,25 +176,25 @@ namespace BlackCore IContextNetwork *CRuntime::getIContextNetwork() { - Q_ASSERT_X(this->m_contextSettings, "CCoreRuntime", "Requested missing network context"); + Q_ASSERT_X(this->m_contextNetwork, "CCoreRuntime", "Requested missing network context"); return this->m_contextNetwork; } const IContextNetwork *CRuntime::getIContextNetwork() const { - Q_ASSERT_X(this->m_contextSettings, "CCoreRuntime", "Requested missing network context"); + Q_ASSERT_X(this->m_contextNetwork, "CCoreRuntime", "Requested missing network context"); return this->m_contextNetwork; } IContextAudio *CRuntime::getIContextAudio() { - Q_ASSERT_X(this->m_contextSettings, "CCoreRuntime", "Requested missing audio context"); + Q_ASSERT_X(this->m_contextAudio, "CCoreRuntime", "Requested missing audio context"); return this->m_contextAudio; } const IContextAudio *CRuntime::getIContextAudio() const { - Q_ASSERT_X(this->m_contextSettings, "CCoreRuntime", "Requested missing audio context"); + Q_ASSERT_X(this->m_contextAudio, "CCoreRuntime", "Requested missing audio context"); return this->m_contextAudio; } @@ -203,35 +212,56 @@ namespace BlackCore const IContextApplication *CRuntime::getIContextApplication() const { - Q_ASSERT_X(this->m_contextSettings, "CCoreRuntime", "Requested missing application context"); + Q_ASSERT_X(this->m_contextApplication, "CCoreRuntime", "Requested missing application context"); return this->m_contextApplication; } IContextApplication *CRuntime::getIContextApplication() { - Q_ASSERT_X(this->m_contextSettings, "CCoreRuntime", "Requested missing application context"); + Q_ASSERT_X(this->m_contextApplication, "CCoreRuntime", "Requested missing application context"); return this->m_contextApplication; } const IContextSimulator *CRuntime::getIContextSimulator() const { - Q_ASSERT_X(this->m_contextSettings, "CCoreRuntime", "Requested missing simulator context"); + Q_ASSERT_X(this->m_contextSimulator, "CCoreRuntime", "Requested missing simulator context"); return this->m_contextSimulator; } IContextSimulator *CRuntime::getIContextSimulator() { - Q_ASSERT_X(this->m_contextSettings, "CCoreRuntime", "Requested missing simulator context"); + Q_ASSERT_X(this->m_contextSimulator, "CCoreRuntime", "Requested missing simulator context"); return this->m_contextSimulator; } CContextAudio *CRuntime::getCContextAudio() { - Q_ASSERT_X(this->m_contextSettings, "CCoreRuntime", "Requested missing audio context"); - Q_ASSERT_X(this->m_contextSimulator->usingLocalObjects(), "CCoreRuntime", "Cannot specialize to local object"); + Q_ASSERT_X(this->m_contextAudio, "CCoreRuntime", "Requested missing audio context"); + Q_ASSERT_X(this->m_contextAudio->usingLocalObjects(), "CCoreRuntime", "Cannot specialize to local object"); return static_cast(this->m_contextAudio); } + CContextAudio *CRuntime::getCContextAudio() const + { + Q_ASSERT_X(this->m_contextAudio, "CCoreRuntime", "Requested missing audio context"); + Q_ASSERT_X(this->m_contextAudio->usingLocalObjects(), "CCoreRuntime", "Cannot specialize to local object"); + return static_cast(this->m_contextAudio); + } + + CContextSimulator *CRuntime::getCContextSimulator() + { + Q_ASSERT_X(this->m_contextSimulator, "CCoreRuntime", "Requested missing simulator context"); + Q_ASSERT_X(this->m_contextSimulator->usingLocalObjects(), "CCoreRuntime", "Cannot specialize to local object"); + return static_cast(this->m_contextSimulator); + } + + CContextSimulator *CRuntime::getCContextSimulator() const + { + Q_ASSERT_X(this->m_contextSimulator, "CCoreRuntime", "Requested missing simulator context"); + Q_ASSERT_X(this->m_contextSimulator->usingLocalObjects(), "CCoreRuntime", "Cannot specialize to local object"); + return static_cast(this->m_contextSimulator); + } + const CRuntimeConfig &CRuntimeConfig::forCore() { static CRuntimeConfig cfg = CRuntimeConfig(CRuntimeConfig(CRuntimeConfig::LocalInDbusServer)); diff --git a/src/blackcore/context_runtime.h b/src/blackcore/context_runtime.h index 08539491c..2d4fe4fc9 100644 --- a/src/blackcore/context_runtime.h +++ b/src/blackcore/context_runtime.h @@ -26,29 +26,6 @@ namespace BlackCore { Q_OBJECT - private: - bool m_init; /*!< flag */ - CDBusServer *m_dbusServer; - bool m_initDBusConnection; - QDBusConnection m_dbusConnection; - IContextNetwork *m_contextNetwork; - IContextAudio *m_contextAudio; - IContextSettings *m_contextSettings; - IContextApplication *m_contextApplication; - IContextSimulator *m_contextSimulator; - - //! Init - void init(const CRuntimeConfig &config); - - //! initialization of DBus connection (where applicable) - void initDBusConnection(); - - //! initialization of DBus connection (where applicable) - void initDBusServer(const QString &dBusAddress); - - //! post init tasks, mainly connecting context signal slots - void initPostSetup(); - public: //! Constructor CRuntime(const CRuntimeConfig &config, QObject *parent = nullptr); @@ -93,8 +70,34 @@ namespace BlackCore IContextSimulator *getIContextSimulator(); private: + bool m_init; /*!< flag */ + CDBusServer *m_dbusServer; + bool m_initDBusConnection; + QDBusConnection m_dbusConnection; + IContextNetwork *m_contextNetwork; + IContextAudio *m_contextAudio; + IContextSettings *m_contextSettings; + IContextApplication *m_contextApplication; + IContextSimulator *m_contextSimulator; + + //! Init + void init(const CRuntimeConfig &config); + + //! initialization of DBus connection (where applicable) + void initDBusConnection(); + + //! initialization of DBus connection (where applicable) + void initDBusServer(const QString &dBusAddress); + + //! post init tasks, mainly connecting context signal slots + void initPostSetup(); + CContextAudio *getCContextAudio(); CContextAudio *getCContextAudio() const; + + CContextSimulator *getCContextSimulator(); + CContextSimulator *getCContextSimulator() const; + }; } #endif // guard diff --git a/src/blackcore/context_settings.h b/src/blackcore/context_settings.h index 40cf1d802..fb8283afe 100644 --- a/src/blackcore/context_settings.h +++ b/src/blackcore/context_settings.h @@ -22,7 +22,6 @@ namespace BlackCore { - /*! * Context settings interface */ diff --git a/src/blackcore/context_settings_impl.h b/src/blackcore/context_settings_impl.h index c9c9c8033..530603ece 100644 --- a/src/blackcore/context_settings_impl.h +++ b/src/blackcore/context_settings_impl.h @@ -24,15 +24,12 @@ namespace BlackCore { Q_OBJECT Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTSETTINGS_INTERFACENAME) + friend class CRuntime; protected: //! \brief Constructor CContextSettings(CRuntimeConfig::ContextMode mode, CRuntime *runtime = nullptr); - public: - //! Destructor - virtual ~CContextSettings() {} - //! \brief Register myself in DBus CContextSettings *registerWithDBus(CDBusServer *server) { @@ -40,6 +37,10 @@ namespace BlackCore return this; } + public: + //! Destructor + virtual ~CContextSettings() {} + //! \brief settings file const QString &getSettingsDirectory() const { return BlackMisc::Settings::CSettingUtilities::getSettingsDirectory(); } @@ -74,7 +75,6 @@ namespace BlackCore virtual QString getSettingsAsJsonString() const override; private: - friend class CRuntime; BlackMisc::Settings::CSettingsNetwork m_settingsNetwork; BlackMisc::Hardware::CKeyboardKeyList m_hotkeys; QJsonDocument toJsonDocument() const; diff --git a/src/blackcore/context_settings_proxy.h b/src/blackcore/context_settings_proxy.h index 30527b999..2dfa789e7 100644 --- a/src/blackcore/context_settings_proxy.h +++ b/src/blackcore/context_settings_proxy.h @@ -25,14 +25,13 @@ namespace BlackCore class CContextSettingsProxy : public IContextSettings { Q_OBJECT + friend class CRuntime; public: - //! \brief Destructor virtual ~CContextSettingsProxy() {} private: - friend class CRuntime; BlackMisc::CGenericDBusInterface *m_dBusInterface; //! Relay connection signals to local signals @@ -47,7 +46,6 @@ namespace BlackCore CContextSettingsProxy(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : IContextSettings(mode, runtime), m_dBusInterface(nullptr) {} public slots: - //! \copydoc IContextSettings::getNetworkSettings() virtual BlackMisc::Settings::CSettingsNetwork getNetworkSettings() const override; diff --git a/src/blackcore/context_simulator.h b/src/blackcore/context_simulator.h index 5f3218b3d..5bf6bf454 100644 --- a/src/blackcore/context_simulator.h +++ b/src/blackcore/context_simulator.h @@ -24,7 +24,6 @@ namespace BlackCore Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTSIMULATOR_INTERFACENAME) public: - //! \brief Service name static const QString &InterfaceName() { @@ -55,8 +54,6 @@ namespace BlackCore virtual BlackMisc::Aviation::CAircraft getOwnAircraft() const = 0; protected: - friend class CRuntime; - //! \brief Constructor IContextSimulator(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : CContext(mode, runtime) {} }; diff --git a/src/blackcore/context_simulator_impl.h b/src/blackcore/context_simulator_impl.h index 87f5b8be6..327f3cd55 100644 --- a/src/blackcore/context_simulator_impl.h +++ b/src/blackcore/context_simulator_impl.h @@ -22,14 +22,23 @@ namespace BlackCore { Q_OBJECT Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTSIMULATOR_INTERFACENAME) + friend class CRuntime; public: - //! \brief Constructor - CContextSimulator(CRuntimeConfig::ContextMode, CRuntime *runtime); - //! \brief Destructor virtual ~CContextSimulator(); + public slots: + //! \copydoc IContextSimulator::isConnected() + virtual bool isConnected() const override; + + //! \copydoc IContextSimulator::getOwnAircraft() + virtual BlackMisc::Aviation::CAircraft getOwnAircraft() const override; + + protected: + //! \brief Constructor + CContextSimulator(CRuntimeConfig::ContextMode, CRuntime *runtime); + //! Register myself in DBus CContextSimulator *registerWithDBus(CDBusServer *server) { @@ -38,13 +47,6 @@ namespace BlackCore return this; } - public slots: - //! \copydoc IContextSimulator::isConnected() - virtual bool isConnected() const override; - - //! \copydoc IContextSimulator::getOwnAircraft() - virtual BlackMisc::Aviation::CAircraft getOwnAircraft() const override; - private slots: //! \copydoc IContextSimulator::updateOwnAircraft() virtual void updateOwnAircraft(); @@ -62,9 +64,7 @@ namespace BlackCore BlackMisc::Aviation::CAircraft m_ownAircraft; BlackCore::ISimulator *m_simulator; QTimer *m_updateTimer; - BlackCore::IContextNetwork *m_contextNetwork; QDir m_pluginsDir; - IContextNetwork *getNetworkContext(); }; } // namespace BlackCore diff --git a/src/blackcore/context_simulator_proxy.h b/src/blackcore/context_simulator_proxy.h index 4379dcdf9..893637b62 100644 --- a/src/blackcore/context_simulator_proxy.h +++ b/src/blackcore/context_simulator_proxy.h @@ -15,12 +15,13 @@ namespace BlackCore class CContextSimulatorProxy : public IContextSimulator { Q_OBJECT + friend class CRuntime; + public: //! Destructor ~CContextSimulatorProxy() {} private: - friend class CRuntime; BlackMisc::CGenericDBusInterface *m_dBusInterface; //! Relay connection signals to local signals