[Telepathy-commits] [telepathy-qt4/master] ConnectionManager: add a becomeReady() method returning a pending operation

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


---
 TelepathyQt4/cli-connection-manager.cpp |   33 +++++++++++++++++++++++++++++++
 TelepathyQt4/cli-connection-manager.h   |   12 +++++++++++
 2 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/TelepathyQt4/cli-connection-manager.cpp b/TelepathyQt4/cli-connection-manager.cpp
index 38ed616..4f8297f 100644
--- a/TelepathyQt4/cli-connection-manager.cpp
+++ b/TelepathyQt4/cli-connection-manager.cpp
@@ -26,6 +26,7 @@
 #include <QtCore/QTimer>
 
 #include <TelepathyQt4/Client/DBus>
+#include <TelepathyQt4/Client/PendingSuccess>
 #include <TelepathyQt4/Constants>
 #include <TelepathyQt4/Types>
 
@@ -169,6 +170,20 @@ struct ConnectionManager::Private
                 TELEPATHY_CONNECTION_MANAGER_OBJECT_PATH_BASE).append(name);
     }
 
+    // A PendingOperation on which the ConnectionManager can call
+    // setFinished().
+    class PendingReady : public PendingOperation
+    {
+        friend class ConnectionManager;
+    public:
+        PendingReady(ConnectionManager *parent)
+            : PendingOperation(parent)
+        {
+        }
+    };
+
+    QList<PendingReady *> pendingReadyOperations;
+
     ~Private()
     {
         Q_FOREACH (ProtocolInfo* protocol, protocols) {
@@ -281,6 +296,19 @@ bool ConnectionManager::isReady() const
 }
 
 
+// TODO: We don't actually consider anything during initial setup to be
+// fatal, so the documentation isn't completely true.
+PendingOperation *ConnectionManager::becomeReady()
+{
+    if (mPriv->ready)
+        return new PendingSuccess(this);
+
+    Private::PendingReady *pendingReady = new Private::PendingReady(this);
+    mPriv->pendingReadyOperations << pendingReady;
+    return pendingReady;
+}
+
+
 ConnectionManagerInterface* ConnectionManager::baseInterface() const
 {
     return mPriv->baseInterface;
@@ -390,6 +418,11 @@ void ConnectionManager::continueIntrospection()
             debug() << "ConnectionManager is ready";
             mPriv->ready = true;
             Q_EMIT ready(this);
+
+            while (!mPriv->pendingReadyOperations.isEmpty()) {
+                debug() << "Finishing one";
+                mPriv->pendingReadyOperations.takeFirst()->setFinished();
+            }
         } else {
             (mPriv->*(mPriv->introspectQueue.dequeue()))();
         }
diff --git a/TelepathyQt4/cli-connection-manager.h b/TelepathyQt4/cli-connection-manager.h
index 2bc3f8c..8d0fc0c 100644
--- a/TelepathyQt4/cli-connection-manager.h
+++ b/TelepathyQt4/cli-connection-manager.h
@@ -45,6 +45,7 @@
 #include <TelepathyQt4/Client/DBus>
 #include <TelepathyQt4/Client/DBusProxy>
 #include <TelepathyQt4/Client/OptionalInterfaceFactory>
+#include <TelepathyQt4/Client/PendingOperation>
 
 namespace Telepathy
 {
@@ -228,7 +229,18 @@ public:
 
     bool isReady() const;
 
+    /**
+     * Return a pending operation which will succeed when this object finishes
+     * its initial setup, or will fail if a fatal error occurs during this
+     * initial setup.
+     *
+     * \return A PendingOperation which will emit PendingOperation::finished
+     *         when this object has finished or failed its initial setup
+     */
+    PendingOperation *becomeReady();
+
 Q_SIGNALS:
+    // FIXME: do we need this if we have becomeReady()?
     void ready(ConnectionManager*);
 
 protected:
-- 
1.5.6.5




More information about the Telepathy-commits mailing list