From 9de387acf968dedbc9c5fbe474be8c6b0c0f21f0 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 20 May 2014 20:54:23 +0200 Subject: [PATCH] refs #242, own aircraft context --- src/blackcore/context_all_interfaces.h | 1 + src/blackcore/context_all_proxies.h | 2 + src/blackcore/context_ownaircraft.h | 74 +++++++++++ src/blackcore/context_ownaircraft_impl.cpp | 130 ++++++++++++++++++++ src/blackcore/context_ownaircraft_impl.h | 67 ++++++++++ src/blackcore/context_ownaircraft_proxy.cpp | 63 ++++++++++ src/blackcore/context_ownaircraft_proxy.h | 59 +++++++++ 7 files changed, 396 insertions(+) create mode 100644 src/blackcore/context_ownaircraft.h create mode 100644 src/blackcore/context_ownaircraft_impl.cpp create mode 100644 src/blackcore/context_ownaircraft_impl.h create mode 100644 src/blackcore/context_ownaircraft_proxy.cpp create mode 100644 src/blackcore/context_ownaircraft_proxy.h diff --git a/src/blackcore/context_all_interfaces.h b/src/blackcore/context_all_interfaces.h index b22d978dd..59472f732 100644 --- a/src/blackcore/context_all_interfaces.h +++ b/src/blackcore/context_all_interfaces.h @@ -4,6 +4,7 @@ #include "context_application.h" #include "context_audio.h" #include "context_network.h" +#include "context_ownaircraft.h" #include "context_settings.h" #include "context_simulator.h" diff --git a/src/blackcore/context_all_proxies.h b/src/blackcore/context_all_proxies.h index 47694c700..72a9f72c5 100644 --- a/src/blackcore/context_all_proxies.h +++ b/src/blackcore/context_all_proxies.h @@ -4,7 +4,9 @@ #include "context_application_proxy.h" #include "context_audio_proxy.h" #include "context_network_proxy.h" +#include "context_ownaircraft_proxy.h" #include "context_settings_proxy.h" #include "context_simulator_proxy.h" + #endif // guard diff --git a/src/blackcore/context_ownaircraft.h b/src/blackcore/context_ownaircraft.h new file mode 100644 index 000000000..fff757520 --- /dev/null +++ b/src/blackcore/context_ownaircraft.h @@ -0,0 +1,74 @@ +/* Copyright (C) 2013 VATSIM Community / contributors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BLACKCORE_CONTEXTOWNAIRCRAFT_H +#define BLACKCORE_CONTEXTOWNAIRCRAFT_H + +#include "blackcore/context.h" +#include "blackmisc/avallclasses.h" +#include "blackmisc/statusmessagelist.h" + +#define BLACKCORE_CONTEXTOWNAIRCRAFT_INTERFACENAME "net.vatsim.PilotClient.BlackCore.ContextOwnAircraft" +#define BLACKCORE_CONTEXTOWNAIRCRAFT_OBJECTPATH "/OwnAircraft" + +namespace BlackCore +{ + + //! \brief Own context proxy + class 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; + } + + //! Destructor + virtual ~IContextOwnAircraft() {} + + signals: + //! Aircraft situation update + void changedAircraftSituation(const BlackMisc::Aviation::CAircraftSituation &situation); + + public slots: + + //! Get own aircraft + virtual BlackMisc::Aviation::CAircraft getOwnAircraft() const = 0; + + /*! + * Set own aircraft + * \param aircraft + * \return message list, as aircraft can only be set prior connecting + */ + virtual BlackMisc::CStatusMessageList setOwnAircraft(const BlackMisc::Aviation::CAircraft &aircraft) = 0; + + //! Own position, be aware height is terrain height + virtual void updateOwnPosition(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::Aviation::CAltitude &altitude) = 0; + + //! Complete situation update + virtual void updateOwnSituation(const BlackMisc::Aviation::CAircraftSituation &situation) = 0; + + //! Update own cockpit + virtual void updateOwnCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder) = 0; + + protected: + //! Constructor + IContextOwnAircraft(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : CContext(mode, runtime) {} + }; +} + +#endif // guard diff --git a/src/blackcore/context_ownaircraft_impl.cpp b/src/blackcore/context_ownaircraft_impl.cpp new file mode 100644 index 000000000..763f3859b --- /dev/null +++ b/src/blackcore/context_ownaircraft_impl.cpp @@ -0,0 +1,130 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "context_ownaircraft_impl.h" +#include "context_runtime.h" +#include "context_settings.h" + + +using namespace BlackMisc; +using namespace BlackMisc::PhysicalQuantities; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::Network; +using namespace BlackMisc::Geo; + +namespace BlackCore +{ + + /* + * Init this context + */ + CContextOwnAircraft::CContextOwnAircraft(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : + IContextOwnAircraft(mode, runtime) + { + Q_ASSERT(this->getRuntime()); + Q_ASSERT(this->getRuntime()->getIContextSettings()); + + // 1. Init own aircraft + this->initOwnAircraft(); + + // 2. connect signals and slots + } + + /* + * Cleanup + */ + CContextOwnAircraft::~CContextOwnAircraft() + { + } + + /* + * Init own aircraft + */ + void CContextOwnAircraft::initOwnAircraft() + { + Q_ASSERT(this->getRuntime()); + Q_ASSERT(this->getRuntime()->getIContextSettings()); + 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->getIContextSettings()->getNetworkSettings().getCurrentTrafficNetworkServer().getUser()); + + // TODO: This would need to come from somewhere (mappings) + // Own callsign, plane ICAO status, model used + this->m_ownAircraft.setCallsign(CCallsign("BLACK")); + this->m_ownAircraft.setIcaoInfo(CAircraftIcao("C172", "L1P", "GA", "GA", "0000ff")); + } + + /* + * Own Aircraft + */ + CStatusMessageList CContextOwnAircraft::setOwnAircraft(const BlackMisc::Aviation::CAircraft &aircraft) + { + this->m_ownAircraft = aircraft; + return CStatusMessageList(); + } + + /* + * Own position + */ + void CContextOwnAircraft::updateOwnPosition(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::Aviation::CAltitude &altitude) + { + if (this->getRuntime()->isSlotLogForOwnAircraftEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, position.toQString(), altitude.toQString()); + this->m_ownAircraft.setPosition(position); + this->m_ownAircraft.setAltitude(altitude); + } + + /* + * Update own situation + */ + void CContextOwnAircraft::updateOwnSituation(const BlackMisc::Aviation::CAircraftSituation &situation) + { + if (this->getRuntime()->isSlotLogForOwnAircraftEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, situation.toQString()); + this->m_ownAircraft.setSituation(situation); + } + + /* + * Own cockpit data + */ + void CContextOwnAircraft::updateOwnCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder) + { + if (this->getRuntime()->isSlotLogForOwnAircraftEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, com1.toQString(), com2.toQString(), transponder.toQString()); + bool changed = false; + if (com1 != this->m_ownAircraft.getCom1System()) + { + this->m_ownAircraft.setCom1System(com1); + changed = true; + } + if (com2 != this->m_ownAircraft.getCom2System()) + { + this->m_ownAircraft.setCom2System(com2); + changed = true; + } + if (transponder != this->m_ownAircraft.getTransponder()) + { + this->m_ownAircraft.setTransponder(transponder); + changed = true; + } + + if (!changed) return; + } + + /* + * Own aircraft + */ + CAircraft CContextOwnAircraft::getOwnAircraft() const + { + if (this->getRuntime()->isSlotLogForOwnAircraftEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, this->m_ownAircraft.toQString()); + return this->m_ownAircraft; + } + +} // namespace diff --git a/src/blackcore/context_ownaircraft_impl.h b/src/blackcore/context_ownaircraft_impl.h new file mode 100644 index 000000000..c88348b52 --- /dev/null +++ b/src/blackcore/context_ownaircraft_impl.h @@ -0,0 +1,67 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BLACKCORE_CONTEXTOWNAIRCRAFT_IMPL_H +#define BLACKCORE_CONTEXTOWNAIRCRAFT_IMPL_H + +#include "blackcore/context_ownaircraft.h" +#include "blackcore/context_settings.h" +#include "blackcore/context_runtime.h" +#include "blackcore/dbus_server.h" + +namespace BlackCore +{ + + //! Network context implementation + class CContextOwnAircraft : public IContextOwnAircraft + { + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTOWNAIRCRAFT_INTERFACENAME) + friend class CRuntime; + + public: + //! Destructor + virtual ~CContextOwnAircraft(); + + public slots: // IContextOwnAircraft overrides + + //! \copydoc IContextOwnAircraft::setOwnAircraft() + virtual BlackMisc::CStatusMessageList setOwnAircraft(const BlackMisc::Aviation::CAircraft &aircraft) override; + + //! \copydoc IContextOwnAircraft::updateOwnPosition() + virtual void updateOwnPosition(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::Aviation::CAltitude &altitude) override; + + //! \copydoc IContextOwnAircraft::updateOwnSituation() + virtual void updateOwnSituation(const BlackMisc::Aviation::CAircraftSituation &situation) override; + + //! \copydoc IContextOwnAircraft::updateOwnCockpit() + virtual void updateOwnCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder) override; + + //! \copydoc IContextOwnAircraft::getOwnAircraft() + virtual BlackMisc::Aviation::CAircraft getOwnAircraft() const override; + + protected: + //! Constructor, with link to runtime + CContextOwnAircraft(CRuntimeConfig::ContextMode, CRuntime *runtime); + + //! Register myself in DBus + CContextOwnAircraft *registerWithDBus(CDBusServer *server) + { + if (!server || this->m_mode != CRuntimeConfig::LocalInDbusServer) return this; + server->addObject(IContextOwnAircraft::ObjectPath(), this); + return this; + } + + private: + BlackMisc::Aviation::CAircraft m_ownAircraft; + + //! Init my very own aircraft + void initOwnAircraft(); + + + }; +} + +#endif // guard diff --git a/src/blackcore/context_ownaircraft_proxy.cpp b/src/blackcore/context_ownaircraft_proxy.cpp new file mode 100644 index 000000000..0ebb2cd2d --- /dev/null +++ b/src/blackcore/context_ownaircraft_proxy.cpp @@ -0,0 +1,63 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "blackcore/context_ownaircraft_proxy.h" +#include +#include +#include + +namespace BlackCore +{ + + /* + * Constructor for DBus + */ + CContextOwnAircraftProxy::CContextOwnAircraftProxy(const QString &serviceName, QDBusConnection &connection, CRuntimeConfig::ContextMode mode, CRuntime *runtime) : IContextOwnAircraft(mode, runtime), m_dBusInterface(nullptr) + { + this->m_dBusInterface = new BlackMisc::CGenericDBusInterface( + serviceName , IContextOwnAircraft::ObjectPath(), IContextOwnAircraft::InterfaceName(), + connection, this); + this->relaySignals(serviceName, connection); + } + + /* + * Workaround for signals, not working without, but why? + */ + void CContextOwnAircraftProxy::relaySignals(const QString &serviceName, QDBusConnection &connection) + { +// bool s; = connection.connect(serviceName, IContextOwnAircraft::ObjectPath(), IContextOwnAircraft::InterfaceName(), +// "connectionStatusChanged", this, SIGNAL(connectionStatusChanged(uint, uint, const QString &))); +// Q_ASSERT(s); +// s = connection.connect(serviceName, IContextOwnAircraft::ObjectPath(), IContextOwnAircraft::InterfaceName(), +// "changedAtcStationsBooked", this, SIGNAL(changedAtcStationsBooked())); +// Q_ASSERT(s); +// Q_UNUSED(s); + } + + BlackMisc::Aviation::CAircraft CContextOwnAircraftProxy::getOwnAircraft() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getOwnAircraft")); + } + + BlackMisc::CStatusMessageList CContextOwnAircraftProxy::setOwnAircraft(const BlackMisc::Aviation::CAircraft &aircraft) + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("setOwnAircraft"), aircraft); + } + + void CContextOwnAircraftProxy::updateOwnPosition(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::Aviation::CAltitude &altitude) + { + this->m_dBusInterface->callDBus(QLatin1Literal("updateOwnPosition"), position, altitude); + } + + void CContextOwnAircraftProxy::updateOwnSituation(const BlackMisc::Aviation::CAircraftSituation &situation) + { + this->m_dBusInterface->callDBus(QLatin1Literal("updateOwnSituation"), situation); + } + + void CContextOwnAircraftProxy::updateOwnCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder) + { + this->m_dBusInterface->callDBus(QLatin1Literal("updateOwnCockpit"), com1, com2, transponder); + } +} // namespace diff --git a/src/blackcore/context_ownaircraft_proxy.h b/src/blackcore/context_ownaircraft_proxy.h new file mode 100644 index 000000000..c216ee8d0 --- /dev/null +++ b/src/blackcore/context_ownaircraft_proxy.h @@ -0,0 +1,59 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BLACKCORE_OWNAIRCRAFT_PROXY_H +#define BLACKCORE_OWNAIRCRAFT_PROXY_H + +#include "blackcore/context_ownaircraft.h" +#include "blackmisc/genericdbusinterface.h" +#include "blackmisc/avallclasses.h" + +namespace BlackCore +{ + + //! \brief Network context proxy + class CContextOwnAircraftProxy : public IContextOwnAircraft + { + Q_OBJECT + friend class CRuntime; + + public: + + //! Destructor + virtual ~CContextOwnAircraftProxy() {} + + private: + BlackMisc::CGenericDBusInterface *m_dBusInterface; /*!< DBus interface */ + + //! \brief Relay connection signals to local signals. + void relaySignals(const QString &serviceName, QDBusConnection &connection); + + protected: + //! \brief Constructor + CContextOwnAircraftProxy(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : IContextOwnAircraft(mode, runtime), m_dBusInterface(nullptr) {} + + //! \brief DBus version constructor + CContextOwnAircraftProxy(const QString &serviceName, QDBusConnection &connection, CRuntimeConfig::ContextMode mode, CRuntime *runtime); + + public slots: // IContextOwnAircraft overrides + + //! \copydoc IContextOwnAircraft::setOwnAircraft() + virtual BlackMisc::CStatusMessageList setOwnAircraft(const BlackMisc::Aviation::CAircraft &aircraft) override; + + //! \copydoc IContextOwnAircraft::updateOwnPosition() + virtual void updateOwnPosition(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::Aviation::CAltitude &altitude) override; + + //! \copydoc IContextOwnAircraft::updateOwnSituation() + virtual void updateOwnSituation(const BlackMisc::Aviation::CAircraftSituation &situation) override; + + //! \copydoc IContextOwnAircraft::updateOwnCockpit() + virtual void updateOwnCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder) override; + + //! \copydoc IContextOwnAircraft::getOwnAircraft() + virtual BlackMisc::Aviation::CAircraft getOwnAircraft() const override; + }; +} + +#endif // guard