[Telepathy-commits] [telepathy-qt4/master] Connection: Use PendingReadyConnection.

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Fri Feb 13 12:54:35 PST 2009


P.s: Tests broken (will be fixed in a later patch)
---
 TelepathyQt4/Client/connection.cpp |   54 +++++++++++++++--------------------
 TelepathyQt4/Client/connection.h   |    3 +-
 2 files changed, 25 insertions(+), 32 deletions(-)

diff --git a/TelepathyQt4/Client/connection.cpp b/TelepathyQt4/Client/connection.cpp
index 59e784a..32945b7 100644
--- a/TelepathyQt4/Client/connection.cpp
+++ b/TelepathyQt4/Client/connection.cpp
@@ -35,6 +35,7 @@
 #include <TelepathyQt4/Client/PendingContacts>
 #include <TelepathyQt4/Client/PendingFailure>
 #include <TelepathyQt4/Client/PendingHandles>
+#include <TelepathyQt4/Client/PendingReadyConnection>
 #include <TelepathyQt4/Client/PendingVoidMethodCall>
 
 #include <QMap>
@@ -126,7 +127,6 @@ struct Connection::Private
     void updatePendingOperations();
 
     struct HandleContext;
-    class PendingReady;
 
     // Public object
     Connection *parent;
@@ -139,7 +139,7 @@ struct Connection::Private
     ConnectionInterfaceSimplePresenceInterface *simplePresence;
 
     bool ready;
-    QList<PendingReady *> pendingOperations;
+    QList<PendingReadyConnection *> pendingOperations;
 
     // Introspection
     bool initialIntrospection;
@@ -200,23 +200,6 @@ struct Connection::Private::HandleContext
     QMap<uint, Type> types;
 };
 
-class Connection::Private::PendingReady : public PendingOperation
-{
-    // Connection is a friend so it can call finished() etc.
-    friend class Connection;
-
-public:
-    PendingReady(Connection::Features features, QObject *parent);
-
-    Connection::Features features;
-};
-
-Connection::Private::PendingReady::PendingReady(Connection::Features features, QObject *parent)
-    : PendingOperation(parent),
-      features(features)
-{
-}
-
 Connection::Private::Private(Connection *parent)
     : parent(parent),
       baseInterface(new ConnectionInterface(parent->dbusConnection(),
@@ -432,10 +415,10 @@ void Connection::Private::changeReadiness(Readiness newReadiness)
 
 void Connection::Private::updatePendingOperations()
 {
-    foreach (Private::PendingReady *operation, pendingOperations) {
+    foreach (PendingReadyConnection *operation, pendingOperations) {
         if (ready &&
-            ((operation->features &
-                (features | missingFeatures)) == operation->features)) {
+            ((operation->requestedFeatures() &
+                (features | missingFeatures)) == operation->requestedFeatures())) {
             operation->setFinished();
         }
         if (operation->isFinished()) {
@@ -1323,24 +1306,30 @@ bool Connection::isReady(Features features) const
  * initial setup.
  *
  * \param features Which features should be tested.
- * \return A PendingOperation which will emit PendingOperation::finished
+ * \return A PendingReadyConnection object which will emit finished
  *         when this object has finished or failed its initial setup.
  */
-PendingOperation *Connection::becomeReady(Features requestedFeatures)
+PendingReadyConnection *Connection::becomeReady(Features requestedFeatures)
 {
     if (!isValid()) {
-        return new PendingFailure(this, TELEPATHY_ERROR_NOT_AVAILABLE,
+        PendingReadyConnection *operation =
+            new PendingReadyConnection(requestedFeatures, this);
+        operation->setFinishedWithError(TELEPATHY_ERROR_NOT_AVAILABLE,
                 "Connection is invalid");
+        return operation;
     }
 
     if (isReady(requestedFeatures)) {
-        return new PendingSuccess(this);
+        PendingReadyConnection *operation =
+            new PendingReadyConnection(requestedFeatures, this);
+        operation->setFinished();
+        return operation;
     }
 
     debug() << "Calling becomeReady with requested features:"
             << requestedFeatures;
-    foreach (Private::PendingReady *operation, mPriv->pendingOperations) {
-        if (operation->features == requestedFeatures) {
+    foreach (PendingReadyConnection *operation, mPriv->pendingOperations) {
+        if (operation->requestedFeatures() == requestedFeatures) {
             debug() << "Returning cached pending operation";
             return operation;
         }
@@ -1351,7 +1340,10 @@ PendingOperation *Connection::becomeReady(Features requestedFeatures)
         // just finish silently
         if (requestedFeatures == FeatureSimplePresence &&
             mPriv->missingFeatures & FeatureSimplePresence) {
-            return new PendingSuccess(this);
+            PendingReadyConnection *operation =
+                new PendingReadyConnection(requestedFeatures, this);
+            operation->setFinished();
+            return operation;
         }
 
         // if we already have the interface simple presence enqueue the call to
@@ -1379,8 +1371,8 @@ PendingOperation *Connection::becomeReady(Features requestedFeatures)
     mPriv->pendingFeatures |= requestedFeatures;
 
     debug() << "Creating new pending operation";
-    Private::PendingReady *operation =
-        new Private::PendingReady(requestedFeatures, this);
+    PendingReadyConnection *operation =
+        new PendingReadyConnection(requestedFeatures, this);
     mPriv->pendingOperations.append(operation);
 
     mPriv->updatePendingOperations();
diff --git a/TelepathyQt4/Client/connection.h b/TelepathyQt4/Client/connection.h
index 0f857f0..153c47f 100644
--- a/TelepathyQt4/Client/connection.h
+++ b/TelepathyQt4/Client/connection.h
@@ -51,6 +51,7 @@ class PendingChannel;
 class PendingContactAttributes;
 class PendingHandles;
 class PendingOperation;
+class PendingReadyConnection;
 
 class Connection : public StatefulDBusProxy,
                    private OptionalInterfaceFactory<Connection>
@@ -170,7 +171,7 @@ public:
 
     bool isReady(Features features = 0) const;
 
-    PendingOperation *becomeReady(Features features = 0);
+    PendingReadyConnection *becomeReady(Features features = 0);
 
 Q_SIGNALS:
     void statusChanged(uint newStatus, uint newStatusReason);
-- 
1.5.6.5




More information about the telepathy-commits mailing list