From d782839cb8f75fc5a0ae8534c5fff27d0b5295fd Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 9 Jul 2016 13:50:45 +0200 Subject: [PATCH] refs #703, moved context to subdir * ns: Context * adjusted using classes --- src/blackcore/application.cpp | 3 +- src/blackcore/application.h | 33 +- src/blackcore/blackcore.pro | 2 + src/blackcore/context.cpp | 88 --- src/blackcore/context.h | 154 ---- src/blackcore/context/context.cpp | 91 +++ src/blackcore/context/context.h | 156 ++++ .../{ => context}/contextallempties.h | 4 +- src/blackcore/{ => context}/contextallimpl.h | 4 +- .../{ => context}/contextallinterfaces.h | 4 +- .../{ => context}/contextallproxies.h | 4 +- src/blackcore/context/contextapplication.cpp | 173 +++++ src/blackcore/context/contextapplication.h | 226 ++++++ .../context/contextapplicationempty.h | 196 +++++ .../context/contextapplicationimpl.cpp | 205 ++++++ .../context/contextapplicationimpl.h | 126 ++++ .../context/contextapplicationproxy.cpp | 182 +++++ .../context/contextapplicationproxy.h | 134 ++++ src/blackcore/context/contextaudio.cpp | 36 + src/blackcore/context/contextaudio.h | 180 +++++ src/blackcore/context/contextaudioempty.h | 182 +++++ src/blackcore/context/contextaudioimpl.cpp | 560 +++++++++++++++ src/blackcore/context/contextaudioimpl.h | 191 +++++ src/blackcore/context/contextaudioproxy.cpp | 153 ++++ src/blackcore/context/contextaudioproxy.h | 134 ++++ src/blackcore/context/contextnetwork.cpp | 36 + src/blackcore/context/contextnetwork.h | 286 ++++++++ src/blackcore/context/contextnetworkempty.h | 323 +++++++++ src/blackcore/context/contextnetworkimpl.cpp | 673 ++++++++++++++++++ src/blackcore/context/contextnetworkimpl.h | 313 ++++++++ src/blackcore/context/contextnetworkproxy.cpp | 283 ++++++++ src/blackcore/context/contextnetworkproxy.h | 203 ++++++ src/blackcore/context/contextownaircraft.cpp | 35 + src/blackcore/context/contextownaircraft.h | 153 ++++ .../context/contextownaircraftempty.h | 136 ++++ .../context/contextownaircraftimpl.cpp | 385 ++++++++++ .../context/contextownaircraftimpl.h | 183 +++++ .../context/contextownaircraftproxy.cpp | 103 +++ .../context/contextownaircraftproxy.h | 111 +++ src/blackcore/context/contextsimulator.cpp | 63 ++ src/blackcore/context/contextsimulator.h | 205 ++++++ src/blackcore/context/contextsimulatorempty.h | 232 ++++++ .../context/contextsimulatorimpl.cpp | 633 ++++++++++++++++ src/blackcore/context/contextsimulatorimpl.h | 213 ++++++ .../context/contextsimulatorproxy.cpp | 203 ++++++ src/blackcore/context/contextsimulatorproxy.h | 150 ++++ src/blackcore/contextapplication.cpp | 171 ----- src/blackcore/contextapplication.h | 225 ------ src/blackcore/contextapplicationempty.h | 195 ----- src/blackcore/contextapplicationimpl.cpp | 204 ------ src/blackcore/contextapplicationimpl.h | 125 ---- src/blackcore/contextapplicationproxy.cpp | 181 ----- src/blackcore/contextapplicationproxy.h | 133 ---- src/blackcore/contextaudio.cpp | 34 - src/blackcore/contextaudio.h | 178 ----- src/blackcore/contextaudioempty.h | 179 ----- src/blackcore/contextaudioimpl.cpp | 558 --------------- src/blackcore/contextaudioimpl.h | 196 ----- src/blackcore/contextaudioproxy.cpp | 212 ------ src/blackcore/contextaudioproxy.h | 135 ---- src/blackcore/contextnetwork.cpp | 34 - src/blackcore/contextnetwork.h | 286 -------- src/blackcore/contextnetworkempty.h | 321 --------- src/blackcore/contextnetworkimpl.cpp | 670 ----------------- src/blackcore/contextnetworkimpl.h | 311 -------- src/blackcore/contextnetworkproxy.cpp | 287 -------- src/blackcore/contextnetworkproxy.h | 202 ------ src/blackcore/contextownaircraft.cpp | 32 - src/blackcore/contextownaircraft.h | 152 ---- src/blackcore/contextownaircraftempty.h | 134 ---- src/blackcore/contextownaircraftimpl.cpp | 383 ---------- src/blackcore/contextownaircraftimpl.h | 182 ----- src/blackcore/contextownaircraftproxy.cpp | 102 --- src/blackcore/contextownaircraftproxy.h | 111 --- src/blackcore/contextsimulator.cpp | 61 -- src/blackcore/contextsimulator.h | 204 ------ src/blackcore/contextsimulatorempty.h | 229 ------ src/blackcore/contextsimulatorimpl.cpp | 631 ---------------- src/blackcore/contextsimulatorimpl.h | 213 ------ src/blackcore/contextsimulatorproxy.cpp | 202 ------ src/blackcore/contextsimulatorproxy.h | 150 ---- src/blackcore/corefacade.cpp | 21 +- src/blackcore/corefacade.h | 73 +- src/blackcore/registermetadata.cpp | 6 +- src/blackgui/components/aircraftcomponent.cpp | 5 +- .../components/atcstationcomponent.cpp | 5 +- .../components/audiosetupcomponent.cpp | 3 +- .../components/audiovolumecomponent.cpp | 3 +- .../components/cockpitcomcomponent.cpp | 7 +- .../cockpittranspondermodeledscomponent.cpp | 3 +- .../components/flightplancomponent.cpp | 4 +- .../components/infobarstatuscomponent.cpp | 9 +- .../components/internalscomponent.cpp | 10 +- src/blackgui/components/logincomponent.cpp | 9 +- .../components/mainkeypadareacomponent.cpp | 7 +- .../components/mainkeypadareacomponent.h | 6 +- src/blackgui/components/mappingcomponent.cpp | 5 +- .../components/modelmatcherlogcomponent.cpp | 2 +- src/blackgui/components/registercomponent.cpp | 3 +- .../components/remoteaircraftselector.cpp | 3 +- .../components/settingshotkeycomponent.cpp | 2 +- .../components/settingsnetworkcomponent.cpp | 2 +- .../settingsnetworkserverscomponent.cpp | 2 +- .../components/settingssimulatorcomponent.cpp | 5 +- .../components/simulatorcomponent.cpp | 5 +- .../components/textmessagecomponent.cpp | 7 +- src/blackgui/components/usercomponent.cpp | 3 +- .../components/voiceroomscomponent.cpp | 7 +- src/blackgui/components/weathercomponent.cpp | 7 +- src/blackmisc/aviation/aircraftpartslist.cpp | 1 - src/blackmisc/aviation/aircraftpartslist.h | 4 +- .../simulator/fscommon/simulatorfscommon.h | 2 +- .../fsxconfig/simconnectsettingscomponent.cpp | 4 +- src/swiftguistandard/swiftguistd.cpp | 6 +- src/swiftguistandard/swiftguistdaircraft.cpp | 2 +- src/swiftguistandard/swiftguistdinit.cpp | 3 +- 116 files changed, 8009 insertions(+), 8003 deletions(-) delete mode 100644 src/blackcore/context.cpp delete mode 100644 src/blackcore/context.h create mode 100644 src/blackcore/context/context.cpp create mode 100644 src/blackcore/context/context.h rename src/blackcore/{ => context}/contextallempties.h (86%) rename src/blackcore/{ => context}/contextallimpl.h (67%) rename src/blackcore/{ => context}/contextallinterfaces.h (62%) rename src/blackcore/{ => context}/contextallproxies.h (66%) create mode 100644 src/blackcore/context/contextapplication.cpp create mode 100644 src/blackcore/context/contextapplication.h create mode 100644 src/blackcore/context/contextapplicationempty.h create mode 100644 src/blackcore/context/contextapplicationimpl.cpp create mode 100644 src/blackcore/context/contextapplicationimpl.h create mode 100644 src/blackcore/context/contextapplicationproxy.cpp create mode 100644 src/blackcore/context/contextapplicationproxy.h create mode 100644 src/blackcore/context/contextaudio.cpp create mode 100644 src/blackcore/context/contextaudio.h create mode 100644 src/blackcore/context/contextaudioempty.h create mode 100644 src/blackcore/context/contextaudioimpl.cpp create mode 100644 src/blackcore/context/contextaudioimpl.h create mode 100644 src/blackcore/context/contextaudioproxy.cpp create mode 100644 src/blackcore/context/contextaudioproxy.h create mode 100644 src/blackcore/context/contextnetwork.cpp create mode 100644 src/blackcore/context/contextnetwork.h create mode 100644 src/blackcore/context/contextnetworkempty.h create mode 100644 src/blackcore/context/contextnetworkimpl.cpp create mode 100644 src/blackcore/context/contextnetworkimpl.h create mode 100644 src/blackcore/context/contextnetworkproxy.cpp create mode 100644 src/blackcore/context/contextnetworkproxy.h create mode 100644 src/blackcore/context/contextownaircraft.cpp create mode 100644 src/blackcore/context/contextownaircraft.h create mode 100644 src/blackcore/context/contextownaircraftempty.h create mode 100644 src/blackcore/context/contextownaircraftimpl.cpp create mode 100644 src/blackcore/context/contextownaircraftimpl.h create mode 100644 src/blackcore/context/contextownaircraftproxy.cpp create mode 100644 src/blackcore/context/contextownaircraftproxy.h create mode 100644 src/blackcore/context/contextsimulator.cpp create mode 100644 src/blackcore/context/contextsimulator.h create mode 100644 src/blackcore/context/contextsimulatorempty.h create mode 100644 src/blackcore/context/contextsimulatorimpl.cpp create mode 100644 src/blackcore/context/contextsimulatorimpl.h create mode 100644 src/blackcore/context/contextsimulatorproxy.cpp create mode 100644 src/blackcore/context/contextsimulatorproxy.h delete mode 100644 src/blackcore/contextapplication.cpp delete mode 100644 src/blackcore/contextapplication.h delete mode 100644 src/blackcore/contextapplicationempty.h delete mode 100644 src/blackcore/contextapplicationimpl.cpp delete mode 100644 src/blackcore/contextapplicationimpl.h delete mode 100644 src/blackcore/contextapplicationproxy.cpp delete mode 100644 src/blackcore/contextapplicationproxy.h delete mode 100644 src/blackcore/contextaudio.cpp delete mode 100644 src/blackcore/contextaudio.h delete mode 100644 src/blackcore/contextaudioempty.h delete mode 100644 src/blackcore/contextaudioimpl.cpp delete mode 100644 src/blackcore/contextaudioimpl.h delete mode 100644 src/blackcore/contextaudioproxy.cpp delete mode 100644 src/blackcore/contextaudioproxy.h delete mode 100644 src/blackcore/contextnetwork.cpp delete mode 100644 src/blackcore/contextnetwork.h delete mode 100644 src/blackcore/contextnetworkempty.h delete mode 100644 src/blackcore/contextnetworkimpl.cpp delete mode 100644 src/blackcore/contextnetworkimpl.h delete mode 100644 src/blackcore/contextnetworkproxy.cpp delete mode 100644 src/blackcore/contextnetworkproxy.h delete mode 100644 src/blackcore/contextownaircraft.cpp delete mode 100644 src/blackcore/contextownaircraft.h delete mode 100644 src/blackcore/contextownaircraftempty.h delete mode 100644 src/blackcore/contextownaircraftimpl.cpp delete mode 100644 src/blackcore/contextownaircraftimpl.h delete mode 100644 src/blackcore/contextownaircraftproxy.cpp delete mode 100644 src/blackcore/contextownaircraftproxy.h delete mode 100644 src/blackcore/contextsimulator.cpp delete mode 100644 src/blackcore/contextsimulator.h delete mode 100644 src/blackcore/contextsimulatorempty.h delete mode 100644 src/blackcore/contextsimulatorimpl.cpp delete mode 100644 src/blackcore/contextsimulatorimpl.h delete mode 100644 src/blackcore/contextsimulatorproxy.cpp delete mode 100644 src/blackcore/contextsimulatorproxy.h diff --git a/src/blackcore/application.cpp b/src/blackcore/application.cpp index 80cb60a38..c77ca1679 100644 --- a/src/blackcore/application.cpp +++ b/src/blackcore/application.cpp @@ -9,7 +9,7 @@ #include "blackconfig/buildconfig.h" #include "blackcore/application.h" -#include "blackcore/contextapplication.h" +#include "blackcore/context/contextapplication.h" #include "blackcore/cookiemanager.h" #include "blackcore/corefacade.h" #include "blackcore/networkvatlib.h" @@ -61,6 +61,7 @@ using namespace BlackMisc::Aviation; using namespace BlackMisc::Simulation; using namespace BlackMisc::Weather; using namespace BlackCore; +using namespace BlackCore::Context; using namespace BlackCore::Data; using namespace BlackCore::Db; diff --git a/src/blackcore/application.h b/src/blackcore/application.h index 41a050b6e..8f68b9654 100644 --- a/src/blackcore/application.h +++ b/src/blackcore/application.h @@ -52,11 +52,14 @@ namespace BlackCore class CCoreFacade; class CSetupReader; class CWebDataServices; - class IContextApplication; - class IContextAudio; - class IContextNetwork; - class IContextOwnAircraft; - class IContextSimulator; + namespace Context + { + class IContextApplication; + class IContextAudio; + class IContextNetwork; + class IContextOwnAircraft; + class IContextSimulator; + } /*! * Our runtime. Normally one instance is to be initialized at the beginning of main, and thereafter @@ -259,16 +262,16 @@ namespace BlackCore //! \name Direct access to contexts if a CCoreFacade has been initialized //! @{ - const IContextNetwork *getIContextNetwork() const; - const IContextAudio *getIContextAudio() const; - const IContextApplication *getIContextApplication() const; - const IContextOwnAircraft *getIContextOwnAircraft() const; - const IContextSimulator *getIContextSimulator() const; - IContextNetwork *getIContextNetwork(); - IContextAudio *getIContextAudio(); - IContextApplication *getIContextApplication(); - IContextOwnAircraft *getIContextOwnAircraft(); - IContextSimulator *getIContextSimulator(); + const Context::IContextNetwork *getIContextNetwork() const; + const Context::IContextAudio *getIContextAudio() const; + const Context::IContextApplication *getIContextApplication() const; + const Context::IContextOwnAircraft *getIContextOwnAircraft() const; + const Context::IContextSimulator *getIContextSimulator() const; + Context::IContextNetwork *getIContextNetwork(); + Context::IContextAudio *getIContextAudio(); + Context::IContextApplication *getIContextApplication(); + Context::IContextOwnAircraft *getIContextOwnAircraft(); + Context::IContextSimulator *getIContextSimulator(); //! @} // ----------------------- direct access to some setup data --------------------------------- diff --git a/src/blackcore/blackcore.pro b/src/blackcore/blackcore.pro index 8ad2b2d57..131e91e31 100644 --- a/src/blackcore/blackcore.pro +++ b/src/blackcore/blackcore.pro @@ -23,12 +23,14 @@ precompile_header:!isEmpty(PRECOMPILED_HEADER) { DEFINES += LOG_IN_FILE BUILD_BLACKCORE_LIB HEADERS += *.h +HEADERS += $$PWD/context/*.h HEADERS += $$PWD/data/*.h HEADERS += $$PWD/db/*.h HEADERS += $$PWD/settings/*.h HEADERS += $$PWD/vatsim/*.h SOURCES += *.cpp +SOURCES += $$PWD/context/*.cpp SOURCES += $$PWD/data/*.cpp SOURCES += $$PWD/db/*.cpp SOURCES += $$PWD/vatsim/*.cpp diff --git a/src/blackcore/context.cpp b/src/blackcore/context.cpp deleted file mode 100644 index 1f20c9853..000000000 --- a/src/blackcore/context.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "blackcore/context.h" -#include "blackmisc/logcategorylist.h" - -using namespace BlackMisc; - -namespace BlackCore -{ - const CLogCategoryList &CContext::getLogCategories() - { - static const BlackMisc::CLogCategoryList cats { BlackMisc::CLogCategory::context() }; - return cats; - } - - 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(); - } - - IContextOwnAircraft *CContext::getIContextOwnAircraft() - { - return this->getRuntime()->getIContextOwnAircraft(); - } - - const IContextOwnAircraft *CContext::getIContextOwnAircraft() const - { - return this->getRuntime()->getIContextOwnAircraft(); - } - - IContextSimulator *CContext::getIContextSimulator() - { - return this->getRuntime()->getIContextSimulator(); - } - - void CContext::setDebugEnabled(bool debug) - { - this->m_debugEnabled = debug; - } - - bool CContext::isDebugEnabled() const - { - return this->m_debugEnabled; - } - - const IContextSimulator *CContext::getIContextSimulator() const - { - return this->getRuntime()->getIContextSimulator(); - } - - const CStatusMessage &CContext::statusMessageEmptyContext() - { - static const CStatusMessage m(getLogCategories(), CStatusMessage::SeverityWarning, "empty context"); - return m; - } -} // namespace diff --git a/src/blackcore/context.h b/src/blackcore/context.h deleted file mode 100644 index abc969c93..000000000 --- a/src/blackcore/context.h +++ /dev/null @@ -1,154 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKCORE_CONTEXT_H -#define BLACKCORE_CONTEXT_H - -#include "blackcore/blackcoreexport.h" -#include "blackcore/corefacade.h" -#include "blackcore/corefacadeconfig.h" -#include "blackmisc/logcategory.h" -#include "blackmisc/logmessage.h" -#include "blackmisc/statusmessage.h" - -#include -#include -#include -#include - -namespace BlackMisc { class CLogCategoryList; } - -namespace BlackCore -{ - class IContextApplication; - class IContextAudio; - class IContextNetwork; - class IContextOwnAircraft; - class IContextSimulator; - - //! Base for all context classes - class BLACKCORE_EXPORT CContext : public QObject - { - public: - //! Destructor - virtual ~CContext() {} - - //! Log categories - static const BlackMisc::CLogCategoryList &getLogCategories(); - - //! Using local implementing object? - bool isUsingImplementingObject() const - { - return m_mode == CCoreFacadeConfig::Local || m_mode == CCoreFacadeConfig::LocalInDbusServer; - } - - //! Local or remote object? - bool isLocalObject() const - { - return isUsingImplementingObject() || m_mode == CCoreFacadeConfig::NotUsed; - } - - //! Empty object? - bool isEmptyObject() const - { - return m_mode == CCoreFacadeConfig::NotUsed; - } - - //! Runtime - CCoreFacade *getRuntime() - { - Q_ASSERT(this->parent()); - return static_cast(this->parent()); - } - - //! Const runtime - const CCoreFacade *getRuntime() const - { - Q_ASSERT(this->parent()); - return static_cast(this->parent()); - } - - //! Mode - CCoreFacadeConfig::ContextMode getMode() const { return this->m_mode; } - - //! Unique id - qint64 getUniqueId() const { return this->m_contextId; } - - // - // cross context access - // - - //! Context for application - const IContextApplication *getIContextApplication() const; - - //! Application - IContextApplication *getIContextApplication(); - - //! Context for network - IContextAudio *getIContextAudio(); - - //! Context for network - const IContextAudio *getIContextAudio() const; - - //! Context for network - IContextNetwork *getIContextNetwork(); - - //! Context for network - const IContextNetwork *getIContextNetwork() const; - - //! Context for own aircraft - IContextOwnAircraft *getIContextOwnAircraft(); - - //! Context for own aircraft - const IContextOwnAircraft *getIContextOwnAircraft() const; - - //! Context for simulator - const IContextSimulator *getIContextSimulator() const; - - //! Simulator - IContextSimulator *getIContextSimulator(); - - //! Set debug flag - void setDebugEnabled(bool debug); - - //! Debug enabled? - bool isDebugEnabled() const; - - //! Id and path name for round trip protection - virtual QString getPathAndContextId() const = 0; - - protected: - CCoreFacadeConfig::ContextMode m_mode; //!< How context is used - qint64 m_contextId; //!< unique identifer, avoid redirection rountrips - bool m_debugEnabled = false; //!< debug messages enabled - - //! Constructor - CContext(CCoreFacadeConfig::ContextMode mode, QObject *parent) : - QObject(parent), m_mode(mode), m_contextId(QDateTime::currentMSecsSinceEpoch()) - {} - - //! Path and context id - QString buildPathAndContextId(const QString &path) const - { - return QString(path) + ":" + QString::number(this->getUniqueId()); - } - - //! Empty context called - void logEmptyContextWarning(const QString &functionName) const - { - BlackMisc::CLogMessage(this, BlackMisc::CLogCategory::contextSlot()).warning("Empty context called, details: %1") << functionName; - } - - //! Standard message when status message is returned in empty context - static const BlackMisc::CStatusMessage &statusMessageEmptyContext(); - }; -} -#endif // guard diff --git a/src/blackcore/context/context.cpp b/src/blackcore/context/context.cpp new file mode 100644 index 000000000..71e041ad1 --- /dev/null +++ b/src/blackcore/context/context.cpp @@ -0,0 +1,91 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "blackcore/context/context.h" +#include "blackmisc/logcategorylist.h" + +using namespace BlackMisc; + +namespace BlackCore +{ + namespace Context + { + const CLogCategoryList &CContext::getLogCategories() + { + static const BlackMisc::CLogCategoryList cats { BlackMisc::CLogCategory::context() }; + return cats; + } + + 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(); + } + + IContextOwnAircraft *CContext::getIContextOwnAircraft() + { + return this->getRuntime()->getIContextOwnAircraft(); + } + + const IContextOwnAircraft *CContext::getIContextOwnAircraft() const + { + return this->getRuntime()->getIContextOwnAircraft(); + } + + IContextSimulator *CContext::getIContextSimulator() + { + return this->getRuntime()->getIContextSimulator(); + } + + void CContext::setDebugEnabled(bool debug) + { + this->m_debugEnabled = debug; + } + + bool CContext::isDebugEnabled() const + { + return this->m_debugEnabled; + } + + const IContextSimulator *CContext::getIContextSimulator() const + { + return this->getRuntime()->getIContextSimulator(); + } + + const CStatusMessage &CContext::statusMessageEmptyContext() + { + static const CStatusMessage m(getLogCategories(), CStatusMessage::SeverityWarning, "empty context"); + return m; + } + } // ns +} // ns diff --git a/src/blackcore/context/context.h b/src/blackcore/context/context.h new file mode 100644 index 000000000..e8cdc436f --- /dev/null +++ b/src/blackcore/context/context.h @@ -0,0 +1,156 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKCORE_CONTEXT_CONTEXT_H +#define BLACKCORE_CONTEXT_CONTEXT_H + +#include "blackcore/blackcoreexport.h" +#include "blackcore/corefacade.h" +#include "blackcore/corefacadeconfig.h" +#include "blackmisc/logcategory.h" +#include "blackmisc/logmessage.h" +#include "blackmisc/statusmessage.h" + +#include +#include +#include +#include + +namespace BlackMisc { class CLogCategoryList; } +namespace BlackCore +{ + namespace Context + { + class IContextApplication; + class IContextAudio; + class IContextNetwork; + class IContextOwnAircraft; + class IContextSimulator; + + //! Base for all context classes + class BLACKCORE_EXPORT CContext : public QObject + { + public: + //! Destructor + virtual ~CContext() {} + + //! Log categories + static const BlackMisc::CLogCategoryList &getLogCategories(); + + //! Using local implementing object? + bool isUsingImplementingObject() const + { + return m_mode == CCoreFacadeConfig::Local || m_mode == CCoreFacadeConfig::LocalInDbusServer; + } + + //! Local or remote object? + bool isLocalObject() const + { + return isUsingImplementingObject() || m_mode == CCoreFacadeConfig::NotUsed; + } + + //! Empty object? + bool isEmptyObject() const + { + return m_mode == CCoreFacadeConfig::NotUsed; + } + + //! Runtime + CCoreFacade *getRuntime() + { + Q_ASSERT(this->parent()); + return static_cast(this->parent()); + } + + //! Const runtime + const CCoreFacade *getRuntime() const + { + Q_ASSERT(this->parent()); + return static_cast(this->parent()); + } + + //! Mode + CCoreFacadeConfig::ContextMode getMode() const { return this->m_mode; } + + //! Unique id + qint64 getUniqueId() const { return this->m_contextId; } + + // + // cross context access + // + + //! Context for application + const IContextApplication *getIContextApplication() const; + + //! Application + IContextApplication *getIContextApplication(); + + //! Context for network + IContextAudio *getIContextAudio(); + + //! Context for network + const IContextAudio *getIContextAudio() const; + + //! Context for network + IContextNetwork *getIContextNetwork(); + + //! Context for network + const IContextNetwork *getIContextNetwork() const; + + //! Context for own aircraft + IContextOwnAircraft *getIContextOwnAircraft(); + + //! Context for own aircraft + const IContextOwnAircraft *getIContextOwnAircraft() const; + + //! Context for simulator + const IContextSimulator *getIContextSimulator() const; + + //! Simulator + IContextSimulator *getIContextSimulator(); + + //! Set debug flag + void setDebugEnabled(bool debug); + + //! Debug enabled? + bool isDebugEnabled() const; + + //! Id and path name for round trip protection + virtual QString getPathAndContextId() const = 0; + + protected: + CCoreFacadeConfig::ContextMode m_mode; //!< How context is used + qint64 m_contextId; //!< unique identifer, avoid redirection rountrips + bool m_debugEnabled = false; //!< debug messages enabled + + //! Constructor + CContext(CCoreFacadeConfig::ContextMode mode, QObject *parent) : + QObject(parent), m_mode(mode), m_contextId(QDateTime::currentMSecsSinceEpoch()) + {} + + //! Path and context id + QString buildPathAndContextId(const QString &path) const + { + return QString(path) + ":" + QString::number(this->getUniqueId()); + } + + //! Empty context called + void logEmptyContextWarning(const QString &functionName) const + { + BlackMisc::CLogMessage(this, BlackMisc::CLogCategory::contextSlot()).warning("Empty context called, details: %1") << functionName; + } + + //! Standard message when status message is returned in empty context + static const BlackMisc::CStatusMessage &statusMessageEmptyContext(); + }; + } // ns +} // ns +#endif // guard diff --git a/src/blackcore/contextallempties.h b/src/blackcore/context/contextallempties.h similarity index 86% rename from src/blackcore/contextallempties.h rename to src/blackcore/context/contextallempties.h index ddbf67255..1bb2b42f1 100644 --- a/src/blackcore/contextallempties.h +++ b/src/blackcore/context/contextallempties.h @@ -7,8 +7,8 @@ * contained in the LICENSE file. */ -#ifndef BLACKCORE_CONTEXT_ALL_EMPTIES_H -#define BLACKCORE_CONTEXT_ALL_EMPTIES_H +#ifndef BLACKCORE_CONTEXT_CONTEXT_ALL_EMPTIES_H +#define BLACKCORE_CONTEXT_CONTEXT_ALL_EMPTIES_H #include "contextapplicationempty.h" #include "contextaudioempty.h" diff --git a/src/blackcore/contextallimpl.h b/src/blackcore/context/contextallimpl.h similarity index 67% rename from src/blackcore/contextallimpl.h rename to src/blackcore/context/contextallimpl.h index c83befdbc..2c233c444 100644 --- a/src/blackcore/contextallimpl.h +++ b/src/blackcore/context/contextallimpl.h @@ -1,5 +1,5 @@ -#ifndef BLACKCORE_CONTEXT_ALL_IMPL_H -#define BLACKCORE_CONTEXT_ALL_IMPL_H +#ifndef BLACKCORE_CONTEXT_CONTEXT_ALL_IMPL_H +#define BLACKCORE_CONTEXT_CONTEXT_ALL_IMPL_H #include "contextapplicationimpl.h" #include "contextaudioimpl.h" diff --git a/src/blackcore/contextallinterfaces.h b/src/blackcore/context/contextallinterfaces.h similarity index 62% rename from src/blackcore/contextallinterfaces.h rename to src/blackcore/context/contextallinterfaces.h index 4f583729c..6d72801ad 100644 --- a/src/blackcore/contextallinterfaces.h +++ b/src/blackcore/context/contextallinterfaces.h @@ -1,5 +1,5 @@ -#ifndef BLACKCORE_CONTEXT_ALL_ITERFACES_H -#define BLACKCORE_CONTEXT_ALL_ITERFACES_H +#ifndef BLACKCORE_CONTEXT_CONTEXT_ALL_ITERFACES_H +#define BLACKCORE_CONTEXT_CONTEXT_ALL_ITERFACES_H #include "contextapplication.h" #include "contextaudio.h" diff --git a/src/blackcore/contextallproxies.h b/src/blackcore/context/contextallproxies.h similarity index 66% rename from src/blackcore/contextallproxies.h rename to src/blackcore/context/contextallproxies.h index 5f319895c..cee4781d9 100644 --- a/src/blackcore/contextallproxies.h +++ b/src/blackcore/context/contextallproxies.h @@ -1,5 +1,5 @@ -#ifndef BLACKCORE_CONTEXT_ALL_PROXIES_H -#define BLACKCORE_CONTEXT_ALL_PROXIES_H +#ifndef BLACKCORE_CONTEXT_CONTEXT_ALL_PROXIES_H +#define BLACKCORE_CONTEXT_CONTEXT_ALL_PROXIES_H #include "contextapplicationproxy.h" #include "contextaudioproxy.h" diff --git a/src/blackcore/context/contextapplication.cpp b/src/blackcore/context/contextapplication.cpp new file mode 100644 index 000000000..d2ec2ff63 --- /dev/null +++ b/src/blackcore/context/contextapplication.cpp @@ -0,0 +1,173 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "blackcore/context/contextapplication.h" +#include "blackcore/context/contextapplicationempty.h" +#include "blackcore/context/contextapplicationimpl.h" +#include "blackcore/context/contextapplicationproxy.h" +#include "blackcore/corefacade.h" +#include "blackcore/inputmanager.h" +#include "blackmisc/dbus.h" +#include "blackmisc/dbusserver.h" +#include "blackmisc/logcategory.h" +#include "blackmisc/loghandler.h" +#include "blackmisc/logmessage.h" +#include "blackmisc/settingscache.h" +#include "blackmisc/statusmessage.h" + +#include +#include + +using namespace BlackCore; +using namespace BlackCore::Context; +using namespace BlackMisc; + +namespace BlackCore +{ + namespace Context + { + IContextApplication *IContextApplication::create(CCoreFacade *parent, CCoreFacadeConfig::ContextMode mode, BlackMisc::CDBusServer *server, QDBusConnection &connection) + { + switch (mode) + { + case CCoreFacadeConfig::Local: + case CCoreFacadeConfig::LocalInDbusServer: + return (new CContextApplication(mode, parent))->registerWithDBus(server); + case CCoreFacadeConfig::Remote: + return new CContextApplicationProxy(BlackMisc::CDBusServer::coreServiceName(), connection, mode, parent); + case CCoreFacadeConfig::NotUsed: + default: + return new CContextApplicationEmpty(parent); + } + } + + IContextApplication::IContextApplication(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : + CContext(mode, runtime) + { + if (mode == CCoreFacadeConfig::NotUsed) { return; } + connect(CLogHandler::instance(), &CLogHandler::localMessageLogged, this, [this](const CStatusMessage & message) + { + this->logMessage(message, {}); + }); + connect(CLogHandler::instance(), &CLogHandler::subscriptionAdded, this, [this](const CLogPattern & pattern) + { + this->addLogSubscription({}, pattern); + }); + connect(CLogHandler::instance(), &CLogHandler::subscriptionRemoved, this, [this](const CLogPattern & pattern) + { + this->removeLogSubscription({}, pattern); + }); + connect(this, &IContextApplication::logSubscriptionAdded, this, [this](const CIdentifier & subscriber, const CLogPattern & pattern) + { + this->m_logSubscriptions[subscriber].push_back(pattern); + }); + connect(this, &IContextApplication::logSubscriptionRemoved, this, [this](const CIdentifier & subscriber, const CLogPattern & pattern) + { + this->m_logSubscriptions[subscriber].removeAll(pattern); + }); + + connect(CSettingsCache::instance(), &CSettingsCache::valuesChangedByLocal, [this](const CValueCachePacket & settings) + { + this->changeSettings(settings, {}); + }); + + connect(this, &IContextApplication::settingsChanged, [](const CValueCachePacket & settings, const CIdentifier & origin) + { + // Intentionally don't check for round trip here + CSettingsCache::instance()->changeValuesFromRemote(settings, origin); + }); + + bool s = connect(CInputManager::instance(), &CInputManager::hotkeyActionRegistered, [this](const QStringList & actions) + { + this->registerHotkeyActions(actions, {}); + }); + Q_ASSERT_X(s, Q_FUNC_INFO, "Connect hotkey action failed"); + Q_UNUSED(s); + + s = connect(this, &IContextApplication::hotkeyActionsRegistered, [this](const QStringList & actions, const CIdentifier & origin) + { + if (origin.isFromSameProcess()) { return; } + CInputManager::instance()->registerRemoteActions(actions); + }); + Q_ASSERT_X(s, Q_FUNC_INFO, "Connect hotkey actions failed"); + Q_UNUSED(s); + + s = connect(CInputManager::instance(), &CInputManager::remoteActionFromLocal, [this](const QString & action, bool argument) + { + this->callHotkeyAction(action, argument, {}); + }); + Q_ASSERT_X(s, Q_FUNC_INFO, "Connect remote action failed"); + Q_UNUSED(s); + + s = connect(this, &IContextApplication::remoteHotkeyAction, [this](const QString & action, bool argument, const CIdentifier & origin) + { + if (origin.isFromLocalMachine()) { return; } + CInputManager::instance()->callFunctionsBy(action, argument); + CLogMessage(this, CLogCategory::contextSlot()).debug() << "Calling function" << action << "from origin" << origin.getMachineName(); + }); + Q_ASSERT_X(s, Q_FUNC_INFO, "Connect remote hotkey action failed"); + Q_UNUSED(s); + + // Enable event forwarding from GUI process to core + CInputManager::instance()->setForwarding(true); + } + + CIdentifierList IContextApplication::subscribersOf(const CStatusMessage &message) const + { + CIdentifierList result; + for (auto it = m_logSubscriptions.begin(); it != m_logSubscriptions.end(); ++it) + { + bool match = std::any_of(it->begin(), it->end(), [&message](const CLogPattern & pattern) { return pattern.match(message); }); + if (match) { result.push_back(it.key()); } + } + return result; + } + + void IContextApplication::changeSettings(const CValueCachePacket &settings, const CIdentifier &origin) + { + Q_UNUSED(settings); + Q_UNUSED(origin); + qFatal("Not implemented"); // avoid losing a change during context interface construction + } + + void IContextApplication::registerHotkeyActions(const QStringList &actions, const BlackMisc::CIdentifier &origin) + { + Q_UNUSED(actions); + Q_UNUSED(origin); + qFatal("Not implemented"); // avoid losing a change during context interface construction + } + + void IContextApplication::callHotkeyAction(const QString &action, bool argument, const BlackMisc::CIdentifier &origin) + { + Q_UNUSED(action); + Q_UNUSED(argument); + Q_UNUSED(origin); + } + + void IContextApplication::changeSettings(uint typeValue) + { + Q_UNUSED(typeValue); + } + } // ns +} // ns + +QDBusArgument &operator <<(QDBusArgument &arg, const BlackCore::Context::CLogSubscriptionHash &hash) +{ + QList listOfPairs; + for (auto it = hash.begin(); it != hash.end(); ++it) { listOfPairs.push_back({ it.key(), it.value() }); } + return arg << listOfPairs; +} + +const QDBusArgument &operator >>(const QDBusArgument &arg, BlackCore::Context::CLogSubscriptionHash &hash) +{ + QList listOfPairs; + arg >> listOfPairs; + for (const auto &pair : listOfPairs) { hash.insert(pair.first, pair.second); } + return arg; +} diff --git a/src/blackcore/context/contextapplication.h b/src/blackcore/context/contextapplication.h new file mode 100644 index 000000000..3df6485d4 --- /dev/null +++ b/src/blackcore/context/contextapplication.h @@ -0,0 +1,226 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKCORE_CONTEXT_CONTEXTAPPLICATION_H +#define BLACKCORE_CONTEXT_CONTEXTAPPLICATION_H + +#include "blackcore/blackcoreexport.h" +#include "blackcore/context/context.h" +#include "blackcore/corefacadeconfig.h" +#include "blackmisc/audio/voiceroomlist.h" +#include "blackmisc/compare.h" +#include "blackmisc/dictionary.h" +#include "blackmisc/identifier.h" +#include "blackmisc/identifierlist.h" +#include "blackmisc/logpattern.h" +#include "blackmisc/statusmessage.h" +#include "blackmisc/valuecache.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//! \addtogroup dbus +//! @{ + +//! DBus interface for context +#define BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME "org.swift_project.blackcore.contextapplication" + +//! DBus object path for context +#define BLACKCORE_CONTEXTAPPLICATION_OBJECTPATH "/application" + +//! @} + +class QDBusConnection; +namespace BlackMisc { class CDBusServer; } +namespace BlackCore +{ + class CCoreFacade; + class CInputManager; + + namespace Context + { + //! Used by application context to track which processes are subscribed to which patterns of log message + using CLogSubscriptionHash = QHash>; + + //! Used when marshalling CLogSubscriptionHash, as a QHash with CIdentifier keys can't be marshalled + using CLogSubscriptionPair = QPair>; + + //! Application context interface + class BLACKCORE_EXPORT IContextApplication : public CContext + { + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME) + + protected: + //! Constructor + IContextApplication(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime); + + public: + //! Service name + static const QString &InterfaceName() + { + static QString s(BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME); + return s; + } + + //! Service path + static const QString &ObjectPath() + { + static QString s(BLACKCORE_CONTEXTAPPLICATION_OBJECTPATH); + return s; + } + + //! \copydoc CContext::getPathAndContextId() + virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); } + + //! Factory method + static IContextApplication *create(CCoreFacade *parent, CCoreFacadeConfig::ContextMode mode, BlackMisc::CDBusServer *server, QDBusConnection &conn); + + //! Destructor + virtual ~IContextApplication() {} + + signals: + //! A component changes + void registrationChanged(); + + //! A log message was logged + //! \note Used with CLogMessage, do not use directly + void messageLogged(const BlackMisc::CStatusMessage &message, const BlackMisc::CIdentifier &origin); + + //! A process subscribed to a particular pattern of log messages + //! \note Used with CLogMessage, do not use directly + void logSubscriptionAdded(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern); + + //! A process unsubscribed from a particular pattern of log messages + //! \note Used with CLogMessage, do not use directly + void logSubscriptionRemoved(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern); + + //! One or more settings were changed + //! \note Used for cache relay, do not use directly + void settingsChanged(const BlackMisc::CValueCachePacket &settings, const BlackMisc::CIdentifier &origin); + + //! New action was registered + //! \note Used to register hotkey action, do not use directly + void hotkeyActionsRegistered(const QStringList &actions, const BlackMisc::CIdentifier &origin); + + //! Call a hotkey action on a remote process + //! \note Used for hotkey action, do not use directly + void remoteHotkeyAction(const QString &action, bool argument, const BlackMisc::CIdentifier &origin); + + //! Work around for audio context, #382 + void fakedSetComVoiceRoom(const BlackMisc::Audio::CVoiceRoomList &requestedRooms); + + protected: + //! Compute which process' subscriptions match a given log message. + BlackMisc::CIdentifierList subscribersOf(const BlackMisc::CStatusMessage &message) const; + + //! Tracks which processes are subscribed to which patterns of log messages. + CLogSubscriptionHash m_logSubscriptions; + + public slots: + //! Log a log message + //! \note Not pure because it can be called from the base class constructor. + //! \note this is the function which relays CLogMessage via DBus + virtual void logMessage(const BlackMisc::CStatusMessage &message, const BlackMisc::CIdentifier &origin) { Q_UNUSED(message); Q_UNUSED(origin); } + + //! Subscribe a process to a particular pattern of log messages + //! \note This is the function which relays subscription changes via DBus + virtual void addLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) = 0; + + //! Unsubscribe a process from a particular pattern of log messages + //! \note This is the function which relays subscription changes via DBus + virtual void removeLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) = 0; + + //! Returns hash identifying which processes are subscribed to which patterns of log message + virtual BlackCore::Context::CLogSubscriptionHash getAllLogSubscriptions() const = 0; + + //! Update log subscriptions hash from core + virtual void synchronizeLogSubscriptions() = 0; + + //! Ratify some settings changed by another process + //! \note Not pure because it can be called from the base class constructor. + //! \note This is the function which relays cache changes via DBus. + virtual void changeSettings(const BlackMisc::CValueCachePacket &settings, const BlackMisc::CIdentifier &origin); + + //! Get all settings currently in core settings cache + virtual BlackMisc::CValueCachePacket getAllSettings() const = 0; + + //! Get keys of all unsaved settings currently in core settings cache + virtual QStringList getUnsavedSettingsKeys() const = 0; + + //! Update local settings with settings from core + virtual void synchronizeLocalSettings() = 0; + + //! Save core settings to disk + virtual BlackMisc::CStatusMessage saveSettings(const QString &keyPrefix = {}) = 0; + + //! Save core settings to disk + virtual BlackMisc::CStatusMessage saveSettingsByKey(const QStringList &keys) = 0; + + //! Load core settings from disk + virtual BlackMisc::CStatusMessage loadSettings() = 0; + + //! Register hotkey action implemented by another process + //! \note Not pure because it can be called from the base class constructor. + //! \note This is the function which relays action registrations via DBus + virtual void registerHotkeyActions(const QStringList &actions, const BlackMisc::CIdentifier &origin); + + //! Call a hotkey action on a remote process + //! \note Not pure because it can be called from the base class constructor. + //! \note This is the function which relays action calls via DBus + virtual void callHotkeyAction(const QString &action, bool argument, const BlackMisc::CIdentifier &origin); + + //! Register application, can also be used for ping + virtual BlackMisc::CIdentifier registerApplication(const BlackMisc::CIdentifier &application) = 0; + + //! Unregister application + virtual void unregisterApplication(const BlackMisc::CIdentifier &application) = 0; + + //! All registered applications + virtual BlackMisc::CIdentifierList getRegisteredApplications() const = 0; + + //! Remote enabled version of writing a text file + virtual bool writeToFile(const QString &fileName, const QString &content) = 0; + + //! Remote enabled version of reading a text file + virtual QString readFromFile(const QString &fileName) const = 0; + + //! Remote enabled version of deleting a file + virtual bool removeFile(const QString &fileName) = 0; + + //! Remote enabled version of file exists + virtual bool existsFile(const QString &fileName) const = 0; + + //! Change settings + //! \todo Remove with old settings + void changeSettings(uint typeValue); + + }; + } // ns +} // ns + +//! DBus marshalling for CLogSubscriptionHash, needed because QtDBus can't marshal a QHash with CIdentifier keys. +QDBusArgument &operator <<(QDBusArgument &arg, const BlackCore::Context::CLogSubscriptionHash &); + +//! DBus unmarshalling for CLogSubscriptionHash, needed because QtDBus can't marshal a QHash with CIdentifier keys. +const QDBusArgument &operator >>(const QDBusArgument &arg, BlackCore::Context::CLogSubscriptionHash &); + +Q_DECLARE_METATYPE(BlackCore::Context::CLogSubscriptionHash) +Q_DECLARE_METATYPE(BlackCore::Context::CLogSubscriptionPair) + +#endif // guard diff --git a/src/blackcore/context/contextapplicationempty.h b/src/blackcore/context/contextapplicationempty.h new file mode 100644 index 000000000..6e1d09c40 --- /dev/null +++ b/src/blackcore/context/contextapplicationempty.h @@ -0,0 +1,196 @@ +/* Copyright (C) 2015 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKCORE_CONTEXTAPPLICATION_EMPTY_H +#define BLACKCORE_CONTEXTAPPLICATION_EMPTY_H + +#include "blackcoreexport.h" +#include "contextapplication.h" +#include "corefacade.h" +#include "blackmisc/identifierlist.h" + +namespace BlackCore +{ + class CCoreFacade; + namespace Context + { + //! Application context + class BLACKCORE_EXPORT CContextApplicationEmpty : public IContextApplication + { + public: + //! Constructor + CContextApplicationEmpty(CCoreFacade *runtime) : IContextApplication(CCoreFacadeConfig::NotUsed, runtime) {} + + public slots: + //! \copydoc IContextApplication::logMessage + virtual void logMessage(const BlackMisc::CStatusMessage &message, const BlackMisc::CIdentifier &origin) override + { + Q_UNUSED(message); + Q_UNUSED(origin); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextApplication::addLogSubscription + virtual void addLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) override + { + Q_UNUSED(subscriber); + Q_UNUSED(pattern); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextApplication::removeLogSubscription + virtual void removeLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) override + { + Q_UNUSED(subscriber); + Q_UNUSED(pattern); + logEmptyContextWarning(Q_FUNC_INFO); + + } + + //! \copydoc IContextApplication::getAllLogSubscriptions + virtual CLogSubscriptionHash getAllLogSubscriptions() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return CLogSubscriptionHash(); + } + + //! \copydoc IContextApplication::synchronizeLogSubscriptions + virtual void synchronizeLogSubscriptions() override + { + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextApplication::changeSettings + virtual void changeSettings(const BlackMisc::CValueCachePacket &settings, const BlackMisc::CIdentifier &origin) override + { + Q_UNUSED(settings); + Q_UNUSED(origin); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextApplication::getAllSettings + virtual BlackMisc::CValueCachePacket getAllSettings() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::CValueCachePacket(); + } + + //! \copydoc IContextApplication::getUnsavedSettingsKeys + virtual QStringList getUnsavedSettingsKeys() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return QStringList(); + } + + //! \copydoc IContextApplication::synchronizeLocalSettings + virtual void synchronizeLocalSettings() override + { + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextApplication::saveSettings + virtual BlackMisc::CStatusMessage saveSettings(const QString &keyPrefix = {}) override + { + Q_UNUSED(keyPrefix); + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::CStatusMessage(); + } + + //! \copydoc IContextApplication::saveSettingsByKey + virtual BlackMisc::CStatusMessage saveSettingsByKey(const QStringList &keys) override + { + Q_UNUSED(keys); + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::CStatusMessage(); + } + + //! \copydoc IContextApplication::loadSettings + virtual BlackMisc::CStatusMessage loadSettings() override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::CStatusMessage(); + } + + //! \copydoc IContextApplication::registerHotkeyActions + virtual void registerHotkeyActions(const QStringList &actions, const BlackMisc::CIdentifier &origin) override + { + Q_UNUSED(actions); + Q_UNUSED(origin); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextApplication::callHotkeyAction + virtual void callHotkeyAction(const QString &action, bool argument, const BlackMisc::CIdentifier &origin) override + { + Q_UNUSED(action); + Q_UNUSED(argument); + Q_UNUSED(origin); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextApplication::writeToFile + virtual bool writeToFile(const QString &fileName, const QString &content) override + { + Q_UNUSED(fileName); + Q_UNUSED(content); + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + + //! \copydoc IContextApplication::registerApplication + virtual BlackMisc::CIdentifier registerApplication(const BlackMisc::CIdentifier &application) override + { + Q_UNUSED(application); + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::CIdentifier(); + } + + //! \copydoc IContextApplication::unregisterApplication + virtual void unregisterApplication(const BlackMisc::CIdentifier &application) override + { + Q_UNUSED(application); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextApplication::getRegisteredApplications + virtual BlackMisc::CIdentifierList getRegisteredApplications() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::CIdentifierList(); + } + + //! \copydoc IContextApplication::readFromFile + virtual QString readFromFile(const QString &fileName) const override + { + Q_UNUSED(fileName); + logEmptyContextWarning(Q_FUNC_INFO); + return QString(); + } + + //! \copydoc IContextApplication::removeFile + virtual bool removeFile(const QString &fileName) override + { + Q_UNUSED(fileName); + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + + //! \copydoc IContextApplication::existsFile + virtual bool existsFile(const QString &fileName) const override + { + Q_UNUSED(fileName); + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + }; + } // namespace +} // namespace +#endif // guard diff --git a/src/blackcore/context/contextapplicationimpl.cpp b/src/blackcore/context/contextapplicationimpl.cpp new file mode 100644 index 000000000..091c4535e --- /dev/null +++ b/src/blackcore/context/contextapplicationimpl.cpp @@ -0,0 +1,205 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "blackcore/context/contextapplicationimpl.h" +#include "blackcore/inputmanager.h" +#include "blackmisc/dbusserver.h" +#include "blackmisc/logcategory.h" +#include "blackmisc/loghandler.h" +#include "blackmisc/logmessage.h" +#include "blackmisc/settingscache.h" + +#include +#include +#include +#include +#include + +using namespace BlackMisc; + +namespace BlackCore +{ + namespace Context + { + CContextApplication::CContextApplication(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : + IContextApplication(mode, runtime) + { } + + CContextApplication *CContextApplication::registerWithDBus(BlackMisc::CDBusServer *server) + { + if (!server || this->m_mode != CCoreFacadeConfig::LocalInDbusServer) { return this; } + server->addObject(IContextApplication::ObjectPath(), this); + return this; + } + + void CContextApplication::logMessage(const CStatusMessage &message, const CIdentifier &origin) + { + if (!origin.isFromSameProcess()) + { + CLogHandler::instance()->logRemoteMessage(message); + } + if (subscribersOf(message).containsAnyNotIn(CIdentifierList({ origin, {} }))) + { + emit this->messageLogged(message, origin); + } + } + + void CContextApplication::addLogSubscription(const CIdentifier &subscriber, const CLogPattern &pattern) + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + emit this->logSubscriptionAdded(subscriber, pattern); + } + + void CContextApplication::removeLogSubscription(const CIdentifier &subscriber, const CLogPattern &pattern) + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + emit this->logSubscriptionRemoved(subscriber, pattern); + } + + CLogSubscriptionHash CContextApplication::getAllLogSubscriptions() const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + return m_logSubscriptions; + } + + void CContextApplication::synchronizeLogSubscriptions() + { + // no-op: proxy implements this method by calling getAllLogSubscriptions + } + + void CContextApplication::changeSettings(const CValueCachePacket &settings, const CIdentifier &origin) + { + // Intentionally don't check for round trip here + emit this->settingsChanged(settings, origin); + } + + BlackMisc::CValueCachePacket CContextApplication::getAllSettings() const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + return CSettingsCache::instance()->getAllValuesWithTimestamps(); + } + + QStringList CContextApplication::getUnsavedSettingsKeys() const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + return CSettingsCache::instance()->getAllUnsavedKeys(); + } + + void CContextApplication::synchronizeLocalSettings() + { + // no-op: proxy implements this method by calling getAllSettings + } + + BlackMisc::CStatusMessage CContextApplication::saveSettings(const QString &keyPrefix) + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << keyPrefix; } + return CSettingsCache::instance()->saveToStore(keyPrefix); + } + + BlackMisc::CStatusMessage CContextApplication::saveSettingsByKey(const QStringList &keys) + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << keys.join(", "); } + return CSettingsCache::instance()->saveToStore(keys); + } + + BlackMisc::CStatusMessage CContextApplication::loadSettings() + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + return CSettingsCache::instance()->loadFromStore(); + } + + void CContextApplication::registerHotkeyActions(const QStringList &actions, const CIdentifier &origin) + { + // Intentionally don't check for round trip here + emit this->hotkeyActionsRegistered(actions, origin); + } + + void CContextApplication::callHotkeyAction(const QString &action, bool argument, const CIdentifier &origin) + { + // Intentionally don't check for round trip here + emit this->remoteHotkeyAction(action, argument, origin); + } + + bool CContextApplication::writeToFile(const QString &fileName, const QString &content) + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << fileName << content.left(25); } + if (fileName.isEmpty()) { return false; } + QFile file(fileName); + if (file.open(QIODevice::WriteOnly | QIODevice::Text)) + { + QTextStream out(&file); + out << content; + return true; + } + else + { + return false; + } + } + + CIdentifier CContextApplication::registerApplication(const CIdentifier &application) + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << application; } + if (!m_registeredApplications.contains(application)) + { + m_registeredApplications.push_back(application); + emit registrationChanged(); + emit this->hotkeyActionsRegistered(CInputManager::instance()->allAvailableActions(), {}); + } + else + { + m_registeredApplications.replace(application, application); + } + + return application; + } + + void CContextApplication::unregisterApplication(const CIdentifier &application) + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << application; } + int r = this->m_registeredApplications.remove(application); + if (r > 0) { emit registrationChanged(); } + } + + CIdentifierList CContextApplication::getRegisteredApplications() const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + return m_registeredApplications; + } + + QString CContextApplication::readFromFile(const QString &fileName) const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << fileName; } + QFile file(fileName); + QString content; + if (fileName.isEmpty()) return content; + if (file.open(QIODevice::ReadOnly | QIODevice::Text)) + { + QTextStream in(&file); + in >> content; + file.close(); + } + return content; + } + + bool CContextApplication::removeFile(const QString &fileName) + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << fileName; } + if (fileName.isEmpty()) { return false; } + return QFile::remove(fileName); + } + + bool CContextApplication::existsFile(const QString &fileName) const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << fileName; } + if (fileName.isEmpty()) return false; + return QFile::exists(fileName); + } + } // ns +} // ns diff --git a/src/blackcore/context/contextapplicationimpl.h b/src/blackcore/context/contextapplicationimpl.h new file mode 100644 index 000000000..923627b02 --- /dev/null +++ b/src/blackcore/context/contextapplicationimpl.h @@ -0,0 +1,126 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKCORE_CONTEXT_CONTEXTAPPLICATION_IMPL_H +#define BLACKCORE_CONTEXT_CONTEXTAPPLICATION_IMPL_H + +#include +#include +#include + +#include "blackcore/blackcoreexport.h" +#include "blackcore/context/contextapplication.h" +#include "blackcore/corefacadeconfig.h" +#include "blackmisc/identifier.h" +#include "blackmisc/identifierlist.h" +#include "blackmisc/statusmessage.h" +#include "blackmisc/valuecache.h" + +namespace BlackMisc +{ + class CDBusServer; + class CLogPattern; +} + +namespace BlackCore +{ + class CCoreFacade; + namespace Context + { + //! Application context + class BLACKCORE_EXPORT CContextApplication : public IContextApplication + { + Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME) + Q_OBJECT + friend class BlackCore::CCoreFacade; + friend class IContextApplication; + + public slots: + //! \copydoc IContextApplication::logMessage + virtual void logMessage(const BlackMisc::CStatusMessage &message, const BlackMisc::CIdentifier &origin) override; + + //! \copydoc IContextApplication::addLogSubscription + virtual void addLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) override; + + //! \copydoc IContextApplication::removeLogSubscription + virtual void removeLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) override; + + //! \copydoc IContextApplication::getAllLogSubscriptions + virtual CLogSubscriptionHash getAllLogSubscriptions() const override; + + //! \copydoc IContextApplication::synchronizeLogSubscriptions + virtual void synchronizeLogSubscriptions() override; + + //! \copydoc IContextApplication::changeSettings + virtual void changeSettings(const BlackMisc::CValueCachePacket &settings, const BlackMisc::CIdentifier &origin) override; + + //! \copydoc IContextApplication::getAllSettings + virtual BlackMisc::CValueCachePacket getAllSettings() const override; + + //! \copydoc IContextApplication::getUnsavedSettingsKeys + virtual QStringList getUnsavedSettingsKeys() const override; + + //! \copydoc IContextApplication::synchronizeLocalSettings + virtual void synchronizeLocalSettings() override; + + //! \copydoc IContextApplication::saveSettings + virtual BlackMisc::CStatusMessage saveSettings(const QString &keyPrefix = {}) override; + + //! \copydoc IContextApplication::saveSettingsByKey + virtual BlackMisc::CStatusMessage saveSettingsByKey(const QStringList &keys) override; + + //! \copydoc IContextApplication::loadSettings + virtual BlackMisc::CStatusMessage loadSettings() override; + + //! \copydoc IContextApplication::registerHotkeyActions + virtual void registerHotkeyActions(const QStringList &actions, const BlackMisc::CIdentifier &origin) override; + + //! \copydoc IContextApplication::callHotkeyAction + virtual void callHotkeyAction(const QString &action, bool argument, const BlackMisc::CIdentifier &origin) override; + + //! \copydoc IContextApplication::writeToFile + virtual bool writeToFile(const QString &fileName, const QString &content) override; + + //! \copydoc IContextApplication::registerApplication + virtual BlackMisc::CIdentifier registerApplication(const BlackMisc::CIdentifier &application) override; + + //! \copydoc IContextApplication::unregisterApplication + virtual void unregisterApplication(const BlackMisc::CIdentifier &application) override; + + //! \copydoc IContextApplication::getRegisteredApplications + virtual BlackMisc::CIdentifierList getRegisteredApplications() const override; + + //! \copydoc IContextApplication::readFromFile + virtual QString readFromFile(const QString &fileName) const override; + + //! \copydoc IContextApplication::removeFile + virtual bool removeFile(const QString &fileName) override; + + //! \copydoc IContextApplication::existsFile + virtual bool existsFile(const QString &fileName) const override; + + public: + //! \todo Remove with old settings + using IContextApplication::changeSettings; + + protected: + //! Constructor + CContextApplication(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime); + + //! Register myself in DBus, fail safe + CContextApplication *registerWithDBus(BlackMisc::CDBusServer *server); + + private: + BlackMisc::CIdentifierList m_registeredApplications; + }; + } // namespace +} // namespace +#endif // guard diff --git a/src/blackcore/context/contextapplicationproxy.cpp b/src/blackcore/context/contextapplicationproxy.cpp new file mode 100644 index 000000000..b704b7586 --- /dev/null +++ b/src/blackcore/context/contextapplicationproxy.cpp @@ -0,0 +1,182 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "blackcore/context/contextapplicationproxy.h" +#include "blackmisc/dbus.h" +#include "blackmisc/genericdbusinterface.h" +#include "blackmisc/identifierlist.h" +#include "blackmisc/loghandler.h" +#include "blackmisc/settingscache.h" + +#include +#include +#include +#include + +using namespace BlackMisc; +namespace BlackCore +{ + namespace Context + { + CContextApplicationProxy::CContextApplicationProxy(const QString &serviceName, QDBusConnection &connection, CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextApplication(mode, runtime), m_dBusInterface(nullptr) + { + this->m_dBusInterface = new CGenericDBusInterface(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(), connection, this); + this->relaySignals(serviceName, connection); + + connect(this, &IContextApplication::messageLogged, this, [](const CStatusMessage & message, const CIdentifier & origin) + { + if (!origin.isFromSameProcess()) + { + CLogHandler::instance()->logRemoteMessage(message); + } + }); + } + + void CContextApplicationProxy::relaySignals(const QString &serviceName, QDBusConnection &connection) + { + // signals originating from impl side + bool s = connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(), + "messageLogged", this, SIGNAL(messageLogged(BlackMisc::CStatusMessage, BlackMisc::CIdentifier))); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(), + "logSubscriptionAdded", this, SIGNAL(logSubscriptionAdded(BlackMisc::CIdentifier, BlackMisc::CLogPattern))); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(), + "logSubscriptionRemoved", this, SIGNAL(logSubscriptionRemoved(BlackMisc::CIdentifier, BlackMisc::CLogPattern))); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(), + "settingsChanged", this, SIGNAL(settingsChanged(BlackMisc::CValueCachePacket, BlackMisc::CIdentifier))); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(), + "registrationChanged", this, SIGNAL(registrationChanged())); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(), + "fakedSetComVoiceRoom", this, SIGNAL(fakedSetComVoiceRoom(BlackMisc::Audio::CVoiceRoomList))); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(), + "hotkeyActionsRegistered", this, SIGNAL(hotkeyActionsRegistered(QStringList, BlackMisc::CIdentifier))); + Q_UNUSED(s); + } + + void CContextApplicationProxy::logMessage(const CStatusMessage &message, const CIdentifier &origin) + { + if (subscribersOf(message).containsAnyNotIn(CIdentifierList({ origin, {} }))) + { + this->m_dBusInterface->callDBus(QLatin1Literal("logMessage"), message, origin); + } + } + + void CContextApplicationProxy::addLogSubscription(const CIdentifier &subscriber, const CLogPattern &pattern) + { + this->m_dBusInterface->callDBus(QLatin1Literal("addLogSubscription"), subscriber, pattern); + } + + void CContextApplicationProxy::removeLogSubscription(const CIdentifier &subscriber, const CLogPattern &pattern) + { + this->m_dBusInterface->callDBus(QLatin1Literal("removeLogSubscription"), subscriber, pattern); + } + + CLogSubscriptionHash CContextApplicationProxy::getAllLogSubscriptions() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getAllLogSubscriptions")); + } + + void CContextApplicationProxy::synchronizeLogSubscriptions() + { + // note this proxy method does not call synchronizeLogSubscriptions in core + m_logSubscriptions = getAllLogSubscriptions(); + for (const auto &pattern : CLogHandler::instance()->getAllSubscriptions()) { this->addLogSubscription({}, pattern); } + } + + void CContextApplicationProxy::changeSettings(const CValueCachePacket &settings, const CIdentifier &origin) + { + this->m_dBusInterface->callDBus(QLatin1Literal("changeSettings"), settings, origin); + } + + BlackMisc::CValueCachePacket CContextApplicationProxy::getAllSettings() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getAllSettings")); + } + + QStringList CContextApplicationProxy::getUnsavedSettingsKeys() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getUnsavedSettingsKeys")); + } + + void CContextApplicationProxy::synchronizeLocalSettings() + { + // note this proxy method does not call synchronizeLocalSettings in core + CSettingsCache::instance()->changeValuesFromRemote(this->getAllSettings(), CIdentifier::anonymous()); + } + + BlackMisc::CStatusMessage CContextApplicationProxy::saveSettings(const QString &keyPrefix) + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("saveSettings"), keyPrefix); + } + + BlackMisc::CStatusMessage CContextApplicationProxy::saveSettingsByKey(const QStringList &keys) + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("saveSettingsByKey"), keys); + } + + BlackMisc::CStatusMessage CContextApplicationProxy::loadSettings() + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("loadSettings")); + } + + void CContextApplicationProxy::registerHotkeyActions(const QStringList &actions, const CIdentifier &origin) + { + this->m_dBusInterface->callDBus(QLatin1Literal("registerHotkeyActions"), actions, origin); + } + + void CContextApplicationProxy::callHotkeyAction(const QString &action, bool argument, const CIdentifier &origin) + { + this->m_dBusInterface->callDBus(QLatin1Literal("callHotkeyAction"), action, argument, origin); + } + + BlackMisc::CIdentifier CContextApplicationProxy::registerApplication(const CIdentifier &application) + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("registerApplication"), application); + } + + void CContextApplicationProxy::unregisterApplication(const CIdentifier &application) + { + this->m_dBusInterface->callDBus(QLatin1Literal("unregisterApplication"), application); + } + + BlackMisc::CIdentifierList CContextApplicationProxy::getRegisteredApplications() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getRegisteredApplications")); + } + + bool CContextApplicationProxy::writeToFile(const QString &fileName, const QString &content) + { + if (fileName.isEmpty()) { return false; } + return this->m_dBusInterface->callDBusRet(QLatin1Literal("writeToFile"), fileName, content); + } + + QString CContextApplicationProxy::readFromFile(const QString &fileName) const + { + if (fileName.isEmpty()) { return ""; } + return this->m_dBusInterface->callDBusRet(QLatin1Literal("readFromFile"), fileName); + } + + bool CContextApplicationProxy::removeFile(const QString &fileName) + { + if (fileName.isEmpty()) { return false; } + return this->m_dBusInterface->callDBusRet(QLatin1Literal("removeFile"), fileName); + } + + bool CContextApplicationProxy::existsFile(const QString &fileName) const + { + if (fileName.isEmpty()) { return false; } + return this->m_dBusInterface->callDBusRet(QLatin1Literal("existsFile"), fileName); + } + } // namespace +} // namespace diff --git a/src/blackcore/context/contextapplicationproxy.h b/src/blackcore/context/contextapplicationproxy.h new file mode 100644 index 000000000..b92140853 --- /dev/null +++ b/src/blackcore/context/contextapplicationproxy.h @@ -0,0 +1,134 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKCORE_CONTEXT_CONTEXTAPPLICATION_PROXY_H +#define BLACKCORE_CONTEXT_CONTEXTAPPLICATION_PROXY_H + +#include +#include +#include + +#include "blackcore/blackcoreexport.h" +#include "blackcore/context/contextapplication.h" +#include "blackcore/corefacadeconfig.h" +#include "blackmisc/identifier.h" +#include "blackmisc/identifierlist.h" +#include "blackmisc/statusmessage.h" +#include "blackmisc/valuecache.h" + +class QDBusConnection; + +namespace BlackMisc +{ + class CGenericDBusInterface; + class CLogPattern; +} + +namespace BlackCore +{ + class CCoreFacade; + namespace Context + { + //! Application context proxy + //! \ingroup dbus + class BLACKCORE_EXPORT CContextApplicationProxy : public IContextApplication + { + Q_OBJECT + friend class IContextApplication; + + public: + //! Destructor + virtual ~CContextApplicationProxy() {} + + //! \todo Remove with old settings + using IContextApplication::changeSettings; + + public slots: + //! \copydoc IContextApplication::logMessage + virtual void logMessage(const BlackMisc::CStatusMessage &message, const BlackMisc::CIdentifier &origin) override; + + //! \copydoc IContextApplication::addLogSubscription + virtual void addLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) override; + + //! \copydoc IContextApplication::removeLogSubscription + virtual void removeLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) override; + + //! \copydoc IContextApplication::getAllLogSubscriptions + virtual CLogSubscriptionHash getAllLogSubscriptions() const override; + + //! \copydoc IContextApplication::synchronizeLogSubscriptions + virtual void synchronizeLogSubscriptions() override; + + //! \copydoc IContextApplication::changeSettings + virtual void changeSettings(const BlackMisc::CValueCachePacket &settings, const BlackMisc::CIdentifier &origin) override; + + //! \copydoc IContextApplication::getAllSettings + virtual BlackMisc::CValueCachePacket getAllSettings() const override; + + //! \copydoc IContextApplication::getUnsavedSettingsKeys + virtual QStringList getUnsavedSettingsKeys() const override; + + //! \copydoc IContextApplication::synchronizeLocalSettings + virtual void synchronizeLocalSettings() override; + + //! \copydoc IContextApplication::saveSettings + virtual BlackMisc::CStatusMessage saveSettings(const QString &keyPrefix = {}) override; + + //! \copydoc IContextApplication::saveSettingsByKey + virtual BlackMisc::CStatusMessage saveSettingsByKey(const QStringList &keys) override; + + //! \copydoc IContextApplication::loadSettings + virtual BlackMisc::CStatusMessage loadSettings() override; + + //! \copydoc IContextApplication::registerHotkeyActions + virtual void registerHotkeyActions(const QStringList &actions, const BlackMisc::CIdentifier &origin) override; + + //! \copydoc IContextApplication::callHotkeyAction + virtual void callHotkeyAction(const QString &action, bool argument, const BlackMisc::CIdentifier &origin) override; + + //! \copydoc IContextApplication::registerApplication + virtual BlackMisc::CIdentifier registerApplication(const BlackMisc::CIdentifier &application) override; + + //! \copydoc IContextApplication::unregisterApplication + virtual void unregisterApplication(const BlackMisc::CIdentifier &application) override; + + //! \copydoc IContextApplication::getRegisteredApplications + virtual BlackMisc::CIdentifierList getRegisteredApplications() const override; + + //! \copydoc IContextApplication::writeToFile + virtual bool writeToFile(const QString &fileName, const QString &content) override; + + //! \copydoc IContextApplication::readFromFile + virtual QString readFromFile(const QString &fileName) const override; + + //! \copydoc IContextApplication::removeFile + virtual bool removeFile(const QString &fileName) override; + + //! \copydoc IContextApplication::existsFile + virtual bool existsFile(const QString &fileName) const override; + + protected: + //! Constructor + CContextApplicationProxy(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextApplication(mode, runtime), m_dBusInterface(nullptr) {} + + //! DBus version constructor + CContextApplicationProxy(const QString &serviceName, QDBusConnection &connection, CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime); + + private: + BlackMisc::CGenericDBusInterface *m_dBusInterface; + + //! Relay connection signals to local signals + void relaySignals(const QString &serviceName, QDBusConnection &connection); + }; + } // ns +} // ns + +#endif // guard diff --git a/src/blackcore/context/contextaudio.cpp b/src/blackcore/context/contextaudio.cpp new file mode 100644 index 000000000..5a7365138 --- /dev/null +++ b/src/blackcore/context/contextaudio.cpp @@ -0,0 +1,36 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "contextaudio.h" + +#include "blackcore/context/contextaudio.h" +#include "blackcore/context/contextaudioempty.h" +#include "blackcore/context/contextaudioimpl.h" +#include "blackcore/context/contextaudioproxy.h" +#include "blackmisc/dbusserver.h" + +namespace BlackCore +{ + namespace Context + { + IContextAudio *IContextAudio::create(CCoreFacade *runtime, CCoreFacadeConfig::ContextMode mode, BlackMisc::CDBusServer *server, QDBusConnection &conn) + { + switch (mode) + { + case CCoreFacadeConfig::Local: + case CCoreFacadeConfig::LocalInDbusServer: + return (new CContextAudio(mode, runtime))->registerWithDBus(server); + case CCoreFacadeConfig::Remote: + return new CContextAudioProxy(BlackMisc::CDBusServer::coreServiceName(), conn, mode, runtime); + default: + return new CContextAudioEmpty(runtime); // audio not mandatory + } + } + } // ns +} // ns diff --git a/src/blackcore/context/contextaudio.h b/src/blackcore/context/contextaudio.h new file mode 100644 index 000000000..1c348978c --- /dev/null +++ b/src/blackcore/context/contextaudio.h @@ -0,0 +1,180 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKCORE_CONTEXT_CONTEXTAUDIO_H +#define BLACKCORE_CONTEXT_CONTEXTAUDIO_H + +#include "blackcore/blackcoreexport.h" +#include "blackcore/context/context.h" +#include "blackcore/corefacade.h" +#include "blackcore/corefacadeconfig.h" +#include "blackmisc/audio/audiodeviceinfolist.h" +#include "blackmisc/audio/notificationsounds.h" +#include "blackmisc/audio/voiceroom.h" +#include "blackmisc/audio/voiceroomlist.h" +#include "blackmisc/aviation/callsignset.h" +#include "blackmisc/aviation/comsystem.h" +#include "blackmisc/aviation/selcal.h" +#include "blackmisc/identifier.h" +#include "blackmisc/network/userlist.h" + +#include +#include + +class QDBusConnection; + +namespace BlackMisc +{ + class CDBusServer; + namespace Audio { class CAudioDeviceInfo; } + namespace Aviation { class CCallsign; } +} + +//! \addtogroup dbus +//! @{ + +//! DBus interface for context +#define BLACKCORE_CONTEXTAUDIO_INTERFACENAME "org.swift_project.blackcore.contextaudio" + +//! DBus object path for context +#define BLACKCORE_CONTEXTAUDIO_OBJECTPATH "/audio" + +//! @} + +namespace BlackCore +{ + namespace Context + { + //! Audio context interface + class BLACKCORE_EXPORT IContextAudio : public CContext + { + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAUDIO_INTERFACENAME) + + protected: + //! Constructor + IContextAudio(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : CContext(mode, runtime) {} + + public: + //! Interface name + static const QString &InterfaceName() + { + static QString s(BLACKCORE_CONTEXTAUDIO_INTERFACENAME); + return s; + } + + //! Object path + static const QString &ObjectPath() + { + static QString s(BLACKCORE_CONTEXTAUDIO_OBJECTPATH); + return s; + } + + //! \copydoc CContext::getPathAndContextId() + virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); } + + //! Factory method + static IContextAudio *create(CCoreFacade *runtime, CCoreFacadeConfig::ContextMode mode, BlackMisc::CDBusServer *server, QDBusConnection &conn); + + //! Destructor + virtual ~IContextAudio() {} + + signals: + + //! Voice rooms changed + //! \details the flag indicates, whether a room got connected or disconnected + void changedVoiceRooms(const BlackMisc::Audio::CVoiceRoomList &voiceRooms, bool connected); + + //! Voice room members changed + void changedVoiceRoomMembers(); + + //! Audio volume changed + //! \sa setVoiceOutputVolume + void changedAudioVolume(int volume); + + //! Mute changed + void changedMute(bool muted); + + //! Changed audio devices (e.g. device enabled/disable) + void changedAudioDevices(const BlackMisc::Audio::CAudioDeviceInfoList &devices); + + //! Changed slection of audio devices + void changedSelectedAudioDevices(const BlackMisc::Audio::CAudioDeviceInfoList &devices); + + public slots: + //! Get voice rooms for COM1, COM2: + virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRoomsWithAudioStatus() const = 0; + + //! Get voice rooms for COM1, COM2, but without latest audio status + virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRooms() const = 0; + + //! Get voice room per com unit + virtual BlackMisc::Audio::CVoiceRoom getVoiceRoom(BlackMisc::Aviation::CComSystem::ComUnit comUnit, bool withAudioStatus) const = 0; + + //! Set voice rooms + virtual void setComVoiceRooms(const BlackMisc::Audio::CVoiceRoomList &voiceRooms) = 0; + + //! Own callsign as displayed in voice room + virtual void setOwnCallsignForRooms(const BlackMisc::Aviation::CCallsign &callsign) = 0; + + //! Leave all voice rooms + virtual void leaveAllVoiceRooms() = 0; + + //! Room user callsigns + virtual BlackMisc::Aviation::CCallsignSet getRoomCallsigns(BlackMisc::Aviation::CComSystem::ComUnit comUnit) const = 0; + + //! Room users + virtual BlackMisc::Network::CUserList getRoomUsers(BlackMisc::Aviation::CComSystem::ComUnit comUnit) const = 0; + + //! Audio devices + virtual BlackMisc::Audio::CAudioDeviceInfoList getAudioDevices() const = 0; + + //! Get current audio device + //! \return input and output devices + virtual BlackMisc::Audio::CAudioDeviceInfoList getCurrentAudioDevices() const = 0; + + //! Set current audio device + //! \param audioDevice can be input or audio device + virtual void setCurrentAudioDevice(const BlackMisc::Audio::CAudioDeviceInfo &audioDevice) = 0; + + //! Set voice output volume (0..300) + virtual void setVoiceOutputVolume(int volume) = 0; + + //! Voice output volume (0..300) + virtual int getVoiceOutputVolume() const = 0; + + //! Set mute state + virtual void setMute(bool mute) = 0; + + //! Is muted? + virtual bool isMuted() const = 0; + + //! Play SELCAL tone + virtual void playSelcalTone(const BlackMisc::Aviation::CSelcal &selcal) const = 0; + + //! Play notification sound + //! \param notification CSoundGenerator::Notification + //! \param considerSettings consider settings (notification on/off), false means settings ignored + virtual void playNotification(BlackMisc::Audio::CNotificationSounds::Notification notification, bool considerSettings) const = 0; + + //! Enable audio loopback + virtual void enableAudioLoopback(bool enable = true) = 0; + + //! Is loobback enabled? + virtual bool isAudioLoopbackEnabled() const = 0; + + //! Command line was entered + virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) = 0; + }; + } // ns +} // ns + +#endif // guard diff --git a/src/blackcore/context/contextaudioempty.h b/src/blackcore/context/contextaudioempty.h new file mode 100644 index 000000000..2ef6c5e5e --- /dev/null +++ b/src/blackcore/context/contextaudioempty.h @@ -0,0 +1,182 @@ +/* Copyright (C) 2015 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKCORE_CONTEXTAUDIO_EMPTY_H +#define BLACKCORE_CONTEXTAUDIO_EMPTY_H + +#include "blackcoreexport.h" +#include "contextaudio.h" +#include "voice.h" + +namespace BlackCore +{ + class IVoiceChannel; + namespace Context + { + + //! Audio context implementation + class BLACKCORE_EXPORT CContextAudioEmpty : public IContextAudio + { + public: + //! Constructor + CContextAudioEmpty(CCoreFacade *runtime) : IContextAudio(CCoreFacadeConfig::NotUsed, runtime) {} + + public slots: + //! \copydoc IContextAudio::getComVoiceRooms() + virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRooms() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Audio::CVoiceRoomList(); + } + + //! \copydoc IContextAudio::getComVoiceRoomsWithAudioStatus() + virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRoomsWithAudioStatus() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Audio::CVoiceRoomList(); + } + + //! \copydoc IContextAudio::getVoiceRoom + virtual BlackMisc::Audio::CVoiceRoom getVoiceRoom(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue, bool withAudioStatus) const override + { + Q_UNUSED(comUnitValue); + Q_UNUSED(withAudioStatus); + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Audio::CVoiceRoom(); + } + + //! \copydoc IContextAudio::setComVoiceRooms + virtual void setComVoiceRooms(const BlackMisc::Audio::CVoiceRoomList &newRooms) override + { + Q_UNUSED(newRooms); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextAudio::setOwnCallsignForRooms + virtual void setOwnCallsignForRooms(const BlackMisc::Aviation::CCallsign &callsign) override + { + Q_UNUSED(callsign); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextAudio::getRoomCallsigns() + virtual BlackMisc::Aviation::CCallsignSet getRoomCallsigns(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue) const override + { + Q_UNUSED(comUnitValue); + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Aviation::CCallsignSet(); + } + + //! \copydoc IContextAudio::getRoomUsers() + virtual BlackMisc::Network::CUserList getRoomUsers(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue) const override + { + Q_UNUSED(comUnitValue); + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Network::CUserList(); + } + + //! \copydoc IContextAudio::leaveAllVoiceRooms + virtual void leaveAllVoiceRooms() override + { + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextAudio::getAudioDevices() + virtual BlackMisc::Audio::CAudioDeviceInfoList getAudioDevices() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Audio::CAudioDeviceInfoList(); + } + + //! \copydoc IContextAudio::getCurrentAudioDevices() + virtual BlackMisc::Audio::CAudioDeviceInfoList getCurrentAudioDevices() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Audio::CAudioDeviceInfoList(); + } + + //! \copydoc IContextAudio::setCurrentAudioDevice() + virtual void setCurrentAudioDevice(const BlackMisc::Audio::CAudioDeviceInfo &audioDevice) override + { + Q_UNUSED(audioDevice); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextAudio::setVoiceOutputVolume + virtual void setVoiceOutputVolume(int volume) override + { + Q_UNUSED(volume); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextAudio::getVoiceOutputVolume + virtual int getVoiceOutputVolume() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return 0; + } + + //! \copydoc IContextAudio::setMute + virtual void setMute(bool muted) override + { + Q_UNUSED(muted); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextAudio::isMuted() + virtual bool isMuted() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + + //! \copydoc IContextAudio::playSelcalTone() + virtual void playSelcalTone(const BlackMisc::Aviation::CSelcal &selcal) const override + { + Q_UNUSED(selcal); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextAudio::playNotification() + virtual void playNotification(BlackMisc::Audio::CNotificationSounds::Notification notification, bool considerSettings) const override + { + Q_UNUSED(notification); + Q_UNUSED(considerSettings); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextAudio::enableAudioLoopback() + virtual void enableAudioLoopback(bool enable = true) override + { + Q_UNUSED(enable); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextAudio::isAudioLoopbackEnabled + virtual bool isAudioLoopbackEnabled() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + + //! \copydoc IContextAudio::parseCommandLine + virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override + { + Q_UNUSED(commandLine); + Q_UNUSED(originator); + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + }; + } // ns +} // ns + +#endif // guard diff --git a/src/blackcore/context/contextaudioimpl.cpp b/src/blackcore/context/contextaudioimpl.cpp new file mode 100644 index 000000000..8dd9d509d --- /dev/null +++ b/src/blackcore/context/contextaudioimpl.cpp @@ -0,0 +1,560 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "blackcore/audiodevice.h" +#include "blackcore/audiomixer.h" +#include "blackcore/context/contextaudioimpl.h" +#include "blackcore/context/contextnetwork.h" +#include "blackcore/context/contextownaircraft.h" +#include "blackcore/corefacade.h" +#include "blackcore/voice.h" +#include "blackcore/voicevatlib.h" +#include "blackmisc/audio/audiodeviceinfo.h" +#include "blackmisc/audio/notificationsounds.h" +#include "blackmisc/audio/settings/settingsaudio.h" +#include "blackmisc/audio/voiceroomlist.h" +#include "blackmisc/aviation/callsign.h" +#include "blackmisc/compare.h" +#include "blackmisc/dbusserver.h" +#include "blackmisc/logcategory.h" +#include "blackmisc/logmessage.h" +#include "blackmisc/sequence.h" +#include "blackmisc/simplecommandparser.h" +#include "blackmisc/simulation/simulatedaircraft.h" +#include "blackmisc/statusmessage.h" +#include "blacksound/soundgenerator.h" + +#include +#include +#include +#include + +using namespace BlackMisc; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::Audio; +using namespace BlackMisc::Input; +using namespace BlackMisc::Audio; +using namespace BlackSound; + +namespace BlackCore +{ + namespace Context + { + CContextAudio::CContextAudio(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : + IContextAudio(mode, runtime), + m_voice(new CVoiceVatlib()) + { + // own aircraft may or may not be available + const CCallsign ownCallsign = (this->getIContextOwnAircraft()) ? getIContextOwnAircraft()->getOwnAircraft().getCallsign() : CCallsign(); + + m_channel1 = m_voice->createVoiceChannel(); + m_channel1->setOwnAircraftCallsign(ownCallsign); + connect(m_channel1.data(), &IVoiceChannel::connectionStatusChanged, this, &CContextAudio::ps_connectionStatusChanged); + connect(m_channel1.data(), &IVoiceChannel::userJoinedRoom, this, &CContextAudio::ps_userJoinedRoom); + connect(m_channel1.data(), &IVoiceChannel::userLeftRoom, this, &CContextAudio::ps_userLeftRoom); + m_channel2 = m_voice->createVoiceChannel(); + m_channel2->setOwnAircraftCallsign(ownCallsign); + connect(m_channel2.data(), &IVoiceChannel::connectionStatusChanged, this, &CContextAudio::ps_connectionStatusChanged); + connect(m_channel2.data(), &IVoiceChannel::userJoinedRoom, this, &CContextAudio::ps_userJoinedRoom); + connect(m_channel2.data(), &IVoiceChannel::userLeftRoom, this, &CContextAudio::ps_userLeftRoom); + + m_voiceInputDevice = m_voice->createInputDevice(); + m_voiceOutputDevice = m_voice->createOutputDevice(); + + m_audioMixer = m_voice->createAudioMixer(); + + m_voice->connectVoice(m_voiceInputDevice.get(), m_audioMixer.get(), IAudioMixer::InputMicrophone); + m_voice->connectVoice(m_channel1.data(), m_audioMixer.get(), IAudioMixer::InputVoiceChannel1); + m_voice->connectVoice(m_channel2.data(), m_audioMixer.get(), IAudioMixer::InputVoiceChannel2); + m_voice->connectVoice(m_audioMixer.get(), IAudioMixer::OutputOutputDevice1, m_voiceOutputDevice.get()); + m_voice->connectVoice(m_audioMixer.get(), IAudioMixer::OutputVoiceChannel1, m_channel1.data()); + m_voice->connectVoice(m_audioMixer.get(), IAudioMixer::OutputVoiceChannel2, m_channel2.data()); + + m_audioMixer->makeMixerConnection(IAudioMixer::InputVoiceChannel1, IAudioMixer::OutputOutputDevice1); + m_audioMixer->makeMixerConnection(IAudioMixer::InputVoiceChannel2, IAudioMixer::OutputOutputDevice1); + this->setVoiceOutputVolume(90); + + // Load sounds (init), not possible in own thread + QTimer::singleShot(10 * 1000, this, &CContextAudio::ps_initNotificationSounds); + + m_unusedVoiceChannels.push_back(m_channel1); + m_unusedVoiceChannels.push_back(m_channel2); + } + + CContextAudio *CContextAudio::registerWithDBus(CDBusServer *server) + { + if (!server || this->m_mode != CCoreFacadeConfig::LocalInDbusServer) { return this; } + server->addObject(IContextAudio::ObjectPath(), this); + return this; + } + + CContextAudio::~CContextAudio() + { + this->leaveAllVoiceRooms(); + } + + CVoiceRoomList CContextAudio::getComVoiceRoomsWithAudioStatus() const + { + Q_ASSERT(this->m_voice); + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + return getComVoiceRooms(); + } + + CVoiceRoom CContextAudio::getVoiceRoom(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue, bool withAudioStatus) const + { + Q_ASSERT(this->m_voice); + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << withAudioStatus; } + + auto voiceChannel = m_voiceChannelMapping.value(comUnitValue); + if (voiceChannel) + { + return voiceChannel->getVoiceRoom(); + } + else + { + return CVoiceRoom(); + } + } + + CVoiceRoomList CContextAudio::getComVoiceRooms() const + { + Q_ASSERT(this->m_voice); + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + CVoiceRoomList voiceRoomList; + + auto voiceChannelCom1 = m_voiceChannelMapping.value(BlackMisc::Aviation::CComSystem::Com1); + if (voiceChannelCom1) + { + CVoiceRoom room = voiceChannelCom1->getVoiceRoom(); + voiceRoomList.push_back(room); + } + else + { + voiceRoomList.push_back(CVoiceRoom()); + } + + auto voiceChannelCom2 = m_voiceChannelMapping.value(BlackMisc::Aviation::CComSystem::Com2); + if (voiceChannelCom2) + { + CVoiceRoom room = voiceChannelCom2->getVoiceRoom(); + voiceRoomList.push_back(room); + } + else + { + voiceRoomList.push_back(CVoiceRoom()); + } + + return voiceRoomList; + } + + void CContextAudio::leaveAllVoiceRooms() + { + Q_ASSERT(this->m_voice); + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO;} + m_voiceChannelMapping.clear(); + m_channel1->leaveVoiceRoom(); + m_channel2->leaveVoiceRoom(); + m_unusedVoiceChannels.push_back(m_channel1); + m_unusedVoiceChannels.push_back(m_channel2); + } + + CAudioDeviceInfoList CContextAudio::getAudioDevices() const + { + Q_ASSERT(this->m_voice); + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + CAudioDeviceInfoList devices = this->m_voiceOutputDevice->getOutputDevices(); + devices = devices.join(this->m_voiceInputDevice->getInputDevices()); + return devices; + } + + CAudioDeviceInfoList CContextAudio::getCurrentAudioDevices() const + { + Q_ASSERT(this->m_voice); + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + CAudioDeviceInfoList devices; + devices.push_back(this->m_voiceInputDevice->getCurrentInputDevice()); + devices.push_back(this->m_voiceOutputDevice->getCurrentOutputDevice()); + return devices; + } + + void CContextAudio::setCurrentAudioDevice(const CAudioDeviceInfo &audioDevice) + { + Q_ASSERT(this->m_voice); + Q_ASSERT(audioDevice.getType() != CAudioDeviceInfo::Unknown); + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << audioDevice; } + bool changed = false; + if (audioDevice.getType() == CAudioDeviceInfo::InputDevice) + { + if (this->m_voiceInputDevice->getCurrentInputDevice() != audioDevice) + { + this->m_voiceInputDevice->setInputDevice(audioDevice); + changed = true; + } + } + else + { + if (this->m_voiceOutputDevice->getCurrentOutputDevice() != audioDevice) + { + this->m_voiceOutputDevice->setOutputDevice(audioDevice); + changed = true; + } + } + + if (changed) + { + emit changedSelectedAudioDevices(this->getCurrentAudioDevices()); + } + } + + void CContextAudio::setVoiceOutputVolume(int volume) + { + Q_ASSERT(m_voiceOutputDevice); + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << volume; } + + bool wasMuted = isMuted(); + bool changed = m_voiceOutputDevice->getOutputVolume() != volume; + if (!changed) { return; } + m_voiceOutputDevice->setOutputVolume(volume); + m_outVolumeBeforeMute = m_voiceOutputDevice->getOutputVolume(); + + emit changedAudioVolume(volume); + if ((volume > 0 && wasMuted) || (volume < 1 && !wasMuted)) + { + // inform about muted + emit changedMute(volume < 1); + } + } + + int CContextAudio::getVoiceOutputVolume() const + { + Q_ASSERT(m_voiceOutputDevice); + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + return m_voiceOutputDevice->getOutputVolume(); + } + + void CContextAudio::setMute(bool muted) + { + if (this->isMuted() == muted) { return; } // avoid roundtrips / unnecessary signals + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << muted; } + + int newVolume; + if (muted) + { + Q_ASSERT(this->m_voiceOutputDevice); + m_outVolumeBeforeMute = this->m_voiceOutputDevice->getOutputVolume(); + newVolume = 0; + } + else + { + newVolume = m_outVolumeBeforeMute < MinUnmuteVolume ? MinUnmuteVolume : m_outVolumeBeforeMute; + m_outVolumeBeforeMute = newVolume; + } + + // do not call setVoiceOutputVolume -> infinite loop + if (newVolume != m_voiceOutputDevice->getOutputVolume()) + { + m_voiceOutputDevice->setOutputVolume(newVolume); + emit changedAudioVolume(newVolume); + } + + // signal + emit changedMute(muted); + } + + bool CContextAudio::isMuted() const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + return m_voiceOutputDevice->getOutputVolume() < 1; + } + + void CContextAudio::setComVoiceRooms(const CVoiceRoomList &newRooms) + { + Q_ASSERT(this->m_voice); + Q_ASSERT(newRooms.size() == 2); + Q_ASSERT(getIContextOwnAircraft()); + if (m_debugEnabled) {CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << newRooms; } + + CVoiceRoomList currentRooms = getComVoiceRooms(); + CVoiceRoom currentRoomCom1 = currentRooms[0]; + CVoiceRoom currentRoomCom2 = currentRooms[1]; + CVoiceRoom newRoomCom1 = newRooms[0]; + CVoiceRoom newRoomCom2 = newRooms[1]; + const CCallsign ownCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign()); + + bool changed = false; + + // changed rooms? But only compare on "URL", not status as connected etc. + if (currentRoomCom1.getVoiceRoomUrl() != newRoomCom1.getVoiceRoomUrl()) + { + auto oldVoiceChannel = m_voiceChannelMapping.value(BlackMisc::Aviation::CComSystem::Com1); + if (oldVoiceChannel) + { + m_voiceChannelMapping.remove(BlackMisc::Aviation::CComSystem::Com1); + + // If the voice channel is not used by anybody else + if (!m_voiceChannelMapping.values().contains(oldVoiceChannel)) + { + oldVoiceChannel->leaveVoiceRoom(); + m_unusedVoiceChannels.push_back(oldVoiceChannel); + } + else + { + emit this->changedVoiceRooms(getComVoiceRooms(), false); + } + } + + if (newRoomCom1.isValid()) + { + auto newVoiceChannel = getVoiceChannelBy(newRoomCom1); + newVoiceChannel->setOwnAircraftCallsign(ownCallsign); + bool inUse = m_voiceChannelMapping.values().contains(newVoiceChannel); + m_voiceChannelMapping.insert(BlackMisc::Aviation::CComSystem::Com1, newVoiceChannel); + + // If the voice channel is not used by anybody else + if (!inUse) + { + newVoiceChannel->joinVoiceRoom(newRoomCom1); + } + else + { + emit this->changedVoiceRooms(getComVoiceRooms(), true); + } + } + changed = true; + } + + // changed rooms? But only compare on "URL", not status as connected etc. + if (currentRoomCom2.getVoiceRoomUrl() != newRoomCom2.getVoiceRoomUrl()) + { + auto oldVoiceChannel = m_voiceChannelMapping.value(BlackMisc::Aviation::CComSystem::Com2); + if (oldVoiceChannel) + { + m_voiceChannelMapping.remove(BlackMisc::Aviation::CComSystem::Com2); + + // If the voice channel is not used by anybody else + if (!m_voiceChannelMapping.values().contains(oldVoiceChannel)) + { + oldVoiceChannel->leaveVoiceRoom(); + m_unusedVoiceChannels.push_back(oldVoiceChannel); + } + else + { + emit this->changedVoiceRooms(getComVoiceRooms(), false); + } + } + + if (newRoomCom2.isValid()) + { + auto newVoiceChannel = getVoiceChannelBy(newRoomCom2); + newVoiceChannel->setOwnAircraftCallsign(ownCallsign); + bool inUse = m_voiceChannelMapping.values().contains(newVoiceChannel); + m_voiceChannelMapping.insert(BlackMisc::Aviation::CComSystem::Com2, newVoiceChannel); + + // If the voice channel is not used by anybody else + if (!inUse) + { + newVoiceChannel->joinVoiceRoom(newRoomCom2); + } + else + { + emit this->changedVoiceRooms(getComVoiceRooms(), true); + } + } + changed = true; + } + + // changed not yet used, but I keep it for debugging + // changedVoiceRooms called by connectionStatusChanged; + Q_UNUSED(changed); + } + + void CContextAudio::setOwnCallsignForRooms(const CCallsign &callsign) + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << callsign; } + + if (m_channel1) { m_channel1->setOwnAircraftCallsign(callsign); } + if (m_channel2) { m_channel2->setOwnAircraftCallsign(callsign); } + } + + CCallsignSet CContextAudio::getRoomCallsigns(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue) const + { + Q_ASSERT(this->m_voice); + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + + auto voiceChannel = m_voiceChannelMapping.value(comUnitValue); + if (voiceChannel) + { + return voiceChannel->getVoiceRoomCallsigns(); + } + else + { + return CCallsignSet(); + } + } + + Network::CUserList CContextAudio::getRoomUsers(BlackMisc::Aviation::CComSystem::ComUnit comUnit) const + { + Q_ASSERT(this->m_voice); + Q_ASSERT(this->getRuntime()); + if (!this->getRuntime()->getIContextNetwork()) return Network::CUserList(); + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + + return this->getIContextNetwork()->getUsersForCallsigns(this->getRoomCallsigns(comUnit)); + } + + void CContextAudio::playSelcalTone(const CSelcal &selcal) const + { + Q_ASSERT(this->m_voice); + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << selcal; } + CAudioDeviceInfo outputDevice = m_voiceOutputDevice->getCurrentOutputDevice(); + CSoundGenerator::playSelcal(90, selcal, outputDevice); + } + + void CContextAudio::playNotification(CNotificationSounds::Notification notification, bool considerSettings) const + { + Q_ASSERT(this->m_voice); + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << notification; } + + bool play = !considerSettings || m_audioSettings.getThreadLocal().getNotificationFlag(notification); + if (play) + { + CSoundGenerator::playNotificationSound(90, notification); + } + } + + void CContextAudio::ps_initNotificationSounds() + { + // not possible in own thread + CSoundGenerator::playNotificationSound(0, CNotificationSounds::NotificationsLoadSounds); + } + + void CContextAudio::enableAudioLoopback(bool enable) + { + Q_ASSERT(this->m_audioMixer); + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (enable) + { + m_audioMixer->makeMixerConnection(IAudioMixer::InputMicrophone, IAudioMixer::OutputOutputDevice1); + } + else + { + m_audioMixer->removeMixerConnection(IAudioMixer::InputMicrophone, IAudioMixer::OutputOutputDevice1); + } + } + + bool CContextAudio::isAudioLoopbackEnabled() const + { + Q_ASSERT(this->m_audioMixer); + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + return this->m_audioMixer->hasMixerConnection(IAudioMixer::InputMicrophone, IAudioMixer::OutputOutputDevice1); + } + + bool CContextAudio::parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) + { + Q_UNUSED(originator); + if (commandLine.isEmpty()) { return false; } + CSimpleCommandParser parser( + { + ".vol", ".volume", // output volume + ".mute", // mute + ".unmute" // unmute + }); + parser.parse(commandLine); + if (!parser.isKnownCommand()) { return false; } + + if (parser.matchesCommand(".mute")) + { + this->setMute(true); + return true; + } + else if (parser.matchesCommand(".unmute")) + { + this->setMute(false); + return true; + } + else if (parser.commandStartsWith("vol") && parser.countParts() > 1) + { + int v = parser.toInt(1); + if (v >= 0 && v <= 300) + { + setVoiceOutputVolume(v); + return true; + } + } + return false; + } + + void CContextAudio::ps_setVoiceTransmission(bool enable) + { + // FIXME: Use the 'active' channel instead of hardcoded COM1 + if (enable) m_audioMixer->makeMixerConnection(IAudioMixer::InputMicrophone, IAudioMixer::OutputVoiceChannel1); + else m_audioMixer->removeMixerConnection(IAudioMixer::InputMicrophone, IAudioMixer::OutputVoiceChannel1); + } + + void CContextAudio::ps_connectionStatusChanged(BlackCore::IVoiceChannel::ConnectionStatus oldStatus, + BlackCore::IVoiceChannel::ConnectionStatus newStatus) + { + Q_UNUSED(oldStatus); + + switch (newStatus) + { + case IVoiceChannel::Connected: + emit this->changedVoiceRooms(getComVoiceRooms(), true); + break; + case IVoiceChannel::Disconnecting: + break; + case IVoiceChannel::Connecting: + break; + case IVoiceChannel::ConnectingFailed: + case IVoiceChannel::DisconnectedError: + CLogMessage(this).warning("Voice channel disconnecting error"); + // intentional fall-through + case IVoiceChannel::Disconnected: + if (this->getIContextOwnAircraft()) + { + // good chance to update aircraft + m_channel1->setOwnAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign()); + m_channel2->setOwnAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign()); + } + emit this->changedVoiceRooms(getComVoiceRooms(), false); + break; + default: + break; + } + } + + void CContextAudio::ps_userJoinedRoom(const CCallsign & /**callsign**/) + { + emit this->changedVoiceRoomMembers(); + } + + void CContextAudio::ps_userLeftRoom(const CCallsign & /**callsign**/) + { + emit this->changedVoiceRoomMembers(); + } + + QSharedPointer CContextAudio::getVoiceChannelBy(const CVoiceRoom &voiceRoom) + { + QSharedPointer voiceChannel; + for (const auto &channel : m_voiceChannelMapping.values()) + { + if (channel->getVoiceRoom().getVoiceRoomUrl() == voiceRoom.getVoiceRoomUrl()) voiceChannel = channel; + } + + // If we haven't found a valid voice channel pointer, get an unused one + if (!voiceChannel) + { + Q_ASSERT(!m_unusedVoiceChannels.isEmpty()); + voiceChannel = m_unusedVoiceChannels.takeFirst(); + } + + return voiceChannel; + } + } // namespace +} // namespace diff --git a/src/blackcore/context/contextaudioimpl.h b/src/blackcore/context/contextaudioimpl.h new file mode 100644 index 000000000..7fd19ce06 --- /dev/null +++ b/src/blackcore/context/contextaudioimpl.h @@ -0,0 +1,191 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKCORE_CONTEXT_CONTEXTAUDIO_IMPL_H +#define BLACKCORE_CONTEXT_CONTEXTAUDIO_IMPL_H + +#include "blackcore/actionbind.h" +#include "blackcore/blackcoreexport.h" +#include "blackcore/context/contextaudio.h" +#include "blackcore/corefacadeconfig.h" +#include "blackcore/settings/audio.h" +#include "blackcore/voicechannel.h" +#include "blackmisc/audio/audiodeviceinfolist.h" +#include "blackmisc/audio/notificationsounds.h" +#include "blackmisc/audio/voiceroom.h" +#include "blackmisc/audio/voiceroomlist.h" +#include "blackmisc/aviation/callsignset.h" +#include "blackmisc/aviation/comsystem.h" +#include "blackmisc/aviation/selcal.h" +#include "blackmisc/identifier.h" +#include "blackmisc/network/userlist.h" +#include "blackmisc/settingscache.h" + +#include +#include +#include +#include +#include +#include + +namespace BlackMisc +{ + class CDBusServer; + namespace Audio { class CAudioDeviceInfo; } + namespace Aviation { class CCallsign; } +} + +namespace BlackCore +{ + class CCoreFacade; + class IAudioInputDevice; + class IAudioMixer; + class IAudioOutputDevice; + class IVoice; + class IVoiceChannel; + + namespace Context + { + //! Audio context implementation + class BLACKCORE_EXPORT CContextAudio : public IContextAudio + { + Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAUDIO_INTERFACENAME) + Q_OBJECT + + friend class BlackCore::CCoreFacade; + friend class IContextAudio; + + public: + //! Destructor + virtual ~CContextAudio(); + + public slots: + //! \copydoc IContextAudio::getComVoiceRooms() + virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRooms() const override; + + //! \copydoc IContextAudio::getComVoiceRoomsWithAudioStatus() + virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRoomsWithAudioStatus() const override; + + //! \copydoc IContextAudio::getVoiceRoom + virtual BlackMisc::Audio::CVoiceRoom getVoiceRoom(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue, bool withAudioStatus) const override; + + //! \copydoc IContextAudio::setComVoiceRooms + virtual void setComVoiceRooms(const BlackMisc::Audio::CVoiceRoomList &newRooms) override; + + //! \copydoc IContextAudio::setOwnCallsignForRooms + virtual void setOwnCallsignForRooms(const BlackMisc::Aviation::CCallsign &callsign) override; + + //! \copydoc IContextAudio::getRoomCallsigns() + virtual BlackMisc::Aviation::CCallsignSet getRoomCallsigns(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue) const override; + + //! \copydoc IContextAudio::getRoomUsers() + virtual BlackMisc::Network::CUserList getRoomUsers(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue) const override; + + //! \copydoc IContextAudio::leaveAllVoiceRooms + virtual void leaveAllVoiceRooms() override; + + //! \copydoc IContextAudio::getAudioDevices() + virtual BlackMisc::Audio::CAudioDeviceInfoList getAudioDevices() const override; + + //! \copydoc IContextAudio::getCurrentAudioDevices() + virtual BlackMisc::Audio::CAudioDeviceInfoList getCurrentAudioDevices() const override; + + //! \copydoc IContextAudio::setCurrentAudioDevice() + virtual void setCurrentAudioDevice(const BlackMisc::Audio::CAudioDeviceInfo &audioDevice) override; + + //! \copydoc IContextAudio::setVoiceOutputVolume + virtual void setVoiceOutputVolume(int volume) override; + + //! \copydoc IContextAudio::getVoiceOutputVolume + virtual int getVoiceOutputVolume() const override; + + //! \copydoc IContextAudio::setMute + virtual void setMute(bool muted) override; + + //! \copydoc IContextAudio::isMuted() + virtual bool isMuted() const override; + + //! \copydoc IContextAudio::playSelcalTone + virtual void playSelcalTone(const BlackMisc::Aviation::CSelcal &selcal) const override; + + //! \copydoc IContextAudio::playNotification + virtual void playNotification(BlackMisc::Audio::CNotificationSounds::Notification notification, bool considerSettings) const override; + + //! \copydoc IContextAudio::enableAudioLoopback + virtual void enableAudioLoopback(bool enable = true) override; + + //! \copydoc IContextAudio::isAudioLoopbackEnabled + virtual bool isAudioLoopbackEnabled() const override; + + //! \addtogroup commandline + //! @{ + //!
+            //! .mute                          mute             CContextAudio
+            //! .unmute                        unmute           CContextAudio
+            //! .vol .volume   volume 0..300   set volume       CContextAudio
+            //! 
+ //! @} + //! \copydoc IContextAudio::parseCommandLine + virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override; + + protected: + //! Constructor + CContextAudio(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime); + + //! Register myself in DBus + CContextAudio *registerWithDBus(BlackMisc::CDBusServer *server); + + private slots: + + //! \copydoc IVoice::connectionStatusChanged + //! \sa IContextAudio::changedVoiceRooms + void ps_connectionStatusChanged(IVoiceChannel::ConnectionStatus oldStatus, IVoiceChannel::ConnectionStatus newStatus); + + //! Init notification sounds + void ps_initNotificationSounds(); + + void ps_setVoiceTransmission(bool enable); + + //! User joined the room + void ps_userJoinedRoom(const BlackMisc::Aviation::CCallsign &callsign); + + //! User left the room + void ps_userLeftRoom(const BlackMisc::Aviation::CCallsign &callsign); + + private: + //! Connection in transition + bool inTransitionState() const; + + //! Voice channel by room + QSharedPointer getVoiceChannelBy(const BlackMisc::Audio::CVoiceRoom &voiceRoom); + + const int MinUnmuteVolume = 20; //!< minimum volume when unmuted + CActionBind m_actionPtt { "/Voice/Activate push-to-talk", this, &CContextAudio::ps_setVoiceTransmission }; + std::unique_ptr m_voice; //!< underlying voice lib + std::unique_ptr m_audioMixer; + int m_outVolumeBeforeMute = 90; + + // For easy access. + QSharedPointer m_channel1; + QSharedPointer m_channel2; + std::unique_ptr m_voiceOutputDevice; + std::unique_ptr m_voiceInputDevice; + + QList> m_unusedVoiceChannels; + QHash> m_voiceChannelMapping; + + // settings + BlackMisc::CSetting m_audioSettings { this }; + }; + } // namespace +} // namespace + +#endif // guard diff --git a/src/blackcore/context/contextaudioproxy.cpp b/src/blackcore/context/contextaudioproxy.cpp new file mode 100644 index 000000000..2f60c28d2 --- /dev/null +++ b/src/blackcore/context/contextaudioproxy.cpp @@ -0,0 +1,153 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "blackcore/context/contextaudioproxy.h" +#include "blackmisc/dbus.h" +#include "blackmisc/genericdbusinterface.h" + +#include +#include +#include + +using namespace BlackMisc::Audio; +using namespace BlackMisc::Network; +using namespace BlackMisc::Aviation; + +namespace BlackCore +{ + namespace Context + { + CContextAudioProxy::CContextAudioProxy(const QString &serviceName, QDBusConnection &connection, CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextAudio(mode, runtime), m_dBusInterface(nullptr) + { + this->m_dBusInterface = new BlackMisc::CGenericDBusInterface( + serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(), connection, this); + this->relaySignals(serviceName, connection); + } + + void CContextAudioProxy::relaySignals(const QString &serviceName, QDBusConnection &connection) + { + bool s = connection.connect(serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(), + "changedVoiceRooms", this, SIGNAL(changedVoiceRooms(BlackMisc::Audio::CVoiceRoomList, bool))); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(), + "changedAudioVolume", this, SIGNAL(changedAudioVolume(int))); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(), + "changedAudioDevices", this, SIGNAL(changedAudioDevices(BlackMisc::Audio::CAudioDeviceInfoList))); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(), + "changedSelectedAudioDevices", this, SIGNAL(changedSelectedAudioDevices(BlackMisc::Audio::CAudioDeviceInfoList))); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(), + "changedMute", this, SIGNAL(changedMute(bool))); + Q_ASSERT(s); + Q_UNUSED(s); + } + + void CContextAudioProxy::leaveAllVoiceRooms() + { + this->m_dBusInterface->callDBus(QLatin1Literal("leaveAllVoiceRooms")); + } + + BlackMisc::Aviation::CCallsignSet CContextAudioProxy::getRoomCallsigns(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue) const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getRoomCallsigns"), comUnitValue); + } + + BlackMisc::Network::CUserList CContextAudioProxy::getRoomUsers(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue) const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getRoomUsers"), comUnitValue); + } + + CAudioDeviceInfoList CContextAudioProxy::getAudioDevices() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getAudioDevices")); + } + + CAudioDeviceInfoList CContextAudioProxy::getCurrentAudioDevices() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getCurrentAudioDevices")); + } + + void CContextAudioProxy::setCurrentAudioDevice(const CAudioDeviceInfo &audioDevice) + { + this->m_dBusInterface->callDBus(QLatin1Literal("setCurrentAudioDevice"), audioDevice); + } + + CVoiceRoomList CContextAudioProxy::getComVoiceRoomsWithAudioStatus() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getComVoiceRoomsWithAudioStatus")); + } + + CVoiceRoomList CContextAudioProxy::getComVoiceRooms() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getComVoiceRooms")); + } + + CVoiceRoom CContextAudioProxy::getVoiceRoom(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue, bool withAudioStatus) const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getVoiceRoom"), comUnitValue, withAudioStatus); + } + + void CContextAudioProxy::setComVoiceRooms(const BlackMisc::Audio::CVoiceRoomList &voiceRooms) + { + this->m_dBusInterface->callDBus(QLatin1Literal("setComVoiceRooms"), voiceRooms); + } + + void CContextAudioProxy::setOwnCallsignForRooms(const CCallsign &callsign) + { + this->m_dBusInterface->callDBus(QLatin1Literal("setOwnCallsignForRooms"), callsign); + } + + void CContextAudioProxy::playSelcalTone(const CSelcal &selcal) const + { + this->m_dBusInterface->callDBus(QLatin1Literal("playSelcalTone"), selcal); + } + + void CContextAudioProxy::playNotification(CNotificationSounds::Notification notification, bool considerSettings) const + { + this->m_dBusInterface->callDBus(QLatin1Literal("playNotification"), notification, considerSettings); + } + + void CContextAudioProxy::setVoiceOutputVolume(int volume) + { + this->m_dBusInterface->callDBus(QLatin1Literal("setVoiceOutputVolume"), volume); + } + + int CContextAudioProxy::getVoiceOutputVolume() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getVoiceOutputVolume")); + } + + void CContextAudioProxy::setMute(bool muted) + { + return this->m_dBusInterface->callDBus(QLatin1Literal("setMute"), muted); + } + + bool CContextAudioProxy::isMuted() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("isMuted")); + } + + void CContextAudioProxy::enableAudioLoopback(bool enable) + { + this->m_dBusInterface->callDBus(QLatin1Literal("enableAudioLoopback"), enable); + } + + bool CContextAudioProxy::isAudioLoopbackEnabled() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("isAudioLoopbackEnabled")); + } + + bool CContextAudioProxy::parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("parseCommandLine"), commandLine, originator); + } + } // namespace +} // namespace diff --git a/src/blackcore/context/contextaudioproxy.h b/src/blackcore/context/contextaudioproxy.h new file mode 100644 index 000000000..8061d362d --- /dev/null +++ b/src/blackcore/context/contextaudioproxy.h @@ -0,0 +1,134 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKCORE_CONTEXT_CONTEXTVOICE_PROXY_H +#define BLACKCORE_CONTEXT_CONTEXTVOICE_PROXY_H + +#include +#include + +#include "blackcore/blackcoreexport.h" +#include "blackcore/context/contextaudio.h" +#include "blackcore/corefacadeconfig.h" +#include "blackmisc/audio/audiodeviceinfolist.h" +#include "blackmisc/audio/notificationsounds.h" +#include "blackmisc/audio/voiceroom.h" +#include "blackmisc/audio/voiceroomlist.h" +#include "blackmisc/aviation/callsignset.h" +#include "blackmisc/aviation/comsystem.h" +#include "blackmisc/aviation/selcal.h" +#include "blackmisc/identifier.h" +#include "blackmisc/network/userlist.h" + +class QDBusConnection; + +namespace BlackMisc +{ + class CGenericDBusInterface; + namespace Audio { class CAudioDeviceInfo; } + namespace Aviation { class CCallsign; } +} + +namespace BlackCore +{ + class CCoreFacade; + namespace Context + { + //! Audio context proxy + //! \ingroup dbus + class BLACKCORE_EXPORT CContextAudioProxy : public IContextAudio + { + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAUDIO_INTERFACENAME) + friend class IContextAudio; + + public: + //! Destructor + virtual ~CContextAudioProxy() {} + + 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); + + protected: + //! Contructor + CContextAudioProxy(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextAudio(mode, runtime), m_dBusInterface(nullptr) {} + + //! DBus version constructor + CContextAudioProxy(const QString &serviceName, QDBusConnection &connection, CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime); + + public slots: + //! \copydoc IContextAudio::getComVoiceRooms() + virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRooms() const override; + + //! \copydoc IContextAudio::getComVoiceRoomsWithAudioStatus() + virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRoomsWithAudioStatus() const override; + + //! \copydoc IContextAudio::getVoiceRoom + virtual BlackMisc::Audio::CVoiceRoom getVoiceRoom(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue, bool withAudioStatus) const override; + + //! \copydoc IContextAudio::setComVoiceRooms() + virtual void setComVoiceRooms(const BlackMisc::Audio::CVoiceRoomList &voiceRooms) override; + + //! \copydoc IContextAudio::setOwnCallsignForRooms + virtual void setOwnCallsignForRooms(const BlackMisc::Aviation::CCallsign &callsign) override; + + //! \copydoc IContextAudio::getRoomCallsigns() + virtual BlackMisc::Aviation::CCallsignSet getRoomCallsigns(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue) const override; + + //! \copydoc IContextAudio::getRoomUsers() + virtual BlackMisc::Network::CUserList getRoomUsers(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue) const override; + + //! \copydoc IContextAudio::leaveAllVoiceRooms + virtual void leaveAllVoiceRooms() override; + + //! \copydoc IContextAudio::getAudioDevices() + virtual BlackMisc::Audio::CAudioDeviceInfoList getAudioDevices() const override; + + //! \copydoc IContextAudio::getCurrentAudioDevices() + virtual BlackMisc::Audio::CAudioDeviceInfoList getCurrentAudioDevices() const override; + + //! \copydoc IContextAudio::setCurrentAudioDevice() + virtual void setCurrentAudioDevice(const BlackMisc::Audio::CAudioDeviceInfo &audioDevice) override; + + //!\copydoc IContextAudio::setVoiceOutputVolume + virtual void setVoiceOutputVolume(int volume) override; + + //! \copydoc IContextAudio::getVoiceOutputVolume + virtual int getVoiceOutputVolume() const override; + + //! \copydoc IContextAudio::setMute + virtual void setMute(bool muted) override; + + //! \copydoc IContextAudio::isMuted() + virtual bool isMuted() const override; + + //! \copydoc IContextAudio::playSelcalTone + virtual void playSelcalTone(const BlackMisc::Aviation::CSelcal &selcal) const override; + + //! \copydoc IContextAudio::playNotification + virtual void playNotification(BlackMisc::Audio::CNotificationSounds::Notification notification, bool considerSettings) const override; + + //! \copydoc IContextAudio::enableAudioLoopback() + virtual void enableAudioLoopback(bool enable = true) override; + + //! \copydoc IContextAudio::isAudioLoopbackEnabled() + virtual bool isAudioLoopbackEnabled() const override; + + //! \copydoc IContextOwnAircraft::parseCommandLine + virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override; + }; + } // ns +} // ns +#endif // guard diff --git a/src/blackcore/context/contextnetwork.cpp b/src/blackcore/context/contextnetwork.cpp new file mode 100644 index 000000000..3ecdbfa19 --- /dev/null +++ b/src/blackcore/context/contextnetwork.cpp @@ -0,0 +1,36 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "blackcore/context/contextnetwork.h" +#include "blackcore/context/contextnetworkempty.h" +#include "blackcore/context/contextnetworkimpl.h" +#include "blackcore/context/contextnetworkproxy.h" +#include "blackmisc/dbusserver.h" + +using namespace BlackCore; +namespace BlackCore +{ + namespace Context + { + IContextNetwork *IContextNetwork::create(CCoreFacade *runtime, CCoreFacadeConfig::ContextMode mode, BlackMisc::CDBusServer *server, QDBusConnection &connection) + { + switch (mode) + { + case CCoreFacadeConfig::Local: + case CCoreFacadeConfig::LocalInDbusServer: + return (new CContextNetwork(mode, runtime))->registerWithDBus(server); + case CCoreFacadeConfig::Remote: + return new CContextNetworkProxy(BlackMisc::CDBusServer::coreServiceName(), connection, mode, runtime); + case CCoreFacadeConfig::NotUsed: + default: + return new CContextNetworkEmpty(runtime); + } + } + } // namesapce +} // namesapce diff --git a/src/blackcore/context/contextnetwork.h b/src/blackcore/context/contextnetwork.h new file mode 100644 index 000000000..61613aca6 --- /dev/null +++ b/src/blackcore/context/contextnetwork.h @@ -0,0 +1,286 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKCORE_CONTEXT_CONTEXTNETWORK_H +#define BLACKCORE_CONTEXT_CONTEXTNETWORK_H + +#include +#include + +#include "blackcore/blackcoreexport.h" +#include "blackcore/context/context.h" +#include "blackcore/corefacade.h" +#include "blackcore/corefacadeconfig.h" +#include "blackcore/network.h" +#include "blackmisc/audio/voiceroomlist.h" +#include "blackmisc/aviation/airporticaocode.h" +#include "blackmisc/aviation/atcstation.h" +#include "blackmisc/aviation/atcstationlist.h" +#include "blackmisc/aviation/callsignset.h" +#include "blackmisc/aviation/flightplan.h" +#include "blackmisc/identifier.h" +#include "blackmisc/network/clientlist.h" +#include "blackmisc/network/server.h" +#include "blackmisc/network/serverlist.h" +#include "blackmisc/network/textmessagelist.h" +#include "blackmisc/network/user.h" +#include "blackmisc/network/userlist.h" +#include "blackmisc/simulation/simulatedaircraft.h" +#include "blackmisc/simulation/simulatedaircraftlist.h" +#include "blackmisc/statusmessage.h" +#include "blackmisc/weather/metar.h" + +//! \addtogroup dbus +//! @{ + +//! DBus interface for context +#define BLACKCORE_CONTEXTNETWORK_INTERFACENAME "org.swift_project.blackcore.contextnetwork" + +//! DBus object path for context +#define BLACKCORE_CONTEXTNETWORK_OBJECTPATH "/network" + +//! @} + +class QDBusConnection; +namespace BlackMisc +{ + class CDBusServer; + namespace Aviation + { + class CAircraftParts; + class CCallsign; + } + namespace Network { class CTextMessage; } + namespace Simulation { class CAircraftModel; } +} +namespace BlackCore +{ + namespace Context + { + //! Network context proxy + class BLACKCORE_EXPORT IContextNetwork : public CContext + { + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTNETWORK_INTERFACENAME) + + public: + //! DBus interface name + static const QString &InterfaceName() + { + static QString s(BLACKCORE_CONTEXTNETWORK_INTERFACENAME); + return s; + } + + //! DBus object path + static const QString &ObjectPath() + { + static QString s(BLACKCORE_CONTEXTNETWORK_OBJECTPATH); + return s; + } + + //! \copydoc CContext::getPathAndContextId() + virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); } + + //! Factory method + static IContextNetwork *create(CCoreFacade *parent, CCoreFacadeConfig::ContextMode mode, BlackMisc::CDBusServer *server, QDBusConnection &connection); + + //! Destructor + virtual ~IContextNetwork() {} + + signals: + //! An aircraft disappeared + void removedAircraft(const BlackMisc::Aviation::CCallsign &callsign); + + //! A new aircraft appeared + void addedAircraft(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft); + + //! Read for model matching + void readyForModelMatching(const BlackMisc::Simulation::CSimulatedAircraft &renderedAircraft); + + //! ATC station (online) list has been changed + void changedAtcStationsOnline(); + + //! Digest signal changedAtcStationsOnline() + void changedAtcStationsOnlineDigest(); + + //! ATC station (booked) list has been changed + void changedAtcStationsBooked(); + + //! Digest signal changedAtcStationsBooked() + void changedAtcStationsBookedDigest(); + + //! Aircraft list has been changed + void changedAircraftInRange(); + + //! Digest signal changedAircraftInRange() + void changedAircraftInRangeDigest(); + + //! Aircraft model was changed + //! \details All remote aircraft are stored in the network context. The model can be updated here + //! via \sa updateAircraftModel and then this signal is fired + void changedRemoteAircraftModel(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator); + + //! Aircraft enabled / disabled + //! \details All remote aircraft are stored in the network context. The aircraft can be enabled (for rendering) here + //! via \sa updateAircraftEnabled and then this signal is fired + void changedRemoteAircraftEnabled(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator); + + //! Aircraft enabled / disabled + void changedFastPositionUpdates(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator); + + //! Connection status changed for online station + void changedAtcStationOnlineConnectionStatus(const BlackMisc::Aviation::CAtcStation &atcStation, bool connected); + + //! Terminated connection + void connectionTerminated(); + + //! Connection status changed + void connectionStatusChanged(BlackCore::INetwork::ConnectionStatus from, BlackCore::INetwork::ConnectionStatus to); + + //! Text messages received (also private chat messages, rfaio channel messages) + void textMessagesReceived(const BlackMisc::Network::CTextMessageList &textMessages); + + //! A superivisor text message was received + void supervisorTextMessageReceived(const BlackMisc::Network::CTextMessage &message); + + //! Text message sent (by me) + void textMessageSent(const BlackMisc::Network::CTextMessage &sentMessage); + + // --------------------------- data readers ------------------------------- + + //! Web serice data read + // void webServiceDataRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState state, int number); + void webServiceDataRead(int entity, int state, int number); + + public slots: + //! Reload bookings from booking service + virtual void readAtcBookingsFromSource() const = 0; + + //! The ATC list with online ATC controllers + virtual BlackMisc::Aviation::CAtcStationList getAtcStationsOnline() const = 0; + + //! ATC list, with booked controllers + virtual BlackMisc::Aviation::CAtcStationList getAtcStationsBooked() const = 0 ; + + //! Aircraft list + virtual BlackMisc::Simulation::CSimulatedAircraftList getAircraftInRange() const = 0; + + //! Aircraft callsigns + virtual BlackMisc::Aviation::CCallsignSet getAircraftInRangeCallsigns() const = 0; + + //! Aircraft for given callsign + virtual BlackMisc::Simulation::CSimulatedAircraft getAircraftInRangeForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const = 0; + + //! Aircraft count + virtual int getAircraftInRangeCount() const = 0; + + //! Get METAR, if not available request it (code such as EDDF, KLAX) + virtual BlackMisc::Weather::CMetar getMetarForAirport(const BlackMisc::Aviation::CAirportIcaoCode &airportIcaoCode) const = 0; + + //! Online station for callsign + virtual BlackMisc::Aviation::CAtcStation getOnlineStationForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const = 0; + + //! Get all users + virtual BlackMisc::Network::CUserList getUsers() const = 0; + + //! Users for given callsigns, e.g. for voice room resolution + virtual BlackMisc::Network::CUserList getUsersForCallsigns(const BlackMisc::Aviation::CCallsignSet &callsigns) const = 0; + + //! User for given callsign, e.g. for text messages + virtual BlackMisc::Network::CUser getUserForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const = 0; + + //! Information about other clients + virtual BlackMisc::Network::CClientList getOtherClients() const = 0; + + //! Clients for given callsign, e.g. to test/fetch direct aircraft model + virtual BlackMisc::Network::CClientList getOtherClientsForCallsigns(const BlackMisc::Aviation::CCallsignSet &callsigns) const = 0; + + //! Known voice servers, available when data file was first read + virtual BlackMisc::Network::CServerList getVatsimVoiceServers() const = 0; + + //! Known FSD servers, available when data file was first read + virtual BlackMisc::Network::CServerList getVatsimFsdServers() const = 0; + + //! Callsigns enabled for fast position updates + virtual void setFastPositionEnabledCallsigns(BlackMisc::Aviation::CCallsignSet &callsigns) = 0; + + //! Callsigns enabled for fast position updates + virtual BlackMisc::Aviation::CCallsignSet getFastPositionEnabledCallsigns() = 0; + + //! Connect to Network + //! \return messages generated during connecting + virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, BlackCore::INetwork::LoginMode loginMode) = 0; + + //! Server which is connected, if not connected empty default object. + virtual BlackMisc::Network::CServer getConnectedServer() const = 0; + + //! Disconnect from network + //! \return messages generated during disconnecting + virtual BlackMisc::CStatusMessage disconnectFromNetwork() = 0; + + //! Network connected? + virtual bool isConnected() const = 0; + + //! Text messages (radio and private chat messages) + virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &textMessages) = 0; + + //! Send flight plan + virtual void sendFlightPlan(const BlackMisc::Aviation::CFlightPlan &flightPlan) = 0; + + //! Load flight plan (from network) + virtual BlackMisc::Aviation::CFlightPlan loadFlightPlanFromNetwork(const BlackMisc::Aviation::CCallsign &callsign) const = 0; + + //! Command line was entered + virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) = 0; + + //! Use the selected COM1/2 frequencies, and get the corresponding voice room for it + virtual BlackMisc::Audio::CVoiceRoomList getSelectedVoiceRooms() const = 0; + + //! Use the selected COM1/2 frequencies, and get the corresponding ATC stations for it + virtual BlackMisc::Aviation::CAtcStationList getSelectedAtcStations() const = 0; + + //! Request data updates (pilot's frequencies, ATIS, ..) + virtual void requestDataUpdates() = 0; + + //! Request ATIS updates (for all stations) + virtual void requestAtisUpdates() = 0; + + //! Enable/disable rendering + virtual bool updateAircraftEnabled(const BlackMisc::Aviation::CCallsign &callsign, bool enabledForRedering, const BlackMisc::CIdentifier &originator) = 0; + + //! Change model string + virtual bool updateAircraftModel(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Simulation::CAircraftModel &model, const BlackMisc::CIdentifier &originator) = 0; + + //! Change fast position updates + virtual bool updateFastPositionEnabled(const BlackMisc::Aviation::CCallsign &callsign, bool enableFastPositionSending, const BlackMisc::CIdentifier &originator) = 0; + + //! Get reverse lookup meesages + virtual BlackMisc::CStatusMessageList getReverseLookupMessages(const BlackMisc::Aviation::CCallsign &callsign) const = 0; + + //! Enabled reverse lookup logging? + virtual bool isReverseLookupMessagesEnabled() const = 0; + + //! Enable reverse lookup logging + virtual void enableReverseLookupMessages(bool enabled) = 0; + + //! Create dummy ATC stations for performance tests etc. + virtual void testCreateDummyOnlineAtcStations(int number) = 0; + + //! Inject aircraft parts for testing + virtual void testAddAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftParts &parts, bool incremental) = 0; + + protected: + //! Constructor + IContextNetwork(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : CContext(mode, runtime) {} + }; + } // ns +} // ns +#endif // guard diff --git a/src/blackcore/context/contextnetworkempty.h b/src/blackcore/context/contextnetworkempty.h new file mode 100644 index 000000000..da6749d9c --- /dev/null +++ b/src/blackcore/context/contextnetworkempty.h @@ -0,0 +1,323 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKCORE_CONTEXT_CONTEXTNETWORK_EMPTY_H +#define BLACKCORE_CONTEXT_CONTEXTNETWORK_EMPTY_H + +#include "blackcoreexport.h" +#include "contextnetwork.h" +#include "blackmisc/logmessage.h" + +namespace BlackCore +{ + namespace Context + { + //! Empty context, used during shutdown/initialization + class BLACKCORE_EXPORT CContextNetworkEmpty : public IContextNetwork + { + Q_OBJECT + + public: + //! Constructor + CContextNetworkEmpty(CCoreFacade *runtime) : IContextNetwork(CCoreFacadeConfig::NotUsed, runtime) {} + + public slots: // IContextNetwork overrides + + //! \copydoc IContextNetwork::readAtcBookingsFromSource() + virtual void readAtcBookingsFromSource() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextNetwork::getAtcStationsOnline() + virtual BlackMisc::Aviation::CAtcStationList getAtcStationsOnline() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Aviation::CAtcStationList(); + } + + //! \copydoc IContextNetwork::getAtcStationsBooked() + virtual BlackMisc::Aviation::CAtcStationList getAtcStationsBooked() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Aviation::CAtcStationList(); + } + + //! \copydoc IContextNetwork::getAircraftInRange() + virtual BlackMisc::Simulation::CSimulatedAircraftList getAircraftInRange() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Simulation::CSimulatedAircraftList(); + } + + //! \copydoc IContextNetwork::getAircraftInRangeForCallsign + virtual BlackMisc::Simulation::CSimulatedAircraft getAircraftInRangeForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override + { + Q_UNUSED(callsign); + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Simulation::CSimulatedAircraft(); + } + + //! \copydoc IContextNetwork::getAircraftInRangeCallsigns() + virtual BlackMisc::Aviation::CCallsignSet getAircraftInRangeCallsigns() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Aviation::CCallsignSet(); + } + + //! \copydoc IContextNetwork::getAircraftInRangeCount + virtual int getAircraftInRangeCount() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return 0; + } + + //! \copydoc IContextNetwork::getOnlineStationForCallsign + virtual BlackMisc::Aviation::CAtcStation getOnlineStationForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override + { + Q_UNUSED(callsign); + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Aviation::CAtcStation(); + } + + //! \copydoc IContextNetwork::connectToNetwork + virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, BlackCore::INetwork::LoginMode mode) override + { + Q_UNUSED(mode); + Q_UNUSED(server); + logEmptyContextWarning(Q_FUNC_INFO); + return statusMessageEmptyContext(); + } + + //! \copydoc IContextNetwork::disconnectFromNetwork() + virtual BlackMisc::CStatusMessage disconnectFromNetwork() override + { + logEmptyContextWarning(Q_FUNC_INFO); + return statusMessageEmptyContext(); + } + + //! \copydoc IContextNetwork::isConnected() + virtual bool isConnected() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + + //! \copydoc IContextNetwork::getConnectedServer + virtual BlackMisc::Network::CServer getConnectedServer() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Network::CServer(); + } + + //! \copydoc IContextNetwork::sendTextMessages() + virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &textMessages) override + { + Q_UNUSED(textMessages); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextNetwork::sendFlightPlan() + virtual void sendFlightPlan(const BlackMisc::Aviation::CFlightPlan &flightPlan) override + { + Q_UNUSED(flightPlan); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextNetwork::loadFlightPlanFromNetwork() + virtual BlackMisc::Aviation::CFlightPlan loadFlightPlanFromNetwork(const BlackMisc::Aviation::CCallsign &callsign) const override + { + Q_UNUSED(callsign); + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Aviation::CFlightPlan(); + } + + //! \copydoc IContextNetwork::getMetarForAirport + BlackMisc::Weather::CMetar getMetarForAirport(const BlackMisc::Aviation::CAirportIcaoCode &airportIcaoCode) const override + { + Q_UNUSED(airportIcaoCode); + logEmptyContextWarning(Q_FUNC_INFO); + return {}; + } + + //! \copydoc IContextNetwork::getSelectedVoiceRooms() + virtual BlackMisc::Audio::CVoiceRoomList getSelectedVoiceRooms() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Audio::CVoiceRoomList(); + } + + //! \copydoc IContextNetwork::getSelectedAtcStations + virtual BlackMisc::Aviation::CAtcStationList getSelectedAtcStations() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + // normally 2 entries + return BlackMisc::Aviation::CAtcStationList({ BlackMisc::Aviation::CAtcStation(), BlackMisc::Aviation::CAtcStation()}); + } + + //! \copydoc IContextNetwork::getUsers() + virtual BlackMisc::Network::CUserList getUsers() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Network::CUserList(); + } + + //! \copydoc IContextNetwork::getUsersForCallsigns + virtual BlackMisc::Network::CUserList getUsersForCallsigns(const BlackMisc::Aviation::CCallsignSet &callsigns) const override + { + Q_UNUSED(callsigns); + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Network::CUserList(); + } + + //! \copydoc IContextNetwork::getUserForCallsign + virtual BlackMisc::Network::CUser getUserForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override + { + Q_UNUSED(callsign); + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Network::CUser(); + } + + //! \copydoc IContextNetwork::getOtherClients + virtual BlackMisc::Network::CClientList getOtherClients() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Network::CClientList(); + } + + //! \copydoc IContextNetwork::getOtherClientsForCallsigns + virtual BlackMisc::Network::CClientList getOtherClientsForCallsigns(const BlackMisc::Aviation::CCallsignSet &callsigns) const override + { + Q_UNUSED(callsigns); + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Network::CClientList(); + } + + //! \copydoc IContextNetwork::requestDataUpdates + virtual void requestDataUpdates()override + { + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextNetwork::requestAtisUpdates + virtual void requestAtisUpdates() override + { + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextNetwork::testCreateDummyOnlineAtcStations + virtual void testCreateDummyOnlineAtcStations(int number) override + { + Q_UNUSED(number); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextNetwork::testAddAircraftParts + virtual void testAddAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftParts &parts, bool incremental) override + { + Q_UNUSED(callsign); + Q_UNUSED(parts); + Q_UNUSED(incremental); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextNetwork::parseCommandLine + virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override + { + Q_UNUSED(commandLine); + Q_UNUSED(originator); + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + + //! \copydoc IContextNetwork::getVatsimVoiceServers + virtual BlackMisc::Network::CServerList getVatsimVoiceServers() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Network::CServerList(); + } + + //! \copydoc IContextNetwork::getVatsimFsdServers + virtual BlackMisc::Network::CServerList getVatsimFsdServers() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Network::CServerList(); + } + + //! \copydoc IContextNetwork::updateAircraftEnabled + virtual bool updateAircraftEnabled(const BlackMisc::Aviation::CCallsign &callsign, bool enabledForRedering, const BlackMisc::CIdentifier &originator) override + { + Q_UNUSED(callsign); + Q_UNUSED(originator); + Q_UNUSED(enabledForRedering); + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + + //! \copydoc IContextNetwork::updateAircraftModel + virtual bool updateAircraftModel(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Simulation::CAircraftModel &model, const BlackMisc::CIdentifier &originator) override + { + Q_UNUSED(callsign); + Q_UNUSED(originator); + Q_UNUSED(model); + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + + //! \copydoc IContextNetwork::updateFastPositionEnabled + virtual bool updateFastPositionEnabled(const BlackMisc::Aviation::CCallsign &callsign, bool enableFastPositionSending, const BlackMisc::CIdentifier &originator) override + { + logEmptyContextWarning(Q_FUNC_INFO); + Q_UNUSED(callsign); + Q_UNUSED(enableFastPositionSending); + Q_UNUSED(originator); + return false; + } + + //! \copydoc IContextNetwork::setFastPositionEnabledCallsigns + virtual void setFastPositionEnabledCallsigns(BlackMisc::Aviation::CCallsignSet &callsigns) override + { + Q_UNUSED(callsigns); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextNetwork::getFastPositionEnabledCallsigns + virtual BlackMisc::Aviation::CCallsignSet getFastPositionEnabledCallsigns() override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Aviation::CCallsignSet(); + } + + //! \copydoc IContextNetwork::getReverseLookupMessages + virtual BlackMisc::CStatusMessageList getReverseLookupMessages(const BlackMisc::Aviation::CCallsign &callsign) const override + { + logEmptyContextWarning(Q_FUNC_INFO); + Q_UNUSED(callsign); + return BlackMisc::CStatusMessageList(); + } + + //! \copydoc IContextNetwork::isReverseLookupMessagesEnabled + virtual bool isReverseLookupMessagesEnabled() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + + //! \copydoc IContextNetwork::enableReverseLookupMessages + virtual void enableReverseLookupMessages(bool enabled) override + { + logEmptyContextWarning(Q_FUNC_INFO); + Q_UNUSED(enabled); + } + }; + } // namespace +} // namespace +#endif // guard diff --git a/src/blackcore/context/contextnetworkimpl.cpp b/src/blackcore/context/contextnetworkimpl.cpp new file mode 100644 index 000000000..9346f687b --- /dev/null +++ b/src/blackcore/context/contextnetworkimpl.cpp @@ -0,0 +1,673 @@ +/* Copyright (C) 2013 + * swift project Community / Contributors + * + * This file is part of Swift Project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "blackcore/airspaceanalyzer.h" +#include "blackcore/airspacemonitor.h" +#include "blackcore/application.h" +#include "blackcore/context/contextnetworkimpl.h" +#include "blackcore/context/contextownaircraft.h" +#include "blackcore/context/contextownaircraftimpl.h" +#include "blackcore/context/contextsimulator.h" +#include "blackcore/corefacade.h" +#include "blackcore/networkvatlib.h" +#include "blackcore/webdataservices.h" +#include "blackmisc/aviation/aircrafticaocode.h" +#include "blackmisc/aviation/aircraftparts.h" +#include "blackmisc/aviation/atcstationlist.h" +#include "blackmisc/aviation/callsign.h" +#include "blackmisc/aviation/comsystem.h" +#include "blackmisc/dbusserver.h" +#include "blackmisc/logcategory.h" +#include "blackmisc/logmessage.h" +#include "blackmisc/network/entityflags.h" +#include "blackmisc/network/networkutils.h" +#include "blackmisc/network/textmessage.h" +#include "blackmisc/pq/constants.h" +#include "blackmisc/pq/frequency.h" +#include "blackmisc/pq/units.h" +#include "blackmisc/sequence.h" +#include "blackmisc/simplecommandparser.h" +#include "blackmisc/simulation/simulatorplugininfo.h" +#include "blackmisc/stringutils.h" +#include "contextnetworkimpl.h" + +#include +#include + +using namespace BlackMisc; +using namespace BlackMisc::PhysicalQuantities; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::Network; +using namespace BlackMisc::Geo; +using namespace BlackMisc::Audio; +using namespace BlackMisc::Simulation; +using namespace BlackMisc::Weather; + +namespace BlackCore +{ + namespace Context + { + CContextNetwork::CContextNetwork(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : + IContextNetwork(mode, runtime) + { + Q_ASSERT(this->getRuntime()); + Q_ASSERT(this->getIContextOwnAircraft()); + Q_ASSERT(this->getIContextOwnAircraft()->isUsingImplementingObject()); + + // 1. Init by "network driver" + this->m_network = new CNetworkVatlib(this->getRuntime()->getCContextOwnAircraft(), this); + connect(this->m_network, &INetwork::connectionStatusChanged, this, &CContextNetwork::ps_fsdConnectionStatusChanged); + connect(this->m_network, &INetwork::textMessagesReceived, this, &CContextNetwork::textMessagesReceived); + connect(this->m_network, &INetwork::textMessagesReceived, this, &CContextNetwork::ps_checkForSupervisiorTextMessage); + connect(this->m_network, &INetwork::textMessageSent, this, &CContextNetwork::textMessageSent); + + // 2. Update timer for data (network data such as frequency) + this->m_networkDataUpdateTimer = new QTimer(this); + connect(this->m_networkDataUpdateTimer, &QTimer::timeout, this, &CContextNetwork::requestDataUpdates); + this->m_networkDataUpdateTimer->start(30 * 1000); + + // 3. data reader, start reading when setup is synced with xx delay + Q_ASSERT_X(sApp->getWebDataServices(), Q_FUNC_INFO, "Missing web data services"); + connect(sApp->getWebDataServices(), &CWebDataServices::dataRead, this, &CContextNetwork::webServiceDataRead); + + // 4. Airspace contents + Q_ASSERT_X(this->getRuntime()->getCContextOwnAircraft(), Q_FUNC_INFO, "this and own aircraft context must be local"); + this->m_airspace = new CAirspaceMonitor(this->getRuntime()->getCContextOwnAircraft(), this->m_network, this); + connect(this->m_airspace, &CAirspaceMonitor::changedAtcStationsOnline, this, &CContextNetwork::changedAtcStationsOnline); + connect(this->m_airspace, &CAirspaceMonitor::changedAtcStationsBooked, this, &CContextNetwork::changedAtcStationsBooked); + connect(this->m_airspace, &CAirspaceMonitor::changedAtcStationOnlineConnectionStatus, this, &CContextNetwork::changedAtcStationOnlineConnectionStatus); + connect(this->m_airspace, &CAirspaceMonitor::changedAircraftInRange, this, &CContextNetwork::changedAircraftInRange); + connect(this->m_airspace, &CAirspaceMonitor::removedAircraft, this, &IContextNetwork::removedAircraft); // DBus + connect(this->m_airspace, &CAirspaceMonitor::readyForModelMatching, this, &CContextNetwork::readyForModelMatching); + connect(this->m_airspace, &CAirspaceMonitor::addedAircraft, this, &CContextNetwork::addedAircraft); + } + + CContextNetwork *CContextNetwork::registerWithDBus(BlackMisc::CDBusServer *server) + { + if (!server || this->m_mode != CCoreFacadeConfig::LocalInDbusServer) return this; + server->addObject(IContextNetwork::ObjectPath(), this); + return this; + } + + CContextNetwork::~CContextNetwork() + { + this->gracefulShutdown(); + } + + CAircraftSituationList CContextNetwork::remoteAircraftSituations(const CCallsign &callsign) const + { + Q_ASSERT(this->m_airspace); + return m_airspace->remoteAircraftSituations(callsign); + } + + CAircraftPartsList CContextNetwork::remoteAircraftParts(const CCallsign &callsign, qint64 cutoffTimeBefore) const + { + Q_ASSERT(this->m_airspace); + return m_airspace->remoteAircraftParts(callsign, cutoffTimeBefore); + } + + int CContextNetwork::remoteAircraftSituationsCount(const CCallsign &callsign) const + { + Q_ASSERT(this->m_airspace); + return m_airspace->remoteAircraftSituationsCount(callsign); + } + + bool CContextNetwork::isRemoteAircraftSupportingParts(const CCallsign &callsign) const + { + Q_ASSERT(this->m_airspace); + return m_airspace->isRemoteAircraftSupportingParts(callsign); + } + + CCallsignSet CContextNetwork::remoteAircraftSupportingParts() const + { + Q_ASSERT(this->m_airspace); + return m_airspace->remoteAircraftSupportingParts(); + } + + QList CContextNetwork::connectRemoteAircraftProviderSignals( + QObject *receiver, + std::function situationSlot, + std::function partsSlot, + std::function removedAircraftSlot, + std::function aircraftSnapshotSlot) + { + Q_ASSERT_X(this->m_airspace, Q_FUNC_INFO, "Missing airspace"); + return this->m_airspace->connectRemoteAircraftProviderSignals(receiver, situationSlot, partsSlot, removedAircraftSlot, aircraftSnapshotSlot); + } + + void CContextNetwork::gracefulShutdown() + { + this->disconnect(); // all signals + if (this->isConnected()) { this->disconnectFromNetwork(); } + if (this->m_airspace) { this->m_airspace->gracefulShutdown(); } + } + + CStatusMessage CContextNetwork::connectToNetwork(const CServer &server, INetwork::LoginMode mode) + { + if (this->isDebugEnabled()) {CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + QString msg; + if (!server.getUser().isValid()) + { + return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityError, "Invalid user credentials"); + } + else if (!this->ownAircraft().getAircraftIcaoCode().hasDesignator()) + { + return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityError, "Invalid ICAO data for own aircraft"); + } + else if (!CNetworkUtils::canConnect(server, msg, 2000)) + { + return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityError, msg); + } + else if (this->m_network->isConnected()) + { + return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityError, "Already connected"); + } + else if (this->isPendingConnection()) + { + return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityError, "Pending connection, please wait"); + } + else + { + this->m_currentStatus = INetwork::Connecting; // as semaphore we are going to connect + this->m_airspace->setConnected(true); + this->getIContextOwnAircraft()->updateOwnAircraftPilot(server.getUser()); + const CSimulatedAircraft ownAircraft(this->ownAircraft()); + this->m_network->presetServer(server); + this->m_network->presetLoginMode(mode); + this->m_network->presetCallsign(ownAircraft.getCallsign()); + this->m_network->presetIcaoCodes(ownAircraft); + if (getIContextSimulator()) + { + this->m_network->presetSimulatorInfo(getIContextSimulator()->getSimulatorPluginInfo()); + } + else + { + this->m_network->presetSimulatorInfo(CSimulatorPluginInfo()); + } + this->m_network->initiateConnection(); + return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityInfo, "Connection pending " + server.getAddress() + " " + QString::number(server.getPort())); + } + } + + CServer CContextNetwork::getConnectedServer() const + { + return this->isConnected() ? + this->m_network->getPresetServer() : + CServer(); + } + + CStatusMessage CContextNetwork::disconnectFromNetwork() + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (this->m_network->isConnected()) + { + this->m_currentStatus = INetwork::Disconnecting; // as semaphore we are going to disconnect + this->m_network->terminateConnection(); + this->m_airspace->setConnected(false); + return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityInfo, "Connection terminating"); + } + else if (this->isPendingConnection()) + { + return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityInfo, "Pending connection, please wait"); + } + else + { + return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityWarning, "Already disconnected"); + } + } + + bool CContextNetwork::isConnected() const + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + return this->m_network->isConnected(); + } + + bool CContextNetwork::isPendingConnection() const + { + // if underlying class says pending, we believe it. But not all states (e.g. disconnecting) are covered + if (this->m_network->isPendingConnection()) return true; + + // now check out own extra states, e.g. disconnecting + return INetwork::isPendingStatus(this->m_currentStatus); + } + + bool CContextNetwork::parseCommandLine(const QString &commandLine, const CIdentifier &originator) + { + Q_UNUSED(originator;) + if (commandLine.isEmpty()) { return false; } + CSimpleCommandParser parser({ ".msg", ".m" }); + parser.parse(commandLine); + if (!parser.isKnownCommand()) { return false; } + if (parser.matchesCommand(".msg", ".m")) + { + if (!this->getIContextNetwork()->isConnected()) + { + CLogMessage(this).validationError("Network needs to be connected"); + return false; + } + else if (!this->getIContextOwnAircraft()) + { + CLogMessage(this).validationError("No own aircraft data, no text message can be sent"); + return false; + } + if (parser.countParts() < 3) + { + CLogMessage(this).validationError("Incorrect message"); + return false; + } + QString receiver = parser.part(1).trimmed(); // receiver + + // set receiver + CSimulatedAircraft ownAircraft(this->getIContextOwnAircraft()->getOwnAircraft()); + if (ownAircraft.getCallsign().isEmpty()) + { + CLogMessage(this).validationError("No own callsign"); + return false; + } + + CTextMessage tm; + tm.setSenderCallsign(ownAircraft.getCallsign()); + + if (receiver == "c1" || receiver == "com1") + { + tm.setFrequency(ownAircraft.getCom1System().getFrequencyActive()); + } + else if (receiver == "c2" || receiver == "com2") + { + tm.setFrequency(ownAircraft.getCom2System().getFrequencyActive()); + } + else if (receiver == "u" || receiver == "unicom" || receiver == "uni") + { + tm.setFrequency(CPhysicalQuantitiesConstants::FrequencyUnicom()); + } + else + { + bool isNumber; + double frequencyMhz = receiver.toDouble(&isNumber); + if (isNumber) + { + CFrequency radioFrequency = CFrequency(frequencyMhz, CFrequencyUnit::MHz()); + if (CComSystem::isValidCivilAviationFrequency(radioFrequency)) + { + tm.setFrequency(radioFrequency); + } + else + { + CLogMessage(this).validationError("Wrong COM frequency for text message"); + return false; + } + } + else + { + CCallsign toCallsign(receiver); + tm.setRecipientCallsign(toCallsign); + } + } + + QString msg(parser.remainingStringAfter(2)); + tm.setMessage(msg); + if (tm.isEmpty()) + { + CLogMessage(this).validationError("No text message body"); + return false; + } + CTextMessageList tml(tm); + this->sendTextMessages(tml); + return true; + } + return false; + } + + void CContextNetwork::sendTextMessages(const CTextMessageList &textMessages) + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << textMessages; } + this->m_network->sendTextMessages(textMessages); + } + + void CContextNetwork::sendFlightPlan(const CFlightPlan &flightPlan) + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << flightPlan; } + this->m_network->sendFlightPlan(flightPlan); + this->m_network->sendFlightPlanQuery(this->ownAircraft().getCallsign()); + } + + CFlightPlan CContextNetwork::loadFlightPlanFromNetwork(const BlackMisc::Aviation::CCallsign &callsign) const + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + return this->m_airspace->loadFlightPlanFromNetwork(callsign); + } + + CUserList CContextNetwork::getUsers() const + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + return this->m_airspace->getUsers(); + } + + CUserList CContextNetwork::getUsersForCallsigns(const CCallsignSet &callsigns) const + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + CUserList users; + if (callsigns.isEmpty()) return users; + return this->m_airspace->getUsersForCallsigns(callsigns); + } + + CUser CContextNetwork::getUserForCallsign(const CCallsign &callsign) const + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + CCallsignSet callsigns; + callsigns.push_back(callsign); + CUserList users = this->getUsersForCallsigns(callsigns); + if (users.size() < 1) return CUser(); + return users[0]; + } + + CClientList CContextNetwork::getOtherClients() const + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + return this->m_airspace->getOtherClients(); + } + + CClientList CContextNetwork::getOtherClientsForCallsigns(const CCallsignSet &callsigns) const + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + return this->m_airspace->getOtherClientsForCallsigns(callsigns); + } + + CServerList CContextNetwork::getVatsimFsdServers() const + { + Q_ASSERT_X(sApp->getWebDataServices(), Q_FUNC_INFO, "Missing data reader"); + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + return sApp->getWebDataServices()->getVatsimFsdServers(); + } + + CServerList CContextNetwork::getVatsimVoiceServers() const + { + Q_ASSERT_X(sApp->getWebDataServices(), Q_FUNC_INFO, "Missing data reader"); + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + return sApp->getWebDataServices()->getVatsimVoiceServers(); + } + + void CContextNetwork::ps_fsdConnectionStatusChanged(INetwork::ConnectionStatus from, INetwork::ConnectionStatus to) + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << from << to; } + auto fromOld = this->m_currentStatus; // own status cached + this->m_currentStatus = to; + + if (fromOld == INetwork::Disconnecting) + { + // remark: vatlib does not know disconnecting. In vatlib's terminating connection method + // state Disconnecting is sent manually. We fix the vatlib state here regarding disconnecting + from = INetwork::Disconnecting; + } + + if (to == INetwork::Disconnected) + { + // make sure airspace is really cleaned up + Q_ASSERT(m_airspace); + m_airspace->clear(); + } + + // send 1st position + if (to == INetwork::Connected) + { + CLogMessage(this).info("Connected, own aircraft %1") << this->ownAircraft().getCallsignAsString(); + } + + // send as message + if (to == INetwork::DisconnectedError) + { + CLogMessage(this).error("Connection status changed from %1 to %2") << INetwork::connectionStatusToString(from) << INetwork::connectionStatusToString(to); + } + else + { + CLogMessage(this).info("Connection status changed from %1 to %2") << INetwork::connectionStatusToString(from) << INetwork::connectionStatusToString(to); + } + + // send as own signal + emit this->connectionStatusChanged(from, to); + } + + void CContextNetwork::ps_simulatorRenderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const CLength &maxRenderedDistance, const CLength &maxRenderedBoundary) + { + // mainly passing changed restrictions from simulator to network + if (!m_airspace) { return; } + if (!m_airspace->analyzer()) { return; } + m_airspace->analyzer()->setSimulatorRenderRestrictionsChanged(restricted, enabled, maxAircraft, maxRenderedDistance, maxRenderedBoundary); + } + + void CContextNetwork::ps_updateMetars(const BlackMisc::Weather::CMetarSet &metars) + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + CLogMessage(this).info("%1 METARs updated") << metars.size(); + } + + void CContextNetwork::ps_checkForSupervisiorTextMessage(const CTextMessageList &messages) + { + if (messages.containsPrivateMessages()) + { + CTextMessageList supMessages(messages.getSupervisorMessages()); + for (const CTextMessage &m : supMessages) + { + emit supervisorTextMessageReceived(m); + } + } + } + + const CSimulatedAircraft CContextNetwork::ownAircraft() const + { + Q_ASSERT(this->getRuntime()); + Q_ASSERT(this->getRuntime()->getCContextOwnAircraft()); + return this->getRuntime()->getCContextOwnAircraft()->getOwnAircraft(); + } + + CAtcStationList CContextNetwork::getAtcStationsOnline() const + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + return this->m_airspace->getAtcStationsOnline(); + } + + CAtcStationList CContextNetwork::getAtcStationsBooked() const + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + return this->m_airspace->getAtcStationsBooked(); + } + + CSimulatedAircraftList CContextNetwork::getAircraftInRange() const + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + return this->m_airspace->getAircraftInRange(); + } + + CCallsignSet CContextNetwork::getAircraftInRangeCallsigns() const + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + return this->m_airspace->getAircraftInRangeCallsigns(); + } + + int CContextNetwork::getAircraftInRangeCount() const + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + return this->m_airspace->getAircraftInRangeCount(); + } + + CSimulatedAircraft CContextNetwork::getAircraftInRangeForCallsign(const CCallsign &callsign) const + { + if (this->isDebugEnabled()) { BlackMisc::CLogMessage(this, BlackMisc::CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << callsign; } + return this->m_airspace->getAircraftInRangeForCallsign(callsign); + } + + CAircraftModel CContextNetwork::getAircraftInRangeModelForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const + { + if (this->isDebugEnabled()) { BlackMisc::CLogMessage(this, BlackMisc::CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << callsign; } + return this->m_airspace->getAircraftInRangeModelForCallsign(callsign); + } + + CStatusMessageList CContextNetwork::getReverseLookupMessages(const CCallsign &callsign) const + { + if (this->isDebugEnabled()) { BlackMisc::CLogMessage(this, BlackMisc::CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << callsign; } + return this->m_airspace->getReverseLookupMessages(callsign); + } + + bool CContextNetwork::isReverseLookupMessagesEnabled() const + { + if (this->isDebugEnabled()) { BlackMisc::CLogMessage(this, BlackMisc::CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + return this->m_airspace->isReverseLookupMessagesEnabled(); + } + + void CContextNetwork::enableReverseLookupMessages(bool enabled) + { + if (this->isDebugEnabled()) { BlackMisc::CLogMessage(this, BlackMisc::CLogCategory::contextSlot()).debug() << enabled; } + return this->m_airspace->enableReverseLookupMessages(enabled); + } + + CAtcStation CContextNetwork::getOnlineStationForCallsign(const CCallsign &callsign) const + { + if (this->isDebugEnabled()) { BlackMisc::CLogMessage(this, BlackMisc::CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << callsign; } + return this->m_airspace->getAtcStationsOnline().findFirstByCallsign(callsign); + } + + void CContextNetwork::requestDataUpdates() + { + Q_ASSERT(this->m_network); + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (!this->isConnected()) { return; } + + this->requestAtisUpdates(); + this->m_airspace->requestDataUpdates(); + } + + void CContextNetwork::requestAtisUpdates() + { + Q_ASSERT(this->m_network); + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (!this->isConnected()) { return; } + + this->m_airspace->requestAtisUpdates(); + } + + bool CContextNetwork::updateAircraftEnabled(const CCallsign &callsign, bool enabledForRedering, const BlackMisc::CIdentifier &originator) + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << callsign << enabledForRedering << originator; } + bool c = this->m_airspace->updateAircraftEnabled(callsign, enabledForRedering, originator); + if (c) + { + CSimulatedAircraft aircraft(this->getAircraftInRangeForCallsign(callsign)); + emit this->changedRemoteAircraftEnabled(aircraft, originator); + } + return c; + } + + bool CContextNetwork::updateAircraftModel(const CCallsign &callsign, const CAircraftModel &model, const BlackMisc::CIdentifier &originator) + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << callsign << model << originator; } + bool c = this->m_airspace->updateAircraftModel(callsign, model, originator); + if (c) + { + CSimulatedAircraft aircraft(this->getAircraftInRangeForCallsign(callsign)); + emit this->changedRemoteAircraftModel(aircraft, originator); + } + return c; + } + + bool CContextNetwork::updateFastPositionEnabled(const CCallsign &callsign, bool enableFastPositonUpdates, const BlackMisc::CIdentifier &originator) + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << callsign << enableFastPositonUpdates << originator; } + bool c = this->m_airspace->updateFastPositionEnabled(callsign, enableFastPositonUpdates, originator); + if (c) + { + CSimulatedAircraft aircraft(this->getAircraftInRangeForCallsign(callsign)); + CLogMessage(this).info("Callsign %1 sets fast positions ") << aircraft.getCallsign() << BlackMisc::boolToOnOff(aircraft.fastPositionUpdates()); + emit this->changedFastPositionUpdates(aircraft, originator); + } + return c; + } + + void CContextNetwork::readAtcBookingsFromSource() const + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + Q_ASSERT_X(sApp->getWebDataServices(), Q_FUNC_INFO, "missing reader"); + sApp->getWebDataServices()->readInBackground(BlackMisc::Network::CEntityFlags::BookingEntity); + } + + bool CContextNetwork::updateAircraftRendered(const CCallsign &callsign, bool rendered, const CIdentifier &originator) + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << callsign << rendered << originator; } + bool c = this->m_airspace->updateAircraftRendered(callsign, rendered, originator); + return c; + } + + void CContextNetwork::updateMarkAllAsNotRendered(const CIdentifier &originator) + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << originator; } + this->m_airspace->updateMarkAllAsNotRendered(originator); + } + + CAirspaceAircraftSnapshot CContextNetwork::getLatestAirspaceAircraftSnapshot() const + { + return this->m_airspace->getLatestAirspaceAircraftSnapshot(); + } + + void CContextNetwork::setFastPositionEnabledCallsigns(CCallsignSet &callsigns) + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << callsigns; } + Q_ASSERT(this->m_network); + } + + CCallsignSet CContextNetwork::getFastPositionEnabledCallsigns() + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + Q_ASSERT(this->m_network); + //! \todo Fast position updates in vatlib + return CCallsignSet(); + } + + void CContextNetwork::testCreateDummyOnlineAtcStations(int number) + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << number; } + this->m_airspace->testCreateDummyOnlineAtcStations(number); + } + + void CContextNetwork::testAddAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, const CAircraftParts &parts, bool incremental) + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << parts << incremental; } + this->m_airspace->testAddAircraftParts(callsign, parts, incremental); + } + + CMetar CContextNetwork::getMetarForAirport(const BlackMisc::Aviation::CAirportIcaoCode &airportIcaoCode) const + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << airportIcaoCode; } + return sApp->getWebDataServices()->getMetarForAirport(airportIcaoCode); + } + + CAtcStationList CContextNetwork::getSelectedAtcStations() const + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + CAtcStation com1Station = this->m_airspace->getAtcStationForComUnit(this->ownAircraft().getCom1System()); + CAtcStation com2Station = this->m_airspace->getAtcStationForComUnit(this->ownAircraft().getCom2System()); + + CAtcStationList selectedStations; + selectedStations.push_back(com1Station); + selectedStations.push_back(com2Station); + return selectedStations; + } + + CVoiceRoomList CContextNetwork::getSelectedVoiceRooms() const + { + if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + CAtcStationList stations = this->getSelectedAtcStations(); + Q_ASSERT(stations.size() == 2); + CVoiceRoomList rooms; + CAtcStation s1 = stations[0]; + CAtcStation s2 = stations[1]; + rooms.push_back(s1.getVoiceRoom()); + rooms.push_back(s2.getVoiceRoom()); + return rooms; + } + } // namespace +} // namespace diff --git a/src/blackcore/context/contextnetworkimpl.h b/src/blackcore/context/contextnetworkimpl.h new file mode 100644 index 000000000..29e1d421f --- /dev/null +++ b/src/blackcore/context/contextnetworkimpl.h @@ -0,0 +1,313 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of Swift Project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKCORE_CONTEXT_CONTEXTNETWORK_IMPL_H +#define BLACKCORE_CONTEXT_CONTEXTNETWORK_IMPL_H + +#include +#include +#include +#include +#include +#include + +#include "blackcore/blackcoreexport.h" +#include "blackcore/context/contextnetwork.h" +#include "blackcore/corefacadeconfig.h" +#include "blackcore/network.h" +#include "blackmisc/audio/voiceroomlist.h" +#include "blackmisc/aviation/aircraftpartslist.h" +#include "blackmisc/aviation/aircraftsituationlist.h" +#include "blackmisc/aviation/airporticaocode.h" +#include "blackmisc/aviation/atcstation.h" +#include "blackmisc/aviation/atcstationlist.h" +#include "blackmisc/aviation/callsignset.h" +#include "blackmisc/aviation/flightplan.h" +#include "blackmisc/digestsignal.h" +#include "blackmisc/identifier.h" +#include "blackmisc/network/clientlist.h" +#include "blackmisc/network/server.h" +#include "blackmisc/network/serverlist.h" +#include "blackmisc/network/textmessagelist.h" +#include "blackmisc/network/user.h" +#include "blackmisc/network/userlist.h" +#include "blackmisc/pq/length.h" +#include "blackmisc/simulation/aircraftmodel.h" +#include "blackmisc/simulation/airspaceaircraftsnapshot.h" +#include "blackmisc/simulation/remoteaircraftprovider.h" +#include "blackmisc/simulation/simulatedaircraft.h" +#include "blackmisc/simulation/simulatedaircraftlist.h" +#include "blackmisc/statusmessage.h" +#include "blackmisc/weather/metar.h" +#include "blackmisc/weather/metarset.h" + +class QTimer; + +namespace BlackMisc +{ + class CDBusServer; + namespace Aviation + { + class CAircraftParts; + class CAircraftSituation; + class CCallsign; + } +} + +namespace BlackCore +{ + class CAirspaceMonitor; + class CCoreFacade; + namespace Context + { + //! Network context implementation + class BLACKCORE_EXPORT CContextNetwork : + public IContextNetwork, + public BlackMisc::Simulation::IRemoteAircraftProvider + { + Q_OBJECT + Q_INTERFACES(BlackMisc::Simulation::IRemoteAircraftProvider) + Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTNETWORK_INTERFACENAME) + + friend class IContextNetwork; + friend class BlackCore::CCoreFacade; + + public: + //! Destructor + virtual ~CContextNetwork(); + + //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::remoteAircraftSituations + //! \ingroup remoteaircraftprovider + virtual BlackMisc::Aviation::CAircraftSituationList remoteAircraftSituations(const BlackMisc::Aviation::CCallsign &callsign) const override; + + //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::remoteAircraftSituationsCount + //! \ingroup remoteaircraftprovider + virtual int remoteAircraftSituationsCount(const BlackMisc::Aviation::CCallsign &callsign) const override; + + //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::remoteAircraftParts + //! \ingroup remoteaircraftprovider + virtual BlackMisc::Aviation::CAircraftPartsList remoteAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, qint64 cutoffTimeBefore = -1) const override; + + //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::isRemoteAircraftSupportingParts + //! \ingroup remoteaircraftprovider + virtual bool isRemoteAircraftSupportingParts(const BlackMisc::Aviation::CCallsign &callsign) const override; + + //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::remoteAircraftSupportingParts + //! \ingroup remoteaircraftprovider + virtual BlackMisc::Aviation::CCallsignSet remoteAircraftSupportingParts() const override; + + //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::connectRemoteAircraftProviderSignals + //! \ingroup remoteaircraftprovider + virtual QList connectRemoteAircraftProviderSignals( + QObject *receiver, + std::function addedSituationSlot, + std::function addedPartsSlot, + std::function removedAircraftSlot, + std::function aircraftSnapshotSlot + ) override; + + //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::updateAircraftRendered + //! \ingroup remoteaircraftprovider + virtual bool updateAircraftRendered(const BlackMisc::Aviation::CCallsign &callsign, bool rendered, const BlackMisc::CIdentifier &originator) override; + + //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::updateMarkAllAsNotRendered + //! \ingroup remoteaircraftprovider + virtual void updateMarkAllAsNotRendered(const BlackMisc::CIdentifier &originator) override; + + //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::getLatestAirspaceAircraftSnapshot + //! \ingroup remoteaircraftprovider + virtual BlackMisc::Simulation::CAirspaceAircraftSnapshot getLatestAirspaceAircraftSnapshot() const override; + + //! Network library + INetwork *network() const { return m_network; } + + public slots: + //! \copydoc IContextNetwork::updateAircraftEnabled + //! \ingroup remoteaircraftprovider + virtual bool updateAircraftEnabled(const BlackMisc::Aviation::CCallsign &callsign, bool enabledForRedering, const BlackMisc::CIdentifier &originator) override; + + //! \copydoc IContextNetwork::updateAircraftModel + //! \ingroup remoteaircraftprovider + virtual bool updateAircraftModel(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Simulation::CAircraftModel &model, const BlackMisc::CIdentifier &originator) override; + + //! \copydoc IContextNetwork::updateFastPositionEnabled + //! \ingroup remoteaircraftprovider + virtual bool updateFastPositionEnabled(const BlackMisc::Aviation::CCallsign &callsign, bool enableFastPositonUpdates, const BlackMisc::CIdentifier &originator) override; + + //! \copydoc IContextNetwork::readAtcBookingsFromSource() + virtual void readAtcBookingsFromSource() const override; + + //! \copydoc IContextNetwork::getAtcStationsOnline() + virtual BlackMisc::Aviation::CAtcStationList getAtcStationsOnline() const override; + + //! \copydoc IContextNetwork::getAtcStationsBooked() + virtual BlackMisc::Aviation::CAtcStationList getAtcStationsBooked() const override; + + //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::getAircraftInRange + //! \ingroup remoteaircraftprovider + virtual BlackMisc::Simulation::CSimulatedAircraftList getAircraftInRange() const override; + + //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::getAircraftInRangeCallsigns + //! \ingroup remoteaircraftprovider + virtual BlackMisc::Aviation::CCallsignSet getAircraftInRangeCallsigns() const override; + + //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::getAircraftInRangeCount + //! \ingroup remoteaircraftprovider + virtual int getAircraftInRangeCount() const override; + + //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::getAircraftInRangeForCallsign + //! \ingroup remoteaircraftprovider + virtual BlackMisc::Simulation::CSimulatedAircraft getAircraftInRangeForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override; + + //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::getAircraftInRangeModelForCallsign + //! \ingroup remoteaircraftprovider + virtual BlackMisc::Simulation::CAircraftModel getAircraftInRangeModelForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override; + + //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::getReverseLookupMessages + //! \ingroup remoteaircraftprovider + virtual BlackMisc::CStatusMessageList getReverseLookupMessages(const BlackMisc::Aviation::CCallsign &callsign) const override; + + //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::isReverseLookupMessagesEnabled + //! \ingroup remoteaircraftprovider + virtual bool isReverseLookupMessagesEnabled() const override; + + //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::enableReverseLookupMessages + //! \ingroup remoteaircraftprovider + virtual void enableReverseLookupMessages(bool enabled) override; + + //! \copydoc IContextNetwork::getOnlineStationForCallsign + virtual BlackMisc::Aviation::CAtcStation getOnlineStationForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override; + + //! \copydoc IContextNetwork::connectToNetwork() + virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, BlackCore::INetwork::LoginMode mode) override; + + //! \copydoc IContextNetwork::getConnectedServer + virtual BlackMisc::Network::CServer getConnectedServer() const override; + + //! \copydoc IContextNetwork::disconnectFromNetwork() + virtual BlackMisc::CStatusMessage disconnectFromNetwork() override; + + //! \copydoc IContextNetwork::isConnected() + virtual bool isConnected() const override; + + //! In transition state, e.g. connecting, disconnecting. + //! \details In such a state it is advisable to wait until an end state (connected/disconnected) is reached + //! \remarks Intentionally only running locally, not in interface + bool isPendingConnection() const; + + //! \ingroup commandline + //! @{ + //!
+            //! .m  .msg   message text
+            //! 
+ //! @} + //! \copydoc IContextNetwork::parseCommandLine + virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override; + + //! \copydoc IContextNetwork::sendTextMessages() + virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &textMessages) override; + + //! \copydoc IContextNetwork::sendFlightPlan() + virtual void sendFlightPlan(const BlackMisc::Aviation::CFlightPlan &flightPlan) override; + + //! \copydoc IContextNetwork::loadFlightPlanFromNetwork() + virtual BlackMisc::Aviation::CFlightPlan loadFlightPlanFromNetwork(const BlackMisc::Aviation::CCallsign &callsign) const override; + + //! \copydoc IContextNetwork::getMetarForAirport + BlackMisc::Weather::CMetar getMetarForAirport(const BlackMisc::Aviation::CAirportIcaoCode &airportIcaoCode) const override; + + //! \copydoc IContextNetwork::getSelectedVoiceRooms() + virtual BlackMisc::Audio::CVoiceRoomList getSelectedVoiceRooms() const override; + + //! \copydoc IContextNetwork::getSelectedAtcStations + virtual BlackMisc::Aviation::CAtcStationList getSelectedAtcStations() const override; + + //! \copydoc IContextNetwork::getUsers() + virtual BlackMisc::Network::CUserList getUsers() const override; + + //! \copydoc IContextNetwork::getUsersForCallsigns + virtual BlackMisc::Network::CUserList getUsersForCallsigns(const BlackMisc::Aviation::CCallsignSet &callsigns) const override; + + //! \copydoc IContextNetwork::getUserForCallsign + virtual BlackMisc::Network::CUser getUserForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override; + + //! \copydoc IContextNetwork::getOtherClients + virtual BlackMisc::Network::CClientList getOtherClients() const override; + + //! \copydoc IContextNetwork::getOtherClientsForCallsigns + virtual BlackMisc::Network::CClientList getOtherClientsForCallsigns(const BlackMisc::Aviation::CCallsignSet &callsigns) const override; + + //! \copydoc IContextNetwork::getVatsimFsdServers + virtual BlackMisc::Network::CServerList getVatsimFsdServers() const override; + + //! \copydoc IContextNetwork::getVatsimVoiceServers + virtual BlackMisc::Network::CServerList getVatsimVoiceServers() const override; + + //! \copydoc IContextNetwork::requestDataUpdates + virtual void requestDataUpdates()override; + + //! \copydoc IContextNetwork::requestAtisUpdates + virtual void requestAtisUpdates() override; + + //! \copydoc IContextNetwork::setFastPositionEnabledCallsigns + virtual void setFastPositionEnabledCallsigns(BlackMisc::Aviation::CCallsignSet &callsigns) override; + + //! \copydoc IContextNetwork::getFastPositionEnabledCallsigns + virtual BlackMisc::Aviation::CCallsignSet getFastPositionEnabledCallsigns() override; + + //! \copydoc IContextNetwork::testCreateDummyOnlineAtcStations + virtual void testCreateDummyOnlineAtcStations(int number) override; + + //! \copydoc IContextNetwork::testAddAircraftParts + virtual void testAddAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftParts &parts, bool incremental) override; + + //! Gracefully shut down, e.g. for thread safety + void gracefulShutdown(); + + protected: + //! Constructor, with link to runtime + CContextNetwork(CCoreFacadeConfig::ContextMode, CCoreFacade *runtime); + + //! Register myself in DBus + CContextNetwork *registerWithDBus(BlackMisc::CDBusServer *server); + + private: + CAirspaceMonitor *m_airspace = nullptr; + INetwork *m_network = nullptr; + INetwork::ConnectionStatus m_currentStatus = INetwork::Disconnected; //!< used to detect pending connections + QTimer *m_networkDataUpdateTimer = nullptr; //!< general updates such as ATIS, frequencies, see requestDataUpdates() + + // Digest signals, only sending after some time + BlackMisc::CDigestSignal m_dsAtcStationsBookedChanged { this, &IContextNetwork::changedAtcStationsBooked, &IContextNetwork::changedAtcStationsBookedDigest, 750, 2 }; + BlackMisc::CDigestSignal m_dsAtcStationsOnlineChanged { this, &IContextNetwork::changedAtcStationsOnline, &IContextNetwork::changedAtcStationsOnlineDigest, 750, 4 }; + BlackMisc::CDigestSignal m_dsAircraftsInRangeChanged { this, &IContextNetwork::changedAircraftInRange, &IContextNetwork::changedAircraftInRangeDigest, 750, 4 }; + + //! Own aircraft from \sa CContextOwnAircraft + const BlackMisc::Simulation::CSimulatedAircraft ownAircraft() const; + + private slots: + //! Update METAR collection + void ps_updateMetars(const BlackMisc::Weather::CMetarSet &metars); + + //! Check if a supervisor message was received + void ps_checkForSupervisiorTextMessage(const BlackMisc::Network::CTextMessageList &messages); + + //! Connection status changed + void ps_fsdConnectionStatusChanged(INetwork::ConnectionStatus from, INetwork::ConnectionStatus to); + + //! Render restrictions have been changed, used with analyzer + //! \sa CAirspaceAnalyzer + void ps_simulatorRenderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance, const BlackMisc::PhysicalQuantities::CLength &maxRenderedBoundary); + }; + } // ns +} // ns + +#endif // guard diff --git a/src/blackcore/context/contextnetworkproxy.cpp b/src/blackcore/context/contextnetworkproxy.cpp new file mode 100644 index 000000000..682a2be7c --- /dev/null +++ b/src/blackcore/context/contextnetworkproxy.cpp @@ -0,0 +1,283 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "blackcore/context/contextnetworkproxy.h" +#include "blackmisc/audio/voiceroomlist.h" +#include "blackmisc/dbus.h" +#include "blackmisc/genericdbusinterface.h" + +#include +#include +#include +#include + +using namespace BlackMisc; +using namespace BlackMisc::Network; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::Audio; +using namespace BlackMisc::Weather; +using namespace BlackMisc::Simulation; + +namespace BlackCore +{ + namespace Context + { + CContextNetworkProxy::CContextNetworkProxy(const QString &serviceName, QDBusConnection &connection, CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextNetwork(mode, runtime), m_dBusInterface(nullptr) + { + this->m_dBusInterface = new BlackMisc::CGenericDBusInterface( + serviceName , IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), + connection, this); + this->relaySignals(serviceName, connection); + } + + void CContextNetworkProxy::relaySignals(const QString &serviceName, QDBusConnection &connection) + { + bool s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), + "connectionStatusChanged", this, SIGNAL(connectionStatusChanged(BlackCore::INetwork::ConnectionStatus, BlackCore::INetwork::ConnectionStatus))); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), + "changedAtcStationsBooked", this, SIGNAL(changedAtcStationsBooked())); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), + "changedAtcStationsOnline", this, SIGNAL(changedAtcStationsOnline())); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), + "changedAtcStationsBookedDigest", this, SIGNAL(changedAtcStationsBookedDigest())); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), + "changedAtcStationsOnlineDigest", this, SIGNAL(changedAtcStationsOnlineDigest())); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), + "changedAircraftInRange", this, SIGNAL(changedAircraftInRange())); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), + "changedAtcStationOnlineConnectionStatus", this, SIGNAL(changedAtcStationOnlineConnectionStatus(BlackMisc::Aviation::CAtcStation, bool))); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), + "changedAircraftInRangeDigest", this, SIGNAL(changedAircraftInRangeDigest())); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), + "connectionTerminated", this, SIGNAL(connectionTerminated())); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), + "textMessagesReceived", this, SIGNAL(textMessagesReceived(BlackMisc::Network::CTextMessageList))); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), + "textMessageSent", this, SIGNAL(textMessageSent(BlackMisc::Network::CTextMessage))); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), + "webServiceDataRead", this, SIGNAL(webServiceDataRead(int, int, int))); + + Q_ASSERT(s); + s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), + "changedRemoteAircraftEnabled", this, SIGNAL(changedRemoteAircraftEnabled(BlackMisc::Simulation::CSimulatedAircraft, BlackMisc::CIdentifier))); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), + "changedFastPositionUpdates", this, SIGNAL(changedFastPositionUpdates(BlackMisc::Simulation::CSimulatedAircraft, BlackMisc::CIdentifier))); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), + "addedAircraft", this, SIGNAL(addedAircraft(BlackMisc::Simulation::CSimulatedAircraft))); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), + "removedAircraft", this, SIGNAL(removedAircraft(BlackMisc::Aviation::CCallsign))); + Q_ASSERT(s); + Q_UNUSED(s); + } + + void CContextNetworkProxy::readAtcBookingsFromSource() const + { + this->m_dBusInterface->callDBus(QLatin1Literal("readAtcBookingsFromSource")); + } + + BlackMisc::Aviation::CAtcStationList CContextNetworkProxy::getAtcStationsOnline() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getAtcStationsOnline")); + } + + CAtcStationList CContextNetworkProxy::getAtcStationsBooked() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getAtcStationsBooked")); + } + + CSimulatedAircraftList CContextNetworkProxy::getAircraftInRange() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getAircraftInRange")); + } + + CCallsignSet CContextNetworkProxy::getAircraftInRangeCallsigns() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getAircraftInRangeCallsigns")); + } + + int CContextNetworkProxy::getAircraftInRangeCount() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getAircraftInRangeCount")); + } + + CSimulatedAircraft CContextNetworkProxy::getAircraftInRangeForCallsign(const CCallsign &callsign) const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getAircraftInRangeForCallsign"), callsign); + } + + CAtcStation CContextNetworkProxy::getOnlineStationForCallsign(const CCallsign &callsign) const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getOnlineStationForCallsign"), callsign); + } + + CUserList CContextNetworkProxy::getUsers() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getUsers")); + } + + CUserList CContextNetworkProxy::getUsersForCallsigns(const BlackMisc::Aviation::CCallsignSet &callsigns) const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getUsersForCallsigns"), callsigns); + } + + CUser CContextNetworkProxy::getUserForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getUserForCallsign"), callsign); + } + + CClientList CContextNetworkProxy::getOtherClients() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getOtherClients")); + } + + CServerList CContextNetworkProxy::getVatsimFsdServers() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getVatsimFsdServers")); + } + + CServerList CContextNetworkProxy::getVatsimVoiceServers() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getVatsimVoiceServers")); + } + + CClientList CContextNetworkProxy::getOtherClientsForCallsigns(const BlackMisc::Aviation::CCallsignSet &callsigns) const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getOtherClientsForCallsigns"), callsigns); + } + + CVoiceRoomList CContextNetworkProxy::getSelectedVoiceRooms() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getSelectedVoiceRooms")); + } + + CAtcStationList CContextNetworkProxy::getSelectedAtcStations() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getSelectedAtcStations")); + } + + void CContextNetworkProxy::requestDataUpdates() + { + this->m_dBusInterface->callDBus(QLatin1Literal("requestDataUpdates")); + } + + void CContextNetworkProxy::requestAtisUpdates() + { + this->m_dBusInterface->callDBus(QLatin1Literal("requestAtisUpdates")); + } + + bool CContextNetworkProxy::updateAircraftEnabled(const CCallsign &callsign, bool enabledForRedering, const CIdentifier &originator) + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("updateAircraftEnabled"), callsign, enabledForRedering, originator); + } + + bool CContextNetworkProxy::updateAircraftModel(const CCallsign &callsign, const CAircraftModel &model, const CIdentifier &originator) + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("updateAircraftModel"), callsign, model, originator); + } + + bool CContextNetworkProxy::updateFastPositionEnabled(const CCallsign &callsign, bool enableFastPositionSending, const CIdentifier &originator) + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("updateFastPositionEnabled"), callsign, enableFastPositionSending, originator); + } + + void CContextNetworkProxy::setFastPositionEnabledCallsigns(CCallsignSet &callsigns) + { + this->m_dBusInterface->callDBus(QLatin1Literal("setFastPositionEnabledCallsigns"), callsigns); + } + + CCallsignSet CContextNetworkProxy::getFastPositionEnabledCallsigns() + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getFastPositionEnabledCallsigns")); + } + + CStatusMessageList CContextNetworkProxy::getReverseLookupMessages(const CCallsign &callsign) const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getReverseLookupMessages"), callsign); + } + + bool CContextNetworkProxy::isReverseLookupMessagesEnabled() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("isReverseLookupLoggingEnabled")); + } + + void CContextNetworkProxy::enableReverseLookupMessages(bool enabled) + { + this->m_dBusInterface->callDBus(QLatin1Literal("enableReverseLookupLogging"), enabled); + } + + void CContextNetworkProxy::testCreateDummyOnlineAtcStations(int number) + { + this->m_dBusInterface->callDBus(QLatin1Literal("testCreateDummyOnlineAtcStations"), number); + } + + void CContextNetworkProxy::testAddAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, const CAircraftParts &parts, bool incremental) + { + this->m_dBusInterface->callDBus(QLatin1Literal("testAddAircraftParts"), callsign, parts, incremental); + } + + CStatusMessage CContextNetworkProxy::connectToNetwork(const CServer &server, INetwork::LoginMode loginMode) + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("connectToNetwork"), server, loginMode); + } + + CStatusMessage CContextNetworkProxy::disconnectFromNetwork() + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("disconnectFromNetwork")); + } + + bool CContextNetworkProxy::isConnected() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("isConnected")); + } + + CServer CContextNetworkProxy::getConnectedServer() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getConnectedServer")); + } + + bool CContextNetworkProxy::parseCommandLine(const QString &commandLine, const CIdentifier &originator) + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("parseCommandLine"), commandLine, originator); + } + + void CContextNetworkProxy::sendTextMessages(const CTextMessageList &textMessages) + { + this->m_dBusInterface->callDBus(QLatin1Literal("sendTextMessages"), textMessages); + } + + void CContextNetworkProxy::sendFlightPlan(const BlackMisc::Aviation::CFlightPlan &flightPlan) + { + this->m_dBusInterface->callDBus(QLatin1Literal("sendFlightPlan"), flightPlan); + } + + CFlightPlan CContextNetworkProxy::loadFlightPlanFromNetwork(const CCallsign &callsign) const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("loadFlightPlanFromNetwork"), callsign); + } + + CMetar CContextNetworkProxy::getMetarForAirport(const CAirportIcaoCode &airportIcaoCode) const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getMetarForAirport"), airportIcaoCode); + } + } // ns +} // ns diff --git a/src/blackcore/context/contextnetworkproxy.h b/src/blackcore/context/contextnetworkproxy.h new file mode 100644 index 000000000..cf8bace30 --- /dev/null +++ b/src/blackcore/context/contextnetworkproxy.h @@ -0,0 +1,203 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKCORE_CONTEXT_CONTEXTNETWORK_PROXY_H +#define BLACKCORE_CONTEXT_CONTEXTNETWORK_PROXY_H + +#include "blackcore/blackcoreexport.h" +#include "blackcore/context/contextnetwork.h" +#include "blackcore/corefacadeconfig.h" +#include "blackcoreexport.h" +#include "blackmisc/audio/voiceroomlist.h" +#include "blackmisc/aviation/airporticaocode.h" +#include "blackmisc/aviation/atcstation.h" +#include "blackmisc/aviation/atcstationlist.h" +#include "blackmisc/aviation/callsignset.h" +#include "blackmisc/aviation/flightplan.h" +#include "blackmisc/identifier.h" +#include "blackmisc/network/clientlist.h" +#include "blackmisc/network/network.h" +#include "blackmisc/network/server.h" +#include "blackmisc/network/serverlist.h" +#include "blackmisc/network/textmessagelist.h" +#include "blackmisc/network/user.h" +#include "blackmisc/network/userlist.h" +#include "blackmisc/simulation/simulatedaircraft.h" +#include "blackmisc/simulation/simulatedaircraftlist.h" +#include "blackmisc/statusmessage.h" +#include "blackmisc/weather/metar.h" + +#include +#include +#include + +class QDBusConnection; + +namespace BlackMisc +{ + class CGenericDBusInterface; + namespace Aviation + { + class CAircraftParts; + class CCallsign; + } + namespace Simulation { class CAircraftModel; } +} + +namespace BlackCore +{ + class CCoreFacade; + namespace Context + { + + //! Network context proxy + //! \ingroup dbus + class BLACKCORE_EXPORT CContextNetworkProxy : public IContextNetwork + { + Q_OBJECT + friend class IContextNetwork; + + public: + + //! Destructor + virtual ~CContextNetworkProxy() {} + + public slots: + //! \copydoc IContextNetwork::readAtcBookingsFromSource() + virtual void readAtcBookingsFromSource() const override; + + //! \copydoc IContextNetwork::getAtcStationsOnline() + virtual BlackMisc::Aviation::CAtcStationList getAtcStationsOnline() const override; + + //! \copydoc IContextNetwork::getAtcStationsBooked() + virtual BlackMisc::Aviation::CAtcStationList getAtcStationsBooked() const override; + + //! \copydoc IContextNetwork::getAircraftInRange() + virtual BlackMisc::Simulation::CSimulatedAircraftList getAircraftInRange() const override; + + //! \copydoc IContextNetwork::getAircraftInRangeCallsigns() + virtual BlackMisc::Aviation::CCallsignSet getAircraftInRangeCallsigns() const override; + + //! \copydoc IContextNetwork::getAircraftInRangeCount + virtual int getAircraftInRangeCount() const override; + + //! \copydoc IContextNetwork::getAircraftInRangeForCallsign + virtual BlackMisc::Simulation::CSimulatedAircraft getAircraftInRangeForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override; + + //! \copydoc IContextNetwork::getOnlineStationForCallsign + virtual BlackMisc::Aviation::CAtcStation getOnlineStationForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override; + + //! \copydoc IContextNetwork::connectToNetwork + virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, BlackCore::INetwork::LoginMode mode) override; + + //! \copydoc IContextNetwork::disconnectFromNetwork() + virtual BlackMisc::CStatusMessage disconnectFromNetwork() override; + + //! \copydoc IContextNetwork::isConnected() + virtual bool isConnected() const override; + + //! \copydoc IContextNetwork::getConnectedServer + virtual BlackMisc::Network::CServer getConnectedServer() const override; + + //! \copydoc IContextNetwork::parseCommandLine + virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override; + + //! \copydoc IContextNetwork::sendTextMessages() + virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &textMessages) override; + + //! \copydoc IContextNetwork::sendFlightPlan() + virtual void sendFlightPlan(const BlackMisc::Aviation::CFlightPlan &flightPlan) override; + + //! \copydoc IContextNetwork::loadFlightPlanFromNetwork() + virtual BlackMisc::Aviation::CFlightPlan loadFlightPlanFromNetwork(const BlackMisc::Aviation::CCallsign &callsign) const override; + + //! \copydoc IContextNetwork::getMetarForAirport + BlackMisc::Weather::CMetar getMetarForAirport(const BlackMisc::Aviation::CAirportIcaoCode &airportIcaoCode) const override; + + //! \copydoc IContextNetwork::getSelectedVoiceRooms() + virtual BlackMisc::Audio::CVoiceRoomList getSelectedVoiceRooms() const override; + + //! \copydoc IContextNetwork::getSelectedAtcStations + virtual BlackMisc::Aviation::CAtcStationList getSelectedAtcStations() const override; + + //! \copydoc IContextNetwork::getUsers() + virtual BlackMisc::Network::CUserList getUsers() const override; + + //! \copydoc IContextNetwork::getUsersForCallsigns + virtual BlackMisc::Network::CUserList getUsersForCallsigns(const BlackMisc::Aviation::CCallsignSet &callsigns) const override; + + //! \copydoc IContextNetwork::getUserForCallsign + virtual BlackMisc::Network::CUser getUserForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override; + + //! \copydoc IContextNetwork::getOtherClients + virtual BlackMisc::Network::CClientList getOtherClients() const override; + + //! \copydoc IContextNetwork::getVatsimVoiceServers + virtual BlackMisc::Network::CServerList getVatsimVoiceServers() const override; + + //! \copydoc IContextNetwork::getVatsimFsdServers + virtual BlackMisc::Network::CServerList getVatsimFsdServers() const override; + + //! \copydoc IContextNetwork::getOtherClientsForCallsigns + virtual BlackMisc::Network::CClientList getOtherClientsForCallsigns(const BlackMisc::Aviation::CCallsignSet &callsigns) const override; + + //! \copydoc IContextNetwork::requestDataUpdates + virtual void requestDataUpdates()override; + + //! \copydoc IContextNetwork::requestAtisUpdates + virtual void requestAtisUpdates() override; + + //! \copydoc IContextNetwork::updateAircraftEnabled + virtual bool updateAircraftEnabled(const BlackMisc::Aviation::CCallsign &callsign, bool enabledForRedering, const BlackMisc::CIdentifier &originator) override; + + //! \copydoc IContextNetwork::updateAircraftModel + virtual bool updateAircraftModel(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Simulation::CAircraftModel &model, const BlackMisc::CIdentifier &originator) override; + + //! \copydoc IContextNetwork::updateFastPositionEnabled + virtual bool updateFastPositionEnabled(const BlackMisc::Aviation::CCallsign &callsign, bool enableFastPositionSending, const BlackMisc::CIdentifier &originator) override; + + //! \copydoc IContextNetwork::setFastPositionEnabledCallsigns + virtual void setFastPositionEnabledCallsigns(BlackMisc::Aviation::CCallsignSet &callsigns) override; + + //! \copydoc IContextNetwork::getFastPositionEnabledCallsigns + virtual BlackMisc::Aviation::CCallsignSet getFastPositionEnabledCallsigns() override; + + //! \copydoc IContextNetwork::getReverseLookupMessages + virtual BlackMisc::CStatusMessageList getReverseLookupMessages(const BlackMisc::Aviation::CCallsign &callsign) const override; + + //! \copydoc IContextNetwork::isReverseLookupMessagesEnabled + virtual bool isReverseLookupMessagesEnabled() const override; + + //! \copydoc IContextNetwork::enableReverseLookupMessages + virtual void enableReverseLookupMessages(bool enabled) override; + + //! \copydoc IContextNetwork::testCreateDummyOnlineAtcStations + virtual void testCreateDummyOnlineAtcStations(int number) override; + + //! \copydoc IContextNetwork::testAddAircraftParts + virtual void testAddAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftParts &parts, bool incremental) override; + + private: + BlackMisc::CGenericDBusInterface *m_dBusInterface; /*!< DBus interface */ + + //! Relay connection signals to local signals. + void relaySignals(const QString &serviceName, QDBusConnection &connection); + + protected: + //! Constructor + CContextNetworkProxy(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextNetwork(mode, runtime), m_dBusInterface(nullptr) {} + + //! DBus version constructor + CContextNetworkProxy(const QString &serviceName, QDBusConnection &connection, CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime); + }; + } // ns +} // ns +#endif // guard diff --git a/src/blackcore/context/contextownaircraft.cpp b/src/blackcore/context/contextownaircraft.cpp new file mode 100644 index 000000000..ba363cea5 --- /dev/null +++ b/src/blackcore/context/contextownaircraft.cpp @@ -0,0 +1,35 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "blackcore/context/contextownaircraft.h" +#include "blackcore/context/contextownaircraftempty.h" +#include "blackcore/context/contextownaircraftimpl.h" +#include "blackcore/context/contextownaircraftproxy.h" +#include "blackmisc/dbusserver.h" + +namespace BlackCore +{ + namespace Context + { + IContextOwnAircraft *IContextOwnAircraft::create(CCoreFacade *parent, CCoreFacadeConfig::ContextMode mode, BlackMisc::CDBusServer *server, QDBusConnection &conn) + { + switch (mode) + { + case CCoreFacadeConfig::Local: + case CCoreFacadeConfig::LocalInDbusServer: + return (new CContextOwnAircraft(mode, parent))->registerWithDBus(server); + case CCoreFacadeConfig::Remote: + return new CContextOwnAircraftProxy(BlackMisc::CDBusServer::coreServiceName(), conn, mode, parent); + case CCoreFacadeConfig::NotUsed: + default: + return new CContextOwnAircraftEmpty(parent); + } + } + } // namespace +} // namespace diff --git a/src/blackcore/context/contextownaircraft.h b/src/blackcore/context/contextownaircraft.h new file mode 100644 index 000000000..895dbb235 --- /dev/null +++ b/src/blackcore/context/contextownaircraft.h @@ -0,0 +1,153 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKCORE_CONTEXT_CONTEXTOWNAIRCRAFT_H +#define BLACKCORE_CONTEXT_CONTEXTOWNAIRCRAFT_H + +#include "blackcore/blackcoreexport.h" +#include "blackcore/context/context.h" +#include "blackcore/corefacade.h" +#include "blackcore/corefacadeconfig.h" +#include "blackmisc/aviation/airlineicaocode.h" +#include "blackmisc/aviation/comsystem.h" +#include "blackmisc/aviation/selcal.h" +#include "blackmisc/geo/coordinategeodetic.h" +#include "blackmisc/identifier.h" +#include "blackmisc/network/user.h" +#include "blackmisc/pq/frequency.h" +#include "blackmisc/simulation/simulatedaircraft.h" + +#include +#include + +//! \addtogroup dbus +//! @{ + +//! DBus interface for context +#define BLACKCORE_CONTEXTOWNAIRCRAFT_INTERFACENAME "org.swift_project.blackcore.contextownaircraft" + +//! DBus object path for context +#define BLACKCORE_CONTEXTOWNAIRCRAFT_OBJECTPATH "/ownaircraft" + +//! @} + +class QDBusConnection; +namespace BlackMisc +{ + class CDBusServer; + namespace Aviation + { + class CAircraftIcaoCode; + class CAltitude; + class CCallsign; + class CTransponder; + } +} +namespace BlackCore +{ + namespace Context + { + + //! Own context proxy + //! \ingroup dbus + class BLACKCORE_EXPORT IContextOwnAircraft : public CContext + { + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTOWNAIRCRAFT_INTERFACENAME) + + public: + //! DBus interface name + static const QString &InterfaceName() + { + static QString s(BLACKCORE_CONTEXTOWNAIRCRAFT_INTERFACENAME); + return s; + } + + //! DBus object path + static const QString &ObjectPath() + { + static QString s(BLACKCORE_CONTEXTOWNAIRCRAFT_OBJECTPATH); + return s; + } + + //! \copydoc CContext::getPathAndContextId() + virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); } + + //! Factory method + static IContextOwnAircraft *create(CCoreFacade *parent, CCoreFacadeConfig::ContextMode mode, BlackMisc::CDBusServer *server, QDBusConnection &conn); + + //! Destructor + virtual ~IContextOwnAircraft() {} + + signals: + //! Aircraft cockpit update + void changedAircraftCockpit(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator); + + //! Changed SELCAL code + void changedSelcal(const BlackMisc::Aviation::CSelcal &selcal, const BlackMisc::CIdentifier &originator); + + //! Own callsign was changed + void changedCallsign(const BlackMisc::Aviation::CCallsign &callsign); + + //! Own ICAO was changed + void changedAircraftIcaoCodes(const BlackMisc::Aviation::CAircraftIcaoCode &aircraftIcaoCode, const BlackMisc::Aviation::CAirlineIcaoCode &airlineIcaoCode); + + //! own pilot (aka the swift user) changed + void changedPilot(const BlackMisc::Network::CUser &pilot); + + public slots: + //! Get own aircraft + virtual BlackMisc::Simulation::CSimulatedAircraft getOwnAircraft() const = 0; + + //! Update position + //! \note this is in \sa IContextOwnAircraft as we want to set test positions from the GUI / elsewhere + virtual bool updateOwnPosition(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::Aviation::CAltitude &altitude) = 0; + + //! Update own cockpit + virtual bool updateCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const BlackMisc::CIdentifier &originator) = 0; + + //! Tune in a com frequency + virtual bool updateActiveComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, BlackMisc::Aviation::CComSystem::ComUnit comUnit, const BlackMisc::CIdentifier &originator) = 0; + + //! Set current pilot + virtual bool updateOwnAircraftPilot(const BlackMisc::Network::CUser &pilot) = 0; + + //! Set ICAO data + virtual bool updateOwnIcaoCodes(const BlackMisc::Aviation::CAircraftIcaoCode &aircraftIcaoCode, const BlackMisc::Aviation::CAirlineIcaoCode &airlineIcaoCode) = 0; + + //! Set callsign + virtual bool updateOwnCallsign(const BlackMisc::Aviation::CCallsign &callsign) = 0; + + //! Own SELCAL code + virtual bool updateSelcal(const BlackMisc::Aviation::CSelcal &selcal, const BlackMisc::CIdentifier &originator) = 0; + + //! Output volume 0..300 + virtual void setAudioOutputVolume(int outputVolume) = 0; + + //! Set individual voice rooms (overrides voice rooms) + //! \note Empty string "" disables voice room override + //! \sa enableAutomaticVoiceRoomResolution + virtual void setAudioVoiceRoomOverrideUrls(const QString &voiceRoom1Url, const QString &voiceRoom2Url) = 0; + + //! Automatic voice room resolution for frequencies + virtual void enableAutomaticVoiceRoomResolution(bool enable) = 0; + + //! Parse command line + virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) = 0; + + protected: + //! Constructor + IContextOwnAircraft(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : CContext(mode, runtime) {} + }; + } // ns +} // ns + +#endif // guard diff --git a/src/blackcore/context/contextownaircraftempty.h b/src/blackcore/context/contextownaircraftempty.h new file mode 100644 index 000000000..a3791e6af --- /dev/null +++ b/src/blackcore/context/contextownaircraftempty.h @@ -0,0 +1,136 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKCORE_CONTEXT_CONTEXTOWNAIRCRAFT_EMPTY_H +#define BLACKCORE_CONTEXT_CONTEXTOWNAIRCRAFT_EMPTY_H + +#include "blackcoreexport.h" +#include "contextownaircraft.h" +#include "blackmisc/logmessage.h" + +namespace BlackCore +{ + namespace Context + { + //! Empty context, used during shutdown/initialization + class BLACKCORE_EXPORT CContextOwnAircraftEmpty : public IContextOwnAircraft + { + Q_OBJECT + + public: + //! Constructor + CContextOwnAircraftEmpty(CCoreFacade *runtime) : IContextOwnAircraft(CCoreFacadeConfig::NotUsed, runtime) {} + + public slots: + //! \copydoc IContextOwnAircraft::getOwnAircraft() + virtual BlackMisc::Simulation::CSimulatedAircraft getOwnAircraft() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Simulation::CSimulatedAircraft(); + } + + //! \copydoc IContextOwnAircraft::updateOwnPosition + virtual bool updateOwnPosition(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::Aviation::CAltitude &altitude) override + { + Q_UNUSED(position); + Q_UNUSED(altitude); + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + + //! \copydoc IContextOwnAircraft::updateCockpit + virtual bool updateCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const BlackMisc::CIdentifier &originator) override + { + Q_UNUSED(com1); + Q_UNUSED(com2); + Q_UNUSED(transponder); + Q_UNUSED(originator); + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + + //! \copydoc IContextOwnAircraft::updateActiveComFrequency + virtual bool updateActiveComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, BlackMisc::Aviation::CComSystem::ComUnit comUnit, const BlackMisc::CIdentifier &originator) override + { + Q_UNUSED(frequency); + Q_UNUSED(comUnit); + Q_UNUSED(originator); + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + + //! \copydoc IContextOwnAircraft::updateOwnAircraftPilot + virtual bool updateOwnAircraftPilot(const BlackMisc::Network::CUser &pilot) override + { + Q_UNUSED(pilot); + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + + //! \copydoc IContextOwnAircraft::updateSelcal + virtual bool updateSelcal(const BlackMisc::Aviation::CSelcal &selcal, const BlackMisc::CIdentifier &originator) override + { + Q_UNUSED(selcal); + Q_UNUSED(originator); + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + + //! \copydoc IContextOwnAircraft::updateOwnCallsign + virtual bool updateOwnCallsign(const BlackMisc::Aviation::CCallsign &callsign) override + { + Q_UNUSED(callsign); + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + + //! \copydoc IContextOwnAircraft::updateOwnIcaoCodes + virtual bool updateOwnIcaoCodes(const BlackMisc::Aviation::CAircraftIcaoCode &aircraftIcaoCode, const BlackMisc::Aviation::CAirlineIcaoCode &airlineIcaoCode) override + { + Q_UNUSED(aircraftIcaoCode); + Q_UNUSED(airlineIcaoCode); + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + + //! \copydoc IContextOwnAircraft::setAudioOutputVolume + virtual void setAudioOutputVolume(int outputVolume) override + { + Q_UNUSED(outputVolume); + } + + //! \copydoc IContextOwnAircraft::setAudioVoiceRoomOverrideUrls + virtual void setAudioVoiceRoomOverrideUrls(const QString &voiceRoom1Url, const QString &voiceRoom2Url) override + { + Q_UNUSED(voiceRoom1Url); + Q_UNUSED(voiceRoom2Url); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextOwnAircraft::enableAutomaticVoiceRoomResolution + virtual void enableAutomaticVoiceRoomResolution(bool enable) override + { + Q_UNUSED(enable); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextOwnAircraft::parseCommandLine + virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override + { + Q_UNUSED(commandLine); + Q_UNUSED(originator); + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + }; + } // namespace +} // namespace +#endif // guard diff --git a/src/blackcore/context/contextownaircraftimpl.cpp b/src/blackcore/context/contextownaircraftimpl.cpp new file mode 100644 index 000000000..cf5d51681 --- /dev/null +++ b/src/blackcore/context/contextownaircraftimpl.cpp @@ -0,0 +1,385 @@ +/* Copyright (C) 2014 + * swift project community / contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "blackcore/context/contextapplication.h" +#include "blackcore/context/contextaudio.h" +#include "blackcore/context/contextnetwork.h" +#include "blackcore/context/contextownaircraftimpl.h" +#include "blackmisc/audio/voiceroom.h" +#include "blackmisc/audio/voiceroomlist.h" +#include "blackmisc/aviation/aircrafticaocode.h" +#include "blackmisc/aviation/aircraftsituation.h" +#include "blackmisc/aviation/altitude.h" +#include "blackmisc/aviation/callsign.h" +#include "blackmisc/aviation/transponder.h" +#include "blackmisc/compare.h" +#include "blackmisc/dbusserver.h" +#include "blackmisc/geo/latitude.h" +#include "blackmisc/geo/longitude.h" +#include "blackmisc/logcategory.h" +#include "blackmisc/logmessage.h" +#include "blackmisc/network/server.h" +#include "blackmisc/pq/physicalquantity.h" +#include "blackmisc/pq/units.h" +#include "blackmisc/sequence.h" +#include "blackmisc/simplecommandparser.h" +#include "blackmisc/statusmessage.h" + +#include +#include +#include + +using namespace BlackMisc; +using namespace BlackMisc::PhysicalQuantities; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::Network; +using namespace BlackMisc::Geo; +using namespace BlackMisc::Audio; +using namespace BlackMisc::Simulation; + +namespace BlackCore +{ + namespace Context + { + CContextOwnAircraft::CContextOwnAircraft(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : + IContextOwnAircraft(mode, runtime), + CIdentifiable(this) + { + Q_ASSERT(this->getRuntime()); + this->setObjectName("CContextOwnAircraft"); + + // Init own aircraft + this->initOwnAircraft(); + } + + CContextOwnAircraft *CContextOwnAircraft::registerWithDBus(CDBusServer *server) + { + if (!server || this->m_mode != CCoreFacadeConfig::LocalInDbusServer) return this; + server->addObject(IContextOwnAircraft::ObjectPath(), this); + return this; + } + + CContextOwnAircraft::~CContextOwnAircraft() { } + + CSimulatedAircraft CContextOwnAircraft::getOwnAircraft() const + { + if (this->m_debugEnabled) {CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + QReadLocker l(&m_lockAircraft); + return this->m_ownAircraft; + } + + CCoordinateGeodetic CContextOwnAircraft::getOwnAircraftPosition() const + { + QReadLocker l(&m_lockAircraft); + return this->m_ownAircraft.getPosition(); + } + + CAircraftParts CContextOwnAircraft::getOwnAircraftParts() const + { + QReadLocker l(&m_lockAircraft); + return this->m_ownAircraft.getParts(); + } + + CAircraftModel CContextOwnAircraft::getOwnAircraftModel() const + { + QReadLocker l(&m_lockAircraft); + return this->m_ownAircraft.getModel(); + } + + CLength CContextOwnAircraft::getDistanceToOwnAircraft(const ICoordinateGeodetic &position) const + { + return getOwnAircraft().calculateGreatCircleDistance(position); + } + + void CContextOwnAircraft::initOwnAircraft() + { + Q_ASSERT(this->getRuntime()); + { + QWriteLocker l(&m_lockAircraft); + this->m_ownAircraft.initComSystems(); + this->m_ownAircraft.initTransponder(); + CAircraftSituation situation( + CCoordinateGeodetic( + CLatitude::fromWgs84("N 049° 18' 17"), + CLongitude::fromWgs84("E 008° 27' 05"), + CLength(0, CLengthUnit::m())), + CAltitude(312, CAltitude::MeanSeaLevel, CLengthUnit::ft()) + ); + this->m_ownAircraft.setSituation(situation); + this->m_ownAircraft.setPilot(this->m_currentNetworkServer.getThreadLocal().getUser()); + + // from simulator, if available + this->m_ownAircraft.setCallsign(CCallsign("SWIFT")); // would come from settings + + //! \todo Own aircraft ICAO default data, this would need to come from somewhere (mappings) -> Own callsign, plane ICAO status, model used + this->m_ownAircraft.setIcaoCodes( + CAircraftIcaoCode("C172", "L1P"), + CAirlineIcaoCode() + ); + } + + // voice rooms, if network is already available + if (this->getIContextNetwork()) + { + this->resolveVoiceRooms(); + } + } + + void CContextOwnAircraft::resolveVoiceRooms() + { + Q_ASSERT(this->getIContextAudio()); + Q_ASSERT(this->getIContextNetwork()); + Q_ASSERT(this->getIContextApplication()); + if (!this->getIContextNetwork() || !this->getIContextAudio() || !this->getIContextApplication()) { return; } // no chance to resolve rooms + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + + if (this->m_voiceRoom1UrlOverride.isEmpty() && this->m_voiceRoom2UrlOverride.isEmpty() && !this->m_automaticVoiceRoomResolution) { return; } + if (!this->m_automaticVoiceRoomResolution) { return; } // not responsible + + // requires correct frequencies set + // but local network uses exactly this object here, so if frequencies are set here, + // they are for network context as well + CVoiceRoomList rooms = this->getIContextNetwork()->getSelectedVoiceRooms(); + + if (!this->m_voiceRoom1UrlOverride.isEmpty()) rooms[0] = CVoiceRoom(this->m_voiceRoom1UrlOverride); + if (!this->m_voiceRoom2UrlOverride.isEmpty()) rooms[1] = CVoiceRoom(this->m_voiceRoom2UrlOverride); + + // set the rooms + emit this->getIContextApplication()->fakedSetComVoiceRoom(rooms); + } + + bool CContextOwnAircraft::updateOwnModel(const CAircraftModel &model) + { + QWriteLocker l(&m_lockAircraft); + bool changed = (this->m_ownAircraft.getModel() != model); + if (!changed) { return false; } + this->m_ownAircraft.setModel(model); + return true; + } + + bool CContextOwnAircraft::updateOwnSituation(const CAircraftSituation &situation) + { + QWriteLocker l(&m_lockAircraft); + // there is intentionally no equal check + this->m_ownAircraft.setSituation(situation); + return true; + } + + bool CContextOwnAircraft::updateOwnParts(const CAircraftParts &parts) + { + QWriteLocker l(&m_lockAircraft); + bool changed = (this->m_ownAircraft.getParts() != parts); + if (!changed) { return false; } + this->m_ownAircraft.setParts(parts); + return true; + } + + bool CContextOwnAircraft::updateOwnPosition(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::Aviation::CAltitude &altitude) + { + if (this->m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << position << altitude; } + QWriteLocker l(&m_lockAircraft); + bool changed = (this->m_ownAircraft.getPosition() != position); + if (changed) { this->m_ownAircraft.setPosition(position); } + + if (this->m_ownAircraft.getAltitude() != altitude) + { + changed = true; + this->m_ownAircraft.setAltitude(altitude); + } + return changed; + } + + bool CContextOwnAircraft::updateCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const CIdentifier &originator) + { + if (this->m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << com1 << com2 << transponder; } + bool changed; + { + QWriteLocker l(&m_lockAircraft); + changed = this->m_ownAircraft.hasChangedCockpitData(com1, com2, transponder); + if (changed) { this->m_ownAircraft.setCockpit(com1, com2, transponder); } + } + if (changed) + { + emit this->changedAircraftCockpit(this->m_ownAircraft, originator); + this->resolveVoiceRooms(); + } + return changed; + } + + bool CContextOwnAircraft::updateActiveComFrequency(const CFrequency &frequency, BlackMisc::Aviation::CComSystem::ComUnit unit, const CIdentifier &originator) + { + if (unit != CComSystem::Com1 && unit != CComSystem::Com2) { return false; } + if (!CComSystem::isValidComFrequency(frequency)) { return false; } + CComSystem com1, com2; + CTransponder xpdr; + { + QReadLocker l(&m_lockAircraft); + com1 = this->m_ownAircraft.getCom1System(); + com2 = this->m_ownAircraft.getCom2System(); + xpdr = this->m_ownAircraft.getTransponder(); + } + if (unit == CComSystem::Com1) + { + com1.setFrequencyActive(frequency); + } + else + { + com2.setFrequencyActive(frequency); + } + return updateCockpit(com1, com2, xpdr, originator); + } + + bool CContextOwnAircraft::updateOwnAircraftPilot(const CUser &pilot) + { + { + QWriteLocker l(&m_lockAircraft); + if (this->m_ownAircraft.getPilot() == pilot) { return false; } + this->m_ownAircraft.setPilot(pilot); + } + emit changedPilot(pilot); + return true; + } + + bool CContextOwnAircraft::updateOwnCallsign(const CCallsign &callsign) + { + { + QWriteLocker l(&m_lockAircraft); + if (this->m_ownAircraft.getCallsign() == callsign) { return false; } + this->m_ownAircraft.setCallsign(callsign); + } + emit changedCallsign(callsign); + return true; + } + + bool CContextOwnAircraft::updateOwnIcaoCodes(const BlackMisc::Aviation::CAircraftIcaoCode &aircraftIcaoCode, const BlackMisc::Aviation::CAirlineIcaoCode &airlineIcaoCode) + { + { + QWriteLocker l(&m_lockAircraft); + return this->m_ownAircraft.setIcaoCodes(aircraftIcaoCode, airlineIcaoCode); + } + emit changedAircraftIcaoCodes(aircraftIcaoCode, airlineIcaoCode); + } + + bool CContextOwnAircraft::updateSelcal(const CSelcal &selcal, const CIdentifier &originator) + { + { + QWriteLocker l(&m_lockAircraft); + if (this->m_ownAircraft.getSelcal() == selcal) { return false; } + this->m_ownAircraft.setSelcal(selcal); + } + emit this->changedSelcal(selcal, originator); + return true; + } + + void CContextOwnAircraft::setAudioOutputVolume(int outputVolume) + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << outputVolume; } + if (this->getIContextAudio()) this->getIContextAudio()->setVoiceOutputVolume(outputVolume); + } + + void CContextOwnAircraft::ps_changedAtcStationOnlineConnectionStatus(const CAtcStation &atcStation, bool connected) + { + // any of our active frequencies? + Q_UNUSED(connected); + CSimulatedAircraft myAircraft(getOwnAircraft()); + if (atcStation.getFrequency() != myAircraft.getCom1System().getFrequencyActive() && atcStation.getFrequency() != myAircraft.getCom2System().getFrequencyActive()) { return; } + this->resolveVoiceRooms(); + } + + void CContextOwnAircraft::ps_changedSimulatorModel(const CSimulatedAircraft &ownAircraft) + { + CAircraftModel model(ownAircraft.getModel()); + QWriteLocker l(&m_lockAircraft); + this->m_ownAircraft.setModel(model); + } + + void CContextOwnAircraft::setAudioVoiceRoomOverrideUrls(const QString &voiceRoom1Url, const QString &voiceRoom2Url) + { + if (this->m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << voiceRoom1Url << voiceRoom2Url; } + this->m_voiceRoom1UrlOverride = voiceRoom1Url.trimmed(); + this->m_voiceRoom2UrlOverride = voiceRoom2Url.trimmed(); + this->resolveVoiceRooms(); + } + + void CContextOwnAircraft::enableAutomaticVoiceRoomResolution(bool enable) + { + if (this->m_debugEnabled) {CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << enable; } + this->m_automaticVoiceRoomResolution = enable; + } + + bool CContextOwnAircraft::parseCommandLine(const QString &commandLine, const CIdentifier &originator) + { + Q_UNUSED(originator); + if (commandLine.isEmpty()) { return false; } + CSimpleCommandParser parser( + { + ".x", ".xpdr", // transponder + ".com1", ".com2", // com1, com2 frequencies + ".c1", ".c2", // com1, com2 frequencies + ".selcal" + }); + parser.parse(commandLine); + if (!parser.isKnownCommand()) { return false; } + + CSimulatedAircraft myAircraft(this->getOwnAircraft()); + if (parser.matchesCommand(".x", ".xpdr") && parser.countParts() > 1) + { + CTransponder transponder = myAircraft.getTransponder(); + int xprCode = parser.toInt(1); + if (CTransponder::isValidTransponderCode(xprCode)) + { + transponder.setTransponderCode(xprCode); + // todo RW: replace originator + this->updateCockpit(myAircraft.getCom1System(), myAircraft.getCom2System(), transponder, CIdentifier("commandline")); + return true; + } + else + { + CTransponder::TransponderMode mode = CTransponder::modeFromString(parser.part(1)); + transponder.setTransponderMode(mode); + // todo RW: replace originator + this->updateCockpit(myAircraft.getCom1System(), myAircraft.getCom2System(), transponder, CIdentifier("commandline")); + return true; + } + } + else if (parser.commandStartsWith("com") || parser.commandStartsWith("c")) + { + CFrequency frequency(parser.toDouble(1), CFrequencyUnit::MHz()); + if (CComSystem::isValidComFrequency(frequency)) + { + CComSystem com1 = myAircraft.getCom1System(); + CComSystem com2 = myAircraft.getCom2System(); + if (parser.commandEndsWith("1")) + { + com1.setFrequencyActive(frequency); + } + else if (parser.commandEndsWith("2")) + { + com2.setFrequencyActive(frequency); + } + else + { + return false; + } + this->updateCockpit(com1, com2, myAircraft.getTransponder(), identifier()); + return true; + } + } + else if (parser.matchesCommand(".selcal")) + { + if (CSelcal::isValidCode(parser.part(1))) + { + this->updateSelcal(parser.part(1), this->identifier()); + return true; + } + } + return false; + } + } // namespace +} // namespace diff --git a/src/blackcore/context/contextownaircraftimpl.h b/src/blackcore/context/contextownaircraftimpl.h new file mode 100644 index 000000000..973d85b93 --- /dev/null +++ b/src/blackcore/context/contextownaircraftimpl.h @@ -0,0 +1,183 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKCORE_CONTEXT_CONTEXTOWNAIRCRAFT_IMPL_H +#define BLACKCORE_CONTEXT_CONTEXTOWNAIRCRAFT_IMPL_H + +#include "blackcore/blackcoreexport.h" +#include "blackcore/context/contextownaircraft.h" +#include "blackcore/corefacadeconfig.h" +#include "blackcore/settings/network.h" +#include "blackmisc/aviation/aircraftparts.h" +#include "blackmisc/aviation/airlineicaocode.h" +#include "blackmisc/aviation/atcstation.h" +#include "blackmisc/aviation/comsystem.h" +#include "blackmisc/aviation/selcal.h" +#include "blackmisc/geo/coordinategeodetic.h" +#include "blackmisc/identifiable.h" +#include "blackmisc/identifier.h" +#include "blackmisc/network/user.h" +#include "blackmisc/pq/frequency.h" +#include "blackmisc/pq/length.h" +#include "blackmisc/settingscache.h" +#include "blackmisc/simulation/aircraftmodel.h" +#include "blackmisc/simulation/ownaircraftprovider.h" +#include "blackmisc/simulation/simulatedaircraft.h" + +#include +#include +#include + +namespace BlackMisc +{ + class CDBusServer; + namespace Aviation + { + class CAircraftIcaoCode; + class CAircraftSituation; + class CAltitude; + class CCallsign; + class CTransponder; + } +} +namespace BlackCore +{ + class CCoreFacade; + namespace Context + { + //! Own aircraft context implementation. + //! Central instance of data for \sa IOwnAircraftProvider . + class BLACKCORE_EXPORT CContextOwnAircraft : + public IContextOwnAircraft, + public BlackMisc::Simulation::IOwnAircraftProvider, + public BlackMisc::CIdentifiable + { + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTOWNAIRCRAFT_INTERFACENAME) + Q_INTERFACES(BlackMisc::Simulation::IOwnAircraftProvider) + friend class BlackCore::CCoreFacade; + friend class IContextOwnAircraft; + + public: + //! Destructor + virtual ~CContextOwnAircraft(); + + // IOwnAircraftProvider overrides + //! \ingroup ownaircraftprovider + //! @{ + virtual BlackMisc::Geo::CCoordinateGeodetic getOwnAircraftPosition() const override; + + //! \copydoc BlackMisc::Simulation::IOwnAircraftProvider::getOwnAircraftParts + //! \ingroup ownaircraftprovider + virtual BlackMisc::Aviation::CAircraftParts getOwnAircraftParts() const override; + + //! \copydoc BlackMisc::Simulation::IOwnAircraftProvider::getOwnAircraftModel + //! \ingroup ownaircraftprovider + virtual BlackMisc::Simulation::CAircraftModel getOwnAircraftModel() const override; + + //! \copydoc BlackMisc::Simulation::IOwnAircraftProvider::getDistanceToOwnAircraft + //! \ingroup ownaircraftprovider + virtual BlackMisc::PhysicalQuantities::CLength getDistanceToOwnAircraft(const BlackMisc::Geo::ICoordinateGeodetic &position) const override; + + //! \copydoc BlackMisc::Simulation::IOwnAircraftProvider::updateOwnModel + //! \ingroup ownaircraftprovider + virtual bool updateOwnModel(const BlackMisc::Simulation::CAircraftModel &model) override; + + //! \copydoc BlackMisc::Simulation::IOwnAircraftProvider::updateOwnSituation + //! \ingroup ownaircraftprovider + virtual bool updateOwnSituation(const BlackMisc::Aviation::CAircraftSituation &situation) override; + + //! \copydoc BlackMisc::Simulation::IOwnAircraftProvider::updateOwnParts + //! \ingroup ownaircraftprovider + virtual bool updateOwnParts(const BlackMisc::Aviation::CAircraftParts &parts) override; + + public slots: + //! \copydoc IContextOwnAircraft::getOwnAircraft() + //! \ingroup ownaircraftprovider + virtual BlackMisc::Simulation::CSimulatedAircraft getOwnAircraft() const override; + + //! \copydoc IContextOwnAircraft::updateOwnCallsign + //! \ingroup ownaircraftprovider + virtual bool updateOwnCallsign(const BlackMisc::Aviation::CCallsign &callsign) override; + + //! \copydoc IContextOwnAircraft::updateOwnIcaoCodes + //! \ingroup ownaircraftprovider + virtual bool updateOwnIcaoCodes(const BlackMisc::Aviation::CAircraftIcaoCode &aircraftIcaoCode, const BlackMisc::Aviation::CAirlineIcaoCode &airlineIcaoCode) override; + + //! \copydoc IContextOwnAircraft::updateOwnPosition + virtual bool updateOwnPosition(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::Aviation::CAltitude &altitude) override; + + //! \copydoc IContextOwnAircraft::updateCockpit + virtual bool updateCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const BlackMisc::CIdentifier &originator) override; + + //! \copydoc IContextOwnAircraft::updateSelcal + virtual bool updateSelcal(const BlackMisc::Aviation::CSelcal &selcal, const BlackMisc::CIdentifier &originator) override; + + //! \copydoc IContextOwnAircraft::updateActiveComFrequency + virtual bool updateActiveComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, BlackMisc::Aviation::CComSystem::ComUnit comUnit, const BlackMisc::CIdentifier &originator) override; + + //! \copydoc IContextOwnAircraft::updateOwnAircraftPilot + virtual bool updateOwnAircraftPilot(const BlackMisc::Network::CUser &pilot) override; + + //! \copydoc IContextOwnAircraft::setAudioOutputVolume + virtual void setAudioOutputVolume(int outputVolume) override; + + //! \copydoc IContextOwnAircraft::setAudioVoiceRoomOverrideUrls + virtual void setAudioVoiceRoomOverrideUrls(const QString &voiceRoom1Url, const QString &voiceRoom2Url) override; + + //! \copydoc IContextOwnAircraft::enableAutomaticVoiceRoomResolution + virtual void enableAutomaticVoiceRoomResolution(bool enable) override; + + //! \addtogroup commandline + //! @{ + //!
+            //! .x    .xpdr  code       set transponder code    CContextOwnAircraft
+            //! .com1 .com2  frequency  set COM1/2 frequency    CContextOwnAircraft
+            //! .selcal      code       set SELCAL code         CContextOwnAircraft
+            //! 
+ //! @} + //! \copydoc IContextOwnAircraft::parseCommandLine + virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override; + + protected: + //! Constructor, with link to runtime + CContextOwnAircraft(CCoreFacadeConfig::ContextMode, CCoreFacade *runtime); + + //! Register myself in DBus + CContextOwnAircraft *registerWithDBus(BlackMisc::CDBusServer *server); + + private slots: + //! Station has been changed, needed to tune in/out voice room + //! \note Connected in runtime + void ps_changedAtcStationOnlineConnectionStatus(const BlackMisc::Aviation::CAtcStation &atcStation, bool connected); + + //! Simulator model has been changed + //! \note Connected in runtime + void ps_changedSimulatorModel(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft); + + private: + BlackMisc::Simulation::CSimulatedAircraft m_ownAircraft; //!< my aircraft + bool m_automaticVoiceRoomResolution = true; //!< automatic voice room resolution, or disable for override + QString m_voiceRoom1UrlOverride; //!< overridden voice room url + QString m_voiceRoom2UrlOverride; //!< overridden voice room url + mutable QReadWriteLock m_lockAircraft; //!< lock aircraft + + BlackMisc::CSetting m_currentNetworkServer { this }; + + //! Init my very own aircraft with some defaults, before overridden by simulator + void initOwnAircraft(); + + //! Resolve voice rooms + void resolveVoiceRooms(); + }; + } // ns +} // ns +#endif // guard diff --git a/src/blackcore/context/contextownaircraftproxy.cpp b/src/blackcore/context/contextownaircraftproxy.cpp new file mode 100644 index 000000000..3daf01056 --- /dev/null +++ b/src/blackcore/context/contextownaircraftproxy.cpp @@ -0,0 +1,103 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "blackcore/context/contextownaircraftproxy.h" +#include "blackmisc/dbus.h" +#include "blackmisc/genericdbusinterface.h" + +#include +#include +#include +#include + +using namespace BlackMisc; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::Simulation; + +namespace BlackCore +{ + namespace Context + { + CContextOwnAircraftProxy::CContextOwnAircraftProxy(const QString &serviceName, QDBusConnection &connection, CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextOwnAircraft(mode, runtime), m_dBusInterface(nullptr) + { + this->m_dBusInterface = new BlackMisc::CGenericDBusInterface( + serviceName , IContextOwnAircraft::ObjectPath(), IContextOwnAircraft::InterfaceName(), + connection, this); + this->relaySignals(serviceName, connection); + } + + void CContextOwnAircraftProxy::relaySignals(const QString &serviceName, QDBusConnection &connection) + { + bool s = connection.connect(serviceName, IContextOwnAircraft::ObjectPath(), IContextOwnAircraft::InterfaceName(), + "changedAircraftCockpit", this, SIGNAL(changedAircraftCockpit(BlackMisc::Simulation::CSimulatedAircraft, BlackMisc::CIdentifier))); + Q_ASSERT(s); + Q_UNUSED(s); + } + + BlackMisc::Simulation::CSimulatedAircraft CContextOwnAircraftProxy::getOwnAircraft() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getOwnAircraft")); + } + + bool CContextOwnAircraftProxy::updateCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const CIdentifier &originator) + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("updateCockpit"), com1, com2, transponder, originator); + } + + bool CContextOwnAircraftProxy::updateActiveComFrequency(const PhysicalQuantities::CFrequency &frequency, BlackMisc::Aviation::CComSystem::ComUnit comUnit, const CIdentifier &originator) + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("updateActiveComFrequency"), frequency, comUnit, originator); + } + + bool CContextOwnAircraftProxy::updateOwnAircraftPilot(const BlackMisc::Network::CUser &pilot) + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("updateOwnAircraftPilot"), pilot); + } + + bool CContextOwnAircraftProxy::updateSelcal(const CSelcal &selcal, const CIdentifier &originator) + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("updateSelcal"), selcal, originator); + } + + bool CContextOwnAircraftProxy::updateOwnPosition(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::Aviation::CAltitude &altitude) + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("updateOwnPosition"), position, altitude); + } + + bool CContextOwnAircraftProxy::updateOwnCallsign(const CCallsign &callsign) + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("updateOwnCallsign"), callsign); + } + + bool CContextOwnAircraftProxy::updateOwnIcaoCodes(const CAircraftIcaoCode &aircraftIcaoCode, const CAirlineIcaoCode &airlineIcaoCode) + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("updateOwnIcaoCodes"), aircraftIcaoCode, airlineIcaoCode); + } + + void CContextOwnAircraftProxy::setAudioOutputVolume(int outputVolume) + { + this->m_dBusInterface->callDBus(QLatin1Literal("setAudioOutputVolume"), outputVolume); + } + + void CContextOwnAircraftProxy::setAudioVoiceRoomOverrideUrls(const QString &voiceRoom1Url, const QString &voiceRoom2Url) + { + this->m_dBusInterface->callDBus(QLatin1Literal("setAudioVoiceRoomOverrideUrls"), voiceRoom1Url, voiceRoom2Url); + } + + void CContextOwnAircraftProxy::enableAutomaticVoiceRoomResolution(bool enable) + { + this->m_dBusInterface->callDBus(QLatin1Literal("enableAutomaticVoiceRoomResolution"), enable); + } + + bool CContextOwnAircraftProxy::parseCommandLine(const QString &commandLine, const CIdentifier &originator) + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("parseCommandLine"), commandLine, originator); + } + } // namespace +} // namespace diff --git a/src/blackcore/context/contextownaircraftproxy.h b/src/blackcore/context/contextownaircraftproxy.h new file mode 100644 index 000000000..a6de3dfe2 --- /dev/null +++ b/src/blackcore/context/contextownaircraftproxy.h @@ -0,0 +1,111 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKCORE_CONTEXT_OWNAIRCRAFT_PROXY_H +#define BLACKCORE_CONTEXT_OWNAIRCRAFT_PROXY_H + +#include +#include + +#include "blackcore/blackcoreexport.h" +#include "blackcore/context/contextownaircraft.h" +#include "blackcore/corefacadeconfig.h" +#include "blackmisc/aviation/airlineicaocode.h" +#include "blackmisc/aviation/comsystem.h" +#include "blackmisc/aviation/selcal.h" +#include "blackmisc/geo/coordinategeodetic.h" +#include "blackmisc/identifier.h" +#include "blackmisc/network/user.h" +#include "blackmisc/pq/frequency.h" +#include "blackmisc/simulation/simulatedaircraft.h" + +class QDBusConnection; + +namespace BlackMisc +{ + class CGenericDBusInterface; + namespace Aviation + { + class CAircraftIcaoCode; + class CAltitude; + class CCallsign; + class CTransponder; + } +} +namespace BlackCore +{ + class CCoreFacade; + namespace Context + { + //! Own aircraft context proxy + //! \ingroup dbus + class BLACKCORE_EXPORT CContextOwnAircraftProxy : public IContextOwnAircraft + { + Q_OBJECT + friend class IContextOwnAircraft; + + public: + //! Destructor + virtual ~CContextOwnAircraftProxy() {} + + public slots: + //! \copydoc IContextOwnAircraft::getOwnAircraft() + virtual BlackMisc::Simulation::CSimulatedAircraft getOwnAircraft() const override; + + //! \copydoc IContextOwnAircraft::updateOwnPosition + virtual bool updateOwnPosition(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::Aviation::CAltitude &altitude) override; + + //! \copydoc IContextOwnAircraft::updateCockpit + virtual bool updateCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const BlackMisc::CIdentifier &originator) override; + + //! \copydoc IContextOwnAircraft::updateActiveComFrequency + virtual bool updateActiveComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, BlackMisc::Aviation::CComSystem::ComUnit comUnit, const BlackMisc::CIdentifier &originator) override; + + //! \copydoc IContextOwnAircraft::updateOwnAircraftPilot + virtual bool updateOwnAircraftPilot(const BlackMisc::Network::CUser &pilot) override; + + //! \copydoc IContextOwnAircraft::updateSelcal + virtual bool updateSelcal(const BlackMisc::Aviation::CSelcal &selcal, const BlackMisc::CIdentifier &originator) override; + + //! \copydoc IContextOwnAircraft::updateOwnCallsign + virtual bool updateOwnCallsign(const BlackMisc::Aviation::CCallsign &callsign) override; + + //! \copydoc IContextOwnAircraft::updateOwnIcaoCodes + virtual bool updateOwnIcaoCodes(const BlackMisc::Aviation::CAircraftIcaoCode &aircraftIcaoCode, const BlackMisc::Aviation::CAirlineIcaoCode &airlineIcaoCode) override; + + //! \copydoc IContextOwnAircraft::setAudioOutputVolume + virtual void setAudioOutputVolume(int outputVolume) override; + + //! \copydoc IContextOwnAircraft::setAudioVoiceRoomOverrideUrls + virtual void setAudioVoiceRoomOverrideUrls(const QString &voiceRoom1Url, const QString &voiceRoom2Url) override; + + //! \copydoc IContextOwnAircraft::enableAutomaticVoiceRoomResolution + virtual void enableAutomaticVoiceRoomResolution(bool enable) override; + + //! \copydoc IContextOwnAircraft::parseCommandLine + virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override; + + protected: + //! \brief Constructor + CContextOwnAircraftProxy(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextOwnAircraft(mode, runtime), m_dBusInterface(nullptr) {} + + //! \brief DBus version constructor + CContextOwnAircraftProxy(const QString &serviceName, QDBusConnection &connection, CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime); + + private: + BlackMisc::CGenericDBusInterface *m_dBusInterface; //!< DBus interface */ + + //! \brief Relay connection signals to local signals. + void relaySignals(const QString &serviceName, QDBusConnection &connection); + }; + } // ns +} // ns +#endif // guard diff --git a/src/blackcore/context/contextsimulator.cpp b/src/blackcore/context/contextsimulator.cpp new file mode 100644 index 000000000..6f0c2c63a --- /dev/null +++ b/src/blackcore/context/contextsimulator.cpp @@ -0,0 +1,63 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "blackcore/context/contextsimulator.h" +#include "blackcore/context/contextsimulatorempty.h" +#include "blackcore/context/contextsimulatorimpl.h" +#include "blackcore/context/contextsimulatorproxy.h" +#include "blackmisc/dbusserver.h" +#include "blackmisc/pq/units.h" + +#include + +using namespace BlackMisc::PhysicalQuantities; + +namespace BlackCore +{ + namespace Context + { + const QString &IContextSimulator::InterfaceName() + { + static const QString s(BLACKCORE_CONTEXTSIMULATOR_INTERFACENAME); + return s; + } + + const QString &IContextSimulator::ObjectPath() + { + static const QString s(BLACKCORE_CONTEXTSIMULATOR_OBJECTPATH); + return s; + } + + const BlackMisc::PhysicalQuantities::CTime &IContextSimulator::HighlightTime() + { + static const CTime t(10.0, CTimeUnit::s()); + return t; + } + + IContextSimulator *IContextSimulator::create(CCoreFacade *parent, CCoreFacadeConfig::ContextMode mode, BlackMisc::CDBusServer *server, QDBusConnection &conn) + { + switch (mode) + { + case CCoreFacadeConfig::Local: + case CCoreFacadeConfig::LocalInDbusServer: + return (new CContextSimulator(mode, parent))->registerWithDBus(server); + case CCoreFacadeConfig::Remote: + return new CContextSimulatorProxy(BlackMisc::CDBusServer::coreServiceName(), conn, mode, parent); + case CCoreFacadeConfig::NotUsed: + default: + return new CContextSimulatorEmpty(parent); + } + } + + ISimulator::SimulatorStatus IContextSimulator::getSimulatorStatusEnum() const + { + return static_cast(this->getSimulatorStatus()); + } + } // namespace +} // namespace diff --git a/src/blackcore/context/contextsimulator.h b/src/blackcore/context/contextsimulator.h new file mode 100644 index 000000000..fe1518a87 --- /dev/null +++ b/src/blackcore/context/contextsimulator.h @@ -0,0 +1,205 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKCORE_CONTEXTSIMULATOR_H +#define BLACKCORE_CONTEXTSIMULATOR_H + +//! \addtogroup dbus +//! @{ + +//! DBus interface for context +#define BLACKCORE_CONTEXTSIMULATOR_INTERFACENAME "org.swift_project.blackcore.contextsimulator" + +//! DBus object path for context +#define BLACKCORE_CONTEXTSIMULATOR_OBJECTPATH "/simulator" + +//! @} + +#include "blackconfig/buildconfig.h" +#include "blackcore/blackcoreexport.h" +#include "blackcore/context/context.h" +#include "blackcore/corefacade.h" +#include "blackcore/corefacadeconfig.h" +#include "blackcore/simulator.h" +#include "blackmisc/aviation/airportlist.h" +#include "blackmisc/identifier.h" +#include "blackmisc/pixmap.h" +#include "blackmisc/pq/length.h" +#include "blackmisc/pq/time.h" +#include "blackmisc/simulation/aircraftmodellist.h" +#include "blackmisc/simulation/simulatorplugininfo.h" +#include "blackmisc/simulation/simulatorplugininfolist.h" +#include "blackmisc/simulation/simulatorsetup.h" +#include "blackmisc/weather/weathergrid.h" + +#include +#include + +class QDBusConnection; + +namespace BlackMisc +{ + class CDBusServer; + namespace Simulation { class CSimulatedAircraft; } +} +namespace BlackCore +{ + namespace Context + { + //! Network context + class BLACKCORE_EXPORT IContextSimulator : public CContext + { + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTSIMULATOR_INTERFACENAME) + + public: + //! Service name + static const QString &InterfaceName(); + + //! Service path + static const QString &ObjectPath(); + + //! Highlight time + static const BlackMisc::PhysicalQuantities::CTime &HighlightTime(); + + //! \copydoc CContext::getPathAndContextId() + virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); } + + //! Factory method + static IContextSimulator *create(CCoreFacade *parent, CCoreFacadeConfig::ContextMode mode, BlackMisc::CDBusServer *server, QDBusConnection &conn); + + //! Destructor + virtual ~IContextSimulator() {} + + signals: + //! Simulator combined status + //! \sa ISimulator::SimulatorStatus + void simulatorStatusChanged(int status); + + //! Simulator plugin loaded / unloaded (default info) + void simulatorPluginChanged(BlackMisc::Simulation::CSimulatorPluginInfo info); + + //! Render restrictions have been changed + void renderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance, const BlackMisc::PhysicalQuantities::CLength &maxRenderedBoundary); + + //! Installed aircraft models ready or changed + void installedAircraftModelsChanged(); + + //! A single model has been matched for given aircraft + void modelMatchingCompleted(const BlackMisc::Simulation::CSimulatedAircraft &aircraft); + + //! Emitted when own aircraft model changes + void ownAircraftModelChanged(const BlackMisc::Simulation::CSimulatedAircraft &aircraft); + + //! An airspace snapshot was handled + void airspaceSnapshotHandled(); + + //! A weather grid, requested with requestWeatherGrid(), is received + void weatherGridReceived(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier); + + public slots: + //! Simulator info, currently loaded plugin + virtual BlackMisc::Simulation::CSimulatorPluginInfo getSimulatorPluginInfo() const = 0; + + //! Return list of available simulator plugins + virtual BlackMisc::Simulation::CSimulatorPluginInfoList getAvailableSimulatorPlugins() const = 0; + + //! Load and start specific simulator plugin + virtual bool startSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) = 0; + + //! Stop listener or unload the given plugin (if currently loaded) + virtual void stopSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) = 0; + + //! Simulator combined status + virtual int getSimulatorStatus() const = 0; + + //! Get simulator status as enum + //! \todo To be removed with Qt 5.5 when getSimualtorStatus directly provides the enum + ISimulator::SimulatorStatus getSimulatorStatusEnum() const; + + //! Simulator setup + virtual BlackMisc::Simulation::CSimulatorSetup getSimulatorSetup() const = 0; + + //! Airports in range + virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const = 0; + + //! Reload models from disk + virtual void reloadInstalledModels() = 0; + + //! Installed models in simulator eco system + virtual BlackMisc::Simulation::CAircraftModelList getInstalledModels() const = 0; + + //! Number of installed models in simulator eco system + virtual int getInstalledModelsCount() const = 0; + + //! Model for model string + virtual BlackMisc::Simulation::CAircraftModelList getInstalledModelsStartingWith(const QString modelString) const = 0; + + //! Set time synchronization between simulator and user's computer time + //! \remarks not all drivers implement this, e.g. if it is an intrinsic simulator feature + virtual bool setTimeSynchronization(bool enable, const BlackMisc::PhysicalQuantities::CTime &offset) = 0; + + //! Is time synchronization on? + virtual bool isTimeSynchronized() const = 0; + + //! Max. number of remote aircraft rendered + virtual int getMaxRenderedAircraft() const = 0; + + //! Max. rendered distance + virtual BlackMisc::PhysicalQuantities::CLength getMaxRenderedDistance() const = 0; + + //! Technical range until aircraft are visible + virtual BlackMisc::PhysicalQuantities::CLength getRenderedDistanceBoundary() const = 0; + + //! Text describing the rendering restrictions + virtual QString getRenderRestrictionText() const = 0; + + //! Max. number of remote aircraft rendered and provide optional selection which aircraft those are + virtual void setMaxRenderedAircraft(int number) = 0; + + //! Max. distance until we render an aircraft + virtual void setMaxRenderedDistance(const BlackMisc::PhysicalQuantities::CLength &distance) = 0; + + //! Delete all restrictions (if any) -> unlimited number of aircraft + virtual void deleteAllRenderingRestrictions() = 0; + + //! Is number of aircraft restricted ormax distance set? + virtual bool isRenderingRestricted() const = 0; + + //! Rendering enabled at all + virtual bool isRenderingEnabled() const = 0; + + //! Time synchronization offset + virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const = 0; + + //! Simulator avialable (driver available)? + bool isSimulatorAvailable() const { return BlackConfig::CBuildConfig::isCompiledWithFlightSimulatorSupport() && !getSimulatorPluginInfo().isUnspecified(); } + + //! Icon representing the model + virtual BlackMisc::CPixmap iconForModel(const QString &modelString) const = 0; + + //! Enable debugging + virtual void enableDebugMessages(bool driver, bool interpolator) = 0; + + //! Highlight aircraft in simulator + virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) = 0; + + //! Request weather grid. Argument identifier is past in the signal to identify the requestor + virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier) = 0; + + protected: + //! Constructor + IContextSimulator(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : CContext(mode, runtime) {} + }; + } // namespace +} // namespace + +#endif // guard diff --git a/src/blackcore/context/contextsimulatorempty.h b/src/blackcore/context/contextsimulatorempty.h new file mode 100644 index 000000000..d7be4e0a4 --- /dev/null +++ b/src/blackcore/context/contextsimulatorempty.h @@ -0,0 +1,232 @@ +/* Copyright (C) 2015 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKCORE_CONTEXT_CONTEXTSIMULATOR_EMPTY_H +#define BLACKCORE_CONTEXT_CONTEXTSIMULATOR_EMPTY_H + +#include "blackcoreexport.h" +#include "contextsimulator.h" +#include "blackmisc/logmessage.h" + +namespace BlackCore +{ + namespace Context + { + //! Empty context, used during shutdown/initialization + class BLACKCORE_EXPORT CContextSimulatorEmpty : public IContextSimulator + { + Q_OBJECT + + public: + //! Constructor + CContextSimulatorEmpty(CCoreFacade *runtime) : IContextSimulator(CCoreFacadeConfig::NotUsed, runtime) {} + + public slots: + //! \copydoc IContextSimulator::getSimulatorPluginInfo() + virtual BlackMisc::Simulation::CSimulatorPluginInfo getSimulatorPluginInfo() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Simulation::CSimulatorPluginInfo(); + } + + //! \copydoc IContextSimulator::getAvailableSimulatorPlugins() + virtual BlackMisc::Simulation::CSimulatorPluginInfoList getAvailableSimulatorPlugins() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Simulation::CSimulatorPluginInfoList(); + } + + //! \copydoc IContextSimulator::startSimulatorPlugin() + virtual bool startSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override + { + Q_UNUSED(simulatorInfo); + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + + //! \copydoc IContextSimulator::getSimulatorStatus() + virtual int getSimulatorStatus() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return 0; + } + + //! \copydoc IContextSimulator::stopSimulatorPlugin() + virtual void stopSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override + { + Q_UNUSED(simulatorInfo); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextSimulator::getAirportsInRange() + virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Aviation::CAirportList(); + } + + //! \copydoc IContextSimulator::getInstalledModels() + virtual BlackMisc::Simulation::CAircraftModelList getInstalledModels() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Simulation::CAircraftModelList(); + } + + //! \copydoc IContextSimulator::getInstalledModelsStartingWith + virtual BlackMisc::Simulation::CAircraftModelList getInstalledModelsStartingWith(const QString modelString) const override + { + Q_UNUSED(modelString); + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Simulation::CAircraftModelList(); + } + + //! \copydoc IContextSimulator::getInstalledModelsCount + virtual int getInstalledModelsCount() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return 0; + } + + //! \copydoc IContextSimulator::reloadInstalledModels + virtual void reloadInstalledModels() override + { + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextSimulator::getSimulatorSetup + virtual BlackMisc::Simulation::CSimulatorSetup getSimulatorSetup() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Simulation::CSimulatorSetup(); + } + + //! \copydoc IContextSimulator::setTimeSynchronization + virtual bool setTimeSynchronization(bool enable, const BlackMisc::PhysicalQuantities::CTime &offset) override + { + Q_UNUSED(enable); + Q_UNUSED(offset); + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + + //! \copydoc IContextSimulator::isTimeSynchronized + virtual bool isTimeSynchronized() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + + //! \copydoc IContextSimulator::getMaxRenderedAircraft + virtual int getMaxRenderedAircraft() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return 0; + } + + //! \copydoc IContextSimulator::setMaxRenderedAircraft + virtual void setMaxRenderedAircraft(int number) override + { + Q_UNUSED(number); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextSimulator::setMaxRenderedDistance + virtual void setMaxRenderedDistance(const BlackMisc::PhysicalQuantities::CLength &distance) override + { + Q_UNUSED(distance); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextSimulator::setMaxRenderedDistance + virtual void deleteAllRenderingRestrictions() override + { + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextSimulator::isRenderingRestricted + virtual bool isRenderingRestricted() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + + //! \copydoc IContextSimulator::isRenderingEnabled + virtual bool isRenderingEnabled() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return false; + } + + //! \copydoc IContextSimulator::getMaxRenderedDistance + virtual BlackMisc::PhysicalQuantities::CLength getMaxRenderedDistance() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::PhysicalQuantities::CLength(); + } + + //! \copydoc IContextSimulator::getRenderedDistanceBoundary + virtual BlackMisc::PhysicalQuantities::CLength getRenderedDistanceBoundary() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::PhysicalQuantities::CLength(); + } + + //! \copydoc IContextSimulator::getRenderRestrictionText + virtual QString getRenderRestrictionText() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return QString(); + } + + //! \copydoc IContextSimulator::getTimeSynchronizationOffset + virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::PhysicalQuantities::CTime(); + } + + //! \copydoc IContextSimulator::iconForModel + virtual BlackMisc::CPixmap iconForModel(const QString &modelString) const override + { + Q_UNUSED(modelString); + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::CPixmap(); + } + + //! \copydoc IContextSimulator::highlightAircraft + virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) override + { + Q_UNUSED(aircraftToHighlight); + Q_UNUSED(enableHighlight); + Q_UNUSED(displayTime); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc IContextSimulator::requestWeatherGrid + virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier) override + { + Q_UNUSED(weatherGrid); + Q_UNUSED(identifier); + logEmptyContextWarning(Q_FUNC_INFO); + } + + //! \copydoc ISimulator::enableDebugMessages + virtual void enableDebugMessages(bool driver, bool interpolator) override + { + Q_UNUSED(driver); + Q_UNUSED(interpolator); + logEmptyContextWarning(Q_FUNC_INFO); + } + }; + } // namespace +} // namespace + +#endif // guard diff --git a/src/blackcore/context/contextsimulatorimpl.cpp b/src/blackcore/context/contextsimulatorimpl.cpp new file mode 100644 index 000000000..ab92571c0 --- /dev/null +++ b/src/blackcore/context/contextsimulatorimpl.cpp @@ -0,0 +1,633 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "blackcore/context/contextapplication.h" +#include "blackcore/context/contextnetwork.h" +#include "blackcore/context/contextnetworkimpl.h" +#include "blackcore/context/contextownaircraft.h" +#include "blackcore/context/contextownaircraftimpl.h" +#include "blackcore/context/contextsimulatorimpl.h" +#include "blackcore/corefacade.h" +#include "blackcore/pluginmanagersimulator.h" +#include "blackcore/simulator.h" +#include "blackmisc/aviation/callsign.h" +#include "blackmisc/compare.h" +#include "blackmisc/dbusserver.h" +#include "blackmisc/logcategory.h" +#include "blackmisc/loghandler.h" +#include "blackmisc/logmessage.h" +#include "blackmisc/pq/units.h" +#include "blackmisc/simulation/simulatedaircraft.h" +#include "blackmisc/statusmessage.h" +#include "blackmisc/threadutils.h" + +#include +#include +#include +#include +#include + +using namespace BlackMisc; +using namespace BlackMisc::PhysicalQuantities; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::Network; +using namespace BlackMisc::Simulation; +using namespace BlackMisc::Geo; +using namespace BlackMisc::Simulation; + +namespace BlackCore +{ + namespace Context + { + CContextSimulator::CContextSimulator(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : + IContextSimulator(mode, runtime), + m_plugins(new CPluginManagerSimulator(this)) + { + this->setObjectName("CContextSimulator"); + connect(&m_weatherManager, &CWeatherManager::weatherGridReceived, this, &CContextSimulator::weatherGridReceived); + m_plugins->collectPlugins(); + } + + CContextSimulator *CContextSimulator::registerWithDBus(CDBusServer *server) + { + if (!server || this->m_mode != CCoreFacadeConfig::LocalInDbusServer) return this; + server->addObject(CContextSimulator::ObjectPath(), this); + return this; + } + + CContextSimulator::~CContextSimulator() + { + this->gracefulShutdown(); + } + + void CContextSimulator::gracefulShutdown() + { + this->disconnect(); + this->unloadSimulatorPlugin(); + } + + CSimulatorPluginInfoList CContextSimulator::getAvailableSimulatorPlugins() const + { + return m_plugins->getAvailableSimulatorPlugins(); + } + + bool CContextSimulator::startSimulatorPlugin(const CSimulatorPluginInfo &simulatorInfo) + { + return this->loadSimulatorPlugin(simulatorInfo, true); + } + + void CContextSimulator::stopSimulatorPlugin(const CSimulatorPluginInfo &simulatorInfo) + { + if (!m_simulatorPlugin.first.isUnspecified() && m_simulatorPlugin.first == simulatorInfo) + { + this->unloadSimulatorPlugin(); + } + + ISimulatorListener *listener = m_plugins->getListener(simulatorInfo.getIdentifier()); + Q_ASSERT(listener); + QMetaObject::invokeMethod(listener, "stop"); + } + + int CContextSimulator::getSimulatorStatus() const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (m_simulatorPlugin.first.isUnspecified()) { return 0; } + + Q_ASSERT_X(m_simulatorPlugin.second, Q_FUNC_INFO, "Missing simulator"); + return m_simulatorPlugin.second->getSimulatorStatus(); + } + + BlackMisc::Simulation::CSimulatorPluginInfo CContextSimulator::getSimulatorPluginInfo() const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (m_simulatorPlugin.first.isUnspecified()) { return BlackMisc::Simulation::CSimulatorPluginInfo(); } + + Q_ASSERT(m_simulatorPlugin.second); + return m_simulatorPlugin.first; + } + + CSimulatorSetup CContextSimulator::getSimulatorSetup() const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (m_simulatorPlugin.first.isUnspecified()) + { + return BlackMisc::Simulation::CSimulatorSetup(); + } + + Q_ASSERT(m_simulatorPlugin.second); + return m_simulatorPlugin.second->getSimulatorSetup(); + } + + CAirportList CContextSimulator::getAirportsInRange() const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + // If no ISimulator object is available, return a dummy. + if (m_simulatorPlugin.first.isUnspecified()) + { + return CAirportList(); + } + + Q_ASSERT(m_simulatorPlugin.second); + return m_simulatorPlugin.second->getAirportsInRange(); + } + + CAircraftModelList CContextSimulator::getInstalledModels() const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + // If no ISimulator object is available, return a dummy. + if (m_simulatorPlugin.first.isUnspecified()) + { + return CAircraftModelList(); + } + + Q_ASSERT(m_simulatorPlugin.second); + return m_simulatorPlugin.second->getInstalledModels(); + } + + int CContextSimulator::getInstalledModelsCount() const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (m_simulatorPlugin.first.isUnspecified()) { return 0; } + + Q_ASSERT(m_simulatorPlugin.second); + return m_simulatorPlugin.second->getInstalledModels().size(); + } + + CAircraftModelList CContextSimulator::getInstalledModelsStartingWith(const QString modelString) const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << modelString; } + if (m_simulatorPlugin.first.isUnspecified()) + { + return CAircraftModelList(); + } + + Q_ASSERT(m_simulatorPlugin.second); + return m_simulatorPlugin.second->getInstalledModels().findModelsStartingWith(modelString); + } + + void CContextSimulator::reloadInstalledModels() + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (m_simulatorPlugin.first.isUnspecified()) + { + return; + } + Q_ASSERT(m_simulatorPlugin.second); + m_simulatorPlugin.second->reloadInstalledModels(); + } + + bool CContextSimulator::setTimeSynchronization(bool enable, const CTime &offset) + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (m_simulatorPlugin.first.isUnspecified()) { return false; } + + Q_ASSERT(m_simulatorPlugin.second); + bool c = m_simulatorPlugin.second->setTimeSynchronization(enable, offset); + if (!c) { return false; } + + CLogMessage(this).info(enable ? QStringLiteral("Set time syncronization to %1").arg(offset.toQString()) : QStringLiteral("Disabled time syncrhonization")); + return true; + } + + bool CContextSimulator::isTimeSynchronized() const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (m_simulatorPlugin.first.isUnspecified()) { return false; } + + Q_ASSERT(m_simulatorPlugin.second); + return m_simulatorPlugin.second->isTimeSynchronized(); + } + + int CContextSimulator::getMaxRenderedAircraft() const + { + if (m_debugEnabled) {CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (m_simulatorPlugin.first.isUnspecified()) { return 0; } + Q_ASSERT(m_simulatorPlugin.second); + return m_simulatorPlugin.second->getMaxRenderedAircraft(); + } + + void CContextSimulator::setMaxRenderedAircraft(int number) + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << number; } + if (m_simulatorPlugin.first.isUnspecified()) { return; } + Q_ASSERT(m_simulatorPlugin.second); + m_simulatorPlugin.second->setMaxRenderedAircraft(number); + + } + + void CContextSimulator::setMaxRenderedDistance(const CLength &distance) + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << distance; } + if (m_simulatorPlugin.first.isUnspecified()) { return; } + Q_ASSERT(m_simulatorPlugin.second); + m_simulatorPlugin.second->setMaxRenderedDistance(distance); + } + + QString CContextSimulator::getRenderRestrictionText() const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (m_simulatorPlugin.first.isUnspecified()) { return ""; } + + Q_ASSERT(m_simulatorPlugin.second); + if (!m_simulatorPlugin.second->isRenderingRestricted()) { return "none"; } + QString rt; + if (m_simulatorPlugin.second->isMaxAircraftRestricted()) + { + rt.append(QString::number(m_simulatorPlugin.second->getMaxRenderedAircraft())).append(" A/C"); + } + if (m_simulatorPlugin.second->isMaxDistanceRestricted()) + { + if (!rt.isEmpty()) { rt.append(" ");} + rt.append(m_simulatorPlugin.second->getMaxRenderedDistance().valueRoundedWithUnit(CLengthUnit::NM(), 0)); + } + return rt; + } + + CLength CContextSimulator::getMaxRenderedDistance() const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (m_simulatorPlugin.first.isUnspecified()) { return CLength(0, CLengthUnit::nullUnit()); } + Q_ASSERT(m_simulatorPlugin.second); + return m_simulatorPlugin.second->getMaxRenderedDistance(); + } + + CLength CContextSimulator::getRenderedDistanceBoundary() const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (m_simulatorPlugin.first.isUnspecified()) + { + return CLength(20.0, CLengthUnit::NM()); + } + Q_ASSERT(m_simulatorPlugin.second); + return m_simulatorPlugin.second->getRenderedDistanceBoundary(); + } + + void CContextSimulator::deleteAllRenderingRestrictions() + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (!m_simulatorPlugin.first.isUnspecified()) + { + Q_ASSERT(m_simulatorPlugin.second); + m_simulatorPlugin.second->deleteAllRenderingRestrictions(); + } + } + + bool CContextSimulator::isRenderingRestricted() const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (m_simulatorPlugin.first.isUnspecified()) { return false; } + Q_ASSERT(m_simulatorPlugin.second); + return m_simulatorPlugin.second->isRenderingRestricted(); + } + + bool CContextSimulator::isRenderingEnabled() const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (m_simulatorPlugin.first.isUnspecified()) { return false; } + Q_ASSERT(m_simulatorPlugin.second); + return m_simulatorPlugin.second->isRenderingEnabled(); + } + + CTime CContextSimulator::getTimeSynchronizationOffset() const + { + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (m_simulatorPlugin.first.isUnspecified()) { return CTime(0, CTimeUnit::hrmin()); } + Q_ASSERT(m_simulatorPlugin.second); + return m_simulatorPlugin.second->getTimeSynchronizationOffset(); + } + + bool CContextSimulator::loadSimulatorPlugin(const CSimulatorPluginInfo &simulatorInfo, bool withListener) + { + Q_ASSERT(getIContextApplication()); + Q_ASSERT(getIContextApplication()->isUsingImplementingObject()); + Q_ASSERT(!simulatorInfo.isUnspecified()); + Q_ASSERT(CThreadUtils::isCurrentThreadApplicationThread()); // only run in main thread + + if (!simulatorInfo.isValid()) + { + CLogMessage(this).error("Illegal plugin"); + return false; + } + + // Is the plugin already loaded? + if (!m_simulatorPlugin.first.isUnspecified()) + { + return true; + } + + unloadSimulatorPlugin(); // old plugin unloaded + + // now we have a state where no driver is loaded + if (withListener) + { + this->listenForSimulator(simulatorInfo); + return false; // not a plugin yet, just listener + } + + if (!simulatorInfo.isValid() || simulatorInfo.isUnspecified()) + { + CLogMessage(this).error("Illegal plugin"); + return false; + } + + ISimulatorFactory *factory = m_plugins->getFactory(simulatorInfo.getIdentifier()); + Q_ASSERT_X(factory, Q_FUNC_INFO, "no factory"); + + // We assume we run in the same process as the own aircraft context + // Hence we pass in memory reference to own aircraft object + Q_ASSERT(this->getIContextOwnAircraft()->isUsingImplementingObject()); + Q_ASSERT(this->getIContextNetwork()->isUsingImplementingObject()); + IOwnAircraftProvider *ownAircraftProvider = this->getRuntime()->getCContextOwnAircraft(); + IRemoteAircraftProvider *renderedAircraftProvider = this->getRuntime()->getCContextNetwork(); + ISimulator *simulator = factory->create(simulatorInfo, ownAircraftProvider, renderedAircraftProvider, &m_weatherManager); + Q_ASSERT_X(simulator, Q_FUNC_INFO, "no simulator driver can be created"); + + bool c = connect(simulator, &ISimulator::simulatorStatusChanged, this, &CContextSimulator::ps_onSimulatorStatusChanged); + Q_ASSERT(c); + c = connect(simulator, &ISimulator::ownAircraftModelChanged, this, &IContextSimulator::ownAircraftModelChanged); + Q_ASSERT(c); + c = connect(simulator, &ISimulator::modelMatchingCompleted, this, &IContextSimulator::modelMatchingCompleted); + Q_ASSERT(c); + c = connect(simulator, &ISimulator::installedAircraftModelsChanged, this, &IContextSimulator::installedAircraftModelsChanged); + Q_ASSERT(c); + c = connect(simulator, &ISimulator::renderRestrictionsChanged, this, &IContextSimulator::renderRestrictionsChanged); + Q_ASSERT(c); + c = connect(simulator, &ISimulator::airspaceSnapshotHandled, this, &IContextSimulator::airspaceSnapshotHandled); + Q_ASSERT(c); + + // log from context to simulator + c = connect(CLogHandler::instance(), &CLogHandler::localMessageLogged, simulator, &ISimulator::displayStatusMessage); + Q_ASSERT(c); + c = connect(CLogHandler::instance(), &CLogHandler::remoteMessageLogged, simulator, &ISimulator::displayStatusMessage); + Q_ASSERT(c); + Q_UNUSED(c); + + // use network to initally add aircraft + IContextNetwork *networkContext = this->getIContextNetwork(); + Q_ASSERT(networkContext); + Q_ASSERT(networkContext->isLocalObject()); + + // initially add aircraft + for (const CSimulatedAircraft &simulatedAircraft : networkContext->getAircraftInRange()) + { + Q_ASSERT(!simulatedAircraft.getCallsign().isEmpty()); + simulator->logicallyAddRemoteAircraft(simulatedAircraft); + } + + // when everything is set up connected, update the current plugin info + m_simulatorPlugin.first = simulatorInfo; + m_simulatorPlugin.second = simulator; + + // try to connect to simulator + simulator->connectTo(); + emit simulatorPluginChanged(simulatorInfo); + CLogMessage(this).info("Simulator plugin loaded: %1") << simulatorInfo.toQString(true); + + return true; + } + + void CContextSimulator::listenForSimulator(const CSimulatorPluginInfo &simulatorInfo) + { + Q_ASSERT(this->getIContextApplication()); + Q_ASSERT(this->getIContextApplication()->isUsingImplementingObject()); + Q_ASSERT(!simulatorInfo.isUnspecified()); + + ISimulator::SimulatorStatus simStatus = getSimulatorStatusEnum(); + if (!m_simulatorPlugin.first.isUnspecified() && + m_simulatorPlugin.first == simulatorInfo && simStatus.testFlag(ISimulator::Connected)) + { + // the simulator is already connected and running + return; + } + + if (!m_simulatorPlugin.first.isUnspecified()) + { + // wrong or disconnected plugin, we start from the scratch + this->unloadSimulatorPlugin(); + } + + if (!m_listenersThread.isRunning()) + { + m_listenersThread.setObjectName("CContextSimulator:Thread for listeners"); + m_listenersThread.start(QThread::LowPriority); + } + + ISimulatorListener *listener = m_plugins->createListener(simulatorInfo.getIdentifier()); + Q_ASSERT_X(listener, Q_FUNC_INFO, "No listener"); + + if (listener->thread() != &m_listenersThread) + { + bool c = connect(listener, &ISimulatorListener::simulatorStarted, this, &CContextSimulator::ps_simulatorStarted); + if (!c) + { + CLogMessage(this).error("Unable to use '%1'") << simulatorInfo.toQString(); + return; + } + + Q_ASSERT_X(!listener->parent(), Q_FUNC_INFO, "Objects with parent cannot be moved to thread"); + listener->setProperty("isInitialized", true); + listener->moveToThread(&m_listenersThread); + } + + bool s = QMetaObject::invokeMethod(listener, "start", Qt::QueuedConnection); + Q_ASSERT_X(s, Q_FUNC_INFO, "cannot invoke method"); + Q_UNUSED(s); + + CLogMessage(this).info("Listening for simulator %1") << simulatorInfo.getIdentifier(); + } + + void CContextSimulator::listenForAllSimulators() + { + auto plugins = getAvailableSimulatorPlugins(); + for (const CSimulatorPluginInfo &p : plugins) + { + Q_ASSERT(!p.isUnspecified()); + + if (p.isValid()) + { + listenForSimulator(p); + } + } + } + + void CContextSimulator::unloadSimulatorPlugin() + { + if (!m_simulatorPlugin.first.isUnspecified()) + { + ISimulator *sim = m_simulatorPlugin.second; + m_simulatorPlugin.second = nullptr; + m_simulatorPlugin.first = CSimulatorPluginInfo(); + + Q_ASSERT(this->getIContextNetwork()); + Q_ASSERT(this->getIContextNetwork()->isLocalObject()); + + // unload and disconnect + if (sim) + { + // disconnect signals and delete + sim->unload(); + this->disconnect(sim); + sim->deleteLater(); + emit simulatorPluginChanged(CSimulatorPluginInfo()); + } + } + } + + void CContextSimulator::ps_addRemoteAircraft(const CSimulatedAircraft &remoteAircraft) + { + //! \todo This was previously an assert and it should be one again in the future. This slot should not even be called when no simulator is available. + if (m_simulatorPlugin.first.isUnspecified()) + { + // Do something if no simulator is running + return; + } + + Q_ASSERT(m_simulatorPlugin.second); + Q_ASSERT(!remoteAircraft.getCallsign().isEmpty()); + + m_simulatorPlugin.second->logicallyAddRemoteAircraft(remoteAircraft); + } + + void CContextSimulator::ps_removedRemoteAircraft(const CCallsign &callsign) + { + // \fixme: This was previously an assert and it should be one again in the future. + // This slot should not even be called when no simulator is available. + if (m_simulatorPlugin.first.isUnspecified()) + { + // Do something if no simulator is running + return; + } + + Q_ASSERT(m_simulatorPlugin.second); + m_simulatorPlugin.second->logicallyRemoveRemoteAircraft(callsign); + } + + void CContextSimulator::ps_onSimulatorStatusChanged(int status) + { + ISimulator::SimulatorStatus statusEnum = ISimulator::statusToEnum(status); + if (!statusEnum.testFlag(ISimulator::Connected)) + { + // we got disconnected, plugin no longer needed + unloadSimulatorPlugin(); + } + emit simulatorStatusChanged(status); + } + + void CContextSimulator::ps_textMessagesReceived(const Network::CTextMessageList &textMessages) + { + // todo: + // This was previously an assert and it should be one again in the future. + // This slot should not even be called when no simulator is available. + if (m_simulatorPlugin.first.isUnspecified()) + { + // Do something if no simulator is running + return; + } + + Q_ASSERT(m_simulatorPlugin.second); + for (const auto &tm : textMessages) + { + m_simulatorPlugin.second->displayTextMessage(tm); + } + } + + void CContextSimulator::ps_cockpitChangedFromSimulator(const CSimulatedAircraft &ownAircraft) + { + Q_ASSERT(getIContextOwnAircraft()); + getIContextOwnAircraft()->changedAircraftCockpit(ownAircraft, IContextSimulator::InterfaceName()); + } + + void CContextSimulator::ps_changedRemoteAircraftModel(const CSimulatedAircraft &aircraft, const CIdentifier &originator) + { + Q_ASSERT(m_simulatorPlugin.second); + m_simulatorPlugin.second->changeRemoteAircraftModel(aircraft, originator); + } + + void CContextSimulator::ps_changedRemoteAircraftEnabled(const CSimulatedAircraft &aircraft, const CIdentifier &originator) + { + Q_ASSERT(m_simulatorPlugin.second); + m_simulatorPlugin.second->changeRemoteAircraftEnabled(aircraft, originator); + } + + void CContextSimulator::ps_updateSimulatorCockpitFromContext(const CSimulatedAircraft &ownAircraft, const CIdentifier &originator) + { + // todo: + // This was previously an assert and it should be one again in the future. + // This slot should not even be called when no simulator is available. + if (m_simulatorPlugin.first.isUnspecified()) + { + // Do something if no simulator is running + return; + } + + Q_ASSERT(m_simulatorPlugin.second); + + // avoid loops + if (originator.getName().isEmpty() || originator == IContextSimulator::InterfaceName()) { return; } + + // update + m_simulatorPlugin.second->updateOwnSimulatorCockpit(ownAircraft, originator); + } + + void CContextSimulator::restoreSimulatorPlugins() + { + stopSimulatorListeners(); + + auto enabledSimulators = m_enabledSimulators.getThreadLocal(); + auto allSimulators = m_plugins->getAvailableSimulatorPlugins(); + for (const CSimulatorPluginInfo &s : allSimulators) + { + if (enabledSimulators.contains(s.getIdentifier())) + { + startSimulatorPlugin(s); + } + } + } + + CPixmap CContextSimulator::iconForModel(const QString &modelString) const + { + if (m_simulatorPlugin.first.isUnspecified()) { return CPixmap(); } + Q_ASSERT_X(m_simulatorPlugin.second, Q_FUNC_INFO, "Missing simulator"); + return m_simulatorPlugin.second->iconForModel(modelString); + } + + void CContextSimulator::enableDebugMessages(bool driver, bool interpolator) + { + if (m_simulatorPlugin.first.isUnspecified()) { return; } + Q_ASSERT_X(m_simulatorPlugin.second, Q_FUNC_INFO, "Missing simulator"); + return m_simulatorPlugin.second->enableDebugMessages(driver, interpolator); + } + + void CContextSimulator::highlightAircraft(const CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const CTime &displayTime) + { + Q_ASSERT(m_simulatorPlugin.second); + m_simulatorPlugin.second->highlightAircraft(aircraftToHighlight, enableHighlight, displayTime); + } + + void CContextSimulator::requestWeatherGrid(const Weather::CWeatherGrid &weatherGrid, const CIdentifier &identifier) + { + m_weatherManager.requestWeatherGrid(weatherGrid, identifier); + } + + void CContextSimulator::ps_simulatorStarted(const CSimulatorPluginInfo &info) + { + stopSimulatorListeners(); + loadSimulatorPlugin(info, false); + } + + void CContextSimulator::stopSimulatorListeners() + { + for (const auto &info : getAvailableSimulatorPlugins()) + { + ISimulatorListener *listener = m_plugins->getListener(info.getIdentifier()); + if (listener) { QMetaObject::invokeMethod(listener, "stop"); } + } + } + } // namespace +} // namespace diff --git a/src/blackcore/context/contextsimulatorimpl.h b/src/blackcore/context/contextsimulatorimpl.h new file mode 100644 index 000000000..6e181916a --- /dev/null +++ b/src/blackcore/context/contextsimulatorimpl.h @@ -0,0 +1,213 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKCORE_CONTEXT_CONTEXTSIMULATOR_IMPL_H +#define BLACKCORE_CONTEXT_CONTEXTSIMULATOR_IMPL_H + +#include "blackcore/blackcoreexport.h" +#include "blackcore/context/contextsimulator.h" +#include "blackcore/corefacadeconfig.h" +#include "blackcore/settings/application.h" +#include "blackcore/weathermanager.h" +#include "blackmisc/aviation/airportlist.h" +#include "blackmisc/identifier.h" +#include "blackmisc/network/textmessagelist.h" +#include "blackmisc/pixmap.h" +#include "blackmisc/pq/length.h" +#include "blackmisc/pq/time.h" +#include "blackmisc/settingscache.h" +#include "blackmisc/simulation/aircraftmodellist.h" +#include "blackmisc/simulation/simulatorplugininfo.h" +#include "blackmisc/simulation/simulatorplugininfolist.h" +#include "blackmisc/simulation/simulatorsetup.h" +#include "blackmisc/worker.h" + +#include +#include +#include + +namespace BlackMisc +{ + class CDBusServer; + namespace Aviation { class CCallsign; } + namespace Simulation { class CSimulatedAircraft; } +} + +namespace BlackCore +{ + class CCoreFacade; + class CPluginManagerSimulator; + class ISimulator; + + namespace Context + { + //! Network simulator concrete implementation + class BLACKCORE_EXPORT CContextSimulator : public IContextSimulator + { + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTSIMULATOR_INTERFACENAME) + friend class BlackCore::CCoreFacade; + friend class IContextSimulator; + + public: + //! Destructor + virtual ~CContextSimulator(); + + //! Gracefully shut down, e.g. for plugin unloading + void gracefulShutdown(); + + public slots: + //! \copydoc IContextSimulator::getSimulatorPluginInfo() + virtual BlackMisc::Simulation::CSimulatorPluginInfo getSimulatorPluginInfo() const override; + + //! \copydoc IContextSimulator::getAvailableSimulatorPlugins() + virtual BlackMisc::Simulation::CSimulatorPluginInfoList getAvailableSimulatorPlugins() const override; + + //! \copydoc IContextSimulator::startSimulatorPlugin() + virtual bool startSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override; + + //! \copydoc IContextSimulator::stopSimulatorPlugin() + virtual void stopSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override; + + //! \copydoc IContextSimulator::getSimulatorStatus() + virtual int getSimulatorStatus() const override; + + //! \copydoc IContextSimulator::getSimulatorSetup() + virtual BlackMisc::Simulation::CSimulatorSetup getSimulatorSetup() const override; + + //! \copydoc IContextSimulator::getAirportsInRange + virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override; + + //! \copydoc IContextSimulator::getInstalledModels + virtual BlackMisc::Simulation::CAircraftModelList getInstalledModels() const override; + + //! \copydoc IContextSimulator::getInstalledModelsCount + virtual int getInstalledModelsCount() const override; + + //! \copydoc IContextSimulator::getInstalledModelsStartingWith + virtual BlackMisc::Simulation::CAircraftModelList getInstalledModelsStartingWith(const QString modelString) const override; + + //! \copydoc IContextSimulator::reloadInstalledModels + virtual void reloadInstalledModels() override; + + //! \copydoc IContextSimulator::setTimeSynchronization + virtual bool setTimeSynchronization(bool enable, const BlackMisc::PhysicalQuantities::CTime &offset) override; + + //! \copydoc IContextSimulator::isTimeSynchronized + virtual bool isTimeSynchronized() const override; + + //! \copydoc IContextSimulator::getMaxRenderedAircraft + virtual int getMaxRenderedAircraft() const override; + + //! \copydoc IContextSimulator::setMaxRenderedAircraft + virtual void setMaxRenderedAircraft(int number) override; + + //! \copydoc IContextSimulator::getMaxRenderedDistance + virtual BlackMisc::PhysicalQuantities::CLength getMaxRenderedDistance() const override; + + //! \copydoc IContextSimulator::setMaxRenderedDistance + virtual void setMaxRenderedDistance(const BlackMisc::PhysicalQuantities::CLength &distance) override; + + //! \copydoc IContextSimulator::getRenderRestrictionText + virtual QString getRenderRestrictionText() const override; + + //! \copydoc IContextSimulator::getRenderedDistanceBoundary + virtual BlackMisc::PhysicalQuantities::CLength getRenderedDistanceBoundary() const override; + + //! \copydoc IContextSimulator::setMaxRenderedDistance + virtual void deleteAllRenderingRestrictions() override; + + //! \copydoc IContextSimulator::isRenderingRestricted + virtual bool isRenderingRestricted() const override; + + //! \copydoc IContextSimulator::isRenderingEnabled + virtual bool isRenderingEnabled() const override; + + //! \copydoc IContextSimulator::getTimeSynchronizationOffset + virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const override; + + //! \copydoc IContextSimulator::iconForModel + virtual BlackMisc::CPixmap iconForModel(const QString &modelString) const override; + + //! \copydoc ISimulator::enableDebugMessages + virtual void enableDebugMessages(bool driver, bool interpolator) override; + + //! \copydoc IContextSimulator::highlightAircraft + virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) override; + + //! \copydoc IContextSimulator::requestWeatherGrid + virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier) override; + + protected: + //! Constructor + CContextSimulator(CCoreFacadeConfig::ContextMode, CCoreFacade *runtime); + + //! Register myself in DBus + CContextSimulator *registerWithDBus(BlackMisc::CDBusServer *server); + + private slots: + //! Remote aircraft added + void ps_addRemoteAircraft(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft); + + //! Remove remote aircraft + void ps_removedRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign); + + //! Handle new connection status of simulator + void ps_onSimulatorStatusChanged(int status); + + //! Text message received + void ps_textMessagesReceived(const BlackMisc::Network::CTextMessageList &textMessages); + + //! Listener reports the simulator has started + void ps_simulatorStarted(const BlackMisc::Simulation::CSimulatorPluginInfo &info); + + //! Simulator has changed cockpit + void ps_cockpitChangedFromSimulator(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft); + + //! Changed remote aircraft model + void ps_changedRemoteAircraftModel(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator); + + //! Enable / disable aircraft + void ps_changedRemoteAircraftEnabled(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator); + + //! Update simulator cockpit from context, because someone else has changed cockpit (e.g. GUI, 3rd party) + //! \remarks set by runtime, only to be used locally (not via DBus) + void ps_updateSimulatorCockpitFromContext(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft, const BlackMisc::CIdentifier &originator); + + //! Reads list of enabled simulators, starts listeners + void restoreSimulatorPlugins(); + + private: + //! Load plugin, if required start listeners before + bool loadSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo, bool withListeners); + + //! Unload plugin, if desired restart listeners + void unloadSimulatorPlugin(); + + //! Listen for single simulator + void listenForSimulator(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo); + + //! Listen for all simulators + void listenForAllSimulators(); + + //! Call stop() on all loaded listeners + void stopSimulatorListeners(); + + QPair m_simulatorPlugin; //!< Currently loaded simulator plugin + CPluginManagerSimulator *m_plugins = nullptr; + BlackMisc::CRegularThread m_listenersThread; + BlackCore::CWeatherManager m_weatherManager { this }; + BlackMisc::CSetting m_enabledSimulators { this, &CContextSimulator::restoreSimulatorPlugins }; + }; + } // namespace +} // namespace + +#endif // guard diff --git a/src/blackcore/context/contextsimulatorproxy.cpp b/src/blackcore/context/contextsimulatorproxy.cpp new file mode 100644 index 000000000..f8c1089ac --- /dev/null +++ b/src/blackcore/context/contextsimulatorproxy.cpp @@ -0,0 +1,203 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "blackcore/context/contextsimulatorproxy.h" +#include "blackmisc/dbus.h" +#include "blackmisc/genericdbusinterface.h" +#include "blackmisc/simulation/simulatedaircraft.h" + +#include +#include +#include +#include + +using namespace BlackMisc; +using namespace BlackMisc::PhysicalQuantities; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::Network; +using namespace BlackMisc::Geo; +using namespace BlackMisc::Simulation; + +namespace BlackCore +{ + namespace Context + { + CContextSimulatorProxy::CContextSimulatorProxy(const QString &serviceName, QDBusConnection &connection, CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextSimulator(mode, runtime), m_dBusInterface(nullptr) + { + this->m_dBusInterface = new BlackMisc::CGenericDBusInterface( + serviceName , IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), + connection, this); + this->relaySignals(serviceName, connection); + } + + void CContextSimulatorProxy::relaySignals(const QString &serviceName, QDBusConnection &connection) + { + bool s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), + "simulatorStatusChanged", this, SIGNAL(simulatorStatusChanged(int))); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), + "installedAircraftModelsChanged", this, SIGNAL(installedAircraftModelsChanged())); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), + "ownAircraftModelChanged", this, SIGNAL(ownAircraftModelChanged(BlackMisc::Simulation::CSimulatedAircraft))); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), + "modelMatchingCompleted", this, SIGNAL(modelMatchingCompleted(BlackMisc::Simulation::CSimulatedAircraft))); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), + "renderRestrictionsChanged", this, SIGNAL(renderRestrictionsChanged(bool, bool, int, BlackMisc::PhysicalQuantities::CLength, BlackMisc::PhysicalQuantities::CLength))); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), + "simulatorPluginChanged", this, SIGNAL(simulatorPluginChanged(BlackMisc::Simulation::CSimulatorPluginInfo))); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), + "airspaceSnapshotHandled", this, SIGNAL(airspaceSnapshotHandled())); + Q_ASSERT(s); + s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), + "weatherGridReceived", this, SIGNAL(weatherGridReceived(BlackMisc::Weather::CWeatherGrid, BlackMisc::CIdentifier))); + Q_ASSERT(s); + Q_UNUSED(s); + } + + CSimulatorPluginInfoList CContextSimulatorProxy::getAvailableSimulatorPlugins() const + { + return m_dBusInterface->callDBusRet(QLatin1Literal("getAvailableSimulatorPlugins")); + } + + int CContextSimulatorProxy::getSimulatorStatus() const + { + return m_dBusInterface->callDBusRet(QLatin1Literal("getSimulatorStatus")); + } + + CAirportList CContextSimulatorProxy::getAirportsInRange() const + { + return m_dBusInterface->callDBusRet(QLatin1Literal("getAirportsInRange")); + } + + CAircraftModelList CContextSimulatorProxy::getInstalledModels() const + { + return m_dBusInterface->callDBusRet(QLatin1Literal("getInstalledModels")); + } + + CAircraftModelList CContextSimulatorProxy::getInstalledModelsStartingWith(const QString modelString) const + { + return m_dBusInterface->callDBusRet(QLatin1Literal("getInstalledModelsStartingWith"), modelString); + } + + int CContextSimulatorProxy::getInstalledModelsCount() const + { + return m_dBusInterface->callDBusRet(QLatin1Literal("getInstalledModelsCount")); + } + + void CContextSimulatorProxy::reloadInstalledModels() + { + m_dBusInterface->callDBus(QLatin1Literal("reloadInstalledModels")); + } + + BlackMisc::Simulation::CSimulatorPluginInfo CContextSimulatorProxy::getSimulatorPluginInfo() const + { + return m_dBusInterface->callDBusRet(QLatin1Literal("getSimulatorPluginInfo")); + } + + CSimulatorSetup CContextSimulatorProxy::getSimulatorSetup() const + { + return m_dBusInterface->callDBusRet(QLatin1Literal("getSimulatorSetup")); + } + + bool CContextSimulatorProxy::setTimeSynchronization(bool enable, const CTime &offset) + { + return m_dBusInterface->callDBusRet(QLatin1Literal("setTimeSynchronization"), enable, offset); + } + + bool CContextSimulatorProxy::isTimeSynchronized() const + { + return m_dBusInterface->callDBusRet(QLatin1Literal("isTimeSynchronized")); + } + + void CContextSimulatorProxy::setMaxRenderedAircraft(int number) + { + m_dBusInterface->callDBus(QLatin1Literal("setMaxRenderedAircraft"), number); + } + + void CContextSimulatorProxy::setMaxRenderedDistance(const CLength &distance) + { + m_dBusInterface->callDBus(QLatin1Literal("setMaxRenderedDistance"), distance); + } + + void CContextSimulatorProxy::deleteAllRenderingRestrictions() + { + m_dBusInterface->callDBus(QLatin1Literal("deleteAllRenderingRestrictions")); + } + + bool CContextSimulatorProxy::isRenderingRestricted() const + { + return m_dBusInterface->callDBusRet(QLatin1Literal("isRenderingRestricted")); + } + + bool CContextSimulatorProxy::isRenderingEnabled() const + { + return m_dBusInterface->callDBusRet(QLatin1Literal("isRenderingEnabled")); + } + + CLength CContextSimulatorProxy::getMaxRenderedDistance() const + { + return m_dBusInterface->callDBusRet(QLatin1Literal("getMaxRenderedDistance")); + } + + CLength CContextSimulatorProxy::getRenderedDistanceBoundary() const + { + return m_dBusInterface->callDBusRet(QLatin1Literal("getRenderedDistanceBoundary")); + } + + QString CContextSimulatorProxy::getRenderRestrictionText() const + { + return m_dBusInterface->callDBusRet(QLatin1Literal("getRenderRestrictionText")); + } + + int CContextSimulatorProxy::getMaxRenderedAircraft() const + { + return m_dBusInterface->callDBusRet(QLatin1Literal("getMaxRenderedAircraft")); + } + + CTime CContextSimulatorProxy::getTimeSynchronizationOffset() const + { + return m_dBusInterface->callDBusRet(QLatin1Literal("getTimeSynchronizationOffset")); + } + + bool CContextSimulatorProxy::startSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) + { + return m_dBusInterface->callDBusRet(QLatin1Literal("startSimulatorPlugin"), simulatorInfo); + } + + void CContextSimulatorProxy::stopSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) + { + m_dBusInterface->callDBus(QLatin1Literal("stopSimulatorPlugin"), simulatorInfo); + } + + CPixmap CContextSimulatorProxy::iconForModel(const QString &modelString) const + { + return m_dBusInterface->callDBusRet(QLatin1Literal("iconForModel"), modelString); + } + + void CContextSimulatorProxy::highlightAircraft(const CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const CTime &displayTime) + { + m_dBusInterface->callDBus(QLatin1Literal("highlightAircraft"), aircraftToHighlight, enableHighlight, displayTime); + } + + void CContextSimulatorProxy::requestWeatherGrid(const Weather::CWeatherGrid &weatherGrid, const CIdentifier &identifier) + { + m_dBusInterface->callDBus(QLatin1Literal("requestWeatherGrid"), weatherGrid, identifier); + } + + void CContextSimulatorProxy::enableDebugMessages(bool driver, bool interpolator) + { + m_dBusInterface->callDBus(QLatin1Literal("enableDebugMessages"), driver, interpolator); + } + } // namespace +} // namespace diff --git a/src/blackcore/context/contextsimulatorproxy.h b/src/blackcore/context/contextsimulatorproxy.h new file mode 100644 index 000000000..48f421128 --- /dev/null +++ b/src/blackcore/context/contextsimulatorproxy.h @@ -0,0 +1,150 @@ +/* Copyright (C) 2013 + * swift Project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKCORE_CONTEXTSIMULATOR_PROXY_H +#define BLACKCORE_CONTEXTSIMULATOR_PROXY_H + +#include "blackcore/blackcoreexport.h" +#include "blackcore/context/contextsimulator.h" +#include "blackcore/corefacadeconfig.h" +#include "blackmisc/aviation/airportlist.h" +#include "blackmisc/pixmap.h" +#include "blackmisc/pq/length.h" +#include "blackmisc/pq/time.h" +#include "blackmisc/simulation/aircraftmodellist.h" +#include "blackmisc/simulation/simulatorplugininfo.h" +#include "blackmisc/simulation/simulatorplugininfolist.h" +#include "blackmisc/simulation/simulatorsetup.h" + +#include +#include + +class QDBusConnection; +namespace BlackMisc +{ + class CGenericDBusInterface; + namespace Simulation { class CSimulatedAircraft; } +} + +namespace BlackCore +{ + class CCoreFacade; + namespace Context + { + //! DBus proxy for Simulator Context + //! \ingroup dbus + class BLACKCORE_EXPORT CContextSimulatorProxy : public IContextSimulator + { + Q_OBJECT + friend class IContextSimulator; + + public: + //! Destructor + ~CContextSimulatorProxy() {} + + public slots: + //! \copydoc IContextSimulator::getSimulatorPluginInfo() + virtual BlackMisc::Simulation::CSimulatorPluginInfo getSimulatorPluginInfo() const override; + + //! \copydoc IContextSimulator::getAvailableSimulatorPlugins() + virtual BlackMisc::Simulation::CSimulatorPluginInfoList getAvailableSimulatorPlugins() const override; + + //! \copydoc IContextSimulator::startSimulatorPlugin() + virtual bool startSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override; + + //! \copydoc IContextSimulator::stopSimulatorPlugin() + virtual void stopSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override; + + //! \copydoc IContextSimulator::getSimulatorStatus() + virtual int getSimulatorStatus() const override; + + //! \copydoc IContextSimulator::getAirportsInRange() + virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override; + + //! \copydoc IContextSimulator::getInstalledModels() + virtual BlackMisc::Simulation::CAircraftModelList getInstalledModels() const override; + + //! \copydoc IContextSimulator::getInstalledModelsStartingWith + virtual BlackMisc::Simulation::CAircraftModelList getInstalledModelsStartingWith(const QString modelString) const override; + + //! \copydoc IContextSimulator::getInstalledModelsCount + virtual int getInstalledModelsCount() const override; + + //! \copydoc IContextSimulator::reloadInstalledModels + virtual void reloadInstalledModels() override; + + //! \copydoc IContextSimulator::getSimulatorSetup + virtual BlackMisc::Simulation::CSimulatorSetup getSimulatorSetup() const override; + + //! \copydoc IContextSimulator::setTimeSynchronization + virtual bool setTimeSynchronization(bool enable, const BlackMisc::PhysicalQuantities::CTime &offset) override; + + //! \copydoc IContextSimulator::isTimeSynchronized + virtual bool isTimeSynchronized() const override; + + //! \copydoc IContextSimulator::getMaxRenderedAircraft + virtual int getMaxRenderedAircraft() const override; + + //! \copydoc IContextSimulator::setMaxRenderedAircraft + virtual void setMaxRenderedAircraft(int number) override; + + //! \copydoc IContextSimulator::setMaxRenderedDistance + virtual void setMaxRenderedDistance(const BlackMisc::PhysicalQuantities::CLength &distance) override; + + //! \copydoc IContextSimulator::setMaxRenderedDistance + virtual void deleteAllRenderingRestrictions() override; + + //! \copydoc IContextSimulator::isRenderingRestricted + virtual bool isRenderingRestricted() const override; + + //! \copydoc IContextSimulator::isRenderingEnabled + virtual bool isRenderingEnabled() const override; + + //! \copydoc IContextSimulator::getMaxRenderedDistance + virtual BlackMisc::PhysicalQuantities::CLength getMaxRenderedDistance() const override; + + //! \copydoc IContextSimulator::getRenderedDistanceBoundary + virtual BlackMisc::PhysicalQuantities::CLength getRenderedDistanceBoundary() const override; + + //! \copydoc IContextSimulator::getRenderRestrictionText + virtual QString getRenderRestrictionText() const override; + + //! \copydoc IContextSimulator::getTimeSynchronizationOffset + virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const override; + + //! \copydoc IContextSimulator::iconForModel + virtual BlackMisc::CPixmap iconForModel(const QString &modelString) const override; + + //! \copydoc IContextSimulator::highlightAircraft + virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) override; + + //! \copydoc IContextSimulator::requestWeatherGrid + virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier) override; + + //! \copydoc ISimulator::enableDebugMessages + virtual void enableDebugMessages(bool driver, bool interpolator) override; + + private: + BlackMisc::CGenericDBusInterface *m_dBusInterface; + + //! Relay connection signals to local signals + void relaySignals(const QString &serviceName, QDBusConnection &connection); + + protected: + //! Constructor + CContextSimulatorProxy(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextSimulator(mode, runtime), m_dBusInterface(0) {} + + //! DBus version constructor + CContextSimulatorProxy(const QString &serviceName, QDBusConnection &connection, CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime); + }; + } // ns +} // ns +#endif // guard diff --git a/src/blackcore/contextapplication.cpp b/src/blackcore/contextapplication.cpp deleted file mode 100644 index 220d3caeb..000000000 --- a/src/blackcore/contextapplication.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "blackcore/contextapplication.h" -#include "blackcore/contextapplicationempty.h" -#include "blackcore/contextapplicationimpl.h" -#include "blackcore/contextapplicationproxy.h" -#include "blackcore/corefacade.h" -#include "blackcore/inputmanager.h" -#include "blackmisc/dbus.h" -#include "blackmisc/dbusserver.h" -#include "blackmisc/logcategory.h" -#include "blackmisc/loghandler.h" -#include "blackmisc/logmessage.h" -#include "blackmisc/settingscache.h" -#include "blackmisc/statusmessage.h" - -#include -#include - -using namespace BlackCore; -using namespace BlackMisc; - -namespace BlackCore -{ - - IContextApplication *IContextApplication::create(CCoreFacade *parent, CCoreFacadeConfig::ContextMode mode, BlackMisc::CDBusServer *server, QDBusConnection &connection) - { - switch (mode) - { - case CCoreFacadeConfig::Local: - case CCoreFacadeConfig::LocalInDbusServer: - return (new CContextApplication(mode, parent))->registerWithDBus(server); - case CCoreFacadeConfig::Remote: - return new BlackCore::CContextApplicationProxy(BlackMisc::CDBusServer::coreServiceName(), connection, mode, parent); - case CCoreFacadeConfig::NotUsed: - default: - return new CContextApplicationEmpty(parent); - } - } - - IContextApplication::IContextApplication(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : - CContext(mode, runtime) - { - if (mode == CCoreFacadeConfig::NotUsed) { return; } - connect(CLogHandler::instance(), &CLogHandler::localMessageLogged, this, [this](const CStatusMessage & message) - { - this->logMessage(message, {}); - }); - connect(CLogHandler::instance(), &CLogHandler::subscriptionAdded, this, [this](const CLogPattern & pattern) - { - this->addLogSubscription({}, pattern); - }); - connect(CLogHandler::instance(), &CLogHandler::subscriptionRemoved, this, [this](const CLogPattern & pattern) - { - this->removeLogSubscription({}, pattern); - }); - connect(this, &IContextApplication::logSubscriptionAdded, this, [this](const CIdentifier & subscriber, const CLogPattern & pattern) - { - this->m_logSubscriptions[subscriber].push_back(pattern); - }); - connect(this, &IContextApplication::logSubscriptionRemoved, this, [this](const CIdentifier & subscriber, const CLogPattern & pattern) - { - this->m_logSubscriptions[subscriber].removeAll(pattern); - }); - - connect(CSettingsCache::instance(), &CSettingsCache::valuesChangedByLocal, [this](const CValueCachePacket & settings) - { - this->changeSettings(settings, {}); - }); - - connect(this, &IContextApplication::settingsChanged, [](const CValueCachePacket & settings, const CIdentifier & origin) - { - // Intentionally don't check for round trip here - CSettingsCache::instance()->changeValuesFromRemote(settings, origin); - }); - - bool s = connect(CInputManager::instance(), &CInputManager::hotkeyActionRegistered, [this](const QStringList & actions) - { - this->registerHotkeyActions(actions, {}); - }); - Q_ASSERT_X(s, Q_FUNC_INFO, "Connect hotkey action failed"); - Q_UNUSED(s); - - s = connect(this, &IContextApplication::hotkeyActionsRegistered, [this](const QStringList & actions, const CIdentifier & origin) - { - if (origin.isFromSameProcess()) { return; } - CInputManager::instance()->registerRemoteActions(actions); - }); - Q_ASSERT_X(s, Q_FUNC_INFO, "Connect hotkey actions failed"); - Q_UNUSED(s); - - s = connect(CInputManager::instance(), &CInputManager::remoteActionFromLocal, [this](const QString & action, bool argument) - { - this->callHotkeyAction(action, argument, {}); - }); - Q_ASSERT_X(s, Q_FUNC_INFO, "Connect remote action failed"); - Q_UNUSED(s); - - s = connect(this, &IContextApplication::remoteHotkeyAction, [this](const QString & action, bool argument, const CIdentifier & origin) - { - if (origin.isFromLocalMachine()) { return; } - CInputManager::instance()->callFunctionsBy(action, argument); - CLogMessage(this, CLogCategory::contextSlot()).debug() << "Calling function" << action << "from origin" << origin.getMachineName(); - }); - Q_ASSERT_X(s, Q_FUNC_INFO, "Connect remote hotkey action failed"); - Q_UNUSED(s); - - // Enable event forwarding from GUI process to core - CInputManager::instance()->setForwarding(true); - } - - CIdentifierList IContextApplication::subscribersOf(const CStatusMessage &message) const - { - CIdentifierList result; - for (auto it = m_logSubscriptions.begin(); it != m_logSubscriptions.end(); ++it) - { - bool match = std::any_of(it->begin(), it->end(), [&message](const CLogPattern & pattern) { return pattern.match(message); }); - if (match) { result.push_back(it.key()); } - } - return result; - } - - void IContextApplication::changeSettings(const CValueCachePacket &settings, const CIdentifier &origin) - { - Q_UNUSED(settings); - Q_UNUSED(origin); - qFatal("Not implemented"); // avoid losing a change during context interface construction - } - - void IContextApplication::registerHotkeyActions(const QStringList &actions, const BlackMisc::CIdentifier &origin) - { - Q_UNUSED(actions); - Q_UNUSED(origin); - qFatal("Not implemented"); // avoid losing a change during context interface construction - } - - void IContextApplication::callHotkeyAction(const QString &action, bool argument, const BlackMisc::CIdentifier &origin) - { - Q_UNUSED(action); - Q_UNUSED(argument); - Q_UNUSED(origin); - } - - void IContextApplication::changeSettings(uint typeValue) - { - Q_UNUSED(typeValue); - } - -} // namespace - -QDBusArgument &operator <<(QDBusArgument &arg, const BlackCore::CLogSubscriptionHash &hash) -{ - QList listOfPairs; - for (auto it = hash.begin(); it != hash.end(); ++it) { listOfPairs.push_back({ it.key(), it.value() }); } - return arg << listOfPairs; -} - -const QDBusArgument &operator >>(const QDBusArgument &arg, BlackCore::CLogSubscriptionHash &hash) -{ - QList listOfPairs; - arg >> listOfPairs; - for (const auto &pair : listOfPairs) { hash.insert(pair.first, pair.second); } - return arg; -} diff --git a/src/blackcore/contextapplication.h b/src/blackcore/contextapplication.h deleted file mode 100644 index 460b55e92..000000000 --- a/src/blackcore/contextapplication.h +++ /dev/null @@ -1,225 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKCORE_CONTEXTAPPLICATION_H -#define BLACKCORE_CONTEXTAPPLICATION_H - -#include "blackcore/blackcoreexport.h" -#include "blackcore/context.h" -#include "blackcore/corefacadeconfig.h" -#include "blackmisc/audio/voiceroomlist.h" -#include "blackmisc/compare.h" -#include "blackmisc/dictionary.h" -#include "blackmisc/identifier.h" -#include "blackmisc/identifierlist.h" -#include "blackmisc/logpattern.h" -#include "blackmisc/statusmessage.h" -#include "blackmisc/valuecache.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class QDBusConnection; - -namespace BlackMisc { class CDBusServer; } - -//! \addtogroup dbus -//! @{ - -//! DBus interface for context -#define BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME "org.swift_project.blackcore.contextapplication" - -//! DBus object path for context -#define BLACKCORE_CONTEXTAPPLICATION_OBJECTPATH "/application" - -//! @} - -namespace BlackCore -{ - class CCoreFacade; - class CInputManager; - - //! Used by application context to track which processes are subscribed to which patterns of log message - using CLogSubscriptionHash = QHash>; - - //! Used when marshalling CLogSubscriptionHash, as a QHash with CIdentifier keys can't be marshalled - using CLogSubscriptionPair = QPair>; - - //! Application context interface - class BLACKCORE_EXPORT IContextApplication : public CContext - { - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME) - - protected: - //! Constructor - IContextApplication(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime); - - public: - //! Service name - static const QString &InterfaceName() - { - static QString s(BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME); - return s; - } - - //! Service path - static const QString &ObjectPath() - { - static QString s(BLACKCORE_CONTEXTAPPLICATION_OBJECTPATH); - return s; - } - - //! \copydoc CContext::getPathAndContextId() - virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); } - - //! Factory method - static IContextApplication *create(CCoreFacade *parent, CCoreFacadeConfig::ContextMode mode, BlackMisc::CDBusServer *server, QDBusConnection &conn); - - //! Destructor - virtual ~IContextApplication() {} - - signals: - //! A component changes - void registrationChanged(); - - //! A log message was logged - //! \note Used with CLogMessage, do not use directly - void messageLogged(const BlackMisc::CStatusMessage &message, const BlackMisc::CIdentifier &origin); - - //! A process subscribed to a particular pattern of log messages - //! \note Used with CLogMessage, do not use directly - void logSubscriptionAdded(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern); - - //! A process unsubscribed from a particular pattern of log messages - //! \note Used with CLogMessage, do not use directly - void logSubscriptionRemoved(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern); - - //! One or more settings were changed - //! \note Used for cache relay, do not use directly - void settingsChanged(const BlackMisc::CValueCachePacket &settings, const BlackMisc::CIdentifier &origin); - - //! New action was registered - //! \note Used to register hotkey action, do not use directly - void hotkeyActionsRegistered(const QStringList &actions, const BlackMisc::CIdentifier &origin); - - //! Call a hotkey action on a remote process - //! \note Used for hotkey action, do not use directly - void remoteHotkeyAction(const QString &action, bool argument, const BlackMisc::CIdentifier &origin); - - //! Work around for audio context, #382 - void fakedSetComVoiceRoom(const BlackMisc::Audio::CVoiceRoomList &requestedRooms); - - protected: - //! Compute which process' subscriptions match a given log message. - BlackMisc::CIdentifierList subscribersOf(const BlackMisc::CStatusMessage &message) const; - - //! Tracks which processes are subscribed to which patterns of log messages. - CLogSubscriptionHash m_logSubscriptions; - - public slots: - //! Log a log message - //! \note Not pure because it can be called from the base class constructor. - //! \note this is the function which relays CLogMessage via DBus - virtual void logMessage(const BlackMisc::CStatusMessage &message, const BlackMisc::CIdentifier &origin) { Q_UNUSED(message); Q_UNUSED(origin); } - - //! Subscribe a process to a particular pattern of log messages - //! \note This is the function which relays subscription changes via DBus - virtual void addLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) = 0; - - //! Unsubscribe a process from a particular pattern of log messages - //! \note This is the function which relays subscription changes via DBus - virtual void removeLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) = 0; - - //! Returns hash identifying which processes are subscribed to which patterns of log message - virtual BlackCore::CLogSubscriptionHash getAllLogSubscriptions() const = 0; - - //! Update log subscriptions hash from core - virtual void synchronizeLogSubscriptions() = 0; - - //! Ratify some settings changed by another process - //! \note Not pure because it can be called from the base class constructor. - //! \note This is the function which relays cache changes via DBus. - virtual void changeSettings(const BlackMisc::CValueCachePacket &settings, const BlackMisc::CIdentifier &origin); - - //! Get all settings currently in core settings cache - virtual BlackMisc::CValueCachePacket getAllSettings() const = 0; - - //! Get keys of all unsaved settings currently in core settings cache - virtual QStringList getUnsavedSettingsKeys() const = 0; - - //! Update local settings with settings from core - virtual void synchronizeLocalSettings() = 0; - - //! Save core settings to disk - virtual BlackMisc::CStatusMessage saveSettings(const QString &keyPrefix = {}) = 0; - - //! Save core settings to disk - virtual BlackMisc::CStatusMessage saveSettingsByKey(const QStringList &keys) = 0; - - //! Load core settings from disk - virtual BlackMisc::CStatusMessage loadSettings() = 0; - - //! Register hotkey action implemented by another process - //! \note Not pure because it can be called from the base class constructor. - //! \note This is the function which relays action registrations via DBus - virtual void registerHotkeyActions(const QStringList &actions, const BlackMisc::CIdentifier &origin); - - //! Call a hotkey action on a remote process - //! \note Not pure because it can be called from the base class constructor. - //! \note This is the function which relays action calls via DBus - virtual void callHotkeyAction(const QString &action, bool argument, const BlackMisc::CIdentifier &origin); - - //! Register application, can also be used for ping - virtual BlackMisc::CIdentifier registerApplication(const BlackMisc::CIdentifier &application) = 0; - - //! Unregister application - virtual void unregisterApplication(const BlackMisc::CIdentifier &application) = 0; - - //! All registered applications - virtual BlackMisc::CIdentifierList getRegisteredApplications() const = 0; - - //! Remote enabled version of writing a text file - virtual bool writeToFile(const QString &fileName, const QString &content) = 0; - - //! Remote enabled version of reading a text file - virtual QString readFromFile(const QString &fileName) const = 0; - - //! Remote enabled version of deleting a file - virtual bool removeFile(const QString &fileName) = 0; - - //! Remote enabled version of file exists - virtual bool existsFile(const QString &fileName) const = 0; - - //! Change settings - //! \todo Remove with old settings - void changeSettings(uint typeValue); - - }; -} - -//! DBus marshalling for CLogSubscriptionHash, needed because QtDBus can't marshal a QHash with CIdentifier keys. -QDBusArgument &operator <<(QDBusArgument &arg, const BlackCore::CLogSubscriptionHash &); - -//! DBus unmarshalling for CLogSubscriptionHash, needed because QtDBus can't marshal a QHash with CIdentifier keys. -const QDBusArgument &operator >>(const QDBusArgument &arg, BlackCore::CLogSubscriptionHash &); - -Q_DECLARE_METATYPE(BlackCore::CLogSubscriptionHash) -Q_DECLARE_METATYPE(BlackCore::CLogSubscriptionPair) - -#endif // guard diff --git a/src/blackcore/contextapplicationempty.h b/src/blackcore/contextapplicationempty.h deleted file mode 100644 index 65bf5de8d..000000000 --- a/src/blackcore/contextapplicationempty.h +++ /dev/null @@ -1,195 +0,0 @@ -/* Copyright (C) 2015 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKCORE_CONTEXTAPPLICATION_EMPTY_H -#define BLACKCORE_CONTEXTAPPLICATION_EMPTY_H - -#include "blackcoreexport.h" -#include "contextapplication.h" -#include "corefacade.h" -#include "blackmisc/identifierlist.h" - -namespace BlackCore -{ - class CCoreFacade; - - //! Application context - class BLACKCORE_EXPORT CContextApplicationEmpty : public IContextApplication - { - public: - //! Constructor - CContextApplicationEmpty(CCoreFacade *runtime) : IContextApplication(CCoreFacadeConfig::NotUsed, runtime) {} - - public slots: - //! \copydoc IContextApplication::logMessage - virtual void logMessage(const BlackMisc::CStatusMessage &message, const BlackMisc::CIdentifier &origin) override - { - Q_UNUSED(message); - Q_UNUSED(origin); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextApplication::addLogSubscription - virtual void addLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) override - { - Q_UNUSED(subscriber); - Q_UNUSED(pattern); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextApplication::removeLogSubscription - virtual void removeLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) override - { - Q_UNUSED(subscriber); - Q_UNUSED(pattern); - logEmptyContextWarning(Q_FUNC_INFO); - - } - - //! \copydoc IContextApplication::getAllLogSubscriptions - virtual CLogSubscriptionHash getAllLogSubscriptions() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return CLogSubscriptionHash(); - } - - //! \copydoc IContextApplication::synchronizeLogSubscriptions - virtual void synchronizeLogSubscriptions() override - { - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextApplication::changeSettings - virtual void changeSettings(const BlackMisc::CValueCachePacket &settings, const BlackMisc::CIdentifier &origin) override - { - Q_UNUSED(settings); - Q_UNUSED(origin); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextApplication::getAllSettings - virtual BlackMisc::CValueCachePacket getAllSettings() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::CValueCachePacket(); - } - - //! \copydoc IContextApplication::getUnsavedSettingsKeys - virtual QStringList getUnsavedSettingsKeys() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return QStringList(); - } - - //! \copydoc IContextApplication::synchronizeLocalSettings - virtual void synchronizeLocalSettings() override - { - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextApplication::saveSettings - virtual BlackMisc::CStatusMessage saveSettings(const QString &keyPrefix = {}) override - { - Q_UNUSED(keyPrefix); - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::CStatusMessage(); - } - - //! \copydoc IContextApplication::saveSettingsByKey - virtual BlackMisc::CStatusMessage saveSettingsByKey(const QStringList &keys) override - { - Q_UNUSED(keys); - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::CStatusMessage(); - } - - //! \copydoc IContextApplication::loadSettings - virtual BlackMisc::CStatusMessage loadSettings() override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::CStatusMessage(); - } - - //! \copydoc IContextApplication::registerHotkeyActions - virtual void registerHotkeyActions(const QStringList &actions, const BlackMisc::CIdentifier &origin) override - { - Q_UNUSED(actions); - Q_UNUSED(origin); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextApplication::callHotkeyAction - virtual void callHotkeyAction(const QString &action, bool argument, const BlackMisc::CIdentifier &origin) override - { - Q_UNUSED(action); - Q_UNUSED(argument); - Q_UNUSED(origin); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextApplication::writeToFile - virtual bool writeToFile(const QString &fileName, const QString &content) override - { - Q_UNUSED(fileName); - Q_UNUSED(content); - logEmptyContextWarning(Q_FUNC_INFO); - return false; - } - - //! \copydoc IContextApplication::registerApplication - virtual BlackMisc::CIdentifier registerApplication(const BlackMisc::CIdentifier &application) override - { - Q_UNUSED(application); - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::CIdentifier(); - } - - //! \copydoc IContextApplication::unregisterApplication - virtual void unregisterApplication(const BlackMisc::CIdentifier &application) override - { - Q_UNUSED(application); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextApplication::getRegisteredApplications - virtual BlackMisc::CIdentifierList getRegisteredApplications() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::CIdentifierList(); - } - - //! \copydoc IContextApplication::readFromFile - virtual QString readFromFile(const QString &fileName) const override - { - Q_UNUSED(fileName); - logEmptyContextWarning(Q_FUNC_INFO); - return QString(); - } - - //! \copydoc IContextApplication::removeFile - virtual bool removeFile(const QString &fileName) override - { - Q_UNUSED(fileName); - logEmptyContextWarning(Q_FUNC_INFO); - return false; - } - - //! \copydoc IContextApplication::existsFile - virtual bool existsFile(const QString &fileName) const override - { - Q_UNUSED(fileName); - logEmptyContextWarning(Q_FUNC_INFO); - return false; - } - }; -} // namespace - -#endif // guard diff --git a/src/blackcore/contextapplicationimpl.cpp b/src/blackcore/contextapplicationimpl.cpp deleted file mode 100644 index cc79cb746..000000000 --- a/src/blackcore/contextapplicationimpl.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "blackcore/contextapplicationimpl.h" -#include "blackcore/inputmanager.h" -#include "blackmisc/dbusserver.h" -#include "blackmisc/logcategory.h" -#include "blackmisc/loghandler.h" -#include "blackmisc/logmessage.h" -#include "blackmisc/settingscache.h" - -#include -#include -#include -#include -#include - -using namespace BlackMisc; - -namespace BlackCore -{ - CContextApplication::CContextApplication(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : - IContextApplication(mode, runtime) - { - } - - CContextApplication *CContextApplication::registerWithDBus(BlackMisc::CDBusServer *server) - { - if (!server || this->m_mode != CCoreFacadeConfig::LocalInDbusServer) { return this; } - server->addObject(IContextApplication::ObjectPath(), this); - return this; - } - - void CContextApplication::logMessage(const CStatusMessage &message, const CIdentifier &origin) - { - if (!origin.isFromSameProcess()) - { - CLogHandler::instance()->logRemoteMessage(message); - } - if (subscribersOf(message).containsAnyNotIn(CIdentifierList({ origin, {} }))) - { - emit this->messageLogged(message, origin); - } - } - - void CContextApplication::addLogSubscription(const CIdentifier &subscriber, const CLogPattern &pattern) - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - emit this->logSubscriptionAdded(subscriber, pattern); - } - - void CContextApplication::removeLogSubscription(const CIdentifier &subscriber, const CLogPattern &pattern) - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - emit this->logSubscriptionRemoved(subscriber, pattern); - } - - CLogSubscriptionHash CContextApplication::getAllLogSubscriptions() const - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - return m_logSubscriptions; - } - - void CContextApplication::synchronizeLogSubscriptions() - { - // no-op: proxy implements this method by calling getAllLogSubscriptions - } - - void CContextApplication::changeSettings(const CValueCachePacket &settings, const CIdentifier &origin) - { - // Intentionally don't check for round trip here - emit this->settingsChanged(settings, origin); - } - - BlackMisc::CValueCachePacket CContextApplication::getAllSettings() const - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - return CSettingsCache::instance()->getAllValuesWithTimestamps(); - } - - QStringList CContextApplication::getUnsavedSettingsKeys() const - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - return CSettingsCache::instance()->getAllUnsavedKeys(); - } - - void CContextApplication::synchronizeLocalSettings() - { - // no-op: proxy implements this method by calling getAllSettings - } - - BlackMisc::CStatusMessage CContextApplication::saveSettings(const QString &keyPrefix) - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << keyPrefix; } - return CSettingsCache::instance()->saveToStore(keyPrefix); - } - - BlackMisc::CStatusMessage CContextApplication::saveSettingsByKey(const QStringList &keys) - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << keys.join(", "); } - return CSettingsCache::instance()->saveToStore(keys); - } - - BlackMisc::CStatusMessage CContextApplication::loadSettings() - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - return CSettingsCache::instance()->loadFromStore(); - } - - void CContextApplication::registerHotkeyActions(const QStringList &actions, const CIdentifier &origin) - { - // Intentionally don't check for round trip here - emit this->hotkeyActionsRegistered(actions, origin); - } - - void CContextApplication::callHotkeyAction(const QString &action, bool argument, const CIdentifier &origin) - { - // Intentionally don't check for round trip here - emit this->remoteHotkeyAction(action, argument, origin); - } - - bool CContextApplication::writeToFile(const QString &fileName, const QString &content) - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << fileName << content.left(25); } - if (fileName.isEmpty()) { return false; } - QFile file(fileName); - if (file.open(QIODevice::WriteOnly | QIODevice::Text)) - { - QTextStream out(&file); - out << content; - return true; - } - else - { - return false; - } - } - - CIdentifier CContextApplication::registerApplication(const CIdentifier &application) - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << application; } - if (!m_registeredApplications.contains(application)) - { - m_registeredApplications.push_back(application); - emit registrationChanged(); - emit this->hotkeyActionsRegistered(CInputManager::instance()->allAvailableActions(), {}); - } - else - { - m_registeredApplications.replace(application, application); - } - - return application; - } - - void CContextApplication::unregisterApplication(const CIdentifier &application) - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << application; } - int r = this->m_registeredApplications.remove(application); - if (r > 0) { emit registrationChanged(); } - } - - CIdentifierList CContextApplication::getRegisteredApplications() const - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - return m_registeredApplications; - } - - QString CContextApplication::readFromFile(const QString &fileName) const - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << fileName; } - QFile file(fileName); - QString content; - if (fileName.isEmpty()) return content; - if (file.open(QIODevice::ReadOnly | QIODevice::Text)) - { - QTextStream in(&file); - in >> content; - file.close(); - } - return content; - } - - bool CContextApplication::removeFile(const QString &fileName) - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << fileName; } - if (fileName.isEmpty()) { return false; } - return QFile::remove(fileName); - } - - bool CContextApplication::existsFile(const QString &fileName) const - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << fileName; } - if (fileName.isEmpty()) return false; - return QFile::exists(fileName); - } - -} // namespace diff --git a/src/blackcore/contextapplicationimpl.h b/src/blackcore/contextapplicationimpl.h deleted file mode 100644 index 62473a618..000000000 --- a/src/blackcore/contextapplicationimpl.h +++ /dev/null @@ -1,125 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKCORE_CONTEXTAPPLICATION_IMPL_H -#define BLACKCORE_CONTEXTAPPLICATION_IMPL_H - -#include -#include -#include - -#include "blackcore/blackcoreexport.h" -#include "blackcore/contextapplication.h" -#include "blackcore/corefacadeconfig.h" -#include "blackmisc/identifier.h" -#include "blackmisc/identifierlist.h" -#include "blackmisc/statusmessage.h" -#include "blackmisc/valuecache.h" - -namespace BlackMisc -{ - class CDBusServer; - class CLogPattern; -} - -namespace BlackCore -{ - class CCoreFacade; - - //! Application context - class BLACKCORE_EXPORT CContextApplication : public IContextApplication - { - Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME) - Q_OBJECT - friend class CCoreFacade; - friend class IContextApplication; - - public slots: - //! \copydoc IContextApplication::logMessage - virtual void logMessage(const BlackMisc::CStatusMessage &message, const BlackMisc::CIdentifier &origin) override; - - //! \copydoc IContextApplication::addLogSubscription - virtual void addLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) override; - - //! \copydoc IContextApplication::removeLogSubscription - virtual void removeLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) override; - - //! \copydoc IContextApplication::getAllLogSubscriptions - virtual CLogSubscriptionHash getAllLogSubscriptions() const override; - - //! \copydoc IContextApplication::synchronizeLogSubscriptions - virtual void synchronizeLogSubscriptions() override; - - //! \copydoc IContextApplication::changeSettings - virtual void changeSettings(const BlackMisc::CValueCachePacket &settings, const BlackMisc::CIdentifier &origin) override; - - //! \copydoc IContextApplication::getAllSettings - virtual BlackMisc::CValueCachePacket getAllSettings() const override; - - //! \copydoc IContextApplication::getUnsavedSettingsKeys - virtual QStringList getUnsavedSettingsKeys() const override; - - //! \copydoc IContextApplication::synchronizeLocalSettings - virtual void synchronizeLocalSettings() override; - - //! \copydoc IContextApplication::saveSettings - virtual BlackMisc::CStatusMessage saveSettings(const QString &keyPrefix = {}) override; - - //! \copydoc IContextApplication::saveSettingsByKey - virtual BlackMisc::CStatusMessage saveSettingsByKey(const QStringList &keys) override; - - //! \copydoc IContextApplication::loadSettings - virtual BlackMisc::CStatusMessage loadSettings() override; - - //! \copydoc IContextApplication::registerHotkeyActions - virtual void registerHotkeyActions(const QStringList &actions, const BlackMisc::CIdentifier &origin) override; - - //! \copydoc IContextApplication::callHotkeyAction - virtual void callHotkeyAction(const QString &action, bool argument, const BlackMisc::CIdentifier &origin) override; - - //! \copydoc IContextApplication::writeToFile - virtual bool writeToFile(const QString &fileName, const QString &content) override; - - //! \copydoc IContextApplication::registerApplication - virtual BlackMisc::CIdentifier registerApplication(const BlackMisc::CIdentifier &application) override; - - //! \copydoc IContextApplication::unregisterApplication - virtual void unregisterApplication(const BlackMisc::CIdentifier &application) override; - - //! \copydoc IContextApplication::getRegisteredApplications - virtual BlackMisc::CIdentifierList getRegisteredApplications() const override; - - //! \copydoc IContextApplication::readFromFile - virtual QString readFromFile(const QString &fileName) const override; - - //! \copydoc IContextApplication::removeFile - virtual bool removeFile(const QString &fileName) override; - - //! \copydoc IContextApplication::existsFile - virtual bool existsFile(const QString &fileName) const override; - - public: - //! \todo Remove with old settings - using IContextApplication::changeSettings; - - protected: - //! Constructor - CContextApplication(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime); - - //! Register myself in DBus, fail safe - CContextApplication *registerWithDBus(BlackMisc::CDBusServer *server); - - private: - BlackMisc::CIdentifierList m_registeredApplications; - }; -} // namespace - -#endif // guard diff --git a/src/blackcore/contextapplicationproxy.cpp b/src/blackcore/contextapplicationproxy.cpp deleted file mode 100644 index f785a6884..000000000 --- a/src/blackcore/contextapplicationproxy.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "blackcore/contextapplicationproxy.h" -#include "blackmisc/dbus.h" -#include "blackmisc/genericdbusinterface.h" -#include "blackmisc/identifierlist.h" -#include "blackmisc/loghandler.h" -#include "blackmisc/settingscache.h" - -#include -#include -#include -#include - -using namespace BlackMisc; - -namespace BlackCore -{ - CContextApplicationProxy::CContextApplicationProxy(const QString &serviceName, QDBusConnection &connection, CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextApplication(mode, runtime), m_dBusInterface(nullptr) - { - this->m_dBusInterface = new CGenericDBusInterface(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(), connection, this); - this->relaySignals(serviceName, connection); - - connect(this, &IContextApplication::messageLogged, this, [](const CStatusMessage & message, const CIdentifier & origin) - { - if (!origin.isFromSameProcess()) - { - CLogHandler::instance()->logRemoteMessage(message); - } - }); - } - - void CContextApplicationProxy::relaySignals(const QString &serviceName, QDBusConnection &connection) - { - // signals originating from impl side - bool s = connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(), - "messageLogged", this, SIGNAL(messageLogged(BlackMisc::CStatusMessage, BlackMisc::CIdentifier))); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(), - "logSubscriptionAdded", this, SIGNAL(logSubscriptionAdded(BlackMisc::CIdentifier, BlackMisc::CLogPattern))); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(), - "logSubscriptionRemoved", this, SIGNAL(logSubscriptionRemoved(BlackMisc::CIdentifier, BlackMisc::CLogPattern))); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(), - "settingsChanged", this, SIGNAL(settingsChanged(BlackMisc::CValueCachePacket, BlackMisc::CIdentifier))); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(), - "registrationChanged", this, SIGNAL(registrationChanged())); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(), - "fakedSetComVoiceRoom", this, SIGNAL(fakedSetComVoiceRoom(BlackMisc::Audio::CVoiceRoomList))); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(), - "hotkeyActionsRegistered", this, SIGNAL(hotkeyActionsRegistered(QStringList, BlackMisc::CIdentifier))); - Q_UNUSED(s); - } - - void CContextApplicationProxy::logMessage(const CStatusMessage &message, const CIdentifier &origin) - { - if (subscribersOf(message).containsAnyNotIn(CIdentifierList({ origin, {} }))) - { - this->m_dBusInterface->callDBus(QLatin1Literal("logMessage"), message, origin); - } - } - - void CContextApplicationProxy::addLogSubscription(const CIdentifier &subscriber, const CLogPattern &pattern) - { - this->m_dBusInterface->callDBus(QLatin1Literal("addLogSubscription"), subscriber, pattern); - } - - void CContextApplicationProxy::removeLogSubscription(const CIdentifier &subscriber, const CLogPattern &pattern) - { - this->m_dBusInterface->callDBus(QLatin1Literal("removeLogSubscription"), subscriber, pattern); - } - - CLogSubscriptionHash CContextApplicationProxy::getAllLogSubscriptions() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getAllLogSubscriptions")); - } - - void CContextApplicationProxy::synchronizeLogSubscriptions() - { - // note this proxy method does not call synchronizeLogSubscriptions in core - m_logSubscriptions = getAllLogSubscriptions(); - for (const auto &pattern : CLogHandler::instance()->getAllSubscriptions()) { this->addLogSubscription({}, pattern); } - } - - void CContextApplicationProxy::changeSettings(const CValueCachePacket &settings, const CIdentifier &origin) - { - this->m_dBusInterface->callDBus(QLatin1Literal("changeSettings"), settings, origin); - } - - BlackMisc::CValueCachePacket CContextApplicationProxy::getAllSettings() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getAllSettings")); - } - - QStringList CContextApplicationProxy::getUnsavedSettingsKeys() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getUnsavedSettingsKeys")); - } - - void CContextApplicationProxy::synchronizeLocalSettings() - { - // note this proxy method does not call synchronizeLocalSettings in core - CSettingsCache::instance()->changeValuesFromRemote(this->getAllSettings(), CIdentifier::anonymous()); - } - - BlackMisc::CStatusMessage CContextApplicationProxy::saveSettings(const QString &keyPrefix) - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("saveSettings"), keyPrefix); - } - - BlackMisc::CStatusMessage CContextApplicationProxy::saveSettingsByKey(const QStringList &keys) - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("saveSettingsByKey"), keys); - } - - BlackMisc::CStatusMessage CContextApplicationProxy::loadSettings() - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("loadSettings")); - } - - void CContextApplicationProxy::registerHotkeyActions(const QStringList &actions, const CIdentifier &origin) - { - this->m_dBusInterface->callDBus(QLatin1Literal("registerHotkeyActions"), actions, origin); - } - - void CContextApplicationProxy::callHotkeyAction(const QString &action, bool argument, const CIdentifier &origin) - { - this->m_dBusInterface->callDBus(QLatin1Literal("callHotkeyAction"), action, argument, origin); - } - - BlackMisc::CIdentifier CContextApplicationProxy::registerApplication(const CIdentifier &application) - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("registerApplication"), application); - } - - void CContextApplicationProxy::unregisterApplication(const CIdentifier &application) - { - this->m_dBusInterface->callDBus(QLatin1Literal("unregisterApplication"), application); - } - - BlackMisc::CIdentifierList CContextApplicationProxy::getRegisteredApplications() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getRegisteredApplications")); - } - - bool CContextApplicationProxy::writeToFile(const QString &fileName, const QString &content) - { - if (fileName.isEmpty()) { return false; } - return this->m_dBusInterface->callDBusRet(QLatin1Literal("writeToFile"), fileName, content); - } - - QString CContextApplicationProxy::readFromFile(const QString &fileName) const - { - if (fileName.isEmpty()) { return ""; } - return this->m_dBusInterface->callDBusRet(QLatin1Literal("readFromFile"), fileName); - } - - bool CContextApplicationProxy::removeFile(const QString &fileName) - { - if (fileName.isEmpty()) { return false; } - return this->m_dBusInterface->callDBusRet(QLatin1Literal("removeFile"), fileName); - } - - bool CContextApplicationProxy::existsFile(const QString &fileName) const - { - if (fileName.isEmpty()) { return false; } - return this->m_dBusInterface->callDBusRet(QLatin1Literal("existsFile"), fileName); - } - -} // namespace diff --git a/src/blackcore/contextapplicationproxy.h b/src/blackcore/contextapplicationproxy.h deleted file mode 100644 index f66e84551..000000000 --- a/src/blackcore/contextapplicationproxy.h +++ /dev/null @@ -1,133 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKCORE_CONTEXTAPPLICATION_PROXY_H -#define BLACKCORE_CONTEXTAPPLICATION_PROXY_H - -#include -#include -#include - -#include "blackcore/blackcoreexport.h" -#include "blackcore/contextapplication.h" -#include "blackcore/corefacadeconfig.h" -#include "blackmisc/identifier.h" -#include "blackmisc/identifierlist.h" -#include "blackmisc/statusmessage.h" -#include "blackmisc/valuecache.h" - -class QDBusConnection; - -namespace BlackMisc -{ - class CGenericDBusInterface; - class CLogPattern; -} - -namespace BlackCore -{ - class CCoreFacade; - - //! \brief Application context proxy - //! \ingroup dbus - class BLACKCORE_EXPORT CContextApplicationProxy : public IContextApplication - { - Q_OBJECT - friend class IContextApplication; - - public: - //! Destructor - virtual ~CContextApplicationProxy() {} - - public slots: - //! \copydoc IContextApplication::logMessage - virtual void logMessage(const BlackMisc::CStatusMessage &message, const BlackMisc::CIdentifier &origin) override; - - //! \copydoc IContextApplication::addLogSubscription - virtual void addLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) override; - - //! \copydoc IContextApplication::removeLogSubscription - virtual void removeLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) override; - - //! \copydoc IContextApplication::getAllLogSubscriptions - virtual CLogSubscriptionHash getAllLogSubscriptions() const override; - - //! \copydoc IContextApplication::synchronizeLogSubscriptions - virtual void synchronizeLogSubscriptions() override; - - //! \copydoc IContextApplication::changeSettings - virtual void changeSettings(const BlackMisc::CValueCachePacket &settings, const BlackMisc::CIdentifier &origin) override; - - //! \copydoc IContextApplication::getAllSettings - virtual BlackMisc::CValueCachePacket getAllSettings() const override; - - //! \copydoc IContextApplication::getUnsavedSettingsKeys - virtual QStringList getUnsavedSettingsKeys() const override; - - //! \copydoc IContextApplication::synchronizeLocalSettings - virtual void synchronizeLocalSettings() override; - - //! \copydoc IContextApplication::saveSettings - virtual BlackMisc::CStatusMessage saveSettings(const QString &keyPrefix = {}) override; - - //! \copydoc IContextApplication::saveSettingsByKey - virtual BlackMisc::CStatusMessage saveSettingsByKey(const QStringList &keys) override; - - //! \copydoc IContextApplication::loadSettings - virtual BlackMisc::CStatusMessage loadSettings() override; - - //! \copydoc IContextApplication::registerHotkeyActions - virtual void registerHotkeyActions(const QStringList &actions, const BlackMisc::CIdentifier &origin) override; - - //! \copydoc IContextApplication::callHotkeyAction - virtual void callHotkeyAction(const QString &action, bool argument, const BlackMisc::CIdentifier &origin) override; - - //! \copydoc IContextApplication::registerApplication - virtual BlackMisc::CIdentifier registerApplication(const BlackMisc::CIdentifier &application) override; - - //! \copydoc IContextApplication::unregisterApplication - virtual void unregisterApplication(const BlackMisc::CIdentifier &application) override; - - //! \copydoc IContextApplication::getRegisteredApplications - virtual BlackMisc::CIdentifierList getRegisteredApplications() const override; - - //! \copydoc IContextApplication::writeToFile - virtual bool writeToFile(const QString &fileName, const QString &content) override; - - //! \copydoc IContextApplication::readFromFile - virtual QString readFromFile(const QString &fileName) const override; - - //! \copydoc IContextApplication::removeFile - virtual bool removeFile(const QString &fileName) override; - - //! \copydoc IContextApplication::existsFile - virtual bool existsFile(const QString &fileName) const override; - - public: - //! \todo Remove with old settings - using IContextApplication::changeSettings; - - protected: - //! Constructor - CContextApplicationProxy(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextApplication(mode, runtime), m_dBusInterface(nullptr) {} - - //! DBus version constructor - CContextApplicationProxy(const QString &serviceName, QDBusConnection &connection, CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime); - - private: - BlackMisc::CGenericDBusInterface *m_dBusInterface; - - //! Relay connection signals to local signals - void relaySignals(const QString &serviceName, QDBusConnection &connection); - }; -} - -#endif // guard diff --git a/src/blackcore/contextaudio.cpp b/src/blackcore/contextaudio.cpp deleted file mode 100644 index f7a1305b2..000000000 --- a/src/blackcore/contextaudio.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "contextaudio.h" - -#include "blackcore/contextaudio.h" -#include "blackcore/contextaudioempty.h" -#include "blackcore/contextaudioimpl.h" -#include "blackcore/contextaudioproxy.h" -#include "blackmisc/dbusserver.h" - -namespace BlackCore -{ - - IContextAudio *IContextAudio::create(CCoreFacade *runtime, CCoreFacadeConfig::ContextMode mode, BlackMisc::CDBusServer *server, QDBusConnection &conn) - { - switch (mode) - { - case CCoreFacadeConfig::Local: - case CCoreFacadeConfig::LocalInDbusServer: - return (new CContextAudio(mode, runtime))->registerWithDBus(server); - case CCoreFacadeConfig::Remote: - return new CContextAudioProxy(BlackMisc::CDBusServer::coreServiceName(), conn, mode, runtime); - default: - return new CContextAudioEmpty(runtime); // audio not mandatory - } - } -} // namespace diff --git a/src/blackcore/contextaudio.h b/src/blackcore/contextaudio.h deleted file mode 100644 index 2b99de97d..000000000 --- a/src/blackcore/contextaudio.h +++ /dev/null @@ -1,178 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKCORE_CONTEXTAUDIO_H -#define BLACKCORE_CONTEXTAUDIO_H - -#include "blackcore/blackcoreexport.h" -#include "blackcore/context.h" -#include "blackcore/corefacade.h" -#include "blackcore/corefacadeconfig.h" -#include "blackmisc/audio/audiodeviceinfolist.h" -#include "blackmisc/audio/notificationsounds.h" -#include "blackmisc/audio/voiceroom.h" -#include "blackmisc/audio/voiceroomlist.h" -#include "blackmisc/aviation/callsignset.h" -#include "blackmisc/aviation/comsystem.h" -#include "blackmisc/aviation/selcal.h" -#include "blackmisc/identifier.h" -#include "blackmisc/network/userlist.h" - -#include -#include - -class QDBusConnection; - -namespace BlackMisc -{ - class CDBusServer; - namespace Audio { class CAudioDeviceInfo; } - namespace Aviation { class CCallsign; } -} - -//! \addtogroup dbus -//! @{ - -//! DBus interface for context -#define BLACKCORE_CONTEXTAUDIO_INTERFACENAME "org.swift_project.blackcore.contextaudio" - -//! DBus object path for context -#define BLACKCORE_CONTEXTAUDIO_OBJECTPATH "/audio" - -//! @} - -namespace BlackCore -{ - - //! Audio context interface - class BLACKCORE_EXPORT IContextAudio : public CContext - { - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAUDIO_INTERFACENAME) - - protected: - //! Constructor - IContextAudio(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : CContext(mode, runtime) {} - - public: - //! Interface name - static const QString &InterfaceName() - { - static QString s(BLACKCORE_CONTEXTAUDIO_INTERFACENAME); - return s; - } - - //! Object path - static const QString &ObjectPath() - { - static QString s(BLACKCORE_CONTEXTAUDIO_OBJECTPATH); - return s; - } - - //! \copydoc CContext::getPathAndContextId() - virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); } - - //! Factory method - static IContextAudio *create(CCoreFacade *runtime, CCoreFacadeConfig::ContextMode mode, BlackMisc::CDBusServer *server, QDBusConnection &conn); - - //! Destructor - virtual ~IContextAudio() {} - - signals: - - //! Voice rooms changed - //! \details the flag indicates, whether a room got connected or disconnected - void changedVoiceRooms(const BlackMisc::Audio::CVoiceRoomList &voiceRooms, bool connected); - - //! Voice room members changed - void changedVoiceRoomMembers(); - - //! Audio volume changed - //! \sa setVoiceOutputVolume - void changedAudioVolume(int volume); - - //! Mute changed - void changedMute(bool muted); - - //! Changed audio devices (e.g. device enabled/disable) - void changedAudioDevices(const BlackMisc::Audio::CAudioDeviceInfoList &devices); - - //! Changed slection of audio devices - void changedSelectedAudioDevices(const BlackMisc::Audio::CAudioDeviceInfoList &devices); - - public slots: - //! Get voice rooms for COM1, COM2: - virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRoomsWithAudioStatus() const = 0; - - //! Get voice rooms for COM1, COM2, but without latest audio status - virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRooms() const = 0; - - //! Get voice room per com unit - virtual BlackMisc::Audio::CVoiceRoom getVoiceRoom(BlackMisc::Aviation::CComSystem::ComUnit comUnit, bool withAudioStatus) const = 0; - - //! Set voice rooms - virtual void setComVoiceRooms(const BlackMisc::Audio::CVoiceRoomList &voiceRooms) = 0; - - //! Own callsign as displayed in voice room - virtual void setOwnCallsignForRooms(const BlackMisc::Aviation::CCallsign &callsign) = 0; - - //! Leave all voice rooms - virtual void leaveAllVoiceRooms() = 0; - - //! Room user callsigns - virtual BlackMisc::Aviation::CCallsignSet getRoomCallsigns(BlackMisc::Aviation::CComSystem::ComUnit comUnit) const = 0; - - //! Room users - virtual BlackMisc::Network::CUserList getRoomUsers(BlackMisc::Aviation::CComSystem::ComUnit comUnit) const = 0; - - //! Audio devices - virtual BlackMisc::Audio::CAudioDeviceInfoList getAudioDevices() const = 0; - - //! Get current audio device - //! \return input and output devices - virtual BlackMisc::Audio::CAudioDeviceInfoList getCurrentAudioDevices() const = 0; - - //! Set current audio device - //! \param audioDevice can be input or audio device - virtual void setCurrentAudioDevice(const BlackMisc::Audio::CAudioDeviceInfo &audioDevice) = 0; - - //! Set voice output volume (0..300) - virtual void setVoiceOutputVolume(int volume) = 0; - - //! Voice output volume (0..300) - virtual int getVoiceOutputVolume() const = 0; - - //! Set mute state - virtual void setMute(bool mute) = 0; - - //! Is muted? - virtual bool isMuted() const = 0; - - //! Play SELCAL tone - virtual void playSelcalTone(const BlackMisc::Aviation::CSelcal &selcal) const = 0; - - //! Play notification sound - //! \param notification CSoundGenerator::Notification - //! \param considerSettings consider settings (notification on/off), false means settings ignored - virtual void playNotification(BlackMisc::Audio::CNotificationSounds::Notification notification, bool considerSettings) const = 0; - - //! Enable audio loopback - virtual void enableAudioLoopback(bool enable = true) = 0; - - //! Is loobback enabled? - virtual bool isAudioLoopbackEnabled() const = 0; - - //! Command line was entered - virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) = 0; - }; -} - -#endif // guard diff --git a/src/blackcore/contextaudioempty.h b/src/blackcore/contextaudioempty.h deleted file mode 100644 index 996091888..000000000 --- a/src/blackcore/contextaudioempty.h +++ /dev/null @@ -1,179 +0,0 @@ -/* Copyright (C) 2015 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKCORE_CONTEXTAUDIO_EMPTY_H -#define BLACKCORE_CONTEXTAUDIO_EMPTY_H - -#include "blackcoreexport.h" -#include "contextaudio.h" -#include "voice.h" - -namespace BlackCore -{ - class IVoiceChannel; - - //! Audio context implementation - class BLACKCORE_EXPORT CContextAudioEmpty : public IContextAudio - { - public: - //! Constructor - CContextAudioEmpty(CCoreFacade *runtime) : IContextAudio(CCoreFacadeConfig::NotUsed, runtime) {} - - public slots: - //! \copydoc IContextAudio::getComVoiceRooms() - virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRooms() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Audio::CVoiceRoomList(); - } - - //! \copydoc IContextAudio::getComVoiceRoomsWithAudioStatus() - virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRoomsWithAudioStatus() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Audio::CVoiceRoomList(); - } - - //! \copydoc IContextAudio::getVoiceRoom - virtual BlackMisc::Audio::CVoiceRoom getVoiceRoom(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue, bool withAudioStatus) const override - { - Q_UNUSED(comUnitValue); - Q_UNUSED(withAudioStatus); - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Audio::CVoiceRoom(); - } - - //! \copydoc IContextAudio::setComVoiceRooms - virtual void setComVoiceRooms(const BlackMisc::Audio::CVoiceRoomList &newRooms) override - { - Q_UNUSED(newRooms); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextAudio::setOwnCallsignForRooms - virtual void setOwnCallsignForRooms(const BlackMisc::Aviation::CCallsign &callsign) override - { - Q_UNUSED(callsign); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextAudio::getRoomCallsigns() - virtual BlackMisc::Aviation::CCallsignSet getRoomCallsigns(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue) const override - { - Q_UNUSED(comUnitValue); - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Aviation::CCallsignSet(); - } - - //! \copydoc IContextAudio::getRoomUsers() - virtual BlackMisc::Network::CUserList getRoomUsers(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue) const override - { - Q_UNUSED(comUnitValue); - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Network::CUserList(); - } - - //! \copydoc IContextAudio::leaveAllVoiceRooms - virtual void leaveAllVoiceRooms() override - { - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextAudio::getAudioDevices() - virtual BlackMisc::Audio::CAudioDeviceInfoList getAudioDevices() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Audio::CAudioDeviceInfoList(); - } - - //! \copydoc IContextAudio::getCurrentAudioDevices() - virtual BlackMisc::Audio::CAudioDeviceInfoList getCurrentAudioDevices() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Audio::CAudioDeviceInfoList(); - } - - //! \copydoc IContextAudio::setCurrentAudioDevice() - virtual void setCurrentAudioDevice(const BlackMisc::Audio::CAudioDeviceInfo &audioDevice) override - { - Q_UNUSED(audioDevice); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextAudio::setVoiceOutputVolume - virtual void setVoiceOutputVolume(int volume) override - { - Q_UNUSED(volume); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextAudio::getVoiceOutputVolume - virtual int getVoiceOutputVolume() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return 0; - } - - //! \copydoc IContextAudio::setMute - virtual void setMute(bool muted) override - { - Q_UNUSED(muted); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextAudio::isMuted() - virtual bool isMuted() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return false; - } - - //! \copydoc IContextAudio::playSelcalTone() - virtual void playSelcalTone(const BlackMisc::Aviation::CSelcal &selcal) const override - { - Q_UNUSED(selcal); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextAudio::playNotification() - virtual void playNotification(BlackMisc::Audio::CNotificationSounds::Notification notification, bool considerSettings) const override - { - Q_UNUSED(notification); - Q_UNUSED(considerSettings); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextAudio::enableAudioLoopback() - virtual void enableAudioLoopback(bool enable = true) override - { - Q_UNUSED(enable); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextAudio::isAudioLoopbackEnabled - virtual bool isAudioLoopbackEnabled() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return false; - } - - //! \copydoc IContextAudio::parseCommandLine - virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override - { - Q_UNUSED(commandLine); - Q_UNUSED(originator); - logEmptyContextWarning(Q_FUNC_INFO); - return false; - } - }; -} // namespace - -#endif // guard diff --git a/src/blackcore/contextaudioimpl.cpp b/src/blackcore/contextaudioimpl.cpp deleted file mode 100644 index 577111974..000000000 --- a/src/blackcore/contextaudioimpl.cpp +++ /dev/null @@ -1,558 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "blackcore/audiodevice.h" -#include "blackcore/audiomixer.h" -#include "blackcore/contextaudioimpl.h" -#include "blackcore/contextnetwork.h" -#include "blackcore/contextownaircraft.h" -#include "blackcore/corefacade.h" -#include "blackcore/voice.h" -#include "blackcore/voicevatlib.h" -#include "blackmisc/audio/audiodeviceinfo.h" -#include "blackmisc/audio/notificationsounds.h" -#include "blackmisc/audio/settings/settingsaudio.h" -#include "blackmisc/audio/voiceroomlist.h" -#include "blackmisc/aviation/callsign.h" -#include "blackmisc/compare.h" -#include "blackmisc/dbusserver.h" -#include "blackmisc/logcategory.h" -#include "blackmisc/logmessage.h" -#include "blackmisc/sequence.h" -#include "blackmisc/simplecommandparser.h" -#include "blackmisc/simulation/simulatedaircraft.h" -#include "blackmisc/statusmessage.h" -#include "blacksound/soundgenerator.h" - -#include -#include -#include -#include - -using namespace BlackMisc; -using namespace BlackMisc::Aviation; -using namespace BlackMisc::Audio; -using namespace BlackMisc::Input; -using namespace BlackMisc::Audio; -using namespace BlackSound; - -namespace BlackCore -{ - CContextAudio::CContextAudio(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : - IContextAudio(mode, runtime), - m_voice(new CVoiceVatlib()) - { - // own aircraft may or may not be available - const CCallsign ownCallsign = (this->getIContextOwnAircraft()) ? getIContextOwnAircraft()->getOwnAircraft().getCallsign() : CCallsign(); - - m_channel1 = m_voice->createVoiceChannel(); - m_channel1->setOwnAircraftCallsign(ownCallsign); - connect(m_channel1.data(), &IVoiceChannel::connectionStatusChanged, this, &CContextAudio::ps_connectionStatusChanged); - connect(m_channel1.data(), &IVoiceChannel::userJoinedRoom, this, &CContextAudio::ps_userJoinedRoom); - connect(m_channel1.data(), &IVoiceChannel::userLeftRoom, this, &CContextAudio::ps_userLeftRoom); - m_channel2 = m_voice->createVoiceChannel(); - m_channel2->setOwnAircraftCallsign(ownCallsign); - connect(m_channel2.data(), &IVoiceChannel::connectionStatusChanged, this, &CContextAudio::ps_connectionStatusChanged); - connect(m_channel2.data(), &IVoiceChannel::userJoinedRoom, this, &CContextAudio::ps_userJoinedRoom); - connect(m_channel2.data(), &IVoiceChannel::userLeftRoom, this, &CContextAudio::ps_userLeftRoom); - - m_voiceInputDevice = m_voice->createInputDevice(); - m_voiceOutputDevice = m_voice->createOutputDevice(); - - m_audioMixer = m_voice->createAudioMixer(); - - m_voice->connectVoice(m_voiceInputDevice.get(), m_audioMixer.get(), IAudioMixer::InputMicrophone); - m_voice->connectVoice(m_channel1.data(), m_audioMixer.get(), IAudioMixer::InputVoiceChannel1); - m_voice->connectVoice(m_channel2.data(), m_audioMixer.get(), IAudioMixer::InputVoiceChannel2); - m_voice->connectVoice(m_audioMixer.get(), IAudioMixer::OutputOutputDevice1, m_voiceOutputDevice.get()); - m_voice->connectVoice(m_audioMixer.get(), IAudioMixer::OutputVoiceChannel1, m_channel1.data()); - m_voice->connectVoice(m_audioMixer.get(), IAudioMixer::OutputVoiceChannel2, m_channel2.data()); - - m_audioMixer->makeMixerConnection(IAudioMixer::InputVoiceChannel1, IAudioMixer::OutputOutputDevice1); - m_audioMixer->makeMixerConnection(IAudioMixer::InputVoiceChannel2, IAudioMixer::OutputOutputDevice1); - this->setVoiceOutputVolume(90); - - // Load sounds (init), not possible in own thread - QTimer::singleShot(10 * 1000, this, &CContextAudio::ps_initNotificationSounds); - - m_unusedVoiceChannels.push_back(m_channel1); - m_unusedVoiceChannels.push_back(m_channel2); - } - - CContextAudio *CContextAudio::registerWithDBus(CDBusServer *server) - { - if (!server || this->m_mode != CCoreFacadeConfig::LocalInDbusServer) { return this; } - server->addObject(IContextAudio::ObjectPath(), this); - return this; - } - - CContextAudio::~CContextAudio() - { - this->leaveAllVoiceRooms(); - } - - CVoiceRoomList CContextAudio::getComVoiceRoomsWithAudioStatus() const - { - Q_ASSERT(this->m_voice); - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - return getComVoiceRooms(); - } - - CVoiceRoom CContextAudio::getVoiceRoom(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue, bool withAudioStatus) const - { - Q_ASSERT(this->m_voice); - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << withAudioStatus; } - - auto voiceChannel = m_voiceChannelMapping.value(comUnitValue); - if (voiceChannel) - { - return voiceChannel->getVoiceRoom(); - } - else - { - return CVoiceRoom(); - } - } - - CVoiceRoomList CContextAudio::getComVoiceRooms() const - { - Q_ASSERT(this->m_voice); - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - CVoiceRoomList voiceRoomList; - - auto voiceChannelCom1 = m_voiceChannelMapping.value(BlackMisc::Aviation::CComSystem::Com1); - if (voiceChannelCom1) - { - CVoiceRoom room = voiceChannelCom1->getVoiceRoom(); - voiceRoomList.push_back(room); - } - else - { - voiceRoomList.push_back(CVoiceRoom()); - } - - auto voiceChannelCom2 = m_voiceChannelMapping.value(BlackMisc::Aviation::CComSystem::Com2); - if (voiceChannelCom2) - { - CVoiceRoom room = voiceChannelCom2->getVoiceRoom(); - voiceRoomList.push_back(room); - } - else - { - voiceRoomList.push_back(CVoiceRoom()); - } - - return voiceRoomList; - } - - void CContextAudio::leaveAllVoiceRooms() - { - Q_ASSERT(this->m_voice); - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO;} - m_voiceChannelMapping.clear(); - m_channel1->leaveVoiceRoom(); - m_channel2->leaveVoiceRoom(); - m_unusedVoiceChannels.push_back(m_channel1); - m_unusedVoiceChannels.push_back(m_channel2); - } - - CAudioDeviceInfoList CContextAudio::getAudioDevices() const - { - Q_ASSERT(this->m_voice); - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - CAudioDeviceInfoList devices = this->m_voiceOutputDevice->getOutputDevices(); - devices = devices.join(this->m_voiceInputDevice->getInputDevices()); - return devices; - } - - CAudioDeviceInfoList CContextAudio::getCurrentAudioDevices() const - { - Q_ASSERT(this->m_voice); - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - CAudioDeviceInfoList devices; - devices.push_back(this->m_voiceInputDevice->getCurrentInputDevice()); - devices.push_back(this->m_voiceOutputDevice->getCurrentOutputDevice()); - return devices; - } - - void CContextAudio::setCurrentAudioDevice(const CAudioDeviceInfo &audioDevice) - { - Q_ASSERT(this->m_voice); - Q_ASSERT(audioDevice.getType() != CAudioDeviceInfo::Unknown); - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << audioDevice; } - bool changed = false; - if (audioDevice.getType() == CAudioDeviceInfo::InputDevice) - { - if (this->m_voiceInputDevice->getCurrentInputDevice() != audioDevice) - { - this->m_voiceInputDevice->setInputDevice(audioDevice); - changed = true; - } - } - else - { - if (this->m_voiceOutputDevice->getCurrentOutputDevice() != audioDevice) - { - this->m_voiceOutputDevice->setOutputDevice(audioDevice); - changed = true; - } - } - - if (changed) - { - emit changedSelectedAudioDevices(this->getCurrentAudioDevices()); - } - } - - void CContextAudio::setVoiceOutputVolume(int volume) - { - Q_ASSERT(m_voiceOutputDevice); - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << volume; } - - bool wasMuted = isMuted(); - bool changed = m_voiceOutputDevice->getOutputVolume() != volume; - if (!changed) { return; } - m_voiceOutputDevice->setOutputVolume(volume); - m_outVolumeBeforeMute = m_voiceOutputDevice->getOutputVolume(); - - emit changedAudioVolume(volume); - if ((volume > 0 && wasMuted) || (volume < 1 && !wasMuted)) - { - // inform about muted - emit changedMute(volume < 1); - } - } - - int CContextAudio::getVoiceOutputVolume() const - { - Q_ASSERT(m_voiceOutputDevice); - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - return m_voiceOutputDevice->getOutputVolume(); - } - - void CContextAudio::setMute(bool muted) - { - if (this->isMuted() == muted) { return; } // avoid roundtrips / unnecessary signals - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << muted; } - - int newVolume; - if (muted) - { - Q_ASSERT(this->m_voiceOutputDevice); - m_outVolumeBeforeMute = this->m_voiceOutputDevice->getOutputVolume(); - newVolume = 0; - } - else - { - newVolume = m_outVolumeBeforeMute < MinUnmuteVolume ? MinUnmuteVolume : m_outVolumeBeforeMute; - m_outVolumeBeforeMute = newVolume; - } - - // do not call setVoiceOutputVolume -> infinite loop - if (newVolume != m_voiceOutputDevice->getOutputVolume()) - { - m_voiceOutputDevice->setOutputVolume(newVolume); - emit changedAudioVolume(newVolume); - } - - // signal - emit changedMute(muted); - } - - bool CContextAudio::isMuted() const - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - return m_voiceOutputDevice->getOutputVolume() < 1; - } - - void CContextAudio::setComVoiceRooms(const CVoiceRoomList &newRooms) - { - Q_ASSERT(this->m_voice); - Q_ASSERT(newRooms.size() == 2); - Q_ASSERT(getIContextOwnAircraft()); - if (m_debugEnabled) {CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << newRooms; } - - CVoiceRoomList currentRooms = getComVoiceRooms(); - CVoiceRoom currentRoomCom1 = currentRooms[0]; - CVoiceRoom currentRoomCom2 = currentRooms[1]; - CVoiceRoom newRoomCom1 = newRooms[0]; - CVoiceRoom newRoomCom2 = newRooms[1]; - const CCallsign ownCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign()); - - bool changed = false; - - // changed rooms? But only compare on "URL", not status as connected etc. - if (currentRoomCom1.getVoiceRoomUrl() != newRoomCom1.getVoiceRoomUrl()) - { - auto oldVoiceChannel = m_voiceChannelMapping.value(BlackMisc::Aviation::CComSystem::Com1); - if (oldVoiceChannel) - { - m_voiceChannelMapping.remove(BlackMisc::Aviation::CComSystem::Com1); - - // If the voice channel is not used by anybody else - if (!m_voiceChannelMapping.values().contains(oldVoiceChannel)) - { - oldVoiceChannel->leaveVoiceRoom(); - m_unusedVoiceChannels.push_back(oldVoiceChannel); - } - else - { - emit this->changedVoiceRooms(getComVoiceRooms(), false); - } - } - - if (newRoomCom1.isValid()) - { - auto newVoiceChannel = getVoiceChannelBy(newRoomCom1); - newVoiceChannel->setOwnAircraftCallsign(ownCallsign); - bool inUse = m_voiceChannelMapping.values().contains(newVoiceChannel); - m_voiceChannelMapping.insert(BlackMisc::Aviation::CComSystem::Com1, newVoiceChannel); - - // If the voice channel is not used by anybody else - if (!inUse) - { - newVoiceChannel->joinVoiceRoom(newRoomCom1); - } - else - { - emit this->changedVoiceRooms(getComVoiceRooms(), true); - } - } - changed = true; - } - - // changed rooms? But only compare on "URL", not status as connected etc. - if (currentRoomCom2.getVoiceRoomUrl() != newRoomCom2.getVoiceRoomUrl()) - { - auto oldVoiceChannel = m_voiceChannelMapping.value(BlackMisc::Aviation::CComSystem::Com2); - if (oldVoiceChannel) - { - m_voiceChannelMapping.remove(BlackMisc::Aviation::CComSystem::Com2); - - // If the voice channel is not used by anybody else - if (!m_voiceChannelMapping.values().contains(oldVoiceChannel)) - { - oldVoiceChannel->leaveVoiceRoom(); - m_unusedVoiceChannels.push_back(oldVoiceChannel); - } - else - { - emit this->changedVoiceRooms(getComVoiceRooms(), false); - } - } - - if (newRoomCom2.isValid()) - { - auto newVoiceChannel = getVoiceChannelBy(newRoomCom2); - newVoiceChannel->setOwnAircraftCallsign(ownCallsign); - bool inUse = m_voiceChannelMapping.values().contains(newVoiceChannel); - m_voiceChannelMapping.insert(BlackMisc::Aviation::CComSystem::Com2, newVoiceChannel); - - // If the voice channel is not used by anybody else - if (!inUse) - { - newVoiceChannel->joinVoiceRoom(newRoomCom2); - } - else - { - emit this->changedVoiceRooms(getComVoiceRooms(), true); - } - } - changed = true; - } - - // changed not yet used, but I keep it for debugging - // changedVoiceRooms called by connectionStatusChanged; - Q_UNUSED(changed); - } - - void CContextAudio::setOwnCallsignForRooms(const CCallsign &callsign) - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << callsign; } - - if (m_channel1) { m_channel1->setOwnAircraftCallsign(callsign); } - if (m_channel2) { m_channel2->setOwnAircraftCallsign(callsign); } - } - - CCallsignSet CContextAudio::getRoomCallsigns(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue) const - { - Q_ASSERT(this->m_voice); - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - - auto voiceChannel = m_voiceChannelMapping.value(comUnitValue); - if (voiceChannel) - { - return voiceChannel->getVoiceRoomCallsigns(); - } - else - { - return CCallsignSet(); - } - } - - Network::CUserList CContextAudio::getRoomUsers(BlackMisc::Aviation::CComSystem::ComUnit comUnit) const - { - Q_ASSERT(this->m_voice); - Q_ASSERT(this->getRuntime()); - if (!this->getRuntime()->getIContextNetwork()) return Network::CUserList(); - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - - return this->getIContextNetwork()->getUsersForCallsigns(this->getRoomCallsigns(comUnit)); - } - - void CContextAudio::playSelcalTone(const CSelcal &selcal) const - { - Q_ASSERT(this->m_voice); - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << selcal; } - CAudioDeviceInfo outputDevice = m_voiceOutputDevice->getCurrentOutputDevice(); - CSoundGenerator::playSelcal(90, selcal, outputDevice); - } - - void CContextAudio::playNotification(CNotificationSounds::Notification notification, bool considerSettings) const - { - Q_ASSERT(this->m_voice); - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << notification; } - - bool play = !considerSettings || m_audioSettings.getThreadLocal().getNotificationFlag(notification); - if (play) - { - CSoundGenerator::playNotificationSound(90, notification); - } - } - - void CContextAudio::ps_initNotificationSounds() - { - // not possible in own thread - CSoundGenerator::playNotificationSound(0, CNotificationSounds::NotificationsLoadSounds); - } - - void CContextAudio::enableAudioLoopback(bool enable) - { - Q_ASSERT(this->m_audioMixer); - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - if (enable) - { - m_audioMixer->makeMixerConnection(IAudioMixer::InputMicrophone, IAudioMixer::OutputOutputDevice1); - } - else - { - m_audioMixer->removeMixerConnection(IAudioMixer::InputMicrophone, IAudioMixer::OutputOutputDevice1); - } - } - - bool CContextAudio::isAudioLoopbackEnabled() const - { - Q_ASSERT(this->m_audioMixer); - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - return this->m_audioMixer->hasMixerConnection(IAudioMixer::InputMicrophone, IAudioMixer::OutputOutputDevice1); - } - - bool CContextAudio::parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) - { - Q_UNUSED(originator); - if (commandLine.isEmpty()) { return false; } - CSimpleCommandParser parser( - { - ".vol", ".volume", // output volume - ".mute", // mute - ".unmute" // unmute - }); - parser.parse(commandLine); - if (!parser.isKnownCommand()) { return false; } - - if (parser.matchesCommand(".mute")) - { - this->setMute(true); - return true; - } - else if (parser.matchesCommand(".unmute")) - { - this->setMute(false); - return true; - } - else if (parser.commandStartsWith("vol") && parser.countParts() > 1) - { - int v = parser.toInt(1); - if (v >= 0 && v <= 300) - { - setVoiceOutputVolume(v); - return true; - } - } - return false; - } - - void CContextAudio::ps_setVoiceTransmission(bool enable) - { - // FIXME: Use the 'active' channel instead of hardcoded COM1 - if (enable) m_audioMixer->makeMixerConnection(IAudioMixer::InputMicrophone, IAudioMixer::OutputVoiceChannel1); - else m_audioMixer->removeMixerConnection(IAudioMixer::InputMicrophone, IAudioMixer::OutputVoiceChannel1); - } - - void CContextAudio::ps_connectionStatusChanged(BlackCore::IVoiceChannel::ConnectionStatus oldStatus, - BlackCore::IVoiceChannel::ConnectionStatus newStatus) - { - Q_UNUSED(oldStatus); - - switch (newStatus) - { - case IVoiceChannel::Connected: - emit this->changedVoiceRooms(getComVoiceRooms(), true); - break; - case IVoiceChannel::Disconnecting: - break; - case IVoiceChannel::Connecting: - break; - case IVoiceChannel::ConnectingFailed: - case IVoiceChannel::DisconnectedError: - CLogMessage(this).warning("Voice channel disconnecting error"); - // intentional fall-through - case IVoiceChannel::Disconnected: - if (this->getIContextOwnAircraft()) - { - // good chance to update aircraft - m_channel1->setOwnAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign()); - m_channel2->setOwnAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign()); - } - emit this->changedVoiceRooms(getComVoiceRooms(), false); - break; - default: - break; - } - } - - void CContextAudio::ps_userJoinedRoom(const CCallsign & /**callsign**/) - { - emit this->changedVoiceRoomMembers(); - } - - void CContextAudio::ps_userLeftRoom(const CCallsign & /**callsign**/) - { - emit this->changedVoiceRoomMembers(); - } - - QSharedPointer CContextAudio::getVoiceChannelBy(const CVoiceRoom &voiceRoom) - { - QSharedPointer voiceChannel; - for (const auto &channel : m_voiceChannelMapping.values()) - { - if (channel->getVoiceRoom().getVoiceRoomUrl() == voiceRoom.getVoiceRoomUrl()) voiceChannel = channel; - } - - // If we haven't found a valid voice channel pointer, get an unused one - if (!voiceChannel) - { - Q_ASSERT(!m_unusedVoiceChannels.isEmpty()); - voiceChannel = m_unusedVoiceChannels.takeFirst(); - } - - return voiceChannel; - } - -} // namespace diff --git a/src/blackcore/contextaudioimpl.h b/src/blackcore/contextaudioimpl.h deleted file mode 100644 index 307946f5a..000000000 --- a/src/blackcore/contextaudioimpl.h +++ /dev/null @@ -1,196 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKCORE_CONTEXTAUDIO_IMPL_H -#define BLACKCORE_CONTEXTAUDIO_IMPL_H - -#include "blackcore/actionbind.h" -#include "blackcore/blackcoreexport.h" -#include "blackcore/contextaudio.h" -#include "blackcore/corefacadeconfig.h" -#include "blackcore/settings/audio.h" -#include "blackcore/voicechannel.h" -#include "blackmisc/audio/audiodeviceinfolist.h" -#include "blackmisc/audio/notificationsounds.h" -#include "blackmisc/audio/voiceroom.h" -#include "blackmisc/audio/voiceroomlist.h" -#include "blackmisc/aviation/callsignset.h" -#include "blackmisc/aviation/comsystem.h" -#include "blackmisc/aviation/selcal.h" -#include "blackmisc/identifier.h" -#include "blackmisc/network/userlist.h" -#include "blackmisc/settingscache.h" - -#include -#include -#include -#include -#include -#include - -namespace BlackMisc -{ - class CDBusServer; - - namespace Audio - { - class CAudioDeviceInfo; - } - - namespace Aviation - { - class CCallsign; - } -} - -namespace BlackCore -{ - class CCoreFacade; - class IAudioInputDevice; - class IAudioMixer; - class IAudioOutputDevice; - class IVoice; - class IVoiceChannel; - - //! Audio context implementation - class BLACKCORE_EXPORT CContextAudio : public IContextAudio - { - Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAUDIO_INTERFACENAME) - Q_OBJECT - - friend class CCoreFacade; - friend class IContextAudio; - - public: - //! Destructor - virtual ~CContextAudio(); - - public slots: - //! \copydoc IContextAudio::getComVoiceRooms() - virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRooms() const override; - - //! \copydoc IContextAudio::getComVoiceRoomsWithAudioStatus() - virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRoomsWithAudioStatus() const override; - - //! \copydoc IContextAudio::getVoiceRoom - virtual BlackMisc::Audio::CVoiceRoom getVoiceRoom(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue, bool withAudioStatus) const override; - - //! \copydoc IContextAudio::setComVoiceRooms - virtual void setComVoiceRooms(const BlackMisc::Audio::CVoiceRoomList &newRooms) override; - - //! \copydoc IContextAudio::setOwnCallsignForRooms - virtual void setOwnCallsignForRooms(const BlackMisc::Aviation::CCallsign &callsign) override; - - //! \copydoc IContextAudio::getRoomCallsigns() - virtual BlackMisc::Aviation::CCallsignSet getRoomCallsigns(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue) const override; - - //! \copydoc IContextAudio::getRoomUsers() - virtual BlackMisc::Network::CUserList getRoomUsers(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue) const override; - - //! \copydoc IContextAudio::leaveAllVoiceRooms - virtual void leaveAllVoiceRooms() override; - - //! \copydoc IContextAudio::getAudioDevices() - virtual BlackMisc::Audio::CAudioDeviceInfoList getAudioDevices() const override; - - //! \copydoc IContextAudio::getCurrentAudioDevices() - virtual BlackMisc::Audio::CAudioDeviceInfoList getCurrentAudioDevices() const override; - - //! \copydoc IContextAudio::setCurrentAudioDevice() - virtual void setCurrentAudioDevice(const BlackMisc::Audio::CAudioDeviceInfo &audioDevice) override; - - //! \copydoc IContextAudio::setVoiceOutputVolume - virtual void setVoiceOutputVolume(int volume) override; - - //! \copydoc IContextAudio::getVoiceOutputVolume - virtual int getVoiceOutputVolume() const override; - - //! \copydoc IContextAudio::setMute - virtual void setMute(bool muted) override; - - //! \copydoc IContextAudio::isMuted() - virtual bool isMuted() const override; - - //! \copydoc IContextAudio::playSelcalTone - virtual void playSelcalTone(const BlackMisc::Aviation::CSelcal &selcal) const override; - - //! \copydoc IContextAudio::playNotification - virtual void playNotification(BlackMisc::Audio::CNotificationSounds::Notification notification, bool considerSettings) const override; - - //! \copydoc IContextAudio::enableAudioLoopback - virtual void enableAudioLoopback(bool enable = true) override; - - //! \copydoc IContextAudio::isAudioLoopbackEnabled - virtual bool isAudioLoopbackEnabled() const override; - - //! \addtogroup commandline - //! @{ - //!
-        //! .mute                          mute             CContextAudio
-        //! .unmute                        unmute           CContextAudio
-        //! .vol .volume   volume 0..300   set volume       CContextAudio
-        //! 
- //! @} - //! \copydoc IContextAudio::parseCommandLine - virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override; - - protected: - //! Constructor - CContextAudio(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime); - - //! Register myself in DBus - CContextAudio *registerWithDBus(BlackMisc::CDBusServer *server); - - private slots: - - //! \copydoc IVoice::connectionStatusChanged - //! \sa IContextAudio::changedVoiceRooms - void ps_connectionStatusChanged(IVoiceChannel::ConnectionStatus oldStatus, IVoiceChannel::ConnectionStatus newStatus); - - //! Init notification sounds - void ps_initNotificationSounds(); - - void ps_setVoiceTransmission(bool enable); - - //! User joined the room - void ps_userJoinedRoom(const BlackMisc::Aviation::CCallsign &callsign); - - //! User left the room - void ps_userLeftRoom(const BlackMisc::Aviation::CCallsign &callsign); - - private: - //! Connection in transition - bool inTransitionState() const; - - //! Voice channel by room - QSharedPointer getVoiceChannelBy(const BlackMisc::Audio::CVoiceRoom &voiceRoom); - - const int MinUnmuteVolume = 20; //!< minimum volume when unmuted - CActionBind m_actionPtt { "/Voice/Activate push-to-talk", this, &CContextAudio::ps_setVoiceTransmission }; - std::unique_ptr m_voice; //!< underlying voice lib - std::unique_ptr m_audioMixer; - int m_outVolumeBeforeMute = 90; - - // For easy access. - QSharedPointer m_channel1; - QSharedPointer m_channel2; - std::unique_ptr m_voiceOutputDevice; - std::unique_ptr m_voiceInputDevice; - - QList> m_unusedVoiceChannels; - QHash> m_voiceChannelMapping; - - // settings - BlackMisc::CSetting m_audioSettings { this }; - }; -} // namespace - -#endif // guard diff --git a/src/blackcore/contextaudioproxy.cpp b/src/blackcore/contextaudioproxy.cpp deleted file mode 100644 index 19f6e414b..000000000 --- a/src/blackcore/contextaudioproxy.cpp +++ /dev/null @@ -1,212 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "blackcore/contextaudioproxy.h" -#include "blackmisc/dbus.h" -#include "blackmisc/genericdbusinterface.h" - -#include -#include -#include - -using namespace BlackMisc::Audio; -using namespace BlackMisc::Network; -using namespace BlackMisc::Aviation; - -namespace BlackCore -{ - - /* - * Constructor for DBus - */ - CContextAudioProxy::CContextAudioProxy(const QString &serviceName, QDBusConnection &connection, CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextAudio(mode, runtime), m_dBusInterface(nullptr) - { - this->m_dBusInterface = new BlackMisc::CGenericDBusInterface( - serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(), connection, this); - this->relaySignals(serviceName, connection); - } - - /* - * Relaying signals - */ - void CContextAudioProxy::relaySignals(const QString &serviceName, QDBusConnection &connection) - { - bool s = connection.connect(serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(), - "changedVoiceRooms", this, SIGNAL(changedVoiceRooms(BlackMisc::Audio::CVoiceRoomList, bool))); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(), - "changedAudioVolume", this, SIGNAL(changedAudioVolume(int))); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(), - "changedAudioDevices", this, SIGNAL(changedAudioDevices(BlackMisc::Audio::CAudioDeviceInfoList))); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(), - "changedSelectedAudioDevices", this, SIGNAL(changedSelectedAudioDevices(BlackMisc::Audio::CAudioDeviceInfoList))); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(), - "changedMute", this, SIGNAL(changedMute(bool))); - Q_ASSERT(s); - Q_UNUSED(s); - } - - /* - * Leave all voice rooms - */ - void CContextAudioProxy::leaveAllVoiceRooms() - { - this->m_dBusInterface->callDBus(QLatin1Literal("leaveAllVoiceRooms")); - } - - /* - * COM1 callsigns - */ - BlackMisc::Aviation::CCallsignSet CContextAudioProxy::getRoomCallsigns(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue) const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getRoomCallsigns"), comUnitValue); - } - - /* - * COM1 users - */ - BlackMisc::Network::CUserList CContextAudioProxy::getRoomUsers(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue) const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getRoomUsers"), comUnitValue); - } - - /* - * Audio devices - */ - CAudioDeviceInfoList CContextAudioProxy::getAudioDevices() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getAudioDevices")); - } - - /* - * Get current audio devices - */ - CAudioDeviceInfoList CContextAudioProxy::getCurrentAudioDevices() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getCurrentAudioDevices")); - } - - /* - * Set current audio device - */ - void CContextAudioProxy::setCurrentAudioDevice(const CAudioDeviceInfo &audioDevice) - { - this->m_dBusInterface->callDBus(QLatin1Literal("setCurrentAudioDevice"), audioDevice); - } - - /* - * Voice rooms, with audio status - */ - CVoiceRoomList CContextAudioProxy::getComVoiceRoomsWithAudioStatus() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getComVoiceRoomsWithAudioStatus")); - } - - /* - * Voice rooms, without audio status - */ - CVoiceRoomList CContextAudioProxy::getComVoiceRooms() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getComVoiceRooms")); - } - - /* - * Voice room - */ - CVoiceRoom CContextAudioProxy::getVoiceRoom(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue, bool withAudioStatus) const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getVoiceRoom"), comUnitValue, withAudioStatus); - } - - /* - * Set voice rooms - */ - void CContextAudioProxy::setComVoiceRooms(const BlackMisc::Audio::CVoiceRoomList &voiceRooms) - { - this->m_dBusInterface->callDBus(QLatin1Literal("setComVoiceRooms"), voiceRooms); - } - - /* - * Own voice room callsign - */ - void CContextAudioProxy::setOwnCallsignForRooms(const CCallsign &callsign) - { - this->m_dBusInterface->callDBus(QLatin1Literal("setOwnCallsignForRooms"), callsign); - } - - /* - * Play SELCAL tone - */ - void CContextAudioProxy::playSelcalTone(const CSelcal &selcal) const - { - this->m_dBusInterface->callDBus(QLatin1Literal("playSelcalTone"), selcal); - } - - /* - * Notification sound - */ - void CContextAudioProxy::playNotification(CNotificationSounds::Notification notification, bool considerSettings) const - { - this->m_dBusInterface->callDBus(QLatin1Literal("playNotification"), notification, considerSettings); - } - - void CContextAudioProxy::setVoiceOutputVolume(int volume) - { - this->m_dBusInterface->callDBus(QLatin1Literal("setVoiceOutputVolume"), volume); - } - - int CContextAudioProxy::getVoiceOutputVolume() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getVoiceOutputVolume")); - } - - /* - * Toggle mute - */ - void CContextAudioProxy::setMute(bool muted) - { - return this->m_dBusInterface->callDBus(QLatin1Literal("setMute"), muted); - } - - /* - * Muted? - */ - bool CContextAudioProxy::isMuted() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("isMuted")); - } - - /* - * Loopback - */ - void CContextAudioProxy::enableAudioLoopback(bool enable) - { - this->m_dBusInterface->callDBus(QLatin1Literal("enableAudioLoopback"), enable); - } - - /* - * Loopback - */ - bool CContextAudioProxy::isAudioLoopbackEnabled() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("isAudioLoopbackEnabled")); - } - - /* - * Parse command line - */ - bool CContextAudioProxy::parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("parseCommandLine"), commandLine, originator); - } - -} // namespace diff --git a/src/blackcore/contextaudioproxy.h b/src/blackcore/contextaudioproxy.h deleted file mode 100644 index 6da6b2d56..000000000 --- a/src/blackcore/contextaudioproxy.h +++ /dev/null @@ -1,135 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKCORE_CONTEXTVOICE_PROXY_H -#define BLACKCORE_CONTEXTVOICE_PROXY_H - -#include -#include - -#include "blackcore/blackcoreexport.h" -#include "blackcore/contextaudio.h" -#include "blackcore/corefacadeconfig.h" -#include "blackmisc/audio/audiodeviceinfolist.h" -#include "blackmisc/audio/notificationsounds.h" -#include "blackmisc/audio/voiceroom.h" -#include "blackmisc/audio/voiceroomlist.h" -#include "blackmisc/aviation/callsignset.h" -#include "blackmisc/aviation/comsystem.h" -#include "blackmisc/aviation/selcal.h" -#include "blackmisc/identifier.h" -#include "blackmisc/network/userlist.h" - -class QDBusConnection; - -namespace BlackMisc -{ - class CGenericDBusInterface; - namespace Audio { class CAudioDeviceInfo; } - namespace Aviation { class CCallsign; } -} - -namespace BlackCore -{ - class CCoreFacade; - - //! \brief Audio context proxy - //! \ingroup dbus - class BLACKCORE_EXPORT CContextAudioProxy : public IContextAudio - { - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAUDIO_INTERFACENAME) - friend class IContextAudio; - - public: - - //! Destructor - virtual ~CContextAudioProxy() {} - - 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); - - protected: - //! Contructor - CContextAudioProxy(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextAudio(mode, runtime), m_dBusInterface(nullptr) {} - - //! DBus version constructor - CContextAudioProxy(const QString &serviceName, QDBusConnection &connection, CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime); - - public slots: - //! \copydoc IContextAudio::getComVoiceRooms() - virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRooms() const override; - - //! \copydoc IContextAudio::getComVoiceRoomsWithAudioStatus() - virtual BlackMisc::Audio::CVoiceRoomList getComVoiceRoomsWithAudioStatus() const override; - - //! \copydoc IContextAudio::getVoiceRoom - virtual BlackMisc::Audio::CVoiceRoom getVoiceRoom(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue, bool withAudioStatus) const override; - - //! \copydoc IContextAudio::setComVoiceRooms() - virtual void setComVoiceRooms(const BlackMisc::Audio::CVoiceRoomList &voiceRooms) override; - - //! \copydoc IContextAudio::setOwnCallsignForRooms - virtual void setOwnCallsignForRooms(const BlackMisc::Aviation::CCallsign &callsign) override; - - //! \copydoc IContextAudio::getRoomCallsigns() - virtual BlackMisc::Aviation::CCallsignSet getRoomCallsigns(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue) const override; - - //! \copydoc IContextAudio::getRoomUsers() - virtual BlackMisc::Network::CUserList getRoomUsers(BlackMisc::Aviation::CComSystem::ComUnit comUnitValue) const override; - - //! \copydoc IContextAudio::leaveAllVoiceRooms - virtual void leaveAllVoiceRooms() override; - - //! \copydoc IContextAudio::getAudioDevices() - virtual BlackMisc::Audio::CAudioDeviceInfoList getAudioDevices() const override; - - //! \copydoc IContextAudio::getCurrentAudioDevices() - virtual BlackMisc::Audio::CAudioDeviceInfoList getCurrentAudioDevices() const override; - - //! \copydoc IContextAudio::setCurrentAudioDevice() - virtual void setCurrentAudioDevice(const BlackMisc::Audio::CAudioDeviceInfo &audioDevice) override; - - //!\copydoc IContextAudio::setVoiceOutputVolume - virtual void setVoiceOutputVolume(int volume) override; - - //! \copydoc IContextAudio::getVoiceOutputVolume - virtual int getVoiceOutputVolume() const override; - - //! \copydoc IContextAudio::setMute - virtual void setMute(bool muted) override; - - //! \copydoc IContextAudio::isMuted() - virtual bool isMuted() const override; - - //! \copydoc IContextAudio::playSelcalTone - virtual void playSelcalTone(const BlackMisc::Aviation::CSelcal &selcal) const override; - - //! \copydoc IContextAudio::playNotification - virtual void playNotification(BlackMisc::Audio::CNotificationSounds::Notification notification, bool considerSettings) const override; - - //! \copydoc IContextAudio::enableAudioLoopback() - virtual void enableAudioLoopback(bool enable = true) override; - - //! \copydoc IContextAudio::isAudioLoopbackEnabled() - virtual bool isAudioLoopbackEnabled() const override; - - //! \copydoc IContextOwnAircraft::parseCommandLine - virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override; - - }; -} - -#endif // guard diff --git a/src/blackcore/contextnetwork.cpp b/src/blackcore/contextnetwork.cpp deleted file mode 100644 index 990c19f6e..000000000 --- a/src/blackcore/contextnetwork.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "blackcore/contextnetwork.h" -#include "blackcore/contextnetworkempty.h" -#include "blackcore/contextnetworkimpl.h" -#include "blackcore/contextnetworkproxy.h" -#include "blackmisc/dbusserver.h" - -namespace BlackCore -{ - - IContextNetwork *IContextNetwork::create(CCoreFacade *runtime, CCoreFacadeConfig::ContextMode mode, BlackMisc::CDBusServer *server, QDBusConnection &connection) - { - switch (mode) - { - case CCoreFacadeConfig::Local: - case CCoreFacadeConfig::LocalInDbusServer: - return (new CContextNetwork(mode, runtime))->registerWithDBus(server); - case CCoreFacadeConfig::Remote: - return new CContextNetworkProxy(BlackMisc::CDBusServer::coreServiceName(), connection, mode, runtime); - case CCoreFacadeConfig::NotUsed: - default: - return new CContextNetworkEmpty(runtime); - } - } - -} // namesapce diff --git a/src/blackcore/contextnetwork.h b/src/blackcore/contextnetwork.h deleted file mode 100644 index 7fa9b7c54..000000000 --- a/src/blackcore/contextnetwork.h +++ /dev/null @@ -1,286 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKCORE_CONTEXTNETWORK_H -#define BLACKCORE_CONTEXTNETWORK_H - -#include -#include - -#include "blackcore/blackcoreexport.h" -#include "blackcore/context.h" -#include "blackcore/corefacade.h" -#include "blackcore/corefacadeconfig.h" -#include "blackcore/network.h" -#include "blackmisc/audio/voiceroomlist.h" -#include "blackmisc/aviation/airporticaocode.h" -#include "blackmisc/aviation/atcstation.h" -#include "blackmisc/aviation/atcstationlist.h" -#include "blackmisc/aviation/callsignset.h" -#include "blackmisc/aviation/flightplan.h" -#include "blackmisc/identifier.h" -#include "blackmisc/network/clientlist.h" -#include "blackmisc/network/server.h" -#include "blackmisc/network/serverlist.h" -#include "blackmisc/network/textmessagelist.h" -#include "blackmisc/network/user.h" -#include "blackmisc/network/userlist.h" -#include "blackmisc/simulation/simulatedaircraft.h" -#include "blackmisc/simulation/simulatedaircraftlist.h" -#include "blackmisc/statusmessage.h" -#include "blackmisc/weather/metar.h" - -class QDBusConnection; - -namespace BlackMisc -{ - class CDBusServer; - namespace Aviation - { - class CAircraftParts; - class CCallsign; - } - namespace Network { class CTextMessage; } - namespace Simulation { class CAircraftModel; } -} - -//! \addtogroup dbus -//! @{ - -//! DBus interface for context -#define BLACKCORE_CONTEXTNETWORK_INTERFACENAME "org.swift_project.blackcore.contextnetwork" - -//! DBus object path for context -#define BLACKCORE_CONTEXTNETWORK_OBJECTPATH "/network" - -//! @} - -namespace BlackCore -{ - //! Network context proxy - class BLACKCORE_EXPORT IContextNetwork : public CContext - { - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTNETWORK_INTERFACENAME) - - public: - //! DBus interface name - static const QString &InterfaceName() - { - static QString s(BLACKCORE_CONTEXTNETWORK_INTERFACENAME); - return s; - } - - //! DBus object path - static const QString &ObjectPath() - { - static QString s(BLACKCORE_CONTEXTNETWORK_OBJECTPATH); - return s; - } - - //! \copydoc CContext::getPathAndContextId() - virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); } - - //! Factory method - static IContextNetwork *create(CCoreFacade *parent, CCoreFacadeConfig::ContextMode mode, BlackMisc::CDBusServer *server, QDBusConnection &connection); - - //! Destructor - virtual ~IContextNetwork() {} - - signals: - //! An aircraft disappeared - void removedAircraft(const BlackMisc::Aviation::CCallsign &callsign); - - //! A new aircraft appeared - void addedAircraft(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft); - - //! Read for model matching - void readyForModelMatching(const BlackMisc::Simulation::CSimulatedAircraft &renderedAircraft); - - //! ATC station (online) list has been changed - void changedAtcStationsOnline(); - - //! Digest signal changedAtcStationsOnline() - void changedAtcStationsOnlineDigest(); - - //! ATC station (booked) list has been changed - void changedAtcStationsBooked(); - - //! Digest signal changedAtcStationsBooked() - void changedAtcStationsBookedDigest(); - - //! Aircraft list has been changed - void changedAircraftInRange(); - - //! Digest signal changedAircraftInRange() - void changedAircraftInRangeDigest(); - - //! Aircraft model was changed - //! \details All remote aircraft are stored in the network context. The model can be updated here - //! via \sa updateAircraftModel and then this signal is fired - void changedRemoteAircraftModel(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator); - - //! Aircraft enabled / disabled - //! \details All remote aircraft are stored in the network context. The aircraft can be enabled (for rendering) here - //! via \sa updateAircraftEnabled and then this signal is fired - void changedRemoteAircraftEnabled(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator); - - //! Aircraft enabled / disabled - void changedFastPositionUpdates(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator); - - //! Connection status changed for online station - void changedAtcStationOnlineConnectionStatus(const BlackMisc::Aviation::CAtcStation &atcStation, bool connected); - - //! Terminated connection - void connectionTerminated(); - - //! Connection status changed - void connectionStatusChanged(BlackCore::INetwork::ConnectionStatus from, BlackCore::INetwork::ConnectionStatus to); - - //! Text messages received (also private chat messages, rfaio channel messages) - void textMessagesReceived(const BlackMisc::Network::CTextMessageList &textMessages); - - //! A superivisor text message was received - void supervisorTextMessageReceived(const BlackMisc::Network::CTextMessage &message); - - //! Text message sent (by me) - void textMessageSent(const BlackMisc::Network::CTextMessage &sentMessage); - - // --------------------------- data readers ------------------------------- - - //! Web serice data read - // void webServiceDataRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState state, int number); - void webServiceDataRead(int entity, int state, int number); - - public slots: - //! Reload bookings from booking service - virtual void readAtcBookingsFromSource() const = 0; - - //! The ATC list with online ATC controllers - virtual BlackMisc::Aviation::CAtcStationList getAtcStationsOnline() const = 0; - - //! ATC list, with booked controllers - virtual BlackMisc::Aviation::CAtcStationList getAtcStationsBooked() const = 0 ; - - //! Aircraft list - virtual BlackMisc::Simulation::CSimulatedAircraftList getAircraftInRange() const = 0; - - //! Aircraft callsigns - virtual BlackMisc::Aviation::CCallsignSet getAircraftInRangeCallsigns() const = 0; - - //! Aircraft for given callsign - virtual BlackMisc::Simulation::CSimulatedAircraft getAircraftInRangeForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const = 0; - - //! Aircraft count - virtual int getAircraftInRangeCount() const = 0; - - //! Get METAR, if not available request it (code such as EDDF, KLAX) - virtual BlackMisc::Weather::CMetar getMetarForAirport(const BlackMisc::Aviation::CAirportIcaoCode &airportIcaoCode) const = 0; - - //! Online station for callsign - virtual BlackMisc::Aviation::CAtcStation getOnlineStationForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const = 0; - - //! Get all users - virtual BlackMisc::Network::CUserList getUsers() const = 0; - - //! Users for given callsigns, e.g. for voice room resolution - virtual BlackMisc::Network::CUserList getUsersForCallsigns(const BlackMisc::Aviation::CCallsignSet &callsigns) const = 0; - - //! User for given callsign, e.g. for text messages - virtual BlackMisc::Network::CUser getUserForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const = 0; - - //! Information about other clients - virtual BlackMisc::Network::CClientList getOtherClients() const = 0; - - //! Clients for given callsign, e.g. to test/fetch direct aircraft model - virtual BlackMisc::Network::CClientList getOtherClientsForCallsigns(const BlackMisc::Aviation::CCallsignSet &callsigns) const = 0; - - //! Known voice servers, available when data file was first read - virtual BlackMisc::Network::CServerList getVatsimVoiceServers() const = 0; - - //! Known FSD servers, available when data file was first read - virtual BlackMisc::Network::CServerList getVatsimFsdServers() const = 0; - - //! Callsigns enabled for fast position updates - virtual void setFastPositionEnabledCallsigns(BlackMisc::Aviation::CCallsignSet &callsigns) = 0; - - //! Callsigns enabled for fast position updates - virtual BlackMisc::Aviation::CCallsignSet getFastPositionEnabledCallsigns() = 0; - - //! Connect to Network - //! \return messages generated during connecting - virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, BlackCore::INetwork::LoginMode loginMode) = 0; - - //! Server which is connected, if not connected empty default object. - virtual BlackMisc::Network::CServer getConnectedServer() const = 0; - - //! Disconnect from network - //! \return messages generated during disconnecting - virtual BlackMisc::CStatusMessage disconnectFromNetwork() = 0; - - //! Network connected? - virtual bool isConnected() const = 0; - - //! Text messages (radio and private chat messages) - virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &textMessages) = 0; - - //! Send flight plan - virtual void sendFlightPlan(const BlackMisc::Aviation::CFlightPlan &flightPlan) = 0; - - //! Load flight plan (from network) - virtual BlackMisc::Aviation::CFlightPlan loadFlightPlanFromNetwork(const BlackMisc::Aviation::CCallsign &callsign) const = 0; - - //! Command line was entered - virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) = 0; - - //! Use the selected COM1/2 frequencies, and get the corresponding voice room for it - virtual BlackMisc::Audio::CVoiceRoomList getSelectedVoiceRooms() const = 0; - - //! Use the selected COM1/2 frequencies, and get the corresponding ATC stations for it - virtual BlackMisc::Aviation::CAtcStationList getSelectedAtcStations() const = 0; - - //! Request data updates (pilot's frequencies, ATIS, ..) - virtual void requestDataUpdates() = 0; - - //! Request ATIS updates (for all stations) - virtual void requestAtisUpdates() = 0; - - //! Enable/disable rendering - virtual bool updateAircraftEnabled(const BlackMisc::Aviation::CCallsign &callsign, bool enabledForRedering, const BlackMisc::CIdentifier &originator) = 0; - - //! Change model string - virtual bool updateAircraftModel(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Simulation::CAircraftModel &model, const BlackMisc::CIdentifier &originator) = 0; - - //! Change fast position updates - virtual bool updateFastPositionEnabled(const BlackMisc::Aviation::CCallsign &callsign, bool enableFastPositionSending, const BlackMisc::CIdentifier &originator) = 0; - - //! Get reverse lookup meesages - virtual BlackMisc::CStatusMessageList getReverseLookupMessages(const BlackMisc::Aviation::CCallsign &callsign) const = 0; - - //! Enabled reverse lookup logging? - virtual bool isReverseLookupMessagesEnabled() const = 0; - - //! Enable reverse lookup logging - virtual void enableReverseLookupMessages(bool enabled) = 0; - - //! Create dummy ATC stations for performance tests etc. - virtual void testCreateDummyOnlineAtcStations(int number) = 0; - - //! Inject aircraft parts for testing - virtual void testAddAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftParts &parts, bool incremental) = 0; - - protected: - //! Constructor - IContextNetwork(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : CContext(mode, runtime) {} - }; -} - -#endif // guard diff --git a/src/blackcore/contextnetworkempty.h b/src/blackcore/contextnetworkempty.h deleted file mode 100644 index 67324895e..000000000 --- a/src/blackcore/contextnetworkempty.h +++ /dev/null @@ -1,321 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKCORE_CONTEXTNETWORK_EMPTY_H -#define BLACKCORE_CONTEXTNETWORK_EMPTY_H - -#include "blackcoreexport.h" -#include "contextnetwork.h" -#include "blackmisc/logmessage.h" - -namespace BlackCore -{ - //! Empty context, used during shutdown/initialization - class BLACKCORE_EXPORT CContextNetworkEmpty : public IContextNetwork - { - Q_OBJECT - - public: - //! Constructor - CContextNetworkEmpty(CCoreFacade *runtime) : IContextNetwork(CCoreFacadeConfig::NotUsed, runtime) {} - - public slots: // IContextNetwork overrides - - //! \copydoc IContextNetwork::readAtcBookingsFromSource() - virtual void readAtcBookingsFromSource() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextNetwork::getAtcStationsOnline() - virtual BlackMisc::Aviation::CAtcStationList getAtcStationsOnline() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Aviation::CAtcStationList(); - } - - //! \copydoc IContextNetwork::getAtcStationsBooked() - virtual BlackMisc::Aviation::CAtcStationList getAtcStationsBooked() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Aviation::CAtcStationList(); - } - - //! \copydoc IContextNetwork::getAircraftInRange() - virtual BlackMisc::Simulation::CSimulatedAircraftList getAircraftInRange() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Simulation::CSimulatedAircraftList(); - } - - //! \copydoc IContextNetwork::getAircraftInRangeForCallsign - virtual BlackMisc::Simulation::CSimulatedAircraft getAircraftInRangeForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override - { - Q_UNUSED(callsign); - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Simulation::CSimulatedAircraft(); - } - - //! \copydoc IContextNetwork::getAircraftInRangeCallsigns() - virtual BlackMisc::Aviation::CCallsignSet getAircraftInRangeCallsigns() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Aviation::CCallsignSet(); - } - - //! \copydoc IContextNetwork::getAircraftInRangeCount - virtual int getAircraftInRangeCount() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return 0; - } - - //! \copydoc IContextNetwork::getOnlineStationForCallsign - virtual BlackMisc::Aviation::CAtcStation getOnlineStationForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override - { - Q_UNUSED(callsign); - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Aviation::CAtcStation(); - } - - //! \copydoc IContextNetwork::connectToNetwork - virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, BlackCore::INetwork::LoginMode mode) override - { - Q_UNUSED(mode); - Q_UNUSED(server); - logEmptyContextWarning(Q_FUNC_INFO); - return statusMessageEmptyContext(); - } - - //! \copydoc IContextNetwork::disconnectFromNetwork() - virtual BlackMisc::CStatusMessage disconnectFromNetwork() override - { - logEmptyContextWarning(Q_FUNC_INFO); - return statusMessageEmptyContext(); - } - - //! \copydoc IContextNetwork::isConnected() - virtual bool isConnected() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return false; - } - - //! \copydoc IContextNetwork::getConnectedServer - virtual BlackMisc::Network::CServer getConnectedServer() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Network::CServer(); - } - - //! \copydoc IContextNetwork::sendTextMessages() - virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &textMessages) override - { - Q_UNUSED(textMessages); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextNetwork::sendFlightPlan() - virtual void sendFlightPlan(const BlackMisc::Aviation::CFlightPlan &flightPlan) override - { - Q_UNUSED(flightPlan); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextNetwork::loadFlightPlanFromNetwork() - virtual BlackMisc::Aviation::CFlightPlan loadFlightPlanFromNetwork(const BlackMisc::Aviation::CCallsign &callsign) const override - { - Q_UNUSED(callsign); - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Aviation::CFlightPlan(); - } - - //! \copydoc IContextNetwork::getMetarForAirport - BlackMisc::Weather::CMetar getMetarForAirport(const BlackMisc::Aviation::CAirportIcaoCode &airportIcaoCode) const override - { - Q_UNUSED(airportIcaoCode); - logEmptyContextWarning(Q_FUNC_INFO); - return {}; - } - - //! \copydoc IContextNetwork::getSelectedVoiceRooms() - virtual BlackMisc::Audio::CVoiceRoomList getSelectedVoiceRooms() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Audio::CVoiceRoomList(); - } - - //! \copydoc IContextNetwork::getSelectedAtcStations - virtual BlackMisc::Aviation::CAtcStationList getSelectedAtcStations() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - // normally 2 entries - return BlackMisc::Aviation::CAtcStationList({ BlackMisc::Aviation::CAtcStation(), BlackMisc::Aviation::CAtcStation()}); - } - - //! \copydoc IContextNetwork::getUsers() - virtual BlackMisc::Network::CUserList getUsers() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Network::CUserList(); - } - - //! \copydoc IContextNetwork::getUsersForCallsigns - virtual BlackMisc::Network::CUserList getUsersForCallsigns(const BlackMisc::Aviation::CCallsignSet &callsigns) const override - { - Q_UNUSED(callsigns); - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Network::CUserList(); - } - - //! \copydoc IContextNetwork::getUserForCallsign - virtual BlackMisc::Network::CUser getUserForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override - { - Q_UNUSED(callsign); - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Network::CUser(); - } - - //! \copydoc IContextNetwork::getOtherClients - virtual BlackMisc::Network::CClientList getOtherClients() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Network::CClientList(); - } - - //! \copydoc IContextNetwork::getOtherClientsForCallsigns - virtual BlackMisc::Network::CClientList getOtherClientsForCallsigns(const BlackMisc::Aviation::CCallsignSet &callsigns) const override - { - Q_UNUSED(callsigns); - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Network::CClientList(); - } - - //! \copydoc IContextNetwork::requestDataUpdates - virtual void requestDataUpdates()override - { - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextNetwork::requestAtisUpdates - virtual void requestAtisUpdates() override - { - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextNetwork::testCreateDummyOnlineAtcStations - virtual void testCreateDummyOnlineAtcStations(int number) override - { - Q_UNUSED(number); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextNetwork::testAddAircraftParts - virtual void testAddAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftParts &parts, bool incremental) override - { - Q_UNUSED(callsign); - Q_UNUSED(parts); - Q_UNUSED(incremental); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextNetwork::parseCommandLine - virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override - { - Q_UNUSED(commandLine); - Q_UNUSED(originator); - logEmptyContextWarning(Q_FUNC_INFO); - return false; - } - - //! \copydoc IContextNetwork::getVatsimVoiceServers - virtual BlackMisc::Network::CServerList getVatsimVoiceServers() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Network::CServerList(); - } - - //! \copydoc IContextNetwork::getVatsimFsdServers - virtual BlackMisc::Network::CServerList getVatsimFsdServers() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Network::CServerList(); - } - - //! \copydoc IContextNetwork::updateAircraftEnabled - virtual bool updateAircraftEnabled(const BlackMisc::Aviation::CCallsign &callsign, bool enabledForRedering, const BlackMisc::CIdentifier &originator) override - { - Q_UNUSED(callsign); - Q_UNUSED(originator); - Q_UNUSED(enabledForRedering); - logEmptyContextWarning(Q_FUNC_INFO); - return false; - } - - //! \copydoc IContextNetwork::updateAircraftModel - virtual bool updateAircraftModel(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Simulation::CAircraftModel &model, const BlackMisc::CIdentifier &originator) override - { - Q_UNUSED(callsign); - Q_UNUSED(originator); - Q_UNUSED(model); - logEmptyContextWarning(Q_FUNC_INFO); - return false; - } - - //! \copydoc IContextNetwork::updateFastPositionEnabled - virtual bool updateFastPositionEnabled(const BlackMisc::Aviation::CCallsign &callsign, bool enableFastPositionSending, const BlackMisc::CIdentifier &originator) override - { - logEmptyContextWarning(Q_FUNC_INFO); - Q_UNUSED(callsign); - Q_UNUSED(enableFastPositionSending); - Q_UNUSED(originator); - return false; - } - - //! \copydoc IContextNetwork::setFastPositionEnabledCallsigns - virtual void setFastPositionEnabledCallsigns(BlackMisc::Aviation::CCallsignSet &callsigns) override - { - Q_UNUSED(callsigns); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextNetwork::getFastPositionEnabledCallsigns - virtual BlackMisc::Aviation::CCallsignSet getFastPositionEnabledCallsigns() override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Aviation::CCallsignSet(); - } - - //! \copydoc IContextNetwork::getReverseLookupMessages - virtual BlackMisc::CStatusMessageList getReverseLookupMessages(const BlackMisc::Aviation::CCallsign &callsign) const - { - logEmptyContextWarning(Q_FUNC_INFO); - Q_UNUSED(callsign); - return BlackMisc::CStatusMessageList(); - } - - //! \copydoc IContextNetwork::isReverseLookupMessagesEnabled - virtual bool isReverseLookupMessagesEnabled() const - { - logEmptyContextWarning(Q_FUNC_INFO); - return false; - } - - //! \copydoc IContextNetwork::enableReverseLookupMessages - virtual void enableReverseLookupMessages(bool enabled) - { - logEmptyContextWarning(Q_FUNC_INFO); - Q_UNUSED(enabled); - } - }; -} // namespace - -#endif // guard diff --git a/src/blackcore/contextnetworkimpl.cpp b/src/blackcore/contextnetworkimpl.cpp deleted file mode 100644 index 4d314d611..000000000 --- a/src/blackcore/contextnetworkimpl.cpp +++ /dev/null @@ -1,670 +0,0 @@ -/* Copyright (C) 2013 - * swift project Community / Contributors - * - * This file is part of Swift Project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "blackcore/airspaceanalyzer.h" -#include "blackcore/airspacemonitor.h" -#include "blackcore/application.h" -#include "blackcore/contextnetworkimpl.h" -#include "blackcore/contextownaircraft.h" -#include "blackcore/contextownaircraftimpl.h" -#include "blackcore/contextsimulator.h" -#include "blackcore/corefacade.h" -#include "blackcore/networkvatlib.h" -#include "blackcore/webdataservices.h" -#include "blackmisc/aviation/aircrafticaocode.h" -#include "blackmisc/aviation/aircraftparts.h" -#include "blackmisc/aviation/atcstationlist.h" -#include "blackmisc/aviation/callsign.h" -#include "blackmisc/aviation/comsystem.h" -#include "blackmisc/dbusserver.h" -#include "blackmisc/logcategory.h" -#include "blackmisc/logmessage.h" -#include "blackmisc/network/entityflags.h" -#include "blackmisc/network/networkutils.h" -#include "blackmisc/network/textmessage.h" -#include "blackmisc/pq/constants.h" -#include "blackmisc/pq/frequency.h" -#include "blackmisc/pq/units.h" -#include "blackmisc/sequence.h" -#include "blackmisc/simplecommandparser.h" -#include "blackmisc/simulation/simulatorplugininfo.h" -#include "blackmisc/stringutils.h" -#include "contextnetworkimpl.h" - -#include -#include - -using namespace BlackMisc; -using namespace BlackMisc::PhysicalQuantities; -using namespace BlackMisc::Aviation; -using namespace BlackMisc::Network; -using namespace BlackMisc::Geo; -using namespace BlackMisc::Audio; -using namespace BlackMisc::Simulation; -using namespace BlackMisc::Weather; - -namespace BlackCore -{ - CContextNetwork::CContextNetwork(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : - IContextNetwork(mode, runtime) - { - Q_ASSERT(this->getRuntime()); - Q_ASSERT(this->getIContextOwnAircraft()); - Q_ASSERT(this->getIContextOwnAircraft()->isUsingImplementingObject()); - - // 1. Init by "network driver" - this->m_network = new CNetworkVatlib(this->getRuntime()->getCContextOwnAircraft(), this); - connect(this->m_network, &INetwork::connectionStatusChanged, this, &CContextNetwork::ps_fsdConnectionStatusChanged); - connect(this->m_network, &INetwork::textMessagesReceived, this, &CContextNetwork::textMessagesReceived); - connect(this->m_network, &INetwork::textMessagesReceived, this, &CContextNetwork::ps_checkForSupervisiorTextMessage); - connect(this->m_network, &INetwork::textMessageSent, this, &CContextNetwork::textMessageSent); - - // 2. Update timer for data (network data such as frequency) - this->m_networkDataUpdateTimer = new QTimer(this); - connect(this->m_networkDataUpdateTimer, &QTimer::timeout, this, &CContextNetwork::requestDataUpdates); - this->m_networkDataUpdateTimer->start(30 * 1000); - - // 3. data reader, start reading when setup is synced with xx delay - Q_ASSERT_X(sApp->getWebDataServices(), Q_FUNC_INFO, "Missing web data services"); - connect(sApp->getWebDataServices(), &CWebDataServices::dataRead, this, &CContextNetwork::webServiceDataRead); - - // 4. Airspace contents - Q_ASSERT_X(this->getRuntime()->getCContextOwnAircraft(), Q_FUNC_INFO, "this and own aircraft context must be local"); - this->m_airspace = new CAirspaceMonitor(this->getRuntime()->getCContextOwnAircraft(), this->m_network, this); - connect(this->m_airspace, &CAirspaceMonitor::changedAtcStationsOnline, this, &CContextNetwork::changedAtcStationsOnline); - connect(this->m_airspace, &CAirspaceMonitor::changedAtcStationsBooked, this, &CContextNetwork::changedAtcStationsBooked); - connect(this->m_airspace, &CAirspaceMonitor::changedAtcStationOnlineConnectionStatus, this, &CContextNetwork::changedAtcStationOnlineConnectionStatus); - connect(this->m_airspace, &CAirspaceMonitor::changedAircraftInRange, this, &CContextNetwork::changedAircraftInRange); - connect(this->m_airspace, &CAirspaceMonitor::removedAircraft, this, &IContextNetwork::removedAircraft); // DBus - connect(this->m_airspace, &CAirspaceMonitor::readyForModelMatching, this, &CContextNetwork::readyForModelMatching); - connect(this->m_airspace, &CAirspaceMonitor::addedAircraft, this, &CContextNetwork::addedAircraft); - } - - CContextNetwork *CContextNetwork::registerWithDBus(BlackMisc::CDBusServer *server) - { - if (!server || this->m_mode != CCoreFacadeConfig::LocalInDbusServer) return this; - server->addObject(IContextNetwork::ObjectPath(), this); - return this; - } - - CContextNetwork::~CContextNetwork() - { - this->gracefulShutdown(); - } - - CAircraftSituationList CContextNetwork::remoteAircraftSituations(const CCallsign &callsign) const - { - Q_ASSERT(this->m_airspace); - return m_airspace->remoteAircraftSituations(callsign); - } - - CAircraftPartsList CContextNetwork::remoteAircraftParts(const CCallsign &callsign, qint64 cutoffTimeBefore) const - { - Q_ASSERT(this->m_airspace); - return m_airspace->remoteAircraftParts(callsign, cutoffTimeBefore); - } - - int CContextNetwork::remoteAircraftSituationsCount(const CCallsign &callsign) const - { - Q_ASSERT(this->m_airspace); - return m_airspace->remoteAircraftSituationsCount(callsign); - } - - bool CContextNetwork::isRemoteAircraftSupportingParts(const CCallsign &callsign) const - { - Q_ASSERT(this->m_airspace); - return m_airspace->isRemoteAircraftSupportingParts(callsign); - } - - CCallsignSet CContextNetwork::remoteAircraftSupportingParts() const - { - Q_ASSERT(this->m_airspace); - return m_airspace->remoteAircraftSupportingParts(); - } - - QList CContextNetwork::connectRemoteAircraftProviderSignals( - QObject *receiver, - std::function situationSlot, - std::function partsSlot, - std::function removedAircraftSlot, - std::function aircraftSnapshotSlot) - { - Q_ASSERT_X(this->m_airspace, Q_FUNC_INFO, "Missing airspace"); - return this->m_airspace->connectRemoteAircraftProviderSignals(receiver, situationSlot, partsSlot, removedAircraftSlot, aircraftSnapshotSlot); - } - - void CContextNetwork::gracefulShutdown() - { - this->disconnect(); // all signals - if (this->isConnected()) { this->disconnectFromNetwork(); } - if (this->m_airspace) { this->m_airspace->gracefulShutdown(); } - } - - CStatusMessage CContextNetwork::connectToNetwork(const CServer &server, INetwork::LoginMode mode) - { - if (this->isDebugEnabled()) {CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - QString msg; - if (!server.getUser().isValid()) - { - return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityError, "Invalid user credentials"); - } - else if (!this->ownAircraft().getAircraftIcaoCode().hasDesignator()) - { - return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityError, "Invalid ICAO data for own aircraft"); - } - else if (!CNetworkUtils::canConnect(server, msg, 2000)) - { - return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityError, msg); - } - else if (this->m_network->isConnected()) - { - return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityError, "Already connected"); - } - else if (this->isPendingConnection()) - { - return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityError, "Pending connection, please wait"); - } - else - { - this->m_currentStatus = INetwork::Connecting; // as semaphore we are going to connect - this->m_airspace->setConnected(true); - this->getIContextOwnAircraft()->updateOwnAircraftPilot(server.getUser()); - const CSimulatedAircraft ownAircraft(this->ownAircraft()); - this->m_network->presetServer(server); - this->m_network->presetLoginMode(mode); - this->m_network->presetCallsign(ownAircraft.getCallsign()); - this->m_network->presetIcaoCodes(ownAircraft); - if (getIContextSimulator()) - { - this->m_network->presetSimulatorInfo(getIContextSimulator()->getSimulatorPluginInfo()); - } - else - { - this->m_network->presetSimulatorInfo(CSimulatorPluginInfo()); - } - this->m_network->initiateConnection(); - return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityInfo, "Connection pending " + server.getAddress() + " " + QString::number(server.getPort())); - } - } - - CServer CContextNetwork::getConnectedServer() const - { - return this->isConnected() ? - this->m_network->getPresetServer() : - CServer(); - } - - CStatusMessage CContextNetwork::disconnectFromNetwork() - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - if (this->m_network->isConnected()) - { - this->m_currentStatus = INetwork::Disconnecting; // as semaphore we are going to disconnect - this->m_network->terminateConnection(); - this->m_airspace->setConnected(false); - return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityInfo, "Connection terminating"); - } - else if (this->isPendingConnection()) - { - return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityInfo, "Pending connection, please wait"); - } - else - { - return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityWarning, "Already disconnected"); - } - } - - bool CContextNetwork::isConnected() const - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - return this->m_network->isConnected(); - } - - bool CContextNetwork::isPendingConnection() const - { - // if underlying class says pending, we believe it. But not all states (e.g. disconnecting) are covered - if (this->m_network->isPendingConnection()) return true; - - // now check out own extra states, e.g. disconnecting - return INetwork::isPendingStatus(this->m_currentStatus); - } - - bool CContextNetwork::parseCommandLine(const QString &commandLine, const CIdentifier &originator) - { - Q_UNUSED(originator;) - if (commandLine.isEmpty()) { return false; } - CSimpleCommandParser parser({ ".msg", ".m" }); - parser.parse(commandLine); - if (!parser.isKnownCommand()) { return false; } - if (parser.matchesCommand(".msg", ".m")) - { - if (!this->getIContextNetwork()->isConnected()) - { - CLogMessage(this).validationError("Network needs to be connected"); - return false; - } - else if (!this->getIContextOwnAircraft()) - { - CLogMessage(this).validationError("No own aircraft data, no text message can be sent"); - return false; - } - if (parser.countParts() < 3) - { - CLogMessage(this).validationError("Incorrect message"); - return false; - } - QString receiver = parser.part(1).trimmed(); // receiver - - // set receiver - CSimulatedAircraft ownAircraft(this->getIContextOwnAircraft()->getOwnAircraft()); - if (ownAircraft.getCallsign().isEmpty()) - { - CLogMessage(this).validationError("No own callsign"); - return false; - } - - CTextMessage tm; - tm.setSenderCallsign(ownAircraft.getCallsign()); - - if (receiver == "c1" || receiver == "com1") - { - tm.setFrequency(ownAircraft.getCom1System().getFrequencyActive()); - } - else if (receiver == "c2" || receiver == "com2") - { - tm.setFrequency(ownAircraft.getCom2System().getFrequencyActive()); - } - else if (receiver == "u" || receiver == "unicom" || receiver == "uni") - { - tm.setFrequency(CPhysicalQuantitiesConstants::FrequencyUnicom()); - } - else - { - bool isNumber; - double frequencyMhz = receiver.toDouble(&isNumber); - if (isNumber) - { - CFrequency radioFrequency = CFrequency(frequencyMhz, CFrequencyUnit::MHz()); - if (CComSystem::isValidCivilAviationFrequency(radioFrequency)) - { - tm.setFrequency(radioFrequency); - } - else - { - CLogMessage(this).validationError("Wrong COM frequency for text message"); - return false; - } - } - else - { - CCallsign toCallsign(receiver); - tm.setRecipientCallsign(toCallsign); - } - } - - QString msg(parser.remainingStringAfter(2)); - tm.setMessage(msg); - if (tm.isEmpty()) - { - CLogMessage(this).validationError("No text message body"); - return false; - } - CTextMessageList tml(tm); - this->sendTextMessages(tml); - return true; - } - return false; - } - - void CContextNetwork::sendTextMessages(const CTextMessageList &textMessages) - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << textMessages; } - this->m_network->sendTextMessages(textMessages); - } - - void CContextNetwork::sendFlightPlan(const CFlightPlan &flightPlan) - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << flightPlan; } - this->m_network->sendFlightPlan(flightPlan); - this->m_network->sendFlightPlanQuery(this->ownAircraft().getCallsign()); - } - - CFlightPlan CContextNetwork::loadFlightPlanFromNetwork(const BlackMisc::Aviation::CCallsign &callsign) const - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - return this->m_airspace->loadFlightPlanFromNetwork(callsign); - } - - CUserList CContextNetwork::getUsers() const - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - return this->m_airspace->getUsers(); - } - - CUserList CContextNetwork::getUsersForCallsigns(const CCallsignSet &callsigns) const - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - CUserList users; - if (callsigns.isEmpty()) return users; - return this->m_airspace->getUsersForCallsigns(callsigns); - } - - CUser CContextNetwork::getUserForCallsign(const CCallsign &callsign) const - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - CCallsignSet callsigns; - callsigns.push_back(callsign); - CUserList users = this->getUsersForCallsigns(callsigns); - if (users.size() < 1) return CUser(); - return users[0]; - } - - CClientList CContextNetwork::getOtherClients() const - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - return this->m_airspace->getOtherClients(); - } - - CClientList CContextNetwork::getOtherClientsForCallsigns(const CCallsignSet &callsigns) const - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - return this->m_airspace->getOtherClientsForCallsigns(callsigns); - } - - CServerList CContextNetwork::getVatsimFsdServers() const - { - Q_ASSERT_X(sApp->getWebDataServices(), Q_FUNC_INFO, "Missing data reader"); - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - return sApp->getWebDataServices()->getVatsimFsdServers(); - } - - CServerList CContextNetwork::getVatsimVoiceServers() const - { - Q_ASSERT_X(sApp->getWebDataServices(), Q_FUNC_INFO, "Missing data reader"); - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - return sApp->getWebDataServices()->getVatsimVoiceServers(); - } - - void CContextNetwork::ps_fsdConnectionStatusChanged(INetwork::ConnectionStatus from, INetwork::ConnectionStatus to) - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << from << to; } - auto fromOld = this->m_currentStatus; // own status cached - this->m_currentStatus = to; - - if (fromOld == INetwork::Disconnecting) - { - // remark: vatlib does not know disconnecting. In vatlib's terminating connection method - // state Disconnecting is sent manually. We fix the vatlib state here regarding disconnecting - from = INetwork::Disconnecting; - } - - if (to == INetwork::Disconnected) - { - // make sure airspace is really cleaned up - Q_ASSERT(m_airspace); - m_airspace->clear(); - } - - // send 1st position - if (to == INetwork::Connected) - { - CLogMessage(this).info("Connected, own aircraft %1") << this->ownAircraft().getCallsignAsString(); - } - - // send as message - if (to == INetwork::DisconnectedError) - { - CLogMessage(this).error("Connection status changed from %1 to %2") << INetwork::connectionStatusToString(from) << INetwork::connectionStatusToString(to); - } - else - { - CLogMessage(this).info("Connection status changed from %1 to %2") << INetwork::connectionStatusToString(from) << INetwork::connectionStatusToString(to); - } - - // send as own signal - emit this->connectionStatusChanged(from, to); - } - - void CContextNetwork::ps_simulatorRenderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const CLength &maxRenderedDistance, const CLength &maxRenderedBoundary) - { - // mainly passing changed restrictions from simulator to network - if (!m_airspace) { return; } - if (!m_airspace->analyzer()) { return; } - m_airspace->analyzer()->setSimulatorRenderRestrictionsChanged(restricted, enabled, maxAircraft, maxRenderedDistance, maxRenderedBoundary); - } - - void CContextNetwork::ps_updateMetars(const BlackMisc::Weather::CMetarList &metars) - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - CLogMessage(this).info("%1 METARs updated") << metars.size(); - } - - void CContextNetwork::ps_checkForSupervisiorTextMessage(const CTextMessageList &messages) - { - if (messages.containsPrivateMessages()) - { - CTextMessageList supMessages(messages.getSupervisorMessages()); - for (const CTextMessage &m : supMessages) - { - emit supervisorTextMessageReceived(m); - } - } - } - - const CSimulatedAircraft CContextNetwork::ownAircraft() const - { - Q_ASSERT(this->getRuntime()); - Q_ASSERT(this->getRuntime()->getCContextOwnAircraft()); - return this->getRuntime()->getCContextOwnAircraft()->getOwnAircraft(); - } - - CAtcStationList CContextNetwork::getAtcStationsOnline() const - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - return this->m_airspace->getAtcStationsOnline(); - } - - CAtcStationList CContextNetwork::getAtcStationsBooked() const - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - return this->m_airspace->getAtcStationsBooked(); - } - - CSimulatedAircraftList CContextNetwork::getAircraftInRange() const - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - return this->m_airspace->getAircraftInRange(); - } - - CCallsignSet CContextNetwork::getAircraftInRangeCallsigns() const - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - return this->m_airspace->getAircraftInRangeCallsigns(); - } - - int CContextNetwork::getAircraftInRangeCount() const - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - return this->m_airspace->getAircraftInRangeCount(); - } - - CSimulatedAircraft CContextNetwork::getAircraftInRangeForCallsign(const CCallsign &callsign) const - { - if (this->isDebugEnabled()) { BlackMisc::CLogMessage(this, BlackMisc::CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << callsign; } - return this->m_airspace->getAircraftInRangeForCallsign(callsign); - } - - CAircraftModel CContextNetwork::getAircraftInRangeModelForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const - { - if (this->isDebugEnabled()) { BlackMisc::CLogMessage(this, BlackMisc::CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << callsign; } - return this->m_airspace->getAircraftInRangeModelForCallsign(callsign); - } - - CStatusMessageList CContextNetwork::getReverseLookupMessages(const CCallsign &callsign) const - { - if (this->isDebugEnabled()) { BlackMisc::CLogMessage(this, BlackMisc::CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << callsign; } - return this->m_airspace->getReverseLookupMessages(callsign); - } - - bool CContextNetwork::isReverseLookupMessagesEnabled() const - { - if (this->isDebugEnabled()) { BlackMisc::CLogMessage(this, BlackMisc::CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - return this->m_airspace->isReverseLookupMessagesEnabled(); - } - - void CContextNetwork::enableReverseLookupMessages(bool enabled) - { - if (this->isDebugEnabled()) { BlackMisc::CLogMessage(this, BlackMisc::CLogCategory::contextSlot()).debug() << enabled; } - return this->m_airspace->enableReverseLookupMessages(enabled); - } - - CAtcStation CContextNetwork::getOnlineStationForCallsign(const CCallsign &callsign) const - { - if (this->isDebugEnabled()) { BlackMisc::CLogMessage(this, BlackMisc::CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << callsign; } - return this->m_airspace->getAtcStationsOnline().findFirstByCallsign(callsign); - } - - void CContextNetwork::requestDataUpdates() - { - Q_ASSERT(this->m_network); - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - if (!this->isConnected()) { return; } - - this->requestAtisUpdates(); - this->m_airspace->requestDataUpdates(); - } - - void CContextNetwork::requestAtisUpdates() - { - Q_ASSERT(this->m_network); - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - if (!this->isConnected()) { return; } - - this->m_airspace->requestAtisUpdates(); - } - - bool CContextNetwork::updateAircraftEnabled(const CCallsign &callsign, bool enabledForRedering, const BlackMisc::CIdentifier &originator) - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << callsign << enabledForRedering << originator; } - bool c = this->m_airspace->updateAircraftEnabled(callsign, enabledForRedering, originator); - if (c) - { - CSimulatedAircraft aircraft(this->getAircraftInRangeForCallsign(callsign)); - emit this->changedRemoteAircraftEnabled(aircraft, originator); - } - return c; - } - - bool CContextNetwork::updateAircraftModel(const CCallsign &callsign, const CAircraftModel &model, const BlackMisc::CIdentifier &originator) - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << callsign << model << originator; } - bool c = this->m_airspace->updateAircraftModel(callsign, model, originator); - if (c) - { - CSimulatedAircraft aircraft(this->getAircraftInRangeForCallsign(callsign)); - emit this->changedRemoteAircraftModel(aircraft, originator); - } - return c; - } - - bool CContextNetwork::updateFastPositionEnabled(const CCallsign &callsign, bool enableFastPositonUpdates, const BlackMisc::CIdentifier &originator) - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << callsign << enableFastPositonUpdates << originator; } - bool c = this->m_airspace->updateFastPositionEnabled(callsign, enableFastPositonUpdates, originator); - if (c) - { - CSimulatedAircraft aircraft(this->getAircraftInRangeForCallsign(callsign)); - CLogMessage(this).info("Callsign %1 sets fast positions ") << aircraft.getCallsign() << BlackMisc::boolToOnOff(aircraft.fastPositionUpdates()); - emit this->changedFastPositionUpdates(aircraft, originator); - } - return c; - } - - void CContextNetwork::readAtcBookingsFromSource() const - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - Q_ASSERT_X(sApp->getWebDataServices(), Q_FUNC_INFO, "missing reader"); - sApp->getWebDataServices()->readInBackground(BlackMisc::Network::CEntityFlags::BookingEntity); - } - - bool CContextNetwork::updateAircraftRendered(const CCallsign &callsign, bool rendered, const CIdentifier &originator) - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << callsign << rendered << originator; } - bool c = this->m_airspace->updateAircraftRendered(callsign, rendered, originator); - return c; - } - - void CContextNetwork::updateMarkAllAsNotRendered(const CIdentifier &originator) - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << originator; } - this->m_airspace->updateMarkAllAsNotRendered(originator); - } - - CAirspaceAircraftSnapshot CContextNetwork::getLatestAirspaceAircraftSnapshot() const - { - return this->m_airspace->getLatestAirspaceAircraftSnapshot(); - } - - void CContextNetwork::setFastPositionEnabledCallsigns(CCallsignSet &callsigns) - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << callsigns; } - Q_ASSERT(this->m_network); - } - - CCallsignSet CContextNetwork::getFastPositionEnabledCallsigns() - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - Q_ASSERT(this->m_network); - //! \todo Fast position updates in vatlib - return CCallsignSet(); - } - - void CContextNetwork::testCreateDummyOnlineAtcStations(int number) - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << number; } - this->m_airspace->testCreateDummyOnlineAtcStations(number); - } - - void CContextNetwork::testAddAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, const CAircraftParts &parts, bool incremental) - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << parts << incremental; } - this->m_airspace->testAddAircraftParts(callsign, parts, incremental); - } - - CMetar CContextNetwork::getMetarForAirport(const BlackMisc::Aviation::CAirportIcaoCode &airportIcaoCode) const - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << airportIcaoCode; } - return sApp->getWebDataServices()->getMetarForAirport(airportIcaoCode); - } - - CAtcStationList CContextNetwork::getSelectedAtcStations() const - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - CAtcStation com1Station = this->m_airspace->getAtcStationForComUnit(this->ownAircraft().getCom1System()); - CAtcStation com2Station = this->m_airspace->getAtcStationForComUnit(this->ownAircraft().getCom2System()); - - CAtcStationList selectedStations; - selectedStations.push_back(com1Station); - selectedStations.push_back(com2Station); - return selectedStations; - } - - CVoiceRoomList CContextNetwork::getSelectedVoiceRooms() const - { - if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - CAtcStationList stations = this->getSelectedAtcStations(); - Q_ASSERT(stations.size() == 2); - CVoiceRoomList rooms; - CAtcStation s1 = stations[0]; - CAtcStation s2 = stations[1]; - rooms.push_back(s1.getVoiceRoom()); - rooms.push_back(s2.getVoiceRoom()); - return rooms; - } -} // namespace diff --git a/src/blackcore/contextnetworkimpl.h b/src/blackcore/contextnetworkimpl.h deleted file mode 100644 index a5dee6b79..000000000 --- a/src/blackcore/contextnetworkimpl.h +++ /dev/null @@ -1,311 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of Swift Project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKCORE_CONTEXTNETWORK_IMPL_H -#define BLACKCORE_CONTEXTNETWORK_IMPL_H - -#include -#include -#include -#include -#include -#include - -#include "blackcore/blackcoreexport.h" -#include "blackcore/contextnetwork.h" -#include "blackcore/corefacadeconfig.h" -#include "blackcore/network.h" -#include "blackmisc/audio/voiceroomlist.h" -#include "blackmisc/aviation/aircraftpartslist.h" -#include "blackmisc/aviation/aircraftsituationlist.h" -#include "blackmisc/aviation/airporticaocode.h" -#include "blackmisc/aviation/atcstation.h" -#include "blackmisc/aviation/atcstationlist.h" -#include "blackmisc/aviation/callsignset.h" -#include "blackmisc/aviation/flightplan.h" -#include "blackmisc/digestsignal.h" -#include "blackmisc/identifier.h" -#include "blackmisc/network/clientlist.h" -#include "blackmisc/network/server.h" -#include "blackmisc/network/serverlist.h" -#include "blackmisc/network/textmessagelist.h" -#include "blackmisc/network/user.h" -#include "blackmisc/network/userlist.h" -#include "blackmisc/pq/length.h" -#include "blackmisc/simulation/aircraftmodel.h" -#include "blackmisc/simulation/airspaceaircraftsnapshot.h" -#include "blackmisc/simulation/remoteaircraftprovider.h" -#include "blackmisc/simulation/simulatedaircraft.h" -#include "blackmisc/simulation/simulatedaircraftlist.h" -#include "blackmisc/statusmessage.h" -#include "blackmisc/weather/metar.h" -#include "blackmisc/weather/metarlist.h" - -class QTimer; - -namespace BlackMisc -{ - class CDBusServer; - namespace Aviation - { - class CAircraftParts; - class CAircraftSituation; - class CCallsign; - } -} - -namespace BlackCore -{ - class CAirspaceMonitor; - class CCoreFacade; - - //! Network context implementation - class BLACKCORE_EXPORT CContextNetwork : - public IContextNetwork, - public BlackMisc::Simulation::IRemoteAircraftProvider - { - Q_OBJECT - Q_INTERFACES(BlackMisc::Simulation::IRemoteAircraftProvider) - Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTNETWORK_INTERFACENAME) - - friend class IContextNetwork; - friend class CCoreFacade; - - public: - //! Destructor - virtual ~CContextNetwork(); - - //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::remoteAircraftSituations - //! \ingroup remoteaircraftprovider - virtual BlackMisc::Aviation::CAircraftSituationList remoteAircraftSituations(const BlackMisc::Aviation::CCallsign &callsign) const override; - - //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::remoteAircraftSituationsCount - //! \ingroup remoteaircraftprovider - virtual int remoteAircraftSituationsCount(const BlackMisc::Aviation::CCallsign &callsign) const override; - - //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::remoteAircraftParts - //! \ingroup remoteaircraftprovider - virtual BlackMisc::Aviation::CAircraftPartsList remoteAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, qint64 cutoffTimeBefore = -1) const override; - - //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::isRemoteAircraftSupportingParts - //! \ingroup remoteaircraftprovider - virtual bool isRemoteAircraftSupportingParts(const BlackMisc::Aviation::CCallsign &callsign) const override; - - //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::remoteAircraftSupportingParts - //! \ingroup remoteaircraftprovider - virtual BlackMisc::Aviation::CCallsignSet remoteAircraftSupportingParts() const override; - - //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::connectRemoteAircraftProviderSignals - //! \ingroup remoteaircraftprovider - virtual QList connectRemoteAircraftProviderSignals( - QObject *receiver, - std::function addedSituationSlot, - std::function addedPartsSlot, - std::function removedAircraftSlot, - std::function aircraftSnapshotSlot - ) override; - - //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::updateAircraftRendered - //! \ingroup remoteaircraftprovider - virtual bool updateAircraftRendered(const BlackMisc::Aviation::CCallsign &callsign, bool rendered, const BlackMisc::CIdentifier &originator) override; - - //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::updateMarkAllAsNotRendered - //! \ingroup remoteaircraftprovider - virtual void updateMarkAllAsNotRendered(const BlackMisc::CIdentifier &originator) override; - - //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::getLatestAirspaceAircraftSnapshot - //! \ingroup remoteaircraftprovider - virtual BlackMisc::Simulation::CAirspaceAircraftSnapshot getLatestAirspaceAircraftSnapshot() const override; - - //! Network library - INetwork *network() const { return m_network; } - - public slots: - //! \copydoc IContextNetwork::updateAircraftEnabled - //! \ingroup remoteaircraftprovider - virtual bool updateAircraftEnabled(const BlackMisc::Aviation::CCallsign &callsign, bool enabledForRedering, const BlackMisc::CIdentifier &originator) override; - - //! \copydoc IContextNetwork::updateAircraftModel - //! \ingroup remoteaircraftprovider - virtual bool updateAircraftModel(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Simulation::CAircraftModel &model, const BlackMisc::CIdentifier &originator) override; - - //! \copydoc IContextNetwork::updateFastPositionEnabled - //! \ingroup remoteaircraftprovider - virtual bool updateFastPositionEnabled(const BlackMisc::Aviation::CCallsign &callsign, bool enableFastPositonUpdates, const BlackMisc::CIdentifier &originator) override; - - //! \copydoc IContextNetwork::readAtcBookingsFromSource() - virtual void readAtcBookingsFromSource() const override; - - //! \copydoc IContextNetwork::getAtcStationsOnline() - virtual BlackMisc::Aviation::CAtcStationList getAtcStationsOnline() const override; - - //! \copydoc IContextNetwork::getAtcStationsBooked() - virtual BlackMisc::Aviation::CAtcStationList getAtcStationsBooked() const override; - - //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::getAircraftInRange - //! \ingroup remoteaircraftprovider - virtual BlackMisc::Simulation::CSimulatedAircraftList getAircraftInRange() const override; - - //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::getAircraftInRangeCallsigns - //! \ingroup remoteaircraftprovider - virtual BlackMisc::Aviation::CCallsignSet getAircraftInRangeCallsigns() const override; - - //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::getAircraftInRangeCount - //! \ingroup remoteaircraftprovider - virtual int getAircraftInRangeCount() const override; - - //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::getAircraftInRangeForCallsign - //! \ingroup remoteaircraftprovider - virtual BlackMisc::Simulation::CSimulatedAircraft getAircraftInRangeForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override; - - //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::getAircraftInRangeModelForCallsign - //! \ingroup remoteaircraftprovider - virtual BlackMisc::Simulation::CAircraftModel getAircraftInRangeModelForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override; - - //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::getReverseLookupMessages - //! \ingroup remoteaircraftprovider - virtual BlackMisc::CStatusMessageList getReverseLookupMessages(const BlackMisc::Aviation::CCallsign &callsign) const override; - - //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::isReverseLookupLoggingEnabled - //! \ingroup remoteaircraftprovider - virtual bool isReverseLookupMessagesEnabled() const override; - - //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::enableReverseLookupLogging - //! \ingroup remoteaircraftprovider - virtual void enableReverseLookupMessages(bool enabled) override; - - //! \copydoc IContextNetwork::getOnlineStationForCallsign - virtual BlackMisc::Aviation::CAtcStation getOnlineStationForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override; - - //! \copydoc IContextNetwork::connectToNetwork() - virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, BlackCore::INetwork::LoginMode mode) override; - - //! \copydoc IContextNetwork::getConnectedServer - virtual BlackMisc::Network::CServer getConnectedServer() const override; - - //! \copydoc IContextNetwork::disconnectFromNetwork() - virtual BlackMisc::CStatusMessage disconnectFromNetwork() override; - - //! \copydoc IContextNetwork::isConnected() - virtual bool isConnected() const override; - - //! In transition state, e.g. connecting, disconnecting. - //! \details In such a state it is advisable to wait until an end state (connected/disconnected) is reached - //! \remarks Intentionally only running locally, not in interface - bool isPendingConnection() const; - - //! \ingroup commandline - //! @{ - //!
-        //! .m  .msg   message text
-        //! 
- //! @} - //! \copydoc IContextNetwork::parseCommandLine - virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override; - - //! \copydoc IContextNetwork::sendTextMessages() - virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &textMessages) override; - - //! \copydoc IContextNetwork::sendFlightPlan() - virtual void sendFlightPlan(const BlackMisc::Aviation::CFlightPlan &flightPlan) override; - - //! \copydoc IContextNetwork::loadFlightPlanFromNetwork() - virtual BlackMisc::Aviation::CFlightPlan loadFlightPlanFromNetwork(const BlackMisc::Aviation::CCallsign &callsign) const override; - - //! \copydoc IContextNetwork::getMetarForAirport - BlackMisc::Weather::CMetar getMetarForAirport(const BlackMisc::Aviation::CAirportIcaoCode &airportIcaoCode) const override; - - //! \copydoc IContextNetwork::getSelectedVoiceRooms() - virtual BlackMisc::Audio::CVoiceRoomList getSelectedVoiceRooms() const override; - - //! \copydoc IContextNetwork::getSelectedAtcStations - virtual BlackMisc::Aviation::CAtcStationList getSelectedAtcStations() const override; - - //! \copydoc IContextNetwork::getUsers() - virtual BlackMisc::Network::CUserList getUsers() const override; - - //! \copydoc IContextNetwork::getUsersForCallsigns - virtual BlackMisc::Network::CUserList getUsersForCallsigns(const BlackMisc::Aviation::CCallsignSet &callsigns) const override; - - //! \copydoc IContextNetwork::getUserForCallsign - virtual BlackMisc::Network::CUser getUserForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override; - - //! \copydoc IContextNetwork::getOtherClients - virtual BlackMisc::Network::CClientList getOtherClients() const override; - - //! \copydoc IContextNetwork::getOtherClientsForCallsigns - virtual BlackMisc::Network::CClientList getOtherClientsForCallsigns(const BlackMisc::Aviation::CCallsignSet &callsigns) const override; - - //! \copydoc IContextNetwork::getVatsimFsdServers - virtual BlackMisc::Network::CServerList getVatsimFsdServers() const override; - - //! \copydoc IContextNetwork::getVatsimVoiceServers - virtual BlackMisc::Network::CServerList getVatsimVoiceServers() const override; - - //! \copydoc IContextNetwork::requestDataUpdates - virtual void requestDataUpdates()override; - - //! \copydoc IContextNetwork::requestAtisUpdates - virtual void requestAtisUpdates() override; - - //! \copydoc IContextNetwork::setFastPositionEnabledCallsigns - virtual void setFastPositionEnabledCallsigns(BlackMisc::Aviation::CCallsignSet &callsigns) override; - - //! \copydoc IContextNetwork::getFastPositionEnabledCallsigns - virtual BlackMisc::Aviation::CCallsignSet getFastPositionEnabledCallsigns() override; - - //! \copydoc IContextNetwork::testCreateDummyOnlineAtcStations - virtual void testCreateDummyOnlineAtcStations(int number) override; - - //! \copydoc IContextNetwork::testAddAircraftParts - virtual void testAddAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftParts &parts, bool incremental) override; - - //! Gracefully shut down, e.g. for thread safety - void gracefulShutdown(); - - protected: - //! Constructor, with link to runtime - CContextNetwork(CCoreFacadeConfig::ContextMode, CCoreFacade *runtime); - - //! Register myself in DBus - CContextNetwork *registerWithDBus(BlackMisc::CDBusServer *server); - - private: - CAirspaceMonitor *m_airspace = nullptr; - INetwork *m_network = nullptr; - INetwork::ConnectionStatus m_currentStatus = INetwork::Disconnected; //!< used to detect pending connections - QTimer *m_networkDataUpdateTimer = nullptr; //!< general updates such as ATIS, frequencies, see requestDataUpdates() - - // Digest signals, only sending after some time - BlackMisc::CDigestSignal m_dsAtcStationsBookedChanged { this, &IContextNetwork::changedAtcStationsBooked, &IContextNetwork::changedAtcStationsBookedDigest, 750, 2 }; - BlackMisc::CDigestSignal m_dsAtcStationsOnlineChanged { this, &IContextNetwork::changedAtcStationsOnline, &IContextNetwork::changedAtcStationsOnlineDigest, 750, 4 }; - BlackMisc::CDigestSignal m_dsAircraftsInRangeChanged { this, &IContextNetwork::changedAircraftInRange, &IContextNetwork::changedAircraftInRangeDigest, 750, 4 }; - - //! Own aircraft from \sa CContextOwnAircraft - const BlackMisc::Simulation::CSimulatedAircraft ownAircraft() const; - - private slots: - //! Update METAR collection - void ps_updateMetars(const BlackMisc::Weather::CMetarList &metars); - - //! Check if a supervisor message was received - void ps_checkForSupervisiorTextMessage(const BlackMisc::Network::CTextMessageList &messages); - - //! Connection status changed - void ps_fsdConnectionStatusChanged(INetwork::ConnectionStatus from, INetwork::ConnectionStatus to); - - //! Render restrictions have been changed, used with analyzer - //! \sa CAirspaceAnalyzer - void ps_simulatorRenderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance, const BlackMisc::PhysicalQuantities::CLength &maxRenderedBoundary); - }; -} // ns - -#endif // guard diff --git a/src/blackcore/contextnetworkproxy.cpp b/src/blackcore/contextnetworkproxy.cpp deleted file mode 100644 index 0230d44a0..000000000 --- a/src/blackcore/contextnetworkproxy.cpp +++ /dev/null @@ -1,287 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "blackcore/contextnetworkproxy.h" -#include "blackmisc/audio/voiceroomlist.h" -#include "blackmisc/dbus.h" -#include "blackmisc/genericdbusinterface.h" - -#include -#include -#include -#include - -using namespace BlackMisc; -using namespace BlackMisc::Network; -using namespace BlackMisc::Aviation; -using namespace BlackMisc::Audio; -using namespace BlackMisc::Weather; -using namespace BlackMisc::Simulation; - -namespace BlackCore -{ - /* - * Constructor for DBus - */ - CContextNetworkProxy::CContextNetworkProxy(const QString &serviceName, QDBusConnection &connection, CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextNetwork(mode, runtime), m_dBusInterface(nullptr) - { - this->m_dBusInterface = new BlackMisc::CGenericDBusInterface( - serviceName , IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), - connection, this); - this->relaySignals(serviceName, connection); - } - - /* - * Workaround for signals, not working without, but why? - */ - void CContextNetworkProxy::relaySignals(const QString &serviceName, QDBusConnection &connection) - { - bool s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), - "connectionStatusChanged", this, SIGNAL(connectionStatusChanged(BlackCore::INetwork::ConnectionStatus, BlackCore::INetwork::ConnectionStatus))); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), - "changedAtcStationsBooked", this, SIGNAL(changedAtcStationsBooked())); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), - "changedAtcStationsOnline", this, SIGNAL(changedAtcStationsOnline())); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), - "changedAtcStationsBookedDigest", this, SIGNAL(changedAtcStationsBookedDigest())); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), - "changedAtcStationsOnlineDigest", this, SIGNAL(changedAtcStationsOnlineDigest())); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), - "changedAircraftInRange", this, SIGNAL(changedAircraftInRange())); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), - "changedAtcStationOnlineConnectionStatus", this, SIGNAL(changedAtcStationOnlineConnectionStatus(BlackMisc::Aviation::CAtcStation, bool))); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), - "changedAircraftInRangeDigest", this, SIGNAL(changedAircraftInRangeDigest())); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), - "connectionTerminated", this, SIGNAL(connectionTerminated())); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), - "textMessagesReceived", this, SIGNAL(textMessagesReceived(BlackMisc::Network::CTextMessageList))); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), - "textMessageSent", this, SIGNAL(textMessageSent(BlackMisc::Network::CTextMessage))); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), - "webServiceDataRead", this, SIGNAL(webServiceDataRead(int, int, int))); - - Q_ASSERT(s); - s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), - "changedRemoteAircraftEnabled", this, SIGNAL(changedRemoteAircraftEnabled(BlackMisc::Simulation::CSimulatedAircraft, BlackMisc::CIdentifier))); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), - "changedFastPositionUpdates", this, SIGNAL(changedFastPositionUpdates(BlackMisc::Simulation::CSimulatedAircraft, BlackMisc::CIdentifier))); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), - "addedAircraft", this, SIGNAL(addedAircraft(BlackMisc::Simulation::CSimulatedAircraft))); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextNetwork::ObjectPath(), IContextNetwork::InterfaceName(), - "removedAircraft", this, SIGNAL(removedAircraft(BlackMisc::Aviation::CCallsign))); - Q_ASSERT(s); - Q_UNUSED(s); - } - - void CContextNetworkProxy::readAtcBookingsFromSource() const - { - this->m_dBusInterface->callDBus(QLatin1Literal("readAtcBookingsFromSource")); - } - - BlackMisc::Aviation::CAtcStationList CContextNetworkProxy::getAtcStationsOnline() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getAtcStationsOnline")); - } - - CAtcStationList CContextNetworkProxy::getAtcStationsBooked() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getAtcStationsBooked")); - } - - CSimulatedAircraftList CContextNetworkProxy::getAircraftInRange() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getAircraftInRange")); - } - - CCallsignSet CContextNetworkProxy::getAircraftInRangeCallsigns() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getAircraftInRangeCallsigns")); - } - - int CContextNetworkProxy::getAircraftInRangeCount() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getAircraftInRangeCount")); - } - - CSimulatedAircraft CContextNetworkProxy::getAircraftInRangeForCallsign(const CCallsign &callsign) const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getAircraftInRangeForCallsign"), callsign); - } - - CAtcStation CContextNetworkProxy::getOnlineStationForCallsign(const CCallsign &callsign) const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getOnlineStationForCallsign"), callsign); - } - - CUserList CContextNetworkProxy::getUsers() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getUsers")); - } - - CUserList CContextNetworkProxy::getUsersForCallsigns(const BlackMisc::Aviation::CCallsignSet &callsigns) const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getUsersForCallsigns"), callsigns); - } - - CUser CContextNetworkProxy::getUserForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getUserForCallsign"), callsign); - } - - CClientList CContextNetworkProxy::getOtherClients() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getOtherClients")); - } - - CServerList CContextNetworkProxy::getVatsimFsdServers() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getVatsimFsdServers")); - } - - CServerList CContextNetworkProxy::getVatsimVoiceServers() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getVatsimVoiceServers")); - } - - CClientList CContextNetworkProxy::getOtherClientsForCallsigns(const BlackMisc::Aviation::CCallsignSet &callsigns) const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getOtherClientsForCallsigns"), callsigns); - } - - CVoiceRoomList CContextNetworkProxy::getSelectedVoiceRooms() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getSelectedVoiceRooms")); - } - - CAtcStationList CContextNetworkProxy::getSelectedAtcStations() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getSelectedAtcStations")); - } - - void CContextNetworkProxy::requestDataUpdates() - { - this->m_dBusInterface->callDBus(QLatin1Literal("requestDataUpdates")); - } - - void CContextNetworkProxy::requestAtisUpdates() - { - this->m_dBusInterface->callDBus(QLatin1Literal("requestAtisUpdates")); - } - - bool CContextNetworkProxy::updateAircraftEnabled(const CCallsign &callsign, bool enabledForRedering, const CIdentifier &originator) - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("updateAircraftEnabled"), callsign, enabledForRedering, originator); - } - - bool CContextNetworkProxy::updateAircraftModel(const CCallsign &callsign, const CAircraftModel &model, const CIdentifier &originator) - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("updateAircraftModel"), callsign, model, originator); - } - - bool CContextNetworkProxy::updateFastPositionEnabled(const CCallsign &callsign, bool enableFastPositionSending, const CIdentifier &originator) - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("updateFastPositionEnabled"), callsign, enableFastPositionSending, originator); - } - - void CContextNetworkProxy::setFastPositionEnabledCallsigns(CCallsignSet &callsigns) - { - this->m_dBusInterface->callDBus(QLatin1Literal("setFastPositionEnabledCallsigns"), callsigns); - } - - CCallsignSet CContextNetworkProxy::getFastPositionEnabledCallsigns() - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getFastPositionEnabledCallsigns")); - } - - CStatusMessageList CContextNetworkProxy::getReverseLookupMessages(const CCallsign &callsign) const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getReverseLookupMessages"), callsign); - } - - bool CContextNetworkProxy::isReverseLookupMessagesEnabled() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("isReverseLookupLoggingEnabled")); - } - - void CContextNetworkProxy::enableReverseLookupMessages(bool enabled) - { - this->m_dBusInterface->callDBus(QLatin1Literal("enableReverseLookupLogging"), enabled); - } - - void CContextNetworkProxy::testCreateDummyOnlineAtcStations(int number) - { - this->m_dBusInterface->callDBus(QLatin1Literal("testCreateDummyOnlineAtcStations"), number); - } - - void CContextNetworkProxy::testAddAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, const CAircraftParts &parts, bool incremental) - { - this->m_dBusInterface->callDBus(QLatin1Literal("testAddAircraftParts"), callsign, parts, incremental); - } - - CStatusMessage CContextNetworkProxy::connectToNetwork(const CServer &server, INetwork::LoginMode loginMode) - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("connectToNetwork"), server, loginMode); - } - - CStatusMessage CContextNetworkProxy::disconnectFromNetwork() - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("disconnectFromNetwork")); - } - - bool CContextNetworkProxy::isConnected() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("isConnected")); - } - - CServer CContextNetworkProxy::getConnectedServer() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getConnectedServer")); - } - - bool CContextNetworkProxy::parseCommandLine(const QString &commandLine, const CIdentifier &originator) - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("parseCommandLine"), commandLine, originator); - } - - void CContextNetworkProxy::sendTextMessages(const CTextMessageList &textMessages) - { - this->m_dBusInterface->callDBus(QLatin1Literal("sendTextMessages"), textMessages); - } - - void CContextNetworkProxy::sendFlightPlan(const BlackMisc::Aviation::CFlightPlan &flightPlan) - { - this->m_dBusInterface->callDBus(QLatin1Literal("sendFlightPlan"), flightPlan); - } - - CFlightPlan CContextNetworkProxy::loadFlightPlanFromNetwork(const CCallsign &callsign) const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("loadFlightPlanFromNetwork"), callsign); - } - - CMetar CContextNetworkProxy::getMetarForAirport(const CAirportIcaoCode &airportIcaoCode) const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getMetarForAirport"), airportIcaoCode); - } - -} // namespace diff --git a/src/blackcore/contextnetworkproxy.h b/src/blackcore/contextnetworkproxy.h deleted file mode 100644 index 5360fe5c7..000000000 --- a/src/blackcore/contextnetworkproxy.h +++ /dev/null @@ -1,202 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKCORE_CONTEXTNETWORK_PROXY_H -#define BLACKCORE_CONTEXTNETWORK_PROXY_H - -#include "blackcore/blackcoreexport.h" -#include "blackcore/contextnetwork.h" -#include "blackcore/corefacadeconfig.h" -#include "blackcoreexport.h" -#include "blackmisc/audio/voiceroomlist.h" -#include "blackmisc/aviation/airporticaocode.h" -#include "blackmisc/aviation/atcstation.h" -#include "blackmisc/aviation/atcstationlist.h" -#include "blackmisc/aviation/callsignset.h" -#include "blackmisc/aviation/flightplan.h" -#include "blackmisc/identifier.h" -#include "blackmisc/network/clientlist.h" -#include "blackmisc/network/network.h" -#include "blackmisc/network/server.h" -#include "blackmisc/network/serverlist.h" -#include "blackmisc/network/textmessagelist.h" -#include "blackmisc/network/user.h" -#include "blackmisc/network/userlist.h" -#include "blackmisc/simulation/simulatedaircraft.h" -#include "blackmisc/simulation/simulatedaircraftlist.h" -#include "blackmisc/statusmessage.h" -#include "blackmisc/weather/metar.h" - -#include -#include -#include - -class QDBusConnection; - -namespace BlackMisc -{ - class CGenericDBusInterface; - namespace Aviation - { - class CAircraftParts; - class CCallsign; - } - namespace Simulation { class CAircraftModel; } -} - -namespace BlackCore -{ - class CCoreFacade; - - //! Network context proxy - //! \ingroup dbus - class BLACKCORE_EXPORT CContextNetworkProxy : public IContextNetwork - { - Q_OBJECT - friend class IContextNetwork; - - public: - - //! Destructor - virtual ~CContextNetworkProxy() {} - - private: - BlackMisc::CGenericDBusInterface *m_dBusInterface; /*!< DBus interface */ - - //! Relay connection signals to local signals. - void relaySignals(const QString &serviceName, QDBusConnection &connection); - - protected: - //! Constructor - CContextNetworkProxy(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextNetwork(mode, runtime), m_dBusInterface(nullptr) {} - - //! DBus version constructor - CContextNetworkProxy(const QString &serviceName, QDBusConnection &connection, CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime); - - public slots: // IContextNetwork overrides - - //! \copydoc IContextNetwork::readAtcBookingsFromSource() - virtual void readAtcBookingsFromSource() const override; - - //! \copydoc IContextNetwork::getAtcStationsOnline() - virtual BlackMisc::Aviation::CAtcStationList getAtcStationsOnline() const override; - - //! \copydoc IContextNetwork::getAtcStationsBooked() - virtual BlackMisc::Aviation::CAtcStationList getAtcStationsBooked() const override; - - //! \copydoc IContextNetwork::getAircraftInRange() - virtual BlackMisc::Simulation::CSimulatedAircraftList getAircraftInRange() const override; - - //! \copydoc IContextNetwork::getAircraftInRangeCallsigns() - virtual BlackMisc::Aviation::CCallsignSet getAircraftInRangeCallsigns() const override; - - //! \copydoc IContextNetwork::getAircraftInRangeCount - virtual int getAircraftInRangeCount() const override; - - //! \copydoc IContextNetwork::getAircraftInRangeForCallsign - virtual BlackMisc::Simulation::CSimulatedAircraft getAircraftInRangeForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override; - - //! \copydoc IContextNetwork::getOnlineStationForCallsign - virtual BlackMisc::Aviation::CAtcStation getOnlineStationForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override; - - //! \copydoc IContextNetwork::connectToNetwork - virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, BlackCore::INetwork::LoginMode mode) override; - - //! \copydoc IContextNetwork::disconnectFromNetwork() - virtual BlackMisc::CStatusMessage disconnectFromNetwork() override; - - //! \copydoc IContextNetwork::isConnected() - virtual bool isConnected() const override; - - //! \copydoc IContextNetwork::getConnectedServer - virtual BlackMisc::Network::CServer getConnectedServer() const override; - - //! \copydoc IContextNetwork::parseCommandLine - virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override; - - //! \copydoc IContextNetwork::sendTextMessages() - virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &textMessages) override; - - //! \copydoc IContextNetwork::sendFlightPlan() - virtual void sendFlightPlan(const BlackMisc::Aviation::CFlightPlan &flightPlan) override; - - //! \copydoc IContextNetwork::loadFlightPlanFromNetwork() - virtual BlackMisc::Aviation::CFlightPlan loadFlightPlanFromNetwork(const BlackMisc::Aviation::CCallsign &callsign) const override; - - //! \copydoc IContextNetwork::getMetarForAirport - BlackMisc::Weather::CMetar getMetarForAirport(const BlackMisc::Aviation::CAirportIcaoCode &airportIcaoCode) const override; - - //! \copydoc IContextNetwork::getSelectedVoiceRooms() - virtual BlackMisc::Audio::CVoiceRoomList getSelectedVoiceRooms() const override; - - //! \copydoc IContextNetwork::getSelectedAtcStations - virtual BlackMisc::Aviation::CAtcStationList getSelectedAtcStations() const override; - - //! \copydoc IContextNetwork::getUsers() - virtual BlackMisc::Network::CUserList getUsers() const override; - - //! \copydoc IContextNetwork::getUsersForCallsigns - virtual BlackMisc::Network::CUserList getUsersForCallsigns(const BlackMisc::Aviation::CCallsignSet &callsigns) const override; - - //! \copydoc IContextNetwork::getUserForCallsign - virtual BlackMisc::Network::CUser getUserForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override; - - //! \copydoc IContextNetwork::getOtherClients - virtual BlackMisc::Network::CClientList getOtherClients() const override; - - //! \copydoc IContextNetwork::getVatsimVoiceServers - virtual BlackMisc::Network::CServerList getVatsimVoiceServers() const override; - - //! \copydoc IContextNetwork::getVatsimFsdServers - virtual BlackMisc::Network::CServerList getVatsimFsdServers() const override; - - //! \copydoc IContextNetwork::getOtherClientsForCallsigns - virtual BlackMisc::Network::CClientList getOtherClientsForCallsigns(const BlackMisc::Aviation::CCallsignSet &callsigns) const override; - - //! \copydoc IContextNetwork::requestDataUpdates - virtual void requestDataUpdates()override; - - //! \copydoc IContextNetwork::requestAtisUpdates - virtual void requestAtisUpdates() override; - - //! \copydoc IContextNetwork::updateAircraftEnabled - virtual bool updateAircraftEnabled(const BlackMisc::Aviation::CCallsign &callsign, bool enabledForRedering, const BlackMisc::CIdentifier &originator) override; - - //! \copydoc IContextNetwork::updateAircraftModel - virtual bool updateAircraftModel(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Simulation::CAircraftModel &model, const BlackMisc::CIdentifier &originator) override; - - //! \copydoc IContextNetwork::updateFastPositionEnabled - virtual bool updateFastPositionEnabled(const BlackMisc::Aviation::CCallsign &callsign, bool enableFastPositionSending, const BlackMisc::CIdentifier &originator) override; - - //! \copydoc IContextNetwork::setFastPositionEnabledCallsigns - virtual void setFastPositionEnabledCallsigns(BlackMisc::Aviation::CCallsignSet &callsigns) override; - - //! \copydoc IContextNetwork::getFastPositionEnabledCallsigns - virtual BlackMisc::Aviation::CCallsignSet getFastPositionEnabledCallsigns() override; - - //! \copydoc IContextNetwork::getReverseLookupMessages - virtual BlackMisc::CStatusMessageList getReverseLookupMessages(const BlackMisc::Aviation::CCallsign &callsign) const override; - - //! \copydoc IContextNetwork::isReverseLookupMessagesEnabled - virtual bool isReverseLookupMessagesEnabled() const override; - - //! \copydoc IContextNetwork::enableReverseLookupMessages - virtual void enableReverseLookupMessages(bool enabled) override; - - //! \copydoc IContextNetwork::testCreateDummyOnlineAtcStations - virtual void testCreateDummyOnlineAtcStations(int number) override; - - //! \copydoc IContextNetwork::testAddAircraftParts - virtual void testAddAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftParts &parts, bool incremental) override; - }; -} - -#endif // guard diff --git a/src/blackcore/contextownaircraft.cpp b/src/blackcore/contextownaircraft.cpp deleted file mode 100644 index b2687e893..000000000 --- a/src/blackcore/contextownaircraft.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "blackcore/contextownaircraft.h" -#include "blackcore/contextownaircraftempty.h" -#include "blackcore/contextownaircraftimpl.h" -#include "blackcore/contextownaircraftproxy.h" -#include "blackmisc/dbusserver.h" - -namespace BlackCore -{ - IContextOwnAircraft *IContextOwnAircraft::create(CCoreFacade *parent, CCoreFacadeConfig::ContextMode mode, BlackMisc::CDBusServer *server, QDBusConnection &conn) - { - switch (mode) - { - case CCoreFacadeConfig::Local: - case CCoreFacadeConfig::LocalInDbusServer: - return (new CContextOwnAircraft(mode, parent))->registerWithDBus(server); - case CCoreFacadeConfig::Remote: - return new CContextOwnAircraftProxy(BlackMisc::CDBusServer::coreServiceName(), conn, mode, parent); - case CCoreFacadeConfig::NotUsed: - default: - return new CContextOwnAircraftEmpty(parent); - } - } -} // namespace diff --git a/src/blackcore/contextownaircraft.h b/src/blackcore/contextownaircraft.h deleted file mode 100644 index 825f3b46b..000000000 --- a/src/blackcore/contextownaircraft.h +++ /dev/null @@ -1,152 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKCORE_CONTEXTOWNAIRCRAFT_H -#define BLACKCORE_CONTEXTOWNAIRCRAFT_H - -#include "blackcore/blackcoreexport.h" -#include "blackcore/context.h" -#include "blackcore/corefacade.h" -#include "blackcore/corefacadeconfig.h" -#include "blackmisc/aviation/airlineicaocode.h" -#include "blackmisc/aviation/comsystem.h" -#include "blackmisc/aviation/selcal.h" -#include "blackmisc/geo/coordinategeodetic.h" -#include "blackmisc/identifier.h" -#include "blackmisc/network/user.h" -#include "blackmisc/pq/frequency.h" -#include "blackmisc/simulation/simulatedaircraft.h" - -#include -#include - -class QDBusConnection; - -namespace BlackMisc -{ - class CDBusServer; - namespace Aviation - { - class CAircraftIcaoCode; - class CAltitude; - class CCallsign; - class CTransponder; - } -} - -//! \addtogroup dbus -//! @{ - -//! DBus interface for context -#define BLACKCORE_CONTEXTOWNAIRCRAFT_INTERFACENAME "org.swift_project.blackcore.contextownaircraft" - -//! DBus object path for context -#define BLACKCORE_CONTEXTOWNAIRCRAFT_OBJECTPATH "/ownaircraft" - -//! @} - -namespace BlackCore -{ - - //! Own context proxy - //! \ingroup dbus - class BLACKCORE_EXPORT IContextOwnAircraft : public CContext - { - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTOWNAIRCRAFT_INTERFACENAME) - - public: - //! DBus interface name - static const QString &InterfaceName() - { - static QString s(BLACKCORE_CONTEXTOWNAIRCRAFT_INTERFACENAME); - return s; - } - - //! DBus object path - static const QString &ObjectPath() - { - static QString s(BLACKCORE_CONTEXTOWNAIRCRAFT_OBJECTPATH); - return s; - } - - //! \copydoc CContext::getPathAndContextId() - virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); } - - //! Factory method - static IContextOwnAircraft *create(CCoreFacade *parent, CCoreFacadeConfig::ContextMode mode, BlackMisc::CDBusServer *server, QDBusConnection &conn); - - //! Destructor - virtual ~IContextOwnAircraft() {} - - signals: - //! Aircraft cockpit update - void changedAircraftCockpit(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator); - - //! Changed SELCAL code - void changedSelcal(const BlackMisc::Aviation::CSelcal &selcal, const BlackMisc::CIdentifier &originator); - - //! Own callsign was changed - void changedCallsign(const BlackMisc::Aviation::CCallsign &callsign); - - //! Own ICAO was changed - void changedAircraftIcaoCodes(const BlackMisc::Aviation::CAircraftIcaoCode &aircraftIcaoCode, const BlackMisc::Aviation::CAirlineIcaoCode &airlineIcaoCode); - - //! own pilot (aka the swift user) changed - void changedPilot(const BlackMisc::Network::CUser &pilot); - - public slots: - //! Get own aircraft - virtual BlackMisc::Simulation::CSimulatedAircraft getOwnAircraft() const = 0; - - //! Update position - //! \note this is in \sa IContextOwnAircraft as we want to set test positions from the GUI / elsewhere - virtual bool updateOwnPosition(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::Aviation::CAltitude &altitude) = 0; - - //! Update own cockpit - virtual bool updateCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const BlackMisc::CIdentifier &originator) = 0; - - //! Tune in a com frequency - virtual bool updateActiveComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, BlackMisc::Aviation::CComSystem::ComUnit comUnit, const BlackMisc::CIdentifier &originator) = 0; - - //! Set current pilot - virtual bool updateOwnAircraftPilot(const BlackMisc::Network::CUser &pilot) = 0; - - //! Set ICAO data - virtual bool updateOwnIcaoCodes(const BlackMisc::Aviation::CAircraftIcaoCode &aircraftIcaoCode, const BlackMisc::Aviation::CAirlineIcaoCode &airlineIcaoCode) = 0; - - //! Set callsign - virtual bool updateOwnCallsign(const BlackMisc::Aviation::CCallsign &callsign) = 0; - - //! Own SELCAL code - virtual bool updateSelcal(const BlackMisc::Aviation::CSelcal &selcal, const BlackMisc::CIdentifier &originator) = 0; - - //! Output volume 0..300 - virtual void setAudioOutputVolume(int outputVolume) = 0; - - //! Set individual voice rooms (overrides voice rooms) - //! \note Empty string "" disables voice room override - //! \sa enableAutomaticVoiceRoomResolution - virtual void setAudioVoiceRoomOverrideUrls(const QString &voiceRoom1Url, const QString &voiceRoom2Url) = 0; - - //! Automatic voice room resolution for frequencies - virtual void enableAutomaticVoiceRoomResolution(bool enable) = 0; - - //! Parse command line - virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) = 0; - - protected: - //! Constructor - IContextOwnAircraft(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : CContext(mode, runtime) {} - }; -} - -#endif // guard diff --git a/src/blackcore/contextownaircraftempty.h b/src/blackcore/contextownaircraftempty.h deleted file mode 100644 index 943ee1f62..000000000 --- a/src/blackcore/contextownaircraftempty.h +++ /dev/null @@ -1,134 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKCORE_CONTEXTOWNAIRCRAFT_EMPTY_H -#define BLACKCORE_CONTEXTOWNAIRCRAFT_EMPTY_H - -#include "blackcoreexport.h" -#include "contextownaircraft.h" -#include "blackmisc/logmessage.h" - -namespace BlackCore -{ - //! Empty context, used during shutdown/initialization - class BLACKCORE_EXPORT CContextOwnAircraftEmpty : public IContextOwnAircraft - { - Q_OBJECT - - public: - //! Constructor - CContextOwnAircraftEmpty(CCoreFacade *runtime) : IContextOwnAircraft(CCoreFacadeConfig::NotUsed, runtime) {} - - public slots: - //! \copydoc IContextOwnAircraft::getOwnAircraft() - virtual BlackMisc::Simulation::CSimulatedAircraft getOwnAircraft() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Simulation::CSimulatedAircraft(); - } - - //! \copydoc IContextOwnAircraft::updateOwnPosition - virtual bool updateOwnPosition(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::Aviation::CAltitude &altitude) override - { - Q_UNUSED(position); - Q_UNUSED(altitude); - logEmptyContextWarning(Q_FUNC_INFO); - return false; - } - - //! \copydoc IContextOwnAircraft::updateCockpit - virtual bool updateCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const BlackMisc::CIdentifier &originator) override - { - Q_UNUSED(com1); - Q_UNUSED(com2); - Q_UNUSED(transponder); - Q_UNUSED(originator); - logEmptyContextWarning(Q_FUNC_INFO); - return false; - } - - //! \copydoc IContextOwnAircraft::updateActiveComFrequency - virtual bool updateActiveComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, BlackMisc::Aviation::CComSystem::ComUnit comUnit, const BlackMisc::CIdentifier &originator) override - { - Q_UNUSED(frequency); - Q_UNUSED(comUnit); - Q_UNUSED(originator); - logEmptyContextWarning(Q_FUNC_INFO); - return false; - } - - //! \copydoc IContextOwnAircraft::updateOwnAircraftPilot - virtual bool updateOwnAircraftPilot(const BlackMisc::Network::CUser &pilot) override - { - Q_UNUSED(pilot); - logEmptyContextWarning(Q_FUNC_INFO); - return false; - } - - //! \copydoc IContextOwnAircraft::updateSelcal - virtual bool updateSelcal(const BlackMisc::Aviation::CSelcal &selcal, const BlackMisc::CIdentifier &originator) override - { - Q_UNUSED(selcal); - Q_UNUSED(originator); - logEmptyContextWarning(Q_FUNC_INFO); - return false; - } - - //! \copydoc IContextOwnAircraft::updateOwnCallsign - virtual bool updateOwnCallsign(const BlackMisc::Aviation::CCallsign &callsign) override - { - Q_UNUSED(callsign); - logEmptyContextWarning(Q_FUNC_INFO); - return false; - } - - //! \copydoc IContextOwnAircraft::updateOwnIcaoCodes - virtual bool updateOwnIcaoCodes(const BlackMisc::Aviation::CAircraftIcaoCode &aircraftIcaoCode, const BlackMisc::Aviation::CAirlineIcaoCode &airlineIcaoCode) override - { - Q_UNUSED(aircraftIcaoCode); - Q_UNUSED(airlineIcaoCode); - logEmptyContextWarning(Q_FUNC_INFO); - return false; - } - - //! \copydoc IContextOwnAircraft::setAudioOutputVolume - virtual void setAudioOutputVolume(int outputVolume) override - { - Q_UNUSED(outputVolume); - } - - //! \copydoc IContextOwnAircraft::setAudioVoiceRoomOverrideUrls - virtual void setAudioVoiceRoomOverrideUrls(const QString &voiceRoom1Url, const QString &voiceRoom2Url) override - { - Q_UNUSED(voiceRoom1Url); - Q_UNUSED(voiceRoom2Url); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextOwnAircraft::enableAutomaticVoiceRoomResolution - virtual void enableAutomaticVoiceRoomResolution(bool enable) override - { - Q_UNUSED(enable); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextOwnAircraft::parseCommandLine - virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override - { - Q_UNUSED(commandLine); - Q_UNUSED(originator); - logEmptyContextWarning(Q_FUNC_INFO); - return false; - } - }; -} // namespace - -#endif // guard diff --git a/src/blackcore/contextownaircraftimpl.cpp b/src/blackcore/contextownaircraftimpl.cpp deleted file mode 100644 index 7a783c8b1..000000000 --- a/src/blackcore/contextownaircraftimpl.cpp +++ /dev/null @@ -1,383 +0,0 @@ -/* Copyright (C) 2014 - * swift project community / contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "blackcore/contextapplication.h" -#include "blackcore/contextaudio.h" -#include "blackcore/contextnetwork.h" -#include "blackcore/contextownaircraftimpl.h" -#include "blackmisc/audio/voiceroom.h" -#include "blackmisc/audio/voiceroomlist.h" -#include "blackmisc/aviation/aircrafticaocode.h" -#include "blackmisc/aviation/aircraftsituation.h" -#include "blackmisc/aviation/altitude.h" -#include "blackmisc/aviation/callsign.h" -#include "blackmisc/aviation/transponder.h" -#include "blackmisc/compare.h" -#include "blackmisc/dbusserver.h" -#include "blackmisc/geo/latitude.h" -#include "blackmisc/geo/longitude.h" -#include "blackmisc/logcategory.h" -#include "blackmisc/logmessage.h" -#include "blackmisc/network/server.h" -#include "blackmisc/pq/physicalquantity.h" -#include "blackmisc/pq/units.h" -#include "blackmisc/sequence.h" -#include "blackmisc/simplecommandparser.h" -#include "blackmisc/statusmessage.h" - -#include -#include -#include - -using namespace BlackMisc; -using namespace BlackMisc::PhysicalQuantities; -using namespace BlackMisc::Aviation; -using namespace BlackMisc::Network; -using namespace BlackMisc::Geo; -using namespace BlackMisc::Audio; -using namespace BlackMisc::Simulation; - -namespace BlackCore -{ - CContextOwnAircraft::CContextOwnAircraft(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : - IContextOwnAircraft(mode, runtime), - CIdentifiable(this) - { - Q_ASSERT(this->getRuntime()); - this->setObjectName("CContextOwnAircraft"); - - // Init own aircraft - this->initOwnAircraft(); - } - - CContextOwnAircraft *CContextOwnAircraft::registerWithDBus(CDBusServer *server) - { - if (!server || this->m_mode != CCoreFacadeConfig::LocalInDbusServer) return this; - server->addObject(IContextOwnAircraft::ObjectPath(), this); - return this; - } - - CContextOwnAircraft::~CContextOwnAircraft() { } - - CSimulatedAircraft CContextOwnAircraft::getOwnAircraft() const - { - if (this->m_debugEnabled) {CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - QReadLocker l(&m_lockAircraft); - return this->m_ownAircraft; - } - - CCoordinateGeodetic CContextOwnAircraft::getOwnAircraftPosition() const - { - QReadLocker l(&m_lockAircraft); - return this->m_ownAircraft.getPosition(); - } - - CAircraftParts CContextOwnAircraft::getOwnAircraftParts() const - { - QReadLocker l(&m_lockAircraft); - return this->m_ownAircraft.getParts(); - } - - CAircraftModel CContextOwnAircraft::getOwnAircraftModel() const - { - QReadLocker l(&m_lockAircraft); - return this->m_ownAircraft.getModel(); - } - - CLength CContextOwnAircraft::getDistanceToOwnAircraft(const ICoordinateGeodetic &position) const - { - return getOwnAircraft().calculateGreatCircleDistance(position); - } - - void CContextOwnAircraft::initOwnAircraft() - { - Q_ASSERT(this->getRuntime()); - { - QWriteLocker l(&m_lockAircraft); - this->m_ownAircraft.initComSystems(); - this->m_ownAircraft.initTransponder(); - CAircraftSituation situation( - CCoordinateGeodetic( - CLatitude::fromWgs84("N 049° 18' 17"), - CLongitude::fromWgs84("E 008° 27' 05"), - CLength(0, CLengthUnit::m())), - CAltitude(312, CAltitude::MeanSeaLevel, CLengthUnit::ft()) - ); - this->m_ownAircraft.setSituation(situation); - this->m_ownAircraft.setPilot(this->m_currentNetworkServer.getThreadLocal().getUser()); - - // from simulator, if available - this->m_ownAircraft.setCallsign(CCallsign("SWIFT")); // would come from settings - - //! \todo Own aircraft ICAO default data, this would need to come from somewhere (mappings) -> Own callsign, plane ICAO status, model used - this->m_ownAircraft.setIcaoCodes( - CAircraftIcaoCode("C172", "L1P"), - CAirlineIcaoCode() - ); - } - - // voice rooms, if network is already available - if (this->getIContextNetwork()) - { - this->resolveVoiceRooms(); - } - } - - void CContextOwnAircraft::resolveVoiceRooms() - { - Q_ASSERT(this->getIContextAudio()); - Q_ASSERT(this->getIContextNetwork()); - Q_ASSERT(this->getIContextApplication()); - if (!this->getIContextNetwork() || !this->getIContextAudio() || !this->getIContextApplication()) { return; } // no chance to resolve rooms - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - - if (this->m_voiceRoom1UrlOverride.isEmpty() && this->m_voiceRoom2UrlOverride.isEmpty() && !this->m_automaticVoiceRoomResolution) { return; } - if (!this->m_automaticVoiceRoomResolution) { return; } // not responsible - - // requires correct frequencies set - // but local network uses exactly this object here, so if frequencies are set here, - // they are for network context as well - CVoiceRoomList rooms = this->getIContextNetwork()->getSelectedVoiceRooms(); - - if (!this->m_voiceRoom1UrlOverride.isEmpty()) rooms[0] = CVoiceRoom(this->m_voiceRoom1UrlOverride); - if (!this->m_voiceRoom2UrlOverride.isEmpty()) rooms[1] = CVoiceRoom(this->m_voiceRoom2UrlOverride); - - // set the rooms - emit this->getIContextApplication()->fakedSetComVoiceRoom(rooms); - } - - bool CContextOwnAircraft::updateOwnModel(const CAircraftModel &model) - { - QWriteLocker l(&m_lockAircraft); - bool changed = (this->m_ownAircraft.getModel() != model); - if (!changed) { return false; } - this->m_ownAircraft.setModel(model); - return true; - } - - bool CContextOwnAircraft::updateOwnSituation(const CAircraftSituation &situation) - { - QWriteLocker l(&m_lockAircraft); - // there is intentionally no equal check - this->m_ownAircraft.setSituation(situation); - return true; - } - - bool CContextOwnAircraft::updateOwnParts(const CAircraftParts &parts) - { - QWriteLocker l(&m_lockAircraft); - bool changed = (this->m_ownAircraft.getParts() != parts); - if (!changed) { return false; } - this->m_ownAircraft.setParts(parts); - return true; - } - - bool CContextOwnAircraft::updateOwnPosition(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::Aviation::CAltitude &altitude) - { - if (this->m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << position << altitude; } - QWriteLocker l(&m_lockAircraft); - bool changed = (this->m_ownAircraft.getPosition() != position); - if (changed) { this->m_ownAircraft.setPosition(position); } - - if (this->m_ownAircraft.getAltitude() != altitude) - { - changed = true; - this->m_ownAircraft.setAltitude(altitude); - } - return changed; - } - - bool CContextOwnAircraft::updateCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const CIdentifier &originator) - { - if (this->m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << com1 << com2 << transponder; } - bool changed; - { - QWriteLocker l(&m_lockAircraft); - changed = this->m_ownAircraft.hasChangedCockpitData(com1, com2, transponder); - if (changed) { this->m_ownAircraft.setCockpit(com1, com2, transponder); } - } - if (changed) - { - emit this->changedAircraftCockpit(this->m_ownAircraft, originator); - this->resolveVoiceRooms(); - } - return changed; - } - - bool CContextOwnAircraft::updateActiveComFrequency(const CFrequency &frequency, BlackMisc::Aviation::CComSystem::ComUnit unit, const CIdentifier &originator) - { - if (unit != CComSystem::Com1 && unit != CComSystem::Com2) { return false; } - if (!CComSystem::isValidComFrequency(frequency)) { return false; } - CComSystem com1, com2; - CTransponder xpdr; - { - QReadLocker l(&m_lockAircraft); - com1 = this->m_ownAircraft.getCom1System(); - com2 = this->m_ownAircraft.getCom2System(); - xpdr = this->m_ownAircraft.getTransponder(); - } - if (unit == CComSystem::Com1) - { - com1.setFrequencyActive(frequency); - } - else - { - com2.setFrequencyActive(frequency); - } - return updateCockpit(com1, com2, xpdr, originator); - } - - bool CContextOwnAircraft::updateOwnAircraftPilot(const CUser &pilot) - { - { - QWriteLocker l(&m_lockAircraft); - if (this->m_ownAircraft.getPilot() == pilot) { return false; } - this->m_ownAircraft.setPilot(pilot); - } - emit changedPilot(pilot); - return true; - } - - bool CContextOwnAircraft::updateOwnCallsign(const CCallsign &callsign) - { - { - QWriteLocker l(&m_lockAircraft); - if (this->m_ownAircraft.getCallsign() == callsign) { return false; } - this->m_ownAircraft.setCallsign(callsign); - } - emit changedCallsign(callsign); - return true; - } - - bool CContextOwnAircraft::updateOwnIcaoCodes(const BlackMisc::Aviation::CAircraftIcaoCode &aircraftIcaoCode, const BlackMisc::Aviation::CAirlineIcaoCode &airlineIcaoCode) - { - { - QWriteLocker l(&m_lockAircraft); - return this->m_ownAircraft.setIcaoCodes(aircraftIcaoCode, airlineIcaoCode); - } - emit changedAircraftIcaoCodes(aircraftIcaoCode, airlineIcaoCode); - } - - bool CContextOwnAircraft::updateSelcal(const CSelcal &selcal, const CIdentifier &originator) - { - { - QWriteLocker l(&m_lockAircraft); - if (this->m_ownAircraft.getSelcal() == selcal) { return false; } - this->m_ownAircraft.setSelcal(selcal); - } - emit this->changedSelcal(selcal, originator); - return true; - } - - void CContextOwnAircraft::setAudioOutputVolume(int outputVolume) - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << outputVolume; } - if (this->getIContextAudio()) this->getIContextAudio()->setVoiceOutputVolume(outputVolume); - } - - void CContextOwnAircraft::ps_changedAtcStationOnlineConnectionStatus(const CAtcStation &atcStation, bool connected) - { - // any of our active frequencies? - Q_UNUSED(connected); - CSimulatedAircraft myAircraft(getOwnAircraft()); - if (atcStation.getFrequency() != myAircraft.getCom1System().getFrequencyActive() && atcStation.getFrequency() != myAircraft.getCom2System().getFrequencyActive()) { return; } - this->resolveVoiceRooms(); - } - - void CContextOwnAircraft::ps_changedSimulatorModel(const CSimulatedAircraft &ownAircraft) - { - CAircraftModel model(ownAircraft.getModel()); - QWriteLocker l(&m_lockAircraft); - this->m_ownAircraft.setModel(model); - } - - void CContextOwnAircraft::setAudioVoiceRoomOverrideUrls(const QString &voiceRoom1Url, const QString &voiceRoom2Url) - { - if (this->m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << voiceRoom1Url << voiceRoom2Url; } - this->m_voiceRoom1UrlOverride = voiceRoom1Url.trimmed(); - this->m_voiceRoom2UrlOverride = voiceRoom2Url.trimmed(); - this->resolveVoiceRooms(); - } - - void CContextOwnAircraft::enableAutomaticVoiceRoomResolution(bool enable) - { - if (this->m_debugEnabled) {CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << enable; } - this->m_automaticVoiceRoomResolution = enable; - } - - bool CContextOwnAircraft::parseCommandLine(const QString &commandLine, const CIdentifier &originator) - { - Q_UNUSED(originator); - if (commandLine.isEmpty()) { return false; } - CSimpleCommandParser parser( - { - ".x", ".xpdr", // transponder - ".com1", ".com2", // com1, com2 frequencies - ".c1", ".c2", // com1, com2 frequencies - ".selcal" - }); - parser.parse(commandLine); - if (!parser.isKnownCommand()) { return false; } - - CSimulatedAircraft myAircraft(this->getOwnAircraft()); - if (parser.matchesCommand(".x", ".xpdr") && parser.countParts() > 1) - { - CTransponder transponder = myAircraft.getTransponder(); - int xprCode = parser.toInt(1); - if (CTransponder::isValidTransponderCode(xprCode)) - { - transponder.setTransponderCode(xprCode); - // todo RW: replace originator - this->updateCockpit(myAircraft.getCom1System(), myAircraft.getCom2System(), transponder, CIdentifier("commandline")); - return true; - } - else - { - CTransponder::TransponderMode mode = CTransponder::modeFromString(parser.part(1)); - transponder.setTransponderMode(mode); - // todo RW: replace originator - this->updateCockpit(myAircraft.getCom1System(), myAircraft.getCom2System(), transponder, CIdentifier("commandline")); - return true; - } - } - else if (parser.commandStartsWith("com") || parser.commandStartsWith("c")) - { - CFrequency frequency(parser.toDouble(1), CFrequencyUnit::MHz()); - if (CComSystem::isValidComFrequency(frequency)) - { - CComSystem com1 = myAircraft.getCom1System(); - CComSystem com2 = myAircraft.getCom2System(); - if (parser.commandEndsWith("1")) - { - com1.setFrequencyActive(frequency); - } - else if (parser.commandEndsWith("2")) - { - com2.setFrequencyActive(frequency); - } - else - { - return false; - } - this->updateCockpit(com1, com2, myAircraft.getTransponder(), identifier()); - return true; - } - } - else if (parser.matchesCommand(".selcal")) - { - if (CSelcal::isValidCode(parser.part(1))) - { - this->updateSelcal(parser.part(1), this->identifier()); - return true; - } - } - return false; - } - -} // namespace diff --git a/src/blackcore/contextownaircraftimpl.h b/src/blackcore/contextownaircraftimpl.h deleted file mode 100644 index 0790cf87c..000000000 --- a/src/blackcore/contextownaircraftimpl.h +++ /dev/null @@ -1,182 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKCORE_CONTEXTOWNAIRCRAFT_IMPL_H -#define BLACKCORE_CONTEXTOWNAIRCRAFT_IMPL_H - -#include "blackcore/blackcoreexport.h" -#include "blackcore/contextownaircraft.h" -#include "blackcore/corefacadeconfig.h" -#include "blackcore/settings/network.h" -#include "blackmisc/aviation/aircraftparts.h" -#include "blackmisc/aviation/airlineicaocode.h" -#include "blackmisc/aviation/atcstation.h" -#include "blackmisc/aviation/comsystem.h" -#include "blackmisc/aviation/selcal.h" -#include "blackmisc/geo/coordinategeodetic.h" -#include "blackmisc/identifiable.h" -#include "blackmisc/identifier.h" -#include "blackmisc/network/user.h" -#include "blackmisc/pq/frequency.h" -#include "blackmisc/pq/length.h" -#include "blackmisc/settingscache.h" -#include "blackmisc/simulation/aircraftmodel.h" -#include "blackmisc/simulation/ownaircraftprovider.h" -#include "blackmisc/simulation/simulatedaircraft.h" - -#include -#include -#include - -namespace BlackMisc -{ - class CDBusServer; - namespace Aviation - { - class CAircraftIcaoCode; - class CAircraftSituation; - class CAltitude; - class CCallsign; - class CTransponder; - } -} - -namespace BlackCore -{ - class CCoreFacade; - - //! Own aircraft context implementation. - //! Central instance of data for \sa IOwnAircraftProvider . - class BLACKCORE_EXPORT CContextOwnAircraft : - public IContextOwnAircraft, - public BlackMisc::Simulation::IOwnAircraftProvider, - public BlackMisc::CIdentifiable - { - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTOWNAIRCRAFT_INTERFACENAME) - Q_INTERFACES(BlackMisc::Simulation::IOwnAircraftProvider) - friend class CCoreFacade; - friend class IContextOwnAircraft; - - public: - //! Destructor - virtual ~CContextOwnAircraft(); - - //! \copydoc BlackMisc::Simulation::IOwnAircraftProvider::getOwnAircraftPosition - //! \ingroup ownaircraftprovider - virtual BlackMisc::Geo::CCoordinateGeodetic getOwnAircraftPosition() const override; - - //! \copydoc BlackMisc::Simulation::IOwnAircraftProvider::getOwnAircraftParts - //! \ingroup ownaircraftprovider - virtual BlackMisc::Aviation::CAircraftParts getOwnAircraftParts() const override; - - //! \copydoc BlackMisc::Simulation::IOwnAircraftProvider::getOwnAircraftModel - //! \ingroup ownaircraftprovider - virtual BlackMisc::Simulation::CAircraftModel getOwnAircraftModel() const override; - - //! \copydoc BlackMisc::Simulation::IOwnAircraftProvider::getDistanceToOwnAircraft - //! \ingroup ownaircraftprovider - virtual BlackMisc::PhysicalQuantities::CLength getDistanceToOwnAircraft(const BlackMisc::Geo::ICoordinateGeodetic &position) const override; - - //! \copydoc BlackMisc::Simulation::IOwnAircraftProvider::updateOwnModel - //! \ingroup ownaircraftprovider - virtual bool updateOwnModel(const BlackMisc::Simulation::CAircraftModel &model) override; - - //! \copydoc BlackMisc::Simulation::IOwnAircraftProvider::updateOwnSituation - //! \ingroup ownaircraftprovider - virtual bool updateOwnSituation(const BlackMisc::Aviation::CAircraftSituation &situation) override; - - //! \copydoc BlackMisc::Simulation::IOwnAircraftProvider::updateOwnParts - //! \ingroup ownaircraftprovider - virtual bool updateOwnParts(const BlackMisc::Aviation::CAircraftParts &parts) override; - - public slots: - //! \copydoc IContextOwnAircraft::getOwnAircraft() - //! \ingroup ownaircraftprovider - virtual BlackMisc::Simulation::CSimulatedAircraft getOwnAircraft() const override; - - //! \copydoc IContextOwnAircraft::updateOwnCallsign - //! \ingroup ownaircraftprovider - virtual bool updateOwnCallsign(const BlackMisc::Aviation::CCallsign &callsign) override; - - //! \copydoc IContextOwnAircraft::updateOwnIcaoCodes - //! \ingroup ownaircraftprovider - virtual bool updateOwnIcaoCodes(const BlackMisc::Aviation::CAircraftIcaoCode &aircraftIcaoCode, const BlackMisc::Aviation::CAirlineIcaoCode &airlineIcaoCode) override; - - //! \copydoc IContextOwnAircraft::updateOwnPosition - virtual bool updateOwnPosition(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::Aviation::CAltitude &altitude) override; - - //! \copydoc IContextOwnAircraft::updateCockpit - virtual bool updateCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const BlackMisc::CIdentifier &originator) override; - - //! \copydoc IContextOwnAircraft::updateSelcal - virtual bool updateSelcal(const BlackMisc::Aviation::CSelcal &selcal, const BlackMisc::CIdentifier &originator) override; - - //! \copydoc IContextOwnAircraft::updateActiveComFrequency - virtual bool updateActiveComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, BlackMisc::Aviation::CComSystem::ComUnit comUnit, const BlackMisc::CIdentifier &originator) override; - - //! \copydoc IContextOwnAircraft::updateOwnAircraftPilot - virtual bool updateOwnAircraftPilot(const BlackMisc::Network::CUser &pilot) override; - - //! \copydoc IContextOwnAircraft::setAudioOutputVolume - virtual void setAudioOutputVolume(int outputVolume) override; - - //! \copydoc IContextOwnAircraft::setAudioVoiceRoomOverrideUrls - virtual void setAudioVoiceRoomOverrideUrls(const QString &voiceRoom1Url, const QString &voiceRoom2Url) override; - - //! \copydoc IContextOwnAircraft::enableAutomaticVoiceRoomResolution - virtual void enableAutomaticVoiceRoomResolution(bool enable) override; - - //! \addtogroup commandline - //! @{ - //!
-        //! .x    .xpdr  code       set transponder code    CContextOwnAircraft
-        //! .com1 .com2  frequency  set COM1/2 frequency    CContextOwnAircraft
-        //! .selcal      code       set SELCAL code         CContextOwnAircraft
-        //! 
- //! @} - //! \copydoc IContextOwnAircraft::parseCommandLine - virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override; - - protected: - //! Constructor, with link to runtime - CContextOwnAircraft(CCoreFacadeConfig::ContextMode, CCoreFacade *runtime); - - //! Register myself in DBus - CContextOwnAircraft *registerWithDBus(BlackMisc::CDBusServer *server); - - private slots: - //! Station has been changed, needed to tune in/out voice room - //! \note Connected in runtime - void ps_changedAtcStationOnlineConnectionStatus(const BlackMisc::Aviation::CAtcStation &atcStation, bool connected); - - //! Simulator model has been changed - //! \note Connected in runtime - void ps_changedSimulatorModel(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft); - - private: - BlackMisc::Simulation::CSimulatedAircraft m_ownAircraft; //!< my aircraft - bool m_automaticVoiceRoomResolution = true; //!< automatic voice room resolution, or disable for override - QString m_voiceRoom1UrlOverride; //!< overridden voice room url - QString m_voiceRoom2UrlOverride; //!< overridden voice room url - mutable QReadWriteLock m_lockAircraft; //!< lock aircraft - - BlackMisc::CSetting m_currentNetworkServer { this }; - - //! Init my very own aircraft with some defaults, before overridden by simulator - void initOwnAircraft(); - - //! Resolve voice rooms - void resolveVoiceRooms(); - }; -} // ns - -#endif // guard diff --git a/src/blackcore/contextownaircraftproxy.cpp b/src/blackcore/contextownaircraftproxy.cpp deleted file mode 100644 index 5d1d88a85..000000000 --- a/src/blackcore/contextownaircraftproxy.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "blackcore/contextownaircraftproxy.h" -#include "blackmisc/dbus.h" -#include "blackmisc/genericdbusinterface.h" - -#include -#include -#include -#include - -using namespace BlackMisc; -using namespace BlackMisc::Aviation; -using namespace BlackMisc::Simulation; - -namespace BlackCore -{ - - CContextOwnAircraftProxy::CContextOwnAircraftProxy(const QString &serviceName, QDBusConnection &connection, CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextOwnAircraft(mode, runtime), m_dBusInterface(nullptr) - { - this->m_dBusInterface = new BlackMisc::CGenericDBusInterface( - serviceName , IContextOwnAircraft::ObjectPath(), IContextOwnAircraft::InterfaceName(), - connection, this); - this->relaySignals(serviceName, connection); - } - - void CContextOwnAircraftProxy::relaySignals(const QString &serviceName, QDBusConnection &connection) - { - bool s = connection.connect(serviceName, IContextOwnAircraft::ObjectPath(), IContextOwnAircraft::InterfaceName(), - "changedAircraftCockpit", this, SIGNAL(changedAircraftCockpit(BlackMisc::Simulation::CSimulatedAircraft, BlackMisc::CIdentifier))); - Q_ASSERT(s); - Q_UNUSED(s); - } - - BlackMisc::Simulation::CSimulatedAircraft CContextOwnAircraftProxy::getOwnAircraft() const - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("getOwnAircraft")); - } - - bool CContextOwnAircraftProxy::updateCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const CIdentifier &originator) - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("updateCockpit"), com1, com2, transponder, originator); - } - - bool CContextOwnAircraftProxy::updateActiveComFrequency(const PhysicalQuantities::CFrequency &frequency, BlackMisc::Aviation::CComSystem::ComUnit comUnit, const CIdentifier &originator) - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("updateActiveComFrequency"), frequency, comUnit, originator); - } - - bool CContextOwnAircraftProxy::updateOwnAircraftPilot(const BlackMisc::Network::CUser &pilot) - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("updateOwnAircraftPilot"), pilot); - } - - bool CContextOwnAircraftProxy::updateSelcal(const CSelcal &selcal, const CIdentifier &originator) - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("updateSelcal"), selcal, originator); - } - - bool CContextOwnAircraftProxy::updateOwnPosition(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::Aviation::CAltitude &altitude) - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("updateOwnPosition"), position, altitude); - } - - bool CContextOwnAircraftProxy::updateOwnCallsign(const CCallsign &callsign) - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("updateOwnCallsign"), callsign); - } - - bool CContextOwnAircraftProxy::updateOwnIcaoCodes(const CAircraftIcaoCode &aircraftIcaoCode, const CAirlineIcaoCode &airlineIcaoCode) - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("updateOwnIcaoCodes"), aircraftIcaoCode, airlineIcaoCode); - } - - void CContextOwnAircraftProxy::setAudioOutputVolume(int outputVolume) - { - this->m_dBusInterface->callDBus(QLatin1Literal("setAudioOutputVolume"), outputVolume); - } - - void CContextOwnAircraftProxy::setAudioVoiceRoomOverrideUrls(const QString &voiceRoom1Url, const QString &voiceRoom2Url) - { - this->m_dBusInterface->callDBus(QLatin1Literal("setAudioVoiceRoomOverrideUrls"), voiceRoom1Url, voiceRoom2Url); - } - - void CContextOwnAircraftProxy::enableAutomaticVoiceRoomResolution(bool enable) - { - this->m_dBusInterface->callDBus(QLatin1Literal("enableAutomaticVoiceRoomResolution"), enable); - } - - bool CContextOwnAircraftProxy::parseCommandLine(const QString &commandLine, const CIdentifier &originator) - { - return this->m_dBusInterface->callDBusRet(QLatin1Literal("parseCommandLine"), commandLine, originator); - } - -} // namespace diff --git a/src/blackcore/contextownaircraftproxy.h b/src/blackcore/contextownaircraftproxy.h deleted file mode 100644 index 50397e2ee..000000000 --- a/src/blackcore/contextownaircraftproxy.h +++ /dev/null @@ -1,111 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKCORE_OWNAIRCRAFT_PROXY_H -#define BLACKCORE_OWNAIRCRAFT_PROXY_H - -#include -#include - -#include "blackcore/blackcoreexport.h" -#include "blackcore/contextownaircraft.h" -#include "blackcore/corefacadeconfig.h" -#include "blackmisc/aviation/airlineicaocode.h" -#include "blackmisc/aviation/comsystem.h" -#include "blackmisc/aviation/selcal.h" -#include "blackmisc/geo/coordinategeodetic.h" -#include "blackmisc/identifier.h" -#include "blackmisc/network/user.h" -#include "blackmisc/pq/frequency.h" -#include "blackmisc/simulation/simulatedaircraft.h" - -class QDBusConnection; - -namespace BlackMisc -{ - class CGenericDBusInterface; - namespace Aviation - { - class CAircraftIcaoCode; - class CAltitude; - class CCallsign; - class CTransponder; - } -} - -namespace BlackCore -{ - class CCoreFacade; - - //! Own aircraft context proxy - //! \ingroup dbus - class BLACKCORE_EXPORT CContextOwnAircraftProxy : public IContextOwnAircraft - { - Q_OBJECT - friend class IContextOwnAircraft; - - public: - //! Destructor - virtual ~CContextOwnAircraftProxy() {} - - public slots: - //! \copydoc IContextOwnAircraft::getOwnAircraft() - virtual BlackMisc::Simulation::CSimulatedAircraft getOwnAircraft() const override; - - //! \copydoc IContextOwnAircraft::updateOwnPosition - virtual bool updateOwnPosition(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::Aviation::CAltitude &altitude) override; - - //! \copydoc IContextOwnAircraft::updateCockpit - virtual bool updateCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const BlackMisc::CIdentifier &originator) override; - - //! \copydoc IContextOwnAircraft::updateActiveComFrequency - virtual bool updateActiveComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, BlackMisc::Aviation::CComSystem::ComUnit comUnit, const BlackMisc::CIdentifier &originator) override; - - //! \copydoc IContextOwnAircraft::updateOwnAircraftPilot - virtual bool updateOwnAircraftPilot(const BlackMisc::Network::CUser &pilot) override; - - //! \copydoc IContextOwnAircraft::updateSelcal - virtual bool updateSelcal(const BlackMisc::Aviation::CSelcal &selcal, const BlackMisc::CIdentifier &originator) override; - - //! \copydoc IContextOwnAircraft::updateOwnCallsign - virtual bool updateOwnCallsign(const BlackMisc::Aviation::CCallsign &callsign) override; - - //! \copydoc IContextOwnAircraft::updateOwnIcaoCodes - virtual bool updateOwnIcaoCodes(const BlackMisc::Aviation::CAircraftIcaoCode &aircraftIcaoCode, const BlackMisc::Aviation::CAirlineIcaoCode &airlineIcaoCode) override; - - //! \copydoc IContextOwnAircraft::setAudioOutputVolume - virtual void setAudioOutputVolume(int outputVolume) override; - - //! \copydoc IContextOwnAircraft::setAudioVoiceRoomOverrideUrls - virtual void setAudioVoiceRoomOverrideUrls(const QString &voiceRoom1Url, const QString &voiceRoom2Url) override; - - //! \copydoc IContextOwnAircraft::enableAutomaticVoiceRoomResolution - virtual void enableAutomaticVoiceRoomResolution(bool enable) override; - - //! \copydoc IContextOwnAircraft::parseCommandLine - virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override; - - protected: - //! \brief Constructor - CContextOwnAircraftProxy(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextOwnAircraft(mode, runtime), m_dBusInterface(nullptr) {} - - //! \brief DBus version constructor - CContextOwnAircraftProxy(const QString &serviceName, QDBusConnection &connection, CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime); - - private: - BlackMisc::CGenericDBusInterface *m_dBusInterface; //!< DBus interface */ - - //! \brief Relay connection signals to local signals. - void relaySignals(const QString &serviceName, QDBusConnection &connection); - }; -} // ns - -#endif // guard diff --git a/src/blackcore/contextsimulator.cpp b/src/blackcore/contextsimulator.cpp deleted file mode 100644 index 468070771..000000000 --- a/src/blackcore/contextsimulator.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "blackcore/contextsimulator.h" -#include "blackcore/contextsimulatorempty.h" -#include "blackcore/contextsimulatorimpl.h" -#include "blackcore/contextsimulatorproxy.h" -#include "blackmisc/dbusserver.h" -#include "blackmisc/pq/units.h" - -#include - -using namespace BlackMisc::PhysicalQuantities; - -namespace BlackCore -{ - const QString &IContextSimulator::InterfaceName() - { - static const QString s(BLACKCORE_CONTEXTSIMULATOR_INTERFACENAME); - return s; - } - - const QString &IContextSimulator::ObjectPath() - { - static const QString s(BLACKCORE_CONTEXTSIMULATOR_OBJECTPATH); - return s; - } - - const BlackMisc::PhysicalQuantities::CTime &IContextSimulator::HighlightTime() - { - static const CTime t(10.0, CTimeUnit::s()); - return t; - } - - IContextSimulator *IContextSimulator::create(CCoreFacade *parent, CCoreFacadeConfig::ContextMode mode, BlackMisc::CDBusServer *server, QDBusConnection &conn) - { - switch (mode) - { - case CCoreFacadeConfig::Local: - case CCoreFacadeConfig::LocalInDbusServer: - return (new CContextSimulator(mode, parent))->registerWithDBus(server); - case CCoreFacadeConfig::Remote: - return new CContextSimulatorProxy(BlackMisc::CDBusServer::coreServiceName(), conn, mode, parent); - case CCoreFacadeConfig::NotUsed: - default: - return new CContextSimulatorEmpty(parent); - } - } - - ISimulator::SimulatorStatus IContextSimulator::getSimulatorStatusEnum() const - { - return static_cast(this->getSimulatorStatus()); - } - -} // namespace diff --git a/src/blackcore/contextsimulator.h b/src/blackcore/contextsimulator.h deleted file mode 100644 index 10429d860..000000000 --- a/src/blackcore/contextsimulator.h +++ /dev/null @@ -1,204 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKCORE_CONTEXTSIMULATOR_H -#define BLACKCORE_CONTEXTSIMULATOR_H - -//! \addtogroup dbus -//! @{ - -//! DBus interface for context -#define BLACKCORE_CONTEXTSIMULATOR_INTERFACENAME "org.swift_project.blackcore.contextsimulator" - -//! DBus object path for context -#define BLACKCORE_CONTEXTSIMULATOR_OBJECTPATH "/simulator" - -//! @} - -#include "blackconfig/buildconfig.h" -#include "blackcore/blackcoreexport.h" -#include "blackcore/context.h" -#include "blackcore/corefacade.h" -#include "blackcore/corefacadeconfig.h" -#include "blackcore/simulator.h" -#include "blackmisc/aviation/airportlist.h" -#include "blackmisc/identifier.h" -#include "blackmisc/pixmap.h" -#include "blackmisc/pq/length.h" -#include "blackmisc/pq/time.h" -#include "blackmisc/simulation/aircraftmodellist.h" -#include "blackmisc/simulation/simulatorplugininfo.h" -#include "blackmisc/simulation/simulatorplugininfolist.h" -#include "blackmisc/simulation/simulatorsetup.h" -#include "blackmisc/weather/weathergrid.h" - -#include -#include - -class QDBusConnection; - -namespace BlackMisc -{ - class CDBusServer; - namespace Simulation { class CSimulatedAircraft; } -} - -namespace BlackCore -{ - //! Network context - class BLACKCORE_EXPORT IContextSimulator : public CContext - { - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTSIMULATOR_INTERFACENAME) - - public: - //! Service name - static const QString &InterfaceName(); - - //! Service path - static const QString &ObjectPath(); - - //! Highlight time - static const BlackMisc::PhysicalQuantities::CTime &HighlightTime(); - - //! \copydoc CContext::getPathAndContextId() - virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); } - - //! Factory method - static IContextSimulator *create(CCoreFacade *parent, CCoreFacadeConfig::ContextMode mode, BlackMisc::CDBusServer *server, QDBusConnection &conn); - - //! Destructor - virtual ~IContextSimulator() {} - - signals: - //! Simulator combined status - //! \sa ISimulator::SimulatorStatus - void simulatorStatusChanged(int status); - - //! Simulator plugin loaded / unloaded (default info) - void simulatorPluginChanged(BlackMisc::Simulation::CSimulatorPluginInfo info); - - //! Render restrictions have been changed - void renderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance, const BlackMisc::PhysicalQuantities::CLength &maxRenderedBoundary); - - //! Installed aircraft models ready or changed - void installedAircraftModelsChanged(); - - //! A single model has been matched for given aircraft - void modelMatchingCompleted(const BlackMisc::Simulation::CSimulatedAircraft &aircraft); - - //! Emitted when own aircraft model changes - void ownAircraftModelChanged(const BlackMisc::Simulation::CSimulatedAircraft &aircraft); - - //! An airspace snapshot was handled - void airspaceSnapshotHandled(); - - //! A weather grid, requested with requestWeatherGrid(), is received - void weatherGridReceived(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier); - - public slots: - //! Simulator info, currently loaded plugin - virtual BlackMisc::Simulation::CSimulatorPluginInfo getSimulatorPluginInfo() const = 0; - - //! Return list of available simulator plugins - virtual BlackMisc::Simulation::CSimulatorPluginInfoList getAvailableSimulatorPlugins() const = 0; - - //! Load and start specific simulator plugin - virtual bool startSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) = 0; - - //! Stop listener or unload the given plugin (if currently loaded) - virtual void stopSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) = 0; - - //! Simulator combined status - virtual int getSimulatorStatus() const = 0; - - //! Get simulator status as enum - //! \todo To be removed with Qt 5.5 when getSimualtorStatus directly provides the enum - ISimulator::SimulatorStatus getSimulatorStatusEnum() const; - - //! Simulator setup - virtual BlackMisc::Simulation::CSimulatorSetup getSimulatorSetup() const = 0; - - //! Airports in range - virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const = 0; - - //! Reload models from disk - virtual void reloadInstalledModels() = 0; - - //! Installed models in simulator eco system - virtual BlackMisc::Simulation::CAircraftModelList getInstalledModels() const = 0; - - //! Number of installed models in simulator eco system - virtual int getInstalledModelsCount() const = 0; - - //! Model for model string - virtual BlackMisc::Simulation::CAircraftModelList getInstalledModelsStartingWith(const QString modelString) const = 0; - - //! Set time synchronization between simulator and user's computer time - //! \remarks not all drivers implement this, e.g. if it is an intrinsic simulator feature - virtual bool setTimeSynchronization(bool enable, const BlackMisc::PhysicalQuantities::CTime &offset) = 0; - - //! Is time synchronization on? - virtual bool isTimeSynchronized() const = 0; - - //! Max. number of remote aircraft rendered - virtual int getMaxRenderedAircraft() const = 0; - - //! Max. rendered distance - virtual BlackMisc::PhysicalQuantities::CLength getMaxRenderedDistance() const = 0; - - //! Technical range until aircraft are visible - virtual BlackMisc::PhysicalQuantities::CLength getRenderedDistanceBoundary() const = 0; - - //! Text describing the rendering restrictions - virtual QString getRenderRestrictionText() const = 0; - - //! Max. number of remote aircraft rendered and provide optional selection which aircraft those are - virtual void setMaxRenderedAircraft(int number) = 0; - - //! Max. distance until we render an aircraft - virtual void setMaxRenderedDistance(const BlackMisc::PhysicalQuantities::CLength &distance) = 0; - - //! Delete all restrictions (if any) -> unlimited number of aircraft - virtual void deleteAllRenderingRestrictions() = 0; - - //! Is number of aircraft restricted ormax distance set? - virtual bool isRenderingRestricted() const = 0; - - //! Rendering enabled at all - virtual bool isRenderingEnabled() const = 0; - - //! Time synchronization offset - virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const = 0; - - //! Simulator avialable (driver available)? - bool isSimulatorAvailable() const { return BlackConfig::CBuildConfig::isCompiledWithFlightSimulatorSupport() && !getSimulatorPluginInfo().isUnspecified(); } - - //! Icon representing the model - virtual BlackMisc::CPixmap iconForModel(const QString &modelString) const = 0; - - //! Enable debugging - virtual void enableDebugMessages(bool driver, bool interpolator) = 0; - - //! Highlight aircraft in simulator - virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) = 0; - - //! Request weather grid. Argument identifier is past in the signal to identify the requestor - virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier) = 0; - - protected: - //! Constructor - IContextSimulator(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : CContext(mode, runtime) {} - }; - -} // namespace - -#endif // guard diff --git a/src/blackcore/contextsimulatorempty.h b/src/blackcore/contextsimulatorempty.h deleted file mode 100644 index 1edab6a15..000000000 --- a/src/blackcore/contextsimulatorempty.h +++ /dev/null @@ -1,229 +0,0 @@ -/* Copyright (C) 2015 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKCORE_CONTEXTSIMULATOR_EMPTY_H -#define BLACKCORE_CONTEXTSIMULATOR_EMPTY_H - -#include "blackcoreexport.h" -#include "contextsimulator.h" -#include "blackmisc/logmessage.h" - -namespace BlackCore -{ - //! Empty context, used during shutdown/initialization - class BLACKCORE_EXPORT CContextSimulatorEmpty : public IContextSimulator - { - Q_OBJECT - - public: - //! Constructor - CContextSimulatorEmpty(CCoreFacade *runtime) : IContextSimulator(CCoreFacadeConfig::NotUsed, runtime) {} - - public slots: - //! \copydoc IContextSimulator::getSimulatorPluginInfo() - virtual BlackMisc::Simulation::CSimulatorPluginInfo getSimulatorPluginInfo() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Simulation::CSimulatorPluginInfo(); - } - - //! \copydoc IContextSimulator::getAvailableSimulatorPlugins() - virtual BlackMisc::Simulation::CSimulatorPluginInfoList getAvailableSimulatorPlugins() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Simulation::CSimulatorPluginInfoList(); - } - - //! \copydoc IContextSimulator::startSimulatorPlugin() - virtual bool startSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override - { - Q_UNUSED(simulatorInfo); - logEmptyContextWarning(Q_FUNC_INFO); - return false; - } - - //! \copydoc IContextSimulator::getSimulatorStatus() - virtual int getSimulatorStatus() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return 0; - } - - //! \copydoc IContextSimulator::stopSimulatorPlugin() - virtual void stopSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override - { - Q_UNUSED(simulatorInfo); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextSimulator::getAirportsInRange() - virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Aviation::CAirportList(); - } - - //! \copydoc IContextSimulator::getInstalledModels() - virtual BlackMisc::Simulation::CAircraftModelList getInstalledModels() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Simulation::CAircraftModelList(); - } - - //! \copydoc IContextSimulator::getInstalledModelsStartingWith - virtual BlackMisc::Simulation::CAircraftModelList getInstalledModelsStartingWith(const QString modelString) const override - { - Q_UNUSED(modelString); - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Simulation::CAircraftModelList(); - } - - //! \copydoc IContextSimulator::getInstalledModelsCount - virtual int getInstalledModelsCount() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return 0; - } - - //! \copydoc IContextSimulator::reloadInstalledModels - virtual void reloadInstalledModels() override - { - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextSimulator::getSimulatorSetup - virtual BlackMisc::Simulation::CSimulatorSetup getSimulatorSetup() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::Simulation::CSimulatorSetup(); - } - - //! \copydoc IContextSimulator::setTimeSynchronization - virtual bool setTimeSynchronization(bool enable, const BlackMisc::PhysicalQuantities::CTime &offset) override - { - Q_UNUSED(enable); - Q_UNUSED(offset); - logEmptyContextWarning(Q_FUNC_INFO); - return false; - } - - //! \copydoc IContextSimulator::isTimeSynchronized - virtual bool isTimeSynchronized() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return false; - } - - //! \copydoc IContextSimulator::getMaxRenderedAircraft - virtual int getMaxRenderedAircraft() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return 0; - } - - //! \copydoc IContextSimulator::setMaxRenderedAircraft - virtual void setMaxRenderedAircraft(int number) override - { - Q_UNUSED(number); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextSimulator::setMaxRenderedDistance - virtual void setMaxRenderedDistance(const BlackMisc::PhysicalQuantities::CLength &distance) override - { - Q_UNUSED(distance); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextSimulator::setMaxRenderedDistance - virtual void deleteAllRenderingRestrictions() override - { - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextSimulator::isRenderingRestricted - virtual bool isRenderingRestricted() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return false; - } - - //! \copydoc IContextSimulator::isRenderingEnabled - virtual bool isRenderingEnabled() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return false; - } - - //! \copydoc IContextSimulator::getMaxRenderedDistance - virtual BlackMisc::PhysicalQuantities::CLength getMaxRenderedDistance() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::PhysicalQuantities::CLength(); - } - - //! \copydoc IContextSimulator::getRenderedDistanceBoundary - virtual BlackMisc::PhysicalQuantities::CLength getRenderedDistanceBoundary() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::PhysicalQuantities::CLength(); - } - - //! \copydoc IContextSimulator::getRenderRestrictionText - virtual QString getRenderRestrictionText() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return QString(); - } - - //! \copydoc IContextSimulator::getTimeSynchronizationOffset - virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::PhysicalQuantities::CTime(); - } - - //! \copydoc IContextSimulator::iconForModel - virtual BlackMisc::CPixmap iconForModel(const QString &modelString) const override - { - Q_UNUSED(modelString); - logEmptyContextWarning(Q_FUNC_INFO); - return BlackMisc::CPixmap(); - } - - //! \copydoc IContextSimulator::highlightAircraft - virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) override - { - Q_UNUSED(aircraftToHighlight); - Q_UNUSED(enableHighlight); - Q_UNUSED(displayTime); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextSimulator::requestWeatherGrid - virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier) override - { - Q_UNUSED(weatherGrid); - Q_UNUSED(identifier); - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc ISimulator::enableDebugMessages - virtual void enableDebugMessages(bool driver, bool interpolator) override - { - Q_UNUSED(driver); - Q_UNUSED(interpolator); - logEmptyContextWarning(Q_FUNC_INFO); - } - }; -} // namespace - -#endif // guard diff --git a/src/blackcore/contextsimulatorimpl.cpp b/src/blackcore/contextsimulatorimpl.cpp deleted file mode 100644 index c0c9bf1bf..000000000 --- a/src/blackcore/contextsimulatorimpl.cpp +++ /dev/null @@ -1,631 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "blackcore/contextapplication.h" -#include "blackcore/contextnetwork.h" -#include "blackcore/contextnetworkimpl.h" -#include "blackcore/contextownaircraft.h" -#include "blackcore/contextownaircraftimpl.h" -#include "blackcore/contextsimulatorimpl.h" -#include "blackcore/corefacade.h" -#include "blackcore/pluginmanagersimulator.h" -#include "blackcore/simulator.h" -#include "blackmisc/aviation/callsign.h" -#include "blackmisc/compare.h" -#include "blackmisc/dbusserver.h" -#include "blackmisc/logcategory.h" -#include "blackmisc/loghandler.h" -#include "blackmisc/logmessage.h" -#include "blackmisc/pq/units.h" -#include "blackmisc/simulation/simulatedaircraft.h" -#include "blackmisc/statusmessage.h" -#include "blackmisc/threadutils.h" - -#include -#include -#include -#include -#include - -using namespace BlackMisc; -using namespace BlackMisc::PhysicalQuantities; -using namespace BlackMisc::Aviation; -using namespace BlackMisc::Network; -using namespace BlackMisc::Simulation; -using namespace BlackMisc::Geo; -using namespace BlackMisc::Simulation; - -namespace BlackCore -{ - CContextSimulator::CContextSimulator(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : - IContextSimulator(mode, runtime), - m_plugins(new CPluginManagerSimulator(this)) - { - this->setObjectName("CContextSimulator"); - connect(&m_weatherManager, &CWeatherManager::weatherGridReceived, this, &CContextSimulator::weatherGridReceived); - m_plugins->collectPlugins(); - } - - CContextSimulator *CContextSimulator::registerWithDBus(CDBusServer *server) - { - if (!server || this->m_mode != CCoreFacadeConfig::LocalInDbusServer) return this; - server->addObject(CContextSimulator::ObjectPath(), this); - return this; - } - - CContextSimulator::~CContextSimulator() - { - this->gracefulShutdown(); - } - - void CContextSimulator::gracefulShutdown() - { - this->disconnect(); - this->unloadSimulatorPlugin(); - } - - CSimulatorPluginInfoList CContextSimulator::getAvailableSimulatorPlugins() const - { - return m_plugins->getAvailableSimulatorPlugins(); - } - - bool CContextSimulator::startSimulatorPlugin(const CSimulatorPluginInfo &simulatorInfo) - { - return this->loadSimulatorPlugin(simulatorInfo, true); - } - - void CContextSimulator::stopSimulatorPlugin(const CSimulatorPluginInfo &simulatorInfo) - { - if (!m_simulatorPlugin.first.isUnspecified() && m_simulatorPlugin.first == simulatorInfo) - { - this->unloadSimulatorPlugin(); - } - - ISimulatorListener *listener = m_plugins->getListener(simulatorInfo.getIdentifier()); - Q_ASSERT(listener); - QMetaObject::invokeMethod(listener, "stop"); - } - - int CContextSimulator::getSimulatorStatus() const - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - if (m_simulatorPlugin.first.isUnspecified()) { return 0; } - - Q_ASSERT_X(m_simulatorPlugin.second, Q_FUNC_INFO, "Missing simulator"); - return m_simulatorPlugin.second->getSimulatorStatus(); - } - - BlackMisc::Simulation::CSimulatorPluginInfo CContextSimulator::getSimulatorPluginInfo() const - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - if (m_simulatorPlugin.first.isUnspecified()) { return BlackMisc::Simulation::CSimulatorPluginInfo(); } - - Q_ASSERT(m_simulatorPlugin.second); - return m_simulatorPlugin.first; - } - - CSimulatorSetup CContextSimulator::getSimulatorSetup() const - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - if (m_simulatorPlugin.first.isUnspecified()) - { - return BlackMisc::Simulation::CSimulatorSetup(); - } - - Q_ASSERT(m_simulatorPlugin.second); - return m_simulatorPlugin.second->getSimulatorSetup(); - } - - CAirportList CContextSimulator::getAirportsInRange() const - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - // If no ISimulator object is available, return a dummy. - if (m_simulatorPlugin.first.isUnspecified()) - { - return CAirportList(); - } - - Q_ASSERT(m_simulatorPlugin.second); - return m_simulatorPlugin.second->getAirportsInRange(); - } - - CAircraftModelList CContextSimulator::getInstalledModels() const - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - // If no ISimulator object is available, return a dummy. - if (m_simulatorPlugin.first.isUnspecified()) - { - return CAircraftModelList(); - } - - Q_ASSERT(m_simulatorPlugin.second); - return m_simulatorPlugin.second->getInstalledModels(); - } - - int CContextSimulator::getInstalledModelsCount() const - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - if (m_simulatorPlugin.first.isUnspecified()) { return 0; } - - Q_ASSERT(m_simulatorPlugin.second); - return m_simulatorPlugin.second->getInstalledModels().size(); - } - - CAircraftModelList CContextSimulator::getInstalledModelsStartingWith(const QString modelString) const - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << modelString; } - if (m_simulatorPlugin.first.isUnspecified()) - { - return CAircraftModelList(); - } - - Q_ASSERT(m_simulatorPlugin.second); - return m_simulatorPlugin.second->getInstalledModels().findModelsStartingWith(modelString); - } - - void CContextSimulator::reloadInstalledModels() - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - if (m_simulatorPlugin.first.isUnspecified()) - { - return; - } - Q_ASSERT(m_simulatorPlugin.second); - m_simulatorPlugin.second->reloadInstalledModels(); - } - - bool CContextSimulator::setTimeSynchronization(bool enable, const CTime &offset) - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - if (m_simulatorPlugin.first.isUnspecified()) { return false; } - - Q_ASSERT(m_simulatorPlugin.second); - bool c = m_simulatorPlugin.second->setTimeSynchronization(enable, offset); - if (!c) { return false; } - - CLogMessage(this).info(enable ? QStringLiteral("Set time syncronization to %1").arg(offset.toQString()) : QStringLiteral("Disabled time syncrhonization")); - return true; - } - - bool CContextSimulator::isTimeSynchronized() const - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - if (m_simulatorPlugin.first.isUnspecified()) { return false; } - - Q_ASSERT(m_simulatorPlugin.second); - return m_simulatorPlugin.second->isTimeSynchronized(); - } - - int CContextSimulator::getMaxRenderedAircraft() const - { - if (m_debugEnabled) {CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - if (m_simulatorPlugin.first.isUnspecified()) { return 0; } - Q_ASSERT(m_simulatorPlugin.second); - return m_simulatorPlugin.second->getMaxRenderedAircraft(); - } - - void CContextSimulator::setMaxRenderedAircraft(int number) - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << number; } - if (m_simulatorPlugin.first.isUnspecified()) { return; } - Q_ASSERT(m_simulatorPlugin.second); - m_simulatorPlugin.second->setMaxRenderedAircraft(number); - - } - - void CContextSimulator::setMaxRenderedDistance(const CLength &distance) - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << distance; } - if (m_simulatorPlugin.first.isUnspecified()) { return; } - Q_ASSERT(m_simulatorPlugin.second); - m_simulatorPlugin.second->setMaxRenderedDistance(distance); - } - - QString CContextSimulator::getRenderRestrictionText() const - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - if (m_simulatorPlugin.first.isUnspecified()) { return ""; } - - Q_ASSERT(m_simulatorPlugin.second); - if (!m_simulatorPlugin.second->isRenderingRestricted()) { return "none"; } - QString rt; - if (m_simulatorPlugin.second->isMaxAircraftRestricted()) - { - rt.append(QString::number(m_simulatorPlugin.second->getMaxRenderedAircraft())).append(" A/C"); - } - if (m_simulatorPlugin.second->isMaxDistanceRestricted()) - { - if (!rt.isEmpty()) { rt.append(" ");} - rt.append(m_simulatorPlugin.second->getMaxRenderedDistance().valueRoundedWithUnit(CLengthUnit::NM(), 0)); - } - return rt; - } - - CLength CContextSimulator::getMaxRenderedDistance() const - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - if (m_simulatorPlugin.first.isUnspecified()) { return CLength(0, CLengthUnit::nullUnit()); } - Q_ASSERT(m_simulatorPlugin.second); - return m_simulatorPlugin.second->getMaxRenderedDistance(); - } - - CLength CContextSimulator::getRenderedDistanceBoundary() const - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - if (m_simulatorPlugin.first.isUnspecified()) - { - return CLength(20.0, CLengthUnit::NM()); - } - Q_ASSERT(m_simulatorPlugin.second); - return m_simulatorPlugin.second->getRenderedDistanceBoundary(); - } - - void CContextSimulator::deleteAllRenderingRestrictions() - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - if (!m_simulatorPlugin.first.isUnspecified()) - { - Q_ASSERT(m_simulatorPlugin.second); - m_simulatorPlugin.second->deleteAllRenderingRestrictions(); - } - } - - bool CContextSimulator::isRenderingRestricted() const - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - if (m_simulatorPlugin.first.isUnspecified()) { return false; } - Q_ASSERT(m_simulatorPlugin.second); - return m_simulatorPlugin.second->isRenderingRestricted(); - } - - bool CContextSimulator::isRenderingEnabled() const - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - if (m_simulatorPlugin.first.isUnspecified()) { return false; } - Q_ASSERT(m_simulatorPlugin.second); - return m_simulatorPlugin.second->isRenderingEnabled(); - } - - CTime CContextSimulator::getTimeSynchronizationOffset() const - { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - if (m_simulatorPlugin.first.isUnspecified()) { return CTime(0, CTimeUnit::hrmin()); } - Q_ASSERT(m_simulatorPlugin.second); - return m_simulatorPlugin.second->getTimeSynchronizationOffset(); - } - - bool CContextSimulator::loadSimulatorPlugin(const CSimulatorPluginInfo &simulatorInfo, bool withListener) - { - Q_ASSERT(getIContextApplication()); - Q_ASSERT(getIContextApplication()->isUsingImplementingObject()); - Q_ASSERT(!simulatorInfo.isUnspecified()); - Q_ASSERT(CThreadUtils::isCurrentThreadApplicationThread()); // only run in main thread - - if (!simulatorInfo.isValid()) - { - CLogMessage(this).error("Illegal plugin"); - return false; - } - - // Is the plugin already loaded? - if (!m_simulatorPlugin.first.isUnspecified()) - { - return true; - } - - unloadSimulatorPlugin(); // old plugin unloaded - - // now we have a state where no driver is loaded - if (withListener) - { - this->listenForSimulator(simulatorInfo); - return false; // not a plugin yet, just listener - } - - if (!simulatorInfo.isValid() || simulatorInfo.isUnspecified()) - { - CLogMessage(this).error("Illegal plugin"); - return false; - } - - ISimulatorFactory *factory = m_plugins->getFactory(simulatorInfo.getIdentifier()); - Q_ASSERT_X(factory, Q_FUNC_INFO, "no factory"); - - // We assume we run in the same process as the own aircraft context - // Hence we pass in memory reference to own aircraft object - Q_ASSERT(this->getIContextOwnAircraft()->isUsingImplementingObject()); - Q_ASSERT(this->getIContextNetwork()->isUsingImplementingObject()); - IOwnAircraftProvider *ownAircraftProvider = this->getRuntime()->getCContextOwnAircraft(); - IRemoteAircraftProvider *renderedAircraftProvider = this->getRuntime()->getCContextNetwork(); - ISimulator *simulator = factory->create(simulatorInfo, ownAircraftProvider, renderedAircraftProvider, &m_weatherManager); - Q_ASSERT_X(simulator, Q_FUNC_INFO, "no simulator driver can be created"); - - bool c = connect(simulator, &ISimulator::simulatorStatusChanged, this, &CContextSimulator::ps_onSimulatorStatusChanged); - Q_ASSERT(c); - c = connect(simulator, &ISimulator::ownAircraftModelChanged, this, &IContextSimulator::ownAircraftModelChanged); - Q_ASSERT(c); - c = connect(simulator, &ISimulator::modelMatchingCompleted, this, &IContextSimulator::modelMatchingCompleted); - Q_ASSERT(c); - c = connect(simulator, &ISimulator::installedAircraftModelsChanged, this, &IContextSimulator::installedAircraftModelsChanged); - Q_ASSERT(c); - c = connect(simulator, &ISimulator::renderRestrictionsChanged, this, &IContextSimulator::renderRestrictionsChanged); - Q_ASSERT(c); - c = connect(simulator, &ISimulator::airspaceSnapshotHandled, this, &IContextSimulator::airspaceSnapshotHandled); - Q_ASSERT(c); - - // log from context to simulator - c = connect(CLogHandler::instance(), &CLogHandler::localMessageLogged, simulator, &ISimulator::displayStatusMessage); - Q_ASSERT(c); - c = connect(CLogHandler::instance(), &CLogHandler::remoteMessageLogged, simulator, &ISimulator::displayStatusMessage); - Q_ASSERT(c); - Q_UNUSED(c); - - // use network to initally add aircraft - IContextNetwork *networkContext = this->getIContextNetwork(); - Q_ASSERT(networkContext); - Q_ASSERT(networkContext->isLocalObject()); - - // initially add aircraft - for (const CSimulatedAircraft &simulatedAircraft : networkContext->getAircraftInRange()) - { - Q_ASSERT(!simulatedAircraft.getCallsign().isEmpty()); - simulator->logicallyAddRemoteAircraft(simulatedAircraft); - } - - // when everything is set up connected, update the current plugin info - m_simulatorPlugin.first = simulatorInfo; - m_simulatorPlugin.second = simulator; - - // try to connect to simulator - simulator->connectTo(); - emit simulatorPluginChanged(simulatorInfo); - CLogMessage(this).info("Simulator plugin loaded: %1") << simulatorInfo.toQString(true); - - return true; - } - - void CContextSimulator::listenForSimulator(const CSimulatorPluginInfo &simulatorInfo) - { - Q_ASSERT(this->getIContextApplication()); - Q_ASSERT(this->getIContextApplication()->isUsingImplementingObject()); - Q_ASSERT(!simulatorInfo.isUnspecified()); - - ISimulator::SimulatorStatus simStatus = getSimulatorStatusEnum(); - if (!m_simulatorPlugin.first.isUnspecified() && - m_simulatorPlugin.first == simulatorInfo && simStatus.testFlag(ISimulator::Connected)) - { - // the simulator is already connected and running - return; - } - - if (!m_simulatorPlugin.first.isUnspecified()) - { - // wrong or disconnected plugin, we start from the scratch - this->unloadSimulatorPlugin(); - } - - if (!m_listenersThread.isRunning()) - { - m_listenersThread.setObjectName("CContextSimulator:Thread for listeners"); - m_listenersThread.start(QThread::LowPriority); - } - - ISimulatorListener *listener = m_plugins->createListener(simulatorInfo.getIdentifier()); - Q_ASSERT_X(listener, Q_FUNC_INFO, "No listener"); - - if (listener->thread() != &m_listenersThread) - { - bool c = connect(listener, &ISimulatorListener::simulatorStarted, this, &CContextSimulator::ps_simulatorStarted); - if (!c) - { - CLogMessage(this).error("Unable to use '%1'") << simulatorInfo.toQString(); - return; - } - - Q_ASSERT_X(!listener->parent(), Q_FUNC_INFO, "Objects with parent cannot be moved to thread"); - listener->setProperty("isInitialized", true); - listener->moveToThread(&m_listenersThread); - } - - bool s = QMetaObject::invokeMethod(listener, "start", Qt::QueuedConnection); - Q_ASSERT_X(s, Q_FUNC_INFO, "cannot invoke method"); - Q_UNUSED(s); - - CLogMessage(this).info("Listening for simulator %1") << simulatorInfo.getIdentifier(); - } - - void CContextSimulator::listenForAllSimulators() - { - auto plugins = getAvailableSimulatorPlugins(); - for (const CSimulatorPluginInfo &p : plugins) - { - Q_ASSERT(!p.isUnspecified()); - - if (p.isValid()) - { - listenForSimulator(p); - } - } - } - - void CContextSimulator::unloadSimulatorPlugin() - { - if (!m_simulatorPlugin.first.isUnspecified()) - { - ISimulator *sim = m_simulatorPlugin.second; - m_simulatorPlugin.second = nullptr; - m_simulatorPlugin.first = CSimulatorPluginInfo(); - - Q_ASSERT(this->getIContextNetwork()); - Q_ASSERT(this->getIContextNetwork()->isLocalObject()); - - // unload and disconnect - if (sim) - { - // disconnect signals and delete - sim->unload(); - this->disconnect(sim); - sim->deleteLater(); - emit simulatorPluginChanged(CSimulatorPluginInfo()); - } - } - } - - void CContextSimulator::ps_addRemoteAircraft(const CSimulatedAircraft &remoteAircraft) - { - //! \todo This was previously an assert and it should be one again in the future. This slot should not even be called when no simulator is available. - if (m_simulatorPlugin.first.isUnspecified()) - { - // Do something if no simulator is running - return; - } - - Q_ASSERT(m_simulatorPlugin.second); - Q_ASSERT(!remoteAircraft.getCallsign().isEmpty()); - - m_simulatorPlugin.second->logicallyAddRemoteAircraft(remoteAircraft); - } - - void CContextSimulator::ps_removedRemoteAircraft(const CCallsign &callsign) - { - // \fixme: This was previously an assert and it should be one again in the future. - // This slot should not even be called when no simulator is available. - if (m_simulatorPlugin.first.isUnspecified()) - { - // Do something if no simulator is running - return; - } - - Q_ASSERT(m_simulatorPlugin.second); - m_simulatorPlugin.second->logicallyRemoveRemoteAircraft(callsign); - } - - void CContextSimulator::ps_onSimulatorStatusChanged(int status) - { - ISimulator::SimulatorStatus statusEnum = ISimulator::statusToEnum(status); - if (!statusEnum.testFlag(ISimulator::Connected)) - { - // we got disconnected, plugin no longer needed - unloadSimulatorPlugin(); - } - emit simulatorStatusChanged(status); - } - - void CContextSimulator::ps_textMessagesReceived(const Network::CTextMessageList &textMessages) - { - // todo: - // This was previously an assert and it should be one again in the future. - // This slot should not even be called when no simulator is available. - if (m_simulatorPlugin.first.isUnspecified()) - { - // Do something if no simulator is running - return; - } - - Q_ASSERT(m_simulatorPlugin.second); - for (const auto &tm : textMessages) - { - m_simulatorPlugin.second->displayTextMessage(tm); - } - } - - void CContextSimulator::ps_cockpitChangedFromSimulator(const CSimulatedAircraft &ownAircraft) - { - Q_ASSERT(getIContextOwnAircraft()); - getIContextOwnAircraft()->changedAircraftCockpit(ownAircraft, IContextSimulator::InterfaceName()); - } - - void CContextSimulator::ps_changedRemoteAircraftModel(const CSimulatedAircraft &aircraft, const CIdentifier &originator) - { - Q_ASSERT(m_simulatorPlugin.second); - m_simulatorPlugin.second->changeRemoteAircraftModel(aircraft, originator); - } - - void CContextSimulator::ps_changedRemoteAircraftEnabled(const CSimulatedAircraft &aircraft, const CIdentifier &originator) - { - Q_ASSERT(m_simulatorPlugin.second); - m_simulatorPlugin.second->changeRemoteAircraftEnabled(aircraft, originator); - } - - void CContextSimulator::ps_updateSimulatorCockpitFromContext(const CSimulatedAircraft &ownAircraft, const CIdentifier &originator) - { - // todo: - // This was previously an assert and it should be one again in the future. - // This slot should not even be called when no simulator is available. - if (m_simulatorPlugin.first.isUnspecified()) - { - // Do something if no simulator is running - return; - } - - Q_ASSERT(m_simulatorPlugin.second); - - // avoid loops - if (originator.getName().isEmpty() || originator == IContextSimulator::InterfaceName()) { return; } - - // update - m_simulatorPlugin.second->updateOwnSimulatorCockpit(ownAircraft, originator); - } - - void CContextSimulator::restoreSimulatorPlugins() - { - stopSimulatorListeners(); - - auto enabledSimulators = m_enabledSimulators.getThreadLocal(); - auto allSimulators = m_plugins->getAvailableSimulatorPlugins(); - for (const CSimulatorPluginInfo& s: allSimulators) - { - if (enabledSimulators.contains(s.getIdentifier())) - { - startSimulatorPlugin(s); - } - } - } - - CPixmap CContextSimulator::iconForModel(const QString &modelString) const - { - if (m_simulatorPlugin.first.isUnspecified()) { return CPixmap(); } - Q_ASSERT_X(m_simulatorPlugin.second, Q_FUNC_INFO, "Missing simulator"); - return m_simulatorPlugin.second->iconForModel(modelString); - } - - void CContextSimulator::enableDebugMessages(bool driver, bool interpolator) - { - if (m_simulatorPlugin.first.isUnspecified()) { return; } - Q_ASSERT_X(m_simulatorPlugin.second, Q_FUNC_INFO, "Missing simulator"); - return m_simulatorPlugin.second->enableDebugMessages(driver, interpolator); - } - - void CContextSimulator::highlightAircraft(const CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const CTime &displayTime) - { - Q_ASSERT(m_simulatorPlugin.second); - m_simulatorPlugin.second->highlightAircraft(aircraftToHighlight, enableHighlight, displayTime); - } - - void CContextSimulator::requestWeatherGrid(const Weather::CWeatherGrid &weatherGrid, const CIdentifier &identifier) - { - m_weatherManager.requestWeatherGrid(weatherGrid, identifier); - } - - void CContextSimulator::ps_simulatorStarted(const CSimulatorPluginInfo &info) - { - stopSimulatorListeners(); - loadSimulatorPlugin(info, false); - } - - void CContextSimulator::stopSimulatorListeners() - { - for (const auto &info : getAvailableSimulatorPlugins()) - { - ISimulatorListener *listener = m_plugins->getListener(info.getIdentifier()); - if(listener) { QMetaObject::invokeMethod(listener, "stop"); } - } - } - -} // namespace diff --git a/src/blackcore/contextsimulatorimpl.h b/src/blackcore/contextsimulatorimpl.h deleted file mode 100644 index 0498a6826..000000000 --- a/src/blackcore/contextsimulatorimpl.h +++ /dev/null @@ -1,213 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKCORE_CONTEXTSIMULATOR_IMPL_H -#define BLACKCORE_CONTEXTSIMULATOR_IMPL_H - - -#include "blackcore/blackcoreexport.h" -#include "blackcore/contextsimulator.h" -#include "blackcore/corefacadeconfig.h" -#include "blackcore/settings/application.h" -#include "blackcore/weathermanager.h" -#include "blackmisc/aviation/airportlist.h" -#include "blackmisc/identifier.h" -#include "blackmisc/network/textmessagelist.h" -#include "blackmisc/pixmap.h" -#include "blackmisc/pq/length.h" -#include "blackmisc/pq/time.h" -#include "blackmisc/settingscache.h" -#include "blackmisc/simulation/aircraftmodellist.h" -#include "blackmisc/simulation/simulatorplugininfo.h" -#include "blackmisc/simulation/simulatorplugininfolist.h" -#include "blackmisc/simulation/simulatorsetup.h" -#include "blackmisc/worker.h" - -#include -#include -#include - -namespace BlackMisc -{ - class CDBusServer; - namespace Aviation { class CCallsign; } - namespace Simulation { class CSimulatedAircraft; } -} - -namespace BlackCore -{ - class CCoreFacade; - class CPluginManagerSimulator; - class ISimulator; - - //! Network simulator concrete implementation - class BLACKCORE_EXPORT CContextSimulator : - public IContextSimulator - { - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTSIMULATOR_INTERFACENAME) - friend class CCoreFacade; - friend class IContextSimulator; - - public: - //! Destructor - virtual ~CContextSimulator(); - - //! Gracefully shut down, e.g. for plugin unloading - void gracefulShutdown(); - - public slots: - //! \copydoc IContextSimulator::getSimulatorPluginInfo() - virtual BlackMisc::Simulation::CSimulatorPluginInfo getSimulatorPluginInfo() const override; - - //! \copydoc IContextSimulator::getAvailableSimulatorPlugins() - virtual BlackMisc::Simulation::CSimulatorPluginInfoList getAvailableSimulatorPlugins() const override; - - //! \copydoc IContextSimulator::startSimulatorPlugin() - virtual bool startSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override; - - //! \copydoc IContextSimulator::stopSimulatorPlugin() - virtual void stopSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override; - - //! \copydoc IContextSimulator::getSimulatorStatus() - virtual int getSimulatorStatus() const override; - - //! \copydoc IContextSimulator::getSimulatorSetup() - virtual BlackMisc::Simulation::CSimulatorSetup getSimulatorSetup() const override; - - //! \copydoc IContextSimulator::getAirportsInRange - virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override; - - //! \copydoc IContextSimulator::getInstalledModels - virtual BlackMisc::Simulation::CAircraftModelList getInstalledModels() const override; - - //! \copydoc IContextSimulator::getInstalledModelsCount - virtual int getInstalledModelsCount() const override; - - //! \copydoc IContextSimulator::getInstalledModelsStartingWith - virtual BlackMisc::Simulation::CAircraftModelList getInstalledModelsStartingWith(const QString modelString) const override; - - //! \copydoc IContextSimulator::reloadInstalledModels - virtual void reloadInstalledModels() override; - - //! \copydoc IContextSimulator::setTimeSynchronization - virtual bool setTimeSynchronization(bool enable, const BlackMisc::PhysicalQuantities::CTime &offset) override; - - //! \copydoc IContextSimulator::isTimeSynchronized - virtual bool isTimeSynchronized() const override; - - //! \copydoc IContextSimulator::getMaxRenderedAircraft - virtual int getMaxRenderedAircraft() const override; - - //! \copydoc IContextSimulator::setMaxRenderedAircraft - virtual void setMaxRenderedAircraft(int number) override; - - //! \copydoc IContextSimulator::getMaxRenderedDistance - virtual BlackMisc::PhysicalQuantities::CLength getMaxRenderedDistance() const override; - - //! \copydoc IContextSimulator::setMaxRenderedDistance - virtual void setMaxRenderedDistance(const BlackMisc::PhysicalQuantities::CLength &distance) override; - - //! \copydoc IContextSimulator::getRenderRestrictionText - virtual QString getRenderRestrictionText() const override; - - //! \copydoc IContextSimulator::getRenderedDistanceBoundary - virtual BlackMisc::PhysicalQuantities::CLength getRenderedDistanceBoundary() const override; - - //! \copydoc IContextSimulator::setMaxRenderedDistance - virtual void deleteAllRenderingRestrictions() override; - - //! \copydoc IContextSimulator::isRenderingRestricted - virtual bool isRenderingRestricted() const override; - - //! \copydoc IContextSimulator::isRenderingEnabled - virtual bool isRenderingEnabled() const override; - - //! \copydoc IContextSimulator::getTimeSynchronizationOffset - virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const override; - - //! \copydoc IContextSimulator::iconForModel - virtual BlackMisc::CPixmap iconForModel(const QString &modelString) const override; - - //! \copydoc ISimulator::enableDebugMessages - virtual void enableDebugMessages(bool driver, bool interpolator) override; - - //! \copydoc IContextSimulator::highlightAircraft - virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) override; - - //! \copydoc IContextSimulator::requestWeatherGrid - virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier) override; - - protected: - //! Constructor - CContextSimulator(CCoreFacadeConfig::ContextMode, CCoreFacade *runtime); - - //! Register myself in DBus - CContextSimulator *registerWithDBus(BlackMisc::CDBusServer *server); - - private slots: - //! Remote aircraft added - void ps_addRemoteAircraft(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft); - - //! Remove remote aircraft - void ps_removedRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign); - - //! Handle new connection status of simulator - void ps_onSimulatorStatusChanged(int status); - - //! Text message received - void ps_textMessagesReceived(const BlackMisc::Network::CTextMessageList &textMessages); - - //! Listener reports the simulator has started - void ps_simulatorStarted(const BlackMisc::Simulation::CSimulatorPluginInfo &info); - - //! Simulator has changed cockpit - void ps_cockpitChangedFromSimulator(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft); - - //! Changed remote aircraft model - void ps_changedRemoteAircraftModel(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator); - - //! Enable / disable aircraft - void ps_changedRemoteAircraftEnabled(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator); - - //! Update simulator cockpit from context, because someone else has changed cockpit (e.g. GUI, 3rd party) - //! \remarks set by runtime, only to be used locally (not via DBus) - void ps_updateSimulatorCockpitFromContext(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft, const BlackMisc::CIdentifier &originator); - - //! Reads list of enabled simulators, starts listeners - void restoreSimulatorPlugins(); - - private: - //! Load plugin, if required start listeners before - bool loadSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo, bool withListeners); - - //! Unload plugin, if desired restart listeners - void unloadSimulatorPlugin(); - - //! Listen for single simulator - void listenForSimulator(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo); - - //! Listen for all simulators - void listenForAllSimulators(); - - //! Call stop() on all loaded listeners - void stopSimulatorListeners(); - - QPair m_simulatorPlugin; //!< Currently loaded simulator plugin - CPluginManagerSimulator *m_plugins = nullptr; - BlackMisc::CRegularThread m_listenersThread; - BlackCore::CWeatherManager m_weatherManager { this }; - BlackMisc::CSetting m_enabledSimulators { this, &CContextSimulator::restoreSimulatorPlugins }; - }; - -} // namespace - -#endif // guard diff --git a/src/blackcore/contextsimulatorproxy.cpp b/src/blackcore/contextsimulatorproxy.cpp deleted file mode 100644 index d26fbfd10..000000000 --- a/src/blackcore/contextsimulatorproxy.cpp +++ /dev/null @@ -1,202 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "blackcore/contextsimulatorproxy.h" -#include "blackmisc/dbus.h" -#include "blackmisc/genericdbusinterface.h" -#include "blackmisc/simulation/simulatedaircraft.h" - -#include -#include -#include -#include - -using namespace BlackMisc; -using namespace BlackMisc::PhysicalQuantities; -using namespace BlackMisc::Aviation; -using namespace BlackMisc::Network; -using namespace BlackMisc::Geo; -using namespace BlackMisc::Simulation; - -namespace BlackCore -{ - - CContextSimulatorProxy::CContextSimulatorProxy(const QString &serviceName, QDBusConnection &connection, CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextSimulator(mode, runtime), m_dBusInterface(nullptr) - { - this->m_dBusInterface = new BlackMisc::CGenericDBusInterface( - serviceName , IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), - connection, this); - this->relaySignals(serviceName, connection); - } - - void CContextSimulatorProxy::relaySignals(const QString &serviceName, QDBusConnection &connection) - { - bool s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), - "simulatorStatusChanged", this, SIGNAL(simulatorStatusChanged(int))); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), - "installedAircraftModelsChanged", this, SIGNAL(installedAircraftModelsChanged())); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), - "ownAircraftModelChanged", this, SIGNAL(ownAircraftModelChanged(BlackMisc::Simulation::CSimulatedAircraft))); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), - "modelMatchingCompleted", this, SIGNAL(modelMatchingCompleted(BlackMisc::Simulation::CSimulatedAircraft))); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), - "renderRestrictionsChanged", this, SIGNAL(renderRestrictionsChanged(bool, bool, int, BlackMisc::PhysicalQuantities::CLength, BlackMisc::PhysicalQuantities::CLength))); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), - "simulatorPluginChanged", this, SIGNAL(simulatorPluginChanged(BlackMisc::Simulation::CSimulatorPluginInfo))); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), - "airspaceSnapshotHandled", this, SIGNAL(airspaceSnapshotHandled())); - Q_ASSERT(s); - s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), - "weatherGridReceived", this, SIGNAL(weatherGridReceived())); - Q_ASSERT(s); - Q_UNUSED(s); - } - - CSimulatorPluginInfoList CContextSimulatorProxy::getAvailableSimulatorPlugins() const - { - return m_dBusInterface->callDBusRet(QLatin1Literal("getAvailableSimulatorPlugins")); - } - - int CContextSimulatorProxy::getSimulatorStatus() const - { - return m_dBusInterface->callDBusRet(QLatin1Literal("getSimulatorStatus")); - } - - CAirportList CContextSimulatorProxy::getAirportsInRange() const - { - return m_dBusInterface->callDBusRet(QLatin1Literal("getAirportsInRange")); - } - - CAircraftModelList CContextSimulatorProxy::getInstalledModels() const - { - return m_dBusInterface->callDBusRet(QLatin1Literal("getInstalledModels")); - } - - CAircraftModelList CContextSimulatorProxy::getInstalledModelsStartingWith(const QString modelString) const - { - return m_dBusInterface->callDBusRet(QLatin1Literal("getInstalledModelsStartingWith"), modelString); - } - - int CContextSimulatorProxy::getInstalledModelsCount() const - { - return m_dBusInterface->callDBusRet(QLatin1Literal("getInstalledModelsCount")); - } - - void CContextSimulatorProxy::reloadInstalledModels() - { - m_dBusInterface->callDBus(QLatin1Literal("reloadInstalledModels")); - } - - BlackMisc::Simulation::CSimulatorPluginInfo CContextSimulatorProxy::getSimulatorPluginInfo() const - { - return m_dBusInterface->callDBusRet(QLatin1Literal("getSimulatorPluginInfo")); - } - - CSimulatorSetup CContextSimulatorProxy::getSimulatorSetup() const - { - return m_dBusInterface->callDBusRet(QLatin1Literal("getSimulatorSetup")); - } - - bool CContextSimulatorProxy::setTimeSynchronization(bool enable, const CTime &offset) - { - return m_dBusInterface->callDBusRet(QLatin1Literal("setTimeSynchronization"), enable, offset); - } - - bool CContextSimulatorProxy::isTimeSynchronized() const - { - return m_dBusInterface->callDBusRet(QLatin1Literal("isTimeSynchronized")); - } - - void CContextSimulatorProxy::setMaxRenderedAircraft(int number) - { - m_dBusInterface->callDBus(QLatin1Literal("setMaxRenderedAircraft"), number); - } - - void CContextSimulatorProxy::setMaxRenderedDistance(const CLength &distance) - { - m_dBusInterface->callDBus(QLatin1Literal("setMaxRenderedDistance"), distance); - } - - void CContextSimulatorProxy::deleteAllRenderingRestrictions() - { - m_dBusInterface->callDBus(QLatin1Literal("deleteAllRenderingRestrictions")); - } - - bool CContextSimulatorProxy::isRenderingRestricted() const - { - return m_dBusInterface->callDBusRet(QLatin1Literal("isRenderingRestricted")); - } - - bool CContextSimulatorProxy::isRenderingEnabled() const - { - return m_dBusInterface->callDBusRet(QLatin1Literal("isRenderingEnabled")); - } - - CLength CContextSimulatorProxy::getMaxRenderedDistance() const - { - return m_dBusInterface->callDBusRet(QLatin1Literal("getMaxRenderedDistance")); - } - - CLength CContextSimulatorProxy::getRenderedDistanceBoundary() const - { - return m_dBusInterface->callDBusRet(QLatin1Literal("getRenderedDistanceBoundary")); - } - - QString CContextSimulatorProxy::getRenderRestrictionText() const - { - return m_dBusInterface->callDBusRet(QLatin1Literal("getRenderRestrictionText")); - } - - int CContextSimulatorProxy::getMaxRenderedAircraft() const - { - return m_dBusInterface->callDBusRet(QLatin1Literal("getMaxRenderedAircraft")); - } - - CTime CContextSimulatorProxy::getTimeSynchronizationOffset() const - { - return m_dBusInterface->callDBusRet(QLatin1Literal("getTimeSynchronizationOffset")); - } - - bool CContextSimulatorProxy::startSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) - { - return m_dBusInterface->callDBusRet(QLatin1Literal("startSimulatorPlugin"), simulatorInfo); - } - - void CContextSimulatorProxy::stopSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) - { - m_dBusInterface->callDBus(QLatin1Literal("stopSimulatorPlugin"), simulatorInfo); - } - - CPixmap CContextSimulatorProxy::iconForModel(const QString &modelString) const - { - return m_dBusInterface->callDBusRet(QLatin1Literal("iconForModel"), modelString); - } - - void CContextSimulatorProxy::highlightAircraft(const CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const CTime &displayTime) - { - m_dBusInterface->callDBus(QLatin1Literal("highlightAircraft"), aircraftToHighlight, enableHighlight, displayTime); - } - - void CContextSimulatorProxy::requestWeatherGrid(const Weather::CWeatherGrid &weatherGrid, const CIdentifier &identifier) - { - m_dBusInterface->callDBus(QLatin1Literal("requestWeatherGrid"), weatherGrid, identifier); - } - - void CContextSimulatorProxy::enableDebugMessages(bool driver, bool interpolator) - { - m_dBusInterface->callDBus(QLatin1Literal("enableDebugMessages"), driver, interpolator); - } - -} // namespace diff --git a/src/blackcore/contextsimulatorproxy.h b/src/blackcore/contextsimulatorproxy.h deleted file mode 100644 index 5b12294b4..000000000 --- a/src/blackcore/contextsimulatorproxy.h +++ /dev/null @@ -1,150 +0,0 @@ -/* Copyright (C) 2013 - * swift Project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKCORE_CONTEXTSIMULATOR_PROXY_H -#define BLACKCORE_CONTEXTSIMULATOR_PROXY_H - -#include "blackcore/blackcoreexport.h" -#include "blackcore/contextsimulator.h" -#include "blackcore/corefacadeconfig.h" -#include "blackmisc/aviation/airportlist.h" -#include "blackmisc/pixmap.h" -#include "blackmisc/pq/length.h" -#include "blackmisc/pq/time.h" -#include "blackmisc/simulation/aircraftmodellist.h" -#include "blackmisc/simulation/simulatorplugininfo.h" -#include "blackmisc/simulation/simulatorplugininfolist.h" -#include "blackmisc/simulation/simulatorsetup.h" - -#include -#include - -class QDBusConnection; - -namespace BlackMisc -{ - class CGenericDBusInterface; - namespace Simulation { class CSimulatedAircraft; } -} - -namespace BlackCore -{ - class CCoreFacade; - - //! DBus proxy for Simulator Context - //! \ingroup dbus - class BLACKCORE_EXPORT CContextSimulatorProxy : public IContextSimulator - { - Q_OBJECT - friend class IContextSimulator; - - public: - //! Destructor - ~CContextSimulatorProxy() {} - - private: - BlackMisc::CGenericDBusInterface *m_dBusInterface; - - //! Relay connection signals to local signals - void relaySignals(const QString &serviceName, QDBusConnection &connection); - - protected: - //! Constructor - CContextSimulatorProxy(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextSimulator(mode, runtime), m_dBusInterface(0) {} - - //! DBus version constructor - CContextSimulatorProxy(const QString &serviceName, QDBusConnection &connection, CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime); - - public slots: - //! \copydoc IContextSimulator::getSimulatorPluginInfo() - virtual BlackMisc::Simulation::CSimulatorPluginInfo getSimulatorPluginInfo() const override; - - //! \copydoc IContextSimulator::getAvailableSimulatorPlugins() - virtual BlackMisc::Simulation::CSimulatorPluginInfoList getAvailableSimulatorPlugins() const override; - - //! \copydoc IContextSimulator::startSimulatorPlugin() - virtual bool startSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override; - - //! \copydoc IContextSimulator::stopSimulatorPlugin() - virtual void stopSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override; - - //! \copydoc IContextSimulator::getSimulatorStatus() - virtual int getSimulatorStatus() const override; - - //! \copydoc IContextSimulator::getAirportsInRange() - virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override; - - //! \copydoc IContextSimulator::getInstalledModels() - virtual BlackMisc::Simulation::CAircraftModelList getInstalledModels() const override; - - //! \copydoc IContextSimulator::getInstalledModelsStartingWith - virtual BlackMisc::Simulation::CAircraftModelList getInstalledModelsStartingWith(const QString modelString) const override; - - //! \copydoc IContextSimulator::getInstalledModelsCount - virtual int getInstalledModelsCount() const override; - - //! \copydoc IContextSimulator::reloadInstalledModels - virtual void reloadInstalledModels() override; - - //! \copydoc IContextSimulator::getSimulatorSetup - virtual BlackMisc::Simulation::CSimulatorSetup getSimulatorSetup() const override; - - //! \copydoc IContextSimulator::setTimeSynchronization - virtual bool setTimeSynchronization(bool enable, const BlackMisc::PhysicalQuantities::CTime &offset) override; - - //! \copydoc IContextSimulator::isTimeSynchronized - virtual bool isTimeSynchronized() const override; - - //! \copydoc IContextSimulator::getMaxRenderedAircraft - virtual int getMaxRenderedAircraft() const override; - - //! \copydoc IContextSimulator::setMaxRenderedAircraft - virtual void setMaxRenderedAircraft(int number) override; - - //! \copydoc IContextSimulator::setMaxRenderedDistance - virtual void setMaxRenderedDistance(const BlackMisc::PhysicalQuantities::CLength &distance) override; - - //! \copydoc IContextSimulator::setMaxRenderedDistance - virtual void deleteAllRenderingRestrictions() override; - - //! \copydoc IContextSimulator::isRenderingRestricted - virtual bool isRenderingRestricted() const override; - - //! \copydoc IContextSimulator::isRenderingEnabled - virtual bool isRenderingEnabled() const override; - - //! \copydoc IContextSimulator::getMaxRenderedDistance - virtual BlackMisc::PhysicalQuantities::CLength getMaxRenderedDistance() const override; - - //! \copydoc IContextSimulator::getRenderedDistanceBoundary - virtual BlackMisc::PhysicalQuantities::CLength getRenderedDistanceBoundary() const override; - - //! \copydoc IContextSimulator::getRenderRestrictionText - virtual QString getRenderRestrictionText() const override; - - //! \copydoc IContextSimulator::getTimeSynchronizationOffset - virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const override; - - //! \copydoc IContextSimulator::iconForModel - virtual BlackMisc::CPixmap iconForModel(const QString &modelString) const override; - - //! \copydoc IContextSimulator::highlightAircraft - virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) override; - - //! \copydoc IContextSimulator::requestWeatherGrid - virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier) override; - - //! \copydoc ISimulator::enableDebugMessages - virtual void enableDebugMessages(bool driver, bool interpolator) override; - }; -} // namespace BlackCore - -#endif // guard diff --git a/src/blackcore/corefacade.cpp b/src/blackcore/corefacade.cpp index ae63276ce..238e8f32d 100644 --- a/src/blackcore/corefacade.cpp +++ b/src/blackcore/corefacade.cpp @@ -7,16 +7,16 @@ * contained in the LICENSE file. */ -#include "blackcore/contextapplication.h" -#include "blackcore/contextapplicationimpl.h" -#include "blackcore/contextaudio.h" -#include "blackcore/contextaudioimpl.h" -#include "blackcore/contextnetwork.h" -#include "blackcore/contextnetworkimpl.h" -#include "blackcore/contextownaircraft.h" -#include "blackcore/contextownaircraftimpl.h" -#include "blackcore/contextsimulator.h" -#include "blackcore/contextsimulatorimpl.h" +#include "blackcore/context/contextapplication.h" +#include "blackcore/context/contextapplicationimpl.h" +#include "blackcore/context/contextaudio.h" +#include "blackcore/context/contextaudioimpl.h" +#include "blackcore/context/contextnetwork.h" +#include "blackcore/context/contextnetworkimpl.h" +#include "blackcore/context/contextownaircraft.h" +#include "blackcore/context/contextownaircraftimpl.h" +#include "blackcore/context/contextsimulator.h" +#include "blackcore/context/contextsimulatorimpl.h" #include "blackcore/corefacade.h" #include "blackcore/corefacadeconfig.h" #include "blackcore/registermetadata.h" @@ -41,6 +41,7 @@ using namespace BlackMisc; using namespace BlackMisc::Aviation; using namespace BlackMisc::Simulation; +using namespace BlackCore::Context; namespace BlackCore { diff --git a/src/blackcore/corefacade.h b/src/blackcore/corefacade.h index 6fef60ef1..9b3d32cbe 100644 --- a/src/blackcore/corefacade.h +++ b/src/blackcore/corefacade.h @@ -28,17 +28,20 @@ namespace BlackCore { // forward declaration, see review // https://dev.vatsim-germany.org/boards/22/topics/1350?r=1359#message-1359 - class CContextApplication; - class CContextAudio; - class CContextNetwork; - class CContextOwnAircraft; - class CContextSimulator; class CCoreFacadeConfig; - class IContextApplication; - class IContextAudio; - class IContextNetwork; - class IContextOwnAircraft; - class IContextSimulator; + namespace Context + { + class CContextApplication; + class CContextAudio; + class CContextNetwork; + class CContextOwnAircraft; + class CContextSimulator; + class IContextApplication; + class IContextAudio; + class IContextNetwork; + class IContextOwnAircraft; + class IContextSimulator; + } /*! * The runtime class providing facades (the contexts) for all DBus relevant operations. @@ -71,76 +74,76 @@ namespace BlackCore // ------- Context as interface, normal way to access a context //! Context for network - IContextNetwork *getIContextNetwork(); + Context::IContextNetwork *getIContextNetwork(); //! Context for network - const IContextNetwork *getIContextNetwork() const; + const Context::IContextNetwork *getIContextNetwork() const; //! Context for audio - IContextAudio *getIContextAudio(); + Context::IContextAudio *getIContextAudio(); //! Context for audio - const IContextAudio *getIContextAudio() const; + const Context::IContextAudio *getIContextAudio() const; //! Context for application - IContextApplication *getIContextApplication(); + Context::IContextApplication *getIContextApplication(); //! Context for application - const IContextApplication *getIContextApplication() const; + const Context::IContextApplication *getIContextApplication() const; //! Context for own aircraft - IContextOwnAircraft *getIContextOwnAircraft(); + Context::IContextOwnAircraft *getIContextOwnAircraft(); //! Context for own aircraft - const IContextOwnAircraft *getIContextOwnAircraft() const; + const Context::IContextOwnAircraft *getIContextOwnAircraft() const; //! Context for simulator - IContextSimulator *getIContextSimulator(); + Context::IContextSimulator *getIContextSimulator(); //! Context for simulator - const IContextSimulator *getIContextSimulator() const; + const Context::IContextSimulator *getIContextSimulator() const; // ------- Context as implementing (local) class //! Context for application //! \remarks only applicable for local object - CContextApplication *getCContextApplication(); + Context::CContextApplication *getCContextApplication(); //! Context for application //! \remarks only applicable for local object - const CContextApplication *getCContextApplication() const; + const Context::CContextApplication *getCContextApplication() const; //! Context for audio //! \remarks only applicable for local object - CContextAudio *getCContextAudio(); + Context::CContextAudio *getCContextAudio(); //! Context for audio //! \remarks only applicable for local object - const CContextAudio *getCContextAudio() const; + const Context::CContextAudio *getCContextAudio() const; //! Context for own aircraft //! \remarks only applicable for local object - CContextOwnAircraft *getCContextOwnAircraft(); + Context::CContextOwnAircraft *getCContextOwnAircraft(); //! Context for own aircraft //! \remarks only applicable for local object - const CContextOwnAircraft *getCContextOwnAircraft() const; + const Context::CContextOwnAircraft *getCContextOwnAircraft() const; //! Context for network //! \remarks only applicable for local object - CContextNetwork *getCContextNetwork(); + Context::CContextNetwork *getCContextNetwork(); //! Context for network //! \remarks only applicable for local object - const CContextNetwork *getCContextNetwork() const; + const Context::CContextNetwork *getCContextNetwork() const; //! Context for simulator //! \remarks only applicable for local object - CContextSimulator *getCContextSimulator(); + Context::CContextSimulator *getCContextSimulator(); //! Context for simulator //! \remarks only applicable for local object - const CContextSimulator *getCContextSimulator() const; + const Context::CContextSimulator *getCContextSimulator() const; //! Init void init(const CCoreFacadeConfig &config); @@ -167,11 +170,11 @@ namespace BlackCore // contexts: // There is a reason why we do not use smart pointers here. When the context is deleted // we need to use deleteLater to gracefully shut the context - IContextApplication *m_contextApplication = nullptr; - IContextAudio *m_contextAudio = nullptr; - IContextNetwork *m_contextNetwork = nullptr; - IContextOwnAircraft *m_contextOwnAircraft = nullptr; - IContextSimulator *m_contextSimulator = nullptr; + Context::IContextApplication *m_contextApplication = nullptr; + Context::IContextAudio *m_contextAudio = nullptr; + Context::IContextNetwork *m_contextNetwork = nullptr; + Context::IContextOwnAircraft *m_contextOwnAircraft = nullptr; + Context::IContextSimulator *m_contextSimulator = nullptr; //! initialization of DBus connection (where applicable) void initDBusConnection(const QString &address); diff --git a/src/blackcore/registermetadata.cpp b/src/blackcore/registermetadata.cpp index 569fcda55..3aafacc8c 100644 --- a/src/blackcore/registermetadata.cpp +++ b/src/blackcore/registermetadata.cpp @@ -8,7 +8,7 @@ */ #include "blackcore/registermetadata.h" -#include "blackcore/contextapplication.h" +#include "blackcore/context/contextapplication.h" #include "blackcore/db/databasereader.h" #include "blackcore/settings/reader.h" #include "blackcore/data/globalsetup.h" @@ -28,8 +28,8 @@ namespace BlackCore { void registerMetadata() { - qDBusRegisterMetaType(); - qDBusRegisterMetaType(); + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); diff --git a/src/blackgui/components/aircraftcomponent.cpp b/src/blackgui/components/aircraftcomponent.cpp index 540bcd77c..fb1282cc9 100644 --- a/src/blackgui/components/aircraftcomponent.cpp +++ b/src/blackgui/components/aircraftcomponent.cpp @@ -7,8 +7,8 @@ * contained in the LICENSE file. */ -#include "blackcore/contextnetwork.h" -#include "blackcore/contextsimulator.h" +#include "blackcore/context/contextnetwork.h" +#include "blackcore/context/contextsimulator.h" #include "blackcore/network.h" #include "blackgui/components/aircraftcomponent.h" #include "blackgui/guiapplication.h" @@ -28,6 +28,7 @@ using namespace BlackGui; using namespace BlackGui::Views; using namespace BlackGui::Models; using namespace BlackCore; +using namespace BlackCore::Context; using namespace BlackMisc::Simulation; using namespace BlackMisc::PhysicalQuantities; diff --git a/src/blackgui/components/atcstationcomponent.cpp b/src/blackgui/components/atcstationcomponent.cpp index 7828cc5a7..2e7ab5aee 100644 --- a/src/blackgui/components/atcstationcomponent.cpp +++ b/src/blackgui/components/atcstationcomponent.cpp @@ -7,8 +7,8 @@ * contained in the LICENSE file. */ -#include "blackcore/contextnetwork.h" -#include "blackcore/contextownaircraft.h" +#include "blackcore/context/contextnetwork.h" +#include "blackcore/context/contextownaircraft.h" #include "blackgui/components/atcstationcomponent.h" #include "blackgui/guiapplication.h" #include "blackgui/guiutility.h" @@ -43,6 +43,7 @@ using namespace BlackMisc::Aviation; using namespace BlackMisc::PhysicalQuantities; using namespace BlackMisc::Weather; using namespace BlackCore; +using namespace BlackCore::Context; namespace BlackGui { diff --git a/src/blackgui/components/audiosetupcomponent.cpp b/src/blackgui/components/audiosetupcomponent.cpp index 04708dcda..5bcf1b09d 100644 --- a/src/blackgui/components/audiosetupcomponent.cpp +++ b/src/blackgui/components/audiosetupcomponent.cpp @@ -7,7 +7,7 @@ * contained in the LICENSE file. */ -#include "blackcore/contextaudio.h" +#include "blackcore/context/contextaudio.h" #include "blackgui/components/audiosetupcomponent.h" #include "blackgui/guiapplication.h" #include "blackmisc/audio/audiodeviceinfo.h" @@ -22,6 +22,7 @@ #include using namespace BlackCore; +using namespace BlackCore::Context; using namespace BlackMisc; using namespace BlackGui; using namespace BlackMisc::Aviation; diff --git a/src/blackgui/components/audiovolumecomponent.cpp b/src/blackgui/components/audiovolumecomponent.cpp index 1a173f5e3..625e0935f 100644 --- a/src/blackgui/components/audiovolumecomponent.cpp +++ b/src/blackgui/components/audiovolumecomponent.cpp @@ -8,7 +8,7 @@ */ #include "audiovolumecomponent.h" -#include "blackcore/contextaudio.h" +#include "blackcore/context/contextaudio.h" #include "blackgui/components/audiovolumecomponent.h" #include "blackgui/guiapplication.h" #include "blackmisc/audio/audioutils.h" @@ -22,6 +22,7 @@ #include using namespace BlackCore; +using namespace BlackCore::Context; namespace BlackGui { diff --git a/src/blackgui/components/cockpitcomcomponent.cpp b/src/blackgui/components/cockpitcomcomponent.cpp index 249e69458..1867ec044 100644 --- a/src/blackgui/components/cockpitcomcomponent.cpp +++ b/src/blackgui/components/cockpitcomcomponent.cpp @@ -7,9 +7,9 @@ * contained in the LICENSE file. */ -#include "blackcore/contextaudio.h" -#include "blackcore/contextnetwork.h" -#include "blackcore/contextownaircraft.h" +#include "blackcore/context/contextaudio.h" +#include "blackcore/context/contextnetwork.h" +#include "blackcore/context/contextownaircraft.h" #include "blackgui/components/cockpitcomcomponent.h" #include "blackgui/components/selcalcodeselector.h" #include "blackgui/components/transpondercodespinbox.h" @@ -37,6 +37,7 @@ using namespace BlackGui; using namespace BlackCore; +using namespace BlackCore::Context; using namespace BlackMisc; using namespace BlackMisc::Audio; using namespace BlackMisc::Aviation; diff --git a/src/blackgui/components/cockpittranspondermodeledscomponent.cpp b/src/blackgui/components/cockpittranspondermodeledscomponent.cpp index a89c064b3..83ef48dbd 100644 --- a/src/blackgui/components/cockpittranspondermodeledscomponent.cpp +++ b/src/blackgui/components/cockpittranspondermodeledscomponent.cpp @@ -7,7 +7,7 @@ * contained in the LICENSE file. */ -#include "blackcore/contextownaircraft.h" +#include "blackcore/context/contextownaircraft.h" #include "blackgui/components/cockpittranspondermodeledscomponent.h" #include "blackgui/guiapplication.h" #include "blackgui/led.h" @@ -21,6 +21,7 @@ using namespace BlackMisc; using namespace BlackMisc::Aviation; using namespace BlackMisc::Simulation; using namespace BlackCore; +using namespace BlackCore::Context; namespace BlackGui { diff --git a/src/blackgui/components/flightplancomponent.cpp b/src/blackgui/components/flightplancomponent.cpp index 6590117b2..876ebf2bf 100644 --- a/src/blackgui/components/flightplancomponent.cpp +++ b/src/blackgui/components/flightplancomponent.cpp @@ -7,8 +7,8 @@ * contained in the LICENSE file. */ -#include "blackcore/contextnetwork.h" -#include "blackcore/contextownaircraft.h" +#include "blackcore/context/contextnetwork.h" +#include "blackcore/context/contextownaircraft.h" #include "blackgui/components/flightplancomponent.h" #include "blackgui/components/selcalcodeselector.h" #include "blackgui/guiapplication.h" diff --git a/src/blackgui/components/infobarstatuscomponent.cpp b/src/blackgui/components/infobarstatuscomponent.cpp index 28878c171..f3099247e 100644 --- a/src/blackgui/components/infobarstatuscomponent.cpp +++ b/src/blackgui/components/infobarstatuscomponent.cpp @@ -8,10 +8,10 @@ */ #include "blackconfig/buildconfig.h" -#include "blackcore/contextapplication.h" -#include "blackcore/contextaudio.h" -#include "blackcore/contextnetwork.h" -#include "blackcore/contextsimulator.h" +#include "blackcore/context/contextapplication.h" +#include "blackcore/context/contextaudio.h" +#include "blackcore/context/contextnetwork.h" +#include "blackcore/context/contextsimulator.h" #include "blackcore/simulator.h" #include "blackgui/components/infobarstatuscomponent.h" #include "blackgui/guiapplication.h" @@ -31,6 +31,7 @@ using namespace BlackConfig; using namespace BlackCore; +using namespace BlackCore::Context; using namespace BlackGui; using namespace BlackMisc; diff --git a/src/blackgui/components/internalscomponent.cpp b/src/blackgui/components/internalscomponent.cpp index afea49cff..61548bc60 100644 --- a/src/blackgui/components/internalscomponent.cpp +++ b/src/blackgui/components/internalscomponent.cpp @@ -7,11 +7,11 @@ * contained in the LICENSE file. */ -#include "blackcore/contextapplication.h" -#include "blackcore/contextaudio.h" -#include "blackcore/contextnetwork.h" -#include "blackcore/contextownaircraft.h" -#include "blackcore/contextsimulator.h" +#include "blackcore/context/contextapplication.h" +#include "blackcore/context/contextaudio.h" +#include "blackcore/context/contextnetwork.h" +#include "blackcore/context/contextownaircraft.h" +#include "blackcore/context/contextsimulator.h" #include "blackgui/components/internalscomponent.h" #include "blackgui/components/remoteaircraftselector.h" #include "blackgui/guiapplication.h" diff --git a/src/blackgui/components/logincomponent.cpp b/src/blackgui/components/logincomponent.cpp index c91445625..6c8025db1 100644 --- a/src/blackgui/components/logincomponent.cpp +++ b/src/blackgui/components/logincomponent.cpp @@ -8,10 +8,10 @@ */ #include "blackconfig/buildconfig.h" -#include "blackcore/contextaudio.h" -#include "blackcore/contextnetwork.h" -#include "blackcore/contextownaircraft.h" -#include "blackcore/contextsimulator.h" +#include "blackcore/context/contextaudio.h" +#include "blackcore/context/contextnetwork.h" +#include "blackcore/context/contextownaircraft.h" +#include "blackcore/context/contextsimulator.h" #include "blackcore/webdataservices.h" #include "blackcore/data/globalsetup.h" #include "blackcore/network.h" @@ -55,6 +55,7 @@ using namespace BlackMisc::Network; using namespace BlackMisc::Simulation; using namespace BlackCore; using namespace BlackCore::Data; +using namespace BlackCore::Context; using namespace BlackGui; namespace BlackGui diff --git a/src/blackgui/components/mainkeypadareacomponent.cpp b/src/blackgui/components/mainkeypadareacomponent.cpp index 49d404bee..91a49bf6f 100644 --- a/src/blackgui/components/mainkeypadareacomponent.cpp +++ b/src/blackgui/components/mainkeypadareacomponent.cpp @@ -7,9 +7,9 @@ * contained in the LICENSE file. */ -#include "blackcore/contextaudio.h" -#include "blackcore/contextnetwork.h" -#include "blackcore/contextownaircraft.h" +#include "blackcore/context/contextaudio.h" +#include "blackcore/context/contextnetwork.h" +#include "blackcore/context/contextownaircraft.h" #include "blackcore/corefacade.h" #include "blackgui/components/mainkeypadareacomponent.h" #include "blackgui/guiapplication.h" @@ -25,6 +25,7 @@ using namespace BlackMisc; using namespace BlackMisc::Aviation; using namespace BlackMisc::Simulation; using namespace BlackCore; +using namespace BlackCore::Context; namespace BlackGui { diff --git a/src/blackgui/components/mainkeypadareacomponent.h b/src/blackgui/components/mainkeypadareacomponent.h index c45e199f1..fedd5dddd 100644 --- a/src/blackgui/components/mainkeypadareacomponent.h +++ b/src/blackgui/components/mainkeypadareacomponent.h @@ -75,16 +75,16 @@ namespace BlackGui //! Button was clicked void ps_buttonSelected(); - //! \copydoc BlackCore::IContextNetwork::connectionStatusChanged + //! \copydoc BlackCore::Context::IContextNetwork::connectionStatusChanged void ps_connectionStatusChanged(BlackCore::INetwork::ConnectionStatus from, BlackCore::INetwork::ConnectionStatus to); //! Command line entered void ps_commandEntered(); - //! \copydoc BlackCore::IContextOwnAircraft::changedAircraftCockpit + //! \copydoc BlackCore::Context::IContextOwnAircraft::changedAircraftCockpit void ps_ownAircraftCockpitChanged(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator); - //! \copydoc BlackCore::IContextAudio::changedMute + //! \copydoc BlackCore::Context::IContextAudio::changedMute void ps_muteChanged(bool muted); private: diff --git a/src/blackgui/components/mappingcomponent.cpp b/src/blackgui/components/mappingcomponent.cpp index 31c3f7008..31ab80ef2 100644 --- a/src/blackgui/components/mappingcomponent.cpp +++ b/src/blackgui/components/mappingcomponent.cpp @@ -7,8 +7,8 @@ * contained in the LICENSE file. */ -#include "blackcore/contextnetwork.h" -#include "blackcore/contextsimulator.h" +#include "blackcore/context/contextnetwork.h" +#include "blackcore/context/contextsimulator.h" #include "blackcore/network.h" #include "blackgui/components/mappingcomponent.h" #include "blackgui/components/updatetimer.h" @@ -48,6 +48,7 @@ using namespace BlackMisc::Network; using namespace BlackMisc::Aviation; using namespace BlackMisc::PhysicalQuantities; using namespace BlackCore; +using namespace BlackCore::Context; using namespace BlackGui; using namespace BlackGui::Views; using namespace BlackGui::Models; diff --git a/src/blackgui/components/modelmatcherlogcomponent.cpp b/src/blackgui/components/modelmatcherlogcomponent.cpp index 32d7bfd29..10961a995 100644 --- a/src/blackgui/components/modelmatcherlogcomponent.cpp +++ b/src/blackgui/components/modelmatcherlogcomponent.cpp @@ -12,7 +12,7 @@ #include "blackmisc/propertyindexlist.h" #include "blackmisc/htmlutils.h" -#include "blackcore/contextnetwork.h" +#include "blackcore/context/contextnetwork.h" #include "blackgui/guiapplication.h" #include "blackgui/uppercasevalidator.h" #include diff --git a/src/blackgui/components/registercomponent.cpp b/src/blackgui/components/registercomponent.cpp index 14fb18ffd..52a8d7f6b 100644 --- a/src/blackgui/components/registercomponent.cpp +++ b/src/blackgui/components/registercomponent.cpp @@ -7,7 +7,7 @@ * contained in the LICENSE file. */ -#include "blackcore/contextapplication.h" +#include "blackcore/context/contextapplication.h" #include "blackgui/components/registercomponent.h" #include "blackgui/components/updatetimer.h" #include "blackgui/guiapplication.h" @@ -17,6 +17,7 @@ #include using namespace BlackCore; +using namespace BlackCore::Context; namespace BlackGui { diff --git a/src/blackgui/components/remoteaircraftselector.cpp b/src/blackgui/components/remoteaircraftselector.cpp index a02c721e6..b90ddc95d 100644 --- a/src/blackgui/components/remoteaircraftselector.cpp +++ b/src/blackgui/components/remoteaircraftselector.cpp @@ -7,7 +7,7 @@ * contained in the LICENSE file. */ -#include "blackcore/contextnetwork.h" +#include "blackcore/context/contextnetwork.h" #include "blackgui/components/remoteaircraftselector.h" #include "blackgui/guiapplication.h" #include "blackmisc/aviation/aircrafticaocode.h" @@ -25,6 +25,7 @@ using namespace BlackMisc; using namespace BlackMisc::Aviation; using namespace BlackMisc::Simulation; using namespace BlackCore; +using namespace BlackCore::Context; namespace BlackGui { diff --git a/src/blackgui/components/settingshotkeycomponent.cpp b/src/blackgui/components/settingshotkeycomponent.cpp index bc556bd27..10fc23a59 100644 --- a/src/blackgui/components/settingshotkeycomponent.cpp +++ b/src/blackgui/components/settingshotkeycomponent.cpp @@ -7,7 +7,7 @@ * contained in the LICENSE file. */ -#include "blackcore/contextapplication.h" +#include "blackcore/context/contextapplication.h" #include "blackgui/components/hotkeydialog.h" #include "blackgui/components/settingshotkeycomponent.h" #include "blackgui/guiapplication.h" diff --git a/src/blackgui/components/settingsnetworkcomponent.cpp b/src/blackgui/components/settingsnetworkcomponent.cpp index 928b2a9ca..3ae36817d 100644 --- a/src/blackgui/components/settingsnetworkcomponent.cpp +++ b/src/blackgui/components/settingsnetworkcomponent.cpp @@ -7,7 +7,7 @@ * contained in the LICENSE file. */ -#include "blackcore/contextnetwork.h" +#include "blackcore/context/contextnetwork.h" #include "blackgui/components/settingsnetworkcomponent.h" #include "blackgui/guiapplication.h" #include "ui_settingsnetworkcomponent.h" diff --git a/src/blackgui/components/settingsnetworkserverscomponent.cpp b/src/blackgui/components/settingsnetworkserverscomponent.cpp index 4df7f3487..be7943922 100644 --- a/src/blackgui/components/settingsnetworkserverscomponent.cpp +++ b/src/blackgui/components/settingsnetworkserverscomponent.cpp @@ -8,7 +8,7 @@ */ #include "blackconfig/buildconfig.h" -#include "blackcore/contextapplication.h" +#include "blackcore/context/contextapplication.h" #include "blackcore/data/globalsetup.h" #include "blackgui/editors/serverform.h" #include "blackgui/components/settingsnetworkserverscomponent.h" diff --git a/src/blackgui/components/settingssimulatorcomponent.cpp b/src/blackgui/components/settingssimulatorcomponent.cpp index 9575b8a04..178b43221 100644 --- a/src/blackgui/components/settingssimulatorcomponent.cpp +++ b/src/blackgui/components/settingssimulatorcomponent.cpp @@ -7,8 +7,8 @@ * contained in the LICENSE file. */ -#include "blackcore/contextapplication.h" -#include "blackcore/contextsimulator.h" +#include "blackcore/context/contextapplication.h" +#include "blackcore/context/contextsimulator.h" #include "blackcore/pluginmanagersimulator.h" #include "blackgui/components/settingssimulatorcomponent.h" #include "blackgui/guiapplication.h" @@ -44,6 +44,7 @@ using namespace BlackMisc::Simulation; using namespace BlackMisc::Aviation; using namespace BlackMisc::Simulation; using namespace BlackCore; +using namespace BlackCore::Context; namespace BlackGui { diff --git a/src/blackgui/components/simulatorcomponent.cpp b/src/blackgui/components/simulatorcomponent.cpp index afff2c90f..14c10957f 100644 --- a/src/blackgui/components/simulatorcomponent.cpp +++ b/src/blackgui/components/simulatorcomponent.cpp @@ -7,8 +7,8 @@ * contained in the LICENSE file. */ -#include "blackcore/contextownaircraft.h" -#include "blackcore/contextsimulator.h" +#include "blackcore/context/contextownaircraft.h" +#include "blackcore/context/contextsimulator.h" #include "blackcore/simulator.h" #include "blackgui/components/simulatorcomponent.h" #include "blackgui/guiapplication.h" @@ -31,6 +31,7 @@ using namespace BlackMisc; using namespace BlackMisc::Aviation; using namespace BlackMisc::Simulation; using namespace BlackCore; +using namespace BlackCore::Context; namespace BlackGui { diff --git a/src/blackgui/components/textmessagecomponent.cpp b/src/blackgui/components/textmessagecomponent.cpp index 195808ff5..68d2e48b1 100644 --- a/src/blackgui/components/textmessagecomponent.cpp +++ b/src/blackgui/components/textmessagecomponent.cpp @@ -8,9 +8,9 @@ */ #include "blackcore/application.h" -#include "blackcore/contextaudio.h" -#include "blackcore/contextnetwork.h" -#include "blackcore/contextownaircraft.h" +#include "blackcore/context/contextaudio.h" +#include "blackcore/context/contextnetwork.h" +#include "blackcore/context/contextownaircraft.h" #include "blackcore/corefacade.h" #include "blackgui/components/textmessagecomponent.h" #include "blackgui/dockwidgetinfoarea.h" @@ -43,6 +43,7 @@ #include using namespace BlackCore; +using namespace BlackCore::Context; using namespace BlackMisc; using namespace BlackGui; using namespace BlackGui::Views; diff --git a/src/blackgui/components/usercomponent.cpp b/src/blackgui/components/usercomponent.cpp index ed345fb43..63acfbeb2 100644 --- a/src/blackgui/components/usercomponent.cpp +++ b/src/blackgui/components/usercomponent.cpp @@ -7,7 +7,7 @@ * contained in the LICENSE file. */ -#include "blackcore/contextnetwork.h" +#include "blackcore/context/contextnetwork.h" #include "blackcore/network.h" #include "blackgui/components/usercomponent.h" #include "blackgui/guiapplication.h" @@ -22,6 +22,7 @@ using namespace BlackGui; using namespace BlackGui::Views; using namespace BlackCore; +using namespace BlackCore::Context; namespace BlackGui { diff --git a/src/blackgui/components/voiceroomscomponent.cpp b/src/blackgui/components/voiceroomscomponent.cpp index cfa4e1f44..43d770c92 100644 --- a/src/blackgui/components/voiceroomscomponent.cpp +++ b/src/blackgui/components/voiceroomscomponent.cpp @@ -7,8 +7,8 @@ * contained in the LICENSE file. */ -#include "blackcore/contextaudio.h" -#include "blackcore/contextownaircraft.h" +#include "blackcore/context/contextaudio.h" +#include "blackcore/context/contextownaircraft.h" #include "blackgui/components/voiceroomscomponent.h" #include "blackgui/guiapplication.h" #include "blackgui/views/userview.h" @@ -24,6 +24,7 @@ #include using namespace BlackCore; +using namespace BlackCore::Context; using namespace BlackMisc::Audio; namespace BlackGui @@ -141,7 +142,5 @@ namespace BlackGui this->ui->tvp_CockpitVoiceRoom2->clear(); } } - } // namespace } // namespace - diff --git a/src/blackgui/components/weathercomponent.cpp b/src/blackgui/components/weathercomponent.cpp index 09ea862d5..9af403b03 100644 --- a/src/blackgui/components/weathercomponent.cpp +++ b/src/blackgui/components/weathercomponent.cpp @@ -11,9 +11,9 @@ #include "blackgui/infoarea.h" #include "blackgui/views/viewbase.h" #include "blackgui/guiapplication.h" -#include "blackcore/contextapplication.h" -#include "blackcore/contextsimulator.h" -#include "blackcore/contextownaircraft.h" +#include "blackcore/context/contextapplication.h" +#include "blackcore/context/contextsimulator.h" +#include "blackcore/context/contextownaircraft.h" #include "blackmisc/pq/length.h" #include "blackmisc/logmessage.h" #include "blackmisc/weather/weathergrid.h" @@ -24,6 +24,7 @@ #include using namespace BlackCore; +using namespace BlackCore::Context; using namespace BlackGui; using namespace BlackGui::Models; using namespace BlackGui::Views; diff --git a/src/blackmisc/aviation/aircraftpartslist.cpp b/src/blackmisc/aviation/aircraftpartslist.cpp index f89e226b5..40cc71919 100644 --- a/src/blackmisc/aviation/aircraftpartslist.cpp +++ b/src/blackmisc/aviation/aircraftpartslist.cpp @@ -16,7 +16,6 @@ namespace BlackMisc { namespace Aviation { - CAircraftPartsList::CAircraftPartsList() { } CAircraftPartsList::CAircraftPartsList(const CSequence &other) : diff --git a/src/blackmisc/aviation/aircraftpartslist.h b/src/blackmisc/aviation/aircraftpartslist.h index b617bfefe..d6d90cc38 100644 --- a/src/blackmisc/aviation/aircraftpartslist.h +++ b/src/blackmisc/aviation/aircraftpartslist.h @@ -12,10 +12,10 @@ #ifndef BLACKMISC_AVIATION_AIRCRAFTPARTSLIST_H #define BLACKMISC_AVIATION_AIRCRAFTPARTSLIST_H -#include "blackmisc/aviation/aircraftparts.h" #include "blackmisc/blackmiscexport.h" #include "blackmisc/collection.h" #include "blackmisc/sequence.h" +#include "blackmisc/aviation/aircraftparts.h" #include "blackmisc/timestampobjectlist.h" #include "blackmisc/variant.h" @@ -25,8 +25,6 @@ namespace BlackMisc { namespace Aviation { - class CAircraftParts; - //! Value object encapsulating a list of aircraft parts. class BLACKMISC_EXPORT CAircraftPartsList : public CSequence, diff --git a/src/plugins/simulator/fscommon/simulatorfscommon.h b/src/plugins/simulator/fscommon/simulatorfscommon.h index 4237c8e13..623ecbd51 100644 --- a/src/plugins/simulator/fscommon/simulatorfscommon.h +++ b/src/plugins/simulator/fscommon/simulatorfscommon.h @@ -57,7 +57,7 @@ namespace BlackSimPlugin //! \copydoc BlackCore::ISimulator::getInstalledModels virtual BlackMisc::Simulation::CAircraftModelList getInstalledModels() const override; - //! \copydoc BlackCore::IContextSimulator::iconForModel + //! \copydoc BlackCore::Context::IContextSimulator::iconForModel virtual BlackMisc::CPixmap iconForModel(const QString &modelString) const override; //! \copydoc BlackCore::ISimulator::changeRemoteAircraftModel diff --git a/src/plugins/simulator/fsxconfig/simconnectsettingscomponent.cpp b/src/plugins/simulator/fsxconfig/simconnectsettingscomponent.cpp index 777e6dd0c..4a6093f55 100644 --- a/src/plugins/simulator/fsxconfig/simconnectsettingscomponent.cpp +++ b/src/plugins/simulator/fsxconfig/simconnectsettingscomponent.cpp @@ -10,8 +10,8 @@ #include "simconnectsettingscomponent.h" #include "ui_simconnectsettingscomponent.h" #include "blackgui/guiapplication.h" -#include "blackcore/contextapplication.h" -#include "blackcore/contextsimulator.h" +#include "blackcore/context/contextapplication.h" +#include "blackcore/context/contextsimulator.h" #include "blackmisc/network/networkutils.h" #include "blackmisc/logmessage.h" #include "blackmisc/simulation/fsx/fsxsimulatorsetup.h" diff --git a/src/swiftguistandard/swiftguistd.cpp b/src/swiftguistandard/swiftguistd.cpp index 9d55f7b32..081c924a8 100644 --- a/src/swiftguistandard/swiftguistd.cpp +++ b/src/swiftguistandard/swiftguistd.cpp @@ -7,9 +7,9 @@ * contained in the LICENSE file. */ -#include "blackcore/contextapplication.h" -#include "blackcore/contextaudio.h" -#include "blackcore/contextnetwork.h" +#include "blackcore/context/contextapplication.h" +#include "blackcore/context/contextaudio.h" +#include "blackcore/context/contextnetwork.h" #include "blackcore/network.h" #include "blackgui/components/infobarstatuscomponent.h" #include "blackgui/components/logcomponent.h" diff --git a/src/swiftguistandard/swiftguistdaircraft.cpp b/src/swiftguistandard/swiftguistdaircraft.cpp index 76c1c69f5..9c69e77e7 100644 --- a/src/swiftguistandard/swiftguistdaircraft.cpp +++ b/src/swiftguistandard/swiftguistdaircraft.cpp @@ -7,7 +7,7 @@ * contained in the LICENSE file. */ -#include "blackcore/contextownaircraft.h" +#include "blackcore/context/contextownaircraft.h" #include "blackgui/guiapplication.h" #include "blackmisc/compare.h" #include "blackmisc/geo/coordinategeodetic.h" diff --git a/src/swiftguistandard/swiftguistdinit.cpp b/src/swiftguistandard/swiftguistdinit.cpp index 71e9a0a2e..cdf9d2be1 100644 --- a/src/swiftguistandard/swiftguistdinit.cpp +++ b/src/swiftguistandard/swiftguistdinit.cpp @@ -8,7 +8,7 @@ */ #include "blackconfig/buildconfig.h" -#include "blackcore/contextnetwork.h" +#include "blackcore/context/contextnetwork.h" #include "blackgui/components/aircraftcomponent.h" #include "blackgui/components/atcstationcomponent.h" #include "blackgui/components/cockpitcomponent.h" @@ -47,6 +47,7 @@ class QHBoxLayout; using namespace BlackConfig; using namespace BlackCore; +using namespace BlackCore::Context; using namespace BlackMisc; using namespace BlackMisc::Input; using namespace BlackGui;