telepathy-qt: dbus-tubes: Handle the contact queue properly in every case, and make the feature ready just after the whole queue has been introspected .

Dario Freddi drf at kemper.freedesktop.org
Tue Jul 3 15:08:41 PDT 2012


Module: telepathy-qt
Branch: master
Commit: dc7e28cce51de2e0f55edac758f4eba25c18f47f
URL:    http://cgit.freedesktop.org/telepathy/telepathy-qt/commit/?id=dc7e28cce51de2e0f55edac758f4eba25c18f47f

Author: Dario Freddi <dario.freddi at collabora.co.uk>
Date:   Thu Jun 16 14:14:19 2011 +0200

dbus-tubes: Handle the contact queue properly in every case, and make the feature ready just after the whole queue has been introspected.

---

 TelepathyQt/dbus-tube-channel.cpp                  |   24 ++++++++++++++++++-
 TelepathyQt/dbus-tube-channel.h                    |    1 +
 .../outgoing-stream-tube-channel-internal.h        |    4 +-
 TelepathyQt/outgoing-stream-tube-channel.cpp       |   12 +++++++--
 4 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/TelepathyQt/dbus-tube-channel.cpp b/TelepathyQt/dbus-tube-channel.cpp
index cceabbc..b2b3f97 100644
--- a/TelepathyQt/dbus-tube-channel.cpp
+++ b/TelepathyQt/dbus-tube-channel.cpp
@@ -355,8 +355,19 @@ void DBusTubeChannel::onRequestPropertyDBusNamesFinished(PendingOperation *op)
     if (!op->isError()) {
         debug() << "RequestPropertyDBusNames succeeded";
         PendingVariant *result = qobject_cast<PendingVariant*>(op);
-        mPriv->extractParticipants(qdbus_cast<DBusTubeParticipants>(result->result()));
-        mPriv->readinessHelper->setIntrospectCompleted(DBusTubeChannel::FeatureBusNameMonitoring, true);
+        DBusTubeParticipants participants = qdbus_cast<DBusTubeParticipants>(result->result());
+
+        if (participants.isEmpty()) {
+            // Nothing to do actually, simply mark the feature as ready.
+            mPriv->readinessHelper->setIntrospectCompleted(DBusTubeChannel::FeatureBusNameMonitoring, true);
+        } else {
+            // Extract the participants, populating the QueuedContactFactory
+            mPriv->extractParticipants(participants);
+
+            // Wait for the queue to complete
+            connect(mPriv->queuedContactFactory, SIGNAL(queueCompleted()),
+                    this, SLOT(onQueueCompleted()));
+        }
     } else {
         warning().nospace() << "RequestPropertyDBusNames failed "
             "with " << op->errorName() << ": " << op->errorMessage();
@@ -364,6 +375,15 @@ void DBusTubeChannel::onRequestPropertyDBusNamesFinished(PendingOperation *op)
     }
 }
 
+void DBusTubeChannel::onQueueCompleted()
+{
+    // Set the feature as completed, and disconnect the signal as it's no longer useful
+    mPriv->readinessHelper->setIntrospectCompleted(DBusTubeChannel::FeatureBusNameMonitoring, true);
+
+    disconnect(mPriv->queuedContactFactory, SIGNAL(queueCompleted()),
+               this, SLOT(onQueueCompleted()));
+}
+
 void DBusTubeChannel::onDBusNamesChanged(const Tp::DBusTubeParticipants &added,
         const Tp::UIntList &removed)
 {
diff --git a/TelepathyQt/dbus-tube-channel.h b/TelepathyQt/dbus-tube-channel.h
index d44ec8c..d00f89a 100644
--- a/TelepathyQt/dbus-tube-channel.h
+++ b/TelepathyQt/dbus-tube-channel.h
@@ -68,6 +68,7 @@ private Q_SLOTS:
     TP_QT_NO_EXPORT void onRequestPropertyDBusNamesFinished(Tp::PendingOperation *op);
     TP_QT_NO_EXPORT void onDBusNamesChanged(const Tp::DBusTubeParticipants &added, const Tp::UIntList &removed);
     TP_QT_NO_EXPORT void onContactsRetrieved(const QUuid &uuid, const QList<Tp::ContactPtr> &contacts);
+    TP_QT_NO_EXPORT void onQueueCompleted();
 
 private:
     struct Private;
diff --git a/TelepathyQt/outgoing-stream-tube-channel-internal.h b/TelepathyQt/outgoing-stream-tube-channel-internal.h
index b7fe41c..1480d9d 100644
--- a/TelepathyQt/outgoing-stream-tube-channel-internal.h
+++ b/TelepathyQt/outgoing-stream-tube-channel-internal.h
@@ -64,9 +64,11 @@ public:
 
 Q_SIGNALS:
     void contactsRetrieved(QUuid uuid, QList<Tp::ContactPtr> contacts);
+    void queueCompleted();
 
 private Q_SLOTS:
     void onPendingContactsFinished(Tp::PendingOperation *operation);
+    void processNextRequest();
 
 private:
     struct Entry {
@@ -74,8 +76,6 @@ private:
         UIntList handles;
     };
 
-    void processNextRequest();
-
     bool m_isProcessing;
     ContactManagerPtr m_manager;
     QQueue<Entry> m_queue;
diff --git a/TelepathyQt/outgoing-stream-tube-channel.cpp b/TelepathyQt/outgoing-stream-tube-channel.cpp
index 045b0ae..64e7c2f 100644
--- a/TelepathyQt/outgoing-stream-tube-channel.cpp
+++ b/TelepathyQt/outgoing-stream-tube-channel.cpp
@@ -129,11 +129,17 @@ QueuedContactFactory::~QueuedContactFactory()
 
 void QueuedContactFactory::processNextRequest()
 {
-    if (m_isProcessing || m_queue.isEmpty()) {
+    if (m_isProcessing) {
         // Return, nothing to do
         return;
     }
 
+    if (m_queue.isEmpty()) {
+        // Queue completed, notify and return
+        emit queueCompleted();
+        return;
+    }
+
     m_isProcessing = true;
 
     Entry entry = m_queue.dequeue();
@@ -154,8 +160,8 @@ QUuid QueuedContactFactory::appendNewRequest(const Tp::UIntList &handles)
     entry.handles = handles;
     m_queue.enqueue(entry);
 
-    // Check if we can process a request
-    processNextRequest();
+    // Enqueue a process request in the event loop
+    QTimer::singleShot(0, this, SLOT(processNextRequest()));
 
     // Return the UUID
     return entry.uuid;



More information about the telepathy-commits mailing list