Remove unnecessary includes
[profile/ivi/ofono-qt.git] / lib / ofonointerface.h
1 /*
2  * This file is part of ofono-qt
3  *
4  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
5  *
6  * Contact: Alexander Kanavin <alexander.kanavin@nokia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * version 2.1 as published by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  */
23
24 #ifndef OFONOINTERFACE_H
25 #define OFONOINTERFACE_H
26
27 #include <QtCore/QObject>
28 #include <QVariant>
29 #include <QDBusVariant>
30 #include <QDBusError>
31 #include "libofono-qt_global.h"
32
33 //! Basic oFono interface class
34 /*!
35  * This class implements basic access to properties of oFono interfaces.
36  * It should not be instantiated directly; instead you should instantiate
37  * interface-specific subclasses.
38  */
39 class OFONO_QT_EXPORT OfonoInterface : public QObject
40 {
41     Q_OBJECT
42 public:
43
44     //! How to handle getting the properties
45     enum GetPropertySetting {
46         GetAllOnStartup,        /*!< Get all properties synchronously on startup;
47                                  * they would be immediately available. */
48         GetAllOnFirstRequest    /*!< Do not get properties on startup;
49                                  * get them in an asynhronous way when the first
50                                  * property is requested. */
51     };
52
53     /*!
54      * \param path D-Bus path to the interface
55      * \param ifname D-Bus name of the interface
56      * \param setting specifies how the object should handle oFono properties of the interface
57      */
58     OfonoInterface(const QString &path, const QString &ifname, GetPropertySetting setting, QObject *parent=0);
59     ~OfonoInterface();
60
61     //! Get all properties
62     /*!
63      * Returns the full set of current properties. If the object was constructed with
64      * OfonoInterface::GetAllOnFirstRequest, and no properties have been explicitly queried yet
65      * via requestProperty(), then returns nothing.
66      */
67     QVariantMap properties() const;
68     
69     //! Request a property asynchronously.
70     /*! 
71      * Result is returned via requestPropertyComplete() signal.
72      */
73     void requestProperty(const QString &name);
74
75     //! Set a property asynchronously.
76     /*!
77      * Result is returned via propertyChanged() signal
78      * if setting is successful or via setPropertyFailed() signal if setting has failed.
79      */
80     void setProperty(const QString &name, const QVariant &property);
81     
82     //! Resets the property cache.
83     void resetProperties();
84     
85     //! Get the interface D-Bus path
86     QString path() const {return m_path;}
87     
88     //! Get the interface D-Bus name
89     QString ifname() const {return m_ifname;}
90
91     //! Get the D-Bus error name of the last operation.
92     /*!
93      * Returns the D-Bus error name of the last operation (setting a property
94      * or calling a method) if it has failed
95      */
96     QString errorName() const {return m_errorName;}
97
98     //! Get the D-Bus error message of the last operation.
99     /*!
100      * Returns the D-Bus error message of the last operation (setting a property
101      * or calling a method) if it has failed
102      */
103     QString errorMessage() const {return m_errorMessage;}
104
105 signals:
106     //! Issued when a property has changed
107     /*!
108      * \param name name of the property
109      * \param property value of the property
110      */
111     void propertyChanged(const QString &name, const QVariant &property);
112     
113     //! Issued when requesting a property has completed
114     /*!
115      * \param success true if requesting a property was successful, false if there was an error
116      * \param name name of the property
117      * \param property value of the property
118      */
119     void requestPropertyComplete(bool success, const QString &name, const QVariant &property);
120     
121     //! Issued when setting a property has failed
122     /*!
123      * \param name name of the property
124      */
125     void setPropertyFailed(const QString &name);
126
127 private slots:
128     void onPropertyChanged(QString property, QDBusVariant value);
129     void getPropertiesAsyncResp(QVariantMap properties);
130     void getPropertiesAsyncErr(const QDBusError&);
131     void setPropertyResp();
132     void setPropertyErr(const QDBusError& error);
133 protected slots:
134     void setPath(const QString &path);
135 private:
136     QVariantMap getAllPropertiesSync();
137     
138 protected:
139    QString m_errorName;
140    QString m_errorMessage;
141     
142 private:
143    QString m_path;
144    QString m_ifname;
145    QVariantMap m_properties;
146    QString m_pendingProperty;
147    GetPropertySetting m_getpropsetting;
148 };
149
150 #endif