Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

QNetworkSession Class Reference
[QtNetwork module]

The QNetworkSession class provides control over the system's access points and enables session management for cases when multiple clients access the same access point. More...

    #include <QNetworkSession>

This class is not part of the Qt GUI Framework Edition.

Inherits QObject.


Public Types

enum SessionError { UnknownSessionError, SessionAbortedError, RoamingError, OperationNotSupportedError, InvalidConfigurationError }
enum State { Invalid, NotAvailable, Connecting, Connected, ..., Roaming }

Public Functions

QNetworkSession ( const QNetworkConfiguration & connectionConfig, QObject * parent = 0 )
virtual ~QNetworkSession ()
quint64 activeTime () const
QString bearerName () const
quint64 bytesReceived () const
quint64 bytesWritten () const
QNetworkConfiguration configuration () const
SessionError error () const
QString errorString () const
QNetworkInterface interface () const
bool isActive () const
QVariant sessionProperty ( const QString & key ) const
void setSessionProperty ( const QString & key, const QVariant & value )
State state () const
bool waitForOpened ( int msecs = 30000 )
  • 29 public functions inherited from QObject

Public Slots

void accept ()
void close ()
void ignore ()
void migrate ()
void open ()
void reject ()
void stop ()
  • 1 public slot inherited from QObject

Signals

void closed ()
void error ( QNetworkSession::SessionError error )
void newConfigurationActivated ()
void opened ()
void preferredConfigurationChanged ( const QNetworkConfiguration & config, bool isSeamless )
void stateChanged ( QNetworkSession::State state )

Additional Inherited Members

  • 1 property inherited from QObject
  • 1 public type inherited from QObject
  • 4 static public members inherited from QObject
  • 7 protected functions inherited from QObject
  • 2 protected variables inherited from QObject

Detailed Description

The QNetworkSession class provides control over the system's access points and enables session management for cases when multiple clients access the same access point.

A QNetworkSession enables control over the system's network interfaces. The session's configuration parameter are determined via the QNetworkConfiguration object to which it is bound. Depending on the type of the session (single access point or service network) a session may be linked to one or more network interfaces. By means of opening and closing of network sessions a developer can start and stop the systems network interfaces. If the configuration represents multiple access points (see QNetworkConfiguration::ServiceNetwork) more advanced features such as roaming may be supported.

QNetworkSession supports session management within the same process and depending on the platform's capabilities may support out-of-process sessions. If the same network configuration is used by multiple active sessions the underlying network interface is only terminated once the last session has been closed.

Roaming

Applications may connect to the preferredConfigurationChanged() signal in order to receive notifications when a more suitable access point becomes available. In response to this signal the application may initiate the roaming via migrate() or may ignore() the new access point. Once the session has roamed the newConfigurationActivated() signal is emitted. The application may now test the carrier and can accept() or reject() it. The session will return to the previous access point if the roaming was rejected.

Some platforms may support the notion of forced roaming and application level roaming (ALR). ALR implies that the application controls (via migrate(), ignore(), accept() and reject()) whether a network session can roam from one network configuration to the next. Such control is useful if the application maintains stateful socket connections and wants to control the transition from one interface to the next.

Forced roaming implies that the system automatically roams to the next network without consulting the application. This has the advantage that the application can make use of roaming features without actually being aware of it. It is expected that the application detects that the underlying socket is broken and automatically reconnects via the new network link.

If the platform supports both modes of roaming an application indicates its preference by connecting to the preferredConfigurationChanged() signal. Connecting to this signal means that the application wants to take control over the roaming behavior and therefore implies application level roaming.

See also QNetworkConfiguration and QNetworkConfigurationManager.


Member Type Documentation

enum QNetworkSession::SessionError

This enum describes the session errors that can occur.

ConstantValueDescription
QNetworkSession::UnknownSessionError0An unidentified error occurred.
QNetworkSession::SessionAbortedError1The session was aborted by the user or system.
QNetworkSession::RoamingError2The session cannot roam to the new configuration.
QNetworkSession::OperationNotSupportedError3The operation is not supported for current configuration.
QNetworkSession::InvalidConfigurationError4The operation cannot currently be performed for the current configuration.

enum QNetworkSession::State

This enum describes the connectivity state of the session. If the session is based on a single access point configuration the state of the session is the same as the state of the associated network interface.

ConstantValueDescription
QNetworkSession::Invalid0The session is invalid due to an invalid configuration. This may happen due to a removed access point or a configuration that was invalid to begin with.
QNetworkSession::NotAvailable1The session is based on a defined but not yet discovered QNetworkConfiguration (see QNetworkConfiguration::StateFlag).
QNetworkSession::Connecting2The network session is being established.
QNetworkSession::Connected3The network session is connected. If the current process wishes to use this session it has to register its interest by calling open(). A network session is considered to be ready for socket operations if it isActive() and connected.
QNetworkSession::Closing4The network session is in the process of being shut down.
QNetworkSession::Disconnected5The network session is not connected. The associated QNetworkConfiguration has the state QNetworkConfiguration::Discovered.
QNetworkSession::Roaming6The network session is roaming from one access point to another access point.


Member Function Documentation

QNetworkSession::QNetworkSession ( const QNetworkConfiguration & connectionConfig, QObject * parent = 0 )

Constructs a session based on connectionConfig with the given parent.

See also QNetworkConfiguration.

QNetworkSession::~QNetworkSession ()   [virtual]

Frees the resources associated with the QNetworkSession object.

void QNetworkSession::accept ()   [slot]

Instructs the session to permanently accept the new access point. Once this function has been called the session may not return to the old access point.

The old access point may be closed in the process if there are no other network sessions for it. Therefore any open socket that still uses the old access point may become unusable and should be closed before completing the migration.

quint64 QNetworkSession::activeTime () const

Returns the number of seconds that the session has been active.

QString QNetworkSession::bearerName () const

Returns the type of bearer currently used by this session. The string is not translated and therefore can not be shown to the user. The subsequent table presents the currently known bearer types:

ValueDescription
EthernetThe session is based on Ethernet.
WLANThe session is based on Wireless LAN.
2GThe session uses CSD, GPRS, HSCSD, EDGE or cdmaOne.
CDMA2000The session uses CDMA.
WCDMAThe session uses W-CDMA/UMTS.
HSPAThe session uses High Speed Packet Access.
BluetoothThe session uses Bluetooth.
WiMAXThe session uses WiMAX.

If the session is based on a network configuration of type QNetworkConfiguration::ServiceNetwork the type of the preferred or currently active configuration is returned. Therefore the bearer type may change over time.

This function returns an empty string if this session is based on an invalid configuration.

quint64 QNetworkSession::bytesReceived () const

Returns the amount of data received in bytes; otherwise 0.

This field value includes the usage across all active network sessions which use the same network interface.

If the session is based on a service network configuration the number of sent bytes across all active member configurations are returned.

This function may not always be supported on all platforms and returns 0. The platform capability can be detected via QNetworkConfigurationManager::DataStatistics.

quint64 QNetworkSession::bytesWritten () const

Returns the amount of data sent in bytes; otherwise 0.

This field value includes the usage across all active network sessions which use the same network interface.

If the session is based on a service network configuration the number of sent bytes across all active member configurations are returned.

This function may not always be supported on all platforms and returns 0. The platform capability can be detected via QNetworkConfigurationManager::DataStatistics.

void QNetworkSession::close ()   [slot]

Decreases the session counter on the associated network configuration. If the session counter reaches zero the active network interface is shut down. This also means that state() will only change from Connected to Disconnected if this was the last active session.

If the platform does not support out-of-process sessions calling this function does not stop the interface. In this case stop() has to be used to force a shut down. The platform capabilities can be detected via QNetworkConfigurationManager::capabilities().

Note that this call is asynchronous. Depending on the outcome of this call the results can be enquired by connecting to the stateChanged(), opened() or error() signals.

See also open(), stop(), and isActive().

void QNetworkSession::closed ()   [signal]

This signal is emitted when the network session has been closed.

QNetworkConfiguration QNetworkSession::configuration () const

Returns the QNetworkConfiguration that this network session object is based on.

See also QNetworkConfiguration.

SessionError QNetworkSession::error () const

Returns the type of error that last occurred.

See also state() and errorString().

void QNetworkSession::error ( QNetworkSession::SessionError error )   [signal]

This signal is emitted after an error occurred. The error parameter describes the error that occurred.

See also error() and errorString().

QString QNetworkSession::errorString () const

Returns a human-readable description of the last device error that occurred.

See also error().

void QNetworkSession::ignore ()   [slot]

This function indicates that the application does not wish to roam the session. This is the default behavior if an application doesn't call migrate() in response to a preferredConfigurationChanged() signal.

See also migrate().

QNetworkInterface QNetworkSession::interface () const

Returns the network interface that is used by this session.

This function only returns a valid QNetworkInterface when this session is Connected.

The returned interface may change as a result of a roaming process.

See also state().

bool QNetworkSession::isActive () const

Returns true if this object holds an active session on the underlying network interface. The session can be controlled via open() and close().

void QNetworkSession::migrate ()   [slot]

Instructs the session to roam to the new access point. The old access point remains active until the application calls accept().

The newConfigurationActivated() signal is emitted once roaming has been completed.

See also accept().

void QNetworkSession::newConfigurationActivated ()   [signal]

This signal is emitted once the session has roamed to the new access point. The application may reopen its socket and test the suitability of the new network link. Subsequently it may accept() or reject() the new access point.

See also accept() and reject().

void QNetworkSession::open ()   [slot]

Creates an active/open session which increases the session counter on the underlying network interface. The system will not terminate a network interface until the session reference counter reaches zero. Therefore an active session allows an application to register its use of the interface.

The interface is started if it is not active yet. Some platforms may not provide support for out-of-process sessions. On such platforms the session counter ignores any sessions held by another process. The platform capabilities can be detected via QNetworkConfigurationManager::capabilities().

Note that this call is asynchronous. Depending on the outcome of this call the results can be enquired by connecting to the stateChanged(), opened() or error() signals.

It is not a requirement to open a session in order to monitor the underlying network interface.

See also close(), stop(), and isActive().

void QNetworkSession::opened ()   [signal]

This signal is emitted when the network session has been opened.

The underlying network interface will not be shut down as long as the session remains open. Note that this feature is dependent on system wide session support.

void QNetworkSession::preferredConfigurationChanged ( const QNetworkConfiguration & config, bool isSeamless )   [signal]

This signal is emitted when the preferred configuration/access point for the session changes. Only sessions which are based on service network configurations may emit this signal. config can be used to determine access point specific details such as proxy settings and isSeamless indicates whether roaming will break the sessions IP address.

As a consequence to this signal the application may start the roaming process by calling migrate() or may chose to ignore() the new access point. If the application doesn't call either of the two functions the session ignores the migration opportunity.

If the roaming process is non-seamless the IP address will change which means that a socket becomes invalid. However seamless mobility can ensure that the local IP address does not change. This is achieved by using a virtual IP address which is bound to the actual link address. During the roaming process the virtual address is attached to the new link address.

Some platforms may support the concept of Forced Roaming and Application Level Roaming (ALR). Forced roaming implies that the platform may simply roam to a new configuration without consulting applications. It is up to the application to detect the link layer loss and reestablish its sockets. In contrast ALR provides the opportunity to prevent the system from roaming. If this session is based on a configuration that supports roaming the application can choose whether it wants to be consulted (ALR use case) by connecting to this signal. For as long as this signal connection remains the session remains registered as a roaming stakeholder; otherwise roaming will be enforced by the platform.

See also migrate(), ignore(), and QNetworkConfiguration::isRoamingAvailable().

void QNetworkSession::reject ()   [slot]

The new access point is not suitable for the application. By calling this function the session returns to the previous access point/configuration. This action may invalidate any socket that has been created via the not desired access point.

See also accept().

QVariant QNetworkSession::sessionProperty ( const QString & key ) const

Returns the value for property key.

A network session can have properties attached which may describe the session in more details. This function can be used to gain access to those properties.

The following property keys are guaranteed to be specified on all platforms:

KeyDescription
ActiveConfigurationIdentifierIf the session isActive() this property returns the identifier of the QNetworkConfiguration that is used by this session; otherwise an empty string.

The main purpose of this key is to determine which Internet access point is used if the session is based on a ServiceNetwork. The following code snippet highlights the difference:

    QNetworkConfigurationManager mgr;
    QNetworkConfiguration ap = mgr.defaultConfiguration();
    QNetworkSession* session = new QNetworkSession(ap);
    ... //code activates session

    QString ident = session->sessionProperty("ActiveConfigurationIdentifier").toString();
    if ( ap.type() == QNetworkConfiguration::ServiceNetwork ) {
        Q_ASSERT( ap.identifier() != ident );
        Q_ASSERT( ap.children().contains( mgr.configurationFromIdentifier(ident) ) );
    } else if ( ap.type() == QNetworkConfiguration::InternetAccessPoint ) {
        Q_ASSERT( ap.identifier() == ident );
    }
UserChoiceConfigurationIdentifierIf the session isActive() and is bound to a QNetworkConfiguration of type UserChoice, this property returns the identifier of the QNetworkConfiguration that the configuration resolved to when open() was called; otherwise an empty string.

The purpose of this key is to determine the real QNetworkConfiguration that the session is using. This key is different to ActiveConfigurationIdentifier in that this key may return an identifier for either a service network or a Internet access points configurations whereas ActiveConfigurationIdentifier always returns identifiers for Internet access points configurations.

ConnectInBackgroundSetting this property to true before calling open() implies that the connection attempt is made but if no connection can be established, the user is not connsulted and asked to select a suitable connection. This property is not set by default and support for it depends on the platform.

See also setSessionProperty().

void QNetworkSession::setSessionProperty ( const QString & key, const QVariant & value )

Sets the property value on the session. The property is identified using key. Removing an already set property can be achieved by passing an invalid QVariant.

Note that the UserChoiceConfigurationIdentifier and ActiveConfigurationIdentifier properties are read only and cannot be changed using this method.

See also sessionProperty().

State QNetworkSession::state () const

Returns the state of the session. If the session is based on a single access point configuration the state of the session is the same as the state of the associated network interface. Therefore a network session object can be used to monitor network interfaces.

A QNetworkConfiguration::ServiceNetwork based session summarizes the state of all its children and therefore returns the Connected state if at least one of its sub configurations is connected.

Note that it is not required to hold an active session in order to obtain the network interface state. A connected but inactive session may be used to monitor network interfaces whereas an active and connected session object may prevent the network interface from being shut down.

See also error() and stateChanged().

void QNetworkSession::stateChanged ( QNetworkSession::State state )   [signal]

This signal is emitted whenever the state of the network session changes. The state parameter is the new state.

See also state().

void QNetworkSession::stop ()   [slot]

Invalidates all active sessions against the network interface and therefore stops the underlying network interface. This function always changes the session's state() flag to Disconnected.

See also open() and close().

bool QNetworkSession::waitForOpened ( int msecs = 30000 )

Waits until the session has been opened, up to msecs milliseconds. If the session has been opened, this function returns true; otherwise it returns false. In the case where it returns false, you can call error() to determine the cause of the error.

The following example waits up to one second for the session to be opened:

    session->open();
    if (session->waitForOpened(1000))
        qDebug("Open!");

If msecs is -1, this function will not time out.

See also open() and error().

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt qtmobility-1.0-tp
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web