From 4659f97087ce3b3680ebd45e7bf8ed7e5f52c8b2 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Mon, 20 Dec 2010 12:28:16 +0200 Subject: lcs: fixing the waitForSubscriptionAndBlock. Oops, the previous commit contained the first part of the "add waitUntilReadyAndBlock" change. This is the second part. --- libcontextsubscriber/src/contextkitplugin.cpp | 26 +++++++++++++++++++++- libcontextsubscriber/src/contextkitplugin.h | 4 ++++ libcontextsubscriber/src/iproviderplugin.h | 3 ++- .../unit-tests/provider/contextkitplugin.h | 1 + .../unit-tests/provider/testprovider.cpp | 4 ++++ 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/libcontextsubscriber/src/contextkitplugin.cpp b/libcontextsubscriber/src/contextkitplugin.cpp index eeb8b7a1..da43ddb0 100644 --- a/libcontextsubscriber/src/contextkitplugin.cpp +++ b/libcontextsubscriber/src/contextkitplugin.cpp @@ -88,8 +88,10 @@ ContextKitPlugin::ContextKitPlugin(const QDBusConnection bus, const QString& bus managerInterface(0), connection(new QDBusConnection(bus)), busName(busName), + newProtocol(true), defaultNewProtocol(true), - newProtocol(true) + providerAppearedQueued(false), + providerAppearedSkip(false) { reset(); // Notice if the provider on the dbus comes and goes @@ -103,6 +105,7 @@ ContextKitPlugin::ContextKitPlugin(const QDBusConnection bus, const QString& bus // the provider at startup, whether it's present or not. providerListener->startListening(false); QMetaObject::invokeMethod(this, "onProviderAppeared", Qt::QueuedConnection); + providerAppearedQueued = true; } void ContextKitPlugin::setDefaultNewProtocol(bool s) { @@ -133,6 +136,16 @@ void ContextKitPlugin::onProviderAppeared() // 4. providerListener notices that the provider was started // In this case, the plugin is in "ready" state already. + providerAppearedQueued = false; + + if (providerAppearedSkip) { + // Now we had queued this function to be called, but before it was + // called, waitUntilReadyAndBlock called it. Skip the scheduled call + // (but not the later calls). + providerAppearedSkip = false; + return; + } + contextDebug() << "Provider appeared:" << busName; reset(); @@ -387,6 +400,17 @@ void ContextKitPlugin::onNewValueChanged(QList value, } } +void ContextKitPlugin::waitUntilReadyAndBlock() +{ + onProviderAppeared(); + if (providerAppearedQueued) { + // Calling onProviderAppeared was already scheduled but we already + // called it now. Arrange so that the scheduled call is skipped when + // the event is processed. + providerAppearedSkip = true; + } +} + void ContextKitPlugin::waitForSubscriptionAndBlock(const QString& key) { // Force the subscriptions (that were scheduled) to happen now diff --git a/libcontextsubscriber/src/contextkitplugin.h b/libcontextsubscriber/src/contextkitplugin.h index abeebc7c..9d00a106 100644 --- a/libcontextsubscriber/src/contextkitplugin.h +++ b/libcontextsubscriber/src/contextkitplugin.h @@ -71,6 +71,7 @@ public: void subscribe(QSet keys); void unsubscribe(QSet keys); void setDefaultNewProtocol(bool s); + void waitUntilReadyAndBlock(); void waitForSubscriptionAndBlock(const QString& key); Q_SIGNALS: @@ -118,6 +119,9 @@ private: QHash pendingWatchers; QSet pendingKeys; + + bool providerAppearedQueued; + bool providerAppearedSkip; }; QVariant demarshallValue(const QVariant &v); diff --git a/libcontextsubscriber/src/iproviderplugin.h b/libcontextsubscriber/src/iproviderplugin.h index f5a44abd..79ba9da5 100644 --- a/libcontextsubscriber/src/iproviderplugin.h +++ b/libcontextsubscriber/src/iproviderplugin.h @@ -40,7 +40,8 @@ class IProviderPlugin : public QObject public: virtual void subscribe(QSet keys) = 0; virtual void unsubscribe(QSet keys) = 0; - virtual void waitForSubscriptionAndBlock(const QString& key) = 0; + virtual void waitUntilReadyAndBlock() { } + virtual void waitForSubscriptionAndBlock(const QString& key) { } Q_SIGNALS: void ready(); diff --git a/libcontextsubscriber/unit-tests/provider/contextkitplugin.h b/libcontextsubscriber/unit-tests/provider/contextkitplugin.h index ef5f9c24..0c346836 100644 --- a/libcontextsubscriber/unit-tests/provider/contextkitplugin.h +++ b/libcontextsubscriber/unit-tests/provider/contextkitplugin.h @@ -44,6 +44,7 @@ class ContextKitPlugin : public IProviderPlugin public: void subscribe(QSet keys); void unsubscribe(QSet keys); + void waitUntilReadyAndBlock(); void waitForSubscriptionAndBlock(const QString& key); Q_SIGNALS: diff --git a/libcontextsubscriber/unit-tests/provider/testprovider.cpp b/libcontextsubscriber/unit-tests/provider/testprovider.cpp index 84934417..8f22d909 100644 --- a/libcontextsubscriber/unit-tests/provider/testprovider.cpp +++ b/libcontextsubscriber/unit-tests/provider/testprovider.cpp @@ -137,6 +137,10 @@ void ContextKitPlugin::waitForSubscriptionAndBlock(const QString& key) { } +void ContextKitPlugin::waitUntilReadyAndBlock() +{ +} + // // Definition of testcases // -- cgit v1.2.3