Qt 4.8
Public Types | Public Functions | Properties | Friends | List of all members
QNetworkConfiguration Class Reference

The QNetworkConfiguration class provides an abstraction of one or more access point configurations. More...

#include <qnetworkconfiguration.h>

Public Types

enum  BearerType {
  BearerUnknown, BearerEthernet, BearerWLAN, Bearer2G,
  BearerCDMA2000, BearerWCDMA, BearerHSPA, BearerBluetooth,
  BearerWiMAX
}
 Specifies the type of bearer used by a configuration. More...
 
enum  Purpose { UnknownPurpose = 0, PublicPurpose, PrivatePurpose, ServiceSpecificPurpose }
 Specifies the purpose of the configuration. More...
 
enum  StateFlag { Undefined = 0x0000001, Defined = 0x0000002, Discovered = 0x0000006, Active = 0x000000e }
 Specifies the configuration states. More...
 
enum  Type { InternetAccessPoint = 0, ServiceNetwork, UserChoice, Invalid }
 This enum describes the type of configuration. More...
 

Public Functions

QT_DEPRECATED QString bearerName () const
 This function is deprecated. More...
 
BearerType bearerType () const
 Returns the type of bearer used by this network configuration. More...
 
QString bearerTypeName () const
 Returns the type of bearer used by this network configuration as a string. More...
 
QList< QNetworkConfigurationchildren () const
 Returns all sub configurations of this network configuration in priority order. More...
 
QString identifier () const
 Returns the unique and platform specific identifier for this network configuration; otherwise an empty string. More...
 
bool isRoamingAvailable () const
 Returns true if this configuration supports roaming; otherwise false. More...
 
bool isValid () const
 Returns true if this QNetworkConfiguration object is valid. More...
 
QString name () const
 Returns the user visible name of this configuration. More...
 
bool operator!= (const QNetworkConfiguration &other) const
 Returns true if this configuration is not the same as the other configuration given; otherwise returns false. More...
 
QNetworkConfigurationoperator= (const QNetworkConfiguration &other)
 Copies the content of the QNetworkConfiguration object contained in other into this one. More...
 
bool operator== (const QNetworkConfiguration &other) const
 Returns true, if this configuration is the same as the other configuration given; otherwise returns false. More...
 
Purpose purpose () const
 Returns the purpose of this configuration. More...
 
 QNetworkConfiguration ()
 Constructs an invalid configuration object. More...
 
 QNetworkConfiguration (const QNetworkConfiguration &other)
 Creates a copy of the QNetworkConfiguration object contained in other. More...
 
StateFlags state () const
 Returns the current state of the configuration. More...
 
Type type () const
 Returns the type of the configuration. More...
 
 ~QNetworkConfiguration ()
 Frees the resources associated with the QNetworkConfiguration object. More...
 

Properties

QExplicitlySharedDataPointer< QNetworkConfigurationPrivated
 

Friends

class QNetworkConfigurationManager
 
class QNetworkConfigurationManagerPrivate
 
class QNetworkConfigurationPrivate
 
class QNetworkSessionPrivate
 

Detailed Description

The QNetworkConfiguration class provides an abstraction of one or more access point configurations.

Since
4.7
Attention
Module: QtNetwork

QNetworkConfiguration encapsulates a single access point or service network. In most cases a single access point configuration can be mapped to one network interface. However a single network interface may not always map to only one access point configuration. Multiple configurations for the same network device may enable multiple access points. An example device that could exhibit such a configuration might be a Smartphone which allows the user to manage multiple WLAN configurations while the device itself has only one WLAN network device.

The QNetworkConfiguration also supports the concept of service networks. This concept allows the grouping of multiple access point configurations into one entity. Such a group is called service network and can be beneficial in cases whereby a network session to a particular destination network is required (e.g. a company network). When using a service network the user doesn't usually care which one of the connectivity options is chosen (e.g. corporate WLAN or VPN via GPRS) as long as he can reach the company's target server. Depending on the current position and time some of the access points that make up the service network may not even be available. Furthermore automated access point roaming can be enabled which enables the device to change the network interface configuration dynamically while maintaining the applications connection to the target network. It allows adaption to the changing environment and may enable optimization with regards to cost, speed or other network parameters.

Special configurations of type UserChoice provide a placeholder configuration which is resolved to an actual network configuration by the platform when a QNetworkSession{session} is QNetworkSession::open(){opened}. Not all platforms support the concept of a user choice configuration.

Configuration states

The list of available configurations can be obtained via QNetworkConfigurationManager::allConfigurations(). A configuration can have multiple states. The Defined configuration state indicates that the configuration is stored on the device. However the configuration is not yet ready to be activated as e.g. a WLAN may not be available at the current time.

The Discovered state implies that the configuration is Defined and the outside conditions are such that the configuration can be used immediately to open a new network session. An example of such an outside condition may be that the Ethernet cable is actually connected to the device or that the WLAN with the specified SSID is in range.

The Active state implies that the configuration is Discovered . A configuration in this state is currently being used by an application. The underlying network interface has a valid IP configuration and can transfer IP packets between the device and the target network.

The Undefined state indicates that the system has knowledge of possible target networks but cannot actually use that knowledge to connect to it. An example for such a state could be an encrypted WLAN that has been discovered but the user hasn't actually saved a configuration including the required password which would allow the device to connect to it.

Depending on the type of configuration some states are transient in nature. A GPRS/UMTS connection may almost always be Discovered if the GSM/UMTS network is available. However if the GSM/UMTS network looses the connection the associated configuration may change its state from Discovered to Defined as well. A similar use case might be triggered by WLAN availability. QNetworkConfigurationManager::updateConfigurations() can be used to manually trigger updates of states. Note that some platforms do not require such updates as they implicitly change the state once it has been discovered. If the state of a configuration changes all related QNetworkConfiguration instances change their state automatically.

See also
QNetworkSession, QNetworkConfigurationManager

Definition at line 71 of file qnetworkconfiguration.h.

Enumerations

◆ BearerType

Specifies the type of bearer used by a configuration.

  • BearerUnknown The type of bearer is unknown or unspecified. The bearerTypeName() function may return additional information.
  • BearerEthernet The configuration is for an Ethernet interfaces.
  • BearerWLAN The configuration is for a Wireless LAN interface.
  • Bearer2G The configuration is for a CSD, GPRS, HSCSD, EDGE or cdmaOne interface.
  • BearerCDMA2000 The configuration is for CDMA interface.
  • BearerWCDMA The configuration is for W-CDMA/UMTS interface.
  • BearerHSPA The configuration is for High Speed Packet Access (HSPA) interface.
  • BearerBluetooth The configuration is for a Bluetooth interface.
  • BearerWiMAX The configuration is for a WiMAX interface.
Enumerator
BearerUnknown 
BearerEthernet 
BearerWLAN 
Bearer2G 
BearerCDMA2000 
BearerWCDMA 
BearerHSPA 
BearerBluetooth 
BearerWiMAX 

Definition at line 106 of file qnetworkconfiguration.h.

◆ Purpose

Specifies the purpose of the configuration.

  • UnknownPurpose The configuration doesn't specify any purpose. This is the default value.
  • PublicPurpose The configuration can be used for general purpose internet access.
  • PrivatePurpose The configuration is suitable to access a private network such as an office Intranet.
  • ServiceSpecificPurpose The configuration can be used for operator specific services (e.g. receiving MMS messages or content streaming).
Enumerator
UnknownPurpose 
PublicPurpose 
PrivatePurpose 
ServiceSpecificPurpose 

Definition at line 90 of file qnetworkconfiguration.h.

◆ StateFlag

Specifies the configuration states.

  • Undefined This state is used for transient configurations such as newly discovered WLANs for which the user has not actually created a configuration yet.
  • Defined Defined configurations are known to the system but are not immediately usable (e.g. a configured WLAN is not within range or the Ethernet cable is currently not plugged into the machine).
  • Discovered A discovered configuration can be immediately used to create a new QNetworkSession. An example of a discovered configuration could be a WLAN which is within in range. If the device moves out of range the discovered flag is dropped. A second example is a GPRS configuration which generally remains discovered for as long as the device has network coverage. A configuration that has this state is also in state QNetworkConfiguration::Defined. If the configuration is a service network this flag is set if at least one of the underlying access points configurations has the Discovered state.
  • Active The configuration is currently used by an open network session (see QNetworkSession::isOpen()) . However this does not mean that the current process is the entity that created the open session. It merely indicates that if a new QNetworkSession were to be constructed based on this configuration QNetworkSession::state() would return QNetworkSession::Connected . This state implies the QNetworkConfiguration::Discovered state.
Enumerator
Undefined 
Defined 
Discovered 
Active 

Definition at line 97 of file qnetworkconfiguration.h.

◆ Type

This enum describes the type of configuration.

  • InternetAccessPoint The configuration specifies the details for a single access point. Note that configurations of type InternetAccessPoint may be part of other QNetworkConfigurations of type ServiceNetwork.
  • ServiceNetwork The configuration is based on a group of QNetworkConfigurations of type InternetAccessPoint. All group members can reach the same target network. This type of configuration is a mandatory requirement for roaming enabled network sessions. On some platforms this form of configuration may also be called Service Network Access Point (SNAP).
  • UserChoice The configuration is a placeholder which will be resolved to an actual configuration by the platform when a session is opened. Depending on the platform the selection may generate a popup dialog asking the user for his preferred choice.
  • Invalid The configuration is invalid.
Enumerator
InternetAccessPoint 
ServiceNetwork 
UserChoice 
Invalid 

Definition at line 83 of file qnetworkconfiguration.h.

Constructors and Destructors

◆ QNetworkConfiguration() [1/2]

QNetworkConfiguration::QNetworkConfiguration ( )

Constructs an invalid configuration object.

See also
isValid()

Definition at line 222 of file qnetworkconfiguration.cpp.

223  : d(0)
224 {
225 }
QExplicitlySharedDataPointer< QNetworkConfigurationPrivate > d

◆ QNetworkConfiguration() [2/2]

QNetworkConfiguration::QNetworkConfiguration ( const QNetworkConfiguration other)

Creates a copy of the QNetworkConfiguration object contained in other.

Definition at line 230 of file qnetworkconfiguration.cpp.

231  : d(other.d)
232 {
233 }
QExplicitlySharedDataPointer< QNetworkConfigurationPrivate > d

◆ ~QNetworkConfiguration()

QNetworkConfiguration::~QNetworkConfiguration ( )

Frees the resources associated with the QNetworkConfiguration object.

Definition at line 238 of file qnetworkconfiguration.cpp.

239 {
240 }

Functions

◆ bearerName()

QString QNetworkConfiguration::bearerName ( ) const
inline

This function is deprecated.

It is equivalent to calling bearerTypeName(), however bearerType() should be used in preference.

Definition at line 126 of file qnetworkconfiguration.h.

126 { return bearerTypeName(); }
QString bearerTypeName() const
Returns the type of bearer used by this network configuration as a string.

◆ bearerType()

QNetworkConfiguration::BearerType QNetworkConfiguration::bearerType ( ) const

Returns the type of bearer used by this network configuration.

If the bearer type is QNetworkConfiguration::BearerUnknown{unknown} the bearerTypeName() function can be used to retrieve a textural type name for the bearer.

An invalid network configuration always returns the BearerUnknown value.

Definition at line 436 of file qnetworkconfiguration.cpp.

Referenced by qHash().

437 {
438  if (!isValid())
439  return BearerUnknown;
440 
441  QMutexLocker locker(&d->mutex);
442 
443  return d->bearerType;
444 }
QExplicitlySharedDataPointer< QNetworkConfigurationPrivate > d
QNetworkConfiguration::BearerType bearerType
bool isValid() const
Returns true if this QNetworkConfiguration object is valid.
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ bearerTypeName()

QString QNetworkConfiguration::bearerTypeName ( ) const

Returns the type of bearer used by this network configuration as a string.

The string is not translated and therefore can not be shown to the user. The subsequent table shows the fixed mappings between BearerType and the bearer type name for known types. If the BearerType is unknown this function may return additional information if it is available; otherwise an empty string will be returned.

BearerType Value
BearerUnknown The session is based on an unknown or unspecified bearer type. The value of the string returned describes the bearer type.
BearerEthernet Ethernet
BearerWLAN WLAN
Bearer2G 2G
BearerCDMA2000 CDMA2000
BearerWCDMA WCDMA
BearerHSPA HSPA
BearerBluetooth Bluetooth
BearerWiMAX WiMAX

This function returns an empty string if this is an invalid configuration, a network configuration of type QNetworkConfiguration::ServiceNetwork or QNetworkConfiguration::UserChoice .

See also
bearerType()

Definition at line 494 of file qnetworkconfiguration.cpp.

495 {
496  if (!isValid())
497  return QString();
498 
499  QMutexLocker locker(&d->mutex);
500 
503  return QString();
504 
505  switch (d->bearerType) {
506  case BearerUnknown:
507  return d->bearerTypeName();
508  case BearerEthernet:
509  return QLatin1String("Ethernet");
510  case BearerWLAN:
511  return QLatin1String("WLAN");
512  case Bearer2G:
513  return QLatin1String("2G");
514  case BearerCDMA2000:
515  return QLatin1String("CDMA2000");
516  case BearerWCDMA:
517  return QLatin1String("WCDMA");
518  case BearerHSPA:
519  return QLatin1String("HSPA");
520  case BearerBluetooth:
521  return QLatin1String("Bluetooth");
522  case BearerWiMAX:
523  return QLatin1String("WiMAX");
524  }
525 
526  return QLatin1String("Unknown");
527 }
QExplicitlySharedDataPointer< QNetworkConfigurationPrivate > d
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QNetworkConfiguration::BearerType bearerType
bool isValid() const
Returns true if this QNetworkConfiguration object is valid.
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QNetworkConfiguration::Type type
virtual QString bearerTypeName() const

◆ children()

QList< QNetworkConfiguration > QNetworkConfiguration::children ( ) const

Returns all sub configurations of this network configuration in priority order.

The first sub configuration in the list has the highest priority.

Only network configurations of type ServiceNetwork can have children. Otherwise this function returns an empty list.

Definition at line 381 of file qnetworkconfiguration.cpp.

Referenced by QNetworkSessionManagerPrivate::forceSessionClose(), and QNetworkSessionPrivateImpl::updateStateFromServiceNetwork().

382 {
384 
385  if (!d)
386  return results;
387 
388  QMutexLocker locker(&d->mutex);
389 
391  return results;
392 
393  QMutableMapIterator<unsigned int, QNetworkConfigurationPrivatePointer> i(d->serviceNetworkMembers);
394  while (i.hasNext()) {
395  i.next();
396 
398 
399  //if we have an invalid member get rid of it -> was deleted earlier on
400  {
401  QMutexLocker childLocker(&p->mutex);
402 
403  if (!p->isValid) {
404  i.remove();
405  continue;
406  }
407  }
408 
410  item.d = p;
411  results << item;
412  }
413 
414  return results;
415 }
QExplicitlySharedDataPointer< QNetworkConfigurationPrivate > d
QMap< unsigned int, QNetworkConfigurationPrivatePointer > serviceNetworkMembers
The QNetworkConfiguration class provides an abstraction of one or more access point configurations...
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QNetworkConfiguration::Type type
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ identifier()

QString QNetworkConfiguration::identifier ( ) const

Returns the unique and platform specific identifier for this network configuration; otherwise an empty string.

Definition at line 289 of file qnetworkconfiguration.cpp.

Referenced by QNetworkAccessManagerPrivate::_q_networkSessionClosed(), QNetworkSessionPrivateImpl::close(), QNetworkSessionPrivateImpl::do_open(), QNetworkSessionPrivateImpl::getStatistics(), QNetworkSessionPrivateImpl::iapStateChanged(), QNetworkSession::QNetworkSession(), QNetworkSession::sessionProperty(), QNetworkSessionPrivateImpl::stateChange(), QNetworkSessionPrivateImpl::stop(), and QNetworkSessionPrivateImpl::syncStateWithInterface().

290 {
291  if (!d)
292  return QString();
293 
294  QMutexLocker locker(&d->mutex);
295  return d->id;
296 }
QExplicitlySharedDataPointer< QNetworkConfigurationPrivate > d
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ isRoamingAvailable()

bool QNetworkConfiguration::isRoamingAvailable ( ) const

Returns true if this configuration supports roaming; otherwise false.

Definition at line 365 of file qnetworkconfiguration.cpp.

366 {
367  if (!d)
368  return false;
369 
370  QMutexLocker locker(&d->mutex);
371  return d->roamingSupported;
372 }
QExplicitlySharedDataPointer< QNetworkConfigurationPrivate > d
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ isValid()

bool QNetworkConfiguration::isValid ( ) const

Returns true if this QNetworkConfiguration object is valid.

A configuration may become invalid if the user deletes the configuration or the configuration was default-constructed.

The addition and removal of configurations can be monitored via the QNetworkConfigurationManager.

See also
QNetworkConfigurationManager

Definition at line 325 of file qnetworkconfiguration.cpp.

Referenced by bearerType(), bearerTypeName(), QNetworkSessionPrivateImpl::close(), QNetworkAccessManagerPrivate::createSession(), QNetworkSessionPrivateImpl::currentInterface(), QNetworkSessionPrivateImpl::networkConfigurationsChanged(), QNetworkSessionPrivateImpl::open(), QNetworkSession::sessionProperty(), QNetworkAccessBackend::start(), QNetworkSessionPrivateImpl::stop(), QNetworkSessionPrivateImpl::syncStateWithInterface(), QNetworkSessionPrivateImpl::updateState(), and QNetworkSessionPrivateImpl::updateStateFromActiveConfig().

326 {
327  if (!d)
328  return false;
329 
330  QMutexLocker locker(&d->mutex);
331  return d->isValid;
332 }
QExplicitlySharedDataPointer< QNetworkConfigurationPrivate > d
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ name()

QString QNetworkConfiguration::name ( ) const

Returns the user visible name of this configuration.

The name may either be the name of the underlying access point or the name for service network that this configuration represents.

Definition at line 276 of file qnetworkconfiguration.cpp.

Referenced by QNetworkProxyFactory::systemProxyForQuery().

277 {
278  if (!d)
279  return QString();
280 
281  QMutexLocker locker(&d->mutex);
282  return d->name;
283 }
QExplicitlySharedDataPointer< QNetworkConfigurationPrivate > d
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ operator!=()

bool QNetworkConfiguration::operator!= ( const QNetworkConfiguration other) const
inline

Returns true if this configuration is not the same as the other configuration given; otherwise returns false.

Definition at line 80 of file qnetworkconfiguration.h.

81  { return !operator==(other); }
bool operator==(const QNetworkConfiguration &other) const
Returns true, if this configuration is the same as the other configuration given; otherwise returns f...

◆ operator=()

QNetworkConfiguration & QNetworkConfiguration::operator= ( const QNetworkConfiguration other)

Copies the content of the QNetworkConfiguration object contained in other into this one.

Definition at line 245 of file qnetworkconfiguration.cpp.

246 {
247  d = other.d;
248  return *this;
249 }
QExplicitlySharedDataPointer< QNetworkConfigurationPrivate > d

◆ operator==()

bool QNetworkConfiguration::operator== ( const QNetworkConfiguration other) const

Returns true, if this configuration is the same as the other configuration given; otherwise returns false.

Definition at line 255 of file qnetworkconfiguration.cpp.

256 {
257  return (d == other.d);
258 }
QExplicitlySharedDataPointer< QNetworkConfigurationPrivate > d

◆ purpose()

QNetworkConfiguration::Purpose QNetworkConfiguration::purpose ( ) const

Returns the purpose of this configuration.

The purpose field may be used to programmatically determine the purpose of a configuration. Such information is usually part of the access point or service network meta data.

Definition at line 353 of file qnetworkconfiguration.cpp.

Referenced by qHash().

354 {
355  if (!d)
357 
358  QMutexLocker locker(&d->mutex);
359  return d->purpose;
360 }
QExplicitlySharedDataPointer< QNetworkConfigurationPrivate > d
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QNetworkConfiguration::Purpose purpose

◆ state()

QNetworkConfiguration::StateFlags QNetworkConfiguration::state ( ) const

Returns the current state of the configuration.

Definition at line 337 of file qnetworkconfiguration.cpp.

Referenced by QNetworkSessionPrivateImpl::close(), QNetworkSessionPrivateImpl::finishStopBySendingClosedSignal(), QNetworkSessionManagerPrivate::forceSessionClose(), QNetworkSessionPrivateImpl::open(), QNetworkSessionPrivateImpl::stop(), QNetworkSessionPrivateImpl::updateStateFromActiveConfig(), and QNetworkSessionPrivateImpl::updateStateFromServiceNetwork().

338 {
339  if (!d)
341 
342  QMutexLocker locker(&d->mutex);
343  return d->state;
344 }
QExplicitlySharedDataPointer< QNetworkConfigurationPrivate > d
QNetworkConfiguration::StateFlags state
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ type()

QNetworkConfiguration::Type QNetworkConfiguration::type ( ) const

Returns the type of the configuration.

A configuration can represent a single access point configuration or a set of access point configurations. Such a set is called service network. A configuration that is based on a service network can potentially support roaming of network sessions.

Definition at line 306 of file qnetworkconfiguration.cpp.

Referenced by QNetworkSessionPrivateImpl::connectTimeout(), QNetworkSessionPrivateImpl::do_open(), QNetworkSessionPrivateImpl::iapStateChanged(), QNetworkSessionPrivateImpl::open(), qHash(), QNetworkSession::sessionProperty(), QNetworkSessionPrivateImpl::stateChange(), QNetworkSessionPrivateImpl::syncStateWithInterface(), QNetworkProxyFactory::systemProxyForQuery(), QNetworkSessionPrivateImpl::updateIdentifier(), and QNetworkSessionPrivateImpl::updateState().

307 {
308  if (!d)
310 
311  QMutexLocker locker(&d->mutex);
312  return d->type;
313 }
QExplicitlySharedDataPointer< QNetworkConfigurationPrivate > d
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QNetworkConfiguration::Type type

Friends and Related Functions

◆ QNetworkConfigurationManager

Definition at line 143 of file qnetworkconfiguration.h.

◆ QNetworkConfigurationManagerPrivate

Definition at line 144 of file qnetworkconfiguration.h.

◆ QNetworkConfigurationPrivate

Definition at line 142 of file qnetworkconfiguration.h.

◆ QNetworkSessionPrivate

Definition at line 145 of file qnetworkconfiguration.h.

Properties

◆ d


The documentation for this class was generated from the following files: