diff options
author | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2009-12-10 07:10:53 (GMT) |
---|---|---|
committer | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2010-01-04 01:15:57 (GMT) |
commit | 6f0a0af87c2063cd1dac75134f5cd05291a9196d (patch) | |
tree | e1cf0a83e4faebb227787a97c097ee5afc70e0b3 | |
parent | b22d0a9c4d6e3309287aefdc1a300e2fc566c2c7 (diff) | |
download | Qt-6f0a0af87c2063cd1dac75134f5cd05291a9196d.zip Qt-6f0a0af87c2063cd1dac75134f5cd05291a9196d.tar.gz Qt-6f0a0af87c2063cd1dac75134f5cd05291a9196d.tar.bz2 |
Convert NLA plugin to be incremental.
-rw-r--r-- | src/network/bearer/qnetworkconfigmanager_p.cpp | 12 | ||||
-rw-r--r-- | src/plugins/bearer/nla/qnlaengine.cpp | 101 | ||||
-rw-r--r-- | src/plugins/bearer/nla/qnlaengine.h | 6 |
3 files changed, 95 insertions, 24 deletions
diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 6f833f3..495be4a 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -198,7 +198,7 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() if (nmWifi) { sessionEngines.append(nmWifi); connect(nmWifi, SIGNAL(updateCompleted()), - this, SIGNAL(configurationUpdateComplete())); + this, SLOT(updateConfigurations())); connect(nmWifi, SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer))); connect(nmWifi, SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)), @@ -217,7 +217,7 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() if (generic) { sessionEngines.append(generic); connect(generic, SIGNAL(updateCompleted()), - this, SIGNAL(configurationUpdateComplete())); + this, SLOT(updateConfigurations())); connect(generic, SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer))); connect(generic, SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)), @@ -235,6 +235,14 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() QNetworkSessionEngine *nla = nlaPlugin->create(QLatin1String("nla")); if (nla) { sessionEngines.append(nla); + connect(nla, SIGNAL(updateCompleted()), + this, SLOT(updateConfigurations())); + connect(nla, SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer))); + connect(nla, SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationRemoved(QNetworkConfigurationPrivatePointer))); + connect(nla, SIGNAL(configurationChanged(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationChanged(QNetworkConfigurationPrivatePointer))); } } } diff --git a/src/plugins/bearer/nla/qnlaengine.cpp b/src/plugins/bearer/nla/qnlaengine.cpp index 47bd8d5..a9fc2ee 100644 --- a/src/plugins/bearer/nla/qnlaengine.cpp +++ b/src/plugins/bearer/nla/qnlaengine.cpp @@ -238,21 +238,8 @@ QList<QNetworkConfigurationPrivate *> QNlaThread::getConfigurations() { QMutexLocker locker(&mutex); - QList<QNetworkConfigurationPrivate *> foundConfigurations; - - for (int i = 0; i < fetchedConfigurations.count(); ++i) { - QNetworkConfigurationPrivate *config = new QNetworkConfigurationPrivate; - config->name = fetchedConfigurations.at(i)->name; - config->isValid = fetchedConfigurations.at(i)->isValid; - config->id = fetchedConfigurations.at(i)->id; - config->state = fetchedConfigurations.at(i)->state; - config->type = fetchedConfigurations.at(i)->type; - config->roamingSupported = fetchedConfigurations.at(i)->roamingSupported; - config->purpose = fetchedConfigurations.at(i)->purpose; - config->internet = fetchedConfigurations.at(i)->internet; - - foundConfigurations.append(config); - } + QList<QNetworkConfigurationPrivate *> foundConfigurations = fetchedConfigurations; + fetchedConfigurations.clear(); return foundConfigurations; } @@ -324,7 +311,10 @@ void QNlaThread::run() #ifndef Q_OS_WINCE // Not interested in unrelated IO completion events // although we also don't want to block them - while (WaitForSingleObjectEx(changeEvent, WSA_INFINITE, true) != WAIT_IO_COMPLETION) {} + while (WaitForSingleObjectEx(changeEvent, WSA_INFINITE, true) != WAIT_IO_COMPLETION && + handle) + { + } #else WaitForSingleObject(changeEvent, WSA_INFINITE); #endif @@ -515,7 +505,7 @@ QNlaEngine::QNlaEngine(QObject *parent) { nlaThread = new QNlaThread(this); connect(nlaThread, SIGNAL(networksChanged()), - this, SIGNAL(configurationsChanged())); + this, SLOT(networksChanged())); nlaThread->start(); qApp->processEvents(QEventLoop::ExcludeUserInputEvents); @@ -526,12 +516,57 @@ QNlaEngine::~QNlaEngine() delete nlaThread; } -QList<QNetworkConfigurationPrivate *> QNlaEngine::getConfigurations(bool *ok) +void QNlaEngine::networksChanged() { - if (ok) - *ok = true; + QStringList previous = accessPointConfigurations.keys(); + + QList<QNetworkConfigurationPrivate *> foundConfigurations = nlaThread->getConfigurations(); + while (!foundConfigurations.isEmpty()) { + QNetworkConfigurationPrivate *cpPriv = foundConfigurations.takeFirst(); + + previous.removeAll(cpPriv->id); + + if (accessPointConfigurations.contains(cpPriv->id)) { + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(cpPriv->id); + + bool changed = false; + + if (ptr->isValid != cpPriv->isValid) { + ptr->isValid = cpPriv->isValid; + changed = true; + } + + if (ptr->name != cpPriv->name) { + ptr->name = cpPriv->name; + changed = true; + } + + if (ptr->state != cpPriv->state) { + ptr->state = cpPriv->state; + changed = true; + } - return nlaThread->getConfigurations(); + if (changed) + emit configurationChanged(ptr); + + delete cpPriv; + } else { + QNetworkConfigurationPrivatePointer ptr(cpPriv); + + accessPointConfigurations.insert(ptr->id, ptr); + + emit configurationAdded(ptr); + } + } + + while (!previous.isEmpty()) { + QNetworkConfigurationPrivatePointer ptr = + accessPointConfigurations.take(previous.takeFirst()); + + emit configurationRemoved(ptr); + } + + emit updateCompleted(); } QString QNlaEngine::getInterfaceFromId(const QString &id) @@ -577,6 +612,30 @@ void QNlaEngine::requestUpdate() nlaThread->forceUpdate(); } +QNetworkSession::State QNlaEngine::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; +} + #include "qnlaengine.moc" QT_END_NAMESPACE diff --git a/src/plugins/bearer/nla/qnlaengine.h b/src/plugins/bearer/nla/qnlaengine.h index 464275d..dd038d1 100644 --- a/src/plugins/bearer/nla/qnlaengine.h +++ b/src/plugins/bearer/nla/qnlaengine.h @@ -81,7 +81,6 @@ public: QNlaEngine(QObject *parent = 0); ~QNlaEngine(); - QList<QNetworkConfigurationPrivate *> getConfigurations(bool *ok = 0); QString getInterfaceFromId(const QString &id); bool hasIdentifier(const QString &id); @@ -92,6 +91,11 @@ public: void requestUpdate(); + QNetworkSession::State sessionStateForId(const QString &id); + +private Q_SLOTS: + void networksChanged(); + private: QWindowsSockInit2 winSock; QNlaThread *nlaThread; |