[Telepathy-commits] [telepathy-qt4/master] Connection: Add a PendingOperation-based wrapper for Disconnect()

Simon McVittie simon.mcvittie at collabora.co.uk
Mon Dec 1 06:41:55 PST 2008


---
 TelepathyQt4/cli-connection.cpp |   15 +++++++++++++++
 TelepathyQt4/cli-connection.h   |   12 ++++++++++++
 tests/pinocchio/conn-basics.cpp |   32 +++++++++++++++++++++-----------
 3 files changed, 48 insertions(+), 11 deletions(-)

diff --git a/TelepathyQt4/cli-connection.cpp b/TelepathyQt4/cli-connection.cpp
index 03537bd..eb3be90 100644
--- a/TelepathyQt4/cli-connection.cpp
+++ b/TelepathyQt4/cli-connection.cpp
@@ -461,6 +461,21 @@ PendingChannel* Connection::requestChannel(const QString& channelType, uint hand
     return channel;
 }
 
+#if 0
+// FIXME: this is a 1:1 mapping of the method from TpPrototype, but
+// most likely what we really want as a high-level API is something
+// more analogous to tp_connection_call_when_ready() in telepathy-glib
+PendingOperation* Connection::requestConnect()
+{
+    return new PendingVoidMethodCall(this, this->Connect());
+}
+#endif
+
+PendingOperation* Connection::requestDisconnect()
+{
+    return new PendingVoidMethodCall(this, this->Disconnect());
+}
+
 struct PendingChannel::Private
 {
     Connection* connection;
diff --git a/TelepathyQt4/cli-connection.h b/TelepathyQt4/cli-connection.h
index 8a51d69..dffffd2 100644
--- a/TelepathyQt4/cli-connection.h
+++ b/TelepathyQt4/cli-connection.h
@@ -57,6 +57,7 @@ class PendingChannel;
 #include <TelepathyQt4/Client/Channel>
 #include <TelepathyQt4/Client/DBus>
 #include <TelepathyQt4/Client/OptionalInterfaceFactory>
+#include <TelepathyQt4/Client/PendingOperation>
 
 namespace Telepathy
 {
@@ -417,6 +418,17 @@ public:
      */
     PendingChannel* requestChannel(const QString& channelType, uint handleType, uint handle);
 
+    /**
+     * Start an asynchronous request that the connection be disconnected.
+     * The returned PendingOperation object will signal the success or failure
+     * of this request; under normal circumstances, it can be expected to
+     * succeed.
+     *
+     * \return A %PendingOperation, which will emit finished when the
+     *  Disconnect D-Bus method returns.
+     */
+    PendingOperation* requestDisconnect();
+
 Q_SIGNALS:
     /**
      * Emitted whenever the readiness of the Connection changes.
diff --git a/tests/pinocchio/conn-basics.cpp b/tests/pinocchio/conn-basics.cpp
index 92ac162..386e92b 100644
--- a/tests/pinocchio/conn-basics.cpp
+++ b/tests/pinocchio/conn-basics.cpp
@@ -26,6 +26,7 @@ protected Q_SLOTS:
     void expectNotYetConnected(uint);
     void expectReady(uint);
     void expectSuccessfulCall(QDBusPendingCallWatcher*);
+    void expectSuccessfulCall(PendingOperation*, bool);
 
 private Q_SLOTS:
     void initTestCase();
@@ -141,13 +142,24 @@ void TestConnBasics::testInitialIntrospection()
 }
 
 
-void TestConnBasics::expectSuccessfulCall(QDBusPendingCallWatcher* watcher)
+void TestConnBasics::expectSuccessfulCall(PendingOperation* op, bool success)
 {
-    QDBusPendingReply<> reply = *watcher;
+    if (!success) {
+        qWarning().nospace() << op->errorName()
+            << ": " << op->errorMessage();
+        mLoop->exit(1);
+        return;
+    }
 
-    if (reply.isError()) {
-        qWarning().nospace() << reply.error().name()
-            << ": " << reply.error().message();
+    mLoop->exit(0);
+}
+
+
+void TestConnBasics::expectSuccessfulCall(QDBusPendingCallWatcher* watcher)
+{
+    if (watcher->isError()) {
+        qWarning().nospace() << watcher->error().name()
+            << ": " << watcher->error().message();
         mLoop->exit(1);
         return;
     }
@@ -235,13 +247,11 @@ void TestConnBasics::testConnect()
     QVERIFY(interfaces.contains(QLatin1String(
             TELEPATHY_INTERFACE_CONNECTION_INTERFACE_CAPABILITIES)));
 
-    // FIXME: should have convenience API
-    watcher = new QDBusPendingCallWatcher(
-            mConn->Disconnect());
-    QVERIFY(connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
-            this, SLOT(expectSuccessfulCall(QDBusPendingCallWatcher*))));
+    QVERIFY(connect(mConn->requestDisconnect(),
+          SIGNAL(finished(PendingOperation*, bool)),
+          this,
+          SLOT(expectSuccessfulCall(PendingOperation*, bool))));
     QCOMPARE(mLoop->exec(), 0);
-    delete watcher;
 
     QCOMPARE(mConn->readiness(), Connection::ReadinessDead);
     QCOMPARE(static_cast<uint>(mConn->status()),
-- 
1.5.6.5




More information about the Telepathy-commits mailing list