summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/network/bearer/qbearerengine.cpp38
-rw-r--r--src/network/bearer/qbearerengine_p.h3
-rw-r--r--src/network/bearer/qnetworkconfigmanager.cpp8
-rw-r--r--src/network/bearer/qnetworkconfigmanager_p.cpp90
-rw-r--r--src/network/bearer/qnetworkconfigmanager_p.h15
-rw-r--r--src/plugins/bearer/corewlan/qcorewlanengine.h3
-rw-r--r--src/plugins/bearer/corewlan/qcorewlanengine.mm10
-rw-r--r--src/plugins/bearer/generic/qgenericengine.cpp14
-rw-r--r--src/plugins/bearer/generic/qgenericengine.h3
-rw-r--r--src/plugins/bearer/nativewifi/qnativewifiengine.cpp13
-rw-r--r--src/plugins/bearer/nativewifi/qnativewifiengine.h4
11 files changed, 173 insertions, 28 deletions
diff --git a/src/network/bearer/qbearerengine.cpp b/src/network/bearer/qbearerengine.cpp
index eb851cc..c42e2d2 100644
--- a/src/network/bearer/qbearerengine.cpp
+++ b/src/network/bearer/qbearerengine.cpp
@@ -70,6 +70,44 @@ QBearerEngine::~QBearerEngine()
}
}
+bool QBearerEngine::requiresPolling() const
+{
+ return false;
+}
+
+/*
+ Returns true if configurations are in use; otherwise returns false.
+
+ If configurations are in use and requiresPolling() returns true, polling will be enabled for
+ this engine.
+*/
+bool QBearerEngine::configurationsInUse() const
+{
+ QHash<QString, QNetworkConfigurationPrivatePointer>::ConstIterator it;
+ QHash<QString, QNetworkConfigurationPrivatePointer>::ConstIterator end;
+
+ QMutexLocker locker(&mutex);
+
+ for (it = accessPointConfigurations.begin(),
+ end = accessPointConfigurations.end(); it != end; ++it) {
+ if (it.value()->ref > 1)
+ return true;
+ }
+
+ for (it = snapConfigurations.begin(), end = snapConfigurations.end(); it != end; ++it) {
+ if (it.value()->ref > 1)
+ return true;
+ }
+
+ for (it = userChoiceConfigurations.begin(),
+ end = userChoiceConfigurations.end(); it != end; ++it) {
+ if (it.value()->ref > 1)
+ return true;
+ }
+
+ return false;
+}
+
#include "moc_qbearerengine_p.cpp"
QT_END_NAMESPACE
diff --git a/src/network/bearer/qbearerengine_p.h b/src/network/bearer/qbearerengine_p.h
index 5e12b0f..028c174 100644
--- a/src/network/bearer/qbearerengine_p.h
+++ b/src/network/bearer/qbearerengine_p.h
@@ -89,6 +89,9 @@ public:
virtual QNetworkConfigurationPrivatePointer defaultConfiguration() = 0;
+ virtual bool requiresPolling() const;
+ bool configurationsInUse() const;
+
Q_SIGNALS:
void configurationAdded(QNetworkConfigurationPrivatePointer config);
void configurationRemoved(QNetworkConfigurationPrivatePointer config);
diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp
index 9ff197b..0eb9c63 100644
--- a/src/network/bearer/qnetworkconfigmanager.cpp
+++ b/src/network/bearer/qnetworkconfigmanager.cpp
@@ -174,7 +174,8 @@ QNetworkConfigurationManagerPrivate *qNetworkConfigurationManagerPrivate()
QNetworkConfigurationManager::QNetworkConfigurationManager( QObject* parent )
: QObject(parent)
{
- QNetworkConfigurationManagerPrivate* priv = connManager();
+ QNetworkConfigurationManagerPrivate *priv = connManager();
+
connect(priv, SIGNAL(configurationAdded(QNetworkConfiguration)),
this, SIGNAL(configurationAdded(QNetworkConfiguration)));
connect(priv, SIGNAL(configurationRemoved(QNetworkConfiguration)),
@@ -185,6 +186,8 @@ QNetworkConfigurationManager::QNetworkConfigurationManager( QObject* parent )
this, SIGNAL(onlineStateChanged(bool)));
connect(priv, SIGNAL(configurationChanged(QNetworkConfiguration)),
this, SIGNAL(configurationChanged(QNetworkConfiguration)));
+
+ priv->enablePolling();
}
/*!
@@ -192,6 +195,9 @@ QNetworkConfigurationManager::QNetworkConfigurationManager( QObject* parent )
*/
QNetworkConfigurationManager::~QNetworkConfigurationManager()
{
+ QNetworkConfigurationManagerPrivate *priv = connManager();
+
+ priv->disablePolling();
}
diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp
index 1ac10c5..9740424 100644
--- a/src/network/bearer/qnetworkconfigmanager_p.cpp
+++ b/src/network/bearer/qnetworkconfigmanager_p.cpp
@@ -55,7 +55,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
(QBearerEngineFactoryInterface_iid, QLatin1String("/bearer")))
QNetworkConfigurationManagerPrivate::QNetworkConfigurationManagerPrivate()
-: capFlags(0), mutex(QMutex::Recursive), firstUpdate(true)
+: capFlags(0), mutex(QMutex::Recursive), pollTimer(0), forcedPolling(0), firstUpdate(true)
{
updateConfigurations();
@@ -82,7 +82,7 @@ void QNetworkConfigurationManagerPrivate::configurationAdded(QNetworkConfigurati
}
if (ptr->state == QNetworkConfiguration::Active) {
- onlineConfigurations.insert(ptr);
+ onlineConfigurations.insert(ptr->id);
if (!firstUpdate && onlineConfigurations.count() == 1)
emit onlineStateChanged(true);
}
@@ -100,7 +100,7 @@ void QNetworkConfigurationManagerPrivate::configurationRemoved(QNetworkConfigura
emit configurationRemoved(item);
}
- onlineConfigurations.remove(ptr);
+ onlineConfigurations.remove(ptr->id);
if (!firstUpdate && onlineConfigurations.isEmpty())
emit onlineStateChanged(false);
}
@@ -118,9 +118,9 @@ void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigura
bool previous = !onlineConfigurations.isEmpty();
if (ptr->state == QNetworkConfiguration::Active)
- onlineConfigurations.insert(ptr);
+ onlineConfigurations.insert(ptr->id);
else
- onlineConfigurations.remove(ptr);
+ onlineConfigurations.remove(ptr->id);
bool online = !onlineConfigurations.isEmpty();
@@ -133,6 +133,9 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations()
QMutexLocker locker(&mutex);
if (firstUpdate) {
+ if (sender())
+ return;
+
updating = false;
QFactoryLoader *l = loader();
@@ -161,6 +164,8 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations()
this, SLOT(configurationChanged(QNetworkConfigurationPrivatePointer)));
capFlags |= engine->capabilities();
+
+ engine->requestUpdate();
}
}
@@ -180,6 +185,15 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations()
emit configurationUpdateComplete();
}
+ if (engine && !pollingEngines.isEmpty()) {
+ int index = sessionEngines.indexOf(engine);
+ if (index >= 0)
+ pollingEngines.remove(index);
+
+ if (pollingEngines.isEmpty())
+ startPolling();
+ }
+
if (firstUpdate)
firstUpdate = false;
}
@@ -208,4 +222,70 @@ QList<QBearerEngine *> QNetworkConfigurationManagerPrivate::engines()
return sessionEngines;
}
+void QNetworkConfigurationManagerPrivate::startPolling()
+{
+ QMutexLocker locker(&mutex);
+
+ bool pollingRequired = false;
+
+ if (forcedPolling > 0) {
+ foreach (QBearerEngine *engine, sessionEngines) {
+ if (engine->requiresPolling()) {
+ pollingRequired = true;
+ break;
+ }
+ }
+ }
+
+ if (!pollingRequired) {
+ foreach (QBearerEngine *engine, sessionEngines) {
+ if (engine->configurationsInUse()) {
+ pollingRequired = true;
+ break;
+ }
+ }
+ }
+
+ if (pollingRequired) {
+ if (!pollTimer) {
+ pollTimer = new QTimer(this);
+ pollTimer->setInterval(10000);
+ pollTimer->setSingleShot(true);
+ connect(pollTimer, SIGNAL(timeout()), this, SLOT(pollEngines()));
+ }
+
+ pollTimer->start();
+ }
+}
+
+void QNetworkConfigurationManagerPrivate::pollEngines()
+{
+ QMutexLocker locker(&mutex);
+
+ for (int i = 0; i < sessionEngines.count(); ++i) {
+ if ((forcedPolling && sessionEngines.at(i)->requiresPolling()) ||
+ sessionEngines.at(i)->configurationsInUse()) {
+ pollingEngines.insert(i);
+ sessionEngines.at(i)->requestUpdate();
+ }
+ }
+}
+
+void QNetworkConfigurationManagerPrivate::enablePolling()
+{
+ QMutexLocker locker(&mutex);
+
+ ++forcedPolling;
+
+ if (forcedPolling == 1)
+ startPolling();
+}
+
+void QNetworkConfigurationManagerPrivate::disablePolling()
+{
+ QMutexLocker locker(&mutex);
+
+ --forcedPolling;
+}
+
QT_END_NAMESPACE
diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h
index c7e988e..ac8518c 100644
--- a/src/network/bearer/qnetworkconfigmanager_p.h
+++ b/src/network/bearer/qnetworkconfigmanager_p.h
@@ -61,6 +61,7 @@
QT_BEGIN_NAMESPACE
class QBearerEngine;
+class QTimer;
class Q_NETWORK_EXPORT QNetworkConfigurationManagerPrivate : public QObject
{
@@ -77,6 +78,11 @@ public:
QList<QBearerEngine *> engines();
+ void startPolling();
+
+ void enablePolling();
+ void disablePolling();
+
public slots:
void updateConfigurations();
@@ -92,19 +98,26 @@ Q_SIGNALS:
private:
QMutex mutex;
+ QTimer *pollTimer;
+
QList<QBearerEngine *> sessionEngines;
- QSet<QNetworkConfigurationPrivatePointer> onlineConfigurations;
+ QSet<QString> onlineConfigurations;
QSet<int> updatingEngines;
bool updating;
+ QSet<int> pollingEngines;
+ int forcedPolling;
+
bool firstUpdate;
private Q_SLOTS:
void configurationAdded(QNetworkConfigurationPrivatePointer ptr);
void configurationRemoved(QNetworkConfigurationPrivatePointer ptr);
void configurationChanged(QNetworkConfigurationPrivatePointer ptr);
+
+ void pollEngines();
};
Q_NETWORK_EXPORT QNetworkConfigurationManagerPrivate *qNetworkConfigurationManagerPrivate();
diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.h b/src/plugins/bearer/corewlan/qcorewlanengine.h
index cfd89e4..3289ffb 100644
--- a/src/plugins/bearer/corewlan/qcorewlanengine.h
+++ b/src/plugins/bearer/corewlan/qcorewlanengine.h
@@ -80,13 +80,14 @@ public:
bool getAllScInterfaces();
+ bool requiresPolling() const;
+
private Q_SLOTS:
void doRequestUpdate();
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 598d2f0..5870b01 100644
--- a/src/plugins/bearer/corewlan/qcorewlanengine.mm
+++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm
@@ -243,8 +243,7 @@ void QCoreWlanEngine::requestUpdate()
{
QMutexLocker locker(&mutex);
- pollTimer.stop();
- QTimer::singleShot(0, this, SLOT(doRequestUpdate()));
+ doRequestUpdate();
}
void QCoreWlanEngine::doRequestUpdate()
@@ -343,8 +342,6 @@ void QCoreWlanEngine::doRequestUpdate()
emit configurationRemoved(ptr);
}
- pollTimer.start();
-
emit updateCompleted();
}
@@ -610,4 +607,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/nativewifi/qnativewifiengine.cpp b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp
index c8015d8..ec2da00 100644
--- a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp
+++ b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp
@@ -95,10 +95,6 @@ QNativeWifiEngine::QNativeWifiEngine(QObject *parent)
if (result != ERROR_SUCCESS)
qWarning("%s: WlanRegisterNotification failed with error %ld\n", __FUNCTION__, result);
- // 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();
}
@@ -222,8 +218,6 @@ void QNativeWifiEngine::scanComplete()
emit configurationRemoved(ptr);
}
- pollTimer.start();
-
emit updateCompleted();
}
@@ -492,4 +486,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;
};