summaryrefslogtreecommitdiffstats
path: root/src/dbus
diff options
context:
space:
mode:
authorKevron Rees <kevron.m.rees@intel.com>2015-01-22 15:00:36 -0800
committerThiago Macieira <thiago.macieira@intel.com>2015-02-15 02:17:53 +0000
commit0eec8c86b604374c3210133822d41df229698b34 (patch)
treeef38b6a2def0b285aa35b57c52fbbe14263640a2 /src/dbus
parent06ecd74db138bcdf6f87df5917f6d5035da41823 (diff)
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 <kevron.m.rees@intel.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/dbus')
-rw-r--r--src/dbus/qdbusconnection.cpp21
-rw-r--r--src/dbus/qdbusconnection.h2
-rw-r--r--src/dbus/qdbusconnection_p.h1
-rw-r--r--src/dbus/qdbusintegrator.cpp8
-rw-r--r--src/dbus/qdbusinternalfilters.cpp2
5 files changed, 31 insertions, 3 deletions
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
@@ -762,6 +762,26 @@ bool QDBusConnection::disconnect(const QString &service, const QString &path, co
*/
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");
if (!d || !d->connection || !object || !options || !QDBusUtil::isValidObjectPath(path))
@@ -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);
}