Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/bearer/qnetworkconfigmanager_p.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
5 | ** | - | ||||||||||||||||||
6 | ** This file is part of the QtNetwork module of the Qt Toolkit. | - | ||||||||||||||||||
7 | ** | - | ||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||
16 | ** | - | ||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||
21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||
22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||
24 | ** | - | ||||||||||||||||||
25 | ** GNU General Public License Usage | - | ||||||||||||||||||
26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||
28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||
29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||
31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
35 | ** | - | ||||||||||||||||||
36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
37 | ** | - | ||||||||||||||||||
38 | ****************************************************************************/ | - | ||||||||||||||||||
39 | - | |||||||||||||||||||
40 | #include "qnetworkconfigmanager_p.h" | - | ||||||||||||||||||
41 | #include "qbearerplugin_p.h" | - | ||||||||||||||||||
42 | - | |||||||||||||||||||
43 | #include <QtCore/private/qfactoryloader_p.h> | - | ||||||||||||||||||
44 | - | |||||||||||||||||||
45 | #include <QtCore/qdebug.h> | - | ||||||||||||||||||
46 | #include <QtCore/qtimer.h> | - | ||||||||||||||||||
47 | #include <QtCore/qstringlist.h> | - | ||||||||||||||||||
48 | #include <QtCore/qthread.h> | - | ||||||||||||||||||
49 | #include <QtCore/private/qcoreapplication_p.h> | - | ||||||||||||||||||
50 | #include <QtCore/private/qthread_p.h> | - | ||||||||||||||||||
51 | - | |||||||||||||||||||
52 | #include <QtCore/qbytearray.h> | - | ||||||||||||||||||
53 | #include <QtCore/qglobal.h> | - | ||||||||||||||||||
54 | - | |||||||||||||||||||
55 | #include <utility> | - | ||||||||||||||||||
56 | - | |||||||||||||||||||
57 | - | |||||||||||||||||||
58 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
59 | - | |||||||||||||||||||
60 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
61 | - | |||||||||||||||||||
#ifndef QT_NO_LIBRARY | ||||||||||||||||||||
Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, | ||||||||||||||||||||
(QBearerEngineFactoryInterface_iid, QLatin1String("/bearer"))) | ||||||||||||||||||||
#endifQNetworkConfigurationManagerPrivate::QNetworkConfigurationManagerPrivate() | ||||||||||||||||||||
63 | : QObject(), pollTimer(0), mutex(QMutex::Recursive), forcedPolling(0), firstUpdate(true) | - | ||||||||||||||||||
64 | { | - | ||||||||||||||||||
65 | qRegisterMetaType<QNetworkConfiguration>(); | - | ||||||||||||||||||
66 | qRegisterMetaType<QNetworkConfigurationPrivatePointer>(); | - | ||||||||||||||||||
67 | } | - | ||||||||||||||||||
68 | - | |||||||||||||||||||
69 | void QNetworkConfigurationManagerPrivate::initialize() | - | ||||||||||||||||||
70 | { | - | ||||||||||||||||||
71 | //Two stage construction, because we only want to do this heavyweight work for the winner of the Q_GLOBAL_STATIC race. | - | ||||||||||||||||||
72 | bearerThread = new QDaemonThread(); | - | ||||||||||||||||||
73 | bearerThread->setObjectName(QStringLiteral("Qt bearer thread")); | - | ||||||||||||||||||
74 | - | |||||||||||||||||||
75 | bearerThread->moveToThread(QCoreApplicationPrivate::mainThread()); // because cleanup() is called in main thread context. | - | ||||||||||||||||||
76 | moveToThread(bearerThread); | - | ||||||||||||||||||
77 | bearerThread->start(); | - | ||||||||||||||||||
78 | updateConfigurations(); | - | ||||||||||||||||||
79 | } | - | ||||||||||||||||||
80 | - | |||||||||||||||||||
81 | QNetworkConfigurationManagerPrivate::~QNetworkConfigurationManagerPrivate() | - | ||||||||||||||||||
82 | { | - | ||||||||||||||||||
83 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||
84 | - | |||||||||||||||||||
85 | qDeleteAll(sessionEngines); | - | ||||||||||||||||||
86 | sessionEngines.clear(); | - | ||||||||||||||||||
87 | if (bearerThread) | - | ||||||||||||||||||
88 | bearerThread->quit(); | - | ||||||||||||||||||
89 | } | - | ||||||||||||||||||
90 | - | |||||||||||||||||||
91 | void QNetworkConfigurationManagerPrivate::cleanup() | - | ||||||||||||||||||
92 | { | - | ||||||||||||||||||
93 | QThread* thread = bearerThread; | - | ||||||||||||||||||
94 | deleteLater(); | - | ||||||||||||||||||
95 | if (thread->wait(5000)) | - | ||||||||||||||||||
96 | delete thread; | - | ||||||||||||||||||
97 | } | - | ||||||||||||||||||
98 | - | |||||||||||||||||||
99 | QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration() const | - | ||||||||||||||||||
100 | { | - | ||||||||||||||||||
101 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||
102 | - | |||||||||||||||||||
103 | foreachfor (QBearerEngine *engine ,: sessionEngines) { | - | ||||||||||||||||||
104 | QNetworkConfigurationPrivatePointer ptr = engine->defaultConfiguration(); | - | ||||||||||||||||||
105 | if (ptr) {
| 0-301 | ||||||||||||||||||
106 | QNetworkConfiguration config; | - | ||||||||||||||||||
107 | config.d = ptr; | - | ||||||||||||||||||
108 | return config; executed 301 times by 18 tests: return config; Executed by:
| 301 | ||||||||||||||||||
109 | } | - | ||||||||||||||||||
110 | } never executed: end of block | 0 | ||||||||||||||||||
111 | - | |||||||||||||||||||
112 | // Engines don't have a default configuration. | - | ||||||||||||||||||
113 | - | |||||||||||||||||||
114 | // Return first active snap | - | ||||||||||||||||||
115 | QNetworkConfigurationPrivatePointer defaultConfiguration; | - | ||||||||||||||||||
116 | - | |||||||||||||||||||
117 | foreachfor (QBearerEngine *engine ,: sessionEngines) { | - | ||||||||||||||||||
118 | QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator it; | - | ||||||||||||||||||
QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator end;QMutexLocker locker(&engine->mutex); | ||||||||||||||||||||
119 | - | |||||||||||||||||||
120 | for (it = engine->snapConfigurations.begin(), | - | ||||||||||||||||||
end =const auto &ptr : qAsConst(engine->snapConfigurations.end(); it != end; ++it))) { | ||||||||||||||||||||
121 | QNetworkConfigurationPrivatePointer ptr = it.value();QMutexLocker configLocker(&ptr->mutex); | - | ||||||||||||||||||
122 | - | |||||||||||||||||||
123 | if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) {
| 0 | ||||||||||||||||||
124 | QNetworkConfiguration config; | - | ||||||||||||||||||
125 | config.d = ptr; | - | ||||||||||||||||||
126 | return config; never executed: return config; | 0 | ||||||||||||||||||
127 | } else if (!defaultConfiguration) {
| 0 | ||||||||||||||||||
128 | if ((ptr->state & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered)
| 0 | ||||||||||||||||||
129 | defaultConfiguration = ptr; never executed: defaultConfiguration = ptr; | 0 | ||||||||||||||||||
130 | } never executed: end of block | 0 | ||||||||||||||||||
131 | } never executed: end of block | 0 | ||||||||||||||||||
132 | } never executed: end of block | 0 | ||||||||||||||||||
133 | - | |||||||||||||||||||
134 | // No Active SNAPs return first Discovered SNAP. | - | ||||||||||||||||||
135 | if (defaultConfiguration) {
| 0 | ||||||||||||||||||
136 | QNetworkConfiguration config; | - | ||||||||||||||||||
137 | config.d = defaultConfiguration; | - | ||||||||||||||||||
138 | return config; never executed: return config; | 0 | ||||||||||||||||||
139 | } | - | ||||||||||||||||||
140 | - | |||||||||||||||||||
141 | /* | - | ||||||||||||||||||
142 | No Active or Discovered SNAPs, find the perferred access point. | - | ||||||||||||||||||
143 | The following priority order is used: | - | ||||||||||||||||||
144 | - | |||||||||||||||||||
145 | 1. Active Ethernet | - | ||||||||||||||||||
146 | 2. Active WLAN | - | ||||||||||||||||||
147 | 3. Active Other | - | ||||||||||||||||||
148 | 4. Discovered Ethernet | - | ||||||||||||||||||
149 | 5. Discovered WLAN | - | ||||||||||||||||||
150 | 6. Discovered Other | - | ||||||||||||||||||
151 | */ | - | ||||||||||||||||||
152 | - | |||||||||||||||||||
153 | foreachfor (QBearerEngine *engine ,: sessionEngines) { | - | ||||||||||||||||||
154 | - | |||||||||||||||||||
155 | QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator it; | - | ||||||||||||||||||
QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator end;QMutexLocker locker(&engine->mutex); | ||||||||||||||||||||
156 | - | |||||||||||||||||||
157 | for (it = engine->accessPointConfigurations.begin(), | - | ||||||||||||||||||
end =const auto &ptr : qAsConst(engine->accessPointConfigurations.end(); it != end; ++it))) { | ||||||||||||||||||||
158 | - | |||||||||||||||||||
159 | QNetworkConfigurationPrivatePointer ptr = it.value();QMutexLocker configLocker(&ptr->mutex); | - | ||||||||||||||||||
160 | QNetworkConfiguration::BearerType bearerType = ptr->bearerType; | - | ||||||||||||||||||
161 | - | |||||||||||||||||||
162 | if ((ptr->state & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) {
| 0 | ||||||||||||||||||
163 | if (!defaultConfiguration) {
| 0 | ||||||||||||||||||
164 | defaultConfiguration = ptr; | - | ||||||||||||||||||
165 | } else { never executed: end of block | 0 | ||||||||||||||||||
166 | QMutexLocker defaultConfigLocker(&defaultConfiguration->mutex); | - | ||||||||||||||||||
167 | - | |||||||||||||||||||
168 | if (defaultConfiguration->state == ptr->state) {
| 0 | ||||||||||||||||||
169 | switch (defaultConfiguration->bearerType) { | - | ||||||||||||||||||
170 | case QNetworkConfiguration::BearerEthernet: never executed: case QNetworkConfiguration::BearerEthernet: | 0 | ||||||||||||||||||
171 | // do nothing | - | ||||||||||||||||||
172 | break; never executed: break; | 0 | ||||||||||||||||||
173 | case QNetworkConfiguration::BearerWLAN: never executed: case QNetworkConfiguration::BearerWLAN: | 0 | ||||||||||||||||||
174 | // Ethernet beats WLAN | - | ||||||||||||||||||
175 | defaultConfiguration = ptr; | - | ||||||||||||||||||
176 | break; never executed: break; | 0 | ||||||||||||||||||
177 | default: never executed: default: | 0 | ||||||||||||||||||
178 | // Ethernet and WLAN beats other | - | ||||||||||||||||||
179 | if (bearerType == QNetworkConfiguration::BearerEthernet ||
| 0 | ||||||||||||||||||
180 | bearerType == QNetworkConfiguration::BearerWLAN) {
| 0 | ||||||||||||||||||
181 | defaultConfiguration = ptr; | - | ||||||||||||||||||
182 | } never executed: end of block | 0 | ||||||||||||||||||
183 | } never executed: end of block | 0 | ||||||||||||||||||
184 | } else { | - | ||||||||||||||||||
185 | // active beats discovered | - | ||||||||||||||||||
186 | if ((defaultConfiguration->state & QNetworkConfiguration::Active) !=
| 0 | ||||||||||||||||||
187 | QNetworkConfiguration::Active) {
| 0 | ||||||||||||||||||
188 | defaultConfiguration = ptr; | - | ||||||||||||||||||
189 | } never executed: end of block | 0 | ||||||||||||||||||
190 | } never executed: end of block | 0 | ||||||||||||||||||
191 | } | - | ||||||||||||||||||
192 | } | - | ||||||||||||||||||
193 | } never executed: end of block | 0 | ||||||||||||||||||
194 | } never executed: end of block | 0 | ||||||||||||||||||
195 | - | |||||||||||||||||||
196 | // No Active InternetAccessPoint return first Discovered InternetAccessPoint. | - | ||||||||||||||||||
197 | if (defaultConfiguration) {
| 0 | ||||||||||||||||||
198 | QNetworkConfiguration config; | - | ||||||||||||||||||
199 | config.d = defaultConfiguration; | - | ||||||||||||||||||
200 | return config; never executed: return config; | 0 | ||||||||||||||||||
201 | } | - | ||||||||||||||||||
202 | - | |||||||||||||||||||
203 | return QNetworkConfiguration(); never executed: return QNetworkConfiguration(); | 0 | ||||||||||||||||||
204 | } | - | ||||||||||||||||||
205 | - | |||||||||||||||||||
206 | QList<QNetworkConfiguration> QNetworkConfigurationManagerPrivate::allConfigurations(QNetworkConfiguration::StateFlags filter) const | - | ||||||||||||||||||
207 | { | - | ||||||||||||||||||
208 | QList<QNetworkConfiguration> result; | - | ||||||||||||||||||
209 | - | |||||||||||||||||||
210 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||
211 | - | |||||||||||||||||||
212 | foreachfor (QBearerEngine *engine ,: sessionEngines) { | - | ||||||||||||||||||
213 | - | |||||||||||||||||||
214 | QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator it; | - | ||||||||||||||||||
QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator end;QMutexLocker locker(&engine->mutex); | ||||||||||||||||||||
215 | - | |||||||||||||||||||
216 | //find all InternetAccessPoints | - | ||||||||||||||||||
217 | for (it = engine->accessPointConfigurations.begin(), | - | ||||||||||||||||||
end =const auto &ptr : qAsConst(engine->accessPointConfigurations.end(); it != end; ++it))) { | ||||||||||||||||||||
218 | QNetworkConfigurationPrivatePointer ptr = it.value();QMutexLocker configLocker(&ptr->mutex); | - | ||||||||||||||||||
219 | - | |||||||||||||||||||
220 | if ((ptr->state & filter) == filter) {
| 3-81 | ||||||||||||||||||
221 | QNetworkConfiguration pt; | - | ||||||||||||||||||
222 | pt.d = ptr; | - | ||||||||||||||||||
223 | result << pt; | - | ||||||||||||||||||
224 | } executed 81 times by 4 tests: end of block Executed by:
| 81 | ||||||||||||||||||
225 | } executed 84 times by 4 tests: end of block Executed by:
| 84 | ||||||||||||||||||
226 | - | |||||||||||||||||||
227 | //find all service networks | - | ||||||||||||||||||
228 | for (it = engine->snapConfigurations.begin(), | - | ||||||||||||||||||
end =const auto &ptr : qAsConst(engine->snapConfigurations.end(); it != end; ++it))) { | ||||||||||||||||||||
229 | QNetworkConfigurationPrivatePointer ptr = it.value();QMutexLocker configLocker(&ptr->mutex); | - | ||||||||||||||||||
230 | - | |||||||||||||||||||
231 | if ((ptr->state & filter) == filter) {
| 0 | ||||||||||||||||||
232 | QNetworkConfiguration pt; | - | ||||||||||||||||||
233 | pt.d = ptr; | - | ||||||||||||||||||
234 | result << pt; | - | ||||||||||||||||||
235 | } never executed: end of block | 0 | ||||||||||||||||||
236 | } never executed: end of block | 0 | ||||||||||||||||||
237 | } executed 56 times by 4 tests: end of block Executed by:
| 56 | ||||||||||||||||||
238 | - | |||||||||||||||||||
239 | return result; executed 28 times by 4 tests: return result; Executed by:
| 28 | ||||||||||||||||||
240 | } | - | ||||||||||||||||||
241 | - | |||||||||||||||||||
242 | QNetworkConfiguration QNetworkConfigurationManagerPrivate::configurationFromIdentifier(const QString &identifier) const | - | ||||||||||||||||||
243 | { | - | ||||||||||||||||||
244 | QNetworkConfiguration item; | - | ||||||||||||||||||
245 | - | |||||||||||||||||||
246 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||
247 | - | |||||||||||||||||||
248 | foreachfor (QBearerEngine *engine ,: sessionEngines) { | - | ||||||||||||||||||
249 | QMutexLocker locker(&engine->mutex); | - | ||||||||||||||||||
250 | if (auto ptr = engine->accessPointConfigurations.containsvalue(identifier)) {
| 4-119 | ||||||||||||||||||
251 | item.d = engine->accessPointConfigurations[identifier]; | - | ||||||||||||||||||
elsestd::move(ptr); | ||||||||||||||||||||
252 | break; executed 119 times by 3 tests: break; Executed by:
| 119 | ||||||||||||||||||
253 | } | - | ||||||||||||||||||
254 | if (auto ptr = engine->snapConfigurations.containsvalue(identifier)) {
| 0-4 | ||||||||||||||||||
255 | item.d = engine->snapConfigurations[identifier]; | - | ||||||||||||||||||
elsestd::move(ptr); | ||||||||||||||||||||
256 | break; never executed: break; | 0 | ||||||||||||||||||
257 | } | - | ||||||||||||||||||
258 | if (auto ptr = engine->userChoiceConfigurations.containsvalue(identifier)) {
| 0-4 | ||||||||||||||||||
259 | item.d = engine->userChoiceConfigurations[identifier]; | - | ||||||||||||||||||
else | ||||||||||||||||||||
continue; | ||||||||||||||||||||
return itemstd::move(ptr); | ||||||||||||||||||||
260 | break never executed: ;break; never executed: break; | 0 | ||||||||||||||||||
261 | } | - | ||||||||||||||||||
262 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
263 | - | |||||||||||||||||||
264 | return item; executed 120 times by 3 tests: return item; Executed by:
| 120 | ||||||||||||||||||
265 | } | - | ||||||||||||||||||
266 | - | |||||||||||||||||||
267 | bool QNetworkConfigurationManagerPrivate::isOnline() const | - | ||||||||||||||||||
268 | { | - | ||||||||||||||||||
269 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||
270 | - | |||||||||||||||||||
271 | // We need allConfigurations since onlineConfigurations is filled with queued connections | - | ||||||||||||||||||
272 | // and thus is not always (more importantly just after creation) up to date | - | ||||||||||||||||||
273 | return !allConfigurations(QNetworkConfiguration::Active).isEmpty(); | - | ||||||||||||||||||
274 | } | - | ||||||||||||||||||
275 | - | |||||||||||||||||||
276 | QNetworkConfigurationManager::Capabilities QNetworkConfigurationManagerPrivate::capabilities() const | - | ||||||||||||||||||
277 | { | - | ||||||||||||||||||
278 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||
279 | - | |||||||||||||||||||
280 | QNetworkConfigurationManager::Capabilities capFlags; | - | ||||||||||||||||||
281 | - | |||||||||||||||||||
282 | foreachfor (QBearerEngine *engine ,: sessionEngines) | - | ||||||||||||||||||
283 | capFlags |= engine->capabilities(); executed 188 times by 12 tests: capFlags |= engine->capabilities(); Executed by:
| 188 | ||||||||||||||||||
284 | - | |||||||||||||||||||
285 | return capFlags; executed 94 times by 12 tests: return capFlags; Executed by:
| 94 | ||||||||||||||||||
286 | } | - | ||||||||||||||||||
287 | - | |||||||||||||||||||
288 | void QNetworkConfigurationManagerPrivate::configurationAdded(QNetworkConfigurationPrivatePointer ptr) | - | ||||||||||||||||||
289 | { | - | ||||||||||||||||||
290 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||
291 | - | |||||||||||||||||||
292 | if (!firstUpdate) { | - | ||||||||||||||||||
293 | QNetworkConfiguration item; | - | ||||||||||||||||||
294 | item.d = ptr; | - | ||||||||||||||||||
295 | emit configurationAdded(item); | - | ||||||||||||||||||
296 | } | - | ||||||||||||||||||
297 | - | |||||||||||||||||||
298 | ptr->mutex.lock(); | - | ||||||||||||||||||
299 | if (ptr->state == QNetworkConfiguration::Active) { | - | ||||||||||||||||||
300 | ptr->mutex.unlock(); | - | ||||||||||||||||||
301 | onlineConfigurations.insert(ptr->id); | - | ||||||||||||||||||
302 | if (!firstUpdate && onlineConfigurations.count() == 1) | - | ||||||||||||||||||
303 | emit onlineStateChanged(true); | - | ||||||||||||||||||
304 | } else { | - | ||||||||||||||||||
305 | ptr->mutex.unlock(); | - | ||||||||||||||||||
306 | } | - | ||||||||||||||||||
307 | } | - | ||||||||||||||||||
308 | - | |||||||||||||||||||
309 | void QNetworkConfigurationManagerPrivate::configurationRemoved(QNetworkConfigurationPrivatePointer ptr) | - | ||||||||||||||||||
310 | { | - | ||||||||||||||||||
311 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||
312 | - | |||||||||||||||||||
313 | ptr->mutex.lock(); | - | ||||||||||||||||||
314 | ptr->isValid = false; | - | ||||||||||||||||||
315 | ptr->mutex.unlock(); | - | ||||||||||||||||||
316 | - | |||||||||||||||||||
317 | if (!firstUpdate) { | - | ||||||||||||||||||
318 | QNetworkConfiguration item; | - | ||||||||||||||||||
319 | item.d = ptr; | - | ||||||||||||||||||
320 | emit configurationRemoved(item); | - | ||||||||||||||||||
321 | } | - | ||||||||||||||||||
322 | - | |||||||||||||||||||
323 | onlineConfigurations.remove(ptr->id); | - | ||||||||||||||||||
324 | if (!firstUpdate && onlineConfigurations.isEmpty()) | - | ||||||||||||||||||
325 | emit onlineStateChanged(false); | - | ||||||||||||||||||
326 | } | - | ||||||||||||||||||
327 | - | |||||||||||||||||||
328 | void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigurationPrivatePointer ptr) | - | ||||||||||||||||||
329 | { | - | ||||||||||||||||||
330 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||
331 | - | |||||||||||||||||||
332 | if (!firstUpdate) { | - | ||||||||||||||||||
333 | QNetworkConfiguration item; | - | ||||||||||||||||||
334 | item.d = ptr; | - | ||||||||||||||||||
335 | emit configurationChanged(item); | - | ||||||||||||||||||
336 | } | - | ||||||||||||||||||
337 | - | |||||||||||||||||||
338 | bool previous = !onlineConfigurations.isEmpty(); | - | ||||||||||||||||||
339 | - | |||||||||||||||||||
340 | ptr->mutex.lock(); | - | ||||||||||||||||||
341 | if (ptr->state == QNetworkConfiguration::Active) | - | ||||||||||||||||||
342 | onlineConfigurations.insert(ptr->id); | - | ||||||||||||||||||
343 | else | - | ||||||||||||||||||
344 | onlineConfigurations.remove(ptr->id); | - | ||||||||||||||||||
345 | ptr->mutex.unlock(); | - | ||||||||||||||||||
346 | - | |||||||||||||||||||
347 | bool online = !onlineConfigurations.isEmpty(); | - | ||||||||||||||||||
348 | - | |||||||||||||||||||
349 | if (!firstUpdate && online != previous) | - | ||||||||||||||||||
350 | emit onlineStateChanged(online); | - | ||||||||||||||||||
351 | } | - | ||||||||||||||||||
352 | - | |||||||||||||||||||
353 | void QNetworkConfigurationManagerPrivate::updateConfigurations() | - | ||||||||||||||||||
354 | { | - | ||||||||||||||||||
355 | #ifndef QT_NO_LIBRARYtypedef QMultiMap<int, QString> PluginKeyMap; | - | ||||||||||||||||||
356 | typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator; | - | ||||||||||||||||||
357 | #endifQMutexLocker locker(&mutex); | - | ||||||||||||||||||
358 | - | |||||||||||||||||||
359 | if (firstUpdate) {
| 18-274 | ||||||||||||||||||
360 | if (qobject_cast<QBearerEngine *>(sender()))
| 0-18 | ||||||||||||||||||
361 | return; never executed: return; | 0 | ||||||||||||||||||
362 | - | |||||||||||||||||||
363 | updating = false; | - | ||||||||||||||||||
364 | - | |||||||||||||||||||
365 | #ifndef QT_NO_LIBRARYbool envOK = false; | - | ||||||||||||||||||
366 | const int skipGeneric = qgetenvqEnvironmentVariableIntValue("QT_EXCLUDE_GENERIC_BEARER").toInt(, &envOK); | - | ||||||||||||||||||
367 | QBearerEngine *generic = 0; | - | ||||||||||||||||||
368 | static QFactoryLoader loader(QBearerEngineFactoryInterface_iid, QLatin1String("/bearer")); | - | ||||||||||||||||||
369 | QFactoryLoader *l = loader();&loader; | - | ||||||||||||||||||
370 | const PluginKeyMap keyMap = l->keyMap(); | - | ||||||||||||||||||
371 | const PluginKeyMapConstIterator cend = keyMap.constEnd(); | - | ||||||||||||||||||
372 | QStringList addedEngines; | - | ||||||||||||||||||
373 | for (PluginKeyMapConstIterator it = keyMap.constBegin(); it != cend; ++it) {
| 18-54 | ||||||||||||||||||
374 | const QString &key = it.value(); | - | ||||||||||||||||||
375 | if (addedEngines.contains(key))
| 0-54 | ||||||||||||||||||
376 | continue; never executed: continue; | 0 | ||||||||||||||||||
377 | - | |||||||||||||||||||
378 | addedEngines.append(key); | - | ||||||||||||||||||
379 | if (QBearerEngine *engine = qLoadPlugin<QBearerEngine, QBearerEnginePlugin>(l, key)) {
| 18-36 | ||||||||||||||||||
380 | if (key == QLatin1String("generic"))
| 18 | ||||||||||||||||||
381 | generic = engine; executed 18 times by 16 tests: generic = engine; Executed by:
| 18 | ||||||||||||||||||
382 | else | - | ||||||||||||||||||
383 | sessionEngines.append(engine); executed 18 times by 16 tests: sessionEngines.append(engine); Executed by:
| 18 | ||||||||||||||||||
384 | - | |||||||||||||||||||
385 | engine->moveToThread(bearerThread); | - | ||||||||||||||||||
386 | - | |||||||||||||||||||
387 | connect(engine, SIGNAL(updateCompleted()), | - | ||||||||||||||||||
388 | this, SLOT(updateConfigurations()), | - | ||||||||||||||||||
389 | Qt::QueuedConnection); | - | ||||||||||||||||||
390 | connect(engine, SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), | - | ||||||||||||||||||
391 | this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer)), | - | ||||||||||||||||||
392 | Qt::QueuedConnection); | - | ||||||||||||||||||
393 | connect(engine, SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)), | - | ||||||||||||||||||
394 | this, SLOT(configurationRemoved(QNetworkConfigurationPrivatePointer)), | - | ||||||||||||||||||
395 | Qt::QueuedConnection); | - | ||||||||||||||||||
396 | connect(engine, SIGNAL(configurationChanged(QNetworkConfigurationPrivatePointer)), | - | ||||||||||||||||||
397 | this, SLOT(configurationChanged(QNetworkConfigurationPrivatePointer)), | - | ||||||||||||||||||
398 | Qt::QueuedConnection); | - | ||||||||||||||||||
399 | } executed 36 times by 16 tests: end of block Executed by:
| 36 | ||||||||||||||||||
400 | } executed 54 times by 16 tests: end of block Executed by:
| 54 | ||||||||||||||||||
401 | - | |||||||||||||||||||
402 | if (generic) {
| 0-18 | ||||||||||||||||||
403 | if (!envOK || skipGeneric <= 0)
| 0-18 | ||||||||||||||||||
404 | sessionEngines.append(generic); executed 18 times by 16 tests: sessionEngines.append(generic); Executed by:
| 18 | ||||||||||||||||||
405 | else | - | ||||||||||||||||||
406 | delete generic; never executed: delete generic; | 0 | ||||||||||||||||||
407 | } | - | ||||||||||||||||||
408 | #endif } executed 18 times by 16 tests: end of block Executed by:
| 18 | ||||||||||||||||||
409 | - | |||||||||||||||||||
410 | QBearerEngine *engine = qobject_cast<QBearerEngine *>(sender()); | - | ||||||||||||||||||
411 | if (engine && !updatingEngines.isEmpty())
| 18-274 | ||||||||||||||||||
412 | updatingEngines.remove(engine); executed 168 times by 18 tests: updatingEngines.remove(engine); Executed by:
| 168 | ||||||||||||||||||
413 | - | |||||||||||||||||||
414 | if (updating && updatingEngines.isEmpty()) {
| 82-168 | ||||||||||||||||||
415 | updating = false; | - | ||||||||||||||||||
416 | emit configurationUpdateComplete(); | - | ||||||||||||||||||
417 | } executed 82 times by 18 tests: end of block Executed by:
| 82 | ||||||||||||||||||
418 | - | |||||||||||||||||||
419 | if (engine && !pollingEngines.isEmpty()) {
| 18-274 | ||||||||||||||||||
420 | pollingEngines.remove(engine); | - | ||||||||||||||||||
421 | if (pollingEngines.isEmpty())
| 0-51 | ||||||||||||||||||
422 | startPolling(); executed 51 times by 4 tests: startPolling(); Executed by:
| 51 | ||||||||||||||||||
423 | } executed 51 times by 4 tests: end of block Executed by:
| 51 | ||||||||||||||||||
424 | - | |||||||||||||||||||
425 | if (firstUpdate) {
| 18-274 | ||||||||||||||||||
426 | firstUpdate = false; | - | ||||||||||||||||||
427 | const QList<QBearerEngine*> enginesToInitialize = sessionEngines; //shallow copy the list in case it is modified when we unlock mutex | - | ||||||||||||||||||
428 | locker.unlock(); | - | ||||||||||||||||||
429 | foreachfor (QBearerEngine* engine ,: enginesToInitialize) | - | ||||||||||||||||||
430 | {QMetaObject::invokeMethod(engine, "initialize", Qt::BlockingQueuedConnection); executed 36 times by 16 tests: QMetaObject::invokeMethod(engine, "initialize", Qt::BlockingQueuedConnection); Executed by:
| 36 | ||||||||||||||||||
431 | }} executed 18 times by 16 tests: end of block Executed by:
| 18 | ||||||||||||||||||
432 | } executed 292 times by 18 tests: end of block Executed by:
| 292 | ||||||||||||||||||
433 | - | |||||||||||||||||||
434 | void QNetworkConfigurationManagerPrivate::performAsyncConfigurationUpdate() | - | ||||||||||||||||||
435 | { | - | ||||||||||||||||||
436 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||
437 | - | |||||||||||||||||||
438 | if (sessionEngines.isEmpty()) {
| 0-86 | ||||||||||||||||||
439 | emit configurationUpdateComplete(); | - | ||||||||||||||||||
440 | return; never executed: return; | 0 | ||||||||||||||||||
441 | } | - | ||||||||||||||||||
442 | - | |||||||||||||||||||
443 | updating = true; | - | ||||||||||||||||||
444 | - | |||||||||||||||||||
445 | foreachfor (QBearerEngine *engine ,: qAsConst(sessionEngines))) { | - | ||||||||||||||||||
446 | updatingEngines.insert(engine); | - | ||||||||||||||||||
447 | QMetaObject::invokeMethod(engine, "requestUpdate"); | - | ||||||||||||||||||
448 | } executed 172 times by 18 tests: end of block Executed by:
| 172 | ||||||||||||||||||
449 | } executed 86 times by 18 tests: end of block Executed by:
| 86 | ||||||||||||||||||
450 | - | |||||||||||||||||||
451 | QList<QBearerEngine *> QNetworkConfigurationManagerPrivate::engines() const | - | ||||||||||||||||||
452 | { | - | ||||||||||||||||||
453 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||
454 | - | |||||||||||||||||||
455 | return sessionEngines; | - | ||||||||||||||||||
456 | } | - | ||||||||||||||||||
457 | - | |||||||||||||||||||
458 | void QNetworkConfigurationManagerPrivate::startPolling() | - | ||||||||||||||||||
459 | { | - | ||||||||||||||||||
460 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||
461 | if (!pollTimer) {
| 19-64 | ||||||||||||||||||
462 | pollTimer = new QTimer(this); | - | ||||||||||||||||||
463 | bool ok; | - | ||||||||||||||||||
464 | int interval = qgetenvqEnvironmentVariableIntValue("QT_BEARER_POLL_TIMEOUT").toInt(, &ok); | - | ||||||||||||||||||
465 | if (!ok)
| 0-19 | ||||||||||||||||||
466 | interval = 10000;//default 10 seconds executed 19 times by 17 tests: interval = 10000; Executed by:
| 19 | ||||||||||||||||||
467 | pollTimer->setInterval(interval); | - | ||||||||||||||||||
468 | pollTimer->setSingleShot(true); | - | ||||||||||||||||||
469 | connect(pollTimer, SIGNAL(timeout()), this, SLOT(pollEngines())); | - | ||||||||||||||||||
470 | } executed 19 times by 17 tests: end of block Executed by:
| 19 | ||||||||||||||||||
471 | - | |||||||||||||||||||
472 | if (pollTimer->isActive())
| 13-70 | ||||||||||||||||||
473 | return; executed 13 times by 6 tests: return; Executed by:
| 13 | ||||||||||||||||||
474 | - | |||||||||||||||||||
475 | foreachfor (QBearerEngine *engine ,: qAsConst(sessionEngines))) { | - | ||||||||||||||||||
476 | if (engine->requiresPolling() && (forcedPolling || engine->configurationsInUse())) {
| 0-70 | ||||||||||||||||||
477 | pollTimer->start(); | - | ||||||||||||||||||
478 | break; executed 66 times by 16 tests: break; Executed by:
| 66 | ||||||||||||||||||
479 | } | - | ||||||||||||||||||
480 | } executed 74 times by 18 tests: end of block Executed by:
| 74 | ||||||||||||||||||
481 | performAsyncConfigurationUpdate(); | - | ||||||||||||||||||
482 | } executed 70 times by 18 tests: end of block Executed by:
| 70 | ||||||||||||||||||
483 | - | |||||||||||||||||||
484 | void QNetworkConfigurationManagerPrivate::pollEngines() | - | ||||||||||||||||||
485 | { | - | ||||||||||||||||||
486 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||
487 | - | |||||||||||||||||||
488 | foreachfor (QBearerEngine *engine ,: qAsConst(sessionEngines))) { | - | ||||||||||||||||||
489 | if (engine->requiresPolling() && (forcedPolling || engine->configurationsInUse())) {
| 0-51 | ||||||||||||||||||
490 | pollingEngines.insert(engine); | - | ||||||||||||||||||
491 | QMetaObject::invokeMethod(engine, "requestUpdate"); | - | ||||||||||||||||||
492 | } executed 51 times by 4 tests: end of block Executed by:
| 51 | ||||||||||||||||||
493 | } executed 102 times by 4 tests: end of block Executed by:
| 102 | ||||||||||||||||||
494 | } executed 51 times by 4 tests: end of block Executed by:
| 51 | ||||||||||||||||||
495 | - | |||||||||||||||||||
496 | void QNetworkConfigurationManagerPrivate::enablePolling() | - | ||||||||||||||||||
497 | { | - | ||||||||||||||||||
498 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||
499 | - | |||||||||||||||||||
500 | ++forcedPolling; | - | ||||||||||||||||||
501 | - | |||||||||||||||||||
502 | if (forcedPolling == 1) | - | ||||||||||||||||||
503 | QMetaObject::invokeMethod(this, "startPolling"); | - | ||||||||||||||||||
504 | } | - | ||||||||||||||||||
505 | - | |||||||||||||||||||
506 | void QNetworkConfigurationManagerPrivate::disablePolling() | - | ||||||||||||||||||
507 | { | - | ||||||||||||||||||
508 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||
509 | - | |||||||||||||||||||
510 | --forcedPolling; | - | ||||||||||||||||||
511 | } | - | ||||||||||||||||||
512 | - | |||||||||||||||||||
513 | QT_END_NAMESPACE | - | ||||||||||||||||||
514 | - | |||||||||||||||||||
515 | #endif // QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |