00001 /* 00002 * Copyright (C) 2008, 2009 Nokia Corporation. 00003 * 00004 * Contact: Marius Vollmer <marius.vollmer@nokia.com> 00005 * 00006 * This program 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 program 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 program; 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 PROPERTYHANDLE_H 00023 #define PROPERTYHANDLE_H 00024 00025 #include <QObject> 00026 #include <QString> 00027 #include <QVariant> 00028 #include <QSet> 00029 #include <QReadWriteLock> 00030 #include <QMutex> 00031 00032 class ContextPropertyInfo; 00033 class ContextProviderInfo; 00034 00035 namespace ContextSubscriber { 00036 00037 class Provider; 00038 class DBusNameListener; 00039 00040 class PropertyHandle : public QObject 00041 { 00042 Q_OBJECT 00043 00044 public: 00045 void subscribe(); 00046 void unsubscribe(); 00047 00048 QString key() const; 00049 QVariant value() const; 00050 bool isSubscribePending() const; 00051 const ContextPropertyInfo* info() const; 00052 00053 static PropertyHandle* instance(const QString& key); 00054 static const ContextProviderInfo commanderInfo; 00055 00056 void onValueChanged(); 00057 void setSubscribeFinished(Provider *provider); 00058 static void ignoreCommander(); 00059 static void setTypeCheck(bool typeCheck); 00060 00061 void blockUntilSubscribed(); 00062 00063 Q_SIGNALS: 00064 void valueChanged(); 00065 00066 private Q_SLOTS: 00067 void updateProvider(); 00068 00069 private: 00070 PropertyHandle(const QString& key); 00071 00072 QSet<Provider*> pendingSubscriptions; 00073 QList<Provider*> myProviders; 00074 ContextPropertyInfo *myInfo; 00075 unsigned int subscribeCount; 00076 QMutex subscribeCountLock; 00077 QString myKey; 00078 mutable QReadWriteLock valueLock; 00079 QVariant myValue; 00080 static DBusNameListener *commanderListener; 00081 static bool commandingEnabled; 00082 static bool typeCheckEnabled; 00083 }; 00084 00085 } // end namespace 00086 00087 #endif