From 03b7418d038ab4a2965e97eb2ecd7ce8ac378023 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Mon, 21 Apr 2014 14:56:05 +0200 Subject: [PATCH] Add connectTo/disconnectFrom/canConnect to simulator context refs #187 --- src/blackcore/context_simulator.h | 9 ++++++++ src/blackcore/context_simulator_impl.cpp | 27 ++++++++++++++++++++++- src/blackcore/context_simulator_impl.h | 10 +++++++++ src/blackcore/context_simulator_proxy.cpp | 15 +++++++++++++ src/blackcore/context_simulator_proxy.h | 10 +++++++++ 5 files changed, 70 insertions(+), 1 deletion(-) diff --git a/src/blackcore/context_simulator.h b/src/blackcore/context_simulator.h index 27ec4d177..44f306a04 100644 --- a/src/blackcore/context_simulator.h +++ b/src/blackcore/context_simulator.h @@ -51,6 +51,15 @@ namespace BlackCore //! Returns true when simulator is connected and available virtual bool isConnected() const = 0; + //! \brief Can we connect? + virtual bool canConnect() = 0; + + //! \brief Connect to simulator + virtual bool connectTo() = 0; + + //! \brief Disconnect from simulator + virtual bool disconnectFrom() = 0; + //! Get user aircraft value object virtual BlackMisc::Aviation::CAircraft getOwnAircraft() const = 0; diff --git a/src/blackcore/context_simulator_impl.cpp b/src/blackcore/context_simulator_impl.cpp index 813cd2327..4842482cd 100644 --- a/src/blackcore/context_simulator_impl.cpp +++ b/src/blackcore/context_simulator_impl.cpp @@ -24,9 +24,13 @@ namespace BlackCore m_updateTimer = new QTimer(this); loadPlugins(); connect(m_updateTimer, &QTimer::timeout, this, &CContextSimulator::updateOwnAircraft); + connectTo(); } - CContextSimulator::~CContextSimulator() {} + CContextSimulator::~CContextSimulator() + { + disconnectFrom(); + } bool CContextSimulator::isConnected() const { @@ -35,6 +39,27 @@ namespace BlackCore return m_simulator->isConnected(); } + bool CContextSimulator::canConnect() + { + if (this->getRuntime()->isSlotLogForSimulatorEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO); + if (!m_simulator) return false; + return m_simulator->canConnect(); + } + + bool CContextSimulator::connectTo() + { + if (this->getRuntime()->isSlotLogForSimulatorEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO); + if (!m_simulator) return false; + return m_simulator->connectTo(); + } + + bool CContextSimulator::disconnectFrom() + { + if (this->getRuntime()->isSlotLogForSimulatorEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO); + if (!m_simulator) return false; + return m_simulator->disconnectFrom(); + } + BlackMisc::Aviation::CAircraft CContextSimulator::getOwnAircraft() const { if (this->getRuntime()->isSlotLogForSimulatorEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO); diff --git a/src/blackcore/context_simulator_impl.h b/src/blackcore/context_simulator_impl.h index 91d70d0df..312db541a 100644 --- a/src/blackcore/context_simulator_impl.h +++ b/src/blackcore/context_simulator_impl.h @@ -29,9 +29,19 @@ namespace BlackCore virtual ~CContextSimulator(); public slots: + //! \copydoc IContextSimulator::isConnected() virtual bool isConnected() const override; + //! \brief Can we connect? + virtual bool canConnect() override; + + //! \brief Connect to simulator + virtual bool connectTo() override; + + //! \brief Disconnect from simulator + virtual bool disconnectFrom() override; + //! \copydoc IContextSimulator::getOwnAircraft() virtual BlackMisc::Aviation::CAircraft getOwnAircraft() const override; diff --git a/src/blackcore/context_simulator_proxy.cpp b/src/blackcore/context_simulator_proxy.cpp index 9bf1677ae..5542938df 100644 --- a/src/blackcore/context_simulator_proxy.cpp +++ b/src/blackcore/context_simulator_proxy.cpp @@ -32,6 +32,21 @@ namespace BlackCore return m_dBusInterface->callDBusRet(QLatin1Literal("isConnected")); } + bool CContextSimulatorProxy::canConnect() + { + return m_dBusInterface->callDBusRet(QLatin1Literal("canConnect")); + } + + bool CContextSimulatorProxy::connectTo() + { + return m_dBusInterface->callDBusRet(QLatin1Literal("connectTo")); + } + + bool CContextSimulatorProxy::disconnectFrom() + { + return m_dBusInterface->callDBusRet(QLatin1Literal("disconnectFrom")); + } + BlackMisc::Aviation::CAircraft CContextSimulatorProxy::getOwnAircraft() const { return m_dBusInterface->callDBusRet(QLatin1Literal("getOwnAircraft")); diff --git a/src/blackcore/context_simulator_proxy.h b/src/blackcore/context_simulator_proxy.h index 9711eb6da..c680e2899 100644 --- a/src/blackcore/context_simulator_proxy.h +++ b/src/blackcore/context_simulator_proxy.h @@ -35,9 +35,19 @@ namespace BlackCore CContextSimulatorProxy(const QString &serviceName, QDBusConnection &connection, CRuntimeConfig::ContextMode mode, CRuntime *runtime); public slots: + //! \copydoc IContextSimulator::isConnected() virtual bool isConnected() const override; + //! \brief Can we connect? + virtual bool canConnect() override; + + //! \brief Connect to simulator + virtual bool connectTo() override; + + //! \brief Disconnect from simulator + virtual bool disconnectFrom() override; + //! \copydoc IContextSimulator::getOwnAircraft() virtual BlackMisc::Aviation::CAircraft getOwnAircraft() const override;