summaryrefslogtreecommitdiffstats
path: root/src/network/bearer
diff options
context:
space:
mode:
authorAaron McCarthy <aaron.mccarthy@nokia.com>2010-02-22 01:23:24 (GMT)
committerAaron McCarthy <aaron.mccarthy@nokia.com>2010-02-22 01:42:03 (GMT)
commita56597916b275a2f0d2e3b9f8ac3653eeb4e2e91 (patch)
treeb1bfe41a9bd2b0569e1df9fcd662b95272c6156e /src/network/bearer
parent0109df3ee449767c1836ec7028ac219c57cf9ca7 (diff)
downloadQt-a56597916b275a2f0d2e3b9f8ac3653eeb4e2e91.zip
Qt-a56597916b275a2f0d2e3b9f8ac3653eeb4e2e91.tar.gz
Qt-a56597916b275a2f0d2e3b9f8ac3653eeb4e2e91.tar.bz2
Add locking to bearer code.
QNetworkConfigurationManagerPrivate and QBearerEngine derived classes need to be thread-safe.
Diffstat (limited to 'src/network/bearer')
-rw-r--r--src/network/bearer/qbearerengine.cpp2
-rw-r--r--src/network/bearer/qbearerengine_p.h19
-rw-r--r--src/network/bearer/qnetworkconfigmanager.cpp84
-rw-r--r--src/network/bearer/qnetworkconfigmanager_p.cpp109
-rw-r--r--src/network/bearer/qnetworkconfigmanager_p.h22
-rw-r--r--src/network/bearer/qnetworksession.cpp2
6 files changed, 136 insertions, 102 deletions
diff --git a/src/network/bearer/qbearerengine.cpp b/src/network/bearer/qbearerengine.cpp
index 58d64f2..eb851cc 100644
--- a/src/network/bearer/qbearerengine.cpp
+++ b/src/network/bearer/qbearerengine.cpp
@@ -44,7 +44,7 @@
QT_BEGIN_NAMESPACE
QBearerEngine::QBearerEngine(QObject *parent)
-: QObject(parent)
+: QObject(parent), mutex(QMutex::Recursive)
{
}
diff --git a/src/network/bearer/qbearerengine_p.h b/src/network/bearer/qbearerengine_p.h
index 7e96877..5e12b0f 100644
--- a/src/network/bearer/qbearerengine_p.h
+++ b/src/network/bearer/qbearerengine_p.h
@@ -63,6 +63,7 @@
#include <QtCore/qstring.h>
#include <QtCore/qhash.h>
#include <QtCore/qsharedpointer.h>
+#include <QtCore/qmutex.h>
QT_BEGIN_NAMESPACE
@@ -72,6 +73,8 @@ class Q_NETWORK_EXPORT QBearerEngine : public QObject
{
Q_OBJECT
+ friend class QNetworkConfigurationManager;
+
public:
QBearerEngine(QObject *parent = 0);
virtual ~QBearerEngine();
@@ -86,7 +89,14 @@ public:
virtual QNetworkConfigurationPrivatePointer defaultConfiguration() = 0;
-public:
+Q_SIGNALS:
+ void configurationAdded(QNetworkConfigurationPrivatePointer config);
+ void configurationRemoved(QNetworkConfigurationPrivatePointer config);
+ void configurationChanged(QNetworkConfigurationPrivatePointer config);
+
+ void updateCompleted();
+
+protected:
//this table contains an up to date list of all configs at any time.
//it must be updated if configurations change, are added/removed or
//the members of ServiceNetworks change
@@ -94,12 +104,7 @@ public:
QHash<QString, QNetworkConfigurationPrivatePointer> snapConfigurations;
QHash<QString, QNetworkConfigurationPrivatePointer> userChoiceConfigurations;
-Q_SIGNALS:
- void configurationAdded(QNetworkConfigurationPrivatePointer config);
- void configurationRemoved(QNetworkConfigurationPrivatePointer config);
- void configurationChanged(QNetworkConfigurationPrivatePointer config);
-
- void updateCompleted();
+ mutable QMutex mutex;
};
QT_END_NAMESPACE
diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp
index f54a985..e960323 100644
--- a/src/network/bearer/qnetworkconfigmanager.cpp
+++ b/src/network/bearer/qnetworkconfigmanager.cpp
@@ -206,7 +206,81 @@ QNetworkConfigurationManager::~QNetworkConfigurationManager()
*/
QNetworkConfiguration QNetworkConfigurationManager::defaultConfiguration() const
{
- return connManager()->defaultConfiguration();
+ QNetworkConfigurationManagerPrivate *conPriv = connManager();
+
+ foreach (QBearerEngine *engine, conPriv->engines()) {
+ QNetworkConfigurationPrivatePointer ptr = engine->defaultConfiguration();
+
+ if (ptr) {
+ QNetworkConfiguration config;
+ config.d = ptr;
+ return config;
+ }
+ }
+
+ // Engines don't have a default configuration.
+
+ // Return first active snap
+ QNetworkConfigurationPrivatePointer firstDiscovered;
+
+ foreach (QBearerEngine *engine, conPriv->engines()) {
+ QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator it;
+ QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator end;
+
+ QMutexLocker locker(&engine->mutex);
+
+ for (it = engine->snapConfigurations.begin(), end = engine->snapConfigurations.end();
+ it != end; ++it) {
+ if ((it.value()->state & QNetworkConfiguration::Active) ==
+ QNetworkConfiguration::Active) {
+ QNetworkConfiguration config;
+ config.d = it.value();
+ return config;
+ } else if ((it.value()->state & QNetworkConfiguration::Discovered) ==
+ QNetworkConfiguration::Discovered) {
+ firstDiscovered = it.value();
+ }
+ }
+ }
+
+ // No Active SNAPs return first Discovered SNAP.
+ if (firstDiscovered) {
+ QNetworkConfiguration config;
+ config.d = firstDiscovered;
+ return config;
+ }
+
+ // No Active or Discovered SNAPs, do same for InternetAccessPoints.
+ firstDiscovered.reset();
+
+ foreach (QBearerEngine *engine, conPriv->engines()) {
+ QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator it;
+ QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator end;
+
+ QMutexLocker locker(&engine->mutex);
+
+ for (it = engine->accessPointConfigurations.begin(),
+ end = engine->accessPointConfigurations.end(); it != end; ++it) {
+ if ((it.value()->state & QNetworkConfiguration::Active) ==
+ QNetworkConfiguration::Active) {
+ QNetworkConfiguration config;
+ config.d = it.value();
+ return config;
+ } else if ((it.value()->state & QNetworkConfiguration::Discovered) ==
+ QNetworkConfiguration::Discovered) {
+ firstDiscovered = it.value();
+ }
+ }
+ }
+
+ // No Active InternetAccessPoint return first Discovered InternetAccessPoint.
+ if (firstDiscovered) {
+ QNetworkConfiguration config;
+ config.d = firstDiscovered;
+ return config;
+ }
+
+ return QNetworkConfiguration();
}
/*!
@@ -234,10 +308,12 @@ QList<QNetworkConfiguration> QNetworkConfigurationManager::allConfigurations(QNe
QList<QNetworkConfiguration> result;
QNetworkConfigurationManagerPrivate* conPriv = connManager();
- foreach (QBearerEngine *engine, conPriv->sessionEngines) {
+ foreach (QBearerEngine *engine, conPriv->engines()) {
QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator it;
QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator end;
+ QMutexLocker locker(&engine->mutex);
+
//find all InternetAccessPoints
for (it = engine->accessPointConfigurations.begin(),
end = engine->accessPointConfigurations.end(); it != end; ++it) {
@@ -274,7 +350,9 @@ QNetworkConfiguration QNetworkConfigurationManager::configurationFromIdentifier(
QNetworkConfiguration item;
- foreach (QBearerEngine *engine, conPriv->sessionEngines) {
+ foreach (QBearerEngine *engine, conPriv->engines()) {
+ QMutexLocker locker(&engine->mutex);
+
if (engine->accessPointConfigurations.contains(identifier))
item.d = engine->accessPointConfigurations.value(identifier);
else if (engine->snapConfigurations.contains(identifier))
diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp
index 141d522..6ac61b3 100644
--- a/src/network/bearer/qnetworkconfigmanager_p.cpp
+++ b/src/network/bearer/qnetworkconfigmanager_p.cpp
@@ -47,19 +47,34 @@
#include <QtCore/qdebug.h>
#include <QtCore/qtimer.h>
#include <QtCore/qstringlist.h>
+#include <QtCore/private/qcoreapplication_p.h>
QT_BEGIN_NAMESPACE
Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
(QBearerEngineFactoryInterface_iid, QLatin1String("/bearer")))
+QNetworkConfigurationManagerPrivate::QNetworkConfigurationManagerPrivate()
+: capFlags(0), firstUpdate(true), mutex(QMutex::Recursive)
+{
+ updateConfigurations();
+
+ moveToThread(QCoreApplicationPrivate::mainThread());
+ foreach (QBearerEngine *engine, sessionEngines)
+ engine->moveToThread(QCoreApplicationPrivate::mainThread());
+}
+
QNetworkConfigurationManagerPrivate::~QNetworkConfigurationManagerPrivate()
{
+ QMutexLocker locker(&mutex);
+
qDeleteAll(sessionEngines);
}
void QNetworkConfigurationManagerPrivate::configurationAdded(QNetworkConfigurationPrivatePointer ptr)
{
+ QMutexLocker locker(&mutex);
+
if (!firstUpdate) {
QNetworkConfiguration item;
item.d = ptr;
@@ -75,6 +90,8 @@ void QNetworkConfigurationManagerPrivate::configurationAdded(QNetworkConfigurati
void QNetworkConfigurationManagerPrivate::configurationRemoved(QNetworkConfigurationPrivatePointer ptr)
{
+ QMutexLocker locker(&mutex);
+
ptr->isValid = false;
if (!firstUpdate) {
@@ -90,6 +107,8 @@ void QNetworkConfigurationManagerPrivate::configurationRemoved(QNetworkConfigura
void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigurationPrivatePointer ptr)
{
+ QMutexLocker locker(&mutex);
+
if (!firstUpdate) {
QNetworkConfiguration item;
item.d = ptr;
@@ -111,6 +130,8 @@ void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigura
void QNetworkConfigurationManagerPrivate::updateConfigurations()
{
+ QMutexLocker locker(&mutex);
+
if (firstUpdate) {
updating = false;
@@ -163,87 +184,10 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations()
firstUpdate = false;
}
-/*!
- Returns the default configuration of the first plugin, if one exists; otherwise returns an
- invalid configuration.
-
- \internal
-*/
-QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration()
-{
- foreach (QBearerEngine *engine, sessionEngines) {
- QNetworkConfigurationPrivatePointer ptr = engine->defaultConfiguration();
-
- if (ptr) {
- QNetworkConfiguration config;
- config.d = ptr;
- return config;
- }
- }
-
- // Engines don't have a default configuration.
-
- // Return first active snap
- QNetworkConfigurationPrivatePointer firstDiscovered;
-
- foreach (QBearerEngine *engine, sessionEngines) {
- QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator it;
- QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator end;
-
- for (it = engine->snapConfigurations.begin(), end = engine->snapConfigurations.end();
- it != end; ++it) {
- if ((it.value()->state & QNetworkConfiguration::Active) ==
- QNetworkConfiguration::Active) {
- QNetworkConfiguration config;
- config.d = it.value();
- return config;
- } else if ((it.value()->state & QNetworkConfiguration::Discovered) ==
- QNetworkConfiguration::Discovered) {
- firstDiscovered = it.value();
- }
- }
- }
-
- // No Active SNAPs return first Discovered SNAP.
- if (firstDiscovered) {
- QNetworkConfiguration config;
- config.d = firstDiscovered;
- return config;
- }
-
- // No Active or Discovered SNAPs, do same for InternetAccessPoints.
- firstDiscovered.reset();
-
- foreach (QBearerEngine *engine, sessionEngines) {
- QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator it;
- QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator end;
-
- for (it = engine->accessPointConfigurations.begin(),
- end = engine->accessPointConfigurations.end(); it != end; ++it) {
- if ((it.value()->state & QNetworkConfiguration::Active) ==
- QNetworkConfiguration::Active) {
- QNetworkConfiguration config;
- config.d = it.value();
- return config;
- } else if ((it.value()->state & QNetworkConfiguration::Discovered) ==
- QNetworkConfiguration::Discovered) {
- firstDiscovered = it.value();
- }
- }
- }
-
- // No Active InternetAccessPoint return first Discovered InternetAccessPoint.
- if (firstDiscovered) {
- QNetworkConfiguration config;
- config.d = firstDiscovered;
- return config;
- }
-
- return QNetworkConfiguration();
-}
-
void QNetworkConfigurationManagerPrivate::performAsyncConfigurationUpdate()
{
+ QMutexLocker locker(&mutex);
+
if (sessionEngines.isEmpty()) {
emit configurationUpdateComplete();
return;
@@ -257,4 +201,11 @@ void QNetworkConfigurationManagerPrivate::performAsyncConfigurationUpdate()
}
}
+QList<QBearerEngine *> QNetworkConfigurationManagerPrivate::engines()
+{
+ QMutexLocker locker(&mutex);
+
+ return sessionEngines;
+}
+
QT_END_NAMESPACE
diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h
index e178c2d..c7e988e 100644
--- a/src/network/bearer/qnetworkconfigmanager_p.h
+++ b/src/network/bearer/qnetworkconfigmanager_p.h
@@ -56,20 +56,17 @@
#include "qnetworkconfigmanager.h"
#include "qnetworkconfiguration_p.h"
+#include <QtCore/qmutex.h>
+
QT_BEGIN_NAMESPACE
class QBearerEngine;
-class QNetworkConfigurationManagerPrivate : public QObject
+class Q_NETWORK_EXPORT QNetworkConfigurationManagerPrivate : public QObject
{
Q_OBJECT
public:
- QNetworkConfigurationManagerPrivate()
- : QObject(0), capFlags(0), firstUpdate(true)
- {
- updateConfigurations();
- }
-
+ QNetworkConfigurationManagerPrivate();
virtual ~QNetworkConfigurationManagerPrivate();
QNetworkConfiguration defaultConfiguration();
@@ -78,7 +75,7 @@ public:
void performAsyncConfigurationUpdate();
- bool firstUpdate;
+ QList<QBearerEngine *> engines();
public slots:
void updateConfigurations();
@@ -92,14 +89,17 @@ Q_SIGNALS:
void abort();
-public:
+private:
+ QMutex mutex;
+
QList<QBearerEngine *> sessionEngines;
-private:
QSet<QNetworkConfigurationPrivatePointer> onlineConfigurations;
- bool updating;
QSet<int> updatingEngines;
+ bool updating;
+
+ bool firstUpdate;
private Q_SLOTS:
void configurationAdded(QNetworkConfigurationPrivatePointer ptr);
diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp
index 3e77354..6a82791 100644
--- a/src/network/bearer/qnetworksession.cpp
+++ b/src/network/bearer/qnetworksession.cpp
@@ -225,7 +225,7 @@ QT_BEGIN_NAMESPACE
QNetworkSession::QNetworkSession(const QNetworkConfiguration& connectionConfig, QObject* parent)
: QObject(parent), d(0)
{
- foreach (QBearerEngine *engine, qNetworkConfigurationManagerPrivate()->sessionEngines) {
+ foreach (QBearerEngine *engine, qNetworkConfigurationManagerPrivate()->engines()) {
if (engine->hasIdentifier(connectionConfig.identifier())) {
d = engine->createSessionBackend();
d->q = this;