1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 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 plugins of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
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 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at qt-info@nokia.com.
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QICDENGINE_H
|
---|
43 | #define QICDENGINE_H
|
---|
44 |
|
---|
45 | #include <QtNetwork/private/qbearerengine_p.h>
|
---|
46 |
|
---|
47 | #include <QtCore/qtimer.h>
|
---|
48 |
|
---|
49 | #include "maemo_icd.h"
|
---|
50 |
|
---|
51 | QT_BEGIN_NAMESPACE
|
---|
52 |
|
---|
53 | class QNetworkConfigurationPrivate;
|
---|
54 | class IapMonitor;
|
---|
55 | class QDBusInterface;
|
---|
56 | class QDBusServiceWatcher;
|
---|
57 |
|
---|
58 | inline QNetworkConfiguration::BearerType bearerTypeFromIapType(const QString &iapType)
|
---|
59 | {
|
---|
60 | if (iapType == QLatin1String("WLAN_INFRA") ||
|
---|
61 | iapType == QLatin1String("WLAN_ADHOC")) {
|
---|
62 | return QNetworkConfiguration::BearerWLAN;
|
---|
63 | } else if (iapType == QLatin1String("GPRS")) {
|
---|
64 | return QNetworkConfiguration::BearerHSPA;
|
---|
65 | } else {
|
---|
66 | return QNetworkConfiguration::BearerUnknown;
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | class IcdNetworkConfigurationPrivate : public QNetworkConfigurationPrivate
|
---|
71 | {
|
---|
72 | public:
|
---|
73 | IcdNetworkConfigurationPrivate();
|
---|
74 | ~IcdNetworkConfigurationPrivate();
|
---|
75 |
|
---|
76 | virtual QString bearerTypeName() const;
|
---|
77 |
|
---|
78 | // In Maemo the id field (defined in QNetworkConfigurationPrivate)
|
---|
79 | // is the IAP id (which typically is UUID)
|
---|
80 | QByteArray network_id; // typically WLAN ssid or similar
|
---|
81 | QString iap_type; // is this one WLAN or GPRS
|
---|
82 |
|
---|
83 | QString service_type;
|
---|
84 | QString service_id;
|
---|
85 | quint32 service_attrs;
|
---|
86 |
|
---|
87 | // Network attributes for this IAP, this is the value returned by icd and
|
---|
88 | // passed to it when connecting.
|
---|
89 | quint32 network_attrs;
|
---|
90 | };
|
---|
91 |
|
---|
92 | inline IcdNetworkConfigurationPrivate *toIcdConfig(QNetworkConfigurationPrivatePointer ptr)
|
---|
93 | {
|
---|
94 | return static_cast<IcdNetworkConfigurationPrivate *>(ptr.data());
|
---|
95 | }
|
---|
96 |
|
---|
97 | class QIcdEngine : public QBearerEngine
|
---|
98 | {
|
---|
99 | Q_OBJECT
|
---|
100 |
|
---|
101 | public:
|
---|
102 | QIcdEngine(QObject *parent = 0);
|
---|
103 | ~QIcdEngine();
|
---|
104 |
|
---|
105 | bool hasIdentifier(const QString &id);
|
---|
106 |
|
---|
107 | Q_INVOKABLE void initialize();
|
---|
108 | Q_INVOKABLE void requestUpdate();
|
---|
109 |
|
---|
110 | QNetworkConfigurationManager::Capabilities capabilities() const;
|
---|
111 |
|
---|
112 | QNetworkSessionPrivate *createSessionBackend();
|
---|
113 |
|
---|
114 | QNetworkConfigurationPrivatePointer defaultConfiguration();
|
---|
115 |
|
---|
116 | void deleteConfiguration(const QString &iap_id);
|
---|
117 |
|
---|
118 | inline QNetworkConfigurationPrivatePointer configuration(const QString &id)
|
---|
119 | {
|
---|
120 | QMutexLocker locker(&mutex);
|
---|
121 |
|
---|
122 | return accessPointConfigurations.value(id);
|
---|
123 | }
|
---|
124 |
|
---|
125 | inline void addSessionConfiguration(QNetworkConfigurationPrivatePointer ptr)
|
---|
126 | {
|
---|
127 | QMutexLocker locker(&mutex);
|
---|
128 |
|
---|
129 | accessPointConfigurations.insert(ptr->id, ptr);
|
---|
130 |
|
---|
131 | locker.unlock();
|
---|
132 | emit configurationAdded(ptr);
|
---|
133 | }
|
---|
134 |
|
---|
135 | inline void changedSessionConfiguration(QNetworkConfigurationPrivatePointer ptr)
|
---|
136 | {
|
---|
137 | emit configurationChanged(ptr);
|
---|
138 | }
|
---|
139 |
|
---|
140 | void cleanup();
|
---|
141 |
|
---|
142 | void addConfiguration(QString &iap_id);
|
---|
143 |
|
---|
144 | Q_SIGNALS:
|
---|
145 | void iapStateChanged(const QString& iapid, uint icd_connection_state);
|
---|
146 |
|
---|
147 | private Q_SLOTS:
|
---|
148 | void finishAsyncConfigurationUpdate();
|
---|
149 | void asyncUpdateConfigurationsSlot(QDBusMessage msg);
|
---|
150 | void connectionStateSignalsSlot(QDBusMessage msg);
|
---|
151 | void icdServiceOwnerChanged(const QString &serviceName, const QString &oldOwner,
|
---|
152 | const QString &newOwner);
|
---|
153 |
|
---|
154 | private:
|
---|
155 | void startListeningStateSignalsForAllConnections();
|
---|
156 | void doRequestUpdate(QList<Maemo::IcdScanResult> scanned = QList<Maemo::IcdScanResult>());
|
---|
157 | void cancelAsyncConfigurationUpdate();
|
---|
158 | void getIcdInitialState();
|
---|
159 | bool ensureDBusConnection();
|
---|
160 |
|
---|
161 | private:
|
---|
162 | IapMonitor *iapMonitor;
|
---|
163 | QDBusInterface *m_dbusInterface;
|
---|
164 | QTimer m_scanTimer;
|
---|
165 | QString m_onlineIapId;
|
---|
166 | QStringList m_typesToBeScanned;
|
---|
167 | QList<Maemo::IcdScanResult> m_scanResult;
|
---|
168 |
|
---|
169 | QDBusServiceWatcher *m_icdServiceWatcher;
|
---|
170 |
|
---|
171 | bool firstUpdate;
|
---|
172 | bool m_scanGoingOn;
|
---|
173 | };
|
---|
174 |
|
---|
175 | QT_END_NAMESPACE
|
---|
176 |
|
---|
177 | #endif // QICDENGINE_H
|
---|