diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2013-01-16 19:41:49 +0800 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-01-23 07:54:00 +0100 |
commit | 3c6bb0ed8bfc9a2c679f4154585a16e47275ad21 (patch) | |
tree | c92aeb8ff742dd5c7af269fcbfb9a5f3bc22e85b /src | |
parent | 18c7ce5994126e7eb89e37c3d2bf6d528f84fdc3 (diff) |
Make the QtDBus object tree keep a count of active children
The new member variable activeChildren shall contain the number of
direct children that are active. This number differs from
children.count() because the vector may contain empty entries that
haven't been garbage-collected yet (obj == NULL and activeChildren ==
0).
When this count drops to zero, we know we can simply erase the vector of
children.
Change-Id: Ia20604d3fac852ea4a6e8862d934fbb936fa5e18
Reviewed-by: David Faure (KDE) <faure@kde.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/dbus/qdbusconnection.cpp | 10 | ||||
-rw-r--r-- | src/dbus/qdbusconnection_p.h | 7 | ||||
-rw-r--r-- | src/dbus/qdbusintegrator.cpp | 28 |
3 files changed, 32 insertions, 13 deletions
diff --git a/src/dbus/qdbusconnection.cpp b/src/dbus/qdbusconnection.cpp index 678b10d108..dd9417b87a 100644 --- a/src/dbus/qdbusconnection.cpp +++ b/src/dbus/qdbusconnection.cpp @@ -803,13 +803,8 @@ bool QDBusConnection::registerObject(const QString &path, QObject *object, Regis 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; - } - } + if (options & SubPath && node->activeChildren) + return false; } else { if ((options & ExportChildObjects && !node->children.isEmpty())) return false; @@ -846,6 +841,7 @@ bool QDBusConnection::registerObject(const QString &path, QObject *object, Regis } } else { // add entry + ++node->activeChildren; node = node->children.insert(it, pathComponents.at(i)); } diff --git a/src/dbus/qdbusconnection_p.h b/src/dbus/qdbusconnection_p.h index 50307e2738..3beb258bd8 100644 --- a/src/dbus/qdbusconnection_p.h +++ b/src/dbus/qdbusconnection_p.h @@ -140,14 +140,16 @@ public: { typedef QVector<ObjectTreeNode> DataList; - inline ObjectTreeNode() : obj(0), flags(0) { } + inline ObjectTreeNode() : obj(0), flags(0), activeChildren(0) { } inline ObjectTreeNode(const QString &n) // intentionally implicit - : name(n), obj(0), flags(0) { } + : name(n), obj(0), flags(0), activeChildren(0) { } inline ~ObjectTreeNode() { } inline bool operator<(const QString &other) const { return name < other; } inline bool operator<(const QStringRef &other) const { return QStringRef(&name) < other; } + inline bool isActive() const + { return obj || activeChildren; } QString name; union { @@ -155,6 +157,7 @@ public: QDBusVirtualObject *treeNode; }; int flags; + int activeChildren; DataList children; }; diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index 72586404a2..0caccbe044 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -591,13 +591,23 @@ static void huntAndDestroy(QObject *needle, QDBusConnectionPrivate::ObjectTreeNo { QDBusConnectionPrivate::ObjectTreeNode::DataList::Iterator it = haystack.children.begin(); QDBusConnectionPrivate::ObjectTreeNode::DataList::Iterator end = haystack.children.end(); - for ( ; it != end; ++it) + for ( ; it != end; ++it) { + if (!it->isActive()) + continue; huntAndDestroy(needle, *it); + if (!it->isActive()) + --haystack.activeChildren; + } if (needle == haystack.obj) { haystack.obj = 0; haystack.flags = 0; } + + if (haystack.activeChildren == 0) { + // quick clean-up, if we're out of children + haystack.children.clear(); + } } static void huntAndUnregister(const QStringList &pathComponents, int i, QDBusConnection::UnregisterMode mode, @@ -610,6 +620,7 @@ static void huntAndUnregister(const QStringList &pathComponents, int i, QDBusCon if (mode == QDBusConnection::UnregisterTree) { // clear the sub-tree as well + node->activeChildren = 0; 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 } @@ -618,10 +629,17 @@ static void huntAndUnregister(const QStringList &pathComponents, int i, QDBusCon 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)) + if (it == end || it->name != pathComponents.at(i) || !it->isActive()) return; // node not found huntAndUnregister(pathComponents, i + 1, mode, it); + if (!it->isActive()) + --node->activeChildren; + + if (node->activeChildren == 0) { + // quick clean-up, if we're out of children + node->children.clear(); + } } } @@ -631,8 +649,10 @@ static void huntAndEmit(DBusConnection *connection, DBusMessage *msg, { QDBusConnectionPrivate::ObjectTreeNode::DataList::ConstIterator it = haystack.children.constBegin(); QDBusConnectionPrivate::ObjectTreeNode::DataList::ConstIterator end = haystack.children.constEnd(); - for ( ; it != end; ++it) - huntAndEmit(connection, msg, needle, *it, isScriptable, isAdaptor, path + QLatin1Char('/') + it->name); + for ( ; it != end; ++it) { + if (it->isActive()) + huntAndEmit(connection, msg, needle, *it, isScriptable, isAdaptor, path + QLatin1Char('/') + it->name); + } if (needle == haystack.obj) { // is this a signal we should relay? |