ContextSubscriber::Provider Class Reference

Connects to a group of properties via the help of a plugin. More...

#include <provider.h>

Inheritance diagram for ContextSubscriber::Provider:

ContextSubscriber::QueuedInvoker

List of all members.

Signals

void subscribeFinished (Provider *provider, QString key)
void valueChanged (QString key)

Public Member Functions

bool subscribe (const QString &key)
 Schedules a property to be subscribed to.
void unsubscribe (const QString &key)
 Schedules a property to be unsubscribed from when the main loop is entered the next time.
TimedValue get (const QString &key) const
void clearValues ()
 Clears the cached values for this provider.
void blockUntilSubscribed (const QString &key)

Static Public Member Functions

static Providerinstance (const ContextProviderInfo &providerInfo)
 Returns a singleton for the named plugin with the constructionString.

Private Types

enum  PluginState { INITIALIZING, READY, FAILED }

Private Slots

void onPluginReady ()
 Updates pluginState to READY and requests subscription for the keys that should be subscribed.
void onPluginFailed (QString error)
 Updates pluginState to FAILED and signals subscribeFinished for keys we are trying to subscribe to.
void onPluginSubscribeFinished (QString key)
 Deprecated.
void onPluginSubscribeFinished (QString key, TimedValue value)
 Forwards the call to signalSubscribeFinished.
void onPluginSubscribeFailed (QString failedKey, QString error)
 Forwards the call to signalSubscribeFinished, after logging a warning.
void onPluginValueChanged (QString key, QVariant newValue)
 Deprecated: plugins should use the variant taking a TimedValue.
void onPluginValueChanged (QString key, TimedValue newValue)
 Forwards the newValue for key received from the plugin to the upper layers via HandleSignalRouter.

Private Member Functions

 Provider (const ContextProviderInfo &providerInfo)
 Stores the passed plugin name and construction paramater, then moves into the main thread and queues a constructPlugin call.
Q_INVOKABLE void handleSubscribes ()
 Executed when the main loop is entered and we have previously scheduled subscriptions / unsubscriptions.
Q_INVOKABLE void constructPlugin ()
 Decides which plugin to instantiate based on the plugin passed to the constructor.
void signalSubscribeFinished (QString key)
 The plugin has finished subscribing to a key, signals this fact to the upper layer.

Private Attributes

IProviderPluginplugin
 Plugin instance communicating with the concrete provider.
PluginState pluginState
ContextProviderInfo providerInfo
 Parameters used to initialize the plugin.
QMutex subscribeLock
QSet< QString > toSubscribe
 Keys pending for subscription.
QSet< QString > toUnsubscribe
 Keys pending for unsubscription.
QSet< QString > subscribedKeys
 The keys that should be currently subscribed to.
QMap< QString, TimedValuevalues
 A cache of values already received from the plugin.
bool pluginConstructed


Detailed Description

Connects to a group of properties via the help of a plugin.

Each instance of this class keeps a plugin dependent communication channel (DBus, shared memory, etc.) open and handles subscriptions, value changes of the properties belonging to the provider on the other end of the channel.

This class is thread safe, the instance, subscribe and unsubscribe methods can be called from any threads. However this class also guarantees that the signal subscribeFinished and valueChanged will be always emitted from inside the main thread's main loop.


Member Enumeration Documentation

Enumerator:
INITIALIZING 
READY 
FAILED 


Constructor & Destructor Documentation

ContextSubscriber::Provider::Provider ( const ContextProviderInfo providerInfo  )  [private]

Stores the passed plugin name and construction paramater, then moves into the main thread and queues a constructPlugin call.


Member Function Documentation

Provider * ContextSubscriber::Provider::instance ( const ContextProviderInfo providerInfo  )  [static]

Returns a singleton for the named plugin with the constructionString.

bool ContextSubscriber::Provider::subscribe ( const QString &  key  ) 

Schedules a property to be subscribed to.

Returns true if and only if the main loop has to run for the subscription to be finalized.

void ContextSubscriber::Provider::unsubscribe ( const QString &  key  ) 

Schedules a property to be unsubscribed from when the main loop is entered the next time.

TimedValue ContextSubscriber::Provider::get ( const QString &  key  )  const

void ContextSubscriber::Provider::clearValues (  ) 

Clears the cached values for this provider.

This is used when the provider instance is (re)connected to the commander.

void ContextSubscriber::Provider::blockUntilSubscribed ( const QString &  key  ) 

void ContextSubscriber::Provider::subscribeFinished ( Provider provider,
QString  key 
) [signal]

void ContextSubscriber::Provider::valueChanged ( QString  key  )  [signal]

void ContextSubscriber::Provider::onPluginReady (  )  [private, slot]

Updates pluginState to READY and requests subscription for the keys that should be subscribed.

void ContextSubscriber::Provider::onPluginFailed ( QString  error  )  [private, slot]

Updates pluginState to FAILED and signals subscribeFinished for keys we are trying to subscribe to.

void ContextSubscriber::Provider::onPluginSubscribeFinished ( QString  key  )  [private, slot]

Deprecated.

void ContextSubscriber::Provider::onPluginSubscribeFinished ( QString  key,
TimedValue  value 
) [private, slot]

Forwards the call to signalSubscribeFinished.

void ContextSubscriber::Provider::onPluginSubscribeFailed ( QString  key,
QString  error 
) [private, slot]

Forwards the call to signalSubscribeFinished, after logging a warning.

void ContextSubscriber::Provider::onPluginValueChanged ( QString  key,
QVariant  newValue 
) [private, slot]

Deprecated: plugins should use the variant taking a TimedValue.

Forwards the newValue for key received from the plugin to the upper layers via HandleSignalRouter.

void ContextSubscriber::Provider::onPluginValueChanged ( QString  key,
TimedValue  newValue 
) [private, slot]

Forwards the newValue for key received from the plugin to the upper layers via HandleSignalRouter.

void ContextSubscriber::Provider::handleSubscribes (  )  [private]

Executed when the main loop is entered and we have previously scheduled subscriptions / unsubscriptions.

void ContextSubscriber::Provider::constructPlugin (  )  [private]

Decides which plugin to instantiate based on the plugin passed to the constructor.

Always called in the main loop after the constructor is finished. Each plugin library implements a function which can create new instances of that plugin (TODO: come up with the name of the function).

void ContextSubscriber::Provider::signalSubscribeFinished ( QString  key  )  [private]

The plugin has finished subscribing to a key, signals this fact to the upper layer.

The final API for this is the waitForSubscription() method in ContextProperty.


Member Data Documentation

Plugin instance communicating with the concrete provider.

Parameters used to initialize the plugin.

Keys pending for subscription.

Keys pending for unsubscription.

The keys that should be currently subscribed to.

A cache of values already received from the plugin.


The documentation for this class was generated from the following files:

Generated on Thu Feb 21 18:31:19 2013 for libcontextsubscriber by  doxygen 1.5.6