00001 /* 00002 * Copyright (C) 2008, 2009 Nokia Corporation. 00003 * 00004 * Contact: Marius Vollmer <marius.vollmer@nokia.com> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public License 00008 * version 2.1 as published by the Free Software Foundation. 00009 * 00010 * This library is distributed in the hope that it will be useful, but 00011 * WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 00018 * 02110-1301 USA 00019 * 00020 */ 00021 00022 #ifndef PROVIDER_H 00023 #define PROVIDER_H 00024 00025 #include "queuedinvoker.h" 00026 #include "contextproviderinfo.h" 00027 #include "timedvalue.h" 00028 00029 #include <QObject> 00030 #include <QDBusConnection> 00031 #include <QSet> 00032 #include <QMutex> 00033 00034 class ContextPropertyInfo; 00035 00036 namespace ContextSubscriber { 00037 00038 class PropertyHandle; 00039 class SubscriberInterface; 00040 class DBusNameListener; 00041 class ManagerInterface; 00042 class IProviderPlugin; 00043 00044 class Provider : public QueuedInvoker 00045 { 00046 Q_OBJECT 00047 00048 public: 00049 static Provider* instance(const ContextProviderInfo& providerInfo); 00050 bool subscribe(const QString &key); 00051 void unsubscribe(const QString &key); 00052 TimedValue get(const QString &key) const; 00053 void clearValues(); 00054 00055 void blockUntilSubscribed(const QString& key); 00056 00057 Q_SIGNALS: 00058 void subscribeFinished(Provider *provider, QString key); 00059 void valueChanged(QString key); 00060 00061 private Q_SLOTS: 00062 void onPluginReady(); 00063 void onPluginFailed(QString error); 00064 void onPluginSubscribeFinished(QString key); 00065 void onPluginSubscribeFinished(QString key, TimedValue value); 00066 void onPluginSubscribeFailed(QString failedKey, QString error); 00067 void onPluginValueChanged(QString key, QVariant newValue); 00068 void onPluginValueChanged(QString key, TimedValue newValue); 00069 00070 private: 00071 enum PluginState { INITIALIZING, READY, FAILED }; 00072 Provider(const ContextProviderInfo& providerInfo); 00073 Q_INVOKABLE void handleSubscribes(); 00074 Q_INVOKABLE void constructPlugin(); 00075 void signalSubscribeFinished(QString key); 00076 00077 IProviderPlugin* plugin; 00078 PluginState pluginState; 00079 ContextProviderInfo providerInfo; 00080 00081 QMutex subscribeLock; 00082 QSet<QString> toSubscribe; 00083 QSet<QString> toUnsubscribe; 00084 00085 // FIXME: rename this to something which contains the word intention in it 00086 QSet<QString> subscribedKeys; 00087 00088 QMap<QString, TimedValue> values; 00089 bool pluginConstructed; 00090 }; 00091 00092 } // end namespace 00093 00094 #endif