From df67c249dfc966192c9cef40c320157c2044251e Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Sun, 15 Jun 2014 13:13:25 +0100 Subject: [PATCH] refs #268 added DBus proxy object for XBus::CService --- .../simulator/xplane/xbus_service_proxy.cpp | 106 ++++++++++++++++++ .../simulator/xplane/xbus_service_proxy.h | 104 +++++++++++++++++ 2 files changed, 210 insertions(+) create mode 100644 src/plugins/simulator/xplane/xbus_service_proxy.cpp create mode 100644 src/plugins/simulator/xplane/xbus_service_proxy.h diff --git a/src/plugins/simulator/xplane/xbus_service_proxy.cpp b/src/plugins/simulator/xplane/xbus_service_proxy.cpp new file mode 100644 index 000000000..7ac700e38 --- /dev/null +++ b/src/plugins/simulator/xplane/xbus_service_proxy.cpp @@ -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 + +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(QLatin1String("getXPlaneVersionMajor")); + } + + int CXBusServiceProxy::getXPlaneVersionMinor() const + { + return m_dbusInterface->callDBusRet(QLatin1String("getXPlaneVersionMinor")); + } + + QString CXBusServiceProxy::getXPlaneInstallationPath() const + { + return m_dbusInterface->callDBusRet(QLatin1String("getXPlaneInstallationPath")); + } + + QString CXBusServiceProxy::getXPlanePreferencesPath() const + { + return m_dbusInterface->callDBusRet(QLatin1String("getXPlanePreferencesPath")); + } + + double CXBusServiceProxy::getLatitude() const + { + return m_dbusInterface->callDBusRet(QLatin1String("getLatitude")); + } + + double CXBusServiceProxy::getLongitude() const + { + return m_dbusInterface->callDBusRet(QLatin1String("getLongitude")); + } + + double CXBusServiceProxy::getAltitudeMSL() const + { + return m_dbusInterface->callDBusRet(QLatin1String("getAltitudeMSL")); + } + + double CXBusServiceProxy::getHeightAGL() const + { + return m_dbusInterface->callDBusRet(QLatin1String("getHeightAGL")); + } + + double CXBusServiceProxy::getGroundSpeed() const + { + return m_dbusInterface->callDBusRet(QLatin1String("getGroundSpeed")); + } + + double CXBusServiceProxy::getIndicatedAirspeed() const + { + return m_dbusInterface->callDBusRet(QLatin1String("getIndicatedAirspeed")); + } + + double CXBusServiceProxy::getTrueAirspeed() const + { + return m_dbusInterface->callDBusRet(QLatin1String("getTrueAirspeed")); + } + + double CXBusServiceProxy::getPitch() const + { + return m_dbusInterface->callDBusRet(QLatin1String("getPitch")); + } + + double CXBusServiceProxy::getRoll() const + { + return m_dbusInterface->callDBusRet(QLatin1String("getRoll")); + } + + double CXBusServiceProxy::getTrueHeading() const + { + return m_dbusInterface->callDBusRet(QLatin1String("getTrueHeading")); + } + + } +} \ No newline at end of file diff --git a/src/plugins/simulator/xplane/xbus_service_proxy.h b/src/plugins/simulator/xplane/xbus_service_proxy.h new file mode 100644 index 000000000..8cec9b4eb --- /dev/null +++ b/src/plugins/simulator/xplane/xbus_service_proxy.h @@ -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