qtmobility/src/bearer/qnetworksession.cpp
changeset 0 cfcbf08528c4
child 2 5822d84012fb
child 4 90517678cc4f
equal deleted inserted replaced
-1:000000000000 0:cfcbf08528c4
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include <QEventLoop>
       
    43 #include <QTimer>
       
    44 
       
    45 #include "qnetworksession.h"
       
    46 
       
    47 #ifdef Q_OS_SYMBIAN
       
    48 #include "qnetworksession_s60_p.h"
       
    49 #elif Q_WS_MAEMO_6
       
    50 #include "qnetworksession_maemo_p.h"
       
    51 #else
       
    52 #include "qnetworksession_p.h"
       
    53 #endif
       
    54 
       
    55 QTM_BEGIN_NAMESPACE
       
    56 
       
    57 /*!
       
    58     \class QNetworkSession
       
    59 
       
    60     \brief The QNetworkSession class provides control over the system's access points
       
    61     and enables session management for cases when multiple clients access the same access point.
       
    62 
       
    63     \inmodule QtNetwork
       
    64     \ingroup bearer
       
    65 
       
    66     A QNetworkSession enables control over the system's network interfaces. The session's configuration
       
    67     parameter are determined via the QNetworkConfiguration object to which it is bound. Depending on the 
       
    68     type of the session (single access point or service network) a session may be linked to one or more
       
    69     network interfaces. By means of \l{open()}{opening} and \l{close()}{closing} of network sessions 
       
    70     a developer can start and stop the systems network interfaces. If the configuration represents 
       
    71     multiple access points (see \l QNetworkConfiguration::ServiceNetwork) more advanced features such as roaming may be supported.
       
    72 
       
    73     QNetworkSession supports session management within the same process and depending on the platform's 
       
    74     capabilities may support out-of-process sessions. If the same 
       
    75     network configuration is used by multiple open sessions the underlying network interface is only terminated once
       
    76     the last session has been closed.
       
    77 
       
    78     \section1 Roaming
       
    79 
       
    80     Applications may connect to the preferredConfigurationChanged() signal in order to 
       
    81     receive notifications when a more suitable access point becomes available. 
       
    82     In response to this signal the application must either initiate the roaming via migrate()
       
    83     or ignore() the new access point. Once the session has roamed the 
       
    84     newConfigurationActivated() signal is emitted. The application may now test the 
       
    85     carrier and must either accept() or reject() it. The session will return to the previous
       
    86     access point if the roaming was rejected. The subsequent state diagram depicts the required
       
    87     state transitions.
       
    88     
       
    89     \image roaming-states.png
       
    90 
       
    91     Some platforms may distinguish forced roaming and application level roaming (ALR). 
       
    92     ALR implies that the application controls (via migrate(), ignore(), accept() and reject()) 
       
    93     whether a network session can roam from one access point to the next. Such control is useful
       
    94     if the application maintains stateful socket connections and wants to control the transition from
       
    95     one interface to the next. Forced roaming implies that the system automatically roams to the next network without 
       
    96     consulting the application. This has the advantage that the application can make use of roaming features
       
    97     without actually being aware of it. It is expected that the application detects that the underlying 
       
    98     socket is broken and automatically reconnects via the new network link.
       
    99 
       
   100     If the platform supports both modes of roaming, an application indicates its preference
       
   101     by connecting to the preferredConfigurationChanged() signal. Connecting to this signal means that
       
   102     the application wants to take control over the roaming behavior and therefore implies application
       
   103     level roaming. If the client does not connect to the preferredConfigurationChanged(), forced roaming
       
   104     is used. If forced roaming is not supported the network session will not roam by default.
       
   105 
       
   106     Some applications may want to suppress any form of roaming altogether. Possible use cases may be 
       
   107     high priority downloads or remote services which cannot handle a roaming enabled client. Clients
       
   108     can suppress roaming by connecting to the preferredConfigurationChanged() signal and answer each
       
   109     signal emission with ignore().
       
   110 
       
   111     \sa QNetworkConfiguration, QNetworkConfigurationManager
       
   112 */
       
   113 
       
   114 /*!
       
   115     \enum QNetworkSession::State
       
   116 
       
   117     This enum describes the connectivity state of the session. If the session is based on a
       
   118     single access point configuration the state of the session is the same as the state of the
       
   119     associated network interface.
       
   120 
       
   121     \value Invalid          The session is invalid due to an invalid configuration. This may 
       
   122                             happen due to a removed access point or a configuration that was 
       
   123                             invalid to begin with.
       
   124     \value NotAvailable     The session is based on a defined but not yet discovered QNetworkConfiguration
       
   125                             (see \l QNetworkConfiguration::StateFlag).
       
   126     \value Connecting       The network session is being established.
       
   127     \value Connected        The network session is connected. If the current process wishes to use this session
       
   128                             it has to register its interest by calling open(). A network session 
       
   129                             is considered to be ready for socket operations if it isOpen() and connected.
       
   130     \value Closing          The network session is in the process of being shut down.
       
   131     \value Disconnected     The network session is not connected. The associated QNetworkConfiguration
       
   132                             has the state QNetworkConfiguration::Discovered.
       
   133     \value Roaming          The network session is roaming from one access point to another 
       
   134                             access point.
       
   135 */
       
   136 
       
   137 /*!
       
   138     \enum QNetworkSession::SessionError
       
   139 
       
   140     This enum describes the session errors that can occur.
       
   141 
       
   142     \value UnknownSessionError          An unidentified error occurred.
       
   143     \value SessionAbortedError          The session was aborted by the user or system.
       
   144     \value RoamingError                 The session cannot roam to a new configuration.
       
   145     \value OperationNotSupportedError   The operation is not supported for current configuration.
       
   146     \value InvalidConfigurationError    The operation cannot currently be performed for the
       
   147                                         current configuration.
       
   148 */
       
   149 
       
   150 /*!
       
   151     \fn void QNetworkSession::stateChanged(QNetworkSession::State state)
       
   152 
       
   153     This signal is emitted whenever the state of the network session changes.
       
   154     The \a state parameter is the new state.
       
   155 
       
   156     \sa state()
       
   157 */
       
   158 
       
   159 /*!
       
   160     \fn void QNetworkSession::error(QNetworkSession::SessionError error)
       
   161 
       
   162     This signal is emitted after an error occurred. The \a error parameter
       
   163     describes the error that occurred.
       
   164 
       
   165     \sa error(), errorString()
       
   166 */
       
   167 
       
   168 /*!
       
   169     \fn void QNetworkSession::preferredConfigurationChanged(const QNetworkConfiguration& config, bool isSeamless)
       
   170 
       
   171     This signal is emitted when the preferred configuration/access point for the
       
   172     session changes. Only sessions which are based on service network configurations
       
   173     may emit this signal. \a config can be used to determine access point specific
       
   174     details such as proxy settings and \a isSeamless indicates whether roaming will
       
   175     break the sessions IP address.
       
   176 
       
   177     As a consequence to this signal the application must either start the roaming process
       
   178     by calling migrate() or choose to ignore() the new access point.
       
   179 
       
   180     If the roaming process is non-seamless the IP address will change which means that
       
   181     a socket becomes invalid. However seamless mobility can ensure that the local IP address
       
   182     does not change. This is achieved by using a virtual IP address which is bound to the actual
       
   183     link address. During the roaming process the virtual address is attached to the new link 
       
   184     address.
       
   185 
       
   186     Some platforms may support the concept of Forced Roaming and Application Level Roaming (ALR). 
       
   187     Forced roaming implies that the platform may simply roam to a new configuration without 
       
   188     consulting applications. It is up to the application to detect the link layer loss and reestablish
       
   189     its sockets. In contrast ALR provides the opportunity to prevent the system from roaming. 
       
   190     If this session is based on a configuration that supports roaming the application can choose
       
   191     whether it wants to be consulted (ALR use case) by connecting to this signal. For as long as this signal 
       
   192     connection remains the session remains registered as a roaming stakeholder; otherwise roaming will 
       
   193     be enforced by the platform.
       
   194 
       
   195     \sa migrate(), ignore(), QNetworkConfiguration::isRoamingAvailable()
       
   196 */
       
   197 
       
   198 /*!
       
   199     \fn void QNetworkSession::newConfigurationActivated()
       
   200 
       
   201     This signal is emitted once the session has roamed to the new access point.
       
   202     The application may reopen its socket and test the suitability of the new network link.
       
   203     Subsequently it must either accept() or reject() the new access point. 
       
   204 
       
   205     \sa accept(), reject()
       
   206 */
       
   207 
       
   208 /*!
       
   209     \fn void QNetworkSession::opened()
       
   210 
       
   211     This signal is emitted when the network session has been opened. 
       
   212     
       
   213     The underlying network interface will not be shut down as long as the session remains open.
       
   214     Note that this feature is dependent on \l{QNetworkConfigurationManager::SystemSessionSupport}{system wide session support}.
       
   215 */
       
   216 
       
   217 /*!
       
   218     \fn void QNetworkSession::closed()
       
   219 
       
   220     This signal is emitted when the network session has been closed.
       
   221 */
       
   222 
       
   223 /*!
       
   224     Constructs a session based on \a connectionConfig with the given \a parent.
       
   225 
       
   226     \sa QNetworkConfiguration
       
   227 */
       
   228 QNetworkSession::QNetworkSession(const QNetworkConfiguration& connectionConfig, QObject* parent)
       
   229     : QObject(parent)
       
   230 {
       
   231     d = new QNetworkSessionPrivate;
       
   232     d->q = this;
       
   233     d->publicConfig = connectionConfig;
       
   234     d->syncStateWithInterface();
       
   235     QObject::connect(d, SIGNAL(quitPendingWaitsForOpened()), 
       
   236                 this, SIGNAL(opened()));
       
   237 }
       
   238 
       
   239 /*!
       
   240     Frees the resources associated with the QNetworkSession object.
       
   241 */
       
   242 QNetworkSession::~QNetworkSession()
       
   243 {
       
   244     delete d;
       
   245 }
       
   246 
       
   247 /*!
       
   248     Creates an open session which increases the session counter on the underlying network interface.
       
   249     The system will not terminate a network interface until the session reference counter reaches zero.
       
   250     Therefore an open session allows an application to register its use of the interface.
       
   251 
       
   252     As a result of calling open() the interface will be started if it is not connected/up yet. 
       
   253     Some platforms may not provide support for out-of-process sessions. On such platforms the session
       
   254     counter ignores any sessions held by another process. The platform capabilities can be 
       
   255     detected via QNetworkConfigurationManager::capabilities().
       
   256 
       
   257     Note that this call is asynchronous. Depending on the outcome of this call the results can be enquired 
       
   258     by connecting to the stateChanged(), opened() or error() signals.
       
   259 
       
   260     It is not a requirement to open a session in order to monitor the underlying network interface.
       
   261 
       
   262     \sa close(), stop(), isOpen()
       
   263 */
       
   264 void QNetworkSession::open()
       
   265 {
       
   266     d->open();
       
   267 }
       
   268 
       
   269 /*!
       
   270     Waits until the session has been opened, up to \a msecs milliseconds. If the session has been opened, this
       
   271     function returns true; otherwise it returns false. In the case where it returns false, you can call error()
       
   272     to determine the cause of the error.
       
   273 
       
   274     The following example waits up to one second for the session to be opened:
       
   275 
       
   276     \code
       
   277         session->open();
       
   278         if (session->waitForOpened(1000))
       
   279             qDebug("Open!");
       
   280     \endcode
       
   281 
       
   282     If \a msecs is -1, this function will not time out.
       
   283 
       
   284     \sa open(), error()
       
   285 */
       
   286 bool QNetworkSession::waitForOpened(int msecs)
       
   287 {
       
   288     if (d->isOpen)
       
   289         return true;
       
   290 
       
   291     if (d->state != Connecting)
       
   292         return false;
       
   293 
       
   294     QEventLoop* loop = new QEventLoop(this);
       
   295     QObject::connect(d, SIGNAL(quitPendingWaitsForOpened()),
       
   296                      loop, SLOT(quit()));
       
   297     QObject::connect(this, SIGNAL(error(QNetworkSession::SessionError)),
       
   298                      loop, SLOT(quit()));
       
   299 
       
   300     //final call
       
   301     if (msecs>=0)
       
   302         QTimer::singleShot(msecs, loop, SLOT(quit()));
       
   303 
       
   304     loop->exec();
       
   305     loop->disconnect();
       
   306     loop->deleteLater();
       
   307 
       
   308     return d->isOpen;
       
   309 }
       
   310 
       
   311 /*!
       
   312     Decreases the session counter on the associated network configuration. If the session counter reaches zero
       
   313     the active network interface is shut down. This also means that state() will only change from \l Connected to
       
   314     \l Disconnected if the current session was the last open session.
       
   315 
       
   316     If the platform does not support out-of-process sessions calling this function does not stop the
       
   317     interface. In this case \l{stop()} has to be used to force a shut down. 
       
   318     The platform capabilities can be detected via QNetworkConfigurationManager::capabilities().
       
   319 
       
   320     Note that this call is asynchronous. Depending on the outcome of this call the results can be enquired 
       
   321     by connecting to the stateChanged(), opened() or error() signals.
       
   322 
       
   323     \sa open(), stop(), isOpen()
       
   324 */
       
   325 void QNetworkSession::close()
       
   326 {
       
   327     d->close();
       
   328 }
       
   329 
       
   330 /*!
       
   331     Invalidates all open sessions against the network interface and therefore stops the 
       
   332     underlying network interface. This function always changes the session's state() flag to
       
   333     \l Disconnected. 
       
   334     
       
   335     On Symbian platform, a 'NetworkControl' capability is required for
       
   336     full interface-level stop (without the capability, only the current session is stopped).
       
   337 
       
   338     \sa open(), close()
       
   339 */
       
   340 void QNetworkSession::stop()
       
   341 {
       
   342     d->stop();
       
   343 }
       
   344 
       
   345 /*!
       
   346     Returns the QNetworkConfiguration that this network session object is based on.
       
   347 
       
   348     \sa QNetworkConfiguration
       
   349 */
       
   350 QNetworkConfiguration QNetworkSession::configuration() const
       
   351 {
       
   352     return d->publicConfig;
       
   353 }
       
   354 
       
   355 /*
       
   356     Returns the type of bearer currently used by this session. The string is not translated and
       
   357     therefore can not be shown to the user. The subsequent table presents the currently known
       
   358     bearer types:
       
   359 
       
   360     \table
       
   361         \header 
       
   362             \o Value
       
   363             \o Description
       
   364         \row
       
   365             \o Unknown
       
   366             \o The session is based on an unknown or unspecified bearer type.
       
   367         \row
       
   368             \o Ethernet
       
   369             \o The session is based on Ethernet.
       
   370         \row
       
   371             \o WLAN
       
   372             \o The session is based on Wireless LAN.
       
   373         \row
       
   374             \o 2G
       
   375             \o The session uses CSD, GPRS, HSCSD, EDGE or cdmaOne.
       
   376         \row 
       
   377             \o CDMA2000
       
   378             \o The session uses CDMA.
       
   379         \row
       
   380             \o WCDMA
       
   381             \o The session uses W-CDMA/UMTS.
       
   382         \row
       
   383             \o HSPA
       
   384             \o The session uses High Speed Packet Access.
       
   385         \row
       
   386             \o Bluetooth
       
   387             \o The session uses Bluetooth.
       
   388         \row
       
   389             \o WiMAX
       
   390             \o The session uses WiMAX.
       
   391     \endtable
       
   392 
       
   393     If the session is based on a network configuration of type 
       
   394     \l QNetworkConfiguration::ServiceNetwork the type of the preferred or currently 
       
   395     active configuration is returned. Therefore the bearer type may change 
       
   396     over time.
       
   397 
       
   398     This function returns an empty string if this session is based on an invalid configuration, or
       
   399     a network configuration of type \l QNetworkConfiguration::ServiceNetwork with no
       
   400     \l {QNetworkConfiguration::children()}{children}.
       
   401 */
       
   402 /*QString QNetworkSession::bearerName() const
       
   403 {
       
   404     return d->bearerName();
       
   405 }*/
       
   406 
       
   407 /*!
       
   408     Returns the network interface that is used by this session.
       
   409 
       
   410     This function only returns a valid QNetworkInterface when this session is \l Connected.
       
   411 
       
   412     The returned interface may change as a result of a roaming process.
       
   413     
       
   414     Note: this function does not work in Symbian emulator due to the way the 
       
   415     connectivity is emulated on Windows.
       
   416 
       
   417     \sa state()
       
   418 */
       
   419 QNetworkInterface QNetworkSession::interface() const
       
   420 {
       
   421     return d->currentInterface();
       
   422 }
       
   423 
       
   424 /*!
       
   425     Returns true if this session is open. If the number of all open sessions is greater than
       
   426     zero the underlying network interface will remain connected/up.
       
   427 
       
   428     The session can be controlled via open() and close().
       
   429 */
       
   430 bool QNetworkSession::isOpen() const
       
   431 {
       
   432     return d->isOpen;
       
   433 }
       
   434 
       
   435 /*!
       
   436     Returns the state of the session. 
       
   437     
       
   438     If the session is based on a single access point configuration the state of the 
       
   439     session is the same as the state of the associated network interface. Therefore
       
   440     a network session object can be used to monitor network interfaces. 
       
   441 
       
   442     A \l QNetworkConfiguration::ServiceNetwork based session summarizes the state of all its children
       
   443     and therefore returns the \l Connected state if at least one of the service network's 
       
   444     \l {QNetworkConfiguration::children()}{children()} configurations is active. 
       
   445 
       
   446     Note that it is not required to hold an open session in order to obtain the network interface state.
       
   447     A connected but closed session may be used to monitor network interfaces whereas an open and connected
       
   448     session object may prevent the network interface from being shut down.
       
   449 
       
   450     \sa error(), stateChanged()
       
   451 */
       
   452 QNetworkSession::State QNetworkSession::state() const
       
   453 {
       
   454     return d->state;
       
   455 }
       
   456 
       
   457 /*!
       
   458     Returns the type of error that last occurred.
       
   459 
       
   460     \sa state(), errorString()
       
   461 */
       
   462 QNetworkSession::SessionError QNetworkSession::error() const
       
   463 {
       
   464     return d->error();
       
   465 }
       
   466 
       
   467 /*!
       
   468     Returns a human-readable description of the last device error that 
       
   469     occurred.
       
   470 
       
   471     \sa error()
       
   472 */
       
   473 QString QNetworkSession::errorString() const
       
   474 {
       
   475     return d->errorString();
       
   476 }
       
   477 
       
   478 /*!
       
   479     Returns the value for property \a key.
       
   480 
       
   481     A network session can have properties attached which may describe the session in more details.
       
   482     This function can be used to gain access to those properties.
       
   483 
       
   484     The following property keys are guaranteed to be specified on all platforms:
       
   485 
       
   486     \table
       
   487         \header
       
   488             \o Key \o Description
       
   489         \row
       
   490             \o ActiveConfiguration
       
   491             \o If the session \l isOpen() this property returns the identifier of the
       
   492             QNetworkConfiguration that is used by this session; otherwise an empty string.
       
   493 
       
   494             The main purpose of this key is to determine which Internet access point is used
       
   495             if the session is based on a \l{QNetworkConfiguration::ServiceNetwork}{ServiceNetwork}. 
       
   496             The following code snippet highlights the difference:
       
   497             \code
       
   498                     QNetworkConfigurationManager mgr;
       
   499                     QNetworkConfiguration ap = mgr.defaultConfiguration();
       
   500                     QNetworkSession* session = new QNetworkSession(ap);
       
   501                     ... //code activates session
       
   502 
       
   503                     QString ident = session->sessionProperty("ActiveConfiguration").toString();
       
   504                     if ( ap.type() == QNetworkConfiguration::ServiceNetwork ) {
       
   505                         Q_ASSERT( ap.identifier() != ident );
       
   506                         Q_ASSERT( ap.children().contains( mgr.configurationFromIdentifier(ident) ) );
       
   507                     } else if ( ap.type() == QNetworkConfiguration::InternetAccessPoint ) {
       
   508                         Q_ASSERT( ap.identifier() == ident );
       
   509                     }
       
   510                 \endcode
       
   511         \row
       
   512             \o UserChoiceConfiguration
       
   513             \o If the session \l isOpen() and is bound to a QNetworkConfiguration of type
       
   514             UserChoice, this property returns the identifier of the QNetworkConfiguration that the
       
   515             configuration resolved to when \l open() was called; otherwise an empty string.
       
   516 
       
   517             The purpose of this key is to determine the real QNetworkConfiguration that the
       
   518             session is using. This key is different to \i ActiveConfiguration in that
       
   519             this key may return an identifier for either a
       
   520             \l {QNetworkConfiguration::ServiceNetwork}{service network} or a
       
   521             \l {QNetworkConfiguration::InternetAccessPoint}{Internet access points} configurations
       
   522             whereas \i ActiveConfiguration always returns identifiers to 
       
   523             \l {QNetworkConfiguration::InternetAccessPoint}{Internet access points} configurations.
       
   524         \row
       
   525             \o ConnectInBackground
       
   526             \o Setting this property to \i true before calling \l open() implies that the connection attempt
       
   527             is made but if no connection can be established, the user is not connsulted and asked to select
       
   528             a suitable connection. This property is not set by default and support for it depends on the platform.
       
   529     \endtable
       
   530 */
       
   531 QVariant QNetworkSession::sessionProperty(const QString& key) const
       
   532 {
       
   533     if (!d->publicConfig.isValid())
       
   534         return QVariant();
       
   535 
       
   536     if (key == "ActiveConfiguration") {
       
   537         if (!d->isOpen)
       
   538             return QString();
       
   539         else
       
   540             return d->activeConfig.identifier();
       
   541     }
       
   542 
       
   543     if (key == "UserChoiceConfiguration") {
       
   544         if (!d->isOpen || d->publicConfig.type() != QNetworkConfiguration::UserChoice)
       
   545             return QString();
       
   546 
       
   547         if (d->serviceConfig.isValid())
       
   548             return d->serviceConfig.identifier();
       
   549         else
       
   550             return d->activeConfig.identifier();
       
   551     }
       
   552 
       
   553     return d->sessionProperty(key);
       
   554 }
       
   555 
       
   556 /*!
       
   557     Sets the property \a value on the session. The property is identified using
       
   558     \a key. Removing an already set  property can be achieved by passing an 
       
   559     invalid QVariant.
       
   560 
       
   561     Note that the \i UserChoiceConfiguration and \i ActiveConfiguration
       
   562     properties are read only and cannot be changed using this method.
       
   563 */
       
   564 void QNetworkSession::setSessionProperty(const QString& key, const QVariant& value)
       
   565 {
       
   566     if (key == "ActiveConfiguration" 
       
   567             || key == "UserChoiceConfiguration") 
       
   568         return;
       
   569 
       
   570     d->setSessionProperty(key, value);
       
   571 }
       
   572 
       
   573 /*!
       
   574     Instructs the session to roam to the new access point. The old access point remains active 
       
   575     until the application calls accept().
       
   576 
       
   577    The newConfigurationActivated() signal is emitted once roaming has been completed.
       
   578 
       
   579     \sa accept()
       
   580 */
       
   581 void QNetworkSession::migrate()
       
   582 {
       
   583     d->migrate();
       
   584 }
       
   585 
       
   586 /*!
       
   587     This function indicates that the application does not wish to roam the session.
       
   588 
       
   589     \sa migrate()
       
   590 */
       
   591 void QNetworkSession::ignore()
       
   592 {
       
   593     // Needed on at least Symbian platform: the roaming must be explicitly 
       
   594     // ignore()'d or migrate()'d
       
   595     d->ignore();
       
   596 }
       
   597 
       
   598 /*!
       
   599     Instructs the session to permanently accept the new access point. Once this function 
       
   600     has been called the session may not return to the old access point.
       
   601 
       
   602     The old access point may be closed in the process if there are no other network sessions for it.
       
   603     Therefore any open socket that still uses the old access point 
       
   604     may become unusable and should be closed before completing the migration.
       
   605 */
       
   606 void QNetworkSession::accept()
       
   607 {
       
   608     d->accept();
       
   609 }
       
   610 
       
   611 /*!
       
   612     The new access point is not suitable for the application. By calling this function the 
       
   613     session returns to the previous access point/configuration. This action may invalidate
       
   614     any socket that has been created via the not desired access point.
       
   615 
       
   616     \sa accept()
       
   617 */
       
   618 void QNetworkSession::reject()
       
   619 {
       
   620     d->reject();
       
   621 }
       
   622 
       
   623 
       
   624 /*!
       
   625     Returns the amount of data sent in bytes; otherwise 0.
       
   626 
       
   627     This field value includes the usage across all open network 
       
   628     sessions which use the same network interface.
       
   629 
       
   630     If the session is based on a service network configuration the number of 
       
   631     sent bytes across all active member configurations are returned.
       
   632 
       
   633     This function may not always be supported on all platforms and returns
       
   634     0. The platform capability can be detected via QNetworkConfigurationManager::DataStatistics.
       
   635 */
       
   636 quint64 QNetworkSession::bytesWritten() const
       
   637 {
       
   638     return d->bytesWritten();
       
   639 }
       
   640 
       
   641 /*!
       
   642     Returns the amount of data received in bytes; otherwise 0.
       
   643 
       
   644     This field value includes the usage across all open network 
       
   645     sessions which use the same network interface.
       
   646 
       
   647     If the session is based on a service network configuration the number of 
       
   648     sent bytes across all active member configurations are returned.
       
   649 
       
   650     This function may not always be supported on all platforms and returns
       
   651     0. The platform capability can be detected via QNetworkConfigurationManager::DataStatistics.
       
   652 */
       
   653 quint64 QNetworkSession::bytesReceived() const
       
   654 {
       
   655     return d->bytesReceived();
       
   656 }
       
   657 
       
   658 /*!
       
   659     Returns the number of seconds that the session has been active.
       
   660 */
       
   661 quint64 QNetworkSession::activeTime() const
       
   662 {
       
   663     return d->activeTime();
       
   664 }
       
   665 
       
   666 /*!
       
   667     \internal
       
   668 
       
   669     This function is required to detect whether the client wants to control 
       
   670     the roaming process. If he connects to preferredConfigurationChanged() signal
       
   671     he intends to influence it. Otherwise QNetworkSession always roams
       
   672     without registering this session as a stakeholder in the roaming process.
       
   673 
       
   674     For more details check the Forced vs ALR roaming section in the QNetworkSession 
       
   675     class description.
       
   676 */
       
   677 void QNetworkSession::connectNotify(const char *signal)
       
   678 {
       
   679     QObject::connectNotify(signal);
       
   680     //check for preferredConfigurationChanged() signal connect notification
       
   681     //This is not required on all platforms
       
   682 #ifdef Q_OS_SYMBIAN
       
   683     if (qstrcmp(signal, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool))) == 0) {
       
   684         d->setALREnabled(true);
       
   685     }
       
   686 #endif    
       
   687 }
       
   688 
       
   689 /*!
       
   690     \internal
       
   691 
       
   692     This function is called when the client disconnects from the preferredConfigurationChanged()
       
   693     signal.
       
   694 
       
   695     \sa connectNotify()
       
   696 */
       
   697 void QNetworkSession::disconnectNotify(const char *signal)
       
   698 {
       
   699     QObject::disconnectNotify(signal);
       
   700     //check for preferredConfigurationChanged() signal disconnect notification
       
   701     //This is not required on all platforms
       
   702 #ifdef Q_OS_SYMBIAN
       
   703     if (qstrcmp(signal, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool))) == 0) {
       
   704         d->setALREnabled(false);
       
   705     }    
       
   706 #endif    
       
   707 }
       
   708 
       
   709 #include "moc_qnetworksession.cpp"
       
   710 
       
   711 QTM_END_NAMESPACE