summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron McCarthy <aaron.mccarthy@nokia.com>2010-03-01 07:45:35 (GMT)
committerAaron McCarthy <aaron.mccarthy@nokia.com>2010-03-02 05:42:32 (GMT)
commitd042a00b5828961e1e1fa82017717b5f72dde9ef (patch)
tree600353f03174c0bfe80d964c5a6d2500e5df235d
parentef30a6f336d55c813423bf139d8363f50181179f (diff)
downloadQt-d042a00b5828961e1e1fa82017717b5f72dde9ef.zip
Qt-d042a00b5828961e1e1fa82017717b5f72dde9ef.tar.gz
Qt-d042a00b5828961e1e1fa82017717b5f72dde9ef.tar.bz2
Bearer management changes from Qt Mobility (fca9891).
fca98911b75ce12e70d93cfc2932a9759758a605
-rw-r--r--src/network/bearer/qnetworkconfigmanager.cpp5
-rw-r--r--src/network/bearer/qnetworkconfiguration.cpp1
-rw-r--r--src/network/bearer/qnetworksession.cpp4
-rw-r--r--src/plugins/bearer/corewlan/qcorewlanengine.h6
-rw-r--r--src/plugins/bearer/corewlan/qcorewlanengine.mm196
-rw-r--r--src/plugins/bearer/generic/qgenericengine.cpp11
-rw-r--r--src/plugins/bearer/icd/monitor.cpp56
-rw-r--r--src/plugins/bearer/icd/monitor.h22
-rw-r--r--src/plugins/bearer/icd/qicdengine.cpp24
-rw-r--r--src/plugins/bearer/icd/qnetworksession_impl.cpp32
-rw-r--r--src/plugins/bearer/icd/qnetworksession_impl.h7
-rw-r--r--src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp3
-rw-r--r--src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp293
-rw-r--r--src/plugins/bearer/networkmanager/qnetworkmanagerservice.h112
-rw-r--r--src/plugins/bearer/networkmanager/qnmdbushelper.cpp11
-rw-r--r--src/plugins/bearer/networkmanager/qnmdbushelper.h2
-rw-r--r--src/plugins/bearer/qnetworksession_impl.cpp3
-rw-r--r--src/plugins/bearer/symbian/qnetworksession_impl.cpp17
-rw-r--r--src/plugins/bearer/symbian/symbianengine.cpp38
-rw-r--r--src/plugins/bearer/symbian/symbianengine.h1
-rw-r--r--tests/auto/qbearertestcommon.h13
-rw-r--r--tests/auto/qnetworksession/lackey/main.cpp13
-rw-r--r--tests/auto/qnetworksession/test/tst_qnetworksession.cpp293
23 files changed, 794 insertions, 369 deletions
diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp
index e960323..9ff197b 100644
--- a/src/network/bearer/qnetworkconfigmanager.cpp
+++ b/src/network/bearer/qnetworkconfigmanager.cpp
@@ -302,6 +302,11 @@ QNetworkConfiguration QNetworkConfigurationManager::defaultConfiguration() const
be used to update each configuration's state. Note that such an update may require
some time. It's completion is signalled by updateCompleted(). In the absence of a
configuration update this function returns the best estimate at the time of the call.
+ Therefore, if WLAN configurations are of interest, it is recommended that
+ updateConfigurations() is called once after QNetworkConfigurationManager
+ instantiation (WLAN scans are too time consuming to perform in constructor).
+ After this the data is kept automatically up-to-date as the system reports
+ any changes.
*/
QList<QNetworkConfiguration> QNetworkConfigurationManager::allConfigurations(QNetworkConfiguration::StateFlags filter) const
{
diff --git a/src/network/bearer/qnetworkconfiguration.cpp b/src/network/bearer/qnetworkconfiguration.cpp
index c551dc5..c4ba406 100644
--- a/src/network/bearer/qnetworkconfiguration.cpp
+++ b/src/network/bearer/qnetworkconfiguration.cpp
@@ -40,7 +40,6 @@
****************************************************************************/
#include "qnetworkconfiguration.h"
-
#include "qnetworkconfiguration_p.h"
QT_BEGIN_NAMESPACE
diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp
index 6a82791..f0d7ede 100644
--- a/src/network/bearer/qnetworksession.cpp
+++ b/src/network/bearer/qnetworksession.cpp
@@ -275,6 +275,8 @@ void QNetworkSession::open()
{
if (d)
d->open();
+ else
+ emit error(InvalidConfigurationError);
}
/*!
@@ -308,6 +310,8 @@ bool QNetworkSession::waitForOpened(int msecs)
QEventLoop* loop = new QEventLoop(this);
QObject::connect(d, SIGNAL(quitPendingWaitsForOpened()),
loop, SLOT(quit()));
+ QObject::connect(this, SIGNAL(error(QNetworkSession::SessionError)),
+ loop, SLOT(quit()));
//final call
if (msecs>=0)
diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.h b/src/plugins/bearer/corewlan/qcorewlanengine.h
index 044b433..cfd89e4 100644
--- a/src/plugins/bearer/corewlan/qcorewlanengine.h
+++ b/src/plugins/bearer/corewlan/qcorewlanengine.h
@@ -46,6 +46,7 @@
#include <QMap>
#include <QTimer>
+#include <SystemConfiguration/SystemConfiguration.h>
QT_BEGIN_NAMESPACE
@@ -91,6 +92,11 @@ private:
bool isKnownSsid(const QString &interfaceName, const QString &ssid);
QList<QNetworkConfigurationPrivate *> foundConfigurations;
+ SCDynamicStoreRef storeSession;
+ CFRunLoopSourceRef runloopSource;
+
+ void startNetworkChangeLoop();
+
};
QT_END_NAMESPACE
diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm
index a5384d1..4ab4d88 100644
--- a/src/plugins/bearer/corewlan/qcorewlanengine.mm
+++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm
@@ -105,12 +105,23 @@ static QString qGetInterfaceType(const QString &interfaceString)
return networkInterfaces.value(interfaceString, QLatin1String("Unknown"));
}
+void networkChangeCallback(SCDynamicStoreRef/* store*/, CFArrayRef changedKeys, void *info)
+{
+ for ( long i = 0; i < CFArrayGetCount(changedKeys); i++) {
+
+ CFStringRef changed = (CFStringRef)CFArrayGetValueAtIndex(changedKeys, i);
+ if( cfstringRefToQstring(changed).contains("/Network/Global/IPv4")) {
+ QCoreWlanEngine* wlanEngine = static_cast<QCoreWlanEngine*>(info);
+ wlanEngine->requestUpdate();
+ }
+ }
+ return;
+}
+
QCoreWlanEngine::QCoreWlanEngine(QObject *parent)
: QBearerEngineImpl(parent)
{
- connect(&pollTimer, SIGNAL(timeout()), this, SLOT(doRequestUpdate()));
- pollTimer.setInterval(10000);
- doRequestUpdate();
+ startNetworkChangeLoop();
}
QCoreWlanEngine::~QCoreWlanEngine()
@@ -150,7 +161,6 @@ void QCoreWlanEngine::connectToId(const QString &id)
NSEnumerator *enumerator = [remNets objectEnumerator];
CWWirelessProfile *wProfile;
NSUInteger index=0;
- CWNetwork *apNetwork;
NSDictionary *parametersDict;
NSArray* apArray;
@@ -179,26 +189,24 @@ void QCoreWlanEngine::connectToId(const QString &id)
if(!err) {
for(uint row=0; row < [apArray count]; row++ ) {
- apNetwork = [apArray objectAtIndex:row];
+ CWNetwork *apNetwork = [apArray objectAtIndex:row];
if([[apNetwork ssid] compare:[wProfile ssid]] == NSOrderedSame) {
bool result = [wifiInterface associateToNetwork: apNetwork parameters:[NSDictionary dictionaryWithDictionary:params] error:&err];
if(!result) {
- qWarning() <<"ERROR"<< nsstringToQString([err localizedDescription ]);
emit connectionError(id, ConnectError);
} else {
- [apNetwork release];
[autoreleasepool release];
return;
}
}
+ [apNetwork release];
}
}
}
index++;
}
- [apNetwork release];
emit connectionError(id, InterfaceLookupError);
#endif
@@ -350,81 +358,83 @@ QStringList QCoreWlanEngine::scanForSsids(const QString &interfaceName)
NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
CWInterface *currentInterface = [CWInterface interfaceWithName:qstringToNSString(interfaceName)];
- NSError *err = nil;
- NSDictionary *parametersDict = nil;
- NSArray* apArray = [currentInterface scanForNetworksWithParameters:parametersDict error:&err];
+ if([currentInterface power]) {
+ NSError *err = nil;
+ NSDictionary *parametersDict = nil;
+ NSArray* apArray = [currentInterface scanForNetworksWithParameters:parametersDict error:&err];
- CWNetwork *apNetwork;
- if (!err) {
- for(uint row=0; row < [apArray count]; row++ ) {
- NSAutoreleasePool *looppool = [[NSAutoreleasePool alloc] init];
+ CWNetwork *apNetwork;
+ if (!err) {
+ for(uint row=0; row < [apArray count]; row++ ) {
+ NSAutoreleasePool *looppool = [[NSAutoreleasePool alloc] init];
- apNetwork = [apArray objectAtIndex:row];
+ apNetwork = [apArray objectAtIndex:row];
- const QString networkSsid = nsstringToQString([apNetwork ssid]);
+ const QString networkSsid = nsstringToQString([apNetwork ssid]);
- const QString id = QString::number(qHash(QLatin1String("corewlan:") + networkSsid));
- found.append(id);
+ const QString id = QString::number(qHash(QLatin1String("corewlan:") + networkSsid));
+ found.append(id);
- QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined;
+ QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined;
- if ([currentInterface.interfaceState intValue] == kCWInterfaceStateRunning) {
- if (networkSsid == nsstringToQString([currentInterface ssid]))
- state = QNetworkConfiguration::Active;
- } else {
- if (isKnownSsid(interfaceName, networkSsid))
- state = QNetworkConfiguration::Discovered;
- else
- state = QNetworkConfiguration::Defined;
- }
+ if ([currentInterface.interfaceState intValue] == kCWInterfaceStateRunning) {
+ if (networkSsid == nsstringToQString([currentInterface ssid]))
+ state = QNetworkConfiguration::Active;
+ } else {
+ if (isKnownSsid(interfaceName, networkSsid))
+ state = QNetworkConfiguration::Discovered;
+ else
+ state = QNetworkConfiguration::Defined;
+ }
- if (accessPointConfigurations.contains(id)) {
- QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);
+ if (accessPointConfigurations.contains(id)) {
+ QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);
- bool changed = false;
+ bool changed = false;
- if (!ptr->isValid) {
- ptr->isValid = true;
- changed = true;
- }
+ if (!ptr->isValid) {
+ ptr->isValid = true;
+ changed = true;
+ }
- if (ptr->name != networkSsid) {
- ptr->name = networkSsid;
- changed = true;
- }
+ if (ptr->name != networkSsid) {
+ ptr->name = networkSsid;
+ changed = true;
+ }
- if (ptr->id != id) {
- ptr->id = id;
- changed = true;
- }
+ if (ptr->id != id) {
+ ptr->id = id;
+ changed = true;
+ }
- if (ptr->state != state) {
- ptr->state = state;
- changed = true;
- }
+ if (ptr->state != state) {
+ ptr->state = state;
+ changed = true;
+ }
- if (changed)
- emit configurationChanged(ptr);
- } else {
- QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate);
+ if (changed)
+ emit configurationChanged(ptr);
+ } else {
+ QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate);
- ptr->name = networkSsid;
- ptr->isValid = true;
- ptr->id = id;
- ptr->state = state;
- ptr->type = QNetworkConfiguration::InternetAccessPoint;
- ptr->bearer = QLatin1String("WLAN");
+ ptr->name = networkSsid;
+ ptr->isValid = true;
+ ptr->id = id;
+ ptr->state = state;
+ ptr->type = QNetworkConfiguration::InternetAccessPoint;
+ ptr->bearer = QLatin1String("WLAN");
- accessPointConfigurations.insert(id, ptr);
- configurationInterface.insert(id, interfaceName);
+ accessPointConfigurations.insert(id, ptr);
+ configurationInterface.insert(id, interfaceName);
- emit configurationAdded(ptr);
+ emit configurationAdded(ptr);
+ }
+ [looppool release];
}
- [looppool release];
- }
- } else {
- qWarning() << "ERROR scanning for ssids" << nsstringToQString([err localizedDescription])
- <<nsstringToQString([err domain]);
+ } /*else {
+ qWarning() << "ERROR scanning for ssids" << nsstringToQString([err localizedDescription])
+ <<nsstringToQString([err domain]);
+ }*/
}
[autoreleasepool drain];
@@ -540,6 +550,60 @@ QNetworkConfigurationManager::Capabilities QCoreWlanEngine::capabilities() const
return QNetworkConfigurationManager::ForcedRoaming;
}
+void QCoreWlanEngine::startNetworkChangeLoop()
+{
+ storeSession = NULL;
+
+ SCDynamicStoreContext dynStoreContext = { 0, this/*(void *)storeSession*/, NULL, NULL, NULL };
+ storeSession = SCDynamicStoreCreate(NULL,
+ CFSTR("networkChangeCallback"),
+ networkChangeCallback,
+ &dynStoreContext);
+ if (!storeSession ) {
+ qWarning() << "could not open dynamic store: error:" << SCErrorString(SCError());
+ return;
+ }
+
+ CFMutableArrayRef notificationKeys;
+ notificationKeys = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
+ CFMutableArrayRef patternsArray;
+ patternsArray = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
+
+ CFStringRef storeKey;
+ storeKey = SCDynamicStoreKeyCreateNetworkGlobalEntity(NULL,
+ kSCDynamicStoreDomainState,
+ kSCEntNetIPv4);
+ CFArrayAppendValue(notificationKeys, storeKey);
+ CFRelease(storeKey);
+
+ storeKey = SCDynamicStoreKeyCreateNetworkServiceEntity(NULL,
+ kSCDynamicStoreDomainState,
+ kSCCompAnyRegex,
+ kSCEntNetIPv4);
+ CFArrayAppendValue(patternsArray, storeKey);
+ CFRelease(storeKey);
+
+ if (!SCDynamicStoreSetNotificationKeys(storeSession , notificationKeys, patternsArray)) {
+ qWarning() << "register notification error:"<< SCErrorString(SCError());
+ CFRelease(storeSession );
+ CFRelease(notificationKeys);
+ CFRelease(patternsArray);
+ return;
+ }
+ CFRelease(notificationKeys);
+ CFRelease(patternsArray);
+
+ runloopSource = SCDynamicStoreCreateRunLoopSource(NULL, storeSession , 0);
+ if (!runloopSource) {
+ qWarning() << "runloop source error:"<< SCErrorString(SCError());
+ CFRelease(storeSession );
+ return;
+ }
+
+ CFRunLoopAddSource(CFRunLoopGetCurrent(), runloopSource, kCFRunLoopDefaultMode);
+ return;
+}
+
QNetworkSessionPrivate *QCoreWlanEngine::createSessionBackend()
{
return new QNetworkSessionPrivateImpl;
diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp
index a95b14b..ccf1057 100644
--- a/src/plugins/bearer/generic/qgenericengine.cpp
+++ b/src/plugins/bearer/generic/qgenericengine.cpp
@@ -125,14 +125,11 @@ static QString qGetInterfaceType(const QString &interface)
ifreq request;
strncpy(request.ifr_name, interface.toLocal8Bit().data(), sizeof(request.ifr_name));
- if (ioctl(sock, SIOCGIFHWADDR, &request) >= 0) {
- switch (request.ifr_hwaddr.sa_family) {
- case ARPHRD_ETHER:
- return QLatin1String("Ethernet");
- }
- }
-
+ int result = ioctl(sock, SIOCGIFHWADDR, &request);
close(sock);
+
+ if (result >= 0 && request.ifr_hwaddr.sa_family == ARPHRD_ETHER)
+ return QLatin1String("Ethernet");
#else
Q_UNUSED(interface);
#endif
diff --git a/src/plugins/bearer/icd/monitor.cpp b/src/plugins/bearer/icd/monitor.cpp
index 0ff45d2..5b0af7e 100644
--- a/src/plugins/bearer/icd/monitor.cpp
+++ b/src/plugins/bearer/icd/monitor.cpp
@@ -47,32 +47,12 @@
#include <maemo_icd.h>
#include <iapconf.h>
-#define IAP "/system/osso/connectivity/IAP"
-
-static int iap_prefix_len;
-
-/* Notify func that is called when IAP is added or deleted */
-void notify_iap(GConfClient *, guint, GConfEntry *entry, gpointer user_data)
-{
- const char *key = gconf_entry_get_key(entry);
- if (key && g_str_has_prefix(key, IAP)) {
- IapMonitor *ptr = (IapMonitor *)user_data;
- if (gconf_entry_get_value(entry)) {
- ptr->iapAdded(key, entry);
- } else {
- ptr->iapDeleted(key, entry);
- }
- }
-}
-
void IapMonitor::setup(QIcdEngine *d_ptr)
{
if (first_call) {
- d = d_ptr;
- iap_prefix_len = strlen(IAP);
- iap = new Maemo::IAPMonitor(notify_iap, (gpointer)this);
- first_call = false;
+ d = d_ptr;
+ first_call = false;
}
}
@@ -80,37 +60,25 @@ void IapMonitor::setup(QIcdEngine *d_ptr)
void IapMonitor::cleanup()
{
if (!first_call) {
- delete iap;
- timers.removeAll();
- first_call = true;
+ timers.removeAll();
+ first_call = true;
}
}
-void IapMonitor::iapAdded(const char *key, GConfEntry * /*entry*/)
+void IapMonitor::iapAdded(const QString &iap_id)
{
- //qDebug("Notify called for added element: %s=%s",
- // gconf_entry_get_key(entry), gconf_value_to_string(gconf_entry_get_value(entry)));
-
- /* We cannot know when the IAP is fully added to gconf, so a timer is
+ /* We cannot know when the IAP is fully added to db, so a timer is
* installed instead. When the timer expires we hope that IAP is added ok.
*/
- QString iap_id = QString(key + iap_prefix_len + 1).section('/',0,0);
- timers.add(iap_id, d);
+ QString id = iap_id;
+ timers.add(id, d);
}
-void IapMonitor::iapDeleted(const char *key, GConfEntry * /*entry*/)
+void IapMonitor::iapRemoved(const QString &iap_id)
{
- //qDebug("Notify called for deleted element: %s", gconf_entry_get_key(entry));
-
- /* We are only interested in IAP deletions so we skip the config entries
- */
- if (strstr(key + iap_prefix_len + 1, "/")) {
- //qDebug("Deleting IAP config %s", key+iap_prefix_len);
- return;
- }
-
- QString iap_id = key + iap_prefix_len + 1;
- d->deleteConfiguration(iap_id);
+ QString id = iap_id;
+ d->deleteConfiguration(id);
}
+
diff --git a/src/plugins/bearer/icd/monitor.h b/src/plugins/bearer/icd/monitor.h
index 82b0f36..10ffb30 100644
--- a/src/plugins/bearer/icd/monitor.h
+++ b/src/plugins/bearer/icd/monitor.h
@@ -53,7 +53,7 @@
class QIcdEngine;
/* The IapAddTimer is a helper class that makes sure we update
- * the configuration only after all gconf additions to certain
+ * the configuration only after all db additions to certain
* iap are finished (after a certain timeout)
*/
class _IapAddTimer : public QObject
@@ -64,10 +64,10 @@ public:
_IapAddTimer() {}
~_IapAddTimer()
{
- if (timer.isActive()) {
- QObject::disconnect(&timer, SIGNAL(timeout()), this, SLOT(timeout()));
- timer.stop();
- }
+ if (timer.isActive()) {
+ QObject::disconnect(&timer, SIGNAL(timeout()), this, SLOT(timeout()));
+ timer.stop();
+ }
}
void add(QString& iap_id, QIcdEngine *d);
@@ -92,23 +92,21 @@ public:
void removeAll();
};
-class IapMonitor
+class IapMonitor : public Maemo::IAPMonitor
{
public:
IapMonitor() : first_call(true) { }
- friend void notify_iap(GConfClient *, guint,
- GConfEntry *entry, gpointer user_data);
void setup(QIcdEngine *d);
void cleanup();
+protected:
+ void iapAdded(const QString &iapId);
+ void iapRemoved(const QString &iapId);
+
private:
bool first_call;
- void iapAdded(const char *key, GConfEntry *entry);
- void iapDeleted(const char *key, GConfEntry *entry);
-
- Maemo::IAPMonitor *iap;
QIcdEngine *d;
IapAddTimer timers;
};
diff --git a/src/plugins/bearer/icd/qicdengine.cpp b/src/plugins/bearer/icd/qicdengine.cpp
index f10042a..206a6fd 100644
--- a/src/plugins/bearer/icd/qicdengine.cpp
+++ b/src/plugins/bearer/icd/qicdengine.cpp
@@ -189,14 +189,9 @@ void QIcdEngine::doRequestUpdate()
QList<QString> all_iaps;
Maemo::IAPConf::getAll(all_iaps);
- foreach (QString escaped_iap_id, all_iaps) {
+ foreach (QString iap_id, all_iaps) {
QByteArray ssid;
- /* The key that is returned by getAll() needs to be unescaped */
- gchar *unescaped_id = gconf_unescape_key(escaped_iap_id.toUtf8().data(), -1);
- QString iap_id = QString((char *)unescaped_id);
- g_free(unescaped_id);
-
previous.removeAll(iap_id);
Maemo::IAPConf saved_ap(iap_id);
@@ -231,11 +226,12 @@ void QIcdEngine::doRequestUpdate()
IcdNetworkConfigurationPrivate *cpPriv = new IcdNetworkConfigurationPrivate;
cpPriv->name = saved_ap.value("name").toString();
- if (cpPriv->name.isEmpty())
- if (!ssid.isEmpty() && ssid.size() > 0)
- cpPriv->name = ssid.data();
- else
- cpPriv->name = iap_id;
+ if (cpPriv->name.isEmpty()) {
+ if (!ssid.isEmpty() && ssid.size() > 0)
+ cpPriv->name = ssid.data();
+ else
+ cpPriv->name = iap_id;
+ }
cpPriv->isValid = true;
cpPriv->id = iap_id;
cpPriv->network_id = ssid;
@@ -379,9 +375,9 @@ void QIcdEngine::deleteConfiguration(const QString &iap_id)
{
QMutexLocker locker(&mutex);
- /* Called when IAPs are deleted in gconf, in this case we do not scan
- * or read all the IAPs from gconf because it might take too much power
- * (multiple applications would need to scan and read all IAPs from gconf)
+ /* Called when IAPs are deleted in db, in this case we do not scan
+ * 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);
diff --git a/src/plugins/bearer/icd/qnetworksession_impl.cpp b/src/plugins/bearer/icd/qnetworksession_impl.cpp
index a9e93e0..2acaa47 100644
--- a/src/plugins/bearer/icd/qnetworksession_impl.cpp
+++ b/src/plugins/bearer/icd/qnetworksession_impl.cpp
@@ -49,6 +49,7 @@
#include <maemo_icd.h>
#include <iapconf.h>
+#include <proxyconf.h>
#include <sys/types.h>
#include <ifaddrs.h>
@@ -299,6 +300,8 @@ void IcdListener::cleanupSession(QNetworkSessionPrivateImpl *ptr)
void QNetworkSessionPrivateImpl::cleanupSession(void)
{
icdListener()->cleanupSession(this);
+
+ QObject::disconnect(q, SIGNAL(stateChanged(QNetworkSession::State)), this, SLOT(updateProxies(QNetworkSession::State)));
}
@@ -451,6 +454,8 @@ void QNetworkSessionPrivateImpl::syncStateWithInterface()
connect(&manager, SIGNAL(configurationChanged(QNetworkConfiguration)),
this, SLOT(configurationChanged(QNetworkConfiguration)));
+ QObject::connect(q, SIGNAL(stateChanged(QNetworkSession::State)), this, SLOT(updateProxies(QNetworkSession::State)));
+
state = QNetworkSession::Invalid;
lastError = QNetworkSession::UnknownSessionError;
@@ -867,7 +872,6 @@ void QNetworkSessionPrivateImpl::do_open()
qDebug() << "connect to"<< iap << "failed, result is empty";
#endif
updateState(QNetworkSession::Disconnected);
- emit quitPendingWaitsForOpened();
emit QNetworkSessionPrivate::error(QNetworkSession::InvalidConfigurationError);
if (publicConfig.type() == QNetworkConfiguration::UserChoice)
cleanupAnyConfiguration();
@@ -882,7 +886,6 @@ void QNetworkSessionPrivateImpl::do_open()
if ((publicConfig.type() != QNetworkConfiguration::UserChoice) &&
(connected_iap != config.identifier())) {
updateState(QNetworkSession::Disconnected);
- emit quitPendingWaitsForOpened();
emit QNetworkSessionPrivate::error(QNetworkSession::InvalidConfigurationError);
return;
}
@@ -946,7 +949,6 @@ void QNetworkSessionPrivateImpl::do_open()
updateState(QNetworkSession::Disconnected);
if (publicConfig.type() == QNetworkConfiguration::UserChoice)
cleanupAnyConfiguration();
- emit quitPendingWaitsForOpened();
emit QNetworkSessionPrivate::error(QNetworkSession::UnknownSessionError);
}
}
@@ -1099,6 +1101,30 @@ QNetworkSession::SessionError QNetworkSessionPrivateImpl::error() const
return QNetworkSession::UnknownSessionError;
}
+void QNetworkSessionPrivateImpl::updateProxies(QNetworkSession::State newState)
+{
+ if ((newState == QNetworkSession::Connected) &&
+ (newState != currentState))
+ updateProxyInformation();
+ else if ((newState == QNetworkSession::Disconnected) &&
+ (currentState == QNetworkSession::Closing))
+ clearProxyInformation();
+
+ currentState = newState;
+}
+
+
+void QNetworkSessionPrivateImpl::updateProxyInformation()
+{
+ Maemo::ProxyConf::update();
+}
+
+
+void QNetworkSessionPrivateImpl::clearProxyInformation()
+{
+ Maemo::ProxyConf::clear();
+}
+
#include "qnetworksession_impl.moc"
QT_END_NAMESPACE
diff --git a/src/plugins/bearer/icd/qnetworksession_impl.h b/src/plugins/bearer/icd/qnetworksession_impl.h
index b7461dc..587e6dc 100644
--- a/src/plugins/bearer/icd/qnetworksession_impl.h
+++ b/src/plugins/bearer/icd/qnetworksession_impl.h
@@ -75,7 +75,7 @@ class QNetworkSessionPrivateImpl : public QNetworkSessionPrivate
public:
QNetworkSessionPrivateImpl(QIcdEngine *engine)
- : engine(engine), connectFlags(ICD_CONNECTION_FLAG_USER_EVENT)
+ : engine(engine), connectFlags(ICD_CONNECTION_FLAG_USER_EVENT), currentState(QNetworkSession::Invalid)
{
}
@@ -118,6 +118,7 @@ private Q_SLOTS:
void do_open();
void networkConfigurationsChanged();
void configurationChanged(const QNetworkConfiguration &config);
+ void updateProxies(QNetworkSession::State newState);
private:
QNetworkConfigurationManager manager;
@@ -139,6 +140,10 @@ private:
void updateIdentifier(QString &newId);
quint64 getStatistics(bool sent) const;
void cleanupSession(void);
+
+ void updateProxyInformation();
+ void clearProxyInformation();
+ QNetworkSession::State currentState;
};
QT_END_NAMESPACE
diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp
index 5c6efe3..0fa8f3c 100644
--- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp
+++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp
@@ -49,7 +49,6 @@
#include <QtCore/qdebug.h>
-#include <NetworkManager/NetworkManager.h>
#include <QtDBus>
#include <QDBusConnection>
#include <QDBusError>
@@ -147,7 +146,7 @@ QString QNetworkManagerEngine::getInterfaceFromId(const QString &id)
continue;
QNetworkManagerInterfaceDevice device(devices.at(0).path());
- return device.interface().name();
+ return device.networkInterface().name();
}
}
diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp
index 5dc0ea4..c780fbc 100644
--- a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp
+++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp
@@ -41,26 +41,22 @@
#include <QObject>
#include <QList>
-#include <QtDBus>
-#include <QDBusConnection>
-#include <QDBusError>
-#include <QDBusInterface>
-#include <QDBusMessage>
-#include <QDBusReply>
-#include <QDBusPendingCallWatcher>
-#include <QDBusObjectPath>
-#include <QDBusPendingCall>
-
-#include <NetworkManager/NetworkManager.h>
+#include <QtDBus/QtDBus>
+#include <QtDBus/QDBusConnection>
+#include <QtDBus/QDBusError>
+#include <QtDBus/QDBusInterface>
+#include <QtDBus/QDBusMessage>
+#include <QtDBus/QDBusReply>
+#include <QtDBus/QDBusPendingCallWatcher>
+#include <QtDBus/QDBusObjectPath>
+#include <QtDBus/QDBusPendingCall>
-#include "qnmdbushelper.h"
#include "qnetworkmanagerservice.h"
+#include "qnmdbushelper.h"
-//Q_DECLARE_METATYPE(QList<uint>)
QT_BEGIN_NAMESPACE
static QDBusConnection dbusConnection = QDBusConnection::systemBus();
-//static QDBusInterface iface(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, dbusConnection);
class QNetworkManagerInterfacePrivate
{
@@ -70,19 +66,19 @@ public:
};
QNetworkManagerInterface::QNetworkManagerInterface(QObject *parent)
- : QObject(parent), nmDBusHelper(0)
+ : QObject(parent)
{
d = new QNetworkManagerInterfacePrivate();
- d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE,
- NM_DBUS_PATH,
- NM_DBUS_INTERFACE,
+ d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
+ QLatin1String(NM_DBUS_PATH),
+ QLatin1String(NM_DBUS_INTERFACE),
dbusConnection);
if (!d->connectionInterface->isValid()) {
d->valid = false;
return;
}
d->valid = true;
- nmDBusHelper = new QNmDBusHelper;
+ nmDBusHelper = new QNmDBusHelper(this);
connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap<QString,QVariant>)),
this,SIGNAL(propertiesChanged( const QString &, QMap<QString,QVariant>)));
connect(nmDBusHelper,SIGNAL(pathForStateChanged(const QString &, quint32)),
@@ -92,8 +88,6 @@ QNetworkManagerInterface::QNetworkManagerInterface(QObject *parent)
QNetworkManagerInterface::~QNetworkManagerInterface()
{
- if (nmDBusHelper)
- delete nmDBusHelper;
delete d->connectionInterface;
delete d;
}
@@ -108,24 +102,24 @@ bool QNetworkManagerInterface::setConnections()
if(!isValid() )
return false;
bool allOk = false;
- if (!dbusConnection.connect(NM_DBUS_SERVICE,
- NM_DBUS_PATH,
- NM_DBUS_INTERFACE,
- "PropertiesChanged",
+ if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
+ QLatin1String(NM_DBUS_PATH),
+ QLatin1String(NM_DBUS_INTERFACE),
+ QLatin1String("PropertiesChanged"),
nmDBusHelper,SLOT(slotPropertiesChanged( QMap<QString,QVariant>)))) {
allOk = true;
}
- if (!dbusConnection.connect(NM_DBUS_SERVICE,
- NM_DBUS_PATH,
- NM_DBUS_INTERFACE,
- "DeviceAdded",
+ if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
+ QLatin1String(NM_DBUS_PATH),
+ QLatin1String(NM_DBUS_INTERFACE),
+ QLatin1String("DeviceAdded"),
this,SIGNAL(deviceAdded(QDBusObjectPath)))) {
allOk = true;
}
- if (!dbusConnection.connect(NM_DBUS_SERVICE,
- NM_DBUS_PATH,
- NM_DBUS_INTERFACE,
- "DeviceRemoved",
+ if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
+ QLatin1String(NM_DBUS_PATH),
+ QLatin1String(NM_DBUS_INTERFACE),
+ QLatin1String("DeviceRemoved"),
this,SIGNAL(deviceRemoved(QDBusObjectPath)))) {
allOk = true;
}
@@ -140,7 +134,7 @@ QDBusInterface *QNetworkManagerInterface::connectionInterface() const
QList <QDBusObjectPath> QNetworkManagerInterface::getDevices() const
{
- QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call("GetDevices");
+ QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call(QLatin1String("GetDevices"));
return reply.value();
}
@@ -149,7 +143,7 @@ void QNetworkManagerInterface::activateConnection( const QString &serviceName,
QDBusObjectPath devicePath,
QDBusObjectPath specificObject)
{
- QDBusPendingCall pendingCall = d->connectionInterface->asyncCall("ActivateConnection",
+ QDBusPendingCall pendingCall = d->connectionInterface->asyncCall(QLatin1String("ActivateConnection"),
QVariant(serviceName),
QVariant::fromValue(connectionPath),
QVariant::fromValue(devicePath),
@@ -162,7 +156,7 @@ void QNetworkManagerInterface::activateConnection( const QString &serviceName,
void QNetworkManagerInterface::deactivateConnection(QDBusObjectPath connectionPath) const
{
- d->connectionInterface->call("DeactivateConnection", QVariant::fromValue(connectionPath));
+ d->connectionInterface->call(QLatin1String("DeactivateConnection"), QVariant::fromValue(connectionPath));
}
bool QNetworkManagerInterface::wirelessEnabled() const
@@ -186,7 +180,6 @@ quint32 QNetworkManagerInterface::state()
return d->connectionInterface->property("State").toUInt();
}
-/////////////
class QNetworkManagerInterfaceAccessPointPrivate
{
public:
@@ -200,9 +193,9 @@ QNetworkManagerInterfaceAccessPoint::QNetworkManagerInterfaceAccessPoint(const Q
{
d = new QNetworkManagerInterfaceAccessPointPrivate();
d->path = dbusPathName;
- d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE,
+ d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
d->path,
- NM_DBUS_INTERFACE_ACCESS_POINT,
+ QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT),
dbusConnection);
if (!d->connectionInterface->isValid()) {
d->valid = false;
@@ -215,8 +208,6 @@ QNetworkManagerInterfaceAccessPoint::QNetworkManagerInterfaceAccessPoint(const Q
QNetworkManagerInterfaceAccessPoint::~QNetworkManagerInterfaceAccessPoint()
{
- if (nmDBusHelper)
- delete nmDBusHelper;
delete d->connectionInterface;
delete d;
}
@@ -232,17 +223,15 @@ bool QNetworkManagerInterfaceAccessPoint::setConnections()
return false;
bool allOk = false;
- if (nmDBusHelper)
- delete nmDBusHelper;
- nmDBusHelper = 0;
- nmDBusHelper = new QNmDBusHelper;
+ delete nmDBusHelper;
+ nmDBusHelper = new QNmDBusHelper(this);
connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap<QString,QVariant>)),
this,SIGNAL(propertiesChanged( const QString &, QMap<QString,QVariant>)));
- if(dbusConnection.connect(NM_DBUS_SERVICE,
+ if(dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
d->path,
- NM_DBUS_INTERFACE_ACCESS_POINT,
- "PropertiesChanged",
+ QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT),
+ QLatin1String("PropertiesChanged"),
nmDBusHelper,SLOT(slotPropertiesChanged( QMap<QString,QVariant>))) ) {
allOk = true;
@@ -300,7 +289,6 @@ quint32 QNetworkManagerInterfaceAccessPoint::strength() const
return d->connectionInterface->property("Strength").toUInt();
}
-/////////////
class QNetworkManagerInterfaceDevicePrivate
{
public:
@@ -314,9 +302,9 @@ QNetworkManagerInterfaceDevice::QNetworkManagerInterfaceDevice(const QString &de
{
d = new QNetworkManagerInterfaceDevicePrivate();
d->path = deviceObjectPath;
- d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE,
+ d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
d->path,
- NM_DBUS_INTERFACE_DEVICE,
+ QLatin1String(NM_DBUS_INTERFACE_DEVICE),
dbusConnection);
if (!d->connectionInterface->isValid()) {
d->valid = false;
@@ -328,8 +316,6 @@ QNetworkManagerInterfaceDevice::QNetworkManagerInterfaceDevice(const QString &de
QNetworkManagerInterfaceDevice::~QNetworkManagerInterfaceDevice()
{
- if (nmDBusHelper)
- delete nmDBusHelper;
delete d->connectionInterface;
delete d;
}
@@ -345,16 +331,14 @@ bool QNetworkManagerInterfaceDevice::setConnections()
return false;
bool allOk = false;
- if (nmDBusHelper)
- delete nmDBusHelper;
- nmDBusHelper = 0;
- nmDBusHelper = new QNmDBusHelper;
+ delete nmDBusHelper;
+ nmDBusHelper = new QNmDBusHelper(this);
connect(nmDBusHelper,SIGNAL(pathForStateChanged(const QString &, quint32)),
this, SIGNAL(stateChanged(const QString&, quint32)));
- if(dbusConnection.connect(NM_DBUS_SERVICE,
+ if(dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
d->path,
- NM_DBUS_INTERFACE_DEVICE,
- "StateChanged",
+ QLatin1String(NM_DBUS_INTERFACE_DEVICE),
+ QLatin1String("StateChanged"),
nmDBusHelper,SLOT(deviceStateChanged(quint32)))) {
allOk = true;
}
@@ -371,7 +355,7 @@ QString QNetworkManagerInterfaceDevice::udi() const
return d->connectionInterface->property("Udi").toString();
}
-QNetworkInterface QNetworkManagerInterfaceDevice::interface() const
+QNetworkInterface QNetworkManagerInterfaceDevice::networkInterface() const
{
return QNetworkInterface::interfaceFromName(d->connectionInterface->property("Interface").toString());
}
@@ -397,7 +381,6 @@ QDBusObjectPath QNetworkManagerInterfaceDevice::ip4config() const
return prop.value<QDBusObjectPath>();
}
-/////////////
class QNetworkManagerInterfaceDeviceWiredPrivate
{
public:
@@ -411,9 +394,9 @@ QNetworkManagerInterfaceDeviceWired::QNetworkManagerInterfaceDeviceWired(const Q
{
d = new QNetworkManagerInterfaceDeviceWiredPrivate();
d->path = ifaceDevicePath;
- d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE,
+ d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
d->path,
- NM_DBUS_INTERFACE_DEVICE_WIRED,
+ QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRED),
dbusConnection, parent);
if (!d->connectionInterface->isValid()) {
d->valid = false;
@@ -425,8 +408,6 @@ QNetworkManagerInterfaceDeviceWired::QNetworkManagerInterfaceDeviceWired(const Q
QNetworkManagerInterfaceDeviceWired::~QNetworkManagerInterfaceDeviceWired()
{
- if (nmDBusHelper)
- delete nmDBusHelper;
delete d->connectionInterface;
delete d;
}
@@ -444,16 +425,14 @@ bool QNetworkManagerInterfaceDeviceWired::setConnections()
bool allOk = false;
- if (nmDBusHelper)
- delete nmDBusHelper;
- nmDBusHelper = 0;
- nmDBusHelper = new QNmDBusHelper;
+ delete nmDBusHelper;
+ nmDBusHelper = new QNmDBusHelper(this);
connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap<QString,QVariant>)),
this,SIGNAL(propertiesChanged( const QString &, QMap<QString,QVariant>)));
- if(dbusConnection.connect(NM_DBUS_SERVICE,
+ if(dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
d->path,
- NM_DBUS_INTERFACE_DEVICE_WIRED,
- "PropertiesChanged",
+ QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRED),
+ QLatin1String("PropertiesChanged"),
nmDBusHelper,SLOT(slotPropertiesChanged( QMap<QString,QVariant>))) ) {
allOk = true;
}
@@ -480,7 +459,6 @@ bool QNetworkManagerInterfaceDeviceWired::carrier() const
return d->connectionInterface->property("Carrier").toBool();
}
-/////////////
class QNetworkManagerInterfaceDeviceWirelessPrivate
{
public:
@@ -494,9 +472,9 @@ QNetworkManagerInterfaceDeviceWireless::QNetworkManagerInterfaceDeviceWireless(c
{
d = new QNetworkManagerInterfaceDeviceWirelessPrivate();
d->path = ifaceDevicePath;
- d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE,
+ d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
d->path,
- NM_DBUS_INTERFACE_DEVICE_WIRELESS,
+ QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS),
dbusConnection, parent);
if (!d->connectionInterface->isValid()) {
d->valid = false;
@@ -508,8 +486,6 @@ QNetworkManagerInterfaceDeviceWireless::QNetworkManagerInterfaceDeviceWireless(c
QNetworkManagerInterfaceDeviceWireless::~QNetworkManagerInterfaceDeviceWireless()
{
- if (nmDBusHelper)
- delete nmDBusHelper;
delete d->connectionInterface;
delete d;
}
@@ -525,10 +501,8 @@ bool QNetworkManagerInterfaceDeviceWireless::setConnections()
return false;
bool allOk = false;
- if (nmDBusHelper)
- delete nmDBusHelper;
- nmDBusHelper = 0;
- nmDBusHelper = new QNmDBusHelper;
+ delete nmDBusHelper;
+ nmDBusHelper = new QNmDBusHelper(this);
connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap<QString,QVariant>)),
this,SIGNAL(propertiesChanged( const QString &, QMap<QString,QVariant>)));
@@ -538,28 +512,28 @@ bool QNetworkManagerInterfaceDeviceWireless::setConnections()
connect(nmDBusHelper, SIGNAL(pathForAccessPointRemoved(const QString &,QDBusObjectPath)),
this,SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath)));
- if(!dbusConnection.connect(NM_DBUS_SERVICE,
+ if(!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
d->path,
- NM_DBUS_INTERFACE_DEVICE_WIRELESS,
- "AccessPointAdded",
+ QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS),
+ QLatin1String("AccessPointAdded"),
nmDBusHelper, SLOT(slotAccessPointAdded( QDBusObjectPath )))) {
allOk = true;
}
- if(!dbusConnection.connect(NM_DBUS_SERVICE,
+ if(!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
d->path,
- NM_DBUS_INTERFACE_DEVICE_WIRELESS,
- "AccessPointRemoved",
+ QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS),
+ QLatin1String("AccessPointRemoved"),
nmDBusHelper, SLOT(slotAccessPointRemoved( QDBusObjectPath )))) {
allOk = true;
}
- if(!dbusConnection.connect(NM_DBUS_SERVICE,
+ if(!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
d->path,
- NM_DBUS_INTERFACE_DEVICE_WIRELESS,
- "PropertiesChanged",
+ QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS),
+ QLatin1String("PropertiesChanged"),
nmDBusHelper,SLOT(slotPropertiesChanged( QMap<QString,QVariant>)))) {
allOk = true;
}
@@ -574,7 +548,7 @@ QDBusInterface *QNetworkManagerInterfaceDeviceWireless::connectionInterface() co
QList <QDBusObjectPath> QNetworkManagerInterfaceDeviceWireless::getAccessPoints()
{
- QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call("GetAccessPoints");
+ QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call(QLatin1String("GetAccessPoints"));
return reply.value();
}
@@ -603,7 +577,6 @@ quint32 QNetworkManagerInterfaceDeviceWireless::wirelessCapabilities() const
return d->connectionInterface->property("WirelelessCapabilities").toUInt();
}
-/////////////
class QNetworkManagerSettingsPrivate
{
public:
@@ -618,8 +591,8 @@ QNetworkManagerSettings::QNetworkManagerSettings(const QString &settingsService,
d = new QNetworkManagerSettingsPrivate();
d->path = settingsService;
d->connectionInterface = new QDBusInterface(settingsService,
- NM_DBUS_PATH_SETTINGS,
- NM_DBUS_IFACE_SETTINGS,
+ QLatin1String(NM_DBUS_PATH_SETTINGS),
+ QLatin1String(NM_DBUS_IFACE_SETTINGS),
dbusConnection);
if (!d->connectionInterface->isValid()) {
d->valid = false;
@@ -644,8 +617,8 @@ bool QNetworkManagerSettings::setConnections()
{
bool allOk = false;
- if (!dbusConnection.connect(d->path, NM_DBUS_PATH_SETTINGS,
- NM_DBUS_IFACE_SETTINGS, "NewConnection",
+ if (!dbusConnection.connect(d->path, QLatin1String(NM_DBUS_PATH_SETTINGS),
+ QLatin1String(NM_DBUS_IFACE_SETTINGS), QLatin1String("NewConnection"),
this, SIGNAL(newConnection(QDBusObjectPath)))) {
allOk = true;
}
@@ -655,7 +628,7 @@ bool QNetworkManagerSettings::setConnections()
QList <QDBusObjectPath> QNetworkManagerSettings::listConnections()
{
- QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call("ListConnections");
+ QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call(QLatin1String("ListConnections"));
return reply.value();
}
@@ -665,7 +638,6 @@ QDBusInterface *QNetworkManagerSettings::connectionInterface() const
}
-/////////////
class QNetworkManagerSettingsConnectionPrivate
{
public:
@@ -685,7 +657,7 @@ QNetworkManagerSettingsConnection::QNetworkManagerSettingsConnection(const QStri
d->service = settingsService;
d->connectionInterface = new QDBusInterface(settingsService,
d->path,
- NM_DBUS_IFACE_SETTINGS_CONNECTION,
+ QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION),
dbusConnection, parent);
if (!d->connectionInterface->isValid()) {
//qWarning() << "Could not find NetworkManagerSettingsConnection";
@@ -693,14 +665,12 @@ QNetworkManagerSettingsConnection::QNetworkManagerSettingsConnection(const QStri
return;
}
d->valid = true;
- QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call("GetSettings");
+ QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call(QLatin1String("GetSettings"));
d->settingsMap = rep.value();
}
QNetworkManagerSettingsConnection::~QNetworkManagerSettingsConnection()
{
- if (nmDBusHelper)
- delete nmDBusHelper;
delete d->connectionInterface;
delete d;
}
@@ -717,32 +687,26 @@ bool QNetworkManagerSettingsConnection::setConnections()
bool allOk = false;
if(!dbusConnection.connect(d->service, d->path,
- NM_DBUS_IFACE_SETTINGS_CONNECTION, "Updated",
+ QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), QLatin1String("Updated"),
this, SIGNAL(updated(QNmSettingsMap)))) {
allOk = true;
} else {
QDBusError error = dbusConnection.lastError();
}
- if (nmDBusHelper)
- delete nmDBusHelper;
- nmDBusHelper = 0;
- nmDBusHelper = new QNmDBusHelper;
+ delete nmDBusHelper;
+ nmDBusHelper = new QNmDBusHelper(this);
connect(nmDBusHelper, SIGNAL(pathForSettingsRemoved(const QString &)),
this,SIGNAL(removed( const QString &)));
if (!dbusConnection.connect(d->service, d->path,
- NM_DBUS_IFACE_SETTINGS_CONNECTION, "Removed",
+ QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), QLatin1String("Removed"),
nmDBusHelper, SIGNAL(slotSettingsRemoved()))) {
allOk = true;
}
return allOk;
}
-//QNetworkManagerSettingsConnection::update(QNmSettingsMap map)
-//{
-// d->connectionInterface->call("Update", QVariant::fromValue(map));
-//}
QDBusInterface *QNetworkManagerSettingsConnection::connectionInterface() const
{
@@ -751,23 +715,23 @@ QDBusInterface *QNetworkManagerSettingsConnection::connectionInterface() const
QNmSettingsMap QNetworkManagerSettingsConnection::getSettings()
{
- QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call("GetSettings");
+ QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call(QLatin1String("GetSettings"));
d->settingsMap = rep.value();
return d->settingsMap;
}
NMDeviceType QNetworkManagerSettingsConnection::getType()
{
- QNmSettingsMap::const_iterator i = d->settingsMap.find("connection");
- while (i != d->settingsMap.end() && i.key() == "connection") {
+ QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("connection"));
+ while (i != d->settingsMap.end() && i.key() == QLatin1String("connection")) {
QMap<QString,QVariant> innerMap = i.value();
- QMap<QString,QVariant>::const_iterator ii = innerMap.find("type");
- while (ii != innerMap.end() && ii.key() == "type") {
+ QMap<QString,QVariant>::const_iterator ii = innerMap.find(QLatin1String("type"));
+ while (ii != innerMap.end() && ii.key() == QLatin1String("type")) {
QString devType = ii.value().toString();
- if (devType == "802-3-ethernet") {
+ if (devType == QLatin1String("802-3-ethernet")) {
return DEVICE_TYPE_802_3_ETHERNET;
}
- if (devType == "802-11-wireless") {
+ if (devType == QLatin1String("802-11-wireless")) {
return DEVICE_TYPE_802_11_WIRELESS;
}
ii++;
@@ -779,11 +743,11 @@ NMDeviceType QNetworkManagerSettingsConnection::getType()
bool QNetworkManagerSettingsConnection::isAutoConnect()
{
- QNmSettingsMap::const_iterator i = d->settingsMap.find("connection");
- while (i != d->settingsMap.end() && i.key() == "connection") {
+ QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("connection"));
+ while (i != d->settingsMap.end() && i.key() == QLatin1String("connection")) {
QMap<QString,QVariant> innerMap = i.value();
- QMap<QString,QVariant>::const_iterator ii = innerMap.find("autoconnect");
- while (ii != innerMap.end() && ii.key() == "autoconnect") {
+ QMap<QString,QVariant>::const_iterator ii = innerMap.find(QLatin1String("autoconnect"));
+ while (ii != innerMap.end() && ii.key() == QLatin1String("autoconnect")) {
return ii.value().toBool();
ii++;
}
@@ -794,11 +758,11 @@ bool QNetworkManagerSettingsConnection::isAutoConnect()
quint64 QNetworkManagerSettingsConnection::getTimestamp()
{
- QNmSettingsMap::const_iterator i = d->settingsMap.find("connection");
- while (i != d->settingsMap.end() && i.key() == "connection") {
+ QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("connection"));
+ while (i != d->settingsMap.end() && i.key() == QLatin1String("connection")) {
QMap<QString,QVariant> innerMap = i.value();
- QMap<QString,QVariant>::const_iterator ii = innerMap.find("timestamp");
- while (ii != innerMap.end() && ii.key() == "timestamp") {
+ QMap<QString,QVariant>::const_iterator ii = innerMap.find(QLatin1String("timestamp"));
+ while (ii != innerMap.end() && ii.key() == QLatin1String("timestamp")) {
return ii.value().toUInt();
ii++;
}
@@ -809,11 +773,11 @@ quint64 QNetworkManagerSettingsConnection::getTimestamp()
QString QNetworkManagerSettingsConnection::getId()
{
- QNmSettingsMap::const_iterator i = d->settingsMap.find("connection");
- while (i != d->settingsMap.end() && i.key() == "connection") {
+ QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("connection"));
+ while (i != d->settingsMap.end() && i.key() == QLatin1String("connection")) {
QMap<QString,QVariant> innerMap = i.value();
- QMap<QString,QVariant>::const_iterator ii = innerMap.find("id");
- while (ii != innerMap.end() && ii.key() == "id") {
+ QMap<QString,QVariant>::const_iterator ii = innerMap.find(QLatin1String("id"));
+ while (ii != innerMap.end() && ii.key() == QLatin1String("id")) {
return ii.value().toString();
ii++;
}
@@ -824,11 +788,11 @@ QString QNetworkManagerSettingsConnection::getId()
QString QNetworkManagerSettingsConnection::getUuid()
{
- QNmSettingsMap::const_iterator i = d->settingsMap.find("connection");
- while (i != d->settingsMap.end() && i.key() == "connection") {
+ QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("connection"));
+ while (i != d->settingsMap.end() && i.key() == QLatin1String("connection")) {
QMap<QString,QVariant> innerMap = i.value();
- QMap<QString,QVariant>::const_iterator ii = innerMap.find("uuid");
- while (ii != innerMap.end() && ii.key() == "uuid") {
+ QMap<QString,QVariant>::const_iterator ii = innerMap.find(QLatin1String("uuid"));
+ while (ii != innerMap.end() && ii.key() == QLatin1String("uuid")) {
return ii.value().toString();
ii++;
}
@@ -840,11 +804,11 @@ QString QNetworkManagerSettingsConnection::getUuid()
QString QNetworkManagerSettingsConnection::getSsid()
{
- QNmSettingsMap::const_iterator i = d->settingsMap.find("802-11-wireless");
- while (i != d->settingsMap.end() && i.key() == "802-11-wireless") {
+ QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("802-11-wireless"));
+ while (i != d->settingsMap.end() && i.key() == QLatin1String("802-11-wireless")) {
QMap<QString,QVariant> innerMap = i.value();
- QMap<QString,QVariant>::const_iterator ii = innerMap.find("ssid");
- while (ii != innerMap.end() && ii.key() == "ssid") {
+ QMap<QString,QVariant>::const_iterator ii = innerMap.find(QLatin1String("ssid"));
+ while (ii != innerMap.end() && ii.key() == QLatin1String("ssid")) {
return ii.value().toString();
ii++;
}
@@ -856,11 +820,11 @@ QString QNetworkManagerSettingsConnection::getSsid()
QString QNetworkManagerSettingsConnection::getMacAddress()
{
if(getType() == DEVICE_TYPE_802_3_ETHERNET) {
- QNmSettingsMap::const_iterator i = d->settingsMap.find("802-3-ethernet");
- while (i != d->settingsMap.end() && i.key() == "802-3-ethernet") {
+ QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("802-3-ethernet"));
+ while (i != d->settingsMap.end() && i.key() == QLatin1String("802-3-ethernet")) {
QMap<QString,QVariant> innerMap = i.value();
- QMap<QString,QVariant>::const_iterator ii = innerMap.find("mac-address");
- while (ii != innerMap.end() && ii.key() == "mac-address") {
+ QMap<QString,QVariant>::const_iterator ii = innerMap.find(QLatin1String("mac-address"));
+ while (ii != innerMap.end() && ii.key() == QLatin1String("mac-address")) {
return ii.value().toString();
ii++;
}
@@ -869,11 +833,11 @@ QString QNetworkManagerSettingsConnection::getMacAddress()
}
else if(getType() == DEVICE_TYPE_802_11_WIRELESS) {
- QNmSettingsMap::const_iterator i = d->settingsMap.find("802-11-wireless");
- while (i != d->settingsMap.end() && i.key() == "802-11-wireless") {
+ QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("802-11-wireless"));
+ while (i != d->settingsMap.end() && i.key() == QLatin1String("802-11-wireless")) {
QMap<QString,QVariant> innerMap = i.value();
- QMap<QString,QVariant>::const_iterator ii = innerMap.find("mac-address");
- while (ii != innerMap.end() && ii.key() == "mac-address") {
+ QMap<QString,QVariant>::const_iterator ii = innerMap.find(QLatin1String("mac-address"));
+ while (ii != innerMap.end() && ii.key() == QLatin1String("mac-address")) {
return ii.value().toString();
ii++;
}
@@ -886,11 +850,11 @@ QString QNetworkManagerSettingsConnection::getMacAddress()
QStringList QNetworkManagerSettingsConnection::getSeenBssids()
{
if(getType() == DEVICE_TYPE_802_11_WIRELESS) {
- QNmSettingsMap::const_iterator i = d->settingsMap.find("802-11-wireless");
- while (i != d->settingsMap.end() && i.key() == "802-11-wireless") {
+ QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("802-11-wireless"));
+ while (i != d->settingsMap.end() && i.key() == QLatin1String("802-11-wireless")) {
QMap<QString,QVariant> innerMap = i.value();
- QMap<QString,QVariant>::const_iterator ii = innerMap.find("seen-bssids");
- while (ii != innerMap.end() && ii.key() == "seen-bssids") {
+ QMap<QString,QVariant>::const_iterator ii = innerMap.find(QLatin1String("seen-bssids"));
+ while (ii != innerMap.end() && ii.key() == QLatin1String("seen-bssids")) {
return ii.value().toStringList();
ii++;
}
@@ -900,7 +864,6 @@ QStringList QNetworkManagerSettingsConnection::getSeenBssids()
return QStringList();
}
-/////////////
class QNetworkManagerConnectionActivePrivate
{
public:
@@ -914,9 +877,9 @@ QNetworkManagerConnectionActive::QNetworkManagerConnectionActive( const QString
{
d = new QNetworkManagerConnectionActivePrivate();
d->path = activeConnectionObjectPath;
- d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE,
+ d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
d->path,
- NM_DBUS_INTERFACE_ACTIVE_CONNECTION,
+ QLatin1String(NM_DBUS_INTERFACE_ACTIVE_CONNECTION),
dbusConnection, parent);
if (!d->connectionInterface->isValid()) {
d->valid = false;
@@ -928,8 +891,6 @@ QNetworkManagerConnectionActive::QNetworkManagerConnectionActive( const QString
QNetworkManagerConnectionActive::~QNetworkManagerConnectionActive()
{
- if (nmDBusHelper)
- delete nmDBusHelper;
delete d->connectionInterface;
delete d;
}
@@ -945,16 +906,14 @@ bool QNetworkManagerConnectionActive::setConnections()
return false;
bool allOk = false;
- if (nmDBusHelper)
- delete nmDBusHelper;
- nmDBusHelper = 0;
- nmDBusHelper = new QNmDBusHelper;
+ delete nmDBusHelper;
+ nmDBusHelper = new QNmDBusHelper(this);
connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap<QString,QVariant>)),
this,SIGNAL(propertiesChanged( const QString &, QMap<QString,QVariant>)));
- if(dbusConnection.connect(NM_DBUS_SERVICE,
+ if(dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),
d->path,
- NM_DBUS_INTERFACE_ACTIVE_CONNECTION,
- "PropertiesChanged",
+ QLatin1String(NM_DBUS_INTERFACE_ACTIVE_CONNECTION),
+ QLatin1String("PropertiesChanged"),
nmDBusHelper,SLOT(slotPropertiesChanged( QMap<QString,QVariant>))) ) {
allOk = true;
}
@@ -1000,8 +959,6 @@ bool QNetworkManagerConnectionActive::defaultRoute() const
return d->connectionInterface->property("Default").toBool();
}
-
-////
class QNetworkManagerIp4ConfigPrivate
{
public:
@@ -1015,9 +972,9 @@ QNetworkManagerIp4Config::QNetworkManagerIp4Config( const QString &deviceObjectP
{
d = new QNetworkManagerIp4ConfigPrivate();
d->path = deviceObjectPath;
- d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE,
+ d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE),
d->path,
- NM_DBUS_INTERFACE_IP4_CONFIG,
+ QLatin1String(NM_DBUS_INTERFACE_IP4_CONFIG),
dbusConnection, parent);
if (!d->connectionInterface->isValid()) {
d->valid = false;
diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h
index 81903ec..048f628 100644
--- a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h
+++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h
@@ -53,26 +53,87 @@
// We mean it.
//
-#include <NetworkManager/NetworkManager.h>
-#include <QtDBus>
-#include <QDBusConnection>
-#include <QDBusError>
-#include <QDBusInterface>
-#include <QDBusMessage>
-#include <QDBusReply>
+#include <QtDBus/QtDBus>
+#include <QtDBus/QDBusConnection>
+#include <QtDBus/QDBusError>
+#include <QtDBus/QDBusInterface>
+#include <QtDBus/QDBusMessage>
+#include <QtDBus/QDBusReply>
#include <QNetworkInterface>
-#include <QDBusPendingCallWatcher>
+#include <QtDBus/QDBusPendingCallWatcher>
+#include <QtDBus/QDBusObjectPath>
+#include <QtDBus/QDBusContext>
+#include <QMap>
#include "qnmdbushelper.h"
+#ifndef NETWORK_MANAGER_H
+typedef enum NMDeviceType
+{
+ DEVICE_TYPE_UNKNOWN = 0,
+ DEVICE_TYPE_802_3_ETHERNET,
+ DEVICE_TYPE_802_11_WIRELESS,
+ DEVICE_TYPE_GSM,
+ DEVICE_TYPE_CDMA
+} NMDeviceType;
+
+typedef enum
+{
+ NM_DEVICE_STATE_UNKNOWN = 0,
+ NM_DEVICE_STATE_UNMANAGED,
+ NM_DEVICE_STATE_UNAVAILABLE,
+ NM_DEVICE_STATE_DISCONNECTED,
+ NM_DEVICE_STATE_PREPARE,
+ NM_DEVICE_STATE_CONFIG,
+ NM_DEVICE_STATE_NEED_AUTH,
+ NM_DEVICE_STATE_IP_CONFIG,
+ NM_DEVICE_STATE_ACTIVATED,
+ NM_DEVICE_STATE_FAILED
+} NMDeviceState;
+
+typedef enum
+{
+ NM_ACTIVE_CONNECTION_STATE_UNKNOWN = 0,
+ NM_ACTIVE_CONNECTION_STATE_ACTIVATING,
+ NM_ACTIVE_CONNECTION_STATE_ACTIVATED
+} NMActiveConnectionState;
+
+#define NM_DBUS_SERVICE "org.freedesktop.NetworkManager"
+
+#define NM_DBUS_PATH "/org/freedesktop/NetworkManager"
+#define NM_DBUS_INTERFACE "org.freedesktop.NetworkManager"
+#define NM_DBUS_INTERFACE_DEVICE NM_DBUS_INTERFACE ".Device"
+#define NM_DBUS_INTERFACE_DEVICE_WIRED NM_DBUS_INTERFACE_DEVICE ".Wired"
+#define NM_DBUS_INTERFACE_DEVICE_WIRELESS NM_DBUS_INTERFACE_DEVICE ".Wireless"
+#define NM_DBUS_PATH_ACCESS_POINT NM_DBUS_PATH "/AccessPoint"
+#define NM_DBUS_INTERFACE_ACCESS_POINT NM_DBUS_INTERFACE ".AccessPoint"
+
+#define NM_DBUS_PATH_SETTINGS "/org/freedesktop/NetworkManagerSettings"
+
+#define NM_DBUS_IFACE_SETTINGS_CONNECTION "org.freedesktop.NetworkManagerSettings.Connection"
+#define NM_DBUS_IFACE_SETTINGS "org.freedesktop.NetworkManagerSettings"
+#define NM_DBUS_INTERFACE_ACTIVE_CONNECTION NM_DBUS_INTERFACE ".Connection.Active"
+#define NM_DBUS_INTERFACE_IP4_CONFIG NM_DBUS_INTERFACE ".IP4Config"
+
+#define NM_DBUS_SERVICE_USER_SETTINGS "org.freedesktop.NetworkManagerUserSettings"
+#define NM_DBUS_SERVICE_SYSTEM_SETTINGS "org.freedesktop.NetworkManagerSystemSettings"
+
+#define NM_802_11_AP_FLAGS_NONE 0x00000000
+#define NM_802_11_AP_FLAGS_PRIVACY 0x00000001
+#endif
+
QT_BEGIN_NAMESPACE
typedef QMap< QString, QMap<QString,QVariant> > QNmSettingsMap;
typedef QList<quint32> ServerThing;
-Q_DECLARE_METATYPE(QNmSettingsMap)
-Q_DECLARE_METATYPE(ServerThing)
+QT_END_NAMESPACE
+
+Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE(QNmSettingsMap))
+Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE(ServerThing))
+
+QT_BEGIN_NAMESPACE
class QNetworkManagerInterfacePrivate;
class QNetworkManagerInterface : public QObject
@@ -107,12 +168,10 @@ Q_SIGNALS:
private Q_SLOTS:
private:
-// Q_DISABLE_COPY(QNetworkManagerInterface); ??
QNetworkManagerInterfacePrivate *d;
QNmDBusHelper *nmDBusHelper;
-}; //end QNetworkManagerInterface
+};
-////////
class QNetworkManagerInterfaceAccessPointPrivate;
class QNetworkManagerInterfaceAccessPoint : public QObject
{
@@ -120,7 +179,6 @@ class QNetworkManagerInterfaceAccessPoint : public QObject
public:
- // NM_DEVICE_STATE
enum DeviceState {
Unknown = 0,
Unmanaged,
@@ -181,9 +239,8 @@ private:
QNetworkManagerInterfaceAccessPointPrivate *d;
QNmDBusHelper *nmDBusHelper;
-}; //end QNetworkManagerInterfaceAccessPoint
+};
-////////
class QNetworkManagerInterfaceDevicePrivate;
class QNetworkManagerInterfaceDevice : public QObject
{
@@ -195,7 +252,7 @@ public:
~QNetworkManagerInterfaceDevice();
QString udi() const;
- QNetworkInterface interface() const;
+ QNetworkInterface networkInterface() const;
QDBusInterface *connectionInterface() const;
quint32 ip4Address() const;
quint32 state() const;
@@ -211,9 +268,8 @@ Q_SIGNALS:
private:
QNetworkManagerInterfaceDevicePrivate *d;
QNmDBusHelper *nmDBusHelper;
-}; //end QNetworkManagerInterfaceDevice
+};
-////////
class QNetworkManagerInterfaceDeviceWiredPrivate;
class QNetworkManagerInterfaceDeviceWired : public QObject
{
@@ -236,9 +292,8 @@ Q_SIGNALS:
private:
QNetworkManagerInterfaceDeviceWiredPrivate *d;
QNmDBusHelper *nmDBusHelper;
-}; // end QNetworkManagerInterfaceDeviceWired
+};
-////
class QNetworkManagerInterfaceDeviceWirelessPrivate;
class QNetworkManagerInterfaceDeviceWireless : public QObject
{
@@ -278,9 +333,8 @@ Q_SIGNALS:
private:
QNetworkManagerInterfaceDeviceWirelessPrivate *d;
QNmDBusHelper *nmDBusHelper;
-}; // end QNetworkManagerInterfaceDeviceWireless
+};
-////
class QNetworkManagerSettingsPrivate;
class QNetworkManagerSettings : public QObject
{
@@ -300,9 +354,8 @@ Q_SIGNALS:
void newConnection(QDBusObjectPath);
private:
QNetworkManagerSettingsPrivate *d;
-}; //end QNetworkManagerSettings
+};
-////
class QNetworkManagerSettingsConnectionPrivate;
class QNetworkManagerSettingsConnection : public QObject
{
@@ -315,7 +368,6 @@ public:
QDBusInterface *connectionInterface() const;
QNmSettingsMap getSettings();
- // void update(QNmSettingsMap map);
bool setConnections();
NMDeviceType getType();
bool isAutoConnect();
@@ -335,9 +387,8 @@ Q_SIGNALS:
private:
QNmDBusHelper *nmDBusHelper;
QNetworkManagerSettingsConnectionPrivate *d;
-}; //end QNetworkManagerSettingsConnection
+};
-////
class QNetworkManagerConnectionActivePrivate;
class QNetworkManagerConnectionActive : public QObject
{
@@ -371,9 +422,8 @@ Q_SIGNALS:
private:
QNetworkManagerConnectionActivePrivate *d;
QNmDBusHelper *nmDBusHelper;
-}; //QNetworkManagerConnectionActive
+};
-////
class QNetworkManagerIp4ConfigPrivate;
class QNetworkManagerIp4Config : public QObject
{
@@ -383,14 +433,12 @@ public:
QNetworkManagerIp4Config(const QString &dbusPathName, QObject *parent = 0);
~QNetworkManagerIp4Config();
- // QList<quint32> nameservers();
QStringList domains() const;
bool isValid();
private:
QNetworkManagerIp4ConfigPrivate *d;
};
-////
QT_END_NAMESPACE
diff --git a/src/plugins/bearer/networkmanager/qnmdbushelper.cpp b/src/plugins/bearer/networkmanager/qnmdbushelper.cpp
index d5e20f3..e195eeb 100644
--- a/src/plugins/bearer/networkmanager/qnmdbushelper.cpp
+++ b/src/plugins/bearer/networkmanager/qnmdbushelper.cpp
@@ -43,7 +43,7 @@
#include "qnmdbushelper.h"
-#include <NetworkManager/NetworkManager.h>
+#include "qnetworkmanagerservice.h"
#include <QDBusError>
#include <QDBusInterface>
@@ -54,6 +54,15 @@
QT_BEGIN_NAMESPACE
+QNmDBusHelper::QNmDBusHelper(QObject * parent)
+ : QObject(parent)
+{
+}
+
+QNmDBusHelper::~QNmDBusHelper()
+{
+}
+
void QNmDBusHelper::deviceStateChanged(quint32 state)
{
QDBusMessage msg = this->message();
diff --git a/src/plugins/bearer/networkmanager/qnmdbushelper.h b/src/plugins/bearer/networkmanager/qnmdbushelper.h
index 862290c..933d55a 100644
--- a/src/plugins/bearer/networkmanager/qnmdbushelper.h
+++ b/src/plugins/bearer/networkmanager/qnmdbushelper.h
@@ -52,6 +52,8 @@ class QNmDBusHelper: public QObject, protected QDBusContext
{
Q_OBJECT
public:
+ QNmDBusHelper(QObject *parent = 0);
+ ~QNmDBusHelper();
public slots:
void deviceStateChanged(quint32);
diff --git a/src/plugins/bearer/qnetworksession_impl.cpp b/src/plugins/bearer/qnetworksession_impl.cpp
index f41fdba..5f03893 100644
--- a/src/plugins/bearer/qnetworksession_impl.cpp
+++ b/src/plugins/bearer/qnetworksession_impl.cpp
@@ -147,6 +147,8 @@ void QNetworkSessionPrivateImpl::open()
if ((activeConfig.state() & QNetworkConfiguration::Discovered) !=
QNetworkConfiguration::Discovered) {
lastError =QNetworkSession::InvalidConfigurationError;
+ state = QNetworkSession::Invalid;
+ emit stateChanged(state);
emit QNetworkSessionPrivate::error(lastError);
return;
}
@@ -400,7 +402,6 @@ void QNetworkSessionPrivateImpl::connectionError(const QString &id,
lastError = QNetworkSession::UnknownSessionError;
}
- emit quitPendingWaitsForOpened();
emit QNetworkSessionPrivate::error(lastError);
}
}
diff --git a/src/plugins/bearer/symbian/qnetworksession_impl.cpp b/src/plugins/bearer/symbian/qnetworksession_impl.cpp
index 9af1fe9..bec562d 100644
--- a/src/plugins/bearer/symbian/qnetworksession_impl.cpp
+++ b/src/plugins/bearer/symbian/qnetworksession_impl.cpp
@@ -141,7 +141,10 @@ void QNetworkSessionPrivateImpl::syncStateWithInterface()
if (state != QNetworkSession::Connected) {
// There were no open connections to used IAP or SNAP
- if ((privateConfiguration(publicConfig)->state & QNetworkConfiguration::Discovered) ==
+ if (iError == QNetworkSession::InvalidConfigurationError) {
+ newState(QNetworkSession::Invalid);
+ }
+ else if ((privateConfiguration(publicConfig)->state & QNetworkConfiguration::Discovered) ==
QNetworkConfiguration::Discovered) {
newState(QNetworkSession::Disconnected);
} else {
@@ -231,13 +234,23 @@ QNetworkSession::SessionError QNetworkSessionPrivateImpl::error() const
void QNetworkSessionPrivateImpl::open()
{
- if (isOpen || !privateConfiguration(publicConfig) || (state == QNetworkSession::Connecting)) {
+ if (isOpen || (state == QNetworkSession::Connecting)) {
return;
}
// Cancel notifications from RConnectionMonitor
// => RConnection::ProgressNotification will be used for IAP/SNAP monitoring
iConnectionMonitor.CancelNotifications();
+
+ // Configuration must be at least in Discovered - state for connecting purposes.
+ if ((publicConfig.state() & QNetworkConfiguration::Discovered) !=
+ QNetworkConfiguration::Discovered) {
+ newState(QNetworkSession::Invalid);
+ iError = QNetworkSession::InvalidConfigurationError;
+ emit QNetworkSessionPrivate::error(iError);
+ syncStateWithInterface();
+ return;
+ }
TInt error = iSocketServ.Connect();
if (error != KErrNone) {
diff --git a/src/plugins/bearer/symbian/symbianengine.cpp b/src/plugins/bearer/symbian/symbianengine.cpp
index b3c9cb3..88a563c 100644
--- a/src/plugins/bearer/symbian/symbianengine.cpp
+++ b/src/plugins/bearer/symbian/symbianengine.cpp
@@ -98,7 +98,7 @@ QString SymbianNetworkConfigurationPrivate::bearerName() const
}
SymbianEngine::SymbianEngine(QObject *parent)
-: QBearerEngine(parent), CActive(CActive::EPriorityIdle), iInitOk(true)
+: QBearerEngine(parent), CActive(CActive::EPriorityIdle), iFirstUpdate(true), iInitOk(true)
{
CActiveScheduler::Add(this);
@@ -136,9 +136,12 @@ SymbianEngine::SymbianEngine(QObject *parent)
updateConfigurations();
updateStatesToSnaps();
+
+ updateAvailableAccessPoints(); // On first time updates synchronously (without WLAN scans)
// Start monitoring IAP and/or SNAP changes in Symbian CommsDB
startCommsDatabaseNotifications();
+ iFirstUpdate = false;
}
SymbianEngine::~SymbianEngine()
@@ -153,7 +156,14 @@ SymbianEngine::~SymbianEngine()
#endif
delete ipAccessPointsAvailabilityScanner;
+
+ // CCommsDatabase destructor uses cleanup stack. Since QNetworkConfigurationManager
+ // is a global static, but the time we are here, E32Main() has been exited already and
+ // the thread's default cleanup stack has been deleted. Without this line, a
+ // 'E32USER-CBase 69' -panic will occur.
+ CTrapCleanup* cleanup = CTrapCleanup::New();
delete ipCommsDB;
+ delete cleanup;
}
bool SymbianEngine::hasIdentifier(const QString &id)
@@ -692,9 +702,10 @@ void SymbianEngine::accessPointScanningReady(TBool scanSuccessful, TConnMonIapIn
updateStatesToSnaps();
- startCommsDatabaseNotifications();
-
- emit updateCompleted();
+ if (!iFirstUpdate) {
+ startCommsDatabaseNotifications();
+ emit updateCompleted();
+ }
}
void SymbianEngine::updateStatesToSnaps()
@@ -987,11 +998,22 @@ void AccessPointsAvailabilityScanner::DoCancel()
void AccessPointsAvailabilityScanner::StartScanning()
{
- iConnectionMonitor.GetPckgAttribute(EBearerIdAll, 0, KIapAvailability, iIapBuf, iStatus);
- if (!IsActive()) {
- SetActive();
+ if (iOwner.iFirstUpdate) {
+ // On first update (the mgr is being instantiated) update only those bearers who
+ // don't need time-consuming scans (WLAN).
+ // Note: EBearerIdWCDMA covers also GPRS bearer
+ iConnectionMonitor.GetPckgAttribute(EBearerIdWCDMA, 0, KIapAvailability, iIapBuf, iStatus);
+ User::WaitForRequest(iStatus);
+ if (iStatus.Int() == KErrNone) {
+ iOwner.accessPointScanningReady(true,iIapBuf());
+ }
+ } else {
+ iConnectionMonitor.GetPckgAttribute(EBearerIdAll, 0, KIapAvailability, iIapBuf, iStatus);
+ if (!IsActive()) {
+ SetActive();
+ }
}
-}
+}
void AccessPointsAvailabilityScanner::RunL()
{
diff --git a/src/plugins/bearer/symbian/symbianengine.h b/src/plugins/bearer/symbian/symbianengine.h
index 5448813..ee6d070 100644
--- a/src/plugins/bearer/symbian/symbianengine.h
+++ b/src/plugins/bearer/symbian/symbianengine.h
@@ -162,6 +162,7 @@ private: // MConnectionMonitorObserver
void EventL(const CConnMonEventBase& aEvent);
private: // Data
+ bool iFirstUpdate;
CCommsDatabase* ipCommsDB;
RConnectionMonitor iConnectionMonitor;
diff --git a/tests/auto/qbearertestcommon.h b/tests/auto/qbearertestcommon.h
index 0bfe622..c9df249 100644
--- a/tests/auto/qbearertestcommon.h
+++ b/tests/auto/qbearertestcommon.h
@@ -42,6 +42,19 @@
#ifndef QBEARERTESTCOMMON_H
#define QBEARERTESTCOMMON_H
+// Wait for __expr to happen, while still allowing events to be processed.
+#define QTRY_NOOP(__expr) \
+ do { \
+ const int __step = 50; \
+ const int __timeout = 15000; \
+ if (!(__expr)) { \
+ QTest::qWait(0); \
+ } \
+ for (int __i = 0; __i < __timeout && !(__expr); __i+=__step) { \
+ QTest::qWait(__step); \
+ } \
+ } while(0)
+
// Will try to wait for the condition while allowing event processing
#define QTRY_VERIFY(__expr) \
do { \
diff --git a/tests/auto/qnetworksession/lackey/main.cpp b/tests/auto/qnetworksession/lackey/main.cpp
index 41e935a..66d6dd4 100644
--- a/tests/auto/qnetworksession/lackey/main.cpp
+++ b/tests/auto/qnetworksession/lackey/main.cpp
@@ -69,14 +69,15 @@ int main(int argc, char** argv)
QNetworkConfigurationManager manager;
QList<QNetworkConfiguration> discovered =
-#if defined (Q_OS_SYMBIAN)
- // On Symbian, on the first query (before updateConfigurations() call
- // the discovered-states are not correct, so defined-state will do.
- manager.allConfigurations(QNetworkConfiguration::Defined);
-#else
manager.allConfigurations(QNetworkConfiguration::Discovered);
-#endif
+
+ foreach(QNetworkConfiguration config, discovered) {
+ qDebug() << "Lackey: Name of the config enumerated: " << config.name();
+ qDebug() << "Lackey: State of the config enumerated: " << config.state();
+ }
+
if (discovered.isEmpty()) {
+ qDebug("Lackey: no discovered configurations, returning empty error.");
return NO_DISCOVERED_CONFIGURATIONS_ERROR;
}
diff --git a/tests/auto/qnetworksession/test/tst_qnetworksession.cpp b/tests/auto/qnetworksession/test/tst_qnetworksession.cpp
index 4ef3a4f..58b1a48 100644
--- a/tests/auto/qnetworksession/test/tst_qnetworksession.cpp
+++ b/tests/auto/qnetworksession/test/tst_qnetworksession.cpp
@@ -54,6 +54,7 @@
QT_USE_NAMESPACE
Q_DECLARE_METATYPE(QNetworkConfiguration)
+Q_DECLARE_METATYPE(QNetworkConfiguration::Type);
Q_DECLARE_METATYPE(QNetworkSession::State);
Q_DECLARE_METATYPE(QNetworkSession::SessionError);
@@ -70,6 +71,11 @@ private slots:
void outOfProcessSession();
void invalidSession();
+ void repeatedOpenClose_data();
+ void repeatedOpenClose();
+
+ void roamingErrorCodes();
+
void sessionProperties_data();
void sessionProperties();
@@ -94,11 +100,17 @@ private:
#endif
};
+// Helper functions
+bool openSession(QNetworkSession *session);
+bool closeSession(QNetworkSession *session, bool lastSessionOnConfiguration = true);
+QNetworkConfiguration suitableConfiguration(QString bearerType, QNetworkConfiguration::Type configType);
+
void tst_QNetworkSession::initTestCase()
{
qRegisterMetaType<QNetworkSession::State>("QNetworkSession::State");
qRegisterMetaType<QNetworkSession::SessionError>("QNetworkSession::SessionError");
qRegisterMetaType<QNetworkConfiguration>("QNetworkConfiguration");
+ qRegisterMetaType<QNetworkConfiguration::Type>("QNetworkConfiguration::Type");
#ifdef Q_WS_MAEMO_6
iapconf = new Maemo::IAPConf("007");
@@ -211,9 +223,42 @@ void tst_QNetworkSession::cleanupTestCase()
void tst_QNetworkSession::invalidSession()
{
+ // Verify that session created with invalid configuration remains in invalid state
QNetworkSession session(QNetworkConfiguration(), 0);
QVERIFY(!session.isOpen());
QVERIFY(session.state() == QNetworkSession::Invalid);
+ QVERIFY(session.error() == QNetworkSession::InvalidConfigurationError);
+
+ // Verify that opening session with invalid configuration both 1) emits invalidconfigurationerror
+ // and 2) sets session's state as invalid.
+ QSignalSpy errorSpy(&session, SIGNAL(error(QNetworkSession::SessionError)));
+ session.open();
+ session.waitForOpened(1000); // Should bail out right away
+ QVERIFY(errorSpy.count() == 1);
+ QNetworkSession::SessionError error =
+ qvariant_cast<QNetworkSession::SessionError> (errorSpy.first().at(0));
+ QVERIFY(error == QNetworkSession::InvalidConfigurationError);
+ QVERIFY(session.error() == QNetworkSession::InvalidConfigurationError);
+ QVERIFY(session.state() == QNetworkSession::Invalid);
+
+ // Check same thing with a config from platform (there are subtle differences
+ // because emtpy configuration does not have private pointer). Test with config
+ // in '(un)defined' state
+ QList<QNetworkConfiguration> allConfigs = manager.allConfigurations();
+ foreach(QNetworkConfiguration config, allConfigs) {
+ if ((config.state() & QNetworkConfiguration::Discovered) != QNetworkConfiguration::Discovered) {
+ QNetworkSession session2(config);
+ QSignalSpy errorSpy2(&session2, SIGNAL(error(QNetworkSession::SessionError)));
+ session2.open();
+ session2.waitForOpened(1000); // Should bail out right away
+ QVERIFY(errorSpy2.count() == 1);
+ QNetworkSession::SessionError error2 =
+ qvariant_cast<QNetworkSession::SessionError> (errorSpy2.first().at(0));
+ QVERIFY(error2 == QNetworkSession::InvalidConfigurationError);
+ QVERIFY(session2.state() == QNetworkSession::Invalid);
+ break; // Once is enough
+ }
+ }
}
void tst_QNetworkSession::sessionProperties_data()
@@ -300,6 +345,100 @@ void tst_QNetworkSession::sessionProperties()
}
}
+void tst_QNetworkSession::repeatedOpenClose_data() {
+ QTest::addColumn<QString>("bearerType");
+ QTest::addColumn<QNetworkConfiguration::Type>("configurationType");
+ QTest::addColumn<int>("repeatTimes");
+
+ QTest::newRow("WLAN_IAP") << "WLAN" << QNetworkConfiguration::InternetAccessPoint << 3;
+ // QTest::newRow("Cellular_IAP") << "cellular" << QNetworkConfiguration::InternetAccessPoint << 3;
+ // QTest::newRow("SNAP") << "bearer_type_not_relevant_with_SNAPs" << QNetworkConfiguration::ServiceNetwork << 3;
+}
+
+// Tests repeated-open close.
+void tst_QNetworkSession::repeatedOpenClose() {
+ QFETCH(QString, bearerType);
+ QFETCH(QNetworkConfiguration::Type, configurationType);
+ QFETCH(int, repeatTimes);
+
+ // First check that opening once succeeds and determine if repeatable testing is doable
+ QNetworkConfiguration config = suitableConfiguration(bearerType, configurationType);
+ if (!config.isValid()) {
+ QSKIP("No suitable configurations, skipping this round of repeated open-close test.", SkipSingle);
+ }
+ qDebug() << "Using following configuratio to repeatedly open and close: " << config.name();
+ QNetworkSession permanentSession(config);
+ if (!openSession(&permanentSession) ||
+ !closeSession(&permanentSession)) {
+ QSKIP("Unable to open/close session, skipping this round of repeated open-close test.", SkipSingle);
+ }
+ for (int i = repeatTimes; i > 0; i--) {
+ QVERIFY(openSession(&permanentSession));
+ QVERIFY(closeSession(&permanentSession));
+ }
+}
+
+void tst_QNetworkSession::roamingErrorCodes() {
+
+#ifndef Q_OS_SYMBIAN
+ QSKIP("Roaming supported on Symbian.", SkipAll);
+#else
+ QNetworkConfiguration wlanIapConfig = suitableConfiguration("WLAN", QNetworkConfiguration::InternetAccessPoint);
+ if (!wlanIapConfig.isValid()) {
+ QSKIP("No WLAN IAP accessible, skipping test.", SkipAll);
+ }
+ // Check that opening and closing two sessions on same config work gracefully:
+ QNetworkSession iapSession(wlanIapConfig);
+ QVERIFY(openSession(&iapSession));
+ QNetworkSession adminIapSession(wlanIapConfig);
+ QVERIFY(openSession(&adminIapSession));
+ QVERIFY(closeSession(&iapSession, false)); // false == not a last session based on the configuration
+ QVERIFY(closeSession(&adminIapSession));
+
+ // Open configurations again, force close bearer and check that errors are emitted correctly
+ // on the other session
+ QVERIFY(openSession(&iapSession));
+ QVERIFY(openSession(&adminIapSession));
+ QSignalSpy errorSpy(&iapSession, SIGNAL(error(QNetworkSession::SessionError)));
+ adminIapSession.stop(); // requires NetworkControl capabilities
+ QTRY_VERIFY(!errorSpy.isEmpty()); // wait for error signals
+ QNetworkSession::SessionError error = qvariant_cast<QNetworkSession::SessionError>(errorSpy.first().at(0));
+ QVERIFY(error == QNetworkSession::SessionAbortedError);
+ QVERIFY(iapSession.state() == QNetworkSession::Disconnected);
+ QVERIFY(adminIapSession.state() == QNetworkSession::Disconnected);
+#endif // Q_OS_SYMBIAN
+ /*
+ // Check for roaming error. Challenging to automate, therefore commented out.
+ // Case requires that you have controllable WLAN in Internet SNAP (only).
+ QNetworkConfiguration snapConfig = suitableConfiguration("bearer_not_relevant_with_snaps", QNetworkConfiguration::ServiceNetwork);
+ if (!snapConfig.isValid()) {
+ QSKIP("No SNAP accessible, skipping test.", SkipAll);
+ }
+ QNetworkSession snapSession(snapConfig);
+ QVERIFY(openSession(&snapSession));
+ QSignalSpy errorSpySnap(&snapSession, SIGNAL(error(QNetworkSession::SessionError)));
+ qDebug("Disconnect the WLAN now");
+ QTRY_VERIFY(!errorSpySnap.isEmpty()); // wait for error signals
+ QVERIFY(errorSpySnap.count() == 1);
+ error = qvariant_cast<QNetworkSession::SessionError>(errorSpySnap.first().at(0));
+ qDebug() << "Error received when turning off wlan on SNAP: " << error;
+ QVERIFY(error == QNetworkSession::RoamingError);
+
+ qDebug("Connect the WLAN now");
+ QTest::qWait(60000); // Wait for WLAN to get up
+ QNetworkConfiguration wlanIapConfig2 = suitableConfiguration("WLAN", QNetworkConfiguration::InternetAccessPoint);
+ QNetworkSession iapSession2(wlanIapConfig2);
+ QVERIFY(openSession(&iapSession2));
+ QSignalSpy errorSpy2(&iapSession2, SIGNAL(error(QNetworkSession::SessionError)));
+ qDebug("Disconnect the WLAN now");
+ QTRY_VERIFY(!errorSpy2.isEmpty()); // wait for error signals
+ QVERIFY(errorSpy2.count() == 1);
+ error = qvariant_cast<QNetworkSession::SessionError>(errorSpy2.first().at(0));
+ QVERIFY(error == QNetworkSession::SessionAbortedError);
+ QVERIFY(iapSession2.state() == QNetworkSession::Disconnected);
+ */
+}
+
void tst_QNetworkSession::userChoiceSession_data()
{
QTest::addColumn<QNetworkConfiguration>("configuration");
@@ -810,7 +949,7 @@ QDebug operator<<(QDebug debug, const QList<QNetworkConfiguration> &list)
}
// Note: outOfProcessSession requires that at least one configuration is
-// at Discovered -state (Defined is ok for symbian as well, as long as it is possible to open).
+// at Discovered -state.
void tst_QNetworkSession::outOfProcessSession()
{
qDebug() << "START";
@@ -913,6 +1052,158 @@ void tst_QNetworkSession::outOfProcessSession()
qDebug("STOP");
}
+// A convinience / helper function for testcases. Return the first matching configuration.
+// Ignores configurations in other than 'discovered' -state. Returns invalid (QNetworkConfiguration())
+// if none found.
+QNetworkConfiguration suitableConfiguration(QString bearerType, QNetworkConfiguration::Type configType) {
+ // Refresh configurations and derive configurations matching given parameters.
+ QNetworkConfigurationManager mgr;
+ QSignalSpy updateSpy(&mgr, SIGNAL(updateCompleted()));
+ mgr.updateConfigurations();
+ QTRY_NOOP(updateSpy.count() == 1);
+ if (updateSpy.count() != 1) {
+ qDebug("tst_QNetworkSession::suitableConfiguration() failure: unable to update configurations");
+ return QNetworkConfiguration();
+ }
+ QList<QNetworkConfiguration> discoveredConfigs = mgr.allConfigurations(QNetworkConfiguration::Discovered);
+ foreach(QNetworkConfiguration config, discoveredConfigs) {
+ if ((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) {
+ // qDebug() << "Dumping config because is active: " << config.name();
+ discoveredConfigs.removeOne(config);
+ } else if (config.type() != configType) {
+ // qDebug() << "Dumping config because type (IAP/SNAP) mismatches: " << config.name();
+ discoveredConfigs.removeOne(config);
+ } else if ((config.type() == QNetworkConfiguration::InternetAccessPoint) &&
+ bearerType == "cellular") { // 'cellular' bearertype is for convinience
+ if (config.bearerName() != "2G" &&
+ config.bearerName() != "CDMA2000" &&
+ config.bearerName() != "WCDMA" &&
+ config.bearerName() != "HSPA") {
+ // qDebug() << "Dumping config because bearer mismatches (cellular): " << config.name();
+ discoveredConfigs.removeOne(config);
+ }
+ } else if ((config.type() == QNetworkConfiguration::InternetAccessPoint) &&
+ bearerType != config.bearerName()) {
+ // qDebug() << "Dumping config because bearer mismatches (WLAN): " << config.name();
+ discoveredConfigs.removeOne(config);
+ }
+ }
+ if (discoveredConfigs.isEmpty()) {
+ qDebug("tst_QNetworkSession::suitableConfiguration() failure: no suitable configurations present.");
+ return QNetworkConfiguration();
+ } else {
+ return discoveredConfigs.first();
+ }
+}
+
+// A convinience function for test-cases: opens the given configuration and return
+// true if it was done gracefully.
+bool openSession(QNetworkSession *session) {
+ QNetworkConfigurationManager mgr;
+ QSignalSpy openedSpy(session, SIGNAL(opened()));
+ QSignalSpy stateChangeSpy(session, SIGNAL(stateChanged(QNetworkSession::State)));
+ QSignalSpy errorSpy(session, SIGNAL(error(QNetworkSession::SessionError)));
+ QSignalSpy configChangeSpy(&mgr, SIGNAL(configurationChanged(QNetworkConfiguration)));
+ // Store some initial statuses, because expected signals differ if the config is already
+ // active by some other session
+ QNetworkConfiguration::StateFlags configInitState = session->configuration().state();
+ QNetworkSession::State sessionInitState = session->state();
+
+ if (session->isOpen() ||
+ !session->sessionProperty("ActiveConfiguration").toString().isEmpty()) {
+ qDebug("tst_QNetworkSession::openSession() failure: session was already open / active.");
+ return false;
+ } else {
+ session->open();
+ session->waitForOpened(120000); // Bringing interfaces up and down may take time at platform
+ }
+ // Check that connection opening went by the book. Add checks here if more strictness needed.
+ if (!session->isOpen()) {
+ qDebug("tst_QNetworkSession::openSession() failure: QNetworkSession::open() failed.");
+ return false;
+ }
+ if (openedSpy.count() != 1) {
+ qDebug("tst_QNetworkSession::openSession() failure: QNetworkSession::opened() - signal not received.");
+ return false;
+ }
+ if (!errorSpy.isEmpty()) {
+ qDebug("tst_QNetworkSession::openSession() failure: QNetworkSession::error() - signal was detected.");
+ return false;
+ }
+ if (sessionInitState != QNetworkSession::Connected &&
+ stateChangeSpy.isEmpty()) {
+ qDebug("tst_QNetworkSession::openSession() failure: QNetworkSession::stateChanged() - signals not detected.");
+ return false;
+ }
+ if (configInitState != QNetworkConfiguration::Active &&
+ configChangeSpy.isEmpty()) {
+ qDebug("tst_QNetworkSession::openSession() failure: QNetworkConfigurationManager::configurationChanged() - signals not detected.");
+ return false;
+ }
+ if (session->configuration().state() != QNetworkConfiguration::Active) {
+ qDebug("tst_QNetworkSession::openSession() failure: session's configuration is not in 'Active' -state.");
+ return false;
+ }
+ return true;
+}
+
+// Helper function for closing opened session. Performs checks that
+// session is closed gradefully (e.g. signals). Function does not delete
+// the session. The lastSessionOnConfiguration (true by default) is used to
+// tell if there are more sessions open, basing on same configration. This
+// impacts the checks made.
+bool closeSession(QNetworkSession *session, bool lastSessionOnConfiguration) {
+ if (!session) {
+ qDebug("tst_QNetworkSession::closeSession() failure: NULL session given");
+ return false;
+ }
+ if (session->state() != QNetworkSession::Connected ||
+ !session->isOpen()) {
+ qDebug("tst_QNetworkSession::closeSession() failure: session is not opened.");
+ return false;
+ }
+ QNetworkConfigurationManager mgr;
+ QSignalSpy sessionClosedSpy(session, SIGNAL(closed()));
+ QSignalSpy sessionStateChangedSpy(session, SIGNAL(stateChanged(QNetworkSession::State)));
+ QSignalSpy sessionErrorSpy(session, SIGNAL(error(QNetworkSession::SessionError)));
+ QSignalSpy configChangeSpy(&mgr, SIGNAL(configurationChanged(QNetworkConfiguration)));
+
+ session->close();
+
+ if (!sessionErrorSpy.isEmpty()) {
+ qDebug("tst_QNetworkSession::closeSession() failure: QNetworkSession::error() received.");
+ return false;
+ }
+ if (sessionClosedSpy.count() != 1) {
+ qDebug("tst_QNetworkSession::closeSession() failure: QNetworkSession::closed() signal not received.");
+ return false;
+ }
+ if (lastSessionOnConfiguration &&
+ sessionStateChangedSpy.isEmpty()) {
+ qDebug("tst_QNetworkSession::closeSession() failure: QNetworkSession::stateChanged() signals not received.");
+ return false;
+ }
+ if (lastSessionOnConfiguration &&
+ session->state() != QNetworkSession::Disconnected) {
+ qDebug("tst_QNetworkSession::closeSession() failure: QNetworkSession is not in Disconnected -state");
+ return false;
+ }
+ QTRY_NOOP(!configChangeSpy.isEmpty());
+ if (lastSessionOnConfiguration &&
+ configChangeSpy.isEmpty()) {
+ qDebug("tst_QNetworkSession::closeSession() failure: QNetworkConfigurationManager::configurationChanged() - signal not detected.");
+ return false;
+ }
+ if (lastSessionOnConfiguration &&
+ session->configuration().state() != QNetworkConfiguration::Discovered) {
+ qDebug("tst_QNetworkSession::closeSession() failure: session's configuration is not back in 'Discovered' -state.");
+ return false;
+ }
+ return true;
+}
+
+
+
QTEST_MAIN(tst_QNetworkSession)
#include "tst_qnetworksession.moc"