diff options
author | Marja Hassinen <marja.hassinen@nokia.com> | 2010-12-17 16:28:22 +0200 |
---|---|---|
committer | Marja Hassinen <marja.hassinen@nokia.com> | 2010-12-17 16:28:22 +0200 |
commit | 672eadf9c8ec967076c7fe8ab011872bfa18f63a (patch) | |
tree | f632dc57f221b28609da248e1ef36fc9e5081788 | |
parent | 762c0ac25a79d7dda13c82dc592495a745f1f8d7 (diff) |
lcs: fixing the waitForSubscriptionAndBlock.
The subscription wasn't really happening (only scheduled), but now it is.
This version still suffers from a "multiple subscribe" problem; the Subscribe
D-Bus call is sent twice.
-rw-r--r-- | libcontextsubscriber/src/contextkitplugin.cpp | 17 | ||||
-rw-r--r-- | libcontextsubscriber/src/contextkitplugin.h | 1 |
2 files changed, 16 insertions, 2 deletions
diff --git a/libcontextsubscriber/src/contextkitplugin.cpp b/libcontextsubscriber/src/contextkitplugin.cpp index efb587fd..eeb8b7a1 100644 --- a/libcontextsubscriber/src/contextkitplugin.cpp +++ b/libcontextsubscriber/src/contextkitplugin.cpp @@ -233,7 +233,7 @@ void ContextKitPlugin::subscribe(QSet<QString> keys) // previous async call. (We emit "ready" when handling // GetSubscriber. "Ready" is not queued, and the above // layer can call subscribe when handling it.) - + pendingKeys.insert(key); QMetaObject::invokeMethod(this, "newSubscribe", Qt::QueuedConnection, Q_ARG(QString, key)); } else { @@ -243,6 +243,13 @@ void ContextKitPlugin::subscribe(QSet<QString> keys) void ContextKitPlugin::newSubscribe(const QString& key) { + if (pendingKeys.contains(key) == false) { + // this key was already handled, probably because + // waitForSubscriptionAndBlock forced the subscription to happen. + return; + } + pendingKeys.remove(key); + QString objectPath = keyToPath(key); // Store the "object path -> key" mapping so that we can transform // back when a valueChanged signal comes over D-Bus. (Note the @@ -382,8 +389,14 @@ void ContextKitPlugin::onNewValueChanged(QList<QVariant> value, void ContextKitPlugin::waitForSubscriptionAndBlock(const QString& key) { - if (pendingWatchers.contains(key)) + // Force the subscriptions (that were scheduled) to happen now + while (newProtocol && pendingKeys.size() > 0) { + QString key = *(pendingKeys.constBegin()); + newSubscribe(key); + } + if (pendingWatchers.contains(key)) { pendingWatchers.value(key)->waitForFinished(); + } } void ContextKitPlugin::removePendingWatcher(const QString& key) diff --git a/libcontextsubscriber/src/contextkitplugin.h b/libcontextsubscriber/src/contextkitplugin.h index 3215d882..abeebc7c 100644 --- a/libcontextsubscriber/src/contextkitplugin.h +++ b/libcontextsubscriber/src/contextkitplugin.h @@ -117,6 +117,7 @@ private: QHash<QString, QString> objectPathToKey; QHash<QString, PendingSubscribeWatcher*> pendingWatchers; + QSet<QString> pendingKeys; }; QVariant demarshallValue(const QVariant &v); |