aboutsummaryrefslogtreecommitdiff
path: root/libcontextsubscriber/src/propertyhandle.h
blob: b74fcc7b152c4a87e0412251788d155edc80a204 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * Copyright (C) 2008, 2009 Nokia Corporation.
 *
 * Contact: Marius Vollmer <marius.vollmer@nokia.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

#ifndef PROPERTYHANDLE_H
#define PROPERTYHANDLE_H

#include <QObject>
#include <QString>
#include <QVariant>
#include <QSet>
#include <QReadWriteLock>
#include <QMutex>

class ContextPropertyInfo;
class ContextProviderInfo;

namespace ContextSubscriber {

class Provider;
class DBusNameListener;

class PropertyHandle : public QObject
{
    Q_OBJECT

public:
    void subscribe();
    void unsubscribe();

    QString key() const;
    QVariant value() const;
    bool isSubscribePending() const;
    const ContextPropertyInfo* info() const;

    static PropertyHandle* instance(const QString& key);
    static const ContextProviderInfo commanderInfo;

    void onValueChanged();
    void setSubscribeFinished(Provider *provider);
    static void ignoreCommander();
    static void setTypeCheck(bool typeCheck);

Q_SIGNALS:
    void valueChanged();

private Q_SLOTS:
    void updateProvider();

private:
    PropertyHandle(const QString& key);

        QSet<Provider*> pendingSubscriptions; ///< Providers pending subscription
    QList<Provider*> myProviders; ///< Providers of this property
    ContextPropertyInfo *myInfo; ///< Metadata for this property
    unsigned int subscribeCount; ///< Number of subscribed ContextProperty objects subscribed to this property
    QMutex subscribeCountLock;
    QString myKey; ///< Key of this property
    mutable QReadWriteLock valueLock;
    QVariant myValue; ///< Current value of this property
    static DBusNameListener *commanderListener; ///< Listener for ContextCommander's (dis)appearance
    static bool commandingEnabled; ///< Whether the properties can be directed to ContextCommander
    static bool typeCheckEnabled; ///< Whether we check the type of the value received from the provider
};

} // end namespace

#endif