bearer/qnetworkconfiguration.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
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 Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qnetworkconfiguration.h" -
43#include "qnetworkconfiguration_p.h" -
44 -
45QT_BEGIN_NAMESPACE -
46 -
47/*! -
48 \class QNetworkConfiguration -
49 -
50 \brief The QNetworkConfiguration class provides an abstraction of one or more access point configurations. -
51 -
52 \since 4.7 -
53 -
54 \inmodule QtNetwork -
55 \ingroup network -
56 \ingroup shared -
57 -
58 QNetworkConfiguration encapsulates a single access point or service network. -
59 In most cases a single access point configuration can be mapped to one network -
60 interface. However a single network interface may not always map to only one -
61 access point configuration. Multiple configurations for the same -
62 network device may enable multiple access points. An example -
63 device that could exhibit such a configuration might be a -
64 Smartphone which allows the user to manage multiple WLAN -
65 configurations while the device itself has only one WLAN network device. -
66 -
67 The QNetworkConfiguration also supports the concept of service networks. -
68 This concept allows the grouping of multiple access point configurations -
69 into one entity. Such a group is called service network and can be -
70 beneficial in cases whereby a network session to a -
71 particular destination network is required (e.g. a company network). -
72 When using a service network the user doesn't usually care which one of the -
73 connectivity options is chosen (e.g. corporate WLAN or VPN via GPRS) -
74 as long as he can reach the company's target server. Depending -
75 on the current position and time some of the access points that make -
76 up the service network may not even be available. Furthermore -
77 automated access point roaming can be enabled which enables the device -
78 to change the network interface configuration dynamically while maintaining -
79 the applications connection to the target network. It allows adaption -
80 to the changing environment and may enable optimization with regards to -
81 cost, speed or other network parameters. -
82 -
83 Special configurations of type UserChoice provide a placeholder configuration which is -
84 resolved to an actual network configuration by the platform when a -
85 \l {QNetworkSession}{session} is \l {QNetworkSession::open()}{opened}. Not all platforms -
86 support the concept of a user choice configuration. -
87 -
88 \section1 Configuration states -
89 -
90 The list of available configurations can be obtained via -
91 QNetworkConfigurationManager::allConfigurations(). A configuration can have -
92 multiple states. The \l Defined configuration state indicates that the configuration -
93 is stored on the device. However the configuration is not yet ready to be activated -
94 as e.g. a WLAN may not be available at the current time. -
95 -
96 The \l Discovered state implies that the configuration is \l Defined and -
97 the outside conditions are such that the configuration can be used immediately -
98 to open a new network session. An example of such an outside condition may be -
99 that the Ethernet cable is actually connected to the device or that the WLAN -
100 with the specified SSID is in range. -
101 -
102 The \l Active state implies that the configuration is \l Discovered. A configuration -
103 in this state is currently being used by an application. The underlying network -
104 interface has a valid IP configuration and can transfer IP packets between the -
105 device and the target network. -
106 -
107 The \l Undefined state indicates that the system has knowledge of possible target -
108 networks but cannot actually use that knowledge to connect to it. An example -
109 for such a state could be an encrypted WLAN that has been discovered -
110 but the user hasn't actually saved a configuration including the required password -
111 which would allow the device to connect to it. -
112 -
113 Depending on the type of configuration some states are transient in nature. A GPRS/UMTS -
114 connection may almost always be \l Discovered if the GSM/UMTS network is available. -
115 However if the GSM/UMTS network looses the connection the associated configuration may change its state -
116 from \l Discovered to \l Defined as well. A similar use case might be triggered by -
117 WLAN availability. QNetworkConfigurationManager::updateConfigurations() can be used to -
118 manually trigger updates of states. Note that some platforms do not require such updates -
119 as they implicitly change the state once it has been discovered. If the state of a -
120 configuration changes all related QNetworkConfiguration instances change their state automatically. -
121 -
122 \sa QNetworkSession, QNetworkConfigurationManager -
123*/ -
124 -
125/*! -
126 \enum QNetworkConfiguration::Type -
127 -
128 This enum describes the type of configuration. -
129 -
130 \value InternetAccessPoint The configuration specifies the details for a single access point. -
131 Note that configurations of type InternetAccessPoint may be part -
132 of other QNetworkConfigurations of type ServiceNetwork. -
133 \value ServiceNetwork The configuration is based on a group of QNetworkConfigurations of -
134 type InternetAccessPoint. All group members can reach the same -
135 target network. This type of configuration is a mandatory -
136 requirement for roaming enabled network sessions. On some -
137 platforms this form of configuration may also be called Service -
138 Network Access Point (SNAP). -
139 \value UserChoice The configuration is a placeholder which will be resolved to an -
140 actual configuration by the platform when a session is opened. Depending -
141 on the platform the selection may generate a popup dialog asking the user -
142 for his preferred choice. -
143 \value Invalid The configuration is invalid. -
144*/ -
145 -
146/*! -
147 \enum QNetworkConfiguration::StateFlag -
148 -
149 Specifies the configuration states. -
150 -
151 \value Undefined This state is used for transient configurations such as newly discovered -
152 WLANs for which the user has not actually created a configuration yet. -
153 \value Defined Defined configurations are known to the system but are not immediately -
154 usable (e.g. a configured WLAN is not within range or the Ethernet cable -
155 is currently not plugged into the machine). -
156 \value Discovered A discovered configuration can be immediately used to create a new -
157 QNetworkSession. An example of a discovered configuration could be a WLAN -
158 which is within in range. If the device moves out of range the discovered -
159 flag is dropped. A second example is a GPRS configuration which generally -
160 remains discovered for as long as the device has network coverage. A -
161 configuration that has this state is also in state -
162 QNetworkConfiguration::Defined. If the configuration is a service network -
163 this flag is set if at least one of the underlying access points -
164 configurations has the Discovered state. -
165 \value Active The configuration is currently used by an open network session -
166 (see \l QNetworkSession::isOpen()). However this does not mean that the -
167 current process is the entity that created the open session. It merely -
168 indicates that if a new QNetworkSession were to be constructed based on -
169 this configuration \l QNetworkSession::state() would return -
170 \l QNetworkSession::Connected. This state implies the -
171 QNetworkConfiguration::Discovered state. -
172*/ -
173 -
174/*! -
175 \enum QNetworkConfiguration::Purpose -
176 -
177 Specifies the purpose of the configuration. -
178 -
179 \value UnknownPurpose The configuration doesn't specify any purpose. This is the default value. -
180 \value PublicPurpose The configuration can be used for general purpose internet access. -
181 \value PrivatePurpose The configuration is suitable to access a private network such as an office Intranet. -
182 \value ServiceSpecificPurpose The configuration can be used for operator specific services (e.g. -
183 receiving MMS messages or content streaming). -
184*/ -
185 -
186/*! -
187 \enum QNetworkConfiguration::BearerType -
188 -
189 Specifies the type of bearer used by a configuration. -
190 -
191 \value BearerUnknown The type of bearer is unknown or unspecified. The bearerTypeName() -
192 function may return additional information. -
193 \value BearerEthernet The configuration is for an Ethernet interfaces. -
194 \value BearerWLAN The configuration is for a Wireless LAN interface. -
195 \value Bearer2G The configuration is for a CSD, GPRS, HSCSD, EDGE or cdmaOne interface. -
196 \value BearerCDMA2000 The configuration is for CDMA interface. -
197 \value BearerWCDMA The configuration is for W-CDMA/UMTS interface. -
198 \value BearerHSPA The configuration is for High Speed Packet Access (HSPA) interface. -
199 \value BearerBluetooth The configuration is for a Bluetooth interface. -
200 \value BearerWiMAX The configuration is for a WiMAX interface. -
201*/ -
202 -
203/*! -
204 Constructs an invalid configuration object. -
205 -
206 \sa isValid() -
207*/ -
208QNetworkConfiguration::QNetworkConfiguration() -
209 : d(0) -
210{ -
211}
executed: }
Execution Count:3347
3347
212 -
213/*! -
214 Creates a copy of the QNetworkConfiguration object contained in \a other. -
215*/ -
216QNetworkConfiguration::QNetworkConfiguration(const QNetworkConfiguration &other) -
217 : d(other.d) -
218{ -
219}
executed: }
Execution Count:260
260
220 -
221/*! -
222 Frees the resources associated with the QNetworkConfiguration object. -
223*/ -
224QNetworkConfiguration::~QNetworkConfiguration() -
225{ -
226} -
227 -
228/*! -
229 Copies the content of the QNetworkConfiguration object contained in \a other into this one. -
230*/ -
231QNetworkConfiguration &QNetworkConfiguration::operator=(const QNetworkConfiguration &other) -
232{ -
233 d = other.d;
executed (the execution status of this line is deduced): d = other.d;
-
234 return *this;
executed: return *this;
Execution Count:193
193
235} -
236 -
237/*! -
238 \fn void QNetworkConfiguration::swap(QNetworkConfiguration &other) -
239 \since 5.0 -
240 -
241 Swaps this network configuration with \a other. This function is -
242 very fast and never fails. -
243*/ -
244 -
245/*! -
246 Returns true, if this configuration is the same as the \a other -
247 configuration given; otherwise returns false. -
248*/ -
249bool QNetworkConfiguration::operator==(const QNetworkConfiguration &other) const -
250{ -
251 return (d == other.d);
executed: return (d == other.d);
Execution Count:73
73
252} -
253 -
254/*! -
255 \fn bool QNetworkConfiguration::operator!=(const QNetworkConfiguration &other) const -
256 -
257 Returns true if this configuration is not the same as the \a other -
258 configuration given; otherwise returns false. -
259*/ -
260 -
261/*! -
262 Returns the user visible name of this configuration. -
263 -
264 The name may either be the name of the underlying access point or the -
265 name for service network that this configuration represents. -
266*/ -
267QString QNetworkConfiguration::name() const -
268{ -
269 if (!d)
evaluated: !d
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:51
6-51
270 return QString();
executed: return QString();
Execution Count:6
6
271 -
272 QMutexLocker locker(&d->mutex);
executed (the execution status of this line is deduced): QMutexLocker locker(&d->mutex);
-
273 return d->name;
executed: return d->name;
Execution Count:51
51
274} -
275 -
276/*! -
277 Returns the unique and platform specific identifier for this network configuration; -
278 otherwise an empty string. -
279*/ -
280QString QNetworkConfiguration::identifier() const -
281{ -
282 if (!d)
evaluated: !d
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:299
2-299
283 return QString();
executed: return QString();
Execution Count:2
2
284 -
285 QMutexLocker locker(&d->mutex);
executed (the execution status of this line is deduced): QMutexLocker locker(&d->mutex);
-
286 return d->id;
executed: return d->id;
Execution Count:299
299
287} -
288 -
289/*! -
290 Returns the type of the configuration. -
291 -
292 A configuration can represent a single access point configuration or -
293 a set of access point configurations. Such a set is called service network. -
294 A configuration that is based on a service network can potentially support -
295 roaming of network sessions. -
296*/ -
297QNetworkConfiguration::Type QNetworkConfiguration::type() const -
298{ -
299 if (!d)
evaluated: !d
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:99
7-99
300 return QNetworkConfiguration::Invalid;
executed: return QNetworkConfiguration::Invalid;
Execution Count:7
7
301 -
302 QMutexLocker locker(&d->mutex);
executed (the execution status of this line is deduced): QMutexLocker locker(&d->mutex);
-
303 return d->type;
executed: return d->type;
Execution Count:99
99
304} -
305 -
306/*! -
307 Returns true if this QNetworkConfiguration object is valid. -
308 A configuration may become invalid if the user deletes the configuration or -
309 the configuration was default-constructed. -
310 -
311 The addition and removal of configurations can be monitored via the -
312 QNetworkConfigurationManager. -
313 -
314 \sa QNetworkConfigurationManager -
315*/ -
316bool QNetworkConfiguration::isValid() const -
317{ -
318 if (!d)
evaluated: !d
TRUEFALSE
yes
Evaluation Count:100
yes
Evaluation Count:131
100-131
319 return false;
executed: return false;
Execution Count:100
100
320 -
321 QMutexLocker locker(&d->mutex);
executed (the execution status of this line is deduced): QMutexLocker locker(&d->mutex);
-
322 return d->isValid;
executed: return d->isValid;
Execution Count:131
131
323} -
324 -
325/*! -
326 Returns the current state of the configuration. -
327*/ -
328QNetworkConfiguration::StateFlags QNetworkConfiguration::state() const -
329{ -
330 if (!d)
evaluated: !d
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:161
11-161
331 return QNetworkConfiguration::Undefined;
executed: return QNetworkConfiguration::Undefined;
Execution Count:11
11
332 -
333 QMutexLocker locker(&d->mutex);
executed (the execution status of this line is deduced): QMutexLocker locker(&d->mutex);
-
334 return d->state;
executed: return d->state;
Execution Count:161
161
335} -
336 -
337/*! -
338 Returns the purpose of this configuration. -
339 -
340 The purpose field may be used to programmatically determine the -
341 purpose of a configuration. Such information is usually part of the -
342 access point or service network meta data. -
343*/ -
344QNetworkConfiguration::Purpose QNetworkConfiguration::purpose() const -
345{ -
346 if (!d)
evaluated: !d
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:26
4-26
347 return QNetworkConfiguration::UnknownPurpose;
executed: return QNetworkConfiguration::UnknownPurpose;
Execution Count:4
4
348 -
349 QMutexLocker locker(&d->mutex);
executed (the execution status of this line is deduced): QMutexLocker locker(&d->mutex);
-
350 return d->purpose;
executed: return d->purpose;
Execution Count:26
26
351} -
352 -
353/*! -
354 Returns true if this configuration supports roaming; otherwise false. -
355*/ -
356bool QNetworkConfiguration::isRoamingAvailable() const -
357{ -
358 if (!d)
evaluated: !d
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:18
2-18
359 return false;
executed: return false;
Execution Count:2
2
360 -
361 QMutexLocker locker(&d->mutex);
executed (the execution status of this line is deduced): QMutexLocker locker(&d->mutex);
-
362 return d->roamingSupported;
executed: return d->roamingSupported;
Execution Count:18
18
363} -
364 -
365/*! -
366 Returns all sub configurations of this network configuration in priority order. The first sub -
367 configuration in the list has the highest priority. -
368 -
369 Only network configurations of type \l ServiceNetwork can have children. Otherwise this -
370 function returns an empty list. -
371*/ -
372QList<QNetworkConfiguration> QNetworkConfiguration::children() const -
373{ -
374 QList<QNetworkConfiguration> results;
never executed (the execution status of this line is deduced): QList<QNetworkConfiguration> results;
-
375 -
376 if (!d)
never evaluated: !d
0
377 return results;
never executed: return results;
0
378 -
379 QMutexLocker locker(&d->mutex);
never executed (the execution status of this line is deduced): QMutexLocker locker(&d->mutex);
-
380 -
381 if (d->type != QNetworkConfiguration::ServiceNetwork || !d->isValid)
never evaluated: d->type != QNetworkConfiguration::ServiceNetwork
never evaluated: !d->isValid
0
382 return results;
never executed: return results;
0
383 -
384 QMutableMapIterator<unsigned int, QNetworkConfigurationPrivatePointer> i(d->serviceNetworkMembers);
never executed (the execution status of this line is deduced): QMutableMapIterator<unsigned int, QNetworkConfigurationPrivatePointer> i(d->serviceNetworkMembers);
-
385 while (i.hasNext()) {
never evaluated: i.hasNext()
0
386 i.next();
never executed (the execution status of this line is deduced): i.next();
-
387 -
388 QNetworkConfigurationPrivatePointer p = i.value();
never executed (the execution status of this line is deduced): QNetworkConfigurationPrivatePointer p = i.value();
-
389 -
390 //if we have an invalid member get rid of it -> was deleted earlier on -
391 { -
392 QMutexLocker childLocker(&p->mutex);
never executed (the execution status of this line is deduced): QMutexLocker childLocker(&p->mutex);
-
393 -
394 if (!p->isValid) {
never evaluated: !p->isValid
0
395 i.remove();
never executed (the execution status of this line is deduced): i.remove();
-
396 continue;
never executed: continue;
0
397 } -
398 } -
399 -
400 QNetworkConfiguration item;
never executed (the execution status of this line is deduced): QNetworkConfiguration item;
-
401 item.d = p;
never executed (the execution status of this line is deduced): item.d = p;
-
402 results << item;
never executed (the execution status of this line is deduced): results << item;
-
403 }
never executed: }
0
404 -
405 return results;
never executed: return results;
0
406} -
407 -
408/*! -
409 Returns the type of bearer used by this network configuration. -
410 -
411 If the bearer type is \l {QNetworkConfiguration::BearerUnknown}{unknown} the bearerTypeName() -
412 function can be used to retrieve a textural type name for the bearer. -
413 -
414 An invalid network configuration always returns the BearerUnknown value. -
415*/ -
416QNetworkConfiguration::BearerType QNetworkConfiguration::bearerType() const -
417{ -
418 if (!isValid())
partially evaluated: !isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10
0-10
419 return BearerUnknown;
never executed: return BearerUnknown;
0
420 -
421 QMutexLocker locker(&d->mutex);
executed (the execution status of this line is deduced): QMutexLocker locker(&d->mutex);
-
422 -
423 return d->bearerType;
executed: return d->bearerType;
Execution Count:10
10
424} -
425 -
426/*! -
427 Returns the type of bearer used by this network configuration as a string. -
428 -
429 The string is not translated and therefore can not be shown to the user. The subsequent table -
430 shows the fixed mappings between BearerType and the bearer type name for known types. If the -
431 BearerType is unknown this function may return additional information if it is available; -
432 otherwise an empty string will be returned. -
433 -
434 \table -
435 \header -
436 \li BearerType -
437 \li Value -
438 \row -
439 \li BearerUnknown -
440 \li -
441 \li The session is based on an unknown or unspecified bearer type. The value of the -
442 string returned describes the bearer type. -
443 \row -
444 \li BearerEthernet -
445 \li Ethernet -
446 \row -
447 \li BearerWLAN -
448 \li WLAN -
449 \row -
450 \li Bearer2G -
451 \li 2G -
452 \row -
453 \li BearerCDMA2000 -
454 \li CDMA2000 -
455 \row -
456 \li BearerWCDMA -
457 \li WCDMA -
458 \row -
459 \li BearerHSPA -
460 \li HSPA -
461 \row -
462 \li BearerBluetooth -
463 \li Bluetooth -
464 \row -
465 \li BearerWiMAX -
466 \li WiMAX -
467 \endtable -
468 -
469 This function returns an empty string if this is an invalid configuration, a network -
470 configuration of type \l QNetworkConfiguration::ServiceNetwork or -
471 \l QNetworkConfiguration::UserChoice. -
472 -
473 \sa bearerType() -
474*/ -
475QString QNetworkConfiguration::bearerTypeName() const -
476{ -
477 if (!isValid())
evaluated: !isValid()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:4
1-4
478 return QString();
executed: return QString();
Execution Count:1
1
479 -
480 QMutexLocker locker(&d->mutex);
executed (the execution status of this line is deduced): QMutexLocker locker(&d->mutex);
-
481 -
482 if (d->type == QNetworkConfiguration::ServiceNetwork ||
partially evaluated: d->type == QNetworkConfiguration::ServiceNetwork
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
483 d->type == QNetworkConfiguration::UserChoice)
partially evaluated: d->type == QNetworkConfiguration::UserChoice
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
484 return QString();
never executed: return QString();
0
485 -
486 switch (d->bearerType) { -
487 case BearerEthernet: -
488 return QStringLiteral("Ethernet");
executed: return QString::fromUtf8("" "Ethernet" "", sizeof("Ethernet") - 1);
Execution Count:4
4
489 case BearerWLAN: -
490 return QStringLiteral("WLAN");
never executed: return QString::fromUtf8("" "WLAN" "", sizeof("WLAN") - 1);
0
491 case Bearer2G: -
492 return QStringLiteral("2G");
never executed: return QString::fromUtf8("" "2G" "", sizeof("2G") - 1);
0
493 case BearerCDMA2000: -
494 return QStringLiteral("CDMA2000");
never executed: return QString::fromUtf8("" "CDMA2000" "", sizeof("CDMA2000") - 1);
0
495 case BearerWCDMA: -
496 return QStringLiteral("WCDMA");
never executed: return QString::fromUtf8("" "WCDMA" "", sizeof("WCDMA") - 1);
0
497 case BearerHSPA: -
498 return QStringLiteral("HSPA");
never executed: return QString::fromUtf8("" "HSPA" "", sizeof("HSPA") - 1);
0
499 case BearerBluetooth: -
500 return QStringLiteral("Bluetooth");
never executed: return QString::fromUtf8("" "Bluetooth" "", sizeof("Bluetooth") - 1);
0
501 case BearerWiMAX: -
502 return QStringLiteral("WiMAX");
never executed: return QString::fromUtf8("" "WiMAX" "", sizeof("WiMAX") - 1);
0
503 case BearerUnknown: -
504 break;
never executed: break;
0
505 } -
506 return QStringLiteral("Unknown");
never executed: return QString::fromUtf8("" "Unknown" "", sizeof("Unknown") - 1);
0
507} -
508 -
509QT_END_NAMESPACE -
510 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial