diff options
author | Gergely Risko <gergely+context@risko.hu> | 2009-09-08 15:12:34 +0300 |
---|---|---|
committer | Gergely Risko <gergely+context@risko.hu> | 2009-09-08 15:12:34 +0300 |
commit | f1eeff2ac92e9b97e43cbbb17d737539327631e5 (patch) | |
tree | a9d7e08da5eccf7b54b4d45c60c4602b303fde41 | |
parent | 56974de18e0d0ac44db97bedc5e283b60a16e948 (diff) |
Small optimizations, doxygen documentation.
-rw-r--r-- | libcontextsubscriber/src/contextkitplugin.cpp | 35 | ||||
-rw-r--r-- | libcontextsubscriber/src/contextkitplugin.h | 20 | ||||
-rw-r--r-- | libcontextsubscriber/src/handlesignalrouter.cpp | 24 | ||||
-rw-r--r-- | libcontextsubscriber/src/handlesignalrouter.h | 1 | ||||
-rw-r--r-- | libcontextsubscriber/src/propertyhandle.cpp | 18 | ||||
-rw-r--r-- | libcontextsubscriber/src/propertyhandle.h | 2 | ||||
-rw-r--r-- | libcontextsubscriber/src/propertyprovider.cpp | 16 | ||||
-rw-r--r-- | libcontextsubscriber/src/propertyprovider.h | 6 |
8 files changed, 68 insertions, 54 deletions
diff --git a/libcontextsubscriber/src/contextkitplugin.cpp b/libcontextsubscriber/src/contextkitplugin.cpp index 30094d26..ca26b33a 100644 --- a/libcontextsubscriber/src/contextkitplugin.cpp +++ b/libcontextsubscriber/src/contextkitplugin.cpp @@ -26,9 +26,9 @@ #include "sconnect.h" #include <QStringList> -namespace ContextSubscriber { - -IProviderPlugin* contextKitPluginFactory(const QString& constructionString) +/// Creates a new instance, the service to connect to has to be passed +/// in \c constructionString in the format <tt>[session|dbus]:servicename</tt>. +ContextSubscriber::IProviderPlugin* contextKitPluginFactory(QString constructionString) { QStringList constr = constructionString.split(":"); if (constr.size() != 2) { @@ -36,14 +36,24 @@ IProviderPlugin* contextKitPluginFactory(const QString& constructionString) return 0; } if (constr[0] == "session") - return new ContextKitPlugin(QDBusConnection::sessionBus(), constr[1]); + return new ContextSubscriber::ContextKitPlugin(QDBusConnection::sessionBus(), constr[1]); else if (constr[0] == "system") - return new ContextKitPlugin(QDBusConnection::systemBus(), constr[1]); + return new ContextSubscriber::ContextKitPlugin(QDBusConnection::systemBus(), constr[1]); contextCritical() << "Unknown bus type: " << constructionString; return 0; } +namespace ContextSubscriber { + +/*! + \class ContextKitPlugin + \brief Implementation of the ContextKit D-Bus protocol. +*/ + +/// Creates subscriber and manager interface, tries to get a +/// subscriber instance from the manager and starts listening for +/// provider appearing and disappearing on D-Bus. ContextKitPlugin::ContextKitPlugin(const QDBusConnection bus, const QString& busName) : subscriberInterface(0), managerInterface(0), connection(new QDBusConnection(bus)), busName(busName) @@ -67,7 +77,8 @@ ContextKitPlugin::ContextKitPlugin(const QDBusConnection bus, const QString& bus onProviderAppeared(); } -/// Provider reappeared on the DBus, so get a new subscriber interface from it +/// Gets a new subscriber interface from manager when the provider +/// appears. void ContextKitPlugin::onProviderAppeared() { contextDebug() << "ContextKitPlugin::onProviderAppeared"; @@ -76,7 +87,7 @@ void ContextKitPlugin::onProviderAppeared() managerInterface->getSubscriber(); } -/// Delete our subscriber interface when the provider went away +/// Delete our subscriber interface when the provider goes away. void ContextKitPlugin::onProviderDisappeared() { contextDebug() << "ContextKitPlugin::onProviderDisappeared"; @@ -85,8 +96,8 @@ void ContextKitPlugin::onProviderDisappeared() emit failed("Provider went away"); } -/// Called when the manager interface is ready with the asynchronous -/// GetSubscriber call. +/// Starts using the fresh subscriber interface when it is returned by +/// the manager in response to the GetSubscriber call. void ContextKitPlugin::onDBusGetSubscriberFinished(QString objectPath) { if (objectPath != "") { @@ -110,29 +121,33 @@ void ContextKitPlugin::onDBusGetSubscriberFinished(QString objectPath) emit failed("Was unable to get subscriber object on dbus"); } +/// Signals the Provider that the subscribe is finished. void ContextKitPlugin::onDBusSubscribeFinished(QList<QString> keys) { foreach (const QString& key, keys) emit subscribeFinished(key); } +/// Signals the Provider that the subscribe is failed. void ContextKitPlugin::onDBusSubscribeFailed(QList<QString> keys, QString error) { foreach (const QString& key, keys) emit subscribeFailed(key, error); } +/// Forwards the subscribe request to the wire. void ContextKitPlugin::subscribe(QSet<QString> keys) { subscriberInterface->subscribe(keys); } +/// Forwards the unsubscribe request to the wire. void ContextKitPlugin::unsubscribe(QSet<QString> keys) { subscriberInterface->unsubscribe(keys); } -/// Slot, handling changed values coming from the provider over DBUS. +/// Forwards value changes from the wire to the upper layer (Provider). void ContextKitPlugin::onDBusValuesChanged(QMap<QString, QVariant> values) { foreach (const QString& key, values.keys()) diff --git a/libcontextsubscriber/src/contextkitplugin.h b/libcontextsubscriber/src/contextkitplugin.h index 6152a778..5fe8046d 100644 --- a/libcontextsubscriber/src/contextkitplugin.h +++ b/libcontextsubscriber/src/contextkitplugin.h @@ -29,12 +29,12 @@ #include <QMap> #include "dbusnamelistener.h" #include "propertyprovider.h" -namespace ContextSubscriber { extern "C" { - IProviderPlugin* contextKitPluginFactory(const QString& constructionString); + ContextSubscriber::IProviderPlugin* contextKitPluginFactory(QString constructionString); } +namespace ContextSubscriber { class ContextKitPlugin : public IProviderPlugin { Q_OBJECT @@ -45,11 +45,11 @@ public: void unsubscribe(QSet<QString> keys); signals: - void ready(); - void failed(QString error); - void subscribeFinished(QString key); - void subscribeFailed(QString failedKey, QString error); - void valueChanged(QString key, QVariant value); + void ready(); ///< Emitted when the GetSubscriber call returns successfully. + void failed(QString error); ///< Emitted when the GetSubscriber call fails or provider not on D-Bus at all. + void subscribeFinished(QString key); ///< Emitted when Subscribe call succeeds on D-Bus. + void subscribeFailed(QString failedKey, QString error); ///< Emitted when Subscribe call fails on D-Bus. + void valueChanged(QString key, QVariant value); ///< Emitted when ValueChanged signal comes on D-Bus private slots: void onDBusValuesChanged(QMap<QString, QVariant> values); @@ -61,11 +61,11 @@ private slots: private: DBusNameListener *providerListener; ///< Listens to provider's (dis)appearance over DBus - SubscriberInterface *subscriberInterface; ///< The DBus interface for the Subscriber object - ManagerInterface *managerInterface; ///< The DBus interface for the Manager object + SubscriberInterface *subscriberInterface; ///< The D-Bus interface for the Subscriber object + ManagerInterface *managerInterface; ///< The D-Bus interface for the Manager object QDBusConnection *connection; ///< The connection to DBus - QString busName; ///< The bus name of the DBus provider connected to + QString busName; ///< The D-Bus service name of the ContextKit provider connected to }; diff --git a/libcontextsubscriber/src/handlesignalrouter.cpp b/libcontextsubscriber/src/handlesignalrouter.cpp index e5c5f624..25ec624b 100644 --- a/libcontextsubscriber/src/handlesignalrouter.cpp +++ b/libcontextsubscriber/src/handlesignalrouter.cpp @@ -19,20 +19,22 @@ * */ -/*! \class HandleSignalRouter +#include "handlesignalrouter.h" +#include "propertyhandle.h" + +namespace ContextSubscriber { - \brief Routes the <tt>valueChanged()</tt> signal to the correct \c +/*! + \class HandleSignalRouter + + \brief Routes the <tt>valueChanged()</tt> and the + <tt>subscribeFinished()</tt> signals to the correct \c PropertyHandle object. This is an optimization, so we don't have to connect all of the - value changes from the same provider to all of the - <tt>PropertyHandle</tt>s of that provider. + providers to all of the <tt>PropertyHandle</tt>s of that provider. */ -#include "handlesignalrouter.h" -#include "propertyhandle.h" - -namespace ContextSubscriber { HandleSignalRouter HandleSignalRouter::myInstance; @@ -51,4 +53,10 @@ void HandleSignalRouter::onValueChanged(QString key, QVariant value) handle->setValue(value); } +void HandleSignalRouter::onSubscribeFinished(QString key) +{ + PropertyHandle* handle = PropertyHandle::instance(key); + handle->setSubscribeFinished(); +} + } // end namespace diff --git a/libcontextsubscriber/src/handlesignalrouter.h b/libcontextsubscriber/src/handlesignalrouter.h index 42f5187b..11d742cd 100644 --- a/libcontextsubscriber/src/handlesignalrouter.h +++ b/libcontextsubscriber/src/handlesignalrouter.h @@ -36,6 +36,7 @@ public: public slots: void onValueChanged(QString key, QVariant value); + void onSubscribeFinished(QString key); private: HandleSignalRouter(); diff --git a/libcontextsubscriber/src/propertyhandle.cpp b/libcontextsubscriber/src/propertyhandle.cpp index cfeb55fe..cdd08a41 100644 --- a/libcontextsubscriber/src/propertyhandle.cpp +++ b/libcontextsubscriber/src/propertyhandle.cpp @@ -158,15 +158,6 @@ void PropertyHandle::updateProvider() } } - if (myProvider) { - disconnect(dynamic_cast<QObject*>(myProvider), SIGNAL(subscribeFinished(QSet<QString>)), - this, SLOT(onSubscribeFinished(QSet<QString>))); - } - if (newProvider) { - sconnect(dynamic_cast<QObject*>(newProvider), SIGNAL(subscribeFinished(QSet<QString>)), - this, SLOT(onSubscribeFinished(QSet<QString>))); - } - if (newProvider != myProvider && subscribeCount > 0) { // The provider has changed and ContextProperty classes are subscribed to this handle. // Unsubscribe from the old provider @@ -204,13 +195,10 @@ void PropertyHandle::unsubscribe() } } -/// Sets \c subscribePending to false if this property is contained in -/// the \c keys set. -void PropertyHandle::onSubscribeFinished(QSet<QString> keys) +/// Sets \c subscribePending to false. +void PropertyHandle::setSubscribeFinished() { - if (keys.contains(myKey)) { - subscribePending = false; - } + subscribePending = false; } QString PropertyHandle::key() const diff --git a/libcontextsubscriber/src/propertyhandle.h b/libcontextsubscriber/src/propertyhandle.h index 09e336c5..95ff6387 100644 --- a/libcontextsubscriber/src/propertyhandle.h +++ b/libcontextsubscriber/src/propertyhandle.h @@ -52,6 +52,7 @@ public: static PropertyHandle* instance(const QString& key); void setValue(QVariant newValue); + void setSubscribeFinished(); static void ignoreCommander(); static void setTypeCheck(bool typeCheck); @@ -59,7 +60,6 @@ signals: void valueChanged(); private slots: - void onSubscribeFinished(QSet<QString> keys); void updateProvider(); private: diff --git a/libcontextsubscriber/src/propertyprovider.cpp b/libcontextsubscriber/src/propertyprovider.cpp index b6e4de61..2034340a 100644 --- a/libcontextsubscriber/src/propertyprovider.cpp +++ b/libcontextsubscriber/src/propertyprovider.cpp @@ -119,20 +119,23 @@ void Provider::constructPlugin() } // Connect the signal of changing values to the class who handles it -// HandleSignalRouter* handleSignalRouter = HandleSignalRouter::instance(); + HandleSignalRouter* handleSignalRouter = HandleSignalRouter::instance(); sconnect(plugin, SIGNAL(valueChanged(QString, QVariant)), this, SLOT(onPluginValueChanged(QString, QVariant))); + sconnect(this, SIGNAL(valueChanged(QString, QVariant)), + handleSignalRouter, SLOT(onValueChanged(QString, QVariant))); sconnect(plugin, SIGNAL(ready()), this, SLOT(onPluginReady())); sconnect(plugin, SIGNAL(failed(QString)), this, SLOT(onPluginFailed(QString))); - // FIXME: signal these things through the handlesignalrouter sconnect(plugin, SIGNAL(subscribeFinished(QString)), this, SLOT(onPluginSubscribeFinished(QString))); sconnect(plugin, SIGNAL(subscribeFailed(QString, QString)), this, SLOT(onPluginSubscribeFailed(QString, QString))); + sconnect(this, SIGNAL(subscribeFinished(QString)), + handleSignalRouter, SLOT(onSubscribeFinished(QString))); } /// Updates \c pluginState to \c READY and requests subscription for @@ -172,8 +175,7 @@ void Provider::signalSubscribeFinished(QString key) { QMutexLocker lock(&subscribeLock); if (subscribedKeys.contains(key)) - // FIXME: get rid of QSet, go through signalhandlerouter - emit subscribeFinished(QSet<QString>() << key); + emit subscribeFinished(key); } /// Forwards the call to \c signalSubscribeFinished. @@ -264,7 +266,9 @@ void Provider::handleSubscribes() case FAILED: // it failed for good. contextDebug() << "Plugin init has failed"; - if (toSubscribe.size() > 0) emit subscribeFinished(toSubscribe); + if (toSubscribe.size() > 0) + foreach (QString key, toSubscribe) + emit subscribeFinished(key); toSubscribe.clear(); toUnsubscribe.clear(); break; @@ -282,7 +286,7 @@ void Provider::onPluginValueChanged(QString key, QVariant newValue) { QMutexLocker lock(&subscribeLock); if (subscribedKeys.contains(key)) - HandleSignalRouter::instance()->onValueChanged(key, newValue); + emit valueChanged(key, newValue); else contextWarning() << "Received a property not subscribed to:" << key; } diff --git a/libcontextsubscriber/src/propertyprovider.h b/libcontextsubscriber/src/propertyprovider.h index 6fa6feb9..a8767b3b 100644 --- a/libcontextsubscriber/src/propertyprovider.h +++ b/libcontextsubscriber/src/propertyprovider.h @@ -53,9 +53,6 @@ signals: void valueChanged(QString key, QVariant value); }; -/// Prototype for IProviderPlugin factory functions. -typedef IProviderPlugin* (*ProviderPluginFactoryPrototype)(const QString &constructionString); - class Provider : public QueuedInvoker { Q_OBJECT @@ -66,7 +63,8 @@ public: void unsubscribe(const QString &key); signals: - void subscribeFinished(QSet<QString> keys); + void subscribeFinished(QString key); + void valueChanged(QString key, QVariant value); private slots: void onPluginReady(); |