summaryrefslogtreecommitdiffstats
path: root/src/dbus/qdbusconnection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/dbus/qdbusconnection.cpp')
-rw-r--r--src/dbus/qdbusconnection.cpp52
1 files changed, 51 insertions, 1 deletions
diff --git a/src/dbus/qdbusconnection.cpp b/src/dbus/qdbusconnection.cpp
index 9656903846..a55ff14fcf 100644
--- a/src/dbus/qdbusconnection.cpp
+++ b/src/dbus/qdbusconnection.cpp
@@ -222,6 +222,18 @@ void QDBusConnectionManager::setConnection(const QString &name, QDBusConnectionP
*/
/*!
+ \internal
+ \since 4.8
+ \enum QDBusConnection::VirtualObjectRegisterOption
+ Specifies the options for registering virtual objects with the connection. The possible values are:
+
+ \value SingleNode register a virtual object to handle one path only
+ \value SubPath register a virtual object so that it handles all sub paths
+
+ \sa registerVirtualObject(), QDBusVirtualObject
+*/
+
+/*!
\enum QDBusConnection::UnregisterMode
The mode for unregistering an object path:
@@ -801,9 +813,21 @@ bool QDBusConnection::registerObject(const QString &path, QObject *object, Regis
// this node exists
// consider it free if there's no object here and the user is not trying to
// replace the object sub-tree
- if ((options & ExportChildObjects && !node->children.isEmpty()) || node->obj)
+ if (node->obj)
return false;
+ if (options & QDBusConnectionPrivate::VirtualObject) {
+ // technically the check for children needs to go even deeper
+ if (options & SubPath) {
+ foreach (const QDBusConnectionPrivate::ObjectTreeNode &child, node->children) {
+ if (child.obj)
+ return false;
+ }
+ }
+ } else {
+ if ((options & ExportChildObjects && !node->children.isEmpty()))
+ return false;
+ }
// we can add the object here
node->obj = object;
node->flags = options;
@@ -813,6 +837,13 @@ bool QDBusConnection::registerObject(const QString &path, QObject *object, Regis
return true;
}
+ // if a virtual object occupies this path, return false
+ if (node->obj && (node->flags & QDBusConnectionPrivate::VirtualObject) && (node->flags & QDBusConnection::SubPath)) {
+ qDebug("Cannot register object at %s because QDBusVirtualObject handles all sub-paths.",
+ qPrintable(path));
+ return false;
+ }
+
// find the position where we'd insert the node
QDBusConnectionPrivate::ObjectTreeNode::DataList::Iterator it =
qLowerBound(node->children.begin(), node->children.end(), pathComponents.at(i));
@@ -841,6 +872,21 @@ bool QDBusConnection::registerObject(const QString &path, QObject *object, Regis
}
/*!
+ \internal
+ \since 4.8
+ Registers a QDBusTreeNode for a path. It can handle a path including all child paths, thus
+ handling multiple DBus nodes.
+
+ To unregister a QDBusTreeNode use the unregisterObject() function with its path.
+*/
+bool QDBusConnection::registerVirtualObject(const QString &path, QDBusVirtualObject *treeNode,
+ VirtualObjectRegisterOption options)
+{
+ int opts = options | QDBusConnectionPrivate::VirtualObject;
+ return registerObject(path, (QObject*) treeNode, (RegisterOptions) opts);
+}
+
+/*!
Unregisters an object that was registered with the registerObject() at the object path given by
\a path and, if \a mode is QDBusConnection::UnregisterTree, all of its sub-objects too.
@@ -905,6 +951,8 @@ QObject *QDBusConnection::objectRegisteredAt(const QString &path) const
while (node) {
if (pathComponents.count() == i)
return node->obj;
+ if ((node->flags & QDBusConnectionPrivate::VirtualObject) && (node->flags & QDBusConnection::SubPath))
+ return node->obj;
QDBusConnectionPrivate::ObjectTreeNode::DataList::ConstIterator it =
qLowerBound(node->children.constBegin(), node->children.constEnd(), pathComponents.at(i));
@@ -917,6 +965,8 @@ QObject *QDBusConnection::objectRegisteredAt(const QString &path) const
return 0;
}
+
+
/*!
Returns a QDBusConnectionInterface object that represents the
D-Bus server interface on this connection.