Do not subclass OfonoModemInterface from OfonoInterface
[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     //! Changes the interface path
98     /*!
99      * This method changes the D-Bus path to the interface.
100      * Properties are updated immediately if property setting is set to
101      * GetAllOnStartup or reset otherwise.
102      */
103     void setPath(const QString &path);
104     
105     //! Sets the last error explicitly
106     void setError(const QString &errorName, const QString &errorMessage);
107
108 signals:
109     //! Issued when a property has changed
110     /*!
111      * \param name name of the property
112      * \param property value of the property
113      */
114     void propertyChanged(const QString &name, const QVariant &property);
115     
116     //! Issued when requesting a property has completed
117     /*!
118      * \param success true if requesting a property was successful, false if there was an error
119      * \param name name of the property
120      * \param property value of the property
121      */
122     void requestPropertyComplete(bool success, const QString &name, const QVariant &property);
123     
124     //! Issued when setting a property has failed
125     /*!
126      * \param name name of the property
127      */
128     void setPropertyFailed(const QString &name);
129
130 private slots:
131     void onPropertyChanged(QString property, QDBusVariant value);
132     void getPropertiesAsyncResp(QVariantMap properties);
133     void getPropertiesAsyncErr(const QDBusError&);
134     void setPropertyResp();
135     void setPropertyErr(const QDBusError& error);
136 protected slots:
137 private:
138     QVariantMap getAllPropertiesSync();
139     
140 protected:
141    QString m_errorName;
142    QString m_errorMessage;
143     
144 private:
145    QString m_path;
146    QString m_ifname;
147    QVariantMap m_properties;
148    QString m_pendingProperty;
149    OfonoGetPropertySetting m_getpropsetting;
150 };
151
152 #endif