650a9a803725dbb557996a4ddd0042f11cc1e8d1
[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 "ofonopropertysetting.h"
32 #include "libofono-qt_global.h"
33
34 //! Basic oFono interface class
35 /*!
36  * This class implements basic access to properties of oFono interfaces.
37  * It should not be instantiated directly; instead you should instantiate
38  * interface-specific subclasses.
39  */
40 class OFONO_QT_EXPORT OfonoInterface : public QObject
41 {
42     Q_OBJECT
43 public:
44
45     /*!
46      * \param path D-Bus path to the interface
47      * \param ifname D-Bus name of the interface
48      * \param setting specifies how the object should handle oFono properties of the interface
49      */
50     OfonoInterface(const QString &path, const QString &ifname, OfonoGetPropertySetting setting, QObject *parent=0);
51     ~OfonoInterface();
52
53     //! Get all properties
54     /*!
55      * Returns the full set of current properties. If the object was constructed with
56      * OfonoInterface::GetAllOnFirstRequest, and no properties have been explicitly queried yet
57      * via requestProperty(), then returns nothing.
58      */
59     QVariantMap properties() const;
60     
61     //! Request a property asynchronously.
62     /*! 
63      * Result is returned via requestPropertyComplete() signal.
64      */
65     void requestProperty(const QString &name);
66
67     //! Set a property asynchronously.
68     /*!
69      * Result is returned via propertyChanged() signal
70      * if setting is successful or via setPropertyFailed() signal if setting has failed.
71      */
72     void setProperty(const QString &name, const QVariant &property);
73     
74     //! Resets the property cache.
75     void resetProperties();
76     
77     //! Get the interface D-Bus path
78     QString path() const {return m_path;}
79     
80     //! Get the interface D-Bus name
81     QString ifname() const {return m_ifname;}
82
83     //! Get the D-Bus error name of the last operation.
84     /*!
85      * Returns the D-Bus error name of the last operation (setting a property
86      * or calling a method) if it has failed
87      */
88     QString errorName() const {return m_errorName;}
89
90     //! Get the D-Bus error message of the last operation.
91     /*!
92      * Returns the D-Bus error message of the last operation (setting a property
93      * or calling a method) if it has failed
94      */
95     QString errorMessage() const {return m_errorMessage;}
96
97 public slots:
98     //! Changes the interface path
99     /*!
100      * This method changes the D-Bus path to the interface.
101      * Properties are updated immediately if property setting is set to
102      * GetAllOnStartup or reset otherwise.
103      */
104     void setPath(const QString &path);
105     
106     //! Sets the last error explicitly
107     void setError(const QString &errorName, const QString &errorMessage);
108
109 signals:
110     //! Issued when a property has changed
111     /*!
112      * \param name name of the property
113      * \param property value of the property
114      */
115     void propertyChanged(const QString &name, const QVariant &property);
116     
117     //! Issued when requesting a property has completed
118     /*!
119      * \param success true if requesting a property was successful, false if there was an error
120      * \param name name of the property
121      * \param property value of the property
122      */
123     void requestPropertyComplete(bool success, const QString &name, const QVariant &property);
124     
125     //! Issued when setting a property has failed
126     /*!
127      * \param name name of the property
128      */
129     void setPropertyFailed(const QString &name);
130
131 private slots:
132     void onPropertyChanged(QString property, QDBusVariant value);
133     void getPropertiesAsyncResp(QVariantMap properties);
134     void getPropertiesAsyncErr(const QDBusError&);
135     void setPropertyResp();
136     void setPropertyErr(const QDBusError& error);
137 protected slots:
138 private:
139     QVariantMap getAllPropertiesSync();
140     
141 protected:
142    QString m_errorName;
143    QString m_errorMessage;
144     
145 private:
146    QString m_path;
147    QString m_ifname;
148    QVariantMap m_properties;
149    QString m_pendingProperty;
150    OfonoGetPropertySetting m_getpropsetting;
151 };
152
153 #endif