Qt 4.8
qsharednetworksession.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 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 
43 #include "qbearerengine_p.h"
44 #include <QThreadStorage>
45 
46 #ifndef QT_NO_BEARERMANAGEMENT
47 
49 
51 
53 {
55  if (!rv) {
57  tls.setLocalData(rv);
58  }
59  return rv;
60 }
61 
62 static void doDeleteLater(QObject* obj)
63 {
64  obj->deleteLater();
65 }
66 
68 {
70  //if already have a session, return it
71  if (m->sessions.contains(config)) {
73  if (!p.isNull())
74  return p;
75  }
76  //otherwise make one
78  m->sessions[config] = session;
79  return session;
80 }
81 
83 {
85  m->sessions[config] = session;
86 }
87 
89 {
90  return ((uint)config.type()) | (((uint)config.bearerType()) << 8) | (((uint)config.purpose()) << 16);
91 }
92 
94 
95 #endif // QT_NO_BEARERMANAGEMENT
BearerType bearerType() const
Returns the type of bearer used by this network configuration.
QHash< QNetworkConfiguration, QWeakPointer< QNetworkSession > > sessions
QSharedPointer< T > toStrongRef() const
Promotes this weak reference to a strong one and returns a QSharedPointer object holding that referen...
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
Purpose purpose() const
Returns the purpose of this configuration.
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
The QNetworkConfiguration class provides an abstraction of one or more access point configurations...
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
T & localData()
Returns a reference to the data that was set by the calling thread.
unsigned int uint
Definition: qglobal.h:996
static void doDeleteLater(QObject *obj)
QSharedNetworkSessionManager * sharedNetworkSessionManager()
static void setSession(QNetworkConfiguration config, QSharedPointer< QNetworkSession > session)
void setLocalData(T t)
Sets the local data for the calling thread to data.
QNetworkSession(const QNetworkConfiguration &connConfig, QObject *parent=0)
Constructs a session based on connectionConfig with the given parent.
static QSharedPointer< QNetworkSession > getSession(QNetworkConfiguration config)
bool isNull() const
Returns true if this object is holding a reference to a null pointer.
The QThreadStorage class provides per-thread data storage.
void deleteLater()
Schedules this object for deletion.
Definition: qobject.cpp:2145
uint qHash(const QNetworkConfiguration &config)
QThreadStorage< QSharedNetworkSessionManager * > tls
Type type() const
Returns the type of the configuration.