diff options
author | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2009-12-11 01:27:14 (GMT) |
---|---|---|
committer | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2010-01-04 01:16:19 (GMT) |
commit | a60b9d95fddb75a53cde258dbf4b9063a58a88b8 (patch) | |
tree | 7709fec46aaa0e90da14fedd3abdaef8b560c326 /src | |
parent | 6f0a0af87c2063cd1dac75134f5cd05291a9196d (diff) | |
download | Qt-a60b9d95fddb75a53cde258dbf4b9063a58a88b8.zip Qt-a60b9d95fddb75a53cde258dbf4b9063a58a88b8.tar.gz Qt-a60b9d95fddb75a53cde258dbf4b9063a58a88b8.tar.bz2 |
Convert Native Wifi plugin to be incremental.
Diffstat (limited to 'src')
-rw-r--r-- | src/network/bearer/qnetworkconfigmanager_p.cpp | 14 | ||||
-rw-r--r-- | src/plugins/bearer/nativewifi/qnativewifiengine.cpp | 115 | ||||
-rw-r--r-- | src/plugins/bearer/nativewifi/qnativewifiengine.h | 7 |
3 files changed, 106 insertions, 30 deletions
diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 495be4a..c9b10dd 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -251,9 +251,21 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() QBearerEnginePlugin *nativeWifiPlugin = qobject_cast<QBearerEnginePlugin *>(l->instance(QLatin1String("nativewifi"))); if (nativeWifiPlugin) { - QNetworkSessionEngine *nativeWifi = nativeWifiPlugin->create(QLatin1String("nativewifi")); + QNetworkSessionEngine *nativeWifi = + nativeWifiPlugin->create(QLatin1String("nativewifi")); if (nativeWifi) { sessionEngines.append(nativeWifi); + connect(nativeWifi, SIGNAL(updateCompleted()), + this, SLOT(updateConfigurations())); + connect(nativeWifi, + SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer))); + connect(nativeWifi, + SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationRemoved(QNetworkConfigurationPrivatePointer))); + connect(nativeWifi, + SIGNAL(configurationChanged(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationChanged(QNetworkConfigurationPrivatePointer))); capFlags |= QNetworkConfigurationManager::CanStartAndStopInterfaces; } diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp index 93fc9ca..e65eeea 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp @@ -68,7 +68,7 @@ void qNotificationCallback(WLAN_NOTIFICATION_DATA *data, QNativeWifiEngine *d) switch (data->NotificationCode) { case wlan_notification_acm_connection_complete: case wlan_notification_acm_disconnected: - d->emitConfigurationsChanged(); + QMetaObject::invokeMethod(d, "scanComplete", Qt::QueuedConnection); break; default: qDebug() << "wlan unknown notification"; @@ -96,8 +96,9 @@ QNativeWifiEngine::QNativeWifiEngine(QObject *parent) // 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, SIGNAL(configurationsChanged())); + connect(&pollTimer, SIGNAL(timeout()), this, SLOT(scanComplete())); pollTimer.setInterval(10000); + scanComplete(); } QNativeWifiEngine::~QNativeWifiEngine() @@ -105,19 +106,16 @@ QNativeWifiEngine::~QNativeWifiEngine() local_WlanCloseHandle(handle, 0); } -QList<QNetworkConfigurationPrivate *> QNativeWifiEngine::getConfigurations(bool *ok) +void QNativeWifiEngine::scanComplete() { - if (ok) - *ok = false; - - QList<QNetworkConfigurationPrivate *> foundConfigurations; + QStringList previous = accessPointConfigurations.keys(); // enumerate interfaces 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); - return foundConfigurations; + return; } for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { @@ -146,36 +144,66 @@ QList<QNetworkConfigurationPrivate *> QNativeWifiEngine::getConfigurations(bool network.dot11Ssid.uSSIDLength); } - // don't add duplicate networks - if (seenNetworks.contains(networkName)) - continue; - else - seenNetworks.append(networkName); - - QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; + const QString id = QString::number(qHash(QLatin1String("WLAN:") + networkName)); - cpPriv->isValid = true; + previous.removeAll(id); - cpPriv->name = networkName; - cpPriv->id = QString::number(qHash(QLatin1String("WLAN:") + cpPriv->name)); + QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined; if (!(network.dwFlags & WLAN_AVAILABLE_NETWORK_HAS_PROFILE)) - cpPriv->state = QNetworkConfiguration::Undefined; + state = QNetworkConfiguration::Undefined; if (network.strProfileName[0] != 0) { if (network.bNetworkConnectable) { if (network.dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED) - cpPriv->state = QNetworkConfiguration::Active; + state = QNetworkConfiguration::Active; else - cpPriv->state = QNetworkConfiguration::Discovered; + state = QNetworkConfiguration::Discovered; } else { - cpPriv->state = QNetworkConfiguration::Defined; + state = QNetworkConfiguration::Defined; } } - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + if (seenNetworks.contains(networkName)) + continue; + else + seenNetworks.append(networkName); + + if (accessPointConfigurations.contains(id)) { + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); - foundConfigurations.append(cpPriv); + bool changed = false; + + if (!ptr->isValid) { + ptr->isValid = true; + changed = true; + } + + if (ptr->name != networkName) { + ptr->name = networkName; + changed = true; + } + + if (ptr->state != state) { + ptr->state = state; + changed = true; + } + + if (changed) + emit configurationChanged(ptr); + } else { + QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate); + + ptr->name = networkName; + ptr->isValid = true; + ptr->id = id; + ptr->state = state; + ptr->type = QNetworkConfiguration::InternetAccessPoint; + + accessPointConfigurations.insert(id, ptr); + + emit configurationAdded(ptr); + } } local_WlanFreeMemory(networkList); @@ -183,12 +211,16 @@ QList<QNetworkConfigurationPrivate *> QNativeWifiEngine::getConfigurations(bool local_WlanFreeMemory(interfaceList); - if (ok) - *ok = true; + while (!previous.isEmpty()) { + QNetworkConfigurationPrivatePointer ptr = + accessPointConfigurations.take(previous.takeFirst()); + + emit configurationRemoved(ptr); + } pollTimer.start(); - return foundConfigurations; + emit updateCompleted(); } QString QNativeWifiEngine::getInterfaceFromId(const QString &id) @@ -227,6 +259,7 @@ QString QNativeWifiEngine::getInterfaceFromId(const QString &id) guid = guid.arg(interface.InterfaceGuid.Data4[i], 2, 16, QChar('0')); local_WlanFreeMemory(connectionAttributes); + local_WlanFreeMemory(interfaceList); return guid.toUpper(); } @@ -234,6 +267,8 @@ QString QNativeWifiEngine::getInterfaceFromId(const QString &id) local_WlanFreeMemory(connectionAttributes); } + local_WlanFreeMemory(interfaceList); + return QString(); } @@ -397,6 +432,32 @@ void QNativeWifiEngine::requestUpdate() if (result != ERROR_SUCCESS) qWarning("%s: WlanScan failed with error %ld\n", __FUNCTION__, result); } + + local_WlanFreeMemory(interfaceList); +} + +QNetworkSession::State QNativeWifiEngine::sessionStateForId(const QString &id) +{ + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + + if (!ptr) + return QNetworkSession::Invalid; + + if (!ptr->isValid) { + return QNetworkSession::Invalid; + } else if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + return QNetworkSession::Connected; + } else if ((ptr->state & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + return QNetworkSession::Disconnected; + } else if ((ptr->state & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) { + return QNetworkSession::NotAvailable; + } else if ((ptr->state & QNetworkConfiguration::Undefined) == + QNetworkConfiguration::Undefined) { + return QNetworkSession::NotAvailable; + } + + return QNetworkSession::Invalid; } QT_END_NAMESPACE diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.h b/src/plugins/bearer/nativewifi/qnativewifiengine.h index 6686ea8..5d6af40 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.h +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.h @@ -60,6 +60,7 @@ QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; +struct WLAN_NOTIFICATION_DATA; class QNativeWifiEngine : public QNetworkSessionEngine { @@ -69,7 +70,6 @@ public: QNativeWifiEngine(QObject *parent = 0); ~QNativeWifiEngine(); - QList<QNetworkConfigurationPrivate *> getConfigurations(bool *ok = 0); QString getInterfaceFromId(const QString &id); bool hasIdentifier(const QString &id); @@ -80,10 +80,13 @@ public: void requestUpdate(); - inline void emitConfigurationsChanged() { emit configurationsChanged(); } + QNetworkSession::State sessionStateForId(const QString &id); inline bool available() const { return handle != 0; } +public Q_SLOTS: + void scanComplete(); + private: QTimer pollTimer; |