From 0eec8c86b604374c3210133822d41df229698b34 Mon Sep 17 00:00:00 2001 From: Kevron Rees Date: Thu, 22 Jan 2015 15:00:36 -0800 Subject: QDBusConnection::registorObject with interface Currently QDBus relies on a key in QMetaClassInfo to understand the DBus interface name. This patch allows QDBus to also use a specified interface name in the registerObject call instead of relying on QMetaClassInfo that might not be there (if the QObject was created in QML or Javascript for example). Change-Id: Ie02b2c67e7deb07f43e35eb166c11833fcbf38f3 Task-number: QTBUG-44074 Reviewed-by: Kevron Rees Reviewed-by: Thiago Macieira --- src/dbus/qdbusconnection.cpp | 21 +++++++++++++++++++++ src/dbus/qdbusconnection.h | 2 ++ src/dbus/qdbusconnection_p.h | 1 + src/dbus/qdbusintegrator.cpp | 8 ++++++-- src/dbus/qdbusinternalfilters.cpp | 2 +- 5 files changed, 31 insertions(+), 3 deletions(-) (limited to 'src/dbus') diff --git a/src/dbus/qdbusconnection.cpp b/src/dbus/qdbusconnection.cpp index c758f85d79..ff897faab6 100644 --- a/src/dbus/qdbusconnection.cpp +++ b/src/dbus/qdbusconnection.cpp @@ -761,6 +761,26 @@ bool QDBusConnection::disconnect(const QString &service, const QString &path, co was registered with QDBusConnection::ExportChildObjects. */ bool QDBusConnection::registerObject(const QString &path, QObject *object, RegisterOptions options) +{ + return registerObject(path, QString(), object, options); +} + +/*! + \overload + \since 5.5 + + Registers the object \a object at path \a path with interface name \a interface + and returns \c true if the registration was successful. The \a options parameter + specifies how much of the object \a object will be exposed through + D-Bus. + + This function does not replace existing objects: if there is already an object registered at + path \a path, this function will return false. Use unregisterObject() to unregister it first. + + You cannot register an object as a child object of an object that + was registered with QDBusConnection::ExportChildObjects. +*/ +bool QDBusConnection::registerObject(const QString &path, const QString &interface, QObject *object, RegisterOptions options) { Q_ASSERT_X(QDBusUtil::isValidObjectPath(path), "QDBusConnection::registerObject", "Invalid object path given"); @@ -793,6 +813,7 @@ bool QDBusConnection::registerObject(const QString &path, QObject *object, Regis // we can add the object here node->obj = object; node->flags = options; + node->interfaceName = interface; d->registerObject(node); //qDebug("REGISTERED FOR %s", path.toLocal8Bit().constData()); diff --git a/src/dbus/qdbusconnection.h b/src/dbus/qdbusconnection.h index c89bbf4e3a..10598c0b7b 100644 --- a/src/dbus/qdbusconnection.h +++ b/src/dbus/qdbusconnection.h @@ -161,6 +161,8 @@ public: bool registerObject(const QString &path, QObject *object, RegisterOptions options = ExportAdaptors); + bool registerObject(const QString &path, const QString &interface, QObject *object, + RegisterOptions options = ExportAdaptors); void unregisterObject(const QString &path, UnregisterMode mode = UnregisterNode); QObject *objectRegisteredAt(const QString &path) const; diff --git a/src/dbus/qdbusconnection_p.h b/src/dbus/qdbusconnection_p.h index 29c4d6869c..5d8777c622 100644 --- a/src/dbus/qdbusconnection_p.h +++ b/src/dbus/qdbusconnection_p.h @@ -152,6 +152,7 @@ public: { return obj || !children.isEmpty(); } QString name; + QString interfaceName; union { QObject *obj; QDBusVirtualObject *treeNode; diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index d819009d9b..a95d96e526 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -1481,8 +1481,12 @@ void QDBusConnectionPrivate::activateObject(ObjectTreeNode &node, const QDBusMes if (node.flags & (QDBusConnection::ExportScriptableSlots|QDBusConnection::ExportNonScriptableSlots) || node.flags & (QDBusConnection::ExportScriptableInvokables|QDBusConnection::ExportNonScriptableInvokables)) { bool interfaceFound = true; - if (!msg.interface().isEmpty()) - interfaceFound = qDBusInterfaceInObject(node.obj, msg.interface()); + if (!msg.interface().isEmpty()) { + if (!node.interfaceName.isEmpty()) + interfaceFound = msg.interface() == node.interfaceName; + else + interfaceFound = qDBusInterfaceInObject(node.obj, msg.interface()); + } if (interfaceFound) { if (!activateCall(node.obj, node.flags, msg)) diff --git a/src/dbus/qdbusinternalfilters.cpp b/src/dbus/qdbusinternalfilters.cpp index e206db105a..d9e5f7408b 100644 --- a/src/dbus/qdbusinternalfilters.cpp +++ b/src/dbus/qdbusinternalfilters.cpp @@ -134,7 +134,7 @@ QString qDBusIntrospectObject(const QDBusConnectionPrivate::ObjectTreeNode &node // create XML for the object itself const QMetaObject *mo = node.obj->metaObject(); for ( ; mo != &QObject::staticMetaObject; mo = mo->superClass()) - xml_data += qDBusGenerateMetaObjectXml(QString(), mo, mo->superClass(), + xml_data += qDBusGenerateMetaObjectXml(node.interfaceName, mo, mo->superClass(), node.flags); } -- cgit v1.2.3