From 18c7ce5994126e7eb89e37c3d2bf6d528f84fdc3 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sat, 19 Jan 2013 19:46:24 -0800 Subject: 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) --- src/dbus/qdbusintegrator.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/dbus/qdbusintegrator.cpp') 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, -- cgit v1.2.3