[telepathy-qt4/master] ClientRegistrar: Use MethodInvocationContext instead of PendingClientOperation.

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Thu May 14 13:19:29 PDT 2009


---
 TelepathyQt4/abstract-client.h           |    4 +-
 TelepathyQt4/client-registrar-internal.h |    6 +-
 TelepathyQt4/client-registrar.cpp        |   74 ++++++++++++++++++++++-------
 tests/dbus/client-handler.cpp            |   10 ++--
 4 files changed, 64 insertions(+), 30 deletions(-)

diff --git a/TelepathyQt4/abstract-client.h b/TelepathyQt4/abstract-client.h
index a699508..b13daca 100644
--- a/TelepathyQt4/abstract-client.h
+++ b/TelepathyQt4/abstract-client.h
@@ -37,8 +37,6 @@
 namespace Tp
 {
 
-class PendingClientOperation;
-
 class AbstractClient : public RefCounted
 {
     Q_DISABLE_COPY(AbstractClient)
@@ -98,7 +96,7 @@ public:
     ChannelClassList channelFilter() const;
     virtual bool bypassApproval() const = 0;
 
-    virtual void handleChannels(PendingClientOperation *operation,
+    virtual void handleChannels(const MethodInvocationContextPtr<> &context,
             const AccountPtr &account,
             const ConnectionPtr &connection,
             const QList<ChannelPtr> &channels,
diff --git a/TelepathyQt4/client-registrar-internal.h b/TelepathyQt4/client-registrar-internal.h
index 7a6a3c9..c51ad49 100644
--- a/TelepathyQt4/client-registrar-internal.h
+++ b/TelepathyQt4/client-registrar-internal.h
@@ -32,7 +32,6 @@
 namespace Tp
 {
 
-class PendingClientOperation;
 class PendingOperation;
 
 class ClientAdaptor : public QDBusAbstractAdaptor
@@ -131,13 +130,14 @@ public Q_SLOTS: // Methods
             const QDBusMessage &message);
 
 private Q_SLOTS:
-    void onOperationFinished(Tp::PendingOperation *op);
     void onChannelInvalidated(Tp::DBusProxy *proxy);
 
 private:
+    static void onContextFinished(const MethodInvocationContextPtr<> &context,
+            const QList<ChannelPtr> &channels, ClientHandlerAdaptor *self);
+
     QDBusConnection mBus;
     AbstractClientHandler *mClient;
-    QHash<PendingClientOperation *, QList<ChannelPtr> > mOperations;
     QSet<ChannelPtr> mHandledChannels;
 
     static QHash<QPair<QString, QString>, QList<ClientHandlerAdaptor *> > mAdaptorsForConnection;
diff --git a/TelepathyQt4/client-registrar.cpp b/TelepathyQt4/client-registrar.cpp
index 2706a4d..1f34180 100644
--- a/TelepathyQt4/client-registrar.cpp
+++ b/TelepathyQt4/client-registrar.cpp
@@ -31,12 +31,54 @@
 #include <TelepathyQt4/Channel>
 #include <TelepathyQt4/ChannelRequest>
 #include <TelepathyQt4/Connection>
-#include <TelepathyQt4/PendingClientOperation>
+#include <TelepathyQt4/MethodInvocationContext>
 #include <TelepathyQt4/PendingReady>
 
 namespace Tp
 {
 
+class HandleChannelsInvocationContext : public MethodInvocationContext<>
+{
+    Q_DISABLE_COPY(HandleChannelsInvocationContext)
+
+public:
+    typedef void (*FinishedCb)(const MethodInvocationContextPtr<> &context,
+                               const QList<ChannelPtr> &channels,
+                               void *data);
+
+    static MethodInvocationContextPtr<> create(const QDBusConnection &bus,
+            const QDBusMessage &message, const QList<ChannelPtr> &channels,
+            FinishedCb finishedCb, void *finishedCbData)
+    {
+        return MethodInvocationContextPtr<>::dynamicCast(
+                SharedPtr<HandleChannelsInvocationContext>(
+                    new HandleChannelsInvocationContext(bus, message, channels,
+                        finishedCb, finishedCbData)));
+    }
+
+private:
+    HandleChannelsInvocationContext(const QDBusConnection &connection,
+            const QDBusMessage &message, const QList<ChannelPtr> &channels,
+            FinishedCb finishedCb, void *finishedCbData)
+        : MethodInvocationContext<>(connection, message),
+          mChannels(channels),
+          mFinishedCb(finishedCb),
+          mFinishedCbData(finishedCbData)
+    {
+    }
+
+    void onFinished()
+    {
+        if (mFinishedCb) {
+            mFinishedCb(MethodInvocationContextPtr<>(this), mChannels, mFinishedCbData);
+        }
+    }
+
+    QList<ChannelPtr> mChannels;
+    FinishedCb mFinishedCb;
+    void *mFinishedCbData;
+};
+
 ClientAdaptor::ClientAdaptor(const QStringList &interfaces,
         QObject *parent)
     : QDBusAbstractAdaptor(parent),
@@ -114,35 +156,31 @@ void ClientHandlerAdaptor::HandleChannels(const QDBusObjectPath &accountPath,
         userActionTime = QDateTime::fromTime_t((uint) userActionTime_t);
     }
 
-    PendingClientOperation *operation = new PendingClientOperation(mBus,
-            message, this);
-    connect(operation,
-            SIGNAL(finished(Tp::PendingOperation*)),
-            SLOT(onOperationFinished(Tp::PendingOperation*)));
+    MethodInvocationContextPtr<> context =
+        HandleChannelsInvocationContext::create(mBus, message,
+                channels,
+                (HandleChannelsInvocationContext::FinishedCb) &ClientHandlerAdaptor::onContextFinished,
+                this);
 
-    mClient->handleChannels(operation, account, connection, channels,
+    mClient->handleChannels(context, account, connection, channels,
             channelRequests, userActionTime, handlerInfo);
-
-    mOperations.insert(operation, channels);
 }
 
-void ClientHandlerAdaptor::onOperationFinished(PendingOperation *op)
+void ClientHandlerAdaptor::onContextFinished(
+        const MethodInvocationContextPtr<> &context,
+        const QList<ChannelPtr> &channels, ClientHandlerAdaptor *self)
 {
-    if (!op->isError()) {
-        debug() << "HandleChannels operation finished successfully, "
+    if (!context->isError()) {
+        debug() << "HandleChannels context finished successfully, "
             "updating handled channels";
-        QList<ChannelPtr> channels =
-            mOperations.value(dynamic_cast<PendingClientOperation*>(op));
         foreach (const ChannelPtr &channel, channels) {
-            mHandledChannels.insert(channel);
-            connect(channel.data(),
+            self->mHandledChannels.insert(channel);
+            self->connect(channel.data(),
                     SIGNAL(invalidated(Tp::DBusProxy *,
                                        const QString &, const QString &)),
                     SLOT(onChannelInvalidated(Tp::DBusProxy *)));
         }
     }
-
-    mOperations.remove(dynamic_cast<PendingClientOperation*>(op));
 }
 
 void ClientHandlerAdaptor::onChannelInvalidated(DBusProxy *proxy)
diff --git a/tests/dbus/client-handler.cpp b/tests/dbus/client-handler.cpp
index 4783e61..c2e55dd 100644
--- a/tests/dbus/client-handler.cpp
+++ b/tests/dbus/client-handler.cpp
@@ -17,8 +17,8 @@
 #include <TelepathyQt4/ClientRegistrar>
 #include <TelepathyQt4/Connection>
 #include <TelepathyQt4/Debug>
+#include <TelepathyQt4/MethodInvocationContext>
 #include <TelepathyQt4/PendingAccount>
-#include <TelepathyQt4/PendingClientOperation>
 #include <TelepathyQt4/PendingReady>
 #include <TelepathyQt4/Types>
 
@@ -157,7 +157,7 @@ public:
         return mBypassApproval;
     }
 
-    void handleChannels(PendingClientOperation *operation,
+    void handleChannels(const MethodInvocationContextPtr<> &context,
             const AccountPtr &account,
             const ConnectionPtr &connection,
             const QList<ChannelPtr> &channels,
@@ -179,10 +179,8 @@ public:
                     SIGNAL(channelClosed()));
         }
 
-        operation->setFinished();
-        connect(operation,
-                SIGNAL(finished(Tp::PendingOperation*)),
-                SIGNAL(handleChannelsFinished()));
+        context->setFinished();
+        QTimer::singleShot(0, this, SIGNAL(handleChannelsFinished()));
     }
 
     void addRequest(const ChannelRequestPtr &request)
-- 
1.5.6.5




More information about the telepathy-commits mailing list