summaryrefslogtreecommitdiffstats
path: root/src/dbus/qdbusintegrator.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2013-01-19 19:46:24 -0800
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-01-23 07:53:52 +0100
commit18c7ce5994126e7eb89e37c3d2bf6d528f84fdc3 (patch)
treebab555ff4a1455e7b0e6c634ac2b84498d6d668f /src/dbus/qdbusintegrator.cpp
parentf8b681deed6298fa7c2ed7ada4752116432289cf (diff)
Rewrite QDBusConnection::unregisterObject to be recursive
The current implementation is a loop. We need it to be recursive so that we can execute more operations when unwinding. This will be necessary in the next commit. Change-Id: Ia3c98fed0719cede0a0d92d3e343cf016ec7baf2 Reviewed-by: David Faure (KDE) <faure@kde.org>
Diffstat (limited to 'src/dbus/qdbusintegrator.cpp')
-rw-r--r--src/dbus/qdbusintegrator.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp
index 42e6a80670..72586404a2 100644
--- a/src/dbus/qdbusintegrator.cpp
+++ b/src/dbus/qdbusintegrator.cpp
@@ -600,6 +600,31 @@ static void huntAndDestroy(QObject *needle, QDBusConnectionPrivate::ObjectTreeNo
}
}
+static void huntAndUnregister(const QStringList &pathComponents, int i, QDBusConnection::UnregisterMode mode,
+ QDBusConnectionPrivate::ObjectTreeNode *node)
+{
+ if (pathComponents.count() == i) {
+ // found it
+ node->obj = 0;
+ node->flags = 0;
+
+ if (mode == QDBusConnection::UnregisterTree) {
+ // clear the sub-tree as well
+ node->children.clear(); // can't disconnect the objects because we really don't know if they can
+ // be found somewhere else in the path too
+ }
+ } else {
+ // keep going
+ QDBusConnectionPrivate::ObjectTreeNode::DataList::Iterator end = node->children.end();
+ QDBusConnectionPrivate::ObjectTreeNode::DataList::Iterator it =
+ std::lower_bound(node->children.begin(), end, pathComponents.at(i));
+ if (it == end || it->name != pathComponents.at(i))
+ return; // node not found
+
+ huntAndUnregister(pathComponents, i + 1, mode, it);
+ }
+}
+
static void huntAndEmit(DBusConnection *connection, DBusMessage *msg,
QObject *needle, const QDBusConnectionPrivate::ObjectTreeNode &haystack,
bool isScriptable, bool isAdaptor, const QString &path = QString())
@@ -2266,6 +2291,21 @@ void QDBusConnectionPrivate::registerObject(const ObjectTreeNode *node)
cleanupDeletedNodes(rootNode);
}
+void QDBusConnectionPrivate::unregisterObject(const QString &path, QDBusConnection::UnregisterMode mode)
+{
+ QDBusConnectionPrivate::ObjectTreeNode *node = &rootNode;
+ QStringList pathComponents;
+ int i;
+ if (path == QLatin1String("/")) {
+ i = 0;
+ } else {
+ pathComponents = path.split(QLatin1Char('/'));
+ i = 1;
+ }
+
+ huntAndUnregister(pathComponents, i, mode, node);
+}
+
void QDBusConnectionPrivate::connectRelay(const QString &service,
const QString &path, const QString &interface,
QDBusAbstractInterface *receiver,