source: trunk/doc/src/network-programming/bearermanagement.qdoc

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 14.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the documentation of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:FDL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in a
14** written agreement between you and Nokia.
15**
16** GNU Free Documentation License
17** Alternatively, this file may be used under the terms of the GNU Free
18** Documentation License version 1.3 as published by the Free Software
19** Foundation and appearing in the file included in the packaging of this
20** file.
21**
22** If you have questions regarding the use of this file, please contact
23** Nokia at [email protected].
24** $QT_END_LICENSE$
25**
26****************************************************************************/
27
28/*!
29\page bearer-management.html
30
31\title Bearer Management
32\ingroup qt-network
33\brief An API to control the system's connectivity state.
34
35Bearer Management controls the connectivity state of the system so that
36the user can start or stop interfaces or roam transparently between
37access points.
38
39\tableofcontents
40
41
42\section1 Overview
43
44The Bearer Management API controls the system's connectivity state. This
45incorporates simple information such as whether the device is online and
46how many interfaces there are as well as enables the application developer
47to start, stop network interfaces and influences other connection specific
48details. Depending on the platform's capabilities it may even provide
49session management so that a network interface remains up for as long as
50clients have a registered interest in them while at the same time
51optimizes the interface's uptime.
52
53This API does not provide support for management of network configurations
54themselves. It is up to the platform to provide infrastructure which
55enables to user to create, edit or delete network configurations.
56
57\section2 The API in Detail
58
59Computer systems manage their network interfaces via a set of configurations.
60Each configuration describes a set of parameters which instruct the system
61how a particular network interface is started. One of the most simplistic
62examples might be an Ethernet configuration that links a network card to a
63DHCP server. A more complex example might be a Wireless LAN configuration
64which may comprise of hardware details such as the WLAN card address,
65WLAN access point details (e.g ESSID, encryption details) and user specific
66information (for example username and password). Once the network interface
67was configured and started according to the configuration blue print,
68multiple applications are free to use this link layer connection/session
69for their own socket operations. Note that the QNetworkConfiguration object
70only provides limited information about the configuration details themselves.
71It's main purpose is to act as a configuration identifier through which link
72layer connections can be created, destroyed and monitored.
73
74QNetworkSession provides two types of use cases. It enables the monitoring of
75physical network interfaces and management of network sessions. Network sessions
76are a common feature on mobile devices where multiple applications
77can request network sessions as they see fit. The system consolidates and tracks
78active network sessions for the same network interface by maintaining the link
79layer connections until the last session has been closed. The subsequent table
80lists the major QNetworkSession functions and how they fit into the session and
81hardware management categories:
82
83\table 60%
84\header \o Interface management \o Session management
85\row \o QNetworkSession::stop() \o QNetworkSession::open()
86\row \o QNetworkSession::interface() \o QNetworkSession::close()
87\row \o QNetworkSession::state() \o QNetworkSession::isOpen()
88\row \o QNetworkSession::bytesWritten() \o QNetworkSession::migrate()
89\row \o QNetworkSession::bytesReceived() \o QNetworkSession::ignore()
90\row \o QNetworkSession::activeTime() \o QNetworkSession::accept()
91\row \o QNetworkSession::stateChanged() \o QNetworkSession::reject()
92\row \o \o QNetworkSession::opened()
93\row \o \o QNetworkSession::closed()
94\endtable
95
96The state of the session represents the state of the underlying access point
97whereas the session's openness implies the networking/connectivity state available
98to the current process.
99
100Possible use cases for interface management are network management related
101applications which intend to monitor the connectivity state but do not engage
102in network communication themselves. Any application wanting to open a socket
103to a remote address will typically use session management related functionality.
104
105\section3 Service networks
106
107Some mobile platforms use the concept of grouped access points (also
108called SNAP or Service Network Access Point). In principle multiple
109configurations are grouped together and possibly even prioritized when
110compared to each other. This is useful for use cases where all
111configurations serve a similar purpose or context. A common context could
112be that they provide access to the public Internet or possibly only to the
113office Intranet. By providing a pool of configurations the system can make
114a decision based on given priorities which usually map to factors such as
115speed, availability and cost. Furthermore the system can automatically
116roam from one access point to the next one while ensuring minimal impact on
117the user experience.
118
119The \l{QNetworkConfiguration::Type} flag specifies to what category a
120configuration belongs. The \l{QNetworkConfiguration::InternetAccessPoint}
121type is the most common example. It represents a configuration that can be
122used to create a session. The above mentioned grouping behavior is provided
123by \l {QNetworkConfiguration::ServiceNetwork} configurations. Service
124networks are place holders until such time when the user attempts to
125\l {QNetworkSession::open()}{open()} a new session. At that point in time
126the system determines which of the configurations \l{QNetworkConfiguration::children()}
127is best to use. The selection algorithm is provided by the platform and is usually managed
128by network settings applications. A service network can only have one level of indirection
129which implies children can only be of type \l {QNetworkConfiguration::InternetAccessPoint}.
130
131Most systems allow the user to define the systems default configuration.
132Usually the default behavior is either a service network, a particular
133Internet access point or the user instructs the platform to ask the user
134once an application requests the network. User interaction is generally
135implemented by some sort of system dialog which shows up at the appropriate
136point in time. The application does not have to handle the user input. This
137API provides the \l QNetworkConfigurationManager::defaultConfiguration()
138call which serves a similar purpose. The subsequent code snippet provides
139a quick way how an application can quickly create a new network session
140without (or only minimal) user interaction:
141
142\code
143 // Set Internet Access Point
144 QNetworkConfigurationManager manager;
145 const bool canStartIAP = (manager.capabilities()
146 & QNetworkConfigurationManager::CanStartAndStopInterfaces);
147 // Is there default access point, use it
148 QNetworkConfiguration cfg = manager.defaultConfiguration();
149 if (!cfg.isValid() || (!canStartIAP && cfg.state() != QNetworkConfiguration::Active)) {
150 QMessageBox::information(this, tr("Network"), tr(
151 "No Access Point found."));
152 return;
153 }
154
155 session = new QNetworkSession(cfg, this);
156 session->open();
157 session->waitForOpened(-1);
158\endcode
159
160To accommodate the "Ask user" use case the default configuration can be of
161type QNetworkConfiguration::UserChoice. A user choice configuration is
162resolved as part of the \l {QNetworkSession::open()} call. Note that a
163\l{QNetworkConfiguration::UserChoice}{UserChoice} configuration is only
164ever returned via \l {QNetworkConfigurationManager::defaultConfiguration()}
165and not \l QNetworkConfigurationManager::allConfigurations().
166
167On systems which do not maintain a list of
168\l {QNetworkConfigurationManager::defaultConfiguration()}{defaultConfiguration()}
169an invalid configuration is returned. A possible workaround could be to
170implement a custom dialog which is populated based on what
171\l QNetworkConfigurationManager::allConfigurations() returns.
172
173\section3 Managing network sessions
174
175A QNetworkSession object separates a \l {QNetworkSession::state()}{state()}
176and an \l{QNetworkSession::isOpen()}{isOpen()} condition.
177
178The state() attribute enables developers to detect whether the system
179currently maintains a global network session for the given
180QNetworkConfiguration. If \l {QNetworkSession::isOpen()}{isOpen()}
181returns true the QNetworkSession instance at hand was at least one of the
182entities requesting the global network session. This distinction is
183required to support the notion of session registrations. For as long as
184there are one or more open QNetworkSession instances the underlying
185network interface is not shut down. Therefore the session
186\l{QNetworkSession::state()}{state()} can be used to monitor the state of
187network interfaces.
188
189An open session is created by calling \l {QNetworkSession::open()} and
190closed via \l{QNetworkSession::close()}, respectively. If the session
191is \l{QNetworkSession::Disconnected}{disconnected} at the time of the