diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/bearer/corewlan/qcorewlanengine.h | 5 | ||||
-rw-r--r-- | src/plugins/bearer/corewlan/qcorewlanengine.mm | 125 | ||||
-rw-r--r-- | src/plugins/bearer/generic/qgenericengine.cpp | 14 | ||||
-rw-r--r-- | src/plugins/bearer/generic/qgenericengine.h | 3 | ||||
-rw-r--r-- | src/plugins/bearer/icd/qicdengine.cpp | 23 | ||||
-rw-r--r-- | src/plugins/bearer/icd/qnetworksession_impl.cpp | 13 | ||||
-rw-r--r-- | src/plugins/bearer/nativewifi/qnativewifiengine.cpp | 75 | ||||
-rw-r--r-- | src/plugins/bearer/nativewifi/qnativewifiengine.h | 4 | ||||
-rw-r--r-- | src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp | 8 | ||||
-rw-r--r-- | src/plugins/bearer/nla/qnlaengine.cpp | 56 | ||||
-rw-r--r-- | src/plugins/bearer/qnetworksession_impl.cpp | 56 | ||||
-rw-r--r-- | src/plugins/bearer/qnetworksession_impl.h | 9 |
12 files changed, 236 insertions, 155 deletions
diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.h b/src/plugins/bearer/corewlan/qcorewlanengine.h index cfd89e4..cbaa9d6 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.h +++ b/src/plugins/bearer/corewlan/qcorewlanengine.h @@ -78,7 +78,9 @@ public: QNetworkConfigurationPrivatePointer defaultConfiguration(); - bool getAllScInterfaces(); + bool getWifiInterfaces(); + + bool requiresPolling() const; private Q_SLOTS: void doRequestUpdate(); @@ -86,7 +88,6 @@ private Q_SLOTS: private: bool isWifiReady(const QString &dev); QMap<QString, QString> configurationInterface; - QTimer pollTimer; QStringList scanForSsids(const QString &interfaceName); bool isKnownSsid(const QString &interfaceName, const QString &ssid); diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm index 2d33d36..9a213e7 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.mm +++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm @@ -61,14 +61,78 @@ #include <Foundation/NSEnumerator.h> #include <Foundation/NSKeyValueObserving.h> #include <Foundation/NSAutoreleasePool.h> +#include <Foundation/NSLock.h> #include <SystemConfiguration/SCNetworkConfiguration.h> +#include <private/qt_cocoa_helpers_mac_p.h> + 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)remove; +- (void)setEngine:(QCoreWlanEngine *)coreEngine; +- (void)dealloc; + +@property (assign) QCoreWlanEngine* engine; + +@end + +@implementation QNSListener +- (id) init +{ + [locker lock]; + autoreleasepool = [[NSAutoreleasePool alloc] init]; + center = [NSNotificationCenter defaultCenter]; + currentInterface = [CWInterface interface]; +// [center addObserver:self selector:@selector(notificationHandler:) name:kCWLinkDidChangeNotification object:nil]; + [center addObserver:self selector:@selector(notificationHandler:) name:kCWPowerDidChangeNotification object:nil]; + [locker unlock]; + return self; +} + +-(void)dealloc +{ + [autoreleasepool release]; + [super dealloc]; +} + +-(void)setEngine:(QCoreWlanEngine *)coreEngine +{ + [locker lock]; + if(!engine) + engine = coreEngine; + [locker unlock]; +} + +-(void)remove +{ + [locker lock]; + [center removeObserver:self]; + [locker unlock]; +} + +- (void)notificationHandler:(NSNotification *)notification +{ + engine->requestUpdate(); +} +@end + +QNSListener *listener = 0; + +#endif + QT_BEGIN_NAMESPACE inline QString cfstringRefToQstring(CFStringRef cfStringRef) { -// return QString([cfStringRef UTF8String]); QString retVal; CFIndex maxLength = 2 * CFStringGetLength(cfStringRef) + 1/*zero term*/; // max UTF8 char *cstring = new char[maxLength]; @@ -122,12 +186,23 @@ QCoreWlanEngine::QCoreWlanEngine(QObject *parent) : QBearerEngineImpl(parent) { startNetworkChangeLoop(); + +#if defined(MAC_SDK_10_6) + if(!listener) { + listener = [[QNSListener alloc] init]; + listener.engine = this; + } +#endif } 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) @@ -242,15 +317,14 @@ void QCoreWlanEngine::requestUpdate() { QMutexLocker locker(&mutex); - pollTimer.stop(); - QTimer::singleShot(0, this, SLOT(doRequestUpdate())); + doRequestUpdate(); } void QCoreWlanEngine::doRequestUpdate() { QMutexLocker locker(&mutex); - getAllScInterfaces(); + getWifiInterfaces(); QStringList previous = accessPointConfigurations.keys(); @@ -328,8 +402,6 @@ void QCoreWlanEngine::doRequestUpdate() emit configurationRemoved(ptr); } - pollTimer.start(); - emit updateCompleted(); } @@ -340,7 +412,7 @@ QStringList QCoreWlanEngine::scanForSsids(const QString &interfaceName) QStringList found; #if defined(MAC_SDK_10_6) - NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + QMacCocoaAutoReleasePool pool; CWInterface *currentInterface = [CWInterface interfaceWithName:qstringToNSString(interfaceName)]; if([currentInterface power]) { @@ -351,7 +423,6 @@ QStringList QCoreWlanEngine::scanForSsids(const QString &interfaceName) CWNetwork *apNetwork; if (!err) { for(uint row=0; row < [apArray count]; row++ ) { - NSAutoreleasePool *looppool = [[NSAutoreleasePool alloc] init]; apNetwork = [apArray objectAtIndex:row]; @@ -414,11 +485,9 @@ QStringList QCoreWlanEngine::scanForSsids(const QString &interfaceName) emit configurationAdded(ptr); } - [looppool release]; } } } - [autoreleasepool drain]; #else Q_UNUSED(interfaceName); #endif @@ -458,39 +527,18 @@ bool QCoreWlanEngine::isKnownSsid(const QString &interfaceName, const QString &s return false; } -bool QCoreWlanEngine::getAllScInterfaces() +bool QCoreWlanEngine::getWifiInterfaces() { QMutexLocker locker(&mutex); networkInterfaces.clear(); - NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + QMacCocoaAutoReleasePool pool; - CFArrayRef interfaces = SCNetworkInterfaceCopyAll(); - if (interfaces != NULL) { - CFIndex interfaceCount; - CFIndex interfaceIndex; - interfaceCount = CFArrayGetCount(interfaces); - for (interfaceIndex = 0; interfaceIndex < interfaceCount; interfaceIndex++) { - NSAutoreleasePool *looppool = [[NSAutoreleasePool alloc] init]; - - CFStringRef bsdName; - CFTypeRef thisInterface = CFArrayGetValueAtIndex(interfaces, interfaceIndex); - bsdName = SCNetworkInterfaceGetBSDName((SCNetworkInterfaceRef)thisInterface); - QString interfaceName = cfstringRefToQstring(bsdName); - QString typeStr; - CFStringRef type = SCNetworkInterfaceGetInterfaceType((SCNetworkInterfaceRef)thisInterface); - if ( CFEqual(type, kSCNetworkInterfaceTypeIEEE80211)) { - typeStr = "WLAN"; - } - if(!networkInterfaces.contains(interfaceName) && !typeStr.isEmpty()) { - networkInterfaces.insert(interfaceName,typeStr); - } - [looppool release]; - } + NSArray *wifiInterfaces = [CWInterface supportedInterfaces]; + for(uint row=0; row < [wifiInterfaces count]; row++ ) { + networkInterfaces.insert( nsstringToQString([wifiInterfaces objectAtIndex:row]),"WLAN"); } - CFRelease(interfaces); - [autoreleasepool drain]; return true; } @@ -589,4 +637,9 @@ QNetworkConfigurationPrivatePointer QCoreWlanEngine::defaultConfiguration() return QNetworkConfigurationPrivatePointer(); } +bool QCoreWlanEngine::requiresPolling() const +{ + return true; +} + QT_END_NAMESPACE diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp index e6c871d..a9e78b2 100644 --- a/src/plugins/bearer/generic/qgenericengine.cpp +++ b/src/plugins/bearer/generic/qgenericengine.cpp @@ -142,9 +142,6 @@ static QString qGetInterfaceType(const QString &interface) QGenericEngine::QGenericEngine(QObject *parent) : QBearerEngineImpl(parent) { - connect(&pollTimer, SIGNAL(timeout()), this, SLOT(doRequestUpdate())); - pollTimer.setInterval(10000); - doRequestUpdate(); } QGenericEngine::~QGenericEngine() @@ -179,8 +176,7 @@ void QGenericEngine::requestUpdate() { QMutexLocker locker(&mutex); - pollTimer.stop(); - QTimer::singleShot(0, this, SLOT(doRequestUpdate())); + doRequestUpdate(); } void QGenericEngine::doRequestUpdate() @@ -282,8 +278,6 @@ void QGenericEngine::doRequestUpdate() emit configurationRemoved(ptr); } - pollTimer.start(); - emit updateCompleted(); } @@ -328,5 +322,11 @@ QNetworkConfigurationPrivatePointer QGenericEngine::defaultConfiguration() return QNetworkConfigurationPrivatePointer(); } + +bool QGenericEngine::requiresPolling() const +{ + return true; +} + QT_END_NAMESPACE diff --git a/src/plugins/bearer/generic/qgenericengine.h b/src/plugins/bearer/generic/qgenericengine.h index cd9a976..a1b9167 100644 --- a/src/plugins/bearer/generic/qgenericengine.h +++ b/src/plugins/bearer/generic/qgenericengine.h @@ -78,12 +78,13 @@ public: QNetworkConfigurationPrivatePointer defaultConfiguration(); + bool requiresPolling() const; + private Q_SLOTS: void doRequestUpdate(); private: QMap<QString, QString> configurationInterface; - QTimer pollTimer; }; QT_END_NAMESPACE diff --git a/src/plugins/bearer/icd/qicdengine.cpp b/src/plugins/bearer/icd/qicdengine.cpp index 206a6fd..5e506ef 100644 --- a/src/plugins/bearer/icd/qicdengine.cpp +++ b/src/plugins/bearer/icd/qicdengine.cpp @@ -206,14 +206,11 @@ void QIcdEngine::doRequestUpdate() QString iap_type = saved_ap.value("type").toString(); if (iap_type.startsWith("WLAN")) { ssid = saved_ap.value("wlan_ssid").toByteArray(); - if (ssid.isEmpty()) { - qWarning() << "Cannot get ssid for" << iap_id; + if (ssid.isEmpty()) continue; - } QString security_method = saved_ap.value("wlan_security").toString(); } else if (iap_type.isEmpty()) { - qWarning() << "IAP" << iap_id << "network type is not set! Skipping it"; continue; } else { #ifdef BEARER_MANAGEMENT_DEBUG @@ -270,7 +267,9 @@ void QIcdEngine::doRequestUpdate() scanned, error); if (!error.isEmpty()) { - qWarning() << "Network scanning failed" << error; +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Network scanning failed" << error; +#endif } else { #ifdef BEARER_MANAGEMENT_DEBUG if (!scanned.isEmpty()) @@ -379,19 +378,13 @@ void QIcdEngine::deleteConfiguration(const QString &iap_id) * or read all the IAPs from db because it might take too much power * (multiple applications would need to scan and read all IAPs from db) */ - if (accessPointConfigurations.contains(iap_id)) { - QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(iap_id); - - if (ptr) { - ptr->isValid = false; + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(iap_id); + if (ptr) { #ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "IAP" << iap_id << "was removed from storage."; + qDebug() << "IAP" << iap_id << "was removed from storage."; #endif - emit configurationRemoved(ptr); - } else { - qWarning("Configuration not found for IAP %s", iap_id.toAscii().data()); - } + emit configurationRemoved(ptr); } else { #ifdef BEARER_MANAGEMENT_DEBUG qDebug("IAP: %s, already missing from the known list", iap_id.toAscii().data()); diff --git a/src/plugins/bearer/icd/qnetworksession_impl.cpp b/src/plugins/bearer/icd/qnetworksession_impl.cpp index 03624fa..bb81408 100644 --- a/src/plugins/bearer/icd/qnetworksession_impl.cpp +++ b/src/plugins/bearer/icd/qnetworksession_impl.cpp @@ -140,7 +140,9 @@ static DBusHandlerResult signal_handler(DBusConnection *, DBUS_TYPE_STRING, &network_type, DBUS_TYPE_STRING, &state, DBUS_TYPE_INVALID) == FALSE) { - qWarning() << QString("Failed to parse icd status signal: %1").arg(error.message); +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << QString("Failed to parse icd status signal: %1").arg(error.message); +#endif } else { QString _iap_id(iap_id); QString _network_type(network_type); @@ -166,7 +168,6 @@ void IcdListener::setup(QNetworkSessionPrivateImpl *d) dbus_connection = get_dbus_conn(&error); if (dbus_error_is_set(&error)) { - qWarning() << "Cannot get dbus connection."; dbus_error_free(&error); return; } @@ -176,7 +177,6 @@ void IcdListener::setup(QNetworkSessionPrivateImpl *d) dbus_bus_add_match(dbus_connection, ICD_DBUS_MATCH, &error); if (dbus_error_is_set(&error)) { - qWarning() << "Cannot add match" << ICD_DBUS_MATCH; dbus_error_free(&error); return; } @@ -185,7 +185,6 @@ void IcdListener::setup(QNetworkSessionPrivateImpl *d) ICD_DBUS_PATH, &icd_vtable, (void*)this) == FALSE) { - qWarning() << "Cannot register dbus signal handler, interface"<< ICD_DBUS_INTERFACE << "path" << ICD_DBUS_PATH; dbus_error_free(&error); return; } @@ -340,8 +339,6 @@ void QNetworkSessionPrivateImpl::updateIdentifier(QString &newId) } else { toIcdConfig(privateConfiguration(publicConfig))->network_attrs |= ICD_NW_ATTR_IAPNAME; if (privateConfiguration(publicConfig)->id != newId) { - qWarning() << "Your config id changed from" << privateConfiguration(publicConfig)->id - << "to" << newId; privateConfiguration(publicConfig)->id = newId; } } @@ -1015,25 +1012,21 @@ void QNetworkSessionPrivateImpl::stop() void QNetworkSessionPrivateImpl::migrate() { - qWarning("This platform does not support roaming (%s).", __FUNCTION__); } void QNetworkSessionPrivateImpl::accept() { - qWarning("This platform does not support roaming (%s).", __FUNCTION__); } void QNetworkSessionPrivateImpl::ignore() { - qWarning("This platform does not support roaming (%s).", __FUNCTION__); } void QNetworkSessionPrivateImpl::reject() { - qWarning("This platform does not support roaming (%s).", __FUNCTION__); } diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp index c8015d8..952a6a3 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp @@ -83,8 +83,10 @@ QNativeWifiEngine::QNativeWifiEngine(QObject *parent) DWORD result = local_WlanOpenHandle(1, 0, &clientVersion, &handle); if (result != ERROR_SUCCESS) { +#ifdef BEARER_MANAGEMENT_DEBUG if (result != ERROR_SERVICE_NOT_ACTIVE) - qWarning("%s: WlanOpenHandle failed with error %ld\n", __FUNCTION__, result); + qDebug("%s: WlanOpenHandle failed with error %ld\n", __FUNCTION__, result); +#endif return; } @@ -92,13 +94,11 @@ QNativeWifiEngine::QNativeWifiEngine(QObject *parent) result = local_WlanRegisterNotification(handle, WLAN_NOTIFICATION_SOURCE_ALL, true, WLAN_NOTIFICATION_CALLBACK(qNotificationCallback), this, 0, 0); +#ifdef BEARER_MANAGEMENT_DEBUG if (result != ERROR_SUCCESS) - qWarning("%s: WlanRegisterNotification failed with error %ld\n", __FUNCTION__, result); + qDebug("%s: WlanRegisterNotification failed with error %ld\n", __FUNCTION__, result); +#endif - // On Windows XP SP2 and SP3 only connection and disconnection notifications are available. - // We need to poll for changes in available wireless networks. - connect(&pollTimer, SIGNAL(timeout()), this, SLOT(scanComplete())); - pollTimer.setInterval(10000); scanComplete(); } @@ -117,7 +117,9 @@ void QNativeWifiEngine::scanComplete() WLAN_INTERFACE_INFO_LIST *interfaceList; DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); if (result != ERROR_SUCCESS) { - qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); +#endif return; } @@ -128,8 +130,10 @@ void QNativeWifiEngine::scanComplete() result = local_WlanGetAvailableNetworkList(handle, &interface.InterfaceGuid, 3, 0, &networkList); if (result != ERROR_SUCCESS) { - qWarning("%s: WlanGetAvailableNetworkList failed with error %ld\n", - __FUNCTION__, result); +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug("%s: WlanGetAvailableNetworkList failed with error %ld\n", + __FUNCTION__, result); +#endif continue; } @@ -222,8 +226,6 @@ void QNativeWifiEngine::scanComplete() emit configurationRemoved(ptr); } - pollTimer.start(); - emit updateCompleted(); } @@ -235,7 +237,9 @@ QString QNativeWifiEngine::getInterfaceFromId(const QString &id) WLAN_INTERFACE_INFO_LIST *interfaceList; DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); if (result != ERROR_SUCCESS) { - qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); +#endif return QString(); } @@ -248,8 +252,10 @@ QString QNativeWifiEngine::getInterfaceFromId(const QString &id) wlan_intf_opcode_current_connection, 0, &dataSize, reinterpret_cast<PVOID *>(&connectionAttributes), 0); if (result != ERROR_SUCCESS) { +#ifdef BEARER_MANAGEMENT_DEBUG if (result != ERROR_INVALID_STATE) - qWarning("%s: WlanQueryInterface failed with error %ld\n", __FUNCTION__, result); + qDebug("%s: WlanQueryInterface failed with error %ld\n", __FUNCTION__, result); +#endif continue; } @@ -286,7 +292,9 @@ bool QNativeWifiEngine::hasIdentifier(const QString &id) WLAN_INTERFACE_INFO_LIST *interfaceList; DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); if (result != ERROR_SUCCESS) { - qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); +#endif return false; } @@ -297,8 +305,10 @@ bool QNativeWifiEngine::hasIdentifier(const QString &id) result = local_WlanGetAvailableNetworkList(handle, &interface.InterfaceGuid, 3, 0, &networkList); if (result != ERROR_SUCCESS) { - qWarning("%s: WlanGetAvailableNetworkList failed with error %ld\n", - __FUNCTION__, result); +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug("%s: WlanGetAvailableNetworkList failed with error %ld\n", + __FUNCTION__, result); +#endif continue; } @@ -341,7 +351,9 @@ void QNativeWifiEngine::connectToId(const QString &id) WLAN_INTERFACE_INFO_LIST *interfaceList; DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); if (result != ERROR_SUCCESS) { - qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); +#endif emit connectionError(id, InterfaceLookupError); return; } @@ -355,8 +367,10 @@ void QNativeWifiEngine::connectToId(const QString &id) result = local_WlanGetAvailableNetworkList(handle, &interface.InterfaceGuid, 3, 0, &networkList); if (result != ERROR_SUCCESS) { - qWarning("%s: WlanGetAvailableNetworkList failed with error %ld\n", - __FUNCTION__, result); +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug("%s: WlanGetAvailableNetworkList failed with error %ld\n", + __FUNCTION__, result); +#endif continue; } @@ -384,7 +398,9 @@ void QNativeWifiEngine::connectToId(const QString &id) DWORD result = local_WlanConnect(handle, &interface.InterfaceGuid, ¶meters, 0); if (result != ERROR_SUCCESS) { - qWarning("%s: WlanConnect failed with error %ld\n", __FUNCTION__, result); +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug("%s: WlanConnect failed with error %ld\n", __FUNCTION__, result); +#endif emit connectionError(id, ConnectError); break; } @@ -423,7 +439,9 @@ void QNativeWifiEngine::disconnectFromId(const QString &id) DWORD result = local_WlanDisconnect(handle, &guid, 0); if (result != ERROR_SUCCESS) { - qWarning("%s: WlanDisconnect failed with error %ld\n", __FUNCTION__, result); +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug("%s: WlanDisconnect failed with error %ld\n", __FUNCTION__, result); +#endif emit connectionError(id, DisconnectionError); return; } @@ -437,14 +455,18 @@ void QNativeWifiEngine::requestUpdate() WLAN_INTERFACE_INFO_LIST *interfaceList; DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); if (result != ERROR_SUCCESS) { - qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); +#endif return; } for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { result = local_WlanScan(handle, &interfaceList->InterfaceInfo[i].InterfaceGuid, 0, 0, 0); +#ifdef BEARER_MANAGEMENT_DEBUG if (result != ERROR_SUCCESS) - qWarning("%s: WlanScan failed with error %ld\n", __FUNCTION__, result); + qDebug("%s: WlanScan failed with error %ld\n", __FUNCTION__, result); +#endif } local_WlanFreeMemory(interfaceList); @@ -492,4 +514,11 @@ QNetworkConfigurationPrivatePointer QNativeWifiEngine::defaultConfiguration() return QNetworkConfigurationPrivatePointer(); } +bool QNativeWifiEngine::requiresPolling() const +{ + // On Windows XP SP2 and SP3 only connection and disconnection notifications are available. + // We need to poll for changes in available wireless networks. + return true; +} + QT_END_NAMESPACE diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.h b/src/plugins/bearer/nativewifi/qnativewifiengine.h index a9a9375..56489b6 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.h +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.h @@ -90,12 +90,12 @@ public: inline bool available() const { return handle != 0; } + bool requiresPolling() const; + public Q_SLOTS: void scanComplete(); private: - QTimer pollTimer; - Qt::HANDLE handle; }; diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp index c780fbc..d23bb0d 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp @@ -199,7 +199,6 @@ QNetworkManagerInterfaceAccessPoint::QNetworkManagerInterfaceAccessPoint(const Q dbusConnection); if (!d->connectionInterface->isValid()) { d->valid = false; - qWarning() << "Could not find InterfaceAccessPoint"; return; } d->valid = true; @@ -308,7 +307,6 @@ QNetworkManagerInterfaceDevice::QNetworkManagerInterfaceDevice(const QString &de dbusConnection); if (!d->connectionInterface->isValid()) { d->valid = false; - qWarning() << "Could not find NetworkManagerInterfaceDevice"; return; } d->valid = true; @@ -400,7 +398,6 @@ QNetworkManagerInterfaceDeviceWired::QNetworkManagerInterfaceDeviceWired(const Q dbusConnection, parent); if (!d->connectionInterface->isValid()) { d->valid = false; - qWarning() << "Could not find InterfaceDeviceWired"; return; } d->valid = true; @@ -478,7 +475,6 @@ QNetworkManagerInterfaceDeviceWireless::QNetworkManagerInterfaceDeviceWireless(c dbusConnection, parent); if (!d->connectionInterface->isValid()) { d->valid = false; - qWarning() << "Could not find InterfaceDeviceWireless"; return; } d->valid = true; @@ -596,7 +592,6 @@ QNetworkManagerSettings::QNetworkManagerSettings(const QString &settingsService, dbusConnection); if (!d->connectionInterface->isValid()) { d->valid = false; - //qWarning() << "Could not find NetworkManagerSettings"; return; } d->valid = true; @@ -660,7 +655,6 @@ QNetworkManagerSettingsConnection::QNetworkManagerSettingsConnection(const QStri QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), dbusConnection, parent); if (!d->connectionInterface->isValid()) { - //qWarning() << "Could not find NetworkManagerSettingsConnection"; d->valid = false; return; } @@ -883,7 +877,6 @@ QNetworkManagerConnectionActive::QNetworkManagerConnectionActive( const QString dbusConnection, parent); if (!d->connectionInterface->isValid()) { d->valid = false; - //qWarning() << "Could not find NetworkManagerSettingsConnection"; return; } d->valid = true; @@ -978,7 +971,6 @@ QNetworkManagerIp4Config::QNetworkManagerIp4Config( const QString &deviceObjectP dbusConnection, parent); if (!d->connectionInterface->isValid()) { d->valid = false; - //qWarning() << "Could not find NetworkManagerIp4Config"; return; } d->valid = true; diff --git a/src/plugins/bearer/nla/qnlaengine.cpp b/src/plugins/bearer/nla/qnlaengine.cpp index ff334e5..334eb14 100644 --- a/src/plugins/bearer/nla/qnlaengine.cpp +++ b/src/plugins/bearer/nla/qnlaengine.cpp @@ -228,8 +228,11 @@ QNlaThread::~QNlaThread() if (handle) { /* cancel completion event */ - if (WSALookupServiceEnd(handle) == SOCKET_ERROR) - qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); + if (WSALookupServiceEnd(handle) == SOCKET_ERROR) { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug("WSALookupServiceEnd error %d", WSAGetLastError()); +#endif + } } mutex.unlock(); @@ -252,8 +255,11 @@ void QNlaThread::forceUpdate() if (handle) { /* cancel completion event */ - if (WSALookupServiceEnd(handle) == SOCKET_ERROR) - qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); + if (WSALookupServiceEnd(handle) == SOCKET_ERROR) { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug("WSALookupServiceEnd error %d", WSAGetLastError()); +#endif + } handle = 0; } mutex.unlock(); @@ -262,10 +268,8 @@ void QNlaThread::forceUpdate() void QNlaThread::run() { WSAEVENT changeEvent = WSACreateEvent(); - if (changeEvent == WSA_INVALID_EVENT) { - qWarning("WSACreateEvent error %d", WSAGetLastError()); + if (changeEvent == WSA_INVALID_EVENT) return; - } while (true) { fetchConfigurations(); @@ -284,10 +288,8 @@ void QNlaThread::run() int result = WSALookupServiceBegin(&qsRestrictions, LUP_RETURN_ALL, &handle); mutex.unlock(); - if (result == SOCKET_ERROR) { - qWarning("%s: WSALookupServiceBegin error %d", __FUNCTION__, WSAGetLastError()); + if (result == SOCKET_ERROR) break; - } WSACOMPLETION completion; WSAOVERLAPPED overlapped; @@ -303,11 +305,8 @@ void QNlaThread::run() result = WSANSPIoctl(handle, SIO_NSP_NOTIFY_CHANGE, 0, 0, 0, 0, &bytesReturned, &completion); if (result == SOCKET_ERROR) { - int error = WSAGetLastError(); - if (error != WSA_IO_PENDING) { - qWarning("WSANSPIoctl error %d", error); + if (WSAGetLastError() != WSA_IO_PENDING) break; - } } #ifndef Q_OS_WINCE @@ -325,7 +324,6 @@ void QNlaThread::run() if (handle) { result = WSALookupServiceEnd(handle); if (result == SOCKET_ERROR) { - qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); mutex.unlock(); break; } @@ -360,7 +358,7 @@ DWORD QNlaThread::parseBlob(NLA_BLOB *blob, QNetworkConfigurationPrivate *cpPriv switch (blob->header.type) { case NLA_RAW_DATA: #ifdef BEARER_MANAGEMENT_DEBUG - qWarning("%s: unhandled header type NLA_RAW_DATA", __FUNCTION__); + qDebug("%s: unhandled header type NLA_RAW_DATA", __FUNCTION__); #endif break; case NLA_INTERFACE: @@ -372,7 +370,7 @@ DWORD QNlaThread::parseBlob(NLA_BLOB *blob, QNetworkConfigurationPrivate *cpPriv break; case NLA_802_1X_LOCATION: #ifdef BEARER_MANAGEMENT_DEBUG - qWarning("%s: unhandled header type NLA_802_1X_LOCATION", __FUNCTION__); + qDebug("%s: unhandled header type NLA_802_1X_LOCATION", __FUNCTION__); #endif break; case NLA_CONNECTIVITY: @@ -380,18 +378,15 @@ DWORD QNlaThread::parseBlob(NLA_BLOB *blob, QNetworkConfigurationPrivate *cpPriv cpPriv->internet = true; else cpPriv->internet = false; -#ifdef BEARER_MANAGEMENT_DEBUG - qWarning("%s: unhandled header type NLA_CONNECTIVITY", __FUNCTION__); -#endif break; case NLA_ICS: #ifdef BEARER_MANAGEMENT_DEBUG - qWarning("%s: unhandled header type NLA_ICS", __FUNCTION__); + qDebug("%s: unhandled header type NLA_ICS", __FUNCTION__); #endif break; default: #ifdef BEARER_MANAGEMENT_DEBUG - qWarning("%s: unhandled header type %d", __FUNCTION__, blob->header.type); + qDebug("%s: unhandled header type %d", __FUNCTION__, blob->header.type); #endif ; } @@ -462,7 +457,6 @@ void QNlaThread::fetchConfigurations() int result = WSALookupServiceBegin(&qsRestrictions, LUP_RETURN_ALL | LUP_DEEP, &hLookup); if (result == SOCKET_ERROR) { - qWarning("%s: WSALookupServiceBegin error %d", __FUNCTION__, WSAGetLastError()); mutex.lock(); fetchedConfigurations.clear(); mutex.unlock(); @@ -474,18 +468,8 @@ void QNlaThread::fetchConfigurations() result = WSALookupServiceNext(hLookup, LUP_RETURN_ALL, &bufferLength, reinterpret_cast<WSAQUERYSET *>(buffer)); - if (result == SOCKET_ERROR) { - int error = WSAGetLastError(); - - if (error == WSA_E_NO_MORE) - break; - - if (error == WSAEFAULT) - break; - - qWarning("WSALookupServiceNext error %d", WSAGetLastError()); + if (result == SOCKET_ERROR) break; - } QNetworkConfigurationPrivate *cpPriv = parseQuerySet(reinterpret_cast<WSAQUERYSET *>(buffer)); @@ -496,7 +480,9 @@ void QNlaThread::fetchConfigurations() if (hLookup) { result = WSALookupServiceEnd(hLookup); if (result == SOCKET_ERROR) { - qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug("WSALookupServiceEnd error %d", WSAGetLastError()); +#endif } } diff --git a/src/plugins/bearer/qnetworksession_impl.cpp b/src/plugins/bearer/qnetworksession_impl.cpp index 11585ef..db1759c 100644 --- a/src/plugins/bearer/qnetworksession_impl.cpp +++ b/src/plugins/bearer/qnetworksession_impl.cpp @@ -100,9 +100,6 @@ void QNetworkSessionManagerPrivate::forceSessionClose(const QNetworkConfiguratio void QNetworkSessionPrivateImpl::syncStateWithInterface() { - connect(&manager, SIGNAL(updateCompleted()), this, SLOT(networkConfigurationsChanged())); - connect(&manager, SIGNAL(configurationChanged(QNetworkConfiguration)), - this, SLOT(configurationChanged(QNetworkConfiguration))); connect(sessionManager(), SIGNAL(forcedSessionClose(QNetworkConfiguration)), this, SLOT(forcedSessionClose(QNetworkConfiguration))); @@ -119,6 +116,10 @@ void QNetworkSessionPrivateImpl::syncStateWithInterface() activeConfig = publicConfig; engine = getEngineFromId(activeConfig.identifier()); if (engine) { + qRegisterMetaType<QNetworkConfigurationPrivatePointer>("QNetworkConfigurationPrivatePointer"); + connect(engine, SIGNAL(configurationChanged(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationChanged(QNetworkConfigurationPrivatePointer)), + Qt::QueuedConnection); connect(engine, SIGNAL(connectionError(QString,QBearerEngineImpl::ConnectionError)), this, SLOT(connectionError(QString,QBearerEngineImpl::ConnectionError)), Qt::QueuedConnection); @@ -203,22 +204,18 @@ void QNetworkSessionPrivateImpl::stop() void QNetworkSessionPrivateImpl::migrate() { - qWarning("This platform does not support roaming (%s).", Q_FUNC_INFO); } void QNetworkSessionPrivateImpl::accept() { - qWarning("This platform does not support roaming (%s).", Q_FUNC_INFO); } void QNetworkSessionPrivateImpl::ignore() { - qWarning("This platform does not support roaming (%s).", Q_FUNC_INFO); } void QNetworkSessionPrivateImpl::reject() { - qWarning("This platform does not support roaming (%s).", Q_FUNC_INFO); } QNetworkInterface QNetworkSessionPrivateImpl::currentInterface() const @@ -233,13 +230,37 @@ QNetworkInterface QNetworkSessionPrivateImpl::currentInterface() const return QNetworkInterface::interfaceFromName(interface); } -QVariant QNetworkSessionPrivateImpl::sessionProperty(const QString& /*key*/) const +QVariant QNetworkSessionPrivateImpl::sessionProperty(const QString &key) const { + if (key == QLatin1String("AutoCloseSessionTimeout")) { + if (engine && engine->requiresPolling() && + !(engine->capabilities() & QNetworkConfigurationManager::CanStartAndStopInterfaces)) { + if (sessionTimeout >= 0) + return sessionTimeout * 10000; + else + return -1; + } + } + return QVariant(); } -void QNetworkSessionPrivateImpl::setSessionProperty(const QString& /*key*/, const QVariant& /*value*/) +void QNetworkSessionPrivateImpl::setSessionProperty(const QString &key, const QVariant &value) { + if (key == QLatin1String("AutoCloseSessionTimeout")) { + if (engine && engine->requiresPolling() && + !(engine->capabilities() & QNetworkConfigurationManager::CanStartAndStopInterfaces)) { + int timeout = value.toInt(); + if (timeout >= 0) { + connect(engine, SIGNAL(updateCompleted()), + this, SLOT(decrementTimeout()), Qt::UniqueConnection); + sessionTimeout = timeout / 10000; // convert to poll intervals + } else { + disconnect(engine, SIGNAL(updateCompleted()), this, SLOT(decrementTimeout())); + sessionTimeout = -1; + } + } + } } QString QNetworkSessionPrivateImpl::errorString() const @@ -364,12 +385,14 @@ void QNetworkSessionPrivateImpl::networkConfigurationsChanged() startTime = engine->startTime(activeConfig.identifier()); } -void QNetworkSessionPrivateImpl::configurationChanged(const QNetworkConfiguration &config) +void QNetworkSessionPrivateImpl::configurationChanged(QNetworkConfigurationPrivatePointer config) { - if (serviceConfig.isValid() && (config == serviceConfig || config == activeConfig)) + if (serviceConfig.isValid() && + (config->id == serviceConfig.identifier() || config->id == activeConfig.identifier())) { updateStateFromServiceNetwork(); - else if (config == activeConfig) + } else if (config->id == activeConfig.identifier()) { updateStateFromActiveConfig(); + } } void QNetworkSessionPrivateImpl::forcedSessionClose(const QNetworkConfiguration &config) @@ -406,4 +429,13 @@ void QNetworkSessionPrivateImpl::connectionError(const QString &id, } } +void QNetworkSessionPrivateImpl::decrementTimeout() +{ + if (--sessionTimeout <= 0) { + disconnect(engine, SIGNAL(updateCompleted()), this, SLOT(decrementTimeout())); + sessionTimeout = -1; + close(); + } +} + QT_END_NAMESPACE diff --git a/src/plugins/bearer/qnetworksession_impl.h b/src/plugins/bearer/qnetworksession_impl.h index 7349e77..c644174 100644 --- a/src/plugins/bearer/qnetworksession_impl.h +++ b/src/plugins/bearer/qnetworksession_impl.h @@ -69,7 +69,7 @@ class QNetworkSessionPrivateImpl : public QNetworkSessionPrivate Q_OBJECT public: QNetworkSessionPrivateImpl() - : startTime(0) + : startTime(0), sessionTimeout(-1) { } @@ -108,13 +108,12 @@ private: private Q_SLOTS: void networkConfigurationsChanged(); - void configurationChanged(const QNetworkConfiguration &config); + void configurationChanged(QNetworkConfigurationPrivatePointer config); void forcedSessionClose(const QNetworkConfiguration &config); void connectionError(const QString &id, QBearerEngineImpl::ConnectionError error); + void decrementTimeout(); private: - QNetworkConfigurationManager manager; - bool opened; QBearerEngineImpl *engine; @@ -122,6 +121,8 @@ private: QNetworkSession::SessionError lastError; quint64 startTime; + + int sessionTimeout; }; QT_END_NAMESPACE |