summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-03-05 11:59:28 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-03-05 11:59:28 (GMT)
commit4e8ee4b26d5cd80cb85d2dc4a71e62873789d4be (patch)
tree4e5011606c5351ebd07ac2c31a20b4825512cc58
parent267d7ed88d72d2fb3230a1ba5c3aa6b41f9ac79a (diff)
parent12b6987031be9faee3886d7623888feb4e1762af (diff)
downloadQt-4e8ee4b26d5cd80cb85d2dc4a71e62873789d4be.zip
Qt-4e8ee4b26d5cd80cb85d2dc4a71e62873789d4be.tar.gz
Qt-4e8ee4b26d5cd80cb85d2dc4a71e62873789d4be.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: Update the Qt focus widget on responder change. Doc: fix spelling errors. add wifi power notifications. more Qt way for autorelease. Remove unnecessary qWarnings from bearer management code. Don't keep polling network sessions open indefinitely. Prefer ethernet over wlan. Updating polling mechanism for bearer management engines.
-rw-r--r--doc/src/development/developing-on-mac.qdoc4
-rw-r--r--src/gui/kernel/qcocoaview_mac.mm7
-rw-r--r--src/network/access/qnetworkaccessmanager.cpp21
-rw-r--r--src/network/access/qnetworkaccessmanager.h1
-rw-r--r--src/network/access/qnetworkaccessmanager_p.h2
-rw-r--r--src/network/bearer/qbearerengine.cpp38
-rw-r--r--src/network/bearer/qbearerengine_p.h3
-rw-r--r--src/network/bearer/qnetworkconfigmanager.cpp77
-rw-r--r--src/network/bearer/qnetworkconfigmanager_p.cpp90
-rw-r--r--src/network/bearer/qnetworkconfigmanager_p.h15
-rw-r--r--src/network/bearer/qnetworksession.cpp14
-rw-r--r--src/plugins/bearer/corewlan/qcorewlanengine.h5
-rw-r--r--src/plugins/bearer/corewlan/qcorewlanengine.mm124
-rw-r--r--src/plugins/bearer/generic/qgenericengine.cpp14
-rw-r--r--src/plugins/bearer/generic/qgenericengine.h3
-rw-r--r--src/plugins/bearer/icd/qicdengine.cpp23
-rw-r--r--src/plugins/bearer/icd/qnetworksession_impl.cpp13
-rw-r--r--src/plugins/bearer/nativewifi/qnativewifiengine.cpp75
-rw-r--r--src/plugins/bearer/nativewifi/qnativewifiengine.h4
-rw-r--r--src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp8
-rw-r--r--src/plugins/bearer/nla/qnlaengine.cpp56
-rw-r--r--src/plugins/bearer/qnetworksession_impl.cpp56
-rw-r--r--src/plugins/bearer/qnetworksession_impl.h9
-rw-r--r--tests/auto/qnetworksession/test/tst_qnetworksession.cpp63
24 files changed, 541 insertions, 184 deletions
diff --git a/doc/src/development/developing-on-mac.qdoc b/doc/src/development/developing-on-mac.qdoc
index 20eefb7..1eb829e 100644
--- a/doc/src/development/developing-on-mac.qdoc
+++ b/doc/src/development/developing-on-mac.qdoc
@@ -72,10 +72,10 @@
Carbon Qt can be developed on and deployed to 10.4, but there is no 64-bit
support.
- With Qt 4.7 we now reccommend using the Cocoa version of Qt for developement,
+ With Qt 4.7 we now recommend using the Cocoa version of Qt for development,
unless you want to target the 10.4 platform. Qt now uses Cocoa by default,
both for the binary package and when configuring from source. Download the
- Carbon binarypackages or configure with "-carbon" to use that version.
+ Carbon binary packages or configure with "-carbon" to use that version.
There are two versions of the Qt binary, one with x86 and x86_64
Cocoa and another with x86 and ppc Carbon. If you want a different setup
diff --git a/src/gui/kernel/qcocoaview_mac.mm b/src/gui/kernel/qcocoaview_mac.mm
index f7cb21f..6261429 100644
--- a/src/gui/kernel/qcocoaview_mac.mm
+++ b/src/gui/kernel/qcocoaview_mac.mm
@@ -1047,6 +1047,13 @@ static int qCocoaViewCount = 0;
return YES;
}
+- (BOOL)becomeFirstResponder
+{
+ if (QApplication::focusWidget() == 0)
+ QApplicationPrivate::setFocusWidget([self QT_MANGLE_NAMESPACE(qt_qwidget)], Qt::OtherFocusReason);
+ return YES;
+}
+
- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal
{
Q_UNUSED(isLocal);
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp
index 5876ee2..7bb1399 100644
--- a/src/network/access/qnetworkaccessmanager.cpp
+++ b/src/network/access/qnetworkaccessmanager.cpp
@@ -880,11 +880,16 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera
return new QDisabledNetworkReply(this, req, op);
}
- if (d->initializeSession && !d->networkSession) {
+ if (!d->networkSession && (d->initializeSession || !d->networkConfiguration.isEmpty())) {
QNetworkConfigurationManager manager;
- d->createSession(manager.defaultConfiguration());
+ if (d->networkConfiguration.isEmpty())
+ d->createSession(manager.defaultConfiguration());
+ else
+ d->createSession(manager.configurationFromIdentifier(d->networkConfiguration));
d->initializeSession = false;
+ } else if (d->networkSession) {
+ d->networkSession->setSessionProperty(QLatin1String("AutoCloseSessionTimeout"), -1);
}
QNetworkRequest request = req;
@@ -943,6 +948,9 @@ void QNetworkAccessManagerPrivate::_q_replyFinished()
QNetworkReply *reply = qobject_cast<QNetworkReply *>(q->sender());
if (reply)
emit q->finished(reply);
+
+ if (networkSession && q->findChildren<QNetworkReply *>().count() == 1)
+ networkSession->setSessionProperty(QLatin1String("AutoCloseSessionTimeout"), 120000);
}
void QNetworkAccessManagerPrivate::_q_replySslErrors(const QList<QSslError> &errors)
@@ -1210,6 +1218,7 @@ void QNetworkAccessManagerPrivate::createSession(const QNetworkConfiguration &co
networkSession = new QNetworkSession(config, q);
QObject::connect(networkSession, SIGNAL(opened()), q, SIGNAL(networkSessionOnline()));
+ QObject::connect(networkSession, SIGNAL(closed()), q, SLOT(_q_networkSessionClosed()));
QObject::connect(networkSession, SIGNAL(newConfigurationActivated()),
q, SLOT(_q_networkSessionNewConfigurationActivated()));
QObject::connect(networkSession,
@@ -1218,6 +1227,14 @@ void QNetworkAccessManagerPrivate::createSession(const QNetworkConfiguration &co
SLOT(_q_networkSessionPreferredConfigurationChanged(QNetworkConfiguration,bool)));
}
+void QNetworkAccessManagerPrivate::_q_networkSessionClosed()
+{
+ networkConfiguration = networkSession->configuration().identifier();
+
+ delete networkSession;
+ networkSession = 0;
+}
+
void QNetworkAccessManagerPrivate::_q_networkSessionNewConfigurationActivated()
{
Q_Q(QNetworkAccessManager);
diff --git a/src/network/access/qnetworkaccessmanager.h b/src/network/access/qnetworkaccessmanager.h
index 252dfd0..694a54f 100644
--- a/src/network/access/qnetworkaccessmanager.h
+++ b/src/network/access/qnetworkaccessmanager.h
@@ -139,6 +139,7 @@ private:
Q_DECLARE_PRIVATE(QNetworkAccessManager)
Q_PRIVATE_SLOT(d_func(), void _q_replyFinished())
Q_PRIVATE_SLOT(d_func(), void _q_replySslErrors(QList<QSslError>))
+ Q_PRIVATE_SLOT(d_func(), void _q_networkSessionClosed())
Q_PRIVATE_SLOT(d_func(), void _q_networkSessionNewConfigurationActivated())
Q_PRIVATE_SLOT(d_func(), void _q_networkSessionPreferredConfigurationChanged(QNetworkConfiguration,bool))
};
diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h
index 8d772f0..0140268 100644
--- a/src/network/access/qnetworkaccessmanager_p.h
+++ b/src/network/access/qnetworkaccessmanager_p.h
@@ -105,6 +105,7 @@ public:
void createSession(const QNetworkConfiguration &config);
+ void _q_networkSessionClosed();
void _q_networkSessionNewConfigurationActivated();
void _q_networkSessionPreferredConfigurationChanged(const QNetworkConfiguration &config,
bool isSeamless);
@@ -121,6 +122,7 @@ public:
#endif
QNetworkSession *networkSession;
+ QString networkConfiguration;
bool networkAccessEnabled;
bool initializeSession;
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..b631cf1 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();
}
@@ -221,7 +227,7 @@ QNetworkConfiguration QNetworkConfigurationManager::defaultConfiguration() const
// Engines don't have a default configuration.
// Return first active snap
- QNetworkConfigurationPrivatePointer firstDiscovered;
+ QNetworkConfigurationPrivatePointer defaultConfiguration;
foreach (QBearerEngine *engine, conPriv->engines()) {
QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator it;
@@ -236,22 +242,35 @@ QNetworkConfiguration QNetworkConfigurationManager::defaultConfiguration() const
QNetworkConfiguration config;
config.d = it.value();
return config;
- } else if ((it.value()->state & QNetworkConfiguration::Discovered) ==
- QNetworkConfiguration::Discovered) {
- firstDiscovered = it.value();
+ } else if (!defaultConfiguration) {
+ if ((it.value()->state & QNetworkConfiguration::Discovered) ==
+ QNetworkConfiguration::Discovered) {
+ defaultConfiguration = it.value();
+ }
}
}
}
// No Active SNAPs return first Discovered SNAP.
- if (firstDiscovered) {
+ if (defaultConfiguration) {
QNetworkConfiguration config;
- config.d = firstDiscovered;
+ config.d = defaultConfiguration;
return config;
}
- // No Active or Discovered SNAPs, do same for InternetAccessPoints.
- firstDiscovered.reset();
+ /*
+ No Active or Discovered SNAPs, find the perferred access point.
+ The following priority order is used:
+
+ 1. Active Ethernet
+ 2. Active WLAN
+ 3. Active Other
+ 4. Discovered Ethernet
+ 5. Discovered WLAN
+ 6. Discovered Other
+ */
+
+ defaultConfiguration.reset();
foreach (QBearerEngine *engine, conPriv->engines()) {
QHash<QString, QNetworkConfigurationPrivatePointer>::Iterator it;
@@ -261,22 +280,42 @@ QNetworkConfiguration QNetworkConfigurationManager::defaultConfiguration() const
for (it = engine->accessPointConfigurations.begin(),
end = engine->accessPointConfigurations.end(); it != end; ++it) {
- if ((it.value()->state & QNetworkConfiguration::Active) ==
- QNetworkConfiguration::Active) {
- QNetworkConfiguration config;
- config.d = it.value();
- return config;
- } else if ((it.value()->state & QNetworkConfiguration::Discovered) ==
- QNetworkConfiguration::Discovered) {
- firstDiscovered = it.value();
+
+ if ((it.value()->state & QNetworkConfiguration::Discovered) ==
+ QNetworkConfiguration::Discovered) {
+ if (!defaultConfiguration) {
+ defaultConfiguration = it.value();
+ } else {
+ if (defaultConfiguration->state == it.value()->state) {
+ if (defaultConfiguration->bearerName() == QLatin1String("Ethernet")) {
+ // do nothing
+ } else if (defaultConfiguration->bearerName() == QLatin1String("WLAN")) {
+ // ethernet beats wlan
+ if (it.value()->bearerName() == QLatin1String("Ethernet"))
+ defaultConfiguration = it.value();
+ } else {
+ // ethernet and wlan beats other
+ if (it.value()->bearerName() == QLatin1String("Ethernet") ||
+ it.value()->bearerName() == QLatin1String("WLAN")) {
+ defaultConfiguration = it.value();
+ }
+ }
+ } else {
+ // active beats discovered
+ if ((defaultConfiguration->state & QNetworkConfiguration::Active) !=
+ QNetworkConfiguration::Active) {
+ defaultConfiguration = it.value();
+ }
+ }
+ }
}
}
}
// No Active InternetAccessPoint return first Discovered InternetAccessPoint.
- if (firstDiscovered) {
+ if (defaultConfiguration) {
QNetworkConfiguration config;
- config.d = firstDiscovered;
+ config.d = defaultConfiguration;
return config;
}
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/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp
index 047c8d3..cf9f4b2 100644
--- a/src/network/bearer/qnetworksession.cpp
+++ b/src/network/bearer/qnetworksession.cpp
@@ -492,6 +492,20 @@ QString QNetworkSession::errorString() const
\o Setting this property to \i true before calling \l open() implies that the connection attempt
is made but if no connection can be established, the user is not connsulted and asked to select
a suitable connection. This property is not set by default and support for it depends on the platform.
+
+ \row
+ \o AutoCloseSessionTimeout
+ \o If the session requires polling to keep its state up to date, this property holds
+ the timeout in milliseconds before the session will automatically close. If the
+ value of this property is -1 the session will not automatically close. This property
+ is set to -1 by default.
+
+ The purpose of this property is to minimize resource use on platforms that use
+ polling to update the state of the session. Applications can set the value of this
+ property to the desired timeout before the session is closed. In response to the
+ closed() signal the network session should be deleted to ensure that all polling is
+ stopped. The session can then be recreated once it is required again. This property
+ has no effect for sessions that do not require polling.
\endtable
*/
QVariant QNetworkSession::sessionProperty(const QString& key) const
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..8f174db 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,22 @@ 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();
+
+ [listener remove];
+ [listener release];
}
QString QCoreWlanEngine::getInterfaceFromId(const QString &id)
@@ -242,15 +316,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 +401,6 @@ void QCoreWlanEngine::doRequestUpdate()
emit configurationRemoved(ptr);
}
- pollTimer.start();
-
emit updateCompleted();
}
@@ -340,7 +411,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 +422,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 +484,9 @@ QStringList QCoreWlanEngine::scanForSsids(const QString &interfaceName)
emit configurationAdded(ptr);
}
- [looppool release];
}
}
}
- [autoreleasepool drain];
#else
Q_UNUSED(interfaceName);
#endif
@@ -458,39 +526,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 +636,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, &parameters, 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
diff --git a/tests/auto/qnetworksession/test/tst_qnetworksession.cpp b/tests/auto/qnetworksession/test/tst_qnetworksession.cpp
index 58b1a48..4b56f77 100644
--- a/tests/auto/qnetworksession/test/tst_qnetworksession.cpp
+++ b/tests/auto/qnetworksession/test/tst_qnetworksession.cpp
@@ -85,6 +85,9 @@ private slots:
void sessionOpenCloseStop_data();
void sessionOpenCloseStop();
+ void sessionAutoClose_data();
+ void sessionAutoClose();
+
private:
QNetworkConfigurationManager manager;
@@ -1202,7 +1205,67 @@ bool closeSession(QNetworkSession *session, bool lastSessionOnConfiguration) {
return true;
}
+void tst_QNetworkSession::sessionAutoClose_data()
+{
+ QTest::addColumn<QNetworkConfiguration>("configuration");
+
+ bool testData = false;
+ foreach (const QNetworkConfiguration &config,
+ manager.allConfigurations(QNetworkConfiguration::Discovered)) {
+ QNetworkSession session(config);
+ if (!session.sessionProperty(QLatin1String("AutoCloseSessionTimeout")).isValid())
+ continue;
+
+ testData = true;
+
+ const QString name = config.name().isEmpty() ? QString("<Hidden>") : config.name();
+ QTest::newRow(name.toLocal8Bit().constData()) << config;
+ }
+
+ if (!testData)
+ QSKIP("No applicable configurations to test", SkipAll);
+}
+
+void tst_QNetworkSession::sessionAutoClose()
+{
+ QFETCH(QNetworkConfiguration, configuration);
+
+ QNetworkSession session(configuration);
+
+ QVERIFY(session.configuration() == configuration);
+ QVariant autoCloseSession = session.sessionProperty(QLatin1String("AutoCloseSessionTimeout"));
+
+ QVERIFY(autoCloseSession.isValid());
+
+ // property defaults to false
+ QCOMPARE(autoCloseSession.toInt(), -1);
+
+ QSignalSpy closeSpy(&session, SIGNAL(closed()));
+
+ session.open();
+ session.waitForOpened();
+
+ if (!session.isOpen())
+ QSKIP("Session not open", SkipSingle);
+
+ // set session to auto close at next polling interval.
+ session.setSessionProperty(QLatin1String("AutoCloseSessionTimeout"), 0);
+
+ QTRY_VERIFY(!closeSpy.isEmpty());
+
+ QCOMPARE(session.state(), QNetworkSession::Connected);
+
+ QVERIFY(!session.isOpen());
+
+ QVERIFY(session.configuration() == configuration);
+
+ autoCloseSession = session.sessionProperty(QLatin1String("AutoCloseSessionTimeout"));
+
+ QVERIFY(autoCloseSession.isValid());
+
+ QCOMPARE(autoCloseSession.toInt(), -1);
+}
QTEST_MAIN(tst_QNetworkSession)