diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-03-15 04:57:33 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-03-15 04:57:33 (GMT) |
commit | f5fa6d1955f4fc49e7bcf2bb1ef905d5927fe158 (patch) | |
tree | 2929fc2f4afcf1fca05b33dd30ddfc9b86142b96 /src/plugins | |
parent | 065f26ef3996368ba67ff5d8e34b20106c359a95 (diff) | |
parent | 1edf1e7c80857165c2cdc01c97658518a20bb806 (diff) | |
download | Qt-f5fa6d1955f4fc49e7bcf2bb1ef905d5927fe158.zip Qt-f5fa6d1955f4fc49e7bcf2bb1ef905d5927fe158.tar.gz Qt-f5fa6d1955f4fc49e7bcf2bb1ef905d5927fe158.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-1: (56 commits)
Remove NetworkManager test-bed application.
Remove configure test for NetworkManager.
Fix QDir::entryList regression
Add DEFINES to mingw32/windres.exe command line.
Fix up whitespace in license headers.
Fix SetDialogPreference build error on Symbian.
get known wifi networks a more complicated way, but without accessing
Only enable BM by default in QNAM for appropriate platforms.
fix crash on 10.6 with no wifi interface
Fix creation of QNetworkSession.
Make QNetworkConfigurationManager and QNetworkConfiguration threadsafe.
remove qt_winQString2MB() and qt_winMB2QString()
Fix include() path in qimportbase.pri
Fix qmake crash on Windows
Compile
Revert some unfinished changes.
Fix compilation with namespaced Qt
Add a placeholder text into the new search lineedit
Ui improvements to QDBusViewer.
Make double-clicking a d-bus method work again
...
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/bearer/bearer.pro | 2 | ||||
-rw-r--r-- | src/plugins/bearer/corewlan/qcorewlanengine.h | 13 | ||||
-rw-r--r-- | src/plugins/bearer/corewlan/qcorewlanengine.mm | 401 | ||||
-rw-r--r-- | src/plugins/bearer/generic/qgenericengine.cpp | 20 | ||||
-rw-r--r-- | src/plugins/bearer/generic/qgenericengine.h | 2 | ||||
-rw-r--r-- | src/plugins/bearer/icd/qicdengine.cpp | 25 | ||||
-rw-r--r-- | src/plugins/bearer/icd/qicdengine.h | 2 | ||||
-rw-r--r-- | src/plugins/bearer/icd/qnetworksession_impl.cpp | 221 | ||||
-rw-r--r-- | src/plugins/bearer/nativewifi/qnativewifiengine.cpp | 23 | ||||
-rw-r--r-- | src/plugins/bearer/nativewifi/qnativewifiengine.h | 2 | ||||
-rw-r--r-- | src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp | 60 | ||||
-rw-r--r-- | src/plugins/bearer/networkmanager/qnetworkmanagerengine.h | 2 | ||||
-rw-r--r-- | src/plugins/bearer/nla/qnlaengine.cpp | 14 | ||||
-rw-r--r-- | src/plugins/bearer/nla/qnlaengine.h | 2 | ||||
-rw-r--r-- | src/plugins/bearer/symbian/qnetworksession_impl.cpp | 198 | ||||
-rw-r--r-- | src/plugins/bearer/symbian/symbianengine.cpp | 56 | ||||
-rw-r--r-- | src/plugins/bearer/symbian/symbianengine.h | 2 |
17 files changed, 809 insertions, 236 deletions
diff --git a/src/plugins/bearer/bearer.pro b/src/plugins/bearer/bearer.pro index a67c8f6..00be80e 100644 --- a/src/plugins/bearer/bearer.pro +++ b/src/plugins/bearer/bearer.pro @@ -1,6 +1,6 @@ TEMPLATE = subdirs -!maemo:contains(QT_CONFIG, dbus):contains(QT_CONFIG, networkmanager) { +!maemo6:contains(QT_CONFIG, dbus) { SUBDIRS += networkmanager generic } #win32:SUBDIRS += nla diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.h b/src/plugins/bearer/corewlan/qcorewlanengine.h index cbaa9d6..76574a8 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.h +++ b/src/plugins/bearer/corewlan/qcorewlanengine.h @@ -68,7 +68,7 @@ public: void connectToId(const QString &id); void disconnectFromId(const QString &id); - void requestUpdate(); + Q_INVOKABLE void requestUpdate(); QNetworkSession::State sessionStateForId(const QString &id); @@ -90,14 +90,21 @@ private: QMap<QString, QString> configurationInterface; QStringList scanForSsids(const QString &interfaceName); - bool isKnownSsid(const QString &interfaceName, const QString &ssid); + bool isKnownSsid(const QString &ssid); QList<QNetworkConfigurationPrivate *> foundConfigurations; SCDynamicStoreRef storeSession; CFRunLoopSourceRef runloopSource; - void startNetworkChangeLoop(); + bool hasWifi; + +protected: + QMap<QString, QMap<QString,QString> > userProfiles; + void startNetworkChangeLoop(); + void getUserConfigurations(); + QString getNetworkNameFromSsid(const QString &ssid); + QString getSsidFromNetworkName(const QString &name); }; QT_END_NAMESPACE diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm index cb278d9..392e24c 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.mm +++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm @@ -50,13 +50,11 @@ #include <QtCore/qstringlist.h> #include <QtCore/qdebug.h> - -#if defined(MAC_SDK_10_6) //not much functionality without this +#include <QDir> #include <CoreWLAN/CoreWLAN.h> #include <CoreWLAN/CWInterface.h> #include <CoreWLAN/CWNetwork.h> #include <CoreWLAN/CWNetwork.h> -#endif #include <Foundation/NSEnumerator.h> #include <Foundation/NSKeyValueObserving.h> @@ -69,16 +67,14 @@ QMap <QString, QString> networkInterfaces; -#ifdef MAC_SDK_10_6 @interface QNSListener : NSObject { NSNotificationCenter *center; CWInterface *currentInterface; QCoreWlanEngine *engine; - NSAutoreleasePool *autoreleasepool; NSLock *locker; } -- (void)notificationHandler:(NSNotification *)notification; +- (void)notificationHandler;//:(NSNotification *)notification; - (void)remove; - (void)setEngine:(QCoreWlanEngine *)coreEngine; - (void)dealloc; @@ -91,7 +87,7 @@ QMap <QString, QString> networkInterfaces; - (id) init { [locker lock]; - autoreleasepool = [[NSAutoreleasePool alloc] init]; + QMacCocoaAutoReleasePool pool; center = [NSNotificationCenter defaultCenter]; currentInterface = [CWInterface interface]; // [center addObserver:self selector:@selector(notificationHandler:) name:kCWLinkDidChangeNotification object:nil]; @@ -102,7 +98,6 @@ QMap <QString, QString> networkInterfaces; -(void)dealloc { - [autoreleasepool release]; [super dealloc]; } @@ -121,7 +116,7 @@ QMap <QString, QString> networkInterfaces; [locker unlock]; } -- (void)notificationHandler:(NSNotification *)notification +- (void)notificationHandler//:(NSNotification *)notification { engine->requestUpdate(); } @@ -129,14 +124,12 @@ QMap <QString, QString> networkInterfaces; QNSListener *listener = 0; -#endif - QT_BEGIN_NAMESPACE static QString qGetInterfaceType(const QString &interfaceString) { - return networkInterfaces.value(interfaceString, QLatin1String("Unknown")); + return networkInterfaces.value(interfaceString, QLatin1String("WLAN")); } void networkChangeCallback(SCDynamicStoreRef/* store*/, CFArrayRef changedKeys, void *info) @@ -157,22 +150,24 @@ QCoreWlanEngine::QCoreWlanEngine(QObject *parent) { startNetworkChangeLoop(); -#if defined(MAC_SDK_10_6) - if(!listener) { + QMacCocoaAutoReleasePool pool; + if([[CWInterface supportedInterfaces] count] > 0 && !listener) { listener = [[QNSListener alloc] init]; listener.engine = this; + hasWifi = true; + } else { + hasWifi = false; } -#endif + getUserConfigurations(); + requestUpdate(); } QCoreWlanEngine::~QCoreWlanEngine() { while (!foundConfigurations.isEmpty()) delete foundConfigurations.takeFirst(); -#if defined(MAC_SDK_10_6) [listener remove]; [listener release]; -#endif } QString QCoreWlanEngine::getInterfaceFromId(const QString &id) @@ -192,73 +187,88 @@ bool QCoreWlanEngine::hasIdentifier(const QString &id) void QCoreWlanEngine::connectToId(const QString &id) { QMutexLocker locker(&mutex); - - NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + QMacCocoaAutoReleasePool pool; QString interfaceString = getInterfaceFromId(id); if(networkInterfaces.value(interfaceString) == "WLAN") { -#if defined(MAC_SDK_10_6) CWInterface *wifiInterface = [CWInterface interfaceWithName: qt_mac_QStringToNSString(interfaceString)]; - CWConfiguration *userConfig = [ wifiInterface configuration]; - - NSSet *remNets = [userConfig rememberedNetworks]; //CWWirelessProfile - NSEnumerator *enumerator = [remNets objectEnumerator]; - CWWirelessProfile *wProfile; - NSUInteger index=0; - NSDictionary *parametersDict; - NSArray* apArray; - - CW8021XProfile *user8021XProfile; - NSError *err; - NSMutableDictionary *params; + if([wifiInterface power]) { + NSError *err = nil; + NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0]; + + NSString *wantedSsid = 0; + bool okToProceed = true; + if(getNetworkNameFromSsid(id) != id) { + NSArray *array = [CW8021XProfile allUser8021XProfiles]; + for (NSUInteger i=0; i<[array count]; ++i) { + const QString idCheck = QString::number(qHash(QLatin1String("corewlan:") + qt_mac_NSStringToQString([[array objectAtIndex:i] userDefinedName]))); + const QString idCheck2 = QString::number(qHash(QLatin1String("corewlan:") + qt_mac_NSStringToQString([[array objectAtIndex:i] ssid]))); + + if(id == idCheck + || id == idCheck2) { + QString thisName = getSsidFromNetworkName(id); + if(thisName.isEmpty()) { + wantedSsid = qt_mac_QStringToNSString(id); + } else { + wantedSsid = qt_mac_QStringToNSString(thisName); + } + okToProceed = false; + [params setValue: [array objectAtIndex:i] forKey:kCWAssocKey8021XProfile]; + break; + } + } + } - while ((wProfile = [enumerator nextObject])) { //CWWirelessProfile + if(okToProceed) { + NSUInteger index = 0; - if(id == QString::number(qHash(QLatin1String("corewlan:") + qt_mac_NSStringToQString([wProfile ssid])))) { - user8021XProfile = nil; - user8021XProfile = [ wProfile user8021XProfile]; + CWConfiguration *userConfig = [ wifiInterface configuration]; + NSSet *remNets = [userConfig rememberedNetworks]; + NSEnumerator *enumerator = [remNets objectEnumerator]; + CWWirelessProfile *wProfile; - err = nil; - params = [NSMutableDictionary dictionaryWithCapacity:0]; + while ((wProfile = [enumerator nextObject])) { + const QString idCheck = QString::number(qHash(QLatin1String("corewlan:") + qt_mac_NSStringToQString([wProfile ssid]))); - if(user8021XProfile) { - [params setValue: user8021XProfile forKey:kCWAssocKey8021XProfile]; - } else { - [params setValue: [wProfile passphrase] forKey: kCWAssocKeyPassphrase]; + if(id == idCheck) { + wantedSsid = [wProfile ssid]; + [params setValue: [wProfile passphrase] forKey: kCWAssocKeyPassphrase]; + break; + } + index++; } + } - parametersDict = nil; - apArray = [NSMutableArray arrayWithArray:[wifiInterface scanForNetworksWithParameters:parametersDict error:&err]]; - - if(!err) { - - for(uint row=0; row < [apArray count]; row++ ) { - CWNetwork *apNetwork = [apArray objectAtIndex:row]; - if([[apNetwork ssid] compare:[wProfile ssid]] == NSOrderedSame) { + NSDictionary *parametersDict = nil; + NSArray *apArray = [NSMutableArray arrayWithArray:[wifiInterface scanForNetworksWithParameters:parametersDict error:&err]]; - bool result = [wifiInterface associateToNetwork: apNetwork parameters:[NSDictionary dictionaryWithDictionary:params] error:&err]; + if(!err) { + for(uint row=0; row < [apArray count]; row++ ) { + CWNetwork *apNetwork = [apArray objectAtIndex:row]; + if([[apNetwork ssid] compare:wantedSsid] == NSOrderedSame) { + bool result = [wifiInterface associateToNetwork: apNetwork parameters:[NSDictionary dictionaryWithDictionary:params] error:&err]; - if(!result) { - emit connectionError(id, ConnectError); - } else { - [autoreleasepool release]; - return; - } + if(!result) { + emit connectionError(id, ConnectError); + } else { + return; } } } + } else { + qDebug() <<"ERROR"<< qt_mac_NSStringToQString([err localizedDescription ]); } - index++; - } + emit connectionError(id, InterfaceLookupError); + } else { + // not wifi + } + locker.unlock(); emit connectionError(id, InterfaceLookupError); -#endif - } else { - // not wifi + locker.relock(); } emit connectionError(id, OperationNotSupported); - [autoreleasepool release]; } void QCoreWlanEngine::disconnectFromId(const QString &id) @@ -268,25 +278,26 @@ void QCoreWlanEngine::disconnectFromId(const QString &id) QString interfaceString = getInterfaceFromId(id); if(networkInterfaces.value(getInterfaceFromId(id)) == "WLAN") { //wifi only for now #if defined(MAC_SDK_10_6) - NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + QMacCocoaAutoReleasePool pool; CWInterface *wifiInterface = [CWInterface interfaceWithName: qt_mac_QStringToNSString(interfaceString)]; [wifiInterface disassociate]; if([[wifiInterface interfaceState]intValue] != kCWInterfaceStateInactive) { + locker.unlock(); emit connectionError(id, DisconnectionError); + locker.relock(); } - [autoreleasepool release]; return; #endif } else { } + + locker.unlock(); emit connectionError(id, OperationNotSupported); } void QCoreWlanEngine::requestUpdate() { - QMutexLocker locker(&mutex); - doRequestUpdate(); } @@ -340,6 +351,8 @@ void QCoreWlanEngine::doRequestUpdate() bool changed = false; + ptr->mutex.lock(); + if (!ptr->isValid) { ptr->isValid = true; changed = true; @@ -360,8 +373,13 @@ void QCoreWlanEngine::doRequestUpdate() changed = true; } - if (changed) + ptr->mutex.unlock(); + + if (changed) { + locker.unlock(); emit configurationChanged(ptr); + locker.relock(); + } } } @@ -369,9 +387,13 @@ void QCoreWlanEngine::doRequestUpdate() QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(previous.takeFirst()); configurationInterface.remove(ptr->id); + + locker.unlock(); emit configurationRemoved(ptr); + locker.relock(); } + locker.unlock(); emit updateCompleted(); } @@ -381,16 +403,20 @@ QStringList QCoreWlanEngine::scanForSsids(const QString &interfaceName) QStringList found; -#if defined(MAC_SDK_10_6) - QMacCocoaAutoReleasePool pool; + if(!hasWifi) { + return found; + } + QMacCocoaAutoReleasePool pool; CWInterface *currentInterface = [CWInterface interfaceWithName:qt_mac_QStringToNSString(interfaceName)]; + QStringList addedConfigs; + if([currentInterface power]) { NSError *err = nil; NSDictionary *parametersDict = nil; NSArray* apArray = [currentInterface scanForNetworksWithParameters:parametersDict error:&err]; - CWNetwork *apNetwork; + if (!err) { for(uint row=0; row < [apArray count]; row++ ) { @@ -402,15 +428,18 @@ QStringList QCoreWlanEngine::scanForSsids(const QString &interfaceName) found.append(id); QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined; - - if ([currentInterface.interfaceState intValue] == kCWInterfaceStateRunning) { - if (networkSsid == qt_mac_NSStringToQString([currentInterface ssid])) + bool known = isKnownSsid(networkSsid); + if( [currentInterface.interfaceState intValue] == kCWInterfaceStateRunning) { + if( networkSsid == qt_mac_NSStringToQString( [currentInterface ssid])) { state = QNetworkConfiguration::Active; - } else { - if (isKnownSsid(interfaceName, networkSsid)) + } + } + if(state == QNetworkConfiguration::Undefined) { + if(known) { state = QNetworkConfiguration::Discovered; - else - state = QNetworkConfiguration::Defined; + } else { + state = QNetworkConfiguration::Undefined; + } } if (accessPointConfigurations.contains(id)) { @@ -418,6 +447,8 @@ QStringList QCoreWlanEngine::scanForSsids(const QString &interfaceName) bool changed = false; + ptr->mutex.lock(); + if (!ptr->isValid) { ptr->isValid = true; changed = true; @@ -438,11 +469,18 @@ QStringList QCoreWlanEngine::scanForSsids(const QString &interfaceName) changed = true; } - if (changed) + ptr->mutex.unlock(); + + if (changed) { + locker.unlock(); emit configurationChanged(ptr); + locker.relock(); + } + addedConfigs << networkSsid; } else { QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate); + found.append(id); ptr->name = networkSsid; ptr->isValid = true; ptr->id = id; @@ -450,17 +488,60 @@ QStringList QCoreWlanEngine::scanForSsids(const QString &interfaceName) ptr->type = QNetworkConfiguration::InternetAccessPoint; ptr->bearer = QLatin1String("WLAN"); - accessPointConfigurations.insert(id, ptr); - configurationInterface.insert(id, interfaceName); + accessPointConfigurations.insert(ptr->id, ptr); + configurationInterface.insert(ptr->id, interfaceName); + locker.unlock(); emit configurationAdded(ptr); + locker.relock(); + addedConfigs << networkSsid; } } } } -#else - Q_UNUSED(interfaceName); -#endif + + // add known configurations that are not around. + QMapIterator<QString, QMap<QString,QString> > i(userProfiles); + while (i.hasNext()) { + i.next(); + QString networkName = i.key(); + if(!addedConfigs.contains(networkName)) { + QString interfaceName; + QMapIterator<QString, QString> ij(i.value()); + while (ij.hasNext()) { + ij.next(); + interfaceName = ij.value(); + } + QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate); + const QString id = QString::number(qHash(QLatin1String("corewlan:") + networkName)); + found.append(id); + + ptr->name = networkName; + ptr->isValid = true; + ptr->id = id; + ptr->bearer = QLatin1String("WLAN"); + ptr->type = QNetworkConfiguration::InternetAccessPoint; + QString ssid = getSsidFromNetworkName(networkName); + + if( [currentInterface.interfaceState intValue] == kCWInterfaceStateRunning) { + if( ssid == qt_mac_NSStringToQString([currentInterface ssid])) { + ptr->state = QNetworkConfiguration::Active; + } + } + + if(!ptr->state) { + if( addedConfigs.contains(ssid)) { + ptr->state = QNetworkConfiguration::Discovered; + } + } + + if(!ptr->state) { + ptr->state = QNetworkConfiguration::Defined; + } + accessPointConfigurations.insert(ptr->id, ptr); + configurationInterface.insert(ptr->id, interfaceName); + } + } return found; } @@ -468,32 +549,27 @@ bool QCoreWlanEngine::isWifiReady(const QString &wifiDeviceName) { QMutexLocker locker(&mutex); -#if defined(MAC_SDK_10_6) - CWInterface *defaultInterface = [CWInterface interfaceWithName: qt_mac_QStringToNSString(wifiDeviceName)]; - if([defaultInterface power]) - return true; -#else - Q_UNUSED(wifiDeviceName); -#endif + if(hasWifi) { + QMacCocoaAutoReleasePool pool; + CWInterface *defaultInterface = [CWInterface interfaceWithName: qt_mac_QStringToNSString(wifiDeviceName)]; + if([defaultInterface power]) + return true; + } return false; } -bool QCoreWlanEngine::isKnownSsid(const QString &interfaceName, const QString &ssid) +bool QCoreWlanEngine::isKnownSsid(const QString &ssid) { QMutexLocker locker(&mutex); -#if defined(MAC_SDK_10_6) - CWInterface *wifiInterface = [CWInterface interfaceWithName: qt_mac_QStringToNSString(interfaceName)]; - CWConfiguration *userConfig = [wifiInterface configuration]; - NSSet *remNets = [userConfig rememberedNetworks]; - for (CWWirelessProfile *wProfile in remNets) { - if(ssid == qt_mac_NSStringToQString([wProfile ssid])) + QMapIterator<QString, QMap<QString,QString> > i(userProfiles); + while (i.hasNext()) { + i.next(); + QMap<QString,QString> map = i.value(); + if(map.keys().contains(ssid)) { return true; + } } -#else - Q_UNUSED(interfaceName); - Q_UNUSED(ssid); -#endif return false; } @@ -508,7 +584,6 @@ bool QCoreWlanEngine::getWifiInterfaces() for(uint row=0; row < [wifiInterfaces count]; row++ ) { networkInterfaces.insert( qt_mac_NSStringToQString([wifiInterfaces objectAtIndex:row]),"WLAN"); } - return true; } @@ -612,4 +687,124 @@ bool QCoreWlanEngine::requiresPolling() const return true; } +QString QCoreWlanEngine::getSsidFromNetworkName(const QString &name) +{ + QMapIterator<QString, QMap<QString,QString> > i(userProfiles); + while (i.hasNext()) { + i.next(); + + QMap<QString,QString> map = i.value(); + QMapIterator<QString, QString> ij(i.value()); + while (ij.hasNext()) { + ij.next(); + const QString idCheck = QString::number(qHash(QLatin1String("corewlan:") +i.key())); + if(name == i.key() || name == idCheck) { + return ij.key(); + } + } + } + return QString(); +} + +QString QCoreWlanEngine::getNetworkNameFromSsid(const QString &ssid) +{ + QMapIterator<QString, QMap<QString,QString> > i(userProfiles); + while (i.hasNext()) { + i.next(); + QMap<QString,QString> map = i.value(); + QMapIterator<QString, QString> ij(i.value()); + while (ij.hasNext()) { + ij.next(); + if(ij.key() == ssid) { + return i.key(); + } + + } + return map.key(ssid); + } + return QString(); +} + + +void QCoreWlanEngine::getUserConfigurations() +{ + QMacCocoaAutoReleasePool pool; + userProfiles.clear(); + + NSArray *wifiInterfaces = [CWInterface supportedInterfaces]; + for(uint row=0; row < [wifiInterfaces count]; row++ ) { + + CWInterface *wifiInterface = [CWInterface interfaceWithName: [wifiInterfaces objectAtIndex:row]]; + +// add user configured system networks + NSString *filePath = @"/Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist"; + NSDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath]; + NSString *input = @"KnownNetworks"; + NSString *ssidStr = @"SSID_STR"; + + for (id key in plistDict) { + if ([input isEqualToString:key]) { + + NSDictionary *knownNetworksDict = [plistDict objectForKey:key]; + for (id networkKey in knownNetworksDict) { + + NSDictionary *itemDict = [knownNetworksDict objectForKey:networkKey]; + NSInteger dictSize = [itemDict count]; + id objects[dictSize]; + id keys[dictSize]; + + [itemDict getObjects:objects andKeys:keys]; + + for(int i = 0; i < dictSize; i++) { + if([ssidStr isEqualToString:keys[i]]) { + QString thisSsid = qt_mac_NSStringToQString(objects[i]); + if(!userProfiles.contains(thisSsid)) { + QMap <QString,QString> map; + map.insert(thisSsid, qt_mac_NSStringToQString([wifiInterface name])); + userProfiles.insert(thisSsid, map); + } + } + } + } + } + } + + // 802.1X user profiles + QString userProfilePath = QDir::homePath() + "/Library/Preferences/com.apple.eap.profiles.plist"; + NSDictionary* eapDict = [[NSMutableDictionary alloc] initWithContentsOfFile:qt_mac_QStringToNSString(userProfilePath)]; + NSString *profileStr= @"Profiles"; + NSString *nameStr = @"UserDefinedName"; + NSString *networkSsidStr = @"Wireless Network"; + for (id profileKey in eapDict) { + if ([profileStr isEqualToString:profileKey]) { + NSDictionary *itemDict = [eapDict objectForKey:profileKey]; + for (id itemKey in itemDict) { + + NSInteger dictSize = [itemKey count]; + id objects[dictSize]; + id keys[dictSize]; + + [itemKey getObjects:objects andKeys:keys]; + QString networkName; + QString ssid; + for(int i = 0; i < dictSize; i++) { + if([nameStr isEqualToString:keys[i]]) { + networkName = qt_mac_NSStringToQString(objects[i]); + } + if([networkSsidStr isEqualToString:keys[i]]) { + ssid = qt_mac_NSStringToQString(objects[i]); + } + if(!userProfiles.contains(networkName) + && !ssid.isEmpty()) { + QMap<QString,QString> map; + map.insert(ssid, qt_mac_NSStringToQString([wifiInterface name])); + userProfiles.insert(networkName, map); + } + } + } + } + } + } +} + QT_END_NAMESPACE diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp index a9e78b2..dfc74f2 100644 --- a/src/plugins/bearer/generic/qgenericengine.cpp +++ b/src/plugins/bearer/generic/qgenericengine.cpp @@ -50,6 +50,7 @@ #include <QtCore/qstringlist.h> #include <QtCore/qdebug.h> +#include <QtCore/private/qcoreapplication_p.h> #ifdef Q_OS_WIN #include "../platformdefs_win.h" @@ -174,8 +175,6 @@ void QGenericEngine::disconnectFromId(const QString &id) void QGenericEngine::requestUpdate() { - QMutexLocker locker(&mutex); - doRequestUpdate(); } @@ -231,6 +230,8 @@ void QGenericEngine::doRequestUpdate() bool changed = false; + ptr->mutex.lock(); + if (!ptr->isValid) { ptr->isValid = true; changed = true; @@ -251,8 +252,13 @@ void QGenericEngine::doRequestUpdate() changed = true; } - if (changed) + ptr->mutex.unlock(); + + if (changed) { + locker.unlock(); emit configurationChanged(ptr); + locker.relock(); + } } else { QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate); @@ -266,7 +272,9 @@ void QGenericEngine::doRequestUpdate() accessPointConfigurations.insert(id, ptr); configurationInterface.insert(id, interface.name()); + locker.unlock(); emit configurationAdded(ptr); + locker.relock(); } } @@ -275,9 +283,13 @@ void QGenericEngine::doRequestUpdate() accessPointConfigurations.take(previous.takeFirst()); configurationInterface.remove(ptr->id); + + locker.unlock(); emit configurationRemoved(ptr); + locker.relock(); } + locker.unlock(); emit updateCompleted(); } @@ -290,6 +302,8 @@ QNetworkSession::State QGenericEngine::sessionStateForId(const QString &id) if (!ptr) return QNetworkSession::Invalid; + QMutexLocker configLocker(&ptr->mutex); + if (!ptr->isValid) { return QNetworkSession::Invalid; } else if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { diff --git a/src/plugins/bearer/generic/qgenericengine.h b/src/plugins/bearer/generic/qgenericengine.h index a1b9167..616a3fd 100644 --- a/src/plugins/bearer/generic/qgenericengine.h +++ b/src/plugins/bearer/generic/qgenericengine.h @@ -68,7 +68,7 @@ public: void connectToId(const QString &id); void disconnectFromId(const QString &id); - void requestUpdate(); + Q_INVOKABLE void requestUpdate(); QNetworkSession::State sessionStateForId(const QString &id); diff --git a/src/plugins/bearer/icd/qicdengine.cpp b/src/plugins/bearer/icd/qicdengine.cpp index 5e506ef..5e9dc0a 100644 --- a/src/plugins/bearer/icd/qicdengine.cpp +++ b/src/plugins/bearer/icd/qicdengine.cpp @@ -180,7 +180,10 @@ void QIcdEngine::doRequestUpdate() ptr->roamingSupported = false; userChoiceConfigurations.insert(ptr->id, ptr); + + locker.unlock(); emit configurationAdded(ptr); + locker.relock(); } /* We return currently configured IAPs in the first run and do the WLAN @@ -241,7 +244,10 @@ void QIcdEngine::doRequestUpdate() QNetworkConfigurationPrivatePointer ptr(cpPriv); accessPointConfigurations.insert(iap_id, ptr); + + locker.unlock(); emit configurationAdded(ptr); + locker.relock(); #ifdef BEARER_MANAGEMENT_DEBUG qDebug("IAP: %s, name: %s, ssid: %s, added to known list", @@ -299,6 +305,8 @@ void QIcdEngine::doRequestUpdate() bool changed = false; + ptr->mutex.lock(); + if (!ptr->isValid) { ptr->isValid = true; changed = true; @@ -319,8 +327,13 @@ void QIcdEngine::doRequestUpdate() iapid.toAscii().data(), scanned_ssid.data()); #endif - if (changed) + ptr->mutex.unlock(); + + if (changed) { + locker.unlock(); emit configurationChanged(ptr); + locker.relock(); + } if (!ap.scan.network_type.startsWith("WLAN")) continue; // not a wlan AP @@ -354,7 +367,10 @@ void QIcdEngine::doRequestUpdate() QNetworkConfigurationPrivatePointer ptr(cpPriv); accessPointConfigurations.insert(ptr->id, ptr); + + locker.unlock(); emit configurationAdded(ptr); + locker.relock(); } } } @@ -363,11 +379,15 @@ void QIcdEngine::doRequestUpdate() QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(previous.takeFirst()); + locker.unlock(); emit configurationRemoved(ptr); + locker.relock(); } - if (sender()) + if (sender()) { + locker.unlock(); emit updateCompleted(); + } } void QIcdEngine::deleteConfiguration(const QString &iap_id) @@ -384,6 +404,7 @@ void QIcdEngine::deleteConfiguration(const QString &iap_id) qDebug() << "IAP" << iap_id << "was removed from storage."; #endif + locker.unlock(); emit configurationRemoved(ptr); } else { #ifdef BEARER_MANAGEMENT_DEBUG diff --git a/src/plugins/bearer/icd/qicdengine.h b/src/plugins/bearer/icd/qicdengine.h index 6ebe40d..50cda62 100644 --- a/src/plugins/bearer/icd/qicdengine.h +++ b/src/plugins/bearer/icd/qicdengine.h @@ -86,7 +86,7 @@ public: bool hasIdentifier(const QString &id); - void requestUpdate(); + Q_INVOKABLE void requestUpdate(); QNetworkConfigurationManager::Capabilities capabilities() const; diff --git a/src/plugins/bearer/icd/qnetworksession_impl.cpp b/src/plugins/bearer/icd/qnetworksession_impl.cpp index bb81408..a2ae65c 100644 --- a/src/plugins/bearer/icd/qnetworksession_impl.cpp +++ b/src/plugins/bearer/icd/qnetworksession_impl.cpp @@ -312,19 +312,42 @@ void QNetworkSessionPrivateImpl::updateState(QNetworkSession::State newState) state = newState; if (state == QNetworkSession::Disconnected) { - isOpen = false; + isOpen = false; currentNetworkInterface.clear(); - if (publicConfig.type() == QNetworkConfiguration::UserChoice) - privateConfiguration(activeConfig)->state = QNetworkConfiguration::Defined; - privateConfiguration(publicConfig)->state = QNetworkConfiguration::Defined; + if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + IcdNetworkConfigurationPrivate *icdConfig = + toIcdConfig(privateConfiguration(activeConfig)); + + icdConfig->mutex.lock(); + icdConfig->state = QNetworkConfiguration::Defined; + icdConfig->mutex.unlock(); + } + + IcdNetworkConfigurationPrivate *icdConfig = + toIcdConfig(privateConfiguration(publicConfig)); + + icdConfig->mutex.lock(); + icdConfig->state = QNetworkConfiguration::Defined; + icdConfig->mutex.unlock(); } else if (state == QNetworkSession::Connected) { - isOpen = true; + isOpen = true; if (publicConfig.type() == QNetworkConfiguration::UserChoice) { - privateConfiguration(activeConfig)->state = QNetworkConfiguration::Active; - privateConfiguration(activeConfig)->type = QNetworkConfiguration::InternetAccessPoint; + IcdNetworkConfigurationPrivate *icdConfig = + toIcdConfig(privateConfiguration(activeConfig)); + + icdConfig->mutex.lock(); + icdConfig->state = QNetworkConfiguration::Active; + icdConfig->type = QNetworkConfiguration::InternetAccessPoint; + icdConfig->mutex.unlock(); } - privateConfiguration(publicConfig)->state = QNetworkConfiguration::Active; + + IcdNetworkConfigurationPrivate *icdConfig = + toIcdConfig(privateConfiguration(publicConfig)); + + icdConfig->mutex.lock(); + icdConfig->state = QNetworkConfiguration::Active; + icdConfig->mutex.unlock(); } emit stateChanged(newState); @@ -334,13 +357,22 @@ void QNetworkSessionPrivateImpl::updateState(QNetworkSession::State newState) void QNetworkSessionPrivateImpl::updateIdentifier(QString &newId) { if (publicConfig.type() == QNetworkConfiguration::UserChoice) { - toIcdConfig(privateConfiguration(activeConfig))->network_attrs |= ICD_NW_ATTR_IAPNAME; - privateConfiguration(activeConfig)->id = newId; + IcdNetworkConfigurationPrivate *icdConfig = + toIcdConfig(privateConfiguration(activeConfig)); + + icdConfig->mutex.lock(); + icdConfig->network_attrs |= ICD_NW_ATTR_IAPNAME; + icdConfig->id = newId; + icdConfig->mutex.unlock(); } else { - toIcdConfig(privateConfiguration(publicConfig))->network_attrs |= ICD_NW_ATTR_IAPNAME; - if (privateConfiguration(publicConfig)->id != newId) { - privateConfiguration(publicConfig)->id = newId; - } + IcdNetworkConfigurationPrivate *icdConfig = + toIcdConfig(privateConfiguration(publicConfig)); + + icdConfig->mutex.lock(); + icdConfig->network_attrs |= ICD_NW_ATTR_IAPNAME; + if (icdConfig->id != newId) + icdConfig->id = newId; + icdConfig->mutex.unlock(); } } @@ -368,10 +400,15 @@ quint64 QNetworkSessionPrivateImpl::getStatistics(bool sent) const } } else { /* We probably will never get to this branch */ - if (res.params.network_id == toIcdConfig(privateConfiguration(activeConfig))->network_id) { - counter_tx = res.bytes_sent; - counter_rx = res.bytes_received; + IcdNetworkConfigurationPrivate *icdConfig = + toIcdConfig(privateConfiguration(activeConfig)); + + icdConfig->mutex.lock(); + if (res.params.network_id == icdConfig->network_id) { + counter_tx = res.bytes_sent; + counter_rx = res.bytes_received; } + icdConfig->mutex.unlock(); } } @@ -413,20 +450,25 @@ QNetworkConfiguration& QNetworkSessionPrivateImpl::copyConfig(QNetworkConfigurat cpPriv = toIcdConfig(privateConfiguration(toConfig)); } - cpPriv->name = privateConfiguration(fromConfig)->name; - cpPriv->isValid = privateConfiguration(fromConfig)->isValid; + IcdNetworkConfigurationPrivate *fromPriv = toIcdConfig(privateConfiguration(fromConfig)); + + QMutexLocker toLocker(&cpPriv->mutex); + QMutexLocker fromLocker(&fromPriv->mutex); + + cpPriv->name = fromPriv->name; + cpPriv->isValid = fromPriv->isValid; // Note that we do not copy id field here as the publicConfig does // not contain a valid IAP id. - cpPriv->state = privateConfiguration(fromConfig)->state; - cpPriv->type = privateConfiguration(fromConfig)->type; - cpPriv->roamingSupported = privateConfiguration(fromConfig)->roamingSupported; - cpPriv->purpose = privateConfiguration(fromConfig)->purpose; - cpPriv->network_id = toIcdConfig(privateConfiguration(fromConfig))->network_id; - cpPriv->iap_type = toIcdConfig(privateConfiguration(fromConfig))->iap_type; - cpPriv->network_attrs = toIcdConfig(privateConfiguration(fromConfig))->network_attrs; - cpPriv->service_type = toIcdConfig(privateConfiguration(fromConfig))->service_type; - cpPriv->service_id = toIcdConfig(privateConfiguration(fromConfig))->service_id; - cpPriv->service_attrs = toIcdConfig(privateConfiguration(fromConfig))->service_attrs; + cpPriv->state = fromPriv->state; + cpPriv->type = fromPriv->type; + cpPriv->roamingSupported = fromPriv->roamingSupported; + cpPriv->purpose = fromPriv->purpose; + cpPriv->network_id = fromPriv->network_id; + cpPriv->iap_type = fromPriv->iap_type; + cpPriv->network_attrs = fromPriv->network_attrs; + cpPriv->service_type = fromPriv->service_type; + cpPriv->service_id = fromPriv->service_id; + cpPriv->service_attrs = fromPriv->service_attrs; return toConfig; } @@ -511,18 +553,30 @@ void QNetworkSessionPrivateImpl::syncStateWithInterface() * then do not update current state etc. */ if (publicConfig.type() == QNetworkConfiguration::UserChoice || - privateConfiguration(publicConfig)->id == state_results.first().params.network_id) { + publicConfig.identifier() == state_results.first().params.network_id) { switch (state_results.first().state) { case ICD_STATE_DISCONNECTED: state = QNetworkSession::Disconnected; - if (privateConfiguration(activeConfig)) - privateConfiguration(activeConfig)->isValid = true; + { + QNetworkConfigurationPrivatePointer ptr = privateConfiguration(activeConfig); + if (ptr) { + ptr->mutex.lock(); + ptr->isValid = true; + ptr->mutex.unlock(); + } + } break; case ICD_STATE_CONNECTING: state = QNetworkSession::Connecting; - if (privateConfiguration(activeConfig)) - privateConfiguration(activeConfig)->isValid = true; + { + QNetworkConfigurationPrivatePointer ptr = privateConfiguration(activeConfig); + if (ptr) { + ptr->mutex.lock(); + ptr->isValid = true; + ptr->mutex.unlock(); + } + } break; case ICD_STATE_CONNECTED: { @@ -540,6 +594,8 @@ void QNetworkSessionPrivateImpl::syncStateWithInterface() QNetworkConfigurationPrivatePointer ptr = privateConfiguration(activeConfig); + QMutexLocker configLocker(&ptr->mutex); + state = QNetworkSession::Connected; toIcdConfig(ptr)->network_id = state_results.first().params.network_id; ptr->id = toIcdConfig(ptr)->network_id; @@ -553,26 +609,35 @@ void QNetworkSessionPrivateImpl::syncStateWithInterface() ptr->isValid = true; currentNetworkInterface = get_network_interface(); - Maemo::IAPConf iap_name(privateConfiguration(activeConfig)->id); + Maemo::IAPConf iap_name(ptr->id); QString name_value = iap_name.value("name").toString(); if (!name_value.isEmpty()) - privateConfiguration(activeConfig)->name = name_value; + ptr->name = name_value; else - privateConfiguration(activeConfig)->name = privateConfiguration(activeConfig)->id; + ptr->name = ptr->id; // Add the new active configuration to manager or update the old config - if (!engine->hasIdentifier(privateConfiguration(activeConfig)->id)) - engine->addSessionConfiguration(privateConfiguration(activeConfig)); - else - engine->changedSessionConfiguration(privateConfiguration(activeConfig)); - } + if (!engine->hasIdentifier(ptr->id)) { + configLocker.unlock(); + engine->addSessionConfiguration(ptr); + } else { + configLocker.unlock(); + engine->changedSessionConfiguration(ptr); + } + } break; case ICD_STATE_DISCONNECTING: state = QNetworkSession::Closing; - if (privateConfiguration(activeConfig)) - privateConfiguration(activeConfig)->isValid = true; + { + QNetworkConfigurationPrivatePointer ptr = privateConfiguration(activeConfig); + if (ptr) { + ptr->mutex.lock(); + ptr->isValid = true; + ptr->mutex.unlock(); + } + } break; default: break; @@ -634,12 +699,16 @@ void QNetworkSessionPrivateImpl::updateStateFromServiceNetwork() void QNetworkSessionPrivateImpl::clearConfiguration(QNetworkConfiguration &config) { - toIcdConfig(privateConfiguration(config))->network_id.clear(); - toIcdConfig(privateConfiguration(config))->iap_type.clear(); - toIcdConfig(privateConfiguration(config))->network_attrs = 0; - toIcdConfig(privateConfiguration(config))->service_type.clear(); - toIcdConfig(privateConfiguration(config))->service_id.clear(); - toIcdConfig(privateConfiguration(config))->service_attrs = 0; + IcdNetworkConfigurationPrivate *icdConfig = toIcdConfig(privateConfiguration(config)); + + QMutexLocker locker(&icdConfig->mutex); + + icdConfig->network_id.clear(); + icdConfig->iap_type.clear(); + icdConfig->network_attrs = 0; + icdConfig->service_type.clear(); + icdConfig->service_id.clear(); + icdConfig->service_attrs = 0; } @@ -649,8 +718,8 @@ void QNetworkSessionPrivateImpl::updateStateFromActiveConfig() bool newActive = false; - if (!privateConfiguration(activeConfig)) - return; + if (!activeConfig.isValid()) + return; if (!activeConfig.isValid()) { state = QNetworkSession::Invalid; @@ -837,16 +906,21 @@ void QNetworkSessionPrivateImpl::do_open() QList<Maemo::ConnectParams> params; Maemo::ConnectParams param; - param.connect.service_type = toIcdConfig(privateConfiguration(config))->service_type; - param.connect.service_attrs = toIcdConfig(privateConfiguration(config))->service_attrs; - param.connect.service_id = toIcdConfig(privateConfiguration(config))->service_id; - param.connect.network_type = toIcdConfig(privateConfiguration(config))->iap_type; - param.connect.network_attrs = toIcdConfig(privateConfiguration(config))->network_attrs; - if (toIcdConfig(privateConfiguration(config))->network_attrs & ICD_NW_ATTR_IAPNAME) + + IcdNetworkConfigurationPrivate *icdConfig = toIcdConfig(privateConfiguration(config)); + + icdConfig->mutex.lock(); + param.connect.service_type = icdConfig->service_type; + param.connect.service_attrs = icdConfig->service_attrs; + param.connect.service_id = icdConfig->service_id; + param.connect.network_type = icdConfig->iap_type; + param.connect.network_attrs = icdConfig->network_attrs; + if (icdConfig->network_attrs & ICD_NW_ATTR_IAPNAME) param.connect.network_id = QByteArray(iap.toLatin1()); else - param.connect.network_id = toIcdConfig(privateConfiguration(config))->network_id; + param.connect.network_id = icdConfig->network_id; params.append(param); + icdConfig->mutex.unlock(); #ifdef BEARER_MANAGEMENT_DEBUG qDebug("connecting to %s/%s/0x%x/%s/0x%x/%s", @@ -887,26 +961,30 @@ void QNetworkSessionPrivateImpl::do_open() return; } + IcdNetworkConfigurationPrivate *icdConfig = toIcdConfig(privateConfiguration(config)); /* Did we connect to non saved IAP? */ - if (!(toIcdConfig(privateConfiguration(config))->network_attrs & ICD_NW_ATTR_IAPNAME)) { + icdConfig->mutex.lock(); + if (!(icdConfig->network_attrs & ICD_NW_ATTR_IAPNAME)) { /* Because the connection succeeded, the IAP is now known. */ - toIcdConfig(privateConfiguration(config))->network_attrs |= ICD_NW_ATTR_IAPNAME; - privateConfiguration(config)->id = connected_iap; + icdConfig->network_attrs |= ICD_NW_ATTR_IAPNAME; + icdConfig->id = connected_iap; } /* User might have changed the IAP name when a new IAP was saved */ - Maemo::IAPConf iap_name(privateConfiguration(config)->id); + Maemo::IAPConf iap_name(icdConfig->id); QString name = iap_name.value("name").toString(); if (!name.isEmpty()) - privateConfiguration(config)->name = name; + icdConfig->name = name; + + icdConfig->iap_type = connect_result.connect.network_type; - toIcdConfig(privateConfiguration(config))->iap_type = connect_result.connect.network_type; + icdConfig->isValid = true; + icdConfig->state = QNetworkConfiguration::Active; + icdConfig->type = QNetworkConfiguration::InternetAccessPoint; - privateConfiguration(config)->isValid = true; - privateConfiguration(config)->state = QNetworkConfiguration::Active; - privateConfiguration(config)->type = QNetworkConfiguration::InternetAccessPoint; + icdConfig->mutex.unlock(); startTime = QDateTime::currentDateTime(); updateState(QNetworkSession::Connected); @@ -995,8 +1073,11 @@ void QNetworkSessionPrivateImpl::stop() * configurationChanged is emitted (below). */ - privateConfiguration(activeConfig)->state = QNetworkConfiguration::Discovered; - engine->changedSessionConfiguration(privateConfiguration(activeConfig)); + QNetworkConfigurationPrivatePointer ptr = privateConfiguration(activeConfig); + ptr->mutex.lock(); + ptr->state = QNetworkConfiguration::Discovered; + ptr->mutex.unlock(); + engine->changedSessionConfiguration(ptr); opened = false; isOpen = false; diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp index b6522ad..6c74159 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp @@ -185,6 +185,8 @@ void QNativeWifiEngine::scanComplete() bool changed = false; + ptr->mutex.lock(); + if (!ptr->isValid) { ptr->isValid = true; changed = true; @@ -200,8 +202,13 @@ void QNativeWifiEngine::scanComplete() changed = true; } - if (changed) + ptr->mutex.unlock(); + + if (changed) { + locker.unlock(); emit configurationChanged(ptr); + locker.relock(); + } } else { QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate); @@ -214,7 +221,9 @@ void QNativeWifiEngine::scanComplete() accessPointConfigurations.insert(id, ptr); + locker.unlock(); emit configurationAdded(ptr); + locker.relock(); } } @@ -227,9 +236,12 @@ void QNativeWifiEngine::scanComplete() QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(previous.takeFirst()); + locker.unlock(); emit configurationRemoved(ptr); + locker.relock(); } + locker.unlock(); emit updateCompleted(); } @@ -358,6 +370,7 @@ void QNativeWifiEngine::connectToId(const QString &id) #ifdef BEARER_MANAGEMENT_DEBUG qDebug("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); #endif + locker.unlock(); emit connectionError(id, InterfaceLookupError); return; } @@ -405,7 +418,9 @@ void QNativeWifiEngine::connectToId(const QString &id) #ifdef BEARER_MANAGEMENT_DEBUG qDebug("%s: WlanConnect failed with error %ld\n", __FUNCTION__, result); #endif + locker.unlock(); emit connectionError(id, ConnectError); + locker.relock(); break; } @@ -415,8 +430,10 @@ void QNativeWifiEngine::connectToId(const QString &id) local_WlanFreeMemory(interfaceList); - if (profile.isEmpty()) + if (profile.isEmpty()) { + locker.unlock(); emit connectionError(id, InterfaceLookupError); + } } void QNativeWifiEngine::disconnectFromId(const QString &id) @@ -426,6 +443,7 @@ void QNativeWifiEngine::disconnectFromId(const QString &id) QString interface = getInterfaceFromId(id); if (interface.isEmpty()) { + locker.unlock(); emit connectionError(id, InterfaceLookupError); return; } @@ -446,6 +464,7 @@ void QNativeWifiEngine::disconnectFromId(const QString &id) #ifdef BEARER_MANAGEMENT_DEBUG qDebug("%s: WlanDisconnect failed with error %ld\n", __FUNCTION__, result); #endif + locker.unlock(); emit connectionError(id, DisconnectionError); return; } diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.h b/src/plugins/bearer/nativewifi/qnativewifiengine.h index 56489b6..2005b2b 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.h +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.h @@ -78,7 +78,7 @@ public: void connectToId(const QString &id); void disconnectFromId(const QString &id); - void requestUpdate(); + Q_INVOKABLE void requestUpdate(); QNetworkSession::State sessionStateForId(const QString &id); diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp index 0fa8f3c..d7e315a 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp @@ -297,10 +297,17 @@ void QNetworkManagerEngine::interfacePropertiesChanged(const QString &path, QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); if (ptr) { + ptr->mutex.lock(); if (activeConnection->state() == 2 && ptr->state != QNetworkConfiguration::Active) { ptr->state = QNetworkConfiguration::Active; + ptr->mutex.unlock(); + + locker.unlock(); emit configurationChanged(ptr); + locker.relock(); + } else { + ptr->mutex.unlock(); } } } @@ -313,9 +320,16 @@ void QNetworkManagerEngine::interfacePropertiesChanged(const QString &path, QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(identifiers.takeFirst()); + ptr->mutex.lock(); if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { ptr->state = QNetworkConfiguration::Discovered; + ptr->mutex.unlock(); + + locker.unlock(); emit configurationChanged(ptr); + locker.relock(); + } else { + ptr->mutex.unlock(); } } } @@ -339,10 +353,17 @@ void QNetworkManagerEngine::activeConnectionPropertiesChanged(const QString &pat QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); if (ptr) { + ptr->mutex.lock(); if (activeConnection->state() == 2 && ptr->state != QNetworkConfiguration::Active) { ptr->state = QNetworkConfiguration::Active; + ptr->mutex.unlock(); + + locker.unlock(); emit configurationChanged(ptr); + locker.relock(); + } else { + ptr->mutex.unlock(); } } } @@ -424,6 +445,8 @@ void QNetworkManagerEngine::newConnection(const QDBusObjectPath &path, QNetworkConfigurationPrivatePointer ptr(cpPriv); accessPointConfigurations.insert(ptr->id, ptr); + + locker.unlock(); emit configurationAdded(ptr); } @@ -444,7 +467,8 @@ void QNetworkManagerEngine::removeConnection(const QString &path) connection->connectionInterface()->path())); QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(id); - ptr->isValid = false; + + locker.unlock(); emit configurationRemoved(ptr); } @@ -476,11 +500,16 @@ void QNetworkManagerEngine::updateConnection(const QNmSettingsMap &settings) QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(cpPriv->id); + ptr->mutex.lock(); + ptr->isValid = cpPriv->isValid; ptr->name = cpPriv->name; ptr->id = cpPriv->id; ptr->state = cpPriv->state; + ptr->mutex.unlock(); + + locker.unlock(); emit configurationChanged(ptr); delete cpPriv; } @@ -500,10 +529,17 @@ void QNetworkManagerEngine::activationFinished(QDBusPendingCallWatcher *watcher) QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); if (ptr) { + ptr->mutex.lock(); if (activeConnection.state() == 2 && ptr->state != QNetworkConfiguration::Active) { ptr->state = QNetworkConfiguration::Active; + ptr->mutex.unlock(); + + locker.unlock(); emit configurationChanged(ptr); + locker.relock(); + } else { + ptr->mutex.unlock(); } } } @@ -543,7 +579,11 @@ void QNetworkManagerEngine::newAccessPoint(const QString &path, const QDBusObjec QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(connectionId); + ptr->mutex.lock(); ptr->state = QNetworkConfiguration::Discovered; + ptr->mutex.unlock(); + + locker.unlock(); emit configurationChanged(ptr); return; } @@ -562,6 +602,8 @@ void QNetworkManagerEngine::newAccessPoint(const QString &path, const QDBusObjec ptr->bearer = QLatin1String("WLAN"); accessPointConfigurations.insert(ptr->id, ptr); + + locker.unlock(); emit configurationAdded(ptr); } @@ -592,7 +634,11 @@ void QNetworkManagerEngine::removeAccessPoint(const QString &path, QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(connectionId); + ptr->mutex.lock(); ptr->state = QNetworkConfiguration::Defined; + ptr->mutex.unlock(); + + locker.unlock(); emit configurationChanged(ptr); return; } @@ -601,8 +647,11 @@ void QNetworkManagerEngine::removeAccessPoint(const QString &path, QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(QString::number(qHash(objectPath.path()))); - if (ptr) + if (ptr) { + locker.unlock(); emit configurationRemoved(ptr); + locker.relock(); + } } delete accessPoint; @@ -633,7 +682,11 @@ void QNetworkManagerEngine::updateAccessPoint(const QMap<QString, QVariant> &map QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(connectionId); + ptr->mutex.lock(); ptr->state = QNetworkConfiguration::Discovered; + ptr->mutex.unlock(); + + locker.unlock(); emit configurationChanged(ptr); return; } @@ -687,7 +740,10 @@ QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QStri QString::number(qHash(accessPoints.at(i)->connectionInterface()->path())); QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(accessPointId); + + locker.unlock(); emit configurationRemoved(ptr); + locker.relock(); } break; } diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h index ca1f857..05a1429 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h @@ -80,7 +80,7 @@ public: void connectToId(const QString &id); void disconnectFromId(const QString &id); - void requestUpdate(); + Q_INVOKABLE void requestUpdate(); QNetworkSession::State sessionStateForId(const QString &id); diff --git a/src/plugins/bearer/nla/qnlaengine.cpp b/src/plugins/bearer/nla/qnlaengine.cpp index 334eb14..9ab9924 100644 --- a/src/plugins/bearer/nla/qnlaengine.cpp +++ b/src/plugins/bearer/nla/qnlaengine.cpp @@ -522,6 +522,8 @@ void QNlaEngine::networksChanged() bool changed = false; + ptr->mutex.lock(); + if (ptr->isValid != cpPriv->isValid) { ptr->isValid = cpPriv->isValid; changed = true; @@ -537,8 +539,13 @@ void QNlaEngine::networksChanged() changed = true; } - if (changed) + ptr->mutex.unlock(); + + if (changed) { + locker.unlock(); emit configurationChanged(ptr); + locker.relock(); + } delete cpPriv; } else { @@ -546,7 +553,9 @@ void QNlaEngine::networksChanged() accessPointConfigurations.insert(ptr->id, ptr); + locker.unlock(); emit configurationAdded(ptr); + locker.relock(); } } @@ -554,9 +563,12 @@ void QNlaEngine::networksChanged() QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(previous.takeFirst()); + locker.unlock(); emit configurationRemoved(ptr); + locker.relock(); } + locker.unlock(); emit updateCompleted(); } diff --git a/src/plugins/bearer/nla/qnlaengine.h b/src/plugins/bearer/nla/qnlaengine.h index 14c5201..1d49464 100644 --- a/src/plugins/bearer/nla/qnlaengine.h +++ b/src/plugins/bearer/nla/qnlaengine.h @@ -90,7 +90,7 @@ public: void connectToId(const QString &id); void disconnectFromId(const QString &id); - void requestUpdate(); + Q_INVOKABLE void requestUpdate(); QNetworkSession::State sessionStateForId(const QString &id); diff --git a/src/plugins/bearer/symbian/qnetworksession_impl.cpp b/src/plugins/bearer/symbian/qnetworksession_impl.cpp index bec562d..0737942 100644 --- a/src/plugins/bearer/symbian/qnetworksession_impl.cpp +++ b/src/plugins/bearer/symbian/qnetworksession_impl.cpp @@ -100,7 +100,7 @@ QNetworkSessionPrivateImpl::~QNetworkSessionPrivateImpl() void QNetworkSessionPrivateImpl::syncStateWithInterface() { - if (!privateConfiguration(publicConfig)) + if (!publicConfig.isValid()) return; // Start monitoring changes in IAP states @@ -143,9 +143,8 @@ void QNetworkSessionPrivateImpl::syncStateWithInterface() // There were no open connections to used IAP or SNAP if (iError == QNetworkSession::InvalidConfigurationError) { newState(QNetworkSession::Invalid); - } - else if ((privateConfiguration(publicConfig)->state & QNetworkConfiguration::Discovered) == - QNetworkConfiguration::Discovered) { + } else if ((publicConfig.state() & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { newState(QNetworkSession::Disconnected); } else { newState(QNetworkSession::NotAvailable); @@ -293,10 +292,15 @@ void QNetworkSessionPrivateImpl::open() for (TUint i=1; i<=count; i++) { // Note: GetConnectionInfo expects 1-based index. if (iConnection.GetConnectionInfo(i, connInfo) == KErrNone) { - if (connInfo().iIapId == toSymbianConfig(privateConfiguration(publicConfig))->numericId) { + SymbianNetworkConfigurationPrivate *symbianConfig = + toSymbianConfig(privateConfiguration(publicConfig)); + + QMutexLocker configLocker(&symbianConfig->mutex); + + if (connInfo().iIapId == symbianConfig->numericId) { if (iConnection.Attach(connInfo, RConnection::EAttachTypeNormal) == KErrNone) { activeConfig = publicConfig; - activeInterface = interface(toSymbianConfig(privateConfiguration(activeConfig))->numericId); + activeInterface = interface(symbianConfig->numericId); connected = ETrue; startTime = QDateTime::currentDateTime(); if (iDynamicSetdefaultif) { @@ -320,7 +324,12 @@ void QNetworkSessionPrivateImpl::open() if (!connected) { TCommDbConnPref pref; pref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); - pref.SetIapId(toSymbianConfig(privateConfiguration(publicConfig))->numericId); + SymbianNetworkConfigurationPrivate *symbianConfig = + toSymbianConfig(privateConfiguration(publicConfig)); + + symbianConfig->mutex.lock(); + pref.SetIapId(symbianConfig->numericId); + symbianConfig->mutex.unlock(); iConnection.Start(pref, iStatus); if (!IsActive()) { SetActive(); @@ -328,7 +337,12 @@ void QNetworkSessionPrivateImpl::open() newState(QNetworkSession::Connecting); } } else if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { - TConnSnapPref snapPref(toSymbianConfig(privateConfiguration(publicConfig))->numericId); + SymbianNetworkConfigurationPrivate *symbianConfig = + toSymbianConfig(privateConfiguration(publicConfig)); + + symbianConfig->mutex.lock(); + TConnSnapPref snapPref(symbianConfig->numericId); + symbianConfig->mutex.unlock(); iConnection.Start(snapPref, iStatus); if (!IsActive()) { SetActive(); @@ -387,7 +401,13 @@ void QNetworkSessionPrivateImpl::close(bool allowSignals) return; } - TUint activeIap = toSymbianConfig(privateConfiguration(activeConfig))->numericId; + SymbianNetworkConfigurationPrivate *symbianConfig = + toSymbianConfig(privateConfiguration(activeConfig)); + + symbianConfig->mutex.lock(); + TUint activeIap = symbianConfig->numericId; + symbianConfig->mutex.unlock(); + isOpen = false; activeConfig = QNetworkConfiguration(); serviceConfig = QNetworkConfiguration(); @@ -501,7 +521,13 @@ void QNetworkSessionPrivateImpl::PreferredCarrierAvailable(TAccessPointInfo aOld iALRUpgradingConnection = aIsUpgrade; QList<QNetworkConfiguration> configs = publicConfig.children(); for (int i=0; i < configs.count(); i++) { - if (toSymbianConfig(privateConfiguration(configs[i]))->numericId == aNewAPInfo.AccessPoint()) { + SymbianNetworkConfigurationPrivate *symbianConfig = + toSymbianConfig(privateConfiguration(configs[i])); + + QMutexLocker configLocker(&symbianConfig->mutex); + + if (symbianConfig->numericId == aNewAPInfo.AccessPoint()) { + configLocker.unlock(); emit preferredConfigurationChanged(configs[i], aIsSeamless); } } @@ -625,13 +651,24 @@ quint64 QNetworkSessionPrivateImpl::transferredData(TUint dataType) const if (config.type() == QNetworkConfiguration::ServiceNetwork) { QList<QNetworkConfiguration> configs = config.children(); for (int i=0; i < configs.count(); i++) { - if (toSymbianConfig(privateConfiguration(configs[i]))->numericId == apId) { + SymbianNetworkConfigurationPrivate *symbianConfig = + toSymbianConfig(privateConfiguration(configs[i])); + + QMutexLocker configLocker(&symbianConfig->mutex); + + if (symbianConfig->numericId == apId) { configFound = true; break; } } - } else if (toSymbianConfig(privateConfiguration(config))->numericId == apId) { - configFound = true; + } else { + SymbianNetworkConfigurationPrivate *symbianConfig = + toSymbianConfig(privateConfiguration(config)); + + symbianConfig->mutex.lock(); + if (symbianConfig->numericId == apId) + configFound = true; + symbianConfig->mutex.unlock(); } if (configFound) { TUint tData; @@ -668,9 +705,12 @@ QNetworkConfiguration QNetworkSessionPrivateImpl::activeConfiguration(TUint32 ia // Try to search IAP from the used SNAP using IAP Id QList<QNetworkConfiguration> children = publicConfig.children(); for (int i=0; i < children.count(); i++) { - if (toSymbianConfig(privateConfiguration(children[i]))->numericId == iapId) { + SymbianNetworkConfigurationPrivate *childConfig = + toSymbianConfig(privateConfiguration(children[i])); + + QMutexLocker childLocker(&childConfig->mutex); + if (childConfig->numericId == iapId) return children[i]; - } } // Given IAP Id was not found from the used SNAP @@ -682,10 +722,21 @@ QNetworkConfiguration QNetworkSessionPrivateImpl::activeConfiguration(TUint32 ia // <=> Note: It's possible that in this case reported IAP is // clone of the one of the IAPs of the used SNAP // => If mappingName matches, clone has been found - QNetworkConfiguration pt = QNetworkConfigurationManager().configurationFromIdentifier(QString::number(qHash(iapId))); - if (privateConfiguration(pt)) { + QNetworkConfiguration pt = QNetworkConfigurationManager() + .configurationFromIdentifier(QString::number(qHash(iapId))); + + SymbianNetworkConfigurationPrivate *symbianConfig = + toSymbianConfig(privateConfiguration(pt)); + if (symbianConfig) { + QMutexLocker configLocker(&symbianConfig->mutex); + for (int i=0; i < children.count(); i++) { - if (toSymbianConfig(privateConfiguration(children[i]))->mappingName == toSymbianConfig(privateConfiguration(pt))->mappingName) { + SymbianNetworkConfigurationPrivate *childConfig = + toSymbianConfig(privateConfiguration(children[i])); + + QMutexLocker childLocker(&childConfig->mutex); + + if (childConfig->mappingName == symbianConfig->mappingName) { return children[i]; } } @@ -776,13 +827,21 @@ void QNetworkSessionPrivateImpl::RunL() iMobility = CActiveCommsMobilityApiExt::NewL(iConnection, *this); } #endif + isOpen = true; activeConfig = newActiveConfig; - activeInterface = interface(toSymbianConfig(privateConfiguration(activeConfig))->numericId); + + SymbianNetworkConfigurationPrivate *symbianConfig = + toSymbianConfig(privateConfiguration(activeConfig)); + + symbianConfig->mutex.lock(); + activeInterface = interface(symbianConfig->numericId); if (publicConfig.type() == QNetworkConfiguration::UserChoice) { - serviceConfig = QNetworkConfigurationManager().configurationFromIdentifier(toSymbianConfig(privateConfiguration(activeConfig))->serviceNetworkPtr->id); + serviceConfig = QNetworkConfigurationManager() + .configurationFromIdentifier(symbianConfig->serviceNetworkPtr->id); } - + symbianConfig->mutex.unlock(); + startTime = QDateTime::currentDateTime(); newState(QNetworkSession::Connected); @@ -830,7 +889,14 @@ bool QNetworkSessionPrivateImpl::newState(QNetworkSession::State newState, TUint if (isOpen && publicConfig.type() == QNetworkConfiguration::ServiceNetwork && newState == QNetworkSession::Connected) { activeConfig = activeConfiguration(accessPointId); - activeInterface = interface(toSymbianConfig(privateConfiguration(activeConfig))->numericId); + + SymbianNetworkConfigurationPrivate *symbianConfig = + toSymbianConfig(privateConfiguration(activeConfig)); + + symbianConfig->mutex.lock(); + activeInterface = interface(symbianConfig->numericId); + symbianConfig->mutex.unlock(); + #ifdef SNAP_FUNCTIONALITY_AVAILABLE if (iDynamicSetdefaultif) { // Use name of the IAP to set default IAP @@ -880,13 +946,25 @@ bool QNetworkSessionPrivateImpl::newState(QNetworkSession::State newState, TUint retVal = true; } else { if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { - if (toSymbianConfig(privateConfiguration(publicConfig))->numericId == accessPointId) { + SymbianNetworkConfigurationPrivate *symbianConfig = + toSymbianConfig(privateConfiguration(publicConfig)); + + QMutexLocker configLocker(&symbianConfig->mutex); + if (symbianConfig->numericId == accessPointId) { + configLocker.unlock(); + state = newState; emit stateChanged(state); retVal = true; } } else if (publicConfig.type() == QNetworkConfiguration::UserChoice && isOpen) { - if (toSymbianConfig(privateConfiguration(activeConfig))->numericId == accessPointId) { + SymbianNetworkConfigurationPrivate *symbianConfig = + toSymbianConfig(privateConfiguration(activeConfig)); + + QMutexLocker configLocker(&symbianConfig->mutex); + if (symbianConfig->numericId == accessPointId) { + configLocker.unlock(); + state = newState; emit stateChanged(state); retVal = true; @@ -894,11 +972,17 @@ bool QNetworkSessionPrivateImpl::newState(QNetworkSession::State newState, TUint } else if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { QList<QNetworkConfiguration> subConfigurations = publicConfig.children(); for (int i = 0; i < subConfigurations.count(); i++) { - if (toSymbianConfig(privateConfiguration(subConfigurations[i]))->numericId == accessPointId) { + SymbianNetworkConfigurationPrivate *symbianConfig = + toSymbianConfig(privateConfiguration(subConfigurations[i])); + + QMutexLocker configLocker(&symbianConfig->mutex); + + if (symbianConfig->numericId == accessPointId) { if (newState == QNetworkSession::Connected) { // Make sure that when AccessPoint is reported to be Connected // also state of the related configuration changes to Active. - privateConfiguration(subConfigurations[i])->state = QNetworkConfiguration::Active; + symbianConfig->state = QNetworkConfiguration::Active; + configLocker.unlock(); state = newState; emit stateChanged(state); @@ -907,11 +991,14 @@ bool QNetworkSessionPrivateImpl::newState(QNetworkSession::State newState, TUint if (newState == QNetworkSession::Disconnected) { // Make sure that when AccessPoint is reported to be disconnected // also state of the related configuration changes from Active to Defined. - privateConfiguration(subConfigurations[i])->state = QNetworkConfiguration::Defined; + symbianConfig->state = QNetworkConfiguration::Defined; } QNetworkConfiguration config = bestConfigFromSNAP(publicConfig); if ((config.state() == QNetworkConfiguration::Defined) || (config.state() == QNetworkConfiguration::Discovered)) { + + configLocker.unlock(); + state = newState; emit stateChanged(state); retVal = true; @@ -1033,15 +1120,24 @@ void QNetworkSessionPrivateImpl::EventL(const CConnMonEventBase& aEvent) if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { QList<QNetworkConfiguration> subConfigurations = publicConfig.children(); for (int i = 0; i < subConfigurations.count(); i++ ) { - if (toSymbianConfig(privateConfiguration(subConfigurations[i]))->connectionId == connectionId) { - apId = toSymbianConfig(privateConfiguration(subConfigurations[i]))->numericId; + SymbianNetworkConfigurationPrivate *symbianConfig = + toSymbianConfig(privateConfiguration(subConfigurations[i])); + + QMutexLocker configLocker(&symbianConfig->mutex); + + if (symbianConfig->connectionId == connectionId) { + apId = symbianConfig->numericId; break; } } } else if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { - if (toSymbianConfig(privateConfiguration(publicConfig))->connectionId == connectionId) { - apId = toSymbianConfig(privateConfiguration(publicConfig))->numericId; - } + SymbianNetworkConfigurationPrivate *symbianConfig = + toSymbianConfig(privateConfiguration(publicConfig)); + + symbianConfig->mutex.lock(); + if (symbianConfig->connectionId == connectionId) + apId = symbianConfig->numericId; + symbianConfig->mutex.unlock(); } if (apId > 0) { @@ -1064,15 +1160,24 @@ void QNetworkSessionPrivateImpl::EventL(const CConnMonEventBase& aEvent) if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { QList<QNetworkConfiguration> subConfigurations = publicConfig.children(); for (int i = 0; i < subConfigurations.count(); i++ ) { - if (toSymbianConfig(privateConfiguration(subConfigurations[i]))->numericId == apId) { - toSymbianConfig(privateConfiguration(subConfigurations[i]))->connectionId = connectionId; + SymbianNetworkConfigurationPrivate *symbianConfig = + toSymbianConfig(privateConfiguration(subConfigurations[i])); + + QMutexLocker configLocker(&symbianConfig->mutex); + + if (symbianConfig->numericId == apId) { + symbianConfig->connectionId = connectionId; break; } } } else if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { - if (toSymbianConfig(privateConfiguration(publicConfig))->numericId == apId) { - toSymbianConfig(privateConfiguration(publicConfig))->connectionId = connectionId; - } + SymbianNetworkConfigurationPrivate *symbianConfig = + toSymbianConfig(privateConfiguration(publicConfig)); + + symbianConfig->mutex.lock(); + if (symbianConfig->numericId == apId) + symbianConfig->connectionId = connectionId; + symbianConfig->mutex.unlock(); } } } @@ -1087,15 +1192,24 @@ void QNetworkSessionPrivateImpl::EventL(const CConnMonEventBase& aEvent) if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { QList<QNetworkConfiguration> subConfigurations = publicConfig.children(); for (int i = 0; i < subConfigurations.count(); i++ ) { - if (toSymbianConfig(privateConfiguration(subConfigurations[i]))->connectionId == connectionId) { - toSymbianConfig(privateConfiguration(subConfigurations[i]))->connectionId = 0; + SymbianNetworkConfigurationPrivate *symbianConfig = + toSymbianConfig(privateConfiguration(subConfigurations[i])); + + QMutexLocker configLocker(&symbianConfig->mutex); + + if (symbianConfig->connectionId == connectionId) { + symbianConfig->connectionId = 0; break; } } } else if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { - if (toSymbianConfig(privateConfiguration(publicConfig))->connectionId == connectionId) { - toSymbianConfig(privateConfiguration(publicConfig))->connectionId = 0; - } + SymbianNetworkConfigurationPrivate *symbianConfig = + toSymbianConfig(privateConfiguration(publicConfig)); + + symbianConfig->mutex.lock(); + if (symbianConfig->connectionId == connectionId) + symbianConfig->connectionId = 0; + symbianConfig->mutex.unlock(); } } break; diff --git a/src/plugins/bearer/symbian/symbianengine.cpp b/src/plugins/bearer/symbian/symbianengine.cpp index 88a563c..980892a 100644 --- a/src/plugins/bearer/symbian/symbianengine.cpp +++ b/src/plugins/bearer/symbian/symbianengine.cpp @@ -75,6 +75,8 @@ SymbianNetworkConfigurationPrivate::~SymbianNetworkConfigurationPrivate() QString SymbianNetworkConfigurationPrivate::bearerName() const { + QMutexLocker locker(&mutex); + switch (bearer) { case BearerEthernet: return QLatin1String("Ethernet"); @@ -250,7 +252,10 @@ void SymbianEngine::updateConfigurationsL() if (error == KErrNone) { QNetworkConfigurationPrivatePointer ptr(cpPriv); accessPointConfigurations.insert(ptr->id, ptr); + + locker.unlock(); emit configurationAdded(ptr); + locker.relock(); } } CleanupStack::PopAndDestroy(&connectionMethod); @@ -288,7 +293,10 @@ void SymbianEngine::updateConfigurationsL() QNetworkConfigurationPrivatePointer ptr(cpPriv); snapConfigurations.insert(ident, ptr); + + locker.unlock(); emit configurationAdded(ptr); + locker.relock(); CleanupStack::Pop(cpPriv); } @@ -309,7 +317,11 @@ void SymbianEngine::updateConfigurationsL() QNetworkConfigurationPrivatePointer ptr(cpPriv); toSymbianConfig(ptr)->serviceNetworkPtr = privSNAP; accessPointConfigurations.insert(ptr->id, ptr); + + locker.unlock(); emit configurationAdded(ptr); + locker.relock(); + privSNAP->serviceNetworkMembers.append(ptr); } } else { @@ -358,7 +370,9 @@ void SymbianEngine::updateConfigurationsL() QNetworkConfigurationPrivatePointer ptr(cpPriv); accessPointConfigurations.insert(ident, ptr); + locker.unlock(); emit configurationAdded(ptr); + locker.relock(); } else { delete cpPriv; } @@ -372,7 +386,10 @@ void SymbianEngine::updateConfigurationsL() foreach (const QString &oldIface, knownConfigs) { //remove non existing IAP QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(oldIface); + + locker.unlock(); emit configurationRemoved(ptr); + locker.relock(); // Remove non existing IAP from SNAPs foreach (const QString &iface, snapConfigurations.keys()) { @@ -391,7 +408,10 @@ void SymbianEngine::updateConfigurationsL() foreach (const QString &oldIface, knownSnapConfigs) { //remove non existing SNAPs QNetworkConfigurationPrivatePointer ptr = snapConfigurations.take(oldIface); + + locker.unlock(); emit configurationRemoved(ptr); + locker.relock(); } } @@ -596,7 +616,7 @@ QNetworkConfigurationPrivatePointer SymbianEngine::defaultConfigurationL() } #endif - if (!ptr->isValid) { + if (!ptr || !ptr->isValid) { QString iface = QString::number(qHash(KUserChoiceIAPId)); ptr = userChoiceConfigurations.value(iface); } @@ -651,7 +671,9 @@ void SymbianEngine::updateActiveAccessPoints() if (iOnline != online) { iOnline = online; + locker.unlock(); emit this->onlineStateChanged(iOnline); + locker.relock(); } } @@ -704,7 +726,9 @@ void SymbianEngine::accessPointScanningReady(TBool scanSuccessful, TConnMonIapIn if (!iFirstUpdate) { startCommsDatabaseNotifications(); + locker.unlock(); emit updateCompleted(); + locker.relock(); } } @@ -746,10 +770,18 @@ bool SymbianEngine::changeConfigurationStateTo(QNetworkConfigurationPrivatePoint { QMutexLocker locker(&mutex); + ptr->mutex.lock(); if (newState != ptr->state) { ptr->state = newState; + ptr->mutex.unlock(); + + locker.unlock(); emit configurationChanged(ptr); + locker.relock(); + return true; + } else { + ptr->mutex.unlock(); } return false; } @@ -763,10 +795,18 @@ bool SymbianEngine::changeConfigurationStateAtMinTo(QNetworkConfigurationPrivate { QMutexLocker locker(&mutex); + ptr->mutex.lock(); if ((newState | ptr->state) != ptr->state) { ptr->state = (ptr->state | newState); + ptr->mutex.unlock(); + + locker.unlock(); emit configurationChanged(ptr); + locker.relock(); + return true; + } else { + ptr->mutex.unlock(); } return false; } @@ -781,10 +821,18 @@ bool SymbianEngine::changeConfigurationStateAtMaxTo(QNetworkConfigurationPrivate { QMutexLocker locker(&mutex); + ptr->mutex.lock(); if ((newState & ptr->state) != ptr->state) { ptr->state = (newState & ptr->state); + ptr->mutex.unlock(); + + locker.unlock(); emit configurationChanged(ptr); + locker.relock(); + return true; + } else { + ptr->mutex.unlock(); } return false; } @@ -893,7 +941,10 @@ void SymbianEngine::EventL(const CConnMonEventBase& aEvent) if (!iOnline) { iOnline = true; + + locker.unlock(); emit this->onlineStateChanged(iOnline); + locker.relock(); } } } @@ -923,7 +974,10 @@ void SymbianEngine::EventL(const CConnMonEventBase& aEvent) } if (iOnline != online) { iOnline = online; + + locker.unlock(); emit this->onlineStateChanged(iOnline); + locker.relock(); } } break; diff --git a/src/plugins/bearer/symbian/symbianengine.h b/src/plugins/bearer/symbian/symbianengine.h index ee6d070..e6af908 100644 --- a/src/plugins/bearer/symbian/symbianengine.h +++ b/src/plugins/bearer/symbian/symbianengine.h @@ -109,7 +109,7 @@ public: bool hasIdentifier(const QString &id); - void requestUpdate(); + Q_INVOKABLE void requestUpdate(); QNetworkConfigurationManager::Capabilities capabilities() const; |