diff --git a/src/blackmisc/genericdbusinterface.h b/src/blackmisc/genericdbusinterface.h index 072499b9e..517575ce3 100644 --- a/src/blackmisc/genericdbusinterface.h +++ b/src/blackmisc/genericdbusinterface.h @@ -1,3 +1,14 @@ +/* Copyright (C) 2013 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + #ifndef BLACKMISC_GENERICDBUSINTERFACE_H #define BLACKMISC_GENERICDBUSINTERFACE_H @@ -5,6 +16,15 @@ #include #include #include +#include + +#ifndef Q_MOC_RUN +/*! + * Any signals tagged with this macro will be ignored by BlackMisc::CGenericDBusInterface::relayParentSignals(). + * \see QMetaMethod::tag + */ +#define BLACK_NO_RELAY +#endif namespace BlackMisc { @@ -23,6 +43,25 @@ namespace BlackMisc QDBusAbstractInterface(serviceName, path, interfaceName.toUtf8().constData(), connection, parent) { } + //! For each signal in parent, attempt to connect to it an interface signal of the same name. + //! \see BLACK_NO_RELAY + void relayParentSignals() + { + const QMetaObject *metaObject = this->parent()->metaObject(); + const QMetaObject *superMetaObject = metaObject; + while (strcmp(superMetaObject->superClass()->className(), "QObject") != 0) { superMetaObject = superMetaObject->superClass(); } + + for (int i = superMetaObject->methodOffset(), count = metaObject->methodCount(); i < count; ++i) + { + QMetaMethod method = metaObject->method(i); + if (method.methodType() != QMetaMethod::Signal) { continue; } + if (method.tag() && strcmp(method.tag(), "BLACK_NO_RELAY") == 0) { continue; } + + this->connection().connect(this->service(), this->path(), this->interface(), method.name(), this->parent(), + method.methodSignature().prepend("2")); // the reason for this "2" can be found in the definition of SIGNAL() macro + } + } + //! Call DBus, no return value template void callDBus(const QLatin1String &method, Args&&... args) diff --git a/src/plugins/simulator/xplane/xbus_service_proxy.cpp b/src/plugins/simulator/xplane/xbus_service_proxy.cpp index 2db961363..344ee9b39 100644 --- a/src/plugins/simulator/xplane/xbus_service_proxy.cpp +++ b/src/plugins/simulator/xplane/xbus_service_proxy.cpp @@ -17,21 +17,7 @@ namespace BlackSimPlugin CXBusServiceProxy::CXBusServiceProxy(QDBusConnection &connection, QObject *parent, bool dummy) : QObject(parent) { m_dbusInterface = new BlackMisc::CGenericDBusInterface(XBUS_SERVICE_SERVICENAME, ObjectPath(), InterfaceName(), connection, this); - if (! dummy) { 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().prepend("2")); - } - } + if (! dummy) { m_dbusInterface->relayParentSignals(); } } void CXBusServiceProxy::updateAirportsInRange() diff --git a/src/plugins/simulator/xplane/xbus_service_proxy.h b/src/plugins/simulator/xplane/xbus_service_proxy.h index 8c3cafaf4..313a528b2 100644 --- a/src/plugins/simulator/xplane/xbus_service_proxy.h +++ b/src/plugins/simulator/xplane/xbus_service_proxy.h @@ -56,8 +56,6 @@ namespace BlackSimPlugin private: BlackMisc::CGenericDBusInterface *m_dbusInterface = nullptr; - void relaySignals(); - // Returns a function object which can be passed to CGenericDBusInterface::callDBusAsync. template std::function setterCallback(T *obj) diff --git a/src/plugins/simulator/xplane/xbus_traffic_proxy.cpp b/src/plugins/simulator/xplane/xbus_traffic_proxy.cpp index ca7bac39e..ce4ee30d0 100644 --- a/src/plugins/simulator/xplane/xbus_traffic_proxy.cpp +++ b/src/plugins/simulator/xplane/xbus_traffic_proxy.cpp @@ -17,21 +17,7 @@ namespace BlackSimPlugin CXBusTrafficProxy::CXBusTrafficProxy(QDBusConnection &connection, QObject *parent, bool dummy) : QObject(parent) { m_dbusInterface = new BlackMisc::CGenericDBusInterface(XBUS_SERVICENAME, ObjectPath(), InterfaceName(), connection, this); - if (! dummy) { relaySignals(); } - } - - void CXBusTrafficProxy::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().prepend("2")); - } - } + if (! dummy) { m_dbusInterface->relayParentSignals(); } } bool CXBusTrafficProxy::initialize() diff --git a/src/plugins/simulator/xplane/xbus_traffic_proxy.h b/src/plugins/simulator/xplane/xbus_traffic_proxy.h index 443ec6757..5fd5ec7a0 100644 --- a/src/plugins/simulator/xplane/xbus_traffic_proxy.h +++ b/src/plugins/simulator/xplane/xbus_traffic_proxy.h @@ -51,8 +51,6 @@ namespace BlackSimPlugin private: BlackMisc::CGenericDBusInterface *m_dbusInterface = nullptr; - void relaySignals(); - signals: //! \copydoc XBus::CTraffic::installedModelsUpdated void installedModelsUpdated(const QStringList &modelStrings, const QStringList &icaos, const QStringList &airlines, const QStringList &liveries);