refs #268 added DBus proxy object for XBus::CService

This commit is contained in:
Mathew Sutcliffe
2014-06-15 13:13:25 +01:00
parent 7d29049326
commit df67c249df
2 changed files with 210 additions and 0 deletions

View File

@@ -0,0 +1,106 @@
/* 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/. */
#include "xbus_service_proxy.h"
#include "blackcore/dbus_server.h"
#include <QMetaMethod>
namespace BlackSimPlugin
{
namespace XPlane
{
CXBusServiceProxy::CXBusServiceProxy(QDBusConnection &connection, QObject *parent) : QObject(parent)
{
m_dbusInterface = new BlackMisc::CGenericDBusInterface(BlackCore::CDBusServer::ServiceName, ObjectPath(), InterfaceName(), connection, this);
relaySignals();
}
void CXBusServiceProxy::relaySignals()
{
// TODO can this be refactored into CGenericDBusInterface?
for (int i = 0, count = metaObject()->methodCount(); i < count; ++i)
{
auto method = metaObject()->method(i);
if (method.methodType() == QMetaMethod::Signal)
{
m_dbusInterface->connection().connect(m_dbusInterface->service(), m_dbusInterface->path(), m_dbusInterface->interface(),
method.name(), this, method.methodSignature());
}
}
}
int CXBusServiceProxy::getXPlaneVersionMajor() const
{
return m_dbusInterface->callDBusRet<int>(QLatin1String("getXPlaneVersionMajor"));
}
int CXBusServiceProxy::getXPlaneVersionMinor() const
{
return m_dbusInterface->callDBusRet<int>(QLatin1String("getXPlaneVersionMinor"));
}
QString CXBusServiceProxy::getXPlaneInstallationPath() const
{
return m_dbusInterface->callDBusRet<QString>(QLatin1String("getXPlaneInstallationPath"));
}
QString CXBusServiceProxy::getXPlanePreferencesPath() const
{
return m_dbusInterface->callDBusRet<QString>(QLatin1String("getXPlanePreferencesPath"));
}
double CXBusServiceProxy::getLatitude() const
{
return m_dbusInterface->callDBusRet<double>(QLatin1String("getLatitude"));
}
double CXBusServiceProxy::getLongitude() const
{
return m_dbusInterface->callDBusRet<double>(QLatin1String("getLongitude"));
}
double CXBusServiceProxy::getAltitudeMSL() const
{
return m_dbusInterface->callDBusRet<double>(QLatin1String("getAltitudeMSL"));
}
double CXBusServiceProxy::getHeightAGL() const
{
return m_dbusInterface->callDBusRet<double>(QLatin1String("getHeightAGL"));
}
double CXBusServiceProxy::getGroundSpeed() const
{
return m_dbusInterface->callDBusRet<double>(QLatin1String("getGroundSpeed"));
}
double CXBusServiceProxy::getIndicatedAirspeed() const
{
return m_dbusInterface->callDBusRet<double>(QLatin1String("getIndicatedAirspeed"));
}
double CXBusServiceProxy::getTrueAirspeed() const
{
return m_dbusInterface->callDBusRet<double>(QLatin1String("getTrueAirspeed"));
}
double CXBusServiceProxy::getPitch() const
{
return m_dbusInterface->callDBusRet<double>(QLatin1String("getPitch"));
}
double CXBusServiceProxy::getRoll() const
{
return m_dbusInterface->callDBusRet<double>(QLatin1String("getRoll"));
}
double CXBusServiceProxy::getTrueHeading() const
{
return m_dbusInterface->callDBusRet<double>(QLatin1String("getTrueHeading"));
}
}
}

View File

@@ -0,0 +1,104 @@
/* 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 BLACKSIMPLUGIN_XBUS_SERVICE_PROXY_H
#define BLACKSIMPLUGIN_XBUS_SERVICE_PROXY_H
//! \file
#include "blackmisc/genericdbusinterface.h"
//! \private
#define XBUS_SERVICE_INTERFACENAME "net.vatsim.PilotClient.XBus"
//! \private
#define XBUS_SERVICE_OBJECTPATH "/XBus"
namespace BlackSimPlugin
{
namespace XPlane
{
/*!
* Proxy object connected to a real XBus::CService object via DBus
*/
class CXBusServiceProxy : public QObject
{
Q_OBJECT
public:
//! Service name
static const QString &InterfaceName()
{
static QString s(XBUS_SERVICE_INTERFACENAME);
return s;
}
//! Service path
static const QString &ObjectPath()
{
static QString s(XBUS_SERVICE_OBJECTPATH);
return s;
}
//! Constructor
CXBusServiceProxy(QDBusConnection &connection, QObject *parent = nullptr);
private:
BlackMisc::CGenericDBusInterface *m_dbusInterface = nullptr;
void relaySignals();
signals:
//! \copydoc XBus::CService::aircraftModelChanged
void aircraftModelChanged(const QString &path, const QString &filename, const QString &livery);
public slots:
//! \copydoc XBus::CService::getXPlaneVersionMajor
int getXPlaneVersionMajor() const;
//! \copydoc XBus::CService::getXPlaneVersionMinor
int getXPlaneVersionMinor() const;
//! \copydoc XBus::CService::getXPlaneInstallationPath
QString getXPlaneInstallationPath() const;
//! \copydoc XBus::CService::getXPlanePreferencesPath
QString getXPlanePreferencesPath() const;
//! \copydoc XBus::CService::getLatitude
double getLatitude() const;
//! \copydoc XBus::CService::getLongitude
double getLongitude() const;
//! \copydoc XBus::CService::getAltitudeMSL
double getAltitudeMSL() const;
//! \copydoc XBus::CService::getHeightAGL
double getHeightAGL() const;
//! \copydoc XBus::CService::getGroundSpeed
double getGroundSpeed() const;
//! \copydoc XBus::CService::getIndicatedAirspeed
double getIndicatedAirspeed() const;
//! \copydoc XBus::CService::getTrueAirspeed
double getTrueAirspeed() const;
//! \copydoc XBus::CService::getPitch
double getPitch() const;
//! \copydoc XBus::CService::getRoll
double getRoll() const;
//! \copydoc XBus::CService::getTrueHeading
double getTrueHeading() const;
};
}
}
#endif // guard