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