diff options
author | Frederik Gladhorn <frederik.gladhorn@nokia.com> | 2011-05-22 21:36:10 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-08-18 17:59:18 +0200 |
commit | 3cea6b22a6b1628cedd59a3286dcaa8088491660 (patch) | |
tree | 3e99604c0c16f31387bcce7b6aa31bdc337d8023 /src/dbus/qdbusconnection.cpp | |
parent | a34771074c4a2475b4c6702b6aef147eb4908cfe (diff) |
Add DBus VirtualObject to handle multiple paths.
When a virtual object is registered with the SubPath option
it will handle all dbus calls to itself and all child paths.
It needs to reimplement handleMessage for that purpose.
Introspection needs to be implemented manually in the introspect function.
Reviewed-by: Thiago Macieira <thiago.macieira@nokia.com>
(cherry picked from commit b07919b3de8cff3e44b7271062372b14bcda5b83)
(cherry picked from commit 997c2dfed7a04da2fac577f1c29b89bda4939e2d)
(cherry picked from commit c676b7095d826dc2d006f52a4b234546af5e2137)
Change-Id: I003007604b286af8000959756ce9d25c17306f5b
Reviewed-on: http://codereview.qt.nokia.com/3051
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@nokia.com>
Diffstat (limited to 'src/dbus/qdbusconnection.cpp')
-rw-r--r-- | src/dbus/qdbusconnection.cpp | 52 |
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. |