[Telepathy-commits] [telepathy-qt4/master] Connection: Make PendingConnection return a QSharedPointer<Connection> instead of Connection *.

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Fri Feb 13 09:48:04 PST 2009


---
 TelepathyQt4/Client/pending-connection.cpp |   17 ++++++++++-------
 TelepathyQt4/Client/pending-connection.h   |    5 +++--
 tests/pinocchio/cm-basics.cpp              |    2 +-
 3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/TelepathyQt4/Client/pending-connection.cpp b/TelepathyQt4/Client/pending-connection.cpp
index 7858b0f..471350f 100644
--- a/TelepathyQt4/Client/pending-connection.cpp
+++ b/TelepathyQt4/Client/pending-connection.cpp
@@ -57,7 +57,7 @@ struct PendingConnection::Private
     }
 
     ConnectionManager *manager;
-    Connection *connection;
+    QSharedPointer<Connection> connection;
 };
 
 /**
@@ -113,12 +113,14 @@ ConnectionManager *PendingConnection::manager() const
  *
  * \return Connection object.
  */
-Connection *PendingConnection::connection() const
+QSharedPointer<Connection> PendingConnection::connection() const
 {
     if (!isFinished()) {
-        warning() <<
-            "PendingConnection::connection called before finished, returning 0";
-        return 0;
+        warning() << "PendingConnection::connection called before finished, returning 0";
+        return QSharedPointer<Connection>();
+    } else if (!isValid()) {
+        warning() << "PendingConnection::connection called when not valid, returning 0";
+        return QSharedPointer<Connection>();
     }
 
     return mPriv->connection;
@@ -133,8 +135,9 @@ void PendingConnection::onCallFinished(QDBusPendingCallWatcher *watcher)
         QString serviceName = reply.argumentAt<0>();
         QDBusObjectPath objectPath = reply.argumentAt<1>();
         debug() << "Creating connection for objectPath: " << objectPath.path();
-        mPriv->connection = new Connection(mPriv->manager->dbusConnection(),
-                serviceName, objectPath.path(), mPriv->manager);
+        mPriv->connection = QSharedPointer<Connection>(
+                new Connection(mPriv->manager->dbusConnection(),
+                    serviceName, objectPath.path()));
         setFinished();
     } else {
         debug().nospace() <<
diff --git a/TelepathyQt4/Client/pending-connection.h b/TelepathyQt4/Client/pending-connection.h
index 1b48da2..21e497f 100644
--- a/TelepathyQt4/Client/pending-connection.h
+++ b/TelepathyQt4/Client/pending-connection.h
@@ -26,8 +26,10 @@
 #error IN_TELEPATHY_QT4_HEADER
 #endif
 
+#include <TelepathyQt4/Client/Connection>
 #include <TelepathyQt4/Client/PendingOperation>
 
+#include <QSharedPointer>
 #include <QString>
 #include <QVariantMap>
 
@@ -39,7 +41,6 @@ namespace Client
 {
 
 class ConnectionManager;
-class Connection;
 
 class PendingConnection : public PendingOperation
 {
@@ -49,7 +50,7 @@ public:
     ~PendingConnection();
 
     ConnectionManager *manager() const;
-    Connection *connection() const;
+    QSharedPointer<Connection> connection() const;
 
 private Q_SLOTS:
     void onCallFinished(QDBusPendingCallWatcher *watcher);
diff --git a/tests/pinocchio/cm-basics.cpp b/tests/pinocchio/cm-basics.cpp
index 21439ea..e0e2ff5 100644
--- a/tests/pinocchio/cm-basics.cpp
+++ b/tests/pinocchio/cm-basics.cpp
@@ -136,7 +136,7 @@ void TestCmBasics::testBasics()
             SLOT(expectSuccessfulCall(Telepathy::Client::PendingOperation *)));
     QCOMPARE(mLoop->exec(), 0);
 
-    QVERIFY(pconn->connection() != 0);
+    QVERIFY(!pconn->connection().isNull());
 }
 
 
-- 
1.5.6.5




More information about the telepathy-commits mailing list