[Telepathy-commits] [telepathy-qt4/master] Connection: change from "is a ConnectionInterface" to "has a ConnectionInterface"

Simon McVittie simon.mcvittie at collabora.co.uk
Wed Dec 3 10:13:42 PST 2008


For the moment, the baseInterface accessor is public rather than
protected, because we don't yet have a satisfactory API for Connect
(something like telepathy-glib's tp_connection_call_when_ready(),
using a PendingOperation).
---
 TelepathyQt4/cli-channel.cpp    |    2 +-
 TelepathyQt4/cli-connection.cpp |   36 ++++++++++++++++++++++++++++--------
 TelepathyQt4/cli-connection.h   |   18 ++++++++++++++++--
 tests/pinocchio/chan-basics.cpp |   17 +++++++++--------
 tests/pinocchio/conn-basics.cpp |   21 ++++++++++-----------
 5 files changed, 64 insertions(+), 30 deletions(-)

diff --git a/TelepathyQt4/cli-channel.cpp b/TelepathyQt4/cli-channel.cpp
index 7869315..545ade7 100644
--- a/TelepathyQt4/cli-channel.cpp
+++ b/TelepathyQt4/cli-channel.cpp
@@ -401,7 +401,7 @@ struct Channel::Private
 Channel::Channel(Connection* connection,
                  const QString& objectPath,
                  QObject* parent)
-  : StatefulDBusProxy(connection->connection(), connection->service(),
+  : StatefulDBusProxy(connection->dbusConnection(), connection->busName(),
             objectPath, parent),
     mPriv(new Private(*this, connection))
 {
diff --git a/TelepathyQt4/cli-connection.cpp b/TelepathyQt4/cli-connection.cpp
index 4219987..759dc49 100644
--- a/TelepathyQt4/cli-connection.cpp
+++ b/TelepathyQt4/cli-connection.cpp
@@ -44,6 +44,9 @@ struct Connection::Private
     // Public object
     Connection& parent;
 
+    // Instance of generated interface class
+    ConnectionInterface* baseInterface;
+
     // Optional interface proxies
     ConnectionInterfaceAliasingInterface* aliasing;
     ConnectionInterfacePresenceInterface* presence;
@@ -68,23 +71,31 @@ struct Connection::Private
         aliasing = 0;
         presence = 0;
         properties = 0;
+        baseInterface = 0;
 
         initialIntrospection = false;
         readiness = ReadinessJustCreated;
         status = ConnectionStatusDisconnected;
         statusReason = ConnectionStatusReasonNoneSpecified;
         aliasFlags = 0;
+    }
+
+    void startIntrospection()
+    {
+        Q_ASSERT(baseInterface == 0);
+        baseInterface = new ConnectionInterface(parent.dbusConnection(),
+            parent.busName(), parent.objectPath(), &parent);
 
         debug() << "Connecting to StatusChanged()";
 
-        parent.connect(&parent,
+        parent.connect(baseInterface,
                        SIGNAL(StatusChanged(uint, uint)),
                        SLOT(onStatusChanged(uint, uint)));
 
         debug() << "Calling GetStatus()";
 
         QDBusPendingCallWatcher* watcher =
-            new QDBusPendingCallWatcher(parent.GetStatus(), &parent);
+            new QDBusPendingCallWatcher(baseInterface->GetStatus(), &parent);
         parent.connect(watcher,
                        SIGNAL(finished(QDBusPendingCallWatcher*)),
                        SLOT(gotStatus(QDBusPendingCallWatcher*)));
@@ -118,7 +129,7 @@ struct Connection::Private
         // gain GetAll-able properties on the connection
         debug() << "Calling GetInterfaces()";
         QDBusPendingCallWatcher* watcher =
-            new QDBusPendingCallWatcher(parent.GetInterfaces(), &parent);
+            new QDBusPendingCallWatcher(baseInterface->GetInterfaces(), &parent);
         parent.connect(watcher,
                        SIGNAL(finished(QDBusPendingCallWatcher*)),
                        SLOT(gotInterfaces(QDBusPendingCallWatcher*)));
@@ -211,18 +222,21 @@ struct Connection::Private
 Connection::Connection(const QString& serviceName,
                        const QString& objectPath,
                        QObject* parent)
-    : ConnectionInterface(serviceName, objectPath, parent),
+    : StatefulDBusProxy(QDBusConnection::sessionBus(), serviceName,
+          objectPath, parent),
       mPriv(new Private(*this))
 {
+    mPriv->startIntrospection();
 }
 
 Connection::Connection(const QDBusConnection& connection,
                        const QString& serviceName,
                        const QString& objectPath,
                        QObject* parent)
-    : ConnectionInterface(connection, serviceName, objectPath, parent),
+    : StatefulDBusProxy(connection, serviceName, objectPath, parent),
       mPriv(new Private(*this))
 {
+    mPriv->startIntrospection();
 }
 
 Connection::~Connection()
@@ -448,6 +462,12 @@ void Connection::gotSimpleStatuses(QDBusPendingCallWatcher* watcher)
     mPriv->continueIntrospection();
 }
 
+ConnectionInterface* Connection::baseInterface() const
+{
+    Q_ASSERT(mPriv->baseInterface != 0);
+    return mPriv->baseInterface;
+}
+
 PendingChannel* Connection::requestChannel(const QString& channelType, uint handleType, uint handle)
 {
     debug() << "Requesting a Channel with type" << channelType << "and handle" << handle << "of type" << handleType;
@@ -455,7 +475,7 @@ PendingChannel* Connection::requestChannel(const QString& channelType, uint hand
     PendingChannel* channel =
         new PendingChannel(this, channelType, handleType, handle);
     QDBusPendingCallWatcher* watcher =
-        new QDBusPendingCallWatcher(RequestChannel(channelType, handleType, handle, true), channel);
+        new QDBusPendingCallWatcher(mPriv->baseInterface->RequestChannel(channelType, handleType, handle, true), channel);
 
     channel->connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
                               SLOT(onCallFinished(QDBusPendingCallWatcher*)));
@@ -469,13 +489,13 @@ PendingChannel* Connection::requestChannel(const QString& channelType, uint hand
 // more analogous to tp_connection_call_when_ready() in telepathy-glib
 PendingOperation* Connection::requestConnect()
 {
-    return new PendingVoidMethodCall(this, this->Connect());
+    return new PendingVoidMethodCall(this, baseInterface()->Connect());
 }
 #endif
 
 PendingOperation* Connection::requestDisconnect()
 {
-    return new PendingVoidMethodCall(this, this->Disconnect());
+    return new PendingVoidMethodCall(this, baseInterface()->Disconnect());
 }
 
 }
diff --git a/TelepathyQt4/cli-connection.h b/TelepathyQt4/cli-connection.h
index 4c4acf5..acf355a 100644
--- a/TelepathyQt4/cli-connection.h
+++ b/TelepathyQt4/cli-connection.h
@@ -55,6 +55,7 @@ class Connection;
 #include <TelepathyQt4/Constants>
 #include <TelepathyQt4/Client/Channel>
 #include <TelepathyQt4/Client/DBus>
+#include <TelepathyQt4/Client/DBusProxy>
 #include <TelepathyQt4/Client/OptionalInterfaceFactory>
 #include <TelepathyQt4/Client/PendingOperation>
 
@@ -92,7 +93,7 @@ namespace Client
  * individual accessor descriptions for details on which functions can be used
  * in the different states.
  */
-class Connection : public ConnectionInterface, private OptionalInterfaceFactory
+class Connection : public StatefulDBusProxy, private OptionalInterfaceFactory
 {
     Q_OBJECT
     Q_ENUMS(Readiness);
@@ -315,7 +316,7 @@ public:
             return 0;
 
         // If present or forced, delegate to OptionalInterfaceFactory
-        return OptionalInterfaceFactory::interface<Interface>(*this);
+        return OptionalInterfaceFactory::interface<Interface>(*baseInterface());
     }
 
     /**
@@ -438,6 +439,19 @@ Q_SIGNALS:
      */
     void readinessChanged(uint newReadiness);
 
+public:
+    /**
+     * Get the ConnectionInterface for this Connection.
+     *
+     * FIXME: This method should be protected since the convenience methods
+     * provided by this class should always be used instead. However, they
+     * haven't all been written yet.
+     *
+     * \return A pointer to the existing ConnectionInterface for this
+     *         Connection
+     */
+    ConnectionInterface* baseInterface() const;
+
 private Q_SLOTS:
     void onStatusChanged(uint, uint);
     void gotStatus(QDBusPendingCallWatcher* watcher);
diff --git a/tests/pinocchio/chan-basics.cpp b/tests/pinocchio/chan-basics.cpp
index ebc8f4f..699e4be 100644
--- a/tests/pinocchio/chan-basics.cpp
+++ b/tests/pinocchio/chan-basics.cpp
@@ -112,9 +112,10 @@ void TestChanBasics::initTestCase()
 
     // Get a connected Connection
     mConn = new Connection(mConnBusName, mConnObjectPath);
+    Q_ASSERT(mConn->baseInterface() != 0);
 
     QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(
-            mConn->Connect());
+            mConn->baseInterface()->Connect());
     QVERIFY(connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
             this, SLOT(expectSuccessfulCall(QDBusPendingCallWatcher*))));
     QCOMPARE(mLoop->exec(), 0);
@@ -129,13 +130,14 @@ void TestChanBasics::initTestCase()
     // Using direct access to low-level stuff here, so we can test the
     // Channel constructor directly
     QDBusPendingReply<Telepathy::UIntList> requestHandlesReply =
-        mConn->RequestHandles(Telepathy::HandleTypeList,
+        mConn->baseInterface()->RequestHandles(Telepathy::HandleTypeList,
             QStringList() << "subscribe");
     requestHandlesReply.waitForFinished();
     mSubscribeHandle = requestHandlesReply.value().at(0);
 
     QDBusPendingReply<QDBusObjectPath> requestChannelReply =
-        mConn->RequestChannel(TELEPATHY_INTERFACE_CHANNEL_TYPE_CONTACT_LIST,
+        mConn->baseInterface()->RequestChannel(
+            TELEPATHY_INTERFACE_CHANNEL_TYPE_CONTACT_LIST,
             Telepathy::HandleTypeList, mSubscribeHandle, true);
     requestChannelReply.waitForFinished();
     mSubscribeChanObjectPath = requestChannelReply.value().path();
@@ -320,12 +322,11 @@ void TestChanBasics::cleanup()
 
 void TestChanBasics::cleanupTestCase()
 {
-    QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(
-            mConn->Disconnect());
-    QVERIFY(connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
-            this, SLOT(expectSuccessfulCall(QDBusPendingCallWatcher*))));
+    QVERIFY(connect(mConn->requestDisconnect(),
+          SIGNAL(finished(Telepathy::Client::PendingOperation*)),
+          this,
+          SLOT(expectSuccessfulCall(Telepathy::Client::PendingOperation*))));
     QCOMPARE(mLoop->exec(), 0);
-    delete watcher;
 
     delete mConn;
     mConn = NULL;
diff --git a/tests/pinocchio/conn-basics.cpp b/tests/pinocchio/conn-basics.cpp
index fb46ef3..b78331c 100644
--- a/tests/pinocchio/conn-basics.cpp
+++ b/tests/pinocchio/conn-basics.cpp
@@ -189,11 +189,11 @@ void TestConnBasics::testConnect()
     QVERIFY(disconnect(mConn, SIGNAL(readinessChanged(uint)),
           this, SLOT(expectNotYetConnected(uint))));
 
-    // FIXME: should have convenience API
+    // FIXME: should have convenience API so we don't have to use
+    // baseInterface directly
     qDebug() << "calling Connect()";
-
     QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(
-            mConn->Connect());
+            mConn->baseInterface()->Connect());
     QVERIFY(connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
             this, SLOT(expectSuccessfulCall(QDBusPendingCallWatcher*))));
     QCOMPARE(mLoop->exec(), 0);
@@ -250,11 +250,11 @@ void TestConnBasics::testAlreadyConnected()
     QVERIFY(disconnect(mConn, SIGNAL(readinessChanged(uint)),
           this, SLOT(expectNotYetConnected(uint))));
 
-    // FIXME: should have convenience API
+    // FIXME: should have convenience API so we don't have to use
+    // baseInterface directly
     qDebug() << "calling Connect()";
-
     QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(
-            mConn->Connect());
+            mConn->baseInterface()->Connect());
     QVERIFY(connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
             this, SLOT(expectSuccessfulCall(QDBusPendingCallWatcher*))));
     QCOMPARE(mLoop->exec(), 0);
@@ -282,12 +282,11 @@ void TestConnBasics::testAlreadyConnected()
     QVERIFY(disconnect(mConn, SIGNAL(readinessChanged(uint)),
           this, SLOT(expectReady(uint))));
 
-    watcher = new QDBusPendingCallWatcher(
-            mConn->Disconnect());
-    QVERIFY(connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
-            this, SLOT(expectSuccessfulCall(QDBusPendingCallWatcher*))));
+    QVERIFY(connect(mConn->requestDisconnect(),
+          SIGNAL(finished(Telepathy::Client::PendingOperation*)),
+          this,
+          SLOT(expectSuccessfulCall(Telepathy::Client::PendingOperation*))));
     QCOMPARE(mLoop->exec(), 0);
-    delete watcher;
 
     delete mConn;
     mConn = NULL;
-- 
1.5.6.5



More information about the Telepathy-commits mailing list