Qt 4.8
qnetworkconfigmanager.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 
42 #include "qnetworkconfigmanager.h"
43 
45 #include "qbearerengine_p.h"
46 
47 #include <QtCore/qstringlist.h>
48 #include <QtCore/qcoreapplication.h>
49 #include <QtCore/qmutex.h>
50 #include <QtCore/qthread.h>
51 #include <QtCore/private/qcoreapplication_p.h>
52 
53 #ifndef QT_NO_BEARERMANAGEMENT
54 
56 
58 Q_GLOBAL_STATIC(QMutex, connManager_mutex)
60 
61 static void connManager_cleanup()
62 {
63  // this is not atomic or thread-safe!
64  int shutdown = appShutdown.fetchAndStoreAcquire(1);
65  Q_ASSERT(shutdown == 0);
66  if(connManager_ptr)
67  connManager_ptr->cleanup();
68  connManager_ptr = 0;
69 }
70 
72 {
74 }
75 
77 {
79  if (!ptr && !appShutdown) {
80  QMutexLocker locker(connManager_mutex());
81  if (!(ptr = connManager_ptr.fetchAndAddAcquire(0))) {
83 
85  // right thread or no main thread yet
86  ptr->addPostRoutine();
87  ptr->initialize();
88  } else {
89  // wrong thread, we need to make the main thread do this
90  QObject *obj = new QObject;
92  ptr->initialize(); // this moves us to the right thread
94  obj->deleteLater();
95  }
96 
97  connManager_ptr.fetchAndStoreRelease(ptr);
98  }
99  }
100  return ptr;
101 }
102 
104 {
105  return connManager();
106 }
107 
252  : QObject(parent)
253 {
255 
262  connect(priv, SIGNAL(onlineStateChanged(bool)),
263  this, SIGNAL(onlineStateChanged(bool)));
265  this, SIGNAL(updateCompleted()));
266 
267  priv->enablePolling();
268 }
269 
274 {
276  if (priv)
277  priv->disablePolling();
278 }
279 
280 
291 {
293  if (priv)
294  return priv->defaultConfiguration();
295 
296  return QNetworkConfiguration();
297 }
298 
325 {
327  if (priv)
328  return priv->allConfigurations(filter);
329 
331 }
332 
340 {
342  if (priv)
343  return priv->configurationFromIdentifier(identifier);
344 
345  return QNetworkConfiguration();
346 }
347 
359 {
361  if (priv)
362  return priv->isOnline();
363 
364  return false;
365 }
366 
370 QNetworkConfigurationManager::Capabilities QNetworkConfigurationManager::capabilities() const
371 {
373  if (priv)
374  return priv->capabilities();
375 
376  return QNetworkConfigurationManager::Capabilities(0);
377 }
378 
394 {
396  if (priv)
398 }
399 
400 #include "moc_qnetworkconfigmanager.cpp"
401 
403 
404 #endif // QT_NO_BEARERMANAGEMENT
static QBasicAtomicPointer< QNetworkConfigurationManagerPrivate > connManager_ptr
void updateConfigurations()
Initiates an update of all configurations.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QMutex class provides access serialization between threads.
Definition: qmutex.h:60
void qAddPostRoutine(QtCleanUpFunction p)
void configurationChanged(const QNetworkConfiguration &config)
This signal is emitted when the QNetworkConfiguration::state(){state} of config changes.
QNetworkConfigurationManager(QObject *parent=0)
Constructs a QNetworkConfigurationManager with the given parent.
T * fetchAndStoreRelease(T *newValue)
#define SLOT(a)
Definition: qobjectdefs.h:226
static QNetworkConfigurationManagerPrivate * connManager()
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * fetchAndAddAcquire(qptrdiff valueToAdd)
QNetworkConfigurationManager::Capabilities capabilities() const
Returns the capabilities supported by the current platform.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual ~QNetworkConfigurationManager()
Frees the resources associated with the QNetworkConfigurationManager object.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static QBasicAtomicInt appShutdown
QNetworkConfiguration defaultConfiguration() const
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
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
bool isOnline() const
Returns true if the system is considered to be connected to another device via an active network inte...
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
Definition: qglobal.h:1968
QNetworkConfigurationManagerPrivate * qNetworkConfigurationManagerPrivate()
QList< QNetworkConfiguration > allConfigurations(QNetworkConfiguration::StateFlags filter) const
void onlineStateChanged(bool isOnline)
This signal is emitted when the device changes from online to offline mode or vice versa...
void moveToThread(QThread *thread)
Changes the thread affinity for this object and its children.
Definition: qobject.cpp:1458
const T * ptr(const T &t)
QList< QNetworkConfiguration > allConfigurations(QNetworkConfiguration::StateFlags flags=0) const
Returns the list of configurations which comply with the given filter.
void configurationRemoved(const QNetworkConfiguration &config)
This signal is emitted when a configuration is about to be removed from the system.
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QNetworkConfiguration defaultConfiguration() const
Returns the default configuration to be used.
static QThread * mainThread()
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
static const QMetaObjectPrivate * priv(const uint *data)
QFuture< void > filter(Sequence &sequence, FilterFunction filterFunction)
QNetworkConfiguration configurationFromIdentifier(const QString &identifier) const
Returns the QNetworkConfiguration for identifier; otherwise returns an invalid QNetworkConfiguration...
static void connManager_cleanup()
void updateCompleted()
This signal is emitted when the configuration update has been completed.
QNetworkConfiguration configurationFromIdentifier(const QString &identifier) const
QNetworkConfigurationManager::Capabilities capabilities() const
void deleteLater()
Schedules this object for deletion.
Definition: qobject.cpp:2145
void configurationAdded(const QNetworkConfiguration &config)
This signal is emitted whenever a new network configuration is added to the system.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62