src/publishsubscribe/gconflayer_linux_p.h
changeset 0 876b1a06bc25
equal deleted inserted replaced
-1:000000000000 0:876b1a06bc25
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef GCONFLAYER_H
       
    43 #define GCONFLAYER_H
       
    44 
       
    45 #include "qvaluespace_p.h"
       
    46 #include "qvaluespacepublisher.h"
       
    47 
       
    48 #include <QSet>
       
    49 #include "gconfitem_p.h"
       
    50 #include <QMutex>
       
    51 
       
    52 QTM_BEGIN_NAMESPACE
       
    53 
       
    54 class GConfLayer : public QAbstractValueSpaceLayer
       
    55 {
       
    56     Q_OBJECT
       
    57 
       
    58 public:
       
    59     GConfLayer();
       
    60     virtual ~GConfLayer();
       
    61 
       
    62 protected:
       
    63     /*virtual*/ QString name();
       
    64 
       
    65     /*virtual*/ bool startup(Type type);
       
    66 
       
    67     /*virtual*/ QUuid id();
       
    68     /*virtual*/ unsigned int order();
       
    69 
       
    70     /*virtual*/ Handle item(Handle parent, const QString &subPath);
       
    71     /*virtual*/ void removeHandle(Handle handle);
       
    72     /*virtual*/ void setProperty(Handle handle, Properties properties);
       
    73 
       
    74     /*virtual*/ bool value(Handle handle, QVariant *data);
       
    75     /*virtual*/ bool value(Handle handle, const QString &subPath, QVariant *data);
       
    76     /*virtual*/ QSet<QString> children(Handle handle);
       
    77 
       
    78     /*virtual*/ QValueSpace::LayerOptions layerOptions() const;
       
    79 
       
    80     /* QValueSpaceSubscriber functions */
       
    81     /*virtual*/ bool supportsInterestNotification() const;
       
    82     /*virtual*/ bool notifyInterest(Handle handle, bool interested);
       
    83 
       
    84     /* QValueSpacePublisher functions */
       
    85     /*virtual*/ bool setValue(QValueSpacePublisher *creator, Handle handle,
       
    86                               const QString &subPath, const QVariant &value);
       
    87     /*virtual*/ bool removeValue(QValueSpacePublisher *creator, Handle handle,
       
    88                                  const QString &subPath);
       
    89     /*virtual*/ bool removeSubTree(QValueSpacePublisher *creator, Handle handle);
       
    90     /*virtual*/ void addWatch(QValueSpacePublisher *creator, Handle handle);
       
    91     /*virtual*/ void removeWatches(QValueSpacePublisher *creator, Handle parent);
       
    92     /*virtual*/ void sync();
       
    93 
       
    94 public:
       
    95     static GConfLayer *instance();
       
    96 
       
    97 private slots:
       
    98     void notifyChanged(const QString &key, const QVariant &value);
       
    99 
       
   100 private:
       
   101     struct GConfHandle {
       
   102         GConfHandle(const QString &p)
       
   103         :   path(p), refCount(1)
       
   104         {
       
   105         }
       
   106 
       
   107         QString path;
       
   108         unsigned int refCount;
       
   109     };
       
   110 
       
   111     QHash<QString, GConfHandle *> m_handles;
       
   112 
       
   113     GConfHandle *gConfHandle(Handle handle)
       
   114     {
       
   115         if (handle == InvalidHandle)
       
   116             return 0;
       
   117 
       
   118         GConfHandle *h = reinterpret_cast<GConfHandle *>(handle);
       
   119         if (m_handles.values().contains(h))
       
   120             return h;
       
   121 
       
   122         return 0;
       
   123     }
       
   124 
       
   125     //private methods not locking a mutex
       
   126     bool getValue(Handle handle, const QString &subPath, QVariant *data);
       
   127     Handle getItem(Handle parent, const QString &subPath);
       
   128     void doRemoveHandle(Handle handle);
       
   129 
       
   130 private:    //data
       
   131     QSet<GConfHandle *> m_monitoringHandles;
       
   132     QMap<QString, GConfItem *> m_monitoringItems;
       
   133     QMutex m_mutex;
       
   134 };
       
   135 
       
   136 QTM_END_NAMESPACE
       
   137 
       
   138 #endif //GCONFLAYER_H