[Telepathy-commits] [telepathy-qt4/master] ConnectionManager: share one PendingReady object between becomeReady callers

Simon McVittie simon.mcvittie at collabora.co.uk
Thu Dec 11 04:34:53 PST 2008


Since we don't yet support any optional features, there's no point in
having multiple PendingReady instances.

Note that it's not possible to share the PendingSuccess instances in the
"already ready" case.
---
 TelepathyQt4/cli-connection-manager.cpp |   23 ++++++++++++++---------
 1 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/TelepathyQt4/cli-connection-manager.cpp b/TelepathyQt4/cli-connection-manager.cpp
index 4f8297f..d42ec76 100644
--- a/TelepathyQt4/cli-connection-manager.cpp
+++ b/TelepathyQt4/cli-connection-manager.cpp
@@ -182,7 +182,7 @@ struct ConnectionManager::Private
         }
     };
 
-    QList<PendingReady *> pendingReadyOperations;
+    PendingReady *pendingReady;
 
     ~Private()
     {
@@ -230,7 +230,8 @@ struct ConnectionManager::Private
           cmName(name),
           baseInterface(new ConnectionManagerInterface(parent.dbusConnection(),
                       parent.busName(), parent.objectPath(), &parent)),
-          ready(false)
+          ready(false),
+          pendingReady(0)
     {
         debug() << "Creating new ConnectionManager:" << parent.busName();
 
@@ -300,12 +301,15 @@ bool ConnectionManager::isReady() const
 // fatal, so the documentation isn't completely true.
 PendingOperation *ConnectionManager::becomeReady()
 {
-    if (mPriv->ready)
+    if (mPriv->ready) {
         return new PendingSuccess(this);
+    }
+
+    if (!mPriv->pendingReady) {
+        mPriv->pendingReady = new Private::PendingReady(this);
+    }
 
-    Private::PendingReady *pendingReady = new Private::PendingReady(this);
-    mPriv->pendingReadyOperations << pendingReady;
-    return pendingReady;
+    return mPriv->pendingReady;
 }
 
 
@@ -419,9 +423,10 @@ void ConnectionManager::continueIntrospection()
             mPriv->ready = true;
             Q_EMIT ready(this);
 
-            while (!mPriv->pendingReadyOperations.isEmpty()) {
-                debug() << "Finishing one";
-                mPriv->pendingReadyOperations.takeFirst()->setFinished();
+            if (mPriv->pendingReady) {
+                mPriv->pendingReady->setFinished();
+                // it will delete itself later
+                mPriv->pendingReady = 0;
             }
         } else {
             (mPriv->*(mPriv->introspectQueue.dequeue()))();
-- 
1.5.6.5




More information about the Telepathy-commits mailing list