Add DBus implementation for IContextSimulator

This class implements the DBus version off simulator context.
When one of its methods is called, it forwards it to
the configured DBus session/server.
refs #135
This commit is contained in:
Roland Winklmeier
2014-02-10 22:35:29 +01:00
parent 1d6572d222
commit c7d35d29a4
3 changed files with 114 additions and 5 deletions

View File

@@ -57,19 +57,17 @@ namespace BlackCore
return static_cast<CCoreRuntime *>(this->parent());
}
/*!
* \brief Using local objects?
* \return
*/
//! \copydoc IContextSimulator::usingLocalObjects()
virtual bool usingLocalObjects() const override { return true; }
virtual BlackMisc::Aviation::CAircraft ownAircraft() const override;
public slots:
//! \copydoc IContextSimulator::isConnected()
virtual bool isConnected() const override;
private slots:
//! \copydoc IContextSimulator::updateOwnAircraft()
virtual void updateOwnAircraft();
/*!

View File

@@ -0,0 +1,43 @@
/* 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_simulator_proxy.h"
#include <QObject>
#include <QMetaEnum>
#include <QDBusConnection>
using namespace BlackMisc;
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Aviation;
using namespace BlackMisc::Geo;
namespace BlackCore
{
// Constructor for DBus
CContextSimulatorProxy::CContextSimulatorProxy(const QString &serviceName, QDBusConnection &connection, QObject *parent) : IContextSimulator(parent), m_dBusInterface(0)
{
this->m_dBusInterface = new BlackMisc::CGenericDBusInterface(
serviceName , IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(),
connection, this);
this->relaySignals(serviceName, connection);
}
// Workaround for signals, not working without, but why?
void CContextSimulatorProxy::relaySignals(const QString &/*serviceName*/, QDBusConnection &/*connection*/)
{
}
bool CContextSimulatorProxy::isConnected() const
{
return m_dBusInterface->callDBusRet<bool>(QLatin1Literal("isConnected"));
}
BlackMisc::Aviation::CAircraft CContextSimulatorProxy::ownAircraft() const
{
return m_dBusInterface->callDBusRet<BlackMisc::Aviation::CAircraft>(QLatin1Literal("ownAircraft"));
}
} // namespace BlackCore

View File

@@ -0,0 +1,68 @@
/* 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_CONTEXTSIMULATOR_PROXY_H
#define BLACKCORE_CONTEXTSIMULATOR_PROXY_H
#include "blackcore/context_simulator.h"
#include "blackmisc/genericdbusinterface.h"
namespace BlackCore
{
//! \brief DBus proxy for Simulator Context
class CContextSimulatorProxy : public IContextSimulator
{
Q_OBJECT
public:
/*!
* \brief DBus version constructor
* \param serviceName
* \param connection
* \param parent
*/
CContextSimulatorProxy(const QString &serviceName, QDBusConnection &connection, QObject *parent = 0);
//! Destructor
~CContextSimulatorProxy() {}
/*!
* \brief Using local objects?
* \return
*/
virtual bool usingLocalObjects() const override { return false; }
virtual BlackMisc::Aviation::CAircraft ownAircraft() const override;
private:
BlackMisc::CGenericDBusInterface *m_dBusInterface;
/*!
* Relay connection signals to local signals
* No idea why this has to be wired and is not done automatically
* \param connection
*/
void relaySignals(const QString &serviceName, QDBusConnection &connection);
protected:
/*!
* \brief CContextNetworkProxy
* \param parent
*/
CContextSimulatorProxy(QObject *parent = nullptr) : IContextSimulator(parent), m_dBusInterface(0) {}
signals:
public slots:
//! \copydoc IContextSimulator::isConnected()
virtual bool isConnected() const override;
//virtual void ownAircraftUpdateReceived(BlackMisc::Aviation::CAircraft aircraft) override;
};
} // namespace BlackCore
#endif // BLACKCORE_CONTEXTSIMULATOR_PROXY_H