mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-13 15:45:42 +08:00
refs #466 Refactored automatic signal relaying into CGenericDBusInterface.
This commit is contained in:
@@ -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 <QDBusPendingCall>
|
||||
#include <QDBusPendingReply>
|
||||
#include <QObject>
|
||||
#include <QMetaMethod>
|
||||
|
||||
#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 <typename... Args>
|
||||
void callDBus(const QLatin1String &method, Args&&... args)
|
||||
|
||||
Reference in New Issue
Block a user