00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef CONTEXTKITPLUGIN_H
00023 #define CONTEXTKITPLUGIN_H
00024
00025 #include "dbusnamelistener.h"
00026 #include "subscriberinterface.h"
00027 #include "provider.h"
00028 #include "iproviderplugin.h"
00029 #include "asyncdbusinterface.h"
00030 #include "timedvalue.h"
00031 #include <QString>
00032 #include <QDBusConnection>
00033 #include <QDBusPendingCallWatcher>
00034 #include <QDBusObjectPath>
00035 #include <QSet>
00036 #include <QVariant>
00037 #include <QMap>
00038 #include <QHash>
00039
00040 extern "C" {
00041 ContextSubscriber::IProviderPlugin* contextKitPluginFactory(QString constructionString);
00042 }
00043
00044 namespace ContextSubscriber {
00045 class PendingSubscribeWatcher : public QDBusPendingCallWatcher
00046 {
00047 Q_OBJECT;
00048
00049 public:
00050 PendingSubscribeWatcher(const QDBusPendingCall &call,
00051 const QString &key,
00052 QObject * parent = 0);
00053 private Q_SLOTS:
00054 void onFinished();
00055 void processDeferredDeleteEvents();
00056
00057 Q_SIGNALS:
00058 void subscribeFailed(QString, QString);
00059 void valueChanged(QString, TimedValue);
00060 void subscribeFinished(QString);
00061 void providerNotPresent();
00062
00063 private:
00064 QString key;
00065 };
00066
00067 class ContextKitPlugin : public IProviderPlugin
00068 {
00069 Q_OBJECT
00070
00071 public:
00072 ContextKitPlugin(const QDBusConnection bus, const QString& busName);
00073 void subscribe(QSet<QString> keys);
00074 void unsubscribe(QSet<QString> keys);
00075 void setDefaultNewProtocol(bool s);
00076 void blockUntilReady();
00077 void blockUntilSubscribed(const QString& key);
00078
00079 Q_SIGNALS:
00080 #ifdef DOXYGEN_ONLY
00081 void ready();
00082 void failed(QString error);
00083 void subscribeFinished(QString key);
00084 void subscribeFailed(QString failedKey, QString error);
00085 void valueChanged(QString key, QVariant value);
00086 #endif
00087
00088 private Q_SLOTS:
00089 void onNewValueChanged(QList<QVariant> value,
00090 quint64 timestamp,
00091 QDBusMessage message);
00092 void onDBusValuesChanged(QMap<QString, QVariant> values);
00093 void onDBusGetSubscriberFinished(QDBusObjectPath objectPath);
00094 void onDBusGetSubscriberFailed(QDBusError err);
00095 void onDBusSubscribeFinished(QList<QString> keys);
00096 void onDBusSubscribeFailed(QList<QString> keys, QString error);
00097 void onProviderAppeared();
00098 void onProviderDisappeared();
00099 void newSubscribe(const QString& key);
00100 void removePendingWatcher(const QString& key);
00101
00102 private:
00103 static QString keyToPath(QString key);
00104
00105 void reset();
00106 void useNewProtocol();
00107
00108 QMap<QString, QVariant>& mergeNullsWithMap(QMap<QString, QVariant> &map, QStringList nulls) const;
00109
00110 DBusNameListener *providerListener;
00111 SubscriberInterface *subscriberInterface;
00112 QDBusAbstractInterface *managerInterface;
00113
00114 QDBusConnection *connection;
00115 QString busName;
00116
00117 bool newProtocol;
00118 bool defaultNewProtocol;
00119
00120 QHash<QString, QString> objectPathToKey;
00121
00122 QHash<QString, PendingSubscribeWatcher*> pendingWatchers;
00123 QSet<QString> pendingKeys;
00124 };
00125
00126 QVariant demarshallValue(const QVariant &v);
00127
00128 }
00129
00130 #endif