From 1d6572d22227178dfc236129c1acb564f861dbde Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Mon, 10 Feb 2014 22:34:01 +0100 Subject: [PATCH] Add local implementation for IContextSimulator This class implements the local BlackCore object for the simulator context. It initializes its member variables with default values. refs #135 --- src/blackcore/context_simulator_impl.cpp | 67 +++++++++++++++++ src/blackcore/context_simulator_impl.h | 91 ++++++++++++++++++++++++ 2 files changed, 158 insertions(+) create mode 100644 src/blackcore/context_simulator_impl.cpp create mode 100644 src/blackcore/context_simulator_impl.h diff --git a/src/blackcore/context_simulator_impl.cpp b/src/blackcore/context_simulator_impl.cpp new file mode 100644 index 000000000..a91b588bf --- /dev/null +++ b/src/blackcore/context_simulator_impl.cpp @@ -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/. */ + +#include "context_simulator_impl.h" +#include "coreruntime.h" +#include "fsx/simulator_fsx.h" + +using namespace BlackMisc; +using namespace BlackMisc::PhysicalQuantities; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::Geo; + +namespace BlackCore +{ + // Init this context + CContextSimulator::CContextSimulator(QObject *parent) : + IContextSimulator(parent), + m_simulator(new BlackCore::FSX::CSimulatorFSX(this)), + m_updateTimer(nullptr), + m_contextNetwork(nullptr) + + { + m_updateTimer = new QTimer(this); + connect(m_simulator, &ISimulator::connectionChanged, this, &CContextSimulator::setConnectionStatus); + connect(m_updateTimer, &QTimer::timeout, this, &CContextSimulator::updateOwnAircraft); + } + + // Cleanup + CContextSimulator::~CContextSimulator() + { + } + + bool CContextSimulator::isConnected() const + { + return m_simulator->isConnected(); + } + + BlackMisc::Aviation::CAircraft CContextSimulator::ownAircraft() const + { + return m_ownAircraft; + } + + void CContextSimulator::updateOwnAircraft() + { + m_ownAircraft = m_simulator->getOwnAircraft(); + + if (!m_contextNetwork) + { + m_contextNetwork = getRuntime()->getIContextNetwork(); + } + + m_contextNetwork->updateOwnSituation(m_ownAircraft.getSituation()); + m_contextNetwork->updateOwnCockpit(m_ownAircraft.getCom1System(), m_ownAircraft.getCom2System(), m_ownAircraft.getTransponder()); + } + + void CContextSimulator::setConnectionStatus(bool value) + { + if (value) + m_updateTimer->start(100); + else + m_updateTimer->stop(); + emit connectionChanged(value); + } + +} // namespace BlackCore diff --git a/src/blackcore/context_simulator_impl.h b/src/blackcore/context_simulator_impl.h new file mode 100644 index 000000000..c8d0c85ba --- /dev/null +++ b/src/blackcore/context_simulator_impl.h @@ -0,0 +1,91 @@ +/* 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_CONTEXTSIMULATOR_IMPL_H +#define BLACKCORE_CONTEXTSIMULATOR_IMPL_H + +#include "blackcore/context_simulator.h" +#include "blackcore/context_network_interface.h" +#include "blackcore/simulator.h" + +#include + +namespace BlackCore +{ + /*! + * \brief Network simulator concrete implementation + */ + class CContextSimulator : public IContextSimulator + { + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTSIMULATOR_INTERFACENAME) + + public: + //! \brief Constructor + CContextSimulator(QObject *parent = nullptr); + + //! \brief Destructor + virtual ~CContextSimulator(); + + /*! + * \brief Register myself in DBus + * \param server + */ + void registerWithDBus(CDBusServer *server) + { + Q_ASSERT(server); + server->addObject(CContextSimulator::ObjectPath(), this); + } + + /*! + * \brief Runtime + * \return + */ + const CCoreRuntime *getRuntime() const + { + return static_cast(this->parent()); + } + + /*! + * \brief Runtime + * \return + */ + CCoreRuntime *getRuntime() + { + return static_cast(this->parent()); + } + + /*! + * \brief Using local objects? + * \return + */ + virtual bool usingLocalObjects() const override { return true; } + + virtual BlackMisc::Aviation::CAircraft ownAircraft() const override; + + public slots: + + virtual bool isConnected() const override; + + private slots: + virtual void updateOwnAircraft(); + + /*! + * \brief Set new connection status + * \param value + */ + void setConnectionStatus(bool value); + + private: + BlackMisc::Aviation::CAircraft m_ownAircraft; + BlackCore::ISimulator *m_simulator; + + QTimer *m_updateTimer; + BlackCore::IContextNetwork *m_contextNetwork; + }; + +} // namespace BlackCore + +#endif // BLACKCORE_CONTEXTSIMULATOR_IMPL_H