From a56597916b275a2f0d2e3b9f8ac3653eeb4e2e91 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 22 Feb 2010 11:23:24 +1000 Subject: Add locking to bearer code. QNetworkConfigurationManagerPrivate and QBearerEngine derived classes need to be thread-safe. --- src/network/bearer/qbearerengine.cpp | 2 +- src/network/bearer/qbearerengine_p.h | 19 ++-- src/network/bearer/qnetworkconfigmanager.cpp | 84 +++++++++++++++- src/network/bearer/qnetworkconfigmanager_p.cpp | 109 ++++++--------------- src/network/bearer/qnetworkconfigmanager_p.h | 22 ++--- src/network/bearer/qnetworksession.cpp | 2 +- src/plugins/bearer/corewlan/qcorewlanengine.mm | 22 +++++ src/plugins/bearer/generic/qgenericengine.cpp | 10 ++ src/plugins/bearer/icd/qicdengine.cpp | 10 ++ .../bearer/nativewifi/qnativewifiengine.cpp | 14 +++ .../networkmanager/qnetworkmanagerengine.cpp | 50 ++++++++++ src/plugins/bearer/nla/qnlaengine.cpp | 10 ++ src/plugins/bearer/qnetworksession_impl.cpp | 2 +- src/plugins/bearer/symbian/symbianengine.cpp | 44 +++++++++ 14 files changed, 297 insertions(+), 103 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 #include #include +#include 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 snapConfigurations; QHash 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::Iterator it; + QHash::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::Iterator it; + QHash::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 QNetworkConfigurationManager::allConfigurations(QNe QList result; QNetworkConfigurationManagerPrivate* conPriv = connManager(); - foreach (QBearerEngine *engine, conPriv->sessionEngines) { + foreach (QBearerEngine *engine, conPriv->engines()) { QHash::Iterator it; QHash::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 #include #include +#include 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::Iterator it; - QHash::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::Iterator it; - QHash::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 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 + 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 engines(); public slots: void updateConfigurations(); @@ -92,14 +89,17 @@ Q_SIGNALS: void abort(); -public: +private: + QMutex mutex; + QList sessionEngines; -private: QSet onlineConfigurations; - bool updating; QSet 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; diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm index fff65e4..a5384d1 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.mm +++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm @@ -121,16 +121,22 @@ QCoreWlanEngine::~QCoreWlanEngine() QString QCoreWlanEngine::getInterfaceFromId(const QString &id) { + QMutexLocker locker(&mutex); + return configurationInterface.value(id); } bool QCoreWlanEngine::hasIdentifier(const QString &id) { + QMutexLocker locker(&mutex); + return configurationInterface.contains(id); } void QCoreWlanEngine::connectToId(const QString &id) { + QMutexLocker locker(&mutex); + NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; QString interfaceString = getInterfaceFromId(id); @@ -205,6 +211,8 @@ void QCoreWlanEngine::connectToId(const QString &id) void QCoreWlanEngine::disconnectFromId(const QString &id) { + QMutexLocker locker(&mutex); + QString interfaceString = getInterfaceFromId(id); if(networkInterfaces.value(getInterfaceFromId(id)) == "WLAN") { //wifi only for now #if defined(MAC_SDK_10_6) @@ -225,12 +233,16 @@ void QCoreWlanEngine::disconnectFromId(const QString &id) void QCoreWlanEngine::requestUpdate() { + QMutexLocker locker(&mutex); + pollTimer.stop(); QTimer::singleShot(0, this, SLOT(doRequestUpdate())); } void QCoreWlanEngine::doRequestUpdate() { + QMutexLocker locker(&mutex); + getAllScInterfaces(); QStringList previous = accessPointConfigurations.keys(); @@ -330,6 +342,8 @@ void QCoreWlanEngine::doRequestUpdate() QStringList QCoreWlanEngine::scanForSsids(const QString &interfaceName) { + QMutexLocker locker(&mutex); + QStringList found; #if defined(MAC_SDK_10_6) @@ -422,6 +436,8 @@ QStringList QCoreWlanEngine::scanForSsids(const QString &interfaceName) bool QCoreWlanEngine::isWifiReady(const QString &wifiDeviceName) { + QMutexLocker locker(&mutex); + #if defined(MAC_SDK_10_6) CWInterface *defaultInterface = [CWInterface interfaceWithName: qstringToNSString(wifiDeviceName)]; if([defaultInterface power]) @@ -434,6 +450,8 @@ bool QCoreWlanEngine::isWifiReady(const QString &wifiDeviceName) bool QCoreWlanEngine::isKnownSsid(const QString &interfaceName, const QString &ssid) { + QMutexLocker locker(&mutex); + #if defined(MAC_SDK_10_6) CWInterface *wifiInterface = [CWInterface interfaceWithName: qstringToNSString(interfaceName)]; CWConfiguration *userConfig = [wifiInterface configuration]; @@ -451,6 +469,8 @@ bool QCoreWlanEngine::isKnownSsid(const QString &interfaceName, const QString &s bool QCoreWlanEngine::getAllScInterfaces() { + QMutexLocker locker(&mutex); + networkInterfaces.clear(); NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; @@ -491,6 +511,8 @@ bool QCoreWlanEngine::getAllScInterfaces() QNetworkSession::State QCoreWlanEngine::sessionStateForId(const QString &id) { + QMutexLocker locker(&mutex); + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); if (!ptr) diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp index dba2c08..a95b14b 100644 --- a/src/plugins/bearer/generic/qgenericengine.cpp +++ b/src/plugins/bearer/generic/qgenericengine.cpp @@ -154,11 +154,15 @@ QGenericEngine::~QGenericEngine() QString QGenericEngine::getInterfaceFromId(const QString &id) { + QMutexLocker locker(&mutex); + return configurationInterface.value(id); } bool QGenericEngine::hasIdentifier(const QString &id) { + QMutexLocker locker(&mutex); + return configurationInterface.contains(id); } @@ -174,12 +178,16 @@ void QGenericEngine::disconnectFromId(const QString &id) void QGenericEngine::requestUpdate() { + QMutexLocker locker(&mutex); + pollTimer.stop(); QTimer::singleShot(0, this, SLOT(doRequestUpdate())); } void QGenericEngine::doRequestUpdate() { + QMutexLocker locker(&mutex); + // Immediately after connecting with a wireless access point // QNetworkInterface::allInterfaces() will sometimes return an empty list. Calling it again a // second time results in a non-empty list. If we loose interfaces we will end up removing @@ -282,6 +290,8 @@ void QGenericEngine::doRequestUpdate() QNetworkSession::State QGenericEngine::sessionStateForId(const QString &id) { + QMutexLocker locker(&mutex); + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); if (!ptr) diff --git a/src/plugins/bearer/icd/qicdengine.cpp b/src/plugins/bearer/icd/qicdengine.cpp index 3233eda..f10042a 100644 --- a/src/plugins/bearer/icd/qicdengine.cpp +++ b/src/plugins/bearer/icd/qicdengine.cpp @@ -100,6 +100,8 @@ QIcdEngine::~QIcdEngine() bool QIcdEngine::hasIdentifier(const QString &id) { + QMutexLocker locker(&mutex); + return accessPointConfigurations.contains(id) || snapConfigurations.contains(id) || userChoiceConfigurations.contains(id); @@ -107,6 +109,8 @@ bool QIcdEngine::hasIdentifier(const QString &id) void QIcdEngine::requestUpdate() { + QMutexLocker locker(&mutex); + QTimer::singleShot(0, this, SLOT(doRequestUpdate())); } @@ -156,6 +160,8 @@ static uint32_t getNetworkAttrs(bool is_iap_id, void QIcdEngine::doRequestUpdate() { + QMutexLocker locker(&mutex); + QStringList previous = accessPointConfigurations.keys(); /* All the scanned access points */ @@ -371,6 +377,8 @@ void QIcdEngine::doRequestUpdate() void QIcdEngine::deleteConfiguration(const QString &iap_id) { + QMutexLocker locker(&mutex); + /* Called when IAPs are deleted in gconf, in this case we do not scan * or read all the IAPs from gconf because it might take too much power * (multiple applications would need to scan and read all IAPs from gconf) @@ -409,6 +417,8 @@ QNetworkSessionPrivate *QIcdEngine::createSessionBackend() QNetworkConfigurationPrivatePointer QIcdEngine::defaultConfiguration() { + QMutexLocker locker(&mutex); + // Here we just return [ANY] request to icd and let the icd decide which IAP to connect. return userChoiceConfigurations.value(OSSO_IAP_ANY); } diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp index e4ab0aa..c8015d8 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp @@ -109,6 +109,8 @@ QNativeWifiEngine::~QNativeWifiEngine() void QNativeWifiEngine::scanComplete() { + QMutexLocker locker(&mutex); + QStringList previous = accessPointConfigurations.keys(); // enumerate interfaces @@ -227,6 +229,8 @@ void QNativeWifiEngine::scanComplete() QString QNativeWifiEngine::getInterfaceFromId(const QString &id) { + QMutexLocker locker(&mutex); + // enumerate interfaces WLAN_INTERFACE_INFO_LIST *interfaceList; DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); @@ -276,6 +280,8 @@ QString QNativeWifiEngine::getInterfaceFromId(const QString &id) bool QNativeWifiEngine::hasIdentifier(const QString &id) { + QMutexLocker locker(&mutex); + // enumerate interfaces WLAN_INTERFACE_INFO_LIST *interfaceList; DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); @@ -330,6 +336,8 @@ bool QNativeWifiEngine::hasIdentifier(const QString &id) void QNativeWifiEngine::connectToId(const QString &id) { + QMutexLocker locker(&mutex); + WLAN_INTERFACE_INFO_LIST *interfaceList; DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); if (result != ERROR_SUCCESS) { @@ -393,6 +401,8 @@ void QNativeWifiEngine::connectToId(const QString &id) void QNativeWifiEngine::disconnectFromId(const QString &id) { + QMutexLocker locker(&mutex); + QString interface = getInterfaceFromId(id); if (interface.isEmpty()) { @@ -421,6 +431,8 @@ void QNativeWifiEngine::disconnectFromId(const QString &id) void QNativeWifiEngine::requestUpdate() { + QMutexLocker locker(&mutex); + // enumerate interfaces WLAN_INTERFACE_INFO_LIST *interfaceList; DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); @@ -440,6 +452,8 @@ void QNativeWifiEngine::requestUpdate() QNetworkSession::State QNativeWifiEngine::sessionStateForId(const QString &id) { + QMutexLocker locker(&mutex); + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); if (!ptr) diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp index 4c8928c..5c6efe3 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp @@ -120,6 +120,8 @@ QNetworkManagerEngine::~QNetworkManagerEngine() bool QNetworkManagerEngine::networkManagerAvailable() const { + QMutexLocker locker(&mutex); + return interface->isValid(); } @@ -130,6 +132,8 @@ void QNetworkManagerEngine::doRequestUpdate() QString QNetworkManagerEngine::getInterfaceFromId(const QString &id) { + QMutexLocker locker(&mutex); + foreach (const QDBusObjectPath &acPath, interface->activeConnections()) { QNetworkManagerConnectionActive activeConnection(acPath.path()); @@ -152,6 +156,8 @@ QString QNetworkManagerEngine::getInterfaceFromId(const QString &id) bool QNetworkManagerEngine::hasIdentifier(const QString &id) { + QMutexLocker locker(&mutex); + if (connectionFromId(id)) return true; @@ -170,6 +176,8 @@ bool QNetworkManagerEngine::hasIdentifier(const QString &id) QString QNetworkManagerEngine::bearerName(const QString &id) { + QMutexLocker locker(&mutex); + QNetworkManagerSettingsConnection *connection = connectionFromId(id); if (!connection) @@ -192,6 +200,8 @@ QString QNetworkManagerEngine::bearerName(const QString &id) void QNetworkManagerEngine::connectToId(const QString &id) { + QMutexLocker locker(&mutex); + QNetworkManagerSettingsConnection *connection = connectionFromId(id); if (!connection) @@ -223,6 +233,8 @@ void QNetworkManagerEngine::connectToId(const QString &id) void QNetworkManagerEngine::disconnectFromId(const QString &id) { + QMutexLocker locker(&mutex); + foreach (const QDBusObjectPath &acPath, interface->activeConnections()) { QNetworkManagerConnectionActive activeConnection(acPath.path()); @@ -238,12 +250,16 @@ void QNetworkManagerEngine::disconnectFromId(const QString &id) void QNetworkManagerEngine::requestUpdate() { + QMutexLocker locker(&mutex); + QTimer::singleShot(0, this, SLOT(doRequestUpdate())); } void QNetworkManagerEngine::interfacePropertiesChanged(const QString &path, const QMap &properties) { + QMutexLocker locker(&mutex); + Q_UNUSED(path) QMapIterator i(properties); @@ -310,6 +326,8 @@ void QNetworkManagerEngine::interfacePropertiesChanged(const QString &path, void QNetworkManagerEngine::activeConnectionPropertiesChanged(const QString &path, const QMap &properties) { + QMutexLocker locker(&mutex); + Q_UNUSED(properties) QNetworkManagerConnectionActive *activeConnection = activeConnections.value(path); @@ -333,10 +351,14 @@ void QNetworkManagerEngine::activeConnectionPropertiesChanged(const QString &pat void QNetworkManagerEngine::devicePropertiesChanged(const QString &path, const QMap &properties) { + Q_UNUSED(path); + Q_UNUSED(properties); } void QNetworkManagerEngine::deviceAdded(const QDBusObjectPath &path) { + QMutexLocker locker(&mutex); + QNetworkManagerInterfaceDevice device(path.path()); if (device.deviceType() == DEVICE_TYPE_802_11_WIRELESS) { QNetworkManagerInterfaceDeviceWireless *wirelessDevice = @@ -358,12 +380,16 @@ void QNetworkManagerEngine::deviceAdded(const QDBusObjectPath &path) void QNetworkManagerEngine::deviceRemoved(const QDBusObjectPath &path) { + QMutexLocker locker(&mutex); + delete wirelessDevices.value(path.path()); } void QNetworkManagerEngine::newConnection(const QDBusObjectPath &path, QNetworkManagerSettings *settings) { + QMutexLocker locker(&mutex); + if (!settings) settings = qobject_cast(sender()); @@ -404,6 +430,8 @@ void QNetworkManagerEngine::newConnection(const QDBusObjectPath &path, void QNetworkManagerEngine::removeConnection(const QString &path) { + QMutexLocker locker(&mutex); + Q_UNUSED(path) QNetworkManagerSettingsConnection *connection = @@ -423,6 +451,8 @@ void QNetworkManagerEngine::removeConnection(const QString &path) void QNetworkManagerEngine::updateConnection(const QNmSettingsMap &settings) { + QMutexLocker locker(&mutex); + QNetworkManagerSettingsConnection *connection = qobject_cast(sender()); if (!connection) @@ -458,6 +488,8 @@ void QNetworkManagerEngine::updateConnection(const QNmSettingsMap &settings) void QNetworkManagerEngine::activationFinished(QDBusPendingCallWatcher *watcher) { + QMutexLocker locker(&mutex); + QDBusPendingReply reply = *watcher; if (!reply.isError()) { QDBusObjectPath result = reply.value(); @@ -480,6 +512,8 @@ void QNetworkManagerEngine::activationFinished(QDBusPendingCallWatcher *watcher) void QNetworkManagerEngine::newAccessPoint(const QString &path, const QDBusObjectPath &objectPath) { + QMutexLocker locker(&mutex); + Q_UNUSED(path) QNetworkManagerInterfaceAccessPoint *accessPoint = @@ -535,6 +569,8 @@ void QNetworkManagerEngine::newAccessPoint(const QString &path, const QDBusObjec void QNetworkManagerEngine::removeAccessPoint(const QString &path, const QDBusObjectPath &objectPath) { + QMutexLocker locker(&mutex); + Q_UNUSED(path) for (int i = 0; i < accessPoints.count(); ++i) { @@ -579,6 +615,8 @@ void QNetworkManagerEngine::removeAccessPoint(const QString &path, void QNetworkManagerEngine::updateAccessPoint(const QMap &map) { + QMutexLocker locker(&mutex); + Q_UNUSED(map) QNetworkManagerInterfaceAccessPoint *accessPoint = @@ -607,6 +645,8 @@ QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QStri const QString &settingsPath, const QNmSettingsMap &map) { + QMutexLocker locker(&mutex); + QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; cpPriv->name = map.value("connection").value("id").toString(); cpPriv->isValid = true; @@ -664,6 +704,8 @@ QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QStri QNetworkManagerSettingsConnection *QNetworkManagerEngine::connectionFromId(const QString &id) const { + QMutexLocker locker(&mutex); + for (int i = 0; i < connections.count(); ++i) { QNetworkManagerSettingsConnection *connection = connections.at(i); const QString service = connection->connectionInterface()->service(); @@ -680,6 +722,8 @@ QNetworkManagerSettingsConnection *QNetworkManagerEngine::connectionFromId(const QNetworkSession::State QNetworkManagerEngine::sessionStateForId(const QString &id) { + QMutexLocker locker(&mutex); + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); if (!ptr) @@ -718,6 +762,8 @@ QNetworkSession::State QNetworkManagerEngine::sessionStateForId(const QString &i quint64 QNetworkManagerEngine::bytesWritten(const QString &id) { + QMutexLocker locker(&mutex); + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); if (ptr && (ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { const QString networkInterface = getInterfaceFromId(id); @@ -744,6 +790,8 @@ quint64 QNetworkManagerEngine::bytesWritten(const QString &id) quint64 QNetworkManagerEngine::bytesReceived(const QString &id) { + QMutexLocker locker(&mutex); + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); if (ptr && (ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { const QString networkInterface = getInterfaceFromId(id); @@ -770,6 +818,8 @@ quint64 QNetworkManagerEngine::bytesReceived(const QString &id) quint64 QNetworkManagerEngine::startTime(const QString &id) { + QMutexLocker locker(&mutex); + QNetworkManagerSettingsConnection *connection = connectionFromId(id); if (connection) return connection->getTimestamp(); diff --git a/src/plugins/bearer/nla/qnlaengine.cpp b/src/plugins/bearer/nla/qnlaengine.cpp index 2001c0b..ff334e5 100644 --- a/src/plugins/bearer/nla/qnlaengine.cpp +++ b/src/plugins/bearer/nla/qnlaengine.cpp @@ -521,6 +521,8 @@ QNlaEngine::~QNlaEngine() void QNlaEngine::networksChanged() { + QMutexLocker locker(&mutex); + QStringList previous = accessPointConfigurations.keys(); QList foundConfigurations = nlaThread->getConfigurations(); @@ -574,11 +576,15 @@ void QNlaEngine::networksChanged() QString QNlaEngine::getInterfaceFromId(const QString &id) { + QMutexLocker locker(&mutex); + return configurationInterface.value(id.toUInt()); } bool QNlaEngine::hasIdentifier(const QString &id) { + QMutexLocker locker(&mutex); + return configurationInterface.contains(id.toUInt()); } @@ -604,11 +610,15 @@ void QNlaEngine::disconnectFromId(const QString &id) void QNlaEngine::requestUpdate() { + QMutexLocker locker(&mutex); + nlaThread->forceUpdate(); } QNetworkSession::State QNlaEngine::sessionStateForId(const QString &id) { + QMutexLocker locker(&mutex); + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); if (!ptr) diff --git a/src/plugins/bearer/qnetworksession_impl.cpp b/src/plugins/bearer/qnetworksession_impl.cpp index 3fe844a..f41fdba 100644 --- a/src/plugins/bearer/qnetworksession_impl.cpp +++ b/src/plugins/bearer/qnetworksession_impl.cpp @@ -57,7 +57,7 @@ static QBearerEngineImpl *getEngineFromId(const QString &id) { QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); - foreach (QBearerEngine *engine, priv->sessionEngines) { + foreach (QBearerEngine *engine, priv->engines()) { QBearerEngineImpl *engineImpl = qobject_cast(engine); if (engineImpl && engineImpl->hasIdentifier(id)) return engineImpl; diff --git a/src/plugins/bearer/symbian/symbianengine.cpp b/src/plugins/bearer/symbian/symbianengine.cpp index e25eda4..0331026 100644 --- a/src/plugins/bearer/symbian/symbianengine.cpp +++ b/src/plugins/bearer/symbian/symbianengine.cpp @@ -158,6 +158,8 @@ SymbianEngine::~SymbianEngine() bool SymbianEngine::hasIdentifier(const QString &id) { + QMutexLocker locker(&mutex); + return accessPointConfigurations.contains(id) || snapConfigurations.contains(id) || userChoiceConfigurations.contains(id); @@ -187,6 +189,8 @@ QNetworkSessionPrivate *SymbianEngine::createSessionBackend() void SymbianEngine::requestUpdate() { + QMutexLocker locker(&mutex); + if (!iInitOk || iUpdateGoingOn) { return; } @@ -199,6 +203,8 @@ void SymbianEngine::requestUpdate() void SymbianEngine::updateConfigurations() { + QMutexLocker locker(&mutex); + if (!iInitOk) { return; } @@ -208,6 +214,8 @@ void SymbianEngine::updateConfigurations() void SymbianEngine::updateConfigurationsL() { + QMutexLocker locker(&mutex); + QList knownConfigs = accessPointConfigurations.keys(); QList knownSnapConfigs = snapConfigurations.keys(); @@ -381,6 +389,8 @@ void SymbianEngine::updateConfigurationsL() SymbianNetworkConfigurationPrivate *SymbianEngine::configFromConnectionMethodL( RCmConnectionMethod& connectionMethod) { + QMutexLocker locker(&mutex); + SymbianNetworkConfigurationPrivate *cpPriv = new SymbianNetworkConfigurationPrivate; CleanupStack::PushL(cpPriv); @@ -463,6 +473,8 @@ SymbianNetworkConfigurationPrivate *SymbianEngine::configFromConnectionMethodL( bool SymbianEngine::readNetworkConfigurationValuesFromCommsDb( TUint32 aApId, SymbianNetworkConfigurationPrivate *apNetworkConfiguration) { + QMutexLocker locker(&mutex); + TRAPD(error, readNetworkConfigurationValuesFromCommsDbL(aApId,apNetworkConfiguration)); if (error != KErrNone) { return false; @@ -473,6 +485,8 @@ bool SymbianEngine::readNetworkConfigurationValuesFromCommsDb( void SymbianEngine::readNetworkConfigurationValuesFromCommsDbL( TUint32 aApId, SymbianNetworkConfigurationPrivate *apNetworkConfiguration) { + QMutexLocker locker(&mutex); + CApDataHandler* pDataHandler = CApDataHandler::NewLC(*ipCommsDB); CApAccessPointItem* pAPItem = CApAccessPointItem::NewLC(); TBuf name; @@ -533,6 +547,8 @@ void SymbianEngine::readNetworkConfigurationValuesFromCommsDbL( QNetworkConfigurationPrivatePointer SymbianEngine::defaultConfiguration() { + QMutexLocker locker(&mutex); + QNetworkConfigurationPrivatePointer ptr; if (iInitOk) { @@ -546,6 +562,8 @@ QNetworkConfigurationPrivatePointer SymbianEngine::defaultConfiguration() QNetworkConfigurationPrivatePointer SymbianEngine::defaultConfigurationL() { + QMutexLocker locker(&mutex); + QNetworkConfigurationPrivatePointer ptr; #ifdef SNAP_FUNCTIONALITY_AVAILABLE @@ -571,6 +589,8 @@ QNetworkConfigurationPrivatePointer SymbianEngine::defaultConfigurationL() void SymbianEngine::updateActiveAccessPoints() { + QMutexLocker locker(&mutex); + bool online = false; QList inactiveConfigs = accessPointConfigurations.keys(); @@ -620,6 +640,8 @@ void SymbianEngine::updateActiveAccessPoints() void SymbianEngine::updateAvailableAccessPoints() { + QMutexLocker locker(&mutex); + if (!ipAccessPointsAvailabilityScanner) { ipAccessPointsAvailabilityScanner = new AccessPointsAvailabilityScanner(*this, iConnectionMonitor); } @@ -631,6 +653,8 @@ void SymbianEngine::updateAvailableAccessPoints() void SymbianEngine::accessPointScanningReady(TBool scanSuccessful, TConnMonIapInfo iapInfo) { + QMutexLocker locker(&mutex); + iUpdateGoingOn = false; if (scanSuccessful) { QList unavailableConfigs = accessPointConfigurations.keys(); @@ -668,6 +692,8 @@ void SymbianEngine::accessPointScanningReady(TBool scanSuccessful, TConnMonIapIn void SymbianEngine::updateStatesToSnaps() { + QMutexLocker locker(&mutex); + // Go through SNAPs and set correct state to SNAPs QList snapConfigIdents = snapConfigurations.keys(); foreach (QString iface, snapConfigIdents) { @@ -700,6 +726,8 @@ void SymbianEngine::updateStatesToSnaps() bool SymbianEngine::changeConfigurationStateTo(QNetworkConfigurationPrivatePointer ptr, QNetworkConfiguration::StateFlags newState) { + QMutexLocker locker(&mutex); + if (newState != ptr->state) { ptr->state = newState; emit configurationChanged(ptr); @@ -715,6 +743,8 @@ bool SymbianEngine::changeConfigurationStateTo(QNetworkConfigurationPrivatePoint bool SymbianEngine::changeConfigurationStateAtMinTo(QNetworkConfigurationPrivatePointer ptr, QNetworkConfiguration::StateFlags newState) { + QMutexLocker locker(&mutex); + if ((newState | ptr->state) != ptr->state) { ptr->state = (ptr->state | newState); emit configurationChanged(ptr); @@ -731,6 +761,8 @@ bool SymbianEngine::changeConfigurationStateAtMinTo(QNetworkConfigurationPrivate bool SymbianEngine::changeConfigurationStateAtMaxTo(QNetworkConfigurationPrivatePointer ptr, QNetworkConfiguration::StateFlags newState) { + QMutexLocker locker(&mutex); + if ((newState & ptr->state) != ptr->state) { ptr->state = (newState & ptr->state); emit configurationChanged(ptr); @@ -741,6 +773,8 @@ bool SymbianEngine::changeConfigurationStateAtMaxTo(QNetworkConfigurationPrivate void SymbianEngine::startCommsDatabaseNotifications() { + QMutexLocker locker(&mutex); + if (!iWaitingCommsDatabaseNotifications) { iWaitingCommsDatabaseNotifications = ETrue; if (!IsActive()) { @@ -753,6 +787,8 @@ void SymbianEngine::startCommsDatabaseNotifications() void SymbianEngine::stopCommsDatabaseNotifications() { + QMutexLocker locker(&mutex); + if (iWaitingCommsDatabaseNotifications) { iWaitingCommsDatabaseNotifications = EFalse; if (!IsActive()) { @@ -769,6 +805,8 @@ void SymbianEngine::stopCommsDatabaseNotifications() void SymbianEngine::RunL() { + QMutexLocker locker(&mutex); + if (iStatus != KErrCancel) { RDbNotifier::TEvent event = STATIC_CAST(RDbNotifier::TEvent, iStatus.Int()); switch (event) { @@ -805,12 +843,16 @@ void SymbianEngine::RunL() void SymbianEngine::DoCancel() { + QMutexLocker locker(&mutex); + ipCommsDB->CancelRequestNotification(); } void SymbianEngine::EventL(const CConnMonEventBase& aEvent) { + QMutexLocker locker(&mutex); + switch (aEvent.EventType()) { case EConnMonCreateConnection: { @@ -902,6 +944,8 @@ void SymbianEngine::EventL(const CConnMonEventBase& aEvent) QNetworkConfigurationPrivatePointer SymbianEngine::dataByConnectionId(TUint aConnectionId) { + QMutexLocker locker(&mutex); + QNetworkConfiguration item; QHash::const_iterator i = -- cgit v0.12