diff options
Diffstat (limited to 'src')
17 files changed, 1091 insertions, 1349 deletions
diff --git a/src/network/bearer/bearer.pri b/src/network/bearer/bearer.pri index 7dc9195..c03c615 100644 --- a/src/network/bearer/bearer.pri +++ b/src/network/bearer/bearer.pri @@ -1,50 +1,18 @@ # Qt network bearer management module -#DEFINES += BEARER_MANAGEMENT_DEBUG - HEADERS += bearer/qnetworkconfiguration.h \ bearer/qnetworksession.h \ - bearer/qnetworkconfigmanager.h + bearer/qnetworkconfigmanager.h \ + bearer/qnetworkconfigmanager_p.h \ + bearer/qnetworkconfiguration_p.h \ + bearer/qnetworksession_p.h \ + bearer/qbearerengine_p.h \ + bearer/qbearerplugin.h SOURCES += bearer/qnetworksession.cpp \ bearer/qnetworkconfigmanager.cpp \ - bearer/qnetworkconfiguration.cpp - -maemo { - CONFIG += link_pkgconfig - - exists(../debug) { - message("Enabling debug messages.") - DEFINES += BEARER_MANAGEMENT_DEBUG - } - - HEADERS += bearer/qnetworksession_maemo_p.h \ - bearer/qnetworkconfigmanager_maemo_p.h \ - bearer/qnetworkconfiguration_maemo_p.h - - SOURCES += bearer/qnetworkconfigmanager_maemo.cpp \ - bearer/qnetworksession_maemo.cpp - - documentation.path = $$QT_MOBILITY_PREFIX/doc - documentation.files = doc/html - - PKGCONFIG += glib-2.0 dbus-glib-1 gconf-2.0 osso-ic conninet - - CONFIG += create_pc create_prl - QMAKE_PKGCONFIG_REQUIRES = glib-2.0 dbus-glib-1 gconf-2.0 osso-ic conninet - pkgconfig.path = $$QT_MOBILITY_LIB/pkgconfig - pkgconfig.files = QtBearer.pc - - INSTALLS += pkgconfig documentation -} else { - HEADERS += bearer/qnetworkconfigmanager_p.h \ - bearer/qnetworkconfiguration_p.h \ - bearer/qnetworksession_p.h \ - bearer/qbearerengine_p.h \ - bearer/qbearerplugin.h - - SOURCES += bearer/qnetworkconfigmanager_p.cpp \ - bearer/qbearerengine.cpp \ - bearer/qbearerplugin.cpp -} + bearer/qnetworkconfiguration.cpp \ + bearer/qnetworkconfigmanager_p.cpp \ + bearer/qbearerengine.cpp \ + bearer/qbearerplugin.cpp diff --git a/src/network/bearer/qnetworkconfigmanager_maemo.cpp b/src/network/bearer/qnetworkconfigmanager_maemo.cpp deleted file mode 100644 index 96da30d..0000000 --- a/src/network/bearer/qnetworkconfigmanager_maemo.cpp +++ /dev/null @@ -1,759 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtNetwork module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <string.h> - -#include "qnetworkconfigmanager_maemo_p.h" - -#include <QDebug> -#include <QHash> - -#include <wlancond.h> -#include <libicd-network-wlan-dev.h> -#include <maemo_icd.h> -#include <iapconf.h> -#include <iapmonitor.h> - -QT_BEGIN_NAMESPACE - -#define IAP "/system/osso/connectivity/IAP" -static int iap_prefix_len; -static void notify_iap(GConfClient *client, guint id, - GConfEntry *entry, gpointer user_data); - - -/* The IapAddTimer is a helper class that makes sure we update - * the configuration only after all gconf additions to certain - * iap are finished (after a certain timeout) - */ -class _IapAddTimer : public QObject -{ - Q_OBJECT - -public: - _IapAddTimer() {} - ~_IapAddTimer() - { - if (timer.isActive()) { - QObject::disconnect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); - timer.stop(); - } - } - - void add(QString& iap_id, QNetworkConfigurationManagerPrivate *d); - - QString iap_id; - QTimer timer; - QNetworkConfigurationManagerPrivate *d; - -public Q_SLOTS: - void timeout(); -}; - - -void _IapAddTimer::add(QString& id, QNetworkConfigurationManagerPrivate *d_ptr) -{ - iap_id = id; - d = d_ptr; - - if (timer.isActive()) { - QObject::disconnect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); - timer.stop(); - } - timer.setSingleShot(true); - QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); - timer.start(1500); -} - - -void _IapAddTimer::timeout() -{ - d->addConfiguration(iap_id); -} - - -class IapAddTimer { - QHash<QString, _IapAddTimer* > timers; - -public: - IapAddTimer() {} - ~IapAddTimer() {} - - void add(QString& iap_id, QNetworkConfigurationManagerPrivate *d); - void del(QString& iap_id); - void removeAll(); -}; - - -void IapAddTimer::removeAll() -{ - QHashIterator<QString, _IapAddTimer* > i(timers); - while (i.hasNext()) { - i.next(); - _IapAddTimer *t = i.value(); - delete t; - } - timers.clear(); -} - - -void IapAddTimer::add(QString& iap_id, QNetworkConfigurationManagerPrivate *d) -{ - if (timers.contains(iap_id)) { - _IapAddTimer *iap = timers.value(iap_id); - iap->add(iap_id, d); - } else { - _IapAddTimer *iap = new _IapAddTimer; - iap->add(iap_id, d); - timers.insert(iap_id, iap); - } -} - -void IapAddTimer::del(QString& iap_id) -{ - if (timers.contains(iap_id)) { - _IapAddTimer *iap = timers.take(iap_id); - delete iap; - } -} - - -class IapMonitor -{ -public: - IapMonitor() : first_call(true) { } - friend void notify_iap(GConfClient *, guint, - GConfEntry *entry, gpointer user_data); - - void setup(QNetworkConfigurationManagerPrivate *d); - void cleanup(); - -private: - bool first_call; - - void iapAdded(const char *key, GConfEntry *entry); - void iapDeleted(const char *key, GConfEntry *entry); - - Maemo::IAPMonitor *iap; - QNetworkConfigurationManagerPrivate *d; - IapAddTimer timers; -}; - -Q_GLOBAL_STATIC(IapMonitor, iapMonitor); - - -/* Notify func that is called when IAP is added or deleted */ -static 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(QNetworkConfigurationManagerPrivate *d_ptr) -{ - if (first_call) { - d = d_ptr; - iap_prefix_len = strlen(IAP); - iap = new Maemo::IAPMonitor(notify_iap, (gpointer)this); - first_call = false; - } -} - - -void IapMonitor::cleanup() -{ - if (!first_call) { - delete iap; - timers.removeAll(); - first_call = true; - } -} - - -void IapMonitor::iapAdded(const char *key, GConfEntry * /*entry*/) -{ - //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 - * 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); -} - - -void IapMonitor::iapDeleted(const char *key, GConfEntry * /*entry*/) -{ - //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); -} - - - -void QNetworkConfigurationManagerPrivate::registerPlatformCapabilities() -{ - capFlags |= QNetworkConfigurationManager::CanStartAndStopInterfaces; - capFlags |= QNetworkConfigurationManager::DataStatistics; - capFlags |= QNetworkConfigurationManager::ForcedRoaming; -} - - -static inline QString network_attrs_to_security(uint network_attrs) -{ - uint cap = 0; - nwattr2cap(network_attrs, &cap); /* from libicd-network-wlan-dev.h */ - if (cap & WLANCOND_OPEN) - return "NONE"; - else if (cap & WLANCOND_WEP) - return "WEP"; - else if (cap & WLANCOND_WPA_PSK) - return "WPA_PSK"; - else if (cap & WLANCOND_WPA_EAP) - return "WPA_EAP"; - return ""; -} - - -struct SSIDInfo { - QString iap_id; - QString wlan_security; -}; - - -void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigurationPrivate *ptr) -{ - QNetworkConfiguration item; - item.d = ptr; - emit configurationChanged(item); -} - -void QNetworkConfigurationManagerPrivate::deleteConfiguration(QString& iap_id) -{ - /* 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) - */ - if (accessPointConfigurations.contains(iap_id)) { - QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = accessPointConfigurations.take(iap_id); - if (priv.data()) { - priv->isValid = false; -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "IAP" << iap_id << "was removed from storage."; -#endif - - QNetworkConfiguration item; - item.d = priv; - emit configurationRemoved(item); - configChanged(priv.data(), false); - } else - qWarning("Configuration not found for IAP %s", iap_id.toAscii().data()); - } else { -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug("IAP: %s, already missing from the known list", iap_id.toAscii().data()); -#endif - } -} - - -uint32_t QNetworkConfigurationManagerPrivate::getNetworkAttrs(bool is_iap_id, - QString& iap_id, - QString& iap_type, - QString security_method) -{ - guint network_attr = 0; - dbus_uint32_t cap = 0; - - if (iap_type == "WLAN_INFRA") - cap |= WLANCOND_INFRA; - else if (iap_type == "WLAN_ADHOC") - cap |= WLANCOND_ADHOC; - - if (security_method.isEmpty() && (cap & (WLANCOND_INFRA | WLANCOND_ADHOC))) { - Maemo::IAPConf saved_ap(iap_id); - security_method = saved_ap.value("wlan_security").toString(); - } - - if (!security_method.isEmpty()) { - if (security_method == "WEP") - cap |= WLANCOND_WEP; - else if (security_method == "WPA_PSK") - cap |= WLANCOND_WPA_PSK; - else if (security_method == "WPA_EAP") - cap |= WLANCOND_WPA_EAP; - else if (security_method == "NONE") - cap |= WLANCOND_OPEN; - - if (cap & (WLANCOND_WPA_PSK | WLANCOND_WPA_EAP)) { - Maemo::IAPConf saved_iap(iap_id); - bool wpa2_only = saved_iap.value("EAP_wpa2_only_mode").toBool(); - if (wpa2_only) { - cap |= WLANCOND_WPA2; - } - } - } - - cap2nwattr(cap, &network_attr); - if (is_iap_id) - network_attr |= ICD_NW_ATTR_IAPNAME; - - return (uint32_t)network_attr; -} - - -void QNetworkConfigurationManagerPrivate::addConfiguration(QString& iap_id) -{ - if (!accessPointConfigurations.contains(iap_id)) { - Maemo::IAPConf saved_iap(iap_id); - QString iap_type = saved_iap.value("type").toString(); - if (!iap_type.isEmpty()) { - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - cpPriv->name = saved_iap.value("name").toString(); - if (cpPriv->name.isEmpty()) - cpPriv->name = iap_id; - cpPriv->isValid = true; - cpPriv->id = iap_id; - cpPriv->iap_type = iap_type; - cpPriv->network_attrs = getNetworkAttrs(true, iap_id, iap_type, QString()); - cpPriv->service_id = saved_iap.value("service_id").toString(); - cpPriv->service_type = saved_iap.value("service_type").toString(); - if (iap_type.startsWith("WLAN")) { - QByteArray ssid = saved_iap.value("wlan_ssid").toByteArray(); - if (ssid.isEmpty()) { - qWarning() << "Cannot get ssid for" << iap_id; - } - } - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - cpPriv->state = QNetworkConfiguration::Defined; - - QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> ptr(cpPriv); - accessPointConfigurations.insert(iap_id, ptr); - -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug("IAP: %s, name: %s, added to known list", iap_id.toAscii().data(), cpPriv->name.toAscii().data()); -#endif - - QNetworkConfiguration item; - item.d = ptr; - emit configurationAdded(item); - configChanged(ptr.data(), true); - } else { - qWarning("IAP %s does not have \"type\" field defined, skipping this IAP.", iap_id.toAscii().data()); - } - } else { -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "IAP" << iap_id << "already in gconf."; -#endif - - /* Check if the data in gconf changed and update configuration - * accordingly - */ - QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> ptr = accessPointConfigurations.take(iap_id); - if (ptr.data()) { - Maemo::IAPConf changed_iap(iap_id); - QString iap_type = changed_iap.value("type").toString(); - bool update_needed = false; /* if IAP type or ssid changed, we need to change the state */ - - ptr->network_attrs = getNetworkAttrs(true, iap_id, iap_type, QString()); - ptr->service_id = changed_iap.value("service_id").toString(); - ptr->service_type = changed_iap.value("service_type").toString(); - - if (!iap_type.isEmpty()) { - ptr->name = changed_iap.value("name").toString(); - if (ptr->name.isEmpty()) - ptr->name = iap_id; - ptr->isValid = true; - if (ptr->iap_type != iap_type) { - ptr->iap_type = iap_type; - update_needed = true; - } - if (iap_type.startsWith("WLAN")) { - QByteArray ssid = changed_iap.value("wlan_ssid").toByteArray(); - if (ssid.isEmpty()) { - qWarning() << "Cannot get ssid for" << iap_id; - } - if (ptr->network_id != ssid) { - ptr->network_id = ssid; - update_needed = true; - } - } - } - accessPointConfigurations.insert(iap_id, ptr); - if (update_needed) { - ptr->type = QNetworkConfiguration::InternetAccessPoint; - if (ptr->state != QNetworkConfiguration::Defined) { - ptr->state = QNetworkConfiguration::Defined; - configurationChanged(ptr.data()); - } - } - } else { - qWarning("Cannot find IAP %s from current configuration although it should be there.", iap_id.toAscii().data()); - } - } -} - - -void QNetworkConfigurationManagerPrivate::updateConfigurations() -{ - /* Contains known network id (like ssid) from storage */ - QMultiHash<QByteArray, SSIDInfo* > knownConfigs; - - /* All the scanned access points */ - QList<Maemo::IcdScanResult> scanned; - - /* Turn on IAP monitoring */ - iapMonitor()->setup(this); - - if (firstUpdate) { - /* We create a default configuration which is a pseudo config */ - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - cpPriv->name = "UserChoice"; - cpPriv->state = QNetworkConfiguration::Discovered; - cpPriv->isValid = true; - cpPriv->id = OSSO_IAP_ANY; - cpPriv->type = QNetworkConfiguration::UserChoice; - cpPriv->purpose = QNetworkConfiguration::UnknownPurpose; - cpPriv->roamingSupported = false; - cpPriv->manager = this; - QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> ptr(cpPriv); - userChoiceConfigurations.insert(cpPriv->id, ptr); - } - - /* We return currently configured IAPs in the first run and do the WLAN - * scan in subsequent runs. - */ - QList<QString> all_iaps; - Maemo::IAPConf::getAll(all_iaps); - - foreach (QString escaped_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); - - Maemo::IAPConf saved_ap(iap_id); - bool is_temporary = saved_ap.value("temporary").toBool(); - if (is_temporary) { -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "IAP" << iap_id << "is temporary, skipping it."; -#endif - continue; - } - - 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; - continue; - } - - QString security_method = saved_ap.value("wlan_security").toString(); - SSIDInfo *info = new SSIDInfo; - info->iap_id = iap_id; - info->wlan_security = security_method; - knownConfigs.insert(ssid, info); - } else if (iap_type.isEmpty()) { - qWarning() << "IAP" << iap_id << "network type is not set! Skipping it"; - continue; - } else { -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "IAP" << iap_id << "network type is" << iap_type; -#endif - ssid.clear(); - } - - if (!accessPointConfigurations.contains(iap_id)) { - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - //cpPriv->name = iap_info.value().toString(); - 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; - cpPriv->isValid = true; - cpPriv->id = iap_id; - cpPriv->network_id = ssid; - cpPriv->network_attrs = getNetworkAttrs(true, iap_id, iap_type, QString()); - cpPriv->iap_type = iap_type; - cpPriv->service_id = saved_ap.value("service_id").toString(); - cpPriv->service_type = saved_ap.value("service_type").toString(); - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - cpPriv->state = QNetworkConfiguration::Defined; - cpPriv->manager = this; - - QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> ptr(cpPriv); - accessPointConfigurations.insert(iap_id, ptr); - -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug("IAP: %s, name: %s, ssid: %s, added to known list", iap_id.toAscii().data(), cpPriv->name.toAscii().data(), !ssid.isEmpty() ? ssid.data() : "-"); -#endif - } else { -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug("IAP: %s, ssid: %s, already exists in the known list", iap_id.toAscii().data(), !ssid.isEmpty() ? ssid.data() : "-"); -#endif - } - } - - if (!firstUpdate) { - QStringList scannedNetworkTypes; - QStringList networkTypesToScan; - QString error; - Maemo::Icd icd(ICD_SHORT_SCAN_TIMEOUT); - - scannedNetworkTypes = icd.scan(ICD_SCAN_REQUEST_ACTIVE, - networkTypesToScan, - scanned, - error); - if (!error.isEmpty()) { - qWarning() << "Network scanning failed" << error; - } else { -#ifdef BEARER_MANAGEMENT_DEBUG - if (!scanned.isEmpty()) - qDebug() << "Scan returned" << scanned.size() << "networks"; - else - qDebug() << "Scan returned nothing."; -#endif - } - } - - - /* This is skipped in the first update as scanned size is zero */ - if (!scanned.isEmpty()) - for (int i=0; i<scanned.size(); ++i) { - const Maemo::IcdScanResult ap = scanned.at(i); - - if (ap.scan.network_attrs & ICD_NW_ATTR_IAPNAME) { - /* The network_id is IAP id, so the IAP is a known one */ - QString iapid = ap.scan.network_id.data(); - QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = accessPointConfigurations.take(iapid); - if (priv.data()) { - priv->state = QNetworkConfiguration::Discovered; /* Defined is set automagically */ - priv->network_attrs = ap.scan.network_attrs; - priv->service_id = ap.scan.service_id; - priv->service_type = ap.scan.service_type; - priv->service_attrs = ap.scan.service_attrs; - - configurationChanged(priv.data()); - accessPointConfigurations.insert(iapid, priv); -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug("IAP: %s, ssid: %s, discovered", iapid.toAscii().data(), priv->network_id.data()); -#endif - - if (!ap.scan.network_type.startsWith("WLAN")) - continue; // not a wlan AP - - /* Remove scanned AP from known configurations so that we can - * emit configurationRemoved signal later - */ - QList<SSIDInfo* > known_iaps = knownConfigs.values(priv->network_id); - rescan_list: - if (!known_iaps.isEmpty()) { - for (int k=0; k<known_iaps.size(); ++k) { - SSIDInfo *iap = known_iaps.at(k); - -#ifdef BEARER_MANAGEMENT_DEBUG - //qDebug() << "iap" << iap->iap_id << "security" << iap->wlan_security << "scan" << network_attrs_to_security(ap.scan.network_attrs); -#endif - - if (iap->wlan_security == - network_attrs_to_security(ap.scan.network_attrs)) { - /* Remove IAP from the list */ - knownConfigs.remove(priv->network_id, iap); -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "Removed IAP" << iap->iap_id << "from unknown config"; -#endif - known_iaps.removeAt(k); - delete iap; - goto rescan_list; - } - } - } - } else { - qWarning() << "IAP" << iapid << "is missing in configuration."; - } - - } else { - /* Non saved access point data */ - QByteArray scanned_ssid = ap.scan.network_id; - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - QString hrs = scanned_ssid.data(); - - cpPriv->name = ap.network_name.isEmpty() ? hrs : ap.network_name; - cpPriv->isValid = true; - cpPriv->id = scanned_ssid.data(); // Note: id is now ssid, it should be set to IAP id if the IAP is saved - cpPriv->network_id = scanned_ssid; - cpPriv->iap_type = ap.scan.network_type; - cpPriv->network_attrs = ap.scan.network_attrs; - cpPriv->service_id = ap.scan.service_id; - cpPriv->service_type = ap.scan.service_type; - cpPriv->service_attrs = ap.scan.service_attrs; - cpPriv->manager = this; - - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - cpPriv->state = QNetworkConfiguration::Undefined; - - QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> ptr(cpPriv); - accessPointConfigurations.insert(cpPriv->id, ptr); - -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "IAP with network id" << cpPriv->id << "was found in the scan."; -#endif - - QNetworkConfiguration item; - item.d = ptr; - emit configurationAdded(item); - } - } - - - /* Remove non existing iaps since last update */ - if (!firstUpdate) { - QHashIterator<QByteArray, SSIDInfo* > i(knownConfigs); - while (i.hasNext()) { - i.next(); - SSIDInfo *iap = i.value(); - QString iap_id = iap->iap_id; - //qDebug() << i.key() << ": " << iap_id; - - QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = accessPointConfigurations.take(iap_id); - if (priv.data()) { - priv->isValid = false; -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "IAP" << iap_id << "was removed as it was not found in scan."; -#endif - - QNetworkConfiguration item; - item.d = priv; - emit configurationRemoved(item); - configChanged(priv.data(), false); - - //if we would have SNAP support we would have to remove the references - //from existing ServiceNetworks to the removed access point configuration - } - } - } - - - QMutableHashIterator<QByteArray, SSIDInfo* > i(knownConfigs); - while (i.hasNext()) { - i.next(); - SSIDInfo *iap = i.value(); - delete iap; - i.remove(); - } - - if (!firstUpdate) - emit configurationUpdateComplete(); - - if (firstUpdate) - firstUpdate = false; -} - - -QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration() -{ - /* Here we just return [ANY] request to icd and let the icd decide which - * IAP to connect. - */ - QNetworkConfiguration item; - if (userChoiceConfigurations.contains(OSSO_IAP_ANY)) - item.d = userChoiceConfigurations.value(OSSO_IAP_ANY); - return item; -} - - -void QNetworkConfigurationManagerPrivate::performAsyncConfigurationUpdate() -{ - QTimer::singleShot(0, this, SLOT(updateConfigurations())); -} - - -void QNetworkConfigurationManagerPrivate::cleanup() -{ - iapMonitor()->cleanup(); -} - - -void QNetworkConfigurationManagerPrivate::configChanged(QNetworkConfigurationPrivate *ptr, bool added) -{ - if (added) { - if (ptr && ptr->state == QNetworkConfiguration::Active) { - onlineConfigurations++; - if (!firstUpdate && onlineConfigurations == 1) - emit onlineStateChanged(true); - } - } else { - if (ptr && ptr->state == QNetworkConfiguration::Active) { - onlineConfigurations--; - if (!firstUpdate && onlineConfigurations == 0) - emit onlineStateChanged(false); - if (onlineConfigurations < 0) - onlineConfigurations = 0; - } - } -} - - -#include "qnetworkconfigmanager_maemo.moc" -#include "moc_qnetworkconfigmanager_maemo_p.cpp" - -QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworkconfigmanager_maemo_p.h b/src/network/bearer/qnetworkconfigmanager_maemo_p.h deleted file mode 100644 index 5cc99c2..0000000 --- a/src/network/bearer/qnetworkconfigmanager_maemo_p.h +++ /dev/null @@ -1,141 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtNetwork module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QNETWORKCONFIGURATIONMANAGERPRIVATE_H -#define QNETWORKCONFIGURATIONMANAGERPRIVATE_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of the QLibrary class. This header file may change from -// version to version without notice, or even be removed. -// -// We mean it. -// - -#include <qnetworkconfigmanager.h> -#include <qnetworkconfiguration_maemo_p.h> -#include <qnetworksession_maemo_p.h> - -#include <QHash> -#include <QStringList> - -QT_BEGIN_NAMESPACE - - -class QNetworkConfigurationManagerPrivate : public QObject -{ - Q_OBJECT -public: - QNetworkConfigurationManagerPrivate() - : QObject(0), capFlags(0), firstUpdate(true), onlineConfigurations(0) - { - registerPlatformCapabilities(); - updateConfigurations(); - } - - virtual ~QNetworkConfigurationManagerPrivate() - { - QList<QString> configIdents = snapConfigurations.keys(); - foreach(const QString oldIface, configIdents) { - QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = snapConfigurations.take(oldIface); - priv->isValid = false; - priv->id.clear(); - } - - configIdents = accessPointConfigurations.keys(); - foreach(const QString oldIface, configIdents) { - QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = accessPointConfigurations.take(oldIface); - priv->isValid = false; - priv->id.clear(); - } - - configIdents = userChoiceConfigurations.keys(); - foreach(const QString oldIface, configIdents) { - QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = userChoiceConfigurations.take(oldIface); - priv->isValid = false; - priv->id.clear(); - } - - cleanup(); - } - - QNetworkConfiguration defaultConfiguration(); - - QNetworkConfigurationManager::Capabilities capFlags; - void registerPlatformCapabilities(); - - void performAsyncConfigurationUpdate(); - - //this table contains an up to date list of all configs at any time. - //it must be updated if configurations change, are added/removed or - //the members of ServiceNetworks change - QHash<QString, QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> > accessPointConfigurations; - QHash<QString, QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> > snapConfigurations; - QHash<QString, QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> > userChoiceConfigurations; - bool firstUpdate; - int onlineConfigurations; - friend class IapMonitor; - void cleanup(); - void deleteConfiguration(QString &iap_id); - void addConfiguration(QString &iap_id); - void configurationChanged(QNetworkConfigurationPrivate *ptr); - uint32_t getNetworkAttrs(bool is_iap_id, QString& iap_id, - QString& iap_type, QString security_method); - void configChanged(QNetworkConfigurationPrivate *ptr, bool added); - friend class QNetworkSessionPrivate; - -public slots: - void updateConfigurations(); - -Q_SIGNALS: - void configurationAdded(const QNetworkConfiguration& config); - void configurationRemoved(const QNetworkConfiguration& config); - void configurationUpdateComplete(); - void configurationChanged(const QNetworkConfiguration& config); - void onlineStateChanged(bool isOnline); -}; - -QT_END_NAMESPACE - -#endif //QNETWORKCONFIGURATIONMANAGERPRIVATE_H diff --git a/src/network/bearer/qnetworkconfiguration.cpp b/src/network/bearer/qnetworkconfiguration.cpp index 1585be1..cf10677 100644 --- a/src/network/bearer/qnetworkconfiguration.cpp +++ b/src/network/bearer/qnetworkconfiguration.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** diff --git a/src/network/bearer/qnetworkconfiguration_maemo_p.h b/src/network/bearer/qnetworkconfiguration_maemo_p.h deleted file mode 100644 index 3b43312..0000000 --- a/src/network/bearer/qnetworkconfiguration_maemo_p.h +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtNetwork module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QNETWORKCONFIGURATIONPRIVATE_H -#define QNETWORKCONFIGURATIONPRIVATE_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <qnetworkconfiguration.h> -#include <QtCore/qshareddata.h> -#include <QNetworkInterface> - -QT_BEGIN_NAMESPACE - -class QNetworkConfigurationPrivate : public QSharedData -{ -public: - QNetworkConfigurationPrivate () - : isValid(false), type(QNetworkConfiguration::Invalid), - roamingSupported(false), purpose(QNetworkConfiguration::UnknownPurpose), - network_attrs(0), service_attrs(0), manager(0) - { - } - - ~QNetworkConfigurationPrivate() - { - //release pointers to member configurations - serviceNetworkMembers.clear(); - } - - QString name; - bool isValid; - QString id; - QNetworkConfiguration::StateFlags state; - QNetworkConfiguration::Type type; - bool roamingSupported; - QNetworkConfiguration::Purpose purpose; - - QList<QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> > serviceNetworkMembers; - QNetworkInterface serviceInterface; - - /* In Maemo the id field (defined above) is the IAP id (which typically is UUID) */ - QByteArray network_id; /* typically WLAN ssid or similar */ - QString iap_type; /* is this one WLAN or GPRS */ - QString bearerName() const - { - if (iap_type == "WLAN_INFRA" || - iap_type == "WLAN_ADHOC") - return QString("WLAN"); - else if (iap_type == "GPRS") - return QString("HSPA"); - - //return whatever it is - //this may have to be split up later on - return iap_type; - } - - uint32_t network_attrs; /* network attributes for this IAP, this is the value returned by icd and passed to it when connecting */ - - QString service_type; - QString service_id; - uint32_t service_attrs; - - QNetworkConfigurationManagerPrivate *manager; - -private: - - // disallow detaching - QNetworkConfigurationPrivate &operator=(const QNetworkConfigurationPrivate &other); - QNetworkConfigurationPrivate(const QNetworkConfigurationPrivate &other); -}; - -QT_END_NAMESPACE - -#endif //QNETWORKCONFIGURATIONPRIVATE_H diff --git a/src/network/bearer/qnetworkconfiguration_p.h b/src/network/bearer/qnetworkconfiguration_p.h index 40aea8b..6b40946 100644 --- a/src/network/bearer/qnetworkconfiguration_p.h +++ b/src/network/bearer/qnetworkconfiguration_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp index ba50ed6..f9bb9ea 100644 --- a/src/network/bearer/qnetworksession.cpp +++ b/src/network/bearer/qnetworksession.cpp @@ -45,12 +45,7 @@ #include "qnetworksession.h" #include "qbearerengine_p.h" #include "qnetworkconfigmanager_p.h" - -#if Q_WS_MAEMO_6 -#include "qnetworksession_maemo_p.h" -#else #include "qnetworksession_p.h" -#endif QT_BEGIN_NAMESPACE diff --git a/src/network/bearer/qnetworksession_p.h b/src/network/bearer/qnetworksession_p.h index a6bb7cb..76691b3 100644 --- a/src/network/bearer/qnetworksession_p.h +++ b/src/network/bearer/qnetworksession_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -109,6 +109,12 @@ protected: return config.d; } + inline void setPrivateConfiguration(QNetworkConfiguration &config, + QNetworkConfigurationPrivatePointer ptr) const + { + config.d = ptr; + } + Q_SIGNALS: //releases any pending waitForOpened() calls void quitPendingWaitsForOpened(); diff --git a/src/plugins/bearer/bearer.pro b/src/plugins/bearer/bearer.pro index 7347735..95c9851 100644 --- a/src/plugins/bearer/bearer.pro +++ b/src/plugins/bearer/bearer.pro @@ -5,5 +5,6 @@ win32:SUBDIRS += nla win32:!wince*:SUBDIRS += nativewifi macx:SUBDIRS += corewlan symbian:SUBDIRS += symbian +maemo6:contains(QT_CONFIG, dbus):SUBDIRS += icd isEmpty(SUBDIRS):SUBDIRS += generic diff --git a/src/plugins/bearer/icd/icd.pro b/src/plugins/bearer/icd/icd.pro new file mode 100644 index 0000000..5eaf5af --- /dev/null +++ b/src/plugins/bearer/icd/icd.pro @@ -0,0 +1,22 @@ +TARGET = qicdbearer +include(../../qpluginbase.pri) + +QT += network dbus + +CONFIG += link_pkgconfig +PKGCONFIG += glib-2.0 dbus-glib-1 gconf-2.0 osso-ic conninet + +HEADERS += qicdengine.h \ + monitor.h \ + qnetworksession_impl.h + +SOURCES += main.cpp \ + qicdengine.cpp \ + monitor.cpp \ + qnetworksession_impl.cpp + +#DEFINES += BEARER_MANAGEMENT_DEBUG + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/bearer +target.path += $$[QT_INSTALL_PLUGINS]/bearer +INSTALLS += target diff --git a/src/plugins/bearer/icd/main.cpp b/src/plugins/bearer/icd/main.cpp new file mode 100644 index 0000000..8984d2c --- /dev/null +++ b/src/plugins/bearer/icd/main.cpp @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qicdengine.h" + +#include <QtNetwork/qbearerplugin.h> + +#include <QtCore/qdebug.h> + +QT_BEGIN_NAMESPACE + +class QIcdEnginePlugin : public QBearerEnginePlugin +{ +public: + QIcdEnginePlugin(); + ~QIcdEnginePlugin(); + + QStringList keys() const; + QBearerEngine *create(const QString &key) const; +}; + +QIcdEnginePlugin::QIcdEnginePlugin() +{ +} + +QIcdEnginePlugin::~QIcdEnginePlugin() +{ +} + +QStringList QIcdEnginePlugin::keys() const +{ + return QStringList() << QLatin1String("icd"); +} + +QBearerEngine *QIcdEnginePlugin::create(const QString &key) const +{ + if (key == QLatin1String("icd")) + return new QIcdEngine; + else + return 0; +} + +Q_EXPORT_STATIC_PLUGIN(QIcdEnginePlugin) +Q_EXPORT_PLUGIN2(qicdbearer, QIcdEnginePlugin) + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/icd/monitor.cpp b/src/plugins/bearer/icd/monitor.cpp new file mode 100644 index 0000000..0ff45d2 --- /dev/null +++ b/src/plugins/bearer/icd/monitor.cpp @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "monitor.h" +#include "qicdengine.h" + +#include <wlancond.h> +#include <libicd-network-wlan-dev.h> +#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; + } +} + + +void IapMonitor::cleanup() +{ + if (!first_call) { + delete iap; + timers.removeAll(); + first_call = true; + } +} + + +void IapMonitor::iapAdded(const char *key, GConfEntry * /*entry*/) +{ + //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 + * 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); +} + + +void IapMonitor::iapDeleted(const char *key, GConfEntry * /*entry*/) +{ + //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); +} diff --git a/src/plugins/bearer/icd/monitor.h b/src/plugins/bearer/icd/monitor.h new file mode 100644 index 0000000..82b0f36 --- /dev/null +++ b/src/plugins/bearer/icd/monitor.h @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MONITOR_H +#define MONITOR_H + +#include <QtCore/qhash.h> +#include <QtCore/qtimer.h> + +#include <gconf/gconf.h> +#include <gconf/gconf-client.h> + +#include <iapmonitor.h> + +class QIcdEngine; + +/* The IapAddTimer is a helper class that makes sure we update + * the configuration only after all gconf additions to certain + * iap are finished (after a certain timeout) + */ +class _IapAddTimer : public QObject +{ + Q_OBJECT + +public: + _IapAddTimer() {} + ~_IapAddTimer() + { + if (timer.isActive()) { + QObject::disconnect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); + timer.stop(); + } + } + + void add(QString& iap_id, QIcdEngine *d); + + QString iap_id; + QTimer timer; + QIcdEngine *d; + +public Q_SLOTS: + void timeout(); +}; + +class IapAddTimer { + QHash<QString, _IapAddTimer* > timers; + +public: + IapAddTimer() {} + ~IapAddTimer() {} + + void add(QString& iap_id, QIcdEngine *d); + void del(QString& iap_id); + void removeAll(); +}; + +class IapMonitor +{ +public: + IapMonitor() : first_call(true) { } + friend void notify_iap(GConfClient *, guint, + GConfEntry *entry, gpointer user_data); + + void setup(QIcdEngine *d); + void cleanup(); + +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; +}; + +#endif // MONITOR_H diff --git a/src/plugins/bearer/icd/qicdengine.cpp b/src/plugins/bearer/icd/qicdengine.cpp new file mode 100644 index 0000000..3233eda --- /dev/null +++ b/src/plugins/bearer/icd/qicdengine.cpp @@ -0,0 +1,416 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qicdengine.h" +#include "monitor.h" +#include "qnetworksession_impl.h" + +#include <libicd-network-wlan-dev.h> +#include <maemo_icd.h> +#include <iapconf.h> + +QT_BEGIN_NAMESPACE + +IcdNetworkConfigurationPrivate::IcdNetworkConfigurationPrivate() +: network_attrs(0), service_attrs(0) +{ +} + +IcdNetworkConfigurationPrivate::~IcdNetworkConfigurationPrivate() +{ +} + +QString IcdNetworkConfigurationPrivate::bearerName() const +{ + if (iap_type == QLatin1String("WLAN_INFRA") || + iap_type == QLatin1String("WLAN_ADHOC")) { + return QLatin1String("WLAN"); + } else if (iap_type == QLatin1String("GPRS")) { + return QLatin1String("HSPA"); + } else { + return iap_type; + } +} + +static inline QString network_attrs_to_security(uint network_attrs) +{ + uint cap = 0; + nwattr2cap(network_attrs, &cap); /* from libicd-network-wlan-dev.h */ + if (cap & WLANCOND_OPEN) + return "NONE"; + else if (cap & WLANCOND_WEP) + return "WEP"; + else if (cap & WLANCOND_WPA_PSK) + return "WPA_PSK"; + else if (cap & WLANCOND_WPA_EAP) + return "WPA_EAP"; + return ""; +} + +QIcdEngine::QIcdEngine(QObject *parent) +: QBearerEngine(parent), iapMonitor(new IapMonitor) +{ + /* Turn on IAP monitoring */ + iapMonitor->setup(this); + + doRequestUpdate(); +} + +QIcdEngine::~QIcdEngine() +{ +} + +bool QIcdEngine::hasIdentifier(const QString &id) +{ + return accessPointConfigurations.contains(id) || + snapConfigurations.contains(id) || + userChoiceConfigurations.contains(id); +} + +void QIcdEngine::requestUpdate() +{ + QTimer::singleShot(0, this, SLOT(doRequestUpdate())); +} + +static uint32_t getNetworkAttrs(bool is_iap_id, + QString& iap_id, + QString& iap_type, + QString security_method) +{ + guint network_attr = 0; + dbus_uint32_t cap = 0; + + if (iap_type == "WLAN_INFRA") + cap |= WLANCOND_INFRA; + else if (iap_type == "WLAN_ADHOC") + cap |= WLANCOND_ADHOC; + + if (security_method.isEmpty() && (cap & (WLANCOND_INFRA | WLANCOND_ADHOC))) { + Maemo::IAPConf saved_ap(iap_id); + security_method = saved_ap.value("wlan_security").toString(); + } + + if (!security_method.isEmpty()) { + if (security_method == "WEP") + cap |= WLANCOND_WEP; + else if (security_method == "WPA_PSK") + cap |= WLANCOND_WPA_PSK; + else if (security_method == "WPA_EAP") + cap |= WLANCOND_WPA_EAP; + else if (security_method == "NONE") + cap |= WLANCOND_OPEN; + + if (cap & (WLANCOND_WPA_PSK | WLANCOND_WPA_EAP)) { + Maemo::IAPConf saved_iap(iap_id); + bool wpa2_only = saved_iap.value("EAP_wpa2_only_mode").toBool(); + if (wpa2_only) { + cap |= WLANCOND_WPA2; + } + } + } + + cap2nwattr(cap, &network_attr); + if (is_iap_id) + network_attr |= ICD_NW_ATTR_IAPNAME; + + return (uint32_t)network_attr; +} + +void QIcdEngine::doRequestUpdate() +{ + QStringList previous = accessPointConfigurations.keys(); + + /* All the scanned access points */ + QList<Maemo::IcdScanResult> scanned; + + /* We create a default configuration which is a pseudo config */ + if (!userChoiceConfigurations.contains(OSSO_IAP_ANY)) { + QNetworkConfigurationPrivatePointer ptr(new IcdNetworkConfigurationPrivate); + + ptr->name = QLatin1String("UserChoice"); + ptr->state = QNetworkConfiguration::Discovered; + ptr->isValid = true; + ptr->id = OSSO_IAP_ANY; + ptr->type = QNetworkConfiguration::UserChoice; + ptr->purpose = QNetworkConfiguration::UnknownPurpose; + ptr->roamingSupported = false; + + userChoiceConfigurations.insert(ptr->id, ptr); + emit configurationAdded(ptr); + } + + /* We return currently configured IAPs in the first run and do the WLAN + * scan in subsequent runs. + */ + QList<QString> all_iaps; + Maemo::IAPConf::getAll(all_iaps); + + foreach (QString escaped_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); + bool is_temporary = saved_ap.value("temporary").toBool(); + if (is_temporary) { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "IAP" << iap_id << "is temporary, skipping it."; +#endif + continue; + } + + 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; + 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 + qDebug() << "IAP" << iap_id << "network type is" << iap_type; +#endif + ssid.clear(); + } + + if (!accessPointConfigurations.contains(iap_id)) { + 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; + cpPriv->isValid = true; + cpPriv->id = iap_id; + cpPriv->network_id = ssid; + cpPriv->network_attrs = getNetworkAttrs(true, iap_id, iap_type, QString()); + cpPriv->iap_type = iap_type; + cpPriv->service_id = saved_ap.value("service_id").toString(); + cpPriv->service_type = saved_ap.value("service_type").toString(); + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + cpPriv->state = QNetworkConfiguration::Defined; + + QNetworkConfigurationPrivatePointer ptr(cpPriv); + accessPointConfigurations.insert(iap_id, ptr); + emit configurationAdded(ptr); + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug("IAP: %s, name: %s, ssid: %s, added to known list", + iap_id.toAscii().data(), ptr->name.toAscii().data(), + !ssid.isEmpty() ? ssid.data() : "-"); +#endif + } else { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug("IAP: %s, ssid: %s, already exists in the known list", + iap_id.toAscii().data(), !ssid.isEmpty() ? ssid.data() : "-"); +#endif + } + } + + if (sender()) { + QStringList scannedNetworkTypes; + QStringList networkTypesToScan; + QString error; + Maemo::Icd icd(ICD_SHORT_SCAN_TIMEOUT); + + scannedNetworkTypes = icd.scan(ICD_SCAN_REQUEST_ACTIVE, + networkTypesToScan, + scanned, + error); + if (!error.isEmpty()) { + qWarning() << "Network scanning failed" << error; + } else { +#ifdef BEARER_MANAGEMENT_DEBUG + if (!scanned.isEmpty()) + qDebug() << "Scan returned" << scanned.size() << "networks"; + else + qDebug() << "Scan returned nothing."; +#endif + } + } + + /* This is skipped in the first update as scanned size is zero */ + if (!scanned.isEmpty()) { + for (int i=0; i<scanned.size(); ++i) { + const Maemo::IcdScanResult ap = scanned.at(i); + + QByteArray scanned_ssid = ap.scan.network_id; + + if (ap.scan.network_attrs & ICD_NW_ATTR_IAPNAME) { + /* The network_id is IAP id, so the IAP is a known one */ + QString iapid = ap.scan.network_id.data(); + + previous.removeAll(iapid); + + if (accessPointConfigurations.contains(iapid)) { + QNetworkConfigurationPrivatePointer ptr = + accessPointConfigurations.value(iapid); + + bool changed = false; + + if (!ptr->isValid) { + ptr->isValid = true; + changed = true; + } + + if (ptr->state != QNetworkConfiguration::Discovered) { + ptr->state = QNetworkConfiguration::Discovered; + changed = true; + } + + toIcdConfig(ptr)->network_attrs = ap.scan.network_attrs; + toIcdConfig(ptr)->service_id = ap.scan.service_id; + toIcdConfig(ptr)->service_type = ap.scan.service_type; + toIcdConfig(ptr)->service_attrs = ap.scan.service_attrs; + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug("IAP: %s, ssid: %s, discovered", + iapid.toAscii().data(), scanned_ssid.data()); +#endif + + if (changed) + emit configurationChanged(ptr); + + if (!ap.scan.network_type.startsWith("WLAN")) + continue; // not a wlan AP + } + } else { + IcdNetworkConfigurationPrivate *cpPriv = new IcdNetworkConfigurationPrivate; + + QString hrs = scanned_ssid.data(); + + cpPriv->name = ap.network_name.isEmpty() ? hrs : ap.network_name; + cpPriv->isValid = true; + // Note: id is now ssid, it should be set to IAP id if the IAP is saved + cpPriv->id = scanned_ssid.data(); + cpPriv->network_id = scanned_ssid; + cpPriv->iap_type = ap.scan.network_type; + if (cpPriv->iap_type.isEmpty()) + cpPriv->iap_type = QLatin1String("WLAN"); + cpPriv->network_attrs = ap.scan.network_attrs; + cpPriv->service_id = ap.scan.service_id; + cpPriv->service_type = ap.scan.service_type; + cpPriv->service_attrs = ap.scan.service_attrs; + + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + cpPriv->state = QNetworkConfiguration::Undefined; + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "IAP with network id" << cpPriv->id << "was found in the scan."; +#endif + + previous.removeAll(cpPriv->id); + + QNetworkConfigurationPrivatePointer ptr(cpPriv); + accessPointConfigurations.insert(ptr->id, ptr); + emit configurationAdded(ptr); + } + } + } + + while (!previous.isEmpty()) { + QNetworkConfigurationPrivatePointer ptr = + accessPointConfigurations.take(previous.takeFirst()); + + emit configurationRemoved(ptr); + } + + if (sender()) + emit updateCompleted(); +} + +void QIcdEngine::deleteConfiguration(const QString &iap_id) +{ + /* 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) + */ + if (accessPointConfigurations.contains(iap_id)) { + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(iap_id); + + if (ptr) { + ptr->isValid = false; +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "IAP" << iap_id << "was removed from storage."; +#endif + + emit configurationRemoved(ptr); + } else { + qWarning("Configuration not found for IAP %s", iap_id.toAscii().data()); + } + } else { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug("IAP: %s, already missing from the known list", iap_id.toAscii().data()); +#endif + } +} + +QNetworkConfigurationManager::Capabilities QIcdEngine::capabilities() const +{ + return QNetworkConfigurationManager::CanStartAndStopInterfaces | + QNetworkConfigurationManager::DataStatistics | + QNetworkConfigurationManager::ForcedRoaming; +} + +QNetworkSessionPrivate *QIcdEngine::createSessionBackend() +{ + return new QNetworkSessionPrivateImpl(this); +} + +QNetworkConfigurationPrivatePointer QIcdEngine::defaultConfiguration() +{ + // Here we just return [ANY] request to icd and let the icd decide which IAP to connect. + return userChoiceConfigurations.value(OSSO_IAP_ANY); +} + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/icd/qicdengine.h b/src/plugins/bearer/icd/qicdengine.h new file mode 100644 index 0000000..30b5711 --- /dev/null +++ b/src/plugins/bearer/icd/qicdengine.h @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QICDENGINE_H +#define QICDENGINE_H + +#include <QtNetwork/private/qbearerengine_p.h> + +QT_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; +class IapMonitor; + +class IcdNetworkConfigurationPrivate : public QNetworkConfigurationPrivate +{ +public: + IcdNetworkConfigurationPrivate(); + ~IcdNetworkConfigurationPrivate(); + + QString bearerName() const; + + // In Maemo the id field (defined in QNetworkConfigurationPrivate) + // is the IAP id (which typically is UUID) + QByteArray network_id; // typically WLAN ssid or similar + QString iap_type; // is this one WLAN or GPRS + + // Network attributes for this IAP, this is the value returned by icd and + // passed to it when connecting. + uint32_t network_attrs; + + QString service_type; + QString service_id; + uint32_t service_attrs; +}; + +inline IcdNetworkConfigurationPrivate *toIcdConfig(QNetworkConfigurationPrivatePointer ptr) +{ + return static_cast<IcdNetworkConfigurationPrivate *>(ptr.data()); +} + +class QIcdEngine : public QBearerEngine +{ + Q_OBJECT + + friend class QNetworkSessionPrivateImpl; + +public: + QIcdEngine(QObject *parent = 0); + ~QIcdEngine(); + + bool hasIdentifier(const QString &id); + + void requestUpdate(); + + QNetworkConfigurationManager::Capabilities capabilities() const; + + QNetworkSessionPrivate *createSessionBackend(); + + QNetworkConfigurationPrivatePointer defaultConfiguration(); + + void deleteConfiguration(const QString &iap_id); + +private: + inline void addSessionConfiguration(QNetworkConfigurationPrivatePointer ptr) + { + accessPointConfigurations.insert(ptr->id, ptr); + emit configurationAdded(ptr); + } + + inline void changedSessionConfiguration(QNetworkConfigurationPrivatePointer ptr) + { + emit configurationChanged(ptr); + } + +private Q_SLOTS: + void doRequestUpdate(); + +private: + IapMonitor *iapMonitor; +}; + +QT_END_NAMESPACE + +#endif // QICDENGINE_H diff --git a/src/network/bearer/qnetworksession_maemo.cpp b/src/plugins/bearer/icd/qnetworksession_impl.cpp index 6fb4453..6cc4a1d 100644 --- a/src/network/bearer/qnetworksession_maemo.cpp +++ b/src/plugins/bearer/icd/qnetworksession_impl.cpp @@ -1,10 +1,10 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the QtNetwork module of the Qt Toolkit. +** This file is part of the plugins of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage @@ -39,9 +39,11 @@ ** ****************************************************************************/ +#include "qnetworksession_impl.h" +#include "qicdengine.h" + #include <QHash> -#include "qnetworksession_maemo_p.h" #include <dbus/dbus.h> #include <dbus/dbus-glib-lowlevel.h> @@ -92,9 +94,9 @@ public: friend DBusHandlerResult signal_handler(DBusConnection *connection, DBusMessage *message, void *user_data); - void setup(QNetworkSessionPrivate *d); + void setup(QNetworkSessionPrivateImpl *d); void cleanup(); - void cleanupSession(QNetworkSessionPrivate *ptr); + void cleanupSession(QNetworkSessionPrivateImpl *ptr); enum IapConnectionStatus { /* The IAP was connected */ @@ -110,7 +112,7 @@ public: private: void icdSignalReceived(QString&, QString&, QString&); bool first_call; - QHash<QString, QNetworkSessionPrivate* > sessions; + QHash<QString, QNetworkSessionPrivateImpl *> sessions; }; Q_GLOBAL_STATIC(IcdListener, icdListener); @@ -154,7 +156,7 @@ static DBusHandlerResult signal_handler(DBusConnection *, } -void IcdListener::setup(QNetworkSessionPrivate *d) +void IcdListener::setup(QNetworkSessionPrivateImpl *d) { if (first_call) { // We use the old Icd dbus interface like in ConIC @@ -196,7 +198,7 @@ void IcdListener::setup(QNetworkSessionPrivate *d) QString id = d->activeConfig.identifier(); if (!sessions.contains(id)) { - QNetworkSessionPrivate *ptr = d; + QNetworkSessionPrivateImpl *ptr = d; sessions.insert(id, ptr); } } @@ -224,8 +226,9 @@ void IcdListener::icdSignalReceived(QString& iap_id, return; } - QNetworkSessionPrivate *session = sessions.value(iap_id); - QNetworkConfiguration ap_conf = session->manager.configurationFromIdentifier(iap_id); + QNetworkSessionPrivateImpl *session = sessions.value(iap_id); + QNetworkConfiguration ap_conf = + QNetworkConfigurationManager().configurationFromIdentifier(iap_id); if (!ap_conf.isValid()) { #ifdef BEARER_MANAGEMENT_DEBUG qDebug() << "Unknown IAP" << iap_id; @@ -284,7 +287,7 @@ void IcdListener::cleanup() } -void IcdListener::cleanupSession(QNetworkSessionPrivate *ptr) +void IcdListener::cleanupSession(QNetworkSessionPrivateImpl *ptr) { if (ptr->publicConfig.type() == QNetworkConfiguration::UserChoice) (void)sessions.take(ptr->activeConfig.identifier()); @@ -293,54 +296,56 @@ void IcdListener::cleanupSession(QNetworkSessionPrivate *ptr) } -void QNetworkSessionPrivate::cleanupSession(void) +void QNetworkSessionPrivateImpl::cleanupSession(void) { icdListener()->cleanupSession(this); } -void QNetworkSessionPrivate::updateState(QNetworkSession::State newState) +void QNetworkSessionPrivateImpl::updateState(QNetworkSession::State newState) { - if( newState != state) { - state = newState; + if (newState == state) + return; + + state = newState; if (state == QNetworkSession::Disconnected) { isOpen = false; currentNetworkInterface.clear(); if (publicConfig.type() == QNetworkConfiguration::UserChoice) - activeConfig.d->state = QNetworkConfiguration::Defined; - publicConfig.d->state = QNetworkConfiguration::Defined; + privateConfiguration(activeConfig)->state = QNetworkConfiguration::Defined; + privateConfiguration(publicConfig)->state = QNetworkConfiguration::Defined; } else if (state == QNetworkSession::Connected) { isOpen = true; if (publicConfig.type() == QNetworkConfiguration::UserChoice) { - activeConfig.d->state = QNetworkConfiguration::Active; - activeConfig.d->type = QNetworkConfiguration::InternetAccessPoint; + privateConfiguration(activeConfig)->state = QNetworkConfiguration::Active; + privateConfiguration(activeConfig)->type = QNetworkConfiguration::InternetAccessPoint; } - publicConfig.d->state = QNetworkConfiguration::Active; + privateConfiguration(publicConfig)->state = QNetworkConfiguration::Active; } - emit q->stateChanged(newState); - } + emit stateChanged(newState); } -void QNetworkSessionPrivate::updateIdentifier(QString &newId) +void QNetworkSessionPrivateImpl::updateIdentifier(QString &newId) { if (publicConfig.type() == QNetworkConfiguration::UserChoice) { - activeConfig.d->network_attrs |= ICD_NW_ATTR_IAPNAME; - activeConfig.d->id = newId; + toIcdConfig(privateConfiguration(activeConfig))->network_attrs |= ICD_NW_ATTR_IAPNAME; + privateConfiguration(activeConfig)->id = newId; } else { - publicConfig.d->network_attrs |= ICD_NW_ATTR_IAPNAME; - if (publicConfig.d->id != newId) { - qWarning() << "Your config id changed from" << publicConfig.d->id << "to" << newId; - publicConfig.d->id = newId; + 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; } } } -quint64 QNetworkSessionPrivate::getStatistics(bool sent) const +quint64 QNetworkSessionPrivateImpl::getStatistics(bool sent) const { /* This could be also implemented by using the Maemo::Icd::statistics() * that gets the statistics data for a specific IAP. Change if @@ -363,8 +368,7 @@ quint64 QNetworkSessionPrivate::getStatistics(bool sent) const } } else { /* We probably will never get to this branch */ - QNetworkConfigurationPrivate *d = activeConfig.d.data(); - if (res.params.network_id == d->network_id) { + if (res.params.network_id == toIcdConfig(privateConfiguration(activeConfig))->network_id) { counter_tx = res.bytes_sent; counter_rx = res.bytes_received; } @@ -378,17 +382,17 @@ quint64 QNetworkSessionPrivate::getStatistics(bool sent) const } -quint64 QNetworkSessionPrivate::bytesWritten() const +quint64 QNetworkSessionPrivateImpl::bytesWritten() const { return getStatistics(true); } -quint64 QNetworkSessionPrivate::bytesReceived() const +quint64 QNetworkSessionPrivateImpl::bytesReceived() const { return getStatistics(false); } -quint64 QNetworkSessionPrivate::activeTime() const +quint64 QNetworkSessionPrivateImpl::activeTime() const { if (startTime.isNull()) { return 0; @@ -397,29 +401,32 @@ quint64 QNetworkSessionPrivate::activeTime() const } -QNetworkConfiguration& QNetworkSessionPrivate::copyConfig(QNetworkConfiguration &fromConfig, QNetworkConfiguration &toConfig, bool deepCopy) +QNetworkConfiguration& QNetworkSessionPrivateImpl::copyConfig(QNetworkConfiguration &fromConfig, + QNetworkConfiguration &toConfig, + bool deepCopy) { + IcdNetworkConfigurationPrivate *cpPriv; if (deepCopy) { - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> ptr(cpPriv); - toConfig.d = ptr; + cpPriv = new IcdNetworkConfigurationPrivate; + setPrivateConfiguration(toConfig, QNetworkConfigurationPrivatePointer(cpPriv)); + } else { + cpPriv = toIcdConfig(privateConfiguration(toConfig)); } - toConfig.d->name = fromConfig.d->name; - toConfig.d->isValid = fromConfig.d->isValid; + cpPriv->name = privateConfiguration(fromConfig)->name; + cpPriv->isValid = privateConfiguration(fromConfig)->isValid; // Note that we do not copy id field here as the publicConfig does // not contain a valid IAP id. - toConfig.d->state = fromConfig.d->state; - toConfig.d->type = fromConfig.d->type; - toConfig.d->roamingSupported = fromConfig.d->roamingSupported; - toConfig.d->purpose = fromConfig.d->purpose; - toConfig.d->network_id = fromConfig.d->network_id; - toConfig.d->iap_type = fromConfig.d->iap_type; - toConfig.d->network_attrs = fromConfig.d->network_attrs; - toConfig.d->service_type = fromConfig.d->service_type; - toConfig.d->service_id = fromConfig.d->service_id; - toConfig.d->service_attrs = fromConfig.d->service_attrs; - toConfig.d->manager = fromConfig.d->manager; + cpPriv->state = privateConfiguration(fromConfig)->state; + cpPriv->type = privateConfiguration(fromConfig)->type; + cpPriv->roamingSupported = privateConfiguration(fromConfig)->roamingSupported; + cpPriv->purpose = privateConfiguration(fromConfig)->purpose; + cpPriv->network_id = toIcdConfig(privateConfiguration(fromConfig))->network_id; + cpPriv->iap_type = toIcdConfig(privateConfiguration(fromConfig))->iap_type; + cpPriv->network_attrs = toIcdConfig(privateConfiguration(fromConfig))->network_attrs; + cpPriv->service_type = toIcdConfig(privateConfiguration(fromConfig))->service_type; + cpPriv->service_id = toIcdConfig(privateConfiguration(fromConfig))->service_id; + cpPriv->service_attrs = toIcdConfig(privateConfiguration(fromConfig))->service_attrs; return toConfig; } @@ -428,7 +435,7 @@ QNetworkConfiguration& QNetworkSessionPrivate::copyConfig(QNetworkConfiguration /* This is called by QNetworkSession constructor and it updates the current * state of the configuration. */ -void QNetworkSessionPrivate::syncStateWithInterface() +void QNetworkSessionPrivateImpl::syncStateWithInterface() { /* Start to listen Icd status messages. */ icdListener()->setup(this); @@ -439,20 +446,10 @@ void QNetworkSessionPrivate::syncStateWithInterface() isOpen = false; opened = false; - QObject::connect(&manager, SIGNAL(updateCompleted()), this, SLOT(networkConfigurationsChanged())); + connect(&manager, SIGNAL(updateCompleted()), this, SLOT(networkConfigurationsChanged())); - if (publicConfig.d.data()) { - QNetworkConfigurationManagerPrivate* mgr = (QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager; - if (mgr) { - QObject::connect(mgr, SIGNAL(configurationChanged(QNetworkConfiguration)), - this, SLOT(configurationChanged(QNetworkConfiguration))); - } else { - qWarning()<<"Manager object not set when trying to connect configurationChanged signal. Your configuration object is not correctly setup, did you remember to call manager.updateConfigurations() before creating session object?"; - state = QNetworkSession::Invalid; - lastError = QNetworkSession::UnknownSessionError; - return; - } - } + connect(&manager, SIGNAL(configurationChanged(QNetworkConfiguration)), + this, SLOT(configurationChanged(QNetworkConfiguration))); state = QNetworkSession::Invalid; lastError = QNetworkSession::UnknownSessionError; @@ -512,84 +509,68 @@ void QNetworkSessionPrivate::syncStateWithInterface() * then do not update current state etc. */ if (publicConfig.type() == QNetworkConfiguration::UserChoice || - publicConfig.d->id == state_results.first().params.network_id) { + privateConfiguration(publicConfig)->id == state_results.first().params.network_id) { switch (state_results.first().state) { case ICD_STATE_DISCONNECTED: state = QNetworkSession::Disconnected; - if (activeConfig.d.data()) - activeConfig.d->isValid = true; + if (privateConfiguration(activeConfig)) + privateConfiguration(activeConfig)->isValid = true; break; case ICD_STATE_CONNECTING: state = QNetworkSession::Connecting; - if (activeConfig.d.data()) - activeConfig.d->isValid = true; + if (privateConfiguration(activeConfig)) + privateConfiguration(activeConfig)->isValid = true; break; case ICD_STATE_CONNECTED: { if (!state_results.first().error.isEmpty()) break; - const QString id = state_results.first().params.network_id; + const QString id = state_results.first().params.network_id; - QNetworkConfigurationManagerPrivate *mgr = (QNetworkConfigurationManagerPrivate*)activeConfig.d.data()->manager; - if (mgr->accessPointConfigurations.contains(id)) { - //we don't want the copied data if the config is already known by the manager - //just reuse it so that existing references to the old data get the same update - QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = mgr->accessPointConfigurations.value(activeConfig.d->id); - activeConfig.d = priv; - } + QNetworkConfiguration config = manager.configurationFromIdentifier(id); + if (config.isValid()) { + //we don't want the copied data if the config is already known by the manager + //just reuse it so that existing references to the old data get the same update + setPrivateConfiguration(activeConfig, privateConfiguration(config)); + } + QNetworkConfigurationPrivatePointer ptr = privateConfiguration(activeConfig); state = QNetworkSession::Connected; - activeConfig.d->network_id = state_results.first().params.network_id; - activeConfig.d->id = activeConfig.d->network_id; - activeConfig.d->network_attrs = state_results.first().params.network_attrs; - activeConfig.d->iap_type = state_results.first().params.network_type; - activeConfig.d->service_type = state_results.first().params.service_type; - activeConfig.d->service_id = state_results.first().params.service_id; - activeConfig.d->service_attrs = state_results.first().params.service_attrs; - activeConfig.d->type = QNetworkConfiguration::InternetAccessPoint; - activeConfig.d->state = QNetworkConfiguration::Active; - activeConfig.d->isValid = true; + toIcdConfig(ptr)->network_id = state_results.first().params.network_id; + ptr->id = toIcdConfig(ptr)->network_id; + toIcdConfig(ptr)->network_attrs = state_results.first().params.network_attrs; + toIcdConfig(ptr)->iap_type = state_results.first().params.network_type; + toIcdConfig(ptr)->service_type = state_results.first().params.service_type; + toIcdConfig(ptr)->service_id = state_results.first().params.service_id; + toIcdConfig(ptr)->service_attrs = state_results.first().params.service_attrs; + ptr->type = QNetworkConfiguration::InternetAccessPoint; + ptr->state = QNetworkConfiguration::Active; + ptr->isValid = true; currentNetworkInterface = get_network_interface(); - Maemo::IAPConf iap_name(activeConfig.d->id); + Maemo::IAPConf iap_name(privateConfiguration(activeConfig)->id); QString name_value = iap_name.value("name").toString(); if (!name_value.isEmpty()) - activeConfig.d->name = name_value; + privateConfiguration(activeConfig)->name = name_value; else - activeConfig.d->name = activeConfig.d->id; + privateConfiguration(activeConfig)->name = privateConfiguration(activeConfig)->id; // Add the new active configuration to manager or update the old config - mgr = (QNetworkConfigurationManagerPrivate*)activeConfig.d.data()->manager; - if (!(mgr->accessPointConfigurations.contains(activeConfig.d->id))) { - QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> ptr = activeConfig.d; - mgr->accessPointConfigurations.insert(activeConfig.d->id, ptr); - - QNetworkConfiguration item; - item.d = ptr; - emit mgr->configurationAdded(item); - -#ifdef BEARER_MANAGEMENT_DEBUG - //qDebug()<<"New configuration"<<activeConfig.d->id<<"added to manager in sync"; -#endif - - } else { - mgr->configurationChanged((QNetworkConfigurationPrivate*)(activeConfig.d.data())); -#ifdef BEARER_MANAGEMENT_DEBUG - //qDebug()<<"Existing configuration"<<activeConfig.d->id<<"updated in manager in sync"; -#endif - } - + if (!(engine->accessPointConfigurations.contains(privateConfiguration(activeConfig)->id))) + engine->addSessionConfiguration(privateConfiguration(activeConfig)); + else + engine->changedSessionConfiguration(privateConfiguration(activeConfig)); } break; case ICD_STATE_DISCONNECTING: state = QNetworkSession::Closing; - if (activeConfig.d.data()) - activeConfig.d->isValid = true; + if (privateConfiguration(activeConfig)) + privateConfiguration(activeConfig)->isValid = true; break; default: break; @@ -610,7 +591,7 @@ void QNetworkSessionPrivate::syncStateWithInterface() } -void QNetworkSessionPrivate::networkConfigurationsChanged() +void QNetworkSessionPrivateImpl::networkConfigurationsChanged() { if (serviceConfig.isValid()) updateStateFromServiceNetwork(); @@ -619,7 +600,7 @@ void QNetworkSessionPrivate::networkConfigurationsChanged() } -void QNetworkSessionPrivate::updateStateFromServiceNetwork() +void QNetworkSessionPrivateImpl::updateStateFromServiceNetwork() { QNetworkSession::State oldState = state; @@ -629,12 +610,12 @@ void QNetworkSessionPrivate::updateStateFromServiceNetwork() if (activeConfig != config) { activeConfig = config; - emit q->newConfigurationActivated(); + emit newConfigurationActivated(); } state = QNetworkSession::Connected; if (state != oldState) - emit q->stateChanged(state); + emit stateChanged(state); return; } @@ -645,33 +626,33 @@ void QNetworkSessionPrivate::updateStateFromServiceNetwork() state = QNetworkSession::Disconnected; if (state != oldState) - emit q->stateChanged(state); + emit stateChanged(state); } -void QNetworkSessionPrivate::clearConfiguration(QNetworkConfiguration &config) +void QNetworkSessionPrivateImpl::clearConfiguration(QNetworkConfiguration &config) { - config.d->network_id.clear(); - config.d->iap_type.clear(); - config.d->network_attrs = 0; - config.d->service_type.clear(); - config.d->service_id.clear(); - config.d->service_attrs = 0; + toIcdConfig(privateConfiguration(config))->network_id.clear(); + toIcdConfig(privateConfiguration(config))->iap_type.clear(); + toIcdConfig(privateConfiguration(config))->network_attrs = 0; + toIcdConfig(privateConfiguration(config))->service_type.clear(); + toIcdConfig(privateConfiguration(config))->service_id.clear(); + toIcdConfig(privateConfiguration(config))->service_attrs = 0; } -void QNetworkSessionPrivate::updateStateFromActiveConfig() +void QNetworkSessionPrivateImpl::updateStateFromActiveConfig() { QNetworkSession::State oldState = state; bool newActive = false; - if (!activeConfig.d.data()) + if (!privateConfiguration(activeConfig)) return; if (!activeConfig.isValid()) { state = QNetworkSession::Invalid; - clearConfiguration(activeConfig); + clearConfiguration(activeConfig); } else if ((activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { state = QNetworkSession::Connected; newActive = opened; @@ -681,7 +662,7 @@ void QNetworkSessionPrivate::updateStateFromActiveConfig() state = QNetworkSession::NotAvailable; } else if ((activeConfig.state() & QNetworkConfiguration::Undefined) == QNetworkConfiguration::Undefined) { state = QNetworkSession::NotAvailable; - clearConfiguration(activeConfig); + //clearConfiguration(activeConfig); } bool oldActive = isOpen; @@ -691,17 +672,17 @@ void QNetworkSessionPrivate::updateStateFromActiveConfig() emit quitPendingWaitsForOpened(); if (oldActive && !isOpen) - emit q->closed(); + emit closed(); if (oldState != state) { - emit q->stateChanged(state); + emit stateChanged(state); if (state == QNetworkSession::Disconnected) { #ifdef BEARER_MANAGEMENT_DEBUG //qDebug()<<"session aborted error emitted for"<<activeConfig.identifier(); #endif lastError = QNetworkSession::SessionAbortedError; - emit q->error(lastError); + emit QNetworkSessionPrivate::error(lastError); } } @@ -711,7 +692,7 @@ void QNetworkSessionPrivate::updateStateFromActiveConfig() } -void QNetworkSessionPrivate::configurationChanged(const QNetworkConfiguration &config) +void QNetworkSessionPrivateImpl::configurationChanged(const QNetworkConfiguration &config) { if (serviceConfig.isValid() && (config == serviceConfig || config == activeConfig)) updateStateFromServiceNetwork(); @@ -771,11 +752,11 @@ static QString get_network_interface() } -void QNetworkSessionPrivate::open() +void QNetworkSessionPrivateImpl::open() { if (serviceConfig.isValid()) { lastError = QNetworkSession::OperationNotSupportedError; - emit q->error(lastError); + emit QNetworkSessionPrivate::error(lastError); } else if (!isOpen) { if (publicConfig.type() == QNetworkConfiguration::UserChoice) { @@ -786,7 +767,7 @@ void QNetworkSessionPrivate::open() */ opened = true; state = QNetworkSession::Connecting; - emit q->stateChanged(state); + emit stateChanged(state); QTimer::singleShot(0, this, SLOT(do_open())); return; } @@ -797,14 +778,14 @@ void QNetworkSessionPrivate::open() if ((activeConfig.state() & QNetworkConfiguration::Discovered) != QNetworkConfiguration::Discovered) { lastError =QNetworkSession::InvalidConfigurationError; - emit q->error(lastError); + emit QNetworkSessionPrivate::error(lastError); return; } opened = true; if ((activeConfig.state() & QNetworkConfiguration::Active) != QNetworkConfiguration::Active) { state = QNetworkSession::Connecting; - emit q->stateChanged(state); + emit stateChanged(state); QTimer::singleShot(0, this, SLOT(do_open())); return; @@ -820,7 +801,7 @@ void QNetworkSessionPrivate::open() } -void QNetworkSessionPrivate::do_open() +void QNetworkSessionPrivateImpl::do_open() { icd_connection_flags flags = connectFlags; bool st; @@ -831,7 +812,7 @@ void QNetworkSessionPrivate::do_open() #ifdef BEARER_MANAGEMENT_DEBUG qDebug() << "Already connected to" << activeConfig.identifier(); #endif - emit q->stateChanged(QNetworkSession::Connected); + emit stateChanged(QNetworkSession::Connected); emit quitPendingWaitsForOpened(); return; } @@ -854,15 +835,15 @@ void QNetworkSessionPrivate::do_open() QList<Maemo::ConnectParams> params; Maemo::ConnectParams param; - param.connect.service_type = config.d->service_type; - param.connect.service_attrs = config.d->service_attrs; - param.connect.service_id = config.d->service_id; - param.connect.network_type = config.d->iap_type; - param.connect.network_attrs = config.d->network_attrs; - if (config.d->network_attrs & ICD_NW_ATTR_IAPNAME) + param.connect.service_type = toIcdConfig(privateConfiguration(config))->service_type; + param.connect.service_attrs = toIcdConfig(privateConfiguration(config))->service_attrs; + param.connect.service_id = toIcdConfig(privateConfiguration(config))->service_id; + param.connect.network_type = toIcdConfig(privateConfiguration(config))->iap_type; + param.connect.network_attrs = toIcdConfig(privateConfiguration(config))->network_attrs; + if (toIcdConfig(privateConfiguration(config))->network_attrs & ICD_NW_ATTR_IAPNAME) param.connect.network_id = QByteArray(iap.toLatin1()); else - param.connect.network_id = config.d->network_id; + param.connect.network_id = toIcdConfig(privateConfiguration(config))->network_id; params.append(param); #ifdef BEARER_MANAGEMENT_DEBUG @@ -887,7 +868,7 @@ void QNetworkSessionPrivate::do_open() #endif updateState(QNetworkSession::Disconnected); emit quitPendingWaitsForOpened(); - emit q->error(QNetworkSession::InvalidConfigurationError); + emit QNetworkSessionPrivate::error(QNetworkSession::InvalidConfigurationError); if (publicConfig.type() == QNetworkConfiguration::UserChoice) cleanupAnyConfiguration(); return; @@ -902,30 +883,30 @@ void QNetworkSessionPrivate::do_open() (connected_iap != config.identifier())) { updateState(QNetworkSession::Disconnected); emit quitPendingWaitsForOpened(); - emit q->error(QNetworkSession::InvalidConfigurationError); + emit QNetworkSessionPrivate::error(QNetworkSession::InvalidConfigurationError); return; } /* Did we connect to non saved IAP? */ - if (!(config.d->network_attrs & ICD_NW_ATTR_IAPNAME)) { + if (!(toIcdConfig(privateConfiguration(config))->network_attrs & ICD_NW_ATTR_IAPNAME)) { /* Because the connection succeeded, the IAP is now known. */ - config.d->network_attrs |= ICD_NW_ATTR_IAPNAME; - config.d->id = connected_iap; + toIcdConfig(privateConfiguration(config))->network_attrs |= ICD_NW_ATTR_IAPNAME; + privateConfiguration(config)->id = connected_iap; } /* User might have changed the IAP name when a new IAP was saved */ - Maemo::IAPConf iap_name(config.d->id); + Maemo::IAPConf iap_name(privateConfiguration(config)->id); QString name = iap_name.value("name").toString(); if (!name.isEmpty()) - config.d->name = name; + privateConfiguration(config)->name = name; - config.d->iap_type = connect_result.connect.network_type; + toIcdConfig(privateConfiguration(config))->iap_type = connect_result.connect.network_type; - config.d->isValid = true; - config.d->state = QNetworkConfiguration::Active; - config.d->type = QNetworkConfiguration::InternetAccessPoint; + privateConfiguration(config)->isValid = true; + privateConfiguration(config)->state = QNetworkConfiguration::Active; + privateConfiguration(config)->type = QNetworkConfiguration::InternetAccessPoint; startTime = QDateTime::currentDateTime(); updateState(QNetworkSession::Connected); @@ -933,7 +914,7 @@ void QNetworkSessionPrivate::do_open() currentNetworkInterface = get_network_interface(); #ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "connected to" << result << config.d->name << "at" << currentNetworkInterface; + qDebug() << "connected to" << result << config.name() << "at" << currentNetworkInterface; #endif /* We first check if the configuration already exists in the manager @@ -942,56 +923,18 @@ void QNetworkSessionPrivate::do_open() * from config manager list. */ - if (publicConfig.d->type == QNetworkConfiguration::UserChoice) { - -#ifdef BEARER_MANAGEMENT_DEBUG -#if 0 - QList<QNetworkConfiguration> configs; - QNetworkConfigurationManagerPrivate *conPriv = (QNetworkConfigurationManagerPrivate*)config.d.data()->manager; - QList<QString> cpsIdents = conPriv->accessPointConfigurations.keys(); - foreach( QString ii, cpsIdents) { - QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> p = - conPriv->accessPointConfigurations.value(ii); - QNetworkConfiguration pt; - pt.d = conPriv->accessPointConfigurations.value(ii); - configs << pt; - } - - int all = configs.count(); - qDebug() << "All configurations:" << all; - foreach(QNetworkConfiguration p, configs) { - qDebug() << p.name() <<": isvalid->" <<p.isValid() << " type->"<< p.type() << - " roaming->" << p.isRoamingAvailable() << "identifier->" << p.identifier() << - " purpose->" << p.purpose() << " state->" << p.state(); - } -#endif -#endif - - QNetworkConfigurationManagerPrivate *mgr = (QNetworkConfigurationManagerPrivate*)config.d.data()->manager; - if (!mgr->accessPointConfigurations.contains(result)) { - QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> ptr = config.d; - mgr->accessPointConfigurations.insert(result, ptr); - - QNetworkConfiguration item; - item.d = ptr; - emit mgr->configurationAdded(item); - -#ifdef BEARER_MANAGEMENT_DEBUG - //qDebug()<<"New configuration"<<result<<"added to manager in open"; -#endif - + if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + if (!engine->accessPointConfigurations.contains(result)) { + engine->addSessionConfiguration(privateConfiguration(config)); } else { - QExplicitlySharedDataPointer<QNetworkConfigurationPrivate> priv = mgr->accessPointConfigurations.value(result); - QNetworkConfiguration reference; - reference.d = priv; - copyConfig(config, reference, false); - config = reference; - activeConfig = reference; - mgr->configurationChanged((QNetworkConfigurationPrivate*)(config.d.data())); - -#ifdef BEARER_MANAGEMENT_DEBUG - //qDebug()<<"Existing configuration"<<result<<"updated in manager in open"; -#endif + QNetworkConfigurationPrivatePointer priv = + engine->accessPointConfigurations.value(result); + QNetworkConfiguration reference; + setPrivateConfiguration(reference, priv); + copyConfig(config, reference, false); + config = reference; + activeConfig = reference; + engine->changedSessionConfiguration(privateConfiguration(config)); } } @@ -1005,42 +948,42 @@ void QNetworkSessionPrivate::do_open() if (publicConfig.type() == QNetworkConfiguration::UserChoice) cleanupAnyConfiguration(); emit quitPendingWaitsForOpened(); - emit q->error(QNetworkSession::UnknownSessionError); + emit QNetworkSessionPrivate::error(QNetworkSession::UnknownSessionError); } } -void QNetworkSessionPrivate::cleanupAnyConfiguration() +void QNetworkSessionPrivateImpl::cleanupAnyConfiguration() { #ifdef BEARER_MANAGEMENT_DEBUG - qDebug()<<"Removing configuration created for" << activeConfig.d->id; + qDebug()<<"Removing configuration created for" << activeConfig.identifier(); #endif activeConfig = publicConfig; } -void QNetworkSessionPrivate::close() +void QNetworkSessionPrivateImpl::close() { if (serviceConfig.isValid()) { lastError = QNetworkSession::OperationNotSupportedError; - emit q->error(lastError); + emit QNetworkSessionPrivate::error(lastError); } else if (isOpen) { opened = false; isOpen = false; - emit q->closed(); + emit closed(); } } -void QNetworkSessionPrivate::stop() +void QNetworkSessionPrivateImpl::stop() { if (serviceConfig.isValid()) { lastError = QNetworkSession::OperationNotSupportedError; - emit q->error(lastError); + emit QNetworkSessionPrivate::error(lastError); } else { if ((activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { state = QNetworkSession::Closing; - emit q->stateChanged(state); + emit stateChanged(state); Maemo::Icd icd; #ifdef BEARER_MANAGEMENT_DEBUG @@ -1054,9 +997,8 @@ void QNetworkSessionPrivate::stop() * configurationChanged is emitted (below). */ - activeConfig.d->state = QNetworkConfiguration::Discovered; - QNetworkConfigurationManagerPrivate *mgr = (QNetworkConfigurationManagerPrivate*)activeConfig.d.data()->manager; - mgr->configurationChanged((QNetworkConfigurationPrivate*)activeConfig.d.data()); + privateConfiguration(activeConfig)->state = QNetworkConfiguration::Discovered; + engine->changedSessionConfiguration(privateConfiguration(activeConfig)); opened = false; isOpen = false; @@ -1064,37 +1006,37 @@ void QNetworkSessionPrivate::stop() } else { opened = false; isOpen = false; - emit q->closed(); + emit closed(); } } } -void QNetworkSessionPrivate::migrate() +void QNetworkSessionPrivateImpl::migrate() { qWarning("This platform does not support roaming (%s).", __FUNCTION__); } -void QNetworkSessionPrivate::accept() +void QNetworkSessionPrivateImpl::accept() { qWarning("This platform does not support roaming (%s).", __FUNCTION__); } -void QNetworkSessionPrivate::ignore() +void QNetworkSessionPrivateImpl::ignore() { qWarning("This platform does not support roaming (%s).", __FUNCTION__); } -void QNetworkSessionPrivate::reject() +void QNetworkSessionPrivateImpl::reject() { qWarning("This platform does not support roaming (%s).", __FUNCTION__); } -QNetworkInterface QNetworkSessionPrivate::currentInterface() const +QNetworkInterface QNetworkSessionPrivateImpl::currentInterface() const { if (!publicConfig.isValid() || state != QNetworkSession::Connected) return QNetworkInterface(); @@ -1106,7 +1048,7 @@ QNetworkInterface QNetworkSessionPrivate::currentInterface() const } -void QNetworkSessionPrivate::setSessionProperty(const QString& key, const QVariant& value) +void QNetworkSessionPrivateImpl::setSessionProperty(const QString& key, const QVariant& value) { if (value.isValid()) { properties.insert(key, value); @@ -1128,13 +1070,13 @@ void QNetworkSessionPrivate::setSessionProperty(const QString& key, const QVaria } -QVariant QNetworkSessionPrivate::sessionProperty(const QString& key) const +QVariant QNetworkSessionPrivateImpl::sessionProperty(const QString& key) const { return properties.value(key); } -QString QNetworkSessionPrivate::errorString() const +QString QNetworkSessionPrivateImpl::errorString() const { QString errorStr; switch(q->error()) { @@ -1153,12 +1095,11 @@ QString QNetworkSessionPrivate::errorString() const } -QNetworkSession::SessionError QNetworkSessionPrivate::error() const +QNetworkSession::SessionError QNetworkSessionPrivateImpl::error() const { return QNetworkSession::UnknownSessionError; } -#include "qnetworksession_maemo.moc" -#include "moc_qnetworksession_maemo_p.cpp" +#include "qnetworksession_impl.moc" QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworksession_maemo_p.h b/src/plugins/bearer/icd/qnetworksession_impl.h index ff294f6..22e41b3 100644 --- a/src/network/bearer/qnetworksession_maemo_p.h +++ b/src/plugins/bearer/icd/qnetworksession_impl.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef QNETWORKSESSIONPRIVATE_H -#define QNETWORKSESSIONPRIVATE_H +#ifndef QNETWORKSESSION_IMPL_H +#define QNETWORKSESSION_IMPL_H // // W A R N I N G @@ -52,36 +52,36 @@ // // We mean it. // -#include "qnetworkconfigmanager_maemo_p.h" -#include "qnetworksession.h" -#include <qnetworksession.h> -#include <QNetworkInterface> -#include <QDateTime> +#include <QtNetwork/private/qnetworksession_p.h> +#include <QtNetwork/qnetworkconfigmanager.h> + +//#include "qnetworkconfigmanager_maemo_p.h" +//#include "qnetworksession.h" + +//#include <qnetworksession.h> +//#include <QNetworkInterface> +#include <QtCore/qdatetime.h> -#ifdef Q_WS_MAEMO_6 #include <icd/dbus_api.h> -#endif QT_BEGIN_NAMESPACE -class QNetworkSessionPrivate : public QObject +class QIcdEngine; + +class QNetworkSessionPrivateImpl : public QNetworkSessionPrivate { Q_OBJECT + public: - QNetworkSessionPrivate() : - tx_data(0), rx_data(0), m_activeTime(0), isOpen(false), -#ifdef Q_WS_MAEMO_6 - connectFlags(ICD_CONNECTION_FLAG_USER_EVENT) -#else - connectFlags(0) -#endif + QNetworkSessionPrivateImpl(QIcdEngine *engine) + : engine(engine), connectFlags(ICD_CONNECTION_FLAG_USER_EVENT) { } - ~QNetworkSessionPrivate() + ~QNetworkSessionPrivateImpl() { - cleanupSession(); + cleanupSession(); } //called by QNetworkSession constructor and ensures @@ -97,6 +97,7 @@ public: void open(); void close(); void stop(); + void migrate(); void accept(); void ignore(); @@ -113,10 +114,6 @@ private: void updateStateFromServiceNetwork(); void updateStateFromActiveConfig(); -Q_SIGNALS: - //releases any pending waitForOpened() calls - void quitPendingWaitsForOpened(); - private Q_SLOTS: void do_open(); void networkConfigurationsChanged(); @@ -124,37 +121,17 @@ private Q_SLOTS: private: QNetworkConfigurationManager manager; - - quint64 tx_data; - quint64 rx_data; - quint64 m_activeTime; - - // The config set on QNetworkSession. - QNetworkConfiguration publicConfig; - - // If publicConfig is a ServiceNetwork this is a copy of publicConfig. - // If publicConfig is an UserChoice that is resolved to a ServiceNetwork this is the actual - // ServiceNetwork configuration. - QNetworkConfiguration serviceConfig; - - // This is the actual active configuration currently in use by the session. - // Either a copy of publicConfig or one of serviceConfig.children(). - QNetworkConfiguration activeConfig; + QIcdEngine *engine; QNetworkConfiguration& copyConfig(QNetworkConfiguration &fromConfig, QNetworkConfiguration &toConfig, bool deepCopy = true); void clearConfiguration(QNetworkConfiguration &config); void cleanupAnyConfiguration(); - QNetworkSession::State state; - bool isOpen; bool opened; icd_connection_flags connectFlags; QNetworkSession::SessionError lastError; - QNetworkSession* q; - friend class QNetworkSession; - QDateTime startTime; QString currentNetworkInterface; friend class IcdListener; |