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
This commit is contained in:
Roland Winklmeier
2014-02-10 22:34:01 +01:00
parent 6fac031720
commit 1d6572d222
2 changed files with 158 additions and 0 deletions

View File

@@ -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

View File

@@ -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 <QTimer>
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<CCoreRuntime *>(this->parent());
}
/*!
* \brief Runtime
* \return
*/
CCoreRuntime *getRuntime()
{
return static_cast<CCoreRuntime *>(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