[telepathy-qt4/master] ClientRegistrar: Make AbstractClientHandler::add/removeRequest receive a ChannelRequestPtr object.

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Tue May 5 07:48:51 PDT 2009


Changes:
AbstractClientHandler::handleChannels receives a list of not ready ChannelRequestPtr objects.
AbstractClientHandler::addRequest receives a ready ChannelRequestPtr object.
AbstractClientHandler::removeRequest receives a not-ready ChannelRequestPtr object.
---
 TelepathyQt4/abstract-client.cpp         |    5 +-
 TelepathyQt4/abstract-client.h           |    5 +-
 TelepathyQt4/client-registrar-internal.h |   39 +++++++++++++-
 TelepathyQt4/client-registrar.cpp        |   86 ++++++++++++++++++++++++-----
 4 files changed, 113 insertions(+), 22 deletions(-)

diff --git a/TelepathyQt4/abstract-client.cpp b/TelepathyQt4/abstract-client.cpp
index 2361c3b..dda5056 100644
--- a/TelepathyQt4/abstract-client.cpp
+++ b/TelepathyQt4/abstract-client.cpp
@@ -67,15 +67,14 @@ bool AbstractClientHandler::isListeningRequests() const
 }
 
 void AbstractClientHandler::addRequest(
-        const QString &requestObjectPath,
-        const QVariantMap &requestProperties)
+        const ChannelRequestPtr &channelRequest)
 {
     // do nothing, subclasses that want to listen requests should reimplement
     // this method
 }
 
 void AbstractClientHandler::removeRequest(
-        const QString &requestObjectPath,
+        const ChannelRequestPtr &channelRequest,
         const QString &errorName, const QString &errorMessage)
 {
     // do nothing, subclasses that want to listen requests should reimplement
diff --git a/TelepathyQt4/abstract-client.h b/TelepathyQt4/abstract-client.h
index d646b3d..a599428 100644
--- a/TelepathyQt4/abstract-client.h
+++ b/TelepathyQt4/abstract-client.h
@@ -75,9 +75,8 @@ public:
             const QVariantMap &handlerInfo) = 0;
 
     bool isListeningRequests() const;
-    virtual void addRequest(const QString &requestObjectPath,
-            const QVariantMap &requestProperties);
-    virtual void removeRequest(const QString &requestObjectPath,
+    virtual void addRequest(const ChannelRequestPtr &request);
+    virtual void removeRequest(const ChannelRequestPtr &request,
             const QString &errorName, const QString &errorMessage);
 
 protected:
diff --git a/TelepathyQt4/client-registrar-internal.h b/TelepathyQt4/client-registrar-internal.h
index 960cae8..cf86b6a 100644
--- a/TelepathyQt4/client-registrar-internal.h
+++ b/TelepathyQt4/client-registrar-internal.h
@@ -205,15 +205,52 @@ public:
 
 public Q_SLOTS: // Methods
     void AddRequest(const QDBusObjectPath &request,
-            const QVariantMap &properties,
+            const QVariantMap &requestProperties,
             const QDBusMessage &message);
     void RemoveRequest(const QDBusObjectPath &request,
             const QString &errorName, const QString &errorMessage,
             const QDBusMessage &message);
 
+private Q_SLOTS:
+    void onAddRequestCallFinished();
+
 private:
+    void processAddRequestQueue();
+
+    class AddRequestCall;
+
     QDBusConnection mBus;
     AbstractClientHandler *mClient;
+    QQueue<AddRequestCall*> mAddRequestQueue;
+    bool mProcessingAddRequest;
+};
+
+class ClientHandlerRequestsAdaptor::AddRequestCall : public QObject
+{
+    Q_OBJECT
+
+public:
+    AddRequestCall(AbstractClientHandler *client,
+            const QDBusObjectPath &request,
+            const QVariantMap &requestProperties,
+            const QDBusConnection &bus,
+            QObject *parent);
+    virtual ~AddRequestCall();
+
+    void process();
+
+Q_SIGNALS:
+    void finished();
+
+private Q_SLOTS:
+    void onChannelRequestReady(Tp::PendingOperation *op);
+
+private:
+    AbstractClientHandler *mClient;
+    QDBusObjectPath mRequestPath;
+    QVariantMap mRequestProperties;
+    QDBusConnection mBus;
+    ChannelRequestPtr mRequest;
 };
 
 } // Tp
diff --git a/TelepathyQt4/client-registrar.cpp b/TelepathyQt4/client-registrar.cpp
index 455e301..4f71035 100644
--- a/TelepathyQt4/client-registrar.cpp
+++ b/TelepathyQt4/client-registrar.cpp
@@ -145,9 +145,6 @@ void ClientHandlerAdaptor::HandleChannelsCall::process()
     foreach (const QDBusObjectPath &path, mRequestsSatisfied) {
         channelRequest = ChannelRequest::create(mBus,
                 path.path(), QVariantMap());
-        connect(channelRequest->becomeReady(),
-                SIGNAL(finished(Tp::PendingOperation *)),
-                SLOT(onObjectReady(Tp::PendingOperation *)));
         mChannelRequests.append(channelRequest);
     }
 }
@@ -196,12 +193,6 @@ void ClientHandlerAdaptor::HandleChannelsCall::checkFinished()
         }
     }
 
-    foreach (const ChannelRequestPtr &channelRequest, mChannelRequests) {
-        if (!channelRequest->isReady()) {
-            return;
-        }
-    }
-
     // FIXME: Telepathy supports 64-bit time_t, but Qt only does so on
     // ILP64 systems (e.g. sparc64, but not x86_64). If QDateTime
     // gains a fromTimestamp64 method, we should use it instead.
@@ -212,6 +203,7 @@ void ClientHandlerAdaptor::HandleChannelsCall::checkFinished()
     mClient->handleChannels(mOperation, mAccount, mConnection, mChannels,
             mChannelRequests, userActionTime, mHandlerInfo);
     emit finished();
+    deleteLater();
 }
 
 void ClientHandlerAdaptor::HandleChannelsCall::setFinishedWithError(const QString &errorName,
@@ -227,7 +219,8 @@ ClientHandlerRequestsAdaptor::ClientHandlerRequestsAdaptor(
         AbstractClientHandler *client)
     : QDBusAbstractAdaptor(client),
       mBus(bus),
-      mClient(client)
+      mClient(client),
+      mProcessingAddRequest(false)
 {
 }
 
@@ -235,15 +228,16 @@ ClientHandlerRequestsAdaptor::~ClientHandlerRequestsAdaptor()
 {
 }
 
-// TODO should we use ChannelRequestPtr on
-// AbstractClientHandler::addRequest/removeRequest?
 void ClientHandlerRequestsAdaptor::AddRequest(
         const QDBusObjectPath &request,
-        const QVariantMap &properties,
+        const QVariantMap &requestProperties,
         const QDBusMessage &message)
 {
     mBus.send(message.createReply());
-    mClient->addRequest(request.path(), properties);
+
+    mAddRequestQueue.enqueue(new AddRequestCall(mClient, request,
+                requestProperties, mBus, this));
+    processAddRequestQueue();
 }
 
 void ClientHandlerRequestsAdaptor::RemoveRequest(
@@ -252,7 +246,69 @@ void ClientHandlerRequestsAdaptor::RemoveRequest(
         const QDBusMessage &message)
 {
     mBus.send(message.createReply());
-    mClient->removeRequest(request.path(), errorName, errorMessage);
+    mClient->removeRequest(ChannelRequest::create(mBus,
+                request.path(), QVariantMap()), errorName, errorMessage);
+}
+
+void ClientHandlerRequestsAdaptor::processAddRequestQueue()
+{
+    if (mProcessingAddRequest) {
+        return;
+    }
+
+    mProcessingAddRequest = true;
+    AddRequestCall *call = mAddRequestQueue.head();
+    connect(call,
+            SIGNAL(finished()),
+            SLOT(onAddRequestCallFinished()));
+    call->process();
+}
+
+void ClientHandlerRequestsAdaptor::onAddRequestCallFinished()
+{
+    mAddRequestQueue.dequeue();
+    mProcessingAddRequest = false;
+    processAddRequestQueue();
+}
+
+ClientHandlerRequestsAdaptor::AddRequestCall::AddRequestCall(
+        AbstractClientHandler *client,
+        const QDBusObjectPath &request,
+        const QVariantMap &requestProperties,
+        const QDBusConnection &bus,
+        QObject *parent)
+    : QObject(parent),
+      mClient(client),
+      mRequestPath(request),
+      mRequestProperties(requestProperties),
+      mBus(bus)
+{
+}
+
+ClientHandlerRequestsAdaptor::AddRequestCall::~AddRequestCall()
+{
+}
+
+void ClientHandlerRequestsAdaptor::AddRequestCall::process()
+{
+    mRequest = ChannelRequest::create(mBus,
+            mRequestPath.path(), mRequestProperties);
+    connect(mRequest->becomeReady(),
+            SIGNAL(finished(Tp::PendingOperation *)),
+            SLOT(onChannelRequestReady(Tp::PendingOperation *)));
+}
+
+void ClientHandlerRequestsAdaptor::AddRequestCall::onChannelRequestReady(
+        PendingOperation *op)
+{
+    if (!op->isError()) {
+        mClient->addRequest(mRequest);
+    } else {
+        warning() << "Unable to make ChannelRequest ready:" << op->errorName()
+            << "-" << op->errorMessage() << ". Ignoring AddRequest call";
+    }
+    emit finished();
+    deleteLater();
 }
 
 struct ClientRegistrar::Private
-- 
1.5.6.5




More information about the telepathy-commits mailing list