From 0f31f63e11d4fcb2b399979de28368a89275b911 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 22 Dec 2009 12:17:58 +1000 Subject: Bearer Management Integration 1. --- config.tests/mac/corelwan/corewlan.pro | 4 + config.tests/mac/corelwan/corewlantest.mm | 49 + config.tests/unix/networkmanager/main.cpp | 47 + .../unix/networkmanager/networkmanager.pro | 11 + examples/network/bearercloud/bearercloud.cpp | 197 ++++ examples/network/bearercloud/bearercloud.h | 81 ++ examples/network/bearercloud/bearercloud.pro | 30 + examples/network/bearercloud/cloud.cpp | 361 ++++++ examples/network/bearercloud/cloud.h | 97 ++ examples/network/bearercloud/icons.qrc | 7 + examples/network/bearercloud/lan.svg | 76 ++ examples/network/bearercloud/main.cpp | 89 ++ examples/network/bearercloud/unknown.svg | 76 ++ examples/network/bearercloud/wlan.svg | 151 +++ examples/network/bearermonitor/bearermonitor.cpp | 395 +++++++ examples/network/bearermonitor/bearermonitor.h | 92 ++ examples/network/bearermonitor/bearermonitor.pro | 32 + .../network/bearermonitor/bearermonitor_240_320.ui | 420 +++++++ .../network/bearermonitor/bearermonitor_640_480.ui | 386 +++++++ examples/network/bearermonitor/main.cpp | 55 + examples/network/bearermonitor/sessionwidget.cpp | 156 +++ examples/network/bearermonitor/sessionwidget.h | 75 ++ examples/network/bearermonitor/sessionwidget.ui | 251 +++++ src/network/bearer/bearer.pro | 163 +++ src/network/bearer/qcorewlanengine_mac.mm | 461 ++++++++ src/network/bearer/qcorewlanengine_mac_p.h | 100 ++ src/network/bearer/qgenericengine.cpp | 234 ++++ src/network/bearer/qgenericengine_p.h | 94 ++ src/network/bearer/qnativewifiengine_win.cpp | 726 ++++++++++++ src/network/bearer/qnativewifiengine_win_p.h | 95 ++ src/network/bearer/qnetworkconfigmanager.cpp | 333 ++++++ src/network/bearer/qnetworkconfigmanager.h | 101 ++ src/network/bearer/qnetworkconfigmanager_maemo.cpp | 760 +++++++++++++ src/network/bearer/qnetworkconfigmanager_maemo_p.h | 141 +++ src/network/bearer/qnetworkconfigmanager_p.cpp | 450 ++++++++ src/network/bearer/qnetworkconfigmanager_p.h | 178 +++ src/network/bearer/qnetworkconfigmanager_s60_p.cpp | 974 ++++++++++++++++ src/network/bearer/qnetworkconfigmanager_s60_p.h | 182 +++ src/network/bearer/qnetworkconfiguration.cpp | 349 ++++++ src/network/bearer/qnetworkconfiguration.h | 113 ++ src/network/bearer/qnetworkconfiguration_maemo_p.h | 109 ++ src/network/bearer/qnetworkconfiguration_p.h | 104 ++ src/network/bearer/qnetworkconfiguration_s60_p.cpp | 60 + src/network/bearer/qnetworkconfiguration_s60_p.h | 108 ++ src/network/bearer/qnetworkmanagerservice_p.cpp | 1011 +++++++++++++++++ src/network/bearer/qnetworkmanagerservice_p.h | 400 +++++++ src/network/bearer/qnetworksession.cpp | 689 ++++++++++++ src/network/bearer/qnetworksession.h | 135 +++ src/network/bearer/qnetworksession_maemo.cpp | 1181 ++++++++++++++++++++ src/network/bearer/qnetworksession_maemo_p.h | 167 +++ src/network/bearer/qnetworksession_p.cpp | 542 +++++++++ src/network/bearer/qnetworksession_p.h | 167 +++ src/network/bearer/qnetworksession_s60_p.cpp | 1168 +++++++++++++++++++ src/network/bearer/qnetworksession_s60_p.h | 213 ++++ src/network/bearer/qnetworksessionengine.cpp | 57 + src/network/bearer/qnetworksessionengine_p.h | 98 ++ src/network/bearer/qnetworksessionengine_win_p.h | 145 +++ src/network/bearer/qnlaengine_win.cpp | 592 ++++++++++ src/network/bearer/qnlaengine_win_p.h | 104 ++ src/network/bearer/qnmdbushelper.cpp | 117 ++ src/network/bearer/qnmdbushelper_p.h | 90 ++ src/network/bearer/qnmwifiengine_unix.cpp | 1133 +++++++++++++++++++ src/network/bearer/qnmwifiengine_unix_p.h | 164 +++ tests/auto/qbearertestcommon.h | 74 ++ .../qnetworkconfigmanager.pro | 15 + .../tst_qnetworkconfigmanager.cpp | 335 ++++++ .../qnetworkconfiguration.pro | 15 + .../tst_qnetworkconfiguration.cpp | 303 +++++ tests/auto/qnetworksession/lackey/lackey.pro | 12 + tests/auto/qnetworksession/lackey/main.cpp | 138 +++ tests/auto/qnetworksession/qnetworksession.pro | 2 + .../tst_qnetworksession/tst_qnetworksession.cpp | 873 +++++++++++++++ .../tst_qnetworksession/tst_qnetworksession.pro | 21 + tests/manual/bearerex/bearerex.cpp | 565 ++++++++++ tests/manual/bearerex/bearerex.h | 138 +++ tests/manual/bearerex/bearerex.pro | 34 + tests/manual/bearerex/bearerex.ui | 95 ++ tests/manual/bearerex/detailedinfodialog.ui | 54 + tests/manual/bearerex/main.cpp | 58 + tests/manual/bearerex/sessiondialog.ui | 139 +++ tests/manual/bearerex/xqlistwidget.cpp | 66 ++ tests/manual/bearerex/xqlistwidget.h | 58 + tests/manual/networkmanager/README | 2 + tests/manual/networkmanager/dialog.ui | 213 ++++ tests/manual/networkmanager/networkmanager.pro | 19 + tests/manual/networkmanager/networkmanagertest.cpp | 287 +++++ tests/manual/networkmanager/nmview.cpp | 1030 +++++++++++++++++ tests/manual/networkmanager/nmview.h | 107 ++ tests/manual/networkmanager/startdlg.cpp | 95 ++ tests/manual/networkmanager/startdlg.h | 58 + 90 files changed, 21952 insertions(+) create mode 100644 config.tests/mac/corelwan/corewlan.pro create mode 100644 config.tests/mac/corelwan/corewlantest.mm create mode 100644 config.tests/unix/networkmanager/main.cpp create mode 100644 config.tests/unix/networkmanager/networkmanager.pro create mode 100644 examples/network/bearercloud/bearercloud.cpp create mode 100644 examples/network/bearercloud/bearercloud.h create mode 100644 examples/network/bearercloud/bearercloud.pro create mode 100644 examples/network/bearercloud/cloud.cpp create mode 100644 examples/network/bearercloud/cloud.h create mode 100644 examples/network/bearercloud/icons.qrc create mode 100644 examples/network/bearercloud/lan.svg create mode 100644 examples/network/bearercloud/main.cpp create mode 100644 examples/network/bearercloud/unknown.svg create mode 100644 examples/network/bearercloud/wlan.svg create mode 100644 examples/network/bearermonitor/bearermonitor.cpp create mode 100644 examples/network/bearermonitor/bearermonitor.h create mode 100644 examples/network/bearermonitor/bearermonitor.pro create mode 100644 examples/network/bearermonitor/bearermonitor_240_320.ui create mode 100644 examples/network/bearermonitor/bearermonitor_640_480.ui create mode 100644 examples/network/bearermonitor/main.cpp create mode 100644 examples/network/bearermonitor/sessionwidget.cpp create mode 100644 examples/network/bearermonitor/sessionwidget.h create mode 100644 examples/network/bearermonitor/sessionwidget.ui create mode 100644 src/network/bearer/bearer.pro create mode 100644 src/network/bearer/qcorewlanengine_mac.mm create mode 100644 src/network/bearer/qcorewlanengine_mac_p.h create mode 100644 src/network/bearer/qgenericengine.cpp create mode 100644 src/network/bearer/qgenericengine_p.h create mode 100644 src/network/bearer/qnativewifiengine_win.cpp create mode 100644 src/network/bearer/qnativewifiengine_win_p.h create mode 100644 src/network/bearer/qnetworkconfigmanager.cpp create mode 100644 src/network/bearer/qnetworkconfigmanager.h create mode 100644 src/network/bearer/qnetworkconfigmanager_maemo.cpp create mode 100644 src/network/bearer/qnetworkconfigmanager_maemo_p.h create mode 100644 src/network/bearer/qnetworkconfigmanager_p.cpp create mode 100644 src/network/bearer/qnetworkconfigmanager_p.h create mode 100644 src/network/bearer/qnetworkconfigmanager_s60_p.cpp create mode 100644 src/network/bearer/qnetworkconfigmanager_s60_p.h create mode 100644 src/network/bearer/qnetworkconfiguration.cpp create mode 100644 src/network/bearer/qnetworkconfiguration.h create mode 100644 src/network/bearer/qnetworkconfiguration_maemo_p.h create mode 100644 src/network/bearer/qnetworkconfiguration_p.h create mode 100644 src/network/bearer/qnetworkconfiguration_s60_p.cpp create mode 100644 src/network/bearer/qnetworkconfiguration_s60_p.h create mode 100644 src/network/bearer/qnetworkmanagerservice_p.cpp create mode 100644 src/network/bearer/qnetworkmanagerservice_p.h create mode 100644 src/network/bearer/qnetworksession.cpp create mode 100644 src/network/bearer/qnetworksession.h create mode 100644 src/network/bearer/qnetworksession_maemo.cpp create mode 100644 src/network/bearer/qnetworksession_maemo_p.h create mode 100644 src/network/bearer/qnetworksession_p.cpp create mode 100644 src/network/bearer/qnetworksession_p.h create mode 100644 src/network/bearer/qnetworksession_s60_p.cpp create mode 100644 src/network/bearer/qnetworksession_s60_p.h create mode 100644 src/network/bearer/qnetworksessionengine.cpp create mode 100644 src/network/bearer/qnetworksessionengine_p.h create mode 100644 src/network/bearer/qnetworksessionengine_win_p.h create mode 100644 src/network/bearer/qnlaengine_win.cpp create mode 100644 src/network/bearer/qnlaengine_win_p.h create mode 100644 src/network/bearer/qnmdbushelper.cpp create mode 100644 src/network/bearer/qnmdbushelper_p.h create mode 100644 src/network/bearer/qnmwifiengine_unix.cpp create mode 100644 src/network/bearer/qnmwifiengine_unix_p.h create mode 100644 tests/auto/qbearertestcommon.h create mode 100644 tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro create mode 100644 tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp create mode 100644 tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro create mode 100644 tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp create mode 100644 tests/auto/qnetworksession/lackey/lackey.pro create mode 100644 tests/auto/qnetworksession/lackey/main.cpp create mode 100644 tests/auto/qnetworksession/qnetworksession.pro create mode 100644 tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp create mode 100644 tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro create mode 100644 tests/manual/bearerex/bearerex.cpp create mode 100644 tests/manual/bearerex/bearerex.h create mode 100644 tests/manual/bearerex/bearerex.pro create mode 100644 tests/manual/bearerex/bearerex.ui create mode 100644 tests/manual/bearerex/detailedinfodialog.ui create mode 100644 tests/manual/bearerex/main.cpp create mode 100644 tests/manual/bearerex/sessiondialog.ui create mode 100644 tests/manual/bearerex/xqlistwidget.cpp create mode 100644 tests/manual/bearerex/xqlistwidget.h create mode 100644 tests/manual/networkmanager/README create mode 100644 tests/manual/networkmanager/dialog.ui create mode 100644 tests/manual/networkmanager/networkmanager.pro create mode 100644 tests/manual/networkmanager/networkmanagertest.cpp create mode 100644 tests/manual/networkmanager/nmview.cpp create mode 100644 tests/manual/networkmanager/nmview.h create mode 100644 tests/manual/networkmanager/startdlg.cpp create mode 100644 tests/manual/networkmanager/startdlg.h diff --git a/config.tests/mac/corelwan/corewlan.pro b/config.tests/mac/corelwan/corewlan.pro new file mode 100644 index 0000000..54a6c36 --- /dev/null +++ b/config.tests/mac/corelwan/corewlan.pro @@ -0,0 +1,4 @@ +SOURCES=corewlantest.mm +TARGET=corewlan +LIBS += -framework CoreWLAN -framework Foundation +CONFIG-=app_bundle diff --git a/config.tests/mac/corelwan/corewlantest.mm b/config.tests/mac/corelwan/corewlantest.mm new file mode 100644 index 0000000..bcddf44 --- /dev/null +++ b/config.tests/mac/corelwan/corewlantest.mm @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 +#include + +int main() +{ + [CWInterface interfaceWithName:@"en2"]; + return 0; +} diff --git a/config.tests/unix/networkmanager/main.cpp b/config.tests/unix/networkmanager/main.cpp new file mode 100644 index 0000000..6f2bae6 --- /dev/null +++ b/config.tests/unix/networkmanager/main.cpp @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 + +int main(int argc, char** argv) +{ + return 0; +} diff --git a/config.tests/unix/networkmanager/networkmanager.pro b/config.tests/unix/networkmanager/networkmanager.pro new file mode 100644 index 0000000..554f513 --- /dev/null +++ b/config.tests/unix/networkmanager/networkmanager.pro @@ -0,0 +1,11 @@ +###################################################################### +# Automatically generated by qmake (2.01a) Mon Oct 19 12:58:26 2009 +###################################################################### + +TEMPLATE = app +TARGET = +DEPENDPATH += . +INCLUDEPATH += . + +# Input +SOURCES += main.cpp diff --git a/examples/network/bearercloud/bearercloud.cpp b/examples/network/bearercloud/bearercloud.cpp new file mode 100644 index 0000000..182d4ec --- /dev/null +++ b/examples/network/bearercloud/bearercloud.cpp @@ -0,0 +1,197 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 "bearercloud.h" +#include "cloud.h" + +#include +#include +#include +#include + +#include + +#include + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +//! [0] +BearerCloud::BearerCloud(QObject *parent) +: QGraphicsScene(parent), timerId(0) +{ + setSceneRect(-300, -300, 600, 600); + + qsrand(QDateTime::currentDateTime().toTime_t()); + + offset[QNetworkConfiguration::Active] = 2 * M_PI * qrand() / RAND_MAX; + offset[QNetworkConfiguration::Discovered] = offset[QNetworkConfiguration::Active] + M_PI / 6; + offset[QNetworkConfiguration::Defined] = offset[QNetworkConfiguration::Discovered] - M_PI / 6; + offset[QNetworkConfiguration::Undefined] = offset[QNetworkConfiguration::Undefined] + M_PI / 6; + + thisDevice = new QGraphicsTextItem(QHostInfo::localHostName()); + thisDevice->setData(0, QLatin1String("This Device")); + thisDevice->setPos(thisDevice->boundingRect().width() / -2, + thisDevice->boundingRect().height() / -2); + addItem(thisDevice); + + qreal radius = Cloud::getRadiusForState(QNetworkConfiguration::Active); + QGraphicsEllipseItem *orbit = new QGraphicsEllipseItem(-radius, -radius, 2*radius, 2*radius); + orbit->setPen(QColor(Qt::green)); + addItem(orbit); + radius = Cloud::getRadiusForState(QNetworkConfiguration::Discovered); + orbit = new QGraphicsEllipseItem(-radius, -radius, 2*radius, 2*radius); + orbit->setPen(QColor(Qt::blue)); + addItem(orbit); + radius = Cloud::getRadiusForState(QNetworkConfiguration::Defined); + orbit = new QGraphicsEllipseItem(-radius, -radius, 2*radius, 2*radius); + orbit->setPen(QColor(Qt::darkGray)); + addItem(orbit); + radius = Cloud::getRadiusForState(QNetworkConfiguration::Undefined); + orbit = new QGraphicsEllipseItem(-radius, -radius, 2*radius, 2*radius); + orbit->setPen(QColor(Qt::lightGray)); + addItem(orbit); + + connect(&manager, SIGNAL(configurationAdded(QNetworkConfiguration)), + this, SLOT(configurationAdded(QNetworkConfiguration))); + connect(&manager, SIGNAL(configurationRemoved(QNetworkConfiguration)), + this, SLOT(configurationRemoved(QNetworkConfiguration))); + connect(&manager, SIGNAL(configurationChanged(QNetworkConfiguration)), + this, SLOT(configurationChanged(QNetworkConfiguration))); + + QTimer::singleShot(0, this, SLOT(updateConfigurations())); +} +//! [0] + +BearerCloud::~BearerCloud() +{ +} + +void BearerCloud::cloudMoved() +{ + if (!timerId) + timerId = startTimer(1000 / 25); +} + +void BearerCloud::timerEvent(QTimerEvent *) +{ + QList clouds; + foreach (QGraphicsItem *item, items()) { + if (Cloud *cloud = qgraphicsitem_cast(item)) + clouds << cloud; + } + + foreach (Cloud *cloud, clouds) + cloud->calculateForces(); + + bool cloudsMoved = false; + foreach (Cloud *cloud, clouds) + cloudsMoved |= cloud->advance(); + + if (!cloudsMoved) { + killTimer(timerId); + timerId = 0; + } +} + +//! [2] +void BearerCloud::configurationAdded(const QNetworkConfiguration &config) +{ + const QNetworkConfiguration::StateFlags state = config.state(); + + configStates.insert(state, config.identifier()); + + const qreal radius = Cloud::getRadiusForState(state); + const int count = configStates.count(state); + const qreal angle = 2 * M_PI / count; + + Cloud *item = new Cloud(config); + configurations.insert(config.identifier(), item); + + item->setPos(radius * cos((count-1) * angle + offset[state]), + radius * sin((count-1) * angle + offset[state])); + + addItem(item); + + cloudMoved(); +} +//! [2] + +//! [3] +void BearerCloud::configurationRemoved(const QNetworkConfiguration &config) +{ + foreach (const QNetworkConfiguration::StateFlags &state, configStates.uniqueKeys()) + configStates.remove(state, config.identifier()); + + Cloud *item = configurations.take(config.identifier()); + + item->setFinalScale(0.0); + item->setDeleteAfterAnimation(true); + + cloudMoved(); +} +//! [3] + +//! [4] +void BearerCloud::configurationChanged(const QNetworkConfiguration &config) +{ + foreach (const QNetworkConfiguration::StateFlags &state, configStates.uniqueKeys()) + configStates.remove(state, config.identifier()); + + configStates.insert(config.state(), config.identifier()); + + cloudMoved(); +} +//! [4] + +//! [1] +void BearerCloud::updateConfigurations() +{ + QList allConfigurations = manager.allConfigurations(); + + while (!allConfigurations.isEmpty()) + configurationAdded(allConfigurations.takeFirst()); + + cloudMoved(); +} +//! [1] + diff --git a/examples/network/bearercloud/bearercloud.h b/examples/network/bearercloud/bearercloud.h new file mode 100644 index 0000000..c18ffd3 --- /dev/null +++ b/examples/network/bearercloud/bearercloud.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 + +#include +#include +#include + +QTM_USE_NAMESPACE + +class Cloud; + +class BearerCloud : public QGraphicsScene +{ + Q_OBJECT + +public: + BearerCloud(QObject *parent = 0); + ~BearerCloud(); + + void cloudMoved(); + + void timerEvent(QTimerEvent *event); + +private Q_SLOTS: + void configurationAdded(const QNetworkConfiguration &config); + void configurationRemoved(const QNetworkConfiguration &config); + void configurationChanged(const QNetworkConfiguration &config); + void updateConfigurations(); + +private: + QNetworkConfigurationManager manager; + + QGraphicsTextItem *thisDevice; + QHash configurations; + + QMap offset; + QMultiMap configStates; + + int timerId; +}; + diff --git a/examples/network/bearercloud/bearercloud.pro b/examples/network/bearercloud/bearercloud.pro new file mode 100644 index 0000000..308ddda --- /dev/null +++ b/examples/network/bearercloud/bearercloud.pro @@ -0,0 +1,30 @@ +HEADERS = bearercloud.h \ + cloud.h + +SOURCES = main.cpp \ + bearercloud.cpp \ + cloud.cpp + +RESOURCES = icons.qrc + +TARGET = bearercloud + +QT = core gui network svg + +INCLUDEPATH += ../../src/bearer + +include(../examples.pri) + +qtAddLibrary(QtBearer) + +CONFIG += console + +include(../examples.pri) + + +macx: { + contains(QT_CONFIG,qt_framework):LIBS += -framework QtBearer + INCLUDEPATH += ../../ + contains(CONFIG, debug) { + } +} diff --git a/examples/network/bearercloud/cloud.cpp b/examples/network/bearercloud/cloud.cpp new file mode 100644 index 0000000..4a1bde7 --- /dev/null +++ b/examples/network/bearercloud/cloud.cpp @@ -0,0 +1,361 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 "cloud.h" +#include "bearercloud.h" + +#include + +#include +#include +#include +#include +#include + +#include + +#include + +static QMap svgCache; + +//! [0] +Cloud::Cloud(const QNetworkConfiguration &config, QGraphicsItem *parent) +: QGraphicsItem(parent), configuration(config), deleteAfterAnimation(false) +{ + session = new QNetworkSession(configuration, this); + connect(session, SIGNAL(newConfigurationActivated()), + this, SLOT(newConfigurationActivated())); + connect(session, SIGNAL(stateChanged(QNetworkSession::State)), + this, SLOT(stateChanged(QNetworkSession::State))); + + setFlag(ItemIsMovable); +#if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)) + setFlag(ItemSendsGeometryChanges); +#endif + setZValue(1); + + icon = new QGraphicsSvgItem(this); + text = new QGraphicsTextItem(this); + + currentScale = 0; + finalScale = 1; + setTransform(QTransform::fromScale(currentScale, currentScale), false); + setOpacity(0); + + newConfigurationActivated(); +} +//! [0] + +Cloud::~Cloud() +{ +} + +void Cloud::setFinalScale(qreal factor) +{ + finalScale = factor; +} + +void Cloud::setDeleteAfterAnimation(bool deleteAfter) +{ + deleteAfterAnimation = deleteAfter; +} + +void Cloud::calculateForces() +{ + if (!scene() || scene()->mouseGrabberItem() == this) { + newPos = pos(); + return; + } + + // sum up all the forces push this item away + qreal xvel = 0; + qreal yvel = 0; + QLineF orbitForce; + foreach (QGraphicsItem *item, scene()->items()) { + // other clouds + Cloud *cloud = qgraphicsitem_cast(item); + if (!cloud && item->data(0) != QLatin1String("This Device")) + continue; + + qreal factor = 1.0; + + QLineF line(cloud ? item->mapToScene(0, 0) : QPointF(0, 0), mapToScene(0, 0)); + if (item->data(0) == QLatin1String("This Device")) + orbitForce = line; + + if (cloud) + factor = cloud->currentScale; + + qreal dx = line.dx(); + qreal dy = line.dy(); + double l = 2.0 * (dx * dx + dy * dy); + if (l > 0) { + xvel += factor * dx * 200.0 / l; + yvel += factor * dy * 200.0 / l; + } + } + + // tendency to stay at a fixed orbit + qreal orbit = getRadiusForState(configuration.state()); + qreal distance = orbitForce.length(); + + QLineF unit = orbitForce.unitVector(); + + orbitForce.setLength(xvel * unit.dx() + yvel * unit.dy()); + + qreal w = 2 - exp(-pow(distance-orbit, 2)/(2 * 50)); + + if (distance < orbit) { + xvel += orbitForce.dx() * w; + yvel += orbitForce.dy() * w; + } else { + xvel -= orbitForce.dx() * w; + yvel -= orbitForce.dy() * w; + } + + if (qAbs(xvel) < 0.1 && qAbs(yvel) < 0.1) + xvel = yvel = 0; + + QRectF sceneRect = scene()->sceneRect(); + newPos = pos() + QPointF(xvel, yvel); + newPos.setX(qMin(qMax(newPos.x(), sceneRect.left() + 10), sceneRect.right() - 10)); + newPos.setY(qMin(qMax(newPos.y(), sceneRect.top() + 10), sceneRect.bottom() - 10)); +} + +bool Cloud::advance() +{ + static const qreal scaleDelta = 0.01; + + bool animated = false; + + if (currentScale < finalScale) { + animated = true; + currentScale = qMin(currentScale + scaleDelta, finalScale); + setTransform(QTransform::fromScale(currentScale, currentScale), false); + } else if (currentScale > finalScale) { + animated = true; + currentScale = qMax(currentScale - scaleDelta, finalScale); + setTransform(QTransform::fromScale(currentScale, currentScale), false); + } + + if (newPos != pos()) { + setPos(newPos); + animated = true; + } + + if (opacity() != finalOpacity) { + animated = true; + if (qAbs(finalScale - currentScale) > 0.0) { + // use scale as reference + setOpacity(opacity() + scaleDelta * (finalOpacity - opacity()) / + qAbs(finalScale - currentScale)); + } else { + setOpacity(finalOpacity); + } + } + + if (!animated && deleteAfterAnimation) + deleteLater(); + + return animated; +} + +QRectF Cloud::boundingRect() const +{ + return childrenBoundingRect(); +} + +void Cloud::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) +{ +} + +//! [4] +QVariant Cloud::itemChange(GraphicsItemChange change, const QVariant &value) +{ + switch (change) { + case ItemPositionHasChanged: + if (BearerCloud *bearercloud = qobject_cast(scene())) + bearercloud->cloudMoved(); + default: + ; + }; + + return QGraphicsItem::itemChange(change, value); +} +//! [4] + +//! [3] +void Cloud::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) { + if (session->isActive()) + session->close(); + else + session->open(); + + event->accept(); + } +} +//! [3] + +//! [2] +void Cloud::stateChanged(QNetworkSession::State state) +{ + if (configuration.name().isEmpty()) + finalOpacity = qreal(0.1); + else if (session->state() == QNetworkSession::NotAvailable) + finalOpacity = 0.5; + else + finalOpacity = 1.0; + + QString tooltip; + + if (configuration.name().isEmpty()) + tooltip += tr("HIDDEN NETWORK
"); + else + tooltip += tr("%1
").arg(configuration.name()); + + const QNetworkInterface interface = session->interface(); + if (interface.isValid()) + tooltip += tr("
Interface: %1").arg(interface.humanReadableName()); + tooltip += tr("
Id: %1").arg(configuration.identifier()); + + const QString bearerName = session->bearerName(); + if (!bearerName.isEmpty()) + tooltip += tr("
Bearer: %1").arg(bearerName); + + QString s = tr("
State: %1 (%2)"); + switch (state) { + case QNetworkSession::Invalid: + s = s.arg(tr("Invalid")); + break; + case QNetworkSession::NotAvailable: + s = s.arg(tr("Not Available")); + break; + case QNetworkSession::Connecting: + s = s.arg(tr("Connecting")); + break; + case QNetworkSession::Connected: + s = s.arg(tr("Connected")); + break; + case QNetworkSession::Closing: + s = s.arg(tr("Closing")); + break; + case QNetworkSession::Disconnected: + s = s.arg(tr("Disconnected")); + break; + case QNetworkSession::Roaming: + s = s.arg(tr("Roaming")); + break; + default: + s = s.arg(tr("Unknown")); + } + + if (session->isActive()) + s = s.arg(tr("Active")); + else + s = s.arg(tr("Inactive")); + + tooltip += s; + + tooltip += tr("

Active time: %1 seconds").arg(session->activeTime()); + tooltip += tr("
Received data: %1 bytes").arg(session->bytesReceived()); + tooltip += tr("
Sent data: %1 bytes").arg(session->bytesWritten()); + + setToolTip(tooltip); +} +//! [2] + +//! [1] +void Cloud::newConfigurationActivated() +{ + const QString bearerName = session->bearerName(); + if (!svgCache.contains(bearerName)) { + if (bearerName == QLatin1String("WLAN")) + svgCache.insert(bearerName, new QSvgRenderer(QLatin1String(":wlan.svg"))); + else if (bearerName == QLatin1String("Ethernet")) + svgCache.insert(bearerName, new QSvgRenderer(QLatin1String(":lan.svg"))); + else + svgCache.insert(bearerName, new QSvgRenderer(QLatin1String(":unknown.svg"))); + } + + icon->setSharedRenderer(svgCache[bearerName]); + + if (configuration.name().isEmpty()) { + text->setPlainText(tr("HIDDEN NETWORK")); + } else { + if (configuration.type() == QNetworkConfiguration::ServiceNetwork) + text->setHtml("" + configuration.name() + ""); + else + text->setPlainText(configuration.name()); + } + + const qreal height = icon->boundingRect().height() + text->boundingRect().height(); + + icon->setPos(icon->boundingRect().width() / -2, height / -2); + + text->setPos(text->boundingRect().width() / -2, + height / 2 - text->boundingRect().height()); + + stateChanged(session->state()); +} +//! [1] + +qreal Cloud::getRadiusForState(QNetworkConfiguration::StateFlags state) +{ + switch (state) { + case QNetworkConfiguration::Active: + return 100; + break; + case QNetworkConfiguration::Discovered: + return 150; + break; + case QNetworkConfiguration::Defined: + return 200; + break; + case QNetworkConfiguration::Undefined: + return 250; + break; + default: + return 300; + } +} + diff --git a/examples/network/bearercloud/cloud.h b/examples/network/bearercloud/cloud.h new file mode 100644 index 0000000..4ce43df --- /dev/null +++ b/examples/network/bearercloud/cloud.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 +#include + +#include +QTM_USE_NAMESPACE + +class QGraphicsTextItem; +class QGraphicsSvgItem; + +class Cloud : public QObject, public QGraphicsItem +{ + Q_OBJECT + Q_INTERFACES(QGraphicsItem) + +public: + Cloud(const QNetworkConfiguration &config, QGraphicsItem *parent = 0); + ~Cloud(); + + enum { Type = UserType + 1 }; + int type() const { return Type; } + + void setFinalScale(qreal factor); + void setDeleteAfterAnimation(bool deleteAfter); + + void calculateForces(); + + bool advance(); + QRectF boundingRect() const; + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + + static qreal getRadiusForState(QNetworkConfiguration::StateFlags state); + +protected: + QVariant itemChange(GraphicsItemChange change, const QVariant &value); + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); + +private Q_SLOTS: + void stateChanged(QNetworkSession::State state); + void newConfigurationActivated(); + +private: + QNetworkConfiguration configuration; + QNetworkSession *session; + + QGraphicsTextItem *text; + QGraphicsSvgItem *icon; + + qreal finalOpacity; + qreal finalScale; + qreal currentScale; + + QPointF newPos; + + bool deleteAfterAnimation; +}; + diff --git a/examples/network/bearercloud/icons.qrc b/examples/network/bearercloud/icons.qrc new file mode 100644 index 0000000..84a8939 --- /dev/null +++ b/examples/network/bearercloud/icons.qrc @@ -0,0 +1,7 @@ + + + wlan.svg + lan.svg + unknown.svg + + diff --git a/examples/network/bearercloud/lan.svg b/examples/network/bearercloud/lan.svg new file mode 100644 index 0000000..3cce805 --- /dev/null +++ b/examples/network/bearercloud/lan.svg @@ -0,0 +1,76 @@ + + + + + + + + + + + image/svg+xml + + + + + + LAN + + diff --git a/examples/network/bearercloud/main.cpp b/examples/network/bearercloud/main.cpp new file mode 100644 index 0000000..33c55e9 --- /dev/null +++ b/examples/network/bearercloud/main.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 "bearercloud.h" + +#include +#include + +class CloudView : public QGraphicsView +{ + Q_OBJECT + +public: + CloudView(QGraphicsScene *scene); + ~CloudView() { } + +protected: + void resizeEvent(QResizeEvent *) { + fitInView(sceneRect(), Qt::KeepAspectRatio); + } +#ifdef Q_OS_WINCE + void hideEvent(QHideEvent *) { + qApp->quit(); + } +#endif +}; + +CloudView::CloudView(QGraphicsScene *scene) +: QGraphicsView(scene) +{ + setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing | + QPainter::SmoothPixmapTransform); +#if defined (Q_OS_SYMBIAN) || defined (Q_OS_WINCE) + setWindowState(Qt::WindowMaximized); +#endif +} + +#include "main.moc" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + BearerCloud bearerCloud; + + CloudView view(&bearerCloud); + view.show(); + + return app.exec(); +} + diff --git a/examples/network/bearercloud/unknown.svg b/examples/network/bearercloud/unknown.svg new file mode 100644 index 0000000..fd10298 --- /dev/null +++ b/examples/network/bearercloud/unknown.svg @@ -0,0 +1,76 @@ + + + + + + + + + + + image/svg+xml + + + + + + NET + + diff --git a/examples/network/bearercloud/wlan.svg b/examples/network/bearercloud/wlan.svg new file mode 100644 index 0000000..8b86089 --- /dev/null +++ b/examples/network/bearercloud/wlan.svg @@ -0,0 +1,151 @@ + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/examples/network/bearermonitor/bearermonitor.cpp b/examples/network/bearermonitor/bearermonitor.cpp new file mode 100644 index 0000000..70c8269 --- /dev/null +++ b/examples/network/bearermonitor/bearermonitor.cpp @@ -0,0 +1,395 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 "bearermonitor.h" +#include "sessionwidget.h" + +#include + +#ifdef Q_OS_WIN +#include +#undef interface + +#ifndef NS_NLA +#define NS_NLA 15 +#endif +#endif + +BearerMonitor::BearerMonitor(QWidget *parent) +: QWidget(parent) +{ + setupUi(this); + delete tabWidget->currentWidget(); + sessionGroup->hide(); +#if defined (Q_OS_SYMBIAN) || defined(Q_OS_WINCE) + setWindowState(Qt::WindowMaximized); +#endif + updateConfigurations(); + + onlineStateChanged(!manager.allConfigurations(QNetworkConfiguration::Active).isEmpty()); + + QNetworkConfiguration defaultConfiguration = manager.defaultConfiguration(); + for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) { + QTreeWidgetItem *item = treeWidget->topLevelItem(i); + + if (item->data(0, Qt::UserRole).toString() == defaultConfiguration.identifier()) { + treeWidget->setCurrentItem(item); + showConfigurationFor(item); + break; + } + } + + connect(&manager, SIGNAL(configurationAdded(const QNetworkConfiguration&)), + this, SLOT(configurationAdded(const QNetworkConfiguration&))); + connect(&manager, SIGNAL(configurationRemoved(const QNetworkConfiguration&)), + this, SLOT(configurationRemoved(const QNetworkConfiguration&))); + connect(&manager, SIGNAL(configurationChanged(const QNetworkConfiguration&)), + this, SLOT(configurationChanged(const QNetworkConfiguration))); + connect(&manager, SIGNAL(updateCompleted()), this, SLOT(updateConfigurations())); + connect(&manager, SIGNAL(onlineStateChanged(bool)), this ,SLOT(onlineStateChanged(bool))); + +#ifdef Q_OS_WIN + connect(registerButton, SIGNAL(clicked()), this, SLOT(registerNetwork())); + connect(unregisterButton, SIGNAL(clicked()), this, SLOT(unregisterNetwork())); +#else + nlaGroup->hide(); +#endif + + connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)), + this, SLOT(createSessionFor(QTreeWidgetItem*))); + + connect(treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), + this, SLOT(showConfigurationFor(QTreeWidgetItem*))); + + connect(newSessionButton, SIGNAL(clicked()), + this, SLOT(createNewSession())); + connect(deleteSessionButton, SIGNAL(clicked()), + this, SLOT(deleteSession())); + + connect(scanButton, SIGNAL(clicked()), + this, SLOT(performScan())); +} + +BearerMonitor::~BearerMonitor() +{ +} + +static void updateItem(QTreeWidgetItem *item, const QNetworkConfiguration &config) +{ + item->setText(0, config.name()); + item->setData(0, Qt::UserRole, config.identifier()); + + QFont font = item->font(1); + font.setBold((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active); + item->setFont(0, font); +} + +void BearerMonitor::configurationAdded(const QNetworkConfiguration &config, QTreeWidgetItem *parent) +{ + QTreeWidgetItem *item = new QTreeWidgetItem; + updateItem(item, config); + + if (parent) + parent->addChild(item); + else + treeWidget->addTopLevelItem(item); + + if (config.type() == QNetworkConfiguration::ServiceNetwork) { + foreach (const QNetworkConfiguration &child, config.children()) + configurationAdded(child, item); + } +} + +void BearerMonitor::configurationRemoved(const QNetworkConfiguration &config) +{ + for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) { + QTreeWidgetItem *item = treeWidget->topLevelItem(i); + + if (item->data(0, Qt::UserRole).toString() == config.identifier()) { + delete item; + break; + } + } +} + +void BearerMonitor::configurationChanged(const QNetworkConfiguration &config) +{ + for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) { + QTreeWidgetItem *item = treeWidget->topLevelItem(i); + + if (item->data(0, Qt::UserRole).toString() == config.identifier()) { + updateItem(item, config); + + if (config.type() == QNetworkConfiguration::ServiceNetwork) + updateSnapConfiguration(item, config); + + if (item == treeWidget->currentItem()) + showConfigurationFor(item); + + break; + } + } +} + +void BearerMonitor::updateSnapConfiguration(QTreeWidgetItem *parent, const QNetworkConfiguration &snap) +{ + QMap itemMap; + for (int i = 0; i < parent->childCount(); ++i) { + QTreeWidgetItem *item = parent->child(i); + itemMap.insert(item->data(0, Qt::UserRole).toString(), item); + } + + QList allConfigurations = snap.children(); + + while (!allConfigurations.isEmpty()) { + QNetworkConfiguration config = allConfigurations.takeFirst(); + + QTreeWidgetItem *item = itemMap.take(config.identifier()); + if (item) { + updateItem(item, config); + + if (config.type() == QNetworkConfiguration::ServiceNetwork) + updateSnapConfiguration(item, config); + } else { + configurationAdded(config, parent); + } + } + + foreach (const QString &id, itemMap.keys()) + delete itemMap.value(id); + + itemMap.clear(); +} + +void BearerMonitor::updateConfigurations() +{ + progressBar->hide(); + scanButton->show(); + + QList items = treeWidget->findItems(QLatin1String("*"), Qt::MatchWildcard); + QMap itemMap; + while (!items.isEmpty()) { + QTreeWidgetItem *item = items.takeFirst(); + itemMap.insert(item->data(0, Qt::UserRole).toString(), item); + } + + QList allConfigurations = manager.allConfigurations(); + + while (!allConfigurations.isEmpty()) { + QNetworkConfiguration config = allConfigurations.takeFirst(); + + QTreeWidgetItem *item = itemMap.take(config.identifier()); + if (item) { + updateItem(item, config); + + if (config.type() == QNetworkConfiguration::ServiceNetwork) + updateSnapConfiguration(item, config); + } else { + configurationAdded(config); + } + } + + foreach (const QString &id, itemMap.keys()) + delete itemMap.value(id); +} + +void BearerMonitor::onlineStateChanged(bool isOnline) +{ + if (isOnline) + onlineState->setText(tr("Online")); + else + onlineState->setText(tr("Offline")); +} + +#ifdef Q_OS_WIN +void BearerMonitor::registerNetwork() +{ + QTreeWidgetItem *item = treeWidget->currentItem(); + + QNetworkConfiguration configuration = + manager.configurationFromIdentifier(item->data(0, Qt::UserRole).toString()); + + const QString name = configuration.name(); + + qDebug() << "Registering" << name << "with system"; + + WSAQUERYSET networkInfo; + memset(&networkInfo, 0, sizeof(networkInfo)); + networkInfo.dwSize = sizeof(networkInfo); + networkInfo.lpszServiceInstanceName = (LPWSTR)name.utf16(); + networkInfo.dwNameSpace = NS_NLA; + + if (WSASetService(&networkInfo, RNRSERVICE_REGISTER, 0) == SOCKET_ERROR) + qDebug() << "WSASetService(RNRSERVICE_REGISTER) returned" << WSAGetLastError(); +} + +void BearerMonitor::unregisterNetwork() +{ + QTreeWidgetItem *item = treeWidget->currentItem(); + + QNetworkConfiguration configuration = + manager.configurationFromIdentifier(item->data(0, Qt::UserRole).toString()); + + const QString name = configuration.name(); + + qDebug() << "Unregistering" << name << "with system"; + + WSAQUERYSET networkInfo; + memset(&networkInfo, 0, sizeof(networkInfo)); + networkInfo.dwSize = sizeof(networkInfo); + networkInfo.lpszServiceInstanceName = (LPWSTR)name.utf16(); + networkInfo.dwNameSpace = NS_NLA; + + if (WSASetService(&networkInfo, RNRSERVICE_DELETE, 0) == SOCKET_ERROR) + qDebug() << "WSASetService(RNRSERVICE_DELETE) returned" << WSAGetLastError(); +} +#endif + +void BearerMonitor::showConfigurationFor(QTreeWidgetItem *item) +{ + QString identifier; + + if (item) + identifier = item->data(0, Qt::UserRole).toString(); + + QNetworkConfiguration conf = manager.configurationFromIdentifier(identifier); + + switch (conf.state()) { + case QNetworkConfiguration::Active: + configurationState->setText(tr("Active")); + break; + case QNetworkConfiguration::Discovered: + configurationState->setText(tr("Discovered")); + break; + case QNetworkConfiguration::Defined: + configurationState->setText(tr("Defined")); + break; + case QNetworkConfiguration::Undefined: + configurationState->setText(tr("Undefined")); + break; + default: + configurationState->setText(QString()); + } + + switch (conf.type()) { + case QNetworkConfiguration::InternetAccessPoint: + configurationType->setText(tr("Internet Access Point")); + break; + case QNetworkConfiguration::ServiceNetwork: + configurationType->setText(tr("Service Network")); + break; + case QNetworkConfiguration::UserChoice: + configurationType->setText(tr("User Choice")); + break; + case QNetworkConfiguration::Invalid: + configurationType->setText(tr("Invalid")); + break; + default: + configurationType->setText(QString()); + } + + switch (conf.purpose()) { + case QNetworkConfiguration::UnknownPurpose: + configurationPurpose->setText(tr("Unknown")); + break; + case QNetworkConfiguration::PublicPurpose: + configurationPurpose->setText(tr("Public")); + break; + case QNetworkConfiguration::PrivatePurpose: + configurationPurpose->setText(tr("Private")); + break; + case QNetworkConfiguration::ServiceSpecificPurpose: + configurationPurpose->setText(tr("Service Specific")); + break; + default: + configurationPurpose->setText(QString()); + } + + configurationIdentifier->setText(conf.identifier()); + + configurationRoaming->setText(conf.isRoamingAvailable() ? tr("Available") : tr("Not available")); + + configurationChildren->setText(QString::number(conf.children().count())); + + configurationName->setText(conf.name()); +} + +void BearerMonitor::createSessionFor(QTreeWidgetItem *item) +{ + const QString identifier = item->data(0, Qt::UserRole).toString(); + + QNetworkConfiguration conf = manager.configurationFromIdentifier(identifier); + + SessionWidget *session = new SessionWidget(conf); + + tabWidget->addTab(session, conf.name()); + + sessionGroup->show(); + + sessionWidgets.append(session); +} + +void BearerMonitor::createNewSession() +{ + QTreeWidgetItem *item = treeWidget->currentItem(); + + createSessionFor(item); +} + +void BearerMonitor::deleteSession() +{ + SessionWidget *session = qobject_cast(tabWidget->currentWidget()); + if (session) { + sessionWidgets.removeAll(session); + + delete session; + + if (tabWidget->count() == 0) + sessionGroup->hide(); + } +} + +void BearerMonitor::performScan() +{ + scanButton->hide(); + progressBar->show(); + manager.updateConfigurations(); +} diff --git a/examples/network/bearermonitor/bearermonitor.h b/examples/network/bearermonitor/bearermonitor.h new file mode 100644 index 0000000..d1f4601 --- /dev/null +++ b/examples/network/bearermonitor/bearermonitor.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 BEARERMONITOR_H +#define BEARERMONITOR_H + +#include +#include +#if defined (Q_OS_SYMBIAN) || defined(Q_OS_WINCE) +#include "ui_bearermonitor_240_320.h" +#else +#include "ui_bearermonitor_640_480.h" +#endif + +QTM_USE_NAMESPACE + +class SessionWidget; + +class BearerMonitor : public QWidget, public Ui_BearerMonitor +{ + Q_OBJECT + +public: + BearerMonitor(QWidget *parent = 0); + ~BearerMonitor(); + +private slots: + void configurationAdded(const QNetworkConfiguration &config, QTreeWidgetItem *parent = 0); + void configurationRemoved(const QNetworkConfiguration &config); + void configurationChanged(const QNetworkConfiguration &config); + void updateSnapConfiguration(QTreeWidgetItem *parent, const QNetworkConfiguration &snap); + void updateConfigurations(); + + void onlineStateChanged(bool isOnline); + +#ifdef Q_OS_WIN + void registerNetwork(); + void unregisterNetwork(); +#endif + + void showConfigurationFor(QTreeWidgetItem *item); + + void createSessionFor(QTreeWidgetItem *item); + void createNewSession(); + void deleteSession(); + + void performScan(); + +private: + QNetworkConfigurationManager manager; + QList sessionWidgets; +}; + +#endif //BEARERMONITOR_H diff --git a/examples/network/bearermonitor/bearermonitor.pro b/examples/network/bearermonitor/bearermonitor.pro new file mode 100644 index 0000000..c8fb3c2 --- /dev/null +++ b/examples/network/bearermonitor/bearermonitor.pro @@ -0,0 +1,32 @@ +HEADERS = sessionwidget.h \ + bearermonitor.h + +SOURCES = main.cpp \ + bearermonitor.cpp \ + sessionwidget.cpp + +FORMS = bearermonitor_240_320.ui \ + bearermonitor_640_480.ui \ + sessionwidget.ui + +TARGET = bearermonitor + +QT = core gui network + +INCLUDEPATH += ../../src/bearer + +include(../examples.pri) + +qtAddLibrary(QtBearer) +win32:!wince*:LIBS += -lWs2_32 +wince*:LIBS += -lWs2 + +CONFIG += console + +include(../examples.pri) + +macx: { + contains(QT_CONFIG,qt_framework):LIBS += -framework QtBearer + contains(CONFIG, debug) { + } +} diff --git a/examples/network/bearermonitor/bearermonitor_240_320.ui b/examples/network/bearermonitor/bearermonitor_240_320.ui new file mode 100644 index 0000000..ce9c2d1 --- /dev/null +++ b/examples/network/bearermonitor/bearermonitor_240_320.ui @@ -0,0 +1,420 @@ + + + BearerMonitor + + + + 0 + 0 + 240 + 320 + + + + Form + + + + + + QFrame::NoFrame + + + QFrame::Plain + + + true + + + + + 0 + -274 + 206 + 576 + + + + + + + System State + + + true + + + + 0 + + + 0 + + + 0 + + + + + + + Online State: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + + Configurations + + + true + + + + 0 + + + 0 + + + 0 + + + + + + + + + Name: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + State: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Type: + + + + + + + + 0 + 0 + + + + Invalid + + + + + + + + + + + Purpose: + + + + + + + + 0 + 0 + + + + Unknown + + + + + + + + + + + Identifier: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Roaming: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Children: + + + + + + + + 0 + 0 + + + + + + + + + + + + + Network Location Awareness + + + + + + Register + + + + + + + Unregister + + + + + + + + + + New Session + + + + + + + Delete Session + + + + + + + Scan + + + + + + + 0 + + + -1 + + + false + + + false + + + %p% + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 0 + 0 + + + + Qt::ScrollBarAlwaysOff + + + false + + + + 1 + + + + + + + + + + + + + Sessions + + + true + + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + 0 + + + + Session 1 + + + + + + + + + + + + + + + + diff --git a/examples/network/bearermonitor/bearermonitor_640_480.ui b/examples/network/bearermonitor/bearermonitor_640_480.ui new file mode 100644 index 0000000..941eaa0 --- /dev/null +++ b/examples/network/bearermonitor/bearermonitor_640_480.ui @@ -0,0 +1,386 @@ + + + BearerMonitor + + + + 0 + 0 + 640 + 515 + + + + Form + + + + + + System State + + + true + + + + 0 + + + 0 + + + 0 + + + + + + + Online State: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + + Configurations + + + true + + + + 0 + + + 0 + + + 0 + + + + + false + + + + 1 + + + + + + + + + + + + Name: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + State: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Type: + + + + + + + + 0 + 0 + + + + Invalid + + + + + + + + + + + Purpose: + + + + + + + + 0 + 0 + + + + Unknown + + + + + + + + + + + Identifier: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Roaming: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Children: + + + + + + + + 0 + 0 + + + + + + + + + + + + + Network Location Awareness + + + + + + Register + + + + + + + Unregister + + + + + + + + + + New Session + + + + + + + Delete Session + + + + + + + Scan + + + + + + + 0 + + + -1 + + + false + + + false + + + %p% + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + Sessions + + + true + + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + 0 + + + + Session 1 + + + + + + + + + + + + diff --git a/examples/network/bearermonitor/main.cpp b/examples/network/bearermonitor/main.cpp new file mode 100644 index 0000000..9685181 --- /dev/null +++ b/examples/network/bearermonitor/main.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 + +#include "bearermonitor.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + BearerMonitor monitor; + monitor.show(); + + return app.exec(); +} + diff --git a/examples/network/bearermonitor/sessionwidget.cpp b/examples/network/bearermonitor/sessionwidget.cpp new file mode 100644 index 0000000..7633dd7 --- /dev/null +++ b/examples/network/bearermonitor/sessionwidget.cpp @@ -0,0 +1,156 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 "sessionwidget.h" + +SessionWidget::SessionWidget(const QNetworkConfiguration &config, QWidget *parent) +: QWidget(parent) +{ + setupUi(this); + + session = new QNetworkSession(config, this); + + connect(session, SIGNAL(stateChanged(QNetworkSession::State)), + this, SLOT(updateSession())); + connect(session, SIGNAL(error(QNetworkSession::SessionError)), + this, SLOT(updateSession())); + + updateSession(); + + sessionId->setText(QString("0x%1").arg(qulonglong(session), 8, 16, QChar('0'))); + + configuration->setText(session->configuration().name()); + + connect(openSessionButton, SIGNAL(clicked()), + this, SLOT(openSession())); + connect(openSyncSessionButton, SIGNAL(clicked()), + this, SLOT(openSyncSession())); + connect(closeSessionButton, SIGNAL(clicked()), + this, SLOT(closeSession())); + connect(stopSessionButton, SIGNAL(clicked()), + this, SLOT(stopSession())); +} + +SessionWidget::~SessionWidget() +{ + delete session; +} + +void SessionWidget::updateSession() +{ + updateSessionState(session->state()); + updateSessionError(session->error()); + + bearer->setText(session->bearerName()); + + interfaceName->setText(session->interface().humanReadableName()); + interfaceGuid->setText(session->interface().name()); +} + +void SessionWidget::openSession() +{ + session->open(); + updateSession(); +} + +void SessionWidget::openSyncSession() +{ + session->open(); + session->waitForOpened(); + updateSession(); +} + +void SessionWidget::closeSession() +{ + session->close(); + updateSession(); +} + +void SessionWidget::stopSession() +{ + session->stop(); + updateSession(); +} + +void SessionWidget::updateSessionState(QNetworkSession::State state) +{ + QString s = tr("%1 (%2)"); + + switch (state) { + case QNetworkSession::Invalid: + s = s.arg(tr("Invalid")); + break; + case QNetworkSession::NotAvailable: + s = s.arg(tr("Not Available")); + break; + case QNetworkSession::Connecting: + s = s.arg(tr("Connecting")); + break; + case QNetworkSession::Connected: + s = s.arg(tr("Connected")); + break; + case QNetworkSession::Closing: + s = s.arg(tr("Closing")); + break; + case QNetworkSession::Disconnected: + s = s.arg(tr("Disconnected")); + break; + case QNetworkSession::Roaming: + s = s.arg(tr("Roaming")); + break; + default: + s = s.arg(tr("Unknown")); + } + + if (session->isActive()) + s = s.arg(tr("Active")); + else + s = s.arg(tr("Inactive")); + + sessionState->setText(s); +} + +void SessionWidget::updateSessionError(QNetworkSession::SessionError error) +{ + lastError->setText(QString::number(error)); + errorString->setText(session->errorString()); +} + diff --git a/examples/network/bearermonitor/sessionwidget.h b/examples/network/bearermonitor/sessionwidget.h new file mode 100644 index 0000000..cb6591e --- /dev/null +++ b/examples/network/bearermonitor/sessionwidget.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 SESSIONWIDGET_H +#define SESSIONWIDGET_H + +#include "ui_sessionwidget.h" + +#include + +QTM_USE_NAMESPACE + +class SessionWidget : public QWidget, public Ui_SessionWidget +{ + Q_OBJECT + +public: + SessionWidget(const QNetworkConfiguration &config, QWidget *parent = 0); + ~SessionWidget(); + +private: + void updateSessionState(QNetworkSession::State state); + void updateSessionError(QNetworkSession::SessionError error); + +private Q_SLOTS: + void openSession(); + void openSyncSession(); + void closeSession(); + void stopSession(); + void updateSession(); + +private: + QNetworkSession *session; +}; + +#endif + diff --git a/examples/network/bearermonitor/sessionwidget.ui b/examples/network/bearermonitor/sessionwidget.ui new file mode 100644 index 0000000..f02f306 --- /dev/null +++ b/examples/network/bearermonitor/sessionwidget.ui @@ -0,0 +1,251 @@ + + + SessionWidget + + + + 0 + 0 + 340 + 220 + + + + Form + + + + + + + + Session ID: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + + 0 + 0 + + + + Session State: + + + + + + + + 0 + 0 + + + + Invalid + + + + + + + + + + + Configuration: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Bearer: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Interface Name: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Interface GUID: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Last Error: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Error String + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Open + + + + + + + Blocking Open + + + + + + + Close + + + + + + + Stop + + + + + + + + + + diff --git a/src/network/bearer/bearer.pro b/src/network/bearer/bearer.pro new file mode 100644 index 0000000..2255b7c --- /dev/null +++ b/src/network/bearer/bearer.pro @@ -0,0 +1,163 @@ +# Qt bearer management library +TEMPLATE = lib +TARGET = QtBearer + +QT += network +include (../../common.pri) + +DEFINES += QT_BUILD_BEARER_LIB QT_MAKEDLL + +#DEFINES += BEARER_MANAGEMENT_DEBUG + +PUBLIC_HEADERS += qnetworkconfiguration.h \ + qnetworksession.h \ + qnetworkconfigmanager.h + +HEADERS += $$PUBLIC_HEADERS +SOURCES += qnetworksession.cpp \ + qnetworkconfigmanager.cpp \ + qnetworkconfiguration.cpp + +symbian: { + exists($${EPOCROOT}epoc32/release/winscw/udeb/cmmanager.lib)| \ + exists($${EPOCROOT}epoc32/release/armv5/lib/cmmanager.lib) { + message("Building with SNAP support") + DEFINES += SNAP_FUNCTIONALITY_AVAILABLE=1 + LIBS += -lcmmanager + } else { + message("Building without SNAP support") + LIBS += -lapengine + } + + INCLUDEPATH += $$APP_LAYER_SYSTEMINCLUDE + + HEADERS += qnetworkconfigmanager_s60_p.h \ + qnetworkconfiguration_s60_p.h \ + qnetworksession_s60_p.h + SOURCES += qnetworkconfigmanager_s60_p.cpp \ + qnetworkconfiguration_s60_p.cpp \ + qnetworksession_s60_p.cpp + + LIBS += -lcommdb \ + -lapsettingshandlerui \ + -lconnmon \ + -lcentralrepository \ + -lesock \ + -linsock \ + -lecom \ + -lefsrv \ + -lnetmeta + + deploy.path = $${EPOCROOT} + exportheaders.sources = $$PUBLIC_HEADERS + exportheaders.path = epoc32/include + + for(header, exportheaders.sources) { + BLD_INF_RULES.prj_exports += "$$header $$deploy.path$$exportheaders.path/$$basename(header)" + } + + bearer_deployment.sources = QtBearer.dll + bearer_deployment.path = /sys/bin + DEPLOYMENT += bearer_deployment + + TARGET.CAPABILITY = All -TCB +} else { + maemo { + QT += dbus + CONFIG += link_pkgconfig + + exists(../debug) { + message("Enabling debug messages.") + DEFINES += BEARER_MANAGEMENT_DEBUG + } + + HEADERS += qnetworksession_maemo_p.h \ + qnetworkconfigmanager_maemo_p.h \ + qnetworkconfiguration_maemo_p.h + + SOURCES += qnetworkconfigmanager_maemo.cpp \ + 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 { + + DEFINES += BEARER_ENGINE + + HEADERS += qnetworkconfigmanager_p.h \ + qnetworkconfiguration_p.h \ + qnetworksession_p.h \ + qnetworksessionengine_p.h \ + qgenericengine_p.h + + SOURCES += qnetworkconfigmanager_p.cpp \ + qnetworksession_p.cpp \ + qnetworksessionengine.cpp \ + qgenericengine.cpp + + unix:!mac:contains(networkmanager_enabled, yes) { + contains(QT_CONFIG,dbus) { + DEFINES += BACKEND_NM + QT += dbus + + HEADERS += qnmdbushelper_p.h \ + qnetworkmanagerservice_p.h \ + qnmwifiengine_unix_p.h + + SOURCES += qnmdbushelper.cpp \ + qnetworkmanagerservice_p.cpp \ + qnmwifiengine_unix.cpp + } else { + message("NetworkManager backend requires Qt DBus support") + } + } + + win32: { + HEADERS += qnlaengine_win_p.h \ + qnetworksessionengine_win_p.h + + !wince*:HEADERS += qnativewifiengine_win_p.h + + SOURCES += qnlaengine_win.cpp + + !wince*:SOURCES += qnativewifiengine_win.cpp + + !wince*:LIBS += -lWs2_32 + wince*:LIBS += -lWs2 + } + } + macx: { + HEADERS += qcorewlanengine_mac_p.h + SOURCES+= qcorewlanengine_mac.mm + LIBS += -framework Foundation -framework SystemConfiguration + + contains(corewlan_enabled, yes) { + isEmpty(QMAKE_MAC_SDK) { + SDK6="yes" + } else { + contains(QMAKE_MAC_SDK, "/Developer/SDKs/MacOSX10.6.sdk") { + SDK6="yes" + } + } + + !isEmpty(SDK6) { + LIBS += -framework CoreWLAN + DEFINES += MAC_SDK_10_6 + } + } + + + } +} + +include(../../features/deploy.pri) diff --git a/src/network/bearer/qcorewlanengine_mac.mm b/src/network/bearer/qcorewlanengine_mac.mm new file mode 100644 index 0000000..5451615 --- /dev/null +++ b/src/network/bearer/qcorewlanengine_mac.mm @@ -0,0 +1,461 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 "qcorewlanengine_mac_p.h" +#include "qnetworkconfiguration_p.h" + +#include +#include +#include +#include + +#include + +#if defined(MAC_SDK_10_6) //not much functionality without this +#include +#include +#include +#include +#endif + +#include +#include +#include + +#include +QMap networkInterfaces; + +QTM_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC(QCoreWlanEngine, coreWlanEngine) + +inline QString cfstringRefToQstring(CFStringRef cfStringRef) { +// return QString([cfStringRef UTF8String]); + QString retVal; + CFIndex maxLength = 2 * CFStringGetLength(cfStringRef) + 1/*zero term*/; // max UTF8 + char *cstring = new char[maxLength]; + if (CFStringGetCString(CFStringRef(cfStringRef), cstring, maxLength, kCFStringEncodingUTF8)) { + retVal = QString::fromUtf8(cstring); + } + delete cstring; + return retVal; +} + +inline CFStringRef qstringToCFStringRef(const QString &string) +{ + return CFStringCreateWithCharacters(0, reinterpret_cast(string.unicode()), + string.length()); +} + +inline NSString *qstringToNSString(const QString &qstr) +{ return [reinterpret_cast(qstringToCFStringRef(qstr)) autorelease]; } + +inline QString nsstringToQString(const NSString *nsstr) +{ return cfstringRefToQstring(reinterpret_cast(nsstr)); } + +inline QStringList nsarrayToQStringList(void *nsarray) +{ + QStringList result; + NSArray *array = static_cast(nsarray); + for (NSUInteger i=0; i<[array count]; ++i) + result << nsstringToQString([array objectAtIndex:i]); + return result; +} + +static QString qGetInterfaceType(const QString &interfaceString) +{ + return networkInterfaces.value(interfaceString); +} + +QCoreWlanEngine::QCoreWlanEngine(QObject *parent) +: QNetworkSessionEngine(parent) +{ + getAllScInterfaces(); + connect(&pollTimer, SIGNAL(timeout()), this, SIGNAL(configurationsChanged())); + pollTimer.setInterval(10000); +} + +QCoreWlanEngine::~QCoreWlanEngine() +{ +} + +QList QCoreWlanEngine::getWifiConfigurations() +{ + QMapIterator i(networkInterfaces); + while (i.hasNext()) { + i.next(); + QString interfaceName = i.key(); + if (i.value() == "WLAN") { + if(!isWifiReady(interfaceName)) { + qWarning() << "wifi not powered on"; + return QList(); + } else { + // QList profs = getWlanProfiles(interfaceName); + scanForSsids(interfaceName); + } + } else { + + } + } + return QList (); +} + +QList QCoreWlanEngine::getConfigurations(bool *ok) +{ + if (ok) + *ok = true; + NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + + QList foundConfigurations; + QList wificonfigs = getWifiConfigurations(); + + uint identifier; + QMapIterator i(networkInterfaces); + while (i.hasNext()) { + i.next(); + if (i.value() == "WLAN") { + QList fetchedConfigurations = scanForSsids(i.key()); + for (int i = 0; i < fetchedConfigurations.count(); ++i) { + + QNetworkConfigurationPrivate *config = new QNetworkConfigurationPrivate; + config->name = fetchedConfigurations.at(i)->name; + config->isValid = fetchedConfigurations.at(i)->isValid; + config->id = fetchedConfigurations.at(i)->id; + + config->state = fetchedConfigurations.at(i)->state; + config->type = fetchedConfigurations.at(i)->type; + config->roamingSupported = fetchedConfigurations.at(i)->roamingSupported; + config->purpose = fetchedConfigurations.at(i)->purpose; + config->internet = fetchedConfigurations.at(i)->internet; + config->serviceInterface = fetchedConfigurations.at(i)->serviceInterface; + + identifier = config->name.toUInt(); + configurationInterface[identifier] = config->serviceInterface.name(); + foundConfigurations.append(config); + } + } + + QNetworkInterface interface = QNetworkInterface::interfaceFromName(i.key()); + QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; + const QString humanReadableName = interface.humanReadableName(); + cpPriv->name = humanReadableName.isEmpty() ? interface.name() : humanReadableName; + cpPriv->isValid = true; + + if (interface.index()) + identifier = interface.index(); + else + identifier = qHash(interface.hardwareAddress()); + + cpPriv->id = QString::number(identifier); + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + cpPriv->state = QNetworkConfiguration::Undefined; + + if (interface.flags() & QNetworkInterface::IsRunning) { + cpPriv->state = QNetworkConfiguration::Defined; + cpPriv->internet = true; + } + if ( !interface.addressEntries().isEmpty()) { + cpPriv->state |= QNetworkConfiguration::Active; + cpPriv->internet = true; + } + configurationInterface[identifier] = interface.name(); + foundConfigurations.append(cpPriv); + } + [autoreleasepool release]; + pollTimer.start(); + return foundConfigurations; +} + +QString QCoreWlanEngine::getInterfaceFromId(const QString &id) +{ + return configurationInterface.value(id.toUInt()); +} + +bool QCoreWlanEngine::hasIdentifier(const QString &id) +{ + return configurationInterface.contains(id.toUInt()); +} + +QString QCoreWlanEngine::bearerName(const QString &id) +{ + QString interface = getInterfaceFromId(id); + + if (interface.isEmpty()) + return QString(); + + return qGetInterfaceType(interface); +} + +void QCoreWlanEngine::connectToId(const QString &id) +{ + NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + QString interfaceString = getInterfaceFromId(id); + + if(networkInterfaces.value(interfaceString) == "WLAN") { +#if defined(MAC_SDK_10_6) + CWInterface *wifiInterface = [CWInterface interfaceWithName: qstringToNSString(interfaceString)]; + CWConfiguration *userConfig = [ wifiInterface configuration]; + + NSSet *remNets = [userConfig rememberedNetworks]; //CWWirelessProfile + + NSEnumerator *enumerator = [remNets objectEnumerator]; + CWWirelessProfile *wProfile; + NSUInteger index=0; + while ((wProfile = [enumerator nextObject])) { //CWWirelessProfile + + if(id == nsstringToQString([wProfile ssid])) { + CW8021XProfile *user8021XProfile = nil; + user8021XProfile = [ wProfile user8021XProfile]; + + NSError *err = nil; + NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0]; + + if(user8021XProfile) { + [params setValue: user8021XProfile forKey:kCWAssocKey8021XProfile]; + } else { + [params setValue: [wProfile passphrase] forKey: kCWAssocKeyPassphrase]; + } + + NSDictionary *parametersDict = nil; + NSArray* apArray = [NSMutableArray arrayWithArray:[wifiInterface scanForNetworksWithParameters:parametersDict error:&err]]; + if(!err) { + for(uint row=0; row < [apArray count]; row++ ) { + CWNetwork *apNetwork = [apArray objectAtIndex:row]; + if([[apNetwork ssid] compare:[wProfile ssid]] == NSOrderedSame) { + bool result = [wifiInterface associateToNetwork: apNetwork parameters:[NSDictionary dictionaryWithDictionary:params] error:&err]; + if(!result) { + qWarning() <<"ERROR"<< nsstringToQString([err localizedDescription ]); + emit connectionError(id, ConnectError); + } else { + [autoreleasepool release]; + return; + } + } + } + } + } + index++; + } + emit connectionError(id, InterfaceLookupError); +#endif + } else { + // not wifi + } + emit connectionError(id, OperationNotSupported); + [autoreleasepool release]; +} + +void QCoreWlanEngine::disconnectFromId(const QString &id) +{ + QString interfaceString = getInterfaceFromId(id); + if(networkInterfaces.value(getInterfaceFromId(id)) == "WLAN") { //wifi only for now +#if defined(MAC_SDK_10_6) + NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + CWInterface *wifiInterface = [CWInterface interfaceWithName: qstringToNSString(interfaceString)]; + [wifiInterface disassociate]; + if([[wifiInterface interfaceState]intValue] != kCWInterfaceStateInactive) { + emit connectionError(id, DisconnectionError); + } + [autoreleasepool release]; + return; +#endif + } else { + + } + emit connectionError(id, OperationNotSupported); +} + +void QCoreWlanEngine::requestUpdate() +{ + getAllScInterfaces(); + emit configurationsChanged(); +} + +QCoreWlanEngine *QCoreWlanEngine::instance() +{ + return coreWlanEngine(); +} + +QList QCoreWlanEngine::scanForSsids(const QString &interfaceName) +{ + QList foundConfigs; +#if defined(MAC_SDK_10_6) + NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + + CWInterface *currentInterface = [CWInterface interfaceWithName:qstringToNSString(interfaceName)]; + NSError *err = nil; + NSDictionary *parametersDict = nil; + NSArray* apArray = [NSMutableArray arrayWithArray:[currentInterface scanForNetworksWithParameters:parametersDict error:&err]]; + + if(!err) { + for(uint row=0; row < [apArray count]; row++ ) { + CWNetwork *apNetwork = [apArray objectAtIndex:row]; + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + QString networkSsid = nsstringToQString([apNetwork ssid]); + cpPriv->name = networkSsid; + cpPriv->isValid = true; + cpPriv->id = networkSsid; + cpPriv->internet = true; + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + cpPriv->serviceInterface = QNetworkInterface::interfaceFromName(nsstringToQString([[CWInterface interface] name])); + + CWWirelessProfile *networkProfile = apNetwork.wirelessProfile; + CW8021XProfile *userNetworkProfile = networkProfile.user8021XProfile; + if(!userNetworkProfile) { + } else { + qWarning() <<"Has profile!" ; + } + + if( [currentInterface.interfaceState intValue] == kCWInterfaceStateRunning) { + QString interfaceSsidString = nsstringToQString( [currentInterface ssid]); + if( cpPriv->name == interfaceSsidString) { + cpPriv->state |= QNetworkConfiguration::Active; + } + } else { + if(isKnownSsid(cpPriv->serviceInterface.name(), networkSsid)) { + cpPriv->state = QNetworkConfiguration::Discovered; + } else { + cpPriv->state = QNetworkConfiguration::Defined; + } + } + if(!cpPriv->state) { + cpPriv->state = QNetworkConfiguration::Undefined; + } + if([[apNetwork securityMode ] intValue]== kCWSecurityModeOpen) + cpPriv->purpose = QNetworkConfiguration::PublicPurpose; + else + cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; + foundConfigs.append(cpPriv); + } + } else { + qWarning() << "ERROR scanning for ssids" << nsstringToQString([err localizedDescription]) + < QCoreWlanEngine::getWlanProfiles(const QString &interfaceName) +{ + Q_UNUSED(interfaceName) +#if defined(MAC_SDK_10_6) +// for( CW8021XProfile *each8021XProfile in [CW8021XProfile allUser8021XProfiles] ) { +// qWarning() << "Profile name" << nsstringToQString([each8021XProfile ssid]); +// } + +#endif + return QList (); +} + +bool QCoreWlanEngine::getAllScInterfaces() +{ + networkInterfaces.clear(); + NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + + CFArrayRef interfaces = SCNetworkInterfaceCopyAll(); + if (interfaces != NULL) { + CFIndex interfaceCount; + CFIndex interfaceIndex; + interfaceCount = CFArrayGetCount(interfaces); + for (interfaceIndex = 0; interfaceIndex < interfaceCount; interfaceIndex++) { + + CFStringRef bsdName; + CFTypeRef thisInterface = CFArrayGetValueAtIndex(interfaces, interfaceIndex); + bsdName = SCNetworkInterfaceGetBSDName((SCNetworkInterfaceRef)thisInterface); + QString interfaceName = cfstringRefToQstring(bsdName); + QString typeStr; + CFStringRef type = SCNetworkInterfaceGetInterfaceType((SCNetworkInterfaceRef)thisInterface); + if ( CFEqual(type, kSCNetworkInterfaceTypeIEEE80211)) { + typeStr = "WLAN"; +// } else if (CFEqual(type, kSCNetworkInterfaceTypeBluetooth)) { +// typeStr = "Bluetooth"; + } else if(CFEqual(type, kSCNetworkInterfaceTypeEthernet)) { + typeStr = "Ethernet"; + } else if(CFEqual(type, kSCNetworkInterfaceTypeFireWire)) { + typeStr = "Ethernet"; //ok a bit fudged + } + if(!networkInterfaces.contains(interfaceName) && !typeStr.isEmpty()) { + networkInterfaces.insert(interfaceName,typeStr); + } + } + } + CFRelease(interfaces); + + [autoreleasepool release]; + return true; +} + +#include "moc_qcorewlanengine_mac_p.cpp" + +QTM_END_NAMESPACE + diff --git a/src/network/bearer/qcorewlanengine_mac_p.h b/src/network/bearer/qcorewlanengine_mac_p.h new file mode 100644 index 0000000..fc8e4b5 --- /dev/null +++ b/src/network/bearer/qcorewlanengine_mac_p.h @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 QCOREWLANENGINE_P_H +#define QCOREWLANENGINE_P_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 "qnetworksessionengine_p.h" +#include +#include +QTM_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; + +class QCoreWlanEngine : public QNetworkSessionEngine +{ + Q_OBJECT + +public: + QCoreWlanEngine(QObject *parent = 0); + ~QCoreWlanEngine(); + + QList getConfigurations(bool *ok = 0); + QString getInterfaceFromId(const QString &id); + bool hasIdentifier(const QString &id); + + QString bearerName(const QString &id); + + void connectToId(const QString &id); + void disconnectFromId(const QString &id); + + void requestUpdate(); + + static QCoreWlanEngine *instance(); + static bool getAllScInterfaces(); + +private: + bool isWifiReady(const QString &dev); + QMap configurationInterface; + QTimer pollTimer; + QList scanForSsids(const QString &interfaceName); + + QList getWlanProfiles(const QString &interfaceName); + + QList getWifiConfigurations(); + bool isKnownSsid(const QString &interfaceName, const QString &ssid); +}; + +QTM_END_NAMESPACE + +#endif + diff --git a/src/network/bearer/qgenericengine.cpp b/src/network/bearer/qgenericengine.cpp new file mode 100644 index 0000000..184a69c --- /dev/null +++ b/src/network/bearer/qgenericengine.cpp @@ -0,0 +1,234 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 "qgenericengine_p.h" +#include "qnetworkconfiguration_p.h" + +#include +#include +#include +#include + +#include + +#ifdef Q_OS_WIN +#include "qnetworksessionengine_win_p.h" +#endif + +QTM_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC(QGenericEngine, genericEngine) + +static QString qGetInterfaceType(const QString &interface) +{ +#ifdef Q_OS_WIN32 + unsigned long oid; + DWORD bytesWritten; + + NDIS_MEDIUM medium; + NDIS_PHYSICAL_MEDIUM physicalMedium; + + HANDLE handle = CreateFile((TCHAR *)QString("\\\\.\\%1").arg(interface).utf16(), 0, + FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); + if (handle == INVALID_HANDLE_VALUE) + return QString(); + + oid = OID_GEN_MEDIA_SUPPORTED; + bytesWritten = 0; + bool result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), + &medium, sizeof(medium), &bytesWritten, 0); + if (!result) { + CloseHandle(handle); + return QString(); + } + + oid = OID_GEN_PHYSICAL_MEDIUM; + bytesWritten = 0; + result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), + &physicalMedium, sizeof(physicalMedium), &bytesWritten, 0); + if (!result) { + CloseHandle(handle); + + if (medium == NdisMedium802_3) + return QLatin1String("Ethernet"); + else + return QString(); + } + + CloseHandle(handle); + + if (medium == NdisMedium802_3) { + switch (physicalMedium) { + case NdisPhysicalMediumWirelessLan: + return QLatin1String("WLAN"); + case NdisPhysicalMediumBluetooth: + return QLatin1String("Bluetooth"); + case NdisPhysicalMediumWiMax: + return QLatin1String("WiMAX"); + default: +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Physical Medium" << physicalMedium; +#endif + return QLatin1String("Ethernet"); + } + } + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << medium << physicalMedium; +#endif +#else + Q_UNUSED(interface); +#endif + + return QString(); +} + +QGenericEngine::QGenericEngine(QObject *parent) +: QNetworkSessionEngine(parent) +{ + connect(&pollTimer, SIGNAL(timeout()), this, SIGNAL(configurationsChanged())); + pollTimer.setInterval(10000); +} + +QGenericEngine::~QGenericEngine() +{ +} + +QList QGenericEngine::getConfigurations(bool *ok) +{ + if (ok) + *ok = true; + + QList foundConfigurations; + + // Immediately after connecting with a wireless access point + // QNetworkInterface::allInterfaces() will sometimes return an empty list. Calling it again a + // second time results in a non-empty list. If we loose interfaces we will end up removing + // network configurations which will break current sessions. + QList interfaces = QNetworkInterface::allInterfaces(); + if (interfaces.isEmpty()) + interfaces = QNetworkInterface::allInterfaces(); + + // create configuration for each interface + while (!interfaces.isEmpty()) { + QNetworkInterface interface = interfaces.takeFirst(); + + if (!interface.isValid()) + continue; + + // ignore loopback interface + if (interface.flags() & QNetworkInterface::IsLoopBack) + continue; + + // ignore WLAN interface handled in seperate engine + if (qGetInterfaceType(interface.name()) == "WLAN") + continue; + + QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; + const QString humanReadableName = interface.humanReadableName(); + cpPriv->name = humanReadableName.isEmpty() ? interface.name() : humanReadableName; + cpPriv->isValid = true; + + uint identifier; + if (interface.index()) + identifier = qHash(QLatin1String("NLA:") + QString::number(interface.index())); + else + identifier = qHash(QLatin1String("NLA:") + interface.hardwareAddress()); + + cpPriv->id = QString::number(identifier); + cpPriv->state = QNetworkConfiguration::Discovered; + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + if (interface.flags() & QNetworkInterface::IsUp) + cpPriv->state |= QNetworkConfiguration::Active; + + configurationInterface[identifier] = interface.name(); + + foundConfigurations.append(cpPriv); + } + + pollTimer.start(); + + return foundConfigurations; +} + +QString QGenericEngine::getInterfaceFromId(const QString &id) +{ + return configurationInterface.value(id.toUInt()); +} + +bool QGenericEngine::hasIdentifier(const QString &id) +{ + return configurationInterface.contains(id.toUInt()); +} + +QString QGenericEngine::bearerName(const QString &id) +{ + QString interface = getInterfaceFromId(id); + + if (interface.isEmpty()) + return QString(); + + return qGetInterfaceType(interface); +} + +void QGenericEngine::connectToId(const QString &id) +{ + emit connectionError(id, OperationNotSupported); +} + +void QGenericEngine::disconnectFromId(const QString &id) +{ + emit connectionError(id, OperationNotSupported); +} + +void QGenericEngine::requestUpdate() +{ + emit configurationsChanged(); +} + +QGenericEngine *QGenericEngine::instance() +{ + return genericEngine(); +} + +#include "moc_qgenericengine_p.cpp" +QTM_END_NAMESPACE + diff --git a/src/network/bearer/qgenericengine_p.h b/src/network/bearer/qgenericengine_p.h new file mode 100644 index 0000000..976776e --- /dev/null +++ b/src/network/bearer/qgenericengine_p.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 QGENERICENGINE_P_H +#define QGENERICENGINE_P_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 "qnetworksessionengine_p.h" + +#include +#include + +QTM_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; + +class QGenericEngine : public QNetworkSessionEngine +{ + Q_OBJECT + +public: + QGenericEngine(QObject *parent = 0); + ~QGenericEngine(); + + QList getConfigurations(bool *ok = 0); + QString getInterfaceFromId(const QString &id); + bool hasIdentifier(const QString &id); + + QString bearerName(const QString &id); + + void connectToId(const QString &id); + void disconnectFromId(const QString &id); + + void requestUpdate(); + + static QGenericEngine *instance(); + +private: + QMap configurationInterface; + QTimer pollTimer; +}; + +QTM_END_NAMESPACE + +#endif + diff --git a/src/network/bearer/qnativewifiengine_win.cpp b/src/network/bearer/qnativewifiengine_win.cpp new file mode 100644 index 0000000..d8fe5fb --- /dev/null +++ b/src/network/bearer/qnativewifiengine_win.cpp @@ -0,0 +1,726 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 "qnativewifiengine_win_p.h" +#include "qnetworkconfiguration_p.h" + +#include +#include +#include +#include + +#include + +#include +#undef interface + +QTM_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC(QNativeWifiEngine, nativeWifiEngine) + +#define WLAN_MAX_NAME_LENGTH 256 +#define WLAN_MAX_PHY_TYPE_NUMBER 8 +#define WLAN_NOTIFICATION_SOURCE_ALL 0x0000ffff +#define WLAN_AVAILABLE_NETWORK_CONNECTED 1 +#define WLAN_AVAILABLE_NETWORK_HAS_PROFILE 2 +#define DOT11_SSID_MAX_LENGTH 32 + +struct WLAN_NOTIFICATION_DATA { + DWORD NotificationSource; + DWORD NotificationCode; + GUID InterfaceGuid; + DWORD dwDataSize; + PVOID pData; +}; + +enum WLAN_INTERFACE_STATE { + wlan_interface_state_not_ready = 0, + wlan_interface_state_connected, + wlan_interface_state_ad_hoc_network_formed, + wlan_interface_state_disconnecting, + wlan_interface_state_disconnected, + wlan_interface_state_associating, + wlan_interface_state_discovering, + wlan_interface_state_authenticating +}; + +struct WLAN_INTERFACE_INFO { + GUID InterfaceGuid; + WCHAR strInterfaceDescription[WLAN_MAX_NAME_LENGTH]; + WLAN_INTERFACE_STATE isState; +}; + +struct WLAN_INTERFACE_INFO_LIST { + DWORD dwNumberOfItems; + DWORD dwIndex; + WLAN_INTERFACE_INFO InterfaceInfo[1]; +}; + +struct DOT11_SSID { + ULONG uSSIDLength; + UCHAR ucSSID[DOT11_SSID_MAX_LENGTH]; +}; + +struct NDIS_OBJECT_HEADER { + UCHAR Type; + UCHAR Revision; + USHORT Size; +}; + +typedef UCHAR DOT11_MAC_ADDRESS[6]; +struct DOT11_BSSID_LIST { + NDIS_OBJECT_HEADER Header; + ULONG uNumberOfEntries; + ULONG uTotalNumOfEntries; + DOT11_MAC_ADDRESS BSSIDs[1]; +}; + +enum DOT11_BSS_TYPE { + dot11_BSS_type_infrastructure = 1, + dot11_BSS_type_independent = 2, + dot11_BSS_type_any = 3 +}; + +enum DOT11_PHY_TYPE { + dot11_phy_type_unknown = 0, + dot11_phy_type_any = dot11_phy_type_unknown, + dot11_phy_type_fhss = 1, + dot11_phy_type_dsss = 2, + dot11_phy_type_irbaseband = 3, + dot11_phy_type_ofdm = 4, + dot11_phy_type_hrdsss = 5, + dot11_phy_type_erp = 6, + dot11_phy_type_ht = 7, + dot11_phy_type_IHV_start = 0x80000000, + dot11_phy_type_IHV_end = 0xffffffff +}; + +enum DOT11_AUTH_ALGORITHM { + DOT11_AUTH_ALGO_80211_OPEN = 1, + DOT11_AUTH_ALGO_80211_SHARED_KEY = 2, + DOT11_AUTH_ALGO_WPA = 3, + DOT11_AUTH_ALGO_WPA_PSK = 4, + DOT11_AUTH_ALGO_WPA_NONE = 5, + DOT11_AUTH_ALGO_RSNA = 6, + DOT11_AUTH_ALGO_RSNA_PSK = 7, + DOT11_AUTH_ALGO_IHV_START = 0x80000000, + DOT11_AUTH_ALGO_IHV_END = 0xffffffff +}; + +enum DOT11_CIPHER_ALGORITHM { + DOT11_CIPHER_ALGO_NONE = 0x00, + DOT11_CIPHER_ALGO_WEP40 = 0x01, + DOT11_CIPHER_ALGO_TKIP = 0x02, + DOT11_CIPHER_ALGO_CCMP = 0x04, + DOT11_CIPHER_ALGO_WEP104 = 0x05, + DOT11_CIPHER_ALGO_WPA_USE_GROUP = 0x100, + DOT11_CIPHER_ALGO_RSN_USE_GROUP = 0x100, + DOT11_CIPHER_ALGO_WEP = 0x101, + DOT11_CIPHER_ALGO_IHV_START = 0x80000000, + DOT11_CIPHER_ALGO_IHV_END = 0xffffffff +}; + +struct WLAN_AVAILABLE_NETWORK { + WCHAR strProfileName[WLAN_MAX_NAME_LENGTH]; + DOT11_SSID dot11Ssid; + DOT11_BSS_TYPE dot11BssType; + ULONG uNumberOfBssids; + BOOL bNetworkConnectable; + DWORD wlanNotConnectableReason; + ULONG uNumberOfPhyTypes; + DOT11_PHY_TYPE dot11PhyTypes[WLAN_MAX_PHY_TYPE_NUMBER]; + BOOL bMorePhyTypes; + ULONG wlanSignalQuality; + BOOL bSecurityEnabled; + DOT11_AUTH_ALGORITHM dot11DefaultAuthAlgorithm; + DOT11_CIPHER_ALGORITHM dot11DefaultCipherAlgorithm; + DWORD dwFlags; + DWORD dwReserved; +}; + +struct WLAN_AVAILABLE_NETWORK_LIST { + DWORD dwNumberOfItems; + DWORD dwIndex; + WLAN_AVAILABLE_NETWORK Network[1]; +}; + +enum WLAN_INTF_OPCODE { + wlan_intf_opcode_autoconf_start = 0x000000000, + wlan_intf_opcode_autoconf_enabled, + wlan_intf_opcode_background_scan_enabled, + wlan_intf_opcode_media_streaming_mode, + wlan_intf_opcode_radio_state, + wlan_intf_opcode_bss_type, + wlan_intf_opcode_interface_state, + wlan_intf_opcode_current_connection, + wlan_intf_opcode_channel_number, + wlan_intf_opcode_supported_infrastructure_auth_cipher_pairs, + wlan_intf_opcode_supported_adhoc_auth_cipher_pairs, + wlan_intf_opcode_supported_country_or_region_string_list, + wlan_intf_opcode_current_operation_mode, + wlan_intf_opcode_supported_safe_mode, + wlan_intf_opcode_certified_safe_mode, + wlan_intf_opcode_autoconf_end = 0x0fffffff, + wlan_intf_opcode_msm_start = 0x10000100, + wlan_intf_opcode_statistics, + wlan_intf_opcode_rssi, + wlan_intf_opcode_msm_end = 0x1fffffff, + wlan_intf_opcode_security_start = 0x20010000, + wlan_intf_opcode_security_end = 0x2fffffff, + wlan_intf_opcode_ihv_start = 0x30000000, + wlan_intf_opcode_ihv_end = 0x3fffffff +}; + +enum WLAN_OPCODE_VALUE_TYPE { + wlan_opcode_value_type_query_only = 0, + wlan_opcode_value_type_set_by_group_policy, + wlan_opcode_value_type_set_by_user, + wlan_opcode_value_type_invalid +}; + +enum WLAN_CONNECTION_MODE { + wlan_connection_mode_profile = 0, + wlan_connection_mode_temporary_profile, + wlan_connection_mode_discovery_secure, + wlan_connection_mode_discovery_unsecure, + wlan_connection_mode_auto, + wlan_connection_mode_invalid +}; + +struct WLAN_CONNECTION_PARAMETERS { + WLAN_CONNECTION_MODE wlanConnectionMode; + LPCWSTR strProfile; + DOT11_SSID *pDot11Ssid; + DOT11_BSSID_LIST *pDesiredBssidList; + DOT11_BSS_TYPE dot11BssType; + DWORD dwFlags; +}; + +struct WLAN_RAW_DATA { + DWORD dwDataSize; + BYTE DataBlob[1]; +}; + +enum WLAN_NOTIFICATION_ACM { + wlan_notification_acm_start = 0, + wlan_notification_acm_autoconf_enabled, + wlan_notification_acm_autoconf_disabled, + wlan_notification_acm_background_scan_enabled, + wlan_notification_acm_background_scan_disabled, + wlan_notification_acm_bss_type_change, + wlan_notification_acm_power_setting_change, + wlan_notification_acm_scan_complete, + wlan_notification_acm_scan_fail, + wlan_notification_acm_connection_start, + wlan_notification_acm_connection_complete, + wlan_notification_acm_connection_attempt_fail, + wlan_notification_acm_filter_list_change, + wlan_notification_acm_interface_arrival, + wlan_notification_acm_interface_removal, + wlan_notification_acm_profile_change, + wlan_notification_acm_profile_name_change, + wlan_notification_acm_profiles_exhausted, + wlan_notification_acm_network_not_available, + wlan_notification_acm_network_available, + wlan_notification_acm_disconnecting, + wlan_notification_acm_disconnected, + wlan_notification_acm_adhoc_network_state_change, + wlan_notification_acm_end +}; + +struct WLAN_ASSOCIATION_ATTRIBUTES { + DOT11_SSID dot11Ssid; + DOT11_BSS_TYPE dot11BssType; + DOT11_MAC_ADDRESS dot11Bssid; + DOT11_PHY_TYPE dot11PhyType; + ULONG uDot11PhyIndex; + ULONG wlanSignalQuality; + ULONG ulRxRate; + ULONG ulTxRate; +}; + +struct WLAN_SECURITY_ATTRIBUTES { + BOOL bSecurityEnabled; + BOOL bOneXEnabled; + DOT11_AUTH_ALGORITHM dot11AuthAlgorithm; + DOT11_CIPHER_ALGORITHM dot11CipherAlgorithm; +}; + +struct WLAN_CONNECTION_ATTRIBUTES { + WLAN_INTERFACE_STATE isState; + WLAN_CONNECTION_MODE wlanConnectionMode; + WCHAR strProfileName[WLAN_MAX_NAME_LENGTH]; + WLAN_ASSOCIATION_ATTRIBUTES wlanAssociationAttributes; + WLAN_SECURITY_ATTRIBUTES wlanSecurityAttributes; +}; + +typedef void (WINAPI *WLAN_NOTIFICATION_CALLBACK)(WLAN_NOTIFICATION_DATA *, PVOID); + +typedef DWORD (WINAPI *WlanOpenHandleProto) + (DWORD dwClientVersion, PVOID pReserved, PDWORD pdwNegotiatedVersion, PHANDLE phClientHandle); +typedef DWORD (WINAPI *WlanRegisterNotificationProto) + (HANDLE hClientHandle, DWORD dwNotifSource, BOOL bIgnoreDuplicate, + WLAN_NOTIFICATION_CALLBACK funcCallback, PVOID pCallbackContext, + PVOID pReserved, PDWORD pdwPrevNotifSource); +typedef DWORD (WINAPI *WlanEnumInterfacesProto) + (HANDLE hClientHandle, PVOID pReserved, WLAN_INTERFACE_INFO_LIST **ppInterfaceList); +typedef DWORD (WINAPI *WlanGetAvailableNetworkListProto) + (HANDLE hClientHandle, const GUID* pInterfaceGuid, DWORD dwFlags, PVOID pReserved, + WLAN_AVAILABLE_NETWORK_LIST **ppAvailableNetworkList); +typedef DWORD (WINAPI *WlanQueryInterfaceProto) + (HANDLE hClientHandle, const GUID *pInterfaceGuid, WLAN_INTF_OPCODE OpCode, PVOID pReserved, + PDWORD pdwDataSize, PVOID *ppData, WLAN_OPCODE_VALUE_TYPE *pWlanOpcodeValueType); +typedef DWORD (WINAPI *WlanConnectProto) + (HANDLE hClientHandle, const GUID *pInterfaceGuid, + const WLAN_CONNECTION_PARAMETERS *pConnectionParameters, PVOID pReserved); +typedef DWORD (WINAPI *WlanDisconnectProto) + (HANDLE hClientHandle, const GUID *pInterfaceGuid, PVOID pReserved); +typedef DWORD (WINAPI *WlanScanProto) + (HANDLE hClientHandle, const GUID *pInterfaceGuid, const DOT11_SSID *pDot11Ssid, + const WLAN_RAW_DATA *pIeData, PVOID pReserved); +typedef VOID (WINAPI *WlanFreeMemoryProto)(PVOID pMemory); +typedef DWORD (WINAPI *WlanCloseHandleProto)(HANDLE hClientHandle, PVOID pReserved); + +static WlanOpenHandleProto local_WlanOpenHandle = 0; +static WlanRegisterNotificationProto local_WlanRegisterNotification = 0; +static WlanEnumInterfacesProto local_WlanEnumInterfaces = 0; +static WlanGetAvailableNetworkListProto local_WlanGetAvailableNetworkList = 0; +static WlanQueryInterfaceProto local_WlanQueryInterface = 0; +static WlanConnectProto local_WlanConnect = 0; +static WlanDisconnectProto local_WlanDisconnect = 0; +static WlanScanProto local_WlanScan = 0; +static WlanFreeMemoryProto local_WlanFreeMemory = 0; +static WlanCloseHandleProto local_WlanCloseHandle = 0; + +static void resolveLibrary() +{ + static volatile bool triedResolve = false; + + if (!triedResolve) { +#ifndef QT_NO_THREAD + QMutexLocker locker(QMutexPool::globalInstanceGet(&local_WlanOpenHandle)); +#endif + + if (!triedResolve) { + local_WlanOpenHandle = (WlanOpenHandleProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanOpenHandle"); + local_WlanRegisterNotification = (WlanRegisterNotificationProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanRegisterNotification"); + local_WlanEnumInterfaces = (WlanEnumInterfacesProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanEnumInterfaces"); + local_WlanGetAvailableNetworkList = (WlanGetAvailableNetworkListProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanGetAvailableNetworkList"); + local_WlanQueryInterface = (WlanQueryInterfaceProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanQueryInterface"); + local_WlanConnect = (WlanConnectProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanConnect"); + local_WlanDisconnect = (WlanDisconnectProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanDisconnect"); + local_WlanScan = (WlanScanProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanScan"); + local_WlanFreeMemory = (WlanFreeMemoryProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanFreeMemory"); + local_WlanCloseHandle = (WlanCloseHandleProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanCloseHandle"); + + triedResolve = true; + } + } +} + +void qNotificationCallback(WLAN_NOTIFICATION_DATA *data, QNativeWifiEngine *d) +{ + Q_UNUSED(d); + + switch (data->NotificationCode) { + case wlan_notification_acm_connection_complete: + case wlan_notification_acm_disconnected: + d->emitConfigurationsChanged(); + break; + default: + qDebug() << "wlan unknown notification"; + } +} + +QNativeWifiEngine::QNativeWifiEngine(QObject *parent) +: QNetworkSessionEngine(parent), handle(0) +{ + DWORD clientVersion; + + DWORD result = local_WlanOpenHandle(1, 0, &clientVersion, &handle); + if (result != ERROR_SUCCESS) { + if (result != ERROR_SERVICE_NOT_ACTIVE) + qWarning("%s: WlanOpenHandle failed with error %ld\n", __FUNCTION__, result); + + return; + } + + result = local_WlanRegisterNotification(handle, WLAN_NOTIFICATION_SOURCE_ALL, true, + WLAN_NOTIFICATION_CALLBACK(qNotificationCallback), + this, 0, 0); + if (result != ERROR_SUCCESS) + qWarning("%s: WlanRegisterNotification failed with error %ld\n", __FUNCTION__, result); + + // On Windows XP SP2 and SP3 only connection and disconnection notifications are available. + // We need to poll for changes in available wireless networks. + connect(&pollTimer, SIGNAL(timeout()), this, SIGNAL(configurationsChanged())); + pollTimer.setInterval(10000); +} + +QNativeWifiEngine::~QNativeWifiEngine() +{ + local_WlanCloseHandle(handle, 0); +} + +QList QNativeWifiEngine::getConfigurations(bool *ok) +{ + if (ok) + *ok = false; + + QList foundConfigurations; + + // enumerate interfaces + WLAN_INTERFACE_INFO_LIST *interfaceList; + DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); + return foundConfigurations; + } + + for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { + const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i]; + + WLAN_AVAILABLE_NETWORK_LIST *networkList; + result = local_WlanGetAvailableNetworkList(handle, &interface.InterfaceGuid, + 3, 0, &networkList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanGetAvailableNetworkList failed with error %ld\n", + __FUNCTION__, result); + continue; + } + + QStringList seenNetworks; + + for (unsigned int j = 0; j < networkList->dwNumberOfItems; ++j) { + WLAN_AVAILABLE_NETWORK &network = networkList->Network[j]; + + QString networkName; + + if (network.strProfileName[0] != 0) { + networkName = QString::fromWCharArray(network.strProfileName); + } else { + networkName = QByteArray(reinterpret_cast(network.dot11Ssid.ucSSID), + network.dot11Ssid.uSSIDLength); + } + + // don't add duplicate networks + if (seenNetworks.contains(networkName)) + continue; + else + seenNetworks.append(networkName); + + QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; + + cpPriv->isValid = true; + + cpPriv->name = networkName; + cpPriv->id = QString::number(qHash(QLatin1String("WLAN:") + cpPriv->name)); + + if (!(network.dwFlags & WLAN_AVAILABLE_NETWORK_HAS_PROFILE)) + cpPriv->state = QNetworkConfiguration::Undefined; + + if (network.strProfileName[0] != 0) { + if (network.bNetworkConnectable) { + if (network.dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED) + cpPriv->state = QNetworkConfiguration::Active; + else + cpPriv->state = QNetworkConfiguration::Discovered; + } else { + cpPriv->state = QNetworkConfiguration::Defined; + } + } + + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + + foundConfigurations.append(cpPriv); + } + + local_WlanFreeMemory(networkList); + } + + local_WlanFreeMemory(interfaceList); + + if (ok) + *ok = true; + + pollTimer.start(); + + return foundConfigurations; +} + +QString QNativeWifiEngine::getInterfaceFromId(const QString &id) +{ + // enumerate interfaces + WLAN_INTERFACE_INFO_LIST *interfaceList; + DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); + return QString(); + } + + for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { + const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i]; + + DWORD dataSize; + WLAN_CONNECTION_ATTRIBUTES *connectionAttributes; + result = local_WlanQueryInterface(handle, &interface.InterfaceGuid, + wlan_intf_opcode_current_connection, 0, &dataSize, + reinterpret_cast(&connectionAttributes), 0); + if (result != ERROR_SUCCESS) { + if (result != ERROR_INVALID_STATE) + qWarning("%s: WlanQueryInterface failed with error %ld\n", __FUNCTION__, result); + + continue; + } + + if (qHash(QLatin1String("WLAN:") + + QString::fromWCharArray(connectionAttributes->strProfileName)) == id.toUInt()) { + QString guid("{%1-%2-%3-%4%5-%6%7%8%9%10%11}"); + + guid = guid.arg(interface.InterfaceGuid.Data1, 8, 16, QChar('0')); + guid = guid.arg(interface.InterfaceGuid.Data2, 4, 16, QChar('0')); + guid = guid.arg(interface.InterfaceGuid.Data3, 4, 16, QChar('0')); + for (int i = 0; i < 8; ++i) + guid = guid.arg(interface.InterfaceGuid.Data4[i], 2, 16, QChar('0')); + + local_WlanFreeMemory(connectionAttributes); + + return guid.toUpper(); + } + + local_WlanFreeMemory(connectionAttributes); + } + + return QString(); +} + +bool QNativeWifiEngine::hasIdentifier(const QString &id) +{ + // enumerate interfaces + WLAN_INTERFACE_INFO_LIST *interfaceList; + DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); + return false; + } + + for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { + const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i]; + + WLAN_AVAILABLE_NETWORK_LIST *networkList; + result = local_WlanGetAvailableNetworkList(handle, &interface.InterfaceGuid, + 3, 0, &networkList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanGetAvailableNetworkList failed with error %ld\n", + __FUNCTION__, result); + continue; + } + + for (unsigned int j = 0; j < networkList->dwNumberOfItems; ++j) { + WLAN_AVAILABLE_NETWORK &network = networkList->Network[j]; + + QString networkName; + + if (network.strProfileName[0] != 0) { + networkName = QString::fromWCharArray(network.strProfileName); + } else { + networkName = QByteArray(reinterpret_cast(network.dot11Ssid.ucSSID), + network.dot11Ssid.uSSIDLength); + } + + if (qHash(QLatin1String("WLAN:") + networkName) == id.toUInt()) { + local_WlanFreeMemory(networkList); + local_WlanFreeMemory(interfaceList); + return true; + } + } + + local_WlanFreeMemory(networkList); + } + + local_WlanFreeMemory(interfaceList); + + return false; +} + +QString QNativeWifiEngine::bearerName(const QString &) +{ + return QLatin1String("WLAN"); +} + +void QNativeWifiEngine::connectToId(const QString &id) +{ + WLAN_INTERFACE_INFO_LIST *interfaceList; + DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); + emit connectionError(id, InterfaceLookupError); + return; + } + + QString profile; + + for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { + const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i]; + + WLAN_AVAILABLE_NETWORK_LIST *networkList; + result = local_WlanGetAvailableNetworkList(handle, &interface.InterfaceGuid, + 3, 0, &networkList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanGetAvailableNetworkList failed with error %ld\n", + __FUNCTION__, result); + continue; + } + + for (unsigned int j = 0; j < networkList->dwNumberOfItems; ++j) { + WLAN_AVAILABLE_NETWORK &network = networkList->Network[j]; + + profile = QString::fromWCharArray(network.strProfileName); + + if (qHash(QLatin1String("WLAN:") + profile) == id.toUInt()) + break; + else + profile.clear(); + } + + local_WlanFreeMemory(networkList); + + if (!profile.isEmpty()) { + WLAN_CONNECTION_PARAMETERS parameters; + parameters.wlanConnectionMode = wlan_connection_mode_profile; + parameters.strProfile = reinterpret_cast(profile.utf16()); + parameters.pDot11Ssid = 0; + parameters.pDesiredBssidList = 0; + parameters.dot11BssType = dot11_BSS_type_any; + parameters.dwFlags = 0; + + DWORD result = local_WlanConnect(handle, &interface.InterfaceGuid, ¶meters, 0); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanConnect failed with error %ld\n", __FUNCTION__, result); + emit connectionError(id, ConnectError); + break; + } + + break; + } + } + + local_WlanFreeMemory(interfaceList); + + if (profile.isEmpty()) + emit connectionError(id, InterfaceLookupError); +} + +void QNativeWifiEngine::disconnectFromId(const QString &id) +{ + QString interface = getInterfaceFromId(id); + + if (interface.isEmpty()) { + emit connectionError(id, InterfaceLookupError); + return; + } + + QStringList split = interface.mid(1, interface.length() - 2).split('-'); + + GUID guid; + guid.Data1 = split.at(0).toUInt(0, 16); + guid.Data2 = split.at(1).toUShort(0, 16); + guid.Data3 = split.at(2).toUShort(0, 16); + guid.Data4[0] = split.at(3).left(2).toUShort(0, 16); + guid.Data4[1] = split.at(3).right(2).toUShort(0, 16); + for (int i = 0; i < 6; ++i) + guid.Data4[i + 2] = split.at(4).mid(i*2, 2).toUShort(0, 16); + + DWORD result = local_WlanDisconnect(handle, &guid, 0); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanDisconnect failed with error %ld\n", __FUNCTION__, result); + emit connectionError(id, DisconnectionError); + return; + } +} + +void QNativeWifiEngine::requestUpdate() +{ + // enumerate interfaces + WLAN_INTERFACE_INFO_LIST *interfaceList; + DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); + return; + } + + for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { + result = local_WlanScan(handle, &interfaceList->InterfaceInfo[i].InterfaceGuid, 0, 0, 0); + if (result != ERROR_SUCCESS) + qWarning("%s: WlanScan failed with error %ld\n", __FUNCTION__, result); + } +} + +QNativeWifiEngine *QNativeWifiEngine::instance() +{ + resolveLibrary(); + + // native wifi dll not available + if (!local_WlanOpenHandle) + return 0; + + QNativeWifiEngine *engine = nativeWifiEngine(); + + // could not initialise subsystem + if (engine && engine->handle == 0) + return 0; + + return engine; +} + +#include "moc_qnativewifiengine_win_p.cpp" + +QTM_END_NAMESPACE diff --git a/src/network/bearer/qnativewifiengine_win_p.h b/src/network/bearer/qnativewifiengine_win_p.h new file mode 100644 index 0000000..0d5bcb0 --- /dev/null +++ b/src/network/bearer/qnativewifiengine_win_p.h @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 QNATIVEWIFIENGINE_P_H +#define QNATIVEWIFIENGINE_P_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 "qnetworksessionengine_p.h" + +#include + +QTM_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; + +class QNativeWifiEngine : public QNetworkSessionEngine +{ + Q_OBJECT + +public: + QNativeWifiEngine(QObject *parent = 0); + ~QNativeWifiEngine(); + + QList getConfigurations(bool *ok = 0); + QString getInterfaceFromId(const QString &id); + bool hasIdentifier(const QString &id); + + QString bearerName(const QString &id); + + void connectToId(const QString &id); + void disconnectFromId(const QString &id); + + void requestUpdate(); + + inline void emitConfigurationsChanged() { emit configurationsChanged(); } + + static QNativeWifiEngine *instance(); + +private: + QTimer pollTimer; + + Qt::HANDLE handle; +}; + +QTM_END_NAMESPACE + +#endif diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp new file mode 100644 index 0000000..264f0df --- /dev/null +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -0,0 +1,333 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 "qnetworkconfigmanager.h" + +#ifdef Q_OS_SYMBIAN +#include "qnetworkconfigmanager_s60_p.h" +#else +#include "qnetworkconfigmanager_p.h" +#endif + +QTM_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC(QNetworkConfigurationManagerPrivate, connManager); + +/*! + \class QNetworkConfigurationManager + + \brief The QNetworkConfigurationManager class manages the network configurations provided + by the system. + + \inmodule QtNetwork + \ingroup bearer + + QNetworkConfigurationManager provides access to the network configurations known to the system and + enables applications to detect the system capabilities (with regards to network sessions) at runtime. + + A QNetworkConfiguration abstracts a set of configuration options describing how a + network interface has to be configured to connect to a particular target network. + QNetworkConfigurationManager maintains and updates the global list of + QNetworkConfigurations. Applications can access and filter this list via + allConfigurations(). If a new configuration is added or an existing one is removed or changed + the configurationAdded(), configurationRemoved() and configurationChanged() signals are emitted + respectively. + + The defaultConfiguration() can be used when intending to immediately create a new + network session without caring about the particular configuration. It returns + a \l QNetworkConfiguration::Discovered configuration. If there are not any + discovered ones an invalid configuration is returned. + + Some configuration updates may require some time to perform updates. A WLAN scan is + such an example. Unless the platform performs internal updates it may be required to + manually trigger configuration updates via QNetworkConfigurationManager::updateConfigurations(). + The completion of the update process is indicted by emitting the updateCompleted() + signal. The update process ensures that every existing QNetworkConfiguration instance + is updated. There is no need to ask for a renewed configuration list via allConfigurations(). + + \sa QNetworkConfiguration +*/ + +/*! + \fn void QNetworkConfigurationManager::configurationAdded(const QNetworkConfiguration& config) + + This signal is emitted whenever a new network configuration is added to the system. The new + configuration is specified by \a config. +*/ + +/*! + \fn void QNetworkConfigurationManager::configurationRemoved(const QNetworkConfiguration& configuration) + + This signal is emitted when a configuration is about to be removed from the system. The removed + \a configuration is invalid but retains name and identifier. +*/ + +/*! + \fn void QNetworkConfigurationManager::updateCompleted() + + This signal is emitted when the configuration update has been completed. Such an update can + be initiated via \l updateConfigurations(). +*/ + +/*! \fn void QNetworkConfigurationManager::configurationChanged(const QNetworkConfiguration& config) + + This signal is emitted when the \l {QNetworkConfiguration::state()}{state} of \a config changes. +*/ + +/*! + \fn void QNetworkConfigurationManager::onlineStateChanged(bool isOnline) + + This signal is emitted when the device changes from online to offline mode or vice versa. + \a isOnline represents the new state of the device. + + The state is considered to be online for as long as + \l{allConfigurations()}{allConfigurations}(QNetworkConfiguration::Active) returns a list with + at least one entry. +*/ + +/*! + \enum QNetworkConfigurationManager::Capability + + Specifies the system capabilities of the bearer API. The possible values are: + + \value CanStartAndStopInterfaces Network sessions and their underlying access points can be + started and stopped. If this flag is not set QNetworkSession + can only monitor but not influence the state of access points. + On some platforms this feature may require elevated user + permissions. This option is platform specific and may not + always be available. + \value DirectConnectionRouting Network sessions and their sockets can be bound to a + particular network interface. Any packet that passes through + the socket goes to the specified network interface and thus + disregards standard routing table entries. This may be useful + when two interfaces can reach overlapping IP ranges or an + application has specific needs in regards to target networks. + This option is platform specific and may not always be + available. + \value SystemSessionSupport If this flag is set the underlying platform ensures that a + network interface is not shut down until the last network + session has been \l{QNetworkSession::close()}{closed()}. This + works across multiple processes. If the platform session + support is missing this API can only ensure the above behavior + for network sessions within the same process. + In general mobile platforms (such as Symbian/S60) have such + support whereas most desktop platform lack this capability. + \value ApplicationLevelRoaming The system gives applications control over the systems roaming + behavior. Applications can initiate roaming (in case the + current link is not suitable) and are consulted if the system + has identified a more suitable access point. + \value ForcedRoaming The system disconnects an existing access point and reconnects + via a more suitable one. The application does not have any + control over this process and has to reconnect its active + sockets. + \value DataStatistics If this flag is set QNetworkSession can provide statistics + about transmitted and received data. +*/ + +/*! + Constructs a QNetworkConfigurationManager with the given \a parent. +*/ +QNetworkConfigurationManager::QNetworkConfigurationManager( QObject* parent ) + : QObject(parent) +{ + QNetworkConfigurationManagerPrivate* priv = connManager(); + connect(priv, SIGNAL(configurationAdded(QNetworkConfiguration)), + this, SIGNAL(configurationAdded(QNetworkConfiguration))); + connect(priv, SIGNAL(configurationRemoved(QNetworkConfiguration)), + this, SIGNAL(configurationRemoved(QNetworkConfiguration))); + connect(priv, SIGNAL(configurationUpdateComplete()), + this, SIGNAL(updateCompleted())); + connect(priv, SIGNAL(onlineStateChanged(bool)), + this, SIGNAL(onlineStateChanged(bool))); + connect(priv, SIGNAL(configurationChanged(QNetworkConfiguration)), + this, SIGNAL(configurationChanged(QNetworkConfiguration))); +} + +/*! + Frees the resources associated with the QNetworkConfigurationManager object. +*/ +QNetworkConfigurationManager::~QNetworkConfigurationManager() +{ +} + + +/*! + Returns the default configuration to be used. This function always returns a discovered + configuration; otherwise an invalid configuration. + + In some cases it may be required to call updateConfigurations() and wait for the + updateCompleted() signal before calling this function. + + \sa allConfigurations() +*/ +QNetworkConfiguration QNetworkConfigurationManager::defaultConfiguration() const +{ + return connManager()->defaultConfiguration(); +} + +/*! + Returns the list of configurations which comply with the given \a filter. + + By default this function returns all (defined and undefined) configurations. + + A wireless network with a particular SSID may only be accessible in a + certain area despite the fact that the system has a valid configuration + for it. Therefore the filter flag may be used to limit the list to + discovered and possibly connected configurations only. + + If \a filter is set to zero this function returns all possible configurations. + + Note that this function returns the states for all configurations as they are known at + the time of this function call. If for instance a configuration of type WLAN is defined + the system may have to perform a WLAN scan in order to determine whether it is + actually available. To obtain the most accurate state updateConfigurations() should + be used to update each configuration's state. Note that such an update may require + some time. It's completion is signalled by updateCompleted(). In the absence of a + configuration update this function returns the best estimate at the time of the call. +*/ +QList QNetworkConfigurationManager::allConfigurations(QNetworkConfiguration::StateFlags filter) const +{ + QList result; + QNetworkConfigurationManagerPrivate* conPriv = connManager(); + QList cpsIdents = conPriv->accessPointConfigurations.keys(); + + //find all InternetAccessPoints + foreach( QString ii, cpsIdents) { + QExplicitlySharedDataPointer p = + conPriv->accessPointConfigurations.value(ii); + if ( (p->state & filter) == filter ) { + QNetworkConfiguration pt; + pt.d = conPriv->accessPointConfigurations.value(ii); + result << pt; + } + } + + //find all service networks + cpsIdents = conPriv->snapConfigurations.keys(); + foreach( QString ii, cpsIdents) { + QExplicitlySharedDataPointer p = + conPriv->snapConfigurations.value(ii); + if ( (p->state & filter) == filter ) { + QNetworkConfiguration pt; + pt.d = conPriv->snapConfigurations.value(ii); + result << pt; + } + } + + return result; +} + +/*! + Returns the QNetworkConfiguration for \a identifier; otherwise returns an + invalid QNetworkConfiguration. + + \sa QNetworkConfiguration::identifier() +*/ +QNetworkConfiguration QNetworkConfigurationManager::configurationFromIdentifier(const QString& identifier) const +{ + QNetworkConfigurationManagerPrivate* conPriv = connManager(); + QNetworkConfiguration item; + if (conPriv->accessPointConfigurations.contains(identifier)) + item.d = conPriv->accessPointConfigurations.value(identifier); + else if (conPriv->snapConfigurations.contains(identifier)) + item.d = conPriv->snapConfigurations.value(identifier); + else if (conPriv->userChoiceConfigurations.contains(identifier)) + item.d = conPriv->userChoiceConfigurations.value(identifier); + return item; + +} + +/*! + Returns true if the system is considered to be connected to another device via an active + network interface; otherwise returns false. + + This is equivalent to the following code snippet: + + \code + QNetworkConfigurationManager mgr; + QList activeConfigs = mgr.allConfigurations(QNetworkConfiguration::Active) + if (activeConfigs.count() > 0) + Q_ASSERT(mgr.isOnline()) + else + Q_ASSERT(!mgr.isOnline()) + \endcode + + \sa onlineStateChanged() +*/ +bool QNetworkConfigurationManager::isOnline() const +{ + QNetworkConfigurationManagerPrivate* conPriv = connManager(); + Q_UNUSED(conPriv); + QList activeConfigs = allConfigurations(QNetworkConfiguration::Active); + return activeConfigs.count() > 0; +} + +/*! + Returns the capabilities supported by the current platform. +*/ +QNetworkConfigurationManager::Capabilities QNetworkConfigurationManager::capabilities() const +{ + return connManager()->capFlags; +} + +/*! + Initiates an update of all configurations. This may be used to initiate WLAN scans or other + time consuming updates which may be required to obtain the correct state for configurations. + + This call is asynchronous. On completion of this update the updateCompleted() signal is + emitted. If new configurations are discovered or old ones were removed or changed the update + process may trigger the emission of one or multiple configurationAdded(), + configurationRemoved() and configurationChanged() signals. + + If a configuration state changes as a result of this update all existing QNetworkConfiguration + instances are updated automatically. + + \sa allConfigurations() +*/ +void QNetworkConfigurationManager::updateConfigurations() +{ + connManager()->performAsyncConfigurationUpdate(); +} + +#include "moc_qnetworkconfigmanager.cpp" + +QTM_END_NAMESPACE + diff --git a/src/network/bearer/qnetworkconfigmanager.h b/src/network/bearer/qnetworkconfigmanager.h new file mode 100644 index 0000000..98641f6 --- /dev/null +++ b/src/network/bearer/qnetworkconfigmanager.h @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 QNETWORKCONFIGURATIONMANAGER_H +#define QNETWORKCONFIGURATIONMANAGER_H + +#include "qmobilityglobal.h" + +#include +#include "qnetworkconfiguration.h" + +QT_BEGIN_HEADER + +QTM_BEGIN_NAMESPACE + +class QNetworkConfigurationManagerPrivate; +class Q_BEARER_EXPORT QNetworkConfigurationManager : public QObject +{ + Q_OBJECT + +public: + + enum Capability { + CanStartAndStopInterfaces = 0x00000001, + DirectConnectionRouting = 0x00000002, + SystemSessionSupport = 0x00000004, + ApplicationLevelRoaming = 0x00000008, + ForcedRoaming = 0x00000010, + DataStatistics = 0x00000020 + }; + + Q_DECLARE_FLAGS(Capabilities, Capability) + + QNetworkConfigurationManager( QObject* parent = 0 ); + virtual ~QNetworkConfigurationManager(); + + + QNetworkConfigurationManager::Capabilities capabilities() const; + + QNetworkConfiguration defaultConfiguration() const; + QList allConfigurations(QNetworkConfiguration::StateFlags flags = 0) const; + QNetworkConfiguration configurationFromIdentifier(const QString& identifier) const; + void updateConfigurations(); + + bool isOnline() const; + +Q_SIGNALS: + void configurationAdded(const QNetworkConfiguration& config); + void configurationRemoved(const QNetworkConfiguration& config); + void configurationChanged(const QNetworkConfiguration& config); + void onlineStateChanged(bool isOnline); + void updateCompleted(); + +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(QNetworkConfigurationManager::Capabilities) + +QTM_END_NAMESPACE + +QT_END_HEADER + +#endif //QNETWORKCONFIGURATIONMANAGER_H + diff --git a/src/network/bearer/qnetworkconfigmanager_maemo.cpp b/src/network/bearer/qnetworkconfigmanager_maemo.cpp new file mode 100644 index 0000000..795b054 --- /dev/null +++ b/src/network/bearer/qnetworkconfigmanager_maemo.cpp @@ -0,0 +1,760 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 + +#include "qnetworkconfigmanager_maemo_p.h" + +#include +#include +#include + +#include +#include +#include +#include +#include + +QTM_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 timers; + +public: + IapAddTimer() {} + ~IapAddTimer() {} + + void add(QString& iap_id, QNetworkConfigurationManagerPrivate *d); + void del(QString& iap_id); + void removeAll(); +}; + + +void IapAddTimer::removeAll() +{ + QHashIterator 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 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 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 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 knownConfigs; + + /* All the scanned access points */ + QList 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 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 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 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 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 known_iaps = knownConfigs.values(priv->network_id); + rescan_list: + if (!known_iaps.isEmpty()) { + for (int k=0; kiap_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 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 i(knownConfigs); + while (i.hasNext()) { + i.next(); + SSIDInfo *iap = i.value(); + QString iap_id = iap->iap_id; + //qDebug() << i.key() << ": " << iap_id; + + QExplicitlySharedDataPointer 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 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" + +QTM_END_NAMESPACE diff --git a/src/network/bearer/qnetworkconfigmanager_maemo_p.h b/src/network/bearer/qnetworkconfigmanager_maemo_p.h new file mode 100644 index 0000000..e182495 --- /dev/null +++ b/src/network/bearer/qnetworkconfigmanager_maemo_p.h @@ -0,0 +1,141 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 +#include +#include + +#include +#include + +QTM_BEGIN_NAMESPACE + + +class QNetworkConfigurationManagerPrivate : public QObject +{ + Q_OBJECT +public: + QNetworkConfigurationManagerPrivate() + : QObject(0), capFlags(0), firstUpdate(true), onlineConfigurations(0) + { + registerPlatformCapabilities(); + updateConfigurations(); + } + + virtual ~QNetworkConfigurationManagerPrivate() + { + QList configIdents = snapConfigurations.keys(); + foreach(const QString oldIface, configIdents) { + QExplicitlySharedDataPointer priv = snapConfigurations.take(oldIface); + priv->isValid = false; + priv->id.clear(); + } + + configIdents = accessPointConfigurations.keys(); + foreach(const QString oldIface, configIdents) { + QExplicitlySharedDataPointer priv = accessPointConfigurations.take(oldIface); + priv->isValid = false; + priv->id.clear(); + } + + configIdents = userChoiceConfigurations.keys(); + foreach(const QString oldIface, configIdents) { + QExplicitlySharedDataPointer 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 > accessPointConfigurations; + QHash > snapConfigurations; + QHash > 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); +}; + +QTM_END_NAMESPACE + +#endif //QNETWORKCONFIGURATIONMANAGERPRIVATE_H diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp new file mode 100644 index 0000000..8b15f41 --- /dev/null +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -0,0 +1,450 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 "qnetworkconfigmanager_p.h" +#include "qgenericengine_p.h" + +#ifdef Q_OS_WIN +#include "qnlaengine_win_p.h" +#endif +#ifdef Q_OS_WIN32 +#include "qnativewifiengine_win_p.h" +#endif +#if defined(BACKEND_NM) +#include "qnmwifiengine_unix_p.h" +#endif +#ifdef Q_OS_DARWIN +#include "qcorewlanengine_mac_p.h" +#endif + +#include +#include +#include + +QTM_BEGIN_NAMESPACE + +void QNetworkConfigurationManagerPrivate::registerPlatformCapabilities() +{ + capFlags = QNetworkConfigurationManager::ForcedRoaming; +} + +void QNetworkConfigurationManagerPrivate::configurationAdded(QNetworkConfigurationPrivate *cpPriv, QNetworkSessionEngine *engine) +{ + QExplicitlySharedDataPointer ptr(new QNetworkConfigurationPrivate); + + ptr.data()->isValid = cpPriv->isValid; + ptr.data()->name = cpPriv->name; + ptr.data()->id = cpPriv->id; + ptr.data()->state = cpPriv->state; + ptr.data()->type = cpPriv->type; + ptr.data()->roamingSupported = cpPriv->roamingSupported; + ptr.data()->purpose = cpPriv->purpose; + ptr.data()->internet = cpPriv->internet; + + accessPointConfigurations.insert(cpPriv->id, ptr); + configurationEngine.insert(cpPriv->id, engine); + + if (!firstUpdate) { + QNetworkConfiguration item; + item.d = ptr; + emit configurationAdded(item); + } + + if (ptr.data()->state == QNetworkConfiguration::Active) { + ++onlineConfigurations; + if (!firstUpdate && onlineConfigurations == 1) + emit onlineStateChanged(true); + } +} + +void QNetworkConfigurationManagerPrivate::configurationRemoved(const QString &id) +{ + if (!accessPointConfigurations.contains(id)) + return; + + QExplicitlySharedDataPointer ptr = + accessPointConfigurations.take(id); + + configurationEngine.remove(id); + + ptr.data()->isValid = false; + + if (!firstUpdate) { + QNetworkConfiguration item; + item.d = ptr; + emit configurationRemoved(item); + } + + if (ptr.data()->state == QNetworkConfiguration::Active) { + --onlineConfigurations; + if (!firstUpdate && onlineConfigurations == 0) + emit onlineStateChanged(false); + } +} + +void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigurationPrivate *cpPriv) +{ + if (!accessPointConfigurations.contains(cpPriv->id)) + return; + + QExplicitlySharedDataPointer ptr = + accessPointConfigurations.value(cpPriv->id); + + if (ptr.data()->isValid != cpPriv->isValid || + ptr.data()->name != cpPriv->name || + ptr.data()->id != cpPriv->id || + ptr.data()->state != cpPriv->state || + ptr.data()->type != cpPriv->type || + ptr.data()->roamingSupported != cpPriv->roamingSupported || + ptr.data()->purpose != cpPriv->purpose || + ptr.data()->internet != cpPriv->internet) { + + const QNetworkConfiguration::StateFlags oldState = ptr.data()->state; + + ptr.data()->isValid = cpPriv->isValid; + ptr.data()->name = cpPriv->name; + ptr.data()->id = cpPriv->id; + ptr.data()->state = cpPriv->state; + ptr.data()->type = cpPriv->type; + ptr.data()->roamingSupported = cpPriv->roamingSupported; + ptr.data()->purpose = cpPriv->purpose; + ptr.data()->internet = cpPriv->internet; + + if (!firstUpdate) { + QNetworkConfiguration item; + item.d = ptr; + emit configurationChanged(item); + } + + if (ptr.data()->state == QNetworkConfiguration::Active && oldState != ptr.data()->state) { + // configuration went online + ++onlineConfigurations; + if (!firstUpdate && onlineConfigurations == 1) + emit onlineStateChanged(true); + } else if (ptr.data()->state != QNetworkConfiguration::Active && oldState == QNetworkConfiguration::Active) { + // configuration went offline + --onlineConfigurations; + if (!firstUpdate && onlineConfigurations == 0) + emit onlineStateChanged(false); + } + } +} + +void QNetworkConfigurationManagerPrivate::updateInternetServiceConfiguration() +{ + if (!snapConfigurations.contains(QLatin1String("Internet Service Network"))) { + QNetworkConfigurationPrivate *serviceNetwork = new QNetworkConfigurationPrivate; + serviceNetwork->name = tr("Internet"); + serviceNetwork->isValid = true; + serviceNetwork->id = QLatin1String("Internet Service Network"); + serviceNetwork->state = QNetworkConfiguration::Defined; + serviceNetwork->type = QNetworkConfiguration::ServiceNetwork; + + QExplicitlySharedDataPointer ptr(serviceNetwork); + + snapConfigurations.insert(serviceNetwork->id, ptr); + + if (!firstUpdate) { + QNetworkConfiguration item; + item.d = ptr; + emit configurationAdded(item); + } + } + + QExplicitlySharedDataPointer ptr = + snapConfigurations.value(QLatin1String("Internet Service Network")); + + QList > serviceNetworkMembers; + + QHash >::const_iterator i = + accessPointConfigurations.constBegin(); + + QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Defined; + while (i != accessPointConfigurations.constEnd()) { + QExplicitlySharedDataPointer child = i.value(); + + if (child.data()->internet && ((child.data()->state & QNetworkConfiguration::Defined) + == QNetworkConfiguration::Defined)) { + serviceNetworkMembers.append(child); + + state |= child.data()->state; + } + + ++i; + } + + + if (ptr.data()->state != state || ptr.data()->serviceNetworkMembers != serviceNetworkMembers) { + ptr.data()->state = state; + ptr.data()->serviceNetworkMembers = serviceNetworkMembers; + + QNetworkConfiguration item; + item.d = ptr; + emit configurationChanged(item); + } +} + +void QNetworkConfigurationManagerPrivate::updateConfigurations() +{ + if (firstUpdate) { + updateState = NotUpdating; + onlineConfigurations = 0; + +#if defined (Q_OS_DARWIN) + coreWifi = QCoreWlanEngine::instance(); + if (coreWifi) { + connect(coreWifi, SIGNAL(configurationsChanged()), + this, SLOT(updateConfigurations())); + } +#else +#if defined(BACKEND_NM) + nmWifi = QNmWifiEngine::instance(); + if (nmWifi) { + connect(nmWifi, SIGNAL(configurationsChanged()), + this, SLOT(updateConfigurations())); + } else { +#endif + generic = QGenericEngine::instance(); + if (generic) { + connect(generic, SIGNAL(configurationsChanged()), + this, SLOT(updateConfigurations())); + } +#if defined(BACKEND_NM) + } +#endif +#endif + +#ifdef Q_OS_WIN + nla = QNlaEngine::instance(); + if (nla) { + connect(nla, SIGNAL(configurationsChanged()), + this, SLOT(updateConfigurations())); + } +#endif + +#ifdef Q_OS_WIN32 + nativeWifi = QNativeWifiEngine::instance(); + if (nativeWifi) { + connect(nativeWifi, SIGNAL(configurationsChanged()), + this, SLOT(updateConfigurations())); + + capFlags |= QNetworkConfigurationManager::CanStartAndStopInterfaces; + } +#endif + } + + QNetworkSessionEngine *engine = qobject_cast(sender()); + if (updateState & Updating && engine) { +#if defined (Q_OS_DARWIN) + if (engine == coreWifi) + updateState &= ~CoreWifiUpdating; +#else +#if defined(BACKEND_NM) + if (engine == nmWifi) + updateState &= ~NmUpdating; + else if (engine == generic) + updateState &= ~GenericUpdating; +#else + if (engine == generic) + updateState &= ~GenericUpdating; +#endif +#endif + +#ifdef Q_OS_WIN + else if (engine == nla) + updateState &= ~NlaUpdating; +#ifdef Q_OS_WIN32 + else if (engine == nativeWifi) + updateState &= ~NativeWifiUpdating; +#endif +#endif + } + QList engines; + if (firstUpdate) { +#if defined (Q_OS_DARWIN) + if (coreWifi) + engines << coreWifi; +#else +#if defined(BACKEND_NM) + if (nmWifi) + engines << nmWifi; + else if (generic) + engines << generic; +#else + if (generic) + engines << generic; +#endif +#endif + +#ifdef Q_OS_WIN + if (nla) + engines << nla; +#ifdef Q_OS_WIN32 + if (nativeWifi) + engines << nativeWifi; +#endif +#endif + } else if (engine) { + engines << engine; + } + + while (!engines.isEmpty()) { + engine = engines.takeFirst(); + + bool ok; + QList foundConfigurations = engine->getConfigurations(&ok); + + // Find removed configurations. + QList removedIdentifiers = configurationEngine.keys(); + for (int i = 0; i < foundConfigurations.count(); ++i) + removedIdentifiers.removeOne(foundConfigurations.at(i)->id); + + // Update or add configurations. + while (!foundConfigurations.isEmpty()) { + QNetworkConfigurationPrivate *cpPriv = foundConfigurations.takeFirst(); + + if (accessPointConfigurations.contains(cpPriv->id)) + configurationChanged(cpPriv); + else + configurationAdded(cpPriv, engine); + + delete cpPriv; + } + + // Remove configurations. + while (!removedIdentifiers.isEmpty()) { + const QString id = removedIdentifiers.takeFirst(); + + if (configurationEngine.value(id) == engine) + configurationRemoved(id); + } + } + + updateInternetServiceConfiguration(); + + if (updateState == Updating) { + updateState = NotUpdating; + emit configurationUpdateComplete(); + } + + if (firstUpdate) + firstUpdate = false; +} + +/*! + Returns the first active configuration found, if one exists; otherwise returns the first + discovered configuration found, if one exists; otherwise returns an empty configuration. + + \internal +*/ +QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration() +{ + QExplicitlySharedDataPointer firstActive; + QExplicitlySharedDataPointer firstDiscovered; + + QHash >::const_iterator i = + accessPointConfigurations.constBegin(); + while (i != accessPointConfigurations.constEnd()) { + QNetworkConfigurationPrivate *priv = i.value().data(); + + if (!firstActive && priv->isValid && + (priv->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) + firstActive = i.value(); + if (!firstDiscovered && priv->isValid && + (priv->state & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) + firstDiscovered = i.value(); + + ++i; + } + + QNetworkConfiguration item; + + if (firstActive) + item.d = firstActive; + else if (firstDiscovered) + item.d = firstDiscovered; + + return item; +} + +void QNetworkConfigurationManagerPrivate::performAsyncConfigurationUpdate() +{ + updateState = Updating; +#if defined (Q_OS_DARWIN) + if (coreWifi) { + updateState |= CoreWifiUpdating; + coreWifi->requestUpdate(); + } +#else +#if defined(BACKEND_NM) + if (nmWifi) { + updateState |= NmUpdating; + nmWifi->requestUpdate(); + } else if (generic) { + updateState |= GenericUpdating; + generic->requestUpdate(); + } +#else + if (generic) { + updateState |= GenericUpdating; + generic->requestUpdate(); + } +#endif +#endif +#ifdef Q_OS_WIN + if (nla) { + updateState |= NlaUpdating; + nla->requestUpdate(); + } +#endif + +#ifdef Q_OS_WIN32 + if (nativeWifi) { + updateState |= NativeWifiUpdating; + nativeWifi->requestUpdate(); + } +#endif +} + +#include "moc_qnetworkconfigmanager_p.cpp" + +QTM_END_NAMESPACE + diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h new file mode 100644 index 0000000..0c42f9b --- /dev/null +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -0,0 +1,178 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qnetworkconfigmanager.h" +#include "qnetworkconfiguration_p.h" + +#include +#include + +QTM_BEGIN_NAMESPACE + +#ifdef BEARER_ENGINE +class QNetworkSessionEngine; +class QGenericEngine; +class QNlaEngine; +class QNativeWifiEngine; +class QNmWifiEngine; +class QCoreWlanEngine; +#endif + + +class QNetworkConfigurationManagerPrivate : public QObject +{ + Q_OBJECT +public: + QNetworkConfigurationManagerPrivate() + : QObject(0), capFlags(0), firstUpdate(true) + { + registerPlatformCapabilities(); + updateConfigurations(); + } + + virtual ~QNetworkConfigurationManagerPrivate() + { + QList configIdents = snapConfigurations.keys(); + foreach(const QString oldIface, configIdents) { + QExplicitlySharedDataPointer priv = snapConfigurations.take(oldIface); + priv->isValid = false; + priv->id.clear(); + } + + configIdents = accessPointConfigurations.keys(); + foreach(const QString oldIface, configIdents) { + QExplicitlySharedDataPointer priv = accessPointConfigurations.take(oldIface); + priv->isValid = false; + priv->id.clear(); + } + } + + 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 > accessPointConfigurations; + QHash > snapConfigurations; + QHash > userChoiceConfigurations; +#ifdef BEARER_ENGINE + QHash configurationEngine; +#endif + bool firstUpdate; + +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); + +private: +#ifdef BEARER_ENGINE + void updateInternetServiceConfiguration(); + + void abort(); +#endif + +#ifdef BEARER_ENGINE + QGenericEngine *generic; +#ifdef Q_OS_WIN + QNlaEngine *nla; +#ifndef Q_OS_WINCE + QNativeWifiEngine *nativeWifi; +#endif +#endif +#ifdef BACKEND_NM + QNmWifiEngine *nmWifi; +#endif +#ifdef Q_OS_DARWIN + QCoreWlanEngine *coreWifi; +#endif + + uint onlineConfigurations; + + enum EngineUpdate { + NotUpdating = 0x00, + Updating = 0x01, + GenericUpdating = 0x02, + NlaUpdating = 0x04, + NativeWifiUpdating = 0x08, + NmUpdating = 0x20, + CoreWifiUpdating = 0x40, + }; + Q_DECLARE_FLAGS(EngineUpdateState, EngineUpdate) + + EngineUpdateState updateState; +#endif + +private Q_SLOTS: +#ifdef BEARER_ENGINE + void configurationAdded(QNetworkConfigurationPrivate *cpPriv, QNetworkSessionEngine *engine); + void configurationRemoved(const QString &id); + void configurationChanged(QNetworkConfigurationPrivate *cpPriv); +#endif +}; + +QTM_END_NAMESPACE + +#endif //QNETWORKCONFIGURATIONMANAGERPRIVATE_H diff --git a/src/network/bearer/qnetworkconfigmanager_s60_p.cpp b/src/network/bearer/qnetworkconfigmanager_s60_p.cpp new file mode 100644 index 0000000..760a194 --- /dev/null +++ b/src/network/bearer/qnetworkconfigmanager_s60_p.cpp @@ -0,0 +1,974 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 "qnetworkconfigmanager_s60_p.h" + +#include +#include +#include + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + #include + #include + #include + #include + #include + #include +#else + #include + #include + #include +#endif + +QTM_BEGIN_NAMESPACE + +static const int KValueThatWillBeAddedToSNAPId = 1000; +static const int KUserChoiceIAPId = 0; + +QNetworkConfigurationManagerPrivate::QNetworkConfigurationManagerPrivate() + : QObject(0), CActive(CActive::EPriorityIdle), capFlags(0), iFirstUpdate(true), iInitOk(true) +{ + CActiveScheduler::Add(this); + + registerPlatformCapabilities(); + TRAPD(error, ipCommsDB = CCommsDatabase::NewL(EDatabaseTypeIAP)); + if (error != KErrNone) { + iInitOk = false; + return; + } + + TRAP_IGNORE(iConnectionMonitor.ConnectL()); + TRAP_IGNORE(iConnectionMonitor.NotifyEventL(*this)); + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + TRAP(error, iCmManager.OpenL()); + if (error != KErrNone) { + iInitOk = false; + return; + } +#endif + + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + cpPriv->name = "UserChoice"; + cpPriv->bearer = QNetworkConfigurationPrivate::BearerUnknown; + cpPriv->state = QNetworkConfiguration::Discovered; + cpPriv->isValid = true; + cpPriv->id = QString::number(qHash(KUserChoiceIAPId)); + cpPriv->numericId = KUserChoiceIAPId; + cpPriv->connectionId = 0; + cpPriv->type = QNetworkConfiguration::UserChoice; + cpPriv->purpose = QNetworkConfiguration::UnknownPurpose; + cpPriv->roamingSupported = false; + cpPriv->manager = this; + QExplicitlySharedDataPointer ptr(cpPriv); + userChoiceConfigurations.insert(cpPriv->id, ptr); + + updateConfigurations(); + updateStatesToSnaps(); + + // Start monitoring IAP and/or SNAP changes in Symbian CommsDB + startCommsDatabaseNotifications(); +} + +QNetworkConfigurationManagerPrivate::~QNetworkConfigurationManagerPrivate() +{ + Cancel(); + + QList configIdents = snapConfigurations.keys(); + foreach(QString oldIface, configIdents) { + QExplicitlySharedDataPointer priv = snapConfigurations.take(oldIface); + priv->isValid = false; + priv->id.clear(); + } + + configIdents = accessPointConfigurations.keys(); + foreach(QString oldIface, configIdents) { + QExplicitlySharedDataPointer priv = accessPointConfigurations.take(oldIface); + priv->isValid = false; + priv->id.clear(); + } + + configIdents = userChoiceConfigurations.keys(); + foreach(QString oldIface, configIdents) { + QExplicitlySharedDataPointer priv = userChoiceConfigurations.take(oldIface); + priv->isValid = false; + priv->id.clear(); + priv->manager = 0; + } + + iConnectionMonitor.CancelNotifications(); + iConnectionMonitor.Close(); + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + iCmManager.Close(); +#endif + + delete ipAccessPointsAvailabilityScanner; + delete ipCommsDB; +} + + +void QNetworkConfigurationManagerPrivate::registerPlatformCapabilities() +{ + capFlags |= QNetworkConfigurationManager::CanStartAndStopInterfaces; + capFlags |= QNetworkConfigurationManager::DirectConnectionRouting; + capFlags |= QNetworkConfigurationManager::SystemSessionSupport; +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + capFlags |= QNetworkConfigurationManager::ApplicationLevelRoaming; + capFlags |= QNetworkConfigurationManager::ForcedRoaming; +#endif + capFlags |= QNetworkConfigurationManager::DataStatistics; +} + +void QNetworkConfigurationManagerPrivate::performAsyncConfigurationUpdate() +{ + if (!iInitOk || iUpdateGoingOn) { + return; + } + iUpdateGoingOn = true; + + stopCommsDatabaseNotifications(); + updateConfigurations(); // Synchronous call + updateAvailableAccessPoints(); // Asynchronous call +} + +void QNetworkConfigurationManagerPrivate::updateConfigurations() +{ + if (!iInitOk) { + return; + } + + TRAP_IGNORE(updateConfigurationsL()); +} + +void QNetworkConfigurationManagerPrivate::updateConfigurationsL() +{ + QList knownConfigs = accessPointConfigurations.keys(); + QList knownSnapConfigs = snapConfigurations.keys(); + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + // S60 version is >= Series60 3rd Edition Feature Pack 2 + TInt error = KErrNone; + + // Loop through all IAPs + RArray connectionMethods; // IAPs + CleanupClosePushL(connectionMethods); + iCmManager.ConnectionMethodL(connectionMethods); + for(int i = 0; i < connectionMethods.Count(); i++) { + RCmConnectionMethod connectionMethod = iCmManager.ConnectionMethodL(connectionMethods[i]); + CleanupClosePushL(connectionMethod); + TUint32 iapId = connectionMethod.GetIntAttributeL(CMManager::ECmIapId); + QString ident = QString::number(qHash(iapId)); + if (accessPointConfigurations.contains(ident)) { + knownConfigs.removeOne(ident); + } else { + QNetworkConfigurationPrivate* cpPriv = NULL; + TRAP(error, cpPriv = configFromConnectionMethodL(connectionMethod)); + if (error == KErrNone) { + QExplicitlySharedDataPointer ptr(cpPriv); + accessPointConfigurations.insert(cpPriv->id, ptr); + if (!iFirstUpdate) { + QNetworkConfiguration item; + item.d = ptr; + emit configurationAdded(item); + } + } + } + CleanupStack::PopAndDestroy(&connectionMethod); + } + CleanupStack::PopAndDestroy(&connectionMethods); + + // Loop through all SNAPs + RArray destinations; + CleanupClosePushL(destinations); + iCmManager.AllDestinationsL(destinations); + for(int i = 0; i < destinations.Count(); i++) { + RCmDestination destination; + destination = iCmManager.DestinationL(destinations[i]); + CleanupClosePushL(destination); + QString ident = QString::number(qHash(destination.Id()+KValueThatWillBeAddedToSNAPId)); //TODO: Check if it's ok to add 1000 SNAP Id to prevent SNAP ids overlapping IAP ids + if (snapConfigurations.contains(ident)) { + knownSnapConfigs.removeOne(ident); + } else { + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + CleanupStack::PushL(cpPriv); + + HBufC *pName = destination.NameLC(); + cpPriv->name = QString::fromUtf16(pName->Ptr(),pName->Length()); + CleanupStack::PopAndDestroy(pName); + pName = NULL; + + cpPriv->isValid = true; + cpPriv->id = ident; + cpPriv->numericId = destination.Id(); + cpPriv->connectionId = 0; + cpPriv->state = QNetworkConfiguration::Defined; + cpPriv->type = QNetworkConfiguration::ServiceNetwork; + cpPriv->purpose = QNetworkConfiguration::UnknownPurpose; + cpPriv->roamingSupported = false; + cpPriv->manager = this; + + QExplicitlySharedDataPointer ptr(cpPriv); + snapConfigurations.insert(ident, ptr); + if (!iFirstUpdate) { + QNetworkConfiguration item; + item.d = ptr; + emit configurationAdded(item); + } + + CleanupStack::Pop(cpPriv); + } + QExplicitlySharedDataPointer privSNAP = snapConfigurations.value(ident); + + for (int j=0; j < destination.ConnectionMethodCount(); j++) { + RCmConnectionMethod connectionMethod = destination.ConnectionMethodL(j); + CleanupClosePushL(connectionMethod); + + TUint32 iapId = connectionMethod.GetIntAttributeL(CMManager::ECmIapId); + QString iface = QString::number(qHash(iapId)); + // Check that IAP can be found from accessPointConfigurations list + QExplicitlySharedDataPointer priv = accessPointConfigurations.value(iface); + if (priv.data() == 0) { + QNetworkConfigurationPrivate* cpPriv = NULL; + TRAP(error, cpPriv = configFromConnectionMethodL(connectionMethod)); + if (error == KErrNone) { + QExplicitlySharedDataPointer ptr(cpPriv); + ptr.data()->serviceNetworkPtr = privSNAP; + accessPointConfigurations.insert(cpPriv->id, ptr); + if (!iFirstUpdate) { + QNetworkConfiguration item; + item.d = ptr; + emit configurationAdded(item); + } + privSNAP->serviceNetworkMembers.append(ptr); + } + } else { + knownConfigs.removeOne(iface); + // Check that IAP can be found from related SNAP's configuration list + bool iapFound = false; + for (int i=0; iserviceNetworkMembers.count(); i++) { + if (privSNAP->serviceNetworkMembers[i]->numericId == iapId) { + iapFound = true; + break; + } + } + if (!iapFound) { + priv.data()->serviceNetworkPtr = privSNAP; + privSNAP->serviceNetworkMembers.append(priv); + } + } + + CleanupStack::PopAndDestroy(&connectionMethod); + } + + if (privSNAP->serviceNetworkMembers.count() > 1) { + // Roaming is supported only if SNAP contains more than one IAP + privSNAP->roamingSupported = true; + } + + CleanupStack::PopAndDestroy(&destination); + } + CleanupStack::PopAndDestroy(&destinations); + +#else + // S60 version is < Series60 3rd Edition Feature Pack 2 + CCommsDbTableView* pDbTView = ipCommsDB->OpenTableLC(TPtrC(IAP)); + + // Loop through all IAPs + TUint32 apId = 0; + TInt retVal = pDbTView->GotoFirstRecord(); + while (retVal == KErrNone) { + pDbTView->ReadUintL(TPtrC(COMMDB_ID), apId); + QString ident = QString::number(qHash(apId)); + if (accessPointConfigurations.contains(ident)) { + knownConfigs.removeOne(ident); + } else { + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + if (readNetworkConfigurationValuesFromCommsDb(apId, cpPriv)) { + QExplicitlySharedDataPointer ptr(cpPriv); + accessPointConfigurations.insert(ident, ptr); + if (!iFirstUpdate) { + QNetworkConfiguration item; + item.d = ptr; + emit configurationAdded(item); + } + } else { + delete cpPriv; + } + } + retVal = pDbTView->GotoNextRecord(); + } + CleanupStack::PopAndDestroy(pDbTView); +#endif + updateActiveAccessPoints(); + + foreach (QString oldIface, knownConfigs) { + //remove non existing IAP + QExplicitlySharedDataPointer priv = accessPointConfigurations.take(oldIface); + priv->isValid = false; + if (!iFirstUpdate) { + QNetworkConfiguration item; + item.d = priv; + emit configurationRemoved(item); + } + // Remove non existing IAP from SNAPs + QList snapConfigIdents = snapConfigurations.keys(); + foreach (QString iface, snapConfigIdents) { + QExplicitlySharedDataPointer priv2 = snapConfigurations.value(iface); + // => Check if one of the IAPs of the SNAP is active + for (int i=0; iserviceNetworkMembers.count(); i++) { + if (priv2->serviceNetworkMembers[i]->numericId == priv->numericId) { + priv2->serviceNetworkMembers.removeAt(i); + break; + } + } + } + } + foreach (QString oldIface, knownSnapConfigs) { + //remove non existing SNAPs + QExplicitlySharedDataPointer priv = snapConfigurations.take(oldIface); + priv->isValid = false; + if (!iFirstUpdate) { + QNetworkConfiguration item; + item.d = priv; + emit configurationRemoved(item); + } + } + + iFirstUpdate = false; +} + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE +QNetworkConfigurationPrivate* QNetworkConfigurationManagerPrivate::configFromConnectionMethodL( + RCmConnectionMethod& connectionMethod) +{ + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + CleanupStack::PushL(cpPriv); + + TUint32 iapId = connectionMethod.GetIntAttributeL(CMManager::ECmIapId); + QString ident = QString::number(qHash(iapId)); + + HBufC *pName = connectionMethod.GetStringAttributeL(CMManager::ECmName); + CleanupStack::PushL(pName); + cpPriv->name = QString::fromUtf16(pName->Ptr(),pName->Length()); + CleanupStack::PopAndDestroy(pName); + pName = NULL; + + TUint32 bearerId = connectionMethod.GetIntAttributeL(CMManager::ECmCommsDBBearerType); + switch (bearerId) { + case KCommDbBearerCSD: + cpPriv->bearer = QNetworkConfigurationPrivate::Bearer2G; + break; + case KCommDbBearerWcdma: + cpPriv->bearer = QNetworkConfigurationPrivate::BearerWCDMA; + break; + case KCommDbBearerLAN: + cpPriv->bearer = QNetworkConfigurationPrivate::BearerEthernet; + break; + case KCommDbBearerVirtual: + cpPriv->bearer = QNetworkConfigurationPrivate::BearerUnknown; + break; + case KCommDbBearerPAN: + cpPriv->bearer = QNetworkConfigurationPrivate::BearerUnknown; + break; + case KCommDbBearerWLAN: + cpPriv->bearer = QNetworkConfigurationPrivate::BearerWLAN; + break; + default: + cpPriv->bearer = QNetworkConfigurationPrivate::BearerUnknown; + break; + } + + TInt error = KErrNone; + TUint32 bearerType = connectionMethod.GetIntAttributeL(CMManager::ECmBearerType); + switch (bearerType) { + case KUidPacketDataBearerType: + // "Packet data" Bearer => Mapping is done using "Access point name" + TRAP(error, pName = connectionMethod.GetStringAttributeL(CMManager::EPacketDataAPName)); + break; + case KUidWlanBearerType: + // "Wireless LAN" Bearer => Mapping is done using "WLAN network name" = SSID + TRAP(error, pName = connectionMethod.GetStringAttributeL(CMManager::EWlanSSID)); + break; + } + if (!pName) { + // "Data call" Bearer or "High Speed (GSM)" Bearer => Mapping is done using "Dial-up number" + TRAP(error, pName = connectionMethod.GetStringAttributeL(CMManager::EDialDefaultTelNum)); + } + + if (error == KErrNone && pName) { + CleanupStack::PushL(pName); + cpPriv->mappingName = QString::fromUtf16(pName->Ptr(),pName->Length()); + CleanupStack::PopAndDestroy(pName); + pName = NULL; + } + + cpPriv->state = QNetworkConfiguration::Defined; + TBool isConnected = connectionMethod.GetBoolAttributeL(CMManager::ECmConnected); + if (isConnected) { + cpPriv->state = QNetworkConfiguration::Active; + } + + cpPriv->isValid = true; + cpPriv->id = ident; + cpPriv->numericId = iapId; + cpPriv->connectionId = 0; + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + cpPriv->purpose = QNetworkConfiguration::UnknownPurpose; + cpPriv->roamingSupported = false; + cpPriv->manager = this; + + CleanupStack::Pop(cpPriv); + return cpPriv; +} +#else +bool QNetworkConfigurationManagerPrivate::readNetworkConfigurationValuesFromCommsDb( + TUint32 aApId, QNetworkConfigurationPrivate* apNetworkConfiguration) +{ + TRAPD(error, readNetworkConfigurationValuesFromCommsDbL(aApId,apNetworkConfiguration)); + if (error != KErrNone) { + return false; + } + return true; +} + +void QNetworkConfigurationManagerPrivate::readNetworkConfigurationValuesFromCommsDbL( + TUint32 aApId, QNetworkConfigurationPrivate* apNetworkConfiguration) +{ + CApDataHandler* pDataHandler = CApDataHandler::NewLC(*ipCommsDB); + CApAccessPointItem* pAPItem = CApAccessPointItem::NewLC(); + TBuf name; + + CApUtils* pApUtils = CApUtils::NewLC(*ipCommsDB); + TUint32 apId = pApUtils->WapIdFromIapIdL(aApId); + + pDataHandler->AccessPointDataL(apId,*pAPItem); + pAPItem->ReadTextL(EApIapName, name); + if (name.Compare(_L("Easy WLAN")) == 0) { + // "Easy WLAN" won't be accepted to the Configurations list + User::Leave(KErrNotFound); + } + + QString ident = QString::number(qHash(aApId)); + + apNetworkConfiguration->name = QString::fromUtf16(name.Ptr(),name.Length()); + apNetworkConfiguration->isValid = true; + apNetworkConfiguration->id = ident; + apNetworkConfiguration->numericId = aApId; + apNetworkConfiguration->connectionId = 0; + apNetworkConfiguration->state = (QNetworkConfiguration::Defined); + apNetworkConfiguration->type = QNetworkConfiguration::InternetAccessPoint; + apNetworkConfiguration->purpose = QNetworkConfiguration::UnknownPurpose; + apNetworkConfiguration->roamingSupported = false; + switch (pAPItem->BearerTypeL()) { + case EApBearerTypeCSD: + apNetworkConfiguration->bearer = QNetworkConfigurationPrivate::Bearer2G; + break; + case EApBearerTypeGPRS: + apNetworkConfiguration->bearer = QNetworkConfigurationPrivate::Bearer2G; + break; + case EApBearerTypeHSCSD: + apNetworkConfiguration->bearer = QNetworkConfigurationPrivate::BearerHSPA; + break; + case EApBearerTypeCDMA: + apNetworkConfiguration->bearer = QNetworkConfigurationPrivate::BearerCDMA2000; + break; + case EApBearerTypeWLAN: + apNetworkConfiguration->bearer = QNetworkConfigurationPrivate::BearerWLAN; + break; + case EApBearerTypeLAN: + apNetworkConfiguration->bearer = QNetworkConfigurationPrivate::BearerEthernet; + break; + case EApBearerTypeLANModem: + apNetworkConfiguration->bearer = QNetworkConfigurationPrivate::BearerEthernet; + break; + default: + apNetworkConfiguration->bearer = QNetworkConfigurationPrivate::BearerUnknown; + break; + } + apNetworkConfiguration->manager = this; + + CleanupStack::PopAndDestroy(pApUtils); + CleanupStack::PopAndDestroy(pAPItem); + CleanupStack::PopAndDestroy(pDataHandler); +} +#endif + +QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration() +{ + QNetworkConfiguration config; + + if (iInitOk) { + stopCommsDatabaseNotifications(); + TRAP_IGNORE(config = defaultConfigurationL()); + startCommsDatabaseNotifications(); + } + + return config; +} + +QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfigurationL() +{ + QNetworkConfiguration item; + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + // Check Default Connection (SNAP or IAP) + TCmDefConnValue defaultConnectionValue; + iCmManager.ReadDefConnL(defaultConnectionValue); + if (defaultConnectionValue.iType == ECmDefConnDestination) { + QString iface = QString::number(qHash(defaultConnectionValue.iId+KValueThatWillBeAddedToSNAPId)); + QExplicitlySharedDataPointer priv = snapConfigurations.value(iface); + if (priv.data() != 0) { + item.d = priv; + } + } else if (defaultConnectionValue.iType == ECmDefConnConnectionMethod) { + QString iface = QString::number(qHash(defaultConnectionValue.iId)); + QExplicitlySharedDataPointer priv = accessPointConfigurations.value(iface); + if (priv.data() != 0) { + item.d = priv; + } + } +#endif + + if (!item.isValid()) { + QString iface = QString::number(qHash(KUserChoiceIAPId)); + QExplicitlySharedDataPointer priv = userChoiceConfigurations.value(iface); + if (priv.data() != 0) { + item.d = priv; + } + } + + return item; +} + +void QNetworkConfigurationManagerPrivate::updateActiveAccessPoints() +{ + bool online = false; + QList inactiveConfigs = accessPointConfigurations.keys(); + + TRequestStatus status; + TUint connectionCount; + iConnectionMonitor.GetConnectionCount(connectionCount, status); + User::WaitForRequest(status); + + // Go through all connections and set state of related IAPs to Active + TUint connectionId; + TUint subConnectionCount; + TUint apId; + if (status.Int() == KErrNone) { + for (TUint i = 1; i <= connectionCount; i++) { + iConnectionMonitor.GetConnectionInfo(i, connectionId, subConnectionCount); + iConnectionMonitor.GetUintAttribute(connectionId, subConnectionCount, KIAPId, apId, status); + User::WaitForRequest(status); + QString ident = QString::number(qHash(apId)); + QExplicitlySharedDataPointer priv = accessPointConfigurations.value(ident); + if (priv.data()) { + online = true; + inactiveConfigs.removeOne(ident); + priv.data()->connectionId = connectionId; + // Configuration is Active + changeConfigurationStateTo(priv, QNetworkConfiguration::Active); + } + } + } + + // Make sure that state of rest of the IAPs won't be Active + foreach (QString iface, inactiveConfigs) { + QExplicitlySharedDataPointer priv = accessPointConfigurations.value(iface); + if (priv.data()) { + // Configuration is either Defined or Discovered + changeConfigurationStateAtMaxTo(priv, QNetworkConfiguration::Discovered); + } + } + + if (iOnline != online) { + iOnline = online; + emit this->onlineStateChanged(iOnline); + } +} + +void QNetworkConfigurationManagerPrivate::updateAvailableAccessPoints() +{ + if (!ipAccessPointsAvailabilityScanner) { + ipAccessPointsAvailabilityScanner = new AccessPointsAvailabilityScanner(*this, iConnectionMonitor); + } + if (ipAccessPointsAvailabilityScanner) { + // Scanning may take a while because WLAN scanning will be done (if device supports WLAN). + ipAccessPointsAvailabilityScanner->StartScanning(); + } +} + +void QNetworkConfigurationManagerPrivate::accessPointScanningReady(TBool scanSuccessful, TConnMonIapInfo iapInfo) +{ + iUpdateGoingOn = false; + if (scanSuccessful) { + QList unavailableConfigs = accessPointConfigurations.keys(); + + // Set state of returned IAPs to Discovered + // if state is not already Active + for(TUint i=0; i priv = accessPointConfigurations.value(ident); + if (priv.data()) { + unavailableConfigs.removeOne(ident); + if (priv.data()->state < QNetworkConfiguration::Active) { + // Configuration is either Discovered or Active + changeConfigurationStateAtMinTo(priv, QNetworkConfiguration::Discovered); + } + } + } + + // Make sure that state of rest of the IAPs won't be Discovered or Active + foreach (QString iface, unavailableConfigs) { + QExplicitlySharedDataPointer priv = accessPointConfigurations.value(iface); + if (priv.data()) { + // Configuration is Defined + changeConfigurationStateAtMaxTo(priv, QNetworkConfiguration::Defined); + } + } + } + + updateStatesToSnaps(); + + startCommsDatabaseNotifications(); + + emit this->configurationUpdateComplete(); +} + +void QNetworkConfigurationManagerPrivate::updateStatesToSnaps() +{ + // Go through SNAPs and set correct state to SNAPs + QList snapConfigIdents = snapConfigurations.keys(); + foreach (QString iface, snapConfigIdents) { + bool discovered = false; + bool active = false; + QExplicitlySharedDataPointer priv = snapConfigurations.value(iface); + // => Check if one of the IAPs of the SNAP is discovered or active + // => If one of IAPs is active, also SNAP is active + // => If one of IAPs is discovered but none of the IAPs is active, SNAP is discovered + for (int i=0; iserviceNetworkMembers.count(); i++) { + QExplicitlySharedDataPointer priv2 = priv->serviceNetworkMembers[i]; + if ((priv->serviceNetworkMembers[i]->state & QNetworkConfiguration::Active) + == QNetworkConfiguration::Active) { + active = true; + break; + } else if ((priv->serviceNetworkMembers[i]->state & QNetworkConfiguration::Discovered) + == QNetworkConfiguration::Discovered) { + discovered = true; + } + } + if (active) { + changeConfigurationStateTo(priv, QNetworkConfiguration::Active); + } else if (discovered) { + changeConfigurationStateTo(priv, QNetworkConfiguration::Discovered); + } else { + changeConfigurationStateTo(priv, QNetworkConfiguration::Defined); + } + } +} + +bool QNetworkConfigurationManagerPrivate::changeConfigurationStateTo(QExplicitlySharedDataPointer& sharedData, + QNetworkConfiguration::StateFlags newState) +{ + if (newState != sharedData.data()->state) { + sharedData.data()->state = newState; + QNetworkConfiguration item; + item.d = sharedData; + if (!iFirstUpdate) { + emit configurationChanged(item); + } + return true; + } + return false; +} + +/* changeConfigurationStateAtMinTo function does not overwrite possible better + * state (e.g. Discovered state does not overwrite Active state) but + * makes sure that state is at minimum given state. +*/ +bool QNetworkConfigurationManagerPrivate::changeConfigurationStateAtMinTo(QExplicitlySharedDataPointer& sharedData, + QNetworkConfiguration::StateFlags newState) +{ + if ((newState | sharedData.data()->state) != sharedData.data()->state) { + sharedData.data()->state = (sharedData.data()->state | newState); + QNetworkConfiguration item; + item.d = sharedData; + if (!iFirstUpdate) { + emit configurationChanged(item); + } + return true; + } + return false; +} + +/* changeConfigurationStateAtMaxTo function overwrites possible better + * state (e.g. Discovered state overwrites Active state) and + * makes sure that state is at maximum given state (e.g. Discovered state + * does not overwrite Defined state). +*/ +bool QNetworkConfigurationManagerPrivate::changeConfigurationStateAtMaxTo(QExplicitlySharedDataPointer& sharedData, + QNetworkConfiguration::StateFlags newState) +{ + if ((newState & sharedData.data()->state) != sharedData.data()->state) { + sharedData.data()->state = (newState & sharedData.data()->state); + QNetworkConfiguration item; + item.d = sharedData; + if (!iFirstUpdate) { + emit configurationChanged(item); + } + return true; + } + return false; +} + +void QNetworkConfigurationManagerPrivate::startCommsDatabaseNotifications() +{ + if (!iWaitingCommsDatabaseNotifications) { + iWaitingCommsDatabaseNotifications = ETrue; + if (!IsActive()) { + SetActive(); + // Start waiting for new notification + ipCommsDB->RequestNotification(iStatus); + } + } +} + +void QNetworkConfigurationManagerPrivate::stopCommsDatabaseNotifications() +{ + if (iWaitingCommsDatabaseNotifications) { + iWaitingCommsDatabaseNotifications = EFalse; + if (!IsActive()) { + SetActive(); + // Make sure that notifier recorded events will not be returned + // as soon as the client issues the next RequestNotification() request. + ipCommsDB->RequestNotification(iStatus); + ipCommsDB->CancelRequestNotification(); + } else { + ipCommsDB->CancelRequestNotification(); + } + } +} + +void QNetworkConfigurationManagerPrivate::RunL() +{ + if (iStatus != KErrCancel) { + RDbNotifier::TEvent event = STATIC_CAST(RDbNotifier::TEvent, iStatus.Int()); + switch (event) { + case RDbNotifier::EUnlock: /** All read locks have been removed. */ + case RDbNotifier::ECommit: /** A transaction has been committed. */ + case RDbNotifier::ERollback: /** A transaction has been rolled back */ + case RDbNotifier::ERecover: /** The database has been recovered */ + // Note that if further database events occur while a client is handling + // a request completion, the notifier records the most significant database + // event and this is signalled as soon as the client issues the next + // RequestNotification() request. + // => Stop recording notifications + stopCommsDatabaseNotifications(); + TRAPD(error, updateConfigurationsL()); + if (error == KErrNone) { + updateStatesToSnaps(); + } + iWaitingCommsDatabaseNotifications = true; + break; + default: + // Do nothing + break; + } + } + + if (iWaitingCommsDatabaseNotifications) { + if (!IsActive()) { + SetActive(); + // Start waiting for new notification + ipCommsDB->RequestNotification(iStatus); + } + } +} + +void QNetworkConfigurationManagerPrivate::DoCancel() +{ + ipCommsDB->CancelRequestNotification(); +} + + +void QNetworkConfigurationManagerPrivate::EventL(const CConnMonEventBase& aEvent) +{ + switch (aEvent.EventType()) { + case EConnMonCreateConnection: + { + CConnMonCreateConnection* realEvent; + realEvent = (CConnMonCreateConnection*) &aEvent; + TUint subConnectionCount = 0; + TUint apId; + TUint connectionId = realEvent->ConnectionId(); + TRequestStatus status; + iConnectionMonitor.GetUintAttribute(connectionId, subConnectionCount, KIAPId, apId, status); + User::WaitForRequest(status); + QString ident = QString::number(qHash(apId)); + QExplicitlySharedDataPointer priv = accessPointConfigurations.value(ident); + if (priv.data()) { + priv.data()->connectionId = connectionId; + // Configuration is Active + if (changeConfigurationStateTo(priv, QNetworkConfiguration::Active)) { + updateStatesToSnaps(); + } + if (!iOnline) { + iOnline = true; + emit this->onlineStateChanged(iOnline); + } + } + } + break; + + case EConnMonDeleteConnection: + { + CConnMonDeleteConnection* realEvent; + realEvent = (CConnMonDeleteConnection*) &aEvent; + TUint connectionId = realEvent->ConnectionId(); + QExplicitlySharedDataPointer priv = dataByConnectionId(connectionId); + if (priv.data()) { + priv.data()->connectionId = 0; + // Configuration is either Defined or Discovered + if (changeConfigurationStateAtMaxTo(priv, QNetworkConfiguration::Discovered)) { + updateStatesToSnaps(); + } + } + + bool online = false; + QList iapConfigs = accessPointConfigurations.keys(); + foreach (QString iface, iapConfigs) { + QExplicitlySharedDataPointer priv = accessPointConfigurations.value(iface); + if (priv.data()->state == QNetworkConfiguration::Active) { + online = true; + break; + } + } + if (iOnline != online) { + iOnline = online; + emit this->onlineStateChanged(iOnline); + } + } + break; + + case EConnMonIapAvailabilityChange: + { + CConnMonIapAvailabilityChange* realEvent; + realEvent = (CConnMonIapAvailabilityChange*) &aEvent; + TConnMonIapInfo iaps = realEvent->IapAvailability(); + QList unDiscoveredConfigs = accessPointConfigurations.keys(); + for ( TUint i = 0; i < iaps.Count(); i++ ) { + QString ident = QString::number(qHash(iaps.iIap[i].iIapId)); + QExplicitlySharedDataPointer priv = accessPointConfigurations.value(ident); + if (priv.data()) { + // Configuration is either Discovered or Active + changeConfigurationStateAtMinTo(priv, QNetworkConfiguration::Discovered); + unDiscoveredConfigs.removeOne(ident); + } + } + foreach (QString iface, unDiscoveredConfigs) { + QExplicitlySharedDataPointer priv = accessPointConfigurations.value(iface); + if (priv.data()) { + // Configuration is Defined + changeConfigurationStateAtMaxTo(priv, QNetworkConfiguration::Defined); + } + } + } + break; + + default: + // For unrecognized events + break; + } +} + +QExplicitlySharedDataPointer QNetworkConfigurationManagerPrivate::dataByConnectionId(TUint aConnectionId) +{ + QNetworkConfiguration item; + + QHash >::const_iterator i = + accessPointConfigurations.constBegin(); + while (i != accessPointConfigurations.constEnd()) { + QExplicitlySharedDataPointer priv = i.value(); + if (priv.data()->connectionId == aConnectionId) { + return priv; + } + ++i; + } + + return QExplicitlySharedDataPointer(); +} + +AccessPointsAvailabilityScanner::AccessPointsAvailabilityScanner(QNetworkConfigurationManagerPrivate& owner, + RConnectionMonitor& connectionMonitor) + : CActive(CActive::EPriorityStandard), iOwner(owner), iConnectionMonitor(connectionMonitor) +{ + CActiveScheduler::Add(this); +} + +AccessPointsAvailabilityScanner::~AccessPointsAvailabilityScanner() +{ + Cancel(); +} + +void AccessPointsAvailabilityScanner::DoCancel() +{ + iConnectionMonitor.CancelAsyncRequest(EConnMonGetPckgAttribute); +} + +void AccessPointsAvailabilityScanner::StartScanning() +{ + iConnectionMonitor.GetPckgAttribute(EBearerIdAll, 0, KIapAvailability, iIapBuf, iStatus); + if (!IsActive()) { + SetActive(); + } +} + +void AccessPointsAvailabilityScanner::RunL() +{ + if (iStatus.Int() != KErrNone) { + iIapBuf().iCount = 0; + iOwner.accessPointScanningReady(false,iIapBuf()); + } else { + iOwner.accessPointScanningReady(true,iIapBuf()); + } +} +#include "moc_qnetworkconfigmanager_s60_p.cpp" +QTM_END_NAMESPACE diff --git a/src/network/bearer/qnetworkconfigmanager_s60_p.h b/src/network/bearer/qnetworkconfigmanager_s60_p.h new file mode 100644 index 0000000..296d67f --- /dev/null +++ b/src/network/bearer/qnetworkconfigmanager_s60_p.h @@ -0,0 +1,182 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +#include +#include +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + #include +#endif + +class CCommsDatabase; +class QTimer; + +QTM_BEGIN_NAMESPACE + +class QNetworkSessionPrivate; +class AccessPointsAvailabilityScanner; + +class QNetworkConfigurationManagerPrivate : public QObject, public CActive, public MConnectionMonitorObserver +{ + Q_OBJECT + +public: + QNetworkConfigurationManagerPrivate(); + virtual ~QNetworkConfigurationManagerPrivate(); + + QNetworkConfiguration defaultConfiguration(); + void performAsyncConfigurationUpdate(); + +Q_SIGNALS: + void configurationAdded(const QNetworkConfiguration& config); + void configurationRemoved(const QNetworkConfiguration& config); + void configurationUpdateComplete(); + void configurationChanged(const QNetworkConfiguration& config); + void onlineStateChanged(bool isOnline); + +public Q_SLOTS: + void updateConfigurations(); + +private: + void registerPlatformCapabilities(); + void updateStatesToSnaps(); + bool changeConfigurationStateTo(QExplicitlySharedDataPointer& sharedData, + QNetworkConfiguration::StateFlags newState); + bool changeConfigurationStateAtMinTo(QExplicitlySharedDataPointer& sharedData, + QNetworkConfiguration::StateFlags newState); + bool changeConfigurationStateAtMaxTo(QExplicitlySharedDataPointer& sharedData, + QNetworkConfiguration::StateFlags newState); +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + QNetworkConfigurationPrivate* configFromConnectionMethodL(RCmConnectionMethod& connectionMethod); +#else + bool readNetworkConfigurationValuesFromCommsDb( + TUint32 aApId, QNetworkConfigurationPrivate* apNetworkConfiguration); + void readNetworkConfigurationValuesFromCommsDbL( + TUint32 aApId, QNetworkConfigurationPrivate* apNetworkConfiguration); +#endif + + void updateConfigurationsL(); + void updateActiveAccessPoints(); + void updateAvailableAccessPoints(); + void accessPointScanningReady(TBool scanSuccessful, TConnMonIapInfo iapInfo); + void startCommsDatabaseNotifications(); + void stopCommsDatabaseNotifications(); + + QNetworkConfiguration defaultConfigurationL(); + TBool GetS60PlatformVersion(TUint& aMajor, TUint& aMinor) const; + void startMonitoringIAPData(TUint32 aIapId); + QExplicitlySharedDataPointer dataByConnectionId(TUint aConnectionId); + +protected: // From CActive + void RunL(); + void DoCancel(); + +private: // MConnectionMonitorObserver + void EventL(const CConnMonEventBase& aEvent); + +public: // Data + //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 > accessPointConfigurations; + QHash > snapConfigurations; + QHash > userChoiceConfigurations; + QNetworkConfigurationManager::Capabilities capFlags; + +private: // Data + bool iFirstUpdate; + CCommsDatabase* ipCommsDB; + RConnectionMonitor iConnectionMonitor; + + TBool iWaitingCommsDatabaseNotifications; + TBool iOnline; + TBool iInitOk; + TBool iUpdateGoingOn; + + + AccessPointsAvailabilityScanner* ipAccessPointsAvailabilityScanner; + + friend class QNetworkSessionPrivate; + friend class AccessPointsAvailabilityScanner; + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + RCmManager iCmManager; +#endif +}; + +class AccessPointsAvailabilityScanner : public CActive +{ +public: + AccessPointsAvailabilityScanner(QNetworkConfigurationManagerPrivate& owner, + RConnectionMonitor& connectionMonitor); + ~AccessPointsAvailabilityScanner(); + + void StartScanning(); + +protected: // From CActive + void RunL(); + void DoCancel(); + +private: // Data + QNetworkConfigurationManagerPrivate& iOwner; + RConnectionMonitor& iConnectionMonitor; + TConnMonIapInfoBuf iIapBuf; +}; + +QTM_END_NAMESPACE + +#endif //QNETWORKCONFIGURATIONMANAGERPRIVATE_H diff --git a/src/network/bearer/qnetworkconfiguration.cpp b/src/network/bearer/qnetworkconfiguration.cpp new file mode 100644 index 0000000..c92b356 --- /dev/null +++ b/src/network/bearer/qnetworkconfiguration.cpp @@ -0,0 +1,349 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 "qnetworkconfiguration.h" + +#ifdef Q_OS_SYMBIAN +#include "qnetworkconfiguration_s60_p.h" +#else +#include "qnetworkconfiguration_p.h" +#endif + +QTM_BEGIN_NAMESPACE + +/*! + \class QNetworkConfiguration + + \brief The QNetworkConfiguration class provides an abstraction of one or more access point configurations. + + \inmodule QtNetwork + \ingroup bearer + + QNetworkConfiguration encapsulates a single access point or service network. + In most cases a single access point configuration can be mapped to one network + interface. However a single network interface may not always map to only one + access point configuration. Multiple configurations for the same + network device may enable multiple access points. An example + device that could exhibit such a configuration might be a + Smartphone which allows the user to manage multiple WLAN + configurations while the device itself has only one WLAN network device. + + The QNetworkConfiguration also supports the concept of service networks. + This concept allows the grouping of multiple access point configurations + into one entity. Such a group is called service network and can be + beneficial in cases whereby a network session to a + particular destination network is required (e.g. a company network). + When using a service network the user doesn't usually care which one of the + connectivity options is chosen (e.g. corporate WLAN or VPN via GPRS) + as long as he can reach the company's target server. Depending + on the current position and time some of the access points that make + up the service network may not even be available. Furthermore + automated access point roaming can be enabled which enables the device + to change the network interface configuration dynamically while maintaining + the applications connection to the target network. It allows adaption + to the changing environment and may enable optimization with regards to + cost, speed or other network parameters. + + Special configurations of type UserChoice provide a placeholder configuration which is + resolved to an actual network configuration by the platform when a + \l {QNetworkSession}{session} is \l {QNetworkSession::open()}{opened}. Not all platforms + support the concept of a user choice configuration. + + \section1 Configuration states + + The list of available configurations can be obtained via + QNetworkConfigurationManager::allConfigurations(). A configuration can have + multiple states. The \l Defined configuration state indicates that the configuration + is stored on the device. However the configuration is not yet ready to be activated + as e.g. a WLAN may not be available at the current time. + + The \l Discovered state implies that the configuration is \l Defined and + the outside conditions are such that the configuration can be used immediately + to open a new network session. An example of such an outside condition may be + that the Ethernet cable is actually connected to the device or that the WLAN + with the specified SSID is in range. + + The \l Active state implies that the configuration is \l Discovered. A configuration + in this state is currently being used by an application. The underlying network + interface has a valid IP configuration and can transfer IP packets between the + device and the target network. + + The \l Undefined state indicates that the system has knowledge of possible target + networks but cannot actually use that knowledge to connect to it. An example + for such a state could be an encrypted WLAN that has been discovered + but the user hasn't actually saved a configuration including the required password + which would allow the device to connect to it. + + Depending on the type of configuration some states are transient in nature. A GPRS/UMTS + connection may almost always be \l Discovered if the GSM/UMTS network is available. + However if the GSM/UMTS network looses the connection the associated configuration may change its state + from \l Discovered to \l Defined as well. A similar use case might be triggered by + WLAN availability. QNetworkConfigurationManager::updateConfigurations() can be used to + manually trigger updates of states. Note that some platforms do not require such updates + as they implicitly change the state once it has been discovered. If the state of a + configuration changes all related QNetworkConfiguration instances change their state automatically. + + \sa QNetworkSession, QNetworkConfigurationManager +*/ + +/*! + \enum QNetworkConfiguration::Type + + This enum describes the type of configuration. + + \value InternetAccessPoint The configuration specifies the details for a single access point. + Note that configurations of type InternetAccessPoint may be part + of other QNetworkConfigurations of type ServiceNetwork. + \value ServiceNetwork The configuration is based on a group of QNetworkConfigurations of + type InternetAccessPoint. All group members can reach the same + target network. This type of configuration is a mandatory + requirement for roaming enabled network sessions. On some + platforms this form of configuration may also be called Service + Network Access Point (SNAP). + \value UserChoice The configuration is a placeholder which will be resolved to an + actual configuration by the platform when a session is opened. Depending + on the platform the selection may generate a popup dialog asking the user + for his preferred choice. + \value Invalid The configuration is invalid. +*/ + +/*! + \enum QNetworkConfiguration::StateFlag + + Specifies the configuration states. + + \value Undefined This state is used for transient configurations such as newly discovered + WLANs for which the user has not actually created a configuration yet. + \value Defined Defined configurations are known to the system but are not immediately + usable (e.g. a configured WLAN is not within range or the Ethernet cable + is currently not plugged into the machine). + \value Discovered A discovered configuration can be immediately used to create a new + QNetworkSession. An example of a discovered configuration could be a WLAN + which is within in range. If the device moves out of range the discovered + flag is dropped. A second example is a GPRS configuration which generally + remains discovered for as long as the phone has network coverage. A + configuration that has this state is also in state + QNetworkConfiguration::Defined. If the configuration is a service network + this flag is set if at least one of the underlying access points + configurations has the Discovered state. + \value Active The configuration is currently used by an open/active network session + (see \l QNetworkSession::isActive()). However this does not mean that the + current process is the entity that created the active session. It merely + indicates that if a new QNetworkSession were to be constructed based on + this configuration \l QNetworkSession::state() would return + \l QNetworkSession::Connected. This state implies the + QNetworkConfiguration::Discovered state. +*/ + +/*! + \enum QNetworkConfiguration::Purpose + + Specifies the purpose of the configuration. + + \value UnknownPurpose The configuration doesn't specify any purpose. This is the default value. + \value PublicPurpose The configuration can be used for general purpose internet access. + \value PrivatePurpose The configuration is suitable to access a private network such as an office Intranet. + \value ServiceSpecificPurpose The configuration can be used for operator specific services (e.g. + receiving MMS messages or content streaming). +*/ + +/*! + Constructs an invalid configuration object. + + \sa isValid() +*/ +QNetworkConfiguration::QNetworkConfiguration() + : d(0) +{ +} + +/*! + Creates a copy of the QNetworkConfiguration object contained in \a other. +*/ +QNetworkConfiguration::QNetworkConfiguration(const QNetworkConfiguration& other) + : d(other.d) +{ +} + +/*! + Copies the content of the QNetworkConfiguration object contained in \a other into this one. +*/ +QNetworkConfiguration& QNetworkConfiguration::operator=(const QNetworkConfiguration& other) +{ + d = other.d; + return *this; +} + +/*! + Frees the resources associated with the QNetworkConfiguration object. +*/ +QNetworkConfiguration::~QNetworkConfiguration() +{ +} + +/*! + Returns true, if this configuration is the same as the \a other + configuration given; otherwise returns false. +*/ +bool QNetworkConfiguration::operator==(const QNetworkConfiguration& other) const +{ + if (!d) + return !other.d; + + if (!other.d) + return false; + + return (d == other.d); +} + +/*! + \fn bool QNetworkConfiguration::operator!=(const QNetworkConfiguration& other) const + + Returns true if this configuration is not the same as the \a other + configuration given; otherwise returns false. +*/ + +/*! + Returns the user visible name of this configuration. + + The name may either be the name of the underlying access point or the + name for service network that this configuration represents. +*/ +QString QNetworkConfiguration::name() const +{ + return d ? d->name : QString(); +} + +/*! + Returns the unique and platform specific identifier for this network configuration; + otherwise an empty string. +*/ +QString QNetworkConfiguration::identifier() const +{ + return d ? d->id : QString(); +} + +/*! + Returns the type of the configuration. + + A configuration can represent a single access point configuration or + a set of access point configurations. Such a set is called service network. + A configuration that is based on a service network can potentially support + roaming of network sessions. +*/ +QNetworkConfiguration::Type QNetworkConfiguration::type() const +{ + return d ? d->type : QNetworkConfiguration::Invalid; +} + +/*! + Returns true if this QNetworkConfiguration object is valid. + A configuration may become invalid if the user deletes the configuration or + the configuration was default-constructed. + + The addition and removal of configurations can be monitored via the + QNetworkConfigurationManager. + + \sa QNetworkConfigurationManager +*/ +bool QNetworkConfiguration::isValid() const +{ + return d ? d->isValid : false; +} + +/*! + Returns the current state of the configuration. +*/ +QNetworkConfiguration::StateFlags QNetworkConfiguration::state() const +{ + return d ? d->state : QNetworkConfiguration::Undefined; +} + +/*! + Returns the purpose of this configuration. + + The purpose field may be used to programmatically determine the + purpose of a configuration. Such information is usually part of the + access point or service network meta data. +*/ +QNetworkConfiguration::Purpose QNetworkConfiguration::purpose() const +{ + return d ? d->purpose : QNetworkConfiguration::UnknownPurpose; +} + +/*! + Returns true if this configuration supports roaming; otherwise false. +*/ +bool QNetworkConfiguration::isRoamingAvailable() const +{ + return d ? d->roamingSupported : false; +} + +/*! + Returns all sub configurations of this network configuration. + Only network configurations of type \l ServiceNetwork can have children. Otherwise + this function returns an empty list. +*/ +QList QNetworkConfiguration::children() const +{ + QList results; + if (type() != QNetworkConfiguration::ServiceNetwork || !isValid() ) + return results; + + QMutableListIterator > iter(d->serviceNetworkMembers); + QExplicitlySharedDataPointer p(0); + while(iter.hasNext()) { + p = iter.next(); + //if we have an invalid member get rid of it -> was deleted earlier on + if (!p->isValid) + iter.remove(); + + QNetworkConfiguration item; + item.d = p; + results << item; + } + + return results; +} + + +QTM_END_NAMESPACE + diff --git a/src/network/bearer/qnetworkconfiguration.h b/src/network/bearer/qnetworkconfiguration.h new file mode 100644 index 0000000..f8c17d5 --- /dev/null +++ b/src/network/bearer/qnetworkconfiguration.h @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 QNETWORKCONFIGURATION_H +#define QNETWORKCONFIGURATION_H + +#include "qmobilityglobal.h" + +#include +#include +#include + +QT_BEGIN_HEADER + +QTM_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; +class Q_BEARER_EXPORT QNetworkConfiguration +{ +public: + QNetworkConfiguration(); + QNetworkConfiguration(const QNetworkConfiguration& other); + QNetworkConfiguration &operator=(const QNetworkConfiguration& other); + ~QNetworkConfiguration(); + + bool operator==(const QNetworkConfiguration& cp) const; + inline bool operator!=(const QNetworkConfiguration& cp) const + { return !operator==(cp); } + + enum Type { + InternetAccessPoint = 0, + ServiceNetwork, + UserChoice, + Invalid + }; + + enum Purpose { + UnknownPurpose = 0, + PublicPurpose, + PrivatePurpose, + ServiceSpecificPurpose + }; + + enum StateFlag { + Undefined = 0x0000001, + Defined = 0x0000002, + Discovered = 0x0000006, + Active = 0x000000e + }; + + Q_DECLARE_FLAGS(StateFlags, StateFlag) + + StateFlags state() const; + Type type() const; + Purpose purpose() const; + QString identifier() const; + bool isRoamingAvailable() const; + QList children() const; + + QString name() const; + bool isValid() const; + +private: + friend class QNetworkConfigurationPrivate; + friend class QNetworkConfigurationManager; + friend class QNetworkConfigurationManagerPrivate; + friend class QNetworkSessionPrivate; + QExplicitlySharedDataPointer d; +}; + +QTM_END_NAMESPACE + +QT_END_HEADER + +#endif //QNETWORKCONFIGURATION_H diff --git a/src/network/bearer/qnetworkconfiguration_maemo_p.h b/src/network/bearer/qnetworkconfiguration_maemo_p.h new file mode 100644 index 0000000..8d786aa --- /dev/null +++ b/src/network/bearer/qnetworkconfiguration_maemo_p.h @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 +#include +#include + +QTM_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 > 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 */ + 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); +}; + +QTM_END_NAMESPACE + +#endif //QNETWORKCONFIGURATIONPRIVATE_H diff --git a/src/network/bearer/qnetworkconfiguration_p.h b/src/network/bearer/qnetworkconfiguration_p.h new file mode 100644 index 0000000..a3bcd9a --- /dev/null +++ b/src/network/bearer/qnetworkconfiguration_p.h @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 +#include + +QTM_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate : public QSharedData +{ +public: + QNetworkConfigurationPrivate () + : isValid(false), type(QNetworkConfiguration::Invalid), + roamingSupported(false), purpose(QNetworkConfiguration::UnknownPurpose) + { +#ifdef BEARER_ENGINE + internet = false; +#endif + } + + ~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; + +#ifdef BEARER_ENGINE + bool internet; +#endif + + QList > serviceNetworkMembers; + QNetworkInterface serviceInterface; + +private: + + // disallow detaching + QNetworkConfigurationPrivate &operator=(const QNetworkConfigurationPrivate &other); + QNetworkConfigurationPrivate(const QNetworkConfigurationPrivate &other); +}; + +QTM_END_NAMESPACE + +#endif //QNETWORKCONFIGURATIONPRIVATE_H diff --git a/src/network/bearer/qnetworkconfiguration_s60_p.cpp b/src/network/bearer/qnetworkconfiguration_s60_p.cpp new file mode 100644 index 0000000..61548ba --- /dev/null +++ b/src/network/bearer/qnetworkconfiguration_s60_p.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 "qnetworkconfiguration_s60_p.h" + +QTM_BEGIN_NAMESPACE + +QNetworkConfigurationPrivate::QNetworkConfigurationPrivate() + : isValid(false), type(QNetworkConfiguration::Invalid), + roamingSupported(false), purpose(QNetworkConfiguration::UnknownPurpose), + bearer(QNetworkConfigurationPrivate::BearerUnknown), numericId(0), + connectionId(0), manager(0) +{ +} + +QNetworkConfigurationPrivate::~QNetworkConfigurationPrivate() +{ + //release pointers to member configurations + serviceNetworkMembers.clear(); +} + +QTM_END_NAMESPACE diff --git a/src/network/bearer/qnetworkconfiguration_s60_p.h b/src/network/bearer/qnetworkconfiguration_s60_p.h new file mode 100644 index 0000000..44f8f56 --- /dev/null +++ b/src/network/bearer/qnetworkconfiguration_s60_p.h @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 +#include + +QTM_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate : public QSharedData +{ +public: + enum Bearer { + BearerEthernet, + BearerWLAN, + Bearer2G, + BearerCDMA2000, + BearerWCDMA, + BearerHSPA, + BearerBluetooth, + BearerWiMAX, + BearerUnknown = -1 + }; + + QNetworkConfigurationPrivate(); + ~QNetworkConfigurationPrivate(); + + QString name; + bool isValid; + QString id; + QNetworkConfiguration::StateFlags state; + QNetworkConfiguration::Type type; + bool roamingSupported; + QNetworkConfiguration::Purpose purpose; + + QList > serviceNetworkMembers; + + QNetworkConfigurationPrivate::Bearer bearer; + TUint32 numericId; + TUint connectionId; + + TAny* manager; + + QString mappingName; + + QExplicitlySharedDataPointer serviceNetworkPtr; + +private: + // disallow detaching + QNetworkConfigurationPrivate &operator=(const QNetworkConfigurationPrivate &other); + QNetworkConfigurationPrivate(const QNetworkConfigurationPrivate &other); +}; + +QTM_END_NAMESPACE + +#endif //QNETWORKCONFIGURATIONPRIVATE_H + diff --git a/src/network/bearer/qnetworkmanagerservice_p.cpp b/src/network/bearer/qnetworkmanagerservice_p.cpp new file mode 100644 index 0000000..2f91af0 --- /dev/null +++ b/src/network/bearer/qnetworkmanagerservice_p.cpp @@ -0,0 +1,1011 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include "qnetworkmanagerservice_p.h" + +//Q_DECLARE_METATYPE(QList) +QTM_BEGIN_NAMESPACE + +static QDBusConnection dbusConnection = QDBusConnection::systemBus(); +//static QDBusInterface iface(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, dbusConnection); + +class QNetworkManagerInterfacePrivate +{ +public: + QDBusInterface *connectionInterface; + bool valid; +}; + +QNetworkManagerInterface::QNetworkManagerInterface(QObject *parent) + : QObject(parent) +{ + d = new QNetworkManagerInterfacePrivate(); + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + dbusConnection); + if (!d->connectionInterface->isValid()) { + qWarning() << "Could not find NetworkManager"; + d->valid = false; + return; + } + d->valid = true; + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), + this,SIGNAL(propertiesChanged( const QString &, QMap))); + connect(nmDBusHelper,SIGNAL(pathForStateChanged(const QString &, quint32)), + this, SIGNAL(stateChanged(const QString&, quint32))); + +} + +QNetworkManagerInterface::~QNetworkManagerInterface() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerInterface::isValid() +{ + return d->valid; +} + +bool QNetworkManagerInterface::setConnections() +{ + if(!isValid() ) + return false; + bool allOk = false; + if (!dbusConnection.connect(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "PropertiesChanged", + nmDBusHelper,SLOT(slotPropertiesChanged( QMap)))) { + allOk = true; + } + if (!dbusConnection.connect(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "DeviceAdded", + this,SIGNAL(deviceAdded(QDBusObjectPath)))) { + allOk = true; + } + if (!dbusConnection.connect(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "DeviceRemoved", + this,SIGNAL(deviceRemoved(QDBusObjectPath)))) { + allOk = true; + } + + return allOk; +} + +QDBusInterface *QNetworkManagerInterface::connectionInterface() const +{ + return d->connectionInterface; +} + +QList QNetworkManagerInterface::getDevices() const +{ + QDBusReply > reply = d->connectionInterface->call("GetDevices"); + return reply.value(); +} + +void QNetworkManagerInterface::activateConnection( const QString &serviceName, + QDBusObjectPath connectionPath, + QDBusObjectPath devicePath, + QDBusObjectPath specificObject) +{ + QDBusPendingCall pendingCall = d->connectionInterface->asyncCall("ActivateConnection", + QVariant(serviceName), + QVariant::fromValue(connectionPath), + QVariant::fromValue(devicePath), + QVariant::fromValue(specificObject)); + + QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(pendingCall, this); + connect(callWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SIGNAL(activationFinished(QDBusPendingCallWatcher*))); +} + +void QNetworkManagerInterface::deactivateConnection(QDBusObjectPath connectionPath) const +{ + d->connectionInterface->call("DeactivateConnection", QVariant::fromValue(connectionPath)); +} + +bool QNetworkManagerInterface::wirelessEnabled() const +{ + return d->connectionInterface->property("WirelessEnabled").toBool(); +} + +bool QNetworkManagerInterface::wirelessHardwareEnabled() const +{ + return d->connectionInterface->property("WirelessHardwareEnabled").toBool(); +} + +QList QNetworkManagerInterface::activeConnections() const +{ + QVariant prop = d->connectionInterface->property("ActiveConnections"); + return prop.value >(); +} + +quint32 QNetworkManagerInterface::state() +{ + return d->connectionInterface->property("State").toUInt(); +} + +///////////// +class QNetworkManagerInterfaceAccessPointPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerInterfaceAccessPoint::QNetworkManagerInterfaceAccessPoint(const QString &dbusPathName, QObject *parent) + : QObject(parent) +{ + d = new QNetworkManagerInterfaceAccessPointPrivate(); + d->path = dbusPathName; + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_ACCESS_POINT, + dbusConnection); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find InterfaceAccessPoint"; + return; + } + d->valid = true; + +} + +QNetworkManagerInterfaceAccessPoint::~QNetworkManagerInterfaceAccessPoint() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerInterfaceAccessPoint::isValid() +{ + return d->valid; +} + +bool QNetworkManagerInterfaceAccessPoint::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), + this,SIGNAL(propertiesChanged( const QString &, QMap))); + + if(dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_ACCESS_POINT, + "PropertiesChanged", + nmDBusHelper,SLOT(slotPropertiesChanged( QMap))) ) { + allOk = true; + + } + return allOk; +} + +QDBusInterface *QNetworkManagerInterfaceAccessPoint::connectionInterface() const +{ + return d->connectionInterface; +} + +quint32 QNetworkManagerInterfaceAccessPoint::flags() const +{ + return d->connectionInterface->property("Flags").toUInt(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::wpaFlags() const +{ + return d->connectionInterface->property("WpaFlags").toUInt(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::rsnFlags() const +{ + return d->connectionInterface->property("RsnFlags").toUInt(); +} + +QString QNetworkManagerInterfaceAccessPoint::ssid() const +{ + return d->connectionInterface->property("Ssid").toString(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::frequency() const +{ + return d->connectionInterface->property("Frequency").toUInt(); +} + +QString QNetworkManagerInterfaceAccessPoint::hwAddress() const +{ + return d->connectionInterface->property("HwAddress").toString(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::mode() const +{ + return d->connectionInterface->property("Mode").toUInt(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::maxBitrate() const +{ + return d->connectionInterface->property("MaxBitrate").toUInt(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::strength() const +{ + return d->connectionInterface->property("Strength").toUInt(); +} + +///////////// +class QNetworkManagerInterfaceDevicePrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerInterfaceDevice::QNetworkManagerInterfaceDevice(const QString &deviceObjectPath, QObject *parent) + : QObject(parent) +{ + d = new QNetworkManagerInterfaceDevicePrivate(); + d->path = deviceObjectPath; + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE, + dbusConnection); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find NetworkManager"; + return; + } + d->valid = true; +} + +QNetworkManagerInterfaceDevice::~QNetworkManagerInterfaceDevice() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerInterfaceDevice::isValid() +{ + return d->valid; +} + +bool QNetworkManagerInterfaceDevice::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper,SIGNAL(pathForStateChanged(const QString &, quint32)), + this, SIGNAL(stateChanged(const QString&, quint32))); + if(dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE, + "StateChanged", + nmDBusHelper,SLOT(deviceStateChanged(quint32)))) { + allOk = true; + } + return allOk; +} + +QDBusInterface *QNetworkManagerInterfaceDevice::connectionInterface() const +{ + return d->connectionInterface; +} + +QString QNetworkManagerInterfaceDevice::udi() const +{ + return d->connectionInterface->property("Udi").toString(); +} + +QNetworkInterface QNetworkManagerInterfaceDevice::interface() const +{ + return QNetworkInterface::interfaceFromName(d->connectionInterface->property("Interface").toString()); +} + +quint32 QNetworkManagerInterfaceDevice::ip4Address() const +{ + return d->connectionInterface->property("Ip4Address").toUInt(); +} + +quint32 QNetworkManagerInterfaceDevice::state() const +{ + return d->connectionInterface->property("State").toUInt(); +} + +quint32 QNetworkManagerInterfaceDevice::deviceType() const +{ + return d->connectionInterface->property("DeviceType").toUInt(); +} + +QDBusObjectPath QNetworkManagerInterfaceDevice::ip4config() const +{ + QVariant prop = d->connectionInterface->property("Ip4Config"); + return prop.value(); +} + +///////////// +class QNetworkManagerInterfaceDeviceWiredPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerInterfaceDeviceWired::QNetworkManagerInterfaceDeviceWired(const QString &ifaceDevicePath, QObject *parent) +{ + d = new QNetworkManagerInterfaceDeviceWiredPrivate(); + d->path = ifaceDevicePath; + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE_WIRED, + dbusConnection, parent); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find InterfaceDeviceWired"; + return; + } + d->valid = true; +} + +QNetworkManagerInterfaceDeviceWired::~QNetworkManagerInterfaceDeviceWired() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerInterfaceDeviceWired::isValid() +{ + + return d->valid; +} + +bool QNetworkManagerInterfaceDeviceWired::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), + this,SIGNAL(propertiesChanged( const QString &, QMap))); + if(dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE_WIRED, + "PropertiesChanged", + nmDBusHelper,SLOT(slotPropertiesChanged( QMap))) ) { + allOk = true; + } + return allOk; +} + +QDBusInterface *QNetworkManagerInterfaceDeviceWired::connectionInterface() const +{ + return d->connectionInterface; +} + +QString QNetworkManagerInterfaceDeviceWired::hwAddress() const +{ + return d->connectionInterface->property("HwAddress").toString(); +} + +quint32 QNetworkManagerInterfaceDeviceWired::speed() const +{ + return d->connectionInterface->property("Speed").toUInt(); +} + +bool QNetworkManagerInterfaceDeviceWired::carrier() const +{ + return d->connectionInterface->property("Carrier").toBool(); +} + +///////////// +class QNetworkManagerInterfaceDeviceWirelessPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerInterfaceDeviceWireless::QNetworkManagerInterfaceDeviceWireless(const QString &ifaceDevicePath, QObject *parent) +{ + d = new QNetworkManagerInterfaceDeviceWirelessPrivate(); + d->path = ifaceDevicePath; + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE_WIRELESS, + dbusConnection, parent); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find InterfaceDeviceWireless"; + return; + } + d->valid = true; +} + +QNetworkManagerInterfaceDeviceWireless::~QNetworkManagerInterfaceDeviceWireless() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerInterfaceDeviceWireless::isValid() +{ + return d->valid; +} + +bool QNetworkManagerInterfaceDeviceWireless::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), + this,SIGNAL(propertiesChanged( const QString &, QMap))); + + connect(nmDBusHelper, SIGNAL(pathForAccessPointAdded(const QString &,QDBusObjectPath)), + this,SIGNAL(accessPointAdded(const QString &,QDBusObjectPath))); + + connect(nmDBusHelper, SIGNAL(pathForAccessPointRemoved(const QString &,QDBusObjectPath)), + this,SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath))); + + if(!dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE_WIRELESS, + "AccessPointAdded", + nmDBusHelper, SLOT(slotAccessPointAdded( QDBusObjectPath )))) { + allOk = true; + } + + + if(!dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE_WIRELESS, + "AccessPointRemoved", + nmDBusHelper, SLOT(slotAccessPointRemoved( QDBusObjectPath )))) { + allOk = true; + } + + + if(!dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE_WIRELESS, + "PropertiesChanged", + nmDBusHelper,SLOT(slotPropertiesChanged( QMap)))) { + allOk = true; + } + + return allOk; +} + +QDBusInterface *QNetworkManagerInterfaceDeviceWireless::connectionInterface() const +{ + return d->connectionInterface; +} + +QList QNetworkManagerInterfaceDeviceWireless::getAccessPoints() +{ + QDBusReply > reply = d->connectionInterface->call("GetAccessPoints"); + return reply.value(); +} + +QString QNetworkManagerInterfaceDeviceWireless::hwAddress() const +{ + return d->connectionInterface->property("HwAddress").toString(); +} + +quint32 QNetworkManagerInterfaceDeviceWireless::mode() const +{ + return d->connectionInterface->property("Mode").toUInt(); +} + +quint32 QNetworkManagerInterfaceDeviceWireless::bitrate() const +{ + return d->connectionInterface->property("Bitrate").toUInt(); +} + +QDBusObjectPath QNetworkManagerInterfaceDeviceWireless::activeAccessPoint() const +{ + return d->connectionInterface->property("ActiveAccessPoint").value(); +} + +quint32 QNetworkManagerInterfaceDeviceWireless::wirelessCapabilities() const +{ + return d->connectionInterface->property("WirelelessCapabilities").toUInt(); +} + +///////////// +class QNetworkManagerSettingsPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerSettings::QNetworkManagerSettings(const QString &settingsService, QObject *parent) + : QObject(parent) +{ +// qWarning() << __PRETTY_FUNCTION__; + d = new QNetworkManagerSettingsPrivate(); + d->path = settingsService; + d->connectionInterface = new QDBusInterface(settingsService, + NM_DBUS_PATH_SETTINGS, + NM_DBUS_IFACE_SETTINGS, + dbusConnection); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find NetworkManagerSettings"; + return; + } + d->valid = true; +} + +QNetworkManagerSettings::~QNetworkManagerSettings() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerSettings::isValid() +{ + return d->valid; +} + +bool QNetworkManagerSettings::setConnections() +{ + bool allOk = false; + + if (!dbusConnection.connect(d->path, NM_DBUS_PATH_SETTINGS, + NM_DBUS_IFACE_SETTINGS, "NewConnection", + this, SIGNAL(newConnection(QDBusObjectPath)))) { + allOk = true; + } + + return allOk; +} + +QList QNetworkManagerSettings::listConnections() +{ + QDBusReply > reply = d->connectionInterface->call("ListConnections"); + return reply.value(); +} + +QDBusInterface *QNetworkManagerSettings::connectionInterface() const +{ + return d->connectionInterface; +} + + +///////////// +class QNetworkManagerSettingsConnectionPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + QString service; + QNmSettingsMap settingsMap; + bool valid; +}; + +QNetworkManagerSettingsConnection::QNetworkManagerSettingsConnection(const QString &settingsService, const QString &connectionObjectPath, QObject *parent) +{ + qDBusRegisterMetaType(); + d = new QNetworkManagerSettingsConnectionPrivate(); + d->path = connectionObjectPath; + d->service = settingsService; + d->connectionInterface = new QDBusInterface(settingsService, + d->path, + NM_DBUS_IFACE_SETTINGS_CONNECTION, + dbusConnection, parent); + if (!d->connectionInterface->isValid()) { + qWarning() << "Could not find NetworkManagerSettingsConnection"; + d->valid = false; + return; + } + d->valid = true; + QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call("GetSettings"); + d->settingsMap = rep.value(); +} + +QNetworkManagerSettingsConnection::~QNetworkManagerSettingsConnection() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerSettingsConnection::isValid() +{ + return d->valid; +} + +bool QNetworkManagerSettingsConnection::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + if(!dbusConnection.connect(d->service, d->path, + NM_DBUS_IFACE_SETTINGS_CONNECTION, "NewConnection", + this, SIGNAL(updated(QNmSettingsMap)))) { + allOk = true; + } + + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper, SIGNAL(pathForSettingsRemoved(const QString &)), + this,SIGNAL(removed( const QString &))); + + if (!dbusConnection.connect(d->service, d->path, + NM_DBUS_IFACE_SETTINGS_CONNECTION, "Removed", + nmDBusHelper, SIGNAL(slotSettingsRemoved()))) { + allOk = true; + } + + return allOk; +} +//QNetworkManagerSettingsConnection::update(QNmSettingsMap map) +//{ +// d->connectionInterface->call("Update", QVariant::fromValue(map)); +//} + +QDBusInterface *QNetworkManagerSettingsConnection::connectionInterface() const +{ + return d->connectionInterface; +} + +QNmSettingsMap QNetworkManagerSettingsConnection::getSettings() +{ + QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call("GetSettings"); + d->settingsMap = rep.value(); + return d->settingsMap; +} + +NMDeviceType QNetworkManagerSettingsConnection::getType() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); + while (i != d->settingsMap.end() && i.key() == "connection") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("type"); + while (ii != innerMap.end() && ii.key() == "type") { + QString devType = ii.value().toString(); + if (devType == "802-3-ethernet") { + return DEVICE_TYPE_802_3_ETHERNET; + } + if (devType == "802-11-wireless") { + return DEVICE_TYPE_802_11_WIRELESS; + } + ii++; + } + i++; + } + return DEVICE_TYPE_UNKNOWN; +} + +bool QNetworkManagerSettingsConnection::isAutoConnect() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); + while (i != d->settingsMap.end() && i.key() == "connection") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("autoconnect"); + while (ii != innerMap.end() && ii.key() == "autoconnect") { + return ii.value().toBool(); + ii++; + } + i++; + } + return true; //default networkmanager is autoconnect +} + +quint64 QNetworkManagerSettingsConnection::getTimestamp() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); + while (i != d->settingsMap.end() && i.key() == "connection") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("timestamp"); + while (ii != innerMap.end() && ii.key() == "timestamp") { + return ii.value().toUInt(); + ii++; + } + i++; + } + return 0; +} + +QString QNetworkManagerSettingsConnection::getId() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); + while (i != d->settingsMap.end() && i.key() == "connection") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("id"); + while (ii != innerMap.end() && ii.key() == "id") { + return ii.value().toString(); + ii++; + } + i++; + } + return QString(); +} + +QString QNetworkManagerSettingsConnection::getUuid() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); + while (i != d->settingsMap.end() && i.key() == "connection") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("uuid"); + while (ii != innerMap.end() && ii.key() == "uuid") { + return ii.value().toString(); + ii++; + } + i++; + } + // is no uuid, return the connection path + return d->connectionInterface->path(); +} + +QString QNetworkManagerSettingsConnection::getSsid() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find("802-11-wireless"); + while (i != d->settingsMap.end() && i.key() == "802-11-wireless") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("ssid"); + while (ii != innerMap.end() && ii.key() == "ssid") { + return ii.value().toString(); + ii++; + } + i++; + } + return QString(); +} + +QString QNetworkManagerSettingsConnection::getMacAddress() +{ + if(getType() == DEVICE_TYPE_802_3_ETHERNET) { + QNmSettingsMap::const_iterator i = d->settingsMap.find("802-3-ethernet"); + while (i != d->settingsMap.end() && i.key() == "802-3-ethernet") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("mac-address"); + while (ii != innerMap.end() && ii.key() == "mac-address") { + return ii.value().toString(); + ii++; + } + i++; + } + } + + else if(getType() == DEVICE_TYPE_802_11_WIRELESS) { + QNmSettingsMap::const_iterator i = d->settingsMap.find("802-11-wireless"); + while (i != d->settingsMap.end() && i.key() == "802-11-wireless") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("mac-address"); + while (ii != innerMap.end() && ii.key() == "mac-address") { + return ii.value().toString(); + ii++; + } + i++; + } + } + return QString(); +} + +QStringList QNetworkManagerSettingsConnection::getSeenBssids() +{ + if(getType() == DEVICE_TYPE_802_11_WIRELESS) { + QNmSettingsMap::const_iterator i = d->settingsMap.find("802-11-wireless"); + while (i != d->settingsMap.end() && i.key() == "802-11-wireless") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("seen-bssids"); + while (ii != innerMap.end() && ii.key() == "seen-bssids") { + return ii.value().toStringList(); + ii++; + } + i++; + } + } + return QStringList(); +} + +///////////// +class QNetworkManagerConnectionActivePrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerConnectionActive::QNetworkManagerConnectionActive( const QString &activeConnectionObjectPath, QObject *parent) +{ + d = new QNetworkManagerConnectionActivePrivate(); + d->path = activeConnectionObjectPath; + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + dbusConnection, parent); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find NetworkManagerSettingsConnection"; + return; + } + d->valid = true; +} + +QNetworkManagerConnectionActive::~QNetworkManagerConnectionActive() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerConnectionActive::isValid() +{ + return d->valid; +} + +bool QNetworkManagerConnectionActive::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), + this,SIGNAL(propertiesChanged( const QString &, QMap))); + if(dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + "PropertiesChanged", + nmDBusHelper,SLOT(slotPropertiesChanged( QMap))) ) { + allOk = true; + } + + return allOk; +} + +QDBusInterface *QNetworkManagerConnectionActive::connectionInterface() const +{ + return d->connectionInterface; +} + +QString QNetworkManagerConnectionActive::serviceName() const +{ + return d->connectionInterface->property("ServiceName").toString(); +} + +QDBusObjectPath QNetworkManagerConnectionActive::connection() const +{ + QVariant prop = d->connectionInterface->property("Connection"); + return prop.value(); +} + +QDBusObjectPath QNetworkManagerConnectionActive::specificObject() const +{ + QVariant prop = d->connectionInterface->property("SpecificObject"); + return prop.value(); +} + +QList QNetworkManagerConnectionActive::devices() const +{ + QVariant prop = d->connectionInterface->property("Devices"); + return prop.value >(); +} + +quint32 QNetworkManagerConnectionActive::state() const +{ + return d->connectionInterface->property("State").toUInt(); +} + +bool QNetworkManagerConnectionActive::defaultRoute() const +{ + return d->connectionInterface->property("Default").toBool(); +} + + +//// +class QNetworkManagerIp4ConfigPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerIp4Config::QNetworkManagerIp4Config( const QString &deviceObjectPath, QObject *parent) +{ + d = new QNetworkManagerIp4ConfigPrivate(); + d->path = deviceObjectPath; + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_IP4_CONFIG, + dbusConnection, parent); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find NetworkManagerIp4Config"; + return; + } + d->valid = true; +} + +QNetworkManagerIp4Config::~QNetworkManagerIp4Config() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerIp4Config::isValid() +{ + return d->valid; +} + +QStringList QNetworkManagerIp4Config::domains() const +{ + return d->connectionInterface->property("Domains").toStringList(); +} + +#include "moc_qnetworkmanagerservice_p.cpp" + +QTM_END_NAMESPACE diff --git a/src/network/bearer/qnetworkmanagerservice_p.h b/src/network/bearer/qnetworkmanagerservice_p.h new file mode 100644 index 0000000..8569e71 --- /dev/null +++ b/src/network/bearer/qnetworkmanagerservice_p.h @@ -0,0 +1,400 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 QNETWORKMANAGERSERVICE_H +#define QNETWORKMANAGERSERVICE_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 +#include +#include +#include +#include +#include +#include +#include + + +#include +#include + + +QTM_BEGIN_NAMESPACE +typedef QMap< QString, QMap > QNmSettingsMap; +typedef QList ServerThing; +QTM_END_NAMESPACE + +Q_DECLARE_METATYPE(QTM_PREPEND_NAMESPACE(QNmSettingsMap)) +Q_DECLARE_METATYPE(QTM_PREPEND_NAMESPACE(ServerThing)) + + +QTM_BEGIN_NAMESPACE +class QNetworkManagerInterfacePrivate; +class QNetworkManagerInterface : public QObject +{ + Q_OBJECT + +public: + + QNetworkManagerInterface(QObject *parent = 0); + ~QNetworkManagerInterface(); + + QList getDevices() const; + void activateConnection(const QString &serviceName, QDBusObjectPath connection, QDBusObjectPath device, QDBusObjectPath specificObject); + void deactivateConnection(QDBusObjectPath connectionPath) const; + + QDBusObjectPath path() const; + QDBusInterface *connectionInterface() const; + + bool wirelessEnabled() const; + bool wirelessHardwareEnabled() const; + QList activeConnections() const; + quint32 state(); + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void deviceAdded(QDBusObjectPath); + void deviceRemoved(QDBusObjectPath); + void propertiesChanged( const QString &, QMap); + void stateChanged(const QString&, quint32); + void activationFinished(QDBusPendingCallWatcher*); + +private Q_SLOTS: +private: +// Q_DISABLE_COPY(QNetworkManagerInterface); ?? + QNetworkManagerInterfacePrivate *d; + QNmDBusHelper *nmDBusHelper; +}; //end QNetworkManagerInterface + +//////// +class QNetworkManagerInterfaceAccessPointPrivate; +class QNetworkManagerInterfaceAccessPoint : public QObject +{ + Q_OBJECT + +public: + + // NM_DEVICE_STATE + enum DeviceState { + Unknown = 0, + Unmanaged, + Unavailable, + Disconnected, + Prepare, + Config, + NeedAuthentication, + IpConfig, + Activated, + Failed + }; + + enum ApFlag { + ApNone = 0x0, + Privacy = 0x1 + }; + + Q_DECLARE_FLAGS(ApFlags, ApFlag); + + enum ApSecurityFlag { + ApSecurityNone = 0x0, + PairWep40 = 0x1, + PairWep104 = 0x2, + PairTkip = 0x4, + PairCcmp = 0x8, + GroupWep40 = 0x10, + GroupWep104 = 0x20, + GroupTkip = 0x40, + GroupCcmp = 0x80, + KeyPsk = 0x100, + Key8021x = 0x200 + }; + + Q_DECLARE_FLAGS(ApSecurityFlags, ApSecurityFlag); + + QNetworkManagerInterfaceAccessPoint(const QString &dbusPathName, QObject *parent = 0); + ~QNetworkManagerInterfaceAccessPoint(); + + QDBusInterface *connectionInterface() const; + + quint32 flags() const; + quint32 wpaFlags() const; + quint32 rsnFlags() const; + QString ssid() const; + quint32 frequency() const; + QString hwAddress() const; + quint32 mode() const; + quint32 maxBitrate() const; + quint32 strength() const; + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void propertiesChanged(QMap ); + void propertiesChanged( const QString &, QMap); +private: + QNetworkManagerInterfaceAccessPointPrivate *d; + QNmDBusHelper *nmDBusHelper; + +}; //end QNetworkManagerInterfaceAccessPoint + +//////// +class QNetworkManagerInterfaceDevicePrivate; +class QNetworkManagerInterfaceDevice : public QObject +{ + Q_OBJECT + +public: + + QNetworkManagerInterfaceDevice(const QString &deviceObjectPath, QObject *parent = 0); + ~QNetworkManagerInterfaceDevice(); + + QString udi() const; + QNetworkInterface interface() const; + QDBusInterface *connectionInterface() const; + quint32 ip4Address() const; + quint32 state() const; + quint32 deviceType() const; + + QDBusObjectPath ip4config() const; + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void stateChanged(const QString &, quint32); + +private: + QNetworkManagerInterfaceDevicePrivate *d; + QNmDBusHelper *nmDBusHelper; +}; //end QNetworkManagerInterfaceDevice + +//////// +class QNetworkManagerInterfaceDeviceWiredPrivate; +class QNetworkManagerInterfaceDeviceWired : public QObject +{ + Q_OBJECT + +public: + + QNetworkManagerInterfaceDeviceWired(const QString &ifaceDevicePath, QObject *parent = 0); + ~QNetworkManagerInterfaceDeviceWired(); + + QDBusInterface *connectionInterface() const; + QString hwAddress() const; + quint32 speed() const; + bool carrier() const; + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void propertiesChanged( const QString &, QMap); +private: + QNetworkManagerInterfaceDeviceWiredPrivate *d; + QNmDBusHelper *nmDBusHelper; +}; // end QNetworkManagerInterfaceDeviceWired + +//// +class QNetworkManagerInterfaceDeviceWirelessPrivate; +class QNetworkManagerInterfaceDeviceWireless : public QObject +{ + Q_OBJECT + +public: + + enum DeviceCapability { + None = 0x0, + Wep40 = 0x1, + Wep104 = 0x2, + Tkip = 0x4, + Ccmp = 0x8, + Wpa = 0x10, + Rsn = 0x20 + }; + + QNetworkManagerInterfaceDeviceWireless(const QString &ifaceDevicePath, QObject *parent = 0); + ~QNetworkManagerInterfaceDeviceWireless(); + + QDBusObjectPath path() const; + QList getAccessPoints(); + QDBusInterface *connectionInterface() const; + + QString hwAddress() const; + quint32 mode() const; + quint32 bitrate() const; + QDBusObjectPath activeAccessPoint() const; + quint32 wirelessCapabilities() const; + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void propertiesChanged( const QString &, QMap); + void accessPointAdded(const QString &,QDBusObjectPath); + void accessPointRemoved(const QString &,QDBusObjectPath); +private: + QNetworkManagerInterfaceDeviceWirelessPrivate *d; + QNmDBusHelper *nmDBusHelper; +}; // end QNetworkManagerInterfaceDeviceWireless + +//// +class QNetworkManagerSettingsPrivate; +class QNetworkManagerSettings : public QObject +{ + Q_OBJECT + +public: + + QNetworkManagerSettings(const QString &settingsService, QObject *parent = 0); + ~QNetworkManagerSettings(); + + QDBusInterface *connectionInterface() const; + QList listConnections(); + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void newConnection(QDBusObjectPath); +private: + QNetworkManagerSettingsPrivate *d; +}; //end QNetworkManagerSettings + +//// +class QNetworkManagerSettingsConnectionPrivate; +class QNetworkManagerSettingsConnection : public QObject +{ + Q_OBJECT + +public: + + QNetworkManagerSettingsConnection(const QString &settingsService, const QString &connectionObjectPath, QObject *parent = 0); + ~QNetworkManagerSettingsConnection(); + + QDBusInterface *connectionInterface() const; + QNmSettingsMap getSettings(); + // void update(QNmSettingsMap map); + bool setConnections(); + NMDeviceType getType(); + bool isAutoConnect(); + quint64 getTimestamp(); + QString getId(); + QString getUuid(); + QString getSsid(); + QString getMacAddress(); + QStringList getSeenBssids(); + bool isValid(); + +Q_SIGNALS: + + void updated(QMap< QString, QMap > s); + void removed(const QString &); + +private: + QNmDBusHelper *nmDBusHelper; + QNetworkManagerSettingsConnectionPrivate *d; +}; //end QNetworkManagerSettingsConnection + +//// +class QNetworkManagerConnectionActivePrivate; +class QNetworkManagerConnectionActive : public QObject +{ + Q_OBJECT + +public: + + enum ActiveConnectionState { + Unknown = 0, + Activating = 1, + Activated = 2 + }; + + QNetworkManagerConnectionActive(const QString &dbusPathName, QObject *parent = 0); + ~ QNetworkManagerConnectionActive(); + + QDBusInterface *connectionInterface() const; + QString serviceName() const; + QDBusObjectPath connection() const; + QDBusObjectPath specificObject() const; + QList devices() const; + quint32 state() const; + bool defaultRoute() const; + bool setConnections(); + bool isValid(); + + +Q_SIGNALS: + void propertiesChanged(QList); + void propertiesChanged( const QString &, QMap); +private: + QNetworkManagerConnectionActivePrivate *d; + QNmDBusHelper *nmDBusHelper; +}; //QNetworkManagerConnectionActive + +//// +class QNetworkManagerIp4ConfigPrivate; +class QNetworkManagerIp4Config : public QObject +{ + Q_OBJECT + +public: + QNetworkManagerIp4Config(const QString &dbusPathName, QObject *parent = 0); + ~QNetworkManagerIp4Config(); + + // QList nameservers(); + QStringList domains() const; + bool isValid(); + + private: + QNetworkManagerIp4ConfigPrivate *d; +}; +//// + +QTM_END_NAMESPACE + +#endif //QNETWORKMANAGERSERVICE_H diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp new file mode 100644 index 0000000..d3a323a --- /dev/null +++ b/src/network/bearer/qnetworksession.cpp @@ -0,0 +1,689 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 +#include + +#include "qnetworksession.h" + +#ifdef Q_OS_SYMBIAN +#include "qnetworksession_s60_p.h" +#elif MAEMO +#include "qnetworksession_maemo_p.h" +#else +#include "qnetworksession_p.h" +#endif + +QTM_BEGIN_NAMESPACE + +/*! + \class QNetworkSession + + \brief The QNetworkSession class provides control over the system's access points + and enables session management for cases when multiple clients access the same access point. + + \inmodule QtNetwork + \ingroup bearer + + A QNetworkSession enables control over the system's network interfaces. The session's configuration + parameter are determined via the QNetworkConfiguration object to which it is bound. Depending on the + type of the session (single access point or service network) a session may be linked to one or more + network interfaces. By means of \l{open()}{opening} and \l{close()}{closing} of network sessions + a developer can start and stop the systems network interfaces. If the configuration represents + multiple access points (see \l QNetworkConfiguration::ServiceNetwork) more advanced features such as roaming may be supported. + + QNetworkSession supports session management within the same process and depending on the platform's + capabilities may support out-of-process sessions. If the same + network configuration is used by multiple active sessions the underlying network interface is only terminated once + the last session has been closed. + + \section1 Roaming + + Applications may connect to the preferredConfigurationChanged() signal in order to + receive notifications when a more suitable access point becomes available. + In response to this signal the application may initiate the roaming via migrate() + or may ignore() the new access point. Once the session has roamed the + newConfigurationActivated() signal is emitted. The application may now test the + carrier and can accept() or reject() it. The session will return to the previous + access point if the roaming was rejected. + + Some platforms may support the notion of forced roaming and application level roaming (ALR). + ALR implies that the application controls (via migrate(), ignore(), accept() and reject()) + whether a network session can roam from one network configuration to the next. Such control is useful + if the application maintains stateful socket connections and wants to control the transition from + one interface to the next. + + Forced roaming implies that the system automatically roams to the next network without + consulting the application. This has the advantage that the application can make use of roaming features + without actually being aware of it. It is expected that the application detects that the underlying + socket is broken and automatically reconnects via the new network link. + + If the platform supports both modes of roaming an application indicates its preference + by connecting to the preferredConfigurationChanged() signal. Connecting to this signal means that + the application wants to take control over the roaming behavior and therefore implies application + level roaming. + + \sa QNetworkConfiguration, QNetworkConfigurationManager +*/ + +/*! + \enum QNetworkSession::State + + This enum describes the connectivity state of the session. If the session is based on a + single access point configuration the state of the session is the same as the state of the + associated network interface. + + \value Invalid The session is invalid due to an invalid configuration. This may + happen due to a removed access point or a configuration that was + invalid to begin with. + \value NotAvailable The session is based on a defined but not yet discovered QNetworkConfiguration + (see \l QNetworkConfiguration::StateFlag). + \value Connecting The network session is being established. + \value Connected The network session is connected. If the current process wishes to use this session + it has to register its interest by calling open(). A network session + is considered to be ready for socket operations if it isActive() and connected. + \value Closing The network session is in the process of being shut down. + \value Disconnected The network session is not connected. The associated QNetworkConfiguration + has the state QNetworkConfiguration::Discovered. + \value Roaming The network session is roaming from one access point to another + access point. +*/ + +/*! + \enum QNetworkSession::SessionError + + This enum describes the session errors that can occur. + + \value UnknownSessionError An unidentified error occurred. + \value SessionAbortedError The session was aborted by the user or system. + \value RoamingError The session cannot roam to the new configuration. + \value OperationNotSupportedError The operation is not supported for current configuration. + \value InvalidConfigurationError The operation cannot currently be performed for the + current configuration. +*/ + +/*! + \fn void QNetworkSession::stateChanged(QNetworkSession::State state) + + This signal is emitted whenever the state of the network session changes. + The \a state parameter is the new state. + + \sa state() +*/ + +/*! + \fn void QNetworkSession::error(QNetworkSession::SessionError error) + + This signal is emitted after an error occurred. The \a error parameter + describes the error that occurred. + + \sa error(), errorString() +*/ + +/*! + \fn void QNetworkSession::preferredConfigurationChanged(const QNetworkConfiguration& config, bool isSeamless) + + This signal is emitted when the preferred configuration/access point for the + session changes. Only sessions which are based on service network configurations + may emit this signal. \a config can be used to determine access point specific + details such as proxy settings and \a isSeamless indicates whether roaming will + break the sessions IP address. + + As a consequence to this signal the application may start the roaming process + by calling migrate() or may chose to ignore() the new access point. If the application + doesn't call either of the two functions the session ignores the migration opportunity. + + If the roaming process is non-seamless the IP address will change which means that + a socket becomes invalid. However seamless mobility can ensure that the local IP address + does not change. This is achieved by using a virtual IP address which is bound to the actual + link address. During the roaming process the virtual address is attached to the new link + address. + + Some platforms may support the concept of Forced Roaming and Application Level Roaming (ALR). + Forced roaming implies that the platform may simply roam to a new configuration without + consulting applications. It is up to the application to detect the link layer loss and reestablish + its sockets. In contrast ALR provides the opportunity to prevent the system from roaming. + If this session is based on a configuration that supports roaming the application can choose + whether it wants to be consulted (ALR use case) by connecting to this signal. For as long as this signal + connection remains the session remains registered as a roaming stakeholder; otherwise roaming will + be enforced by the platform. + + \sa migrate(), ignore(), QNetworkConfiguration::isRoamingAvailable() +*/ + +/*! + \fn void QNetworkSession::newConfigurationActivated() + + This signal is emitted once the session has roamed to the new access point. + The application may reopen its socket and test the suitability of the new network link. + Subsequently it may accept() or reject() the new access point. + + \sa accept(), reject() +*/ + +/*! + \fn void QNetworkSession::opened() + + This signal is emitted when the network session has been opened. + + The underlying network interface will not be shut down as long as the session remains open. + Note that this feature is dependent on \l{QNetworkConfigurationManager::SystemSessionSupport}{system wide session support}. +*/ + +/*! + \fn void QNetworkSession::closed() + + This signal is emitted when the network session has been closed. +*/ + +/*! + Constructs a session based on \a connectionConfig with the given \a parent. + + \sa QNetworkConfiguration +*/ +QNetworkSession::QNetworkSession(const QNetworkConfiguration& connectionConfig, QObject* parent) + : QObject(parent) +{ + d = new QNetworkSessionPrivate; + d->q = this; + d->publicConfig = connectionConfig; + d->syncStateWithInterface(); + QObject::connect(d, SIGNAL(quitPendingWaitsForOpened()), + this, SIGNAL(opened())); +} + +/*! + Frees the resources associated with the QNetworkSession object. +*/ +QNetworkSession::~QNetworkSession() +{ + delete d; +} + +/*! + Creates an active/open session which increases the session counter on the underlying network interface. + The system will not terminate a network interface until the session reference counter reaches zero. + Therefore an active session allows an application to register its use of the interface. + + The interface is started if it is not active yet. Some platforms may not provide support + for out-of-process sessions. On such platforms the session counter ignores any sessions + held by another process. The platform capabilities can be + detected via QNetworkConfigurationManager::capabilities(). + + Note that this call is asynchronous. Depending on the outcome of this call the results can be enquired + by connecting to the stateChanged(), opened() or error() signals. + + It is not a requirement to open a session in order to monitor the underlying network interface. + + \sa close(), stop(), isActive() +*/ +void QNetworkSession::open() +{ + d->open(); +} + +/*! + Waits until the session has been opened, up to \a msecs milliseconds. If the session has been opened, this + function returns true; otherwise it returns false. In the case where it returns false, you can call error() + to determine the cause of the error. + + The following example waits up to one second for the session to be opened: + + \code + session->open(); + if (session->waitForOpened(1000)) + qDebug("Open!"); + \endcode + + If \a msecs is -1, this function will not time out. + + \sa open(), error() +*/ +bool QNetworkSession::waitForOpened(int msecs) +{ + if (d->isActive) + return true; + + if (d->state != Connecting) + return false; + + QEventLoop* loop = new QEventLoop(this); + QObject::connect(d, SIGNAL(quitPendingWaitsForOpened()), + loop, SLOT(quit())); + + //final call + if (msecs>=0) + QTimer::singleShot(msecs, loop, SLOT(quit())); + + loop->exec(); + loop->disconnect(); + loop->deleteLater(); + + return d->isActive; +} + +/*! + Decreases the session counter on the associated network configuration. If the session counter reaches zero + the active network interface is shut down. This also means that state() will only change from \l Connected to + \l Disconnected if this was the last active session. + + If the platform does not support out-of-process sessions calling this function does not stop the + interface. In this case \l{stop()} has to be used to force a shut down. + The platform capabilities can be detected via QNetworkConfigurationManager::capabilities(). + + Note that this call is asynchronous. Depending on the outcome of this call the results can be enquired + by connecting to the stateChanged(), opened() or error() signals. + + \sa open(), stop(), isActive() +*/ +void QNetworkSession::close() +{ + d->close(); +} + +/*! + Invalidates all active sessions against the network interface and therefore stops the + underlying network interface. This function always changes the session's state() flag to + \l Disconnected. + + \sa open(), close() +*/ +void QNetworkSession::stop() +{ + d->stop(); +} + +/*! + Returns the QNetworkConfiguration that this network session object is based on. + + \sa QNetworkConfiguration +*/ +QNetworkConfiguration QNetworkSession::configuration() const +{ + return d->publicConfig; +} + +/*! + Returns the type of bearer currently used by this session. The string is not translated and therefore can + not be shown to the user. The subsequent table presents the currently known bearer types: + + \table + \header + \o Value + \o Description + \row + \o Ethernet + \o The session is based on Ethernet. + \row + \o WLAN + \o The session is based on Wireless LAN. + \row + \o 2G + \o The session uses CSD, GPRS, HSCSD, EDGE or cdmaOne. + \row + \o CDMA2000 + \o The session uses CDMA. + \row + \o WCDMA + \o The session uses W-CDMA/UMTS. + \row + \o HSPA + \o The session uses High Speed Packet Access. + \row + \o Bluetooth + \o The session uses Bluetooth. + \row + \o WiMAX + \o The session uses WiMAX. + \endtable + + If the session is based on a network configuration of type + \l QNetworkConfiguration::ServiceNetwork the type of the preferred or currently + active configuration is returned. Therefore the bearer type may change + over time. + + This function returns an empty string if this session is based on an invalid configuration. +*/ +QString QNetworkSession::bearerName() const +{ + return d->bearerName(); +} + +/*! + Returns the network interface that is used by this session. + + This function only returns a valid QNetworkInterface when this session is \l Connected. + + The returned interface may change as a result of a roaming process. + + \sa state() +*/ +QNetworkInterface QNetworkSession::interface() const +{ + return d->currentInterface(); +} + +/*! + Returns true if this object holds an active session on the underlying network interface. + The session can be controlled via open() and close(). +*/ +bool QNetworkSession::isActive() const +{ + return d->isActive; +} + +/*! + Returns the state of the session. If the session is based on a + single access point configuration the state of the session is the same as the state of the + associated network interface. Therefore a network session object can be used to monitor + network interfaces. + + A \l QNetworkConfiguration::ServiceNetwork based session summarizes the state of all its children + and therefore returns the \l Connected state if at least one of its sub configurations is connected. + + Note that it is not required to hold an active session in order to obtain the network interface state. + A connected but inactive session may be used to monitor network interfaces whereas an active and connected + session object may prevent the network interface from being shut down. + + \sa error(), stateChanged() +*/ +QNetworkSession::State QNetworkSession::state() const +{ + return d->state; +} + +/*! + Returns the type of error that last occurred. + + \sa state(), errorString() +*/ +QNetworkSession::SessionError QNetworkSession::error() const +{ + return d->error(); +} + +/*! + Returns a human-readable description of the last device error that + occurred. + + \sa error() +*/ +QString QNetworkSession::errorString() const +{ + return d->errorString(); +} + +/*! + Returns the value for property \a key. + + A network session can have properties attached which may describe the session in more details. + This function can be used to gain access to those properties. + + The following property keys are guaranteed to be specified on all platforms: + + \table + \header + \o Key \o Description + \row + \o ActiveConfigurationIdentifier + \o If the session \l isActive() this property returns the identifier of the + QNetworkConfiguration that is used by this session; otherwise an empty string. + + The main purpose of this key is to determine which Internet access point is used + if the session is based on a \l{QNetworkConfiguration::ServiceNetwork}{ServiceNetwork}. + The following code snippet highlights the difference: + \code + QNetworkConfigurationManager mgr; + QNetworkConfiguration ap = mgr.defaultConfiguration(); + QNetworkSession* session = new QNetworkSession(ap); + ... //code activates session + + QString ident = session->sessionProperty("ActiveConfigurationIdentifier").toString(); + if ( ap.type() == QNetworkConfiguration::ServiceNetwork ) { + Q_ASSERT( ap.identifier() != ident ); + Q_ASSERT( ap.children().contains( mgr.configurationFromIdentifier(ident) ) ); + } else if ( ap.type() == QNetworkConfiguration::InternetAccessPoint ) { + Q_ASSERT( ap.identifier() == ident ); + } + \endcode + \row + \o UserChoiceConfigurationIdentifier + \o If the session \l isActive() and is bound to a QNetworkConfiguration of type + UserChoice, this property returns the identifier of the QNetworkConfiguration that the + configuration resolved to when \l open() was called; otherwise an empty string. + + The purpose of this key is to determine the real QNetworkConfiguration that the + session is using. This key is different to \i ActiveConfigurationIdentifier in that + this key may return an identifier for either a + \l {QNetworkConfiguration::ServiceNetwork}{service network} or a + \l {QNetworkConfiguration::InternetAccessPoint}{Internet access points} configurations + whereas \i ActiveConfigurationIdentifier always returns identifiers for + \l {QNetworkConfiguration::InternetAccessPoint}{Internet access points} configurations. + \row + \o ConnectInBackground + \o Setting this property to \i true before calling \l open() implies that the connection attempt + is made but if no connection can be established, the user is not connsulted and asked to select + a suitable connection. This property is not set by default and support for it depends on the platform. + \endtable +*/ +QVariant QNetworkSession::sessionProperty(const QString& key) const +{ + if (!d->publicConfig.isValid()) + return QVariant(); + + if (key == "ActiveConfigurationIdentifier") { + if (!d->isActive) + return QString(); + else + return d->activeConfig.identifier(); + } + + if (key == "UserChoiceConfigurationIdentifier") { + if (!d->isActive || d->publicConfig.type() != QNetworkConfiguration::UserChoice) + return QString(); + + if (d->serviceConfig.isValid()) + return d->serviceConfig.identifier(); + else + return d->activeConfig.identifier(); + } + + return d->sessionProperty(key); +} + +/*! + Sets the property \a value on the session. The property is identified using + \a key. Removing an already set property can be achieved by passing an + invalid QVariant. + + Note that the \i UserChoiceConfigurationIdentifier and \i ActiveConfigurationIdentifier + properties are read only and cannot be changed using this method. +*/ +void QNetworkSession::setSessionProperty(const QString& key, const QVariant& value) +{ + if (key == "ActiveConfigurationIdentifier" + || key == "UserChoiceConfigurationIdentifier") + return; + + d->setSessionProperty(key, value); +} + +/*! + Instructs the session to roam to the new access point. The old access point remains active + until the application calls accept(). + + The newConfigurationActivated() signal is emitted once roaming has been completed. + + \sa accept() +*/ +void QNetworkSession::migrate() +{ + d->migrate(); +} + +/*! + This function indicates that the application does not wish to roam the session. This + is the default behavior if an application doesn't call migrate() in response to a + preferredConfigurationChanged() signal. + + \sa migrate() +*/ +void QNetworkSession::ignore() +{ + //TODO Do we really need this function if we consider that this is + // the default behavior if nobody calls migrate()? + d->ignore(); +} + +/*! + Instructs the session to permanently accept the new access point. Once this function + has been called the session may not return to the old access point. + + The old access point may be closed in the process if there are no other network sessions for it. + Therefore any open socket that still uses the old access point + may become unusable and should be closed before completing the migration. +*/ +void QNetworkSession::accept() +{ + d->accept(); +} + +/*! + The new access point is not suitable for the application. By calling this function the + session returns to the previous access point/configuration. This action may invalidate + any socket that has been created via the not desired access point. + + \sa accept() +*/ +void QNetworkSession::reject() +{ + d->reject(); +} + + +/*! + Returns the amount of data sent in bytes; otherwise 0. + + This field value includes the usage across all active network + sessions which use the same network interface. + + If the session is based on a service network configuration the number of + sent bytes across all active member configurations are returned. + + This function may not always be supported on all platforms and returns + 0. The platform capability can be detected via QNetworkConfigurationManager::DataStatistics. +*/ +quint64 QNetworkSession::bytesWritten() const +{ + return d->bytesWritten(); +} + +/*! + Returns the amount of data received in bytes; otherwise 0. + + This field value includes the usage across all active network + sessions which use the same network interface. + + If the session is based on a service network configuration the number of + sent bytes across all active member configurations are returned. + + This function may not always be supported on all platforms and returns + 0. The platform capability can be detected via QNetworkConfigurationManager::DataStatistics. +*/ +quint64 QNetworkSession::bytesReceived() const +{ + return d->bytesReceived(); +} + +/*! + Returns the number of seconds that the session has been active. +*/ +quint64 QNetworkSession::activeTime() const +{ + return d->activeTime(); +} + +/*! + \internal + + This function is required to detect whether the client wants to control + the roaming process. If he connects to preferredConfigurationChanged() signal + he intends to influence it. Otherwise QNetworkSession always roams + without registering this session as a stakeholder in the roaming process. + + For more details check the Forced vs ALR roaming section in the QNetworkSession + class description. +*/ +void QNetworkSession::connectNotify(const char *signal) +{ + QObject::connectNotify(signal); + //check for preferredConfigurationChanged() signal connect notification + //This is not required on all platforms +#ifdef Q_OS_SYMBIAN + if (qstrcmp(signal, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool))) == 0) { + d->setALREnabled(true); + } +#endif +} + +/*! + \internal + + This function is called when the client disconnects from the preferredConfigurationChanged() + signal. + + \sa connectNotify() +*/ +void QNetworkSession::disconnectNotify(const char *signal) +{ + QObject::disconnectNotify(signal); + //check for preferredConfigurationChanged() signal disconnect notification + //This is not required on all platforms +#ifdef Q_OS_SYMBIAN + if (qstrcmp(signal, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool))) == 0) { + d->setALREnabled(false); + } +#endif +} + +#include "moc_qnetworksession.cpp" + +QTM_END_NAMESPACE diff --git a/src/network/bearer/qnetworksession.h b/src/network/bearer/qnetworksession.h new file mode 100644 index 0000000..47377c4 --- /dev/null +++ b/src/network/bearer/qnetworksession.h @@ -0,0 +1,135 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 QNETWORKSESSION_H +#define QNETWORKSESSION_H + +#include "qmobilityglobal.h" + +#include +#include +#include +#include +#include +#include "qnetworkconfiguration.h" + + +QT_BEGIN_HEADER + +QTM_BEGIN_NAMESPACE + +class QNetworkSessionPrivate; +class Q_BEARER_EXPORT QNetworkSession : public QObject +{ + Q_OBJECT +public: + enum State { + Invalid = 0, + NotAvailable, + Connecting, + Connected, + Closing, + Disconnected, + Roaming + }; + + enum SessionError { + UnknownSessionError = 0, + SessionAbortedError, + RoamingError, + OperationNotSupportedError, + InvalidConfigurationError + }; + + QNetworkSession(const QNetworkConfiguration& connConfig, QObject* parent =0); + virtual ~QNetworkSession(); + + bool isActive() const; + QNetworkConfiguration configuration() const; + QString bearerName() const; + QNetworkInterface interface() const; + + State state() const; + SessionError error() const; + QString errorString() const; + QVariant sessionProperty(const QString& key) const; + void setSessionProperty(const QString& key, const QVariant& value); + + quint64 bytesWritten() const; + quint64 bytesReceived() const; + quint64 activeTime() const; + + bool waitForOpened(int msecs = 30000); + +public Q_SLOTS: + void open(); + void close(); + void stop(); + + //roaming related slots + void migrate(); + void ignore(); + void accept(); + void reject(); + + +Q_SIGNALS: + void stateChanged(QNetworkSession::State); + void opened(); + void closed(); + void error(QNetworkSession::SessionError); + void preferredConfigurationChanged(const QNetworkConfiguration& config, bool isSeamless); + void newConfigurationActivated(); + +protected: + virtual void connectNotify(const char *signal); + virtual void disconnectNotify(const char *signal); + +private: + QNetworkSessionPrivate* d; + friend class QNetworkSessionPrivate; + }; + +QTM_END_NAMESPACE + +QT_END_HEADER + +#endif //QNETWORKSESSION_H diff --git a/src/network/bearer/qnetworksession_maemo.cpp b/src/network/bearer/qnetworksession_maemo.cpp new file mode 100644 index 0000000..c7c7a31 --- /dev/null +++ b/src/network/bearer/qnetworksession_maemo.cpp @@ -0,0 +1,1181 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 + +#include "qnetworksession_maemo_p.h" +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +QTM_BEGIN_NAMESPACE + +static QHash properties; + +static QString get_network_interface(); +static DBusConnection *dbus_connection; +static DBusHandlerResult signal_handler(DBusConnection *connection, + DBusMessage *message, + void *user_data); + +#define ICD_DBUS_MATCH "type='signal'," \ + "interface='" ICD_DBUS_INTERFACE "'," \ + "path='" ICD_DBUS_PATH "'" + + +static inline DBusConnection *get_dbus_conn(DBusError *error) +{ + DBusConnection *conn = dbus_bus_get(DBUS_BUS_SYSTEM, error); +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Listening to bus" << dbus_bus_get_unique_name(conn); +#endif + + return conn; +} + + +/* Helper class that monitors the Icd status messages and + * can change the IAP status accordingly. This is a singleton. + */ +class IcdListener : public QObject +{ + Q_OBJECT + +public: + IcdListener() : first_call(true) { } + friend DBusHandlerResult signal_handler(DBusConnection *connection, + DBusMessage *message, + void *user_data); + void setup(QNetworkSessionPrivate *d); + void cleanup(); + void cleanupSession(QNetworkSessionPrivate *ptr); + + enum IapConnectionStatus { + /* The IAP was connected */ + CONNECTED = 0, + /* The IAP was disconnected */ + DISCONNECTED, + /* The IAP is disconnecting */ + DISCONNECTING, + /* The IAP has a network address, but is not yet fully connected */ + NETWORK_UP + }; + +private: + void icdSignalReceived(QString&, QString&, QString&); + bool first_call; + QHash sessions; +}; + +Q_GLOBAL_STATIC(IcdListener, icdListener); + + +static DBusHandlerResult signal_handler(DBusConnection *, + DBusMessage *message, + void *user_data) +{ + if (dbus_message_is_signal(message, + ICD_DBUS_INTERFACE, + ICD_STATUS_CHANGED_SIG)) { + + IcdListener *icd = (IcdListener *)user_data; + DBusError error; + dbus_error_init(&error); + + char *iap_id = 0; + char *network_type = 0; + char *state = 0; + + if (dbus_message_get_args(message, &error, + DBUS_TYPE_STRING, &iap_id, + DBUS_TYPE_STRING, &network_type, + DBUS_TYPE_STRING, &state, + DBUS_TYPE_INVALID) == FALSE) { + qWarning() << QString("Failed to parse icd status signal: %1").arg(error.message); + } else { + QString _iap_id(iap_id); + QString _network_type(network_type); + QString _state(state); + + icd->icdSignalReceived(_iap_id, _network_type, _state); + } + + dbus_error_free(&error); + return DBUS_HANDLER_RESULT_HANDLED; + } + + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + + +void IcdListener::setup(QNetworkSessionPrivate *d) +{ + if (first_call) { + // We use the old Icd dbus interface like in ConIC + DBusError error; + dbus_error_init(&error); + + dbus_connection = get_dbus_conn(&error); + if (dbus_error_is_set(&error)) { + qWarning() << "Cannot get dbus connection."; + dbus_error_free(&error); + return; + } + + static struct DBusObjectPathVTable icd_vtable; + icd_vtable.message_function = signal_handler; + + dbus_bus_add_match(dbus_connection, ICD_DBUS_MATCH, &error); + if (dbus_error_is_set(&error)) { + qWarning() << "Cannot add match" << ICD_DBUS_MATCH; + dbus_error_free(&error); + return; + } + + if (dbus_connection_register_object_path(dbus_connection, + ICD_DBUS_PATH, + &icd_vtable, + (void*)this) == FALSE) { + qWarning() << "Cannot register dbus signal handler, interface"<< ICD_DBUS_INTERFACE << "path" << ICD_DBUS_PATH; + dbus_error_free(&error); + return; + } + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Listening" << ICD_STATUS_CHANGED_SIG << "signal from" << ICD_DBUS_SERVICE; +#endif + first_call = false; + dbus_error_free(&error); + } + + QString id = d->activeConfig.identifier(); + if (!sessions.contains(id)) { + QNetworkSessionPrivate *ptr = d; + sessions.insert(id, ptr); + } +} + + +void IcdListener::icdSignalReceived(QString& iap_id, +#ifdef BEARER_MANAGEMENT_DEBUG + QString& network_type, +#else + QString&, +#endif + QString& state) +{ + if (iap_id == OSSO_IAP_SCAN) // icd sends scan status signals which we will ignore + return; + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Status received:" << iap_id << "type" << network_type << "state" << state; +#endif + + if (!sessions.contains(iap_id)) { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "No session for IAP" << iap_id; +#endif + return; + } + + QNetworkSessionPrivate *session = sessions.value(iap_id); + QNetworkConfiguration ap_conf = session->manager.configurationFromIdentifier(iap_id); + if (!ap_conf.isValid()) { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Unknown IAP" << iap_id; +#endif + return; + } + + IapConnectionStatus status; + + if (state == "IDLE") { + status = DISCONNECTED; + } else if (state == "CONNECTED") { + status = CONNECTED; + } else if (state == "NETWORKUP") { + status = NETWORK_UP; + } else { + //qDebug() << "Unknown state" << state; + return; + } + + if (status == DISCONNECTED) { + if (ap_conf.state() == QNetworkConfiguration::Active) { + /* The IAP was just disconnected by Icd */ + session->updateState(QNetworkSession::Disconnected); + } else { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Got a network disconnect when in state" << ap_conf.state(); +#endif + } + } else if (status == CONNECTED) { + /* The IAP was just connected by Icd */ + session->updateState(QNetworkSession::Connected); + session->updateIdentifier(iap_id); + + if (session->publicConfig.identifier() == OSSO_IAP_ANY) { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "IAP" << iap_id << "connected when connecting to" << OSSO_IAP_ANY; +#endif + } else { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "IAP" << iap_id << "connected"; +#endif + } + } + + return; +} + + +void IcdListener::cleanup() +{ + if (!first_call) { + dbus_bus_remove_match(dbus_connection, ICD_DBUS_MATCH, NULL); + dbus_connection_unref(dbus_connection); + } +} + + +void IcdListener::cleanupSession(QNetworkSessionPrivate *ptr) +{ + if (ptr->publicConfig.type() == QNetworkConfiguration::UserChoice) + (void)sessions.take(ptr->activeConfig.identifier()); + else + (void)sessions.take(ptr->publicConfig.identifier()); +} + + +void QNetworkSessionPrivate::cleanupSession(void) +{ + icdListener()->cleanupSession(this); +} + + +void QNetworkSessionPrivate::updateState(QNetworkSession::State newState) +{ + if( newState != state) { + state = newState; + + if (state == QNetworkSession::Disconnected) { + isActive = false; + currentNetworkInterface.clear(); + if (publicConfig.type() == QNetworkConfiguration::UserChoice) + activeConfig.d->state = QNetworkConfiguration::Defined; + publicConfig.d->state = QNetworkConfiguration::Defined; + + } else if (state == QNetworkSession::Connected) { + isActive = true; + if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + activeConfig.d->state = QNetworkConfiguration::Active; + activeConfig.d->type = QNetworkConfiguration::InternetAccessPoint; + } + publicConfig.d->state = QNetworkConfiguration::Active; + } + + emit q->stateChanged(newState); + } +} + + +void QNetworkSessionPrivate::updateIdentifier(QString &newId) +{ + if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + activeConfig.d->network_attrs |= ICD_NW_ATTR_IAPNAME; + activeConfig.d->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; + } + } +} + + +quint64 QNetworkSessionPrivate::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 + * necessary. + */ + Maemo::Icd icd; + QList stats_results; + quint64 counter_rx = 0, counter_tx = 0; + + if (!icd.statistics(stats_results)) { + return 0; + } + + foreach (Maemo::IcdStatisticsResult res, stats_results) { + if (res.params.network_attrs & ICD_NW_ATTR_IAPNAME) { + /* network_id is the IAP UUID */ + if (QString(res.params.network_id.data()) == activeConfig.identifier()) { + counter_tx = res.bytes_sent; + counter_rx = res.bytes_received; + } + } else { + /* We probably will never get to this branch */ + QNetworkConfigurationPrivate *d = activeConfig.d.data(); + if (res.params.network_id == d->network_id) { + counter_tx = res.bytes_sent; + counter_rx = res.bytes_received; + } + } + } + + if (sent) + return counter_tx; + else + return counter_rx; +} + + +quint64 QNetworkSessionPrivate::bytesWritten() const +{ + return getStatistics(true); +} + +quint64 QNetworkSessionPrivate::bytesReceived() const +{ + return getStatistics(false); +} + +quint64 QNetworkSessionPrivate::activeTime() const +{ + if (startTime.isNull()) { + return 0; + } + return startTime.secsTo(QDateTime::currentDateTime()); +} + + +QNetworkConfiguration& QNetworkSessionPrivate::copyConfig(QNetworkConfiguration &fromConfig, QNetworkConfiguration &toConfig, bool deepCopy) +{ + if (deepCopy) { + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + QExplicitlySharedDataPointer ptr(cpPriv); + toConfig.d = ptr; + } + + toConfig.d->name = fromConfig.d->name; + toConfig.d->isValid = fromConfig.d->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; + + return toConfig; +} + + +/* This is called by QNetworkSession constructor and it updates the current + * state of the configuration. + */ +void QNetworkSessionPrivate::syncStateWithInterface() +{ + /* Start to listen Icd status messages. */ + icdListener()->setup(this); + + /* Initially we are not active although the configuration might be in + * connected state. + */ + isActive = false; + opened = false; + + QObject::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; + } + } + + state = QNetworkSession::Invalid; + lastError = QNetworkSession::UnknownSessionError; + + switch (publicConfig.type()) { + case QNetworkConfiguration::InternetAccessPoint: + activeConfig = publicConfig; + break; + case QNetworkConfiguration::ServiceNetwork: + serviceConfig = publicConfig; + break; + case QNetworkConfiguration::UserChoice: + // active config will contain correct data after open() has succeeded + copyConfig(publicConfig, activeConfig); + + /* We create new configuration that holds the actual configuration + * returned by icd. This way publicConfig still contains the + * original user specified configuration. + * + * Note that the new activeConfig configuration is not inserted + * to configurationManager as manager class will get the newly + * connected configuration from gconf when the IAP is saved. + * This configuration manager update is done by IapMonitor class. + * If the ANY connection fails in open(), then the configuration + * data is not saved to gconf and will not be added to + * configuration manager IAP list. + */ +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug()<<"New configuration created for" << publicConfig.identifier(); +#endif + break; + default: + /* Invalid configuration, no point continuing */ + return; + } + + if (!activeConfig.isValid()) + return; + + /* Get the initial state from icd */ + Maemo::Icd icd; + QList state_results; + + /* Update the active config from first connection, this is ok as icd + * supports only one connection anyway. + */ + if (icd.state(state_results) && !state_results.isEmpty()) { + + /* If we did not get full state back, then we are not + * connected and can skip the next part. + */ + if (!(state_results.first().params.network_attrs == 0 && + state_results.first().params.network_id.isEmpty())) { + + /* If we try to connect to specific IAP and we get results back + * that tell the icd is actually connected to another IAP, + * then do not update current state etc. + */ + if (publicConfig.type() == QNetworkConfiguration::UserChoice || + publicConfig.d->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; + break; + case ICD_STATE_CONNECTING: + state = QNetworkSession::Connecting; + if (activeConfig.d.data()) + activeConfig.d->isValid = true; + break; + case ICD_STATE_CONNECTED: + { + if (!state_results.first().error.isEmpty()) + break; + + 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 priv = mgr->accessPointConfigurations.value(activeConfig.d->id); + activeConfig.d = priv; + } + + + 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; + currentNetworkInterface = get_network_interface(); + + Maemo::IAPConf iap_name(activeConfig.d->id); + QString name_value = iap_name.value("name").toString(); + if (!name_value.isEmpty()) + activeConfig.d->name = name_value; + else + activeConfig.d->name = activeConfig.d->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 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"<id<<"added to manager in sync"; +#endif + + } else { + mgr->configurationChanged((QNetworkConfigurationPrivate*)(activeConfig.d.data())); +#ifdef BEARER_MANAGEMENT_DEBUG + //qDebug()<<"Existing configuration"<id<<"updated in manager in sync"; +#endif + } + + } + break; + + case ICD_STATE_DISCONNECTING: + state = QNetworkSession::Closing; + if (activeConfig.d.data()) + activeConfig.d->isValid = true; + break; + default: + break; + } + } + } else { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "status_req tells icd is not connected"; +#endif + } + } else { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "status_req did not return any results from icd"; +#endif + } + + networkConfigurationsChanged(); +} + + +void QNetworkSessionPrivate::networkConfigurationsChanged() +{ + if (serviceConfig.isValid()) + updateStateFromServiceNetwork(); + else + updateStateFromActiveConfig(); +} + + +void QNetworkSessionPrivate::updateStateFromServiceNetwork() +{ + QNetworkSession::State oldState = state; + + foreach (const QNetworkConfiguration &config, serviceConfig.children()) { + if ((config.state() & QNetworkConfiguration::Active) != QNetworkConfiguration::Active) + continue; + + if (activeConfig != config) { + activeConfig = config; + emit q->newConfigurationActivated(); + } + + state = QNetworkSession::Connected; + if (state != oldState) + emit q->stateChanged(state); + + return; + } + + if (serviceConfig.children().isEmpty()) + state = QNetworkSession::NotAvailable; + else + state = QNetworkSession::Disconnected; + + if (state != oldState) + emit q->stateChanged(state); +} + + +void QNetworkSessionPrivate::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; +} + + +void QNetworkSessionPrivate::updateStateFromActiveConfig() +{ + QNetworkSession::State oldState = state; + + bool newActive = false; + + if (!activeConfig.d.data()) + return; + + if (!activeConfig.isValid()) { + state = QNetworkSession::Invalid; + clearConfiguration(activeConfig); + } else if ((activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + state = QNetworkSession::Connected; + newActive = opened; + } else if ((activeConfig.state() & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) { + state = QNetworkSession::Disconnected; + } else if ((activeConfig.state() & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) { + state = QNetworkSession::NotAvailable; + } else if ((activeConfig.state() & QNetworkConfiguration::Undefined) == QNetworkConfiguration::Undefined) { + state = QNetworkSession::NotAvailable; + clearConfiguration(activeConfig); + } + + bool oldActive = isActive; + isActive = newActive; + + if (!oldActive && isActive) + emit quitPendingWaitsForOpened(); + + if (oldActive && !isActive) + emit q->closed(); + + if (oldState != state) { + emit q->stateChanged(state); + + if (state == QNetworkSession::Disconnected) { +#ifdef BEARER_MANAGEMENT_DEBUG + //qDebug()<<"session aborted error emitted for"<error(lastError); + } + } + +#ifdef BEARER_MANAGEMENT_DEBUG + //qDebug()<<"oldState ="<ifa_next) { + family = ifa->ifa_addr->sa_family; + if (family != AF_INET) { + continue; /* Currently only IPv4 is supported by icd dbus interface */ + } + if (((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr == addr.s_addr) { + iface = QString(ifa->ifa_name); + break; + } + } + + freeifaddrs(ifaddr); + return iface; +} + + +void QNetworkSessionPrivate::open() +{ + if (serviceConfig.isValid()) { + lastError = QNetworkSession::OperationNotSupportedError; + emit q->error(lastError); + } else if (!isActive) { + + if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + /* Caller is trying to connect to default IAP. + * At this time we will not know the IAP details so we just + * connect and update the active config when the IAP is + * connected. + */ + opened = true; + state = QNetworkSession::Connecting; + emit q->stateChanged(state); + QTimer::singleShot(0, this, SLOT(do_open())); + return; + } + + /* User is connecting to one specific IAP. If that IAP is not + * in discovered state we cannot continue. + */ + if ((activeConfig.state() & QNetworkConfiguration::Discovered) != + QNetworkConfiguration::Discovered) { + lastError =QNetworkSession::InvalidConfigurationError; + emit q->error(lastError); + return; + } + opened = true; + + if ((activeConfig.state() & QNetworkConfiguration::Active) != QNetworkConfiguration::Active) { + state = QNetworkSession::Connecting; + emit q->stateChanged(state); + + QTimer::singleShot(0, this, SLOT(do_open())); + return; + } + + isActive = (activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active; + if (isActive) + emit quitPendingWaitsForOpened(); + } else { + /* We seem to be active so inform caller */ + emit quitPendingWaitsForOpened(); + } +} + + +void QNetworkSessionPrivate::do_open() +{ + icd_connection_flags flags = connectFlags; + bool st; + QString result; + QString iap = publicConfig.identifier(); + QString bearer_name; + + if (state == QNetworkSession::Connected) { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Already connected to" << activeConfig.identifier(); +#endif + emit q->stateChanged(QNetworkSession::Connected); + emit quitPendingWaitsForOpened(); + return; + } + + Maemo::IcdConnectResult connect_result; + Maemo::Icd icd(ICD_LONG_CONNECT_TIMEOUT); + QNetworkConfiguration config; + if (publicConfig.type() == QNetworkConfiguration::UserChoice) + config = activeConfig; + else + config = publicConfig; + + if (iap == OSSO_IAP_ANY) { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "connecting to default IAP" << iap; +#endif + st = icd.connect(flags, connect_result); + + } else { + + QList 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.network_id = QByteArray(iap.toLatin1()); + else + param.connect.network_id = config.d->network_id; + params.append(param); + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug("connecting to %s/%s/0x%x/%s/0x%x/%s", + param.connect.network_id.data(), + param.connect.network_type.toAscii().constData(), + param.connect.network_attrs, + param.connect.service_type.toAscii().constData(), + param.connect.service_attrs, + param.connect.service_id.toAscii().constData()); +#endif + st = icd.connect(flags, params, connect_result); + } + + if (st) { + result = connect_result.connect.network_id.data(); + QString connected_iap = result; + + if (connected_iap.isEmpty()) { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "connect to"<< iap << "failed, result is empty"; +#endif + updateState(QNetworkSession::Disconnected); + emit quitPendingWaitsForOpened(); + emit q->error(QNetworkSession::InvalidConfigurationError); + if (publicConfig.type() == QNetworkConfiguration::UserChoice) + cleanupAnyConfiguration(); + return; + } + + /* If the user tried to connect to some specific connection (foo) + * and we were already connected to some other connection (bar), + * then we cannot activate this session although icd has a valid + * connection to somewhere. + */ + if ((publicConfig.type() != QNetworkConfiguration::UserChoice) && + (connected_iap != config.identifier())) { + updateState(QNetworkSession::Disconnected); + emit quitPendingWaitsForOpened(); + emit q->error(QNetworkSession::InvalidConfigurationError); + return; + } + + + /* Did we connect to non saved IAP? */ + if (!(config.d->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; + } + + /* User might have changed the IAP name when a new IAP was saved */ + Maemo::IAPConf iap_name(config.d->id); + QString name = iap_name.value("name").toString(); + if (!name.isEmpty()) + config.d->name = name; + + bearer_name = connect_result.connect.network_type; + if (bearer_name == "WLAN_INFRA" || + bearer_name == "WLAN_ADHOC") + currentBearerName = "WLAN"; + else if (bearer_name == "GPRS") + currentBearerName = "HSPA"; + else + currentBearerName = bearer_name; + + config.d->isValid = true; + config.d->state = QNetworkConfiguration::Active; + config.d->type = QNetworkConfiguration::InternetAccessPoint; + + startTime = QDateTime::currentDateTime(); + updateState(QNetworkSession::Connected); + + currentNetworkInterface = get_network_interface(); + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "connected to" << result << config.d->name << "at" << currentNetworkInterface; +#endif + + /* We first check if the configuration already exists in the manager + * and if it is not found there, we then insert it. Note that this + * is only done for user choice config only because it can be missing + * from config manager list. + */ + + if (publicConfig.d->type == QNetworkConfiguration::UserChoice) { + +#ifdef BEARER_MANAGEMENT_DEBUG +#if 0 + QList configs; + QNetworkConfigurationManagerPrivate *conPriv = (QNetworkConfigurationManagerPrivate*)config.d.data()->manager; + QList cpsIdents = conPriv->accessPointConfigurations.keys(); + foreach( QString ii, cpsIdents) { + QExplicitlySharedDataPointer 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.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 ptr = config.d; + mgr->accessPointConfigurations.insert(result, ptr); + + QNetworkConfiguration item; + item.d = ptr; + emit mgr->configurationAdded(item); + +#ifdef BEARER_MANAGEMENT_DEBUG + //qDebug()<<"New configuration"< 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"<error(QNetworkSession::UnknownSessionError); + } +} + + +void QNetworkSessionPrivate::cleanupAnyConfiguration() +{ +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug()<<"Removing configuration created for" << activeConfig.d->id; +#endif + activeConfig = publicConfig; +} + + +void QNetworkSessionPrivate::close() +{ + if (serviceConfig.isValid()) { + lastError = QNetworkSession::OperationNotSupportedError; + emit q->error(lastError); + } else if (isActive) { + opened = false; + isActive = false; + emit q->closed(); + } +} + + +void QNetworkSessionPrivate::stop() +{ + if (serviceConfig.isValid()) { + lastError = QNetworkSession::OperationNotSupportedError; + emit q->error(lastError); + } else { + if ((activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + state = QNetworkSession::Closing; + emit q->stateChanged(state); + + Maemo::Icd icd; +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "stopping session" << publicConfig.identifier(); +#endif + icd.disconnect(ICD_CONNECTION_FLAG_APPLICATION_EVENT); + startTime = QDateTime(); + + /* Note that the state will go disconnected in + * updateStateFromActiveConfig() which gets called after + * configurationChanged is emitted (below). + */ + + activeConfig.d->state = QNetworkConfiguration::Discovered; + QNetworkConfigurationManagerPrivate *mgr = (QNetworkConfigurationManagerPrivate*)activeConfig.d.data()->manager; + mgr->configurationChanged((QNetworkConfigurationPrivate*)activeConfig.d.data()); + + opened = false; + isActive = false; + + } else { + opened = false; + isActive = false; + emit q->closed(); + } + } +} + + +void QNetworkSessionPrivate::migrate() +{ + qWarning("This platform does not support roaming (%s).", __FUNCTION__); +} + + +void QNetworkSessionPrivate::accept() +{ + qWarning("This platform does not support roaming (%s).", __FUNCTION__); +} + + +void QNetworkSessionPrivate::ignore() +{ + qWarning("This platform does not support roaming (%s).", __FUNCTION__); +} + + +void QNetworkSessionPrivate::reject() +{ + qWarning("This platform does not support roaming (%s).", __FUNCTION__); +} + + +QNetworkInterface QNetworkSessionPrivate::currentInterface() const +{ + if (!publicConfig.isValid() || state != QNetworkSession::Connected) + return QNetworkInterface(); + + if (currentNetworkInterface.isEmpty()) + return QNetworkInterface(); + + return QNetworkInterface::interfaceFromName(currentNetworkInterface); +} + + +void QNetworkSessionPrivate::setSessionProperty(const QString& key, const QVariant& value) +{ + if (value.isValid()) { + properties.insert(key, value); + + if (key == "ConnectInBackground") { + bool v = value.toBool(); + if (v) + connectFlags = ICD_CONNECTION_FLAG_APPLICATION_EVENT; + else + connectFlags = ICD_CONNECTION_FLAG_USER_EVENT; + } + } else { + properties.remove(key); + + /* Set default value when property is removed */ + if (key == "ConnectInBackground") + connectFlags = ICD_CONNECTION_FLAG_USER_EVENT; + } +} + + +QVariant QNetworkSessionPrivate::sessionProperty(const QString& key) const +{ + return properties.value(key); +} + + +QString QNetworkSessionPrivate::bearerName() const +{ + if (!publicConfig.isValid()) + return QString(); + + return currentBearerName; +} + + +QString QNetworkSessionPrivate::errorString() const +{ + QString errorStr; + switch(q->error()) { + case QNetworkSession::RoamingError: + errorStr = QObject::tr("Roaming error"); + break; + case QNetworkSession::SessionAbortedError: + errorStr = QObject::tr("Session aborted by user or system"); + break; + default: + case QNetworkSession::UnknownSessionError: + errorStr = QObject::tr("Unidentified Error"); + break; + } + return errorStr; +} + + +QNetworkSession::SessionError QNetworkSessionPrivate::error() const +{ + return QNetworkSession::UnknownSessionError; +} + +#include "qnetworksession_maemo.moc" +#include "moc_qnetworksession_maemo_p.cpp" + +QTM_END_NAMESPACE diff --git a/src/network/bearer/qnetworksession_maemo_p.h b/src/network/bearer/qnetworksession_maemo_p.h new file mode 100644 index 0000000..e233087 --- /dev/null +++ b/src/network/bearer/qnetworksession_maemo_p.h @@ -0,0 +1,167 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 QNETWORKSESSIONPRIVATE_H +#define QNETWORKSESSIONPRIVATE_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_maemo_p.h" +#include "qnetworksession.h" + +#include +#include +#include + +#include + +QTM_BEGIN_NAMESPACE + +class QNetworkSessionPrivate : public QObject +{ + Q_OBJECT +public: + QNetworkSessionPrivate() : + tx_data(0), rx_data(0), m_activeTime(0), isActive(false), + connectFlags(ICD_CONNECTION_FLAG_USER_EVENT) + { + } + + ~QNetworkSessionPrivate() + { + cleanupSession(); + } + + //called by QNetworkSession constructor and ensures + //that the state is immediately updated (w/o actually opening + //a session). Also this function should take care of + //notification hooks to discover future state changes. + void syncStateWithInterface(); + + QNetworkInterface currentInterface() const; + QVariant sessionProperty(const QString& key) const; + void setSessionProperty(const QString& key, const QVariant& value); + QString bearerName() const; + + void open(); + void close(); + void stop(); + void migrate(); + void accept(); + void ignore(); + void reject(); + + QString errorString() const; //must return translated string + QNetworkSession::SessionError error() const; + + quint64 bytesWritten() const; + quint64 bytesReceived() const; + quint64 activeTime() const; + +private: + void updateStateFromServiceNetwork(); + void updateStateFromActiveConfig(); + +Q_SIGNALS: + //releases any pending waitForOpened() calls + void quitPendingWaitsForOpened(); + +private Q_SLOTS: + void do_open(); + void networkConfigurationsChanged(); + void configurationChanged(const QNetworkConfiguration &config); + +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; + + QNetworkConfiguration& copyConfig(QNetworkConfiguration &fromConfig, QNetworkConfiguration &toConfig, bool deepCopy = true); + void clearConfiguration(QNetworkConfiguration &config); + void cleanupAnyConfiguration(); + + QNetworkSession::State state; + bool isActive; + bool opened; + icd_connection_flags connectFlags; + + QNetworkSession::SessionError lastError; + + QNetworkSession* q; + friend class QNetworkSession; + + QDateTime startTime; + QString currentBearerName; + QString currentNetworkInterface; + friend class IcdListener; + void updateState(QNetworkSession::State); + void updateIdentifier(QString &newId); + quint64 getStatistics(bool sent) const; + void cleanupSession(void); +}; + +QTM_END_NAMESPACE + +#endif //QNETWORKSESSIONPRIVATE_H + diff --git a/src/network/bearer/qnetworksession_p.cpp b/src/network/bearer/qnetworksession_p.cpp new file mode 100644 index 0000000..c6f9833 --- /dev/null +++ b/src/network/bearer/qnetworksession_p.cpp @@ -0,0 +1,542 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 "qnetworksession_p.h" +#include "qnetworksession.h" +#include "qnetworksessionengine_p.h" +#include "qgenericengine_p.h" + +#ifdef Q_OS_WIN +#include "qnlaengine_win_p.h" +#endif +#ifdef Q_OS_WIN32 +#include "qnativewifiengine_win_p.h" +#endif +#ifdef Q_OS_DARWIN +#include "qcorewlanengine_mac_p.h" +#endif +#include +#include +#include + +#include + +#if defined(BACKEND_NM) +#include "qnmwifiengine_unix_p.h" +#endif + +QTM_BEGIN_NAMESPACE + +#if defined(BACKEND_NM) +static bool NetworkManagerAvailable() +{ + QDBusConnection dbusConnection = QDBusConnection::systemBus(); + if (dbusConnection.isConnected()) { + QDBusConnectionInterface *dbiface = dbusConnection.interface(); + QDBusReply reply = dbiface->isServiceRegistered("org.freedesktop.NetworkManager"); + if (reply.isValid()) + return reply.value(); + } + return false; +} +#endif + +static QNetworkSessionEngine *getEngineFromId(const QString &id) +{ +#ifdef Q_OS_WIN + QNlaEngine *nla = QNlaEngine::instance(); + if (nla && nla->hasIdentifier(id)) + return nla; +#endif + +#ifdef Q_OS_WIN32 + QNativeWifiEngine *nativeWifi = QNativeWifiEngine::instance(); + if (nativeWifi && nativeWifi->hasIdentifier(id)) + return nativeWifi; +#endif + +#if defined(BACKEND_NM) + if(NetworkManagerAvailable()) { + QNmWifiEngine *nmwiifi = QNmWifiEngine::instance(); + if (nmwiifi && nmwiifi->hasIdentifier(id)) + return nmwiifi; + } +#endif +#ifdef Q_OS_DARWIN + QCoreWlanEngine *coreWifi = QCoreWlanEngine::instance(); + if (coreWifi && coreWifi->hasIdentifier(id)) + return coreWifi; + +#endif + QGenericEngine *generic = QGenericEngine::instance(); + if (generic && generic->hasIdentifier(id)) + return generic; + + return 0; +} + +class QNetworkSessionManagerPrivate : public QObject +{ + Q_OBJECT + +public: + QNetworkSessionManagerPrivate(QObject *parent = 0); + ~QNetworkSessionManagerPrivate(); + + void forceSessionClose(const QNetworkConfiguration &config); + +Q_SIGNALS: + void forcedSessionClose(const QNetworkConfiguration &config); +}; + +#include "qnetworksession_p.moc" + +Q_GLOBAL_STATIC(QNetworkSessionManagerPrivate, sessionManager); + +QNetworkSessionManagerPrivate::QNetworkSessionManagerPrivate(QObject *parent) +: QObject(parent) +{ +} + +QNetworkSessionManagerPrivate::~QNetworkSessionManagerPrivate() +{ +} + +void QNetworkSessionManagerPrivate::forceSessionClose(const QNetworkConfiguration &config) +{ + emit forcedSessionClose(config); +} + +void QNetworkSessionPrivate::syncStateWithInterface() +{ + connect(&manager, SIGNAL(updateCompleted()), this, SLOT(networkConfigurationsChanged())); + connect(&manager, SIGNAL(configurationChanged(QNetworkConfiguration)), + this, SLOT(configurationChanged(QNetworkConfiguration))); + connect(sessionManager(), SIGNAL(forcedSessionClose(QNetworkConfiguration)), + this, SLOT(forcedSessionClose(QNetworkConfiguration))); + + opened = false; + state = QNetworkSession::Invalid; + lastError = QNetworkSession::UnknownSessionError; + + qRegisterMetaType + ("QNetworkSessionEngine::ConnectionError"); + + switch (publicConfig.type()) { + case QNetworkConfiguration::InternetAccessPoint: + activeConfig = publicConfig; + engine = getEngineFromId(activeConfig.identifier()); + if (engine) { + connect(engine, SIGNAL(connectionError(QString,QNetworkSessionEngine::ConnectionError)), + this, SLOT(connectionError(QString,QNetworkSessionEngine::ConnectionError)), + Qt::QueuedConnection); + } + break; + case QNetworkConfiguration::ServiceNetwork: + serviceConfig = publicConfig; + // Defer setting engine and signals until open(). + // fall through + case QNetworkConfiguration::UserChoice: + // Defer setting serviceConfig and activeConfig until open(). + // fall through + default: + engine = 0; + } + + networkConfigurationsChanged(); +} + +void QNetworkSessionPrivate::open() +{ + if (serviceConfig.isValid()) { + lastError = QNetworkSession::OperationNotSupportedError; + emit q->error(lastError); + } else if (!isActive) { + if ((activeConfig.state() & QNetworkConfiguration::Discovered) != + QNetworkConfiguration::Discovered) { + lastError =QNetworkSession::InvalidConfigurationError; + emit q->error(lastError); + return; + } + opened = true; + + if ((activeConfig.state() & QNetworkConfiguration::Active) != QNetworkConfiguration::Active && + (activeConfig.state() & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) { + state = QNetworkSession::Connecting; + emit q->stateChanged(state); + + engine->connectToId(activeConfig.identifier()); + } + + isActive = (activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active; + if (isActive) + emit quitPendingWaitsForOpened(); + } +} + +void QNetworkSessionPrivate::close() +{ + if (serviceConfig.isValid()) { + lastError = QNetworkSession::OperationNotSupportedError; + emit q->error(lastError); + } else if (isActive) { + opened = false; + isActive = false; + emit q->closed(); + } +} + +void QNetworkSessionPrivate::stop() +{ + if (serviceConfig.isValid()) { + lastError = QNetworkSession::OperationNotSupportedError; + emit q->error(lastError); + } else { + if ((activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + state = QNetworkSession::Closing; + emit q->stateChanged(state); + + engine->disconnectFromId(activeConfig.identifier()); + + sessionManager()->forceSessionClose(activeConfig); + } + + opened = false; + isActive = false; + emit q->closed(); + } +} + +void QNetworkSessionPrivate::migrate() +{ + qWarning("This platform does not support roaming (%s).", __FUNCTION__); +} + +void QNetworkSessionPrivate::accept() +{ + qWarning("This platform does not support roaming (%s).", __FUNCTION__); +} + +void QNetworkSessionPrivate::ignore() +{ + qWarning("This platform does not support roaming (%s).", __FUNCTION__); +} + +void QNetworkSessionPrivate::reject() +{ + qWarning("This platform does not support roaming (%s).", __FUNCTION__); +} + +QNetworkInterface QNetworkSessionPrivate::currentInterface() const +{ + if (!publicConfig.isValid() || !engine || state != QNetworkSession::Connected) + return QNetworkInterface(); + + QString interface = engine->getInterfaceFromId(activeConfig.identifier()); + + if (interface.isEmpty()) + return QNetworkInterface(); + return QNetworkInterface::interfaceFromName(interface); +} + +QVariant QNetworkSessionPrivate::sessionProperty(const QString& /*key*/) const +{ + return QVariant(); +} + +void QNetworkSessionPrivate::setSessionProperty(const QString& /*key*/, const QVariant& /*value*/) +{ +} + +QString QNetworkSessionPrivate::bearerName() const +{ + if (!publicConfig.isValid() || !engine) + return QString(); + + return engine->bearerName(activeConfig.identifier()); +} + +QString QNetworkSessionPrivate::errorString() const +{ + switch (lastError) { + case QNetworkSession::UnknownSessionError: + return tr("Unknown session error."); + case QNetworkSession::SessionAbortedError: + return tr("The session was aborted by the user or system."); + case QNetworkSession::OperationNotSupportedError: + return tr("The requested operation is not supported by the system."); + case QNetworkSession::InvalidConfigurationError: + return tr("The specified configuration cannot be used."); + case QNetworkSession::RoamingError: + return tr("Roaming was aborted or is not possible."); + + } + + return QString(); +} + +QNetworkSession::SessionError QNetworkSessionPrivate::error() const +{ + return lastError; +} + +quint64 QNetworkSessionPrivate::bytesWritten() const +{ +#if defined(BACKEND_NM) + if( state == QNetworkSession::Connected ) { + if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + foreach (const QNetworkConfiguration &config, publicConfig.children()) { + if ((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + return static_cast(getEngineFromId(config.d->id))->sentDataForId(config.d->id); + } + } + } else { + return static_cast(getEngineFromId(activeConfig.d->id))->sentDataForId(activeConfig.d->id); + } + } +#endif + return tx_data; +} + +quint64 QNetworkSessionPrivate::bytesReceived() const +{ +#if defined(BACKEND_NM) + if( state == QNetworkSession::Connected ) { + if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + foreach (const QNetworkConfiguration &config, publicConfig.children()) { + if ((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + return static_cast(getEngineFromId(activeConfig.d->id))->receivedDataForId(config.d->id); + } + } + } else { + return static_cast(getEngineFromId(activeConfig.d->id))->receivedDataForId(activeConfig.d->id); + } + } +#endif + return rx_data; +} + +quint64 QNetworkSessionPrivate::activeTime() const +{ +#if defined(BACKEND_NM) + if (startTime.isNull()) { + return 0; + } + if(state == QNetworkSession::Connected ) + return startTime.secsTo(QDateTime::currentDateTime()); +#endif + return m_activeTime; +} + +void QNetworkSessionPrivate::updateStateFromServiceNetwork() +{ + QNetworkSession::State oldState = state; + + foreach (const QNetworkConfiguration &config, serviceConfig.children()) { + if ((config.state() & QNetworkConfiguration::Active) != QNetworkConfiguration::Active) + continue; + + if (activeConfig != config) { + if (engine) { + disconnect(engine, SIGNAL(connectionError(QString,QNetworkSessionEngine::ConnectionError)), + this, SLOT(connectionError(QString,QNetworkSessionEngine::ConnectionError))); + } + + activeConfig = config; + engine = getEngineFromId(activeConfig.identifier()); + if (engine) { + connect(engine, SIGNAL(connectionError(QString,QNetworkSessionEngine::ConnectionError)), + this, SLOT(connectionError(QString,QNetworkSessionEngine::ConnectionError)), + Qt::QueuedConnection); + } + emit q->newConfigurationActivated(); + } + + state = QNetworkSession::Connected; + if (state != oldState) + emit q->stateChanged(state); + + return; + } + + if (serviceConfig.children().isEmpty()) + state = QNetworkSession::NotAvailable; + else + state = QNetworkSession::Disconnected; + + if (state != oldState) + emit q->stateChanged(state); +} + +void QNetworkSessionPrivate::updateStateFromActiveConfig() +{ + QNetworkSession::State oldState = state; + + bool newActive = false; + + if (!activeConfig.isValid()) { + state = QNetworkSession::Invalid; + } else if ((activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + state = QNetworkSession::Connected; + newActive = opened; + } else if ((activeConfig.state() & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) { + state = QNetworkSession::Disconnected; + } else if ((activeConfig.state() & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) { + state = QNetworkSession::NotAvailable; + } else if ((activeConfig.state() & QNetworkConfiguration::Undefined) == QNetworkConfiguration::Undefined) { + state = QNetworkSession::NotAvailable; + } + + bool oldActive = isActive; + isActive = newActive; + + if (!oldActive && isActive) + emit quitPendingWaitsForOpened(); + if (oldActive && !isActive) + emit q->closed(); + + if (oldState != state) + emit q->stateChanged(state); +} + +void QNetworkSessionPrivate::networkConfigurationsChanged() +{ + if (serviceConfig.isValid()) + updateStateFromServiceNetwork(); + else + updateStateFromActiveConfig(); +#if defined(BACKEND_NM) + setActiveTimeStamp(); +#endif +} + +void QNetworkSessionPrivate::configurationChanged(const QNetworkConfiguration &config) +{ + if (serviceConfig.isValid() && (config == serviceConfig || config == activeConfig)) + updateStateFromServiceNetwork(); + else if (config == activeConfig) + updateStateFromActiveConfig(); +} + +void QNetworkSessionPrivate::forcedSessionClose(const QNetworkConfiguration &config) +{ + if (activeConfig == config) { + opened = false; + isActive = false; + + emit q->closed(); + + lastError = QNetworkSession::SessionAbortedError; + emit q->error(lastError); + } +} + +void QNetworkSessionPrivate::connectionError(const QString &id, QNetworkSessionEngine::ConnectionError error) +{ + if (activeConfig.identifier() == id) { + networkConfigurationsChanged(); + switch (error) { + case QNetworkSessionEngine::OperationNotSupported: + lastError = QNetworkSession::OperationNotSupportedError; + opened = false; + break; + case QNetworkSessionEngine::InterfaceLookupError: + case QNetworkSessionEngine::ConnectError: + case QNetworkSessionEngine::DisconnectionError: + default: + lastError = QNetworkSession::UnknownSessionError; + } + + emit quitPendingWaitsForOpened(); + emit q->error(lastError); + } +} + +#if defined(BACKEND_NM) +void QNetworkSessionPrivate::setActiveTimeStamp() +{ + if(NetworkManagerAvailable()) { + startTime = QDateTime(); + return; + } + QString connectionIdent = q->configuration().identifier(); + QString interface = currentInterface().hardwareAddress().toLower(); + QString devicePath = "/org/freedesktop/Hal/devices/net_" + interface.replace(":","_"); + + QString path; + QString serviceName; + QNetworkManagerInterface * ifaceD; + ifaceD = new QNetworkManagerInterface(); + + QList connections = ifaceD->activeConnections(); + foreach(QDBusObjectPath conpath, connections) { + QNetworkManagerConnectionActive *conDetails; + conDetails = new QNetworkManagerConnectionActive(conpath.path()); + QDBusObjectPath connection = conDetails->connection(); + serviceName = conDetails->serviceName(); + QList so = conDetails->devices(); + foreach(QDBusObjectPath device, so) { + + if(device.path() == devicePath) { + path = connection.path(); + } + break; + } + } +if(serviceName.isEmpty()) + return; + QNetworkManagerSettings *settingsiface; + settingsiface = new QNetworkManagerSettings(serviceName); + QList list = settingsiface->listConnections(); + foreach(QDBusObjectPath path, list) { + QNetworkManagerSettingsConnection *sysIface; + sysIface = new QNetworkManagerSettingsConnection(serviceName, path.path()); + startTime = QDateTime::fromTime_t(sysIface->getTimestamp()); + // isActive = (publicConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active; + } + if(startTime.isNull()) + startTime = QDateTime::currentDateTime(); +} +#endif + +#include "moc_qnetworksession_p.cpp" +QTM_END_NAMESPACE + diff --git a/src/network/bearer/qnetworksession_p.h b/src/network/bearer/qnetworksession_p.h new file mode 100644 index 0000000..a2aaa6a --- /dev/null +++ b/src/network/bearer/qnetworksession_p.h @@ -0,0 +1,167 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 QNETWORKSESSIONPRIVATE_H +#define QNETWORKSESSIONPRIVATE_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 "qnetworkconfigmanager_p.h" +#include "qnetworksession.h" +#ifdef BEARER_ENGINE +#include "qnetworksessionengine_p.h" +#endif + +#include "qnetworksession.h" +#include +#include + +QTM_BEGIN_NAMESPACE +#ifdef BEARER_ENGINE +class QNetworkSessionEngine; +#endif + +class QNetworkSessionPrivate : public QObject +{ + Q_OBJECT +public: + QNetworkSessionPrivate() : + tx_data(0), rx_data(0), m_activeTime(0), isActive(false) + { + } + + ~QNetworkSessionPrivate() + { + } + + //called by QNetworkSession constructor and ensures + //that the state is immediately updated (w/o actually opening + //a session). Also this function should take care of + //notification hooks to discover future state changes. + void syncStateWithInterface(); + + QNetworkInterface currentInterface() const; + QVariant sessionProperty(const QString& key) const; + void setSessionProperty(const QString& key, const QVariant& value); + QString bearerName() const; + + void open(); + void close(); + void stop(); + void migrate(); + void accept(); + void ignore(); + void reject(); + + QString errorString() const; //must return translated string + QNetworkSession::SessionError error() const; + + quint64 bytesWritten() const; + quint64 bytesReceived() const; + quint64 activeTime() const; + +private: + void updateStateFromServiceNetwork(); + void updateStateFromActiveConfig(); + +Q_SIGNALS: + //releases any pending waitForOpened() calls + void quitPendingWaitsForOpened(); + +private Q_SLOTS: +#ifdef BEARER_ENGINE + void networkConfigurationsChanged(); + void configurationChanged(const QNetworkConfiguration &config); + void forcedSessionClose(const QNetworkConfiguration &config); + void connectionError(const QString &id, QNetworkSessionEngine::ConnectionError error); +#endif + +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; + + QNetworkSession::State state; + bool isActive; + +#ifdef BEARER_ENGINE + bool opened; + + QNetworkSessionEngine *engine; +#endif + QNetworkSession::SessionError lastError; + + QNetworkSession* q; + friend class QNetworkSession; + +#if defined(BEARER_ENGINE) && defined(BACKEND_NM) + QDateTime startTime; + void setActiveTimeStamp(); +#endif +}; + +QTM_END_NAMESPACE + +#endif //QNETWORKSESSIONPRIVATE_H + diff --git a/src/network/bearer/qnetworksession_s60_p.cpp b/src/network/bearer/qnetworksession_s60_p.cpp new file mode 100644 index 0000000..764c1c4 --- /dev/null +++ b/src/network/bearer/qnetworksession_s60_p.cpp @@ -0,0 +1,1168 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 +#include "qnetworksession_s60_p.h" +#include "qnetworkconfiguration_s60_p.h" +#include "qnetworkconfigmanager_s60_p.h" +#include +#include +#include +#include +#include + +QTM_BEGIN_NAMESPACE + +QNetworkSessionPrivate::QNetworkSessionPrivate() + : CActive(CActive::EPriorityStandard), state(QNetworkSession::Invalid), + isActive(false), ipConnectionNotifier(0), iError(QNetworkSession::UnknownSessionError), + iALREnabled(0) +{ + CActiveScheduler::Add(this); + + // Try to load "Open C" dll dynamically and + // try to attach to setdefaultif function dynamically. + if (iOpenCLibrary.Load(_L("libc")) == KErrNone) { + iDynamicSetdefaultif = (TOpenCSetdefaultifFunction)iOpenCLibrary.Lookup(564); + } + + TRAP_IGNORE(iConnectionMonitor.ConnectL()); +} + +QNetworkSessionPrivate::~QNetworkSessionPrivate() +{ + isActive = false; + + // Cancel Connection Progress Notifications first. + // Note: ConnectionNotifier must be destroyed before Canceling RConnection::Start() + // => deleting ipConnectionNotifier results RConnection::CancelProgressNotification() + delete ipConnectionNotifier; + ipConnectionNotifier = NULL; + + // Cancel possible RConnection::Start() + Cancel(); + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + if (iMobility) { + delete iMobility; + iMobility = NULL; + } +#endif + + iConnection.Close(); + iSocketServ.Close(); + if (iDynamicSetdefaultif) { + iDynamicSetdefaultif(0); + } + + iConnectionMonitor.CancelNotifications(); + iConnectionMonitor.Close(); + + iOpenCLibrary.Close(); +} + +void QNetworkSessionPrivate::syncStateWithInterface() +{ + if (!publicConfig.d) { + return; + } + + // Start monitoring changes in IAP states + TRAP_IGNORE(iConnectionMonitor.NotifyEventL(*this)); + + // Check open connections to see if there is already + // an open connection to selected IAP or SNAP + TUint count; + TRequestStatus status; + iConnectionMonitor.GetConnectionCount(count, status); + User::WaitForRequest(status); + if (status.Int() != KErrNone) { + return; + } + + TUint numSubConnections; + TUint connectionId; + for (TUint i = 1; i <= count; i++) { + TInt ret = iConnectionMonitor.GetConnectionInfo(i, connectionId, numSubConnections); + if (ret == KErrNone) { + TUint apId; + iConnectionMonitor.GetUintAttribute(connectionId, 0, KIAPId, apId, status); + User::WaitForRequest(status); + if (status.Int() == KErrNone) { + TInt connectionStatus; + iConnectionMonitor.GetIntAttribute(connectionId, 0, KConnectionStatus, connectionStatus, status); + User::WaitForRequest(status); + if (connectionStatus == KLinkLayerOpen) { + if (state != QNetworkSession::Closing) { + if (newState(QNetworkSession::Connected, apId)) { + return; + } + } + } + } + } + } + + if (state != QNetworkSession::Connected) { + // There were no open connections to used IAP or SNAP + if ((publicConfig.d.data()->state & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + newState(QNetworkSession::Disconnected); + } else { + newState(QNetworkSession::NotAvailable); + } + } +} + +QNetworkInterface QNetworkSessionPrivate::interface(TUint iapId) const +{ + QString interfaceName; + + TSoInetInterfaceInfo ifinfo; + TPckg ifinfopkg(ifinfo); + TSoInetIfQuery ifquery; + TPckg ifquerypkg(ifquery); + + // Open dummy socket for interface queries + RSocket socket; + TInt retVal = socket.Open(iSocketServ, _L("udp")); + if (retVal != KErrNone) { + return QNetworkInterface(); + } + + // Start enumerating interfaces + socket.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl); + while(socket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, ifinfopkg) == KErrNone) { + ifquery.iName = ifinfo.iName; + TInt err = socket.GetOpt(KSoInetIfQueryByName, KSolInetIfQuery, ifquerypkg); + if(err == KErrNone && ifquery.iZone[1] == iapId) { // IAP ID is index 1 of iZone + if(ifinfo.iAddress.Address() > 0) { + interfaceName = QString::fromUtf16(ifinfo.iName.Ptr(),ifinfo.iName.Length()); + break; + } + } + } + + socket.Close(); + + if (interfaceName.isEmpty()) { + return QNetworkInterface(); + } + + return QNetworkInterface::interfaceFromName(interfaceName); +} + +QNetworkInterface QNetworkSessionPrivate::currentInterface() const +{ + if (!publicConfig.isValid() || state != QNetworkSession::Connected) { + return QNetworkInterface(); + } + + return activeInterface; +} + +QVariant QNetworkSessionPrivate::sessionProperty(const QString& /*key*/) const +{ + return QVariant(); +} + +void QNetworkSessionPrivate::setSessionProperty(const QString& /*key*/, const QVariant& /*value*/) +{ +} + +QString QNetworkSessionPrivate::errorString() const +{ + switch (iError) { + case QNetworkSession::UnknownSessionError: + return tr("Unknown session error."); + case QNetworkSession::SessionAbortedError: + return tr("The session was aborted by the user or system."); + case QNetworkSession::OperationNotSupportedError: + return tr("The requested operation is not supported by the system."); + case QNetworkSession::InvalidConfigurationError: + return tr("The specified configuration cannot be used."); + case QNetworkSession::RoamingError: + return tr("Roaming was aborted or is not possible."); + } + + return QString(); +} + +QNetworkSession::SessionError QNetworkSessionPrivate::error() const +{ + return iError; +} + +void QNetworkSessionPrivate::open() +{ + if (isActive || !publicConfig.d || (state == QNetworkSession::Connecting)) { + return; + } + + // Cancel notifications from RConnectionMonitor + // => RConnection::ProgressNotification will be used for IAP/SNAP monitoring + iConnectionMonitor.CancelNotifications(); + + TInt error = iSocketServ.Connect(); + if (error != KErrNone) { + // Could not open RSocketServ + newState(QNetworkSession::Invalid); + iError = QNetworkSession::UnknownSessionError; + emit q->error(iError); + syncStateWithInterface(); + return; + } + + error = iConnection.Open(iSocketServ); + if (error != KErrNone) { + // Could not open RConnection + iSocketServ.Close(); + newState(QNetworkSession::Invalid); + iError = QNetworkSession::UnknownSessionError; + emit q->error(iError); + syncStateWithInterface(); + return; + } + + // Use RConnection::ProgressNotification for IAP/SNAP monitoring + // (<=> ConnectionProgressNotifier uses RConnection::ProgressNotification) + if (!ipConnectionNotifier) { + ipConnectionNotifier = new ConnectionProgressNotifier(*this,iConnection); + } + if (ipConnectionNotifier) { + ipConnectionNotifier->StartNotifications(); + } + + if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { + // Search through existing connections. + // If there is already connection which matches to given IAP + // try to attach to existing connection. + TBool connected(EFalse); + TConnectionInfoBuf connInfo; + TUint count; + if (iConnection.EnumerateConnections(count) == KErrNone) { + for (TUint i=1; i<=count; i++) { + // Note: GetConnectionInfo expects 1-based index. + if (iConnection.GetConnectionInfo(i, connInfo) == KErrNone) { + if (connInfo().iIapId == publicConfig.d.data()->numericId) { + if (iConnection.Attach(connInfo, RConnection::EAttachTypeNormal) == KErrNone) { + activeConfig = publicConfig; + activeInterface = interface(activeConfig.d.data()->numericId); + connected = ETrue; + startTime = QDateTime::currentDateTime(); + if (iDynamicSetdefaultif) { + // Use name of the IAP to set default IAP + QByteArray nameAsByteArray = publicConfig.name().toUtf8(); + ifreq ifr; + strcpy(ifr.ifr_name, nameAsByteArray.constData()); + + error = iDynamicSetdefaultif(&ifr); + } + isActive = true; + // Make sure that state will be Connected + newState(QNetworkSession::Connected); + emit quitPendingWaitsForOpened(); + break; + } + } + } + } + } + if (!connected) { + TCommDbConnPref pref; + pref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); + pref.SetIapId(publicConfig.d.data()->numericId); + iConnection.Start(pref, iStatus); + if (!IsActive()) { + SetActive(); + } + newState(QNetworkSession::Connecting); + } + } else if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + TConnSnapPref snapPref(publicConfig.d.data()->numericId); + iConnection.Start(snapPref, iStatus); + if (!IsActive()) { + SetActive(); + } + newState(QNetworkSession::Connecting); + } else if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + iKnownConfigsBeforeConnectionStart = ((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager)->accessPointConfigurations.keys(); + iConnection.Start(iStatus); + if (!IsActive()) { + SetActive(); + } + newState(QNetworkSession::Connecting); + } + + if (error != KErrNone) { + isActive = false; + iError = QNetworkSession::UnknownSessionError; + emit q->error(iError); + if (ipConnectionNotifier) { + ipConnectionNotifier->StopNotifications(); + } + syncStateWithInterface(); + } +} + +TUint QNetworkSessionPrivate::iapClientCount(TUint aIAPId) const +{ + TRequestStatus status; + TUint connectionCount; + iConnectionMonitor.GetConnectionCount(connectionCount, status); + User::WaitForRequest(status); + if (status.Int() == KErrNone) { + for (TUint i = 1; i <= connectionCount; i++) { + TUint connectionId; + TUint subConnectionCount; + iConnectionMonitor.GetConnectionInfo(i, connectionId, subConnectionCount); + TUint apId; + iConnectionMonitor.GetUintAttribute(connectionId, subConnectionCount, KIAPId, apId, status); + User::WaitForRequest(status); + if (apId == aIAPId) { + TConnMonClientEnumBuf buf; + iConnectionMonitor.GetPckgAttribute(connectionId, 0, KClientInfo, buf, status); + User::WaitForRequest(status); + if (status.Int() == KErrNone) { + return buf().iCount; + } + } + } + } + return 0; +} + +void QNetworkSessionPrivate::close(bool allowSignals) +{ + if (!isActive) { + return; + } + + TUint activeIap = activeConfig.d.data()->numericId; + isActive = false; + activeConfig = QNetworkConfiguration(); + serviceConfig = QNetworkConfiguration(); + + Cancel(); +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + if (iMobility) { + delete iMobility; + iMobility = NULL; + } +#endif + + if (ipConnectionNotifier) { + ipConnectionNotifier->StopNotifications(); + } + + iConnection.Close(); + iSocketServ.Close(); + if (iDynamicSetdefaultif) { + iDynamicSetdefaultif(0); + } + +#ifdef Q_CC_NOKIAX86 + if ((allowSignals && iapClientCount(activeIap) <= 0) || +#else + if ((allowSignals && iapClientCount(activeIap) <= 1) || +#endif + (publicConfig.type() == QNetworkConfiguration::UserChoice)) { + newState(QNetworkSession::Closing); + } + + syncStateWithInterface(); + if (allowSignals) { + if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + newState(QNetworkSession::Disconnected); + } + emit q->closed(); + } +} + +void QNetworkSessionPrivate::stop() +{ + if (!isActive) { + return; + } + isActive = false; + newState(QNetworkSession::Closing); + iConnection.Stop(RConnection::EStopAuthoritative); + isActive = true; + close(false); + emit q->closed(); +} + +void QNetworkSessionPrivate::migrate() +{ +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + iMobility->MigrateToPreferredCarrier(); +#endif +} + +void QNetworkSessionPrivate::ignore() +{ +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + iMobility->IgnorePreferredCarrier(); + if (!iALRUpgradingConnection) { + newState(QNetworkSession::Disconnected); + } else { + newState(QNetworkSession::Connected,iOldRoamingIap); + } +#endif +} + +void QNetworkSessionPrivate::accept() +{ +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + iMobility->NewCarrierAccepted(); + if (iDynamicSetdefaultif) { + // Use name of the IAP to set default IAP + QByteArray nameAsByteArray = activeConfig.name().toUtf8(); + ifreq ifr; + strcpy(ifr.ifr_name, nameAsByteArray.constData()); + + iDynamicSetdefaultif(&ifr); + } + newState(QNetworkSession::Connected, iNewRoamingIap); +#endif +} + +void QNetworkSessionPrivate::reject() +{ +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + iMobility->NewCarrierRejected(); + if (!iALRUpgradingConnection) { + newState(QNetworkSession::Disconnected); + } else { + newState(QNetworkSession::Connected, iOldRoamingIap); + } +#endif +} + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE +void QNetworkSessionPrivate::PreferredCarrierAvailable(TAccessPointInfo aOldAPInfo, + TAccessPointInfo aNewAPInfo, + TBool aIsUpgrade, + TBool aIsSeamless) +{ + iOldRoamingIap = aOldAPInfo.AccessPoint(); + iNewRoamingIap = aNewAPInfo.AccessPoint(); + newState(QNetworkSession::Roaming); + if (iALREnabled > 0) { + iALRUpgradingConnection = aIsUpgrade; + QList configs = publicConfig.children(); + for (int i=0; i < configs.count(); i++) { + if (configs[i].d.data()->numericId == aNewAPInfo.AccessPoint()) { + emit q->preferredConfigurationChanged(configs[i],aIsSeamless); + } + } + } else { + migrate(); + } +} + +void QNetworkSessionPrivate::NewCarrierActive(TAccessPointInfo /*aNewAPInfo*/, TBool /*aIsSeamless*/) +{ + if (iALREnabled > 0) { + emit q->newConfigurationActivated(); + } else { + accept(); + } +} + +void QNetworkSessionPrivate::Error(TInt /*aError*/) +{ + if (isActive) { + isActive = false; + activeConfig = QNetworkConfiguration(); + serviceConfig = QNetworkConfiguration(); + iError = QNetworkSession::RoamingError; + emit q->error(iError); + Cancel(); + if (ipConnectionNotifier) { + ipConnectionNotifier->StopNotifications(); + } + syncStateWithInterface(); + // In some cases IAP is still in Connected state when + // syncStateWithInterface(); is called + // => Following call makes sure that Session state + // changes immediately to Disconnected. + newState(QNetworkSession::Disconnected); + emit q->closed(); + } +} +#endif + +void QNetworkSessionPrivate::setALREnabled(bool enabled) +{ + if (enabled) { + iALREnabled++; + } else { + iALREnabled--; + } +} + +QNetworkConfiguration QNetworkSessionPrivate::bestConfigFromSNAP(const QNetworkConfiguration& snapConfig) const +{ + QNetworkConfiguration config; + QList subConfigurations = snapConfig.children(); + for (int i = 0; i < subConfigurations.count(); i++ ) { + if (subConfigurations[i].state() == QNetworkConfiguration::Active) { + config = subConfigurations[i]; + break; + } else if (!config.isValid() && subConfigurations[i].state() == QNetworkConfiguration::Discovered) { + config = subConfigurations[i]; + } + } + if (!config.isValid() && subConfigurations.count() > 0) { + config = subConfigurations[0]; + } + return config; +} + +QString QNetworkSessionPrivate::bearerName() const +{ + QNetworkConfiguration config; + if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { + config = publicConfig; + } else if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + if (activeConfig.isValid()) { + config = activeConfig; + } else { + config = bestConfigFromSNAP(publicConfig); + } + } else if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + if (activeConfig.isValid()) { + config = activeConfig; + } + } + + if (!config.isValid()) { + return QString(); + } + + switch (config.d.data()->bearer) { + case QNetworkConfigurationPrivate::BearerEthernet: return QString("Ethernet"); + case QNetworkConfigurationPrivate::BearerWLAN: return QString("WLAN"); + case QNetworkConfigurationPrivate::Bearer2G: return QString("2G"); + case QNetworkConfigurationPrivate::BearerCDMA2000: return QString("CDMA2000"); + case QNetworkConfigurationPrivate::BearerWCDMA: return QString("WCDMA"); + case QNetworkConfigurationPrivate::BearerHSPA: return QString("HSPA"); + case QNetworkConfigurationPrivate::BearerBluetooth: return QString("Bluetooth"); + case QNetworkConfigurationPrivate::BearerWiMAX: return QString("WiMAX"); + default: return QString(); + } +} + +quint64 QNetworkSessionPrivate::bytesWritten() const +{ + return transferredData(KUplinkData); +} + +quint64 QNetworkSessionPrivate::bytesReceived() const +{ + return transferredData(KDownlinkData); +} + +quint64 QNetworkSessionPrivate::transferredData(TUint dataType) const +{ + if (!publicConfig.isValid()) { + return 0; + } + + QNetworkConfiguration config; + if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + if (serviceConfig.isValid()) { + config = serviceConfig; + } else { + if (activeConfig.isValid()) { + config = activeConfig; + } + } + } else { + config = publicConfig; + } + + if (!config.isValid()) { + return 0; + } + + TUint count; + TRequestStatus status; + iConnectionMonitor.GetConnectionCount(count, status); + User::WaitForRequest(status); + if (status.Int() != KErrNone) { + return 0; + } + + TUint transferredData = 0; + TUint numSubConnections; + TUint connectionId; + bool configFound; + for (TUint i = 1; i <= count; i++) { + TInt ret = iConnectionMonitor.GetConnectionInfo(i, connectionId, numSubConnections); + if (ret == KErrNone) { + TUint apId; + iConnectionMonitor.GetUintAttribute(connectionId, 0, KIAPId, apId, status); + User::WaitForRequest(status); + if (status.Int() == KErrNone) { + configFound = false; + if (config.type() == QNetworkConfiguration::ServiceNetwork) { + QList configs = config.children(); + for (int i=0; i < configs.count(); i++) { + if (configs[i].d.data()->numericId == apId) { + configFound = true; + break; + } + } + } else if (config.d.data()->numericId == apId) { + configFound = true; + } + if (configFound) { + TUint tData; + iConnectionMonitor.GetUintAttribute(connectionId, 0, dataType, tData, status ); + User::WaitForRequest(status); + if (status.Int() == KErrNone) { + transferredData += tData; + } + } + } + } + } + + return transferredData; +} + +quint64 QNetworkSessionPrivate::activeTime() const +{ + if (!isActive || startTime.isNull()) { + return 0; + } + return startTime.secsTo(QDateTime::currentDateTime()); +} + +QNetworkConfiguration QNetworkSessionPrivate::activeConfiguration(TUint32 iapId) const +{ + if (iapId == 0) { + _LIT(KSetting, "IAP\\Id"); + iConnection.GetIntSetting(KSetting, iapId); + } + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + // Try to search IAP from the used SNAP using IAP Id + QList children = publicConfig.children(); + for (int i=0; i < children.count(); i++) { + if (children[i].d.data()->numericId == iapId) { + return children[i]; + } + } + + // Given IAP Id was not found from the used SNAP + // => Try to search matching IAP using mappingName + // mappingName contains: + // 1. "Access point name" for "Packet data" Bearer + // 2. "WLAN network name" (= SSID) for "Wireless LAN" Bearer + // 3. "Dial-up number" for "Data call Bearer" or "High Speed (GSM)" Bearer + // <=> Note: It's possible that in this case reported IAP is + // clone of the one of the IAPs of the used SNAP + // => If mappingName matches, clone has been found + QNetworkConfiguration pt; + pt.d = ((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager)->accessPointConfigurations.value(QString::number(qHash(iapId))); + if (pt.d) { + for (int i=0; i < children.count(); i++) { + if (children[i].d.data()->mappingName == pt.d.data()->mappingName) { + return children[i]; + } + } + } else { + // Given IAP Id was not found from known IAPs array + return QNetworkConfiguration(); + } + + // Matching IAP was not found from used SNAP + // => IAP from another SNAP is returned + // (Note: Returned IAP matches to given IAP Id) + return pt; + } +#endif + + if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + if (publicConfig.d.data()->manager) { + QNetworkConfiguration pt; + // Try to found User Selected IAP from known IAPs (accessPointConfigurations) + pt.d = ((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager)->accessPointConfigurations.value(QString::number(qHash(iapId))); + if (pt.d) { + return pt; + } else { + // Check if new (WLAN) IAP was created in IAP/SNAP dialog + // 1. Sync internal configurations array to commsdb first + ((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager)->updateConfigurations(); + // 2. Check if new configuration was created during connection creation + QList knownConfigs = ((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager)->accessPointConfigurations.keys(); + if (knownConfigs.count() > iKnownConfigsBeforeConnectionStart.count()) { + // Configuration count increased => new configuration was created + // => Search new, created configuration + QString newIapId; + for (int i=0; i < iKnownConfigsBeforeConnectionStart.count(); i++) { + if (knownConfigs[i] != iKnownConfigsBeforeConnectionStart[i]) { + newIapId = knownConfigs[i]; + break; + } + } + if (newIapId.isEmpty()) { + newIapId = knownConfigs[knownConfigs.count()-1]; + } + pt.d = ((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager)->accessPointConfigurations.value(newIapId); + if (pt.d) { + return pt; + } + } + } + } + return QNetworkConfiguration(); + } + + return publicConfig; +} + +void QNetworkSessionPrivate::RunL() +{ + TInt statusCode = iStatus.Int(); + + switch (statusCode) { + case KErrNone: // Connection created succesfully + { + TInt error = KErrNone; + QNetworkConfiguration newActiveConfig = activeConfiguration(); + if (!newActiveConfig.isValid()) { + error = KErrGeneral; + } else if (iDynamicSetdefaultif) { + // Use name of the IAP to set default IAP + QByteArray nameAsByteArray = newActiveConfig.name().toUtf8(); + ifreq ifr; + strcpy(ifr.ifr_name, nameAsByteArray.constData()); + + error = iDynamicSetdefaultif(&ifr); + } + + if (error != KErrNone) { + isActive = false; + iError = QNetworkSession::UnknownSessionError; + emit q->error(iError); + Cancel(); + if (ipConnectionNotifier) { + ipConnectionNotifier->StopNotifications(); + } + syncStateWithInterface(); + return; + } + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + // Activate ALR monitoring + iMobility = CActiveCommsMobilityApiExt::NewL(iConnection, *this); + } +#endif + isActive = true; + activeConfig = newActiveConfig; + activeInterface = interface(activeConfig.d.data()->numericId); + if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + QNetworkConfiguration pt; + pt.d = activeConfig.d.data()->serviceNetworkPtr; + serviceConfig = pt; + } + + startTime = QDateTime::currentDateTime(); + + newState(QNetworkSession::Connected); + emit quitPendingWaitsForOpened(); + } + break; + case KErrNotFound: // Connection failed + isActive = false; + activeConfig = QNetworkConfiguration(); + serviceConfig = QNetworkConfiguration(); + iError = QNetworkSession::InvalidConfigurationError; + emit q->error(iError); + Cancel(); + if (ipConnectionNotifier) { + ipConnectionNotifier->StopNotifications(); + } + syncStateWithInterface(); + break; + case KErrCancel: // Connection attempt cancelled + case KErrAlreadyExists: // Connection already exists + default: + isActive = false; + activeConfig = QNetworkConfiguration(); + serviceConfig = QNetworkConfiguration(); + iError = QNetworkSession::UnknownSessionError; + emit q->error(iError); + Cancel(); + if (ipConnectionNotifier) { + ipConnectionNotifier->StopNotifications(); + } + syncStateWithInterface(); + break; + } +} + +void QNetworkSessionPrivate::DoCancel() +{ + iConnection.Close(); +} + +bool QNetworkSessionPrivate::newState(QNetworkSession::State newState, TUint accessPointId) +{ + // Make sure that activeConfig is always updated when SNAP is signaled to be + // connected. + if (isActive && publicConfig.type() == QNetworkConfiguration::ServiceNetwork && + newState == QNetworkSession::Connected) { + activeConfig = activeConfiguration(accessPointId); + activeInterface = interface(activeConfig.d.data()->numericId); + } + + // Make sure that same state is not signaled twice in a row. + if (state == newState) { + return true; + } + + // Make sure that Connecting state does not overwrite Roaming state + if (state == QNetworkSession::Roaming && newState == QNetworkSession::Connecting) { + return false; + } + + bool emitSessionClosed = false; + if (isActive && state == QNetworkSession::Connected && newState == QNetworkSession::Disconnected) { + // Active & Connected state should change directly to Disconnected state + // only when something forces connection to close (eg. when another + // application or session stops connection or when network drops + // unexpectedly). + isActive = false; + activeConfig = QNetworkConfiguration(); + serviceConfig = QNetworkConfiguration(); + iError = QNetworkSession::SessionAbortedError; + emit q->error(iError); + Cancel(); + if (ipConnectionNotifier) { + ipConnectionNotifier->StopNotifications(); + } + // Start monitoring changes in IAP states + TRAP_IGNORE(iConnectionMonitor.NotifyEventL(*this)); + emitSessionClosed = true; // Emit SessionClosed after state change has been reported + } + + bool retVal = false; + if (accessPointId == 0) { + state = newState; + emit q->stateChanged(state); + retVal = true; + } else { + if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { + if (publicConfig.d.data()->numericId == accessPointId) { + state = newState; + emit q->stateChanged(state); + retVal = true; + } + } else if (publicConfig.type() == QNetworkConfiguration::UserChoice && isActive) { + if (activeConfig.d.data()->numericId == accessPointId) { + state = newState; + emit q->stateChanged(state); + retVal = true; + } + } else if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + QList subConfigurations = publicConfig.children(); + for (int i = 0; i < subConfigurations.count(); i++) { + if (subConfigurations[i].d.data()->numericId == accessPointId) { + if (newState == QNetworkSession::Connected) { + // Make sure that when AccessPoint is reported to be Connected + // also state of the related configuration changes to Active. + subConfigurations[i].d.data()->state = QNetworkConfiguration::Active; + + state = newState; + emit q->stateChanged(state); + retVal = true; + } else { + if (newState == QNetworkSession::Disconnected) { + // Make sure that when AccessPoint is reported to be disconnected + // also state of the related configuration changes from Active to Defined. + subConfigurations[i].d.data()->state = QNetworkConfiguration::Defined; + } + QNetworkConfiguration config = bestConfigFromSNAP(publicConfig); + if ((config.state() == QNetworkConfiguration::Defined) || + (config.state() == QNetworkConfiguration::Discovered)) { + state = newState; + emit q->stateChanged(state); + retVal = true; + } + } + } + } + } + } + + if (emitSessionClosed) { + emit q->closed(); + } + + return retVal; +} + +void QNetworkSessionPrivate::handleSymbianConnectionStatusChange(TInt aConnectionStatus, + TInt aError, + TUint accessPointId) +{ + switch (aConnectionStatus) + { + // Connection unitialised + case KConnectionUninitialised: + break; + + // Starting connetion selection + case KStartingSelection: + break; + + // Selection finished + case KFinishedSelection: + if (aError == KErrNone) + { + // The user successfully selected an IAP to be used + break; + } + else + { + // The user pressed e.g. "Cancel" and did not select an IAP + newState(QNetworkSession::Disconnected,accessPointId); + } + break; + + // Connection failure + case KConnectionFailure: + newState(QNetworkSession::NotAvailable); + break; + + // Prepearing connection (e.g. dialing) + case KPsdStartingConfiguration: + case KPsdFinishedConfiguration: + case KCsdFinishedDialling: + case KCsdScanningScript: + case KCsdGettingLoginInfo: + case KCsdGotLoginInfo: + break; + + // Creating connection (e.g. GPRS activation) + case KCsdStartingConnect: + case KCsdFinishedConnect: + newState(QNetworkSession::Connecting,accessPointId); + break; + + // Starting log in + case KCsdStartingLogIn: + break; + + // Finished login + case KCsdFinishedLogIn: + break; + + // Connection open + case KConnectionOpen: + break; + + case KLinkLayerOpen: + newState(QNetworkSession::Connected,accessPointId); + break; + + // Connection blocked or suspended + case KDataTransferTemporarilyBlocked: + break; + + // Hangup or GRPS deactivation + case KConnectionStartingClose: + newState(QNetworkSession::Closing,accessPointId); + break; + + // Connection closed + case KConnectionClosed: + break; + + case KLinkLayerClosed: + newState(QNetworkSession::Disconnected,accessPointId); + break; + + // Unhandled state + default: + break; + } +} + +void QNetworkSessionPrivate::EventL(const CConnMonEventBase& aEvent) +{ + switch (aEvent.EventType()) + { + case EConnMonConnectionStatusChange: + { + CConnMonConnectionStatusChange* realEvent; + realEvent = (CConnMonConnectionStatusChange*) &aEvent; + + TUint connectionId = realEvent->ConnectionId(); + TInt connectionStatus = realEvent->ConnectionStatus(); + + // Try to Find IAP Id using connection Id + TUint apId = 0; + if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + QList subConfigurations = publicConfig.children(); + for (int i = 0; i < subConfigurations.count(); i++ ) { + if (subConfigurations[i].d.data()->connectionId == connectionId) { + apId = subConfigurations[i].d.data()->numericId; + break; + } + } + } else if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { + if (publicConfig.d.data()->connectionId == connectionId) { + apId = publicConfig.d.data()->numericId; + } + } + + if (apId > 0) { + handleSymbianConnectionStatusChange(connectionStatus, KErrNone, apId); + } + } + break; + + case EConnMonCreateConnection: + { + CConnMonCreateConnection* realEvent; + realEvent = (CConnMonCreateConnection*) &aEvent; + TUint apId; + TUint connectionId = realEvent->ConnectionId(); + TRequestStatus status; + iConnectionMonitor.GetUintAttribute(connectionId, 0, KIAPId, apId, status); + User::WaitForRequest(status); + if (status.Int() == KErrNone) { + // Store connection id to related AccessPoint Configuration + if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + QList subConfigurations = publicConfig.children(); + for (int i = 0; i < subConfigurations.count(); i++ ) { + if (subConfigurations[i].d.data()->numericId == apId) { + subConfigurations[i].d.data()->connectionId = connectionId; + break; + } + } + } else if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { + if (publicConfig.d.data()->numericId == apId) { + publicConfig.d.data()->connectionId = connectionId; + } + } + } + } + break; + + case EConnMonDeleteConnection: + { + CConnMonDeleteConnection* realEvent; + realEvent = (CConnMonDeleteConnection*) &aEvent; + TUint connectionId = realEvent->ConnectionId(); + // Remove connection id from related AccessPoint Configuration + if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + QList subConfigurations = publicConfig.children(); + for (int i = 0; i < subConfigurations.count(); i++ ) { + if (subConfigurations[i].d.data()->connectionId == connectionId) { + subConfigurations[i].d.data()->connectionId = 0; + break; + } + } + } else if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { + if (publicConfig.d.data()->connectionId == connectionId) { + publicConfig.d.data()->connectionId = 0; + } + } + } + break; + + default: + // For unrecognized events + break; + } +} + +ConnectionProgressNotifier::ConnectionProgressNotifier(QNetworkSessionPrivate& owner, RConnection& connection) + : CActive(CActive::EPriorityStandard), iOwner(owner), iConnection(connection) +{ + CActiveScheduler::Add(this); +} + +ConnectionProgressNotifier::~ConnectionProgressNotifier() +{ + Cancel(); +} + +void ConnectionProgressNotifier::StartNotifications() +{ + if (!IsActive()) { + SetActive(); + } + iConnection.ProgressNotification(iProgress, iStatus); +} + +void ConnectionProgressNotifier::StopNotifications() +{ + Cancel(); +} + +void ConnectionProgressNotifier::DoCancel() +{ + iConnection.CancelProgressNotification(); +} + +void ConnectionProgressNotifier::RunL() +{ + if (iStatus == KErrNone) { + iOwner.handleSymbianConnectionStatusChange(iProgress().iStage, iProgress().iError); + + SetActive(); + iConnection.ProgressNotification(iProgress, iStatus); + } +} + +#include "moc_qnetworksession_s60_p.cpp" + +QTM_END_NAMESPACE diff --git a/src/network/bearer/qnetworksession_s60_p.h b/src/network/bearer/qnetworksession_s60_p.h new file mode 100644 index 0000000..cfb99c9 --- /dev/null +++ b/src/network/bearer/qnetworksession_s60_p.h @@ -0,0 +1,213 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 QNETWORKSESSIONPRIVATE_H +#define QNETWORKSESSIONPRIVATE_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 "qnetworksession.h" + +#include + +#include +#include +#include +#include +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + #include +#endif + +typedef int(*TOpenCSetdefaultifFunction)(const struct ifreq*); + +QTM_BEGIN_NAMESPACE + +class ConnectionProgressNotifier; + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE +class QNetworkSessionPrivate : public QObject, public CActive, public MMobilityProtocolResp, + public MConnectionMonitorObserver +#else +class QNetworkSessionPrivate : public QObject, public CActive, public MConnectionMonitorObserver +#endif +{ + Q_OBJECT +public: + QNetworkSessionPrivate(); + ~QNetworkSessionPrivate(); + + //called by QNetworkSession constructor and ensures + //that the state is immediately updated (w/o actually opening + //a session). Also this function should take care of + //notification hooks to discover future state changes. + void syncStateWithInterface(); + + QNetworkInterface currentInterface() const; + QVariant sessionProperty(const QString& key) const; + void setSessionProperty(const QString& key, const QVariant& value); + QString bearerName() const; + + void setALREnabled(bool enabled); + + void open(); + void close(bool allowSignals = true); + void stop(); + void migrate(); + void accept(); + void ignore(); + void reject(); + + QString errorString() const; //must return translated string + QNetworkSession::SessionError error() const; + quint64 bytesWritten() const; + quint64 bytesReceived() const; + quint64 activeTime() const; + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE +public: // From MMobilityProtocolResp + void PreferredCarrierAvailable(TAccessPointInfo aOldAPInfo, + TAccessPointInfo aNewAPInfo, + TBool aIsUpgrade, + TBool aIsSeamless); + + void NewCarrierActive(TAccessPointInfo aNewAPInfo, TBool aIsSeamless); + + void Error(TInt aError); +#endif + +Q_SIGNALS: + //releases any pending waitForOpened() calls + void quitPendingWaitsForOpened(); + +protected: // From CActive + void RunL(); + void DoCancel(); + +private: // MConnectionMonitorObserver + void EventL(const CConnMonEventBase& aEvent); + +private: + TUint iapClientCount(TUint aIAPId) const; + quint64 transferredData(TUint dataType) const; + bool newState(QNetworkSession::State newState, TUint accessPointId = 0); + void handleSymbianConnectionStatusChange(TInt aConnectionStatus, TInt aError, TUint accessPointId = 0); + QNetworkConfiguration bestConfigFromSNAP(const QNetworkConfiguration& snapConfig) const; + QNetworkConfiguration activeConfiguration(TUint32 iapId = 0) const; + QNetworkInterface interface(TUint iapId) const; + +private: // data + // The config set on QNetworkSession + mutable 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. + mutable QNetworkConfiguration serviceConfig; + + // This is the actual active configuration currently in use by the session. + // Either a copy of publicConfig or one of serviceConfig.children(). + mutable QNetworkConfiguration activeConfig; + + mutable QNetworkInterface activeInterface; + + QNetworkSession::State state; + bool isActive; + + QNetworkSession* q; + QDateTime startTime; + + RLibrary iOpenCLibrary; + TOpenCSetdefaultifFunction iDynamicSetdefaultif; + + mutable RSocketServ iSocketServ; + mutable RConnection iConnection; + mutable RConnectionMonitor iConnectionMonitor; + ConnectionProgressNotifier* ipConnectionNotifier; +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + CActiveCommsMobilityApiExt* iMobility; +#endif + + QNetworkSession::SessionError iError; + TInt iALREnabled; + TBool iALRUpgradingConnection; + + QList iKnownConfigsBeforeConnectionStart; + + TUint32 iOldRoamingIap; + TUint32 iNewRoamingIap; + + friend class QNetworkSession; + friend class ConnectionProgressNotifier; +}; + +class ConnectionProgressNotifier : public CActive +{ +public: + ConnectionProgressNotifier(QNetworkSessionPrivate& owner, RConnection& connection); + ~ConnectionProgressNotifier(); + + void StartNotifications(); + void StopNotifications(); + +protected: // From CActive + void RunL(); + void DoCancel(); + +private: // Data + QNetworkSessionPrivate& iOwner; + RConnection& iConnection; + TNifProgressBuf iProgress; + +}; + +QTM_END_NAMESPACE + +#endif //QNETWORKSESSIONPRIVATE_H + diff --git a/src/network/bearer/qnetworksessionengine.cpp b/src/network/bearer/qnetworksessionengine.cpp new file mode 100644 index 0000000..55fc4f3 --- /dev/null +++ b/src/network/bearer/qnetworksessionengine.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 "qnetworksessionengine_p.h" + +QTM_BEGIN_NAMESPACE + +QNetworkSessionEngine::QNetworkSessionEngine(QObject *parent) +: QObject(parent) +{ +} + +QNetworkSessionEngine::~QNetworkSessionEngine() +{ +} + +#include "moc_qnetworksessionengine_p.cpp" +QTM_END_NAMESPACE + diff --git a/src/network/bearer/qnetworksessionengine_p.h b/src/network/bearer/qnetworksessionengine_p.h new file mode 100644 index 0000000..795a209 --- /dev/null +++ b/src/network/bearer/qnetworksessionengine_p.h @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 QNETWORKSESSIONENGINE_P_H +#define QNETWORKSESSIONENGINE_P_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 +#include +#include +#include +#include + +QTM_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; +class QNetworkSessionEngine : public QObject +{ + Q_OBJECT + +public: + enum ConnectionError { + InterfaceLookupError = 0, + ConnectError, + OperationNotSupported, + DisconnectionError, + }; + + QNetworkSessionEngine(QObject *parent = 0); + virtual ~QNetworkSessionEngine(); + + virtual QList getConfigurations(bool *ok = 0) = 0; + virtual QString getInterfaceFromId(const QString &id) = 0; + virtual bool hasIdentifier(const QString &id) = 0; + + virtual QString bearerName(const QString &id) = 0; + + virtual void connectToId(const QString &id) = 0; + virtual void disconnectFromId(const QString &id) = 0; + + virtual void requestUpdate() = 0; + +Q_SIGNALS: + void configurationsChanged(); + void connectionError(const QString &id, QNetworkSessionEngine::ConnectionError error); +}; + +QTM_END_NAMESPACE + +#endif diff --git a/src/network/bearer/qnetworksessionengine_win_p.h b/src/network/bearer/qnetworksessionengine_win_p.h new file mode 100644 index 0000000..cf01719 --- /dev/null +++ b/src/network/bearer/qnetworksessionengine_win_p.h @@ -0,0 +1,145 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 QNETWORKSESSIONENGINE_WIN_P_H +#define QNETWORKSESSIONENGINE_WIN_P_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 +#include +#undef interface +#include + +#ifndef NS_NLA + +#define NS_NLA 15 + +enum NLA_BLOB_DATA_TYPE { + NLA_RAW_DATA = 0, + NLA_INTERFACE = 1, + NLA_802_1X_LOCATION = 2, + NLA_CONNECTIVITY = 3, + NLA_ICS = 4 +}; + +enum NLA_CONNECTIVITY_TYPE { + NLA_NETWORK_AD_HOC = 0, + NLA_NETWORK_MANAGED = 1, + NLA_NETWORK_UNMANAGED = 2, + NLA_NETWORK_UNKNOWN = 3 +}; + +enum NLA_INTERNET { + NLA_INTERNET_UNKNOWN = 0, + NLA_INTERNET_NO = 1, + NLA_INTERNET_YES = 2 +}; + +struct NLA_BLOB { + struct { + NLA_BLOB_DATA_TYPE type; + DWORD dwSize; + DWORD nextOffset; + } header; + + union { + // NLA_RAW_DATA + CHAR rawData[1]; + + // NLA_INTERFACE + struct { + DWORD dwType; + DWORD dwSpeed; + CHAR adapterName[1]; + } interfaceData; + + // NLA_802_1X_LOCATION + struct { + CHAR information[1]; + } locationData; + + // NLA_CONNECTIVITY + struct { + NLA_CONNECTIVITY_TYPE type; + NLA_INTERNET internet; + } connectivity; + + // NLA_ICS + struct { + struct { + DWORD speed; + DWORD type; + DWORD state; + WCHAR machineName[256]; + WCHAR sharedAdapterName[256]; + } remote; + } ICS; + } data; +}; +#endif + +enum NDIS_MEDIUM { + NdisMedium802_3 = 0, +}; + +enum NDIS_PHYSICAL_MEDIUM { + NdisPhysicalMediumWirelessLan = 1, + NdisPhysicalMediumBluetooth = 10, + NdisPhysicalMediumWiMax = 12, +}; + +#define OID_GEN_MEDIA_SUPPORTED 0x00010103 +#define OID_GEN_PHYSICAL_MEDIUM 0x00010202 + +#define IOCTL_NDIS_QUERY_GLOBAL_STATS \ + CTL_CODE(FILE_DEVICE_PHYSICAL_NETCARD, 0, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) + +#endif // QNETWORKSESSIONENGINE_WIN_P_H diff --git a/src/network/bearer/qnlaengine_win.cpp b/src/network/bearer/qnlaengine_win.cpp new file mode 100644 index 0000000..b606ef4 --- /dev/null +++ b/src/network/bearer/qnlaengine_win.cpp @@ -0,0 +1,592 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 "qnlaengine_win_p.h" +#include "qnetworkconfiguration_p.h" + +#include +#include +#include +#include + +#include + +#include "qnetworksessionengine_win_p.h" + +QTM_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC(QNlaEngine, nlaEngine) + +QWindowsSockInit::QWindowsSockInit() +: version(0) +{ + //### should we try for 2.2 on all platforms ?? + WSAData wsadata; + + // IPv6 requires Winsock v2.0 or better. + if (WSAStartup(MAKEWORD(2,0), &wsadata) != 0) { + qWarning("QBearerManagementAPI: WinSock v2.0 initialization failed."); + } else { + version = 0x20; + } +} + +QWindowsSockInit::~QWindowsSockInit() +{ + WSACleanup(); +} + +#ifdef BEARER_MANAGEMENT_DEBUG +static void printBlob(NLA_BLOB *blob) +{ + qDebug() << "==== BEGIN NLA_BLOB ===="; + + qDebug() << "type:" << blob->header.type; + qDebug() << "size:" << blob->header.dwSize; + qDebug() << "next offset:" << blob->header.nextOffset; + + switch (blob->header.type) { + case NLA_RAW_DATA: + qDebug() << "Raw Data"; + qDebug() << '\t' << blob->data.rawData; + break; + case NLA_INTERFACE: + qDebug() << "Interface"; + qDebug() << "\ttype:" << blob->data.interfaceData.dwType; + qDebug() << "\tspeed:" << blob->data.interfaceData.dwSpeed; + qDebug() << "\tadapter:" << blob->data.interfaceData.adapterName; + break; + case NLA_802_1X_LOCATION: + qDebug() << "802.1x Location"; + qDebug() << '\t' << blob->data.locationData.information; + break; + case NLA_CONNECTIVITY: + qDebug() << "Connectivity"; + qDebug() << "\ttype:" << blob->data.connectivity.type; + qDebug() << "\tinternet:" << blob->data.connectivity.internet; + break; + case NLA_ICS: + qDebug() << "ICS"; + qDebug() << "\tspeed:" << blob->data.ICS.remote.speed; + qDebug() << "\ttype:" << blob->data.ICS.remote.type; + qDebug() << "\tstate:" << blob->data.ICS.remote.state; + qDebug() << "\tmachine name:" << blob->data.ICS.remote.machineName; + qDebug() << "\tshared adapter name:" << blob->data.ICS.remote.sharedAdapterName; + break; + default: + qDebug() << "UNKNOWN BLOB TYPE"; + } + + qDebug() << "===== END NLA_BLOB ====="; +} +#endif + +static QString qGetInterfaceType(const QString &interface) +{ +#ifdef Q_OS_WINCE + Q_UNUSED(interface) +#else + unsigned long oid; + DWORD bytesWritten; + + NDIS_MEDIUM medium; + NDIS_PHYSICAL_MEDIUM physicalMedium; + + HANDLE handle = CreateFile((TCHAR *)QString("\\\\.\\%1").arg(interface).utf16(), 0, + FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); + if (handle == INVALID_HANDLE_VALUE) + return QString(); + + oid = OID_GEN_MEDIA_SUPPORTED; + bytesWritten = 0; + bool result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), + &medium, sizeof(medium), &bytesWritten, 0); + if (!result) { + CloseHandle(handle); + return QString(); + } + + oid = OID_GEN_PHYSICAL_MEDIUM; + bytesWritten = 0; + result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), + &physicalMedium, sizeof(physicalMedium), &bytesWritten, 0); + if (!result) { + CloseHandle(handle); + + if (medium == NdisMedium802_3) + return QLatin1String("Ethernet"); + else + return QString(); + } + + CloseHandle(handle); + + if (medium == NdisMedium802_3) { + switch (physicalMedium) { + case NdisPhysicalMediumWirelessLan: + return QLatin1String("WLAN"); + case NdisPhysicalMediumBluetooth: + return QLatin1String("Bluetooth"); + case NdisPhysicalMediumWiMax: + return QLatin1String("WiMAX"); + default: +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Physical Medium" << physicalMedium; +#endif + return QLatin1String("Ethernet"); + } + } + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << medium << physicalMedium; +#endif + +#endif + + return QString(); +} + +class QNlaThread : public QThread +{ + Q_OBJECT + +public: + QNlaThread(QNlaEngine *parent = 0); + ~QNlaThread(); + + QList getConfigurations(); + + void forceUpdate(); + +protected: + virtual void run(); + +private: + void updateConfigurations(QList &configs); + DWORD parseBlob(NLA_BLOB *blob, QNetworkConfigurationPrivate *cpPriv) const; + QNetworkConfigurationPrivate *parseQuerySet(const WSAQUERYSET *querySet) const; + void fetchConfigurations(); + +signals: + void networksChanged(); + +private: + QMutex mutex; + HANDLE handle; + bool done; + QList fetchedConfigurations; +}; + +QNlaThread::QNlaThread(QNlaEngine *parent) +: QThread(parent), handle(0), done(false) +{ +} + +QNlaThread::~QNlaThread() +{ + mutex.lock(); + + done = true; + + if (handle) { + /* cancel completion event */ + if (WSALookupServiceEnd(handle) == SOCKET_ERROR) + qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); + } + mutex.unlock(); + + wait(); +} + +QList QNlaThread::getConfigurations() +{ + QMutexLocker locker(&mutex); + + QList foundConfigurations; + + for (int i = 0; i < fetchedConfigurations.count(); ++i) { + QNetworkConfigurationPrivate *config = new QNetworkConfigurationPrivate; + config->name = fetchedConfigurations.at(i)->name; + config->isValid = fetchedConfigurations.at(i)->isValid; + config->id = fetchedConfigurations.at(i)->id; + config->state = fetchedConfigurations.at(i)->state; + config->type = fetchedConfigurations.at(i)->type; + config->roamingSupported = fetchedConfigurations.at(i)->roamingSupported; + config->purpose = fetchedConfigurations.at(i)->purpose; + config->internet = fetchedConfigurations.at(i)->internet; + + foundConfigurations.append(config); + } + + return foundConfigurations; +} + +void QNlaThread::forceUpdate() +{ + mutex.lock(); + + if (handle) { + /* cancel completion event */ + if (WSALookupServiceEnd(handle) == SOCKET_ERROR) + qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); + handle = 0; + } + mutex.unlock(); +} + +void QNlaThread::run() +{ + WSAEVENT changeEvent = WSACreateEvent(); + if (changeEvent == WSA_INVALID_EVENT) { + qWarning("WSACreateEvent error %d", WSAGetLastError()); + return; + } + + while (true) { + fetchConfigurations(); + + WSAQUERYSET qsRestrictions; + + memset(&qsRestrictions, 0, sizeof(qsRestrictions)); + qsRestrictions.dwSize = sizeof(qsRestrictions); + qsRestrictions.dwNameSpace = NS_NLA; + + mutex.lock(); + if (done) { + mutex.unlock(); + break; + } + int result = WSALookupServiceBegin(&qsRestrictions, LUP_RETURN_ALL, &handle); + mutex.unlock(); + + if (result == SOCKET_ERROR) { + qWarning("%s: WSALookupServiceBegin error %d", __FUNCTION__, WSAGetLastError()); + break; + } + + WSACOMPLETION completion; + WSAOVERLAPPED overlapped; + + memset(&overlapped, 0, sizeof(overlapped)); + overlapped.hEvent = changeEvent; + + memset(&completion, 0, sizeof(completion)); + completion.Type = NSP_NOTIFY_EVENT; + completion.Parameters.Event.lpOverlapped = &overlapped; + + DWORD bytesReturned = 0; + result = WSANSPIoctl(handle, SIO_NSP_NOTIFY_CHANGE, 0, 0, 0, 0, + &bytesReturned, &completion); + if (result == SOCKET_ERROR) { + int error = WSAGetLastError(); + if (error != WSA_IO_PENDING) { + qWarning("WSANSPIoctl error %d", error); + break; + } + } + +#ifndef Q_OS_WINCE + // Not interested in unrelated IO completion events + // although we also don't want to block them + while (WaitForSingleObjectEx(changeEvent, WSA_INFINITE, true) != WAIT_IO_COMPLETION) {} +#else + WaitForSingleObject(changeEvent, WSA_INFINITE); +#endif + + mutex.lock(); + if (handle) { + result = WSALookupServiceEnd(handle); + if (result == SOCKET_ERROR) { + qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); + mutex.unlock(); + break; + } + handle = 0; + } + mutex.unlock(); + } + + WSACloseEvent(changeEvent); +} + +void QNlaThread::updateConfigurations(QList &configs) +{ + mutex.lock(); + + while (!fetchedConfigurations.isEmpty()) + delete fetchedConfigurations.takeFirst(); + + fetchedConfigurations = configs; + + mutex.unlock(); + + emit networksChanged(); +} + +DWORD QNlaThread::parseBlob(NLA_BLOB *blob, QNetworkConfigurationPrivate *cpPriv) const +{ +#ifdef BEARER_MANAGEMENT_DEBUG + printBlob(blob); +#endif + + switch (blob->header.type) { + case NLA_RAW_DATA: +#ifdef BEARER_MANAGEMENT_DEBUG + qWarning("%s: unhandled header type NLA_RAW_DATA", __FUNCTION__); +#endif + break; + case NLA_INTERFACE: + cpPriv->state = QNetworkConfiguration::Active; + if (QNlaEngine *engine = qobject_cast(parent())) { + engine->configurationInterface[cpPriv->id.toUInt()] = + QString(blob->data.interfaceData.adapterName); + } + break; + case NLA_802_1X_LOCATION: +#ifdef BEARER_MANAGEMENT_DEBUG + qWarning("%s: unhandled header type NLA_802_1X_LOCATION", __FUNCTION__); +#endif + break; + case NLA_CONNECTIVITY: + if (blob->data.connectivity.internet == NLA_INTERNET_YES) + cpPriv->internet = true; + else + cpPriv->internet = false; +#ifdef BEARER_MANAGEMENT_DEBUG + qWarning("%s: unhandled header type NLA_CONNECTIVITY", __FUNCTION__); +#endif + break; + case NLA_ICS: +#ifdef BEARER_MANAGEMENT_DEBUG + qWarning("%s: unhandled header type NLA_ICS", __FUNCTION__); +#endif + break; + default: +#ifdef BEARER_MANAGEMENT_DEBUG + qWarning("%s: unhandled header type %d", __FUNCTION__, blob->header.type); +#endif + ; + } + + return blob->header.nextOffset; +} + +QNetworkConfigurationPrivate *QNlaThread::parseQuerySet(const WSAQUERYSET *querySet) const +{ + QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; + + cpPriv->name = QString::fromWCharArray(querySet->lpszServiceInstanceName); + cpPriv->isValid = true; + cpPriv->id = QString::number(qHash(QLatin1String("NLA:") + cpPriv->name)); + cpPriv->state = QNetworkConfiguration::Defined; + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "size:" << querySet->dwSize; + qDebug() << "service instance name:" << QString::fromUtf16(querySet->lpszServiceInstanceName); + qDebug() << "service class id:" << querySet->lpServiceClassId; + qDebug() << "version:" << querySet->lpVersion; + qDebug() << "comment:" << QString::fromUtf16(querySet->lpszComment); + qDebug() << "namespace:" << querySet->dwNameSpace; + qDebug() << "namespace provider id:" << querySet->lpNSProviderId; + qDebug() << "context:" << QString::fromUtf16(querySet->lpszContext); + qDebug() << "number of protocols:" << querySet->dwNumberOfProtocols; + qDebug() << "protocols:" << querySet->lpafpProtocols; + qDebug() << "query string:" << QString::fromUtf16(querySet->lpszQueryString); + qDebug() << "number of cs addresses:" << querySet->dwNumberOfCsAddrs; + qDebug() << "cs addresses:" << querySet->lpcsaBuffer; + qDebug() << "output flags:" << querySet->dwOutputFlags; +#endif + + if (querySet->lpBlob) { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "blob size:" << querySet->lpBlob->cbSize; + qDebug() << "blob data:" << querySet->lpBlob->pBlobData; +#endif + + DWORD offset = 0; + do { + NLA_BLOB *blob = reinterpret_cast(querySet->lpBlob->pBlobData + offset); + DWORD nextOffset = parseBlob(blob, cpPriv); + if (nextOffset == offset) + break; + else + offset = nextOffset; + } while (offset != 0 && offset < querySet->lpBlob->cbSize); + } + + return cpPriv; +} + +void QNlaThread::fetchConfigurations() +{ + QList foundConfigurations; + + WSAQUERYSET qsRestrictions; + HANDLE hLookup = 0; + + memset(&qsRestrictions, 0, sizeof(qsRestrictions)); + qsRestrictions.dwSize = sizeof(qsRestrictions); + qsRestrictions.dwNameSpace = NS_NLA; + + int result = WSALookupServiceBegin(&qsRestrictions, LUP_RETURN_ALL | LUP_DEEP, &hLookup); + if (result == SOCKET_ERROR) { + qWarning("%s: WSALookupServiceBegin error %d", __FUNCTION__, WSAGetLastError()); + mutex.lock(); + fetchedConfigurations.clear(); + mutex.unlock(); + } + + char buffer[0x10000]; + while (result == 0) { + DWORD bufferLength = sizeof(buffer); + result = WSALookupServiceNext(hLookup, LUP_RETURN_ALL, + &bufferLength, reinterpret_cast(buffer)); + + if (result == SOCKET_ERROR) { + int error = WSAGetLastError(); + + if (error == WSA_E_NO_MORE) + break; + + if (error == WSAEFAULT) { + qDebug() << "buffer not big enough" << bufferLength; + break; + } + + qWarning("WSALookupServiceNext error %d", WSAGetLastError()); + break; + } + + QNetworkConfigurationPrivate *cpPriv = + parseQuerySet(reinterpret_cast(buffer)); + + foundConfigurations.append(cpPriv); + } + + if (hLookup) { + result = WSALookupServiceEnd(hLookup); + if (result == SOCKET_ERROR) { + qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); + } + } + + updateConfigurations(foundConfigurations); +} + +QNlaEngine::QNlaEngine(QObject *parent) +: QNetworkSessionEngine(parent), nlaThread(0) +{ + nlaThread = new QNlaThread(this); + connect(nlaThread, SIGNAL(networksChanged()), + this, SIGNAL(configurationsChanged())); + nlaThread->start(); + + qApp->processEvents(QEventLoop::ExcludeUserInputEvents); +} + +QNlaEngine::~QNlaEngine() +{ + delete nlaThread; +} + +QList QNlaEngine::getConfigurations(bool *ok) +{ + if (ok) + *ok = true; + + return nlaThread->getConfigurations(); +} + +QString QNlaEngine::getInterfaceFromId(const QString &id) +{ + return configurationInterface.value(id.toUInt()); +} + +bool QNlaEngine::hasIdentifier(const QString &id) +{ + if (configurationInterface.contains(id.toUInt())) + return true; + + foreach (QNetworkConfigurationPrivate *cpPriv, nlaThread->getConfigurations()) { + if (cpPriv->id == id) + return true; + } + + return false; +} + +QString QNlaEngine::bearerName(const QString &id) +{ + QString interface = getInterfaceFromId(id); + + if (interface.isEmpty()) + return QString(); + + return qGetInterfaceType(interface); +} + +void QNlaEngine::connectToId(const QString &id) +{ + emit connectionError(id, OperationNotSupported); +} + +void QNlaEngine::disconnectFromId(const QString &id) +{ + emit connectionError(id, OperationNotSupported); +} + +void QNlaEngine::requestUpdate() +{ + nlaThread->forceUpdate(); +} + +QNlaEngine *QNlaEngine::instance() +{ + return nlaEngine(); +} + +#include "qnlaengine_win.moc" +#include "moc_qnlaengine_win_p.cpp" +QTM_END_NAMESPACE + + + diff --git a/src/network/bearer/qnlaengine_win_p.h b/src/network/bearer/qnlaengine_win_p.h new file mode 100644 index 0000000..394b8cf --- /dev/null +++ b/src/network/bearer/qnlaengine_win_p.h @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 QNLAENGINE_P_H +#define QNLAENGINE_P_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 "qnetworksessionengine_p.h" + +#include + +QTM_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; +class QNlaThread; + +class QWindowsSockInit +{ +public: + QWindowsSockInit(); + ~QWindowsSockInit(); + int version; +}; + +class QNlaEngine : public QNetworkSessionEngine +{ + Q_OBJECT + + friend class QNlaThread; + +public: + QNlaEngine(QObject *parent = 0); + ~QNlaEngine(); + + QList getConfigurations(bool *ok = 0); + QString getInterfaceFromId(const QString &id); + bool hasIdentifier(const QString &id); + + QString bearerName(const QString &id); + + void connectToId(const QString &id); + void disconnectFromId(const QString &id); + + void requestUpdate(); + + static QNlaEngine *instance(); + +private: + QWindowsSockInit winSock; + QNlaThread *nlaThread; + QMap configurationInterface; +}; + +QTM_END_NAMESPACE + +#endif diff --git a/src/network/bearer/qnmdbushelper.cpp b/src/network/bearer/qnmdbushelper.cpp new file mode 100644 index 0000000..3b780f6 --- /dev/null +++ b/src/network/bearer/qnmdbushelper.cpp @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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$ +** +****************************************************************************/ + +// this class is for helping qdbus get stuff + +#include "qnmdbushelper_p.h" + +#if !defined(QT_NO_DBUS) && !defined(Q_OS_MAC) +#include + +#include +#include +#include +#include +#endif + +#include + +QTM_BEGIN_NAMESPACE + +void QNmDBusHelper::deviceStateChanged(quint32 state) + { + QDBusMessage msg = this->message(); + if(state == NM_DEVICE_STATE_ACTIVATED + || state == NM_DEVICE_STATE_DISCONNECTED + || state == NM_DEVICE_STATE_UNAVAILABLE + || state == NM_DEVICE_STATE_FAILED) { + emit pathForStateChanged(msg.path(), state); + } + } + +void QNmDBusHelper::slotAccessPointAdded(QDBusObjectPath path) +{ + if(path.path().length() > 2) { + QDBusMessage msg = this->message(); + emit pathForAccessPointAdded(msg.path(), path); + } +} + +void QNmDBusHelper::slotAccessPointRemoved(QDBusObjectPath path) +{ + if(path.path().length() > 2) { + QDBusMessage msg = this->message(); + emit pathForAccessPointRemoved(msg.path(), path); + } +} + +void QNmDBusHelper::slotPropertiesChanged(QMap map) +{ + QDBusMessage msg = this->message(); + QMapIterator i(map); + while (i.hasNext()) { + i.next(); + if( i.key() == "State") { //state only applies to device interfaces + quint32 state = i.value().toUInt(); + if( state == NM_DEVICE_STATE_ACTIVATED + || state == NM_DEVICE_STATE_DISCONNECTED + || state == NM_DEVICE_STATE_UNAVAILABLE + || state == NM_DEVICE_STATE_FAILED) { + emit pathForPropertiesChanged( msg.path(), map); + } + } else if( i.key() == "ActiveAccessPoint") { + // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value().value().path(); + // } else if( i.key() == "Strength") + // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value().toUInt(); + // else + // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value(); + } + } +} + +void QNmDBusHelper::slotSettingsRemoved() +{ + QDBusMessage msg = this->message(); + emit pathForSettingsRemoved(msg.path()); +} + +#include "moc_qnmdbushelper_p.cpp" +QTM_END_NAMESPACE diff --git a/src/network/bearer/qnmdbushelper_p.h b/src/network/bearer/qnmdbushelper_p.h new file mode 100644 index 0000000..f0248dc --- /dev/null +++ b/src/network/bearer/qnmdbushelper_p.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 QNMDBUSHELPERPRIVATE_H +#define QNMDBUSHELPERPRIVATE_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 +#if !defined(QT_NO_DBUS) && !defined(Q_OS_MAC) +#include +#include +#include +#endif + +QTM_BEGIN_NAMESPACE + +#if !defined(QT_NO_DBUS) && !defined(Q_OS_MAC) + +class QNmDBusHelper: public QObject, protected QDBusContext + { + Q_OBJECT + public: + + public slots: + void deviceStateChanged(quint32); + void slotAccessPointAdded( QDBusObjectPath ); + void slotAccessPointRemoved( QDBusObjectPath ); + void slotPropertiesChanged( QMap); + void slotSettingsRemoved(); + +Q_SIGNALS: + void pathForStateChanged(const QString &, quint32); + void pathForAccessPointAdded(const QString &, QDBusObjectPath ); + void pathForAccessPointRemoved(const QString &, QDBusObjectPath ); + void pathForPropertiesChanged(const QString &, QMap); + void pathForSettingsRemoved(const QString &); +}; +#endif + +QTM_END_NAMESPACE + +#endif// QNMDBUSHELPERPRIVATE_H diff --git a/src/network/bearer/qnmwifiengine_unix.cpp b/src/network/bearer/qnmwifiengine_unix.cpp new file mode 100644 index 0000000..f558fa8 --- /dev/null +++ b/src/network/bearer/qnmwifiengine_unix.cpp @@ -0,0 +1,1133 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 "qnmwifiengine_unix_p.h" +#include "qnetworkconfiguration_p.h" +#include + +#include + +#include +#include +#include + +#include + + + +QTM_BEGIN_NAMESPACE +Q_GLOBAL_STATIC(QNmWifiEngine, nmWifiEngine) +typedef QList > QNmSettingsAddressMap; +QTM_END_NAMESPACE + +Q_DECLARE_METATYPE(QTM_PREPEND_NAMESPACE(QNmSettingsAddressMap)) + +QTM_BEGIN_NAMESPACE + +QNmWifiEngine::QNmWifiEngine(QObject *parent) +: QNetworkSessionEngine(parent) +{ + iface = new QNetworkManagerInterface(); + if(!iface->isValid()) { + return; + } + iface->setConnections(); + connect(iface,SIGNAL(deviceAdded(QDBusObjectPath)), + this,SLOT(addDevice(QDBusObjectPath))); + connect(iface,SIGNAL(deviceRemoved(QDBusObjectPath)), + this,SLOT(removeDevice(QDBusObjectPath))); + + QList list = iface->getDevices(); + + foreach(QDBusObjectPath path, list) { + addDevice(path); + } + + QStringList connectionServices; + connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; + connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; + foreach (QString service, connectionServices) { + QNetworkManagerSettings *settingsiface; + settingsiface = new QNetworkManagerSettings(service); + settingsiface->setConnections(); + connect(settingsiface,SIGNAL(newConnection(QDBusObjectPath)), + this,(SLOT(newConnection(QDBusObjectPath)))); + } + + updated = false; +} + +QNmWifiEngine::~QNmWifiEngine() +{ +} + +QString QNmWifiEngine::getNameForConfiguration(QNetworkManagerInterfaceDevice *devIface) +{ + QString newname; + if (devIface->state() == NM_DEVICE_STATE_ACTIVATED) { + QString path = devIface->ip4config().path(); + QNetworkManagerIp4Config * ipIface; + ipIface = new QNetworkManagerIp4Config(path); + newname = ipIface->domains().join(" "); + } + //fallback to interface name + if(newname.isEmpty()) + newname = devIface->interface().name(); + return newname; +} + + +QList QNmWifiEngine::getConfigurations(bool *ok) +{ +// qWarning() << Q_FUNC_INFO << updated; + if (ok) + *ok = false; + + if(!updated) { + foundConfigurations.clear(); + if(knownSsids.isEmpty()) + getKnownSsids(); // list of ssids that have user configurations. + + scanForAccessPoints(); + getActiveConnectionsPaths(); + knownConnections(); + + accessPointConnections(); + +// findConnections(); + //add access points + updated = true; + } + return foundConfigurations; +} + +void QNmWifiEngine::findConnections() +{ + QList list = iface->getDevices(); + + foreach(QDBusObjectPath path, list) { + QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); + + //// eth + switch (devIface->deviceType()) { +// qWarning() << devIface->connectionInterface()->path(); + + case DEVICE_TYPE_802_3_ETHERNET: + { + QString ident; + QNetworkManagerInterfaceDeviceWired *devWiredIface; + devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); + + ident = devWiredIface->hwAddress(); + + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + cpPriv->name = getNameForConfiguration(devIface); + cpPriv->isValid = true; + cpPriv->id = ident; + cpPriv->internet = devWiredIface->carrier(); + + cpPriv->serviceInterface = devIface->interface(); + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + switch (devIface->state()) { + case NM_DEVICE_STATE_UNKNOWN: + case NM_DEVICE_STATE_UNMANAGED: + case NM_DEVICE_STATE_FAILED: + cpPriv->state = (cpPriv->state | QNetworkConfiguration::Undefined); + break; + case NM_DEVICE_STATE_UNAVAILABLE: + cpPriv->state = (cpPriv->state | QNetworkConfiguration::Defined); + break; + case NM_DEVICE_STATE_PREPARE: + case NM_DEVICE_STATE_CONFIG: + case NM_DEVICE_STATE_NEED_AUTH: + case NM_DEVICE_STATE_IP_CONFIG: + case NM_DEVICE_STATE_DISCONNECTED: + { + cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Discovered + | QNetworkConfiguration::Defined); + } + break; + case NM_DEVICE_STATE_ACTIVATED: + cpPriv->state = (cpPriv->state | QNetworkConfiguration::Active ); + break; + default: + cpPriv->state = (cpPriv->state | QNetworkConfiguration::Undefined); + break; + }; + cpPriv->purpose = QNetworkConfiguration::PublicPurpose; + foundConfigurations.append(cpPriv); + configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); + } + break; + case DEVICE_TYPE_802_11_WIRELESS: + { +// QNetworkManagerInterfaceDeviceWireless *devWirelessIface; +// devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); +// +// //// connections +// QStringList connectionServices; +// connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; +// connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; +// +// QString connPath; +// +// foreach (QString service, connectionServices) { +// QString ident; +// QNetworkManagerSettings *settingsiface; +// settingsiface = new QNetworkManagerSettings(service); +// QList list = settingsiface->listConnections(); +// +// foreach(QDBusObjectPath path, list) { //for each connection path +//qWarning() << path.path(); +// ident = path.path(); +// bool addIt = false; +// QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); +// cpPriv->isValid = true; +// cpPriv->id = ident; +// cpPriv->internet = true; +// +// cpPriv->type = QNetworkConfiguration::InternetAccessPoint; +// cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Discovered +// | QNetworkConfiguration::Defined); +// cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; +// +// QNetworkManagerSettingsConnection *sysIface; +// sysIface = new QNetworkManagerSettingsConnection(service, path.path()); +// cpPriv->name = sysIface->getId();//ii.value().toString(); +//qWarning() << cpPriv->name; +// if(sysIface->getType() == DEVICE_TYPE_802_3_ETHERNET/*type == "802-3-ethernet"*/ +// && devIface->deviceType() == DEVICE_TYPE_802_3_ETHERNET) { +// cpPriv->serviceInterface = devIface->interface(); +// addIt = true; +// } else if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS/*type == "802-11-wireless"*/ +// && devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { +// cpPriv->serviceInterface = devIface->interface(); +// addIt = true; +// // get the wifi interface state first.. do we need this? +// // QString activeAPPath = devWirelessIface->activeAccessPoint().path(); +// } +// +// //#if 0 +// foreach(QString conpath, activeConnectionPaths) { +// QNetworkManagerConnectionActive *aConn; +// aConn = new QNetworkManagerConnectionActive(conpath); +// // in case of accesspoint, specificObject will hold the accessPOintObjectPath +// // qWarning() << aConn->connection().path() << aConn->specificObject().path() << aConn->devices().count(); +// if( aConn->connection().path() == ident) { +// +// QList devs = aConn->devices(); +// foreach(QDBusObjectPath device, devs) { +// QNetworkManagerInterfaceDevice *ifaceDevice; +// ifaceDevice = new QNetworkManagerInterfaceDevice(device.path()); +// cpPriv->serviceInterface = ifaceDevice->interface(); +// cpPriv->state = getStateFlag(ifaceDevice->state()); +// //cpPriv->accessPoint = aConn->specificObject().path(); +// +// break; +// } +// } +// } +// //#endif +// // } //end while connection +// if(addIt) { +// foundConfigurations.append(cpPriv); +// configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); +// } +// } +// } //end each connection service +// +// // ////////////// AccessPoints +//// QList apList = devWirelessIface->getAccessPoints(); +////// qWarning() << apList.count(); +//// foreach(QDBusObjectPath path, apList) { +//// QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); +//// cpPriv = addAccessPoint( devIface->connectionInterface()->path(), path); +//// if(cpPriv->isValid) { +//// foundConfigurations.append(cpPriv); +//// } +//// } + } // end DEVICE_TYPE_802_11_WIRELESS + break; + }; + } //end foreach device +} + +void QNmWifiEngine::knownConnections() +{ +// qWarning() << Q_FUNC_INFO; + //// connections + QStringList connectionServices; + connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; + connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; + + QString connPath; + + foreach (QString service, connectionServices) { + QString ident; + QNetworkManagerSettings *settingsiface; + settingsiface = new QNetworkManagerSettings(service); + QList list = settingsiface->listConnections(); + +// qWarning() <setConnections(); + connect(sysIface, SIGNAL(removed(QString)), + this,SLOT(settingsConnectionRemoved(QString))); + + cpPriv->name = sysIface->getId(); + cpPriv->isValid = true; + cpPriv->id = sysIface->getUuid(); +// cpPriv->id = ident; + cpPriv->internet = true; + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; +//qWarning() << cpPriv->name; + cpPriv->state = getStateForId(cpPriv->id); + + cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; + + if(sysIface->getType() == DEVICE_TYPE_802_3_ETHERNET) { + QString mac = sysIface->getMacAddress(); + if(!mac.length() > 2) { + qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXX" << mac << "type ethernet"; + QString devPath; + devPath = deviceConnectionPath(mac); + + // qWarning() << Q_FUNC_INFO << devPath; + QNetworkManagerInterfaceDevice *devIface; + devIface = new QNetworkManagerInterfaceDevice(devPath); + cpPriv->serviceInterface = devIface->interface(); + QNetworkManagerInterfaceDeviceWired *devWiredIface; + devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); + cpPriv->internet = devWiredIface->carrier(); + + // use this mac addy + } else { + cpPriv->serviceInterface = getBestInterface( DEVICE_TYPE_802_3_ETHERNET, cpPriv->id); + } + + cpPriv->internet = true;//sysIface->isAutoConnect(); + + addIt = true; + } else if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS) { + QString mac = sysIface->getMacAddress();; + if(!mac.length() > 2) { + qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXX" << mac << "type wireless"; + QString devPath; + devPath = deviceConnectionPath(mac); +// qWarning() << Q_FUNC_INFO << devPath; + + QNetworkManagerInterfaceDevice *devIface; + devIface = new QNetworkManagerInterfaceDevice(devPath); + cpPriv->serviceInterface = devIface->interface(); + // use this mac addy + } else { + cpPriv->serviceInterface = getBestInterface( DEVICE_TYPE_802_11_WIRELESS, cpPriv->id); + } + // cpPriv->serviceInterface = devIface->interface(); + addIt = true; + // get the wifi interface state first.. do we need this? + // QString activeAPPath = devWirelessIface->activeAccessPoint().path(); + } + if(addIt) { + foundConfigurations.append(cpPriv); + configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); + } + } //end each connection service + } +} + +void QNmWifiEngine::accessPointConnections() +{ + //qWarning() << Q_FUNC_INFO; + QList list = iface->getDevices(); + foreach(QDBusObjectPath path, list) { + QNetworkManagerInterfaceDevice *devIface; + devIface = new QNetworkManagerInterfaceDevice(path.path()); + if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { + QList apList = availableAccessPoints.uniqueKeys(); + + QList::const_iterator i; + for (i = apList.constBegin(); i != apList.constEnd(); ++i) { + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + cpPriv = addAccessPoint( devIface->connectionInterface()->path(), availableAccessPoints[*i]); + if(cpPriv->isValid) { + foundConfigurations.append(cpPriv); + // qWarning() << "adding" << cpPriv->name << "to things"; + configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); + } + } + } + } +} + +QString QNmWifiEngine::getInterfaceFromId(const QString &id) +{ + return configurationInterface.value(id); +} + +bool QNmWifiEngine::hasIdentifier(const QString &id) +{ + if (configurationInterface.contains(id)) + return true; + foreach (QNetworkConfigurationPrivate *cpPriv, getConfigurations()) { + if (cpPriv->id == id) + return true; + } + return false; +} + +QString QNmWifiEngine::bearerName(const QString &id) +{ + QString interface = getInterfaceFromId(id); + + QList list = iface->getDevices(); + foreach(QDBusObjectPath path, list) { + QNetworkManagerInterfaceDevice *devIface; + devIface = new QNetworkManagerInterfaceDevice(path.path()); + if(interface == devIface->interface().name()) { + switch(devIface->deviceType()) { + case DEVICE_TYPE_802_3_ETHERNET/*NM_DEVICE_TYPE_ETHERNET*/: + return QLatin1String("Ethernet"); + break; + case DEVICE_TYPE_802_11_WIRELESS/*NM_DEVICE_TYPE_WIFI*/: + return QLatin1String("WLAN"); + break; + case DEVICE_TYPE_GSM/*NM_DEVICE_TYPE_GSM*/: + return QLatin1String("2G"); + break; + case DEVICE_TYPE_CDMA/*NM_DEVICE_TYPE_CDMA*/: + return QLatin1String("CDMA2000"); + break; + default: + break; + }; + } + } + return QString(); +} + +void QNmWifiEngine::connectToId(const QString &id) +{ +// qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << __FUNCTION__ << id; + activatingConnectionPath = id; + QStringList connectionSettings = getConnectionPathForId(id); + if(connectionSettings.isEmpty()) { + emit connectionError(id, OperationNotSupported); + return; + } + + QDBusObjectPath connectionPath(connectionSettings.at(1)); + QString interface = getInterfaceFromId(id); + + interface = QNetworkInterface::interfaceFromName(interface).hardwareAddress().toLower(); + QString devPath; + devPath = deviceConnectionPath(interface); + QDBusObjectPath devicePath(devPath); + + iface = new QNetworkManagerInterface(); + iface->activateConnection( + connectionSettings.at(0), + connectionPath, + devicePath, + connectionPath); + + connect(iface, SIGNAL(activationFinished(QDBusPendingCallWatcher*)), + this, SLOT(slotActivationFinished(QDBusPendingCallWatcher*))); +} + +void QNmWifiEngine::disconnectFromId(const QString &id) +{ + QString activeConnectionPath = getActiveConnectionPath(id); + //qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << __FUNCTION__ << id << activeConnectionPath ; + + if (!activeConnectionPath.isEmpty()) { + QNetworkManagerConnectionActive *activeCon; + activeCon = new QNetworkManagerConnectionActive(activeConnectionPath); + QNetworkManagerSettingsConnection *settingsCon; + settingsCon = new QNetworkManagerSettingsConnection(activeCon->serviceName(), activeCon->connection().path()); + + if(settingsCon->isAutoConnect()) { +// qWarning() << id << "is autoconnect"; + emit connectionError(id, OperationNotSupported); + //unsupported + } else { +// qWarning() <deactivateConnection(dbpath); + activatingConnectionPath = ""; + } + } +} + +void QNmWifiEngine::requestUpdate() +{ + updated = false; + knownSsids.clear(); + availableAccessPoints.clear(); + emitConfigurationsChanged(); +} + +QNmWifiEngine *QNmWifiEngine::instance() +{ + QDBusConnection dbusConnection = QDBusConnection::systemBus(); + if (dbusConnection.isConnected()) { + QDBusConnectionInterface *dbiface = dbusConnection.interface(); + QDBusReply reply = dbiface->isServiceRegistered("org.freedesktop.NetworkManager"); + if (reply.isValid() && reply.value()) + return nmWifiEngine(); + } + + return 0; +} + +void QNmWifiEngine::getKnownSsids() +{ + QStringList connectionServices; + connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; + connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; +//qWarning() << Q_FUNC_INFO; + foreach (QString service, connectionServices) { + QNetworkManagerSettings *settingsiface; + settingsiface = new QNetworkManagerSettings(service); + QList list = settingsiface->listConnections(); + foreach(QDBusObjectPath path, list) { + QNetworkManagerSettingsConnection *sysIface; + sysIface = new QNetworkManagerSettingsConnection(service, path.path()); +// qWarning() << sysIface->getSsid(); + knownSsids << sysIface->getSsid(); + } + } +} + +void QNmWifiEngine::getActiveConnectionsPaths() +{ +// qWarning() << Q_FUNC_INFO; + QNetworkManagerInterface *dbIface; + activeConnectionPaths.clear(); + dbIface = new QNetworkManagerInterface; + QList connections = dbIface->activeConnections(); + + foreach(QDBusObjectPath conpath, connections) { + activeConnectionPaths << conpath.path(); +// qWarning() << __FUNCTION__ << conpath.path() << activeConnectionPaths.count(); + + QNetworkManagerConnectionActive *activeConn; + activeConn = new QNetworkManagerConnectionActive(conpath.path()); + +// qWarning() << activeConn->connection().path() /*<< activeConn->specificObject().path() */<< activeConn->devices()[0].path(); + + } +} + +QNetworkConfigurationPrivate * QNmWifiEngine::addAccessPoint( const QString &iPath, QDBusObjectPath path) +{ //foreach accessPoint + //qWarning() << Q_FUNC_INFO << iPath << path.path(); + + QNetworkManagerInterfaceDevice *devIface; + devIface = new QNetworkManagerInterfaceDevice(iPath); + QNetworkManagerInterfaceDeviceWireless *devWirelessIface; + devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(iPath); + + QString activeAPPath = devWirelessIface->activeAccessPoint().path(); + + QNetworkManagerInterfaceAccessPoint *accessPointIface; + accessPointIface = new QNetworkManagerInterfaceAccessPoint(path.path()); + + QString ident = accessPointIface->connectionInterface()->path(); + quint32 nmState = devIface->state(); + + QString ssid = accessPointIface->ssid(); + QString hwAddy = accessPointIface->hwAddress(); + QString sInterface = devIface->interface().name(); + + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + bool addIt = true; + //qWarning() << availableAccessPoints.count() << ssid; + +// if(availableAccessPoints.contains(ssid)) { +// addIt = false; +// +// } +// foreach (QNetworkConfigurationPrivate *cpPriv, foundConfigurations) { +// if (cpPriv->name == ssid) { //weed out duplicate ssid's ?? +// addIt = false; +// break; +// } +// } + + if(addIt) { + + cpPriv->name = ssid; + cpPriv->isValid = true; + cpPriv->id = ident; + cpPriv->internet = true; + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + cpPriv->serviceInterface = devIface->interface(); + + //qWarning() <<__FUNCTION__ << ssid; + + cpPriv->state = getAPState(nmState, knownSsids.contains(cpPriv->name)); + + if(activeAPPath == accessPointIface->connectionInterface()->path()) { + cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Active); + } + if(accessPointIface->flags() == NM_802_11_AP_FLAGS_PRIVACY) + cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; + else + cpPriv->purpose = QNetworkConfiguration::PublicPurpose; + return cpPriv; + } else { + cpPriv->isValid = false; + } + return cpPriv; +} + + + QNetworkConfiguration::StateFlags QNmWifiEngine::getAPState(qint32 nmState, bool isKnown) +{ + QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined; +//qWarning() << nmState << knownSsids; + // this is the state of the wifi device interface + if(isKnown) + state = ( QNetworkConfiguration::Defined); + + switch(nmState) { //device interface state, not AP state + case NM_DEVICE_STATE_UNKNOWN: + case NM_DEVICE_STATE_UNMANAGED: + case NM_DEVICE_STATE_UNAVAILABLE: + state = (QNetworkConfiguration::Undefined); + break; + case NM_DEVICE_STATE_DISCONNECTED: + { + if(isKnown) + state = ( state | QNetworkConfiguration::Discovered); + } + break; + case NM_DEVICE_STATE_PREPARE: + case NM_DEVICE_STATE_CONFIG: + case NM_DEVICE_STATE_NEED_AUTH: + case NM_DEVICE_STATE_IP_CONFIG: + if(isKnown) + state = ( state | QNetworkConfiguration::Discovered); + break; + case NM_DEVICE_STATE_ACTIVATED: + { + if(isKnown) + state = ( state | QNetworkConfiguration::Discovered); + } + break; + }; + return state; +} + +QString QNmWifiEngine::getActiveConnectionPath(const QString &id) +{ + //qWarning() << Q_FUNC_INFO << id; + QStringList connectionSettings = getConnectionPathForId(id); + //qWarning() << Q_FUNC_INFO << id << connectionSettings.count(); + QNetworkManagerInterface * ifaceD; + ifaceD = new QNetworkManagerInterface(); + QList connections = ifaceD->activeConnections(); + foreach(QDBusObjectPath path, connections) { + QNetworkManagerConnectionActive *conDetailsD; + conDetailsD = new QNetworkManagerConnectionActive( path.path()); + if(conDetailsD->connection().path() == connectionSettings.at(1) + && conDetailsD->serviceName() == connectionSettings.at(0)) + return path.path(); + } + return QString(); +} + + QNetworkConfiguration::StateFlags QNmWifiEngine::getStateFlag(quint32 nmstate) + { +// qWarning() << Q_FUNC_INFO << nmstate; + QNetworkConfiguration::StateFlags flag; + switch (nmstate) { + case NM_DEVICE_STATE_UNKNOWN: + case NM_DEVICE_STATE_FAILED: + case NM_DEVICE_STATE_UNMANAGED: + flag = (QNetworkConfiguration::Undefined); + break; + case NM_DEVICE_STATE_PREPARE: + case NM_DEVICE_STATE_CONFIG: + case NM_DEVICE_STATE_NEED_AUTH: + case NM_DEVICE_STATE_IP_CONFIG: + case NM_DEVICE_STATE_UNAVAILABLE: + flag = (QNetworkConfiguration::Defined); + break; + case NM_DEVICE_STATE_DISCONNECTED: + flag = ( flag | QNetworkConfiguration::Discovered ); + break; + case NM_DEVICE_STATE_ACTIVATED: + { + flag = ( flag | QNetworkConfiguration::Discovered + | QNetworkConfiguration::Active ); + } + break; + default: + flag = ( QNetworkConfiguration::Defined); + break; + }; + return flag; + } + +void QNmWifiEngine::updateDeviceInterfaceState(const QString &/*path*/, quint32 nmState) +{ +// qWarning() << Q_FUNC_INFO << path << nmState; + + if(nmState == NM_DEVICE_STATE_ACTIVATED + || nmState == NM_DEVICE_STATE_DISCONNECTED + || nmState == NM_DEVICE_STATE_UNAVAILABLE + || nmState == NM_DEVICE_STATE_FAILED) { + +/* InterfaceLookupError = 0, + ConnectError, + OperationNotSupported, + DisconnectionError, +*/ +// qWarning() << Q_FUNC_INFO << ident; + QNetworkConfiguration::StateFlags state = (QNetworkConfiguration::Defined); + switch (nmState) { + case NM_DEVICE_STATE_UNKNOWN: + case NM_DEVICE_STATE_FAILED: + state = (QNetworkConfiguration::Undefined); + emit connectionError(activatingConnectionPath, ConnectError); + requestUpdate(); +// qWarning() << Q_FUNC_INFO; + break; + case NM_DEVICE_STATE_UNAVAILABLE: + state = (QNetworkConfiguration::Defined); +// emit connectionError(activatingConnectionPath, ConnectError); + requestUpdate(); + break; + case NM_DEVICE_STATE_DISCONNECTED: + state = ( state | QNetworkConfiguration::Discovered ); + requestUpdate(); + break; + case NM_DEVICE_STATE_ACTIVATED: + { + state = ( state | QNetworkConfiguration::Discovered + | QNetworkConfiguration::Active ); + requestUpdate(); + } + break; + default: + state = ( QNetworkConfiguration::Defined); + break; + }; + } +} + +void QNmWifiEngine::addDevice(QDBusObjectPath path) +{ + //qWarning() << Q_FUNC_INFO << path.path(); + QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); + devIface->setConnections(); + connect(devIface,SIGNAL(stateChanged(const QString &, quint32)), + this, SLOT(updateDeviceInterfaceState(const QString&, quint32))); + + if(!devicePaths.contains(path.path())) + devicePaths << path.path(); + + switch(devIface->deviceType()) { + case DEVICE_TYPE_802_3_ETHERNET: + { + QNetworkManagerInterfaceDeviceWired * devWiredIface; + devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); + devWiredIface->setConnections(); + connect(devWiredIface, SIGNAL(propertiesChanged(const QString &,QMap)), + this,SLOT(cmpPropertiesChanged( const QString &, QMap))); + requestUpdate(); + } + break; + case DEVICE_TYPE_802_11_WIRELESS: + { + QNetworkManagerInterfaceDeviceWireless *devWirelessIface; + devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); + devWirelessIface->setConnections(); + + connect(devWirelessIface, SIGNAL(propertiesChanged(const QString &,QMap)), + this,SLOT(cmpPropertiesChanged( const QString &, QMap))); + + connect(devWirelessIface, SIGNAL(accessPointAdded(const QString &,QDBusObjectPath)), + this,SLOT(accessPointAdded(const QString &,QDBusObjectPath))); + + connect(devWirelessIface, SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath)), + this,SLOT(accessPointRemoved(const QString &,QDBusObjectPath))); + requestUpdate(); + + } + break; + default: + break; + }; +} + +void QNmWifiEngine::removeDevice(QDBusObjectPath /*path*/) +{ +// qWarning() << Q_FUNC_INFO << path.path(); +// disconnect(devIface,SIGNAL(stateChanged(const QString &, quint32)), +// this, SLOT(updateDeviceInterfaceState(const QString&, quint32))); +// +// if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { +// // devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); +// // devWirelessIface->setConnections(); +// +// disconnect(devWirelessIface, SIGNAL(propertiesChanged(const QString &,QMap)), +// this,SIGNAL(cmpPropertiesChanged( const QString &, QMap))); +// +// disconnect(devWirelessIface, SIGNAL(accessPointAdded(const QString &,QDBusObjectPath)), +// this,SIGNAL(accessPointAdded(const QString &,QDBusObjectPath))); +// +// disconnect(devWirelessIface, SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath)), +// this,SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath))); +// +// } +} +void QNmWifiEngine::cmpPropertiesChanged(const QString &path, QMap map) +{ + QMapIterator i(map); + while (i.hasNext()) { + i.next(); +// qWarning() << Q_FUNC_INFO << path << i.key() << i.value().toUInt(); + if( i.key() == "State") { //only applies to device interfaces + updateDeviceInterfaceState(path, i.value().toUInt()); + } + if( i.key() == "ActiveAccessPoint") { + } + if( i.key() == "Carrier") { //someone got plugged in + // requestUpdate(); + } + } +} + +void QNmWifiEngine::accessPointRemoved( const QString &aPath, QDBusObjectPath /*oPath*/) +{ + //qWarning() << Q_FUNC_INFO << aPath << oPath.path(); + + if(aPath.contains("devices")) { + requestUpdate(); + } +} + +void QNmWifiEngine::accessPointAdded( const QString &aPath, QDBusObjectPath oPath) +{ + //qWarning() << Q_FUNC_INFO << aPath << oPath.path(); + + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + cpPriv = addAccessPoint( aPath, oPath); + requestUpdate(); +} + +QNetworkConfiguration::StateFlags QNmWifiEngine::getStateForId(const QString &id) +{ + //qWarning() << Q_FUNC_INFO << id; + bool isAvailable = false; + QStringList conPath = getConnectionPathForId(id); + QString aconpath = getActiveConnectionPath(id); + + //qWarning() << Q_FUNC_INFO << id << aconpath; + + if(!aconpath.isEmpty()) { + //active connection + QNetworkManagerConnectionActive *aConn; + aConn = new QNetworkManagerConnectionActive(aconpath); + + QList devs = aConn->devices(); + + foreach(QDBusObjectPath dev, devs) { + //qWarning() << "foreach" << dev.path(); + QNetworkManagerInterfaceDevice *ifaceDevice; + ifaceDevice = new QNetworkManagerInterfaceDevice(dev.path()); + + if(ifaceDevice->deviceType() == DEVICE_TYPE_802_3_ETHERNET) { + + if(isAddressOfConnection(id, ifaceDevice->ip4Address())) { + // this is it! + return getStateFlag(ifaceDevice->state()); + } else { + continue; + } + + if(ifaceDevice->state() == NM_DEVICE_STATE_UNAVAILABLE || + ifaceDevice->state() == NM_DEVICE_STATE_DISCONNECTED) { + isAvailable = true; + + QNetworkManagerInterfaceDeviceWired *devWiredIface; + devWiredIface = new QNetworkManagerInterfaceDeviceWired(ifaceDevice->connectionInterface()->path()); + if(!devWiredIface->carrier()) + return QNetworkConfiguration::Defined; + } //end eth + } else if(ifaceDevice->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { + qWarning() << "FIXME!!!!!!!!!!!!!!!!!"; + } + + return getStateFlag(ifaceDevice->state()); + } + } else { + // not active + //qWarning() << Q_FUNC_INFO << "Not active"; + QNetworkManagerSettingsConnection *sysIface; + sysIface = new QNetworkManagerSettingsConnection(conPath.at(0),conPath.at(1)); + if(sysIface->isValid()) { + if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS) { + QString ssid = sysIface->getSsid(); + bool ok = false; + + if(knownSsids.contains(ssid, Qt::CaseSensitive)) { + foreach(QString onessid, knownSsids) { + // qWarning() << ssid << onessid; + if(onessid == ssid && availableAccessPoints.contains(ssid)) { + // qWarning() < devices = aConn->devices(); + foreach(QDBusObjectPath device, devices) { + QNetworkManagerInterfaceDevice *ifaceDevice; + ifaceDevice = new QNetworkManagerInterfaceDevice(device.path()); + if(ifaceDevice->ip4Address() == ipaddress) { + return true; + } + } + return false; +} + +QNetworkInterface QNmWifiEngine::getBestInterface( quint32 type, const QString &id) +{ + // check active connections first. + QStringList conIdPath = getConnectionPathForId(id); +// qWarning() << Q_FUNC_INFO << id << conIdPath; + + QNetworkInterface interface; + foreach(QString conpath, activeConnectionPaths) { + QNetworkManagerConnectionActive *aConn; + aConn = new QNetworkManagerConnectionActive(conpath); + + if(aConn->connection().path() == conIdPath.at(1) + && aConn->serviceName() == conIdPath.at(0)) { + + QList devs = aConn->devices(); + QNetworkManagerInterfaceDevice *ifaceDevice; + ifaceDevice = new QNetworkManagerInterfaceDevice(devs[0].path()); //just take the first one + interface = ifaceDevice->interface(); + return interface; + } + } + +//try guessing + QList list = iface->getDevices(); + foreach(QDBusObjectPath path, list) { + QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); + if(devIface->deviceType() == type /*&& devIface->managed()*/) { + interface = devIface->interface(); + if(devIface->state() == NM_STATE_DISCONNECTED) { + return interface; + } + } + } + return interface; +} + +quint64 QNmWifiEngine::receivedDataForId(const QString &id) const +{ + if(configurationInterface.count() > 1) + return 0; + quint64 result = 0; + + QString devFile; + devFile = configurationInterface.value(id); + QFile rx("/sys/class/net/"+devFile+"/statistics/rx_bytes"); + if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream in(&rx); + in >> result; + rx.close(); + } + return result; +} + +quint64 QNmWifiEngine::sentDataForId(const QString &id) const +{ + if(configurationInterface.count() > 1) + return 0; + quint64 result = 0; + QString devFile; + devFile = configurationInterface.value(id); + + QFile tx("/sys/class/net/"+devFile+"/statistics/tx_bytes"); + if(tx.exists() && tx.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream in(&tx); + in >> result; + tx.close(); + } + return result; +} + +void QNmWifiEngine::newConnection(QDBusObjectPath /*path*/) +{ + //qWarning() << Q_FUNC_INFO; + requestUpdate(); +} + +void QNmWifiEngine::settingsConnectionRemoved(const QString &/*path*/) +{ + //qWarning() << Q_FUNC_INFO; + requestUpdate(); +} + +void QNmWifiEngine::slotActivationFinished(QDBusPendingCallWatcher *openCall) +{ + QDBusPendingReply reply = *openCall; + if (reply.isError()) { + qWarning() <<"Error" << reply.error().name() << reply.error().message() + < list = iface->getDevices(); + + foreach(QDBusObjectPath path, list) { + QNetworkManagerInterfaceDevice *devIface; + devIface = new QNetworkManagerInterfaceDevice(path.path()); + + if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { + +// qWarning() << devIface->connectionInterface()->path(); + + QNetworkManagerInterfaceDeviceWireless *devWirelessIface; + devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); + ////////////// AccessPoints + QList apList = devWirelessIface->getAccessPoints(); + + foreach(QDBusObjectPath path, apList) { + QNetworkManagerInterfaceAccessPoint *accessPointIface; + accessPointIface = new QNetworkManagerInterfaceAccessPoint(path.path()); + QString ssid = accessPointIface->ssid(); + availableAccessPoints.insert(ssid, path); + } + } + } +} + +QString QNmWifiEngine::deviceConnectionPath(const QString &mac) +{ +// qWarning() << __FUNCTION__ << mac; + QString newMac = mac; + newMac = newMac.replace(":","_").toLower(); + //device object path might not contain just mac address + //might contain extra numbers on the end. thanks HAL + foreach(QString device, devicePaths) { + if(device.contains(newMac)) { + newMac = device; + break; + } + } + return newMac; +} + +QStringList QNmWifiEngine::getConnectionPathForId(const QString &uuid) +{ + QStringList connectionServices; + connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; + connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; +//qWarning() << Q_FUNC_INFO; + foreach (QString service, connectionServices) { + QNetworkManagerSettings *settingsiface; + settingsiface = new QNetworkManagerSettings(service); + QList list = settingsiface->listConnections(); + foreach(QDBusObjectPath path, list) { + QNetworkManagerSettingsConnection *sysIface; + sysIface = new QNetworkManagerSettingsConnection(service, path.path()); +// qWarning() << uuid << sysIface->getUuid(); + if(sysIface->getUuid() == uuid) { +// qWarning() <<__FUNCTION__ << service << sysIface->getId() << sysIface->connectionInterface()->path(); + return QStringList() << service << sysIface->connectionInterface()->path(); + } + } + } + return QStringList(); +} + +#include "moc_qnmwifiengine_unix_p.cpp" + +QTM_END_NAMESPACE + diff --git a/src/network/bearer/qnmwifiengine_unix_p.h b/src/network/bearer/qnmwifiengine_unix_p.h new file mode 100644 index 0000000..1287800 --- /dev/null +++ b/src/network/bearer/qnmwifiengine_unix_p.h @@ -0,0 +1,164 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 QNMWIFIENGINE_P_H +#define QNMWIFIENGINE_P_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 + +#include +#include +#include +#include + +#include "qnetworksessionengine_p.h" +#include +#include +#include + + + +QTM_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; + +class QNmWifiEngine : public QNetworkSessionEngine +{ + Q_OBJECT + +public: + QNmWifiEngine(QObject *parent = 0); + ~QNmWifiEngine(); + + QList getConfigurations(bool *ok = 0); + QString getInterfaceFromId(const QString &id); + bool hasIdentifier(const QString &id); + + QString bearerName(const QString &id); + + void connectToId(const QString &id); + void disconnectFromId(const QString &id); + + void requestUpdate(); + + static QNmWifiEngine *instance(); + + QStringList knownSsids; + inline void emitConfigurationsChanged() { emit configurationsChanged(); } + QNetworkConfigurationPrivate * addAccessPoint(const QString &, QDBusObjectPath ); + + QStringList getConnectionPathForId(const QString &uuid); + //QString getConnectionPathForId(const QString &name = QString()); + quint64 sentDataForId(const QString &id) const; + quint64 receivedDataForId(const QString &id) const; + +private: + bool updated; + QString activatingConnectionPath; + QStringList activeConnectionPaths; + + + QMap availableAccessPoints; + void scanForAccessPoints(); + + QStringList devicePaths; + + void getActiveConnectionsPaths(); + void getKnownSsids(); + void accessPointConnections(); + void knownConnections(); + void findConnections(); + QString deviceConnectionPath(const QString &mac); + + QList foundConfigurations; + // QHash > allConfigurations; + + QNetworkManagerInterface *iface; + + QNetworkConfiguration::StateFlags getAPState(qint32 vState, bool isKnown); + QNetworkConfiguration::StateFlags getStateFlag(quint32 nmstate); + + QString getActiveConnectionPath(const QString &identifier); + QString getNameForConfiguration(QNetworkManagerInterfaceDevice *devIface); + + QNetworkConfiguration::StateFlags getStateForId(const QString &id); + + QNetworkInterface getBestInterface(quint32 type, const QString &conPath); + + QMap configurationInterface; + + bool isAddressOfConnection(const QString &conPath, quint32 ipaddress); + +private slots: + void updateDeviceInterfaceState(const QString &, quint32); + void addDevice(QDBusObjectPath path); + void removeDevice(QDBusObjectPath path); + +Q_SIGNALS: + void configurationChanged(const QNetworkConfiguration& config); + void updateAccessPointState(const QString &, quint32); +// void slotActivationFinished(QDBusPendingCallWatcher*); + +private slots: + void accessPointAdded( const QString &aPath, QDBusObjectPath oPath); + void accessPointRemoved( const QString &aPath, QDBusObjectPath oPath); + void cmpPropertiesChanged(const QString &, QMap map); + void newConnection(QDBusObjectPath); + void settingsConnectionRemoved(const QString &); + void slotActivationFinished(QDBusPendingCallWatcher*); +}; + +QTM_END_NAMESPACE + +#endif + + diff --git a/tests/auto/qbearertestcommon.h b/tests/auto/qbearertestcommon.h new file mode 100644 index 0000000..3356bd6 --- /dev/null +++ b/tests/auto/qbearertestcommon.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 QBEARERTESTCOMMON_H +#define QBEARERTESTCOMMON_H + +// Will try to wait for the condition while allowing event processing +#define QTRY_VERIFY(__expr) \ + do { \ + const int __step = 50; \ + const int __timeout = 90000; \ + if (!(__expr)) { \ + QTest::qWait(0); \ + } \ + for (int __i = 0; __i < __timeout && !(__expr); __i+=__step) { \ + QTest::qWait(__step); \ + } \ + QVERIFY(__expr); \ + } while(0) + +// Will try to wait for the condition while allowing event processing +#define QTRY_COMPARE(__expr, __expected) \ + do { \ + const int __step = 50; \ + const int __timeout = 90000; \ + if ((__expr) != (__expected)) { \ + QTest::qWait(0); \ + } \ + for (int __i = 0; __i < __timeout && ((__expr) != (__expected)); __i+=__step) { \ + QTest::qWait(__step); \ + } \ + QCOMPARE(__expr, __expected); \ + } while(0) + +#endif + diff --git a/tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro b/tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro new file mode 100644 index 0000000..0b2ed1a --- /dev/null +++ b/tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro @@ -0,0 +1,15 @@ +SOURCES += tst_qnetworkconfigmanager.cpp +HEADERS += ../qbearertestcommon.h +TARGET = tst_qnetworkconfigurationmanager +CONFIG += testcase + +QT = core network + +INCLUDEPATH += ../../../src/bearer + +include(../../../common.pri) +qtAddLibrary(QtBearer) + +symbian { + TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData +} diff --git a/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp b/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp new file mode 100644 index 0000000..796677d --- /dev/null +++ b/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp @@ -0,0 +1,335 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 +#include "../qbearertestcommon.h" +#include "qnetworkconfiguration.h" +#include "qnetworkconfigmanager.h" + +#ifdef MAEMO +#include +#include +#endif + +QTM_USE_NAMESPACE +class tst_QNetworkConfigurationManager : public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void allConfigurations(); + void defaultConfiguration(); + void configurationFromIdentifier(); + +private: +#ifdef MAEMO + Maemo::IAPConf *iapconf; + Maemo::IAPConf *iapconf2; + Maemo::IAPConf *gprsiap; +#define MAX_IAPS 50 + Maemo::IAPConf *iaps[MAX_IAPS]; + QProcess *icd_stub; +#endif +}; + +void tst_QNetworkConfigurationManager::initTestCase() +{ +#ifdef MAEMO + iapconf = new Maemo::IAPConf("007"); + iapconf->setValue("ipv4_type", "AUTO"); + iapconf->setValue("wlan_wepkey1", "connt"); + iapconf->setValue("wlan_wepdefkey", 1); + iapconf->setValue("wlan_ssid", QByteArray("JamesBond")); + iapconf->setValue("name", "James Bond"); + iapconf->setValue("type", "WLAN_INFRA"); + + gprsiap = new Maemo::IAPConf("This-is-GPRS-IAP"); + gprsiap->setValue("ask_password", false); + gprsiap->setValue("gprs_accesspointname", "internet"); + gprsiap->setValue("gprs_password", ""); + gprsiap->setValue("gprs_username", ""); + gprsiap->setValue("ipv4_autodns", true); + gprsiap->setValue("ipv4_type", "AUTO"); + gprsiap->setValue("sim_imsi", "244070123456789"); + gprsiap->setValue("name", "MI6"); + gprsiap->setValue("type", "GPRS"); + + iapconf2 = new Maemo::IAPConf("osso.net"); + iapconf2->setValue("ipv4_type", "AUTO"); + iapconf2->setValue("wlan_wepkey1", "osso.net"); + iapconf2->setValue("wlan_wepdefkey", 1); + iapconf2->setValue("wlan_ssid", QByteArray("osso.net")); + iapconf2->setValue("name", "osso.net"); + iapconf2->setValue("type", "WLAN_INFRA"); + iapconf2->setValue("wlan_security", "WEP"); + + /* Create large number of IAPs in the gconf and see what happens */ + fflush(stdout); + printf("Creating %d IAPS: ", MAX_IAPS); + for (int i=0; isetValue("name", QString("test-iap-")+num); + iaps[i]->setValue("type", "WLAN_INFRA"); + iaps[i]->setValue("wlan_ssid", QString(QString("test-ssid-")+num).toAscii()); + iaps[i]->setValue("wlan_security", "WPA_PSK"); + iaps[i]->setValue("EAP_wpa_preshared_passphrase", QString("test-passphrase-")+num); + printf("."); + fflush(stdout); + } + printf("\n"); + fflush(stdout); + + icd_stub = new QProcess(this); + icd_stub->start("/usr/bin/icd2_stub.py"); + QTest::qWait(1000); + + // Add a known network to scan list that icd2 stub returns + QProcess dbus_send; + // 007 network + dbus_send.start("dbus-send --type=method_call --system " + "--dest=com.nokia.icd2 /com/nokia/icd2 " + "com.nokia.icd2.testing.add_available_network " + "string:'' uint32:0 string:'' " + "string:WLAN_INFRA uint32:5000011 array:byte:48,48,55"); + dbus_send.waitForFinished(); + + // osso.net network + dbus_send.start("dbus-send --type=method_call --system " + "--dest=com.nokia.icd2 /com/nokia/icd2 " + "com.nokia.icd2.testing.add_available_network " + "string:'' uint32:0 string:'' " + "string:WLAN_INFRA uint32:83886097 array:byte:111,115,115,111,46,110,101,116"); + dbus_send.waitForFinished(); +#endif +} + + +void tst_QNetworkConfigurationManager::cleanupTestCase() +{ +#ifdef MAEMO + iapconf->clear(); + delete iapconf; + iapconf2->clear(); + delete iapconf2; + gprsiap->clear(); + delete gprsiap; + + printf("Deleting %d IAPS : ", MAX_IAPS); + for (int i=0; iclear(); + delete iaps[i]; + printf("."); + fflush(stdout); + } + printf("\n"); + qDebug() << "Deleted" << MAX_IAPS << "IAPs"; + + icd_stub->terminate(); + icd_stub->waitForFinished(); +#endif +} + +void tst_QNetworkConfigurationManager::init() +{ +} + +void tst_QNetworkConfigurationManager::cleanup() +{ +} + +void printConfigurationDetails(const QNetworkConfiguration& p) +{ + qDebug() << p.name() <<": isvalid->" <"<< p.type() << + " roaming->" << p.isRoamingAvailable() << "identifier->" << p.identifier() << + " purpose->" << p.purpose() << " state->" << p.state(); +} + +void tst_QNetworkConfigurationManager::allConfigurations() +{ + QNetworkConfigurationManager manager; + QList preScanConfigs = manager.allConfigurations(); + + foreach(QNetworkConfiguration c, preScanConfigs) + { + QVERIFY2(c.type()!=QNetworkConfiguration::UserChoice, "allConfiguration must not return UserChoice configs"); + } + + QSignalSpy spy(&manager, SIGNAL(updateCompleted())); + manager.updateConfigurations(); //initiate scans + QTRY_VERIFY(spy.count() == 1); //wait for scan to complete + + QList configs = manager.allConfigurations(); + + int all = configs.count(); + qDebug() << "All configurations:" << all; + QVERIFY(all); + foreach(QNetworkConfiguration p, configs) { + QVERIFY(p.isValid()); + printConfigurationDetails(p); + QVERIFY(p.type() != QNetworkConfiguration::Invalid); + QVERIFY(p.type() != QNetworkConfiguration::UserChoice); + } + + configs = manager.allConfigurations(QNetworkConfiguration::Undefined); + int undefined = configs.count(); + QVERIFY(undefined <= all); + qDebug() << "Undefined configurations:" << undefined; + foreach( const QNetworkConfiguration p, configs) { + printConfigurationDetails(p); + QVERIFY(p.state() & QNetworkConfiguration::Undefined); + QVERIFY(!(p.state() & QNetworkConfiguration::Defined)); + } + + //get defined configs only (same as all) + configs = manager.allConfigurations(QNetworkConfiguration::Defined); + int defined = configs.count(); + qDebug() << "Defined configurations:" << defined; + QVERIFY(defined <= all); + foreach( const QNetworkConfiguration p, configs) { + printConfigurationDetails(p); + QVERIFY(p.state() & QNetworkConfiguration::Defined); + QVERIFY(!(p.state() & QNetworkConfiguration::Undefined)); + } + + //get discovered configurations only + configs = manager.allConfigurations(QNetworkConfiguration::Discovered); + int discovered = configs.count(); + //QVERIFY(discovered); + qDebug() << "Discovered configurations:" << discovered; + foreach(const QNetworkConfiguration p, configs) { + printConfigurationDetails(p); + QVERIFY(p.isValid()); + QVERIFY(!(p.state() & QNetworkConfiguration::Undefined)); + QVERIFY(p.state() & QNetworkConfiguration::Defined); + QVERIFY(p.state() & QNetworkConfiguration::Discovered); + } + + //getactive configurations only + configs = manager.allConfigurations(QNetworkConfiguration::Active); + int active = configs.count(); + if (active) + QVERIFY(manager.isOnline()); + else + QVERIFY(!manager.isOnline()); + + //QVERIFY(active); + qDebug() << "Active configurations:" << active; + foreach(const QNetworkConfiguration p, configs) { + printConfigurationDetails(p); + QVERIFY(p.isValid()); + QVERIFY(!(p.state() & QNetworkConfiguration::Undefined)); + QVERIFY(p.state() & QNetworkConfiguration::Active); + QVERIFY(p.state() & QNetworkConfiguration::Discovered); + QVERIFY(p.state() & QNetworkConfiguration::Defined); + } + + QVERIFY(all >= discovered); + QVERIFY(discovered >= active); +} + + +void tst_QNetworkConfigurationManager::defaultConfiguration() +{ + QNetworkConfigurationManager manager; + QSignalSpy spy(&manager, SIGNAL(updateCompleted())); + manager.updateConfigurations(); //initiate scans + QTRY_VERIFY(spy.count() == 1); //wait for scan to complete + + QList configs = manager.allConfigurations(); + QNetworkConfiguration defaultConfig = manager.defaultConfiguration(); + + bool confirm = configs.contains(defaultConfig); + bool isUserChoice = (defaultConfig.type() == QNetworkConfiguration::UserChoice); + + //user choice config is not part of allConfigurations() + QVERIFY(isUserChoice != confirm); + if (!isUserChoice) { + QVERIFY(confirm || !defaultConfig.isValid()); + QVERIFY(!(confirm && !defaultConfig.isValid())); + } else { + QVERIFY(defaultConfig.isValid()); + QCOMPARE(defaultConfig.name(), QString("UserChoice")); + QCOMPARE(defaultConfig.children().count(), 0); + QVERIFY(!defaultConfig.isRoamingAvailable()); + QCOMPARE(defaultConfig.state(), QNetworkConfiguration::Discovered); + QNetworkConfiguration copy = manager.configurationFromIdentifier(defaultConfig.identifier()); + QVERIFY(copy == defaultConfig); + } +} + +void tst_QNetworkConfigurationManager::configurationFromIdentifier() +{ + QNetworkConfigurationManager manager; + QSet allIdentifier; + + //force an update to get maximum number of configs + QSignalSpy spy(&manager, SIGNAL(updateCompleted())); + manager.updateConfigurations(); //initiate scans + QTRY_VERIFY(spy.count() == 1); //wait for scan to complete + + QList configs = manager.allConfigurations(); + + foreach(QNetworkConfiguration c, configs) { + QVERIFY(!allIdentifier.contains(c.identifier())); + allIdentifier.insert(c.identifier()); + + QNetworkConfiguration direct = manager.configurationFromIdentifier(c.identifier()); + QVERIFY(direct.isValid()); + QVERIFY(direct == c); + } + + //assume that there is no item with identifier 'FooBar' + QVERIFY(!allIdentifier.contains("FooBar")); + QNetworkConfiguration invalid = manager.configurationFromIdentifier("FooBar"); + QVERIFY(!invalid.isValid()); +} + + +QTEST_MAIN(tst_QNetworkConfigurationManager) +#include "tst_qnetworkconfigmanager.moc" diff --git a/tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro b/tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro new file mode 100644 index 0000000..61e4097 --- /dev/null +++ b/tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro @@ -0,0 +1,15 @@ +SOURCES += tst_qnetworkconfiguration.cpp +HEADERS += ../qbearertestcommon.h +TARGET = tst_qnetworkconfiguration +CONFIG += testcase + +QT = core network + +INCLUDEPATH += ../../../src/bearer + +include(../../../common.pri) +qtAddLibrary(QtBearer) + +symbian { + TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData +} diff --git a/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp b/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp new file mode 100644 index 0000000..cbb13f3 --- /dev/null +++ b/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp @@ -0,0 +1,303 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 +#include "../qbearertestcommon.h" +#include "qnetworkconfiguration.h" +#include "qnetworkconfigmanager.h" + +#ifdef MAEMO +#include +#include +#endif + +QTM_USE_NAMESPACE +class tst_QNetworkConfiguration : public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + +private slots: + void invalidPoint(); + void comparison(); + void children(); + void isRoamingAvailable(); + +private: +#ifdef MAEMO + Maemo::IAPConf *iapconf; + Maemo::IAPConf *iapconf2; + Maemo::IAPConf *gprsiap; +#define MAX_IAPS 50 + Maemo::IAPConf *iaps[MAX_IAPS]; + QProcess *icd_stub; +#endif +}; + +void tst_QNetworkConfiguration::initTestCase() +{ +#ifdef MAEMO + iapconf = new Maemo::IAPConf("007"); + iapconf->setValue("ipv4_type", "AUTO"); + iapconf->setValue("wlan_wepkey1", "connt"); + iapconf->setValue("wlan_wepdefkey", 1); + iapconf->setValue("wlan_ssid", QByteArray("JamesBond")); + iapconf->setValue("name", "James Bond"); + iapconf->setValue("type", "WLAN_INFRA"); + + iapconf2 = new Maemo::IAPConf("osso.net"); + iapconf2->setValue("ipv4_type", "AUTO"); + iapconf2->setValue("wlan_wepkey1", "osso.net"); + iapconf2->setValue("wlan_wepdefkey", 1); + iapconf2->setValue("wlan_ssid", QByteArray("osso.net")); + iapconf2->setValue("name", "osso.net"); + iapconf2->setValue("type", "WLAN_INFRA"); + iapconf2->setValue("wlan_security", "WEP"); + + gprsiap = new Maemo::IAPConf("This-is-GPRS-IAP"); + gprsiap->setValue("ask_password", false); + gprsiap->setValue("gprs_accesspointname", "internet"); + gprsiap->setValue("gprs_password", ""); + gprsiap->setValue("gprs_username", ""); + gprsiap->setValue("ipv4_autodns", true); + gprsiap->setValue("ipv4_type", "AUTO"); + gprsiap->setValue("sim_imsi", "244070123456789"); + gprsiap->setValue("name", "MI6"); + gprsiap->setValue("type", "GPRS"); + + /* Create large number of IAPs in the gconf and see what happens */ + fflush(stdout); + printf("Creating %d IAPS: ", MAX_IAPS); + for (int i=0; isetValue("name", QString("test-iap-")+num); + iaps[i]->setValue("type", "WLAN_INFRA"); + iaps[i]->setValue("wlan_ssid", QString(QString("test-ssid-")+num).toAscii()); + iaps[i]->setValue("wlan_security", "WPA_PSK"); + iaps[i]->setValue("EAP_wpa_preshared_passphrase", QString("test-passphrase-")+num); + printf("."); + fflush(stdout); + } + printf("\n"); + fflush(stdout); + + icd_stub = new QProcess(this); + icd_stub->start("/usr/bin/icd2_stub.py"); + QTest::qWait(1000); + + // Add a known network to scan list that icd2 stub returns + QProcess dbus_send; + // 007 network + dbus_send.start("dbus-send --type=method_call --system " + "--dest=com.nokia.icd2 /com/nokia/icd2 " + "com.nokia.icd2.testing.add_available_network " + "string:'' uint32:0 string:'' " + "string:WLAN_INFRA uint32:5000011 array:byte:48,48,55"); + dbus_send.waitForFinished(); + + // osso.net network + dbus_send.start("dbus-send --type=method_call --system " + "--dest=com.nokia.icd2 /com/nokia/icd2 " + "com.nokia.icd2.testing.add_available_network " + "string:'' uint32:0 string:'' " + "string:WLAN_INFRA uint32:83886097 array:byte:111,115,115,111,46,110,101,116"); + dbus_send.waitForFinished(); +#endif +} + +void tst_QNetworkConfiguration::cleanupTestCase() +{ +#ifdef MAEMO + iapconf->clear(); + delete iapconf; + iapconf2->clear(); + delete iapconf2; + gprsiap->clear(); + delete gprsiap; + + printf("Deleting %d IAPS : ", MAX_IAPS); + for (int i=0; iclear(); + delete iaps[i]; + printf("."); + fflush(stdout); + } + printf("\n"); + qDebug() << "Deleted" << MAX_IAPS << "IAPs"; + + // Terminate icd2 stub + icd_stub->terminate(); + icd_stub->waitForFinished(); +#endif +} + +void tst_QNetworkConfiguration::invalidPoint() +{ + QNetworkConfiguration pt; + + QVERIFY(pt.name().isEmpty()); + QVERIFY(!pt.isValid()); + QVERIFY(pt.type() == QNetworkConfiguration::Invalid); + QVERIFY(!(pt.state() & QNetworkConfiguration::Defined)); + QVERIFY(!(pt.state() & QNetworkConfiguration::Discovered)); + QVERIFY(!(pt.state() & QNetworkConfiguration::Active)); + QVERIFY(!pt.isRoamingAvailable()); + + QNetworkConfiguration pt2(pt); + QVERIFY(pt2.name().isEmpty()); + QVERIFY(!pt2.isValid()); + QVERIFY(pt2.type() == QNetworkConfiguration::Invalid); + QVERIFY(!(pt2.state() & QNetworkConfiguration::Defined)); + QVERIFY(!(pt2.state() & QNetworkConfiguration::Discovered)); + QVERIFY(!(pt2.state() & QNetworkConfiguration::Active)); + QVERIFY(!pt2.isRoamingAvailable()); + +} + +void tst_QNetworkConfiguration::comparison() +{ + //test copy constructor and assignment operator + //compare invalid connection points + QNetworkConfiguration pt1; + QVERIFY(!pt1.isValid()); + QVERIFY(pt1.type() == QNetworkConfiguration::Invalid); + + QNetworkConfiguration pt2(pt1); + QVERIFY(pt1==pt2); + QVERIFY(!(pt1!=pt2)); + QVERIFY(pt1.name() == pt2.name()); + QVERIFY(pt1.isValid() == pt2.isValid()); + QVERIFY(pt1.type() == pt2.type()); + QVERIFY(pt1.state() == pt2.state()); + QVERIFY(pt1.purpose() == pt2.purpose()); + + + QNetworkConfiguration pt3; + pt3 = pt1; + QVERIFY(pt1==pt3); + QVERIFY(!(pt1!=pt3)); + QVERIFY(pt1.name() == pt3.name()); + QVERIFY(pt1.isValid() == pt3.isValid()); + QVERIFY(pt1.type() == pt3.type()); + QVERIFY(pt1.state() == pt3.state()); + QVERIFY(pt1.purpose() == pt3.purpose()); + + //test case must run on machine that has valid connection points + QNetworkConfigurationManager manager; + QList preScanConfigs = manager.allConfigurations(); + + QSignalSpy spy(&manager, SIGNAL(updateCompleted())); + manager.updateConfigurations(); //initiate scans + QTRY_VERIFY(spy.count() == 1); //wait for scan to complete + + QList configs = manager.allConfigurations(QNetworkConfiguration::Discovered); + QVERIFY(configs.count()); + QNetworkConfiguration defaultConfig = manager.defaultConfiguration(); + QVERIFY(defaultConfig.isValid()); + QVERIFY(defaultConfig.type() != QNetworkConfiguration::Invalid); + QVERIFY(!defaultConfig.name().isEmpty()); + + pt3 = defaultConfig; + QVERIFY(defaultConfig==pt3); + QVERIFY(!(defaultConfig!=pt3)); + QVERIFY(defaultConfig.name() == pt3.name()); + QVERIFY(defaultConfig.isValid() == pt3.isValid()); + QVERIFY(defaultConfig.type() == pt3.type()); + QVERIFY(defaultConfig.state() == pt3.state()); + QVERIFY(defaultConfig.purpose() == pt3.purpose()); +} + +void tst_QNetworkConfiguration::children() +{ + QNetworkConfigurationManager manager; + QList configs = manager.allConfigurations(); + + foreach(QNetworkConfiguration c, configs) + { + if ( c.type() == QNetworkConfiguration::ServiceNetwork ) { + qDebug() << "found service network" << c.name() << c.children().count(); + QVERIFY(c.isValid()); + QList members = c.children(); + foreach(QNetworkConfiguration child, members) { + QVERIFY(child.isValid()); + QVERIFY(configs.contains(child)); + qDebug() << "\t" << child.name(); + } + } + } +} + +void tst_QNetworkConfiguration::isRoamingAvailable() +{ + QNetworkConfigurationManager manager; + QList configs = manager.allConfigurations(); + + //force update to get maximum list + QSignalSpy spy(&manager, SIGNAL(updateCompleted())); + manager.updateConfigurations(); //initiate scans + QTRY_VERIFY(spy.count() == 1); //wait for scan to complete + + foreach(QNetworkConfiguration c, configs) + { + QVERIFY(QNetworkConfiguration::UserChoice != c.type()); + QVERIFY(QNetworkConfiguration::Invalid != c.type()); + if ( c.type() == QNetworkConfiguration::ServiceNetwork ) { + //cannot test flag as some SNAPs may not support roaming anyway + //QVERIFY(c.roamingavailable()) + if ( c.children().count() <= 1 ) + QVERIFY(!c.isRoamingAvailable()); + foreach(QNetworkConfiguration child, c.children()) { + QVERIFY(QNetworkConfiguration::InternetAccessPoint == child.type()); + QCOMPARE(child.children().count(), 0); + } + } else { + QVERIFY(!c.isRoamingAvailable()); + } + } +} + +QTEST_MAIN(tst_QNetworkConfiguration) +#include "tst_qnetworkconfiguration.moc" diff --git a/tests/auto/qnetworksession/lackey/lackey.pro b/tests/auto/qnetworksession/lackey/lackey.pro new file mode 100644 index 0000000..4cb8555 --- /dev/null +++ b/tests/auto/qnetworksession/lackey/lackey.pro @@ -0,0 +1,12 @@ +SOURCES += main.cpp +TARGET = qnetworksessionlackey +INCLUDEPATH += ../../../../src/bearer +DEPENDPATH += ../../../../src/bearer + +QT = core network + +CONFIG+= testcase + +include(../../../../common.pri) + +qtAddLibrary(QtBearer) diff --git a/tests/auto/qnetworksession/lackey/main.cpp b/tests/auto/qnetworksession/lackey/main.cpp new file mode 100644 index 0000000..53f6f4f --- /dev/null +++ b/tests/auto/qnetworksession/lackey/main.cpp @@ -0,0 +1,138 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 +#include +#include +#include +#include +#include + +#include + +QTM_USE_NAMESPACE + + +#define NO_DISCOVERED_CONFIGURATIONS_ERROR 1 +#define SESSION_OPEN_ERROR 2 + +int main(int argc, char** argv) +{ + QCoreApplication app(argc, argv); + + QNetworkConfigurationManager manager; + QList discovered = + manager.allConfigurations(QNetworkConfiguration::Discovered); + + if (discovered.isEmpty()) + return NO_DISCOVERED_CONFIGURATIONS_ERROR; + + // Cannot read/write to processes on WinCE or Symbian. + // Easiest alternative is to use sockets for IPC. + + QLocalSocket oopSocket; + + oopSocket.connectToServer("tst_qnetworksession"); + oopSocket.waitForConnected(-1); + + qDebug() << "Lackey started"; + + QNetworkSession *session = 0; + do { + if (session) { + delete session; + session = 0; + } + + qDebug() << "Discovered configurations:" << discovered.count(); + + if (discovered.isEmpty()) { + qDebug() << "No more configurations"; + break; + } + + qDebug() << "Taking first configuration"; + + QNetworkConfiguration config = discovered.takeFirst(); + if ((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + qDebug() << config.name() << "is active"; + continue; + } + + qDebug() << "Creating session for" << config.name() << config.identifier(); + + session = new QNetworkSession(config); + + QString output = QString("Starting session for %1\n").arg(config.identifier()); + oopSocket.write(output.toAscii()); + oopSocket.waitForBytesWritten(); + + session->open(); + session->waitForOpened(); + } while (!(session && session->isActive())); + + qDebug() << "loop done"; + + if (!session) { + qDebug() << "Could not start session"; + + oopSocket.disconnectFromServer(); + oopSocket.waitForDisconnected(-1); + + return SESSION_OPEN_ERROR; + } + + QString output = QString("Started session for %1\n").arg(session->configuration().identifier()); + oopSocket.write(output.toAscii()); + oopSocket.waitForBytesWritten(); + + oopSocket.waitForReadyRead(); + oopSocket.readLine(); + + session->stop(); + + delete session; + + oopSocket.disconnectFromServer(); + oopSocket.waitForDisconnected(-1); + + return 0; +} diff --git a/tests/auto/qnetworksession/qnetworksession.pro b/tests/auto/qnetworksession/qnetworksession.pro new file mode 100644 index 0000000..14dbb3e --- /dev/null +++ b/tests/auto/qnetworksession/qnetworksession.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS = lackey tst_qnetworksession diff --git a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp new file mode 100644 index 0000000..cbd4c8f --- /dev/null +++ b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp @@ -0,0 +1,873 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 +#include +#include +#include "../../qbearertestcommon.h" +#include +#include + +#ifdef MAEMO +#include +#include +#endif + +QTM_USE_NAMESPACE + +Q_DECLARE_METATYPE(QNetworkConfiguration) +Q_DECLARE_METATYPE(QNetworkSession::State); +Q_DECLARE_METATYPE(QNetworkSession::SessionError); + +class tst_QNetworkSession : public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + +private slots: + void invalidSession(); + + void sessionProperties_data(); + void sessionProperties(); + + void userChoiceSession_data(); + void userChoiceSession(); + + void sessionOpenCloseStop_data(); + void sessionOpenCloseStop(); + + void outOfProcessSession(); + +private: + QNetworkConfigurationManager manager; + + uint inProcessSessionManagementCount; + +#ifdef MAEMO + Maemo::IAPConf *iapconf; + Maemo::IAPConf *iapconf2; + Maemo::IAPConf *gprsiap; +#define MAX_IAPS 10 + Maemo::IAPConf *iaps[MAX_IAPS]; + QProcess *icd_stub; +#endif +}; + +void tst_QNetworkSession::initTestCase() +{ + qRegisterMetaType("QNetworkSession::State"); + qRegisterMetaType("QNetworkSession::SessionError"); + qRegisterMetaType("QNetworkConfiguration"); + +#ifdef MAEMO + iapconf = new Maemo::IAPConf("007"); + iapconf->setValue("ipv4_type", "AUTO"); + iapconf->setValue("wlan_wepkey1", "connt"); + iapconf->setValue("wlan_wepdefkey", 1); + iapconf->setValue("wlan_ssid", QByteArray("JamesBond")); + iapconf->setValue("name", "James Bond"); + iapconf->setValue("type", "WLAN_INFRA"); + + gprsiap = new Maemo::IAPConf("This-is-GPRS-IAP"); + gprsiap->setValue("ask_password", false); + gprsiap->setValue("gprs_accesspointname", "internet"); + gprsiap->setValue("gprs_password", ""); + gprsiap->setValue("gprs_username", ""); + gprsiap->setValue("ipv4_autodns", true); + gprsiap->setValue("ipv4_type", "AUTO"); + gprsiap->setValue("sim_imsi", "244070123456789"); + gprsiap->setValue("name", "MI6"); + gprsiap->setValue("type", "GPRS"); + + iapconf2 = new Maemo::IAPConf("osso.net"); + iapconf2->setValue("ipv4_type", "AUTO"); + iapconf2->setValue("wlan_wepkey1", "osso.net"); + iapconf2->setValue("wlan_wepdefkey", 1); + iapconf2->setValue("wlan_ssid", QByteArray("osso.net")); + iapconf2->setValue("name", "osso.net"); + iapconf2->setValue("type", "WLAN_INFRA"); + iapconf2->setValue("wlan_security", "WEP"); + + /* Create large number of IAPs in the gconf and see what happens */ + fflush(stdout); + printf("Creating %d IAPS: ", MAX_IAPS); + for (int i=0; isetValue("name", QString("test-iap-")+num); + iaps[i]->setValue("type", "WLAN_INFRA"); + iaps[i]->setValue("wlan_ssid", QString(QString("test-ssid-")+num).toAscii()); + iaps[i]->setValue("wlan_security", "WPA_PSK"); + iaps[i]->setValue("EAP_wpa_preshared_passphrase", QString("test-passphrase-")+num); + printf("."); + fflush(stdout); + } + printf("\n"); + fflush(stdout); + + icd_stub = new QProcess(this); + icd_stub->start("/usr/bin/icd2_stub.py"); + QTest::qWait(1000); + + // Add a known network to scan list that icd2 stub returns + QProcess dbus_send; + // 007 network + dbus_send.start("dbus-send --type=method_call --system " + "--dest=com.nokia.icd2 /com/nokia/icd2 " + "com.nokia.icd2.testing.add_available_network " + "string:'' uint32:0 string:'' " + "string:WLAN_INFRA uint32:5000011 array:byte:48,48,55"); + dbus_send.waitForFinished(); + + // osso.net network + dbus_send.start("dbus-send --type=method_call --system " + "--dest=com.nokia.icd2 /com/nokia/icd2 " + "com.nokia.icd2.testing.add_available_network " + "string:'' uint32:0 string:'' " + "string:WLAN_INFRA uint32:83886097 array:byte:111,115,115,111,46,110,101,116"); + dbus_send.waitForFinished(); +#endif + + inProcessSessionManagementCount = 0; + + QSignalSpy spy(&manager, SIGNAL(updateCompleted())); + manager.updateConfigurations(); + QTRY_VERIFY(spy.count() == 1); +} + +void tst_QNetworkSession::cleanupTestCase() +{ + if (!(manager.capabilities() & QNetworkConfigurationManager::SystemSessionSupport) && + (manager.capabilities() & QNetworkConfigurationManager::CanStartAndStopInterfaces) && + inProcessSessionManagementCount == 0) { + QFAIL("No usable configurations found to complete all possible " + "tests in inProcessSessionManagement()"); + } + +#ifdef MAEMO + iapconf->clear(); + delete iapconf; + iapconf2->clear(); + delete iapconf2; + gprsiap->clear(); + delete gprsiap; + + printf("Deleting %d IAPS : ", MAX_IAPS); + for (int i=0; iclear(); + delete iaps[i]; + printf("."); + fflush(stdout); + } + printf("\n"); + qDebug() << "Deleted" << MAX_IAPS << "IAPs"; + + icd_stub->terminate(); + icd_stub->waitForFinished(); +#endif +} + +void tst_QNetworkSession::invalidSession() +{ + QNetworkSession session(QNetworkConfiguration(), 0); + QVERIFY(!session.isActive()); + QVERIFY(session.state() == QNetworkSession::Invalid); +} + +void tst_QNetworkSession::sessionProperties_data() +{ + QTest::addColumn("configuration"); + + QTest::newRow("invalid configuration") << QNetworkConfiguration(); + + foreach (const QNetworkConfiguration &config, manager.allConfigurations()) { + const QString name = config.name().isEmpty() ? QString("") : config.name(); + QTest::newRow(name.toLocal8Bit().constData()) << config; + } +} + +void tst_QNetworkSession::sessionProperties() +{ + QFETCH(QNetworkConfiguration, configuration); + + QNetworkSession session(configuration); + + QVERIFY(session.configuration() == configuration); + + QStringList validBearerNames = QStringList() << QString() + << QLatin1String("Ethernet") + << QLatin1String("WLAN") + << QLatin1String("2G") + << QLatin1String("CDMA2000") + << QLatin1String("WCDMA") + << QLatin1String("HSPA") + << QLatin1String("Bluetooth") + << QLatin1String("WiMAX"); + + if (!configuration.isValid()) + QVERIFY(session.bearerName().isEmpty()); + else + QVERIFY(validBearerNames.contains(session.bearerName())); + + // QNetworkSession::interface() should return an invalid interface unless + // session is in the connected state. + QCOMPARE(session.state() == QNetworkSession::Connected, session.interface().isValid()); + + if (!configuration.isValid()) { + QVERIFY(configuration.state() == QNetworkConfiguration::Undefined && + session.state() == QNetworkSession::Invalid); + } else { + switch (configuration.state()) { + case QNetworkConfiguration::Undefined: + QVERIFY(session.state() == QNetworkSession::NotAvailable); + break; + case QNetworkConfiguration::Defined: + QVERIFY(session.state() == QNetworkSession::NotAvailable); + break; + case QNetworkConfiguration::Discovered: + QVERIFY(session.state() == QNetworkSession::Connecting || + session.state() == QNetworkSession::Disconnected); + break; + case QNetworkConfiguration::Active: + QVERIFY(session.state() == QNetworkSession::Connected || + session.state() == QNetworkSession::Closing || + session.state() == QNetworkSession::Roaming); + break; + default: + QFAIL("Invalid configuration state"); + }; + } +} + +void tst_QNetworkSession::userChoiceSession_data() +{ + QTest::addColumn("configuration"); + + QNetworkConfiguration config = manager.defaultConfiguration(); + if (config.type() == QNetworkConfiguration::UserChoice) + QTest::newRow("UserChoice") << config; + else + QSKIP("Default configuration is not a UserChoice configuration.", SkipAll); +} + +void tst_QNetworkSession::userChoiceSession() +{ + QFETCH(QNetworkConfiguration, configuration); + + QVERIFY(configuration.type() == QNetworkConfiguration::UserChoice); + + QNetworkSession session(configuration); + + QVERIFY(session.configuration() == configuration); + + QVERIFY(!session.isActive()); + + QVERIFY(session.sessionProperty("ActiveConfigurationIdentifier").toString().isEmpty()); + + + // The remaining tests require the session to be not NotAvailable. + if (session.state() == QNetworkSession::NotAvailable) + QSKIP("Network is not available.", SkipSingle); + + QSignalSpy sessionOpenedSpy(&session, SIGNAL(opened())); + QSignalSpy sessionClosedSpy(&session, SIGNAL(closed())); + QSignalSpy stateChangedSpy(&session, SIGNAL(stateChanged(QNetworkSession::State))); + QSignalSpy errorSpy(&session, SIGNAL(error(QNetworkSession::SessionError))); + + // Test opening the session. + { + bool expectStateChange = session.state() != QNetworkSession::Connected; + + session.open(); + + session.waitForOpened(); + + if (session.isActive()) + QVERIFY(!sessionOpenedSpy.isEmpty() || !errorSpy.isEmpty()); + if (!errorSpy.isEmpty()) { + QNetworkSession::SessionError error = + qvariant_cast(errorSpy.first().at(0)); + if (error == QNetworkSession::OperationNotSupportedError) { + // The session needed to bring up the interface, + // but the operation is not supported. + QSKIP("Configuration does not support open().", SkipSingle); + } else if (error == QNetworkSession::InvalidConfigurationError) { + // The session needed to bring up the interface, but it is not possible for the + // specified configuration. + if ((session.configuration().state() & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + QFAIL("Failed to open session for Discovered configuration."); + } else { + QSKIP("Cannot test session for non-Discovered configuration.", SkipSingle); + } + } else if (error == QNetworkSession::UnknownSessionError) { + QSKIP("Unknown session error.", SkipSingle); + } else { + QFAIL("Error opening session."); + } + } else if (!sessionOpenedSpy.isEmpty()) { + QCOMPARE(sessionOpenedSpy.count(), 1); + QVERIFY(sessionClosedSpy.isEmpty()); + QVERIFY(errorSpy.isEmpty()); + + if (expectStateChange) + QTRY_VERIFY(!stateChangedSpy.isEmpty()); + + QVERIFY(session.state() == QNetworkSession::Connected); + QVERIFY(session.interface().isValid()); + + const QString userChoiceIdentifier = + session.sessionProperty("UserChoiceConfigurationIdentifier").toString(); + + QVERIFY(!userChoiceIdentifier.isEmpty()); + QVERIFY(userChoiceIdentifier != configuration.identifier()); + + QNetworkConfiguration userChoiceConfiguration = + manager.configurationFromIdentifier(userChoiceIdentifier); + + QVERIFY(userChoiceConfiguration.isValid()); + QVERIFY(userChoiceConfiguration.type() != QNetworkConfiguration::UserChoice); + + const QString testIdentifier("abc"); + //resetting UserChoiceConfigurationIdentifier is ignored (read only property) + session.setSessionProperty("UserChoiceConfigurationIdentifier", testIdentifier); + QVERIFY(session.sessionProperty("UserChoiceConfigurationIdentifier").toString() != testIdentifier); + + const QString activeIdentifier = + session.sessionProperty("ActiveConfigurationIdentifier").toString(); + + QVERIFY(!activeIdentifier.isEmpty()); + QVERIFY(activeIdentifier != configuration.identifier()); + + QNetworkConfiguration activeConfiguration = + manager.configurationFromIdentifier(activeIdentifier); + + QVERIFY(activeConfiguration.isValid()); + QVERIFY(activeConfiguration.type() == QNetworkConfiguration::InternetAccessPoint); + + //resetting ActiveConfigurationIdentifier is ignored (read only property) + session.setSessionProperty("ActiveConfigurationIdentifier", testIdentifier); + QVERIFY(session.sessionProperty("ActiveConfigurationIdentifier").toString() != testIdentifier); + + if (userChoiceConfiguration.type() == QNetworkConfiguration::InternetAccessPoint) { + QVERIFY(userChoiceConfiguration == activeConfiguration); + } else { + QVERIFY(userChoiceConfiguration.type() == QNetworkConfiguration::ServiceNetwork); + QVERIFY(userChoiceConfiguration.children().contains(activeConfiguration)); + } + } else { + QFAIL("Timeout waiting for session to open."); + } + } +} + +void tst_QNetworkSession::sessionOpenCloseStop_data() +{ + QTest::addColumn("configuration"); + QTest::addColumn("forceSessionStop"); + + foreach (const QNetworkConfiguration &config, manager.allConfigurations()) { + const QString name = config.name().isEmpty() ? QString("") : config.name(); + QTest::newRow((name + QLatin1String(" close")).toLocal8Bit().constData()) + << config << false; + QTest::newRow((name + QLatin1String(" stop")).toLocal8Bit().constData()) + << config << true; + } +} + +void tst_QNetworkSession::sessionOpenCloseStop() +{ + QFETCH(QNetworkConfiguration, configuration); + QFETCH(bool, forceSessionStop); + + QNetworkSession session(configuration); + + // Test initial state of the session. + { + QVERIFY(session.configuration() == configuration); + QVERIFY(!session.isActive()); + // session may be invalid if configuration is removed between when + // sessionOpenCloseStop_data() is called and here. + QVERIFY((configuration.isValid() && (session.state() != QNetworkSession::Invalid)) || + (!configuration.isValid() && (session.state() == QNetworkSession::Invalid))); + QVERIFY(session.error() == QNetworkSession::UnknownSessionError); + } + + // The remaining tests require the session to be not NotAvailable. + if (session.state() == QNetworkSession::NotAvailable) + QSKIP("Network is not available.", SkipSingle); + + QSignalSpy sessionOpenedSpy(&session, SIGNAL(opened())); + QSignalSpy sessionClosedSpy(&session, SIGNAL(closed())); + QSignalSpy stateChangedSpy(&session, SIGNAL(stateChanged(QNetworkSession::State))); + QSignalSpy errorSpy(&session, SIGNAL(error(QNetworkSession::SessionError))); + + // Test opening the session. + { + QNetworkSession::State previousState = session.state(); + bool expectStateChange = previousState != QNetworkSession::Connected; + + session.open(); + + session.waitForOpened(); + + if (session.isActive()) + QVERIFY(!sessionOpenedSpy.isEmpty() || !errorSpy.isEmpty()); + if (!errorSpy.isEmpty()) { + QNetworkSession::SessionError error = + qvariant_cast(errorSpy.first().at(0)); + + QVERIFY(session.state() == previousState); + + if (error == QNetworkSession::OperationNotSupportedError) { + // The session needed to bring up the interface, + // but the operation is not supported. + QSKIP("Configuration does not support open().", SkipSingle); + } else if (error == QNetworkSession::InvalidConfigurationError) { + // The session needed to bring up the interface, but it is not possible for the + // specified configuration. + if ((session.configuration().state() & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + QFAIL("Failed to open session for Discovered configuration."); + } else { + QSKIP("Cannot test session for non-Discovered configuration.", SkipSingle); + } + } else if (error == QNetworkSession::UnknownSessionError) { + QSKIP("Unknown Session error.", SkipSingle); + } else { + QFAIL("Error opening session."); + } + } else if (!sessionOpenedSpy.isEmpty()) { + QCOMPARE(sessionOpenedSpy.count(), 1); + QVERIFY(sessionClosedSpy.isEmpty()); + QVERIFY(errorSpy.isEmpty()); + + if (expectStateChange) { + QTRY_VERIFY(stateChangedSpy.count() >= 2); + + QNetworkSession::State state = + qvariant_cast(stateChangedSpy.at(0).at(0)); + QVERIFY(state == QNetworkSession::Connecting); + + state = qvariant_cast(stateChangedSpy.at(1).at(0)); + QVERIFY(state == QNetworkSession::Connected); + } + + QVERIFY(session.state() == QNetworkSession::Connected); + QVERIFY(session.interface().isValid()); + } else { + QFAIL("Timeout waiting for session to open."); + } + } + + sessionOpenedSpy.clear(); + sessionClosedSpy.clear(); + stateChangedSpy.clear(); + errorSpy.clear(); + + QNetworkSession session2(configuration); + + QSignalSpy sessionOpenedSpy2(&session2, SIGNAL(opened())); + QSignalSpy sessionClosedSpy2(&session2, SIGNAL(closed())); + QSignalSpy stateChangedSpy2(&session2, SIGNAL(stateChanged(QNetworkSession::State))); + QSignalSpy errorSpy2(&session2, SIGNAL(error(QNetworkSession::SessionError))); + + // Test opening a second session. + { + QVERIFY(session2.configuration() == configuration); + QVERIFY(!session2.isActive()); + QVERIFY(session2.state() == QNetworkSession::Connected); + QVERIFY(session.error() == QNetworkSession::UnknownSessionError); + + session2.open(); + + QTRY_VERIFY(!sessionOpenedSpy2.isEmpty() || !errorSpy2.isEmpty()); + + QVERIFY(session.isActive()); + QVERIFY(session2.isActive()); + QVERIFY(session.state() == QNetworkSession::Connected); + QVERIFY(session2.state() == QNetworkSession::Connected); + QVERIFY(session.interface().isValid()); + QCOMPARE(session.interface().hardwareAddress(), session2.interface().hardwareAddress()); + QCOMPARE(session.interface().index(), session2.interface().index()); + } + + sessionOpenedSpy2.clear(); + + if (forceSessionStop) { + // Test forcing the second session to stop the interface. + QNetworkSession::State previousState = session.state(); +#ifdef Q_CC_NOKIAX86 + // For S60 emulator builds: RConnection::Stop does not work on all Emulators + bool expectStateChange = false; +#else + bool expectStateChange = previousState != QNetworkSession::Disconnected; +#endif + + session2.stop(); + + QTRY_VERIFY(!sessionClosedSpy2.isEmpty() || !errorSpy2.isEmpty()); + + QVERIFY(!session2.isActive()); + + if (!errorSpy2.isEmpty()) { + QVERIFY(!errorSpy.isEmpty()); + + // check for SessionAbortedError + QNetworkSession::SessionError error = + qvariant_cast(errorSpy.first().at(0)); + QNetworkSession::SessionError error2 = + qvariant_cast(errorSpy2.first().at(0)); + + QVERIFY(error == QNetworkSession::SessionAbortedError); + QVERIFY(error2 == QNetworkSession::SessionAbortedError); + + QCOMPARE(errorSpy.count(), 1); + QCOMPARE(errorSpy2.count(), 1); + + errorSpy.clear(); + errorSpy2.clear(); + } + + QVERIFY(errorSpy.isEmpty()); + QVERIFY(errorSpy2.isEmpty()); + + if (expectStateChange) + QTRY_VERIFY(stateChangedSpy2.count() >= 2 || !errorSpy2.isEmpty()); + + if (!errorSpy2.isEmpty()) { + QVERIFY(session2.state() == previousState); + QVERIFY(session.state() == previousState); + + QNetworkSession::SessionError error = + qvariant_cast(errorSpy2.first().at(0)); + if (error == QNetworkSession::OperationNotSupportedError) { + // The session needed to bring down the interface, + // but the operation is not supported. + QSKIP("Configuration does not support stop().", SkipSingle); + } else if (error == QNetworkSession::InvalidConfigurationError) { + // The session needed to bring down the interface, but it is not possible for the + // specified configuration. + if ((session.configuration().state() & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + QFAIL("Failed to stop session for Discovered configuration."); + } else { + QSKIP("Cannot test session for non-Discovered configuration.", SkipSingle); + } + } else { + QFAIL("Error stopping session."); + } + } else if (!sessionClosedSpy2.isEmpty()) { + if (expectStateChange) { + if (configuration.type() == QNetworkConfiguration::ServiceNetwork) { + bool roamedSuccessfully = false; + + QCOMPARE(stateChangedSpy2.count(), 4); + + QNetworkSession::State state = + qvariant_cast(stateChangedSpy2.at(0).at(0)); + QVERIFY(state == QNetworkSession::Connecting); + + state = qvariant_cast(stateChangedSpy2.at(1).at(0)); + QVERIFY(state == QNetworkSession::Connected); + + state = qvariant_cast(stateChangedSpy2.at(2).at(0)); + QVERIFY(state == QNetworkSession::Closing); + + state = qvariant_cast(stateChangedSpy2.at(3).at(0)); + QVERIFY(state == QNetworkSession::Disconnected); + + QTRY_VERIFY(stateChangedSpy.count() > 0); + state = qvariant_cast(stateChangedSpy.at(0).at(0)); + if (state == QNetworkSession::Roaming) { + QTRY_VERIFY(!errorSpy.isEmpty() || stateChangedSpy.count() > 1); + if (stateChangedSpy.count() > 1) { + state = qvariant_cast(stateChangedSpy.at(1).at(0)); + if (state == QNetworkSession::Connected) { + roamedSuccessfully = true; + QTRY_VERIFY(session2.state() == QNetworkSession::Disconnected); + } + } + } + if (roamedSuccessfully) { + QString configId = session.sessionProperty("ActiveConfigurationIdentifier").toString(); + QNetworkConfiguration config = manager.configurationFromIdentifier(configId); + QNetworkSession session3(config); + QSignalSpy errorSpy3(&session3, SIGNAL(error(QNetworkSession::SessionError))); + QSignalSpy sessionOpenedSpy3(&session3, SIGNAL(opened())); + + session3.open(); + session3.waitForOpened(); + + if (session.isActive()) + QVERIFY(!sessionOpenedSpy3.isEmpty() || !errorSpy3.isEmpty()); + + session.stop(); + + QTRY_VERIFY(session.state() == QNetworkSession::Disconnected); + QTRY_VERIFY(session3.state() == QNetworkSession::Disconnected); + } +#ifndef Q_CC_NOKIAX86 + if (!roamedSuccessfully) + QVERIFY(!errorSpy.isEmpty()); +#endif + } else { + QCOMPARE(stateChangedSpy2.count(), 2); + + QNetworkSession::State state = + qvariant_cast(stateChangedSpy2.at(0).at(0)); + QVERIFY(state == QNetworkSession::Closing); + + state = qvariant_cast(stateChangedSpy2.at(1).at(0)); + QVERIFY(state == QNetworkSession::Disconnected); + } + + QTRY_VERIFY(!sessionClosedSpy.isEmpty()); + QVERIFY(session.state() == QNetworkSession::Disconnected); + QVERIFY(session2.state() == QNetworkSession::Disconnected); + } + + QVERIFY(errorSpy2.isEmpty()); + + ++inProcessSessionManagementCount; + } else { + QFAIL("Timeout waiting for session to stop."); + } + +#ifndef Q_CC_NOKIAX86 + QVERIFY(!sessionClosedSpy.isEmpty()); +#endif + QVERIFY(!sessionClosedSpy2.isEmpty()); + +#ifndef Q_CC_NOKIAX86 + QVERIFY(!session.isActive()); +#endif + QVERIFY(!session2.isActive()); + } else { + // Test closing the second session. + { + int stateChangedCountBeforeClose = stateChangedSpy2.count(); + session2.close(); + + QTRY_VERIFY(!sessionClosedSpy2.isEmpty()); +#ifndef Q_CC_NOKIAX86 + QVERIFY(stateChangedSpy2.count() == stateChangedCountBeforeClose); +#endif + + QVERIFY(sessionClosedSpy.isEmpty()); + + QVERIFY(session.isActive()); + QVERIFY(!session2.isActive()); + QVERIFY(session.state() == QNetworkSession::Connected); + QVERIFY(session2.state() == QNetworkSession::Connected); + QVERIFY(session.interface().isValid()); + QCOMPARE(session.interface().hardwareAddress(), session2.interface().hardwareAddress()); + QCOMPARE(session.interface().index(), session2.interface().index()); + } + + sessionClosedSpy2.clear(); + + // Test closing the first session. + { +#ifdef Q_CC_NOKIAX86 + // For S60 emulator builds: RConnection::Close does not actually + // close network connection on all Emulators + bool expectStateChange = false; +#else + bool expectStateChange = session.state() != QNetworkSession::Disconnected && + manager.capabilities() & QNetworkConfigurationManager::SystemSessionSupport; +#endif + + session.close(); + + QTRY_VERIFY(!sessionClosedSpy.isEmpty() || !errorSpy.isEmpty()); + + QVERIFY(!session.isActive()); + + if (expectStateChange) + QTRY_VERIFY(!stateChangedSpy.isEmpty() || !errorSpy.isEmpty()); + + if (!errorSpy.isEmpty()) { + QNetworkSession::SessionError error = + qvariant_cast(errorSpy.first().at(0)); + if (error == QNetworkSession::OperationNotSupportedError) { + // The session needed to bring down the interface, + // but the operation is not supported. + QSKIP("Configuration does not support close().", SkipSingle); + } else if (error == QNetworkSession::InvalidConfigurationError) { + // The session needed to bring down the interface, but it is not possible for the + // specified configuration. + if ((session.configuration().state() & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + QFAIL("Failed to close session for Discovered configuration."); + } else { + QSKIP("Cannot test session for non-Discovered configuration.", SkipSingle); + } + } else { + QFAIL("Error closing session."); + } + } else if (!sessionClosedSpy.isEmpty()) { + QVERIFY(sessionOpenedSpy.isEmpty()); + QCOMPARE(sessionClosedSpy.count(), 1); + if (expectStateChange) + QVERIFY(!stateChangedSpy.isEmpty()); + QVERIFY(errorSpy.isEmpty()); + + if (expectStateChange) + QTRY_VERIFY(session.state() == QNetworkSession::Disconnected); + + ++inProcessSessionManagementCount; + } else { + QFAIL("Timeout waiting for session to close."); + } + } + } +} + +QDebug operator<<(QDebug debug, const QList &list) +{ + debug.nospace() << "( "; + foreach (const QNetworkConfiguration &config, list) + debug.nospace() << config.identifier() << ", "; + debug.nospace() << ")\n"; + return debug; +} + +void tst_QNetworkSession::outOfProcessSession() +{ + QNetworkConfigurationManager manager; + + QList before = manager.allConfigurations(QNetworkConfiguration::Active); + + QSignalSpy spy(&manager, SIGNAL(configurationChanged(QNetworkConfiguration))); + + // Cannot read/write to processes on WinCE or Symbian. + // Easiest alternative is to use sockets for IPC. + + QLocalServer oopServer; + oopServer.listen("tst_qnetworksession"); + + QProcess lackey; + lackey.start("qnetworksessionlackey"); + QVERIFY(lackey.waitForStarted()); + + QVERIFY(oopServer.waitForNewConnection(-1)); + QLocalSocket *oopSocket = oopServer.nextPendingConnection(); + + do { + QByteArray output; + + if(oopSocket->waitForReadyRead()) + output = oopSocket->readLine().trimmed(); + + if (output.startsWith("Started session ")) { + QString identifier = QString::fromLocal8Bit(output.mid(16).constData()); + + QNetworkConfiguration changed; + + do { + QTRY_VERIFY(!spy.isEmpty()); + + changed = qvariant_cast(spy.takeFirst().at(0)); + + } while (changed.identifier() != identifier); + + QVERIFY((changed.state() & QNetworkConfiguration::Active) == + QNetworkConfiguration::Active); + + QVERIFY(!before.contains(changed)); + + QList after = + manager.allConfigurations(QNetworkConfiguration::Active); + + QVERIFY(after.contains(changed)); + + spy.clear(); + + oopSocket->write("stop\n"); + oopSocket->waitForBytesWritten(); + + do { + QTRY_VERIFY(!spy.isEmpty()); + + changed = qvariant_cast(spy.takeFirst().at(0)); + } while (changed.identifier() != identifier); + + QVERIFY((changed.state() & QNetworkConfiguration::Active) != + QNetworkConfiguration::Active); + + QList afterStop = + manager.allConfigurations(QNetworkConfiguration::Active); + + QVERIFY(!afterStop.contains(changed)); + + oopSocket->disconnectFromServer(); + oopSocket->waitForDisconnected(-1); + + lackey.waitForFinished(); + } + // This is effected by QTBUG-4903, process will always report as running + //} while (lackey.state() == QProcess::Running); + + // Workaround: the socket in the lackey will disconnect on exit + } while (oopSocket->state() == QLocalSocket::ConnectedState); + + switch (lackey.exitCode()) { + case 0: + break; + case 1: + QSKIP("No discovered configurations found.", SkipAll); + break; + case 2: + QSKIP("Lackey could not start session.", SkipAll); + default: + QSKIP("Lackey failed", SkipAll); + } +} + +QTEST_MAIN(tst_QNetworkSession) + +#include "tst_qnetworksession.moc" + diff --git a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro new file mode 100644 index 0000000..1410601 --- /dev/null +++ b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro @@ -0,0 +1,21 @@ +SOURCES += tst_qnetworksession.cpp +HEADERS += ../../qbearertestcommon.h +TARGET = tst_qnetworksession +CONFIG += testcase + +QT = core network + +INCLUDEPATH += ../../../../src/bearer + +include(../../../../common.pri) +qtAddLibrary(QtBearer) + +wince* { + LACKEY.sources = $$OUTPUT_DIR/build/tests/bin/qnetworksessionlackey.exe + LACKEY.path = . + DEPLOYMENT += LACKEY +} + +symbian { + TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData +} diff --git a/tests/manual/bearerex/bearerex.cpp b/tests/manual/bearerex/bearerex.cpp new file mode 100644 index 0000000..68590cc --- /dev/null +++ b/tests/manual/bearerex/bearerex.cpp @@ -0,0 +1,565 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 "bearerex.h" + +#include + +Q_DECLARE_METATYPE(QNetworkConfiguration) + +BearerEx::BearerEx(QWidget* parent) + : QMainWindow(parent) +{ + setupUi(this); + + createMenus(); + + connect(&m_NetworkConfigurationManager, SIGNAL(updateCompleted()), this, SLOT(configurationsUpdateCompleted())); + connect(&m_NetworkConfigurationManager, SIGNAL(configurationAdded(const QNetworkConfiguration&)), + this, SLOT(configurationAdded(const QNetworkConfiguration&))); + connect(&m_NetworkConfigurationManager, SIGNAL(configurationRemoved(const QNetworkConfiguration&)), + this, SLOT(configurationRemoved(const QNetworkConfiguration&))); + connect(&m_NetworkConfigurationManager, SIGNAL(onlineStateChanged(bool)), + this, SLOT(onlineStateChanged(bool))); + connect(&m_NetworkConfigurationManager, SIGNAL(configurationChanged(const QNetworkConfiguration&)), + this, SLOT(configurationChanged(const QNetworkConfiguration&))); + showConfigurations(); +} + +void BearerEx::createMenus() +{ + QAction* act1 = new QAction(tr("Show Details"), this); + menuBar()->addAction(act1); + connect(act1, SIGNAL(triggered()), this, SLOT(on_showDetailsButton_clicked())); + + m_openAction = new QAction(tr("Open Session"), this); + menuBar()->addAction(m_openAction); + connect(m_openAction, SIGNAL(triggered()), this, SLOT(on_openSessionButton_clicked())); + + QAction* exitAct = new QAction(tr("Exit"), this); + menuBar()->addAction(exitAct); + connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); +} + +void BearerEx::showConfigurations() +{ + listWidget->clear(); + QListWidgetItem* listItem; + + QNetworkConfiguration defaultConfig = m_NetworkConfigurationManager.defaultConfiguration(); + if (defaultConfig.type() == QNetworkConfiguration::UserChoice) { + listItem = new QListWidgetItem(); + QFont font = listItem->font(); + font.setBold(true); + font.setUnderline(true); + listItem->setFont(font); + listItem->setText(" UserChoice"); + listItem->setData(Qt::UserRole, qVariantFromValue(defaultConfig)); + listWidget->addItem(listItem); + } + + QList configurations = m_NetworkConfigurationManager.allConfigurations(); + for (int i=0; ifont(); + font.setBold(true); + font.setUnderline(true); + listItem->setFont(font); + } + listItem->setText(text); + listItem->setData(Qt::UserRole, qVariantFromValue(configurations[i])); + listWidget->addItem(listItem); + } +} + +void BearerEx::on_updateConfigurationsButton_clicked() +{ + m_NetworkConfigurationManager.updateConfigurations(); +} + +void BearerEx::on_updateListButton_clicked() +{ + showConfigurations(); +} + +void BearerEx::on_showDetailsButton_clicked() +{ + QListWidgetItem* item = listWidget->currentItem(); + if (!item) { + return; + } + + QNetworkConfiguration networkConfiguration = qVariantValue(item->data(Qt::UserRole)); + DetailedInfoDialog infoDialog(&networkConfiguration,this); + infoDialog.exec(); +} + +void BearerEx::on_createSessionButton_clicked() +{ + QListWidgetItem* item = listWidget->currentItem(); + if (!item) { + return; + } + QNetworkConfiguration networkConfiguration = qVariantValue(item->data(Qt::UserRole)); + int newTabIndex = mainTabWidget->count(); + SessionTab* newTab = new SessionTab(&networkConfiguration,&m_NetworkConfigurationManager,eventListWidget,newTabIndex-1); + QString label = QString("S")+QString::number(newTabIndex-1); + mainTabWidget->insertTab(newTabIndex,newTab,label); + mainTabWidget->setCurrentIndex(newTabIndex); +} + +void BearerEx::on_clearEventListButton_clicked() +{ + eventListWidget->clear(); +} + +void BearerEx::configurationAdded(const QNetworkConfiguration& config) +{ + QListWidgetItem* listItem = new QListWidgetItem(); + listItem->setText(QString("Added: ")+config.name()); + eventListWidget->addItem(listItem); +} + +void BearerEx::configurationRemoved(const QNetworkConfiguration& config) +{ + QListWidgetItem* listItem = new QListWidgetItem(); + listItem->setText(QString("Removed: ")+config.name()); + eventListWidget->addItem(listItem); +} + +void BearerEx::onlineStateChanged(bool isOnline) +{ + QListWidgetItem* listItem = new QListWidgetItem(); + QFont font = listItem->font(); + font.setBold(true); + listItem->setFont(font); + if (isOnline) { + listItem->setText(QString("> Online")); + } else { + listItem->setText(QString("< Offline")); + } + eventListWidget->addItem(listItem); +} + +void BearerEx::configurationChanged(const QNetworkConfiguration & config) +{ + QListWidgetItem* listItem = new QListWidgetItem(); + QString state; + switch (config.state()) + { + case QNetworkConfiguration::Undefined: + state = "Undef : "; + break; + case QNetworkConfiguration::Defined: + state = "Def : "; + break; + case QNetworkConfiguration::Discovered: + state = "Disc : "; + break; + case QNetworkConfiguration::Active: + state = "Act : "; + break; + } + listItem->setText(state+config.name()); + eventListWidget->addItem(listItem); +} + +void BearerEx::configurationsUpdateCompleted() +{ + QMessageBox msgBox; + msgBox.setStandardButtons(QMessageBox::Close); + msgBox.setText("Configurations update completed."); + msgBox.exec(); +} + +DetailedInfoDialog::DetailedInfoDialog(QNetworkConfiguration* apNetworkConfiguration, QWidget * parent) + : QDialog(parent) +{ + setupUi(this); + + tableWidget->setColumnCount(2); + int rowCount = 2; + + if (apNetworkConfiguration->type() == QNetworkConfiguration::ServiceNetwork) { + rowCount = rowCount + apNetworkConfiguration->children().count(); + } + + tableWidget->setRowCount(rowCount); + tableWidget->setColumnWidth(1,250); + tableWidget->setItem(0, 0, new QTableWidgetItem(tr("Name"))); + tableWidget->setItem(0, 1, new QTableWidgetItem(apNetworkConfiguration->name())); + tableWidget->setItem(1, 0, new QTableWidgetItem(tr("Id"))); + tableWidget->setItem(1, 1, new QTableWidgetItem(apNetworkConfiguration->identifier())); + if (apNetworkConfiguration->type() == QNetworkConfiguration::ServiceNetwork) { + for (int i=0; ichildren().count(); i++) { + tableWidget->setItem(i+2, 0, new QTableWidgetItem(QString("IAP")+QString::number(i+1))); + tableWidget->setItem(i+2, 1, new QTableWidgetItem(apNetworkConfiguration->children()[i].name())); + } + } + + tableWidget->setFocusPolicy(Qt::NoFocus); + +#ifdef Q_OS_SYMBIAN + this->showMaximized(); +#endif +} + +SessionTab::SessionTab(QNetworkConfiguration* apNetworkConfiguration, + QNetworkConfigurationManager* configManager, + QListWidget* eventListWidget, + int index, + BearerEx * parent) + : QWidget(parent), m_http(0), m_eventListWidget(eventListWidget), + m_index(index), m_httpRequestOngoing(false), m_alrEnabled (false) +{ + setupUi(this); + + m_ConfigManager = configManager; + m_NetworkSession = new QNetworkSession(*apNetworkConfiguration); + + // Update initial Session state to UI + newState(m_NetworkSession->state()); + + connect(m_NetworkSession, SIGNAL(newConfigurationActivated()), this, SLOT(newConfigurationActivated())); + connect(m_NetworkSession, SIGNAL(stateChanged(QNetworkSession::State)), + this, SLOT(stateChanged(QNetworkSession::State))); + connect(m_NetworkSession, SIGNAL(opened()), this, SLOT(opened())); + connect(m_NetworkSession, SIGNAL(closed()), this, SLOT(closed())); + connect(m_NetworkSession, SIGNAL(error(QNetworkSession::SessionError)), this, SLOT(error(QNetworkSession::SessionError))); + + if (apNetworkConfiguration->type() == QNetworkConfiguration::InternetAccessPoint) { + snapLabel->hide(); + snapLineEdit->hide(); + alrButton->hide(); + iapLineEdit->setText(apNetworkConfiguration->name()+" ("+apNetworkConfiguration->identifier()+")"); + } else if (apNetworkConfiguration->type() == QNetworkConfiguration::ServiceNetwork) { + snapLineEdit->setText(apNetworkConfiguration->name()+" ("+apNetworkConfiguration->identifier()+")"); + } + bearerLineEdit->setText(m_NetworkSession->bearerName()); + sentRecDataLineEdit->setText(QString::number(m_NetworkSession->bytesWritten())+ + QString(" / ")+ + QString::number(m_NetworkSession->bytesReceived())); + snapLineEdit->setFocusPolicy(Qt::NoFocus); + iapLineEdit->setFocusPolicy(Qt::NoFocus); + bearerLineEdit->setFocusPolicy(Qt::NoFocus); + sentRecDataLineEdit->setFocusPolicy(Qt::NoFocus); + stateLineEdit->setFocusPolicy(Qt::NoFocus); +} + +SessionTab::~SessionTab() +{ + delete m_NetworkSession; + delete m_http; +} + +void SessionTab::on_createQHttpButton_clicked() +{ + if (m_httpRequestOngoing) { + return; + } + + if (m_http) { + disconnect(m_http, 0, 0, 0); + delete m_http; + } + m_http = new QHttp(this); + createQHttpButton->setText("Recreate QHttp"); + connect(m_http, SIGNAL(done(bool)), this, SLOT(done(bool))); +} + +void SessionTab::on_sendRequestButton_clicked() +{ + if (m_http) { + QString urlstring("http://www.google.com"); + QUrl url(urlstring); + m_http->setHost(url.host(), QHttp::ConnectionModeHttp, url.port() == -1 ? 0 : url.port()); + m_http->get(urlstring); + m_httpRequestOngoing = true; + } else { + QMessageBox msgBox; + msgBox.setStandardButtons(QMessageBox::Close); + msgBox.setText("QHttp not created.\nCreate QHttp First."); + msgBox.exec(); + } +} + +void SessionTab::on_openSessionButton_clicked() +{ + m_NetworkSession->open(); + if (m_NetworkSession->isActive()) { + newState(m_NetworkSession->state()); + } +} + +void SessionTab::on_closeSessionButton_clicked() +{ + m_NetworkSession->close(); + if (!m_NetworkSession->isActive()) { + newState(m_NetworkSession->state()); + } +} + +void SessionTab::on_stopConnectionButton_clicked() +{ + m_NetworkSession->stop(); +} + +void SessionTab::on_alrButton_clicked() +{ + if (!m_alrEnabled) { + connect(m_NetworkSession, SIGNAL(preferredConfigurationChanged(const QNetworkConfiguration&, bool)), + this, SLOT(preferredConfigurationChanged(const QNetworkConfiguration&, bool))); + alrButton->setText("Disable ALR"); + m_alrEnabled = true; + } else { + disconnect(m_NetworkSession, SIGNAL(preferredConfigurationChanged(const QNetworkConfiguration&, bool)), 0, 0); + alrButton->setText("Enable ALR"); + m_alrEnabled = false; + } +} + +void SessionTab::on_deleteSessionButton_clicked() +{ + setWindowTitle("Bearer Example"); + delete this; +} + +void SessionTab::newConfigurationActivated() +{ + QMessageBox msgBox; + msgBox.setText("New configuration activated."); + msgBox.setInformativeText("Do you want to accept new configuration?"); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::Yes); + if (msgBox.exec() == QMessageBox::Yes) { + m_NetworkSession->accept(); + iapLineEdit->setText(m_config.name()+" ("+m_config.identifier()+")"); + } else { + m_NetworkSession->reject(); + } +} + +void SessionTab::preferredConfigurationChanged(const QNetworkConfiguration& config, bool /*isSeamless*/) +{ + m_config = config; + QMessageBox msgBox; + msgBox.setText("Roaming to new configuration."); + msgBox.setInformativeText("Do you want to migrate to "+config.name()+"?"); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::Yes); + if (msgBox.exec() == QMessageBox::Yes) { + m_NetworkSession->migrate(); + } else { + m_NetworkSession->ignore(); + } +} + +void SessionTab::opened() +{ + QListWidgetItem* listItem = new QListWidgetItem(); + QFont font = listItem->font(); + font.setBold(true); + listItem->setFont(font); + listItem->setText(QString("S")+QString::number(m_index)+QString(" - ")+QString("Opened")); + m_eventListWidget->addItem(listItem); + + QVariant identifier = m_NetworkSession->property("ActiveConfigurationIdentifier"); + if (!identifier.isNull()) { + QString configId = identifier.toString(); + QNetworkConfiguration config = m_ConfigManager->configurationFromIdentifier(configId); + if (config.isValid()) { + iapLineEdit->setText(config.name()+" ("+config.identifier()+")"); + } + } + + if (m_NetworkSession->configuration().type() == QNetworkConfiguration::UserChoice) { + QVariant identifier = m_NetworkSession->property("UserChoiceConfigurationIdentifier"); + if (!identifier.isNull()) { + QString configId = identifier.toString(); + QNetworkConfiguration config = m_ConfigManager->configurationFromIdentifier(configId); + if (config.isValid() && (config.type() == QNetworkConfiguration::ServiceNetwork)) { + snapLineEdit->setText(config.name()); + } + } + } +} + +void SessionTab::closed() +{ + QListWidgetItem* listItem = new QListWidgetItem(); + QFont font = listItem->font(); + font.setBold(true); + listItem->setFont(font); + listItem->setText(QString("S")+QString::number(m_index)+QString(" - ")+QString("Closed")); + m_eventListWidget->addItem(listItem); +} + +QString SessionTab::stateString(QNetworkSession::State state) +{ + QString stateString; + switch (state) + { + case QNetworkSession::Invalid: + stateString = "Invalid"; + break; + case QNetworkSession::NotAvailable: + stateString = "NotAvailable"; + break; + case QNetworkSession::Connecting: + stateString = "Connecting"; + break; + case QNetworkSession::Connected: + stateString = "Connected"; + break; + case QNetworkSession::Closing: + stateString = "Closing"; + break; + case QNetworkSession::Disconnected: + stateString = "Disconnected"; + break; + case QNetworkSession::Roaming: + stateString = "Roaming"; + break; + } + return stateString; +} + +void SessionTab::stateChanged(QNetworkSession::State state) +{ + newState(state); + + QListWidgetItem* listItem = new QListWidgetItem(); + listItem->setText(QString("S")+QString::number(m_index)+QString(" - ")+stateString(state)); + m_eventListWidget->addItem(listItem); +} + +void SessionTab::newState(QNetworkSession::State state) +{ + if (state == QNetworkSession::Connected) { + QVariant identifier = m_NetworkSession->property("ActiveConfigurationIdentifier"); + if (!identifier.isNull()) { + QString configId = identifier.toString(); + QNetworkConfiguration config = m_ConfigManager->configurationFromIdentifier(configId); + if (config.isValid()) { + iapLineEdit->setText(config.name()+" ("+config.identifier()+")"); + } + } + } + + bearerLineEdit->setText(m_NetworkSession->bearerName()); + + QString active; + if (m_NetworkSession->isActive()) { + active = " (A)"; + } + stateLineEdit->setText(stateString(state)+active); +} + +void SessionTab::error(QNetworkSession::SessionError error) +{ + QListWidgetItem* listItem = new QListWidgetItem(); + QMessageBox msgBox; + msgBox.setStandardButtons(QMessageBox::Close); + + QString errorString; + switch (error) + { + case QNetworkSession::UnknownSessionError: + errorString = "UnknownSessionError"; + break; + case QNetworkSession::SessionAbortedError: + errorString = "SessionAbortedError"; + break; + case QNetworkSession::RoamingError: + errorString = "RoamingError"; + break; + case QNetworkSession::OperationNotSupportedError: + errorString = "OperationNotSupportedError"; + break; + case QNetworkSession::InvalidConfigurationError: + errorString = "InvalidConfigurationError"; + break; + } + listItem->setText(QString("S")+QString::number(m_index)+QString(" - ")+errorString); + m_eventListWidget->addItem(listItem); + + msgBox.setText(errorString); + msgBox.exec(); +} + +void SessionTab::done(bool error) +{ + m_httpRequestOngoing = false; + + QMessageBox msgBox; + msgBox.setStandardButtons(QMessageBox::Close); + if (error) { + msgBox.setText("HTTP request failed."); + } else { + QString result(m_http->readAll()); + msgBox.setText(QString("HTTP request finished successfully.\nReceived ")+QString::number(result.length())+QString(" bytes.")); + } + msgBox.exec(); + + sentRecDataLineEdit->setText(QString::number(m_NetworkSession->bytesWritten())+ + QString(" / ")+ + QString::number(m_NetworkSession->bytesReceived())); +} + +// End of file + diff --git a/tests/manual/bearerex/bearerex.h b/tests/manual/bearerex/bearerex.h new file mode 100644 index 0000000..f18180e --- /dev/null +++ b/tests/manual/bearerex/bearerex.h @@ -0,0 +1,138 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 ACCESSPOINTMANAGEREX_H +#define ACCESSPOINTMANAGEREX_H + +#include + +#include "ui_bearerex.h" +#include "ui_detailedinfodialog.h" +#include "ui_sessiondialog.h" + +#include "qnetworkconfigmanager.h" +#include "qnetworksession.h" +#include "xqlistwidget.h" + +class QHttp; +class SessionTab; + +QTM_USE_NAMESPACE + +class BearerEx : public QMainWindow, public Ui::BearerExMainWindow +{ + Q_OBJECT + +public: + BearerEx(QWidget* parent = 0); + void createMenus(); + void showConfigurations(); + +private Q_SLOTS: + void on_updateConfigurationsButton_clicked(); + void on_updateListButton_clicked(); + void on_showDetailsButton_clicked(); + void on_createSessionButton_clicked(); + void on_clearEventListButton_clicked(); + + void configurationsUpdateCompleted(); + void configurationAdded(const QNetworkConfiguration& config); + void configurationRemoved(const QNetworkConfiguration& config); + void onlineStateChanged(bool isOnline); + void configurationChanged(const QNetworkConfiguration & config); + +private: + QNetworkConfigurationManager m_NetworkConfigurationManager; + QAction* m_openAction; +}; + +class DetailedInfoDialog : public QDialog, public Ui::DetailedInfoDialog +{ + Q_OBJECT + +public: + DetailedInfoDialog(QNetworkConfiguration* apNetworkConfiguration = 0, QWidget* parent = 0); +}; + + +class SessionTab : public QWidget, public Ui::SessionTab +{ + Q_OBJECT + +public: + SessionTab(QNetworkConfiguration* apNetworkConfiguration = 0, QNetworkConfigurationManager* configManager = 0, + QListWidget* eventListWidget = 0, int index = 0, BearerEx* parent = 0); + ~SessionTab(); + + QString stateString(QNetworkSession::State state); + +private Q_SLOTS: + void on_createQHttpButton_clicked(); + void on_sendRequestButton_clicked(); + void on_openSessionButton_clicked(); + void on_closeSessionButton_clicked(); + void on_stopConnectionButton_clicked(); + void on_deleteSessionButton_clicked(); + void on_alrButton_clicked(); + void done(bool error); + + void newConfigurationActivated(); + void preferredConfigurationChanged(const QNetworkConfiguration& config, bool isSeamless); + void stateChanged(QNetworkSession::State state); + void newState(QNetworkSession::State state); + void opened(); + void closed(); + void error(QNetworkSession::SessionError error); + +private: //data + QHttp* m_http; + QNetworkSession* m_NetworkSession; + QNetworkConfigurationManager* m_ConfigManager; + QListWidget* m_eventListWidget; + QNetworkConfiguration m_config; + int m_index; + bool m_httpRequestOngoing; + bool m_alrEnabled; +}; + +#endif // ACCESSPOINTMANAGEREX_H + +// End of file + diff --git a/tests/manual/bearerex/bearerex.pro b/tests/manual/bearerex/bearerex.pro new file mode 100644 index 0000000..a870eb1 --- /dev/null +++ b/tests/manual/bearerex/bearerex.pro @@ -0,0 +1,34 @@ +TEMPLATE = app +TARGET = BearerEx + +QT += core \ + gui \ + network + +FORMS += sessiondialog.ui \ + bearerex.ui \ + detailedinfodialog.ui +include(../../common.pri) +#not really a test case but deployment happens same way +CONFIG += testcase + +DEPENDPATH += . +INCLUDEPATH += . \ + ../../src/bearer + +# Example headers and sources +HEADERS += bearerex.h \ + xqlistwidget.h + +SOURCES += bearerex.cpp \ + main.cpp \ + xqlistwidget.cpp + +symbian: { + bearerex.sources = Qtbearer.dll + bearerex.path = /sys/bin + DEPLOYMENT += bearerex + + TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData +} +qtAddLibrary(QtBearer) diff --git a/tests/manual/bearerex/bearerex.ui b/tests/manual/bearerex/bearerex.ui new file mode 100644 index 0000000..e5ab62f --- /dev/null +++ b/tests/manual/bearerex/bearerex.ui @@ -0,0 +1,95 @@ + + BearerExMainWindow + + + + 0 + 0 + 360 + 640 + + + + Bearer Example + + + + + + + + Main + + + + + + Network Configurations + + + Qt::AlignCenter + + + + + + + + + + + + Update Configs + + + + + + + Update List + + + + + + + Create Session + + + + + + + Show Details + + + + + + + + + + Events + + + + + + + + + Clear + + + + + + + + + + + + + diff --git a/tests/manual/bearerex/detailedinfodialog.ui b/tests/manual/bearerex/detailedinfodialog.ui new file mode 100644 index 0000000..c4a21fa --- /dev/null +++ b/tests/manual/bearerex/detailedinfodialog.ui @@ -0,0 +1,54 @@ + + DetailedInfoDialog + + + + 0 + 0 + 308 + 396 + + + + Bearer Example + + + + + + Detailed information + + + + + + + + + + QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + DetailedInfoDialog + accept() + + + 205 + 371 + + + 223 + 8 + + + + + diff --git a/tests/manual/bearerex/main.cpp b/tests/manual/bearerex/main.cpp new file mode 100644 index 0000000..e13a494 --- /dev/null +++ b/tests/manual/bearerex/main.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 + +#include "bearerex.h" + +int main(int argc, char* argv[]) +{ + QApplication app(argc, argv); + BearerEx bearerEx; +#ifdef Q_OS_SYMBIAN + bearerEx.showMaximized(); +#else + bearerEx.show(); +#endif + return app.exec(); +} + +// End of file + diff --git a/tests/manual/bearerex/sessiondialog.ui b/tests/manual/bearerex/sessiondialog.ui new file mode 100644 index 0000000..fcf2136 --- /dev/null +++ b/tests/manual/bearerex/sessiondialog.ui @@ -0,0 +1,139 @@ + + SessionTab + + + + + + + + SNAP + + + + + + + true + + + + + + + IAP + + + + + + + true + + + true + + + + + + + Bearer + + + + + + + true + + + + + + + Sent/Rec. + + + + + + + true + + + + + + + State + + + + + + + true + + + + + + + + + + + Open Session + + + + + + + Close Session + + + + + + + Stop Conn. + + + + + + + Create QHttp + + + + + + + Send Test Req. + + + + + + + Enable ALR + + + + + + + Delete Session + + + + + + + + + + diff --git a/tests/manual/bearerex/xqlistwidget.cpp b/tests/manual/bearerex/xqlistwidget.cpp new file mode 100644 index 0000000..0618725 --- /dev/null +++ b/tests/manual/bearerex/xqlistwidget.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 "xqlistwidget.h" + +XQListWidget::XQListWidget(QWidget* parent) : QListWidget(parent) +{ +} + +void XQListWidget::keyPressEvent(QKeyEvent* event) +{ + switch (event->key()) + { + case Qt::Key_Left: + { + focusPreviousChild(); + break; + } + case Qt::Key_Right: + { + focusNextChild(); + break; + } + default: + { + QListWidget::keyPressEvent(event); + } + } +} diff --git a/tests/manual/bearerex/xqlistwidget.h b/tests/manual/bearerex/xqlistwidget.h new file mode 100644 index 0000000..1053328 --- /dev/null +++ b/tests/manual/bearerex/xqlistwidget.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 XQLISTWIDGET_H +#define XQLISTWIDGET_H + +#include +#include + +class XQListWidget: public QListWidget +{ +public: + XQListWidget(QWidget* parent = 0); + +protected: + void keyPressEvent(QKeyEvent* event); +}; + +#endif // XQLISTWIDGET_H + + diff --git a/tests/manual/networkmanager/README b/tests/manual/networkmanager/README new file mode 100644 index 0000000..4bc7171 --- /dev/null +++ b/tests/manual/networkmanager/README @@ -0,0 +1,2 @@ +This application serves as prototype/test-bed for NetworkManager development. The excellent (non-existing) documentation +for the various NetworkManager interfaces makes this harder than it should be. diff --git a/tests/manual/networkmanager/dialog.ui b/tests/manual/networkmanager/dialog.ui new file mode 100644 index 0000000..1301908 --- /dev/null +++ b/tests/manual/networkmanager/dialog.ui @@ -0,0 +1,213 @@ + + + Dialog + + + + 0 + 0 + 919 + 657 + + + + Dialog + + + + + + + + Connections + + + + + + + + Path + + + + + State + + + + + Id + + + + + Settings + + + + + + + + + + + + Devices: + + + + + + + + Path + + + + + Managed + + + + + Interface + + + + + Driver + + + + + Type + + + + + State + + + + + IP4 Address + + + + + IP4 Config + + + + + Hostname + + + + + Domains + + + + + + + + + + Qt::Horizontal + + + + 908 + 20 + + + + + + + + true + + + + SSID + + + + + Strength + + + + + Wpa + + + + + Rsn + + + + + Freq + + + + + Hardware Address + + + + + Mode + + + + + Max Bitrate + + + + + + + + + + Start + + + + + + + Stop + + + + + + + Scan + + + + + + + Update + + + + + + + + + + diff --git a/tests/manual/networkmanager/networkmanager.pro b/tests/manual/networkmanager/networkmanager.pro new file mode 100644 index 0000000..31b2af1 --- /dev/null +++ b/tests/manual/networkmanager/networkmanager.pro @@ -0,0 +1,19 @@ +SOURCES += networkmanagertest.cpp nmview.cpp +HEADERS += nmview.h +TARGET = tst_networkmanagertest + +QT = core network dbus gui + +#not really a test case but deployment happens same way +CONFIG += testcase + +requires(contains(QT_CONFIG,dbus)) + +INCLUDEPATH += ../../src/bearer +include(../../common.pri) + +qtAddLibrary(QtBearer) + +#MOC_DIR = .moc +#OBJECTS_DIR = .obj +FORMS += dialog.ui diff --git a/tests/manual/networkmanager/networkmanagertest.cpp b/tests/manual/networkmanager/networkmanagertest.cpp new file mode 100644 index 0000000..a39b041 --- /dev/null +++ b/tests/manual/networkmanager/networkmanagertest.cpp @@ -0,0 +1,287 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "nmview.h" + +#include + +typedef QMap< QString, QMap > SettingsMap; +Q_DECLARE_METATYPE(SettingsMap) + +void printConnectionDetails(const QString& service) +{ + QDBusConnection dbc = QDBusConnection::systemBus(); + if (!dbc.isConnected()) { + qWarning() << "Unable to connect to D-Bus:" << dbc.lastError(); + return; + } + QDBusInterface allCons(service, NM_DBUS_PATH_SETTINGS, NM_DBUS_IFACE_SETTINGS, dbc); + if (allCons.isValid()) { + QDBusReply > reply = allCons.call("ListConnections"); + if ( reply.isValid() ) { + qWarning() << "Known connections:"; + QList list = reply.value(); + foreach(QDBusObjectPath path, list) { + qWarning() << " " << path.path(); + QDBusInterface sysIface(NM_DBUS_SERVICE_SYSTEM_SETTINGS, path.path(), NM_DBUS_IFACE_SETTINGS_CONNECTION, dbc); + if (sysIface.isValid()) { + QDBusMessage r = sysIface.call("GetSettings"); + QDBusReply< SettingsMap > rep = sysIface.call("GetSettings"); + qWarning() << " GetSettings:" << r.arguments() << r.signature() << rep.isValid() << sysIface.lastError(); + QMap< QString, QMap > map = rep.value(); + QList list = map.keys(); + foreach (QString key, list) { + QMap innerMap = map[key]; + qWarning() << " Key: " << key; + QMap::const_iterator i = innerMap.constBegin(); + while (i != innerMap.constEnd()) { + QString k = i.key(); + qWarning() << " Key: " << k << " Entry: " << i.value(); + if (k == "addresses" && i.value().canConvert()) { + QDBusArgument arg = i.value().value(); + arg.beginArray(); + while (!arg.atEnd()) { + QDBusVariant addr; + arg >> addr; + uint ip = addr.variant().toUInt(); + qWarning() << ip; + qWarning() << " " << QHostAddress(htonl(ip)).toString(); + } + + } + i++; + } + } + } + } + } + } + + +} + +void readConnectionManagerDetails() +{ + qDBusRegisterMetaType(); + QDBusConnection dbc = QDBusConnection::systemBus(); + if (!dbc.isConnected()) { + qWarning() << "Unable to connect to D-Bus:" << dbc.lastError(); + return; + } + + QDBusInterface iface(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, dbc); + if (!iface.isValid()) { + qWarning() << "Could not find NetworkManager"; + return; + } + + uint state = iface.property("State").toUInt(); + switch(state) { + case NM_STATE_UNKNOWN: + qWarning() << "State: Unknown"; break; + case NM_STATE_ASLEEP: + qWarning() << "State: Asleep"; break; + case NM_STATE_CONNECTING: + qWarning() << "State: Connecting"; break; + case NM_STATE_CONNECTED: + qWarning() << "State: Connected"; break; + case NM_STATE_DISCONNECTED: + qWarning() << "State: Disconnected"; break; + } + //get list of network devices + QDBusReply > reply = iface.call("GetDevices"); + if ( reply.isValid() ) { + qWarning() << "Current devices:"; + QList list = reply.value(); + foreach(QDBusObjectPath path, list) { + qWarning() << " " << path.path(); + QDBusInterface devIface(NM_DBUS_SERVICE, path.path(), NM_DBUS_INTERFACE_DEVICE, dbc); + if (devIface.isValid()) { + qWarning() << " Managed: " << devIface.property("Managed").toBool(); + qWarning() << " Interface: " << devIface.property("Interface").toString(); + qWarning() << " HAL UDI: " << devIface.property("Udi").toString(); + qWarning() << " Driver: " << devIface.property("Driver").toString(); + QVariant v = devIface.property("DeviceType"); + switch(v.toUInt()) { + case DEVICE_TYPE_UNKNOWN: + qWarning() << " DeviceType: Unknown" ; + break; + case DEVICE_TYPE_802_3_ETHERNET: + qWarning() << " DeviceType: Ethernet" ; + break; + case DEVICE_TYPE_802_11_WIRELESS: + qWarning() << " DeviceType: Wireless" ; + break; + case DEVICE_TYPE_GSM: + qWarning() << " DeviceType: GSM" ; + break; + case DEVICE_TYPE_CDMA: + qWarning() << " DeviceType: CDMA" ; + break; + + } + v = devIface.property("State"); + switch(v.toUInt()) { + case NM_DEVICE_STATE_UNKNOWN: + qWarning() << " State: Unknown" ; break; + case NM_DEVICE_STATE_UNMANAGED: + qWarning() << " State: Unmanaged" ; break; + case NM_DEVICE_STATE_UNAVAILABLE: + qWarning() << " State: Unavailable" ; break; + case NM_DEVICE_STATE_DISCONNECTED: + qWarning() << " State: Disconnected" ; break; + case NM_DEVICE_STATE_PREPARE: + qWarning() << " State: Preparing" ; break; + case NM_DEVICE_STATE_CONFIG: + qWarning() << " State: Being configured" ; break; + case NM_DEVICE_STATE_NEED_AUTH: + qWarning() << " State: Awaiting secrets" ; break; + case NM_DEVICE_STATE_IP_CONFIG: + qWarning() << " State: IP requested" ; break; + case NM_DEVICE_STATE_ACTIVATED: + qWarning() << " State: Activated" ; break; + case NM_DEVICE_STATE_FAILED: + qWarning() << " State: FAILED" ; break; + } + quint32 ip = devIface.property("Ip4Address").toUInt(); + qWarning() << " IP4Address: " << QHostAddress(htonl(ip)).toString(); + if (v.toUInt() == NM_DEVICE_STATE_ACTIVATED) { + QString path = devIface.property("Ip4Config").value().path(); + qWarning() << " IP4Config: " << path; + QDBusInterface ipIface(NM_DBUS_SERVICE, path, NM_DBUS_INTERFACE_IP4_CONFIG, dbc); + if (ipIface.isValid()) { + qWarning() << " Hostname: " << ipIface.property("Hostname").toString(); + qWarning() << " Domains: " << ipIface.property("Domains").toStringList(); + qWarning() << " NisDomain: " << ipIface.property("NisDomain").toString(); + QDBusArgument arg= ipIface.property("Addresses").value(); + //qWarning() << " " << arg.currentType(); + qWarning() << " Addresses: " << ipIface.property("Addresses"); + qWarning() << " Nameservers: " << ipIface.property("Nameservers"); + qWarning() << " NisServers: " << ipIface.property("NisServers"); + } + + } + + } + } + } + + //get list of active connections + QVariant prop = iface.property("ActiveConnections"); + QList connections = prop.value >(); + QString activePath; + if ( connections.count() ) + qWarning() << "Active connections:"; + foreach(QDBusObjectPath path, connections) { + qWarning() << " " << path.path(); + activePath = path.path(); + QString serviceName; + QDBusInterface conIface(NM_DBUS_SERVICE, path.path(), NM_DBUS_INTERFACE_ACTIVE_CONNECTION, dbc); + if (conIface.isValid()) { + qWarning() << " default connection: " << conIface.property("Default").toBool(); + serviceName = conIface.property("ServiceName").toString(); + qWarning() << " service name: " << serviceName; + qWarning() << " connection path: " << conIface.property("Connection").value().path(); + qWarning() << " specific object:" << conIface.property("SpecificObject").value().path(); + qWarning() << " sharedServiceName: " << conIface.property("SharedServiceName").toString(); + QList devs = conIface.property("Devices").value >(); + qWarning() << " devices: "; + foreach(QDBusObjectPath p, devs) + qWarning() << " " << path.path(); + QVariant v = conIface.property("State"); + switch (v.toInt()) { + case NM_ACTIVE_CONNECTION_STATE_UNKNOWN: + qWarning()<< " State: unknown"; break; + case NM_ACTIVE_CONNECTION_STATE_ACTIVATING: + qWarning()<< " State: activating"; break; + case NM_ACTIVE_CONNECTION_STATE_ACTIVATED: + qWarning()<< " State: activated"; break; + } + } else { + qWarning() << conIface.lastError(); + } + + } + + printConnectionDetails(NM_DBUS_SERVICE_SYSTEM_SETTINGS); + printConnectionDetails(NM_DBUS_SERVICE_USER_SETTINGS); + + + //turn active connection off + /*QDBusObjectPath dbop("/org/freedesktop/NetworkManager/ActiveConnection/1"); + QVariant asd = QVariant::fromValue(dbop); + iface.call(QLatin1String("DeactivateConnection"), asd); + qWarning() << iface.lastError();*/ + + /*QDBusObjectPath p1device("/org/freedesktop/Hal/devices/net_00_60_6e_82_02_65"); + QVariant p1v = QVariant::fromValue(p1device); + QDBusObjectPath p1con("/org/freedesktop/NetworkManagerSettings/0"); + QVariant p1c = QVariant::fromValue(p1con); + QDBusObjectPath p1sp(""); + QVariant p1sp1 = QVariant::fromValue(p1sp); + iface.call(QLatin1String("ActivateConnection"), + QString("/org/freedesktop/NetworkManagerSystemSettings"), p1c,p1v, p1v ); + qWarning() << iface.lastError(); + */ +} + +int main( int argc, char** argv) +{ + QApplication app(argc, argv); + //readConnectionManagerDetails(); + QMainWindow main; + NMView view; + main.setCentralWidget(&view); + main.show(); + return app.exec(); + +} diff --git a/tests/manual/networkmanager/nmview.cpp b/tests/manual/networkmanager/nmview.cpp new file mode 100644 index 0000000..ca9d907 --- /dev/null +++ b/tests/manual/networkmanager/nmview.cpp @@ -0,0 +1,1030 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 "nmview.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +//#include "ui_dialog.h" + +#include +#include +#include +#include + +//static QDBusConnection dbc = QDBusConnection::systemBus(); +//typedef QMap< QString, QMap > SettingsMap; +//Q_DECLARE_METATYPE(SettingsMap) + + +NMView::NMView(QDialog* parent) + : QDialog(parent, 0), dbc(QDBusConnection::systemBus()) +{ + init(); + + if (!dbc.isConnected()) { + qWarning() << "Unable to connect to D-Bus:" << dbc.lastError(); + return; + } + updateConnections(); + getDevices(); +} + +NMView::~NMView() +{ +} +void NMView::init() +{ + setupUi(this); + sess = 0; +// readSettings(); + connect(startButton, SIGNAL(clicked()), this, SLOT(activate())); + connect(stopButton, SIGNAL(clicked()), this, SLOT(deactivate())); + connect(scanButton, SIGNAL(clicked()), this, SLOT(findAccessPoints())); + connect(updateButton, SIGNAL(clicked()), this, SLOT(update())); + + connect(cons, SIGNAL(itemActivated(QTreeWidgetItem*, int)), + this,SLOT(connectionItemActivated(QTreeWidgetItem*, int))); + + + connect(devicesTreeWidget, SIGNAL(itemActivated(QTreeWidgetItem*, int)), + this, SLOT(deviceItemActivated(QTreeWidgetItem*, int))); + + cons->header()->setResizeMode(QHeaderView::ResizeToContents); + devicesTreeWidget->header()->setResizeMode(QHeaderView::ResizeToContents); + accessPointsTreeWidget->header()->setResizeMode(QHeaderView::ResizeToContents); +// accessPointsTreeWidget->header()->setResizeMode(QHeaderView::ResizeToContents); + + manager = new QNetworkConfigurationManager(this); + + connect(manager, SIGNAL(updateCompleted()), this, SLOT(updateCompleted())); + + connect(manager, SIGNAL(configurationAdded(const QNetworkConfiguration &)), + this, SLOT(configurationAdded(const QNetworkConfiguration&))); + + devicesTreeWidget->header()->hideSection(0); + devicesTreeWidget->header()->hideSection(1); + devicesTreeWidget->header()->hideSection(3); + devicesTreeWidget->header()->hideSection(5); + devicesTreeWidget->header()->hideSection(6); + devicesTreeWidget->header()->hideSection(7); + devicesTreeWidget->header()->hideSection(8); + devicesTreeWidget->header()->hideSection(9); +} + +void NMView::updateConnections() +{ + cons->clear(); + manager->updateConfigurations(); + QList configs = manager->allConfigurations(); + foreach(QNetworkConfiguration p, configs) { + QStringList strlist; + strlist << p.name(); + strlist << stateToString(p.state()); + strlist << p.identifier(); + strlist << typeToString(p.type()); + QTreeWidgetItem *item; + item = new QTreeWidgetItem(strlist); + cons->insertTopLevelItem(0, item); + } + cons->sortItems ( 1, Qt::AscendingOrder); +} + +void NMView::getActiveConnections() +{ + QList configs = manager->allConfigurations(QNetworkConfiguration::Active); + foreach(QNetworkConfiguration p, configs) { + qWarning() << __FUNCTION__ << p.name() << p.identifier(); + } + +// QDBusInterface iface(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, dbc); +// if (!iface.isValid()) { +// qWarning() << "Could not find NetworkManager"; +// return; +// } + +// QVariant prop = iface.property("ActiveConnections"); +// QList connections = prop.value >(); +// foreach(QDBusObjectPath path, connections) { +// QDBusInterface conDetails(NM_DBUS_SERVICE, path.path(), NM_DBUS_INTERFACE_ACTIVE_CONNECTION, dbc); +// if (conDetails.isValid()) { +// QString desc = path.path(); +// conDetails.property("Connection Path").value().path(); + +// QList devices = conDetails.property("Devices").value >(); +// +// foreach(QDBusObjectPath devpath, devices) { +// QDBusInterface devIface(NM_DBUS_SERVICE, devpath.path(), NM_DBUS_INTERFACE_DEVICE, dbc); +// desc += " "+devIface.property("Interface").toString(); +// desc += " "+QHostAddress(htonl(devIface.property("Ip4Address").toUInt())).toString(); + +// } + +// qWarning() << conDetails.property("Connection").value().path() << path.path(); + +// QListWidgetItem* item = new QListWidgetItem(desc, activeCons); +// item->setData(Qt::UserRole, path.path()); +// } +// } +} + +void NMView::update() +{ +// if(sess) +// qWarning() << __FUNCTION__<< sess->bytesWritten() << sess->bearerName(); +// QNetworkManagerInterface *dbIface; +// dbIface = new QNetworkManagerInterface; +// QList connections = dbIface->activeConnections(); +// +// foreach(QDBusObjectPath conpath, connections) { +// QNetworkManagerConnectionActive *aConn; +// aConn = new QNetworkManagerConnectionActive(conpath.path()); +// // in case of accesspoint, specificObject will hold the accessPOintObjectPath +// qWarning() << aConn->connection().path() << aConn->specificObject().path() << aConn->devices().count(); +// QList devs = aConn->devices(); +// foreach(QDBusObjectPath device, devs) { +// qWarning() << " " << device.path(); +// } +// } + + QStringList connectionServices; + connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; + connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; + foreach (QString service, connectionServices) { + QDBusInterface allCons(service, + NM_DBUS_PATH_SETTINGS, + NM_DBUS_IFACE_SETTINGS, + dbc); + if (allCons.isValid()) { + QDBusReply > reply = allCons.call("ListConnections"); + if ( reply.isValid() ) { + QList list = reply.value(); + foreach(QDBusObjectPath path, list) { + QDBusInterface sysIface(service, + path.path(), + NM_DBUS_IFACE_SETTINGS_CONNECTION, + dbc); + if (sysIface.isValid()) { + qWarning() << ""; + qWarning() << path.path(); + + // QDBusMessage r = sysIface.call("GetSettings"); + QDBusReply< QNmSettingsMap > rep = sysIface.call("GetSettings"); + + QMap< QString, QMap > map = rep.value(); + QList list = map.keys(); + foreach (QString key, list) { + QMap innerMap = map[key]; + qWarning() << " Key: " << key; + QMap::const_iterator i = innerMap.constBegin(); + + while (i != innerMap.constEnd()) { + QString k = i.key(); + qWarning() << " Key: " << k << " Entry: " << i.value(); + i++; + }//end innerMap + }//end foreach key + }//end settings connection + } // foreach path + } //end ListConnections + } //end settingsInterface + }// end services + QDBusInterface iface(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + dbc); + if (iface.isValid()) { + QVariant prop = iface.property("ActiveConnections"); + QList connections = prop.value >(); + foreach(QDBusObjectPath conpath, connections) { + qWarning() << "Active connection" << conpath.path(); + QDBusInterface conDetails(NM_DBUS_SERVICE, + conpath.path(), + NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + dbc); + if (conDetails.isValid()) { + + QVariant prop = conDetails.property("Connection"); + QDBusObjectPath connection = prop.value(); + qWarning() << conDetails.property("Default").toBool() << connection.path(); + +// QVariant Sprop = conDetails.property("Devices"); +// QList so = Sprop.value >(); +// foreach(QDBusObjectPath device, so) { +// if(device.path() == devicePath) { +// path = connection.path(); +// } +// break; +// } + } + } + } +qWarning() << ""; +} + +void NMView::deactivate() +{ + QList configs = manager->allConfigurations(QNetworkConfiguration::Active); + foreach(QNetworkConfiguration p, configs) { + qWarning() << "Active cons" << p.name(); + if(p.name() == cons->currentItem()->text(0) + && p.identifier() == cons->currentItem()->text(2)) { + qWarning() <<__FUNCTION__<< p.name(); + if(!sess) { + sess = new QNetworkSession(p); + + connect(sess, SIGNAL(stateChanged(QNetworkSession::State)), + this, SLOT(stateChanged(QNetworkSession::State))); + + connect(sess, SIGNAL(error(QNetworkSession::SessionError)), + this, SLOT(networkSessionError(QNetworkSession::SessionError))); + } + sess->close(); + delete sess; + sess = 0; + } + } +} + +void NMView::activate() +{ + qWarning() << __FUNCTION__ << cons->currentItem()->text(0); + + QList configs = manager->allConfigurations(); + foreach(QNetworkConfiguration p, configs) { + if(p.name() == cons->currentItem()->text(0)) { + + sess = new QNetworkSession(p); + + connect(sess, SIGNAL(newConfigurationActivated()), + this, SLOT(getActiveConnections())); + + connect(sess, SIGNAL(stateChanged(QNetworkSession::State)), + this, SLOT(stateChanged(QNetworkSession::State))); + + connect(sess, SIGNAL(error(QNetworkSession::SessionError)), + this, SLOT(networkSessionError(QNetworkSession::SessionError))); + + sess->open(); + } + } +} + +void NMView::getDevices() +{ + qWarning() << ""; + qWarning() << __FUNCTION__; + devicesTreeWidget->clear(); + //qDBusRegisterMetaType(); + + if (!dbc.isConnected()) { + qWarning() << "Unable to connect to D-Bus:" << dbc.lastError(); + return; + } + QDBusInterface iface(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + dbc); +//NetworkManager interface + if (!iface.isValid()) { + qWarning() << "Could not find NetworkManager"; + return; + } + +// uint state = iface.property("State").toUInt(); +// switch(state) { +// case NM_STATE_UNKNOWN: +// qWarning() << "State: Unknown"; break; +// case NM_STATE_ASLEEP: +// qWarning() << "State: Asleep"; break; +// case NM_STATE_CONNECTING: +// qWarning() << "State: Connecting"; break; +// case NM_STATE_CONNECTED: +// qWarning() << "State: Connected"; break; +// case NM_STATE_DISCONNECTED: +// qWarning() << "State: Disconnected"; break; +// } + + //get list of network devices + QTreeWidgetItem *item; + QDBusReply > reply = iface.call("GetDevices"); + if ( reply.isValid() ) { +// qWarning() << "Current devices:"; + QList list = reply.value(); + foreach(QDBusObjectPath path, list) { + QStringList devicesList; + qWarning() << " " << path.path(); + devicesList << path.path(); + + QDBusInterface devIface(NM_DBUS_SERVICE, + path.path(), + NM_DBUS_INTERFACE_DEVICE, + dbc); + if (devIface.isValid()) { + + + + ////// connect the dbus signal +// /*if(*/dbc.connect(NM_DBUS_SERVICE, +// path.path(), +// NM_DBUS_INTERFACE_DEVICE, +// "StateChanged", +// this,SLOT(deviceStateChanged(quint32))); +// { +// qWarning() << "XXXXXXXXXX dbus connect successful" << path.path(); +// } + + + // qWarning() << " Managed: " << devIface.property("Managed").toBool(); + devicesList << devIface.property("Managed").toString(); + // qWarning() << " Interface: " << devIface.property("Interface").toString(); + devicesList << devIface.property("Interface").toString(); + // qWarning() << " HAL UDI: " << devIface.property("Udi").toString(); + // qWarning() << " Driver: " << devIface.property("Driver").toString(); + devicesList << devIface.property("Driver").toString(); + + QString x = deviceTypeToString(devIface.property("DeviceType").toUInt()); + // qWarning() << " Type:" << x; + devicesList << x; + + if( devIface.property("DeviceType").toUInt() == DEVICE_TYPE_802_11_WIRELESS) { + qWarning() << "Device is WIFI"; + // // findAccessPoints(path.path()); + } + + QVariant v = devIface.property("State"); + x = deviceStateToString(v.toUInt()); +// qWarning() << " State:" << x; + devicesList << x; + + quint32 ip = devIface.property("Ip4Address").toUInt(); +// qWarning() << " IP4Address: " << QHostAddress(htonl(ip)).toString(); + devicesList << QHostAddress(htonl(ip)).toString(); + + + if (v.toUInt() == NM_DEVICE_STATE_ACTIVATED) { + QString path = devIface.property("Ip4Config").value().path(); +// qWarning() << " IP4Config: " << path; + devicesList << path; + QDBusInterface ipIface(NM_DBUS_SERVICE, + path, + NM_DBUS_INTERFACE_IP4_CONFIG, + dbc); + if (ipIface.isValid()) { + // qWarning() << " Hostname: " << ipIface.property("Hostname").toString(); + devicesList << ipIface.property("Hostname").toString(); +// qWarning() << " Domains: " << ipIface.property("Domains").toStringList(); + devicesList << ipIface.property("Domains").toStringList().join(", "); +// qWarning() << " NisDomain: " << ipIface.property("NisDomain").toString(); + QDBusArgument arg= ipIface.property("Addresses").value(); +// qWarning() << " Addresses: " << ipIface.property("Addresses"); +// qWarning() << " Nameservers: " << ipIface.property("Nameservers"); +// qWarning() << " NisServers: " << ipIface.property("NisServers"); + } + + } + + } + item = new QTreeWidgetItem(devicesList); + devicesTreeWidget->insertTopLevelItem(0, item); + } + } + + +// netconfig(); + +} + +void NMView::readSettings() +{ + QDBusInterface settingsiface(NM_DBUS_SERVICE_SYSTEM_SETTINGS, + NM_DBUS_PATH_SETTINGS, + NM_DBUS_IFACE_SETTINGS, + dbc); + //NetworkManagerSettings interface + if (settingsiface.isValid()) { + QDBusReply > reply = settingsiface.call("ListConnections"); + if ( reply.isValid() ) { + QList list = reply.value(); + foreach(QDBusObjectPath path, list) { + qWarning() <<__FUNCTION__ << path.path(); + + } + } + } + + QDBusInterface iface(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, dbc); + if (!iface.isValid()) { + qWarning() << "Could not find NetworkManager"; + return; + } + + // QStringList list = item->text().split(" -> "); + + QVariant prop = iface.property("ActiveConnections"); + QList connections = prop.value >(); + foreach(QDBusObjectPath path, connections) { + QDBusInterface conDetails(NM_DBUS_SERVICE, + path.path(), + NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + dbc); + + if (conDetails.isValid()) { + QString desc = path.path(); + qWarning() << desc; + //if ( item->text(0) == conDetails.property("Connection").value().path() ) { + // QListWidgetItem* item = new QTreeWidgetItem( desc, + // cons); + // item->setData(Qt::UserRole, desc); + // activeItemActivated( item ); + //} + } + } +} + +void NMView::printConnectionDetails(const QString& service) +{ + Q_UNUSED(service); + +// +// qWarning() << __FUNCTION__ << service; +// +// QDBusConnection dbc = QDBusConnection::systemBus(); +// if (!dbc.isConnected()) { +// qWarning() << "Unable to connect to D-Bus:" << dbc.lastError(); +// return; +// } +// QDBusInterface allCons(service, +// NM_DBUS_PATH_SETTINGS, +// NM_DBUS_IFACE_SETTINGS, +// dbc); +// +// if (allCons.isValid()) { +// QDBusReply > reply = allCons.call("ListConnections"); +// +// if ( reply.isValid() ) { +// qWarning() << "Known connections:"; +// QList list = reply.value(); +// +// foreach(QDBusObjectPath path, list) { +// qWarning() << " " << path.path(); +// +// QDBusInterface sysIface(NM_DBUS_SERVICE_SYSTEM_SETTINGS, +// path.path(), +// NM_DBUS_IFACE_SETTINGS_CONNECTION, +// dbc); +// +// if (sysIface.isValid()) { +// QDBusMessage r = sysIface.call("GetSettings"); +// QDBusReply< QSettingsMap > rep = sysIface.call("GetSettings"); +// +// qWarning() << " GetSettings:" << r.arguments() << r.signature() << rep.isValid() << sysIface.lastError(); +// +// QMap< QString, QMap > map = rep.value(); +// QList list = map.keys(); +// +// foreach (QString key, list) { +// QMap innerMap = map[key]; +// qWarning() << " Key: " << key; +// QMap::const_iterator i = innerMap.constBegin(); +// +// while (i != innerMap.constEnd()) { +// QString k = i.key(); +// qWarning() << " Key: " << k << " Entry: " << i.value(); +// +// if (k == "addresses" && i.value().canConvert()) { +// QDBusArgument arg = i.value().value(); +// arg.beginArray(); +// +// while (!arg.atEnd()) { +// QDBusVariant addr; +// arg >> addr; +// uint ip = addr.variant().toUInt(); +// qWarning() << ip; +// qWarning() << " " << QHostAddress(htonl(ip)).toString(); +// } +// +// } +// i++; +// } +// } +// } +// } +// } +// } + qWarning() << ""; +} + +void NMView::getNetworkDevices() +{ + +} + +void NMView::connectionItemActivated( QTreeWidgetItem * item, int col ) +{ + Q_UNUSED(col); + + qWarning() <<__FUNCTION__<< item->text(0); + QDBusInterface iface(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + dbc); + if (!iface.isValid()) { + qWarning() << "Could not find NetworkManager"; + return; + } + QVariant prop = iface.property("ActiveConnections"); + QList connections = prop.value >(); + foreach(QDBusObjectPath path, connections) { + QDBusInterface conDetails(NM_DBUS_SERVICE, + path.path(), + NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + dbc); + + if (conDetails.isValid()) { + QString desc = path.path(); + qWarning() << desc; + if ( item->text(0) == conDetails.property("Connection").value().path() ) { +// QListWidgetItem* item = new QTreeWidgetItem( desc, +// cons); +// item->setData(Qt::UserRole, desc); +// activeItemActivated( item ); + } + } + } +} + + + +void NMView::deviceItemActivated( QTreeWidgetItem * item , int section) +{ + Q_UNUSED(item); + Q_UNUSED(section); + + // qWarning() << item->text(section) << item->text(4); + //if(item->text(4) == "Wireless") findAccessPoints(item->text(0)); +} + + +void NMView::netconfig() +{ +// qWarning() << __FUNCTION__; + +// qDBusRegisterMetaType(); + QDBusConnection dbc = QDBusConnection::systemBus(); + if (!dbc.isConnected()) { + qWarning() << "Unable to connect to D-Bus:" << dbc.lastError(); + return; + } + + QDBusInterface iface(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_IFACE_SETTINGS_CONNECTION, + dbc); + if (!iface.isValid()) { + qWarning() << "Could not find NetworkManager Settings"; + return; + } else { + QDBusReply > reply = iface.call("ListConnections"); + QList list = reply.value(); +// qWarning() << reply.value(); + foreach(QDBusObjectPath path, list) { + qWarning() << " " << path.path(); + } + } +} + + +void NMView::findAccessPoints() +{ + accessPointsTreeWidget->clear(); + + QDBusInterface iface(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + dbc); + + QDBusReply > reply = iface.call("GetDevices"); + if ( reply.isValid() ) { + QList list = reply.value(); + foreach(QDBusObjectPath path, list) { + QDBusInterface devIface(NM_DBUS_SERVICE, + path.path(), + NM_DBUS_INTERFACE_DEVICE, + dbc); + if (devIface.isValid()) { + + if( devIface.property("DeviceType").toUInt() == DEVICE_TYPE_802_11_WIRELESS) { + +// qWarning() <<"deviface"<< devIface.path(); + QDBusInterface wififace(NM_DBUS_SERVICE, + devIface.path(), + NM_DBUS_INTERFACE_DEVICE_WIRELESS, + dbc); + if (!wififace.isValid()) { + qWarning() << "Could not find NetworkManager wireless interface"; + return; + } + +///////////////////////// +// if(dbc.connect(NM_DBUS_SERVICE, +// path.path(), +// NM_DBUS_INTERFACE_DEVICE_WIRELESS, +// "PropertiesChanged", +// this,SLOT(aPPropertiesChanged( QMap))) ) { +// qWarning() << "PropertiesChanged connect"; +// } else { +// qWarning() << "NOT connect"; + +// } +///////////////////////// + qWarning() <<"wififace"<< wififace.path(); + QDBusReply > reply2 = wififace.call("GetAccessPoints"); + if ( reply2.isValid() ) { + QTreeWidgetItem *item; + QList list2 = reply2.value(); + foreach(QDBusObjectPath path2, list2) { + QDBusInterface accessPointIface(NM_DBUS_SERVICE, + path2.path(), + NM_DBUS_INTERFACE_ACCESS_POINT, + dbc); + if (accessPointIface.isValid()) { +//// qWarning() <<"path2" << path2.path(); + +// if(dbc.connect(NM_DBUS_SERVICE, //signal strength +// path2.path(), +// NM_DBUS_INTERFACE_ACCESS_POINT, +// "PropertiesChanged", +// this,SLOT(aPPropertiesChanged( QMap))) ) { +// qWarning() << "PropertiesChanged connect"; +// } else { +// qWarning() << "NOT connect"; +// +// } + + QStringList accessPoints; + accessPoints << accessPointIface.property("Ssid").toString(); + accessPoints << QString::number(accessPointIface.property("Strength").toInt()); + accessPoints << securityCapabilitiesToString(accessPointIface.property("WpaFlags" ).toInt()); + accessPoints << securityCapabilitiesToString(accessPointIface.property("RsnFlags" ).toInt()); + accessPoints << accessPointIface.property("Frequency" ).toString(); + accessPoints << accessPointIface.property("HwAddress" ).toString(); + accessPoints << deviceModeToString(accessPointIface.property("Mode" ).toInt()); + accessPoints << accessPointIface.property("MaxBitrate" ).toString(); + //HwAddress + // if(accessPointIface.property("Flags" ).toInt() == NM_802_11_AP_FLAGS_PRIVACY ) { + // qWarning() << "Secure"; + // } + item = new QTreeWidgetItem(accessPoints); + accessPointsTreeWidget->insertTopLevelItem(0, item); + } + } + } + } + } + } + } +} + +QString NMView::deviceStateToString(int state) +{ + QString ret; + switch(state) { + case NM_DEVICE_STATE_UNKNOWN: + ret = "Unknown"; + break; + case NM_DEVICE_STATE_UNMANAGED: + ret = "Unmanaged"; + break; + case NM_DEVICE_STATE_UNAVAILABLE: + ret = "Unavailable"; + break; + case NM_DEVICE_STATE_DISCONNECTED: + ret = "Disconnected"; + break; + case NM_DEVICE_STATE_PREPARE: + ret = "Preparing to connect"; + break; + case NM_DEVICE_STATE_CONFIG: + ret = "Being configured"; + break; + case NM_DEVICE_STATE_NEED_AUTH: + ret = "Awaiting secrets"; + break; + case NM_DEVICE_STATE_IP_CONFIG: + ret = "IP requested"; + break; + case NM_DEVICE_STATE_ACTIVATED: + ret = "Activated"; + break; + case NM_DEVICE_STATE_FAILED: + ret = "FAILED"; + break; + }; + return ret; +} + +QString NMView::deviceTypeToString(int device) +{ + QString ret; + switch(device) { + case DEVICE_TYPE_UNKNOWN: + ret = "Unknown"; + break; + case DEVICE_TYPE_802_3_ETHERNET: + ret = "Ethernet"; + break; + case DEVICE_TYPE_802_11_WIRELESS: + ret = "Wireless"; + break; + case DEVICE_TYPE_GSM: + ret = "GSM"; + break; + case DEVICE_TYPE_CDMA: + ret = "CDMA"; + break; + }; + return ret; +} + +QString NMView::securityCapabilitiesToString(int caps) +{ + int check = caps; +// qWarning() << __FUNCTION__<< caps; + QString ret; + if( check == 0 ) + ret += "None."; + if( (check & NM_802_11_AP_SEC_PAIR_WEP40)) + ret += " 40-bit WEP encryption. "; + if( (check & NM_802_11_AP_SEC_PAIR_WEP104) ) + ret += " 104-bit WEP encryption. "; + if( (check & NM_802_11_AP_SEC_PAIR_TKIP) ) + ret += " TKIP encryption. "; + if( (check & NM_802_11_AP_SEC_PAIR_CCMP) ) + ret += " CCMP encryption. "; + if( (check & NM_802_11_AP_SEC_GROUP_WEP40)) + ret += " 40-bit WEP cipher. "; + if( (check & NM_802_11_AP_SEC_GROUP_WEP104)) + ret += " 104-bit WEP cipher. "; + if( (check & NM_802_11_AP_SEC_GROUP_TKIP) ) + ret += " TKIP cipher. "; + if( (check & NM_802_11_AP_SEC_GROUP_CCMP) ) + ret += " CCMP cipher. "; + if( (check & NM_802_11_AP_SEC_KEY_MGMT_PSK)) + ret += " PSK key management. "; + if( (check & NM_802_11_AP_SEC_KEY_MGMT_802_1X) ) + ret += " 802.1x key management. "; + return ret; +} + +QString NMView::deviceModeToString(int mode) +{ + QString ret; + switch (mode) { + case NM_802_11_MODE_UNKNOWN: + ret = "Unknown"; + break; + case NM_802_11_MODE_ADHOC: + ret = " (Adhoc)."; + break; + case NM_802_11_MODE_INFRA: + ret = " (Infrastructure)"; + }; + return ret; +} + +void NMView::netManagerState(quint32 state) +{ + qWarning() << __FUNCTION__ << state;// << old << reason; + switch(state) { + case NM_STATE_UNKNOWN: + qWarning() << "The NetworkManager daemon is in an unknown state. "; + break; + case NM_STATE_ASLEEP: + qWarning() << "The NetworkManager daemon is asleep and all interfaces managed by it are inactive. "; + break; + case NM_STATE_CONNECTING: + qWarning() << "The NetworkManager daemon is connecting a device. FIXME: What does this mean when one device is active and another is connecting? "; + break; + case NM_STATE_CONNECTED: + qWarning() <<"The NetworkManager daemon is connected. "; + break; + case NM_STATE_DISCONNECTED: + qWarning() << "The NetworkManager daemon is disconnected."; + break; + + }; +} + +void NMView::deviceStateChanged(quint32 state) +{ + qWarning() << __FUNCTION__ << state; + switch(state) { + case NM_DEVICE_STATE_UNKNOWN : + qWarning() <<"The device is in an unknown state. "; + break; + case NM_DEVICE_STATE_UNMANAGED: + qWarning() <<"The device is not managed by NetworkManager."; + break; + case NM_DEVICE_STATE_UNAVAILABLE: + qWarning() <<"The device cannot be used (carrier off, rfkill, etc)."; + break; + case NM_DEVICE_STATE_DISCONNECTED: + qWarning() <<"The device is not connected."; + break; + case NM_DEVICE_STATE_PREPARE: + qWarning() <<"The device is preparing to connect."; + break; + case NM_DEVICE_STATE_CONFIG: + qWarning() <<"The device is being configured."; + break; + case NM_DEVICE_STATE_NEED_AUTH: + qWarning() <<"The device is awaiting secrets necessary to continue connection."; + break; + case NM_DEVICE_STATE_IP_CONFIG: + qWarning() <<"The IP settings of the device are being requested and configured."; + break; + case NM_DEVICE_STATE_ACTIVATED: + qWarning() <<"The device is active."; + break; + case NM_DEVICE_STATE_FAILED: + qWarning() <<"The device is in a failure state following an attempt to activate it."; + break; + }; +} + +void NMView::updateCompleted() +{ + qWarning() << __FUNCTION__; +} + +void NMView::newConfigurationActivated() +{ + qWarning() << __FUNCTION__; + getActiveConnections(); +} + +void NMView::stateChanged(QNetworkSession::State state) +{ + // QString stateStringstr; + switch (state) { + case QNetworkSession::Invalid: + stateString = "Invalid session"; + break; + case QNetworkSession::NotAvailable: + stateString = "Session is defined but not yet discovered"; + break; + case QNetworkSession::Connecting: + stateString = "Session is being established"; + break; + case QNetworkSession::Connected: + stateString = "Session is active and can be used for socket operations"; + cons->currentItem()->setText(1, "Active"); + break; + case QNetworkSession::Closing: + stateString = "Session is being shutdown"; + break; + case QNetworkSession::Disconnected: + qWarning() << __FUNCTION__; + manager->updateConfigurations(); + stateString = "Session disconnected"; + cons->currentItem()->setText(1,"Discovered") ; + break; + case QNetworkSession::Roaming: + stateString = "session is roaming from one AP to another"; + break; + }; + qWarning() << __FUNCTION__ << state << stateString; +} + +QString NMView::stateToString(int state) +{ + switch (state) { + case QNetworkConfiguration::Undefined: + return "Undefined"; + break; + case QNetworkConfiguration::Defined: + return "Defined"; + break; + case QNetworkConfiguration::Discovered: + return "Discovered"; + break; + case QNetworkConfiguration::Active: + return "Active"; + break; + }; + return ""; +} + +void NMView::configurationAdded(const QNetworkConfiguration &config) +{ + qWarning() << __FUNCTION__<< config.name() << config.identifier(); +} + +QString NMView::typeToString(int type) +{ + switch(type) { + case QNetworkConfiguration::InternetAccessPoint: + return "Internet AccessPoint"; + break; + case QNetworkConfiguration::ServiceNetwork: + return "Service Network"; + break; + }; + return QString(); +} + +void NMView::aPPropertiesChanged( QMap map) +{ + //QMap::const_iterator iterator = d->values.find(type + QLatin1String("Path")) + QMapIterator i(map); + while (i.hasNext()) { + i.next(); + if( i.key() == "State") { + qWarning() << __FUNCTION__ << i.key() << ": " << i.value().toUInt(); +// deviceStateChanged(i.value().toUInt()); + } else if( i.key() == "ActiveAccessPoint") { + qWarning() << __FUNCTION__ << i.key() << ": " << i.value().value().path(); + } else if( i.key() == "Strength") + qWarning() << __FUNCTION__ << i.key() << ": " << i.value().toUInt(); + else + qWarning() << __FUNCTION__ << i.key() << ": " << i.value(); + } +} + +void NMView::networkSessionError(QNetworkSession::SessionError error) +{ + QString errorStr; + switch(error) { + case QNetworkSession::RoamingError: + errorStr = "Roaming error"; + break; + case QNetworkSession::SessionAbortedError: + errorStr = "Session aborted by user or system"; + break; + default: + case QNetworkSession::UnknownSessionError: + errorStr = "Unidentified Error"; + break; + }; + + QMessageBox::warning(this, tr("NMView"), errorStr, QMessageBox::Ok); +} diff --git a/tests/manual/networkmanager/nmview.h b/tests/manual/networkmanager/nmview.h new file mode 100644 index 0000000..641385e --- /dev/null +++ b/tests/manual/networkmanager/nmview.h @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 +#include +#include +#include +#include + +#include "ui_dialog.h" + +QTM_USE_NAMESPACE + +class QListWidget; +class QTreeWidget; +class QTreeWidgetItem; + +class NMView : public QDialog, private Ui::Dialog +{ + Q_OBJECT +public: + NMView(QDialog* parent = 0); + virtual ~NMView(); + +private: + void init(); + QString stateString; + + QDBusConnection dbc; + void printConnectionDetails(const QString&); + + QString deviceStateToString(int state); + QString deviceTypeToString(int device); + QString securityCapabilitiesToString(int caps); + QString deviceModeToString(int mode); +//QDBusInterface getInterface(); + QNetworkConfigurationManager *manager; + QNetworkSession *sess; + QString stateToString(int state); + QString typeToString(int type); + +private slots: + void update(); + void deactivate(); + void activate(); + void getActiveConnections(); + void updateConnections(); + void getDevices(); + // void readConnectionManagerDetails(); + void getNetworkDevices(); + void connectionItemActivated( QTreeWidgetItem *, int); +// void activeItemActivated( QListWidgetItem *); + void deviceItemActivated( QTreeWidgetItem *, int); + void netconfig(); + void findAccessPoints(); + + void netManagerState(quint32); + void readSettings(); + void updateCompleted(); + void newConfigurationActivated(); + + void stateChanged(QNetworkSession::State); + void deviceStateChanged(quint32 state); + + void configurationAdded(const QNetworkConfiguration &config); + void aPPropertiesChanged( QMap map); + void networkSessionError(QNetworkSession::SessionError); + +}; diff --git a/tests/manual/networkmanager/startdlg.cpp b/tests/manual/networkmanager/startdlg.cpp new file mode 100644 index 0000000..4720932 --- /dev/null +++ b/tests/manual/networkmanager/startdlg.cpp @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 "startdlg.h" +#include + + +StartDialog::StartDialog(QWidget * parent) + :QDialog(parent) +{ + QVBoxLayout *layout = new QVBoxLayout(this); + box = new QComboBox(); + layout->addWidget(box); + + QHBoxLayout* hbox = new QHBoxLayout(); + QPushButton* start = new QPushButton("Start"); + connect(start, SIGNAL(clicked()), this, SLOT(accept())); + QPushButton* cancel = new QPushButton("Cancel"); + connect(cancel, SIGNAL(clicked()), this, SLOT(reject())); + + + hbox->addWidget(start); + hbox->addWidget(cancel); + + layout->addLayout(hbox); + + QDBusConnection dbc = QDBusConnection::systemBus(); + if (!dbc.isConnected()) { + qWarning() << "Unable to connect to D-Bus:" << dbc.lastError(); + return; + } + QDBusInterface iface(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, dbc); + if (!iface.isValid()) { + qWarning() << "Could not find NetworkManager"; + return; + } + QDBusReply > reply = iface.call("GetDevices"); + if ( reply.isValid() ) { + QList list = reply.value(); + foreach(QDBusObjectPath path, list) { + QDBusInterface devIface(NM_DBUS_SERVICE, path.path(), NM_DBUS_INTERFACE_DEVICE, dbc); + if ( devIface.isValid() ) { + box->addItem(devIface.property("Interface").toString(), QVariant(path.path())); + } + } + } +} + +QString StartDialog::device() const +{ + return dev; +} + +void StartDialog::accept() +{ + dev = box->itemData(box->currentIndex(), Qt::UserRole).toString(); + QDialog::accept(); +} diff --git a/tests/manual/networkmanager/startdlg.h b/tests/manual/networkmanager/startdlg.h new file mode 100644 index 0000000..a9f1e7c --- /dev/null +++ b/tests/manual/networkmanager/startdlg.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 +#include +#include + +class StartDialog : public QDialog +{ + Q_OBJECT +public: + StartDialog(QWidget* parent = 0); + + QString device() const; + +public slots: + void accept(); +private: + QString dev; + QComboBox* box; +}; -- cgit v0.12 From aedf9f81641ba4a85b15e35e6ac8ff457265133a Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 22 Dec 2009 13:54:49 +1000 Subject: Make compile. --- examples/network/bearercloud/bearercloud.h | 2 +- examples/network/bearercloud/bearercloud.pro | 18 --- examples/network/bearercloud/cloud.h | 2 +- examples/network/bearermonitor/bearermonitor.h | 2 +- examples/network/bearermonitor/bearermonitor.pro | 24 ++-- examples/network/bearermonitor/sessionwidget.h | 2 +- examples/network/network.pro | 4 +- src/network/bearer/bearer.pri | 130 +++++++++++++++++++++ src/network/bearer/qcorewlanengine_mac.mm | 4 +- src/network/bearer/qcorewlanengine_mac_p.h | 5 +- src/network/bearer/qgenericengine.cpp | 4 +- src/network/bearer/qgenericengine_p.h | 4 +- src/network/bearer/qnativewifiengine_win.cpp | 4 +- src/network/bearer/qnativewifiengine_win_p.h | 4 +- src/network/bearer/qnetworkconfigmanager.cpp | 4 +- src/network/bearer/qnetworkconfigmanager.h | 8 +- src/network/bearer/qnetworkconfigmanager_maemo.cpp | 4 +- src/network/bearer/qnetworkconfigmanager_maemo_p.h | 4 +- src/network/bearer/qnetworkconfigmanager_p.cpp | 4 +- src/network/bearer/qnetworkconfigmanager_p.h | 4 +- src/network/bearer/qnetworkconfigmanager_s60_p.cpp | 4 +- src/network/bearer/qnetworkconfigmanager_s60_p.h | 4 +- src/network/bearer/qnetworkconfiguration.cpp | 4 +- src/network/bearer/qnetworkconfiguration.h | 9 +- src/network/bearer/qnetworkconfiguration_maemo_p.h | 4 +- src/network/bearer/qnetworkconfiguration_p.h | 4 +- src/network/bearer/qnetworkconfiguration_s60_p.cpp | 4 +- src/network/bearer/qnetworkconfiguration_s60_p.h | 4 +- src/network/bearer/qnetworkmanagerservice_p.cpp | 4 +- src/network/bearer/qnetworkmanagerservice_p.h | 13 +-- src/network/bearer/qnetworksession.cpp | 4 +- src/network/bearer/qnetworksession.h | 8 +- src/network/bearer/qnetworksession_maemo.cpp | 4 +- src/network/bearer/qnetworksession_maemo_p.h | 4 +- src/network/bearer/qnetworksession_p.cpp | 4 +- src/network/bearer/qnetworksession_p.h | 5 +- src/network/bearer/qnetworksession_s60_p.cpp | 4 +- src/network/bearer/qnetworksession_s60_p.h | 4 +- src/network/bearer/qnetworksessionengine.cpp | 4 +- src/network/bearer/qnetworksessionengine_p.h | 5 +- src/network/bearer/qnlaengine_win.cpp | 4 +- src/network/bearer/qnlaengine_win_p.h | 4 +- src/network/bearer/qnmdbushelper.cpp | 4 +- src/network/bearer/qnmdbushelper_p.h | 5 +- src/network/bearer/qnmwifiengine_unix.cpp | 10 +- src/network/bearer/qnmwifiengine_unix_p.h | 4 +- src/network/network.pro | 1 + tests/auto/auto.pro | 3 + .../qnetworkconfigmanager.pro | 12 +- .../tst_qnetworkconfigmanager.cpp | 2 +- .../qnetworkconfiguration.pro | 12 +- .../tst_qnetworkconfiguration.cpp | 2 +- tests/auto/qnetworksession/lackey/lackey.pro | 10 +- tests/auto/qnetworksession/lackey/main.cpp | 2 +- .../tst_qnetworksession/tst_qnetworksession.cpp | 2 +- .../tst_qnetworksession/tst_qnetworksession.pro | 18 +-- tests/manual/bearerex/bearerex.h | 2 +- tests/manual/bearerex/bearerex.pro | 16 --- tests/manual/networkmanager/networkmanager.pro | 10 -- tests/manual/networkmanager/nmview.cpp | 2 +- tests/manual/networkmanager/nmview.h | 2 +- 61 files changed, 245 insertions(+), 219 deletions(-) create mode 100644 src/network/bearer/bearer.pri diff --git a/examples/network/bearercloud/bearercloud.h b/examples/network/bearercloud/bearercloud.h index c18ffd3..79b441f 100644 --- a/examples/network/bearercloud/bearercloud.h +++ b/examples/network/bearercloud/bearercloud.h @@ -45,7 +45,7 @@ #include #include -QTM_USE_NAMESPACE +QT_USE_NAMESPACE class Cloud; diff --git a/examples/network/bearercloud/bearercloud.pro b/examples/network/bearercloud/bearercloud.pro index 308ddda..c45d62a 100644 --- a/examples/network/bearercloud/bearercloud.pro +++ b/examples/network/bearercloud/bearercloud.pro @@ -10,21 +10,3 @@ RESOURCES = icons.qrc TARGET = bearercloud QT = core gui network svg - -INCLUDEPATH += ../../src/bearer - -include(../examples.pri) - -qtAddLibrary(QtBearer) - -CONFIG += console - -include(../examples.pri) - - -macx: { - contains(QT_CONFIG,qt_framework):LIBS += -framework QtBearer - INCLUDEPATH += ../../ - contains(CONFIG, debug) { - } -} diff --git a/examples/network/bearercloud/cloud.h b/examples/network/bearercloud/cloud.h index 4ce43df..f844725 100644 --- a/examples/network/bearercloud/cloud.h +++ b/examples/network/bearercloud/cloud.h @@ -43,7 +43,7 @@ #include #include -QTM_USE_NAMESPACE +QT_USE_NAMESPACE class QGraphicsTextItem; class QGraphicsSvgItem; diff --git a/examples/network/bearermonitor/bearermonitor.h b/examples/network/bearermonitor/bearermonitor.h index d1f4601..9306d90 100644 --- a/examples/network/bearermonitor/bearermonitor.h +++ b/examples/network/bearermonitor/bearermonitor.h @@ -50,7 +50,7 @@ #include "ui_bearermonitor_640_480.h" #endif -QTM_USE_NAMESPACE +QT_USE_NAMESPACE class SessionWidget; diff --git a/examples/network/bearermonitor/bearermonitor.pro b/examples/network/bearermonitor/bearermonitor.pro index c8fb3c2..a854b55 100644 --- a/examples/network/bearermonitor/bearermonitor.pro +++ b/examples/network/bearermonitor/bearermonitor.pro @@ -4,7 +4,7 @@ HEADERS = sessionwidget.h \ SOURCES = main.cpp \ bearermonitor.cpp \ sessionwidget.cpp - + FORMS = bearermonitor_240_320.ui \ bearermonitor_640_480.ui \ sessionwidget.ui @@ -13,20 +13,10 @@ TARGET = bearermonitor QT = core gui network -INCLUDEPATH += ../../src/bearer - -include(../examples.pri) - -qtAddLibrary(QtBearer) -win32:!wince*:LIBS += -lWs2_32 -wince*:LIBS += -lWs2 - -CONFIG += console - -include(../examples.pri) - -macx: { - contains(QT_CONFIG,qt_framework):LIBS += -framework QtBearer - contains(CONFIG, debug) { - } +win32 { + !wince* { + LIBS += -lWs2_32 + } else { + LIBS += -lWs2 + } } diff --git a/examples/network/bearermonitor/sessionwidget.h b/examples/network/bearermonitor/sessionwidget.h index cb6591e..8bc60e4 100644 --- a/examples/network/bearermonitor/sessionwidget.h +++ b/examples/network/bearermonitor/sessionwidget.h @@ -46,7 +46,7 @@ #include -QTM_USE_NAMESPACE +QT_USE_NAMESPACE class SessionWidget : public QWidget, public Ui_SessionWidget { diff --git a/examples/network/network.pro b/examples/network/network.pro index c5a97fb..bd632b8 100644 --- a/examples/network/network.pro +++ b/examples/network/network.pro @@ -11,7 +11,9 @@ SUBDIRS = blockingfortuneclient \ loopback \ threadedfortuneserver \ googlesuggest \ - torrent + torrent \ + bearercloud \ + bearermonitor # no QProcess !vxworks:!qnx:SUBDIRS += network-chat diff --git a/src/network/bearer/bearer.pri b/src/network/bearer/bearer.pri new file mode 100644 index 0000000..d8ddce5 --- /dev/null +++ b/src/network/bearer/bearer.pri @@ -0,0 +1,130 @@ +# Qt network bearer management module + +#DEFINES += BEARER_MANAGEMENT_DEBUG + +HEADERS += bearer/qnetworkconfiguration.h \ + bearer/qnetworksession.h \ + bearer/qnetworkconfigmanager.h + +SOURCES += bearer/qnetworksession.cpp \ + bearer/qnetworkconfigmanager.cpp \ + bearer/qnetworkconfiguration.cpp + +symbian { + exists($${EPOCROOT}epoc32/release/winscw/udeb/cmmanager.lib)| \ + exists($${EPOCROOT}epoc32/release/armv5/lib/cmmanager.lib) { + message("Building with SNAP support") + DEFINES += SNAP_FUNCTIONALITY_AVAILABLE + LIBS += -lcmmanager + } else { + message("Building without SNAP support") + LIBS += -lapengine + } + + INCLUDEPATH += $$APP_LAYER_SYSTEMINCLUDE + + HEADERS += bearer/qnetworkconfigmanager_s60_p.h \ + bearer/qnetworkconfiguration_s60_p.h \ + bearer/qnetworksession_s60_p.h + SOURCES += bearer/qnetworkconfigmanager_s60_p.cpp \ + bearer/qnetworkconfiguration_s60_p.cpp \ + bearer/qnetworksession_s60_p.cpp + + LIBS += -lcommdb \ + -lapsettingshandlerui \ + -lconnmon \ + -lcentralrepository \ + -lesock \ + -linsock \ + -lecom \ + -lefsrv \ + -lnetmeta +} else:maemo { + QT += dbus + 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 { + DEFINES += BEARER_ENGINE + + HEADERS += bearer/qnetworkconfigmanager_p.h \ + bearer/qnetworkconfiguration_p.h \ + bearer/qnetworksession_p.h \ + bearer/qnetworksessionengine_p.h \ + bearer/qgenericengine_p.h + + SOURCES += bearer/qnetworkconfigmanager_p.cpp \ + bearer/qnetworksession_p.cpp \ + bearer/qnetworksessionengine.cpp \ + bearer/qgenericengine.cpp + + unix:!mac:contains(networkmanager_enabled, yes) { + contains(QT_CONFIG,dbus) { + DEFINES += BACKEND_NM + QT += dbus + + HEADERS += bearer/qnmdbushelper_p.h \ + bearer/qnetworkmanagerservice_p.h \ + bearer/qnmwifiengine_unix_p.h + + SOURCES += bearer/qnmdbushelper.cpp \ + bearer/qnetworkmanagerservice_p.cpp \ + bearer/qnmwifiengine_unix.cpp + } else { + message("NetworkManager backend requires Qt DBus support") + } + } + + win32 { + HEADERS += bearer/qnlaengine_win_p.h \ + bearer/qnetworksessionengine_win_p.h + + SOURCES += bearer/qnlaengine_win.cpp + + !wince* { + HEADERS += bearer/qnativewifiengine_win_p.h + + SOURCES += bearer/qnativewifiengine_win.cpp + + LIBS += -lWs2_32 + } else { + LIBS += -lWs2 + } + } + + macx { + HEADERS += bearer/qcorewlanengine_mac_p.h + SOURCES+= bearer/qcorewlanengine_mac.mm + LIBS += -framework Foundation -framework SystemConfiguration + + contains(corewlan_enabled, yes) { + isEmpty(QMAKE_MAC_SDK)|contains(QMAKE_MAC_SDK, "/Developer/SDKs/MacOSX10.6.sdk") { + LIBS += -framework CoreWLAN + DEFINES += MAC_SDK_10_6 + } + } + } +} + diff --git a/src/network/bearer/qcorewlanengine_mac.mm b/src/network/bearer/qcorewlanengine_mac.mm index 5451615..5854384 100644 --- a/src/network/bearer/qcorewlanengine_mac.mm +++ b/src/network/bearer/qcorewlanengine_mac.mm @@ -63,7 +63,7 @@ #include QMap networkInterfaces; -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC(QCoreWlanEngine, coreWlanEngine) @@ -457,5 +457,5 @@ bool QCoreWlanEngine::getAllScInterfaces() #include "moc_qcorewlanengine_mac_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qcorewlanengine_mac_p.h b/src/network/bearer/qcorewlanengine_mac_p.h index fc8e4b5..660ddb5 100644 --- a/src/network/bearer/qcorewlanengine_mac_p.h +++ b/src/network/bearer/qcorewlanengine_mac_p.h @@ -56,7 +56,8 @@ #include "qnetworksessionengine_p.h" #include #include -QTM_BEGIN_NAMESPACE + +QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; @@ -94,7 +95,7 @@ private: bool isKnownSsid(const QString &interfaceName, const QString &ssid); }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif diff --git a/src/network/bearer/qgenericengine.cpp b/src/network/bearer/qgenericengine.cpp index 184a69c..2e48ce8 100644 --- a/src/network/bearer/qgenericengine.cpp +++ b/src/network/bearer/qgenericengine.cpp @@ -53,7 +53,7 @@ #include "qnetworksessionengine_win_p.h" #endif -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC(QGenericEngine, genericEngine) @@ -230,5 +230,5 @@ QGenericEngine *QGenericEngine::instance() } #include "moc_qgenericengine_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qgenericengine_p.h b/src/network/bearer/qgenericengine_p.h index 976776e..88de2a0 100644 --- a/src/network/bearer/qgenericengine_p.h +++ b/src/network/bearer/qgenericengine_p.h @@ -58,7 +58,7 @@ #include #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; @@ -88,7 +88,7 @@ private: QTimer pollTimer; }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif diff --git a/src/network/bearer/qnativewifiengine_win.cpp b/src/network/bearer/qnativewifiengine_win.cpp index d8fe5fb..b4b3888 100644 --- a/src/network/bearer/qnativewifiengine_win.cpp +++ b/src/network/bearer/qnativewifiengine_win.cpp @@ -52,7 +52,7 @@ #include #undef interface -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC(QNativeWifiEngine, nativeWifiEngine) @@ -723,4 +723,4 @@ QNativeWifiEngine *QNativeWifiEngine::instance() #include "moc_qnativewifiengine_win_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnativewifiengine_win_p.h b/src/network/bearer/qnativewifiengine_win_p.h index 0d5bcb0..adc75e1 100644 --- a/src/network/bearer/qnativewifiengine_win_p.h +++ b/src/network/bearer/qnativewifiengine_win_p.h @@ -57,7 +57,7 @@ #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; @@ -90,6 +90,6 @@ private: Qt::HANDLE handle; }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index 264f0df..4b28b22 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -47,7 +47,7 @@ #include "qnetworkconfigmanager_p.h" #endif -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC(QNetworkConfigurationManagerPrivate, connManager); @@ -329,5 +329,5 @@ void QNetworkConfigurationManager::updateConfigurations() #include "moc_qnetworkconfigmanager.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworkconfigmanager.h b/src/network/bearer/qnetworkconfigmanager.h index 98641f6..940fcc5 100644 --- a/src/network/bearer/qnetworkconfigmanager.h +++ b/src/network/bearer/qnetworkconfigmanager.h @@ -42,17 +42,15 @@ #ifndef QNETWORKCONFIGURATIONMANAGER_H #define QNETWORKCONFIGURATIONMANAGER_H -#include "qmobilityglobal.h" - #include #include "qnetworkconfiguration.h" QT_BEGIN_HEADER -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkConfigurationManagerPrivate; -class Q_BEARER_EXPORT QNetworkConfigurationManager : public QObject +class Q_NETWORK_EXPORT QNetworkConfigurationManager : public QObject { Q_OBJECT @@ -93,7 +91,7 @@ Q_SIGNALS: Q_DECLARE_OPERATORS_FOR_FLAGS(QNetworkConfigurationManager::Capabilities) -QTM_END_NAMESPACE +QT_END_NAMESPACE QT_END_HEADER diff --git a/src/network/bearer/qnetworkconfigmanager_maemo.cpp b/src/network/bearer/qnetworkconfigmanager_maemo.cpp index 795b054..26909f9 100644 --- a/src/network/bearer/qnetworkconfigmanager_maemo.cpp +++ b/src/network/bearer/qnetworkconfigmanager_maemo.cpp @@ -53,7 +53,7 @@ #include #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE #define IAP "/system/osso/connectivity/IAP" static int iap_prefix_len; @@ -757,4 +757,4 @@ void QNetworkConfigurationManagerPrivate::configChanged(QNetworkConfigurationPri #include "qnetworkconfigmanager_maemo.moc" #include "moc_qnetworkconfigmanager_maemo_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworkconfigmanager_maemo_p.h b/src/network/bearer/qnetworkconfigmanager_maemo_p.h index e182495..a5462b8 100644 --- a/src/network/bearer/qnetworkconfigmanager_maemo_p.h +++ b/src/network/bearer/qnetworkconfigmanager_maemo_p.h @@ -60,7 +60,7 @@ #include #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkConfigurationManagerPrivate : public QObject @@ -136,6 +136,6 @@ Q_SIGNALS: void onlineStateChanged(bool isOnline); }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif //QNETWORKCONFIGURATIONMANAGERPRIVATE_H diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 8b15f41..49135c1 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -59,7 +59,7 @@ #include #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE void QNetworkConfigurationManagerPrivate::registerPlatformCapabilities() { @@ -446,5 +446,5 @@ void QNetworkConfigurationManagerPrivate::performAsyncConfigurationUpdate() #include "moc_qnetworkconfigmanager_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index 0c42f9b..184d1bd 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -59,7 +59,7 @@ #include #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE #ifdef BEARER_ENGINE class QNetworkSessionEngine; @@ -173,6 +173,6 @@ private Q_SLOTS: #endif }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif //QNETWORKCONFIGURATIONMANAGERPRIVATE_H diff --git a/src/network/bearer/qnetworkconfigmanager_s60_p.cpp b/src/network/bearer/qnetworkconfigmanager_s60_p.cpp index 760a194..8859a4e 100644 --- a/src/network/bearer/qnetworkconfigmanager_s60_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_s60_p.cpp @@ -58,7 +58,7 @@ #include #endif -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE static const int KValueThatWillBeAddedToSNAPId = 1000; static const int KUserChoiceIAPId = 0; @@ -971,4 +971,4 @@ void AccessPointsAvailabilityScanner::RunL() } } #include "moc_qnetworkconfigmanager_s60_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworkconfigmanager_s60_p.h b/src/network/bearer/qnetworkconfigmanager_s60_p.h index 296d67f..cd48df6 100644 --- a/src/network/bearer/qnetworkconfigmanager_s60_p.h +++ b/src/network/bearer/qnetworkconfigmanager_s60_p.h @@ -65,7 +65,7 @@ class CCommsDatabase; class QTimer; -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkSessionPrivate; class AccessPointsAvailabilityScanner; @@ -177,6 +177,6 @@ private: // Data TConnMonIapInfoBuf iIapBuf; }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif //QNETWORKCONFIGURATIONMANAGERPRIVATE_H diff --git a/src/network/bearer/qnetworkconfiguration.cpp b/src/network/bearer/qnetworkconfiguration.cpp index c92b356..9422f07 100644 --- a/src/network/bearer/qnetworkconfiguration.cpp +++ b/src/network/bearer/qnetworkconfiguration.cpp @@ -47,7 +47,7 @@ #include "qnetworkconfiguration_p.h" #endif -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE /*! \class QNetworkConfiguration @@ -345,5 +345,5 @@ QList QNetworkConfiguration::children() const } -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworkconfiguration.h b/src/network/bearer/qnetworkconfiguration.h index f8c17d5..e1fbc43 100644 --- a/src/network/bearer/qnetworkconfiguration.h +++ b/src/network/bearer/qnetworkconfiguration.h @@ -42,18 +42,17 @@ #ifndef QNETWORKCONFIGURATION_H #define QNETWORKCONFIGURATION_H -#include "qmobilityglobal.h" - +#include #include #include #include QT_BEGIN_HEADER -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; -class Q_BEARER_EXPORT QNetworkConfiguration +class Q_NETWORK_EXPORT QNetworkConfiguration { public: QNetworkConfiguration(); @@ -106,7 +105,7 @@ private: QExplicitlySharedDataPointer d; }; -QTM_END_NAMESPACE +QT_END_NAMESPACE QT_END_HEADER diff --git a/src/network/bearer/qnetworkconfiguration_maemo_p.h b/src/network/bearer/qnetworkconfiguration_maemo_p.h index 8d786aa..8d7fbcf 100644 --- a/src/network/bearer/qnetworkconfiguration_maemo_p.h +++ b/src/network/bearer/qnetworkconfiguration_maemo_p.h @@ -57,7 +57,7 @@ #include #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate : public QSharedData { @@ -104,6 +104,6 @@ private: QNetworkConfigurationPrivate(const QNetworkConfigurationPrivate &other); }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif //QNETWORKCONFIGURATIONPRIVATE_H diff --git a/src/network/bearer/qnetworkconfiguration_p.h b/src/network/bearer/qnetworkconfiguration_p.h index a3bcd9a..1dd53c4 100644 --- a/src/network/bearer/qnetworkconfiguration_p.h +++ b/src/network/bearer/qnetworkconfiguration_p.h @@ -57,7 +57,7 @@ #include #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate : public QSharedData { @@ -99,6 +99,6 @@ private: QNetworkConfigurationPrivate(const QNetworkConfigurationPrivate &other); }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif //QNETWORKCONFIGURATIONPRIVATE_H diff --git a/src/network/bearer/qnetworkconfiguration_s60_p.cpp b/src/network/bearer/qnetworkconfiguration_s60_p.cpp index 61548ba..289e09c 100644 --- a/src/network/bearer/qnetworkconfiguration_s60_p.cpp +++ b/src/network/bearer/qnetworkconfiguration_s60_p.cpp @@ -41,7 +41,7 @@ #include "qnetworkconfiguration_s60_p.h" -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE QNetworkConfigurationPrivate::QNetworkConfigurationPrivate() : isValid(false), type(QNetworkConfiguration::Invalid), @@ -57,4 +57,4 @@ QNetworkConfigurationPrivate::~QNetworkConfigurationPrivate() serviceNetworkMembers.clear(); } -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworkconfiguration_s60_p.h b/src/network/bearer/qnetworkconfiguration_s60_p.h index 44f8f56..bccad0c 100644 --- a/src/network/bearer/qnetworkconfiguration_s60_p.h +++ b/src/network/bearer/qnetworkconfiguration_s60_p.h @@ -56,7 +56,7 @@ #include #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate : public QSharedData { @@ -102,7 +102,7 @@ private: QNetworkConfigurationPrivate(const QNetworkConfigurationPrivate &other); }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif //QNETWORKCONFIGURATIONPRIVATE_H diff --git a/src/network/bearer/qnetworkmanagerservice_p.cpp b/src/network/bearer/qnetworkmanagerservice_p.cpp index 2f91af0..4e25533 100644 --- a/src/network/bearer/qnetworkmanagerservice_p.cpp +++ b/src/network/bearer/qnetworkmanagerservice_p.cpp @@ -57,7 +57,7 @@ #include "qnetworkmanagerservice_p.h" //Q_DECLARE_METATYPE(QList) -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE static QDBusConnection dbusConnection = QDBusConnection::systemBus(); //static QDBusInterface iface(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, dbusConnection); @@ -1008,4 +1008,4 @@ QStringList QNetworkManagerIp4Config::domains() const #include "moc_qnetworkmanagerservice_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworkmanagerservice_p.h b/src/network/bearer/qnetworkmanagerservice_p.h index 8569e71..91bf69d 100644 --- a/src/network/bearer/qnetworkmanagerservice_p.h +++ b/src/network/bearer/qnetworkmanagerservice_p.h @@ -64,19 +64,16 @@ #include -#include +#include "qnmdbushelper_p.h" +QT_BEGIN_NAMESPACE -QTM_BEGIN_NAMESPACE typedef QMap< QString, QMap > QNmSettingsMap; typedef QList ServerThing; -QTM_END_NAMESPACE -Q_DECLARE_METATYPE(QTM_PREPEND_NAMESPACE(QNmSettingsMap)) -Q_DECLARE_METATYPE(QTM_PREPEND_NAMESPACE(ServerThing)) +Q_DECLARE_METATYPE(QNmSettingsMap) +Q_DECLARE_METATYPE(ServerThing) - -QTM_BEGIN_NAMESPACE class QNetworkManagerInterfacePrivate; class QNetworkManagerInterface : public QObject { @@ -395,6 +392,6 @@ public: }; //// -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif //QNETWORKMANAGERSERVICE_H diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp index d3a323a..bdae9bc 100644 --- a/src/network/bearer/qnetworksession.cpp +++ b/src/network/bearer/qnetworksession.cpp @@ -52,7 +52,7 @@ #include "qnetworksession_p.h" #endif -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE /*! \class QNetworkSession @@ -686,4 +686,4 @@ void QNetworkSession::disconnectNotify(const char *signal) #include "moc_qnetworksession.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworksession.h b/src/network/bearer/qnetworksession.h index 47377c4..61093c7 100644 --- a/src/network/bearer/qnetworksession.h +++ b/src/network/bearer/qnetworksession.h @@ -42,8 +42,6 @@ #ifndef QNETWORKSESSION_H #define QNETWORKSESSION_H -#include "qmobilityglobal.h" - #include #include #include @@ -54,10 +52,10 @@ QT_BEGIN_HEADER -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkSessionPrivate; -class Q_BEARER_EXPORT QNetworkSession : public QObject +class Q_NETWORK_EXPORT QNetworkSession : public QObject { Q_OBJECT public: @@ -128,7 +126,7 @@ private: friend class QNetworkSessionPrivate; }; -QTM_END_NAMESPACE +QT_END_NAMESPACE QT_END_HEADER diff --git a/src/network/bearer/qnetworksession_maemo.cpp b/src/network/bearer/qnetworksession_maemo.cpp index c7c7a31..742499c 100644 --- a/src/network/bearer/qnetworksession_maemo.cpp +++ b/src/network/bearer/qnetworksession_maemo.cpp @@ -54,7 +54,7 @@ #include #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE static QHash properties; @@ -1178,4 +1178,4 @@ QNetworkSession::SessionError QNetworkSessionPrivate::error() const #include "qnetworksession_maemo.moc" #include "moc_qnetworksession_maemo_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworksession_maemo_p.h b/src/network/bearer/qnetworksession_maemo_p.h index e233087..6594176 100644 --- a/src/network/bearer/qnetworksession_maemo_p.h +++ b/src/network/bearer/qnetworksession_maemo_p.h @@ -62,7 +62,7 @@ #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkSessionPrivate : public QObject { @@ -161,7 +161,7 @@ private: void cleanupSession(void); }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif //QNETWORKSESSIONPRIVATE_H diff --git a/src/network/bearer/qnetworksession_p.cpp b/src/network/bearer/qnetworksession_p.cpp index c6f9833..6df4fdb9 100644 --- a/src/network/bearer/qnetworksession_p.cpp +++ b/src/network/bearer/qnetworksession_p.cpp @@ -63,7 +63,7 @@ #include "qnmwifiengine_unix_p.h" #endif -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE #if defined(BACKEND_NM) static bool NetworkManagerAvailable() @@ -538,5 +538,5 @@ if(serviceName.isEmpty()) #endif #include "moc_qnetworksession_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworksession_p.h b/src/network/bearer/qnetworksession_p.h index a2aaa6a..45e0ebf 100644 --- a/src/network/bearer/qnetworksession_p.h +++ b/src/network/bearer/qnetworksession_p.h @@ -63,7 +63,8 @@ #include #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE + #ifdef BEARER_ENGINE class QNetworkSessionEngine; #endif @@ -161,7 +162,7 @@ private: #endif }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif //QNETWORKSESSIONPRIVATE_H diff --git a/src/network/bearer/qnetworksession_s60_p.cpp b/src/network/bearer/qnetworksession_s60_p.cpp index 764c1c4..0a54b87 100644 --- a/src/network/bearer/qnetworksession_s60_p.cpp +++ b/src/network/bearer/qnetworksession_s60_p.cpp @@ -49,7 +49,7 @@ #include #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE QNetworkSessionPrivate::QNetworkSessionPrivate() : CActive(CActive::EPriorityStandard), state(QNetworkSession::Invalid), @@ -1165,4 +1165,4 @@ void ConnectionProgressNotifier::RunL() #include "moc_qnetworksession_s60_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworksession_s60_p.h b/src/network/bearer/qnetworksession_s60_p.h index cfb99c9..6e62f10 100644 --- a/src/network/bearer/qnetworksession_s60_p.h +++ b/src/network/bearer/qnetworksession_s60_p.h @@ -67,7 +67,7 @@ typedef int(*TOpenCSetdefaultifFunction)(const struct ifreq*); -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class ConnectionProgressNotifier; @@ -207,7 +207,7 @@ private: // Data }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif //QNETWORKSESSIONPRIVATE_H diff --git a/src/network/bearer/qnetworksessionengine.cpp b/src/network/bearer/qnetworksessionengine.cpp index 55fc4f3..7148d14 100644 --- a/src/network/bearer/qnetworksessionengine.cpp +++ b/src/network/bearer/qnetworksessionengine.cpp @@ -41,7 +41,7 @@ #include "qnetworksessionengine_p.h" -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE QNetworkSessionEngine::QNetworkSessionEngine(QObject *parent) : QObject(parent) @@ -53,5 +53,5 @@ QNetworkSessionEngine::~QNetworkSessionEngine() } #include "moc_qnetworksessionengine_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworksessionengine_p.h b/src/network/bearer/qnetworksessionengine_p.h index 795a209..6be750f 100644 --- a/src/network/bearer/qnetworksessionengine_p.h +++ b/src/network/bearer/qnetworksessionengine_p.h @@ -53,13 +53,12 @@ // We mean it. // -#include #include #include #include #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; class QNetworkSessionEngine : public QObject @@ -93,6 +92,6 @@ Q_SIGNALS: void connectionError(const QString &id, QNetworkSessionEngine::ConnectionError error); }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif diff --git a/src/network/bearer/qnlaengine_win.cpp b/src/network/bearer/qnlaengine_win.cpp index b606ef4..b1156d0 100644 --- a/src/network/bearer/qnlaengine_win.cpp +++ b/src/network/bearer/qnlaengine_win.cpp @@ -51,7 +51,7 @@ #include "qnetworksessionengine_win_p.h" -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC(QNlaEngine, nlaEngine) @@ -586,7 +586,7 @@ QNlaEngine *QNlaEngine::instance() #include "qnlaengine_win.moc" #include "moc_qnlaengine_win_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnlaengine_win_p.h b/src/network/bearer/qnlaengine_win_p.h index 394b8cf..d9d752b 100644 --- a/src/network/bearer/qnlaengine_win_p.h +++ b/src/network/bearer/qnlaengine_win_p.h @@ -57,7 +57,7 @@ #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; class QNlaThread; @@ -99,6 +99,6 @@ private: QMap configurationInterface; }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif diff --git a/src/network/bearer/qnmdbushelper.cpp b/src/network/bearer/qnmdbushelper.cpp index 3b780f6..e8ac78e 100644 --- a/src/network/bearer/qnmdbushelper.cpp +++ b/src/network/bearer/qnmdbushelper.cpp @@ -54,7 +54,7 @@ #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE void QNmDBusHelper::deviceStateChanged(quint32 state) { @@ -114,4 +114,4 @@ void QNmDBusHelper::slotSettingsRemoved() } #include "moc_qnmdbushelper_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnmdbushelper_p.h b/src/network/bearer/qnmdbushelper_p.h index f0248dc..ebd4e63 100644 --- a/src/network/bearer/qnmdbushelper_p.h +++ b/src/network/bearer/qnmdbushelper_p.h @@ -53,14 +53,13 @@ // We mean it. // -#include #if !defined(QT_NO_DBUS) && !defined(Q_OS_MAC) #include #include #include #endif -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE #if !defined(QT_NO_DBUS) && !defined(Q_OS_MAC) @@ -85,6 +84,6 @@ Q_SIGNALS: }; #endif -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif// QNMDBUSHELPERPRIVATE_H diff --git a/src/network/bearer/qnmwifiengine_unix.cpp b/src/network/bearer/qnmwifiengine_unix.cpp index f558fa8..c228bcc 100644 --- a/src/network/bearer/qnmwifiengine_unix.cpp +++ b/src/network/bearer/qnmwifiengine_unix.cpp @@ -51,16 +51,12 @@ #include +QT_BEGIN_NAMESPACE - -QTM_BEGIN_NAMESPACE Q_GLOBAL_STATIC(QNmWifiEngine, nmWifiEngine) typedef QList > QNmSettingsAddressMap; -QTM_END_NAMESPACE - -Q_DECLARE_METATYPE(QTM_PREPEND_NAMESPACE(QNmSettingsAddressMap)) -QTM_BEGIN_NAMESPACE +Q_DECLARE_METATYPE(QNmSettingsAddressMap) QNmWifiEngine::QNmWifiEngine(QObject *parent) : QNetworkSessionEngine(parent) @@ -1129,5 +1125,5 @@ QStringList QNmWifiEngine::getConnectionPathForId(const QString &uuid) #include "moc_qnmwifiengine_unix_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnmwifiengine_unix_p.h b/src/network/bearer/qnmwifiengine_unix_p.h index 1287800..a1bdb7b 100644 --- a/src/network/bearer/qnmwifiengine_unix_p.h +++ b/src/network/bearer/qnmwifiengine_unix_p.h @@ -67,7 +67,7 @@ -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; @@ -157,7 +157,7 @@ private slots: void slotActivationFinished(QDBusPendingCallWatcher*); }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif diff --git a/src/network/network.pro b/src/network/network.pro index e890b94..8582d8a 100644 --- a/src/network/network.pro +++ b/src/network/network.pro @@ -17,6 +17,7 @@ unix:QMAKE_PKGCONFIG_REQUIRES = QtCore include(../qbase.pri) include(access/access.pri) +include(bearer/bearer.pri) include(kernel/kernel.pri) include(socket/socket.pri) include(ssl/ssl.pri) diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index d5d72a7..176cc3a 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -434,7 +434,10 @@ SUBDIRS += \ qmargins \ qnetworkaddressentry \ qnetworkcachemetadata \ + qnetworkconfigmanager \ + qnetworkconfiguration \ qnetworkdiskcache \ + qnetworksession \ qobjectperformance \ qpainterpathstroker \ qplugin \ diff --git a/tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro b/tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro index 0b2ed1a..b539dd3 100644 --- a/tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro +++ b/tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro @@ -1,15 +1,5 @@ +load(qttest_p4) SOURCES += tst_qnetworkconfigmanager.cpp HEADERS += ../qbearertestcommon.h -TARGET = tst_qnetworkconfigurationmanager -CONFIG += testcase QT = core network - -INCLUDEPATH += ../../../src/bearer - -include(../../../common.pri) -qtAddLibrary(QtBearer) - -symbian { - TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData -} diff --git a/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp b/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp index 796677d..f92704d 100644 --- a/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp +++ b/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp @@ -49,7 +49,7 @@ #include #endif -QTM_USE_NAMESPACE +QT_USE_NAMESPACE class tst_QNetworkConfigurationManager : public QObject { Q_OBJECT diff --git a/tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro b/tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro index 61e4097..078983d 100644 --- a/tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro +++ b/tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro @@ -1,15 +1,5 @@ +load(qttest_p4) SOURCES += tst_qnetworkconfiguration.cpp HEADERS += ../qbearertestcommon.h -TARGET = tst_qnetworkconfiguration -CONFIG += testcase QT = core network - -INCLUDEPATH += ../../../src/bearer - -include(../../../common.pri) -qtAddLibrary(QtBearer) - -symbian { - TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData -} diff --git a/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp b/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp index cbb13f3..ac0f054 100644 --- a/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp +++ b/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp @@ -49,7 +49,7 @@ #include #endif -QTM_USE_NAMESPACE +QT_USE_NAMESPACE class tst_QNetworkConfiguration : public QObject { Q_OBJECT diff --git a/tests/auto/qnetworksession/lackey/lackey.pro b/tests/auto/qnetworksession/lackey/lackey.pro index 4cb8555..ccbdd98 100644 --- a/tests/auto/qnetworksession/lackey/lackey.pro +++ b/tests/auto/qnetworksession/lackey/lackey.pro @@ -1,12 +1,4 @@ +load(qttest_p4) SOURCES += main.cpp -TARGET = qnetworksessionlackey -INCLUDEPATH += ../../../../src/bearer -DEPENDPATH += ../../../../src/bearer QT = core network - -CONFIG+= testcase - -include(../../../../common.pri) - -qtAddLibrary(QtBearer) diff --git a/tests/auto/qnetworksession/lackey/main.cpp b/tests/auto/qnetworksession/lackey/main.cpp index 53f6f4f..8190292 100644 --- a/tests/auto/qnetworksession/lackey/main.cpp +++ b/tests/auto/qnetworksession/lackey/main.cpp @@ -48,7 +48,7 @@ #include -QTM_USE_NAMESPACE +QT_USE_NAMESPACE #define NO_DISCOVERED_CONFIGURATIONS_ERROR 1 diff --git a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp index cbd4c8f..b5935e1 100644 --- a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp +++ b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp @@ -51,7 +51,7 @@ #include #endif -QTM_USE_NAMESPACE +QT_USE_NAMESPACE Q_DECLARE_METATYPE(QNetworkConfiguration) Q_DECLARE_METATYPE(QNetworkSession::State); diff --git a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro index 1410601..bf33122 100644 --- a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro +++ b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro @@ -1,21 +1,5 @@ +load(qttest_p4) SOURCES += tst_qnetworksession.cpp HEADERS += ../../qbearertestcommon.h -TARGET = tst_qnetworksession -CONFIG += testcase QT = core network - -INCLUDEPATH += ../../../../src/bearer - -include(../../../../common.pri) -qtAddLibrary(QtBearer) - -wince* { - LACKEY.sources = $$OUTPUT_DIR/build/tests/bin/qnetworksessionlackey.exe - LACKEY.path = . - DEPLOYMENT += LACKEY -} - -symbian { - TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData -} diff --git a/tests/manual/bearerex/bearerex.h b/tests/manual/bearerex/bearerex.h index f18180e..04da6ca 100644 --- a/tests/manual/bearerex/bearerex.h +++ b/tests/manual/bearerex/bearerex.h @@ -54,7 +54,7 @@ class QHttp; class SessionTab; -QTM_USE_NAMESPACE +QT_USE_NAMESPACE class BearerEx : public QMainWindow, public Ui::BearerExMainWindow { diff --git a/tests/manual/bearerex/bearerex.pro b/tests/manual/bearerex/bearerex.pro index a870eb1..476e87c 100644 --- a/tests/manual/bearerex/bearerex.pro +++ b/tests/manual/bearerex/bearerex.pro @@ -8,13 +8,6 @@ QT += core \ FORMS += sessiondialog.ui \ bearerex.ui \ detailedinfodialog.ui -include(../../common.pri) -#not really a test case but deployment happens same way -CONFIG += testcase - -DEPENDPATH += . -INCLUDEPATH += . \ - ../../src/bearer # Example headers and sources HEADERS += bearerex.h \ @@ -23,12 +16,3 @@ HEADERS += bearerex.h \ SOURCES += bearerex.cpp \ main.cpp \ xqlistwidget.cpp - -symbian: { - bearerex.sources = Qtbearer.dll - bearerex.path = /sys/bin - DEPLOYMENT += bearerex - - TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData -} -qtAddLibrary(QtBearer) diff --git a/tests/manual/networkmanager/networkmanager.pro b/tests/manual/networkmanager/networkmanager.pro index 31b2af1..84289d3 100644 --- a/tests/manual/networkmanager/networkmanager.pro +++ b/tests/manual/networkmanager/networkmanager.pro @@ -4,16 +4,6 @@ TARGET = tst_networkmanagertest QT = core network dbus gui -#not really a test case but deployment happens same way -CONFIG += testcase - requires(contains(QT_CONFIG,dbus)) -INCLUDEPATH += ../../src/bearer -include(../../common.pri) - -qtAddLibrary(QtBearer) - -#MOC_DIR = .moc -#OBJECTS_DIR = .obj FORMS += dialog.ui diff --git a/tests/manual/networkmanager/nmview.cpp b/tests/manual/networkmanager/nmview.cpp index ca9d907..35a0204 100644 --- a/tests/manual/networkmanager/nmview.cpp +++ b/tests/manual/networkmanager/nmview.cpp @@ -68,7 +68,7 @@ #include #include #include -#include +#include //static QDBusConnection dbc = QDBusConnection::systemBus(); //typedef QMap< QString, QMap > SettingsMap; diff --git a/tests/manual/networkmanager/nmview.h b/tests/manual/networkmanager/nmview.h index 641385e..7db56d4 100644 --- a/tests/manual/networkmanager/nmview.h +++ b/tests/manual/networkmanager/nmview.h @@ -47,7 +47,7 @@ #include "ui_dialog.h" -QTM_USE_NAMESPACE +QT_USE_NAMESPACE class QListWidget; class QTreeWidget; -- cgit v0.12 From ce2439e97af96f6a704522b1aefebd888efd4fff Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 22 Dec 2009 14:34:51 +1000 Subject: Fix up license headers. --- config.tests/mac/corelwan/corewlantest.mm | 2 +- config.tests/unix/networkmanager/main.cpp | 2 +- examples/network/bearercloud/bearercloud.cpp | 2 +- examples/network/bearercloud/bearercloud.h | 2 +- examples/network/bearercloud/cloud.cpp | 2 +- examples/network/bearercloud/cloud.h | 2 +- examples/network/bearercloud/main.cpp | 2 +- examples/network/bearermonitor/bearermonitor.cpp | 2 +- examples/network/bearermonitor/bearermonitor.h | 2 +- examples/network/bearermonitor/main.cpp | 2 +- examples/network/bearermonitor/sessionwidget.cpp | 2 +- examples/network/bearermonitor/sessionwidget.h | 2 +- src/network/bearer/qcorewlanengine_mac_p.h | 2 +- src/network/bearer/qgenericengine.cpp | 2 +- src/network/bearer/qgenericengine_p.h | 2 +- src/network/bearer/qnativewifiengine_win.cpp | 2 +- src/network/bearer/qnativewifiengine_win_p.h | 2 +- src/network/bearer/qnetworkconfigmanager.cpp | 2 +- src/network/bearer/qnetworkconfigmanager.h | 2 +- src/network/bearer/qnetworkconfigmanager_maemo.cpp | 2 +- src/network/bearer/qnetworkconfigmanager_maemo_p.h | 2 +- src/network/bearer/qnetworkconfigmanager_p.cpp | 2 +- src/network/bearer/qnetworkconfigmanager_p.h | 2 +- src/network/bearer/qnetworkconfigmanager_s60_p.cpp | 2 +- src/network/bearer/qnetworkconfigmanager_s60_p.h | 2 +- src/network/bearer/qnetworkconfiguration.cpp | 2 +- src/network/bearer/qnetworkconfiguration.h | 2 +- src/network/bearer/qnetworkconfiguration_maemo_p.h | 2 +- src/network/bearer/qnetworkconfiguration_p.h | 2 +- src/network/bearer/qnetworkconfiguration_s60_p.cpp | 2 +- src/network/bearer/qnetworkconfiguration_s60_p.h | 2 +- src/network/bearer/qnetworkmanagerservice_p.cpp | 2 +- src/network/bearer/qnetworkmanagerservice_p.h | 2 +- src/network/bearer/qnetworksession.cpp | 2 +- src/network/bearer/qnetworksession.h | 2 +- src/network/bearer/qnetworksession_maemo.cpp | 2 +- src/network/bearer/qnetworksession_maemo_p.h | 2 +- src/network/bearer/qnetworksession_p.cpp | 2 +- src/network/bearer/qnetworksession_p.h | 2 +- src/network/bearer/qnetworksession_s60_p.cpp | 2 +- src/network/bearer/qnetworksession_s60_p.h | 2 +- src/network/bearer/qnetworksessionengine.cpp | 2 +- src/network/bearer/qnetworksessionengine_p.h | 2 +- src/network/bearer/qnetworksessionengine_win_p.h | 2 +- src/network/bearer/qnlaengine_win.cpp | 2 +- src/network/bearer/qnlaengine_win_p.h | 2 +- src/network/bearer/qnmdbushelper.cpp | 2 +- src/network/bearer/qnmdbushelper_p.h | 2 +- src/network/bearer/qnmwifiengine_unix.cpp | 2 +- src/network/bearer/qnmwifiengine_unix_p.h | 2 +- tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp | 2 +- tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp | 2 +- tests/auto/qnetworksession/lackey/main.cpp | 2 +- tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp | 2 +- tests/manual/bearerex/bearerex.cpp | 3 ++- tests/manual/bearerex/bearerex.h | 3 ++- tests/manual/bearerex/main.cpp | 3 ++- tests/manual/bearerex/xqlistwidget.cpp | 3 ++- tests/manual/bearerex/xqlistwidget.h | 3 ++- tests/manual/networkmanager/networkmanagertest.cpp | 2 +- tests/manual/networkmanager/nmview.cpp | 2 +- tests/manual/networkmanager/nmview.h | 2 +- tests/manual/networkmanager/startdlg.cpp | 3 ++- tests/manual/networkmanager/startdlg.h | 3 ++- 64 files changed, 71 insertions(+), 64 deletions(-) diff --git a/config.tests/mac/corelwan/corewlantest.mm b/config.tests/mac/corelwan/corewlantest.mm index bcddf44..3a29d84 100644 --- a/config.tests/mac/corelwan/corewlantest.mm +++ b/config.tests/mac/corelwan/corewlantest.mm @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the config.tests of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/config.tests/unix/networkmanager/main.cpp b/config.tests/unix/networkmanager/main.cpp index 6f2bae6..27e6bd1 100644 --- a/config.tests/unix/networkmanager/main.cpp +++ b/config.tests/unix/networkmanager/main.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the config.tests of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/examples/network/bearercloud/bearercloud.cpp b/examples/network/bearercloud/bearercloud.cpp index 182d4ec..27a296d 100644 --- a/examples/network/bearercloud/bearercloud.cpp +++ b/examples/network/bearercloud/bearercloud.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/examples/network/bearercloud/bearercloud.h b/examples/network/bearercloud/bearercloud.h index 79b441f..f09cb53 100644 --- a/examples/network/bearercloud/bearercloud.h +++ b/examples/network/bearercloud/bearercloud.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/examples/network/bearercloud/cloud.cpp b/examples/network/bearercloud/cloud.cpp index 4a1bde7..dcb7caf 100644 --- a/examples/network/bearercloud/cloud.cpp +++ b/examples/network/bearercloud/cloud.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/examples/network/bearercloud/cloud.h b/examples/network/bearercloud/cloud.h index f844725..7a45ff2 100644 --- a/examples/network/bearercloud/cloud.h +++ b/examples/network/bearercloud/cloud.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/examples/network/bearercloud/main.cpp b/examples/network/bearercloud/main.cpp index 33c55e9..86ef46f 100644 --- a/examples/network/bearercloud/main.cpp +++ b/examples/network/bearercloud/main.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/examples/network/bearermonitor/bearermonitor.cpp b/examples/network/bearermonitor/bearermonitor.cpp index 70c8269..5b2bad1 100644 --- a/examples/network/bearermonitor/bearermonitor.cpp +++ b/examples/network/bearermonitor/bearermonitor.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/examples/network/bearermonitor/bearermonitor.h b/examples/network/bearermonitor/bearermonitor.h index 9306d90..d7025dd 100644 --- a/examples/network/bearermonitor/bearermonitor.h +++ b/examples/network/bearermonitor/bearermonitor.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/examples/network/bearermonitor/main.cpp b/examples/network/bearermonitor/main.cpp index 9685181..b7ac4fe 100644 --- a/examples/network/bearermonitor/main.cpp +++ b/examples/network/bearermonitor/main.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/examples/network/bearermonitor/sessionwidget.cpp b/examples/network/bearermonitor/sessionwidget.cpp index 7633dd7..1e59935 100644 --- a/examples/network/bearermonitor/sessionwidget.cpp +++ b/examples/network/bearermonitor/sessionwidget.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/examples/network/bearermonitor/sessionwidget.h b/examples/network/bearermonitor/sessionwidget.h index 8bc60e4..868de3a 100644 --- a/examples/network/bearermonitor/sessionwidget.h +++ b/examples/network/bearermonitor/sessionwidget.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qcorewlanengine_mac_p.h b/src/network/bearer/qcorewlanengine_mac_p.h index 660ddb5..d6454ca 100644 --- a/src/network/bearer/qcorewlanengine_mac_p.h +++ b/src/network/bearer/qcorewlanengine_mac_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qgenericengine.cpp b/src/network/bearer/qgenericengine.cpp index 2e48ce8..14fa886 100644 --- a/src/network/bearer/qgenericengine.cpp +++ b/src/network/bearer/qgenericengine.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qgenericengine_p.h b/src/network/bearer/qgenericengine_p.h index 88de2a0..28d6e90 100644 --- a/src/network/bearer/qgenericengine_p.h +++ b/src/network/bearer/qgenericengine_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnativewifiengine_win.cpp b/src/network/bearer/qnativewifiengine_win.cpp index b4b3888..46d4ead 100644 --- a/src/network/bearer/qnativewifiengine_win.cpp +++ b/src/network/bearer/qnativewifiengine_win.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnativewifiengine_win_p.h b/src/network/bearer/qnativewifiengine_win_p.h index adc75e1..4817867 100644 --- a/src/network/bearer/qnativewifiengine_win_p.h +++ b/src/network/bearer/qnativewifiengine_win_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index 4b28b22..5031dd4 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfigmanager.h b/src/network/bearer/qnetworkconfigmanager.h index 940fcc5..b7ab72b 100644 --- a/src/network/bearer/qnetworkconfigmanager.h +++ b/src/network/bearer/qnetworkconfigmanager.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfigmanager_maemo.cpp b/src/network/bearer/qnetworkconfigmanager_maemo.cpp index 26909f9..2188d61 100644 --- a/src/network/bearer/qnetworkconfigmanager_maemo.cpp +++ b/src/network/bearer/qnetworkconfigmanager_maemo.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfigmanager_maemo_p.h b/src/network/bearer/qnetworkconfigmanager_maemo_p.h index a5462b8..5cc99c2 100644 --- a/src/network/bearer/qnetworkconfigmanager_maemo_p.h +++ b/src/network/bearer/qnetworkconfigmanager_maemo_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 49135c1..47b23d2 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index 184d1bd..f2e2ee5 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfigmanager_s60_p.cpp b/src/network/bearer/qnetworkconfigmanager_s60_p.cpp index 8859a4e..b5bd4d2 100644 --- a/src/network/bearer/qnetworkconfigmanager_s60_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_s60_p.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfigmanager_s60_p.h b/src/network/bearer/qnetworkconfigmanager_s60_p.h index cd48df6..c4d4e30 100644 --- a/src/network/bearer/qnetworkconfigmanager_s60_p.h +++ b/src/network/bearer/qnetworkconfigmanager_s60_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfiguration.cpp b/src/network/bearer/qnetworkconfiguration.cpp index 9422f07..c105dfb 100644 --- a/src/network/bearer/qnetworkconfiguration.cpp +++ b/src/network/bearer/qnetworkconfiguration.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfiguration.h b/src/network/bearer/qnetworkconfiguration.h index e1fbc43..63c37e5 100644 --- a/src/network/bearer/qnetworkconfiguration.h +++ b/src/network/bearer/qnetworkconfiguration.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfiguration_maemo_p.h b/src/network/bearer/qnetworkconfiguration_maemo_p.h index 8d7fbcf..0ae6ea6 100644 --- a/src/network/bearer/qnetworkconfiguration_maemo_p.h +++ b/src/network/bearer/qnetworkconfiguration_maemo_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfiguration_p.h b/src/network/bearer/qnetworkconfiguration_p.h index 1dd53c4..69d7e18 100644 --- a/src/network/bearer/qnetworkconfiguration_p.h +++ b/src/network/bearer/qnetworkconfiguration_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfiguration_s60_p.cpp b/src/network/bearer/qnetworkconfiguration_s60_p.cpp index 289e09c..978c62c 100644 --- a/src/network/bearer/qnetworkconfiguration_s60_p.cpp +++ b/src/network/bearer/qnetworkconfiguration_s60_p.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfiguration_s60_p.h b/src/network/bearer/qnetworkconfiguration_s60_p.h index bccad0c..faacd64 100644 --- a/src/network/bearer/qnetworkconfiguration_s60_p.h +++ b/src/network/bearer/qnetworkconfiguration_s60_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkmanagerservice_p.cpp b/src/network/bearer/qnetworkmanagerservice_p.cpp index 4e25533..9516f31 100644 --- a/src/network/bearer/qnetworkmanagerservice_p.cpp +++ b/src/network/bearer/qnetworkmanagerservice_p.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkmanagerservice_p.h b/src/network/bearer/qnetworkmanagerservice_p.h index 91bf69d..520aeac 100644 --- a/src/network/bearer/qnetworkmanagerservice_p.h +++ b/src/network/bearer/qnetworkmanagerservice_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp index bdae9bc..8ebe1c2 100644 --- a/src/network/bearer/qnetworksession.cpp +++ b/src/network/bearer/qnetworksession.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworksession.h b/src/network/bearer/qnetworksession.h index 61093c7..0573c70 100644 --- a/src/network/bearer/qnetworksession.h +++ b/src/network/bearer/qnetworksession.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworksession_maemo.cpp b/src/network/bearer/qnetworksession_maemo.cpp index 742499c..a35d8cb 100644 --- a/src/network/bearer/qnetworksession_maemo.cpp +++ b/src/network/bearer/qnetworksession_maemo.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworksession_maemo_p.h b/src/network/bearer/qnetworksession_maemo_p.h index 6594176..c5483a9 100644 --- a/src/network/bearer/qnetworksession_maemo_p.h +++ b/src/network/bearer/qnetworksession_maemo_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworksession_p.cpp b/src/network/bearer/qnetworksession_p.cpp index 6df4fdb9..8e39216 100644 --- a/src/network/bearer/qnetworksession_p.cpp +++ b/src/network/bearer/qnetworksession_p.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworksession_p.h b/src/network/bearer/qnetworksession_p.h index 45e0ebf..0e11b3d 100644 --- a/src/network/bearer/qnetworksession_p.h +++ b/src/network/bearer/qnetworksession_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworksession_s60_p.cpp b/src/network/bearer/qnetworksession_s60_p.cpp index 0a54b87..ed5269e 100644 --- a/src/network/bearer/qnetworksession_s60_p.cpp +++ b/src/network/bearer/qnetworksession_s60_p.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworksession_s60_p.h b/src/network/bearer/qnetworksession_s60_p.h index 6e62f10..9aaedb7 100644 --- a/src/network/bearer/qnetworksession_s60_p.h +++ b/src/network/bearer/qnetworksession_s60_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworksessionengine.cpp b/src/network/bearer/qnetworksessionengine.cpp index 7148d14..9e6839e 100644 --- a/src/network/bearer/qnetworksessionengine.cpp +++ b/src/network/bearer/qnetworksessionengine.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworksessionengine_p.h b/src/network/bearer/qnetworksessionengine_p.h index 6be750f..8eb17d4 100644 --- a/src/network/bearer/qnetworksessionengine_p.h +++ b/src/network/bearer/qnetworksessionengine_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworksessionengine_win_p.h b/src/network/bearer/qnetworksessionengine_win_p.h index cf01719..e68a35b 100644 --- a/src/network/bearer/qnetworksessionengine_win_p.h +++ b/src/network/bearer/qnetworksessionengine_win_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnlaengine_win.cpp b/src/network/bearer/qnlaengine_win.cpp index b1156d0..579b0e1 100644 --- a/src/network/bearer/qnlaengine_win.cpp +++ b/src/network/bearer/qnlaengine_win.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnlaengine_win_p.h b/src/network/bearer/qnlaengine_win_p.h index d9d752b..1e7d051 100644 --- a/src/network/bearer/qnlaengine_win_p.h +++ b/src/network/bearer/qnlaengine_win_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnmdbushelper.cpp b/src/network/bearer/qnmdbushelper.cpp index e8ac78e..5d7403b 100644 --- a/src/network/bearer/qnmdbushelper.cpp +++ b/src/network/bearer/qnmdbushelper.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnmdbushelper_p.h b/src/network/bearer/qnmdbushelper_p.h index ebd4e63..99b0357 100644 --- a/src/network/bearer/qnmdbushelper_p.h +++ b/src/network/bearer/qnmdbushelper_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnmwifiengine_unix.cpp b/src/network/bearer/qnmwifiengine_unix.cpp index c228bcc..5870a9f 100644 --- a/src/network/bearer/qnmwifiengine_unix.cpp +++ b/src/network/bearer/qnmwifiengine_unix.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnmwifiengine_unix_p.h b/src/network/bearer/qnmwifiengine_unix_p.h index a1bdb7b..3af73ea 100644 --- a/src/network/bearer/qnmwifiengine_unix_p.h +++ b/src/network/bearer/qnmwifiengine_unix_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp b/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp index f92704d..f065f78 100644 --- a/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp +++ b/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp b/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp index ac0f054..9ac9e47 100644 --- a/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp +++ b/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/tests/auto/qnetworksession/lackey/main.cpp b/tests/auto/qnetworksession/lackey/main.cpp index 8190292..9f32696 100644 --- a/tests/auto/qnetworksession/lackey/main.cpp +++ b/tests/auto/qnetworksession/lackey/main.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp index b5935e1..fc0db05 100644 --- a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp +++ b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/tests/manual/bearerex/bearerex.cpp b/tests/manual/bearerex/bearerex.cpp index 68590cc..c5bf786 100644 --- a/tests/manual/bearerex/bearerex.cpp +++ b/tests/manual/bearerex/bearerex.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #include "bearerex.h" #include diff --git a/tests/manual/bearerex/bearerex.h b/tests/manual/bearerex/bearerex.h index 04da6ca..ff5f23c 100644 --- a/tests/manual/bearerex/bearerex.h +++ b/tests/manual/bearerex/bearerex.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef ACCESSPOINTMANAGEREX_H #define ACCESSPOINTMANAGEREX_H diff --git a/tests/manual/bearerex/main.cpp b/tests/manual/bearerex/main.cpp index e13a494..20b167e 100644 --- a/tests/manual/bearerex/main.cpp +++ b/tests/manual/bearerex/main.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #include #include "bearerex.h" diff --git a/tests/manual/bearerex/xqlistwidget.cpp b/tests/manual/bearerex/xqlistwidget.cpp index 0618725..8104779 100644 --- a/tests/manual/bearerex/xqlistwidget.cpp +++ b/tests/manual/bearerex/xqlistwidget.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #include "xqlistwidget.h" XQListWidget::XQListWidget(QWidget* parent) : QListWidget(parent) diff --git a/tests/manual/bearerex/xqlistwidget.h b/tests/manual/bearerex/xqlistwidget.h index 1053328..0649c2b 100644 --- a/tests/manual/bearerex/xqlistwidget.h +++ b/tests/manual/bearerex/xqlistwidget.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef XQLISTWIDGET_H #define XQLISTWIDGET_H diff --git a/tests/manual/networkmanager/networkmanagertest.cpp b/tests/manual/networkmanager/networkmanagertest.cpp index a39b041..8a6c5fa 100644 --- a/tests/manual/networkmanager/networkmanagertest.cpp +++ b/tests/manual/networkmanager/networkmanagertest.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/tests/manual/networkmanager/nmview.cpp b/tests/manual/networkmanager/nmview.cpp index 35a0204..f7611f0 100644 --- a/tests/manual/networkmanager/nmview.cpp +++ b/tests/manual/networkmanager/nmview.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/tests/manual/networkmanager/nmview.h b/tests/manual/networkmanager/nmview.h index 7db56d4..b725ade 100644 --- a/tests/manual/networkmanager/nmview.h +++ b/tests/manual/networkmanager/nmview.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/tests/manual/networkmanager/startdlg.cpp b/tests/manual/networkmanager/startdlg.cpp index 4720932..e34b5e9 100644 --- a/tests/manual/networkmanager/startdlg.cpp +++ b/tests/manual/networkmanager/startdlg.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #include "startdlg.h" #include diff --git a/tests/manual/networkmanager/startdlg.h b/tests/manual/networkmanager/startdlg.h index a9f1e7c..32c8557 100644 --- a/tests/manual/networkmanager/startdlg.h +++ b/tests/manual/networkmanager/startdlg.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #include #include #include -- cgit v0.12 From f9d1d43e714c467d4101c6bd8eca072fdf9fbdec Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 22 Dec 2009 14:01:30 +1000 Subject: Fix compile warnings. --- src/network/bearer/qgenericengine.cpp | 2 +- src/network/bearer/qnetworksession.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/network/bearer/qgenericengine.cpp b/src/network/bearer/qgenericengine.cpp index 14fa886..d14f0fa 100644 --- a/src/network/bearer/qgenericengine.cpp +++ b/src/network/bearer/qgenericengine.cpp @@ -159,7 +159,7 @@ QList QGenericEngine::getConfigurations(bool *ok continue; // ignore WLAN interface handled in seperate engine - if (qGetInterfaceType(interface.name()) == "WLAN") + if (qGetInterfaceType(interface.name()) == QLatin1String("WLAN")) continue; QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp index 8ebe1c2..dbea087 100644 --- a/src/network/bearer/qnetworksession.cpp +++ b/src/network/bearer/qnetworksession.cpp @@ -509,14 +509,14 @@ QVariant QNetworkSession::sessionProperty(const QString& key) const if (!d->publicConfig.isValid()) return QVariant(); - if (key == "ActiveConfigurationIdentifier") { + if (key == QLatin1String("ActiveConfigurationIdentifier")) { if (!d->isActive) return QString(); else return d->activeConfig.identifier(); } - if (key == "UserChoiceConfigurationIdentifier") { + if (key == QLatin1String("UserChoiceConfigurationIdentifier")) { if (!d->isActive || d->publicConfig.type() != QNetworkConfiguration::UserChoice) return QString(); @@ -539,9 +539,10 @@ QVariant QNetworkSession::sessionProperty(const QString& key) const */ void QNetworkSession::setSessionProperty(const QString& key, const QVariant& value) { - if (key == "ActiveConfigurationIdentifier" - || key == "UserChoiceConfigurationIdentifier") + if (key == QLatin1String("ActiveConfigurationIdentifier") || + key == QLatin1String("UserChoiceConfigurationIdentifier")) { return; + } d->setSessionProperty(key, value); } -- cgit v0.12 From d5b6c723973449914134231c01a381ef9af9f6d4 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 22 Dec 2009 14:40:53 +1000 Subject: Make unit tests compile. --- tests/auto/qnetworksession/lackey/lackey.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/qnetworksession/lackey/lackey.pro b/tests/auto/qnetworksession/lackey/lackey.pro index ccbdd98..6cc1b43 100644 --- a/tests/auto/qnetworksession/lackey/lackey.pro +++ b/tests/auto/qnetworksession/lackey/lackey.pro @@ -1,4 +1,4 @@ -load(qttest_p4) SOURCES += main.cpp +TARGET = qnetworksessionlackey QT = core network -- cgit v0.12 From 27b47c630f8b71897ba56c983c24afe1538f33dc Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 1 Dec 2009 15:46:59 +1000 Subject: Convert generic engine into a plugin. --- src/network/bearer/bearer.pri | 12 +- src/network/bearer/qbearerplugin.cpp | 58 ++++++ src/network/bearer/qbearerplugin.h | 82 +++++++++ src/network/bearer/qgenericengine.cpp | 234 ------------------------- src/network/bearer/qgenericengine_p.h | 94 ---------- src/network/bearer/qnetworkconfigmanager.cpp | 7 + src/network/bearer/qnetworkconfigmanager_p.cpp | 23 ++- src/network/bearer/qnetworkconfigmanager_p.h | 4 +- src/network/bearer/qnetworkconfiguration_p.h | 2 +- src/network/bearer/qnetworksession_p.cpp | 10 +- src/network/bearer/qnetworksessionengine_p.h | 4 +- src/plugins/bearer/bearer.pro | 3 + src/plugins/bearer/generic/generic.pro | 13 ++ src/plugins/bearer/generic/main.cpp | 88 ++++++++++ src/plugins/bearer/generic/qgenericengine.cpp | 234 +++++++++++++++++++++++++ src/plugins/bearer/generic/qgenericengine.h | 83 +++++++++ src/plugins/plugins.pro | 2 +- 17 files changed, 606 insertions(+), 347 deletions(-) create mode 100644 src/network/bearer/qbearerplugin.cpp create mode 100644 src/network/bearer/qbearerplugin.h delete mode 100644 src/network/bearer/qgenericengine.cpp delete mode 100644 src/network/bearer/qgenericengine_p.h create mode 100644 src/plugins/bearer/bearer.pro create mode 100644 src/plugins/bearer/generic/generic.pro create mode 100644 src/plugins/bearer/generic/main.cpp create mode 100644 src/plugins/bearer/generic/qgenericengine.cpp create mode 100644 src/plugins/bearer/generic/qgenericengine.h diff --git a/src/network/bearer/bearer.pri b/src/network/bearer/bearer.pri index d8ddce5..4f53621 100644 --- a/src/network/bearer/bearer.pri +++ b/src/network/bearer/bearer.pri @@ -4,11 +4,13 @@ HEADERS += bearer/qnetworkconfiguration.h \ bearer/qnetworksession.h \ - bearer/qnetworkconfigmanager.h + bearer/qnetworkconfigmanager.h \ + bearer/qbearerplugin.h SOURCES += bearer/qnetworksession.cpp \ bearer/qnetworkconfigmanager.cpp \ - bearer/qnetworkconfiguration.cpp + bearer/qnetworkconfiguration.cpp \ + bearer/qbearerplugin.cpp symbian { exists($${EPOCROOT}epoc32/release/winscw/udeb/cmmanager.lib)| \ @@ -72,13 +74,11 @@ symbian { HEADERS += bearer/qnetworkconfigmanager_p.h \ bearer/qnetworkconfiguration_p.h \ bearer/qnetworksession_p.h \ - bearer/qnetworksessionengine_p.h \ - bearer/qgenericengine_p.h + bearer/qnetworksessionengine_p.h SOURCES += bearer/qnetworkconfigmanager_p.cpp \ bearer/qnetworksession_p.cpp \ - bearer/qnetworksessionengine.cpp \ - bearer/qgenericengine.cpp + bearer/qnetworksessionengine.cpp unix:!mac:contains(networkmanager_enabled, yes) { contains(QT_CONFIG,dbus) { diff --git a/src/network/bearer/qbearerplugin.cpp b/src/network/bearer/qbearerplugin.cpp new file mode 100644 index 0000000..252ee71 --- /dev/null +++ b/src/network/bearer/qbearerplugin.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** 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 "qbearerplugin.h" + +#include + +QT_BEGIN_NAMESPACE + +QBearerEnginePlugin::QBearerEnginePlugin(QObject *parent) +: QObject(parent) +{ + qDebug() << Q_FUNC_INFO; +} + +QBearerEnginePlugin::~QBearerEnginePlugin() +{ +} + +QT_END_NAMESPACE diff --git a/src/network/bearer/qbearerplugin.h b/src/network/bearer/qbearerplugin.h new file mode 100644 index 0000000..036d712 --- /dev/null +++ b/src/network/bearer/qbearerplugin.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** 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 QBEARERPLUGIN_H +#define QBEARERPLUGIN_H + +#include "qnetworksessionengine_p.h" + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Network) + +struct Q_NETWORK_EXPORT QBearerEngineFactoryInterface : public QFactoryInterface +{ + virtual QBearerEngine *create(const QString &key = QString()) const = 0; +}; + +#define QBearerEngineFactoryInterface_iid "com.trolltech.Qt.QBearerEngineFactoryInterface" +Q_DECLARE_INTERFACE(QBearerEngineFactoryInterface, QBearerEngineFactoryInterface_iid) + +class Q_NETWORK_EXPORT QBearerEnginePlugin : public QObject, public QBearerEngineFactoryInterface +{ + Q_OBJECT + Q_INTERFACES(QBearerEngineFactoryInterface:QFactoryInterface) + +public: + explicit QBearerEnginePlugin(QObject *parent = 0); + virtual ~QBearerEnginePlugin(); + + virtual QStringList keys() const = 0; + virtual QBearerEngine *create(const QString &key = QString()) const = 0; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif + diff --git a/src/network/bearer/qgenericengine.cpp b/src/network/bearer/qgenericengine.cpp deleted file mode 100644 index d14f0fa..0000000 --- a/src/network/bearer/qgenericengine.cpp +++ /dev/null @@ -1,234 +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 "qgenericengine_p.h" -#include "qnetworkconfiguration_p.h" - -#include -#include -#include -#include - -#include - -#ifdef Q_OS_WIN -#include "qnetworksessionengine_win_p.h" -#endif - -QT_BEGIN_NAMESPACE - -Q_GLOBAL_STATIC(QGenericEngine, genericEngine) - -static QString qGetInterfaceType(const QString &interface) -{ -#ifdef Q_OS_WIN32 - unsigned long oid; - DWORD bytesWritten; - - NDIS_MEDIUM medium; - NDIS_PHYSICAL_MEDIUM physicalMedium; - - HANDLE handle = CreateFile((TCHAR *)QString("\\\\.\\%1").arg(interface).utf16(), 0, - FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); - if (handle == INVALID_HANDLE_VALUE) - return QString(); - - oid = OID_GEN_MEDIA_SUPPORTED; - bytesWritten = 0; - bool result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), - &medium, sizeof(medium), &bytesWritten, 0); - if (!result) { - CloseHandle(handle); - return QString(); - } - - oid = OID_GEN_PHYSICAL_MEDIUM; - bytesWritten = 0; - result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), - &physicalMedium, sizeof(physicalMedium), &bytesWritten, 0); - if (!result) { - CloseHandle(handle); - - if (medium == NdisMedium802_3) - return QLatin1String("Ethernet"); - else - return QString(); - } - - CloseHandle(handle); - - if (medium == NdisMedium802_3) { - switch (physicalMedium) { - case NdisPhysicalMediumWirelessLan: - return QLatin1String("WLAN"); - case NdisPhysicalMediumBluetooth: - return QLatin1String("Bluetooth"); - case NdisPhysicalMediumWiMax: - return QLatin1String("WiMAX"); - default: -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "Physical Medium" << physicalMedium; -#endif - return QLatin1String("Ethernet"); - } - } - -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << medium << physicalMedium; -#endif -#else - Q_UNUSED(interface); -#endif - - return QString(); -} - -QGenericEngine::QGenericEngine(QObject *parent) -: QNetworkSessionEngine(parent) -{ - connect(&pollTimer, SIGNAL(timeout()), this, SIGNAL(configurationsChanged())); - pollTimer.setInterval(10000); -} - -QGenericEngine::~QGenericEngine() -{ -} - -QList QGenericEngine::getConfigurations(bool *ok) -{ - if (ok) - *ok = true; - - QList foundConfigurations; - - // Immediately after connecting with a wireless access point - // QNetworkInterface::allInterfaces() will sometimes return an empty list. Calling it again a - // second time results in a non-empty list. If we loose interfaces we will end up removing - // network configurations which will break current sessions. - QList interfaces = QNetworkInterface::allInterfaces(); - if (interfaces.isEmpty()) - interfaces = QNetworkInterface::allInterfaces(); - - // create configuration for each interface - while (!interfaces.isEmpty()) { - QNetworkInterface interface = interfaces.takeFirst(); - - if (!interface.isValid()) - continue; - - // ignore loopback interface - if (interface.flags() & QNetworkInterface::IsLoopBack) - continue; - - // ignore WLAN interface handled in seperate engine - if (qGetInterfaceType(interface.name()) == QLatin1String("WLAN")) - continue; - - QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; - const QString humanReadableName = interface.humanReadableName(); - cpPriv->name = humanReadableName.isEmpty() ? interface.name() : humanReadableName; - cpPriv->isValid = true; - - uint identifier; - if (interface.index()) - identifier = qHash(QLatin1String("NLA:") + QString::number(interface.index())); - else - identifier = qHash(QLatin1String("NLA:") + interface.hardwareAddress()); - - cpPriv->id = QString::number(identifier); - cpPriv->state = QNetworkConfiguration::Discovered; - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - if (interface.flags() & QNetworkInterface::IsUp) - cpPriv->state |= QNetworkConfiguration::Active; - - configurationInterface[identifier] = interface.name(); - - foundConfigurations.append(cpPriv); - } - - pollTimer.start(); - - return foundConfigurations; -} - -QString QGenericEngine::getInterfaceFromId(const QString &id) -{ - return configurationInterface.value(id.toUInt()); -} - -bool QGenericEngine::hasIdentifier(const QString &id) -{ - return configurationInterface.contains(id.toUInt()); -} - -QString QGenericEngine::bearerName(const QString &id) -{ - QString interface = getInterfaceFromId(id); - - if (interface.isEmpty()) - return QString(); - - return qGetInterfaceType(interface); -} - -void QGenericEngine::connectToId(const QString &id) -{ - emit connectionError(id, OperationNotSupported); -} - -void QGenericEngine::disconnectFromId(const QString &id) -{ - emit connectionError(id, OperationNotSupported); -} - -void QGenericEngine::requestUpdate() -{ - emit configurationsChanged(); -} - -QGenericEngine *QGenericEngine::instance() -{ - return genericEngine(); -} - -#include "moc_qgenericengine_p.cpp" -QT_END_NAMESPACE - diff --git a/src/network/bearer/qgenericengine_p.h b/src/network/bearer/qgenericengine_p.h deleted file mode 100644 index 28d6e90..0000000 --- a/src/network/bearer/qgenericengine_p.h +++ /dev/null @@ -1,94 +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 QGENERICENGINE_P_H -#define QGENERICENGINE_P_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 "qnetworksessionengine_p.h" - -#include -#include - -QT_BEGIN_NAMESPACE - -class QNetworkConfigurationPrivate; - -class QGenericEngine : public QNetworkSessionEngine -{ - Q_OBJECT - -public: - QGenericEngine(QObject *parent = 0); - ~QGenericEngine(); - - QList getConfigurations(bool *ok = 0); - QString getInterfaceFromId(const QString &id); - bool hasIdentifier(const QString &id); - - QString bearerName(const QString &id); - - void connectToId(const QString &id); - void disconnectFromId(const QString &id); - - void requestUpdate(); - - static QGenericEngine *instance(); - -private: - QMap configurationInterface; - QTimer pollTimer; -}; - -QT_END_NAMESPACE - -#endif - diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index 5031dd4..02cc652 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -51,6 +51,13 @@ QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC(QNetworkConfigurationManagerPrivate, connManager); +#ifndef Q_OS_SYMBIAN +QNetworkConfigurationManagerPrivate *qNetworkConfigurationManagerPrivate() +{ + return connManager(); +} +#endif + /*! \class QNetworkConfigurationManager diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 47b23d2..3e82ab7 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -40,7 +40,6 @@ ****************************************************************************/ #include "qnetworkconfigmanager_p.h" -#include "qgenericengine_p.h" #ifdef Q_OS_WIN #include "qnlaengine_win_p.h" @@ -55,12 +54,19 @@ #include "qcorewlanengine_mac_p.h" #endif +#include "qbearerplugin.h" + +#include + #include #include #include QT_BEGIN_NAMESPACE +Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, + (QBearerEngineFactoryInterface_iid, QLatin1String("/bearer"))) + void QNetworkConfigurationManagerPrivate::registerPlatformCapabilities() { capFlags = QNetworkConfigurationManager::ForcedRoaming; @@ -228,6 +234,9 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() updateState = NotUpdating; onlineConfigurations = 0; + QFactoryLoader *l = loader(); + QStringList keys = l->keys(); + #if defined (Q_OS_DARWIN) coreWifi = QCoreWlanEngine::instance(); if (coreWifi) { @@ -242,10 +251,14 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() this, SLOT(updateConfigurations())); } else { #endif - generic = QGenericEngine::instance(); - if (generic) { - connect(generic, SIGNAL(configurationsChanged()), - this, SLOT(updateConfigurations())); + QBearerEnginePlugin *genericPlugin = + qobject_cast(l->instance(QLatin1String("generic"))); + if (genericPlugin) { + generic = genericPlugin->create(QLatin1String("generic")); + if (generic) { + connect(generic, SIGNAL(configurationsChanged()), + this, SLOT(updateConfigurations())); + } } #if defined(BACKEND_NM) } diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index f2e2ee5..2ac6401 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -135,7 +135,7 @@ private: #endif #ifdef BEARER_ENGINE - QGenericEngine *generic; + QNetworkSessionEngine *generic; #ifdef Q_OS_WIN QNlaEngine *nla; #ifndef Q_OS_WINCE @@ -173,6 +173,8 @@ private Q_SLOTS: #endif }; +QNetworkConfigurationManagerPrivate *qNetworkConfigurationManagerPrivate(); + QT_END_NAMESPACE #endif //QNETWORKCONFIGURATIONMANAGERPRIVATE_H diff --git a/src/network/bearer/qnetworkconfiguration_p.h b/src/network/bearer/qnetworkconfiguration_p.h index 69d7e18..f00bcfa 100644 --- a/src/network/bearer/qnetworkconfiguration_p.h +++ b/src/network/bearer/qnetworkconfiguration_p.h @@ -55,7 +55,7 @@ #include "qnetworkconfiguration.h" #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/network/bearer/qnetworksession_p.cpp b/src/network/bearer/qnetworksession_p.cpp index 8e39216..c2491ae 100644 --- a/src/network/bearer/qnetworksession_p.cpp +++ b/src/network/bearer/qnetworksession_p.cpp @@ -42,7 +42,7 @@ #include "qnetworksession_p.h" #include "qnetworksession.h" #include "qnetworksessionengine_p.h" -#include "qgenericengine_p.h" +#include "qnetworkconfigmanager_p.h" #ifdef Q_OS_WIN #include "qnlaengine_win_p.h" @@ -81,6 +81,8 @@ static bool NetworkManagerAvailable() static QNetworkSessionEngine *getEngineFromId(const QString &id) { + QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); + #ifdef Q_OS_WIN QNlaEngine *nla = QNlaEngine::instance(); if (nla && nla->hasIdentifier(id)) @@ -106,9 +108,9 @@ static QNetworkSessionEngine *getEngineFromId(const QString &id) return coreWifi; #endif - QGenericEngine *generic = QGenericEngine::instance(); - if (generic && generic->hasIdentifier(id)) - return generic; + QNetworkSessionEngine *engine = priv->configurationEngine.value(id); + if (engine && engine->hasIdentifier(id)) + return engine; return 0; } diff --git a/src/network/bearer/qnetworksessionengine_p.h b/src/network/bearer/qnetworksessionengine_p.h index 8eb17d4..9fbd4ac 100644 --- a/src/network/bearer/qnetworksessionengine_p.h +++ b/src/network/bearer/qnetworksessionengine_p.h @@ -61,7 +61,7 @@ QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; -class QNetworkSessionEngine : public QObject +class Q_NETWORK_EXPORT QNetworkSessionEngine : public QObject { Q_OBJECT @@ -92,6 +92,8 @@ Q_SIGNALS: void connectionError(const QString &id, QNetworkSessionEngine::ConnectionError error); }; +typedef QNetworkSessionEngine QBearerEngine; + QT_END_NAMESPACE #endif diff --git a/src/plugins/bearer/bearer.pro b/src/plugins/bearer/bearer.pro new file mode 100644 index 0000000..0e3ef48 --- /dev/null +++ b/src/plugins/bearer/bearer.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs + +SUBDIRS += generic diff --git a/src/plugins/bearer/generic/generic.pro b/src/plugins/bearer/generic/generic.pro new file mode 100644 index 0000000..d32dbe6 --- /dev/null +++ b/src/plugins/bearer/generic/generic.pro @@ -0,0 +1,13 @@ +TARGET = qgenericbearer +include(../../qpluginbase.pri) + +QT += network + +DEFINES += BEARER_ENGINE + +HEADERS += qgenericengine.h +SOURCES += qgenericengine.cpp main.cpp + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/bearer +target.path += $$[QT_INSTALL_PLUGINS]/bearer +INSTALLS += target diff --git a/src/plugins/bearer/generic/main.cpp b/src/plugins/bearer/generic/main.cpp new file mode 100644 index 0000000..c877fce --- /dev/null +++ b/src/plugins/bearer/generic/main.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** 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 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 "qgenericengine.h" + +#include + +#include + +QT_BEGIN_NAMESPACE + +class QGenericEnginePlugin : public QBearerEnginePlugin +{ +public: + QGenericEnginePlugin(); + ~QGenericEnginePlugin(); + + QStringList keys() const; + QBearerEngine *create(const QString &key) const; +}; + +QGenericEnginePlugin::QGenericEnginePlugin() +{ +} + +QGenericEnginePlugin::~QGenericEnginePlugin() +{ +} + +QStringList QGenericEnginePlugin::keys() const +{ + qDebug() << Q_FUNC_INFO; + + return QStringList() << QLatin1String("generic"); +} + +QBearerEngine *QGenericEnginePlugin::create(const QString &key) const +{ + qDebug() << Q_FUNC_INFO; + + if (key == QLatin1String("generic")) + return new QGenericEngine; + else + return 0; +} + +Q_EXPORT_STATIC_PLUGIN(QGenericEnginePlugin) +Q_EXPORT_PLUGIN2(qgenericbearer, QGenericEnginePlugin) + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp new file mode 100644 index 0000000..89db82b --- /dev/null +++ b/src/plugins/bearer/generic/qgenericengine.cpp @@ -0,0 +1,234 @@ +/**************************************************************************** +** +** 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 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 "qgenericengine.h" + +#include + +#include +#include +#include +#include + +#include + +#ifdef Q_OS_WIN +#include "qnetworksessionengine_win_p.h" +#endif + +QT_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC(QGenericEngine, genericEngine) + +static QString qGetInterfaceType(const QString &interface) +{ +#ifdef Q_OS_WIN32 + unsigned long oid; + DWORD bytesWritten; + + NDIS_MEDIUM medium; + NDIS_PHYSICAL_MEDIUM physicalMedium; + + HANDLE handle = CreateFile((TCHAR *)QString("\\\\.\\%1").arg(interface).utf16(), 0, + FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); + if (handle == INVALID_HANDLE_VALUE) + return QString(); + + oid = OID_GEN_MEDIA_SUPPORTED; + bytesWritten = 0; + bool result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), + &medium, sizeof(medium), &bytesWritten, 0); + if (!result) { + CloseHandle(handle); + return QString(); + } + + oid = OID_GEN_PHYSICAL_MEDIUM; + bytesWritten = 0; + result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), + &physicalMedium, sizeof(physicalMedium), &bytesWritten, 0); + if (!result) { + CloseHandle(handle); + + if (medium == NdisMedium802_3) + return QLatin1String("Ethernet"); + else + return QString(); + } + + CloseHandle(handle); + + if (medium == NdisMedium802_3) { + switch (physicalMedium) { + case NdisPhysicalMediumWirelessLan: + return QLatin1String("WLAN"); + case NdisPhysicalMediumBluetooth: + return QLatin1String("Bluetooth"); + case NdisPhysicalMediumWiMax: + return QLatin1String("WiMAX"); + default: +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Physical Medium" << physicalMedium; +#endif + return QLatin1String("Ethernet"); + } + } + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << medium << physicalMedium; +#endif +#else + Q_UNUSED(interface); +#endif + + return QString(); +} + +QGenericEngine::QGenericEngine(QObject *parent) +: QNetworkSessionEngine(parent) +{ + connect(&pollTimer, SIGNAL(timeout()), this, SIGNAL(configurationsChanged())); + pollTimer.setInterval(10000); +} + +QGenericEngine::~QGenericEngine() +{ +} + +QList QGenericEngine::getConfigurations(bool *ok) +{ + if (ok) + *ok = true; + + QList foundConfigurations; + + // Immediately after connecting with a wireless access point + // QNetworkInterface::allInterfaces() will sometimes return an empty list. Calling it again a + // second time results in a non-empty list. If we loose interfaces we will end up removing + // network configurations which will break current sessions. + QList interfaces = QNetworkInterface::allInterfaces(); + if (interfaces.isEmpty()) + interfaces = QNetworkInterface::allInterfaces(); + + // create configuration for each interface + while (!interfaces.isEmpty()) { + QNetworkInterface interface = interfaces.takeFirst(); + + if (!interface.isValid()) + continue; + + // ignore loopback interface + if (interface.flags() & QNetworkInterface::IsLoopBack) + continue; + + // ignore WLAN interface handled in seperate engine + if (qGetInterfaceType(interface.name()) == QLatin1String("WLAN")) + continue; + + QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; + const QString humanReadableName = interface.humanReadableName(); + cpPriv->name = humanReadableName.isEmpty() ? interface.name() : humanReadableName; + cpPriv->isValid = true; + + uint identifier; + if (interface.index()) + identifier = qHash(QLatin1String("NLA:") + QString::number(interface.index())); + else + identifier = qHash(QLatin1String("NLA:") + interface.hardwareAddress()); + + cpPriv->id = QString::number(identifier); + cpPriv->state = QNetworkConfiguration::Discovered; + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + if (interface.flags() & QNetworkInterface::IsUp) + cpPriv->state |= QNetworkConfiguration::Active; + + configurationInterface[identifier] = interface.name(); + + foundConfigurations.append(cpPriv); + } + + pollTimer.start(); + + return foundConfigurations; +} + +QString QGenericEngine::getInterfaceFromId(const QString &id) +{ + return configurationInterface.value(id.toUInt()); +} + +bool QGenericEngine::hasIdentifier(const QString &id) +{ + return configurationInterface.contains(id.toUInt()); +} + +QString QGenericEngine::bearerName(const QString &id) +{ + QString interface = getInterfaceFromId(id); + + if (interface.isEmpty()) + return QString(); + + return qGetInterfaceType(interface); +} + +void QGenericEngine::connectToId(const QString &id) +{ + emit connectionError(id, OperationNotSupported); +} + +void QGenericEngine::disconnectFromId(const QString &id) +{ + emit connectionError(id, OperationNotSupported); +} + +void QGenericEngine::requestUpdate() +{ + emit configurationsChanged(); +} + +QGenericEngine *QGenericEngine::instance() +{ + return genericEngine(); +} + +QT_END_NAMESPACE + diff --git a/src/plugins/bearer/generic/qgenericengine.h b/src/plugins/bearer/generic/qgenericengine.h new file mode 100644 index 0000000..9923a9b --- /dev/null +++ b/src/plugins/bearer/generic/qgenericengine.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** 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 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 QGENERICENGINE_H +#define QGENERICENGINE_H + +#include + +#include +#include + +QT_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; + +class QGenericEngine : public QNetworkSessionEngine +{ + Q_OBJECT + +public: + QGenericEngine(QObject *parent = 0); + ~QGenericEngine(); + + QList getConfigurations(bool *ok = 0); + QString getInterfaceFromId(const QString &id); + bool hasIdentifier(const QString &id); + + QString bearerName(const QString &id); + + void connectToId(const QString &id); + void disconnectFromId(const QString &id); + + void requestUpdate(); + + static QGenericEngine *instance(); + +private: + QMap configurationInterface; + QTimer pollTimer; +}; + +QT_END_NAMESPACE + +#endif + diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index 004b816..d6a426f 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -1,6 +1,6 @@ TEMPLATE = subdirs -SUBDIRS *= accessible imageformats sqldrivers iconengines script +SUBDIRS *= accessible imageformats sqldrivers iconengines script bearer unix:!symbian { contains(QT_CONFIG,iconv)|contains(QT_CONFIG,gnu-libiconv):SUBDIRS *= codecs } else { -- cgit v0.12 From 70d0623570936696ca28536a46a3be63c691f50b Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Wed, 2 Dec 2009 09:26:54 +1000 Subject: Add compile test for NetworkManager. --- .../unix/networkmanager/networkmanager.pro | 14 +- configure | 217 +++++++++++---------- 2 files changed, 119 insertions(+), 112 deletions(-) diff --git a/config.tests/unix/networkmanager/networkmanager.pro b/config.tests/unix/networkmanager/networkmanager.pro index 554f513..c41204f 100644 --- a/config.tests/unix/networkmanager/networkmanager.pro +++ b/config.tests/unix/networkmanager/networkmanager.pro @@ -1,11 +1,3 @@ -###################################################################### -# Automatically generated by qmake (2.01a) Mon Oct 19 12:58:26 2009 -###################################################################### - -TEMPLATE = app -TARGET = -DEPENDPATH += . -INCLUDEPATH += . - -# Input -SOURCES += main.cpp +SOURCES = main.cpp +CONFIG -= qt dylib +mac:CONFIG -= app_bundle diff --git a/configure b/configure index 0b11bf3..dcd7d2d 100755 --- a/configure +++ b/configure @@ -765,6 +765,7 @@ OPT_HELP= CFG_SILENT=no CFG_GRAPHICS_SYSTEM=default CFG_ALSA=auto +CFG_NETWORKMANAGER=auto # initalize variables used for installation QT_INSTALL_PREFIX= @@ -5820,6 +5821,14 @@ if [ "$CFG_ALSA" = "auto" ]; then fi fi +if [ "$CFG_NETWORKMANAGER" = "auto" ]; then + if "$unixtests/compile.test" "$XQMAKESPEC" "$QMAKE_CONFIG" $OPT_VERBOSE "$relpath" "$outpath" config.tests/unix/networkmanager "NetworkManager" $L_FLAGS $I_FLAGS $l_FLAGS; then + CFG_NETWORKMANAGER=yes + else + CFG_NETWORKMANAGER=no + fi +fi + if [ -f "$relpath/src/declarative/declarative.pro" ]; then if [ "$CFG_DECLARATIVE" = "auto" ]; then CFG_DECLARATIVE=yes @@ -6297,6 +6306,10 @@ if [ "$CFG_ALSA" = "yes" ]; then QT_CONFIG="$QT_CONFIG alsa" fi +if [ "$CFG_NETWORKMANAGER" = "yes" ]; then + QT_CONFIG="$QT_CONFIG networkmanager" +fi + # # Some Qt modules are too advanced in C++ for some old compilers # Detect here the platforms where they are known to work. @@ -6997,6 +7010,7 @@ fi [ "$CFG_XRANDR" = "runtime" ] && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_RUNTIME_XRANDR" [ "$CFG_XINPUT" = "runtime" ] && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_RUNTIME_XINPUT" [ "$CFG_ALSA" = "no" ] && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_ALSA" +[ "$CFG_NETWORKMANAGER" = "no" ] && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_NETWORKMANAGER" # sort QCONFIG_FLAGS for neatness if we can [ '!' -z "$AWK" ] && QCONFIG_FLAGS=`echo $QCONFIG_FLAGS | $AWK '{ gsub(" ", "\n"); print }' | sort | uniq` @@ -7332,163 +7346,163 @@ fi if [ "$OPT_VERBOSE" = "yes" ]; then if echo '\c' | grep '\c' >/dev/null; then - echo -n "qmake vars .......... " + echo -n "qmake vars ............. " else - echo "qmake vars .......... \c" + echo "qmake vars ............. \c" fi cat "$QMAKE_VARS_FILE" | tr '\n' ' ' - echo "qmake switches ...... $QMAKE_SWITCHES" + echo "qmake switches ......... $QMAKE_SWITCHES" fi -[ "$CFG_INCREMENTAL" = "yes" ] && [ '!' -z "$INCREMENTAL" ] && echo "Incremental ......... $INCREMENTAL" -echo "Build ............... $CFG_BUILD_PARTS" -echo "Configuration ....... $QMAKE_CONFIG $QT_CONFIG" +[ "$CFG_INCREMENTAL" = "yes" ] && [ '!' -z "$INCREMENTAL" ] && echo "Incremental ............ $INCREMENTAL" +echo "Build .................. $CFG_BUILD_PARTS" +echo "Configuration .......... $QMAKE_CONFIG $QT_CONFIG" if [ "$CFG_DEBUG_RELEASE" = "yes" ]; then - echo "Debug ............... yes (combined)" + echo "Debug .................. yes (combined)" if [ "$CFG_DEBUG" = "yes" ]; then - echo "Default Link ........ debug" + echo "Default Link ........... debug" else - echo "Default Link ........ release" + echo "Default Link ........... release" fi else - echo "Debug ............... $CFG_DEBUG" -fi -echo "Qt 3 compatibility .. $CFG_QT3SUPPORT" -[ "$CFG_DBUS" = "no" ] && echo "QtDBus module ....... no" -[ "$CFG_DBUS" = "yes" ] && echo "QtDBus module ....... yes (run-time)" -[ "$CFG_DBUS" = "linked" ] && echo "QtDBus module ....... yes (linked)" -echo "QtConcurrent code.... $CFG_CONCURRENT" -echo "QtScript module ..... $CFG_SCRIPT" -echo "QtScriptTools module $CFG_SCRIPTTOOLS" -echo "QtXmlPatterns module $CFG_XMLPATTERNS" -echo "Phonon module ....... $CFG_PHONON" -echo "Multimedia module ... $CFG_MULTIMEDIA" -echo "SVG module .......... $CFG_SVG" -echo "WebKit module ....... $CFG_WEBKIT" + echo "Debug .................. $CFG_DEBUG" +fi +echo "Qt 3 compatibility ..... $CFG_QT3SUPPORT" +[ "$CFG_DBUS" = "no" ] && echo "QtDBus module .......... no" +[ "$CFG_DBUS" = "yes" ] && echo "QtDBus module .......... yes (run-time)" +[ "$CFG_DBUS" = "linked" ] && echo "QtDBus module .......... yes (linked)" +echo "QtConcurrent code ...... $CFG_CONCURRENT" +echo "QtScript module ........ $CFG_SCRIPT" +echo "QtScriptTools module ... $CFG_SCRIPTTOOLS" +echo "QtXmlPatterns module ... $CFG_XMLPATTERNS" +echo "Phonon module .......... $CFG_PHONON" +echo "Multimedia module ...... $CFG_MULTIMEDIA" +echo "SVG module ............. $CFG_SVG" +echo "WebKit module .......... $CFG_WEBKIT" if [ "$CFG_WEBKIT" = "yes" ]; then if [ "$CFG_JAVASCRIPTCORE_JIT" = "auto" ]; then - echo "JavaScriptCore JIT .. To be decided by JavaScriptCore" + echo "JavaScriptCore JIT ..... To be decided by JavaScriptCore" else - echo "JavaScriptCore JIT .. $CFG_JAVASCRIPTCORE_JIT" + echo "JavaScriptCore JIT ..... $CFG_JAVASCRIPTCORE_JIT" fi fi -echo "Declarative module .. $CFG_DECLARATIVE" -echo "STL support ......... $CFG_STL" -echo "PCH support ......... $CFG_PRECOMPILE" -echo "MMX/3DNOW/SSE/SSE2.. ${CFG_MMX}/${CFG_3DNOW}/${CFG_SSE}/${CFG_SSE2}" +echo "Declarative module ..... $CFG_DECLARATIVE" +echo "STL support ............ $CFG_STL" +echo "PCH support ............ $CFG_PRECOMPILE" +echo "MMX/3DNOW/SSE/SSE2 ..... ${CFG_MMX}/${CFG_3DNOW}/${CFG_SSE}/${CFG_SSE2}" if [ "${CFG_ARCH}" = "arm" ]; then - echo "iWMMXt support ...... ${CFG_IWMMXT}" -fi -[ "${PLATFORM_QWS}" != "yes" ] && echo "Graphics System ..... $CFG_GRAPHICS_SYSTEM" -echo "IPv6 support ........ $CFG_IPV6" -echo "IPv6 ifname support . $CFG_IPV6IFNAME" -echo "getaddrinfo support . $CFG_GETADDRINFO" -echo "getifaddrs support .. $CFG_GETIFADDRS" -echo "Accessibility ....... $CFG_ACCESSIBILITY" -echo "NIS support ......... $CFG_NIS" -echo "CUPS support ........ $CFG_CUPS" -echo "Iconv support ....... $CFG_ICONV" -echo "Glib support ........ $CFG_GLIB" -echo "GStreamer support ... $CFG_GSTREAMER" -echo "Large File support .. $CFG_LARGEFILE" -echo "GIF support ......... $CFG_GIF" + echo "iWMMXt support ......... ${CFG_IWMMXT}" +fi +[ "${PLATFORM_QWS}" != "yes" ] && echo "Graphics System ........ $CFG_GRAPHICS_SYSTEM" +echo "IPv6 support ........... $CFG_IPV6" +echo "IPv6 ifname support .... $CFG_IPV6IFNAME" +echo "getaddrinfo support .... $CFG_GETADDRINFO" +echo "getifaddrs support ..... $CFG_GETIFADDRS" +echo "Accessibility .......... $CFG_ACCESSIBILITY" +echo "NIS support ............ $CFG_NIS" +echo "CUPS support ........... $CFG_CUPS" +echo "Iconv support .......... $CFG_ICONV" +echo "Glib support ........... $CFG_GLIB" +echo "GStreamer support ...... $CFG_GSTREAMER" +echo "Large File support ..... $CFG_LARGEFILE" +echo "GIF support ............ $CFG_GIF" if [ "$CFG_TIFF" = "no" ]; then - echo "TIFF support ........ $CFG_TIFF" + echo "TIFF support ........... $CFG_TIFF" else - echo "TIFF support ........ $CFG_TIFF ($CFG_LIBTIFF)" + echo "TIFF support ........... $CFG_TIFF ($CFG_LIBTIFF)" fi if [ "$CFG_JPEG" = "no" ]; then - echo "JPEG support ........ $CFG_JPEG" + echo "JPEG support ........... $CFG_JPEG" else - echo "JPEG support ........ $CFG_JPEG ($CFG_LIBJPEG)" + echo "JPEG support ........... $CFG_JPEG ($CFG_LIBJPEG)" fi if [ "$CFG_PNG" = "no" ]; then - echo "PNG support ......... $CFG_PNG" + echo "PNG support ............ $CFG_PNG" else - echo "PNG support ......... $CFG_PNG ($CFG_LIBPNG)" + echo "PNG support ............ $CFG_PNG ($CFG_LIBPNG)" fi if [ "$CFG_MNG" = "no" ]; then - echo "MNG support ......... $CFG_MNG" + echo "MNG support ............ $CFG_MNG" else - echo "MNG support ......... $CFG_MNG ($CFG_LIBMNG)" + echo "MNG support ............ $CFG_MNG ($CFG_LIBMNG)" fi -echo "zlib support ........ $CFG_ZLIB" -echo "Session management .. $CFG_SM" +echo "zlib support ........... $CFG_ZLIB" +echo "Session management ..... $CFG_SM" if [ "$PLATFORM_QWS" = "yes" ]; then - echo "Embedded support .... $CFG_EMBEDDED" + echo "Embedded support ....... $CFG_EMBEDDED" if [ "$CFG_QWS_FREETYPE" = "auto" ]; then - echo "Freetype2 support ... $CFG_QWS_FREETYPE ($CFG_LIBFREETYPE)" + echo "Freetype2 support ...... $CFG_QWS_FREETYPE ($CFG_LIBFREETYPE)" else - echo "Freetype2 support ... $CFG_QWS_FREETYPE" + echo "Freetype2 support ...... $CFG_QWS_FREETYPE" fi # Normalize the decoration output first CFG_GFX_ON=`echo ${CFG_GFX_ON}` CFG_GFX_PLUGIN=`echo ${CFG_GFX_PLUGIN}` - echo "Graphics (qt) ....... ${CFG_GFX_ON}" - echo "Graphics (plugin) ... ${CFG_GFX_PLUGIN}" + echo "Graphics (qt) .......... ${CFG_GFX_ON}" + echo "Graphics (plugin) ...... ${CFG_GFX_PLUGIN}" CFG_DECORATION_ON=`echo ${CFG_DECORATION_ON}` CFG_DECORATION_PLUGIN=`echo ${CFG_DECORATION_PLUGIN}` - echo "Decorations (qt) .... $CFG_DECORATION_ON" - echo "Decorations (plugin) $CFG_DECORATION_PLUGIN" + echo "Decorations (qt) ....... $CFG_DECORATION_ON" + echo "Decorations (plugin) ... $CFG_DECORATION_PLUGIN" CFG_KBD_ON=`echo ${CFG_KBD_ON}` CFG_KBD_PLUGIN=`echo ${CFG_KBD_PLUGIN}` - echo "Keyboard driver (qt). ${CFG_KBD_ON}" - echo "Keyboard driver (plugin) ${CFG_KBD_PLUGIN}" + echo "Keyboard driver (qt) ... ${CFG_KBD_ON}" + echo "Keyboard driver (plugin) .. ${CFG_KBD_PLUGIN}" CFG_MOUSE_ON=`echo ${CFG_MOUSE_ON}` CFG_MOUSE_PLUGIN=`echo ${CFG_MOUSE_PLUGIN}` - echo "Mouse driver (qt) ... $CFG_MOUSE_ON" - echo "Mouse driver (plugin) $CFG_MOUSE_PLUGIN" + echo "Mouse driver (qt) ...... $CFG_MOUSE_ON" + echo "Mouse driver (plugin) .. $CFG_MOUSE_PLUGIN" fi if [ "$CFG_OPENGL" = "desktop" ]; then - echo "OpenGL support ...... yes (Desktop OpenGL)" + echo "OpenGL support ......... yes (Desktop OpenGL)" elif [ "$CFG_OPENGL" = "es1" ]; then - echo "OpenGL support ...... yes (OpenGL ES 1.x Common profile)" + echo "OpenGL support ......... yes (OpenGL ES 1.x Common profile)" elif [ "$CFG_OPENGL" = "es1cl" ]; then - echo "OpenGL support ...... yes (OpenGL ES 1.x Common Lite profile)" + echo "OpenGL support ......... yes (OpenGL ES 1.x Common Lite profile)" elif [ "$CFG_OPENGL" = "es2" ]; then - echo "OpenGL support ...... yes (OpenGL ES 2.x)" + echo "OpenGL support ......... yes (OpenGL ES 2.x)" else - echo "OpenGL support ...... no" + echo "OpenGL support ......... no" fi if [ "$CFG_EGL" != "no" ]; then if [ "$CFG_EGL_GLES_INCLUDES" != "no" ]; then - echo "EGL support ......... yes " + echo "EGL support ............ yes " else - echo "EGL support ......... yes " + echo "EGL support ............ yes " fi fi if [ "$CFG_OPENVG" ]; then if [ "$CFG_OPENVG_SHIVA" = "yes" ]; then - echo "OpenVG support ...... ShivaVG" + echo "OpenVG support ......... ShivaVG" else - echo "OpenVG support ...... $CFG_OPENVG" + echo "OpenVG support ......... $CFG_OPENVG" fi fi if [ "$PLATFORM_X11" = "yes" ]; then - echo "NAS sound support ... $CFG_NAS" - echo "XShape support ...... $CFG_XSHAPE" - echo "XSync support ....... $CFG_XSYNC" - echo "Xinerama support .... $CFG_XINERAMA" - echo "Xcursor support ..... $CFG_XCURSOR" - echo "Xfixes support ...... $CFG_XFIXES" - echo "Xrandr support ...... $CFG_XRANDR" - echo "Xrender support ..... $CFG_XRENDER" - echo "Xi support .......... $CFG_XINPUT" - echo "MIT-SHM support ..... $CFG_MITSHM" - echo "FontConfig support .. $CFG_FONTCONFIG" - echo "XKB Support ......... $CFG_XKB" - echo "immodule support .... $CFG_IM" - echo "GTK theme support ... $CFG_QGTKSTYLE" -fi -[ "$CFG_SQL_mysql" != "no" ] && echo "MySQL support ....... $CFG_SQL_mysql" -[ "$CFG_SQL_psql" != "no" ] && echo "PostgreSQL support .. $CFG_SQL_psql" -[ "$CFG_SQL_odbc" != "no" ] && echo "ODBC support ........ $CFG_SQL_odbc" -[ "$CFG_SQL_oci" != "no" ] && echo "OCI support ......... $CFG_SQL_oci" -[ "$CFG_SQL_tds" != "no" ] && echo "TDS support ......... $CFG_SQL_tds" -[ "$CFG_SQL_db2" != "no" ] && echo "DB2 support ......... $CFG_SQL_db2" -[ "$CFG_SQL_ibase" != "no" ] && echo "InterBase support ... $CFG_SQL_ibase" -[ "$CFG_SQL_sqlite2" != "no" ] && echo "SQLite 2 support .... $CFG_SQL_sqlite2" -[ "$CFG_SQL_sqlite" != "no" ] && echo "SQLite support ...... $CFG_SQL_sqlite ($CFG_SQLITE)" + echo "NAS sound support ...... $CFG_NAS" + echo "XShape support ......... $CFG_XSHAPE" + echo "XSync support .......... $CFG_XSYNC" + echo "Xinerama support ....... $CFG_XINERAMA" + echo "Xcursor support ........ $CFG_XCURSOR" + echo "Xfixes support ......... $CFG_XFIXES" + echo "Xrandr support ......... $CFG_XRANDR" + echo "Xrender support ........ $CFG_XRENDER" + echo "Xi support ............. $CFG_XINPUT" + echo "MIT-SHM support ........ $CFG_MITSHM" + echo "FontConfig support ..... $CFG_FONTCONFIG" + echo "XKB Support ............ $CFG_XKB" + echo "immodule support ....... $CFG_IM" + echo "GTK theme support ...... $CFG_QGTKSTYLE" +fi +[ "$CFG_SQL_mysql" != "no" ] && echo "MySQL support .......... $CFG_SQL_mysql" +[ "$CFG_SQL_psql" != "no" ] && echo "PostgreSQL support ..... $CFG_SQL_psql" +[ "$CFG_SQL_odbc" != "no" ] && echo "ODBC support ........... $CFG_SQL_odbc" +[ "$CFG_SQL_oci" != "no" ] && echo "OCI support ............ $CFG_SQL_oci" +[ "$CFG_SQL_tds" != "no" ] && echo "TDS support ............ $CFG_SQL_tds" +[ "$CFG_SQL_db2" != "no" ] && echo "DB2 support ............ $CFG_SQL_db2" +[ "$CFG_SQL_ibase" != "no" ] && echo "InterBase support ...... $CFG_SQL_ibase" +[ "$CFG_SQL_sqlite2" != "no" ] && echo "SQLite 2 support ....... $CFG_SQL_sqlite2" +[ "$CFG_SQL_sqlite" != "no" ] && echo "SQLite support ......... $CFG_SQL_sqlite ($CFG_SQLITE)" OPENSSL_LINKAGE="" if [ "$CFG_OPENSSL" = "yes" ]; then @@ -7496,9 +7510,9 @@ if [ "$CFG_OPENSSL" = "yes" ]; then elif [ "$CFG_OPENSSL" = "linked" ]; then OPENSSL_LINKAGE="(linked)" fi -echo "OpenSSL support ..... $CFG_OPENSSL $OPENSSL_LINKAGE" +echo "OpenSSL support ........ $CFG_OPENSSL $OPENSSL_LINKAGE" -[ "$CFG_PTMALLOC" != "no" ] && echo "Use ptmalloc ........ $CFG_PTMALLOC" +[ "$CFG_PTMALLOC" != "no" ] && echo "Use ptmalloc ........... $CFG_PTMALLOC" # complain about not being able to use dynamic plugins if we are using a static build if [ "$CFG_SHARED" = "no" ]; then @@ -7521,7 +7535,8 @@ if [ "$PLATFORM_MAC" = "yes" ] && [ "$CFG_FRAMEWORK" = "yes" ] && [ "$CFG_DEBUG" echo "NOTE: Mac OS X frameworks implicitly build debug and release Qt libraries." echo fi -echo "alsa support ........ $CFG_ALSA" +echo "alsa support ........... $CFG_ALSA" +echo "NetworkManager support . $CFG_NETWORKMANAGER" echo sepath=`echo "$relpath" | sed -e 's/\\./\\\\./g'` -- cgit v0.12 From 5c07b6b24144774f16a20115eec1a6700d0db254 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 22 Dec 2009 15:08:34 +1000 Subject: Convert NetworkManager engine into a plugin. Conflicts: src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp src/plugins/bearer/networkmanager/qnetworkmanagerservice.h src/plugins/bearer/networkmanager/qnmdbushelper.cpp src/plugins/bearer/networkmanager/qnmdbushelper.h src/plugins/bearer/networkmanager/qnmwifiengine.cpp src/plugins/bearer/networkmanager/qnmwifiengine.h --- src/network/bearer/bearer.pri | 17 +- src/network/bearer/qnetworkconfigmanager_p.cpp | 32 +- src/network/bearer/qnetworkconfigmanager_p.h | 2 +- src/network/bearer/qnetworkmanagerservice_p.cpp | 1011 ------------------ src/network/bearer/qnetworkmanagerservice_p.h | 397 ------- src/network/bearer/qnetworksession_p.cpp | 33 +- src/network/bearer/qnmdbushelper.cpp | 117 -- src/network/bearer/qnmdbushelper_p.h | 89 -- src/network/bearer/qnmwifiengine_unix.cpp | 1129 -------------------- src/network/bearer/qnmwifiengine_unix_p.h | 164 --- src/plugins/bearer/bearer.pro | 1 + src/plugins/bearer/networkmanager/main.cpp | 88 ++ .../bearer/networkmanager/networkmanager.pro | 19 + .../networkmanager/qnetworkmanagerservice.cpp | 1009 +++++++++++++++++ .../bearer/networkmanager/qnetworkmanagerservice.h | 397 +++++++ .../bearer/networkmanager/qnmdbushelper.cpp | 114 ++ src/plugins/bearer/networkmanager/qnmdbushelper.h | 87 ++ .../bearer/networkmanager/qnmwifiengine.cpp | 1128 +++++++++++++++++++ src/plugins/bearer/networkmanager/qnmwifiengine.h | 165 +++ 19 files changed, 3032 insertions(+), 2967 deletions(-) delete mode 100644 src/network/bearer/qnetworkmanagerservice_p.cpp delete mode 100644 src/network/bearer/qnetworkmanagerservice_p.h delete mode 100644 src/network/bearer/qnmdbushelper.cpp delete mode 100644 src/network/bearer/qnmdbushelper_p.h delete mode 100644 src/network/bearer/qnmwifiengine_unix.cpp delete mode 100644 src/network/bearer/qnmwifiengine_unix_p.h create mode 100644 src/plugins/bearer/networkmanager/main.cpp create mode 100644 src/plugins/bearer/networkmanager/networkmanager.pro create mode 100644 src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp create mode 100644 src/plugins/bearer/networkmanager/qnetworkmanagerservice.h create mode 100644 src/plugins/bearer/networkmanager/qnmdbushelper.cpp create mode 100644 src/plugins/bearer/networkmanager/qnmdbushelper.h create mode 100644 src/plugins/bearer/networkmanager/qnmwifiengine.cpp create mode 100644 src/plugins/bearer/networkmanager/qnmwifiengine.h diff --git a/src/network/bearer/bearer.pri b/src/network/bearer/bearer.pri index 4f53621..bed2597 100644 --- a/src/network/bearer/bearer.pri +++ b/src/network/bearer/bearer.pri @@ -80,22 +80,7 @@ symbian { bearer/qnetworksession_p.cpp \ bearer/qnetworksessionengine.cpp - unix:!mac:contains(networkmanager_enabled, yes) { - contains(QT_CONFIG,dbus) { - DEFINES += BACKEND_NM - QT += dbus - - HEADERS += bearer/qnmdbushelper_p.h \ - bearer/qnetworkmanagerservice_p.h \ - bearer/qnmwifiengine_unix_p.h - - SOURCES += bearer/qnmdbushelper.cpp \ - bearer/qnetworkmanagerservice_p.cpp \ - bearer/qnmwifiengine_unix.cpp - } else { - message("NetworkManager backend requires Qt DBus support") - } - } + contains(QT_CONFIG, networkmanager):DEFINES += BACKEND_NM win32 { HEADERS += bearer/qnlaengine_win_p.h \ diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 3e82ab7..7b68394 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -47,9 +47,6 @@ #ifdef Q_OS_WIN32 #include "qnativewifiengine_win_p.h" #endif -#if defined(BACKEND_NM) -#include "qnmwifiengine_unix_p.h" -#endif #ifdef Q_OS_DARWIN #include "qcorewlanengine_mac_p.h" #endif @@ -244,13 +241,21 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() this, SLOT(updateConfigurations())); } #else -#if defined(BACKEND_NM) - nmWifi = QNmWifiEngine::instance(); - if (nmWifi) { - connect(nmWifi, SIGNAL(configurationsChanged()), - this, SLOT(updateConfigurations())); - } else { +#ifdef BACKEND_NM + if (keys.contains(QLatin1String("networkmanager"))) { + QBearerEnginePlugin *nmPlugin = + qobject_cast(l->instance(QLatin1String("networkmanager"))); + if (nmPlugin) { + nmWifi = nmPlugin->create(QLatin1String("networkmanager")); + if (nmWifi) { + connect(nmWifi, SIGNAL(configurationsChanged()), + this, SLOT(updateConfigurations())); + } + } + } #endif + + if (keys.contains(QLatin1String("generic"))) { QBearerEnginePlugin *genericPlugin = qobject_cast(l->instance(QLatin1String("generic"))); if (genericPlugin) { @@ -260,10 +265,8 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() this, SLOT(updateConfigurations())); } } -#if defined(BACKEND_NM) } #endif -#endif #ifdef Q_OS_WIN nla = QNlaEngine::instance(); @@ -293,7 +296,7 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() #if defined(BACKEND_NM) if (engine == nmWifi) updateState &= ~NmUpdating; - else if (engine == generic) + if (engine == generic) updateState &= ~GenericUpdating; #else if (engine == generic) @@ -319,7 +322,7 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() #if defined(BACKEND_NM) if (nmWifi) engines << nmWifi; - else if (generic) + if (generic) engines << generic; #else if (generic) @@ -431,7 +434,8 @@ void QNetworkConfigurationManagerPrivate::performAsyncConfigurationUpdate() if (nmWifi) { updateState |= NmUpdating; nmWifi->requestUpdate(); - } else if (generic) { + } + if (generic) { updateState |= GenericUpdating; generic->requestUpdate(); } diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index 2ac6401..6a61891 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -143,7 +143,7 @@ private: #endif #endif #ifdef BACKEND_NM - QNmWifiEngine *nmWifi; + QNetworkSessionEngine *nmWifi; #endif #ifdef Q_OS_DARWIN QCoreWlanEngine *coreWifi; diff --git a/src/network/bearer/qnetworkmanagerservice_p.cpp b/src/network/bearer/qnetworkmanagerservice_p.cpp deleted file mode 100644 index 9516f31..0000000 --- a/src/network/bearer/qnetworkmanagerservice_p.cpp +++ /dev/null @@ -1,1011 +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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include "qnetworkmanagerservice_p.h" - -//Q_DECLARE_METATYPE(QList) -QT_BEGIN_NAMESPACE - -static QDBusConnection dbusConnection = QDBusConnection::systemBus(); -//static QDBusInterface iface(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, dbusConnection); - -class QNetworkManagerInterfacePrivate -{ -public: - QDBusInterface *connectionInterface; - bool valid; -}; - -QNetworkManagerInterface::QNetworkManagerInterface(QObject *parent) - : QObject(parent) -{ - d = new QNetworkManagerInterfacePrivate(); - d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, - NM_DBUS_PATH, - NM_DBUS_INTERFACE, - dbusConnection); - if (!d->connectionInterface->isValid()) { - qWarning() << "Could not find NetworkManager"; - d->valid = false; - return; - } - d->valid = true; - nmDBusHelper = new QNmDBusHelper; - connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), - this,SIGNAL(propertiesChanged( const QString &, QMap))); - connect(nmDBusHelper,SIGNAL(pathForStateChanged(const QString &, quint32)), - this, SIGNAL(stateChanged(const QString&, quint32))); - -} - -QNetworkManagerInterface::~QNetworkManagerInterface() -{ - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerInterface::isValid() -{ - return d->valid; -} - -bool QNetworkManagerInterface::setConnections() -{ - if(!isValid() ) - return false; - bool allOk = false; - if (!dbusConnection.connect(NM_DBUS_SERVICE, - NM_DBUS_PATH, - NM_DBUS_INTERFACE, - "PropertiesChanged", - nmDBusHelper,SLOT(slotPropertiesChanged( QMap)))) { - allOk = true; - } - if (!dbusConnection.connect(NM_DBUS_SERVICE, - NM_DBUS_PATH, - NM_DBUS_INTERFACE, - "DeviceAdded", - this,SIGNAL(deviceAdded(QDBusObjectPath)))) { - allOk = true; - } - if (!dbusConnection.connect(NM_DBUS_SERVICE, - NM_DBUS_PATH, - NM_DBUS_INTERFACE, - "DeviceRemoved", - this,SIGNAL(deviceRemoved(QDBusObjectPath)))) { - allOk = true; - } - - return allOk; -} - -QDBusInterface *QNetworkManagerInterface::connectionInterface() const -{ - return d->connectionInterface; -} - -QList QNetworkManagerInterface::getDevices() const -{ - QDBusReply > reply = d->connectionInterface->call("GetDevices"); - return reply.value(); -} - -void QNetworkManagerInterface::activateConnection( const QString &serviceName, - QDBusObjectPath connectionPath, - QDBusObjectPath devicePath, - QDBusObjectPath specificObject) -{ - QDBusPendingCall pendingCall = d->connectionInterface->asyncCall("ActivateConnection", - QVariant(serviceName), - QVariant::fromValue(connectionPath), - QVariant::fromValue(devicePath), - QVariant::fromValue(specificObject)); - - QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(pendingCall, this); - connect(callWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), - this, SIGNAL(activationFinished(QDBusPendingCallWatcher*))); -} - -void QNetworkManagerInterface::deactivateConnection(QDBusObjectPath connectionPath) const -{ - d->connectionInterface->call("DeactivateConnection", QVariant::fromValue(connectionPath)); -} - -bool QNetworkManagerInterface::wirelessEnabled() const -{ - return d->connectionInterface->property("WirelessEnabled").toBool(); -} - -bool QNetworkManagerInterface::wirelessHardwareEnabled() const -{ - return d->connectionInterface->property("WirelessHardwareEnabled").toBool(); -} - -QList QNetworkManagerInterface::activeConnections() const -{ - QVariant prop = d->connectionInterface->property("ActiveConnections"); - return prop.value >(); -} - -quint32 QNetworkManagerInterface::state() -{ - return d->connectionInterface->property("State").toUInt(); -} - -///////////// -class QNetworkManagerInterfaceAccessPointPrivate -{ -public: - QDBusInterface *connectionInterface; - QString path; - bool valid; -}; - -QNetworkManagerInterfaceAccessPoint::QNetworkManagerInterfaceAccessPoint(const QString &dbusPathName, QObject *parent) - : QObject(parent) -{ - d = new QNetworkManagerInterfaceAccessPointPrivate(); - d->path = dbusPathName; - d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_ACCESS_POINT, - dbusConnection); - if (!d->connectionInterface->isValid()) { - d->valid = false; - qWarning() << "Could not find InterfaceAccessPoint"; - return; - } - d->valid = true; - -} - -QNetworkManagerInterfaceAccessPoint::~QNetworkManagerInterfaceAccessPoint() -{ - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerInterfaceAccessPoint::isValid() -{ - return d->valid; -} - -bool QNetworkManagerInterfaceAccessPoint::setConnections() -{ - if(!isValid() ) - return false; - - bool allOk = false; - nmDBusHelper = new QNmDBusHelper; - connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), - this,SIGNAL(propertiesChanged( const QString &, QMap))); - - if(dbusConnection.connect(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_ACCESS_POINT, - "PropertiesChanged", - nmDBusHelper,SLOT(slotPropertiesChanged( QMap))) ) { - allOk = true; - - } - return allOk; -} - -QDBusInterface *QNetworkManagerInterfaceAccessPoint::connectionInterface() const -{ - return d->connectionInterface; -} - -quint32 QNetworkManagerInterfaceAccessPoint::flags() const -{ - return d->connectionInterface->property("Flags").toUInt(); -} - -quint32 QNetworkManagerInterfaceAccessPoint::wpaFlags() const -{ - return d->connectionInterface->property("WpaFlags").toUInt(); -} - -quint32 QNetworkManagerInterfaceAccessPoint::rsnFlags() const -{ - return d->connectionInterface->property("RsnFlags").toUInt(); -} - -QString QNetworkManagerInterfaceAccessPoint::ssid() const -{ - return d->connectionInterface->property("Ssid").toString(); -} - -quint32 QNetworkManagerInterfaceAccessPoint::frequency() const -{ - return d->connectionInterface->property("Frequency").toUInt(); -} - -QString QNetworkManagerInterfaceAccessPoint::hwAddress() const -{ - return d->connectionInterface->property("HwAddress").toString(); -} - -quint32 QNetworkManagerInterfaceAccessPoint::mode() const -{ - return d->connectionInterface->property("Mode").toUInt(); -} - -quint32 QNetworkManagerInterfaceAccessPoint::maxBitrate() const -{ - return d->connectionInterface->property("MaxBitrate").toUInt(); -} - -quint32 QNetworkManagerInterfaceAccessPoint::strength() const -{ - return d->connectionInterface->property("Strength").toUInt(); -} - -///////////// -class QNetworkManagerInterfaceDevicePrivate -{ -public: - QDBusInterface *connectionInterface; - QString path; - bool valid; -}; - -QNetworkManagerInterfaceDevice::QNetworkManagerInterfaceDevice(const QString &deviceObjectPath, QObject *parent) - : QObject(parent) -{ - d = new QNetworkManagerInterfaceDevicePrivate(); - d->path = deviceObjectPath; - d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_DEVICE, - dbusConnection); - if (!d->connectionInterface->isValid()) { - d->valid = false; - qWarning() << "Could not find NetworkManager"; - return; - } - d->valid = true; -} - -QNetworkManagerInterfaceDevice::~QNetworkManagerInterfaceDevice() -{ - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerInterfaceDevice::isValid() -{ - return d->valid; -} - -bool QNetworkManagerInterfaceDevice::setConnections() -{ - if(!isValid() ) - return false; - - bool allOk = false; - nmDBusHelper = new QNmDBusHelper; - connect(nmDBusHelper,SIGNAL(pathForStateChanged(const QString &, quint32)), - this, SIGNAL(stateChanged(const QString&, quint32))); - if(dbusConnection.connect(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_DEVICE, - "StateChanged", - nmDBusHelper,SLOT(deviceStateChanged(quint32)))) { - allOk = true; - } - return allOk; -} - -QDBusInterface *QNetworkManagerInterfaceDevice::connectionInterface() const -{ - return d->connectionInterface; -} - -QString QNetworkManagerInterfaceDevice::udi() const -{ - return d->connectionInterface->property("Udi").toString(); -} - -QNetworkInterface QNetworkManagerInterfaceDevice::interface() const -{ - return QNetworkInterface::interfaceFromName(d->connectionInterface->property("Interface").toString()); -} - -quint32 QNetworkManagerInterfaceDevice::ip4Address() const -{ - return d->connectionInterface->property("Ip4Address").toUInt(); -} - -quint32 QNetworkManagerInterfaceDevice::state() const -{ - return d->connectionInterface->property("State").toUInt(); -} - -quint32 QNetworkManagerInterfaceDevice::deviceType() const -{ - return d->connectionInterface->property("DeviceType").toUInt(); -} - -QDBusObjectPath QNetworkManagerInterfaceDevice::ip4config() const -{ - QVariant prop = d->connectionInterface->property("Ip4Config"); - return prop.value(); -} - -///////////// -class QNetworkManagerInterfaceDeviceWiredPrivate -{ -public: - QDBusInterface *connectionInterface; - QString path; - bool valid; -}; - -QNetworkManagerInterfaceDeviceWired::QNetworkManagerInterfaceDeviceWired(const QString &ifaceDevicePath, QObject *parent) -{ - d = new QNetworkManagerInterfaceDeviceWiredPrivate(); - d->path = ifaceDevicePath; - d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_DEVICE_WIRED, - dbusConnection, parent); - if (!d->connectionInterface->isValid()) { - d->valid = false; - qWarning() << "Could not find InterfaceDeviceWired"; - return; - } - d->valid = true; -} - -QNetworkManagerInterfaceDeviceWired::~QNetworkManagerInterfaceDeviceWired() -{ - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerInterfaceDeviceWired::isValid() -{ - - return d->valid; -} - -bool QNetworkManagerInterfaceDeviceWired::setConnections() -{ - if(!isValid() ) - return false; - - bool allOk = false; - - nmDBusHelper = new QNmDBusHelper; - connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), - this,SIGNAL(propertiesChanged( const QString &, QMap))); - if(dbusConnection.connect(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_DEVICE_WIRED, - "PropertiesChanged", - nmDBusHelper,SLOT(slotPropertiesChanged( QMap))) ) { - allOk = true; - } - return allOk; -} - -QDBusInterface *QNetworkManagerInterfaceDeviceWired::connectionInterface() const -{ - return d->connectionInterface; -} - -QString QNetworkManagerInterfaceDeviceWired::hwAddress() const -{ - return d->connectionInterface->property("HwAddress").toString(); -} - -quint32 QNetworkManagerInterfaceDeviceWired::speed() const -{ - return d->connectionInterface->property("Speed").toUInt(); -} - -bool QNetworkManagerInterfaceDeviceWired::carrier() const -{ - return d->connectionInterface->property("Carrier").toBool(); -} - -///////////// -class QNetworkManagerInterfaceDeviceWirelessPrivate -{ -public: - QDBusInterface *connectionInterface; - QString path; - bool valid; -}; - -QNetworkManagerInterfaceDeviceWireless::QNetworkManagerInterfaceDeviceWireless(const QString &ifaceDevicePath, QObject *parent) -{ - d = new QNetworkManagerInterfaceDeviceWirelessPrivate(); - d->path = ifaceDevicePath; - d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_DEVICE_WIRELESS, - dbusConnection, parent); - if (!d->connectionInterface->isValid()) { - d->valid = false; - qWarning() << "Could not find InterfaceDeviceWireless"; - return; - } - d->valid = true; -} - -QNetworkManagerInterfaceDeviceWireless::~QNetworkManagerInterfaceDeviceWireless() -{ - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerInterfaceDeviceWireless::isValid() -{ - return d->valid; -} - -bool QNetworkManagerInterfaceDeviceWireless::setConnections() -{ - if(!isValid() ) - return false; - - bool allOk = false; - nmDBusHelper = new QNmDBusHelper; - connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), - this,SIGNAL(propertiesChanged( const QString &, QMap))); - - connect(nmDBusHelper, SIGNAL(pathForAccessPointAdded(const QString &,QDBusObjectPath)), - this,SIGNAL(accessPointAdded(const QString &,QDBusObjectPath))); - - connect(nmDBusHelper, SIGNAL(pathForAccessPointRemoved(const QString &,QDBusObjectPath)), - this,SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath))); - - if(!dbusConnection.connect(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_DEVICE_WIRELESS, - "AccessPointAdded", - nmDBusHelper, SLOT(slotAccessPointAdded( QDBusObjectPath )))) { - allOk = true; - } - - - if(!dbusConnection.connect(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_DEVICE_WIRELESS, - "AccessPointRemoved", - nmDBusHelper, SLOT(slotAccessPointRemoved( QDBusObjectPath )))) { - allOk = true; - } - - - if(!dbusConnection.connect(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_DEVICE_WIRELESS, - "PropertiesChanged", - nmDBusHelper,SLOT(slotPropertiesChanged( QMap)))) { - allOk = true; - } - - return allOk; -} - -QDBusInterface *QNetworkManagerInterfaceDeviceWireless::connectionInterface() const -{ - return d->connectionInterface; -} - -QList QNetworkManagerInterfaceDeviceWireless::getAccessPoints() -{ - QDBusReply > reply = d->connectionInterface->call("GetAccessPoints"); - return reply.value(); -} - -QString QNetworkManagerInterfaceDeviceWireless::hwAddress() const -{ - return d->connectionInterface->property("HwAddress").toString(); -} - -quint32 QNetworkManagerInterfaceDeviceWireless::mode() const -{ - return d->connectionInterface->property("Mode").toUInt(); -} - -quint32 QNetworkManagerInterfaceDeviceWireless::bitrate() const -{ - return d->connectionInterface->property("Bitrate").toUInt(); -} - -QDBusObjectPath QNetworkManagerInterfaceDeviceWireless::activeAccessPoint() const -{ - return d->connectionInterface->property("ActiveAccessPoint").value(); -} - -quint32 QNetworkManagerInterfaceDeviceWireless::wirelessCapabilities() const -{ - return d->connectionInterface->property("WirelelessCapabilities").toUInt(); -} - -///////////// -class QNetworkManagerSettingsPrivate -{ -public: - QDBusInterface *connectionInterface; - QString path; - bool valid; -}; - -QNetworkManagerSettings::QNetworkManagerSettings(const QString &settingsService, QObject *parent) - : QObject(parent) -{ -// qWarning() << __PRETTY_FUNCTION__; - d = new QNetworkManagerSettingsPrivate(); - d->path = settingsService; - d->connectionInterface = new QDBusInterface(settingsService, - NM_DBUS_PATH_SETTINGS, - NM_DBUS_IFACE_SETTINGS, - dbusConnection); - if (!d->connectionInterface->isValid()) { - d->valid = false; - qWarning() << "Could not find NetworkManagerSettings"; - return; - } - d->valid = true; -} - -QNetworkManagerSettings::~QNetworkManagerSettings() -{ - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerSettings::isValid() -{ - return d->valid; -} - -bool QNetworkManagerSettings::setConnections() -{ - bool allOk = false; - - if (!dbusConnection.connect(d->path, NM_DBUS_PATH_SETTINGS, - NM_DBUS_IFACE_SETTINGS, "NewConnection", - this, SIGNAL(newConnection(QDBusObjectPath)))) { - allOk = true; - } - - return allOk; -} - -QList QNetworkManagerSettings::listConnections() -{ - QDBusReply > reply = d->connectionInterface->call("ListConnections"); - return reply.value(); -} - -QDBusInterface *QNetworkManagerSettings::connectionInterface() const -{ - return d->connectionInterface; -} - - -///////////// -class QNetworkManagerSettingsConnectionPrivate -{ -public: - QDBusInterface *connectionInterface; - QString path; - QString service; - QNmSettingsMap settingsMap; - bool valid; -}; - -QNetworkManagerSettingsConnection::QNetworkManagerSettingsConnection(const QString &settingsService, const QString &connectionObjectPath, QObject *parent) -{ - qDBusRegisterMetaType(); - d = new QNetworkManagerSettingsConnectionPrivate(); - d->path = connectionObjectPath; - d->service = settingsService; - d->connectionInterface = new QDBusInterface(settingsService, - d->path, - NM_DBUS_IFACE_SETTINGS_CONNECTION, - dbusConnection, parent); - if (!d->connectionInterface->isValid()) { - qWarning() << "Could not find NetworkManagerSettingsConnection"; - d->valid = false; - return; - } - d->valid = true; - QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call("GetSettings"); - d->settingsMap = rep.value(); -} - -QNetworkManagerSettingsConnection::~QNetworkManagerSettingsConnection() -{ - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerSettingsConnection::isValid() -{ - return d->valid; -} - -bool QNetworkManagerSettingsConnection::setConnections() -{ - if(!isValid() ) - return false; - - bool allOk = false; - if(!dbusConnection.connect(d->service, d->path, - NM_DBUS_IFACE_SETTINGS_CONNECTION, "NewConnection", - this, SIGNAL(updated(QNmSettingsMap)))) { - allOk = true; - } - - nmDBusHelper = new QNmDBusHelper; - connect(nmDBusHelper, SIGNAL(pathForSettingsRemoved(const QString &)), - this,SIGNAL(removed( const QString &))); - - if (!dbusConnection.connect(d->service, d->path, - NM_DBUS_IFACE_SETTINGS_CONNECTION, "Removed", - nmDBusHelper, SIGNAL(slotSettingsRemoved()))) { - allOk = true; - } - - return allOk; -} -//QNetworkManagerSettingsConnection::update(QNmSettingsMap map) -//{ -// d->connectionInterface->call("Update", QVariant::fromValue(map)); -//} - -QDBusInterface *QNetworkManagerSettingsConnection::connectionInterface() const -{ - return d->connectionInterface; -} - -QNmSettingsMap QNetworkManagerSettingsConnection::getSettings() -{ - QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call("GetSettings"); - d->settingsMap = rep.value(); - return d->settingsMap; -} - -NMDeviceType QNetworkManagerSettingsConnection::getType() -{ - QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); - while (i != d->settingsMap.end() && i.key() == "connection") { - QMap innerMap = i.value(); - QMap::const_iterator ii = innerMap.find("type"); - while (ii != innerMap.end() && ii.key() == "type") { - QString devType = ii.value().toString(); - if (devType == "802-3-ethernet") { - return DEVICE_TYPE_802_3_ETHERNET; - } - if (devType == "802-11-wireless") { - return DEVICE_TYPE_802_11_WIRELESS; - } - ii++; - } - i++; - } - return DEVICE_TYPE_UNKNOWN; -} - -bool QNetworkManagerSettingsConnection::isAutoConnect() -{ - QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); - while (i != d->settingsMap.end() && i.key() == "connection") { - QMap innerMap = i.value(); - QMap::const_iterator ii = innerMap.find("autoconnect"); - while (ii != innerMap.end() && ii.key() == "autoconnect") { - return ii.value().toBool(); - ii++; - } - i++; - } - return true; //default networkmanager is autoconnect -} - -quint64 QNetworkManagerSettingsConnection::getTimestamp() -{ - QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); - while (i != d->settingsMap.end() && i.key() == "connection") { - QMap innerMap = i.value(); - QMap::const_iterator ii = innerMap.find("timestamp"); - while (ii != innerMap.end() && ii.key() == "timestamp") { - return ii.value().toUInt(); - ii++; - } - i++; - } - return 0; -} - -QString QNetworkManagerSettingsConnection::getId() -{ - QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); - while (i != d->settingsMap.end() && i.key() == "connection") { - QMap innerMap = i.value(); - QMap::const_iterator ii = innerMap.find("id"); - while (ii != innerMap.end() && ii.key() == "id") { - return ii.value().toString(); - ii++; - } - i++; - } - return QString(); -} - -QString QNetworkManagerSettingsConnection::getUuid() -{ - QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); - while (i != d->settingsMap.end() && i.key() == "connection") { - QMap innerMap = i.value(); - QMap::const_iterator ii = innerMap.find("uuid"); - while (ii != innerMap.end() && ii.key() == "uuid") { - return ii.value().toString(); - ii++; - } - i++; - } - // is no uuid, return the connection path - return d->connectionInterface->path(); -} - -QString QNetworkManagerSettingsConnection::getSsid() -{ - QNmSettingsMap::const_iterator i = d->settingsMap.find("802-11-wireless"); - while (i != d->settingsMap.end() && i.key() == "802-11-wireless") { - QMap innerMap = i.value(); - QMap::const_iterator ii = innerMap.find("ssid"); - while (ii != innerMap.end() && ii.key() == "ssid") { - return ii.value().toString(); - ii++; - } - i++; - } - return QString(); -} - -QString QNetworkManagerSettingsConnection::getMacAddress() -{ - if(getType() == DEVICE_TYPE_802_3_ETHERNET) { - QNmSettingsMap::const_iterator i = d->settingsMap.find("802-3-ethernet"); - while (i != d->settingsMap.end() && i.key() == "802-3-ethernet") { - QMap innerMap = i.value(); - QMap::const_iterator ii = innerMap.find("mac-address"); - while (ii != innerMap.end() && ii.key() == "mac-address") { - return ii.value().toString(); - ii++; - } - i++; - } - } - - else if(getType() == DEVICE_TYPE_802_11_WIRELESS) { - QNmSettingsMap::const_iterator i = d->settingsMap.find("802-11-wireless"); - while (i != d->settingsMap.end() && i.key() == "802-11-wireless") { - QMap innerMap = i.value(); - QMap::const_iterator ii = innerMap.find("mac-address"); - while (ii != innerMap.end() && ii.key() == "mac-address") { - return ii.value().toString(); - ii++; - } - i++; - } - } - return QString(); -} - -QStringList QNetworkManagerSettingsConnection::getSeenBssids() -{ - if(getType() == DEVICE_TYPE_802_11_WIRELESS) { - QNmSettingsMap::const_iterator i = d->settingsMap.find("802-11-wireless"); - while (i != d->settingsMap.end() && i.key() == "802-11-wireless") { - QMap innerMap = i.value(); - QMap::const_iterator ii = innerMap.find("seen-bssids"); - while (ii != innerMap.end() && ii.key() == "seen-bssids") { - return ii.value().toStringList(); - ii++; - } - i++; - } - } - return QStringList(); -} - -///////////// -class QNetworkManagerConnectionActivePrivate -{ -public: - QDBusInterface *connectionInterface; - QString path; - bool valid; -}; - -QNetworkManagerConnectionActive::QNetworkManagerConnectionActive( const QString &activeConnectionObjectPath, QObject *parent) -{ - d = new QNetworkManagerConnectionActivePrivate(); - d->path = activeConnectionObjectPath; - d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_ACTIVE_CONNECTION, - dbusConnection, parent); - if (!d->connectionInterface->isValid()) { - d->valid = false; - qWarning() << "Could not find NetworkManagerSettingsConnection"; - return; - } - d->valid = true; -} - -QNetworkManagerConnectionActive::~QNetworkManagerConnectionActive() -{ - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerConnectionActive::isValid() -{ - return d->valid; -} - -bool QNetworkManagerConnectionActive::setConnections() -{ - if(!isValid() ) - return false; - - bool allOk = false; - nmDBusHelper = new QNmDBusHelper; - connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), - this,SIGNAL(propertiesChanged( const QString &, QMap))); - if(dbusConnection.connect(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_ACTIVE_CONNECTION, - "PropertiesChanged", - nmDBusHelper,SLOT(slotPropertiesChanged( QMap))) ) { - allOk = true; - } - - return allOk; -} - -QDBusInterface *QNetworkManagerConnectionActive::connectionInterface() const -{ - return d->connectionInterface; -} - -QString QNetworkManagerConnectionActive::serviceName() const -{ - return d->connectionInterface->property("ServiceName").toString(); -} - -QDBusObjectPath QNetworkManagerConnectionActive::connection() const -{ - QVariant prop = d->connectionInterface->property("Connection"); - return prop.value(); -} - -QDBusObjectPath QNetworkManagerConnectionActive::specificObject() const -{ - QVariant prop = d->connectionInterface->property("SpecificObject"); - return prop.value(); -} - -QList QNetworkManagerConnectionActive::devices() const -{ - QVariant prop = d->connectionInterface->property("Devices"); - return prop.value >(); -} - -quint32 QNetworkManagerConnectionActive::state() const -{ - return d->connectionInterface->property("State").toUInt(); -} - -bool QNetworkManagerConnectionActive::defaultRoute() const -{ - return d->connectionInterface->property("Default").toBool(); -} - - -//// -class QNetworkManagerIp4ConfigPrivate -{ -public: - QDBusInterface *connectionInterface; - QString path; - bool valid; -}; - -QNetworkManagerIp4Config::QNetworkManagerIp4Config( const QString &deviceObjectPath, QObject *parent) -{ - d = new QNetworkManagerIp4ConfigPrivate(); - d->path = deviceObjectPath; - d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_IP4_CONFIG, - dbusConnection, parent); - if (!d->connectionInterface->isValid()) { - d->valid = false; - qWarning() << "Could not find NetworkManagerIp4Config"; - return; - } - d->valid = true; -} - -QNetworkManagerIp4Config::~QNetworkManagerIp4Config() -{ - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerIp4Config::isValid() -{ - return d->valid; -} - -QStringList QNetworkManagerIp4Config::domains() const -{ - return d->connectionInterface->property("Domains").toStringList(); -} - -#include "moc_qnetworkmanagerservice_p.cpp" - -QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworkmanagerservice_p.h b/src/network/bearer/qnetworkmanagerservice_p.h deleted file mode 100644 index 520aeac..0000000 --- a/src/network/bearer/qnetworkmanagerservice_p.h +++ /dev/null @@ -1,397 +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 QNETWORKMANAGERSERVICE_H -#define QNETWORKMANAGERSERVICE_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 -#include -#include -#include -#include -#include -#include -#include - - -#include -#include "qnmdbushelper_p.h" - -QT_BEGIN_NAMESPACE - -typedef QMap< QString, QMap > QNmSettingsMap; -typedef QList ServerThing; - -Q_DECLARE_METATYPE(QNmSettingsMap) -Q_DECLARE_METATYPE(ServerThing) - -class QNetworkManagerInterfacePrivate; -class QNetworkManagerInterface : public QObject -{ - Q_OBJECT - -public: - - QNetworkManagerInterface(QObject *parent = 0); - ~QNetworkManagerInterface(); - - QList getDevices() const; - void activateConnection(const QString &serviceName, QDBusObjectPath connection, QDBusObjectPath device, QDBusObjectPath specificObject); - void deactivateConnection(QDBusObjectPath connectionPath) const; - - QDBusObjectPath path() const; - QDBusInterface *connectionInterface() const; - - bool wirelessEnabled() const; - bool wirelessHardwareEnabled() const; - QList activeConnections() const; - quint32 state(); - bool setConnections(); - bool isValid(); - -Q_SIGNALS: - void deviceAdded(QDBusObjectPath); - void deviceRemoved(QDBusObjectPath); - void propertiesChanged( const QString &, QMap); - void stateChanged(const QString&, quint32); - void activationFinished(QDBusPendingCallWatcher*); - -private Q_SLOTS: -private: -// Q_DISABLE_COPY(QNetworkManagerInterface); ?? - QNetworkManagerInterfacePrivate *d; - QNmDBusHelper *nmDBusHelper; -}; //end QNetworkManagerInterface - -//////// -class QNetworkManagerInterfaceAccessPointPrivate; -class QNetworkManagerInterfaceAccessPoint : public QObject -{ - Q_OBJECT - -public: - - // NM_DEVICE_STATE - enum DeviceState { - Unknown = 0, - Unmanaged, - Unavailable, - Disconnected, - Prepare, - Config, - NeedAuthentication, - IpConfig, - Activated, - Failed - }; - - enum ApFlag { - ApNone = 0x0, - Privacy = 0x1 - }; - - Q_DECLARE_FLAGS(ApFlags, ApFlag); - - enum ApSecurityFlag { - ApSecurityNone = 0x0, - PairWep40 = 0x1, - PairWep104 = 0x2, - PairTkip = 0x4, - PairCcmp = 0x8, - GroupWep40 = 0x10, - GroupWep104 = 0x20, - GroupTkip = 0x40, - GroupCcmp = 0x80, - KeyPsk = 0x100, - Key8021x = 0x200 - }; - - Q_DECLARE_FLAGS(ApSecurityFlags, ApSecurityFlag); - - QNetworkManagerInterfaceAccessPoint(const QString &dbusPathName, QObject *parent = 0); - ~QNetworkManagerInterfaceAccessPoint(); - - QDBusInterface *connectionInterface() const; - - quint32 flags() const; - quint32 wpaFlags() const; - quint32 rsnFlags() const; - QString ssid() const; - quint32 frequency() const; - QString hwAddress() const; - quint32 mode() const; - quint32 maxBitrate() const; - quint32 strength() const; - bool setConnections(); - bool isValid(); - -Q_SIGNALS: - void propertiesChanged(QMap ); - void propertiesChanged( const QString &, QMap); -private: - QNetworkManagerInterfaceAccessPointPrivate *d; - QNmDBusHelper *nmDBusHelper; - -}; //end QNetworkManagerInterfaceAccessPoint - -//////// -class QNetworkManagerInterfaceDevicePrivate; -class QNetworkManagerInterfaceDevice : public QObject -{ - Q_OBJECT - -public: - - QNetworkManagerInterfaceDevice(const QString &deviceObjectPath, QObject *parent = 0); - ~QNetworkManagerInterfaceDevice(); - - QString udi() const; - QNetworkInterface interface() const; - QDBusInterface *connectionInterface() const; - quint32 ip4Address() const; - quint32 state() const; - quint32 deviceType() const; - - QDBusObjectPath ip4config() const; - bool setConnections(); - bool isValid(); - -Q_SIGNALS: - void stateChanged(const QString &, quint32); - -private: - QNetworkManagerInterfaceDevicePrivate *d; - QNmDBusHelper *nmDBusHelper; -}; //end QNetworkManagerInterfaceDevice - -//////// -class QNetworkManagerInterfaceDeviceWiredPrivate; -class QNetworkManagerInterfaceDeviceWired : public QObject -{ - Q_OBJECT - -public: - - QNetworkManagerInterfaceDeviceWired(const QString &ifaceDevicePath, QObject *parent = 0); - ~QNetworkManagerInterfaceDeviceWired(); - - QDBusInterface *connectionInterface() const; - QString hwAddress() const; - quint32 speed() const; - bool carrier() const; - bool setConnections(); - bool isValid(); - -Q_SIGNALS: - void propertiesChanged( const QString &, QMap); -private: - QNetworkManagerInterfaceDeviceWiredPrivate *d; - QNmDBusHelper *nmDBusHelper; -}; // end QNetworkManagerInterfaceDeviceWired - -//// -class QNetworkManagerInterfaceDeviceWirelessPrivate; -class QNetworkManagerInterfaceDeviceWireless : public QObject -{ - Q_OBJECT - -public: - - enum DeviceCapability { - None = 0x0, - Wep40 = 0x1, - Wep104 = 0x2, - Tkip = 0x4, - Ccmp = 0x8, - Wpa = 0x10, - Rsn = 0x20 - }; - - QNetworkManagerInterfaceDeviceWireless(const QString &ifaceDevicePath, QObject *parent = 0); - ~QNetworkManagerInterfaceDeviceWireless(); - - QDBusObjectPath path() const; - QList getAccessPoints(); - QDBusInterface *connectionInterface() const; - - QString hwAddress() const; - quint32 mode() const; - quint32 bitrate() const; - QDBusObjectPath activeAccessPoint() const; - quint32 wirelessCapabilities() const; - bool setConnections(); - bool isValid(); - -Q_SIGNALS: - void propertiesChanged( const QString &, QMap); - void accessPointAdded(const QString &,QDBusObjectPath); - void accessPointRemoved(const QString &,QDBusObjectPath); -private: - QNetworkManagerInterfaceDeviceWirelessPrivate *d; - QNmDBusHelper *nmDBusHelper; -}; // end QNetworkManagerInterfaceDeviceWireless - -//// -class QNetworkManagerSettingsPrivate; -class QNetworkManagerSettings : public QObject -{ - Q_OBJECT - -public: - - QNetworkManagerSettings(const QString &settingsService, QObject *parent = 0); - ~QNetworkManagerSettings(); - - QDBusInterface *connectionInterface() const; - QList listConnections(); - bool setConnections(); - bool isValid(); - -Q_SIGNALS: - void newConnection(QDBusObjectPath); -private: - QNetworkManagerSettingsPrivate *d; -}; //end QNetworkManagerSettings - -//// -class QNetworkManagerSettingsConnectionPrivate; -class QNetworkManagerSettingsConnection : public QObject -{ - Q_OBJECT - -public: - - QNetworkManagerSettingsConnection(const QString &settingsService, const QString &connectionObjectPath, QObject *parent = 0); - ~QNetworkManagerSettingsConnection(); - - QDBusInterface *connectionInterface() const; - QNmSettingsMap getSettings(); - // void update(QNmSettingsMap map); - bool setConnections(); - NMDeviceType getType(); - bool isAutoConnect(); - quint64 getTimestamp(); - QString getId(); - QString getUuid(); - QString getSsid(); - QString getMacAddress(); - QStringList getSeenBssids(); - bool isValid(); - -Q_SIGNALS: - - void updated(QMap< QString, QMap > s); - void removed(const QString &); - -private: - QNmDBusHelper *nmDBusHelper; - QNetworkManagerSettingsConnectionPrivate *d; -}; //end QNetworkManagerSettingsConnection - -//// -class QNetworkManagerConnectionActivePrivate; -class QNetworkManagerConnectionActive : public QObject -{ - Q_OBJECT - -public: - - enum ActiveConnectionState { - Unknown = 0, - Activating = 1, - Activated = 2 - }; - - QNetworkManagerConnectionActive(const QString &dbusPathName, QObject *parent = 0); - ~ QNetworkManagerConnectionActive(); - - QDBusInterface *connectionInterface() const; - QString serviceName() const; - QDBusObjectPath connection() const; - QDBusObjectPath specificObject() const; - QList devices() const; - quint32 state() const; - bool defaultRoute() const; - bool setConnections(); - bool isValid(); - - -Q_SIGNALS: - void propertiesChanged(QList); - void propertiesChanged( const QString &, QMap); -private: - QNetworkManagerConnectionActivePrivate *d; - QNmDBusHelper *nmDBusHelper; -}; //QNetworkManagerConnectionActive - -//// -class QNetworkManagerIp4ConfigPrivate; -class QNetworkManagerIp4Config : public QObject -{ - Q_OBJECT - -public: - QNetworkManagerIp4Config(const QString &dbusPathName, QObject *parent = 0); - ~QNetworkManagerIp4Config(); - - // QList nameservers(); - QStringList domains() const; - bool isValid(); - - private: - QNetworkManagerIp4ConfigPrivate *d; -}; -//// - -QT_END_NAMESPACE - -#endif //QNETWORKMANAGERSERVICE_H diff --git a/src/network/bearer/qnetworksession_p.cpp b/src/network/bearer/qnetworksession_p.cpp index c2491ae..cb170e8 100644 --- a/src/network/bearer/qnetworksession_p.cpp +++ b/src/network/bearer/qnetworksession_p.cpp @@ -59,26 +59,8 @@ #include -#if defined(BACKEND_NM) -#include "qnmwifiengine_unix_p.h" -#endif - QT_BEGIN_NAMESPACE -#if defined(BACKEND_NM) -static bool NetworkManagerAvailable() -{ - QDBusConnection dbusConnection = QDBusConnection::systemBus(); - if (dbusConnection.isConnected()) { - QDBusConnectionInterface *dbiface = dbusConnection.interface(); - QDBusReply reply = dbiface->isServiceRegistered("org.freedesktop.NetworkManager"); - if (reply.isValid()) - return reply.value(); - } - return false; -} -#endif - static QNetworkSessionEngine *getEngineFromId(const QString &id) { QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); @@ -95,13 +77,6 @@ static QNetworkSessionEngine *getEngineFromId(const QString &id) return nativeWifi; #endif -#if defined(BACKEND_NM) - if(NetworkManagerAvailable()) { - QNmWifiEngine *nmwiifi = QNmWifiEngine::instance(); - if (nmwiifi && nmwiifi->hasIdentifier(id)) - return nmwiifi; - } -#endif #ifdef Q_OS_DARWIN QCoreWlanEngine *coreWifi = QCoreWlanEngine::instance(); if (coreWifi && coreWifi->hasIdentifier(id)) @@ -322,7 +297,7 @@ QNetworkSession::SessionError QNetworkSessionPrivate::error() const quint64 QNetworkSessionPrivate::bytesWritten() const { -#if defined(BACKEND_NM) +#if defined(BACKEND_NM) && 0 if( state == QNetworkSession::Connected ) { if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { foreach (const QNetworkConfiguration &config, publicConfig.children()) { @@ -340,7 +315,7 @@ quint64 QNetworkSessionPrivate::bytesWritten() const quint64 QNetworkSessionPrivate::bytesReceived() const { -#if defined(BACKEND_NM) +#if defined(BACKEND_NM) && 0 if( state == QNetworkSession::Connected ) { if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { foreach (const QNetworkConfiguration &config, publicConfig.children()) { @@ -445,7 +420,7 @@ void QNetworkSessionPrivate::networkConfigurationsChanged() updateStateFromServiceNetwork(); else updateStateFromActiveConfig(); -#if defined(BACKEND_NM) +#if defined(BACKEND_NM) && 0 setActiveTimeStamp(); #endif } @@ -492,7 +467,7 @@ void QNetworkSessionPrivate::connectionError(const QString &id, QNetworkSessionE } } -#if defined(BACKEND_NM) +#if defined(BACKEND_NM) && 0 void QNetworkSessionPrivate::setActiveTimeStamp() { if(NetworkManagerAvailable()) { diff --git a/src/network/bearer/qnmdbushelper.cpp b/src/network/bearer/qnmdbushelper.cpp deleted file mode 100644 index 5d7403b..0000000 --- a/src/network/bearer/qnmdbushelper.cpp +++ /dev/null @@ -1,117 +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$ -** -****************************************************************************/ - -// this class is for helping qdbus get stuff - -#include "qnmdbushelper_p.h" - -#if !defined(QT_NO_DBUS) && !defined(Q_OS_MAC) -#include - -#include -#include -#include -#include -#endif - -#include - -QT_BEGIN_NAMESPACE - -void QNmDBusHelper::deviceStateChanged(quint32 state) - { - QDBusMessage msg = this->message(); - if(state == NM_DEVICE_STATE_ACTIVATED - || state == NM_DEVICE_STATE_DISCONNECTED - || state == NM_DEVICE_STATE_UNAVAILABLE - || state == NM_DEVICE_STATE_FAILED) { - emit pathForStateChanged(msg.path(), state); - } - } - -void QNmDBusHelper::slotAccessPointAdded(QDBusObjectPath path) -{ - if(path.path().length() > 2) { - QDBusMessage msg = this->message(); - emit pathForAccessPointAdded(msg.path(), path); - } -} - -void QNmDBusHelper::slotAccessPointRemoved(QDBusObjectPath path) -{ - if(path.path().length() > 2) { - QDBusMessage msg = this->message(); - emit pathForAccessPointRemoved(msg.path(), path); - } -} - -void QNmDBusHelper::slotPropertiesChanged(QMap map) -{ - QDBusMessage msg = this->message(); - QMapIterator i(map); - while (i.hasNext()) { - i.next(); - if( i.key() == "State") { //state only applies to device interfaces - quint32 state = i.value().toUInt(); - if( state == NM_DEVICE_STATE_ACTIVATED - || state == NM_DEVICE_STATE_DISCONNECTED - || state == NM_DEVICE_STATE_UNAVAILABLE - || state == NM_DEVICE_STATE_FAILED) { - emit pathForPropertiesChanged( msg.path(), map); - } - } else if( i.key() == "ActiveAccessPoint") { - // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value().value().path(); - // } else if( i.key() == "Strength") - // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value().toUInt(); - // else - // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value(); - } - } -} - -void QNmDBusHelper::slotSettingsRemoved() -{ - QDBusMessage msg = this->message(); - emit pathForSettingsRemoved(msg.path()); -} - -#include "moc_qnmdbushelper_p.cpp" -QT_END_NAMESPACE diff --git a/src/network/bearer/qnmdbushelper_p.h b/src/network/bearer/qnmdbushelper_p.h deleted file mode 100644 index 99b0357..0000000 --- a/src/network/bearer/qnmdbushelper_p.h +++ /dev/null @@ -1,89 +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 QNMDBUSHELPERPRIVATE_H -#define QNMDBUSHELPERPRIVATE_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. -// - -#if !defined(QT_NO_DBUS) && !defined(Q_OS_MAC) -#include -#include -#include -#endif - -QT_BEGIN_NAMESPACE - -#if !defined(QT_NO_DBUS) && !defined(Q_OS_MAC) - -class QNmDBusHelper: public QObject, protected QDBusContext - { - Q_OBJECT - public: - - public slots: - void deviceStateChanged(quint32); - void slotAccessPointAdded( QDBusObjectPath ); - void slotAccessPointRemoved( QDBusObjectPath ); - void slotPropertiesChanged( QMap); - void slotSettingsRemoved(); - -Q_SIGNALS: - void pathForStateChanged(const QString &, quint32); - void pathForAccessPointAdded(const QString &, QDBusObjectPath ); - void pathForAccessPointRemoved(const QString &, QDBusObjectPath ); - void pathForPropertiesChanged(const QString &, QMap); - void pathForSettingsRemoved(const QString &); -}; -#endif - -QT_END_NAMESPACE - -#endif// QNMDBUSHELPERPRIVATE_H diff --git a/src/network/bearer/qnmwifiengine_unix.cpp b/src/network/bearer/qnmwifiengine_unix.cpp deleted file mode 100644 index 5870a9f..0000000 --- a/src/network/bearer/qnmwifiengine_unix.cpp +++ /dev/null @@ -1,1129 +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 "qnmwifiengine_unix_p.h" -#include "qnetworkconfiguration_p.h" -#include - -#include - -#include -#include -#include - -#include - -QT_BEGIN_NAMESPACE - -Q_GLOBAL_STATIC(QNmWifiEngine, nmWifiEngine) -typedef QList > QNmSettingsAddressMap; - -Q_DECLARE_METATYPE(QNmSettingsAddressMap) - -QNmWifiEngine::QNmWifiEngine(QObject *parent) -: QNetworkSessionEngine(parent) -{ - iface = new QNetworkManagerInterface(); - if(!iface->isValid()) { - return; - } - iface->setConnections(); - connect(iface,SIGNAL(deviceAdded(QDBusObjectPath)), - this,SLOT(addDevice(QDBusObjectPath))); - connect(iface,SIGNAL(deviceRemoved(QDBusObjectPath)), - this,SLOT(removeDevice(QDBusObjectPath))); - - QList list = iface->getDevices(); - - foreach(QDBusObjectPath path, list) { - addDevice(path); - } - - QStringList connectionServices; - connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; - connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; - foreach (QString service, connectionServices) { - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(service); - settingsiface->setConnections(); - connect(settingsiface,SIGNAL(newConnection(QDBusObjectPath)), - this,(SLOT(newConnection(QDBusObjectPath)))); - } - - updated = false; -} - -QNmWifiEngine::~QNmWifiEngine() -{ -} - -QString QNmWifiEngine::getNameForConfiguration(QNetworkManagerInterfaceDevice *devIface) -{ - QString newname; - if (devIface->state() == NM_DEVICE_STATE_ACTIVATED) { - QString path = devIface->ip4config().path(); - QNetworkManagerIp4Config * ipIface; - ipIface = new QNetworkManagerIp4Config(path); - newname = ipIface->domains().join(" "); - } - //fallback to interface name - if(newname.isEmpty()) - newname = devIface->interface().name(); - return newname; -} - - -QList QNmWifiEngine::getConfigurations(bool *ok) -{ -// qWarning() << Q_FUNC_INFO << updated; - if (ok) - *ok = false; - - if(!updated) { - foundConfigurations.clear(); - if(knownSsids.isEmpty()) - getKnownSsids(); // list of ssids that have user configurations. - - scanForAccessPoints(); - getActiveConnectionsPaths(); - knownConnections(); - - accessPointConnections(); - -// findConnections(); - //add access points - updated = true; - } - return foundConfigurations; -} - -void QNmWifiEngine::findConnections() -{ - QList list = iface->getDevices(); - - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); - - //// eth - switch (devIface->deviceType()) { -// qWarning() << devIface->connectionInterface()->path(); - - case DEVICE_TYPE_802_3_ETHERNET: - { - QString ident; - QNetworkManagerInterfaceDeviceWired *devWiredIface; - devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); - - ident = devWiredIface->hwAddress(); - - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - cpPriv->name = getNameForConfiguration(devIface); - cpPriv->isValid = true; - cpPriv->id = ident; - cpPriv->internet = devWiredIface->carrier(); - - cpPriv->serviceInterface = devIface->interface(); - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - switch (devIface->state()) { - case NM_DEVICE_STATE_UNKNOWN: - case NM_DEVICE_STATE_UNMANAGED: - case NM_DEVICE_STATE_FAILED: - cpPriv->state = (cpPriv->state | QNetworkConfiguration::Undefined); - break; - case NM_DEVICE_STATE_UNAVAILABLE: - cpPriv->state = (cpPriv->state | QNetworkConfiguration::Defined); - break; - case NM_DEVICE_STATE_PREPARE: - case NM_DEVICE_STATE_CONFIG: - case NM_DEVICE_STATE_NEED_AUTH: - case NM_DEVICE_STATE_IP_CONFIG: - case NM_DEVICE_STATE_DISCONNECTED: - { - cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Discovered - | QNetworkConfiguration::Defined); - } - break; - case NM_DEVICE_STATE_ACTIVATED: - cpPriv->state = (cpPriv->state | QNetworkConfiguration::Active ); - break; - default: - cpPriv->state = (cpPriv->state | QNetworkConfiguration::Undefined); - break; - }; - cpPriv->purpose = QNetworkConfiguration::PublicPurpose; - foundConfigurations.append(cpPriv); - configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); - } - break; - case DEVICE_TYPE_802_11_WIRELESS: - { -// QNetworkManagerInterfaceDeviceWireless *devWirelessIface; -// devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); -// -// //// connections -// QStringList connectionServices; -// connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; -// connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; -// -// QString connPath; -// -// foreach (QString service, connectionServices) { -// QString ident; -// QNetworkManagerSettings *settingsiface; -// settingsiface = new QNetworkManagerSettings(service); -// QList list = settingsiface->listConnections(); -// -// foreach(QDBusObjectPath path, list) { //for each connection path -//qWarning() << path.path(); -// ident = path.path(); -// bool addIt = false; -// QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); -// cpPriv->isValid = true; -// cpPriv->id = ident; -// cpPriv->internet = true; -// -// cpPriv->type = QNetworkConfiguration::InternetAccessPoint; -// cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Discovered -// | QNetworkConfiguration::Defined); -// cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; -// -// QNetworkManagerSettingsConnection *sysIface; -// sysIface = new QNetworkManagerSettingsConnection(service, path.path()); -// cpPriv->name = sysIface->getId();//ii.value().toString(); -//qWarning() << cpPriv->name; -// if(sysIface->getType() == DEVICE_TYPE_802_3_ETHERNET/*type == "802-3-ethernet"*/ -// && devIface->deviceType() == DEVICE_TYPE_802_3_ETHERNET) { -// cpPriv->serviceInterface = devIface->interface(); -// addIt = true; -// } else if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS/*type == "802-11-wireless"*/ -// && devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { -// cpPriv->serviceInterface = devIface->interface(); -// addIt = true; -// // get the wifi interface state first.. do we need this? -// // QString activeAPPath = devWirelessIface->activeAccessPoint().path(); -// } -// -// //#if 0 -// foreach(QString conpath, activeConnectionPaths) { -// QNetworkManagerConnectionActive *aConn; -// aConn = new QNetworkManagerConnectionActive(conpath); -// // in case of accesspoint, specificObject will hold the accessPOintObjectPath -// // qWarning() << aConn->connection().path() << aConn->specificObject().path() << aConn->devices().count(); -// if( aConn->connection().path() == ident) { -// -// QList devs = aConn->devices(); -// foreach(QDBusObjectPath device, devs) { -// QNetworkManagerInterfaceDevice *ifaceDevice; -// ifaceDevice = new QNetworkManagerInterfaceDevice(device.path()); -// cpPriv->serviceInterface = ifaceDevice->interface(); -// cpPriv->state = getStateFlag(ifaceDevice->state()); -// //cpPriv->accessPoint = aConn->specificObject().path(); -// -// break; -// } -// } -// } -// //#endif -// // } //end while connection -// if(addIt) { -// foundConfigurations.append(cpPriv); -// configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); -// } -// } -// } //end each connection service -// -// // ////////////// AccessPoints -//// QList apList = devWirelessIface->getAccessPoints(); -////// qWarning() << apList.count(); -//// foreach(QDBusObjectPath path, apList) { -//// QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); -//// cpPriv = addAccessPoint( devIface->connectionInterface()->path(), path); -//// if(cpPriv->isValid) { -//// foundConfigurations.append(cpPriv); -//// } -//// } - } // end DEVICE_TYPE_802_11_WIRELESS - break; - }; - } //end foreach device -} - -void QNmWifiEngine::knownConnections() -{ -// qWarning() << Q_FUNC_INFO; - //// connections - QStringList connectionServices; - connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; - connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; - - QString connPath; - - foreach (QString service, connectionServices) { - QString ident; - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(service); - QList list = settingsiface->listConnections(); - -// qWarning() <setConnections(); - connect(sysIface, SIGNAL(removed(QString)), - this,SLOT(settingsConnectionRemoved(QString))); - - cpPriv->name = sysIface->getId(); - cpPriv->isValid = true; - cpPriv->id = sysIface->getUuid(); -// cpPriv->id = ident; - cpPriv->internet = true; - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; -//qWarning() << cpPriv->name; - cpPriv->state = getStateForId(cpPriv->id); - - cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; - - if(sysIface->getType() == DEVICE_TYPE_802_3_ETHERNET) { - QString mac = sysIface->getMacAddress(); - if(!mac.length() > 2) { - qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXX" << mac << "type ethernet"; - QString devPath; - devPath = deviceConnectionPath(mac); - - // qWarning() << Q_FUNC_INFO << devPath; - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(devPath); - cpPriv->serviceInterface = devIface->interface(); - QNetworkManagerInterfaceDeviceWired *devWiredIface; - devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); - cpPriv->internet = devWiredIface->carrier(); - - // use this mac addy - } else { - cpPriv->serviceInterface = getBestInterface( DEVICE_TYPE_802_3_ETHERNET, cpPriv->id); - } - - cpPriv->internet = true;//sysIface->isAutoConnect(); - - addIt = true; - } else if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS) { - QString mac = sysIface->getMacAddress();; - if(!mac.length() > 2) { - qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXX" << mac << "type wireless"; - QString devPath; - devPath = deviceConnectionPath(mac); -// qWarning() << Q_FUNC_INFO << devPath; - - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(devPath); - cpPriv->serviceInterface = devIface->interface(); - // use this mac addy - } else { - cpPriv->serviceInterface = getBestInterface( DEVICE_TYPE_802_11_WIRELESS, cpPriv->id); - } - // cpPriv->serviceInterface = devIface->interface(); - addIt = true; - // get the wifi interface state first.. do we need this? - // QString activeAPPath = devWirelessIface->activeAccessPoint().path(); - } - if(addIt) { - foundConfigurations.append(cpPriv); - configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); - } - } //end each connection service - } -} - -void QNmWifiEngine::accessPointConnections() -{ - //qWarning() << Q_FUNC_INFO; - QList list = iface->getDevices(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(path.path()); - if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { - QList apList = availableAccessPoints.uniqueKeys(); - - QList::const_iterator i; - for (i = apList.constBegin(); i != apList.constEnd(); ++i) { - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - cpPriv = addAccessPoint( devIface->connectionInterface()->path(), availableAccessPoints[*i]); - if(cpPriv->isValid) { - foundConfigurations.append(cpPriv); - // qWarning() << "adding" << cpPriv->name << "to things"; - configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); - } - } - } - } -} - -QString QNmWifiEngine::getInterfaceFromId(const QString &id) -{ - return configurationInterface.value(id); -} - -bool QNmWifiEngine::hasIdentifier(const QString &id) -{ - if (configurationInterface.contains(id)) - return true; - foreach (QNetworkConfigurationPrivate *cpPriv, getConfigurations()) { - if (cpPriv->id == id) - return true; - } - return false; -} - -QString QNmWifiEngine::bearerName(const QString &id) -{ - QString interface = getInterfaceFromId(id); - - QList list = iface->getDevices(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(path.path()); - if(interface == devIface->interface().name()) { - switch(devIface->deviceType()) { - case DEVICE_TYPE_802_3_ETHERNET/*NM_DEVICE_TYPE_ETHERNET*/: - return QLatin1String("Ethernet"); - break; - case DEVICE_TYPE_802_11_WIRELESS/*NM_DEVICE_TYPE_WIFI*/: - return QLatin1String("WLAN"); - break; - case DEVICE_TYPE_GSM/*NM_DEVICE_TYPE_GSM*/: - return QLatin1String("2G"); - break; - case DEVICE_TYPE_CDMA/*NM_DEVICE_TYPE_CDMA*/: - return QLatin1String("CDMA2000"); - break; - default: - break; - }; - } - } - return QString(); -} - -void QNmWifiEngine::connectToId(const QString &id) -{ -// qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << __FUNCTION__ << id; - activatingConnectionPath = id; - QStringList connectionSettings = getConnectionPathForId(id); - if(connectionSettings.isEmpty()) { - emit connectionError(id, OperationNotSupported); - return; - } - - QDBusObjectPath connectionPath(connectionSettings.at(1)); - QString interface = getInterfaceFromId(id); - - interface = QNetworkInterface::interfaceFromName(interface).hardwareAddress().toLower(); - QString devPath; - devPath = deviceConnectionPath(interface); - QDBusObjectPath devicePath(devPath); - - iface = new QNetworkManagerInterface(); - iface->activateConnection( - connectionSettings.at(0), - connectionPath, - devicePath, - connectionPath); - - connect(iface, SIGNAL(activationFinished(QDBusPendingCallWatcher*)), - this, SLOT(slotActivationFinished(QDBusPendingCallWatcher*))); -} - -void QNmWifiEngine::disconnectFromId(const QString &id) -{ - QString activeConnectionPath = getActiveConnectionPath(id); - //qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << __FUNCTION__ << id << activeConnectionPath ; - - if (!activeConnectionPath.isEmpty()) { - QNetworkManagerConnectionActive *activeCon; - activeCon = new QNetworkManagerConnectionActive(activeConnectionPath); - QNetworkManagerSettingsConnection *settingsCon; - settingsCon = new QNetworkManagerSettingsConnection(activeCon->serviceName(), activeCon->connection().path()); - - if(settingsCon->isAutoConnect()) { -// qWarning() << id << "is autoconnect"; - emit connectionError(id, OperationNotSupported); - //unsupported - } else { -// qWarning() <deactivateConnection(dbpath); - activatingConnectionPath = ""; - } - } -} - -void QNmWifiEngine::requestUpdate() -{ - updated = false; - knownSsids.clear(); - availableAccessPoints.clear(); - emitConfigurationsChanged(); -} - -QNmWifiEngine *QNmWifiEngine::instance() -{ - QDBusConnection dbusConnection = QDBusConnection::systemBus(); - if (dbusConnection.isConnected()) { - QDBusConnectionInterface *dbiface = dbusConnection.interface(); - QDBusReply reply = dbiface->isServiceRegistered("org.freedesktop.NetworkManager"); - if (reply.isValid() && reply.value()) - return nmWifiEngine(); - } - - return 0; -} - -void QNmWifiEngine::getKnownSsids() -{ - QStringList connectionServices; - connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; - connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; -//qWarning() << Q_FUNC_INFO; - foreach (QString service, connectionServices) { - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(service); - QList list = settingsiface->listConnections(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerSettingsConnection *sysIface; - sysIface = new QNetworkManagerSettingsConnection(service, path.path()); -// qWarning() << sysIface->getSsid(); - knownSsids << sysIface->getSsid(); - } - } -} - -void QNmWifiEngine::getActiveConnectionsPaths() -{ -// qWarning() << Q_FUNC_INFO; - QNetworkManagerInterface *dbIface; - activeConnectionPaths.clear(); - dbIface = new QNetworkManagerInterface; - QList connections = dbIface->activeConnections(); - - foreach(QDBusObjectPath conpath, connections) { - activeConnectionPaths << conpath.path(); -// qWarning() << __FUNCTION__ << conpath.path() << activeConnectionPaths.count(); - - QNetworkManagerConnectionActive *activeConn; - activeConn = new QNetworkManagerConnectionActive(conpath.path()); - -// qWarning() << activeConn->connection().path() /*<< activeConn->specificObject().path() */<< activeConn->devices()[0].path(); - - } -} - -QNetworkConfigurationPrivate * QNmWifiEngine::addAccessPoint( const QString &iPath, QDBusObjectPath path) -{ //foreach accessPoint - //qWarning() << Q_FUNC_INFO << iPath << path.path(); - - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(iPath); - QNetworkManagerInterfaceDeviceWireless *devWirelessIface; - devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(iPath); - - QString activeAPPath = devWirelessIface->activeAccessPoint().path(); - - QNetworkManagerInterfaceAccessPoint *accessPointIface; - accessPointIface = new QNetworkManagerInterfaceAccessPoint(path.path()); - - QString ident = accessPointIface->connectionInterface()->path(); - quint32 nmState = devIface->state(); - - QString ssid = accessPointIface->ssid(); - QString hwAddy = accessPointIface->hwAddress(); - QString sInterface = devIface->interface().name(); - - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - bool addIt = true; - //qWarning() << availableAccessPoints.count() << ssid; - -// if(availableAccessPoints.contains(ssid)) { -// addIt = false; -// -// } -// foreach (QNetworkConfigurationPrivate *cpPriv, foundConfigurations) { -// if (cpPriv->name == ssid) { //weed out duplicate ssid's ?? -// addIt = false; -// break; -// } -// } - - if(addIt) { - - cpPriv->name = ssid; - cpPriv->isValid = true; - cpPriv->id = ident; - cpPriv->internet = true; - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - cpPriv->serviceInterface = devIface->interface(); - - //qWarning() <<__FUNCTION__ << ssid; - - cpPriv->state = getAPState(nmState, knownSsids.contains(cpPriv->name)); - - if(activeAPPath == accessPointIface->connectionInterface()->path()) { - cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Active); - } - if(accessPointIface->flags() == NM_802_11_AP_FLAGS_PRIVACY) - cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; - else - cpPriv->purpose = QNetworkConfiguration::PublicPurpose; - return cpPriv; - } else { - cpPriv->isValid = false; - } - return cpPriv; -} - - - QNetworkConfiguration::StateFlags QNmWifiEngine::getAPState(qint32 nmState, bool isKnown) -{ - QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined; -//qWarning() << nmState << knownSsids; - // this is the state of the wifi device interface - if(isKnown) - state = ( QNetworkConfiguration::Defined); - - switch(nmState) { //device interface state, not AP state - case NM_DEVICE_STATE_UNKNOWN: - case NM_DEVICE_STATE_UNMANAGED: - case NM_DEVICE_STATE_UNAVAILABLE: - state = (QNetworkConfiguration::Undefined); - break; - case NM_DEVICE_STATE_DISCONNECTED: - { - if(isKnown) - state = ( state | QNetworkConfiguration::Discovered); - } - break; - case NM_DEVICE_STATE_PREPARE: - case NM_DEVICE_STATE_CONFIG: - case NM_DEVICE_STATE_NEED_AUTH: - case NM_DEVICE_STATE_IP_CONFIG: - if(isKnown) - state = ( state | QNetworkConfiguration::Discovered); - break; - case NM_DEVICE_STATE_ACTIVATED: - { - if(isKnown) - state = ( state | QNetworkConfiguration::Discovered); - } - break; - }; - return state; -} - -QString QNmWifiEngine::getActiveConnectionPath(const QString &id) -{ - //qWarning() << Q_FUNC_INFO << id; - QStringList connectionSettings = getConnectionPathForId(id); - //qWarning() << Q_FUNC_INFO << id << connectionSettings.count(); - QNetworkManagerInterface * ifaceD; - ifaceD = new QNetworkManagerInterface(); - QList connections = ifaceD->activeConnections(); - foreach(QDBusObjectPath path, connections) { - QNetworkManagerConnectionActive *conDetailsD; - conDetailsD = new QNetworkManagerConnectionActive( path.path()); - if(conDetailsD->connection().path() == connectionSettings.at(1) - && conDetailsD->serviceName() == connectionSettings.at(0)) - return path.path(); - } - return QString(); -} - - QNetworkConfiguration::StateFlags QNmWifiEngine::getStateFlag(quint32 nmstate) - { -// qWarning() << Q_FUNC_INFO << nmstate; - QNetworkConfiguration::StateFlags flag; - switch (nmstate) { - case NM_DEVICE_STATE_UNKNOWN: - case NM_DEVICE_STATE_FAILED: - case NM_DEVICE_STATE_UNMANAGED: - flag = (QNetworkConfiguration::Undefined); - break; - case NM_DEVICE_STATE_PREPARE: - case NM_DEVICE_STATE_CONFIG: - case NM_DEVICE_STATE_NEED_AUTH: - case NM_DEVICE_STATE_IP_CONFIG: - case NM_DEVICE_STATE_UNAVAILABLE: - flag = (QNetworkConfiguration::Defined); - break; - case NM_DEVICE_STATE_DISCONNECTED: - flag = ( flag | QNetworkConfiguration::Discovered ); - break; - case NM_DEVICE_STATE_ACTIVATED: - { - flag = ( flag | QNetworkConfiguration::Discovered - | QNetworkConfiguration::Active ); - } - break; - default: - flag = ( QNetworkConfiguration::Defined); - break; - }; - return flag; - } - -void QNmWifiEngine::updateDeviceInterfaceState(const QString &/*path*/, quint32 nmState) -{ -// qWarning() << Q_FUNC_INFO << path << nmState; - - if(nmState == NM_DEVICE_STATE_ACTIVATED - || nmState == NM_DEVICE_STATE_DISCONNECTED - || nmState == NM_DEVICE_STATE_UNAVAILABLE - || nmState == NM_DEVICE_STATE_FAILED) { - -/* InterfaceLookupError = 0, - ConnectError, - OperationNotSupported, - DisconnectionError, -*/ -// qWarning() << Q_FUNC_INFO << ident; - QNetworkConfiguration::StateFlags state = (QNetworkConfiguration::Defined); - switch (nmState) { - case NM_DEVICE_STATE_UNKNOWN: - case NM_DEVICE_STATE_FAILED: - state = (QNetworkConfiguration::Undefined); - emit connectionError(activatingConnectionPath, ConnectError); - requestUpdate(); -// qWarning() << Q_FUNC_INFO; - break; - case NM_DEVICE_STATE_UNAVAILABLE: - state = (QNetworkConfiguration::Defined); -// emit connectionError(activatingConnectionPath, ConnectError); - requestUpdate(); - break; - case NM_DEVICE_STATE_DISCONNECTED: - state = ( state | QNetworkConfiguration::Discovered ); - requestUpdate(); - break; - case NM_DEVICE_STATE_ACTIVATED: - { - state = ( state | QNetworkConfiguration::Discovered - | QNetworkConfiguration::Active ); - requestUpdate(); - } - break; - default: - state = ( QNetworkConfiguration::Defined); - break; - }; - } -} - -void QNmWifiEngine::addDevice(QDBusObjectPath path) -{ - //qWarning() << Q_FUNC_INFO << path.path(); - QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); - devIface->setConnections(); - connect(devIface,SIGNAL(stateChanged(const QString &, quint32)), - this, SLOT(updateDeviceInterfaceState(const QString&, quint32))); - - if(!devicePaths.contains(path.path())) - devicePaths << path.path(); - - switch(devIface->deviceType()) { - case DEVICE_TYPE_802_3_ETHERNET: - { - QNetworkManagerInterfaceDeviceWired * devWiredIface; - devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); - devWiredIface->setConnections(); - connect(devWiredIface, SIGNAL(propertiesChanged(const QString &,QMap)), - this,SLOT(cmpPropertiesChanged( const QString &, QMap))); - requestUpdate(); - } - break; - case DEVICE_TYPE_802_11_WIRELESS: - { - QNetworkManagerInterfaceDeviceWireless *devWirelessIface; - devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); - devWirelessIface->setConnections(); - - connect(devWirelessIface, SIGNAL(propertiesChanged(const QString &,QMap)), - this,SLOT(cmpPropertiesChanged( const QString &, QMap))); - - connect(devWirelessIface, SIGNAL(accessPointAdded(const QString &,QDBusObjectPath)), - this,SLOT(accessPointAdded(const QString &,QDBusObjectPath))); - - connect(devWirelessIface, SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath)), - this,SLOT(accessPointRemoved(const QString &,QDBusObjectPath))); - requestUpdate(); - - } - break; - default: - break; - }; -} - -void QNmWifiEngine::removeDevice(QDBusObjectPath /*path*/) -{ -// qWarning() << Q_FUNC_INFO << path.path(); -// disconnect(devIface,SIGNAL(stateChanged(const QString &, quint32)), -// this, SLOT(updateDeviceInterfaceState(const QString&, quint32))); -// -// if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { -// // devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); -// // devWirelessIface->setConnections(); -// -// disconnect(devWirelessIface, SIGNAL(propertiesChanged(const QString &,QMap)), -// this,SIGNAL(cmpPropertiesChanged( const QString &, QMap))); -// -// disconnect(devWirelessIface, SIGNAL(accessPointAdded(const QString &,QDBusObjectPath)), -// this,SIGNAL(accessPointAdded(const QString &,QDBusObjectPath))); -// -// disconnect(devWirelessIface, SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath)), -// this,SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath))); -// -// } -} -void QNmWifiEngine::cmpPropertiesChanged(const QString &path, QMap map) -{ - QMapIterator i(map); - while (i.hasNext()) { - i.next(); -// qWarning() << Q_FUNC_INFO << path << i.key() << i.value().toUInt(); - if( i.key() == "State") { //only applies to device interfaces - updateDeviceInterfaceState(path, i.value().toUInt()); - } - if( i.key() == "ActiveAccessPoint") { - } - if( i.key() == "Carrier") { //someone got plugged in - // requestUpdate(); - } - } -} - -void QNmWifiEngine::accessPointRemoved( const QString &aPath, QDBusObjectPath /*oPath*/) -{ - //qWarning() << Q_FUNC_INFO << aPath << oPath.path(); - - if(aPath.contains("devices")) { - requestUpdate(); - } -} - -void QNmWifiEngine::accessPointAdded( const QString &aPath, QDBusObjectPath oPath) -{ - //qWarning() << Q_FUNC_INFO << aPath << oPath.path(); - - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - cpPriv = addAccessPoint( aPath, oPath); - requestUpdate(); -} - -QNetworkConfiguration::StateFlags QNmWifiEngine::getStateForId(const QString &id) -{ - //qWarning() << Q_FUNC_INFO << id; - bool isAvailable = false; - QStringList conPath = getConnectionPathForId(id); - QString aconpath = getActiveConnectionPath(id); - - //qWarning() << Q_FUNC_INFO << id << aconpath; - - if(!aconpath.isEmpty()) { - //active connection - QNetworkManagerConnectionActive *aConn; - aConn = new QNetworkManagerConnectionActive(aconpath); - - QList devs = aConn->devices(); - - foreach(QDBusObjectPath dev, devs) { - //qWarning() << "foreach" << dev.path(); - QNetworkManagerInterfaceDevice *ifaceDevice; - ifaceDevice = new QNetworkManagerInterfaceDevice(dev.path()); - - if(ifaceDevice->deviceType() == DEVICE_TYPE_802_3_ETHERNET) { - - if(isAddressOfConnection(id, ifaceDevice->ip4Address())) { - // this is it! - return getStateFlag(ifaceDevice->state()); - } else { - continue; - } - - if(ifaceDevice->state() == NM_DEVICE_STATE_UNAVAILABLE || - ifaceDevice->state() == NM_DEVICE_STATE_DISCONNECTED) { - isAvailable = true; - - QNetworkManagerInterfaceDeviceWired *devWiredIface; - devWiredIface = new QNetworkManagerInterfaceDeviceWired(ifaceDevice->connectionInterface()->path()); - if(!devWiredIface->carrier()) - return QNetworkConfiguration::Defined; - } //end eth - } else if(ifaceDevice->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { - qWarning() << "FIXME!!!!!!!!!!!!!!!!!"; - } - - return getStateFlag(ifaceDevice->state()); - } - } else { - // not active - //qWarning() << Q_FUNC_INFO << "Not active"; - QNetworkManagerSettingsConnection *sysIface; - sysIface = new QNetworkManagerSettingsConnection(conPath.at(0),conPath.at(1)); - if(sysIface->isValid()) { - if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS) { - QString ssid = sysIface->getSsid(); - bool ok = false; - - if(knownSsids.contains(ssid, Qt::CaseSensitive)) { - foreach(QString onessid, knownSsids) { - // qWarning() << ssid << onessid; - if(onessid == ssid && availableAccessPoints.contains(ssid)) { - // qWarning() < devices = aConn->devices(); - foreach(QDBusObjectPath device, devices) { - QNetworkManagerInterfaceDevice *ifaceDevice; - ifaceDevice = new QNetworkManagerInterfaceDevice(device.path()); - if(ifaceDevice->ip4Address() == ipaddress) { - return true; - } - } - return false; -} - -QNetworkInterface QNmWifiEngine::getBestInterface( quint32 type, const QString &id) -{ - // check active connections first. - QStringList conIdPath = getConnectionPathForId(id); -// qWarning() << Q_FUNC_INFO << id << conIdPath; - - QNetworkInterface interface; - foreach(QString conpath, activeConnectionPaths) { - QNetworkManagerConnectionActive *aConn; - aConn = new QNetworkManagerConnectionActive(conpath); - - if(aConn->connection().path() == conIdPath.at(1) - && aConn->serviceName() == conIdPath.at(0)) { - - QList devs = aConn->devices(); - QNetworkManagerInterfaceDevice *ifaceDevice; - ifaceDevice = new QNetworkManagerInterfaceDevice(devs[0].path()); //just take the first one - interface = ifaceDevice->interface(); - return interface; - } - } - -//try guessing - QList list = iface->getDevices(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); - if(devIface->deviceType() == type /*&& devIface->managed()*/) { - interface = devIface->interface(); - if(devIface->state() == NM_STATE_DISCONNECTED) { - return interface; - } - } - } - return interface; -} - -quint64 QNmWifiEngine::receivedDataForId(const QString &id) const -{ - if(configurationInterface.count() > 1) - return 0; - quint64 result = 0; - - QString devFile; - devFile = configurationInterface.value(id); - QFile rx("/sys/class/net/"+devFile+"/statistics/rx_bytes"); - if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) { - QTextStream in(&rx); - in >> result; - rx.close(); - } - return result; -} - -quint64 QNmWifiEngine::sentDataForId(const QString &id) const -{ - if(configurationInterface.count() > 1) - return 0; - quint64 result = 0; - QString devFile; - devFile = configurationInterface.value(id); - - QFile tx("/sys/class/net/"+devFile+"/statistics/tx_bytes"); - if(tx.exists() && tx.open(QIODevice::ReadOnly | QIODevice::Text)) { - QTextStream in(&tx); - in >> result; - tx.close(); - } - return result; -} - -void QNmWifiEngine::newConnection(QDBusObjectPath /*path*/) -{ - //qWarning() << Q_FUNC_INFO; - requestUpdate(); -} - -void QNmWifiEngine::settingsConnectionRemoved(const QString &/*path*/) -{ - //qWarning() << Q_FUNC_INFO; - requestUpdate(); -} - -void QNmWifiEngine::slotActivationFinished(QDBusPendingCallWatcher *openCall) -{ - QDBusPendingReply reply = *openCall; - if (reply.isError()) { - qWarning() <<"Error" << reply.error().name() << reply.error().message() - < list = iface->getDevices(); - - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(path.path()); - - if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { - -// qWarning() << devIface->connectionInterface()->path(); - - QNetworkManagerInterfaceDeviceWireless *devWirelessIface; - devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); - ////////////// AccessPoints - QList apList = devWirelessIface->getAccessPoints(); - - foreach(QDBusObjectPath path, apList) { - QNetworkManagerInterfaceAccessPoint *accessPointIface; - accessPointIface = new QNetworkManagerInterfaceAccessPoint(path.path()); - QString ssid = accessPointIface->ssid(); - availableAccessPoints.insert(ssid, path); - } - } - } -} - -QString QNmWifiEngine::deviceConnectionPath(const QString &mac) -{ -// qWarning() << __FUNCTION__ << mac; - QString newMac = mac; - newMac = newMac.replace(":","_").toLower(); - //device object path might not contain just mac address - //might contain extra numbers on the end. thanks HAL - foreach(QString device, devicePaths) { - if(device.contains(newMac)) { - newMac = device; - break; - } - } - return newMac; -} - -QStringList QNmWifiEngine::getConnectionPathForId(const QString &uuid) -{ - QStringList connectionServices; - connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; - connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; -//qWarning() << Q_FUNC_INFO; - foreach (QString service, connectionServices) { - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(service); - QList list = settingsiface->listConnections(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerSettingsConnection *sysIface; - sysIface = new QNetworkManagerSettingsConnection(service, path.path()); -// qWarning() << uuid << sysIface->getUuid(); - if(sysIface->getUuid() == uuid) { -// qWarning() <<__FUNCTION__ << service << sysIface->getId() << sysIface->connectionInterface()->path(); - return QStringList() << service << sysIface->connectionInterface()->path(); - } - } - } - return QStringList(); -} - -#include "moc_qnmwifiengine_unix_p.cpp" - -QT_END_NAMESPACE - diff --git a/src/network/bearer/qnmwifiengine_unix_p.h b/src/network/bearer/qnmwifiengine_unix_p.h deleted file mode 100644 index 3af73ea..0000000 --- a/src/network/bearer/qnmwifiengine_unix_p.h +++ /dev/null @@ -1,164 +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 QNMWIFIENGINE_P_H -#define QNMWIFIENGINE_P_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 - -#include -#include -#include -#include - -#include "qnetworksessionengine_p.h" -#include -#include -#include - - - -QT_BEGIN_NAMESPACE - -class QNetworkConfigurationPrivate; - -class QNmWifiEngine : public QNetworkSessionEngine -{ - Q_OBJECT - -public: - QNmWifiEngine(QObject *parent = 0); - ~QNmWifiEngine(); - - QList getConfigurations(bool *ok = 0); - QString getInterfaceFromId(const QString &id); - bool hasIdentifier(const QString &id); - - QString bearerName(const QString &id); - - void connectToId(const QString &id); - void disconnectFromId(const QString &id); - - void requestUpdate(); - - static QNmWifiEngine *instance(); - - QStringList knownSsids; - inline void emitConfigurationsChanged() { emit configurationsChanged(); } - QNetworkConfigurationPrivate * addAccessPoint(const QString &, QDBusObjectPath ); - - QStringList getConnectionPathForId(const QString &uuid); - //QString getConnectionPathForId(const QString &name = QString()); - quint64 sentDataForId(const QString &id) const; - quint64 receivedDataForId(const QString &id) const; - -private: - bool updated; - QString activatingConnectionPath; - QStringList activeConnectionPaths; - - - QMap availableAccessPoints; - void scanForAccessPoints(); - - QStringList devicePaths; - - void getActiveConnectionsPaths(); - void getKnownSsids(); - void accessPointConnections(); - void knownConnections(); - void findConnections(); - QString deviceConnectionPath(const QString &mac); - - QList foundConfigurations; - // QHash > allConfigurations; - - QNetworkManagerInterface *iface; - - QNetworkConfiguration::StateFlags getAPState(qint32 vState, bool isKnown); - QNetworkConfiguration::StateFlags getStateFlag(quint32 nmstate); - - QString getActiveConnectionPath(const QString &identifier); - QString getNameForConfiguration(QNetworkManagerInterfaceDevice *devIface); - - QNetworkConfiguration::StateFlags getStateForId(const QString &id); - - QNetworkInterface getBestInterface(quint32 type, const QString &conPath); - - QMap configurationInterface; - - bool isAddressOfConnection(const QString &conPath, quint32 ipaddress); - -private slots: - void updateDeviceInterfaceState(const QString &, quint32); - void addDevice(QDBusObjectPath path); - void removeDevice(QDBusObjectPath path); - -Q_SIGNALS: - void configurationChanged(const QNetworkConfiguration& config); - void updateAccessPointState(const QString &, quint32); -// void slotActivationFinished(QDBusPendingCallWatcher*); - -private slots: - void accessPointAdded( const QString &aPath, QDBusObjectPath oPath); - void accessPointRemoved( const QString &aPath, QDBusObjectPath oPath); - void cmpPropertiesChanged(const QString &, QMap map); - void newConnection(QDBusObjectPath); - void settingsConnectionRemoved(const QString &); - void slotActivationFinished(QDBusPendingCallWatcher*); -}; - -QT_END_NAMESPACE - -#endif - - diff --git a/src/plugins/bearer/bearer.pro b/src/plugins/bearer/bearer.pro index 0e3ef48..60ba81b 100644 --- a/src/plugins/bearer/bearer.pro +++ b/src/plugins/bearer/bearer.pro @@ -1,3 +1,4 @@ TEMPLATE = subdirs SUBDIRS += generic +contains(QT_CONFIG, dbus):contains(QT_CONFIG, networkmanager):SUBDIRS += networkmanager diff --git a/src/plugins/bearer/networkmanager/main.cpp b/src/plugins/bearer/networkmanager/main.cpp new file mode 100644 index 0000000..c79fe91 --- /dev/null +++ b/src/plugins/bearer/networkmanager/main.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** 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 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 "qnmwifiengine.h" + +#include + +#include + +QT_BEGIN_NAMESPACE + +class QNetworkManagerEnginePlugin : public QBearerEnginePlugin +{ +public: + QNetworkManagerEnginePlugin(); + ~QNetworkManagerEnginePlugin(); + + QStringList keys() const; + QBearerEngine *create(const QString &key) const; +}; + +QNetworkManagerEnginePlugin::QNetworkManagerEnginePlugin() +{ +} + +QNetworkManagerEnginePlugin::~QNetworkManagerEnginePlugin() +{ +} + +QStringList QNetworkManagerEnginePlugin::keys() const +{ + qDebug() << Q_FUNC_INFO; + + return QStringList() << QLatin1String("networkmanager"); +} + +QBearerEngine *QNetworkManagerEnginePlugin::create(const QString &key) const +{ + qDebug() << Q_FUNC_INFO; + + if (key == QLatin1String("networkmanager")) + return new QNmWifiEngine; + else + return 0; +} + +Q_EXPORT_STATIC_PLUGIN(QNetworkManagerEnginePlugin) +Q_EXPORT_PLUGIN2(qnmbearer, QNetworkManagerEnginePlugin) + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/networkmanager/networkmanager.pro b/src/plugins/bearer/networkmanager/networkmanager.pro new file mode 100644 index 0000000..36d150a --- /dev/null +++ b/src/plugins/bearer/networkmanager/networkmanager.pro @@ -0,0 +1,19 @@ +TARGET = qnmbearer +include(../../qpluginbase.pri) + +QT += network dbus + +DEFINES += BEARER_ENGINE BACKEND_NM + +HEADERS += qnmdbushelper.h \ + qnetworkmanagerservice.h \ + qnmwifiengine.h + +SOURCES += main.cpp \ + qnmdbushelper.cpp \ + qnetworkmanagerservice.cpp \ + qnmwifiengine.cpp + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/bearer +target.path += $$[QT_INSTALL_PLUGINS]/bearer +INSTALLS += target diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp new file mode 100644 index 0000000..e95c2e6 --- /dev/null +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp @@ -0,0 +1,1009 @@ +/**************************************************************************** +** +** 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 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "qnmdbushelper.h" +#include "qnetworkmanagerservice.h" + +//Q_DECLARE_METATYPE(QList) +QT_BEGIN_NAMESPACE + +static QDBusConnection dbusConnection = QDBusConnection::systemBus(); +//static QDBusInterface iface(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, dbusConnection); + +class QNetworkManagerInterfacePrivate +{ +public: + QDBusInterface *connectionInterface; + bool valid; +}; + +QNetworkManagerInterface::QNetworkManagerInterface(QObject *parent) + : QObject(parent) +{ + d = new QNetworkManagerInterfacePrivate(); + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + dbusConnection); + if (!d->connectionInterface->isValid()) { + qWarning() << "Could not find NetworkManager"; + d->valid = false; + return; + } + d->valid = true; + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), + this,SIGNAL(propertiesChanged( const QString &, QMap))); + connect(nmDBusHelper,SIGNAL(pathForStateChanged(const QString &, quint32)), + this, SIGNAL(stateChanged(const QString&, quint32))); + +} + +QNetworkManagerInterface::~QNetworkManagerInterface() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerInterface::isValid() +{ + return d->valid; +} + +bool QNetworkManagerInterface::setConnections() +{ + if(!isValid() ) + return false; + bool allOk = false; + if (!dbusConnection.connect(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "PropertiesChanged", + nmDBusHelper,SLOT(slotPropertiesChanged( QMap)))) { + allOk = true; + } + if (!dbusConnection.connect(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "DeviceAdded", + this,SIGNAL(deviceAdded(QDBusObjectPath)))) { + allOk = true; + } + if (!dbusConnection.connect(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "DeviceRemoved", + this,SIGNAL(deviceRemoved(QDBusObjectPath)))) { + allOk = true; + } + + return allOk; +} + +QDBusInterface *QNetworkManagerInterface::connectionInterface() const +{ + return d->connectionInterface; +} + +QList QNetworkManagerInterface::getDevices() const +{ + QDBusReply > reply = d->connectionInterface->call("GetDevices"); + return reply.value(); +} + +void QNetworkManagerInterface::activateConnection( const QString &serviceName, + QDBusObjectPath connectionPath, + QDBusObjectPath devicePath, + QDBusObjectPath specificObject) +{ + QDBusPendingCall pendingCall = d->connectionInterface->asyncCall("ActivateConnection", + QVariant(serviceName), + QVariant::fromValue(connectionPath), + QVariant::fromValue(devicePath), + QVariant::fromValue(specificObject)); + + QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(pendingCall, this); + connect(callWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SIGNAL(activationFinished(QDBusPendingCallWatcher*))); +} + +void QNetworkManagerInterface::deactivateConnection(QDBusObjectPath connectionPath) const +{ + d->connectionInterface->call("DeactivateConnection", QVariant::fromValue(connectionPath)); +} + +bool QNetworkManagerInterface::wirelessEnabled() const +{ + return d->connectionInterface->property("WirelessEnabled").toBool(); +} + +bool QNetworkManagerInterface::wirelessHardwareEnabled() const +{ + return d->connectionInterface->property("WirelessHardwareEnabled").toBool(); +} + +QList QNetworkManagerInterface::activeConnections() const +{ + QVariant prop = d->connectionInterface->property("ActiveConnections"); + return prop.value >(); +} + +quint32 QNetworkManagerInterface::state() +{ + return d->connectionInterface->property("State").toUInt(); +} + +///////////// +class QNetworkManagerInterfaceAccessPointPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerInterfaceAccessPoint::QNetworkManagerInterfaceAccessPoint(const QString &dbusPathName, QObject *parent) + : QObject(parent) +{ + d = new QNetworkManagerInterfaceAccessPointPrivate(); + d->path = dbusPathName; + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_ACCESS_POINT, + dbusConnection); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find InterfaceAccessPoint"; + return; + } + d->valid = true; + +} + +QNetworkManagerInterfaceAccessPoint::~QNetworkManagerInterfaceAccessPoint() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerInterfaceAccessPoint::isValid() +{ + return d->valid; +} + +bool QNetworkManagerInterfaceAccessPoint::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), + this,SIGNAL(propertiesChanged( const QString &, QMap))); + + if(dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_ACCESS_POINT, + "PropertiesChanged", + nmDBusHelper,SLOT(slotPropertiesChanged( QMap))) ) { + allOk = true; + + } + return allOk; +} + +QDBusInterface *QNetworkManagerInterfaceAccessPoint::connectionInterface() const +{ + return d->connectionInterface; +} + +quint32 QNetworkManagerInterfaceAccessPoint::flags() const +{ + return d->connectionInterface->property("Flags").toUInt(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::wpaFlags() const +{ + return d->connectionInterface->property("WpaFlags").toUInt(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::rsnFlags() const +{ + return d->connectionInterface->property("RsnFlags").toUInt(); +} + +QString QNetworkManagerInterfaceAccessPoint::ssid() const +{ + return d->connectionInterface->property("Ssid").toString(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::frequency() const +{ + return d->connectionInterface->property("Frequency").toUInt(); +} + +QString QNetworkManagerInterfaceAccessPoint::hwAddress() const +{ + return d->connectionInterface->property("HwAddress").toString(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::mode() const +{ + return d->connectionInterface->property("Mode").toUInt(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::maxBitrate() const +{ + return d->connectionInterface->property("MaxBitrate").toUInt(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::strength() const +{ + return d->connectionInterface->property("Strength").toUInt(); +} + +///////////// +class QNetworkManagerInterfaceDevicePrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerInterfaceDevice::QNetworkManagerInterfaceDevice(const QString &deviceObjectPath, QObject *parent) + : QObject(parent) +{ + d = new QNetworkManagerInterfaceDevicePrivate(); + d->path = deviceObjectPath; + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE, + dbusConnection); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find NetworkManager"; + return; + } + d->valid = true; +} + +QNetworkManagerInterfaceDevice::~QNetworkManagerInterfaceDevice() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerInterfaceDevice::isValid() +{ + return d->valid; +} + +bool QNetworkManagerInterfaceDevice::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper,SIGNAL(pathForStateChanged(const QString &, quint32)), + this, SIGNAL(stateChanged(const QString&, quint32))); + if(dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE, + "StateChanged", + nmDBusHelper,SLOT(deviceStateChanged(quint32)))) { + allOk = true; + } + return allOk; +} + +QDBusInterface *QNetworkManagerInterfaceDevice::connectionInterface() const +{ + return d->connectionInterface; +} + +QString QNetworkManagerInterfaceDevice::udi() const +{ + return d->connectionInterface->property("Udi").toString(); +} + +QNetworkInterface QNetworkManagerInterfaceDevice::interface() const +{ + return QNetworkInterface::interfaceFromName(d->connectionInterface->property("Interface").toString()); +} + +quint32 QNetworkManagerInterfaceDevice::ip4Address() const +{ + return d->connectionInterface->property("Ip4Address").toUInt(); +} + +quint32 QNetworkManagerInterfaceDevice::state() const +{ + return d->connectionInterface->property("State").toUInt(); +} + +quint32 QNetworkManagerInterfaceDevice::deviceType() const +{ + return d->connectionInterface->property("DeviceType").toUInt(); +} + +QDBusObjectPath QNetworkManagerInterfaceDevice::ip4config() const +{ + QVariant prop = d->connectionInterface->property("Ip4Config"); + return prop.value(); +} + +///////////// +class QNetworkManagerInterfaceDeviceWiredPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerInterfaceDeviceWired::QNetworkManagerInterfaceDeviceWired(const QString &ifaceDevicePath, QObject *parent) +{ + d = new QNetworkManagerInterfaceDeviceWiredPrivate(); + d->path = ifaceDevicePath; + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE_WIRED, + dbusConnection, parent); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find InterfaceDeviceWired"; + return; + } + d->valid = true; +} + +QNetworkManagerInterfaceDeviceWired::~QNetworkManagerInterfaceDeviceWired() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerInterfaceDeviceWired::isValid() +{ + + return d->valid; +} + +bool QNetworkManagerInterfaceDeviceWired::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), + this,SIGNAL(propertiesChanged( const QString &, QMap))); + if(dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE_WIRED, + "PropertiesChanged", + nmDBusHelper,SLOT(slotPropertiesChanged( QMap))) ) { + allOk = true; + } + return allOk; +} + +QDBusInterface *QNetworkManagerInterfaceDeviceWired::connectionInterface() const +{ + return d->connectionInterface; +} + +QString QNetworkManagerInterfaceDeviceWired::hwAddress() const +{ + return d->connectionInterface->property("HwAddress").toString(); +} + +quint32 QNetworkManagerInterfaceDeviceWired::speed() const +{ + return d->connectionInterface->property("Speed").toUInt(); +} + +bool QNetworkManagerInterfaceDeviceWired::carrier() const +{ + return d->connectionInterface->property("Carrier").toBool(); +} + +///////////// +class QNetworkManagerInterfaceDeviceWirelessPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerInterfaceDeviceWireless::QNetworkManagerInterfaceDeviceWireless(const QString &ifaceDevicePath, QObject *parent) +{ + d = new QNetworkManagerInterfaceDeviceWirelessPrivate(); + d->path = ifaceDevicePath; + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE_WIRELESS, + dbusConnection, parent); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find InterfaceDeviceWireless"; + return; + } + d->valid = true; +} + +QNetworkManagerInterfaceDeviceWireless::~QNetworkManagerInterfaceDeviceWireless() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerInterfaceDeviceWireless::isValid() +{ + return d->valid; +} + +bool QNetworkManagerInterfaceDeviceWireless::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), + this,SIGNAL(propertiesChanged( const QString &, QMap))); + + connect(nmDBusHelper, SIGNAL(pathForAccessPointAdded(const QString &,QDBusObjectPath)), + this,SIGNAL(accessPointAdded(const QString &,QDBusObjectPath))); + + connect(nmDBusHelper, SIGNAL(pathForAccessPointRemoved(const QString &,QDBusObjectPath)), + this,SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath))); + + if(!dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE_WIRELESS, + "AccessPointAdded", + nmDBusHelper, SLOT(slotAccessPointAdded( QDBusObjectPath )))) { + allOk = true; + } + + + if(!dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE_WIRELESS, + "AccessPointRemoved", + nmDBusHelper, SLOT(slotAccessPointRemoved( QDBusObjectPath )))) { + allOk = true; + } + + + if(!dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE_WIRELESS, + "PropertiesChanged", + nmDBusHelper,SLOT(slotPropertiesChanged( QMap)))) { + allOk = true; + } + + return allOk; +} + +QDBusInterface *QNetworkManagerInterfaceDeviceWireless::connectionInterface() const +{ + return d->connectionInterface; +} + +QList QNetworkManagerInterfaceDeviceWireless::getAccessPoints() +{ + QDBusReply > reply = d->connectionInterface->call("GetAccessPoints"); + return reply.value(); +} + +QString QNetworkManagerInterfaceDeviceWireless::hwAddress() const +{ + return d->connectionInterface->property("HwAddress").toString(); +} + +quint32 QNetworkManagerInterfaceDeviceWireless::mode() const +{ + return d->connectionInterface->property("Mode").toUInt(); +} + +quint32 QNetworkManagerInterfaceDeviceWireless::bitrate() const +{ + return d->connectionInterface->property("Bitrate").toUInt(); +} + +QDBusObjectPath QNetworkManagerInterfaceDeviceWireless::activeAccessPoint() const +{ + return d->connectionInterface->property("ActiveAccessPoint").value(); +} + +quint32 QNetworkManagerInterfaceDeviceWireless::wirelessCapabilities() const +{ + return d->connectionInterface->property("WirelelessCapabilities").toUInt(); +} + +///////////// +class QNetworkManagerSettingsPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerSettings::QNetworkManagerSettings(const QString &settingsService, QObject *parent) + : QObject(parent) +{ +// qWarning() << __PRETTY_FUNCTION__; + d = new QNetworkManagerSettingsPrivate(); + d->path = settingsService; + d->connectionInterface = new QDBusInterface(settingsService, + NM_DBUS_PATH_SETTINGS, + NM_DBUS_IFACE_SETTINGS, + dbusConnection); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find NetworkManagerSettings"; + return; + } + d->valid = true; +} + +QNetworkManagerSettings::~QNetworkManagerSettings() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerSettings::isValid() +{ + return d->valid; +} + +bool QNetworkManagerSettings::setConnections() +{ + bool allOk = false; + + if (!dbusConnection.connect(d->path, NM_DBUS_PATH_SETTINGS, + NM_DBUS_IFACE_SETTINGS, "NewConnection", + this, SIGNAL(newConnection(QDBusObjectPath)))) { + allOk = true; + } + + return allOk; +} + +QList QNetworkManagerSettings::listConnections() +{ + QDBusReply > reply = d->connectionInterface->call("ListConnections"); + return reply.value(); +} + +QDBusInterface *QNetworkManagerSettings::connectionInterface() const +{ + return d->connectionInterface; +} + + +///////////// +class QNetworkManagerSettingsConnectionPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + QString service; + QNmSettingsMap settingsMap; + bool valid; +}; + +QNetworkManagerSettingsConnection::QNetworkManagerSettingsConnection(const QString &settingsService, const QString &connectionObjectPath, QObject *parent) +{ + qDBusRegisterMetaType(); + d = new QNetworkManagerSettingsConnectionPrivate(); + d->path = connectionObjectPath; + d->service = settingsService; + d->connectionInterface = new QDBusInterface(settingsService, + d->path, + NM_DBUS_IFACE_SETTINGS_CONNECTION, + dbusConnection, parent); + if (!d->connectionInterface->isValid()) { + qWarning() << "Could not find NetworkManagerSettingsConnection"; + d->valid = false; + return; + } + d->valid = true; + QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call("GetSettings"); + d->settingsMap = rep.value(); +} + +QNetworkManagerSettingsConnection::~QNetworkManagerSettingsConnection() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerSettingsConnection::isValid() +{ + return d->valid; +} + +bool QNetworkManagerSettingsConnection::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + if(!dbusConnection.connect(d->service, d->path, + NM_DBUS_IFACE_SETTINGS_CONNECTION, "NewConnection", + this, SIGNAL(updated(QNmSettingsMap)))) { + allOk = true; + } + + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper, SIGNAL(pathForSettingsRemoved(const QString &)), + this,SIGNAL(removed( const QString &))); + + if (!dbusConnection.connect(d->service, d->path, + NM_DBUS_IFACE_SETTINGS_CONNECTION, "Removed", + nmDBusHelper, SIGNAL(slotSettingsRemoved()))) { + allOk = true; + } + + return allOk; +} +//QNetworkManagerSettingsConnection::update(QNmSettingsMap map) +//{ +// d->connectionInterface->call("Update", QVariant::fromValue(map)); +//} + +QDBusInterface *QNetworkManagerSettingsConnection::connectionInterface() const +{ + return d->connectionInterface; +} + +QNmSettingsMap QNetworkManagerSettingsConnection::getSettings() +{ + QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call("GetSettings"); + d->settingsMap = rep.value(); + return d->settingsMap; +} + +NMDeviceType QNetworkManagerSettingsConnection::getType() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); + while (i != d->settingsMap.end() && i.key() == "connection") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("type"); + while (ii != innerMap.end() && ii.key() == "type") { + QString devType = ii.value().toString(); + if (devType == "802-3-ethernet") { + return DEVICE_TYPE_802_3_ETHERNET; + } + if (devType == "802-11-wireless") { + return DEVICE_TYPE_802_11_WIRELESS; + } + ii++; + } + i++; + } + return DEVICE_TYPE_UNKNOWN; +} + +bool QNetworkManagerSettingsConnection::isAutoConnect() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); + while (i != d->settingsMap.end() && i.key() == "connection") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("autoconnect"); + while (ii != innerMap.end() && ii.key() == "autoconnect") { + return ii.value().toBool(); + ii++; + } + i++; + } + return true; //default networkmanager is autoconnect +} + +quint64 QNetworkManagerSettingsConnection::getTimestamp() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); + while (i != d->settingsMap.end() && i.key() == "connection") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("timestamp"); + while (ii != innerMap.end() && ii.key() == "timestamp") { + return ii.value().toUInt(); + ii++; + } + i++; + } + return 0; +} + +QString QNetworkManagerSettingsConnection::getId() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); + while (i != d->settingsMap.end() && i.key() == "connection") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("id"); + while (ii != innerMap.end() && ii.key() == "id") { + return ii.value().toString(); + ii++; + } + i++; + } + return QString(); +} + +QString QNetworkManagerSettingsConnection::getUuid() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); + while (i != d->settingsMap.end() && i.key() == "connection") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("uuid"); + while (ii != innerMap.end() && ii.key() == "uuid") { + return ii.value().toString(); + ii++; + } + i++; + } + // is no uuid, return the connection path + return d->connectionInterface->path(); +} + +QString QNetworkManagerSettingsConnection::getSsid() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find("802-11-wireless"); + while (i != d->settingsMap.end() && i.key() == "802-11-wireless") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("ssid"); + while (ii != innerMap.end() && ii.key() == "ssid") { + return ii.value().toString(); + ii++; + } + i++; + } + return QString(); +} + +QString QNetworkManagerSettingsConnection::getMacAddress() +{ + if(getType() == DEVICE_TYPE_802_3_ETHERNET) { + QNmSettingsMap::const_iterator i = d->settingsMap.find("802-3-ethernet"); + while (i != d->settingsMap.end() && i.key() == "802-3-ethernet") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("mac-address"); + while (ii != innerMap.end() && ii.key() == "mac-address") { + return ii.value().toString(); + ii++; + } + i++; + } + } + + else if(getType() == DEVICE_TYPE_802_11_WIRELESS) { + QNmSettingsMap::const_iterator i = d->settingsMap.find("802-11-wireless"); + while (i != d->settingsMap.end() && i.key() == "802-11-wireless") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("mac-address"); + while (ii != innerMap.end() && ii.key() == "mac-address") { + return ii.value().toString(); + ii++; + } + i++; + } + } + return QString(); +} + +QStringList QNetworkManagerSettingsConnection::getSeenBssids() +{ + if(getType() == DEVICE_TYPE_802_11_WIRELESS) { + QNmSettingsMap::const_iterator i = d->settingsMap.find("802-11-wireless"); + while (i != d->settingsMap.end() && i.key() == "802-11-wireless") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("seen-bssids"); + while (ii != innerMap.end() && ii.key() == "seen-bssids") { + return ii.value().toStringList(); + ii++; + } + i++; + } + } + return QStringList(); +} + +///////////// +class QNetworkManagerConnectionActivePrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerConnectionActive::QNetworkManagerConnectionActive( const QString &activeConnectionObjectPath, QObject *parent) +{ + d = new QNetworkManagerConnectionActivePrivate(); + d->path = activeConnectionObjectPath; + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + dbusConnection, parent); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find NetworkManagerSettingsConnection"; + return; + } + d->valid = true; +} + +QNetworkManagerConnectionActive::~QNetworkManagerConnectionActive() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerConnectionActive::isValid() +{ + return d->valid; +} + +bool QNetworkManagerConnectionActive::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), + this,SIGNAL(propertiesChanged( const QString &, QMap))); + if(dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + "PropertiesChanged", + nmDBusHelper,SLOT(slotPropertiesChanged( QMap))) ) { + allOk = true; + } + + return allOk; +} + +QDBusInterface *QNetworkManagerConnectionActive::connectionInterface() const +{ + return d->connectionInterface; +} + +QString QNetworkManagerConnectionActive::serviceName() const +{ + return d->connectionInterface->property("ServiceName").toString(); +} + +QDBusObjectPath QNetworkManagerConnectionActive::connection() const +{ + QVariant prop = d->connectionInterface->property("Connection"); + return prop.value(); +} + +QDBusObjectPath QNetworkManagerConnectionActive::specificObject() const +{ + QVariant prop = d->connectionInterface->property("SpecificObject"); + return prop.value(); +} + +QList QNetworkManagerConnectionActive::devices() const +{ + QVariant prop = d->connectionInterface->property("Devices"); + return prop.value >(); +} + +quint32 QNetworkManagerConnectionActive::state() const +{ + return d->connectionInterface->property("State").toUInt(); +} + +bool QNetworkManagerConnectionActive::defaultRoute() const +{ + return d->connectionInterface->property("Default").toBool(); +} + + +//// +class QNetworkManagerIp4ConfigPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerIp4Config::QNetworkManagerIp4Config( const QString &deviceObjectPath, QObject *parent) +{ + d = new QNetworkManagerIp4ConfigPrivate(); + d->path = deviceObjectPath; + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_IP4_CONFIG, + dbusConnection, parent); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find NetworkManagerIp4Config"; + return; + } + d->valid = true; +} + +QNetworkManagerIp4Config::~QNetworkManagerIp4Config() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerIp4Config::isValid() +{ + return d->valid; +} + +QStringList QNetworkManagerIp4Config::domains() const +{ + return d->connectionInterface->property("Domains").toStringList(); +} + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h new file mode 100644 index 0000000..8bed45b --- /dev/null +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h @@ -0,0 +1,397 @@ +/**************************************************************************** +** +** 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 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 QNETWORKMANAGERSERVICE_H +#define QNETWORKMANAGERSERVICE_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 +#include +#include +#include +#include +#include +#include +#include + + +#include +#include "qnmdbushelper.h" + +QT_BEGIN_NAMESPACE + +typedef QMap< QString, QMap > QNmSettingsMap; +typedef QList ServerThing; + +Q_DECLARE_METATYPE(QNmSettingsMap) +Q_DECLARE_METATYPE(ServerThing) + +class QNetworkManagerInterfacePrivate; +class QNetworkManagerInterface : public QObject +{ + Q_OBJECT + +public: + + QNetworkManagerInterface(QObject *parent = 0); + ~QNetworkManagerInterface(); + + QList getDevices() const; + void activateConnection(const QString &serviceName, QDBusObjectPath connection, QDBusObjectPath device, QDBusObjectPath specificObject); + void deactivateConnection(QDBusObjectPath connectionPath) const; + + QDBusObjectPath path() const; + QDBusInterface *connectionInterface() const; + + bool wirelessEnabled() const; + bool wirelessHardwareEnabled() const; + QList activeConnections() const; + quint32 state(); + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void deviceAdded(QDBusObjectPath); + void deviceRemoved(QDBusObjectPath); + void propertiesChanged( const QString &, QMap); + void stateChanged(const QString&, quint32); + void activationFinished(QDBusPendingCallWatcher*); + +private Q_SLOTS: +private: +// Q_DISABLE_COPY(QNetworkManagerInterface); ?? + QNetworkManagerInterfacePrivate *d; + QNmDBusHelper *nmDBusHelper; +}; //end QNetworkManagerInterface + +//////// +class QNetworkManagerInterfaceAccessPointPrivate; +class QNetworkManagerInterfaceAccessPoint : public QObject +{ + Q_OBJECT + +public: + + // NM_DEVICE_STATE + enum DeviceState { + Unknown = 0, + Unmanaged, + Unavailable, + Disconnected, + Prepare, + Config, + NeedAuthentication, + IpConfig, + Activated, + Failed + }; + + enum ApFlag { + ApNone = 0x0, + Privacy = 0x1 + }; + + Q_DECLARE_FLAGS(ApFlags, ApFlag); + + enum ApSecurityFlag { + ApSecurityNone = 0x0, + PairWep40 = 0x1, + PairWep104 = 0x2, + PairTkip = 0x4, + PairCcmp = 0x8, + GroupWep40 = 0x10, + GroupWep104 = 0x20, + GroupTkip = 0x40, + GroupCcmp = 0x80, + KeyPsk = 0x100, + Key8021x = 0x200 + }; + + Q_DECLARE_FLAGS(ApSecurityFlags, ApSecurityFlag); + + QNetworkManagerInterfaceAccessPoint(const QString &dbusPathName, QObject *parent = 0); + ~QNetworkManagerInterfaceAccessPoint(); + + QDBusInterface *connectionInterface() const; + + quint32 flags() const; + quint32 wpaFlags() const; + quint32 rsnFlags() const; + QString ssid() const; + quint32 frequency() const; + QString hwAddress() const; + quint32 mode() const; + quint32 maxBitrate() const; + quint32 strength() const; + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void propertiesChanged(QMap ); + void propertiesChanged( const QString &, QMap); +private: + QNetworkManagerInterfaceAccessPointPrivate *d; + QNmDBusHelper *nmDBusHelper; + +}; //end QNetworkManagerInterfaceAccessPoint + +//////// +class QNetworkManagerInterfaceDevicePrivate; +class QNetworkManagerInterfaceDevice : public QObject +{ + Q_OBJECT + +public: + + QNetworkManagerInterfaceDevice(const QString &deviceObjectPath, QObject *parent = 0); + ~QNetworkManagerInterfaceDevice(); + + QString udi() const; + QNetworkInterface interface() const; + QDBusInterface *connectionInterface() const; + quint32 ip4Address() const; + quint32 state() const; + quint32 deviceType() const; + + QDBusObjectPath ip4config() const; + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void stateChanged(const QString &, quint32); + +private: + QNetworkManagerInterfaceDevicePrivate *d; + QNmDBusHelper *nmDBusHelper; +}; //end QNetworkManagerInterfaceDevice + +//////// +class QNetworkManagerInterfaceDeviceWiredPrivate; +class QNetworkManagerInterfaceDeviceWired : public QObject +{ + Q_OBJECT + +public: + + QNetworkManagerInterfaceDeviceWired(const QString &ifaceDevicePath, QObject *parent = 0); + ~QNetworkManagerInterfaceDeviceWired(); + + QDBusInterface *connectionInterface() const; + QString hwAddress() const; + quint32 speed() const; + bool carrier() const; + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void propertiesChanged( const QString &, QMap); +private: + QNetworkManagerInterfaceDeviceWiredPrivate *d; + QNmDBusHelper *nmDBusHelper; +}; // end QNetworkManagerInterfaceDeviceWired + +//// +class QNetworkManagerInterfaceDeviceWirelessPrivate; +class QNetworkManagerInterfaceDeviceWireless : public QObject +{ + Q_OBJECT + +public: + + enum DeviceCapability { + None = 0x0, + Wep40 = 0x1, + Wep104 = 0x2, + Tkip = 0x4, + Ccmp = 0x8, + Wpa = 0x10, + Rsn = 0x20 + }; + + QNetworkManagerInterfaceDeviceWireless(const QString &ifaceDevicePath, QObject *parent = 0); + ~QNetworkManagerInterfaceDeviceWireless(); + + QDBusObjectPath path() const; + QList getAccessPoints(); + QDBusInterface *connectionInterface() const; + + QString hwAddress() const; + quint32 mode() const; + quint32 bitrate() const; + QDBusObjectPath activeAccessPoint() const; + quint32 wirelessCapabilities() const; + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void propertiesChanged( const QString &, QMap); + void accessPointAdded(const QString &,QDBusObjectPath); + void accessPointRemoved(const QString &,QDBusObjectPath); +private: + QNetworkManagerInterfaceDeviceWirelessPrivate *d; + QNmDBusHelper *nmDBusHelper; +}; // end QNetworkManagerInterfaceDeviceWireless + +//// +class QNetworkManagerSettingsPrivate; +class QNetworkManagerSettings : public QObject +{ + Q_OBJECT + +public: + + QNetworkManagerSettings(const QString &settingsService, QObject *parent = 0); + ~QNetworkManagerSettings(); + + QDBusInterface *connectionInterface() const; + QList listConnections(); + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void newConnection(QDBusObjectPath); +private: + QNetworkManagerSettingsPrivate *d; +}; //end QNetworkManagerSettings + +//// +class QNetworkManagerSettingsConnectionPrivate; +class QNetworkManagerSettingsConnection : public QObject +{ + Q_OBJECT + +public: + + QNetworkManagerSettingsConnection(const QString &settingsService, const QString &connectionObjectPath, QObject *parent = 0); + ~QNetworkManagerSettingsConnection(); + + QDBusInterface *connectionInterface() const; + QNmSettingsMap getSettings(); + // void update(QNmSettingsMap map); + bool setConnections(); + NMDeviceType getType(); + bool isAutoConnect(); + quint64 getTimestamp(); + QString getId(); + QString getUuid(); + QString getSsid(); + QString getMacAddress(); + QStringList getSeenBssids(); + bool isValid(); + +Q_SIGNALS: + + void updated(QMap< QString, QMap > s); + void removed(const QString &); + +private: + QNmDBusHelper *nmDBusHelper; + QNetworkManagerSettingsConnectionPrivate *d; +}; //end QNetworkManagerSettingsConnection + +//// +class QNetworkManagerConnectionActivePrivate; +class QNetworkManagerConnectionActive : public QObject +{ + Q_OBJECT + +public: + + enum ActiveConnectionState { + Unknown = 0, + Activating = 1, + Activated = 2 + }; + + QNetworkManagerConnectionActive(const QString &dbusPathName, QObject *parent = 0); + ~ QNetworkManagerConnectionActive(); + + QDBusInterface *connectionInterface() const; + QString serviceName() const; + QDBusObjectPath connection() const; + QDBusObjectPath specificObject() const; + QList devices() const; + quint32 state() const; + bool defaultRoute() const; + bool setConnections(); + bool isValid(); + + +Q_SIGNALS: + void propertiesChanged(QList); + void propertiesChanged( const QString &, QMap); +private: + QNetworkManagerConnectionActivePrivate *d; + QNmDBusHelper *nmDBusHelper; +}; //QNetworkManagerConnectionActive + +//// +class QNetworkManagerIp4ConfigPrivate; +class QNetworkManagerIp4Config : public QObject +{ + Q_OBJECT + +public: + QNetworkManagerIp4Config(const QString &dbusPathName, QObject *parent = 0); + ~QNetworkManagerIp4Config(); + + // QList nameservers(); + QStringList domains() const; + bool isValid(); + + private: + QNetworkManagerIp4ConfigPrivate *d; +}; +//// + +QT_END_NAMESPACE + +#endif //QNETWORKMANAGERSERVICE_H diff --git a/src/plugins/bearer/networkmanager/qnmdbushelper.cpp b/src/plugins/bearer/networkmanager/qnmdbushelper.cpp new file mode 100644 index 0000000..1d16e55 --- /dev/null +++ b/src/plugins/bearer/networkmanager/qnmdbushelper.cpp @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** 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 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$ +** +****************************************************************************/ + +// this class is for helping qdbus get stuff + +#include "qnmdbushelper.h" + +#include + +#include +#include +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +void QNmDBusHelper::deviceStateChanged(quint32 state) + { + QDBusMessage msg = this->message(); + if(state == NM_DEVICE_STATE_ACTIVATED + || state == NM_DEVICE_STATE_DISCONNECTED + || state == NM_DEVICE_STATE_UNAVAILABLE + || state == NM_DEVICE_STATE_FAILED) { + emit pathForStateChanged(msg.path(), state); + } + } + +void QNmDBusHelper::slotAccessPointAdded(QDBusObjectPath path) +{ + if(path.path().length() > 2) { + QDBusMessage msg = this->message(); + emit pathForAccessPointAdded(msg.path(), path); + } +} + +void QNmDBusHelper::slotAccessPointRemoved(QDBusObjectPath path) +{ + if(path.path().length() > 2) { + QDBusMessage msg = this->message(); + emit pathForAccessPointRemoved(msg.path(), path); + } +} + +void QNmDBusHelper::slotPropertiesChanged(QMap map) +{ + QDBusMessage msg = this->message(); + QMapIterator i(map); + while (i.hasNext()) { + i.next(); + if( i.key() == "State") { //state only applies to device interfaces + quint32 state = i.value().toUInt(); + if( state == NM_DEVICE_STATE_ACTIVATED + || state == NM_DEVICE_STATE_DISCONNECTED + || state == NM_DEVICE_STATE_UNAVAILABLE + || state == NM_DEVICE_STATE_FAILED) { + emit pathForPropertiesChanged( msg.path(), map); + } + } else if( i.key() == "ActiveAccessPoint") { + // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value().value().path(); + // } else if( i.key() == "Strength") + // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value().toUInt(); + // else + // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value(); + } + } +} + +void QNmDBusHelper::slotSettingsRemoved() +{ + QDBusMessage msg = this->message(); + emit pathForSettingsRemoved(msg.path()); +} + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/networkmanager/qnmdbushelper.h b/src/plugins/bearer/networkmanager/qnmdbushelper.h new file mode 100644 index 0000000..9794f98 --- /dev/null +++ b/src/plugins/bearer/networkmanager/qnmdbushelper.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** 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 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 QNMDBUSHELPERPRIVATE_H +#define QNMDBUSHELPERPRIVATE_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 +#include +#include + +QT_BEGIN_NAMESPACE + +#if !defined(QT_NO_DBUS) && !defined(Q_OS_MAC) + +class QNmDBusHelper: public QObject, protected QDBusContext + { + Q_OBJECT + public: + + public slots: + void deviceStateChanged(quint32); + void slotAccessPointAdded( QDBusObjectPath ); + void slotAccessPointRemoved( QDBusObjectPath ); + void slotPropertiesChanged( QMap); + void slotSettingsRemoved(); + +Q_SIGNALS: + void pathForStateChanged(const QString &, quint32); + void pathForAccessPointAdded(const QString &, QDBusObjectPath ); + void pathForAccessPointRemoved(const QString &, QDBusObjectPath ); + void pathForPropertiesChanged(const QString &, QMap); + void pathForSettingsRemoved(const QString &); +}; +#endif + +QT_END_NAMESPACE + +#endif// QNMDBUSHELPERPRIVATE_H diff --git a/src/plugins/bearer/networkmanager/qnmwifiengine.cpp b/src/plugins/bearer/networkmanager/qnmwifiengine.cpp new file mode 100644 index 0000000..4a814ec --- /dev/null +++ b/src/plugins/bearer/networkmanager/qnmwifiengine.cpp @@ -0,0 +1,1128 @@ +/**************************************************************************** +** +** 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 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 "qnmwifiengine.h" + +#include +#include + +#include + +#include +#include +#include "qnetworkmanagerservice.h" + +#include + +QT_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC(QNmWifiEngine, nmWifiEngine) +typedef QList > QNmSettingsAddressMap; + +Q_DECLARE_METATYPE(QNmSettingsAddressMap) + +QNmWifiEngine::QNmWifiEngine(QObject *parent) +: QNetworkSessionEngine(parent) +{ + iface = new QNetworkManagerInterface(); + if(!iface->isValid()) { + return; + } + iface->setConnections(); + connect(iface,SIGNAL(deviceAdded(QDBusObjectPath)), + this,SLOT(addDevice(QDBusObjectPath))); + connect(iface,SIGNAL(deviceRemoved(QDBusObjectPath)), + this,SLOT(removeDevice(QDBusObjectPath))); + + QList list = iface->getDevices(); + + foreach(QDBusObjectPath path, list) { + addDevice(path); + } + + QStringList connectionServices; + connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; + connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; + foreach (QString service, connectionServices) { + QNetworkManagerSettings *settingsiface; + settingsiface = new QNetworkManagerSettings(service); + settingsiface->setConnections(); + connect(settingsiface,SIGNAL(newConnection(QDBusObjectPath)), + this,(SLOT(newConnection(QDBusObjectPath)))); + } + + updated = false; +} + +QNmWifiEngine::~QNmWifiEngine() +{ +} + +QString QNmWifiEngine::getNameForConfiguration(QNetworkManagerInterfaceDevice *devIface) +{ + QString newname; + if (devIface->state() == NM_DEVICE_STATE_ACTIVATED) { + QString path = devIface->ip4config().path(); + QNetworkManagerIp4Config * ipIface; + ipIface = new QNetworkManagerIp4Config(path); + newname = ipIface->domains().join(" "); + } + //fallback to interface name + if(newname.isEmpty()) + newname = devIface->interface().name(); + return newname; +} + + +QList QNmWifiEngine::getConfigurations(bool *ok) +{ +// qWarning() << Q_FUNC_INFO << updated; + if (ok) + *ok = false; + + if(!updated) { + foundConfigurations.clear(); + if(knownSsids.isEmpty()) + getKnownSsids(); // list of ssids that have user configurations. + + scanForAccessPoints(); + getActiveConnectionsPaths(); + knownConnections(); + + accessPointConnections(); + +// findConnections(); + //add access points + updated = true; + } + return foundConfigurations; +} + +void QNmWifiEngine::findConnections() +{ + QList list = iface->getDevices(); + + foreach(QDBusObjectPath path, list) { + QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); + + //// eth + switch (devIface->deviceType()) { +// qWarning() << devIface->connectionInterface()->path(); + + case DEVICE_TYPE_802_3_ETHERNET: + { + QString ident; + QNetworkManagerInterfaceDeviceWired *devWiredIface; + devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); + + ident = devWiredIface->hwAddress(); + + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + cpPriv->name = getNameForConfiguration(devIface); + cpPriv->isValid = true; + cpPriv->id = ident; + cpPriv->internet = devWiredIface->carrier(); + + cpPriv->serviceInterface = devIface->interface(); + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + switch (devIface->state()) { + case NM_DEVICE_STATE_UNKNOWN: + case NM_DEVICE_STATE_UNMANAGED: + case NM_DEVICE_STATE_FAILED: + cpPriv->state = (cpPriv->state | QNetworkConfiguration::Undefined); + break; + case NM_DEVICE_STATE_UNAVAILABLE: + cpPriv->state = (cpPriv->state | QNetworkConfiguration::Defined); + break; + case NM_DEVICE_STATE_PREPARE: + case NM_DEVICE_STATE_CONFIG: + case NM_DEVICE_STATE_NEED_AUTH: + case NM_DEVICE_STATE_IP_CONFIG: + case NM_DEVICE_STATE_DISCONNECTED: + { + cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Discovered + | QNetworkConfiguration::Defined); + } + break; + case NM_DEVICE_STATE_ACTIVATED: + cpPriv->state = (cpPriv->state | QNetworkConfiguration::Active ); + break; + default: + cpPriv->state = (cpPriv->state | QNetworkConfiguration::Undefined); + break; + }; + cpPriv->purpose = QNetworkConfiguration::PublicPurpose; + foundConfigurations.append(cpPriv); + configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); + } + break; + case DEVICE_TYPE_802_11_WIRELESS: + { +// QNetworkManagerInterfaceDeviceWireless *devWirelessIface; +// devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); +// +// //// connections +// QStringList connectionServices; +// connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; +// connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; +// +// QString connPath; +// +// foreach (QString service, connectionServices) { +// QString ident; +// QNetworkManagerSettings *settingsiface; +// settingsiface = new QNetworkManagerSettings(service); +// QList list = settingsiface->listConnections(); +// +// foreach(QDBusObjectPath path, list) { //for each connection path +//qWarning() << path.path(); +// ident = path.path(); +// bool addIt = false; +// QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); +// cpPriv->isValid = true; +// cpPriv->id = ident; +// cpPriv->internet = true; +// +// cpPriv->type = QNetworkConfiguration::InternetAccessPoint; +// cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Discovered +// | QNetworkConfiguration::Defined); +// cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; +// +// QNetworkManagerSettingsConnection *sysIface; +// sysIface = new QNetworkManagerSettingsConnection(service, path.path()); +// cpPriv->name = sysIface->getId();//ii.value().toString(); +//qWarning() << cpPriv->name; +// if(sysIface->getType() == DEVICE_TYPE_802_3_ETHERNET/*type == "802-3-ethernet"*/ +// && devIface->deviceType() == DEVICE_TYPE_802_3_ETHERNET) { +// cpPriv->serviceInterface = devIface->interface(); +// addIt = true; +// } else if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS/*type == "802-11-wireless"*/ +// && devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { +// cpPriv->serviceInterface = devIface->interface(); +// addIt = true; +// // get the wifi interface state first.. do we need this? +// // QString activeAPPath = devWirelessIface->activeAccessPoint().path(); +// } +// +// //#if 0 +// foreach(QString conpath, activeConnectionPaths) { +// QNetworkManagerConnectionActive *aConn; +// aConn = new QNetworkManagerConnectionActive(conpath); +// // in case of accesspoint, specificObject will hold the accessPOintObjectPath +// // qWarning() << aConn->connection().path() << aConn->specificObject().path() << aConn->devices().count(); +// if( aConn->connection().path() == ident) { +// +// QList devs = aConn->devices(); +// foreach(QDBusObjectPath device, devs) { +// QNetworkManagerInterfaceDevice *ifaceDevice; +// ifaceDevice = new QNetworkManagerInterfaceDevice(device.path()); +// cpPriv->serviceInterface = ifaceDevice->interface(); +// cpPriv->state = getStateFlag(ifaceDevice->state()); +// //cpPriv->accessPoint = aConn->specificObject().path(); +// +// break; +// } +// } +// } +// //#endif +// // } //end while connection +// if(addIt) { +// foundConfigurations.append(cpPriv); +// configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); +// } +// } +// } //end each connection service +// +// // ////////////// AccessPoints +//// QList apList = devWirelessIface->getAccessPoints(); +////// qWarning() << apList.count(); +//// foreach(QDBusObjectPath path, apList) { +//// QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); +//// cpPriv = addAccessPoint( devIface->connectionInterface()->path(), path); +//// if(cpPriv->isValid) { +//// foundConfigurations.append(cpPriv); +//// } +//// } + } // end DEVICE_TYPE_802_11_WIRELESS + break; + }; + } //end foreach device +} + +void QNmWifiEngine::knownConnections() +{ +// qWarning() << Q_FUNC_INFO; + //// connections + QStringList connectionServices; + connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; + connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; + + QString connPath; + + foreach (QString service, connectionServices) { + QString ident; + QNetworkManagerSettings *settingsiface; + settingsiface = new QNetworkManagerSettings(service); + QList list = settingsiface->listConnections(); + +// qWarning() <setConnections(); + connect(sysIface, SIGNAL(removed(QString)), + this,SLOT(settingsConnectionRemoved(QString))); + + cpPriv->name = sysIface->getId(); + cpPriv->isValid = true; + cpPriv->id = sysIface->getUuid(); +// cpPriv->id = ident; + cpPriv->internet = true; + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; +//qWarning() << cpPriv->name; + cpPriv->state = getStateForId(cpPriv->id); + + cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; + + if(sysIface->getType() == DEVICE_TYPE_802_3_ETHERNET) { + QString mac = sysIface->getMacAddress(); + if(!mac.length() > 2) { + qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXX" << mac << "type ethernet"; + QString devPath; + devPath = deviceConnectionPath(mac); + + // qWarning() << Q_FUNC_INFO << devPath; + QNetworkManagerInterfaceDevice *devIface; + devIface = new QNetworkManagerInterfaceDevice(devPath); + cpPriv->serviceInterface = devIface->interface(); + QNetworkManagerInterfaceDeviceWired *devWiredIface; + devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); + cpPriv->internet = devWiredIface->carrier(); + + // use this mac addy + } else { + cpPriv->serviceInterface = getBestInterface( DEVICE_TYPE_802_3_ETHERNET, cpPriv->id); + } + + cpPriv->internet = true;//sysIface->isAutoConnect(); + + addIt = true; + } else if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS) { + QString mac = sysIface->getMacAddress();; + if(!mac.length() > 2) { + qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXX" << mac << "type wireless"; + QString devPath; + devPath = deviceConnectionPath(mac); +// qWarning() << Q_FUNC_INFO << devPath; + + QNetworkManagerInterfaceDevice *devIface; + devIface = new QNetworkManagerInterfaceDevice(devPath); + cpPriv->serviceInterface = devIface->interface(); + // use this mac addy + } else { + cpPriv->serviceInterface = getBestInterface( DEVICE_TYPE_802_11_WIRELESS, cpPriv->id); + } + // cpPriv->serviceInterface = devIface->interface(); + addIt = true; + // get the wifi interface state first.. do we need this? + // QString activeAPPath = devWirelessIface->activeAccessPoint().path(); + } + if(addIt) { + foundConfigurations.append(cpPriv); + configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); + } + } //end each connection service + } +} + +void QNmWifiEngine::accessPointConnections() +{ + //qWarning() << Q_FUNC_INFO; + QList list = iface->getDevices(); + foreach(QDBusObjectPath path, list) { + QNetworkManagerInterfaceDevice *devIface; + devIface = new QNetworkManagerInterfaceDevice(path.path()); + if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { + QList apList = availableAccessPoints.uniqueKeys(); + + QList::const_iterator i; + for (i = apList.constBegin(); i != apList.constEnd(); ++i) { + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + cpPriv = addAccessPoint( devIface->connectionInterface()->path(), availableAccessPoints[*i]); + if(cpPriv->isValid) { + foundConfigurations.append(cpPriv); + // qWarning() << "adding" << cpPriv->name << "to things"; + configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); + } + } + } + } +} + +QString QNmWifiEngine::getInterfaceFromId(const QString &id) +{ + return configurationInterface.value(id); +} + +bool QNmWifiEngine::hasIdentifier(const QString &id) +{ + if (configurationInterface.contains(id)) + return true; + foreach (QNetworkConfigurationPrivate *cpPriv, getConfigurations()) { + if (cpPriv->id == id) + return true; + } + return false; +} + +QString QNmWifiEngine::bearerName(const QString &id) +{ + QString interface = getInterfaceFromId(id); + + QList list = iface->getDevices(); + foreach(QDBusObjectPath path, list) { + QNetworkManagerInterfaceDevice *devIface; + devIface = new QNetworkManagerInterfaceDevice(path.path()); + if(interface == devIface->interface().name()) { + switch(devIface->deviceType()) { + case DEVICE_TYPE_802_3_ETHERNET/*NM_DEVICE_TYPE_ETHERNET*/: + return QLatin1String("Ethernet"); + break; + case DEVICE_TYPE_802_11_WIRELESS/*NM_DEVICE_TYPE_WIFI*/: + return QLatin1String("WLAN"); + break; + case DEVICE_TYPE_GSM/*NM_DEVICE_TYPE_GSM*/: + return QLatin1String("2G"); + break; + case DEVICE_TYPE_CDMA/*NM_DEVICE_TYPE_CDMA*/: + return QLatin1String("CDMA2000"); + break; + default: + break; + }; + } + } + return QString(); +} + +void QNmWifiEngine::connectToId(const QString &id) +{ +// qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << __FUNCTION__ << id; + activatingConnectionPath = id; + QStringList connectionSettings = getConnectionPathForId(id); + if(connectionSettings.isEmpty()) { + emit connectionError(id, OperationNotSupported); + return; + } + + QDBusObjectPath connectionPath(connectionSettings.at(1)); + QString interface = getInterfaceFromId(id); + + interface = QNetworkInterface::interfaceFromName(interface).hardwareAddress().toLower(); + QString devPath; + devPath = deviceConnectionPath(interface); + QDBusObjectPath devicePath(devPath); + + iface = new QNetworkManagerInterface(); + iface->activateConnection( + connectionSettings.at(0), + connectionPath, + devicePath, + connectionPath); + + connect(iface, SIGNAL(activationFinished(QDBusPendingCallWatcher*)), + this, SLOT(slotActivationFinished(QDBusPendingCallWatcher*))); +} + +void QNmWifiEngine::disconnectFromId(const QString &id) +{ + QString activeConnectionPath = getActiveConnectionPath(id); + //qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << __FUNCTION__ << id << activeConnectionPath ; + + if (!activeConnectionPath.isEmpty()) { + QNetworkManagerConnectionActive *activeCon; + activeCon = new QNetworkManagerConnectionActive(activeConnectionPath); + QNetworkManagerSettingsConnection *settingsCon; + settingsCon = new QNetworkManagerSettingsConnection(activeCon->serviceName(), activeCon->connection().path()); + + if(settingsCon->isAutoConnect()) { +// qWarning() << id << "is autoconnect"; + emit connectionError(id, OperationNotSupported); + //unsupported + } else { +// qWarning() <deactivateConnection(dbpath); + activatingConnectionPath = ""; + } + } +} + +void QNmWifiEngine::requestUpdate() +{ + updated = false; + knownSsids.clear(); + availableAccessPoints.clear(); + emitConfigurationsChanged(); +} + +QNmWifiEngine *QNmWifiEngine::instance() +{ + QDBusConnection dbusConnection = QDBusConnection::systemBus(); + if (dbusConnection.isConnected()) { + QDBusConnectionInterface *dbiface = dbusConnection.interface(); + QDBusReply reply = dbiface->isServiceRegistered("org.freedesktop.NetworkManager"); + if (reply.isValid() && reply.value()) + return nmWifiEngine(); + } + + return 0; +} + +void QNmWifiEngine::getKnownSsids() +{ + QStringList connectionServices; + connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; + connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; +//qWarning() << Q_FUNC_INFO; + foreach (QString service, connectionServices) { + QNetworkManagerSettings *settingsiface; + settingsiface = new QNetworkManagerSettings(service); + QList list = settingsiface->listConnections(); + foreach(QDBusObjectPath path, list) { + QNetworkManagerSettingsConnection *sysIface; + sysIface = new QNetworkManagerSettingsConnection(service, path.path()); +// qWarning() << sysIface->getSsid(); + knownSsids << sysIface->getSsid(); + } + } +} + +void QNmWifiEngine::getActiveConnectionsPaths() +{ +// qWarning() << Q_FUNC_INFO; + QNetworkManagerInterface *dbIface; + activeConnectionPaths.clear(); + dbIface = new QNetworkManagerInterface; + QList connections = dbIface->activeConnections(); + + foreach(QDBusObjectPath conpath, connections) { + activeConnectionPaths << conpath.path(); +// qWarning() << __FUNCTION__ << conpath.path() << activeConnectionPaths.count(); + + QNetworkManagerConnectionActive *activeConn; + activeConn = new QNetworkManagerConnectionActive(conpath.path()); + +// qWarning() << activeConn->connection().path() /*<< activeConn->specificObject().path() */<< activeConn->devices()[0].path(); + + } +} + +QNetworkConfigurationPrivate * QNmWifiEngine::addAccessPoint( const QString &iPath, QDBusObjectPath path) +{ //foreach accessPoint + //qWarning() << Q_FUNC_INFO << iPath << path.path(); + + QNetworkManagerInterfaceDevice *devIface; + devIface = new QNetworkManagerInterfaceDevice(iPath); + QNetworkManagerInterfaceDeviceWireless *devWirelessIface; + devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(iPath); + + QString activeAPPath = devWirelessIface->activeAccessPoint().path(); + + QNetworkManagerInterfaceAccessPoint *accessPointIface; + accessPointIface = new QNetworkManagerInterfaceAccessPoint(path.path()); + + QString ident = accessPointIface->connectionInterface()->path(); + quint32 nmState = devIface->state(); + + QString ssid = accessPointIface->ssid(); + QString hwAddy = accessPointIface->hwAddress(); + QString sInterface = devIface->interface().name(); + + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + bool addIt = true; + //qWarning() << availableAccessPoints.count() << ssid; + +// if(availableAccessPoints.contains(ssid)) { +// addIt = false; +// +// } +// foreach (QNetworkConfigurationPrivate *cpPriv, foundConfigurations) { +// if (cpPriv->name == ssid) { //weed out duplicate ssid's ?? +// addIt = false; +// break; +// } +// } + + if(addIt) { + + cpPriv->name = ssid; + cpPriv->isValid = true; + cpPriv->id = ident; + cpPriv->internet = true; + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + cpPriv->serviceInterface = devIface->interface(); + + //qWarning() <<__FUNCTION__ << ssid; + + cpPriv->state = getAPState(nmState, knownSsids.contains(cpPriv->name)); + + if(activeAPPath == accessPointIface->connectionInterface()->path()) { + cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Active); + } + if(accessPointIface->flags() == NM_802_11_AP_FLAGS_PRIVACY) + cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; + else + cpPriv->purpose = QNetworkConfiguration::PublicPurpose; + return cpPriv; + } else { + cpPriv->isValid = false; + } + return cpPriv; +} + + + QNetworkConfiguration::StateFlags QNmWifiEngine::getAPState(qint32 nmState, bool isKnown) +{ + QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined; +//qWarning() << nmState << knownSsids; + // this is the state of the wifi device interface + if(isKnown) + state = ( QNetworkConfiguration::Defined); + + switch(nmState) { //device interface state, not AP state + case NM_DEVICE_STATE_UNKNOWN: + case NM_DEVICE_STATE_UNMANAGED: + case NM_DEVICE_STATE_UNAVAILABLE: + state = (QNetworkConfiguration::Undefined); + break; + case NM_DEVICE_STATE_DISCONNECTED: + { + if(isKnown) + state = ( state | QNetworkConfiguration::Discovered); + } + break; + case NM_DEVICE_STATE_PREPARE: + case NM_DEVICE_STATE_CONFIG: + case NM_DEVICE_STATE_NEED_AUTH: + case NM_DEVICE_STATE_IP_CONFIG: + if(isKnown) + state = ( state | QNetworkConfiguration::Discovered); + break; + case NM_DEVICE_STATE_ACTIVATED: + { + if(isKnown) + state = ( state | QNetworkConfiguration::Discovered); + } + break; + }; + return state; +} + +QString QNmWifiEngine::getActiveConnectionPath(const QString &id) +{ + //qWarning() << Q_FUNC_INFO << id; + QStringList connectionSettings = getConnectionPathForId(id); + //qWarning() << Q_FUNC_INFO << id << connectionSettings.count(); + QNetworkManagerInterface * ifaceD; + ifaceD = new QNetworkManagerInterface(); + QList connections = ifaceD->activeConnections(); + foreach(QDBusObjectPath path, connections) { + QNetworkManagerConnectionActive *conDetailsD; + conDetailsD = new QNetworkManagerConnectionActive( path.path()); + if(conDetailsD->connection().path() == connectionSettings.at(1) + && conDetailsD->serviceName() == connectionSettings.at(0)) + return path.path(); + } + return QString(); +} + + QNetworkConfiguration::StateFlags QNmWifiEngine::getStateFlag(quint32 nmstate) + { +// qWarning() << Q_FUNC_INFO << nmstate; + QNetworkConfiguration::StateFlags flag; + switch (nmstate) { + case NM_DEVICE_STATE_UNKNOWN: + case NM_DEVICE_STATE_FAILED: + case NM_DEVICE_STATE_UNMANAGED: + flag = (QNetworkConfiguration::Undefined); + break; + case NM_DEVICE_STATE_PREPARE: + case NM_DEVICE_STATE_CONFIG: + case NM_DEVICE_STATE_NEED_AUTH: + case NM_DEVICE_STATE_IP_CONFIG: + case NM_DEVICE_STATE_UNAVAILABLE: + flag = (QNetworkConfiguration::Defined); + break; + case NM_DEVICE_STATE_DISCONNECTED: + flag = ( flag | QNetworkConfiguration::Discovered ); + break; + case NM_DEVICE_STATE_ACTIVATED: + { + flag = ( flag | QNetworkConfiguration::Discovered + | QNetworkConfiguration::Active ); + } + break; + default: + flag = ( QNetworkConfiguration::Defined); + break; + }; + return flag; + } + +void QNmWifiEngine::updateDeviceInterfaceState(const QString &/*path*/, quint32 nmState) +{ +// qWarning() << Q_FUNC_INFO << path << nmState; + + if(nmState == NM_DEVICE_STATE_ACTIVATED + || nmState == NM_DEVICE_STATE_DISCONNECTED + || nmState == NM_DEVICE_STATE_UNAVAILABLE + || nmState == NM_DEVICE_STATE_FAILED) { + +/* InterfaceLookupError = 0, + ConnectError, + OperationNotSupported, + DisconnectionError, +*/ +// qWarning() << Q_FUNC_INFO << ident; + QNetworkConfiguration::StateFlags state = (QNetworkConfiguration::Defined); + switch (nmState) { + case NM_DEVICE_STATE_UNKNOWN: + case NM_DEVICE_STATE_FAILED: + state = (QNetworkConfiguration::Undefined); + emit connectionError(activatingConnectionPath, ConnectError); + requestUpdate(); +// qWarning() << Q_FUNC_INFO; + break; + case NM_DEVICE_STATE_UNAVAILABLE: + state = (QNetworkConfiguration::Defined); +// emit connectionError(activatingConnectionPath, ConnectError); + requestUpdate(); + break; + case NM_DEVICE_STATE_DISCONNECTED: + state = ( state | QNetworkConfiguration::Discovered ); + requestUpdate(); + break; + case NM_DEVICE_STATE_ACTIVATED: + { + state = ( state | QNetworkConfiguration::Discovered + | QNetworkConfiguration::Active ); + requestUpdate(); + } + break; + default: + state = ( QNetworkConfiguration::Defined); + break; + }; + } +} + +void QNmWifiEngine::addDevice(QDBusObjectPath path) +{ + //qWarning() << Q_FUNC_INFO << path.path(); + QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); + devIface->setConnections(); + connect(devIface,SIGNAL(stateChanged(const QString &, quint32)), + this, SLOT(updateDeviceInterfaceState(const QString&, quint32))); + + if(!devicePaths.contains(path.path())) + devicePaths << path.path(); + + switch(devIface->deviceType()) { + case DEVICE_TYPE_802_3_ETHERNET: + { + QNetworkManagerInterfaceDeviceWired * devWiredIface; + devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); + devWiredIface->setConnections(); + connect(devWiredIface, SIGNAL(propertiesChanged(const QString &,QMap)), + this,SLOT(cmpPropertiesChanged( const QString &, QMap))); + requestUpdate(); + } + break; + case DEVICE_TYPE_802_11_WIRELESS: + { + QNetworkManagerInterfaceDeviceWireless *devWirelessIface; + devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); + devWirelessIface->setConnections(); + + connect(devWirelessIface, SIGNAL(propertiesChanged(const QString &,QMap)), + this,SLOT(cmpPropertiesChanged( const QString &, QMap))); + + connect(devWirelessIface, SIGNAL(accessPointAdded(const QString &,QDBusObjectPath)), + this,SLOT(accessPointAdded(const QString &,QDBusObjectPath))); + + connect(devWirelessIface, SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath)), + this,SLOT(accessPointRemoved(const QString &,QDBusObjectPath))); + requestUpdate(); + + } + break; + default: + break; + }; +} + +void QNmWifiEngine::removeDevice(QDBusObjectPath /*path*/) +{ +// qWarning() << Q_FUNC_INFO << path.path(); +// disconnect(devIface,SIGNAL(stateChanged(const QString &, quint32)), +// this, SLOT(updateDeviceInterfaceState(const QString&, quint32))); +// +// if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { +// // devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); +// // devWirelessIface->setConnections(); +// +// disconnect(devWirelessIface, SIGNAL(propertiesChanged(const QString &,QMap)), +// this,SIGNAL(cmpPropertiesChanged( const QString &, QMap))); +// +// disconnect(devWirelessIface, SIGNAL(accessPointAdded(const QString &,QDBusObjectPath)), +// this,SIGNAL(accessPointAdded(const QString &,QDBusObjectPath))); +// +// disconnect(devWirelessIface, SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath)), +// this,SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath))); +// +// } +} +void QNmWifiEngine::cmpPropertiesChanged(const QString &path, QMap map) +{ + QMapIterator i(map); + while (i.hasNext()) { + i.next(); +// qWarning() << Q_FUNC_INFO << path << i.key() << i.value().toUInt(); + if( i.key() == "State") { //only applies to device interfaces + updateDeviceInterfaceState(path, i.value().toUInt()); + } + if( i.key() == "ActiveAccessPoint") { + } + if( i.key() == "Carrier") { //someone got plugged in + // requestUpdate(); + } + } +} + +void QNmWifiEngine::accessPointRemoved( const QString &aPath, QDBusObjectPath /*oPath*/) +{ + //qWarning() << Q_FUNC_INFO << aPath << oPath.path(); + + if(aPath.contains("devices")) { + requestUpdate(); + } +} + +void QNmWifiEngine::accessPointAdded( const QString &aPath, QDBusObjectPath oPath) +{ + //qWarning() << Q_FUNC_INFO << aPath << oPath.path(); + + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + cpPriv = addAccessPoint( aPath, oPath); + requestUpdate(); +} + +QNetworkConfiguration::StateFlags QNmWifiEngine::getStateForId(const QString &id) +{ + //qWarning() << Q_FUNC_INFO << id; + bool isAvailable = false; + QStringList conPath = getConnectionPathForId(id); + QString aconpath = getActiveConnectionPath(id); + + //qWarning() << Q_FUNC_INFO << id << aconpath; + + if(!aconpath.isEmpty()) { + //active connection + QNetworkManagerConnectionActive *aConn; + aConn = new QNetworkManagerConnectionActive(aconpath); + + QList devs = aConn->devices(); + + foreach(QDBusObjectPath dev, devs) { + //qWarning() << "foreach" << dev.path(); + QNetworkManagerInterfaceDevice *ifaceDevice; + ifaceDevice = new QNetworkManagerInterfaceDevice(dev.path()); + + if(ifaceDevice->deviceType() == DEVICE_TYPE_802_3_ETHERNET) { + + if(isAddressOfConnection(id, ifaceDevice->ip4Address())) { + // this is it! + return getStateFlag(ifaceDevice->state()); + } else { + continue; + } + + if(ifaceDevice->state() == NM_DEVICE_STATE_UNAVAILABLE || + ifaceDevice->state() == NM_DEVICE_STATE_DISCONNECTED) { + isAvailable = true; + + QNetworkManagerInterfaceDeviceWired *devWiredIface; + devWiredIface = new QNetworkManagerInterfaceDeviceWired(ifaceDevice->connectionInterface()->path()); + if(!devWiredIface->carrier()) + return QNetworkConfiguration::Defined; + } //end eth + } else if(ifaceDevice->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { + qWarning() << "FIXME!!!!!!!!!!!!!!!!!"; + } + + return getStateFlag(ifaceDevice->state()); + } + } else { + // not active + //qWarning() << Q_FUNC_INFO << "Not active"; + QNetworkManagerSettingsConnection *sysIface; + sysIface = new QNetworkManagerSettingsConnection(conPath.at(0),conPath.at(1)); + if(sysIface->isValid()) { + if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS) { + QString ssid = sysIface->getSsid(); + bool ok = false; + + if(knownSsids.contains(ssid, Qt::CaseSensitive)) { + foreach(QString onessid, knownSsids) { + // qWarning() << ssid << onessid; + if(onessid == ssid && availableAccessPoints.contains(ssid)) { + // qWarning() < devices = aConn->devices(); + foreach(QDBusObjectPath device, devices) { + QNetworkManagerInterfaceDevice *ifaceDevice; + ifaceDevice = new QNetworkManagerInterfaceDevice(device.path()); + if(ifaceDevice->ip4Address() == ipaddress) { + return true; + } + } + return false; +} + +QNetworkInterface QNmWifiEngine::getBestInterface( quint32 type, const QString &id) +{ + // check active connections first. + QStringList conIdPath = getConnectionPathForId(id); +// qWarning() << Q_FUNC_INFO << id << conIdPath; + + QNetworkInterface interface; + foreach(QString conpath, activeConnectionPaths) { + QNetworkManagerConnectionActive *aConn; + aConn = new QNetworkManagerConnectionActive(conpath); + + if(aConn->connection().path() == conIdPath.at(1) + && aConn->serviceName() == conIdPath.at(0)) { + + QList devs = aConn->devices(); + QNetworkManagerInterfaceDevice *ifaceDevice; + ifaceDevice = new QNetworkManagerInterfaceDevice(devs[0].path()); //just take the first one + interface = ifaceDevice->interface(); + return interface; + } + } + +//try guessing + QList list = iface->getDevices(); + foreach(QDBusObjectPath path, list) { + QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); + if(devIface->deviceType() == type /*&& devIface->managed()*/) { + interface = devIface->interface(); + if(devIface->state() == NM_STATE_DISCONNECTED) { + return interface; + } + } + } + return interface; +} + +quint64 QNmWifiEngine::receivedDataForId(const QString &id) const +{ + if(configurationInterface.count() > 1) + return 0; + quint64 result = 0; + + QString devFile; + devFile = configurationInterface.value(id); + QFile rx("/sys/class/net/"+devFile+"/statistics/rx_bytes"); + if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream in(&rx); + in >> result; + rx.close(); + } + return result; +} + +quint64 QNmWifiEngine::sentDataForId(const QString &id) const +{ + if(configurationInterface.count() > 1) + return 0; + quint64 result = 0; + QString devFile; + devFile = configurationInterface.value(id); + + QFile tx("/sys/class/net/"+devFile+"/statistics/tx_bytes"); + if(tx.exists() && tx.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream in(&tx); + in >> result; + tx.close(); + } + return result; +} + +void QNmWifiEngine::newConnection(QDBusObjectPath /*path*/) +{ + //qWarning() << Q_FUNC_INFO; + requestUpdate(); +} + +void QNmWifiEngine::settingsConnectionRemoved(const QString &/*path*/) +{ + //qWarning() << Q_FUNC_INFO; + requestUpdate(); +} + +void QNmWifiEngine::slotActivationFinished(QDBusPendingCallWatcher *openCall) +{ + QDBusPendingReply reply = *openCall; + if (reply.isError()) { + qWarning() <<"Error" << reply.error().name() << reply.error().message() + < list = iface->getDevices(); + + foreach(QDBusObjectPath path, list) { + QNetworkManagerInterfaceDevice *devIface; + devIface = new QNetworkManagerInterfaceDevice(path.path()); + + if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { + +// qWarning() << devIface->connectionInterface()->path(); + + QNetworkManagerInterfaceDeviceWireless *devWirelessIface; + devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); + ////////////// AccessPoints + QList apList = devWirelessIface->getAccessPoints(); + + foreach(QDBusObjectPath path, apList) { + QNetworkManagerInterfaceAccessPoint *accessPointIface; + accessPointIface = new QNetworkManagerInterfaceAccessPoint(path.path()); + QString ssid = accessPointIface->ssid(); + availableAccessPoints.insert(ssid, path); + } + } + } +} + +QString QNmWifiEngine::deviceConnectionPath(const QString &mac) +{ +// qWarning() << __FUNCTION__ << mac; + QString newMac = mac; + newMac = newMac.replace(":","_").toLower(); + //device object path might not contain just mac address + //might contain extra numbers on the end. thanks HAL + foreach(QString device, devicePaths) { + if(device.contains(newMac)) { + newMac = device; + break; + } + } + return newMac; +} + +QStringList QNmWifiEngine::getConnectionPathForId(const QString &uuid) +{ + QStringList connectionServices; + connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; + connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; +//qWarning() << Q_FUNC_INFO; + foreach (QString service, connectionServices) { + QNetworkManagerSettings *settingsiface; + settingsiface = new QNetworkManagerSettings(service); + QList list = settingsiface->listConnections(); + foreach(QDBusObjectPath path, list) { + QNetworkManagerSettingsConnection *sysIface; + sysIface = new QNetworkManagerSettingsConnection(service, path.path()); +// qWarning() << uuid << sysIface->getUuid(); + if(sysIface->getUuid() == uuid) { +// qWarning() <<__FUNCTION__ << service << sysIface->getId() << sysIface->connectionInterface()->path(); + return QStringList() << service << sysIface->connectionInterface()->path(); + } + } + } + return QStringList(); +} + +QT_END_NAMESPACE + diff --git a/src/plugins/bearer/networkmanager/qnmwifiengine.h b/src/plugins/bearer/networkmanager/qnmwifiengine.h new file mode 100644 index 0000000..4d514e7 --- /dev/null +++ b/src/plugins/bearer/networkmanager/qnmwifiengine.h @@ -0,0 +1,165 @@ +/**************************************************************************** +** +** 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 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 QNMWIFIENGINE_P_H +#define QNMWIFIENGINE_P_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 + +#include +#include +#include + +#include "qnetworkmanagerservice.h" + +#include +#include +#include +#include + + + +QT_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; + +class QNmWifiEngine : public QNetworkSessionEngine +{ + Q_OBJECT + +public: + QNmWifiEngine(QObject *parent = 0); + ~QNmWifiEngine(); + + QList getConfigurations(bool *ok = 0); + QString getInterfaceFromId(const QString &id); + bool hasIdentifier(const QString &id); + + QString bearerName(const QString &id); + + void connectToId(const QString &id); + void disconnectFromId(const QString &id); + + void requestUpdate(); + + static QNmWifiEngine *instance(); + + QStringList knownSsids; + inline void emitConfigurationsChanged() { emit configurationsChanged(); } + QNetworkConfigurationPrivate * addAccessPoint(const QString &, QDBusObjectPath ); + + QStringList getConnectionPathForId(const QString &uuid); + //QString getConnectionPathForId(const QString &name = QString()); + quint64 sentDataForId(const QString &id) const; + quint64 receivedDataForId(const QString &id) const; + +private: + bool updated; + QString activatingConnectionPath; + QStringList activeConnectionPaths; + + + QMap availableAccessPoints; + void scanForAccessPoints(); + + QStringList devicePaths; + + void getActiveConnectionsPaths(); + void getKnownSsids(); + void accessPointConnections(); + void knownConnections(); + void findConnections(); + QString deviceConnectionPath(const QString &mac); + + QList foundConfigurations; + // QHash > allConfigurations; + + QNetworkManagerInterface *iface; + + QNetworkConfiguration::StateFlags getAPState(qint32 vState, bool isKnown); + QNetworkConfiguration::StateFlags getStateFlag(quint32 nmstate); + + QString getActiveConnectionPath(const QString &identifier); + QString getNameForConfiguration(QNetworkManagerInterfaceDevice *devIface); + + QNetworkConfiguration::StateFlags getStateForId(const QString &id); + + QNetworkInterface getBestInterface(quint32 type, const QString &conPath); + + QMap configurationInterface; + + bool isAddressOfConnection(const QString &conPath, quint32 ipaddress); + +private slots: + void updateDeviceInterfaceState(const QString &, quint32); + void addDevice(QDBusObjectPath path); + void removeDevice(QDBusObjectPath path); + +Q_SIGNALS: + void configurationChanged(const QNetworkConfiguration& config); + void updateAccessPointState(const QString &, quint32); +// void slotActivationFinished(QDBusPendingCallWatcher*); + +private slots: + void accessPointAdded( const QString &aPath, QDBusObjectPath oPath); + void accessPointRemoved( const QString &aPath, QDBusObjectPath oPath); + void cmpPropertiesChanged(const QString &, QMap map); + void newConnection(QDBusObjectPath); + void settingsConnectionRemoved(const QString &); + void slotActivationFinished(QDBusPendingCallWatcher*); +}; + +QT_END_NAMESPACE + +#endif + + -- cgit v0.12 From c2254fdcba61c0aceb89f2f5e6dc926a9493c1a2 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 3 Dec 2009 12:36:31 +1000 Subject: Fix QNetworkSession unit tests. Fix out of process test by trimming input read from lackey. Don't fail in cleanupTestCase() if sessionOpenCloseStop() is not run due to command line. --- .../qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp index fc0db05..c7ce963 100644 --- a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp +++ b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp @@ -170,7 +170,7 @@ void tst_QNetworkSession::initTestCase() dbus_send.waitForFinished(); #endif - inProcessSessionManagementCount = 0; + inProcessSessionManagementCount = -1; QSignalSpy spy(&manager, SIGNAL(updateCompleted())); manager.updateConfigurations(); @@ -415,6 +415,8 @@ void tst_QNetworkSession::sessionOpenCloseStop_data() QTest::newRow((name + QLatin1String(" stop")).toLocal8Bit().constData()) << config << true; } + + inProcessSessionManagementCount = 0; } void tst_QNetworkSession::sessionOpenCloseStop() @@ -803,7 +805,7 @@ void tst_QNetworkSession::outOfProcessSession() output = oopSocket->readLine().trimmed(); if (output.startsWith("Started session ")) { - QString identifier = QString::fromLocal8Bit(output.mid(16).constData()); + QString identifier = QString::fromLocal8Bit(output.mid(20).constData()); QNetworkConfiguration changed; -- cgit v0.12 From 2374a4209f9edcc865b18f63e07a50cdaddc70b7 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 3 Dec 2009 12:44:11 +1000 Subject: Convert NLA engine nito a plugin. --- src/network/bearer/bearer.pri | 17 +- src/network/bearer/qnetworkconfigmanager_p.cpp | 17 +- src/network/bearer/qnetworkconfigmanager_p.h | 2 +- src/network/bearer/qnetworksession_p.cpp | 11 +- src/network/bearer/qnetworksessionengine_win_p.h | 145 ------ src/network/bearer/qnlaengine_win.cpp | 592 ----------------------- src/network/bearer/qnlaengine_win_p.h | 104 ---- src/plugins/bearer/bearer.pro | 1 + src/plugins/bearer/generic/generic.pro | 3 +- src/plugins/bearer/generic/qgenericengine.cpp | 2 +- src/plugins/bearer/nla/main.cpp | 88 ++++ src/plugins/bearer/nla/nla.pro | 20 + src/plugins/bearer/nla/qnlaengine.cpp | 591 ++++++++++++++++++++++ src/plugins/bearer/nla/qnlaengine.h | 105 ++++ src/plugins/bearer/platformdefs_win.h | 134 +++++ 15 files changed, 958 insertions(+), 874 deletions(-) delete mode 100644 src/network/bearer/qnetworksessionengine_win_p.h delete mode 100644 src/network/bearer/qnlaengine_win.cpp delete mode 100644 src/network/bearer/qnlaengine_win_p.h create mode 100644 src/plugins/bearer/nla/main.cpp create mode 100644 src/plugins/bearer/nla/nla.pro create mode 100644 src/plugins/bearer/nla/qnlaengine.cpp create mode 100644 src/plugins/bearer/nla/qnlaengine.h create mode 100644 src/plugins/bearer/platformdefs_win.h diff --git a/src/network/bearer/bearer.pri b/src/network/bearer/bearer.pri index bed2597..2c2d255 100644 --- a/src/network/bearer/bearer.pri +++ b/src/network/bearer/bearer.pri @@ -82,21 +82,10 @@ symbian { contains(QT_CONFIG, networkmanager):DEFINES += BACKEND_NM - win32 { - HEADERS += bearer/qnlaengine_win_p.h \ - bearer/qnetworksessionengine_win_p.h + win32:!wince* { + HEADERS += bearer/qnativewifiengine_win_p.h - SOURCES += bearer/qnlaengine_win.cpp - - !wince* { - HEADERS += bearer/qnativewifiengine_win_p.h - - SOURCES += bearer/qnativewifiengine_win.cpp - - LIBS += -lWs2_32 - } else { - LIBS += -lWs2 - } + SOURCES += bearer/qnativewifiengine_win.cpp } macx { diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 7b68394..c61bcd3 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -41,9 +41,6 @@ #include "qnetworkconfigmanager_p.h" -#ifdef Q_OS_WIN -#include "qnlaengine_win_p.h" -#endif #ifdef Q_OS_WIN32 #include "qnativewifiengine_win_p.h" #endif @@ -269,11 +266,17 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() #endif #ifdef Q_OS_WIN - nla = QNlaEngine::instance(); - if (nla) { - connect(nla, SIGNAL(configurationsChanged()), - this, SLOT(updateConfigurations())); + if (keys.contains(QLatin1String("nla"))) { + QBearerEnginePlugin *nlaPlugin = + qobject_cast(l->instance(QLatin1String("nla"))); + if (nlaPlugin) { + nla = nlaPlugin->create(QLatin1String("nla")); + if (nla) { + connect(nla, SIGNAL(configurationsChanged()), + this, SLOT(updateConfigurations())); + } } + } #endif #ifdef Q_OS_WIN32 diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index 6a61891..7b824f0 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -137,7 +137,7 @@ private: #ifdef BEARER_ENGINE QNetworkSessionEngine *generic; #ifdef Q_OS_WIN - QNlaEngine *nla; + QNetworkSessionEngine *nla; #ifndef Q_OS_WINCE QNativeWifiEngine *nativeWifi; #endif diff --git a/src/network/bearer/qnetworksession_p.cpp b/src/network/bearer/qnetworksession_p.cpp index cb170e8..1ce94e2 100644 --- a/src/network/bearer/qnetworksession_p.cpp +++ b/src/network/bearer/qnetworksession_p.cpp @@ -44,9 +44,6 @@ #include "qnetworksessionengine_p.h" #include "qnetworkconfigmanager_p.h" -#ifdef Q_OS_WIN -#include "qnlaengine_win_p.h" -#endif #ifdef Q_OS_WIN32 #include "qnativewifiengine_win_p.h" #endif @@ -59,18 +56,14 @@ #include +#undef interface + QT_BEGIN_NAMESPACE static QNetworkSessionEngine *getEngineFromId(const QString &id) { QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); -#ifdef Q_OS_WIN - QNlaEngine *nla = QNlaEngine::instance(); - if (nla && nla->hasIdentifier(id)) - return nla; -#endif - #ifdef Q_OS_WIN32 QNativeWifiEngine *nativeWifi = QNativeWifiEngine::instance(); if (nativeWifi && nativeWifi->hasIdentifier(id)) diff --git a/src/network/bearer/qnetworksessionengine_win_p.h b/src/network/bearer/qnetworksessionengine_win_p.h deleted file mode 100644 index e68a35b..0000000 --- a/src/network/bearer/qnetworksessionengine_win_p.h +++ /dev/null @@ -1,145 +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 QNETWORKSESSIONENGINE_WIN_P_H -#define QNETWORKSESSIONENGINE_WIN_P_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 -#include -#undef interface -#include - -#ifndef NS_NLA - -#define NS_NLA 15 - -enum NLA_BLOB_DATA_TYPE { - NLA_RAW_DATA = 0, - NLA_INTERFACE = 1, - NLA_802_1X_LOCATION = 2, - NLA_CONNECTIVITY = 3, - NLA_ICS = 4 -}; - -enum NLA_CONNECTIVITY_TYPE { - NLA_NETWORK_AD_HOC = 0, - NLA_NETWORK_MANAGED = 1, - NLA_NETWORK_UNMANAGED = 2, - NLA_NETWORK_UNKNOWN = 3 -}; - -enum NLA_INTERNET { - NLA_INTERNET_UNKNOWN = 0, - NLA_INTERNET_NO = 1, - NLA_INTERNET_YES = 2 -}; - -struct NLA_BLOB { - struct { - NLA_BLOB_DATA_TYPE type; - DWORD dwSize; - DWORD nextOffset; - } header; - - union { - // NLA_RAW_DATA - CHAR rawData[1]; - - // NLA_INTERFACE - struct { - DWORD dwType; - DWORD dwSpeed; - CHAR adapterName[1]; - } interfaceData; - - // NLA_802_1X_LOCATION - struct { - CHAR information[1]; - } locationData; - - // NLA_CONNECTIVITY - struct { - NLA_CONNECTIVITY_TYPE type; - NLA_INTERNET internet; - } connectivity; - - // NLA_ICS - struct { - struct { - DWORD speed; - DWORD type; - DWORD state; - WCHAR machineName[256]; - WCHAR sharedAdapterName[256]; - } remote; - } ICS; - } data; -}; -#endif - -enum NDIS_MEDIUM { - NdisMedium802_3 = 0, -}; - -enum NDIS_PHYSICAL_MEDIUM { - NdisPhysicalMediumWirelessLan = 1, - NdisPhysicalMediumBluetooth = 10, - NdisPhysicalMediumWiMax = 12, -}; - -#define OID_GEN_MEDIA_SUPPORTED 0x00010103 -#define OID_GEN_PHYSICAL_MEDIUM 0x00010202 - -#define IOCTL_NDIS_QUERY_GLOBAL_STATS \ - CTL_CODE(FILE_DEVICE_PHYSICAL_NETCARD, 0, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) - -#endif // QNETWORKSESSIONENGINE_WIN_P_H diff --git a/src/network/bearer/qnlaengine_win.cpp b/src/network/bearer/qnlaengine_win.cpp deleted file mode 100644 index 579b0e1..0000000 --- a/src/network/bearer/qnlaengine_win.cpp +++ /dev/null @@ -1,592 +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 "qnlaengine_win_p.h" -#include "qnetworkconfiguration_p.h" - -#include -#include -#include -#include - -#include - -#include "qnetworksessionengine_win_p.h" - -QT_BEGIN_NAMESPACE - -Q_GLOBAL_STATIC(QNlaEngine, nlaEngine) - -QWindowsSockInit::QWindowsSockInit() -: version(0) -{ - //### should we try for 2.2 on all platforms ?? - WSAData wsadata; - - // IPv6 requires Winsock v2.0 or better. - if (WSAStartup(MAKEWORD(2,0), &wsadata) != 0) { - qWarning("QBearerManagementAPI: WinSock v2.0 initialization failed."); - } else { - version = 0x20; - } -} - -QWindowsSockInit::~QWindowsSockInit() -{ - WSACleanup(); -} - -#ifdef BEARER_MANAGEMENT_DEBUG -static void printBlob(NLA_BLOB *blob) -{ - qDebug() << "==== BEGIN NLA_BLOB ===="; - - qDebug() << "type:" << blob->header.type; - qDebug() << "size:" << blob->header.dwSize; - qDebug() << "next offset:" << blob->header.nextOffset; - - switch (blob->header.type) { - case NLA_RAW_DATA: - qDebug() << "Raw Data"; - qDebug() << '\t' << blob->data.rawData; - break; - case NLA_INTERFACE: - qDebug() << "Interface"; - qDebug() << "\ttype:" << blob->data.interfaceData.dwType; - qDebug() << "\tspeed:" << blob->data.interfaceData.dwSpeed; - qDebug() << "\tadapter:" << blob->data.interfaceData.adapterName; - break; - case NLA_802_1X_LOCATION: - qDebug() << "802.1x Location"; - qDebug() << '\t' << blob->data.locationData.information; - break; - case NLA_CONNECTIVITY: - qDebug() << "Connectivity"; - qDebug() << "\ttype:" << blob->data.connectivity.type; - qDebug() << "\tinternet:" << blob->data.connectivity.internet; - break; - case NLA_ICS: - qDebug() << "ICS"; - qDebug() << "\tspeed:" << blob->data.ICS.remote.speed; - qDebug() << "\ttype:" << blob->data.ICS.remote.type; - qDebug() << "\tstate:" << blob->data.ICS.remote.state; - qDebug() << "\tmachine name:" << blob->data.ICS.remote.machineName; - qDebug() << "\tshared adapter name:" << blob->data.ICS.remote.sharedAdapterName; - break; - default: - qDebug() << "UNKNOWN BLOB TYPE"; - } - - qDebug() << "===== END NLA_BLOB ====="; -} -#endif - -static QString qGetInterfaceType(const QString &interface) -{ -#ifdef Q_OS_WINCE - Q_UNUSED(interface) -#else - unsigned long oid; - DWORD bytesWritten; - - NDIS_MEDIUM medium; - NDIS_PHYSICAL_MEDIUM physicalMedium; - - HANDLE handle = CreateFile((TCHAR *)QString("\\\\.\\%1").arg(interface).utf16(), 0, - FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); - if (handle == INVALID_HANDLE_VALUE) - return QString(); - - oid = OID_GEN_MEDIA_SUPPORTED; - bytesWritten = 0; - bool result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), - &medium, sizeof(medium), &bytesWritten, 0); - if (!result) { - CloseHandle(handle); - return QString(); - } - - oid = OID_GEN_PHYSICAL_MEDIUM; - bytesWritten = 0; - result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), - &physicalMedium, sizeof(physicalMedium), &bytesWritten, 0); - if (!result) { - CloseHandle(handle); - - if (medium == NdisMedium802_3) - return QLatin1String("Ethernet"); - else - return QString(); - } - - CloseHandle(handle); - - if (medium == NdisMedium802_3) { - switch (physicalMedium) { - case NdisPhysicalMediumWirelessLan: - return QLatin1String("WLAN"); - case NdisPhysicalMediumBluetooth: - return QLatin1String("Bluetooth"); - case NdisPhysicalMediumWiMax: - return QLatin1String("WiMAX"); - default: -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "Physical Medium" << physicalMedium; -#endif - return QLatin1String("Ethernet"); - } - } - -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << medium << physicalMedium; -#endif - -#endif - - return QString(); -} - -class QNlaThread : public QThread -{ - Q_OBJECT - -public: - QNlaThread(QNlaEngine *parent = 0); - ~QNlaThread(); - - QList getConfigurations(); - - void forceUpdate(); - -protected: - virtual void run(); - -private: - void updateConfigurations(QList &configs); - DWORD parseBlob(NLA_BLOB *blob, QNetworkConfigurationPrivate *cpPriv) const; - QNetworkConfigurationPrivate *parseQuerySet(const WSAQUERYSET *querySet) const; - void fetchConfigurations(); - -signals: - void networksChanged(); - -private: - QMutex mutex; - HANDLE handle; - bool done; - QList fetchedConfigurations; -}; - -QNlaThread::QNlaThread(QNlaEngine *parent) -: QThread(parent), handle(0), done(false) -{ -} - -QNlaThread::~QNlaThread() -{ - mutex.lock(); - - done = true; - - if (handle) { - /* cancel completion event */ - if (WSALookupServiceEnd(handle) == SOCKET_ERROR) - qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); - } - mutex.unlock(); - - wait(); -} - -QList QNlaThread::getConfigurations() -{ - QMutexLocker locker(&mutex); - - QList foundConfigurations; - - for (int i = 0; i < fetchedConfigurations.count(); ++i) { - QNetworkConfigurationPrivate *config = new QNetworkConfigurationPrivate; - config->name = fetchedConfigurations.at(i)->name; - config->isValid = fetchedConfigurations.at(i)->isValid; - config->id = fetchedConfigurations.at(i)->id; - config->state = fetchedConfigurations.at(i)->state; - config->type = fetchedConfigurations.at(i)->type; - config->roamingSupported = fetchedConfigurations.at(i)->roamingSupported; - config->purpose = fetchedConfigurations.at(i)->purpose; - config->internet = fetchedConfigurations.at(i)->internet; - - foundConfigurations.append(config); - } - - return foundConfigurations; -} - -void QNlaThread::forceUpdate() -{ - mutex.lock(); - - if (handle) { - /* cancel completion event */ - if (WSALookupServiceEnd(handle) == SOCKET_ERROR) - qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); - handle = 0; - } - mutex.unlock(); -} - -void QNlaThread::run() -{ - WSAEVENT changeEvent = WSACreateEvent(); - if (changeEvent == WSA_INVALID_EVENT) { - qWarning("WSACreateEvent error %d", WSAGetLastError()); - return; - } - - while (true) { - fetchConfigurations(); - - WSAQUERYSET qsRestrictions; - - memset(&qsRestrictions, 0, sizeof(qsRestrictions)); - qsRestrictions.dwSize = sizeof(qsRestrictions); - qsRestrictions.dwNameSpace = NS_NLA; - - mutex.lock(); - if (done) { - mutex.unlock(); - break; - } - int result = WSALookupServiceBegin(&qsRestrictions, LUP_RETURN_ALL, &handle); - mutex.unlock(); - - if (result == SOCKET_ERROR) { - qWarning("%s: WSALookupServiceBegin error %d", __FUNCTION__, WSAGetLastError()); - break; - } - - WSACOMPLETION completion; - WSAOVERLAPPED overlapped; - - memset(&overlapped, 0, sizeof(overlapped)); - overlapped.hEvent = changeEvent; - - memset(&completion, 0, sizeof(completion)); - completion.Type = NSP_NOTIFY_EVENT; - completion.Parameters.Event.lpOverlapped = &overlapped; - - DWORD bytesReturned = 0; - result = WSANSPIoctl(handle, SIO_NSP_NOTIFY_CHANGE, 0, 0, 0, 0, - &bytesReturned, &completion); - if (result == SOCKET_ERROR) { - int error = WSAGetLastError(); - if (error != WSA_IO_PENDING) { - qWarning("WSANSPIoctl error %d", error); - break; - } - } - -#ifndef Q_OS_WINCE - // Not interested in unrelated IO completion events - // although we also don't want to block them - while (WaitForSingleObjectEx(changeEvent, WSA_INFINITE, true) != WAIT_IO_COMPLETION) {} -#else - WaitForSingleObject(changeEvent, WSA_INFINITE); -#endif - - mutex.lock(); - if (handle) { - result = WSALookupServiceEnd(handle); - if (result == SOCKET_ERROR) { - qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); - mutex.unlock(); - break; - } - handle = 0; - } - mutex.unlock(); - } - - WSACloseEvent(changeEvent); -} - -void QNlaThread::updateConfigurations(QList &configs) -{ - mutex.lock(); - - while (!fetchedConfigurations.isEmpty()) - delete fetchedConfigurations.takeFirst(); - - fetchedConfigurations = configs; - - mutex.unlock(); - - emit networksChanged(); -} - -DWORD QNlaThread::parseBlob(NLA_BLOB *blob, QNetworkConfigurationPrivate *cpPriv) const -{ -#ifdef BEARER_MANAGEMENT_DEBUG - printBlob(blob); -#endif - - switch (blob->header.type) { - case NLA_RAW_DATA: -#ifdef BEARER_MANAGEMENT_DEBUG - qWarning("%s: unhandled header type NLA_RAW_DATA", __FUNCTION__); -#endif - break; - case NLA_INTERFACE: - cpPriv->state = QNetworkConfiguration::Active; - if (QNlaEngine *engine = qobject_cast(parent())) { - engine->configurationInterface[cpPriv->id.toUInt()] = - QString(blob->data.interfaceData.adapterName); - } - break; - case NLA_802_1X_LOCATION: -#ifdef BEARER_MANAGEMENT_DEBUG - qWarning("%s: unhandled header type NLA_802_1X_LOCATION", __FUNCTION__); -#endif - break; - case NLA_CONNECTIVITY: - if (blob->data.connectivity.internet == NLA_INTERNET_YES) - cpPriv->internet = true; - else - cpPriv->internet = false; -#ifdef BEARER_MANAGEMENT_DEBUG - qWarning("%s: unhandled header type NLA_CONNECTIVITY", __FUNCTION__); -#endif - break; - case NLA_ICS: -#ifdef BEARER_MANAGEMENT_DEBUG - qWarning("%s: unhandled header type NLA_ICS", __FUNCTION__); -#endif - break; - default: -#ifdef BEARER_MANAGEMENT_DEBUG - qWarning("%s: unhandled header type %d", __FUNCTION__, blob->header.type); -#endif - ; - } - - return blob->header.nextOffset; -} - -QNetworkConfigurationPrivate *QNlaThread::parseQuerySet(const WSAQUERYSET *querySet) const -{ - QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; - - cpPriv->name = QString::fromWCharArray(querySet->lpszServiceInstanceName); - cpPriv->isValid = true; - cpPriv->id = QString::number(qHash(QLatin1String("NLA:") + cpPriv->name)); - cpPriv->state = QNetworkConfiguration::Defined; - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "size:" << querySet->dwSize; - qDebug() << "service instance name:" << QString::fromUtf16(querySet->lpszServiceInstanceName); - qDebug() << "service class id:" << querySet->lpServiceClassId; - qDebug() << "version:" << querySet->lpVersion; - qDebug() << "comment:" << QString::fromUtf16(querySet->lpszComment); - qDebug() << "namespace:" << querySet->dwNameSpace; - qDebug() << "namespace provider id:" << querySet->lpNSProviderId; - qDebug() << "context:" << QString::fromUtf16(querySet->lpszContext); - qDebug() << "number of protocols:" << querySet->dwNumberOfProtocols; - qDebug() << "protocols:" << querySet->lpafpProtocols; - qDebug() << "query string:" << QString::fromUtf16(querySet->lpszQueryString); - qDebug() << "number of cs addresses:" << querySet->dwNumberOfCsAddrs; - qDebug() << "cs addresses:" << querySet->lpcsaBuffer; - qDebug() << "output flags:" << querySet->dwOutputFlags; -#endif - - if (querySet->lpBlob) { -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "blob size:" << querySet->lpBlob->cbSize; - qDebug() << "blob data:" << querySet->lpBlob->pBlobData; -#endif - - DWORD offset = 0; - do { - NLA_BLOB *blob = reinterpret_cast(querySet->lpBlob->pBlobData + offset); - DWORD nextOffset = parseBlob(blob, cpPriv); - if (nextOffset == offset) - break; - else - offset = nextOffset; - } while (offset != 0 && offset < querySet->lpBlob->cbSize); - } - - return cpPriv; -} - -void QNlaThread::fetchConfigurations() -{ - QList foundConfigurations; - - WSAQUERYSET qsRestrictions; - HANDLE hLookup = 0; - - memset(&qsRestrictions, 0, sizeof(qsRestrictions)); - qsRestrictions.dwSize = sizeof(qsRestrictions); - qsRestrictions.dwNameSpace = NS_NLA; - - int result = WSALookupServiceBegin(&qsRestrictions, LUP_RETURN_ALL | LUP_DEEP, &hLookup); - if (result == SOCKET_ERROR) { - qWarning("%s: WSALookupServiceBegin error %d", __FUNCTION__, WSAGetLastError()); - mutex.lock(); - fetchedConfigurations.clear(); - mutex.unlock(); - } - - char buffer[0x10000]; - while (result == 0) { - DWORD bufferLength = sizeof(buffer); - result = WSALookupServiceNext(hLookup, LUP_RETURN_ALL, - &bufferLength, reinterpret_cast(buffer)); - - if (result == SOCKET_ERROR) { - int error = WSAGetLastError(); - - if (error == WSA_E_NO_MORE) - break; - - if (error == WSAEFAULT) { - qDebug() << "buffer not big enough" << bufferLength; - break; - } - - qWarning("WSALookupServiceNext error %d", WSAGetLastError()); - break; - } - - QNetworkConfigurationPrivate *cpPriv = - parseQuerySet(reinterpret_cast(buffer)); - - foundConfigurations.append(cpPriv); - } - - if (hLookup) { - result = WSALookupServiceEnd(hLookup); - if (result == SOCKET_ERROR) { - qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); - } - } - - updateConfigurations(foundConfigurations); -} - -QNlaEngine::QNlaEngine(QObject *parent) -: QNetworkSessionEngine(parent), nlaThread(0) -{ - nlaThread = new QNlaThread(this); - connect(nlaThread, SIGNAL(networksChanged()), - this, SIGNAL(configurationsChanged())); - nlaThread->start(); - - qApp->processEvents(QEventLoop::ExcludeUserInputEvents); -} - -QNlaEngine::~QNlaEngine() -{ - delete nlaThread; -} - -QList QNlaEngine::getConfigurations(bool *ok) -{ - if (ok) - *ok = true; - - return nlaThread->getConfigurations(); -} - -QString QNlaEngine::getInterfaceFromId(const QString &id) -{ - return configurationInterface.value(id.toUInt()); -} - -bool QNlaEngine::hasIdentifier(const QString &id) -{ - if (configurationInterface.contains(id.toUInt())) - return true; - - foreach (QNetworkConfigurationPrivate *cpPriv, nlaThread->getConfigurations()) { - if (cpPriv->id == id) - return true; - } - - return false; -} - -QString QNlaEngine::bearerName(const QString &id) -{ - QString interface = getInterfaceFromId(id); - - if (interface.isEmpty()) - return QString(); - - return qGetInterfaceType(interface); -} - -void QNlaEngine::connectToId(const QString &id) -{ - emit connectionError(id, OperationNotSupported); -} - -void QNlaEngine::disconnectFromId(const QString &id) -{ - emit connectionError(id, OperationNotSupported); -} - -void QNlaEngine::requestUpdate() -{ - nlaThread->forceUpdate(); -} - -QNlaEngine *QNlaEngine::instance() -{ - return nlaEngine(); -} - -#include "qnlaengine_win.moc" -#include "moc_qnlaengine_win_p.cpp" -QT_END_NAMESPACE - - - diff --git a/src/network/bearer/qnlaengine_win_p.h b/src/network/bearer/qnlaengine_win_p.h deleted file mode 100644 index 1e7d051..0000000 --- a/src/network/bearer/qnlaengine_win_p.h +++ /dev/null @@ -1,104 +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 QNLAENGINE_P_H -#define QNLAENGINE_P_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 "qnetworksessionengine_p.h" - -#include - -QT_BEGIN_NAMESPACE - -class QNetworkConfigurationPrivate; -class QNlaThread; - -class QWindowsSockInit -{ -public: - QWindowsSockInit(); - ~QWindowsSockInit(); - int version; -}; - -class QNlaEngine : public QNetworkSessionEngine -{ - Q_OBJECT - - friend class QNlaThread; - -public: - QNlaEngine(QObject *parent = 0); - ~QNlaEngine(); - - QList getConfigurations(bool *ok = 0); - QString getInterfaceFromId(const QString &id); - bool hasIdentifier(const QString &id); - - QString bearerName(const QString &id); - - void connectToId(const QString &id); - void disconnectFromId(const QString &id); - - void requestUpdate(); - - static QNlaEngine *instance(); - -private: - QWindowsSockInit winSock; - QNlaThread *nlaThread; - QMap configurationInterface; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/bearer/bearer.pro b/src/plugins/bearer/bearer.pro index 60ba81b..51323b0 100644 --- a/src/plugins/bearer/bearer.pro +++ b/src/plugins/bearer/bearer.pro @@ -2,3 +2,4 @@ TEMPLATE = subdirs SUBDIRS += generic contains(QT_CONFIG, dbus):contains(QT_CONFIG, networkmanager):SUBDIRS += networkmanager +win32:SUBDIRS += nla diff --git a/src/plugins/bearer/generic/generic.pro b/src/plugins/bearer/generic/generic.pro index d32dbe6..506417c 100644 --- a/src/plugins/bearer/generic/generic.pro +++ b/src/plugins/bearer/generic/generic.pro @@ -5,7 +5,8 @@ QT += network DEFINES += BEARER_ENGINE -HEADERS += qgenericengine.h +HEADERS += qgenericengine.h \ + ../platformdefs_win.h SOURCES += qgenericengine.cpp main.cpp QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/bearer diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp index 89db82b..4be27ba 100644 --- a/src/plugins/bearer/generic/qgenericengine.cpp +++ b/src/plugins/bearer/generic/qgenericengine.cpp @@ -51,7 +51,7 @@ #include #ifdef Q_OS_WIN -#include "qnetworksessionengine_win_p.h" +#include "../platformdefs_win.h" #endif QT_BEGIN_NAMESPACE diff --git a/src/plugins/bearer/nla/main.cpp b/src/plugins/bearer/nla/main.cpp new file mode 100644 index 0000000..f0d36c4 --- /dev/null +++ b/src/plugins/bearer/nla/main.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** 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 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 "qnlaengine.h" + +#include + +#include + +QT_BEGIN_NAMESPACE + +class QNlaEnginePlugin : public QBearerEnginePlugin +{ +public: + QNlaEnginePlugin(); + ~QNlaEnginePlugin(); + + QStringList keys() const; + QBearerEngine *create(const QString &key) const; +}; + +QNlaEnginePlugin::QNlaEnginePlugin() +{ +} + +QNlaEnginePlugin::~QNlaEnginePlugin() +{ +} + +QStringList QNlaEnginePlugin::keys() const +{ + qDebug() << Q_FUNC_INFO; + + return QStringList() << QLatin1String("nla"); +} + +QBearerEngine *QNlaEnginePlugin::create(const QString &key) const +{ + qDebug() << Q_FUNC_INFO; + + if (key == QLatin1String("nla")) + return new QNlaEngine; + else + return 0; +} + +Q_EXPORT_STATIC_PLUGIN(QNlaEnginePlugin) +Q_EXPORT_PLUGIN2(qnlabearer, QNlaEnginePlugin) + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/nla/nla.pro b/src/plugins/bearer/nla/nla.pro new file mode 100644 index 0000000..78f3271 --- /dev/null +++ b/src/plugins/bearer/nla/nla.pro @@ -0,0 +1,20 @@ +TARGET = qnlabearer +include(../../qpluginbase.pri) + +QT += network + +!wince* { + LIBS += -lWs2_32 +} else { + LIBS += -lWs2 +} + +DEFINES += BEARER_ENGINE + +HEADERS += qnlaengine.h \ + ../platformdefs_win.h +SOURCES += qnlaengine.cpp main.cpp + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/bearer +target.path += $$[QT_INSTALL_PLUGINS]/bearer +INSTALLS += target diff --git a/src/plugins/bearer/nla/qnlaengine.cpp b/src/plugins/bearer/nla/qnlaengine.cpp new file mode 100644 index 0000000..527776f --- /dev/null +++ b/src/plugins/bearer/nla/qnlaengine.cpp @@ -0,0 +1,591 @@ +/**************************************************************************** +** +** 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 "qnlaengine.h" +#include + +#include +#include +#include +#include + +#include + +#include "../platformdefs_win.h" + +QT_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC(QNlaEngine, nlaEngine) + +QWindowsSockInit2::QWindowsSockInit2() +: version(0) +{ + //### should we try for 2.2 on all platforms ?? + WSAData wsadata; + + // IPv6 requires Winsock v2.0 or better. + if (WSAStartup(MAKEWORD(2,0), &wsadata) != 0) { + qWarning("QBearerManagementAPI: WinSock v2.0 initialization failed."); + } else { + version = 0x20; + } +} + +QWindowsSockInit2::~QWindowsSockInit2() +{ + WSACleanup(); +} + +#ifdef BEARER_MANAGEMENT_DEBUG +static void printBlob(NLA_BLOB *blob) +{ + qDebug() << "==== BEGIN NLA_BLOB ===="; + + qDebug() << "type:" << blob->header.type; + qDebug() << "size:" << blob->header.dwSize; + qDebug() << "next offset:" << blob->header.nextOffset; + + switch (blob->header.type) { + case NLA_RAW_DATA: + qDebug() << "Raw Data"; + qDebug() << '\t' << blob->data.rawData; + break; + case NLA_INTERFACE: + qDebug() << "Interface"; + qDebug() << "\ttype:" << blob->data.interfaceData.dwType; + qDebug() << "\tspeed:" << blob->data.interfaceData.dwSpeed; + qDebug() << "\tadapter:" << blob->data.interfaceData.adapterName; + break; + case NLA_802_1X_LOCATION: + qDebug() << "802.1x Location"; + qDebug() << '\t' << blob->data.locationData.information; + break; + case NLA_CONNECTIVITY: + qDebug() << "Connectivity"; + qDebug() << "\ttype:" << blob->data.connectivity.type; + qDebug() << "\tinternet:" << blob->data.connectivity.internet; + break; + case NLA_ICS: + qDebug() << "ICS"; + qDebug() << "\tspeed:" << blob->data.ICS.remote.speed; + qDebug() << "\ttype:" << blob->data.ICS.remote.type; + qDebug() << "\tstate:" << blob->data.ICS.remote.state; + qDebug() << "\tmachine name:" << blob->data.ICS.remote.machineName; + qDebug() << "\tshared adapter name:" << blob->data.ICS.remote.sharedAdapterName; + break; + default: + qDebug() << "UNKNOWN BLOB TYPE"; + } + + qDebug() << "===== END NLA_BLOB ====="; +} +#endif + +static QString qGetInterfaceType(const QString &interface) +{ +#ifdef Q_OS_WINCE + Q_UNUSED(interface) +#else + unsigned long oid; + DWORD bytesWritten; + + NDIS_MEDIUM medium; + NDIS_PHYSICAL_MEDIUM physicalMedium; + + HANDLE handle = CreateFile((TCHAR *)QString(QLatin1String("\\\\.\\%1")).arg(interface).utf16(), + 0, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); + if (handle == INVALID_HANDLE_VALUE) + return QString(); + + oid = OID_GEN_MEDIA_SUPPORTED; + bytesWritten = 0; + bool result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), + &medium, sizeof(medium), &bytesWritten, 0); + if (!result) { + CloseHandle(handle); + return QString(); + } + + oid = OID_GEN_PHYSICAL_MEDIUM; + bytesWritten = 0; + result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), + &physicalMedium, sizeof(physicalMedium), &bytesWritten, 0); + if (!result) { + CloseHandle(handle); + + if (medium == NdisMedium802_3) + return QLatin1String("Ethernet"); + else + return QString(); + } + + CloseHandle(handle); + + if (medium == NdisMedium802_3) { + switch (physicalMedium) { + case NdisPhysicalMediumWirelessLan: + return QLatin1String("WLAN"); + case NdisPhysicalMediumBluetooth: + return QLatin1String("Bluetooth"); + case NdisPhysicalMediumWiMax: + return QLatin1String("WiMAX"); + default: +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Physical Medium" << physicalMedium; +#endif + return QLatin1String("Ethernet"); + } + } + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << medium << physicalMedium; +#endif + +#endif + + return QString(); +} + +class QNlaThread : public QThread +{ + Q_OBJECT + +public: + QNlaThread(QNlaEngine *parent = 0); + ~QNlaThread(); + + QList getConfigurations(); + + void forceUpdate(); + +protected: + virtual void run(); + +private: + void updateConfigurations(QList &configs); + DWORD parseBlob(NLA_BLOB *blob, QNetworkConfigurationPrivate *cpPriv) const; + QNetworkConfigurationPrivate *parseQuerySet(const WSAQUERYSET *querySet) const; + void fetchConfigurations(); + +signals: + void networksChanged(); + +private: + QMutex mutex; + HANDLE handle; + bool done; + QList fetchedConfigurations; +}; + +QNlaThread::QNlaThread(QNlaEngine *parent) +: QThread(parent), handle(0), done(false) +{ +} + +QNlaThread::~QNlaThread() +{ + mutex.lock(); + + done = true; + + if (handle) { + /* cancel completion event */ + if (WSALookupServiceEnd(handle) == SOCKET_ERROR) + qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); + } + mutex.unlock(); + + wait(); +} + +QList QNlaThread::getConfigurations() +{ + QMutexLocker locker(&mutex); + + QList foundConfigurations; + + for (int i = 0; i < fetchedConfigurations.count(); ++i) { + QNetworkConfigurationPrivate *config = new QNetworkConfigurationPrivate; + config->name = fetchedConfigurations.at(i)->name; + config->isValid = fetchedConfigurations.at(i)->isValid; + config->id = fetchedConfigurations.at(i)->id; + config->state = fetchedConfigurations.at(i)->state; + config->type = fetchedConfigurations.at(i)->type; + config->roamingSupported = fetchedConfigurations.at(i)->roamingSupported; + config->purpose = fetchedConfigurations.at(i)->purpose; + config->internet = fetchedConfigurations.at(i)->internet; + + foundConfigurations.append(config); + } + + return foundConfigurations; +} + +void QNlaThread::forceUpdate() +{ + mutex.lock(); + + if (handle) { + /* cancel completion event */ + if (WSALookupServiceEnd(handle) == SOCKET_ERROR) + qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); + handle = 0; + } + mutex.unlock(); +} + +void QNlaThread::run() +{ + WSAEVENT changeEvent = WSACreateEvent(); + if (changeEvent == WSA_INVALID_EVENT) { + qWarning("WSACreateEvent error %d", WSAGetLastError()); + return; + } + + while (true) { + fetchConfigurations(); + + WSAQUERYSET qsRestrictions; + + memset(&qsRestrictions, 0, sizeof(qsRestrictions)); + qsRestrictions.dwSize = sizeof(qsRestrictions); + qsRestrictions.dwNameSpace = NS_NLA; + + mutex.lock(); + if (done) { + mutex.unlock(); + break; + } + int result = WSALookupServiceBegin(&qsRestrictions, LUP_RETURN_ALL, &handle); + mutex.unlock(); + + if (result == SOCKET_ERROR) { + qWarning("%s: WSALookupServiceBegin error %d", __FUNCTION__, WSAGetLastError()); + break; + } + + WSACOMPLETION completion; + WSAOVERLAPPED overlapped; + + memset(&overlapped, 0, sizeof(overlapped)); + overlapped.hEvent = changeEvent; + + memset(&completion, 0, sizeof(completion)); + completion.Type = NSP_NOTIFY_EVENT; + completion.Parameters.Event.lpOverlapped = &overlapped; + + DWORD bytesReturned = 0; + result = WSANSPIoctl(handle, SIO_NSP_NOTIFY_CHANGE, 0, 0, 0, 0, + &bytesReturned, &completion); + if (result == SOCKET_ERROR) { + int error = WSAGetLastError(); + if (error != WSA_IO_PENDING) { + qWarning("WSANSPIoctl error %d", error); + break; + } + } + +#ifndef Q_OS_WINCE + // Not interested in unrelated IO completion events + // although we also don't want to block them + while (WaitForSingleObjectEx(changeEvent, WSA_INFINITE, true) != WAIT_IO_COMPLETION) {} +#else + WaitForSingleObject(changeEvent, WSA_INFINITE); +#endif + + mutex.lock(); + if (handle) { + result = WSALookupServiceEnd(handle); + if (result == SOCKET_ERROR) { + qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); + mutex.unlock(); + break; + } + handle = 0; + } + mutex.unlock(); + } + + WSACloseEvent(changeEvent); +} + +void QNlaThread::updateConfigurations(QList &configs) +{ + mutex.lock(); + + while (!fetchedConfigurations.isEmpty()) + delete fetchedConfigurations.takeFirst(); + + fetchedConfigurations = configs; + + mutex.unlock(); + + emit networksChanged(); +} + +DWORD QNlaThread::parseBlob(NLA_BLOB *blob, QNetworkConfigurationPrivate *cpPriv) const +{ +#ifdef BEARER_MANAGEMENT_DEBUG + printBlob(blob); +#endif + + switch (blob->header.type) { + case NLA_RAW_DATA: +#ifdef BEARER_MANAGEMENT_DEBUG + qWarning("%s: unhandled header type NLA_RAW_DATA", __FUNCTION__); +#endif + break; + case NLA_INTERFACE: + cpPriv->state = QNetworkConfiguration::Active; + if (QNlaEngine *engine = qobject_cast(parent())) { + engine->configurationInterface[cpPriv->id.toUInt()] = + QString::fromLatin1(blob->data.interfaceData.adapterName); + } + break; + case NLA_802_1X_LOCATION: +#ifdef BEARER_MANAGEMENT_DEBUG + qWarning("%s: unhandled header type NLA_802_1X_LOCATION", __FUNCTION__); +#endif + break; + case NLA_CONNECTIVITY: + if (blob->data.connectivity.internet == NLA_INTERNET_YES) + cpPriv->internet = true; + else + cpPriv->internet = false; +#ifdef BEARER_MANAGEMENT_DEBUG + qWarning("%s: unhandled header type NLA_CONNECTIVITY", __FUNCTION__); +#endif + break; + case NLA_ICS: +#ifdef BEARER_MANAGEMENT_DEBUG + qWarning("%s: unhandled header type NLA_ICS", __FUNCTION__); +#endif + break; + default: +#ifdef BEARER_MANAGEMENT_DEBUG + qWarning("%s: unhandled header type %d", __FUNCTION__, blob->header.type); +#endif + ; + } + + return blob->header.nextOffset; +} + +QNetworkConfigurationPrivate *QNlaThread::parseQuerySet(const WSAQUERYSET *querySet) const +{ + QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; + + cpPriv->name = QString::fromWCharArray(querySet->lpszServiceInstanceName); + cpPriv->isValid = true; + cpPriv->id = QString::number(qHash(QLatin1String("NLA:") + cpPriv->name)); + cpPriv->state = QNetworkConfiguration::Defined; + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "size:" << querySet->dwSize; + qDebug() << "service instance name:" << QString::fromUtf16(querySet->lpszServiceInstanceName); + qDebug() << "service class id:" << querySet->lpServiceClassId; + qDebug() << "version:" << querySet->lpVersion; + qDebug() << "comment:" << QString::fromUtf16(querySet->lpszComment); + qDebug() << "namespace:" << querySet->dwNameSpace; + qDebug() << "namespace provider id:" << querySet->lpNSProviderId; + qDebug() << "context:" << QString::fromUtf16(querySet->lpszContext); + qDebug() << "number of protocols:" << querySet->dwNumberOfProtocols; + qDebug() << "protocols:" << querySet->lpafpProtocols; + qDebug() << "query string:" << QString::fromUtf16(querySet->lpszQueryString); + qDebug() << "number of cs addresses:" << querySet->dwNumberOfCsAddrs; + qDebug() << "cs addresses:" << querySet->lpcsaBuffer; + qDebug() << "output flags:" << querySet->dwOutputFlags; +#endif + + if (querySet->lpBlob) { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "blob size:" << querySet->lpBlob->cbSize; + qDebug() << "blob data:" << querySet->lpBlob->pBlobData; +#endif + + DWORD offset = 0; + do { + NLA_BLOB *blob = reinterpret_cast(querySet->lpBlob->pBlobData + offset); + DWORD nextOffset = parseBlob(blob, cpPriv); + if (nextOffset == offset) + break; + else + offset = nextOffset; + } while (offset != 0 && offset < querySet->lpBlob->cbSize); + } + + return cpPriv; +} + +void QNlaThread::fetchConfigurations() +{ + QList foundConfigurations; + + WSAQUERYSET qsRestrictions; + HANDLE hLookup = 0; + + memset(&qsRestrictions, 0, sizeof(qsRestrictions)); + qsRestrictions.dwSize = sizeof(qsRestrictions); + qsRestrictions.dwNameSpace = NS_NLA; + + int result = WSALookupServiceBegin(&qsRestrictions, LUP_RETURN_ALL | LUP_DEEP, &hLookup); + if (result == SOCKET_ERROR) { + qWarning("%s: WSALookupServiceBegin error %d", __FUNCTION__, WSAGetLastError()); + mutex.lock(); + fetchedConfigurations.clear(); + mutex.unlock(); + } + + char buffer[0x10000]; + while (result == 0) { + DWORD bufferLength = sizeof(buffer); + result = WSALookupServiceNext(hLookup, LUP_RETURN_ALL, + &bufferLength, reinterpret_cast(buffer)); + + if (result == SOCKET_ERROR) { + int error = WSAGetLastError(); + + if (error == WSA_E_NO_MORE) + break; + + if (error == WSAEFAULT) { + qDebug() << "buffer not big enough" << bufferLength; + break; + } + + qWarning("WSALookupServiceNext error %d", WSAGetLastError()); + break; + } + + QNetworkConfigurationPrivate *cpPriv = + parseQuerySet(reinterpret_cast(buffer)); + + foundConfigurations.append(cpPriv); + } + + if (hLookup) { + result = WSALookupServiceEnd(hLookup); + if (result == SOCKET_ERROR) { + qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); + } + } + + updateConfigurations(foundConfigurations); +} + +QNlaEngine::QNlaEngine(QObject *parent) +: QNetworkSessionEngine(parent), nlaThread(0) +{ + nlaThread = new QNlaThread(this); + connect(nlaThread, SIGNAL(networksChanged()), + this, SIGNAL(configurationsChanged())); + nlaThread->start(); + + qApp->processEvents(QEventLoop::ExcludeUserInputEvents); +} + +QNlaEngine::~QNlaEngine() +{ + delete nlaThread; +} + +QList QNlaEngine::getConfigurations(bool *ok) +{ + if (ok) + *ok = true; + + return nlaThread->getConfigurations(); +} + +QString QNlaEngine::getInterfaceFromId(const QString &id) +{ + return configurationInterface.value(id.toUInt()); +} + +bool QNlaEngine::hasIdentifier(const QString &id) +{ + if (configurationInterface.contains(id.toUInt())) + return true; + + foreach (QNetworkConfigurationPrivate *cpPriv, nlaThread->getConfigurations()) { + if (cpPriv->id == id) + return true; + } + + return false; +} + +QString QNlaEngine::bearerName(const QString &id) +{ + QString interface = getInterfaceFromId(id); + + if (interface.isEmpty()) + return QString(); + + return qGetInterfaceType(interface); +} + +void QNlaEngine::connectToId(const QString &id) +{ + emit connectionError(id, OperationNotSupported); +} + +void QNlaEngine::disconnectFromId(const QString &id) +{ + emit connectionError(id, OperationNotSupported); +} + +void QNlaEngine::requestUpdate() +{ + nlaThread->forceUpdate(); +} + +QNlaEngine *QNlaEngine::instance() +{ + return nlaEngine(); +} + +#include "qnlaengine.moc" +QT_END_NAMESPACE + + + diff --git a/src/plugins/bearer/nla/qnlaengine.h b/src/plugins/bearer/nla/qnlaengine.h new file mode 100644 index 0000000..76505fb --- /dev/null +++ b/src/plugins/bearer/nla/qnlaengine.h @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** 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 QNLAENGINE_P_H +#define QNLAENGINE_P_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 +#include + +#include + +QT_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; +class QNlaThread; + +class QWindowsSockInit2 +{ +public: + QWindowsSockInit2(); + ~QWindowsSockInit2(); + int version; +}; + +class QNlaEngine : public QNetworkSessionEngine +{ + Q_OBJECT + + friend class QNlaThread; + +public: + QNlaEngine(QObject *parent = 0); + ~QNlaEngine(); + + QList getConfigurations(bool *ok = 0); + QString getInterfaceFromId(const QString &id); + bool hasIdentifier(const QString &id); + + QString bearerName(const QString &id); + + void connectToId(const QString &id); + void disconnectFromId(const QString &id); + + void requestUpdate(); + + static QNlaEngine *instance(); + +private: + QWindowsSockInit2 winSock; + QNlaThread *nlaThread; + QMap configurationInterface; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/bearer/platformdefs_win.h b/src/plugins/bearer/platformdefs_win.h new file mode 100644 index 0000000..133b7b1 --- /dev/null +++ b/src/plugins/bearer/platformdefs_win.h @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** 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 QPLATFORMDEFS_WIN_H +#define QPLATFORMDEFS_WIN_H + +#include +#include +#undef interface +#include + +#ifndef NS_NLA + +#define NS_NLA 15 + +enum NLA_BLOB_DATA_TYPE { + NLA_RAW_DATA = 0, + NLA_INTERFACE = 1, + NLA_802_1X_LOCATION = 2, + NLA_CONNECTIVITY = 3, + NLA_ICS = 4 +}; + +enum NLA_CONNECTIVITY_TYPE { + NLA_NETWORK_AD_HOC = 0, + NLA_NETWORK_MANAGED = 1, + NLA_NETWORK_UNMANAGED = 2, + NLA_NETWORK_UNKNOWN = 3 +}; + +enum NLA_INTERNET { + NLA_INTERNET_UNKNOWN = 0, + NLA_INTERNET_NO = 1, + NLA_INTERNET_YES = 2 +}; + +struct NLA_BLOB { + struct { + NLA_BLOB_DATA_TYPE type; + DWORD dwSize; + DWORD nextOffset; + } header; + + union { + // NLA_RAW_DATA + CHAR rawData[1]; + + // NLA_INTERFACE + struct { + DWORD dwType; + DWORD dwSpeed; + CHAR adapterName[1]; + } interfaceData; + + // NLA_802_1X_LOCATION + struct { + CHAR information[1]; + } locationData; + + // NLA_CONNECTIVITY + struct { + NLA_CONNECTIVITY_TYPE type; + NLA_INTERNET internet; + } connectivity; + + // NLA_ICS + struct { + struct { + DWORD speed; + DWORD type; + DWORD state; + WCHAR machineName[256]; + WCHAR sharedAdapterName[256]; + } remote; + } ICS; + } data; +}; +#endif + +enum NDIS_MEDIUM { + NdisMedium802_3 = 0, +}; + +enum NDIS_PHYSICAL_MEDIUM { + NdisPhysicalMediumWirelessLan = 1, + NdisPhysicalMediumBluetooth = 10, + NdisPhysicalMediumWiMax = 12, +}; + +#define OID_GEN_MEDIA_SUPPORTED 0x00010103 +#define OID_GEN_PHYSICAL_MEDIUM 0x00010202 + +#define IOCTL_NDIS_QUERY_GLOBAL_STATS \ + CTL_CODE(FILE_DEVICE_PHYSICAL_NETCARD, 0, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) + +#endif -- cgit v0.12 From 3d9d69e56b33935a1af825d837ca81081332963f Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 3 Dec 2009 13:46:36 +1000 Subject: Convert NativeWifi engine into a plugin. --- src/network/bearer/bearer.pri | 6 - src/network/bearer/qnativewifiengine_win.cpp | 726 --------------------- src/network/bearer/qnativewifiengine_win_p.h | 95 --- src/network/bearer/qnetworkconfigmanager_p.cpp | 25 +- src/network/bearer/qnetworkconfigmanager_p.h | 2 +- src/network/bearer/qnetworksession_p.cpp | 9 - src/plugins/bearer/bearer.pro | 1 + src/plugins/bearer/nativewifi/main.cpp | 143 ++++ src/plugins/bearer/nativewifi/nativewifi.pro | 13 + src/plugins/bearer/nativewifi/platformdefs.h | 322 +++++++++ .../bearer/nativewifi/qnativewifiengine.cpp | 406 ++++++++++++ src/plugins/bearer/nativewifi/qnativewifiengine.h | 95 +++ 12 files changed, 998 insertions(+), 845 deletions(-) delete mode 100644 src/network/bearer/qnativewifiengine_win.cpp delete mode 100644 src/network/bearer/qnativewifiengine_win_p.h create mode 100644 src/plugins/bearer/nativewifi/main.cpp create mode 100644 src/plugins/bearer/nativewifi/nativewifi.pro create mode 100644 src/plugins/bearer/nativewifi/platformdefs.h create mode 100644 src/plugins/bearer/nativewifi/qnativewifiengine.cpp create mode 100644 src/plugins/bearer/nativewifi/qnativewifiengine.h diff --git a/src/network/bearer/bearer.pri b/src/network/bearer/bearer.pri index 2c2d255..9476239 100644 --- a/src/network/bearer/bearer.pri +++ b/src/network/bearer/bearer.pri @@ -82,12 +82,6 @@ symbian { contains(QT_CONFIG, networkmanager):DEFINES += BACKEND_NM - win32:!wince* { - HEADERS += bearer/qnativewifiengine_win_p.h - - SOURCES += bearer/qnativewifiengine_win.cpp - } - macx { HEADERS += bearer/qcorewlanengine_mac_p.h SOURCES+= bearer/qcorewlanengine_mac.mm diff --git a/src/network/bearer/qnativewifiengine_win.cpp b/src/network/bearer/qnativewifiengine_win.cpp deleted file mode 100644 index 46d4ead..0000000 --- a/src/network/bearer/qnativewifiengine_win.cpp +++ /dev/null @@ -1,726 +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 "qnativewifiengine_win_p.h" -#include "qnetworkconfiguration_p.h" - -#include -#include -#include -#include - -#include - -#include -#undef interface - -QT_BEGIN_NAMESPACE - -Q_GLOBAL_STATIC(QNativeWifiEngine, nativeWifiEngine) - -#define WLAN_MAX_NAME_LENGTH 256 -#define WLAN_MAX_PHY_TYPE_NUMBER 8 -#define WLAN_NOTIFICATION_SOURCE_ALL 0x0000ffff -#define WLAN_AVAILABLE_NETWORK_CONNECTED 1 -#define WLAN_AVAILABLE_NETWORK_HAS_PROFILE 2 -#define DOT11_SSID_MAX_LENGTH 32 - -struct WLAN_NOTIFICATION_DATA { - DWORD NotificationSource; - DWORD NotificationCode; - GUID InterfaceGuid; - DWORD dwDataSize; - PVOID pData; -}; - -enum WLAN_INTERFACE_STATE { - wlan_interface_state_not_ready = 0, - wlan_interface_state_connected, - wlan_interface_state_ad_hoc_network_formed, - wlan_interface_state_disconnecting, - wlan_interface_state_disconnected, - wlan_interface_state_associating, - wlan_interface_state_discovering, - wlan_interface_state_authenticating -}; - -struct WLAN_INTERFACE_INFO { - GUID InterfaceGuid; - WCHAR strInterfaceDescription[WLAN_MAX_NAME_LENGTH]; - WLAN_INTERFACE_STATE isState; -}; - -struct WLAN_INTERFACE_INFO_LIST { - DWORD dwNumberOfItems; - DWORD dwIndex; - WLAN_INTERFACE_INFO InterfaceInfo[1]; -}; - -struct DOT11_SSID { - ULONG uSSIDLength; - UCHAR ucSSID[DOT11_SSID_MAX_LENGTH]; -}; - -struct NDIS_OBJECT_HEADER { - UCHAR Type; - UCHAR Revision; - USHORT Size; -}; - -typedef UCHAR DOT11_MAC_ADDRESS[6]; -struct DOT11_BSSID_LIST { - NDIS_OBJECT_HEADER Header; - ULONG uNumberOfEntries; - ULONG uTotalNumOfEntries; - DOT11_MAC_ADDRESS BSSIDs[1]; -}; - -enum DOT11_BSS_TYPE { - dot11_BSS_type_infrastructure = 1, - dot11_BSS_type_independent = 2, - dot11_BSS_type_any = 3 -}; - -enum DOT11_PHY_TYPE { - dot11_phy_type_unknown = 0, - dot11_phy_type_any = dot11_phy_type_unknown, - dot11_phy_type_fhss = 1, - dot11_phy_type_dsss = 2, - dot11_phy_type_irbaseband = 3, - dot11_phy_type_ofdm = 4, - dot11_phy_type_hrdsss = 5, - dot11_phy_type_erp = 6, - dot11_phy_type_ht = 7, - dot11_phy_type_IHV_start = 0x80000000, - dot11_phy_type_IHV_end = 0xffffffff -}; - -enum DOT11_AUTH_ALGORITHM { - DOT11_AUTH_ALGO_80211_OPEN = 1, - DOT11_AUTH_ALGO_80211_SHARED_KEY = 2, - DOT11_AUTH_ALGO_WPA = 3, - DOT11_AUTH_ALGO_WPA_PSK = 4, - DOT11_AUTH_ALGO_WPA_NONE = 5, - DOT11_AUTH_ALGO_RSNA = 6, - DOT11_AUTH_ALGO_RSNA_PSK = 7, - DOT11_AUTH_ALGO_IHV_START = 0x80000000, - DOT11_AUTH_ALGO_IHV_END = 0xffffffff -}; - -enum DOT11_CIPHER_ALGORITHM { - DOT11_CIPHER_ALGO_NONE = 0x00, - DOT11_CIPHER_ALGO_WEP40 = 0x01, - DOT11_CIPHER_ALGO_TKIP = 0x02, - DOT11_CIPHER_ALGO_CCMP = 0x04, - DOT11_CIPHER_ALGO_WEP104 = 0x05, - DOT11_CIPHER_ALGO_WPA_USE_GROUP = 0x100, - DOT11_CIPHER_ALGO_RSN_USE_GROUP = 0x100, - DOT11_CIPHER_ALGO_WEP = 0x101, - DOT11_CIPHER_ALGO_IHV_START = 0x80000000, - DOT11_CIPHER_ALGO_IHV_END = 0xffffffff -}; - -struct WLAN_AVAILABLE_NETWORK { - WCHAR strProfileName[WLAN_MAX_NAME_LENGTH]; - DOT11_SSID dot11Ssid; - DOT11_BSS_TYPE dot11BssType; - ULONG uNumberOfBssids; - BOOL bNetworkConnectable; - DWORD wlanNotConnectableReason; - ULONG uNumberOfPhyTypes; - DOT11_PHY_TYPE dot11PhyTypes[WLAN_MAX_PHY_TYPE_NUMBER]; - BOOL bMorePhyTypes; - ULONG wlanSignalQuality; - BOOL bSecurityEnabled; - DOT11_AUTH_ALGORITHM dot11DefaultAuthAlgorithm; - DOT11_CIPHER_ALGORITHM dot11DefaultCipherAlgorithm; - DWORD dwFlags; - DWORD dwReserved; -}; - -struct WLAN_AVAILABLE_NETWORK_LIST { - DWORD dwNumberOfItems; - DWORD dwIndex; - WLAN_AVAILABLE_NETWORK Network[1]; -}; - -enum WLAN_INTF_OPCODE { - wlan_intf_opcode_autoconf_start = 0x000000000, - wlan_intf_opcode_autoconf_enabled, - wlan_intf_opcode_background_scan_enabled, - wlan_intf_opcode_media_streaming_mode, - wlan_intf_opcode_radio_state, - wlan_intf_opcode_bss_type, - wlan_intf_opcode_interface_state, - wlan_intf_opcode_current_connection, - wlan_intf_opcode_channel_number, - wlan_intf_opcode_supported_infrastructure_auth_cipher_pairs, - wlan_intf_opcode_supported_adhoc_auth_cipher_pairs, - wlan_intf_opcode_supported_country_or_region_string_list, - wlan_intf_opcode_current_operation_mode, - wlan_intf_opcode_supported_safe_mode, - wlan_intf_opcode_certified_safe_mode, - wlan_intf_opcode_autoconf_end = 0x0fffffff, - wlan_intf_opcode_msm_start = 0x10000100, - wlan_intf_opcode_statistics, - wlan_intf_opcode_rssi, - wlan_intf_opcode_msm_end = 0x1fffffff, - wlan_intf_opcode_security_start = 0x20010000, - wlan_intf_opcode_security_end = 0x2fffffff, - wlan_intf_opcode_ihv_start = 0x30000000, - wlan_intf_opcode_ihv_end = 0x3fffffff -}; - -enum WLAN_OPCODE_VALUE_TYPE { - wlan_opcode_value_type_query_only = 0, - wlan_opcode_value_type_set_by_group_policy, - wlan_opcode_value_type_set_by_user, - wlan_opcode_value_type_invalid -}; - -enum WLAN_CONNECTION_MODE { - wlan_connection_mode_profile = 0, - wlan_connection_mode_temporary_profile, - wlan_connection_mode_discovery_secure, - wlan_connection_mode_discovery_unsecure, - wlan_connection_mode_auto, - wlan_connection_mode_invalid -}; - -struct WLAN_CONNECTION_PARAMETERS { - WLAN_CONNECTION_MODE wlanConnectionMode; - LPCWSTR strProfile; - DOT11_SSID *pDot11Ssid; - DOT11_BSSID_LIST *pDesiredBssidList; - DOT11_BSS_TYPE dot11BssType; - DWORD dwFlags; -}; - -struct WLAN_RAW_DATA { - DWORD dwDataSize; - BYTE DataBlob[1]; -}; - -enum WLAN_NOTIFICATION_ACM { - wlan_notification_acm_start = 0, - wlan_notification_acm_autoconf_enabled, - wlan_notification_acm_autoconf_disabled, - wlan_notification_acm_background_scan_enabled, - wlan_notification_acm_background_scan_disabled, - wlan_notification_acm_bss_type_change, - wlan_notification_acm_power_setting_change, - wlan_notification_acm_scan_complete, - wlan_notification_acm_scan_fail, - wlan_notification_acm_connection_start, - wlan_notification_acm_connection_complete, - wlan_notification_acm_connection_attempt_fail, - wlan_notification_acm_filter_list_change, - wlan_notification_acm_interface_arrival, - wlan_notification_acm_interface_removal, - wlan_notification_acm_profile_change, - wlan_notification_acm_profile_name_change, - wlan_notification_acm_profiles_exhausted, - wlan_notification_acm_network_not_available, - wlan_notification_acm_network_available, - wlan_notification_acm_disconnecting, - wlan_notification_acm_disconnected, - wlan_notification_acm_adhoc_network_state_change, - wlan_notification_acm_end -}; - -struct WLAN_ASSOCIATION_ATTRIBUTES { - DOT11_SSID dot11Ssid; - DOT11_BSS_TYPE dot11BssType; - DOT11_MAC_ADDRESS dot11Bssid; - DOT11_PHY_TYPE dot11PhyType; - ULONG uDot11PhyIndex; - ULONG wlanSignalQuality; - ULONG ulRxRate; - ULONG ulTxRate; -}; - -struct WLAN_SECURITY_ATTRIBUTES { - BOOL bSecurityEnabled; - BOOL bOneXEnabled; - DOT11_AUTH_ALGORITHM dot11AuthAlgorithm; - DOT11_CIPHER_ALGORITHM dot11CipherAlgorithm; -}; - -struct WLAN_CONNECTION_ATTRIBUTES { - WLAN_INTERFACE_STATE isState; - WLAN_CONNECTION_MODE wlanConnectionMode; - WCHAR strProfileName[WLAN_MAX_NAME_LENGTH]; - WLAN_ASSOCIATION_ATTRIBUTES wlanAssociationAttributes; - WLAN_SECURITY_ATTRIBUTES wlanSecurityAttributes; -}; - -typedef void (WINAPI *WLAN_NOTIFICATION_CALLBACK)(WLAN_NOTIFICATION_DATA *, PVOID); - -typedef DWORD (WINAPI *WlanOpenHandleProto) - (DWORD dwClientVersion, PVOID pReserved, PDWORD pdwNegotiatedVersion, PHANDLE phClientHandle); -typedef DWORD (WINAPI *WlanRegisterNotificationProto) - (HANDLE hClientHandle, DWORD dwNotifSource, BOOL bIgnoreDuplicate, - WLAN_NOTIFICATION_CALLBACK funcCallback, PVOID pCallbackContext, - PVOID pReserved, PDWORD pdwPrevNotifSource); -typedef DWORD (WINAPI *WlanEnumInterfacesProto) - (HANDLE hClientHandle, PVOID pReserved, WLAN_INTERFACE_INFO_LIST **ppInterfaceList); -typedef DWORD (WINAPI *WlanGetAvailableNetworkListProto) - (HANDLE hClientHandle, const GUID* pInterfaceGuid, DWORD dwFlags, PVOID pReserved, - WLAN_AVAILABLE_NETWORK_LIST **ppAvailableNetworkList); -typedef DWORD (WINAPI *WlanQueryInterfaceProto) - (HANDLE hClientHandle, const GUID *pInterfaceGuid, WLAN_INTF_OPCODE OpCode, PVOID pReserved, - PDWORD pdwDataSize, PVOID *ppData, WLAN_OPCODE_VALUE_TYPE *pWlanOpcodeValueType); -typedef DWORD (WINAPI *WlanConnectProto) - (HANDLE hClientHandle, const GUID *pInterfaceGuid, - const WLAN_CONNECTION_PARAMETERS *pConnectionParameters, PVOID pReserved); -typedef DWORD (WINAPI *WlanDisconnectProto) - (HANDLE hClientHandle, const GUID *pInterfaceGuid, PVOID pReserved); -typedef DWORD (WINAPI *WlanScanProto) - (HANDLE hClientHandle, const GUID *pInterfaceGuid, const DOT11_SSID *pDot11Ssid, - const WLAN_RAW_DATA *pIeData, PVOID pReserved); -typedef VOID (WINAPI *WlanFreeMemoryProto)(PVOID pMemory); -typedef DWORD (WINAPI *WlanCloseHandleProto)(HANDLE hClientHandle, PVOID pReserved); - -static WlanOpenHandleProto local_WlanOpenHandle = 0; -static WlanRegisterNotificationProto local_WlanRegisterNotification = 0; -static WlanEnumInterfacesProto local_WlanEnumInterfaces = 0; -static WlanGetAvailableNetworkListProto local_WlanGetAvailableNetworkList = 0; -static WlanQueryInterfaceProto local_WlanQueryInterface = 0; -static WlanConnectProto local_WlanConnect = 0; -static WlanDisconnectProto local_WlanDisconnect = 0; -static WlanScanProto local_WlanScan = 0; -static WlanFreeMemoryProto local_WlanFreeMemory = 0; -static WlanCloseHandleProto local_WlanCloseHandle = 0; - -static void resolveLibrary() -{ - static volatile bool triedResolve = false; - - if (!triedResolve) { -#ifndef QT_NO_THREAD - QMutexLocker locker(QMutexPool::globalInstanceGet(&local_WlanOpenHandle)); -#endif - - if (!triedResolve) { - local_WlanOpenHandle = (WlanOpenHandleProto) - QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanOpenHandle"); - local_WlanRegisterNotification = (WlanRegisterNotificationProto) - QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanRegisterNotification"); - local_WlanEnumInterfaces = (WlanEnumInterfacesProto) - QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanEnumInterfaces"); - local_WlanGetAvailableNetworkList = (WlanGetAvailableNetworkListProto) - QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanGetAvailableNetworkList"); - local_WlanQueryInterface = (WlanQueryInterfaceProto) - QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanQueryInterface"); - local_WlanConnect = (WlanConnectProto) - QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanConnect"); - local_WlanDisconnect = (WlanDisconnectProto) - QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanDisconnect"); - local_WlanScan = (WlanScanProto) - QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanScan"); - local_WlanFreeMemory = (WlanFreeMemoryProto) - QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanFreeMemory"); - local_WlanCloseHandle = (WlanCloseHandleProto) - QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanCloseHandle"); - - triedResolve = true; - } - } -} - -void qNotificationCallback(WLAN_NOTIFICATION_DATA *data, QNativeWifiEngine *d) -{ - Q_UNUSED(d); - - switch (data->NotificationCode) { - case wlan_notification_acm_connection_complete: - case wlan_notification_acm_disconnected: - d->emitConfigurationsChanged(); - break; - default: - qDebug() << "wlan unknown notification"; - } -} - -QNativeWifiEngine::QNativeWifiEngine(QObject *parent) -: QNetworkSessionEngine(parent), handle(0) -{ - DWORD clientVersion; - - DWORD result = local_WlanOpenHandle(1, 0, &clientVersion, &handle); - if (result != ERROR_SUCCESS) { - if (result != ERROR_SERVICE_NOT_ACTIVE) - qWarning("%s: WlanOpenHandle failed with error %ld\n", __FUNCTION__, result); - - return; - } - - result = local_WlanRegisterNotification(handle, WLAN_NOTIFICATION_SOURCE_ALL, true, - WLAN_NOTIFICATION_CALLBACK(qNotificationCallback), - this, 0, 0); - if (result != ERROR_SUCCESS) - qWarning("%s: WlanRegisterNotification failed with error %ld\n", __FUNCTION__, result); - - // On Windows XP SP2 and SP3 only connection and disconnection notifications are available. - // We need to poll for changes in available wireless networks. - connect(&pollTimer, SIGNAL(timeout()), this, SIGNAL(configurationsChanged())); - pollTimer.setInterval(10000); -} - -QNativeWifiEngine::~QNativeWifiEngine() -{ - local_WlanCloseHandle(handle, 0); -} - -QList QNativeWifiEngine::getConfigurations(bool *ok) -{ - if (ok) - *ok = false; - - QList foundConfigurations; - - // enumerate interfaces - WLAN_INTERFACE_INFO_LIST *interfaceList; - DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); - if (result != ERROR_SUCCESS) { - qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); - return foundConfigurations; - } - - for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { - const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i]; - - WLAN_AVAILABLE_NETWORK_LIST *networkList; - result = local_WlanGetAvailableNetworkList(handle, &interface.InterfaceGuid, - 3, 0, &networkList); - if (result != ERROR_SUCCESS) { - qWarning("%s: WlanGetAvailableNetworkList failed with error %ld\n", - __FUNCTION__, result); - continue; - } - - QStringList seenNetworks; - - for (unsigned int j = 0; j < networkList->dwNumberOfItems; ++j) { - WLAN_AVAILABLE_NETWORK &network = networkList->Network[j]; - - QString networkName; - - if (network.strProfileName[0] != 0) { - networkName = QString::fromWCharArray(network.strProfileName); - } else { - networkName = QByteArray(reinterpret_cast(network.dot11Ssid.ucSSID), - network.dot11Ssid.uSSIDLength); - } - - // don't add duplicate networks - if (seenNetworks.contains(networkName)) - continue; - else - seenNetworks.append(networkName); - - QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; - - cpPriv->isValid = true; - - cpPriv->name = networkName; - cpPriv->id = QString::number(qHash(QLatin1String("WLAN:") + cpPriv->name)); - - if (!(network.dwFlags & WLAN_AVAILABLE_NETWORK_HAS_PROFILE)) - cpPriv->state = QNetworkConfiguration::Undefined; - - if (network.strProfileName[0] != 0) { - if (network.bNetworkConnectable) { - if (network.dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED) - cpPriv->state = QNetworkConfiguration::Active; - else - cpPriv->state = QNetworkConfiguration::Discovered; - } else { - cpPriv->state = QNetworkConfiguration::Defined; - } - } - - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - - foundConfigurations.append(cpPriv); - } - - local_WlanFreeMemory(networkList); - } - - local_WlanFreeMemory(interfaceList); - - if (ok) - *ok = true; - - pollTimer.start(); - - return foundConfigurations; -} - -QString QNativeWifiEngine::getInterfaceFromId(const QString &id) -{ - // enumerate interfaces - WLAN_INTERFACE_INFO_LIST *interfaceList; - DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); - if (result != ERROR_SUCCESS) { - qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); - return QString(); - } - - for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { - const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i]; - - DWORD dataSize; - WLAN_CONNECTION_ATTRIBUTES *connectionAttributes; - result = local_WlanQueryInterface(handle, &interface.InterfaceGuid, - wlan_intf_opcode_current_connection, 0, &dataSize, - reinterpret_cast(&connectionAttributes), 0); - if (result != ERROR_SUCCESS) { - if (result != ERROR_INVALID_STATE) - qWarning("%s: WlanQueryInterface failed with error %ld\n", __FUNCTION__, result); - - continue; - } - - if (qHash(QLatin1String("WLAN:") + - QString::fromWCharArray(connectionAttributes->strProfileName)) == id.toUInt()) { - QString guid("{%1-%2-%3-%4%5-%6%7%8%9%10%11}"); - - guid = guid.arg(interface.InterfaceGuid.Data1, 8, 16, QChar('0')); - guid = guid.arg(interface.InterfaceGuid.Data2, 4, 16, QChar('0')); - guid = guid.arg(interface.InterfaceGuid.Data3, 4, 16, QChar('0')); - for (int i = 0; i < 8; ++i) - guid = guid.arg(interface.InterfaceGuid.Data4[i], 2, 16, QChar('0')); - - local_WlanFreeMemory(connectionAttributes); - - return guid.toUpper(); - } - - local_WlanFreeMemory(connectionAttributes); - } - - return QString(); -} - -bool QNativeWifiEngine::hasIdentifier(const QString &id) -{ - // enumerate interfaces - WLAN_INTERFACE_INFO_LIST *interfaceList; - DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); - if (result != ERROR_SUCCESS) { - qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); - return false; - } - - for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { - const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i]; - - WLAN_AVAILABLE_NETWORK_LIST *networkList; - result = local_WlanGetAvailableNetworkList(handle, &interface.InterfaceGuid, - 3, 0, &networkList); - if (result != ERROR_SUCCESS) { - qWarning("%s: WlanGetAvailableNetworkList failed with error %ld\n", - __FUNCTION__, result); - continue; - } - - for (unsigned int j = 0; j < networkList->dwNumberOfItems; ++j) { - WLAN_AVAILABLE_NETWORK &network = networkList->Network[j]; - - QString networkName; - - if (network.strProfileName[0] != 0) { - networkName = QString::fromWCharArray(network.strProfileName); - } else { - networkName = QByteArray(reinterpret_cast(network.dot11Ssid.ucSSID), - network.dot11Ssid.uSSIDLength); - } - - if (qHash(QLatin1String("WLAN:") + networkName) == id.toUInt()) { - local_WlanFreeMemory(networkList); - local_WlanFreeMemory(interfaceList); - return true; - } - } - - local_WlanFreeMemory(networkList); - } - - local_WlanFreeMemory(interfaceList); - - return false; -} - -QString QNativeWifiEngine::bearerName(const QString &) -{ - return QLatin1String("WLAN"); -} - -void QNativeWifiEngine::connectToId(const QString &id) -{ - WLAN_INTERFACE_INFO_LIST *interfaceList; - DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); - if (result != ERROR_SUCCESS) { - qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); - emit connectionError(id, InterfaceLookupError); - return; - } - - QString profile; - - for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { - const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i]; - - WLAN_AVAILABLE_NETWORK_LIST *networkList; - result = local_WlanGetAvailableNetworkList(handle, &interface.InterfaceGuid, - 3, 0, &networkList); - if (result != ERROR_SUCCESS) { - qWarning("%s: WlanGetAvailableNetworkList failed with error %ld\n", - __FUNCTION__, result); - continue; - } - - for (unsigned int j = 0; j < networkList->dwNumberOfItems; ++j) { - WLAN_AVAILABLE_NETWORK &network = networkList->Network[j]; - - profile = QString::fromWCharArray(network.strProfileName); - - if (qHash(QLatin1String("WLAN:") + profile) == id.toUInt()) - break; - else - profile.clear(); - } - - local_WlanFreeMemory(networkList); - - if (!profile.isEmpty()) { - WLAN_CONNECTION_PARAMETERS parameters; - parameters.wlanConnectionMode = wlan_connection_mode_profile; - parameters.strProfile = reinterpret_cast(profile.utf16()); - parameters.pDot11Ssid = 0; - parameters.pDesiredBssidList = 0; - parameters.dot11BssType = dot11_BSS_type_any; - parameters.dwFlags = 0; - - DWORD result = local_WlanConnect(handle, &interface.InterfaceGuid, ¶meters, 0); - if (result != ERROR_SUCCESS) { - qWarning("%s: WlanConnect failed with error %ld\n", __FUNCTION__, result); - emit connectionError(id, ConnectError); - break; - } - - break; - } - } - - local_WlanFreeMemory(interfaceList); - - if (profile.isEmpty()) - emit connectionError(id, InterfaceLookupError); -} - -void QNativeWifiEngine::disconnectFromId(const QString &id) -{ - QString interface = getInterfaceFromId(id); - - if (interface.isEmpty()) { - emit connectionError(id, InterfaceLookupError); - return; - } - - QStringList split = interface.mid(1, interface.length() - 2).split('-'); - - GUID guid; - guid.Data1 = split.at(0).toUInt(0, 16); - guid.Data2 = split.at(1).toUShort(0, 16); - guid.Data3 = split.at(2).toUShort(0, 16); - guid.Data4[0] = split.at(3).left(2).toUShort(0, 16); - guid.Data4[1] = split.at(3).right(2).toUShort(0, 16); - for (int i = 0; i < 6; ++i) - guid.Data4[i + 2] = split.at(4).mid(i*2, 2).toUShort(0, 16); - - DWORD result = local_WlanDisconnect(handle, &guid, 0); - if (result != ERROR_SUCCESS) { - qWarning("%s: WlanDisconnect failed with error %ld\n", __FUNCTION__, result); - emit connectionError(id, DisconnectionError); - return; - } -} - -void QNativeWifiEngine::requestUpdate() -{ - // enumerate interfaces - WLAN_INTERFACE_INFO_LIST *interfaceList; - DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); - if (result != ERROR_SUCCESS) { - qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); - return; - } - - for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { - result = local_WlanScan(handle, &interfaceList->InterfaceInfo[i].InterfaceGuid, 0, 0, 0); - if (result != ERROR_SUCCESS) - qWarning("%s: WlanScan failed with error %ld\n", __FUNCTION__, result); - } -} - -QNativeWifiEngine *QNativeWifiEngine::instance() -{ - resolveLibrary(); - - // native wifi dll not available - if (!local_WlanOpenHandle) - return 0; - - QNativeWifiEngine *engine = nativeWifiEngine(); - - // could not initialise subsystem - if (engine && engine->handle == 0) - return 0; - - return engine; -} - -#include "moc_qnativewifiengine_win_p.cpp" - -QT_END_NAMESPACE diff --git a/src/network/bearer/qnativewifiengine_win_p.h b/src/network/bearer/qnativewifiengine_win_p.h deleted file mode 100644 index 4817867..0000000 --- a/src/network/bearer/qnativewifiengine_win_p.h +++ /dev/null @@ -1,95 +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 QNATIVEWIFIENGINE_P_H -#define QNATIVEWIFIENGINE_P_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 "qnetworksessionengine_p.h" - -#include - -QT_BEGIN_NAMESPACE - -class QNetworkConfigurationPrivate; - -class QNativeWifiEngine : public QNetworkSessionEngine -{ - Q_OBJECT - -public: - QNativeWifiEngine(QObject *parent = 0); - ~QNativeWifiEngine(); - - QList getConfigurations(bool *ok = 0); - QString getInterfaceFromId(const QString &id); - bool hasIdentifier(const QString &id); - - QString bearerName(const QString &id); - - void connectToId(const QString &id); - void disconnectFromId(const QString &id); - - void requestUpdate(); - - inline void emitConfigurationsChanged() { emit configurationsChanged(); } - - static QNativeWifiEngine *instance(); - -private: - QTimer pollTimer; - - Qt::HANDLE handle; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index c61bcd3..c35edbf 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -41,9 +41,6 @@ #include "qnetworkconfigmanager_p.h" -#ifdef Q_OS_WIN32 -#include "qnativewifiengine_win_p.h" -#endif #ifdef Q_OS_DARWIN #include "qcorewlanengine_mac_p.h" #endif @@ -239,6 +236,7 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() } #else #ifdef BACKEND_NM + nmWifi = 0; if (keys.contains(QLatin1String("networkmanager"))) { QBearerEnginePlugin *nmPlugin = qobject_cast(l->instance(QLatin1String("networkmanager"))); @@ -252,6 +250,7 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() } #endif + generic = 0; if (keys.contains(QLatin1String("generic"))) { QBearerEnginePlugin *genericPlugin = qobject_cast(l->instance(QLatin1String("generic"))); @@ -266,10 +265,12 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() #endif #ifdef Q_OS_WIN + nla = 0; if (keys.contains(QLatin1String("nla"))) { QBearerEnginePlugin *nlaPlugin = qobject_cast(l->instance(QLatin1String("nla"))); if (nlaPlugin) { + qDebug() << "creating nla backend"; nla = nlaPlugin->create(QLatin1String("nla")); if (nla) { connect(nla, SIGNAL(configurationsChanged()), @@ -280,13 +281,21 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() #endif #ifdef Q_OS_WIN32 - nativeWifi = QNativeWifiEngine::instance(); - if (nativeWifi) { - connect(nativeWifi, SIGNAL(configurationsChanged()), - this, SLOT(updateConfigurations())); + nativeWifi = 0; + if (keys.contains(QLatin1String("nativewifi"))) { + QBearerEnginePlugin *nativeWifiPlugin = + qobject_cast(l->instance(QLatin1String("nativewifi"))); + if (nativeWifiPlugin) { + qDebug() << "Creating native wifi backend"; + nativeWifi = nativeWifiPlugin->create(QLatin1String("nativewifi")); + if (nativeWifi) { + connect(nativeWifi, SIGNAL(configurationsChanged()), + this, SLOT(updateConfigurations())); - capFlags |= QNetworkConfigurationManager::CanStartAndStopInterfaces; + capFlags |= QNetworkConfigurationManager::CanStartAndStopInterfaces; + } } + } #endif } diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index 7b824f0..5d0df18 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -139,7 +139,7 @@ private: #ifdef Q_OS_WIN QNetworkSessionEngine *nla; #ifndef Q_OS_WINCE - QNativeWifiEngine *nativeWifi; + QNetworkSessionEngine *nativeWifi; #endif #endif #ifdef BACKEND_NM diff --git a/src/network/bearer/qnetworksession_p.cpp b/src/network/bearer/qnetworksession_p.cpp index 1ce94e2..3c9054b 100644 --- a/src/network/bearer/qnetworksession_p.cpp +++ b/src/network/bearer/qnetworksession_p.cpp @@ -44,9 +44,6 @@ #include "qnetworksessionengine_p.h" #include "qnetworkconfigmanager_p.h" -#ifdef Q_OS_WIN32 -#include "qnativewifiengine_win_p.h" -#endif #ifdef Q_OS_DARWIN #include "qcorewlanengine_mac_p.h" #endif @@ -64,12 +61,6 @@ static QNetworkSessionEngine *getEngineFromId(const QString &id) { QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); -#ifdef Q_OS_WIN32 - QNativeWifiEngine *nativeWifi = QNativeWifiEngine::instance(); - if (nativeWifi && nativeWifi->hasIdentifier(id)) - return nativeWifi; -#endif - #ifdef Q_OS_DARWIN QCoreWlanEngine *coreWifi = QCoreWlanEngine::instance(); if (coreWifi && coreWifi->hasIdentifier(id)) diff --git a/src/plugins/bearer/bearer.pro b/src/plugins/bearer/bearer.pro index 51323b0..80d6f4b 100644 --- a/src/plugins/bearer/bearer.pro +++ b/src/plugins/bearer/bearer.pro @@ -3,3 +3,4 @@ TEMPLATE = subdirs SUBDIRS += generic contains(QT_CONFIG, dbus):contains(QT_CONFIG, networkmanager):SUBDIRS += networkmanager win32:SUBDIRS += nla +win32:!wince*:SUBDIRS += nativewifi diff --git a/src/plugins/bearer/nativewifi/main.cpp b/src/plugins/bearer/nativewifi/main.cpp new file mode 100644 index 0000000..2aced02 --- /dev/null +++ b/src/plugins/bearer/nativewifi/main.cpp @@ -0,0 +1,143 @@ +/**************************************************************************** +** +** 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 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 "qnativewifiengine.h" +#include "platformdefs.h" + +#include +#include +#include + +#include + +#include + +QT_BEGIN_NAMESPACE + +static void resolveLibrary() +{ + static volatile bool triedResolve = false; + + if (!triedResolve) { +#ifndef QT_NO_THREAD + QMutexLocker locker(QMutexPool::globalInstanceGet(&local_WlanOpenHandle)); +#endif + + if (!triedResolve) { + local_WlanOpenHandle = (WlanOpenHandleProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanOpenHandle"); + local_WlanRegisterNotification = (WlanRegisterNotificationProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanRegisterNotification"); + local_WlanEnumInterfaces = (WlanEnumInterfacesProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanEnumInterfaces"); + local_WlanGetAvailableNetworkList = (WlanGetAvailableNetworkListProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanGetAvailableNetworkList"); + local_WlanQueryInterface = (WlanQueryInterfaceProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanQueryInterface"); + local_WlanConnect = (WlanConnectProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanConnect"); + local_WlanDisconnect = (WlanDisconnectProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanDisconnect"); + local_WlanScan = (WlanScanProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanScan"); + local_WlanFreeMemory = (WlanFreeMemoryProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanFreeMemory"); + local_WlanCloseHandle = (WlanCloseHandleProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanCloseHandle"); + + triedResolve = true; + } + } +} + +class QNativeWifiEnginePlugin : public QBearerEnginePlugin +{ +public: + QNativeWifiEnginePlugin(); + ~QNativeWifiEnginePlugin(); + + QStringList keys() const; + QBearerEngine *create(const QString &key) const; +}; + +QNativeWifiEnginePlugin::QNativeWifiEnginePlugin() +{ +} + +QNativeWifiEnginePlugin::~QNativeWifiEnginePlugin() +{ +} + +QStringList QNativeWifiEnginePlugin::keys() const +{ + qDebug() << Q_FUNC_INFO; + + return QStringList() << QLatin1String("nativewifi"); +} + +QBearerEngine *QNativeWifiEnginePlugin::create(const QString &key) const +{ + qDebug() << Q_FUNC_INFO; + + if (key != QLatin1String("nativewifi")) + return 0; + + resolveLibrary(); + + // native wifi dll not available + if (!local_WlanOpenHandle) + return 0; + + QNativeWifiEngine *engine = new QNativeWifiEngine; + + // could not initialise subsystem + if (engine && !engine->available()) { + delete engine; + return 0; + } + + return engine; +} + +Q_EXPORT_STATIC_PLUGIN(QNativeWifiEnginePlugin) +Q_EXPORT_PLUGIN2(qnativewifibearer, QNativeWifiEnginePlugin) + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/nativewifi/nativewifi.pro b/src/plugins/bearer/nativewifi/nativewifi.pro new file mode 100644 index 0000000..3aab552 --- /dev/null +++ b/src/plugins/bearer/nativewifi/nativewifi.pro @@ -0,0 +1,13 @@ +TARGET = qnativewifibearer +include(../../qpluginbase.pri) + +QT += network + +DEFINES += BEARER_ENGINE + +HEADERS += qnativewifiengine.h platformdefs.h +SOURCES += qnativewifiengine.cpp main.cpp + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/bearer +target.path += $$[QT_INSTALL_PLUGINS]/bearer +INSTALLS += target diff --git a/src/plugins/bearer/nativewifi/platformdefs.h b/src/plugins/bearer/nativewifi/platformdefs.h new file mode 100644 index 0000000..38fbae4 --- /dev/null +++ b/src/plugins/bearer/nativewifi/platformdefs.h @@ -0,0 +1,322 @@ +/**************************************************************************** +** +** 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 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 PLATFORMDEFS_H +#define PLATFORMDEFS_H + +#include +#undef interface + +#define WLAN_MAX_NAME_LENGTH 256 +#define WLAN_MAX_PHY_TYPE_NUMBER 8 +#define WLAN_NOTIFICATION_SOURCE_ALL 0x0000ffff +#define WLAN_AVAILABLE_NETWORK_CONNECTED 1 +#define WLAN_AVAILABLE_NETWORK_HAS_PROFILE 2 +#define DOT11_SSID_MAX_LENGTH 32 + +struct WLAN_NOTIFICATION_DATA { + DWORD NotificationSource; + DWORD NotificationCode; + GUID InterfaceGuid; + DWORD dwDataSize; + PVOID pData; +}; + +enum WLAN_INTERFACE_STATE { + wlan_interface_state_not_ready = 0, + wlan_interface_state_connected, + wlan_interface_state_ad_hoc_network_formed, + wlan_interface_state_disconnecting, + wlan_interface_state_disconnected, + wlan_interface_state_associating, + wlan_interface_state_discovering, + wlan_interface_state_authenticating +}; + +struct WLAN_INTERFACE_INFO { + GUID InterfaceGuid; + WCHAR strInterfaceDescription[WLAN_MAX_NAME_LENGTH]; + WLAN_INTERFACE_STATE isState; +}; + +struct WLAN_INTERFACE_INFO_LIST { + DWORD dwNumberOfItems; + DWORD dwIndex; + WLAN_INTERFACE_INFO InterfaceInfo[1]; +}; + +struct DOT11_SSID { + ULONG uSSIDLength; + UCHAR ucSSID[DOT11_SSID_MAX_LENGTH]; +}; + +struct NDIS_OBJECT_HEADER { + UCHAR Type; + UCHAR Revision; + USHORT Size; +}; + +typedef UCHAR DOT11_MAC_ADDRESS[6]; +struct DOT11_BSSID_LIST { + NDIS_OBJECT_HEADER Header; + ULONG uNumberOfEntries; + ULONG uTotalNumOfEntries; + DOT11_MAC_ADDRESS BSSIDs[1]; +}; + +enum DOT11_BSS_TYPE { + dot11_BSS_type_infrastructure = 1, + dot11_BSS_type_independent = 2, + dot11_BSS_type_any = 3 +}; + +enum DOT11_PHY_TYPE { + dot11_phy_type_unknown = 0, + dot11_phy_type_any = dot11_phy_type_unknown, + dot11_phy_type_fhss = 1, + dot11_phy_type_dsss = 2, + dot11_phy_type_irbaseband = 3, + dot11_phy_type_ofdm = 4, + dot11_phy_type_hrdsss = 5, + dot11_phy_type_erp = 6, + dot11_phy_type_ht = 7, + dot11_phy_type_IHV_start = 0x80000000, + dot11_phy_type_IHV_end = 0xffffffff +}; + +enum DOT11_AUTH_ALGORITHM { + DOT11_AUTH_ALGO_80211_OPEN = 1, + DOT11_AUTH_ALGO_80211_SHARED_KEY = 2, + DOT11_AUTH_ALGO_WPA = 3, + DOT11_AUTH_ALGO_WPA_PSK = 4, + DOT11_AUTH_ALGO_WPA_NONE = 5, + DOT11_AUTH_ALGO_RSNA = 6, + DOT11_AUTH_ALGO_RSNA_PSK = 7, + DOT11_AUTH_ALGO_IHV_START = 0x80000000, + DOT11_AUTH_ALGO_IHV_END = 0xffffffff +}; + +enum DOT11_CIPHER_ALGORITHM { + DOT11_CIPHER_ALGO_NONE = 0x00, + DOT11_CIPHER_ALGO_WEP40 = 0x01, + DOT11_CIPHER_ALGO_TKIP = 0x02, + DOT11_CIPHER_ALGO_CCMP = 0x04, + DOT11_CIPHER_ALGO_WEP104 = 0x05, + DOT11_CIPHER_ALGO_WPA_USE_GROUP = 0x100, + DOT11_CIPHER_ALGO_RSN_USE_GROUP = 0x100, + DOT11_CIPHER_ALGO_WEP = 0x101, + DOT11_CIPHER_ALGO_IHV_START = 0x80000000, + DOT11_CIPHER_ALGO_IHV_END = 0xffffffff +}; + +struct WLAN_AVAILABLE_NETWORK { + WCHAR strProfileName[WLAN_MAX_NAME_LENGTH]; + DOT11_SSID dot11Ssid; + DOT11_BSS_TYPE dot11BssType; + ULONG uNumberOfBssids; + BOOL bNetworkConnectable; + DWORD wlanNotConnectableReason; + ULONG uNumberOfPhyTypes; + DOT11_PHY_TYPE dot11PhyTypes[WLAN_MAX_PHY_TYPE_NUMBER]; + BOOL bMorePhyTypes; + ULONG wlanSignalQuality; + BOOL bSecurityEnabled; + DOT11_AUTH_ALGORITHM dot11DefaultAuthAlgorithm; + DOT11_CIPHER_ALGORITHM dot11DefaultCipherAlgorithm; + DWORD dwFlags; + DWORD dwReserved; +}; + +struct WLAN_AVAILABLE_NETWORK_LIST { + DWORD dwNumberOfItems; + DWORD dwIndex; + WLAN_AVAILABLE_NETWORK Network[1]; +}; + +enum WLAN_INTF_OPCODE { + wlan_intf_opcode_autoconf_start = 0x000000000, + wlan_intf_opcode_autoconf_enabled, + wlan_intf_opcode_background_scan_enabled, + wlan_intf_opcode_media_streaming_mode, + wlan_intf_opcode_radio_state, + wlan_intf_opcode_bss_type, + wlan_intf_opcode_interface_state, + wlan_intf_opcode_current_connection, + wlan_intf_opcode_channel_number, + wlan_intf_opcode_supported_infrastructure_auth_cipher_pairs, + wlan_intf_opcode_supported_adhoc_auth_cipher_pairs, + wlan_intf_opcode_supported_country_or_region_string_list, + wlan_intf_opcode_current_operation_mode, + wlan_intf_opcode_supported_safe_mode, + wlan_intf_opcode_certified_safe_mode, + wlan_intf_opcode_autoconf_end = 0x0fffffff, + wlan_intf_opcode_msm_start = 0x10000100, + wlan_intf_opcode_statistics, + wlan_intf_opcode_rssi, + wlan_intf_opcode_msm_end = 0x1fffffff, + wlan_intf_opcode_security_start = 0x20010000, + wlan_intf_opcode_security_end = 0x2fffffff, + wlan_intf_opcode_ihv_start = 0x30000000, + wlan_intf_opcode_ihv_end = 0x3fffffff +}; + +enum WLAN_OPCODE_VALUE_TYPE { + wlan_opcode_value_type_query_only = 0, + wlan_opcode_value_type_set_by_group_policy, + wlan_opcode_value_type_set_by_user, + wlan_opcode_value_type_invalid +}; + +enum WLAN_CONNECTION_MODE { + wlan_connection_mode_profile = 0, + wlan_connection_mode_temporary_profile, + wlan_connection_mode_discovery_secure, + wlan_connection_mode_discovery_unsecure, + wlan_connection_mode_auto, + wlan_connection_mode_invalid +}; + +struct WLAN_CONNECTION_PARAMETERS { + WLAN_CONNECTION_MODE wlanConnectionMode; + LPCWSTR strProfile; + DOT11_SSID *pDot11Ssid; + DOT11_BSSID_LIST *pDesiredBssidList; + DOT11_BSS_TYPE dot11BssType; + DWORD dwFlags; +}; + +struct WLAN_RAW_DATA { + DWORD dwDataSize; + BYTE DataBlob[1]; +}; + +enum WLAN_NOTIFICATION_ACM { + wlan_notification_acm_start = 0, + wlan_notification_acm_autoconf_enabled, + wlan_notification_acm_autoconf_disabled, + wlan_notification_acm_background_scan_enabled, + wlan_notification_acm_background_scan_disabled, + wlan_notification_acm_bss_type_change, + wlan_notification_acm_power_setting_change, + wlan_notification_acm_scan_complete, + wlan_notification_acm_scan_fail, + wlan_notification_acm_connection_start, + wlan_notification_acm_connection_complete, + wlan_notification_acm_connection_attempt_fail, + wlan_notification_acm_filter_list_change, + wlan_notification_acm_interface_arrival, + wlan_notification_acm_interface_removal, + wlan_notification_acm_profile_change, + wlan_notification_acm_profile_name_change, + wlan_notification_acm_profiles_exhausted, + wlan_notification_acm_network_not_available, + wlan_notification_acm_network_available, + wlan_notification_acm_disconnecting, + wlan_notification_acm_disconnected, + wlan_notification_acm_adhoc_network_state_change, + wlan_notification_acm_end +}; + +struct WLAN_ASSOCIATION_ATTRIBUTES { + DOT11_SSID dot11Ssid; + DOT11_BSS_TYPE dot11BssType; + DOT11_MAC_ADDRESS dot11Bssid; + DOT11_PHY_TYPE dot11PhyType; + ULONG uDot11PhyIndex; + ULONG wlanSignalQuality; + ULONG ulRxRate; + ULONG ulTxRate; +}; + +struct WLAN_SECURITY_ATTRIBUTES { + BOOL bSecurityEnabled; + BOOL bOneXEnabled; + DOT11_AUTH_ALGORITHM dot11AuthAlgorithm; + DOT11_CIPHER_ALGORITHM dot11CipherAlgorithm; +}; + +struct WLAN_CONNECTION_ATTRIBUTES { + WLAN_INTERFACE_STATE isState; + WLAN_CONNECTION_MODE wlanConnectionMode; + WCHAR strProfileName[WLAN_MAX_NAME_LENGTH]; + WLAN_ASSOCIATION_ATTRIBUTES wlanAssociationAttributes; + WLAN_SECURITY_ATTRIBUTES wlanSecurityAttributes; +}; + +typedef void (WINAPI *WLAN_NOTIFICATION_CALLBACK)(WLAN_NOTIFICATION_DATA *, PVOID); + +typedef DWORD (WINAPI *WlanOpenHandleProto) + (DWORD dwClientVersion, PVOID pReserved, PDWORD pdwNegotiatedVersion, PHANDLE phClientHandle); +typedef DWORD (WINAPI *WlanRegisterNotificationProto) + (HANDLE hClientHandle, DWORD dwNotifSource, BOOL bIgnoreDuplicate, + WLAN_NOTIFICATION_CALLBACK funcCallback, PVOID pCallbackContext, + PVOID pReserved, PDWORD pdwPrevNotifSource); +typedef DWORD (WINAPI *WlanEnumInterfacesProto) + (HANDLE hClientHandle, PVOID pReserved, WLAN_INTERFACE_INFO_LIST **ppInterfaceList); +typedef DWORD (WINAPI *WlanGetAvailableNetworkListProto) + (HANDLE hClientHandle, const GUID* pInterfaceGuid, DWORD dwFlags, PVOID pReserved, + WLAN_AVAILABLE_NETWORK_LIST **ppAvailableNetworkList); +typedef DWORD (WINAPI *WlanQueryInterfaceProto) + (HANDLE hClientHandle, const GUID *pInterfaceGuid, WLAN_INTF_OPCODE OpCode, PVOID pReserved, + PDWORD pdwDataSize, PVOID *ppData, WLAN_OPCODE_VALUE_TYPE *pWlanOpcodeValueType); +typedef DWORD (WINAPI *WlanConnectProto) + (HANDLE hClientHandle, const GUID *pInterfaceGuid, + const WLAN_CONNECTION_PARAMETERS *pConnectionParameters, PVOID pReserved); +typedef DWORD (WINAPI *WlanDisconnectProto) + (HANDLE hClientHandle, const GUID *pInterfaceGuid, PVOID pReserved); +typedef DWORD (WINAPI *WlanScanProto) + (HANDLE hClientHandle, const GUID *pInterfaceGuid, const DOT11_SSID *pDot11Ssid, + const WLAN_RAW_DATA *pIeData, PVOID pReserved); +typedef VOID (WINAPI *WlanFreeMemoryProto)(PVOID pMemory); +typedef DWORD (WINAPI *WlanCloseHandleProto)(HANDLE hClientHandle, PVOID pReserved); + +extern WlanOpenHandleProto local_WlanOpenHandle; +extern WlanRegisterNotificationProto local_WlanRegisterNotification; +extern WlanEnumInterfacesProto local_WlanEnumInterfaces; +extern WlanGetAvailableNetworkListProto local_WlanGetAvailableNetworkList; +extern WlanQueryInterfaceProto local_WlanQueryInterface; +extern WlanConnectProto local_WlanConnect; +extern WlanDisconnectProto local_WlanDisconnect; +extern WlanScanProto local_WlanScan; +extern WlanFreeMemoryProto local_WlanFreeMemory; +extern WlanCloseHandleProto local_WlanCloseHandle; + +#endif // PLATFORMDEFS_H diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp new file mode 100644 index 0000000..5ca49a9 --- /dev/null +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp @@ -0,0 +1,406 @@ +/**************************************************************************** +** +** 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 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 "qnativewifiengine.h" +#include "platformdefs.h" + +#include + +#include + +#include + +QT_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC(QNativeWifiEngine, nativeWifiEngine) + +WlanOpenHandleProto local_WlanOpenHandle = 0; +WlanRegisterNotificationProto local_WlanRegisterNotification = 0; +WlanEnumInterfacesProto local_WlanEnumInterfaces = 0; +WlanGetAvailableNetworkListProto local_WlanGetAvailableNetworkList = 0; +WlanQueryInterfaceProto local_WlanQueryInterface = 0; +WlanConnectProto local_WlanConnect = 0; +WlanDisconnectProto local_WlanDisconnect = 0; +WlanScanProto local_WlanScan = 0; +WlanFreeMemoryProto local_WlanFreeMemory = 0; +WlanCloseHandleProto local_WlanCloseHandle = 0; + + + +void qNotificationCallback(WLAN_NOTIFICATION_DATA *data, QNativeWifiEngine *d) +{ + Q_UNUSED(d); + + switch (data->NotificationCode) { + case wlan_notification_acm_connection_complete: + case wlan_notification_acm_disconnected: + d->emitConfigurationsChanged(); + break; + default: + qDebug() << "wlan unknown notification"; + } +} + +QNativeWifiEngine::QNativeWifiEngine(QObject *parent) +: QNetworkSessionEngine(parent), handle(0) +{ + DWORD clientVersion; + + DWORD result = local_WlanOpenHandle(1, 0, &clientVersion, &handle); + if (result != ERROR_SUCCESS) { + if (result != ERROR_SERVICE_NOT_ACTIVE) + qWarning("%s: WlanOpenHandle failed with error %ld\n", __FUNCTION__, result); + + return; + } + + result = local_WlanRegisterNotification(handle, WLAN_NOTIFICATION_SOURCE_ALL, true, + WLAN_NOTIFICATION_CALLBACK(qNotificationCallback), + this, 0, 0); + if (result != ERROR_SUCCESS) + qWarning("%s: WlanRegisterNotification failed with error %ld\n", __FUNCTION__, result); + + // On Windows XP SP2 and SP3 only connection and disconnection notifications are available. + // We need to poll for changes in available wireless networks. + connect(&pollTimer, SIGNAL(timeout()), this, SIGNAL(configurationsChanged())); + pollTimer.setInterval(10000); +} + +QNativeWifiEngine::~QNativeWifiEngine() +{ + local_WlanCloseHandle(handle, 0); +} + +QList QNativeWifiEngine::getConfigurations(bool *ok) +{ + if (ok) + *ok = false; + + QList foundConfigurations; + + // enumerate interfaces + WLAN_INTERFACE_INFO_LIST *interfaceList; + DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); + return foundConfigurations; + } + + for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { + const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i]; + + WLAN_AVAILABLE_NETWORK_LIST *networkList; + result = local_WlanGetAvailableNetworkList(handle, &interface.InterfaceGuid, + 3, 0, &networkList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanGetAvailableNetworkList failed with error %ld\n", + __FUNCTION__, result); + continue; + } + + QStringList seenNetworks; + + for (unsigned int j = 0; j < networkList->dwNumberOfItems; ++j) { + WLAN_AVAILABLE_NETWORK &network = networkList->Network[j]; + + QString networkName; + + if (network.strProfileName[0] != 0) { + networkName = QString::fromWCharArray(network.strProfileName); + } else { + networkName = QByteArray(reinterpret_cast(network.dot11Ssid.ucSSID), + network.dot11Ssid.uSSIDLength); + } + + // don't add duplicate networks + if (seenNetworks.contains(networkName)) + continue; + else + seenNetworks.append(networkName); + + QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; + + cpPriv->isValid = true; + + cpPriv->name = networkName; + cpPriv->id = QString::number(qHash(QLatin1String("WLAN:") + cpPriv->name)); + + if (!(network.dwFlags & WLAN_AVAILABLE_NETWORK_HAS_PROFILE)) + cpPriv->state = QNetworkConfiguration::Undefined; + + if (network.strProfileName[0] != 0) { + if (network.bNetworkConnectable) { + if (network.dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED) + cpPriv->state = QNetworkConfiguration::Active; + else + cpPriv->state = QNetworkConfiguration::Discovered; + } else { + cpPriv->state = QNetworkConfiguration::Defined; + } + } + + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + + foundConfigurations.append(cpPriv); + } + + local_WlanFreeMemory(networkList); + } + + local_WlanFreeMemory(interfaceList); + + if (ok) + *ok = true; + + pollTimer.start(); + + return foundConfigurations; +} + +QString QNativeWifiEngine::getInterfaceFromId(const QString &id) +{ + // enumerate interfaces + WLAN_INTERFACE_INFO_LIST *interfaceList; + DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); + return QString(); + } + + for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { + const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i]; + + DWORD dataSize; + WLAN_CONNECTION_ATTRIBUTES *connectionAttributes; + result = local_WlanQueryInterface(handle, &interface.InterfaceGuid, + wlan_intf_opcode_current_connection, 0, &dataSize, + reinterpret_cast(&connectionAttributes), 0); + if (result != ERROR_SUCCESS) { + if (result != ERROR_INVALID_STATE) + qWarning("%s: WlanQueryInterface failed with error %ld\n", __FUNCTION__, result); + + continue; + } + + if (qHash(QLatin1String("WLAN:") + + QString::fromWCharArray(connectionAttributes->strProfileName)) == id.toUInt()) { + QString guid("{%1-%2-%3-%4%5-%6%7%8%9%10%11}"); + + guid = guid.arg(interface.InterfaceGuid.Data1, 8, 16, QChar('0')); + guid = guid.arg(interface.InterfaceGuid.Data2, 4, 16, QChar('0')); + guid = guid.arg(interface.InterfaceGuid.Data3, 4, 16, QChar('0')); + for (int i = 0; i < 8; ++i) + guid = guid.arg(interface.InterfaceGuid.Data4[i], 2, 16, QChar('0')); + + local_WlanFreeMemory(connectionAttributes); + + return guid.toUpper(); + } + + local_WlanFreeMemory(connectionAttributes); + } + + return QString(); +} + +bool QNativeWifiEngine::hasIdentifier(const QString &id) +{ + // enumerate interfaces + WLAN_INTERFACE_INFO_LIST *interfaceList; + DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); + return false; + } + + for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { + const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i]; + + WLAN_AVAILABLE_NETWORK_LIST *networkList; + result = local_WlanGetAvailableNetworkList(handle, &interface.InterfaceGuid, + 3, 0, &networkList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanGetAvailableNetworkList failed with error %ld\n", + __FUNCTION__, result); + continue; + } + + for (unsigned int j = 0; j < networkList->dwNumberOfItems; ++j) { + WLAN_AVAILABLE_NETWORK &network = networkList->Network[j]; + + QString networkName; + + if (network.strProfileName[0] != 0) { + networkName = QString::fromWCharArray(network.strProfileName); + } else { + networkName = QByteArray(reinterpret_cast(network.dot11Ssid.ucSSID), + network.dot11Ssid.uSSIDLength); + } + + if (qHash(QLatin1String("WLAN:") + networkName) == id.toUInt()) { + local_WlanFreeMemory(networkList); + local_WlanFreeMemory(interfaceList); + return true; + } + } + + local_WlanFreeMemory(networkList); + } + + local_WlanFreeMemory(interfaceList); + + return false; +} + +QString QNativeWifiEngine::bearerName(const QString &) +{ + return QLatin1String("WLAN"); +} + +void QNativeWifiEngine::connectToId(const QString &id) +{ + WLAN_INTERFACE_INFO_LIST *interfaceList; + DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); + emit connectionError(id, InterfaceLookupError); + return; + } + + QString profile; + + for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { + const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i]; + + WLAN_AVAILABLE_NETWORK_LIST *networkList; + result = local_WlanGetAvailableNetworkList(handle, &interface.InterfaceGuid, + 3, 0, &networkList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanGetAvailableNetworkList failed with error %ld\n", + __FUNCTION__, result); + continue; + } + + for (unsigned int j = 0; j < networkList->dwNumberOfItems; ++j) { + WLAN_AVAILABLE_NETWORK &network = networkList->Network[j]; + + profile = QString::fromWCharArray(network.strProfileName); + + if (qHash(QLatin1String("WLAN:") + profile) == id.toUInt()) + break; + else + profile.clear(); + } + + local_WlanFreeMemory(networkList); + + if (!profile.isEmpty()) { + WLAN_CONNECTION_PARAMETERS parameters; + parameters.wlanConnectionMode = wlan_connection_mode_profile; + parameters.strProfile = reinterpret_cast(profile.utf16()); + parameters.pDot11Ssid = 0; + parameters.pDesiredBssidList = 0; + parameters.dot11BssType = dot11_BSS_type_any; + parameters.dwFlags = 0; + + DWORD result = local_WlanConnect(handle, &interface.InterfaceGuid, ¶meters, 0); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanConnect failed with error %ld\n", __FUNCTION__, result); + emit connectionError(id, ConnectError); + break; + } + + break; + } + } + + local_WlanFreeMemory(interfaceList); + + if (profile.isEmpty()) + emit connectionError(id, InterfaceLookupError); +} + +void QNativeWifiEngine::disconnectFromId(const QString &id) +{ + QString interface = getInterfaceFromId(id); + + if (interface.isEmpty()) { + emit connectionError(id, InterfaceLookupError); + return; + } + + QStringList split = interface.mid(1, interface.length() - 2).split('-'); + + GUID guid; + guid.Data1 = split.at(0).toUInt(0, 16); + guid.Data2 = split.at(1).toUShort(0, 16); + guid.Data3 = split.at(2).toUShort(0, 16); + guid.Data4[0] = split.at(3).left(2).toUShort(0, 16); + guid.Data4[1] = split.at(3).right(2).toUShort(0, 16); + for (int i = 0; i < 6; ++i) + guid.Data4[i + 2] = split.at(4).mid(i*2, 2).toUShort(0, 16); + + DWORD result = local_WlanDisconnect(handle, &guid, 0); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanDisconnect failed with error %ld\n", __FUNCTION__, result); + emit connectionError(id, DisconnectionError); + return; + } +} + +void QNativeWifiEngine::requestUpdate() +{ + // enumerate interfaces + WLAN_INTERFACE_INFO_LIST *interfaceList; + DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); + return; + } + + for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { + result = local_WlanScan(handle, &interfaceList->InterfaceInfo[i].InterfaceGuid, 0, 0, 0); + if (result != ERROR_SUCCESS) + qWarning("%s: WlanScan failed with error %ld\n", __FUNCTION__, result); + } +} + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.h b/src/plugins/bearer/nativewifi/qnativewifiengine.h new file mode 100644 index 0000000..6686ea8 --- /dev/null +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.h @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** 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 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 QNATIVEWIFIENGINE_P_H +#define QNATIVEWIFIENGINE_P_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 + +#include + +QT_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; + +class QNativeWifiEngine : public QNetworkSessionEngine +{ + Q_OBJECT + +public: + QNativeWifiEngine(QObject *parent = 0); + ~QNativeWifiEngine(); + + QList getConfigurations(bool *ok = 0); + QString getInterfaceFromId(const QString &id); + bool hasIdentifier(const QString &id); + + QString bearerName(const QString &id); + + void connectToId(const QString &id); + void disconnectFromId(const QString &id); + + void requestUpdate(); + + inline void emitConfigurationsChanged() { emit configurationsChanged(); } + + inline bool available() const { return handle != 0; } + +private: + QTimer pollTimer; + + Qt::HANDLE handle; +}; + +QT_END_NAMESPACE + +#endif -- cgit v0.12 From 33934fc640c8f7cad0841ab2ae9c1ec22fd09654 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 3 Dec 2009 15:38:14 +1000 Subject: Fix license headers. --- src/network/bearer/qcorewlanengine_mac.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/bearer/qcorewlanengine_mac.mm b/src/network/bearer/qcorewlanengine_mac.mm index 5854384..2455f86 100644 --- a/src/network/bearer/qcorewlanengine_mac.mm +++ b/src/network/bearer/qcorewlanengine_mac.mm @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage -- cgit v0.12 From a28dff36ae1e25be3748b2c26dcbb5b7b4ea6100 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 3 Dec 2009 15:42:07 +1000 Subject: Update license headers. --- src/plugins/bearer/nla/qnlaengine.cpp | 2 +- src/plugins/bearer/nla/qnlaengine.h | 2 +- src/plugins/bearer/platformdefs_win.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/bearer/nla/qnlaengine.cpp b/src/plugins/bearer/nla/qnlaengine.cpp index 527776f..2ad9cac 100644 --- a/src/plugins/bearer/nla/qnlaengine.cpp +++ b/src/plugins/bearer/nla/qnlaengine.cpp @@ -4,7 +4,7 @@ ** 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 diff --git a/src/plugins/bearer/nla/qnlaengine.h b/src/plugins/bearer/nla/qnlaengine.h index 76505fb..1e66c83 100644 --- a/src/plugins/bearer/nla/qnlaengine.h +++ b/src/plugins/bearer/nla/qnlaengine.h @@ -4,7 +4,7 @@ ** 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 diff --git a/src/plugins/bearer/platformdefs_win.h b/src/plugins/bearer/platformdefs_win.h index 133b7b1..f2f44a1 100644 --- a/src/plugins/bearer/platformdefs_win.h +++ b/src/plugins/bearer/platformdefs_win.h @@ -4,7 +4,7 @@ ** 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 -- cgit v0.12 From 13a519ce2d85ee006f2a30a50029195465249b01 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 3 Dec 2009 15:44:21 +1000 Subject: Update license headers. --- tests/auto/qbearertestcommon.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/qbearertestcommon.h b/tests/auto/qbearertestcommon.h index 3356bd6..0bfe622 100644 --- a/tests/auto/qbearertestcommon.h +++ b/tests/auto/qbearertestcommon.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage -- cgit v0.12 From 0bcb2788e1eb225e0e3babb4ca113bcb5769dfc2 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 3 Dec 2009 14:55:23 +1000 Subject: Add config.test for CoreWlan. Untested, I don't have a mac. --- config.tests/mac/corewlan/corewlan.pro | 3 ++ config.tests/mac/corewlan/corewlantest.mm | 49 +++++++++++++++++++++++++++++++ configure | 15 ++++++++++ 3 files changed, 67 insertions(+) create mode 100644 config.tests/mac/corewlan/corewlan.pro create mode 100644 config.tests/mac/corewlan/corewlantest.mm diff --git a/config.tests/mac/corewlan/corewlan.pro b/config.tests/mac/corewlan/corewlan.pro new file mode 100644 index 0000000..8451af3 --- /dev/null +++ b/config.tests/mac/corewlan/corewlan.pro @@ -0,0 +1,3 @@ +SOURCES = corewlantest.mm +LIBS += -framework CoreWLAN -framework Foundation +CONFIG -= app_bundle qt diff --git a/config.tests/mac/corewlan/corewlantest.mm b/config.tests/mac/corewlan/corewlantest.mm new file mode 100644 index 0000000..3a29d84 --- /dev/null +++ b/config.tests/mac/corewlan/corewlantest.mm @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** 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 config.tests 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 +#include + +int main() +{ + [CWInterface interfaceWithName:@"en2"]; + return 0; +} diff --git a/configure b/configure index dcd7d2d..b686081 100755 --- a/configure +++ b/configure @@ -766,6 +766,7 @@ CFG_SILENT=no CFG_GRAPHICS_SYSTEM=default CFG_ALSA=auto CFG_NETWORKMANAGER=auto +CFG_COREWLAN=auto # initalize variables used for installation QT_INSTALL_PREFIX= @@ -5365,6 +5366,14 @@ if [ "$PLATFORM_MAC" = "yes" ]; then # Always enable Phonon (unless it was explicitly disabled) CFG_PHONON=yes fi + + if [ "$CFG_COREWLAN" = "auto" ]; then + if "$unixtests/compile.test" "$XQMAKESPEC" "$QMAKE_CONFIG" $OPT_VERBOSE "$relpath" "$outpath" config.tests/mac/corewlan "CoreWlan" $L_FLAGS $I_FLAGS $l_FLAGS; then + CFG_COREWLAN=yes + else + CFG_COREWLAN=no + fi + fi fi # QWS @@ -6310,6 +6319,10 @@ if [ "$CFG_NETWORKMANAGER" = "yes" ]; then QT_CONFIG="$QT_CONFIG networkmanager" fi +if [ "$CFG_COREWLAN" = "yes" ]; then + QT_CONFIG="$QT_CONFIG corewlan" +fi + # # Some Qt modules are too advanced in C++ for some old compilers # Detect here the platforms where they are known to work. @@ -7011,6 +7024,7 @@ fi [ "$CFG_XINPUT" = "runtime" ] && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_RUNTIME_XINPUT" [ "$CFG_ALSA" = "no" ] && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_ALSA" [ "$CFG_NETWORKMANAGER" = "no" ] && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_NETWORKMANAGER" +[ "$CFG_COREWLAN" = "no" ] && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_COREWLAN" # sort QCONFIG_FLAGS for neatness if we can [ '!' -z "$AWK" ] && QCONFIG_FLAGS=`echo $QCONFIG_FLAGS | $AWK '{ gsub(" ", "\n"); print }' | sort | uniq` @@ -7537,6 +7551,7 @@ if [ "$PLATFORM_MAC" = "yes" ] && [ "$CFG_FRAMEWORK" = "yes" ] && [ "$CFG_DEBUG" fi echo "alsa support ........... $CFG_ALSA" echo "NetworkManager support . $CFG_NETWORKMANAGER" +echo "CoreWlan support ....... $CFG_COREWLAN" echo sepath=`echo "$relpath" | sed -e 's/\\./\\\\./g'` -- cgit v0.12 From f7eb78d6b7cc0e07275ab64bec2743c5b2c0705f Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 3 Dec 2009 15:00:24 +1000 Subject: Convert CoreWlan engine into a plugin. --- src/network/bearer/bearer.pri | 13 - src/network/bearer/qcorewlanengine_mac.mm | 461 ------------------------- src/network/bearer/qcorewlanengine_mac_p.h | 101 ------ src/network/bearer/qnetworkconfigmanager_p.cpp | 23 +- src/network/bearer/qnetworkconfigmanager_p.h | 2 +- src/network/bearer/qnetworksession_p.cpp | 13 - src/plugins/bearer/bearer.pro | 1 + src/plugins/bearer/corewlan/corewlan.pro | 21 ++ src/plugins/bearer/corewlan/main.cpp | 88 +++++ src/plugins/bearer/corewlan/qcorewlanengine.h | 91 +++++ src/plugins/bearer/corewlan/qcorewlanengine.mm | 459 ++++++++++++++++++++++++ 11 files changed, 672 insertions(+), 601 deletions(-) delete mode 100644 src/network/bearer/qcorewlanengine_mac.mm delete mode 100644 src/network/bearer/qcorewlanengine_mac_p.h create mode 100644 src/plugins/bearer/corewlan/corewlan.pro create mode 100644 src/plugins/bearer/corewlan/main.cpp create mode 100644 src/plugins/bearer/corewlan/qcorewlanengine.h create mode 100644 src/plugins/bearer/corewlan/qcorewlanengine.mm diff --git a/src/network/bearer/bearer.pri b/src/network/bearer/bearer.pri index 9476239..5bae333 100644 --- a/src/network/bearer/bearer.pri +++ b/src/network/bearer/bearer.pri @@ -81,18 +81,5 @@ symbian { bearer/qnetworksessionengine.cpp contains(QT_CONFIG, networkmanager):DEFINES += BACKEND_NM - - macx { - HEADERS += bearer/qcorewlanengine_mac_p.h - SOURCES+= bearer/qcorewlanengine_mac.mm - LIBS += -framework Foundation -framework SystemConfiguration - - contains(corewlan_enabled, yes) { - isEmpty(QMAKE_MAC_SDK)|contains(QMAKE_MAC_SDK, "/Developer/SDKs/MacOSX10.6.sdk") { - LIBS += -framework CoreWLAN - DEFINES += MAC_SDK_10_6 - } - } - } } diff --git a/src/network/bearer/qcorewlanengine_mac.mm b/src/network/bearer/qcorewlanengine_mac.mm deleted file mode 100644 index 2455f86..0000000 --- a/src/network/bearer/qcorewlanengine_mac.mm +++ /dev/null @@ -1,461 +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 "qcorewlanengine_mac_p.h" -#include "qnetworkconfiguration_p.h" - -#include -#include -#include -#include - -#include - -#if defined(MAC_SDK_10_6) //not much functionality without this -#include -#include -#include -#include -#endif - -#include -#include -#include - -#include -QMap networkInterfaces; - -QT_BEGIN_NAMESPACE - -Q_GLOBAL_STATIC(QCoreWlanEngine, coreWlanEngine) - -inline QString cfstringRefToQstring(CFStringRef cfStringRef) { -// return QString([cfStringRef UTF8String]); - QString retVal; - CFIndex maxLength = 2 * CFStringGetLength(cfStringRef) + 1/*zero term*/; // max UTF8 - char *cstring = new char[maxLength]; - if (CFStringGetCString(CFStringRef(cfStringRef), cstring, maxLength, kCFStringEncodingUTF8)) { - retVal = QString::fromUtf8(cstring); - } - delete cstring; - return retVal; -} - -inline CFStringRef qstringToCFStringRef(const QString &string) -{ - return CFStringCreateWithCharacters(0, reinterpret_cast(string.unicode()), - string.length()); -} - -inline NSString *qstringToNSString(const QString &qstr) -{ return [reinterpret_cast(qstringToCFStringRef(qstr)) autorelease]; } - -inline QString nsstringToQString(const NSString *nsstr) -{ return cfstringRefToQstring(reinterpret_cast(nsstr)); } - -inline QStringList nsarrayToQStringList(void *nsarray) -{ - QStringList result; - NSArray *array = static_cast(nsarray); - for (NSUInteger i=0; i<[array count]; ++i) - result << nsstringToQString([array objectAtIndex:i]); - return result; -} - -static QString qGetInterfaceType(const QString &interfaceString) -{ - return networkInterfaces.value(interfaceString); -} - -QCoreWlanEngine::QCoreWlanEngine(QObject *parent) -: QNetworkSessionEngine(parent) -{ - getAllScInterfaces(); - connect(&pollTimer, SIGNAL(timeout()), this, SIGNAL(configurationsChanged())); - pollTimer.setInterval(10000); -} - -QCoreWlanEngine::~QCoreWlanEngine() -{ -} - -QList QCoreWlanEngine::getWifiConfigurations() -{ - QMapIterator i(networkInterfaces); - while (i.hasNext()) { - i.next(); - QString interfaceName = i.key(); - if (i.value() == "WLAN") { - if(!isWifiReady(interfaceName)) { - qWarning() << "wifi not powered on"; - return QList(); - } else { - // QList profs = getWlanProfiles(interfaceName); - scanForSsids(interfaceName); - } - } else { - - } - } - return QList (); -} - -QList QCoreWlanEngine::getConfigurations(bool *ok) -{ - if (ok) - *ok = true; - NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; - - QList foundConfigurations; - QList wificonfigs = getWifiConfigurations(); - - uint identifier; - QMapIterator i(networkInterfaces); - while (i.hasNext()) { - i.next(); - if (i.value() == "WLAN") { - QList fetchedConfigurations = scanForSsids(i.key()); - for (int i = 0; i < fetchedConfigurations.count(); ++i) { - - QNetworkConfigurationPrivate *config = new QNetworkConfigurationPrivate; - config->name = fetchedConfigurations.at(i)->name; - config->isValid = fetchedConfigurations.at(i)->isValid; - config->id = fetchedConfigurations.at(i)->id; - - config->state = fetchedConfigurations.at(i)->state; - config->type = fetchedConfigurations.at(i)->type; - config->roamingSupported = fetchedConfigurations.at(i)->roamingSupported; - config->purpose = fetchedConfigurations.at(i)->purpose; - config->internet = fetchedConfigurations.at(i)->internet; - config->serviceInterface = fetchedConfigurations.at(i)->serviceInterface; - - identifier = config->name.toUInt(); - configurationInterface[identifier] = config->serviceInterface.name(); - foundConfigurations.append(config); - } - } - - QNetworkInterface interface = QNetworkInterface::interfaceFromName(i.key()); - QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; - const QString humanReadableName = interface.humanReadableName(); - cpPriv->name = humanReadableName.isEmpty() ? interface.name() : humanReadableName; - cpPriv->isValid = true; - - if (interface.index()) - identifier = interface.index(); - else - identifier = qHash(interface.hardwareAddress()); - - cpPriv->id = QString::number(identifier); - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - cpPriv->state = QNetworkConfiguration::Undefined; - - if (interface.flags() & QNetworkInterface::IsRunning) { - cpPriv->state = QNetworkConfiguration::Defined; - cpPriv->internet = true; - } - if ( !interface.addressEntries().isEmpty()) { - cpPriv->state |= QNetworkConfiguration::Active; - cpPriv->internet = true; - } - configurationInterface[identifier] = interface.name(); - foundConfigurations.append(cpPriv); - } - [autoreleasepool release]; - pollTimer.start(); - return foundConfigurations; -} - -QString QCoreWlanEngine::getInterfaceFromId(const QString &id) -{ - return configurationInterface.value(id.toUInt()); -} - -bool QCoreWlanEngine::hasIdentifier(const QString &id) -{ - return configurationInterface.contains(id.toUInt()); -} - -QString QCoreWlanEngine::bearerName(const QString &id) -{ - QString interface = getInterfaceFromId(id); - - if (interface.isEmpty()) - return QString(); - - return qGetInterfaceType(interface); -} - -void QCoreWlanEngine::connectToId(const QString &id) -{ - NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; - QString interfaceString = getInterfaceFromId(id); - - if(networkInterfaces.value(interfaceString) == "WLAN") { -#if defined(MAC_SDK_10_6) - CWInterface *wifiInterface = [CWInterface interfaceWithName: qstringToNSString(interfaceString)]; - CWConfiguration *userConfig = [ wifiInterface configuration]; - - NSSet *remNets = [userConfig rememberedNetworks]; //CWWirelessProfile - - NSEnumerator *enumerator = [remNets objectEnumerator]; - CWWirelessProfile *wProfile; - NSUInteger index=0; - while ((wProfile = [enumerator nextObject])) { //CWWirelessProfile - - if(id == nsstringToQString([wProfile ssid])) { - CW8021XProfile *user8021XProfile = nil; - user8021XProfile = [ wProfile user8021XProfile]; - - NSError *err = nil; - NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0]; - - if(user8021XProfile) { - [params setValue: user8021XProfile forKey:kCWAssocKey8021XProfile]; - } else { - [params setValue: [wProfile passphrase] forKey: kCWAssocKeyPassphrase]; - } - - NSDictionary *parametersDict = nil; - NSArray* apArray = [NSMutableArray arrayWithArray:[wifiInterface scanForNetworksWithParameters:parametersDict error:&err]]; - if(!err) { - for(uint row=0; row < [apArray count]; row++ ) { - CWNetwork *apNetwork = [apArray objectAtIndex:row]; - if([[apNetwork ssid] compare:[wProfile ssid]] == NSOrderedSame) { - bool result = [wifiInterface associateToNetwork: apNetwork parameters:[NSDictionary dictionaryWithDictionary:params] error:&err]; - if(!result) { - qWarning() <<"ERROR"<< nsstringToQString([err localizedDescription ]); - emit connectionError(id, ConnectError); - } else { - [autoreleasepool release]; - return; - } - } - } - } - } - index++; - } - emit connectionError(id, InterfaceLookupError); -#endif - } else { - // not wifi - } - emit connectionError(id, OperationNotSupported); - [autoreleasepool release]; -} - -void QCoreWlanEngine::disconnectFromId(const QString &id) -{ - QString interfaceString = getInterfaceFromId(id); - if(networkInterfaces.value(getInterfaceFromId(id)) == "WLAN") { //wifi only for now -#if defined(MAC_SDK_10_6) - NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; - CWInterface *wifiInterface = [CWInterface interfaceWithName: qstringToNSString(interfaceString)]; - [wifiInterface disassociate]; - if([[wifiInterface interfaceState]intValue] != kCWInterfaceStateInactive) { - emit connectionError(id, DisconnectionError); - } - [autoreleasepool release]; - return; -#endif - } else { - - } - emit connectionError(id, OperationNotSupported); -} - -void QCoreWlanEngine::requestUpdate() -{ - getAllScInterfaces(); - emit configurationsChanged(); -} - -QCoreWlanEngine *QCoreWlanEngine::instance() -{ - return coreWlanEngine(); -} - -QList QCoreWlanEngine::scanForSsids(const QString &interfaceName) -{ - QList foundConfigs; -#if defined(MAC_SDK_10_6) - NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; - - CWInterface *currentInterface = [CWInterface interfaceWithName:qstringToNSString(interfaceName)]; - NSError *err = nil; - NSDictionary *parametersDict = nil; - NSArray* apArray = [NSMutableArray arrayWithArray:[currentInterface scanForNetworksWithParameters:parametersDict error:&err]]; - - if(!err) { - for(uint row=0; row < [apArray count]; row++ ) { - CWNetwork *apNetwork = [apArray objectAtIndex:row]; - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - QString networkSsid = nsstringToQString([apNetwork ssid]); - cpPriv->name = networkSsid; - cpPriv->isValid = true; - cpPriv->id = networkSsid; - cpPriv->internet = true; - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - cpPriv->serviceInterface = QNetworkInterface::interfaceFromName(nsstringToQString([[CWInterface interface] name])); - - CWWirelessProfile *networkProfile = apNetwork.wirelessProfile; - CW8021XProfile *userNetworkProfile = networkProfile.user8021XProfile; - if(!userNetworkProfile) { - } else { - qWarning() <<"Has profile!" ; - } - - if( [currentInterface.interfaceState intValue] == kCWInterfaceStateRunning) { - QString interfaceSsidString = nsstringToQString( [currentInterface ssid]); - if( cpPriv->name == interfaceSsidString) { - cpPriv->state |= QNetworkConfiguration::Active; - } - } else { - if(isKnownSsid(cpPriv->serviceInterface.name(), networkSsid)) { - cpPriv->state = QNetworkConfiguration::Discovered; - } else { - cpPriv->state = QNetworkConfiguration::Defined; - } - } - if(!cpPriv->state) { - cpPriv->state = QNetworkConfiguration::Undefined; - } - if([[apNetwork securityMode ] intValue]== kCWSecurityModeOpen) - cpPriv->purpose = QNetworkConfiguration::PublicPurpose; - else - cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; - foundConfigs.append(cpPriv); - } - } else { - qWarning() << "ERROR scanning for ssids" << nsstringToQString([err localizedDescription]) - < QCoreWlanEngine::getWlanProfiles(const QString &interfaceName) -{ - Q_UNUSED(interfaceName) -#if defined(MAC_SDK_10_6) -// for( CW8021XProfile *each8021XProfile in [CW8021XProfile allUser8021XProfiles] ) { -// qWarning() << "Profile name" << nsstringToQString([each8021XProfile ssid]); -// } - -#endif - return QList (); -} - -bool QCoreWlanEngine::getAllScInterfaces() -{ - networkInterfaces.clear(); - NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; - - CFArrayRef interfaces = SCNetworkInterfaceCopyAll(); - if (interfaces != NULL) { - CFIndex interfaceCount; - CFIndex interfaceIndex; - interfaceCount = CFArrayGetCount(interfaces); - for (interfaceIndex = 0; interfaceIndex < interfaceCount; interfaceIndex++) { - - CFStringRef bsdName; - CFTypeRef thisInterface = CFArrayGetValueAtIndex(interfaces, interfaceIndex); - bsdName = SCNetworkInterfaceGetBSDName((SCNetworkInterfaceRef)thisInterface); - QString interfaceName = cfstringRefToQstring(bsdName); - QString typeStr; - CFStringRef type = SCNetworkInterfaceGetInterfaceType((SCNetworkInterfaceRef)thisInterface); - if ( CFEqual(type, kSCNetworkInterfaceTypeIEEE80211)) { - typeStr = "WLAN"; -// } else if (CFEqual(type, kSCNetworkInterfaceTypeBluetooth)) { -// typeStr = "Bluetooth"; - } else if(CFEqual(type, kSCNetworkInterfaceTypeEthernet)) { - typeStr = "Ethernet"; - } else if(CFEqual(type, kSCNetworkInterfaceTypeFireWire)) { - typeStr = "Ethernet"; //ok a bit fudged - } - if(!networkInterfaces.contains(interfaceName) && !typeStr.isEmpty()) { - networkInterfaces.insert(interfaceName,typeStr); - } - } - } - CFRelease(interfaces); - - [autoreleasepool release]; - return true; -} - -#include "moc_qcorewlanengine_mac_p.cpp" - -QT_END_NAMESPACE - diff --git a/src/network/bearer/qcorewlanengine_mac_p.h b/src/network/bearer/qcorewlanengine_mac_p.h deleted file mode 100644 index d6454ca..0000000 --- a/src/network/bearer/qcorewlanengine_mac_p.h +++ /dev/null @@ -1,101 +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 QCOREWLANENGINE_P_H -#define QCOREWLANENGINE_P_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 "qnetworksessionengine_p.h" -#include -#include - -QT_BEGIN_NAMESPACE - -class QNetworkConfigurationPrivate; - -class QCoreWlanEngine : public QNetworkSessionEngine -{ - Q_OBJECT - -public: - QCoreWlanEngine(QObject *parent = 0); - ~QCoreWlanEngine(); - - QList getConfigurations(bool *ok = 0); - QString getInterfaceFromId(const QString &id); - bool hasIdentifier(const QString &id); - - QString bearerName(const QString &id); - - void connectToId(const QString &id); - void disconnectFromId(const QString &id); - - void requestUpdate(); - - static QCoreWlanEngine *instance(); - static bool getAllScInterfaces(); - -private: - bool isWifiReady(const QString &dev); - QMap configurationInterface; - QTimer pollTimer; - QList scanForSsids(const QString &interfaceName); - - QList getWlanProfiles(const QString &interfaceName); - - QList getWifiConfigurations(); - bool isKnownSsid(const QString &interfaceName, const QString &ssid); -}; - -QT_END_NAMESPACE - -#endif - diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index c35edbf..f8e0d7b 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -40,11 +40,6 @@ ****************************************************************************/ #include "qnetworkconfigmanager_p.h" - -#ifdef Q_OS_DARWIN -#include "qcorewlanengine_mac_p.h" -#endif - #include "qbearerplugin.h" #include @@ -229,10 +224,17 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() QStringList keys = l->keys(); #if defined (Q_OS_DARWIN) - coreWifi = QCoreWlanEngine::instance(); - if (coreWifi) { - connect(coreWifi, SIGNAL(configurationsChanged()), - this, SLOT(updateConfigurations())); + coreWifi = 0; + if (keys.contains(QLatin1String("corewlan"))) { + QBearerEnginePlugin *coreWlanPlugin = + qobject_cast(l->instance(QLatin1String("corewlan"))); + if (coreWlanPlugin) { + coreWifi = coreWlanPlugin->create(QLatin1String("corewlan")); + if (coreWifi) { + connect(coreWifi, SIGNAL(configurationsChanged()), + this, SLOT(updateConfigurations())); + } + } } #else #ifdef BACKEND_NM @@ -473,7 +475,4 @@ void QNetworkConfigurationManagerPrivate::performAsyncConfigurationUpdate() #endif } -#include "moc_qnetworkconfigmanager_p.cpp" - QT_END_NAMESPACE - diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index 5d0df18..95358bc 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -146,7 +146,7 @@ private: QNetworkSessionEngine *nmWifi; #endif #ifdef Q_OS_DARWIN - QCoreWlanEngine *coreWifi; + QNetworkSessionEngine *coreWifi; #endif uint onlineConfigurations; diff --git a/src/network/bearer/qnetworksession_p.cpp b/src/network/bearer/qnetworksession_p.cpp index 3c9054b..df0ad3e 100644 --- a/src/network/bearer/qnetworksession_p.cpp +++ b/src/network/bearer/qnetworksession_p.cpp @@ -44,29 +44,18 @@ #include "qnetworksessionengine_p.h" #include "qnetworkconfigmanager_p.h" -#ifdef Q_OS_DARWIN -#include "qcorewlanengine_mac_p.h" -#endif #include #include #include #include -#undef interface - QT_BEGIN_NAMESPACE static QNetworkSessionEngine *getEngineFromId(const QString &id) { QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); -#ifdef Q_OS_DARWIN - QCoreWlanEngine *coreWifi = QCoreWlanEngine::instance(); - if (coreWifi && coreWifi->hasIdentifier(id)) - return coreWifi; - -#endif QNetworkSessionEngine *engine = priv->configurationEngine.value(id); if (engine && engine->hasIdentifier(id)) return engine; @@ -498,6 +487,4 @@ if(serviceName.isEmpty()) } #endif -#include "moc_qnetworksession_p.cpp" QT_END_NAMESPACE - diff --git a/src/plugins/bearer/bearer.pro b/src/plugins/bearer/bearer.pro index 80d6f4b..58d2613 100644 --- a/src/plugins/bearer/bearer.pro +++ b/src/plugins/bearer/bearer.pro @@ -4,3 +4,4 @@ SUBDIRS += generic contains(QT_CONFIG, dbus):contains(QT_CONFIG, networkmanager):SUBDIRS += networkmanager win32:SUBDIRS += nla win32:!wince*:SUBDIRS += nativewifi +macx:SUBDIRS += corewlan diff --git a/src/plugins/bearer/corewlan/corewlan.pro b/src/plugins/bearer/corewlan/corewlan.pro new file mode 100644 index 0000000..ffac6df --- /dev/null +++ b/src/plugins/bearer/corewlan/corewlan.pro @@ -0,0 +1,21 @@ +TARGET = qcorewlanbearer +include(../../qpluginbase.pri) + +QT += network +LIBS += -framework Foundation -framework SystemConfiguration + +contains(QT_CONFIG, corewlan) { + isEmpty(QMAKE_MAC_SDK)|contains(QMAKE_MAC_SDK, "/Developer/SDKs/MacOSX10.6.sdk") { + LIBS += -framework CoreWLAN + DEFINES += MAC_SDK_10_6 + } +} + +DEFINES += BEARER_ENGINE + +HEADERS += qcorewlanengine.h +SOURCES += qcorewlanengine.mm main.cpp + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/bearer +target.path += $$[QT_INSTALL_PLUGINS]/bearer +INSTALLS += target diff --git a/src/plugins/bearer/corewlan/main.cpp b/src/plugins/bearer/corewlan/main.cpp new file mode 100644 index 0000000..c0d1efe --- /dev/null +++ b/src/plugins/bearer/corewlan/main.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** 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 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 "qcorewlanengine.h" + +#include + +#include + +QT_BEGIN_NAMESPACE + +class QCoreWlanEnginePlugin : public QBearerEnginePlugin +{ +public: + QCoreWlanEnginePlugin(); + ~QCoreWlanEnginePlugin(); + + QStringList keys() const; + QBearerEngine *create(const QString &key) const; +}; + +QCoreWlanEnginePlugin::QCoreWlanEnginePlugin() +{ +} + +QCoreWlanEnginePlugin::~QCoreWlanEnginePlugin() +{ +} + +QStringList QCoreWlanEnginePlugin::keys() const +{ + qDebug() << Q_FUNC_INFO; + + return QStringList() << QLatin1String("corewlan"); +} + +QBearerEngine *QCoreWlanEnginePlugin::create(const QString &key) const +{ + qDebug() << Q_FUNC_INFO; + + if (key == QLatin1String("corewlan")) + return new QCoreWlanEngine; + else + return 0; +} + +Q_EXPORT_STATIC_PLUGIN(QCoreWlanEnginePlugin) +Q_EXPORT_PLUGIN2(qcorewlanbearer, QCoreWlanEnginePlugin) + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.h b/src/plugins/bearer/corewlan/qcorewlanengine.h new file mode 100644 index 0000000..7ccfeea --- /dev/null +++ b/src/plugins/bearer/corewlan/qcorewlanengine.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** 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 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 QCOREWLANENGINE_P_H +#define QCOREWLANENGINE_P_H + +#include + +#include +#include + +QT_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; + +class QCoreWlanEngine : public QNetworkSessionEngine +{ + Q_OBJECT + +public: + QCoreWlanEngine(QObject *parent = 0); + ~QCoreWlanEngine(); + + QList getConfigurations(bool *ok = 0); + QString getInterfaceFromId(const QString &id); + bool hasIdentifier(const QString &id); + + QString bearerName(const QString &id); + + void connectToId(const QString &id); + void disconnectFromId(const QString &id); + + void requestUpdate(); + + static QCoreWlanEngine *instance(); + static bool getAllScInterfaces(); + +private: + bool isWifiReady(const QString &dev); + QMap configurationInterface; + QTimer pollTimer; + QList scanForSsids(const QString &interfaceName); + + QList getWlanProfiles(const QString &interfaceName); + + QList getWifiConfigurations(); + bool isKnownSsid(const QString &interfaceName, const QString &ssid); +}; + +QT_END_NAMESPACE + +#endif + diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm new file mode 100644 index 0000000..9dea217 --- /dev/null +++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm @@ -0,0 +1,459 @@ +/**************************************************************************** +** +** 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 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 "qcorewlanengine.h" + +#include + +#include +#include +#include +#include + +#include + +#if defined(MAC_SDK_10_6) //not much functionality without this +#include +#include +#include +#include +#endif + +#include +#include +#include + +#include +QMap networkInterfaces; + +QT_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC(QCoreWlanEngine, coreWlanEngine) + +inline QString cfstringRefToQstring(CFStringRef cfStringRef) { +// return QString([cfStringRef UTF8String]); + QString retVal; + CFIndex maxLength = 2 * CFStringGetLength(cfStringRef) + 1/*zero term*/; // max UTF8 + char *cstring = new char[maxLength]; + if (CFStringGetCString(CFStringRef(cfStringRef), cstring, maxLength, kCFStringEncodingUTF8)) { + retVal = QString::fromUtf8(cstring); + } + delete cstring; + return retVal; +} + +inline CFStringRef qstringToCFStringRef(const QString &string) +{ + return CFStringCreateWithCharacters(0, reinterpret_cast(string.unicode()), + string.length()); +} + +inline NSString *qstringToNSString(const QString &qstr) +{ return [reinterpret_cast(qstringToCFStringRef(qstr)) autorelease]; } + +inline QString nsstringToQString(const NSString *nsstr) +{ return cfstringRefToQstring(reinterpret_cast(nsstr)); } + +inline QStringList nsarrayToQStringList(void *nsarray) +{ + QStringList result; + NSArray *array = static_cast(nsarray); + for (NSUInteger i=0; i<[array count]; ++i) + result << nsstringToQString([array objectAtIndex:i]); + return result; +} + +static QString qGetInterfaceType(const QString &interfaceString) +{ + return networkInterfaces.value(interfaceString); +} + +QCoreWlanEngine::QCoreWlanEngine(QObject *parent) +: QNetworkSessionEngine(parent) +{ + getAllScInterfaces(); + connect(&pollTimer, SIGNAL(timeout()), this, SIGNAL(configurationsChanged())); + pollTimer.setInterval(10000); +} + +QCoreWlanEngine::~QCoreWlanEngine() +{ +} + +QList QCoreWlanEngine::getWifiConfigurations() +{ + QMapIterator i(networkInterfaces); + while (i.hasNext()) { + i.next(); + QString interfaceName = i.key(); + if (i.value() == "WLAN") { + if(!isWifiReady(interfaceName)) { + qWarning() << "wifi not powered on"; + return QList(); + } else { + // QList profs = getWlanProfiles(interfaceName); + scanForSsids(interfaceName); + } + } else { + + } + } + return QList (); +} + +QList QCoreWlanEngine::getConfigurations(bool *ok) +{ + if (ok) + *ok = true; + NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + + QList foundConfigurations; + QList wificonfigs = getWifiConfigurations(); + + uint identifier; + QMapIterator i(networkInterfaces); + while (i.hasNext()) { + i.next(); + if (i.value() == "WLAN") { + QList fetchedConfigurations = scanForSsids(i.key()); + for (int i = 0; i < fetchedConfigurations.count(); ++i) { + + QNetworkConfigurationPrivate *config = new QNetworkConfigurationPrivate; + config->name = fetchedConfigurations.at(i)->name; + config->isValid = fetchedConfigurations.at(i)->isValid; + config->id = fetchedConfigurations.at(i)->id; + + config->state = fetchedConfigurations.at(i)->state; + config->type = fetchedConfigurations.at(i)->type; + config->roamingSupported = fetchedConfigurations.at(i)->roamingSupported; + config->purpose = fetchedConfigurations.at(i)->purpose; + config->internet = fetchedConfigurations.at(i)->internet; + config->serviceInterface = fetchedConfigurations.at(i)->serviceInterface; + + identifier = config->name.toUInt(); + configurationInterface[identifier] = config->serviceInterface.name(); + foundConfigurations.append(config); + } + } + + QNetworkInterface interface = QNetworkInterface::interfaceFromName(i.key()); + QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; + const QString humanReadableName = interface.humanReadableName(); + cpPriv->name = humanReadableName.isEmpty() ? interface.name() : humanReadableName; + cpPriv->isValid = true; + + if (interface.index()) + identifier = interface.index(); + else + identifier = qHash(interface.hardwareAddress()); + + cpPriv->id = QString::number(identifier); + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + cpPriv->state = QNetworkConfiguration::Undefined; + + if (interface.flags() & QNetworkInterface::IsRunning) { + cpPriv->state = QNetworkConfiguration::Defined; + cpPriv->internet = true; + } + if ( !interface.addressEntries().isEmpty()) { + cpPriv->state |= QNetworkConfiguration::Active; + cpPriv->internet = true; + } + configurationInterface[identifier] = interface.name(); + foundConfigurations.append(cpPriv); + } + [autoreleasepool release]; + pollTimer.start(); + return foundConfigurations; +} + +QString QCoreWlanEngine::getInterfaceFromId(const QString &id) +{ + return configurationInterface.value(id.toUInt()); +} + +bool QCoreWlanEngine::hasIdentifier(const QString &id) +{ + return configurationInterface.contains(id.toUInt()); +} + +QString QCoreWlanEngine::bearerName(const QString &id) +{ + QString interface = getInterfaceFromId(id); + + if (interface.isEmpty()) + return QString(); + + return qGetInterfaceType(interface); +} + +void QCoreWlanEngine::connectToId(const QString &id) +{ + NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + QString interfaceString = getInterfaceFromId(id); + + if(networkInterfaces.value(interfaceString) == "WLAN") { +#if defined(MAC_SDK_10_6) + CWInterface *wifiInterface = [CWInterface interfaceWithName: qstringToNSString(interfaceString)]; + CWConfiguration *userConfig = [ wifiInterface configuration]; + + NSSet *remNets = [userConfig rememberedNetworks]; //CWWirelessProfile + + NSEnumerator *enumerator = [remNets objectEnumerator]; + CWWirelessProfile *wProfile; + NSUInteger index=0; + while ((wProfile = [enumerator nextObject])) { //CWWirelessProfile + + if(id == nsstringToQString([wProfile ssid])) { + CW8021XProfile *user8021XProfile = nil; + user8021XProfile = [ wProfile user8021XProfile]; + + NSError *err = nil; + NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0]; + + if(user8021XProfile) { + [params setValue: user8021XProfile forKey:kCWAssocKey8021XProfile]; + } else { + [params setValue: [wProfile passphrase] forKey: kCWAssocKeyPassphrase]; + } + + NSDictionary *parametersDict = nil; + NSArray* apArray = [NSMutableArray arrayWithArray:[wifiInterface scanForNetworksWithParameters:parametersDict error:&err]]; + if(!err) { + for(uint row=0; row < [apArray count]; row++ ) { + CWNetwork *apNetwork = [apArray objectAtIndex:row]; + if([[apNetwork ssid] compare:[wProfile ssid]] == NSOrderedSame) { + bool result = [wifiInterface associateToNetwork: apNetwork parameters:[NSDictionary dictionaryWithDictionary:params] error:&err]; + if(!result) { + qWarning() <<"ERROR"<< nsstringToQString([err localizedDescription ]); + emit connectionError(id, ConnectError); + } else { + [autoreleasepool release]; + return; + } + } + } + } + } + index++; + } + emit connectionError(id, InterfaceLookupError); +#endif + } else { + // not wifi + } + emit connectionError(id, OperationNotSupported); + [autoreleasepool release]; +} + +void QCoreWlanEngine::disconnectFromId(const QString &id) +{ + QString interfaceString = getInterfaceFromId(id); + if(networkInterfaces.value(getInterfaceFromId(id)) == "WLAN") { //wifi only for now +#if defined(MAC_SDK_10_6) + NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + CWInterface *wifiInterface = [CWInterface interfaceWithName: qstringToNSString(interfaceString)]; + [wifiInterface disassociate]; + if([[wifiInterface interfaceState]intValue] != kCWInterfaceStateInactive) { + emit connectionError(id, DisconnectionError); + } + [autoreleasepool release]; + return; +#endif + } else { + + } + emit connectionError(id, OperationNotSupported); +} + +void QCoreWlanEngine::requestUpdate() +{ + getAllScInterfaces(); + emit configurationsChanged(); +} + +QCoreWlanEngine *QCoreWlanEngine::instance() +{ + return coreWlanEngine(); +} + +QList QCoreWlanEngine::scanForSsids(const QString &interfaceName) +{ + QList foundConfigs; +#if defined(MAC_SDK_10_6) + NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + + CWInterface *currentInterface = [CWInterface interfaceWithName:qstringToNSString(interfaceName)]; + NSError *err = nil; + NSDictionary *parametersDict = nil; + NSArray* apArray = [NSMutableArray arrayWithArray:[currentInterface scanForNetworksWithParameters:parametersDict error:&err]]; + + if(!err) { + for(uint row=0; row < [apArray count]; row++ ) { + CWNetwork *apNetwork = [apArray objectAtIndex:row]; + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + QString networkSsid = nsstringToQString([apNetwork ssid]); + cpPriv->name = networkSsid; + cpPriv->isValid = true; + cpPriv->id = networkSsid; + cpPriv->internet = true; + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + cpPriv->serviceInterface = QNetworkInterface::interfaceFromName(nsstringToQString([[CWInterface interface] name])); + + CWWirelessProfile *networkProfile = apNetwork.wirelessProfile; + CW8021XProfile *userNetworkProfile = networkProfile.user8021XProfile; + if(!userNetworkProfile) { + } else { + qWarning() <<"Has profile!" ; + } + + if( [currentInterface.interfaceState intValue] == kCWInterfaceStateRunning) { + QString interfaceSsidString = nsstringToQString( [currentInterface ssid]); + if( cpPriv->name == interfaceSsidString) { + cpPriv->state |= QNetworkConfiguration::Active; + } + } else { + if(isKnownSsid(cpPriv->serviceInterface.name(), networkSsid)) { + cpPriv->state = QNetworkConfiguration::Discovered; + } else { + cpPriv->state = QNetworkConfiguration::Defined; + } + } + if(!cpPriv->state) { + cpPriv->state = QNetworkConfiguration::Undefined; + } + if([[apNetwork securityMode ] intValue]== kCWSecurityModeOpen) + cpPriv->purpose = QNetworkConfiguration::PublicPurpose; + else + cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; + foundConfigs.append(cpPriv); + } + } else { + qWarning() << "ERROR scanning for ssids" << nsstringToQString([err localizedDescription]) + < QCoreWlanEngine::getWlanProfiles(const QString &interfaceName) +{ + Q_UNUSED(interfaceName) +#if defined(MAC_SDK_10_6) +// for( CW8021XProfile *each8021XProfile in [CW8021XProfile allUser8021XProfiles] ) { +// qWarning() << "Profile name" << nsstringToQString([each8021XProfile ssid]); +// } + +#endif + return QList (); +} + +bool QCoreWlanEngine::getAllScInterfaces() +{ + networkInterfaces.clear(); + NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + + CFArrayRef interfaces = SCNetworkInterfaceCopyAll(); + if (interfaces != NULL) { + CFIndex interfaceCount; + CFIndex interfaceIndex; + interfaceCount = CFArrayGetCount(interfaces); + for (interfaceIndex = 0; interfaceIndex < interfaceCount; interfaceIndex++) { + + CFStringRef bsdName; + CFTypeRef thisInterface = CFArrayGetValueAtIndex(interfaces, interfaceIndex); + bsdName = SCNetworkInterfaceGetBSDName((SCNetworkInterfaceRef)thisInterface); + QString interfaceName = cfstringRefToQstring(bsdName); + QString typeStr; + CFStringRef type = SCNetworkInterfaceGetInterfaceType((SCNetworkInterfaceRef)thisInterface); + if ( CFEqual(type, kSCNetworkInterfaceTypeIEEE80211)) { + typeStr = "WLAN"; +// } else if (CFEqual(type, kSCNetworkInterfaceTypeBluetooth)) { +// typeStr = "Bluetooth"; + } else if(CFEqual(type, kSCNetworkInterfaceTypeEthernet)) { + typeStr = "Ethernet"; + } else if(CFEqual(type, kSCNetworkInterfaceTypeFireWire)) { + typeStr = "Ethernet"; //ok a bit fudged + } + if(!networkInterfaces.contains(interfaceName) && !typeStr.isEmpty()) { + networkInterfaces.insert(interfaceName,typeStr); + } + } + } + CFRelease(interfaces); + + [autoreleasepool release]; + return true; +} + +QT_END_NAMESPACE -- cgit v0.12 From 19e64169b8f3b0b0c12d99327e8c68c5c8a26498 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 7 Dec 2009 16:03:38 +1000 Subject: Remove debug. --- src/network/bearer/qbearerplugin.cpp | 1 - src/plugins/bearer/corewlan/main.cpp | 4 ---- src/plugins/bearer/generic/main.cpp | 4 ---- src/plugins/bearer/nativewifi/main.cpp | 4 ---- src/plugins/bearer/networkmanager/main.cpp | 4 ---- src/plugins/bearer/nla/main.cpp | 4 ---- 6 files changed, 21 deletions(-) diff --git a/src/network/bearer/qbearerplugin.cpp b/src/network/bearer/qbearerplugin.cpp index 252ee71..7b81b13 100644 --- a/src/network/bearer/qbearerplugin.cpp +++ b/src/network/bearer/qbearerplugin.cpp @@ -48,7 +48,6 @@ QT_BEGIN_NAMESPACE QBearerEnginePlugin::QBearerEnginePlugin(QObject *parent) : QObject(parent) { - qDebug() << Q_FUNC_INFO; } QBearerEnginePlugin::~QBearerEnginePlugin() diff --git a/src/plugins/bearer/corewlan/main.cpp b/src/plugins/bearer/corewlan/main.cpp index c0d1efe..ce0611e 100644 --- a/src/plugins/bearer/corewlan/main.cpp +++ b/src/plugins/bearer/corewlan/main.cpp @@ -67,15 +67,11 @@ QCoreWlanEnginePlugin::~QCoreWlanEnginePlugin() QStringList QCoreWlanEnginePlugin::keys() const { - qDebug() << Q_FUNC_INFO; - return QStringList() << QLatin1String("corewlan"); } QBearerEngine *QCoreWlanEnginePlugin::create(const QString &key) const { - qDebug() << Q_FUNC_INFO; - if (key == QLatin1String("corewlan")) return new QCoreWlanEngine; else diff --git a/src/plugins/bearer/generic/main.cpp b/src/plugins/bearer/generic/main.cpp index c877fce..a7df023 100644 --- a/src/plugins/bearer/generic/main.cpp +++ b/src/plugins/bearer/generic/main.cpp @@ -67,15 +67,11 @@ QGenericEnginePlugin::~QGenericEnginePlugin() QStringList QGenericEnginePlugin::keys() const { - qDebug() << Q_FUNC_INFO; - return QStringList() << QLatin1String("generic"); } QBearerEngine *QGenericEnginePlugin::create(const QString &key) const { - qDebug() << Q_FUNC_INFO; - if (key == QLatin1String("generic")) return new QGenericEngine; else diff --git a/src/plugins/bearer/nativewifi/main.cpp b/src/plugins/bearer/nativewifi/main.cpp index 2aced02..64ed73d 100644 --- a/src/plugins/bearer/nativewifi/main.cpp +++ b/src/plugins/bearer/nativewifi/main.cpp @@ -108,15 +108,11 @@ QNativeWifiEnginePlugin::~QNativeWifiEnginePlugin() QStringList QNativeWifiEnginePlugin::keys() const { - qDebug() << Q_FUNC_INFO; - return QStringList() << QLatin1String("nativewifi"); } QBearerEngine *QNativeWifiEnginePlugin::create(const QString &key) const { - qDebug() << Q_FUNC_INFO; - if (key != QLatin1String("nativewifi")) return 0; diff --git a/src/plugins/bearer/networkmanager/main.cpp b/src/plugins/bearer/networkmanager/main.cpp index c79fe91..d4b74a1 100644 --- a/src/plugins/bearer/networkmanager/main.cpp +++ b/src/plugins/bearer/networkmanager/main.cpp @@ -67,15 +67,11 @@ QNetworkManagerEnginePlugin::~QNetworkManagerEnginePlugin() QStringList QNetworkManagerEnginePlugin::keys() const { - qDebug() << Q_FUNC_INFO; - return QStringList() << QLatin1String("networkmanager"); } QBearerEngine *QNetworkManagerEnginePlugin::create(const QString &key) const { - qDebug() << Q_FUNC_INFO; - if (key == QLatin1String("networkmanager")) return new QNmWifiEngine; else diff --git a/src/plugins/bearer/nla/main.cpp b/src/plugins/bearer/nla/main.cpp index f0d36c4..541d2c5 100644 --- a/src/plugins/bearer/nla/main.cpp +++ b/src/plugins/bearer/nla/main.cpp @@ -67,15 +67,11 @@ QNlaEnginePlugin::~QNlaEnginePlugin() QStringList QNlaEnginePlugin::keys() const { - qDebug() << Q_FUNC_INFO; - return QStringList() << QLatin1String("nla"); } QBearerEngine *QNlaEnginePlugin::create(const QString &key) const { - qDebug() << Q_FUNC_INFO; - if (key == QLatin1String("nla")) return new QNlaEngine; else -- cgit v0.12 From 63d59200884a68e569cce9d0ee470447b8239f6b Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 7 Dec 2009 16:11:11 +1000 Subject: Convert generic engine plugin to be incremental. --- src/network/bearer/qnetworkconfigmanager.cpp | 66 +++-- src/network/bearer/qnetworkconfigmanager_p.cpp | 318 +++++---------------- src/network/bearer/qnetworkconfigmanager_p.h | 70 +---- src/network/bearer/qnetworkconfiguration_p.h | 3 +- src/network/bearer/qnetworksessionengine.cpp | 11 + src/network/bearer/qnetworksessionengine_p.h | 23 +- src/plugins/bearer/generic/qgenericengine.cpp | 149 ++++++---- src/plugins/bearer/generic/qgenericengine.h | 4 +- .../bearer/networkmanager/qnmwifiengine.cpp | 8 +- src/plugins/bearer/networkmanager/qnmwifiengine.h | 4 +- 10 files changed, 266 insertions(+), 390 deletions(-) diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index 02cc652..6c0b17d 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -45,6 +45,7 @@ #include "qnetworkconfigmanager_s60_p.h" #else #include "qnetworkconfigmanager_p.h" +#include "qnetworksessionengine_p.h" #endif QT_BEGIN_NAMESPACE @@ -234,28 +235,31 @@ QList QNetworkConfigurationManager::allConfigurations(QNe { QList result; QNetworkConfigurationManagerPrivate* conPriv = connManager(); - QList cpsIdents = conPriv->accessPointConfigurations.keys(); - - //find all InternetAccessPoints - foreach( QString ii, cpsIdents) { - QExplicitlySharedDataPointer p = - conPriv->accessPointConfigurations.value(ii); - if ( (p->state & filter) == filter ) { - QNetworkConfiguration pt; - pt.d = conPriv->accessPointConfigurations.value(ii); - result << pt; + + foreach (QNetworkSessionEngine *engine, conPriv->sessionEngines) { + QStringList cpsIdents = engine->accessPointConfigurations.keys(); + + //find all InternetAccessPoints + foreach (const QString &ii, cpsIdents) { + QExplicitlySharedDataPointer p = + engine->accessPointConfigurations.value(ii); + if ((p->state & filter) == filter) { + QNetworkConfiguration pt; + pt.d = engine->accessPointConfigurations.value(ii); + result << pt; + } } - } - //find all service networks - cpsIdents = conPriv->snapConfigurations.keys(); - foreach( QString ii, cpsIdents) { - QExplicitlySharedDataPointer p = - conPriv->snapConfigurations.value(ii); - if ( (p->state & filter) == filter ) { - QNetworkConfiguration pt; - pt.d = conPriv->snapConfigurations.value(ii); - result << pt; + //find all service networks + cpsIdents = engine->snapConfigurations.keys(); + foreach (const QString &ii, cpsIdents) { + QExplicitlySharedDataPointer p = + engine->snapConfigurations.value(ii); + if ((p->state & filter) == filter) { + QNetworkConfiguration pt; + pt.d = engine->snapConfigurations.value(ii); + result << pt; + } } } @@ -271,15 +275,23 @@ QList QNetworkConfigurationManager::allConfigurations(QNe QNetworkConfiguration QNetworkConfigurationManager::configurationFromIdentifier(const QString& identifier) const { QNetworkConfigurationManagerPrivate* conPriv = connManager(); + QNetworkConfiguration item; - if (conPriv->accessPointConfigurations.contains(identifier)) - item.d = conPriv->accessPointConfigurations.value(identifier); - else if (conPriv->snapConfigurations.contains(identifier)) - item.d = conPriv->snapConfigurations.value(identifier); - else if (conPriv->userChoiceConfigurations.contains(identifier)) - item.d = conPriv->userChoiceConfigurations.value(identifier); - return item; + foreach (QNetworkSessionEngine *engine, conPriv->sessionEngines) { + if (engine->accessPointConfigurations.contains(identifier)) + item.d = engine->accessPointConfigurations.value(identifier); + else if (engine->snapConfigurations.contains(identifier)) + item.d = engine->snapConfigurations.value(identifier); + else if (engine->userChoiceConfigurations.contains(identifier)) + item.d = engine->userChoiceConfigurations.value(identifier); + else + continue; + + return item; + } + + return item; } /*! diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index f8e0d7b..09714e5 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -53,50 +53,34 @@ QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, (QBearerEngineFactoryInterface_iid, QLatin1String("/bearer"))) +QNetworkConfigurationManagerPrivate::~QNetworkConfigurationManagerPrivate() +{ + while (!sessionEngines.isEmpty()) + delete sessionEngines.takeFirst(); +} + void QNetworkConfigurationManagerPrivate::registerPlatformCapabilities() { capFlags = QNetworkConfigurationManager::ForcedRoaming; } -void QNetworkConfigurationManagerPrivate::configurationAdded(QNetworkConfigurationPrivate *cpPriv, QNetworkSessionEngine *engine) +void QNetworkConfigurationManagerPrivate::configurationAdded(QNetworkConfigurationPrivatePointer ptr) { - QExplicitlySharedDataPointer ptr(new QNetworkConfigurationPrivate); - - ptr.data()->isValid = cpPriv->isValid; - ptr.data()->name = cpPriv->name; - ptr.data()->id = cpPriv->id; - ptr.data()->state = cpPriv->state; - ptr.data()->type = cpPriv->type; - ptr.data()->roamingSupported = cpPriv->roamingSupported; - ptr.data()->purpose = cpPriv->purpose; - ptr.data()->internet = cpPriv->internet; - - accessPointConfigurations.insert(cpPriv->id, ptr); - configurationEngine.insert(cpPriv->id, engine); - if (!firstUpdate) { QNetworkConfiguration item; item.d = ptr; emit configurationAdded(item); } - if (ptr.data()->state == QNetworkConfiguration::Active) { + if (ptr->state == QNetworkConfiguration::Active) { ++onlineConfigurations; if (!firstUpdate && onlineConfigurations == 1) emit onlineStateChanged(true); } } -void QNetworkConfigurationManagerPrivate::configurationRemoved(const QString &id) +void QNetworkConfigurationManagerPrivate::configurationRemoved(QNetworkConfigurationPrivatePointer ptr) { - if (!accessPointConfigurations.contains(id)) - return; - - QExplicitlySharedDataPointer ptr = - accessPointConfigurations.take(id); - - configurationEngine.remove(id); - ptr.data()->isValid = false; if (!firstUpdate) { @@ -112,57 +96,34 @@ void QNetworkConfigurationManagerPrivate::configurationRemoved(const QString &id } } -void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigurationPrivate *cpPriv) +void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigurationPrivatePointer ptr) { - if (!accessPointConfigurations.contains(cpPriv->id)) - return; - - QExplicitlySharedDataPointer ptr = - accessPointConfigurations.value(cpPriv->id); - - if (ptr.data()->isValid != cpPriv->isValid || - ptr.data()->name != cpPriv->name || - ptr.data()->id != cpPriv->id || - ptr.data()->state != cpPriv->state || - ptr.data()->type != cpPriv->type || - ptr.data()->roamingSupported != cpPriv->roamingSupported || - ptr.data()->purpose != cpPriv->purpose || - ptr.data()->internet != cpPriv->internet) { - - const QNetworkConfiguration::StateFlags oldState = ptr.data()->state; - - ptr.data()->isValid = cpPriv->isValid; - ptr.data()->name = cpPriv->name; - ptr.data()->id = cpPriv->id; - ptr.data()->state = cpPriv->state; - ptr.data()->type = cpPriv->type; - ptr.data()->roamingSupported = cpPriv->roamingSupported; - ptr.data()->purpose = cpPriv->purpose; - ptr.data()->internet = cpPriv->internet; + if (!firstUpdate) { + QNetworkConfiguration item; + item.d = ptr; + emit configurationChanged(item); + } - if (!firstUpdate) { - QNetworkConfiguration item; - item.d = ptr; - emit configurationChanged(item); - } + qDebug() << "Need to recalculate online state."; + QNetworkConfiguration::StateFlags oldState = ptr->state; - if (ptr.data()->state == QNetworkConfiguration::Active && oldState != ptr.data()->state) { - // configuration went online - ++onlineConfigurations; - if (!firstUpdate && onlineConfigurations == 1) - emit onlineStateChanged(true); - } else if (ptr.data()->state != QNetworkConfiguration::Active && oldState == QNetworkConfiguration::Active) { - // configuration went offline - --onlineConfigurations; - if (!firstUpdate && onlineConfigurations == 0) - emit onlineStateChanged(false); - } + if (ptr->state == QNetworkConfiguration::Active && oldState != ptr->state) { + // configuration went online + ++onlineConfigurations; + if (!firstUpdate && onlineConfigurations == 1) + emit onlineStateChanged(true); + } else if (ptr->state != QNetworkConfiguration::Active && oldState == QNetworkConfiguration::Active) { + // configuration went offline + --onlineConfigurations; + if (!firstUpdate && onlineConfigurations == 0) + emit onlineStateChanged(false); } } void QNetworkConfigurationManagerPrivate::updateInternetServiceConfiguration() { - if (!snapConfigurations.contains(QLatin1String("Internet Service Network"))) { +#if 0 + if (!generic->snapConfigurations.contains(QLatin1String("Internet Service Network"))) { QNetworkConfigurationPrivate *serviceNetwork = new QNetworkConfigurationPrivate; serviceNetwork->name = tr("Internet"); serviceNetwork->isValid = true; @@ -172,7 +133,7 @@ void QNetworkConfigurationManagerPrivate::updateInternetServiceConfiguration() QExplicitlySharedDataPointer ptr(serviceNetwork); - snapConfigurations.insert(serviceNetwork->id, ptr); + generic->snapConfigurations.insert(serviceNetwork->id, ptr); if (!firstUpdate) { QNetworkConfiguration item; @@ -182,15 +143,15 @@ void QNetworkConfigurationManagerPrivate::updateInternetServiceConfiguration() } QExplicitlySharedDataPointer ptr = - snapConfigurations.value(QLatin1String("Internet Service Network")); + generic->snapConfigurations.value(QLatin1String("Internet Service Network")); QList > serviceNetworkMembers; QHash >::const_iterator i = - accessPointConfigurations.constBegin(); + generic->accessPointConfigurations.constBegin(); QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Defined; - while (i != accessPointConfigurations.constEnd()) { + while (i != generic->accessPointConfigurations.constEnd()) { QExplicitlySharedDataPointer child = i.value(); if (child.data()->internet && ((child.data()->state & QNetworkConfiguration::Defined) @@ -212,186 +173,92 @@ void QNetworkConfigurationManagerPrivate::updateInternetServiceConfiguration() item.d = ptr; emit configurationChanged(item); } +#endif } void QNetworkConfigurationManagerPrivate::updateConfigurations() { if (firstUpdate) { - updateState = NotUpdating; onlineConfigurations = 0; QFactoryLoader *l = loader(); QStringList keys = l->keys(); -#if defined (Q_OS_DARWIN) - coreWifi = 0; if (keys.contains(QLatin1String("corewlan"))) { QBearerEnginePlugin *coreWlanPlugin = qobject_cast(l->instance(QLatin1String("corewlan"))); if (coreWlanPlugin) { - coreWifi = coreWlanPlugin->create(QLatin1String("corewlan")); + QNetworkSessionEngine *coreWifi = coreWlanPlugin->create(QLatin1String("corewlan")); if (coreWifi) { - connect(coreWifi, SIGNAL(configurationsChanged()), - this, SLOT(updateConfigurations())); + sessionEngines.append(coreWifi); } } } -#else -#ifdef BACKEND_NM - nmWifi = 0; + if (keys.contains(QLatin1String("networkmanager"))) { QBearerEnginePlugin *nmPlugin = qobject_cast(l->instance(QLatin1String("networkmanager"))); if (nmPlugin) { - nmWifi = nmPlugin->create(QLatin1String("networkmanager")); + QNetworkSessionEngine *nmWifi = nmPlugin->create(QLatin1String("networkmanager")); if (nmWifi) { - connect(nmWifi, SIGNAL(configurationsChanged()), - this, SLOT(updateConfigurations())); + sessionEngines.append(nmWifi); } } } -#endif - generic = 0; if (keys.contains(QLatin1String("generic"))) { QBearerEnginePlugin *genericPlugin = qobject_cast(l->instance(QLatin1String("generic"))); if (genericPlugin) { - generic = genericPlugin->create(QLatin1String("generic")); + QNetworkSessionEngine *generic = genericPlugin->create(QLatin1String("generic")); if (generic) { - connect(generic, SIGNAL(configurationsChanged()), - this, SLOT(updateConfigurations())); + sessionEngines.append(generic); + connect(generic, SIGNAL(updateCompleted()), + this, SIGNAL(configurationUpdateComplete())); + connect(generic, SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer))); + connect(generic, SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationRemoved(QNetworkConfigurationPrivatePointer))); + connect(generic, SIGNAL(configurationChanged(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationChanged(QNetworkConfigurationPrivatePointer))); } } } -#endif -#ifdef Q_OS_WIN - nla = 0; if (keys.contains(QLatin1String("nla"))) { QBearerEnginePlugin *nlaPlugin = qobject_cast(l->instance(QLatin1String("nla"))); if (nlaPlugin) { - qDebug() << "creating nla backend"; - nla = nlaPlugin->create(QLatin1String("nla")); + QNetworkSessionEngine *nla = nlaPlugin->create(QLatin1String("nla")); if (nla) { - connect(nla, SIGNAL(configurationsChanged()), - this, SLOT(updateConfigurations())); + sessionEngines.append(nla); } } } -#endif -#ifdef Q_OS_WIN32 - nativeWifi = 0; if (keys.contains(QLatin1String("nativewifi"))) { QBearerEnginePlugin *nativeWifiPlugin = qobject_cast(l->instance(QLatin1String("nativewifi"))); if (nativeWifiPlugin) { - qDebug() << "Creating native wifi backend"; - nativeWifi = nativeWifiPlugin->create(QLatin1String("nativewifi")); + QNetworkSessionEngine *nativeWifi = nativeWifiPlugin->create(QLatin1String("nativewifi")); if (nativeWifi) { - connect(nativeWifi, SIGNAL(configurationsChanged()), - this, SLOT(updateConfigurations())); + sessionEngines.append(nativeWifi); capFlags |= QNetworkConfigurationManager::CanStartAndStopInterfaces; } } } -#endif } QNetworkSessionEngine *engine = qobject_cast(sender()); - if (updateState & Updating && engine) { -#if defined (Q_OS_DARWIN) - if (engine == coreWifi) - updateState &= ~CoreWifiUpdating; -#else -#if defined(BACKEND_NM) - if (engine == nmWifi) - updateState &= ~NmUpdating; - if (engine == generic) - updateState &= ~GenericUpdating; -#else - if (engine == generic) - updateState &= ~GenericUpdating; -#endif -#endif - -#ifdef Q_OS_WIN - else if (engine == nla) - updateState &= ~NlaUpdating; -#ifdef Q_OS_WIN32 - else if (engine == nativeWifi) - updateState &= ~NativeWifiUpdating; -#endif -#endif - } - QList engines; - if (firstUpdate) { -#if defined (Q_OS_DARWIN) - if (coreWifi) - engines << coreWifi; -#else -#if defined(BACKEND_NM) - if (nmWifi) - engines << nmWifi; - if (generic) - engines << generic; -#else - if (generic) - engines << generic; -#endif -#endif - -#ifdef Q_OS_WIN - if (nla) - engines << nla; -#ifdef Q_OS_WIN32 - if (nativeWifi) - engines << nativeWifi; -#endif -#endif - } else if (engine) { - engines << engine; - } - - while (!engines.isEmpty()) { - engine = engines.takeFirst(); - - bool ok; - QList foundConfigurations = engine->getConfigurations(&ok); - - // Find removed configurations. - QList removedIdentifiers = configurationEngine.keys(); - for (int i = 0; i < foundConfigurations.count(); ++i) - removedIdentifiers.removeOne(foundConfigurations.at(i)->id); - - // Update or add configurations. - while (!foundConfigurations.isEmpty()) { - QNetworkConfigurationPrivate *cpPriv = foundConfigurations.takeFirst(); - - if (accessPointConfigurations.contains(cpPriv->id)) - configurationChanged(cpPriv); - else - configurationAdded(cpPriv, engine); - - delete cpPriv; - } - - // Remove configurations. - while (!removedIdentifiers.isEmpty()) { - const QString id = removedIdentifiers.takeFirst(); - - if (configurationEngine.value(id) == engine) - configurationRemoved(id); - } + if (!updatingEngines.isEmpty() && engine) { + int index = sessionEngines.indexOf(engine); + if (index >= 0) + updatingEngines.remove(index); } - updateInternetServiceConfiguration(); - - if (updateState == Updating) { - updateState = NotUpdating; + if (updating && updatingEngines.isEmpty()) { + updating = false; emit configurationUpdateComplete(); } @@ -407,22 +274,25 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() */ QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration() { - QExplicitlySharedDataPointer firstActive; - QExplicitlySharedDataPointer firstDiscovered; + QNetworkConfigurationPrivatePointer firstActive; + QNetworkConfigurationPrivatePointer firstDiscovered; - QHash >::const_iterator i = - accessPointConfigurations.constBegin(); - while (i != accessPointConfigurations.constEnd()) { - QNetworkConfigurationPrivate *priv = i.value().data(); + foreach (QNetworkSessionEngine *engine, sessionEngines) { + QHash::const_iterator i = + engine->accessPointConfigurations.constBegin(); - if (!firstActive && priv->isValid && - (priv->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) - firstActive = i.value(); - if (!firstDiscovered && priv->isValid && - (priv->state & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) - firstDiscovered = i.value(); + while (i != engine->accessPointConfigurations.constEnd()) { + QNetworkConfigurationPrivatePointer priv = i.value(); - ++i; + if (!firstActive && priv->isValid && + (priv->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) + firstActive = priv; + if (!firstDiscovered && priv->isValid && + (priv->state & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) + firstDiscovered = priv; + + ++i; + } } QNetworkConfiguration item; @@ -437,42 +307,12 @@ QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration( void QNetworkConfigurationManagerPrivate::performAsyncConfigurationUpdate() { - updateState = Updating; -#if defined (Q_OS_DARWIN) - if (coreWifi) { - updateState |= CoreWifiUpdating; - coreWifi->requestUpdate(); - } -#else -#if defined(BACKEND_NM) - if (nmWifi) { - updateState |= NmUpdating; - nmWifi->requestUpdate(); - } - if (generic) { - updateState |= GenericUpdating; - generic->requestUpdate(); - } -#else - if (generic) { - updateState |= GenericUpdating; - generic->requestUpdate(); - } -#endif -#endif -#ifdef Q_OS_WIN - if (nla) { - updateState |= NlaUpdating; - nla->requestUpdate(); - } -#endif + updating = true; -#ifdef Q_OS_WIN32 - if (nativeWifi) { - updateState |= NativeWifiUpdating; - nativeWifi->requestUpdate(); + for (int i = 0; i < sessionEngines.count(); ++i) { + updatingEngines.insert(i); + sessionEngines.at(i)->requestUpdate(); } -#endif } QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index 95358bc..27a0252 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -56,20 +56,9 @@ #include "qnetworkconfigmanager.h" #include "qnetworkconfiguration_p.h" -#include -#include - QT_BEGIN_NAMESPACE -#ifdef BEARER_ENGINE class QNetworkSessionEngine; -class QGenericEngine; -class QNlaEngine; -class QNativeWifiEngine; -class QNmWifiEngine; -class QCoreWlanEngine; -#endif - class QNetworkConfigurationManagerPrivate : public QObject { @@ -82,22 +71,7 @@ public: updateConfigurations(); } - virtual ~QNetworkConfigurationManagerPrivate() - { - QList configIdents = snapConfigurations.keys(); - foreach(const QString oldIface, configIdents) { - QExplicitlySharedDataPointer priv = snapConfigurations.take(oldIface); - priv->isValid = false; - priv->id.clear(); - } - - configIdents = accessPointConfigurations.keys(); - foreach(const QString oldIface, configIdents) { - QExplicitlySharedDataPointer priv = accessPointConfigurations.take(oldIface); - priv->isValid = false; - priv->id.clear(); - } - } + virtual ~QNetworkConfigurationManagerPrivate(); QNetworkConfiguration defaultConfiguration(); @@ -106,12 +80,6 @@ public: 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 > accessPointConfigurations; - QHash > snapConfigurations; - QHash > userChoiceConfigurations; #ifdef BEARER_ENGINE QHash configurationEngine; #endif @@ -135,41 +103,21 @@ private: #endif #ifdef BEARER_ENGINE - QNetworkSessionEngine *generic; -#ifdef Q_OS_WIN - QNetworkSessionEngine *nla; -#ifndef Q_OS_WINCE - QNetworkSessionEngine *nativeWifi; -#endif -#endif -#ifdef BACKEND_NM - QNetworkSessionEngine *nmWifi; -#endif -#ifdef Q_OS_DARWIN - QNetworkSessionEngine *coreWifi; -#endif +public: + QList sessionEngines; +private: uint onlineConfigurations; - enum EngineUpdate { - NotUpdating = 0x00, - Updating = 0x01, - GenericUpdating = 0x02, - NlaUpdating = 0x04, - NativeWifiUpdating = 0x08, - NmUpdating = 0x20, - CoreWifiUpdating = 0x40, - }; - Q_DECLARE_FLAGS(EngineUpdateState, EngineUpdate) - - EngineUpdateState updateState; + bool updating; + QSet updatingEngines; #endif private Q_SLOTS: #ifdef BEARER_ENGINE - void configurationAdded(QNetworkConfigurationPrivate *cpPriv, QNetworkSessionEngine *engine); - void configurationRemoved(const QString &id); - void configurationChanged(QNetworkConfigurationPrivate *cpPriv); + void configurationAdded(QNetworkConfigurationPrivatePointer ptr); + void configurationRemoved(QNetworkConfigurationPrivatePointer ptr); + void configurationChanged(QNetworkConfigurationPrivatePointer ptr); #endif }; diff --git a/src/network/bearer/qnetworkconfiguration_p.h b/src/network/bearer/qnetworkconfiguration_p.h index f00bcfa..8e69248 100644 --- a/src/network/bearer/qnetworkconfiguration_p.h +++ b/src/network/bearer/qnetworkconfiguration_p.h @@ -59,6 +59,7 @@ QT_BEGIN_NAMESPACE +typedef QExplicitlySharedDataPointer QNetworkConfigurationPrivatePointer; class QNetworkConfigurationPrivate : public QSharedData { public: @@ -89,7 +90,7 @@ public: bool internet; #endif - QList > serviceNetworkMembers; + QList serviceNetworkMembers; QNetworkInterface serviceInterface; private: diff --git a/src/network/bearer/qnetworksessionengine.cpp b/src/network/bearer/qnetworksessionengine.cpp index 9e6839e..0aa9d19 100644 --- a/src/network/bearer/qnetworksessionengine.cpp +++ b/src/network/bearer/qnetworksessionengine.cpp @@ -50,6 +50,17 @@ QNetworkSessionEngine::QNetworkSessionEngine(QObject *parent) QNetworkSessionEngine::~QNetworkSessionEngine() { + foreach (const QString &oldIface, snapConfigurations.keys()) { + QNetworkConfigurationPrivatePointer priv = snapConfigurations.take(oldIface); + priv->isValid = false; + priv->id.clear(); + } + + foreach (const QString &oldIface, accessPointConfigurations.keys()) { + QNetworkConfigurationPrivatePointer priv = accessPointConfigurations.take(oldIface); + priv->isValid = false; + priv->id.clear(); + } } #include "moc_qnetworksessionengine_p.cpp" diff --git a/src/network/bearer/qnetworksessionengine_p.h b/src/network/bearer/qnetworksessionengine_p.h index 9fbd4ac..0145976 100644 --- a/src/network/bearer/qnetworksessionengine_p.h +++ b/src/network/bearer/qnetworksessionengine_p.h @@ -53,14 +53,19 @@ // We mean it. // +#include "qnetworkconfiguration_p.h" + #include #include #include #include +#include +#include QT_BEGIN_NAMESPACE -class QNetworkConfigurationPrivate; +class QNetworkConfiguration; + class Q_NETWORK_EXPORT QNetworkSessionEngine : public QObject { Q_OBJECT @@ -76,7 +81,6 @@ public: QNetworkSessionEngine(QObject *parent = 0); virtual ~QNetworkSessionEngine(); - virtual QList getConfigurations(bool *ok = 0) = 0; virtual QString getInterfaceFromId(const QString &id) = 0; virtual bool hasIdentifier(const QString &id) = 0; @@ -87,8 +91,21 @@ public: virtual void requestUpdate() = 0; +public: + //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 accessPointConfigurations; + QHash snapConfigurations; + QHash userChoiceConfigurations; + Q_SIGNALS: - void configurationsChanged(); + void configurationAdded(QNetworkConfigurationPrivatePointer config); + void configurationRemoved(QNetworkConfigurationPrivatePointer config); + void configurationChanged(QNetworkConfigurationPrivatePointer config); + + void updateCompleted(); + void connectionError(const QString &id, QNetworkSessionEngine::ConnectionError error); }; diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp index 4be27ba..11dfb3e 100644 --- a/src/plugins/bearer/generic/qgenericengine.cpp +++ b/src/plugins/bearer/generic/qgenericengine.cpp @@ -125,21 +125,58 @@ static QString qGetInterfaceType(const QString &interface) QGenericEngine::QGenericEngine(QObject *parent) : QNetworkSessionEngine(parent) { - connect(&pollTimer, SIGNAL(timeout()), this, SIGNAL(configurationsChanged())); + connect(&pollTimer, SIGNAL(timeout()), this, SLOT(doRequestUpdate())); pollTimer.setInterval(10000); + doRequestUpdate(); } QGenericEngine::~QGenericEngine() { } -QList QGenericEngine::getConfigurations(bool *ok) +QString QGenericEngine::getInterfaceFromId(const QString &id) +{ + return configurationInterface.value(id.toUInt()); +} + +bool QGenericEngine::hasIdentifier(const QString &id) +{ + return configurationInterface.contains(id.toUInt()); +} + +QString QGenericEngine::bearerName(const QString &id) +{ + QString interface = getInterfaceFromId(id); + + if (interface.isEmpty()) + return QString(); + + return qGetInterfaceType(interface); +} + +void QGenericEngine::connectToId(const QString &id) +{ + emit connectionError(id, OperationNotSupported); +} + +void QGenericEngine::disconnectFromId(const QString &id) +{ + emit connectionError(id, OperationNotSupported); +} + +void QGenericEngine::requestUpdate() { - if (ok) - *ok = true; + pollTimer.stop(); + QTimer::singleShot(0, this, SLOT(doRequestUpdate())); +} - QList foundConfigurations; +QGenericEngine *QGenericEngine::instance() +{ + return genericEngine(); +} +void QGenericEngine::doRequestUpdate() +{ // Immediately after connecting with a wireless access point // QNetworkInterface::allInterfaces() will sometimes return an empty list. Calling it again a // second time results in a non-empty list. If we loose interfaces we will end up removing @@ -148,6 +185,8 @@ QList QGenericEngine::getConfigurations(bool *ok if (interfaces.isEmpty()) interfaces = QNetworkInterface::allInterfaces(); + QStringList previous = accessPointConfigurations.keys(); + // create configuration for each interface while (!interfaces.isEmpty()) { QNetworkInterface interface = interfaces.takeFirst(); @@ -163,71 +202,77 @@ QList QGenericEngine::getConfigurations(bool *ok if (qGetInterfaceType(interface.name()) == QLatin1String("WLAN")) continue; - QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; - const QString humanReadableName = interface.humanReadableName(); - cpPriv->name = humanReadableName.isEmpty() ? interface.name() : humanReadableName; - cpPriv->isValid = true; - uint identifier; if (interface.index()) - identifier = qHash(QLatin1String("NLA:") + QString::number(interface.index())); + identifier = qHash(QLatin1String("generic:") + QString::number(interface.index())); else - identifier = qHash(QLatin1String("NLA:") + interface.hardwareAddress()); + identifier = qHash(QLatin1String("generic:") + interface.hardwareAddress()); + + const QString id = QString::number(identifier); - cpPriv->id = QString::number(identifier); - cpPriv->state = QNetworkConfiguration::Discovered; - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + previous.removeAll(id); + + QString name = interface.humanReadableName(); + if (name.isEmpty()) + name = interface.name(); + + QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Discovered; if (interface.flags() & QNetworkInterface::IsUp) - cpPriv->state |= QNetworkConfiguration::Active; + state |= QNetworkConfiguration::Active; - configurationInterface[identifier] = interface.name(); + if (accessPointConfigurations.contains(id)) { + QExplicitlySharedDataPointer ptr = + accessPointConfigurations.value(id); - foundConfigurations.append(cpPriv); - } + bool changed = false; - pollTimer.start(); + if (!ptr->isValid) { + ptr->isValid = true; + changed = true; + } - return foundConfigurations; -} + if (ptr->name != name) { + ptr->name = name; + changed = true; + } -QString QGenericEngine::getInterfaceFromId(const QString &id) -{ - return configurationInterface.value(id.toUInt()); -} + if (ptr->id != id) { + ptr->id = id; + changed = true; + } -bool QGenericEngine::hasIdentifier(const QString &id) -{ - return configurationInterface.contains(id.toUInt()); -} + if (ptr->state != state) { + ptr->state = state; + changed = true; + } -QString QGenericEngine::bearerName(const QString &id) -{ - QString interface = getInterfaceFromId(id); + if (changed) + emit configurationChanged(ptr); + } else { + QExplicitlySharedDataPointer ptr(new QNetworkConfigurationPrivate); - if (interface.isEmpty()) - return QString(); + ptr->name = name; + ptr->isValid = true; + ptr->id = id; + ptr->state = state; + ptr->type = QNetworkConfiguration::InternetAccessPoint; - return qGetInterfaceType(interface); -} + accessPointConfigurations.insert(id, ptr); -void QGenericEngine::connectToId(const QString &id) -{ - emit connectionError(id, OperationNotSupported); -} + emit configurationAdded(ptr); + } + } -void QGenericEngine::disconnectFromId(const QString &id) -{ - emit connectionError(id, OperationNotSupported); -} + while (!previous.isEmpty()) { + QExplicitlySharedDataPointer ptr = + accessPointConfigurations.take(previous.takeFirst()); -void QGenericEngine::requestUpdate() -{ - emit configurationsChanged(); -} + emit configurationRemoved(ptr); + } -QGenericEngine *QGenericEngine::instance() -{ - return genericEngine(); + pollTimer.start(); + + emit updateCompleted(); } QT_END_NAMESPACE diff --git a/src/plugins/bearer/generic/qgenericengine.h b/src/plugins/bearer/generic/qgenericengine.h index 9923a9b..62f964a 100644 --- a/src/plugins/bearer/generic/qgenericengine.h +++ b/src/plugins/bearer/generic/qgenericengine.h @@ -59,7 +59,6 @@ public: QGenericEngine(QObject *parent = 0); ~QGenericEngine(); - QList getConfigurations(bool *ok = 0); QString getInterfaceFromId(const QString &id); bool hasIdentifier(const QString &id); @@ -72,6 +71,9 @@ public: static QGenericEngine *instance(); +private Q_SLOTS: + void doRequestUpdate(); + private: QMap configurationInterface; QTimer pollTimer; diff --git a/src/plugins/bearer/networkmanager/qnmwifiengine.cpp b/src/plugins/bearer/networkmanager/qnmwifiengine.cpp index 4a814ec..b215023 100644 --- a/src/plugins/bearer/networkmanager/qnmwifiengine.cpp +++ b/src/plugins/bearer/networkmanager/qnmwifiengine.cpp @@ -112,7 +112,7 @@ QString QNmWifiEngine::getNameForConfiguration(QNetworkManagerInterfaceDevice *d } -QList QNmWifiEngine::getConfigurations(bool *ok) +QList QNmWifiEngine::getConfigurations(bool *ok) { // qWarning() << Q_FUNC_INFO << updated; if (ok) @@ -133,7 +133,7 @@ QList QNmWifiEngine::getConfigurations(bool *ok) //add access points updated = true; } - return foundConfigurations; + return QList(); //foundConfigurations; } void QNmWifiEngine::findConnections() @@ -411,7 +411,7 @@ bool QNmWifiEngine::hasIdentifier(const QString &id) { if (configurationInterface.contains(id)) return true; - foreach (QNetworkConfigurationPrivate *cpPriv, getConfigurations()) { + foreach (QNetworkConfigurationPrivatePointer cpPriv, getConfigurations()) { if (cpPriv->id == id) return true; } @@ -506,7 +506,7 @@ void QNmWifiEngine::requestUpdate() updated = false; knownSsids.clear(); availableAccessPoints.clear(); - emitConfigurationsChanged(); + //emitConfigurationsChanged(); } QNmWifiEngine *QNmWifiEngine::instance() diff --git a/src/plugins/bearer/networkmanager/qnmwifiengine.h b/src/plugins/bearer/networkmanager/qnmwifiengine.h index 4d514e7..d651ef4 100644 --- a/src/plugins/bearer/networkmanager/qnmwifiengine.h +++ b/src/plugins/bearer/networkmanager/qnmwifiengine.h @@ -80,7 +80,7 @@ public: QNmWifiEngine(QObject *parent = 0); ~QNmWifiEngine(); - QList getConfigurations(bool *ok = 0); + QList getConfigurations(bool *ok = 0); QString getInterfaceFromId(const QString &id); bool hasIdentifier(const QString &id); @@ -94,7 +94,7 @@ public: static QNmWifiEngine *instance(); QStringList knownSsids; - inline void emitConfigurationsChanged() { emit configurationsChanged(); } + //inline void emitConfigurationsChanged() { emit configurationsChanged(); } QNetworkConfigurationPrivate * addAccessPoint(const QString &, QDBusObjectPath ); QStringList getConnectionPathForId(const QString &uuid); -- cgit v0.12 From ee8b1156400791a077280138863336ea93a774a7 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Wed, 9 Dec 2009 16:49:06 +1000 Subject: Keep track of which QNetworkInterface is for each QNetworkConfiguration. --- src/plugins/bearer/generic/qgenericengine.cpp | 6 ++++-- src/plugins/bearer/generic/qgenericengine.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp index 11dfb3e..e70d23d 100644 --- a/src/plugins/bearer/generic/qgenericengine.cpp +++ b/src/plugins/bearer/generic/qgenericengine.cpp @@ -136,12 +136,12 @@ QGenericEngine::~QGenericEngine() QString QGenericEngine::getInterfaceFromId(const QString &id) { - return configurationInterface.value(id.toUInt()); + return configurationInterface.value(id); } bool QGenericEngine::hasIdentifier(const QString &id) { - return configurationInterface.contains(id.toUInt()); + return configurationInterface.contains(id); } QString QGenericEngine::bearerName(const QString &id) @@ -258,6 +258,7 @@ void QGenericEngine::doRequestUpdate() ptr->type = QNetworkConfiguration::InternetAccessPoint; accessPointConfigurations.insert(id, ptr); + configurationInterface.insert(id, interface.name()); emit configurationAdded(ptr); } @@ -267,6 +268,7 @@ void QGenericEngine::doRequestUpdate() QExplicitlySharedDataPointer ptr = accessPointConfigurations.take(previous.takeFirst()); + configurationInterface.remove(ptr->id); emit configurationRemoved(ptr); } diff --git a/src/plugins/bearer/generic/qgenericengine.h b/src/plugins/bearer/generic/qgenericengine.h index 62f964a..32d762d 100644 --- a/src/plugins/bearer/generic/qgenericengine.h +++ b/src/plugins/bearer/generic/qgenericengine.h @@ -75,7 +75,7 @@ private Q_SLOTS: void doRequestUpdate(); private: - QMap configurationInterface; + QMap configurationInterface; QTimer pollTimer; }; -- cgit v0.12 From 7858758772ad01e6a772cb048e4f1eda7f4ec9c3 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Wed, 9 Dec 2009 15:44:52 +1000 Subject: Rework NetworkManager backend. --- src/network/bearer/qnetworkconfigmanager.cpp | 2 + src/network/bearer/qnetworkconfigmanager_p.cpp | 47 +- src/network/bearer/qnetworkconfigmanager_p.h | 5 +- src/network/bearer/qnetworksession_p.cpp | 30 +- src/network/bearer/qnetworksessionengine_p.h | 3 + src/plugins/bearer/generic/qgenericengine.cpp | 26 +- src/plugins/bearer/generic/qgenericengine.h | 2 + src/plugins/bearer/networkmanager/main.cpp | 4 +- .../bearer/networkmanager/networkmanager.pro | 4 +- .../networkmanager/qnetworkmanagerengine.cpp | 654 ++++++++++++ .../bearer/networkmanager/qnetworkmanagerengine.h | 125 +++ .../networkmanager/qnetworkmanagerservice.cpp | 6 +- .../bearer/networkmanager/qnetworkmanagerservice.h | 4 +- .../bearer/networkmanager/qnmdbushelper.cpp | 3 + src/plugins/bearer/networkmanager/qnmdbushelper.h | 14 - .../bearer/networkmanager/qnmwifiengine.cpp | 1128 -------------------- src/plugins/bearer/networkmanager/qnmwifiengine.h | 165 --- 17 files changed, 863 insertions(+), 1359 deletions(-) create mode 100644 src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp create mode 100644 src/plugins/bearer/networkmanager/qnetworkmanagerengine.h delete mode 100644 src/plugins/bearer/networkmanager/qnmwifiengine.cpp delete mode 100644 src/plugins/bearer/networkmanager/qnmwifiengine.h diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index 6c0b17d..6b73e3c 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -48,6 +48,8 @@ #include "qnetworksessionengine_p.h" #endif +#include + QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC(QNetworkConfigurationManagerPrivate, connManager); diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 09714e5..6f833f3 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -73,15 +73,15 @@ void QNetworkConfigurationManagerPrivate::configurationAdded(QNetworkConfigurati } if (ptr->state == QNetworkConfiguration::Active) { - ++onlineConfigurations; - if (!firstUpdate && onlineConfigurations == 1) + onlineConfigurations.insert(ptr); + if (!firstUpdate && onlineConfigurations.count() == 1) emit onlineStateChanged(true); } } void QNetworkConfigurationManagerPrivate::configurationRemoved(QNetworkConfigurationPrivatePointer ptr) { - ptr.data()->isValid = false; + ptr->isValid = false; if (!firstUpdate) { QNetworkConfiguration item; @@ -89,11 +89,9 @@ void QNetworkConfigurationManagerPrivate::configurationRemoved(QNetworkConfigura emit configurationRemoved(item); } - if (ptr.data()->state == QNetworkConfiguration::Active) { - --onlineConfigurations; - if (!firstUpdate && onlineConfigurations == 0) - emit onlineStateChanged(false); - } + onlineConfigurations.remove(ptr); + if (!firstUpdate && onlineConfigurations.isEmpty()) + emit onlineStateChanged(false); } void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigurationPrivatePointer ptr) @@ -104,20 +102,17 @@ void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigura emit configurationChanged(item); } - qDebug() << "Need to recalculate online state."; - QNetworkConfiguration::StateFlags oldState = ptr->state; + bool previous = !onlineConfigurations.isEmpty(); - if (ptr->state == QNetworkConfiguration::Active && oldState != ptr->state) { - // configuration went online - ++onlineConfigurations; - if (!firstUpdate && onlineConfigurations == 1) - emit onlineStateChanged(true); - } else if (ptr->state != QNetworkConfiguration::Active && oldState == QNetworkConfiguration::Active) { - // configuration went offline - --onlineConfigurations; - if (!firstUpdate && onlineConfigurations == 0) - emit onlineStateChanged(false); - } + if (ptr->state == QNetworkConfiguration::Active) + onlineConfigurations.insert(ptr); + else + onlineConfigurations.remove(ptr); + + bool online = !onlineConfigurations.isEmpty(); + + if (!firstUpdate && online != previous) + emit onlineStateChanged(online); } void QNetworkConfigurationManagerPrivate::updateInternetServiceConfiguration() @@ -179,7 +174,7 @@ void QNetworkConfigurationManagerPrivate::updateInternetServiceConfiguration() void QNetworkConfigurationManagerPrivate::updateConfigurations() { if (firstUpdate) { - onlineConfigurations = 0; + updating = false; QFactoryLoader *l = loader(); QStringList keys = l->keys(); @@ -202,6 +197,14 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() QNetworkSessionEngine *nmWifi = nmPlugin->create(QLatin1String("networkmanager")); if (nmWifi) { sessionEngines.append(nmWifi); + connect(nmWifi, SIGNAL(updateCompleted()), + this, SIGNAL(configurationUpdateComplete())); + connect(nmWifi, SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer))); + connect(nmWifi, SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationRemoved(QNetworkConfigurationPrivatePointer))); + connect(nmWifi, SIGNAL(configurationChanged(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationChanged(QNetworkConfigurationPrivatePointer))); } } } diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index 27a0252..37e88d3 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -80,9 +80,6 @@ public: void performAsyncConfigurationUpdate(); -#ifdef BEARER_ENGINE - QHash configurationEngine; -#endif bool firstUpdate; public slots: @@ -107,7 +104,7 @@ public: QList sessionEngines; private: - uint onlineConfigurations; + QSet onlineConfigurations; bool updating; QSet updatingEngines; diff --git a/src/network/bearer/qnetworksession_p.cpp b/src/network/bearer/qnetworksession_p.cpp index df0ad3e..8421fbc 100644 --- a/src/network/bearer/qnetworksession_p.cpp +++ b/src/network/bearer/qnetworksession_p.cpp @@ -56,9 +56,10 @@ static QNetworkSessionEngine *getEngineFromId(const QString &id) { QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); - QNetworkSessionEngine *engine = priv->configurationEngine.value(id); - if (engine && engine->hasIdentifier(id)) - return engine; + foreach (QNetworkSessionEngine *engine, priv->sessionEngines) { + if (engine->hasIdentifier(id)) + return engine; + } return 0; } @@ -104,6 +105,7 @@ void QNetworkSessionPrivate::syncStateWithInterface() this, SLOT(forcedSessionClose(QNetworkConfiguration))); opened = false; + isActive = false; state = QNetworkSession::Invalid; lastError = QNetworkSession::UnknownSessionError; @@ -341,6 +343,7 @@ void QNetworkSessionPrivate::updateStateFromServiceNetwork() } state = QNetworkSession::Connected; + qDebug() << oldState << "->" << state; if (state != oldState) emit q->stateChanged(state); @@ -352,31 +355,22 @@ void QNetworkSessionPrivate::updateStateFromServiceNetwork() else state = QNetworkSession::Disconnected; + qDebug() << oldState << "->" << state; if (state != oldState) emit q->stateChanged(state); } void QNetworkSessionPrivate::updateStateFromActiveConfig() { - QNetworkSession::State oldState = state; + if (!engine) + return; - bool newActive = false; + QNetworkSession::State oldState = state; - if (!activeConfig.isValid()) { - state = QNetworkSession::Invalid; - } else if ((activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { - state = QNetworkSession::Connected; - newActive = opened; - } else if ((activeConfig.state() & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) { - state = QNetworkSession::Disconnected; - } else if ((activeConfig.state() & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) { - state = QNetworkSession::NotAvailable; - } else if ((activeConfig.state() & QNetworkConfiguration::Undefined) == QNetworkConfiguration::Undefined) { - state = QNetworkSession::NotAvailable; - } + state = engine->sessionStateForId(activeConfig.identifier()); bool oldActive = isActive; - isActive = newActive; + isActive = (state == QNetworkSession::Connected) ? opened : false; if (!oldActive && isActive) emit quitPendingWaitsForOpened(); diff --git a/src/network/bearer/qnetworksessionengine_p.h b/src/network/bearer/qnetworksessionengine_p.h index 0145976..a698c40 100644 --- a/src/network/bearer/qnetworksessionengine_p.h +++ b/src/network/bearer/qnetworksessionengine_p.h @@ -54,6 +54,7 @@ // #include "qnetworkconfiguration_p.h" +#include "qnetworksession.h" #include #include @@ -91,6 +92,8 @@ public: virtual void requestUpdate() = 0; + virtual QNetworkSession::State sessionStateForId(const QString &id) = 0; + public: //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 diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp index e70d23d..339ef9c 100644 --- a/src/plugins/bearer/generic/qgenericengine.cpp +++ b/src/plugins/bearer/generic/qgenericengine.cpp @@ -249,7 +249,7 @@ void QGenericEngine::doRequestUpdate() if (changed) emit configurationChanged(ptr); } else { - QExplicitlySharedDataPointer ptr(new QNetworkConfigurationPrivate); + QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate); ptr->name = name; ptr->isValid = true; @@ -277,5 +277,29 @@ void QGenericEngine::doRequestUpdate() emit updateCompleted(); } +QNetworkSession::State QGenericEngine::sessionStateForId(const QString &id) +{ + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + + if (!ptr) + return QNetworkSession::Invalid; + + if (!ptr->isValid) { + return QNetworkSession::Invalid; + } else if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + return QNetworkSession::Connected; + } else if ((ptr->state & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + return QNetworkSession::Disconnected; + } else if ((ptr->state & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) { + return QNetworkSession::NotAvailable; + } else if ((ptr->state & QNetworkConfiguration::Undefined) == + QNetworkConfiguration::Undefined) { + return QNetworkSession::NotAvailable; + } + + return QNetworkSession::Invalid; +} + QT_END_NAMESPACE diff --git a/src/plugins/bearer/generic/qgenericengine.h b/src/plugins/bearer/generic/qgenericengine.h index 32d762d..9359d7f 100644 --- a/src/plugins/bearer/generic/qgenericengine.h +++ b/src/plugins/bearer/generic/qgenericengine.h @@ -69,6 +69,8 @@ public: void requestUpdate(); + QNetworkSession::State sessionStateForId(const QString &id); + static QGenericEngine *instance(); private Q_SLOTS: diff --git a/src/plugins/bearer/networkmanager/main.cpp b/src/plugins/bearer/networkmanager/main.cpp index d4b74a1..b561415 100644 --- a/src/plugins/bearer/networkmanager/main.cpp +++ b/src/plugins/bearer/networkmanager/main.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qnmwifiengine.h" +#include "qnetworkmanagerengine.h" #include @@ -73,7 +73,7 @@ QStringList QNetworkManagerEnginePlugin::keys() const QBearerEngine *QNetworkManagerEnginePlugin::create(const QString &key) const { if (key == QLatin1String("networkmanager")) - return new QNmWifiEngine; + return new QNetworkManagerEngine; else return 0; } diff --git a/src/plugins/bearer/networkmanager/networkmanager.pro b/src/plugins/bearer/networkmanager/networkmanager.pro index 36d150a..79c68ea 100644 --- a/src/plugins/bearer/networkmanager/networkmanager.pro +++ b/src/plugins/bearer/networkmanager/networkmanager.pro @@ -7,12 +7,12 @@ DEFINES += BEARER_ENGINE BACKEND_NM HEADERS += qnmdbushelper.h \ qnetworkmanagerservice.h \ - qnmwifiengine.h + qnetworkmanagerengine.h SOURCES += main.cpp \ qnmdbushelper.cpp \ qnetworkmanagerservice.cpp \ - qnmwifiengine.cpp + qnetworkmanagerengine.cpp QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/bearer target.path += $$[QT_INSTALL_PLUGINS]/bearer diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp new file mode 100644 index 0000000..3de20a3 --- /dev/null +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp @@ -0,0 +1,654 @@ +/**************************************************************************** +** +** 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 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 "qnetworkmanagerengine.h" +#include "qnetworkmanagerservice.h" + +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +QNetworkManagerEngine::QNetworkManagerEngine(QObject *parent) +: QNetworkSessionEngine(parent), + interface(new QNetworkManagerInterface(this)), + systemSettings(new QNetworkManagerSettings(NM_DBUS_SERVICE_SYSTEM_SETTINGS, this)), + userSettings(new QNetworkManagerSettings(NM_DBUS_SERVICE_USER_SETTINGS, this)) +{ + interface->setConnections(); + connect(interface, SIGNAL(deviceAdded(QDBusObjectPath)), + this, SLOT(deviceAdded(QDBusObjectPath))); + connect(interface, SIGNAL(deviceRemoved(QDBusObjectPath)), + this, SLOT(deviceRemoved(QDBusObjectPath))); +#if 0 + connect(interface, SIGNAL(stateChanged(const QString,quint32)), + this, SIGNAL(configurationsChanged())); +#endif + connect(interface, SIGNAL(activationFinished(QDBusPendingCallWatcher*)), + this, SLOT(activationFinished(QDBusPendingCallWatcher*))); + connect(interface, SIGNAL(propertiesChanged(QString,QMap)), + this, SLOT(interfacePropertiesChanged(QString,QMap))); + + qDBusRegisterMetaType(); + + systemSettings->setConnections(); + connect(systemSettings, SIGNAL(newConnection(QDBusObjectPath)), + this, SLOT(newConnection(QDBusObjectPath))); + + userSettings->setConnections(); + connect(userSettings, SIGNAL(newConnection(QDBusObjectPath)), + this, SLOT(newConnection(QDBusObjectPath))); + + // Get current list of access points. + foreach (const QDBusObjectPath &devicePath, interface->getDevices()) + deviceAdded(devicePath); + + // Get connections. + foreach (const QDBusObjectPath &settingsPath, systemSettings->listConnections()) + newConnection(settingsPath, systemSettings); + foreach (const QDBusObjectPath &settingsPath, userSettings->listConnections()) + newConnection(settingsPath, userSettings); + + // Get active connections. + foreach (const QDBusObjectPath &acPath, interface->activeConnections()) { + QNetworkManagerConnectionActive *activeConnection = + new QNetworkManagerConnectionActive(acPath.path()); + activeConnections.insert(acPath.path(), activeConnection); + + activeConnection->setConnections(); + connect(activeConnection, SIGNAL(propertiesChanged(QString,QMap)), + this, SLOT(activeConnectionPropertiesChanged(QString,QMap))); + } +} + +QNetworkManagerEngine::~QNetworkManagerEngine() +{ +} + +void QNetworkManagerEngine::doRequestUpdate() +{ +} + +QString QNetworkManagerEngine::getInterfaceFromId(const QString &id) +{ + foreach (const QDBusObjectPath &acPath, interface->activeConnections()) { + QNetworkManagerConnectionActive activeConnection(acPath.path()); + + const QString identifier = QString::number(qHash(activeConnection.serviceName() + ' ' + + activeConnection.connection().path())); + + if (id == identifier) { + QList devices = activeConnection.devices(); + + if (devices.isEmpty()) + continue; + + if (devices.count() > 1) + qDebug() << "multiple network interfaces for" << id; + + QNetworkManagerInterfaceDevice device(devices.at(0).path()); + return device.interface().name(); + } + } + + return QString(); +} + +bool QNetworkManagerEngine::hasIdentifier(const QString &id) +{ + if (connectionFromId(id)) + return true; + + for (int i = 0; i < accessPoints.count(); ++i) { + QNetworkManagerInterfaceAccessPoint *accessPoint = accessPoints.at(i); + + const QString identifier = + QString::number(qHash(accessPoint->connectionInterface()->path())); + + if (id == identifier) + return true; + } + + return false; +} + +QString QNetworkManagerEngine::bearerName(const QString &id) +{ + QNetworkManagerSettingsConnection *connection = connectionFromId(id); + + if (!connection) + return QString(); + + QNmSettingsMap map = connection->getSettings(); + const QString connectionType = map.value("connection").value("type").toString(); + + if (connectionType == "802-3-ethernet") + return QLatin1String("Ethernet"); + else if (connectionType == "802-11-wireless") + return QLatin1String("WLAN"); + else if (connectionType == "gsm") + return QLatin1String("2G"); + else if (connectionType == "cdma") + return QLatin1String("CDMA2000"); + else + return QString(); +} + +void QNetworkManagerEngine::connectToId(const QString &id) +{ + QNetworkManagerSettingsConnection *connection = connectionFromId(id); + + if (!connection) + return; + + QNmSettingsMap map = connection->getSettings(); + const QString connectionType = map.value("connection").value("type").toString(); + + QString dbusDevicePath; + foreach (const QDBusObjectPath &devicePath, interface->getDevices()) { + QNetworkManagerInterfaceDevice device(devicePath.path()); + if (device.deviceType() == DEVICE_TYPE_802_3_ETHERNET && + connectionType == QLatin1String("802-3-ethernet")) { + dbusDevicePath = devicePath.path(); + break; + } else if (device.deviceType() == DEVICE_TYPE_802_11_WIRELESS && + connectionType == QLatin1String("802-11-wireless")) { + dbusDevicePath = devicePath.path(); + break; + } + } + + const QString service = connection->connectionInterface()->service(); + const QString settingsPath = connection->connectionInterface()->path(); + + interface->activateConnection(service, QDBusObjectPath(settingsPath), + QDBusObjectPath(dbusDevicePath), QDBusObjectPath("/")); +} + +void QNetworkManagerEngine::disconnectFromId(const QString &id) +{ + foreach (const QDBusObjectPath &acPath, interface->activeConnections()) { + QNetworkManagerConnectionActive activeConnection(acPath.path()); + + const QString identifier = QString::number(qHash(activeConnection.serviceName() + ' ' + + activeConnection.connection().path())); + + if (id == identifier && accessPointConfigurations.contains(id)) { + interface->deactivateConnection(acPath); + break; + } + } +} + +void QNetworkManagerEngine::requestUpdate() +{ + QTimer::singleShot(0, this, SLOT(doRequestUpdate())); +} + +void QNetworkManagerEngine::interfacePropertiesChanged(const QString &path, + const QMap &properties) +{ + QMapIterator i(properties); + while (i.hasNext()) { + i.next(); + + if (i.key() == QLatin1String("ActiveConnections")) { + // Active connections changed, update configurations. + + QList activeConnections = + qdbus_cast >(i.value().value()); + + QStringList identifiers = accessPointConfigurations.keys(); + foreach (const QString &id, identifiers) + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + + QStringList priorActiveConnections = this->activeConnections.keys(); + + foreach (const QDBusObjectPath &acPath, activeConnections) { + priorActiveConnections.removeOne(acPath.path()); + QNetworkManagerConnectionActive *activeConnection = + this->activeConnections.value(acPath.path()); + if (!activeConnection) { + activeConnection = new QNetworkManagerConnectionActive(acPath.path()); + this->activeConnections.insert(acPath.path(), activeConnection); + + activeConnection->setConnections(); + connect(activeConnection, SIGNAL(propertiesChanged(QString,QMap)), + this, SLOT(activeConnectionPropertiesChanged(QString,QMap))); + } + + const QString id = QString::number(qHash(activeConnection->serviceName() + ' ' + + activeConnection->connection().path())); + + identifiers.removeOne(id); + + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + if (ptr) { + if (activeConnection->state() == 2 && + ptr->state != QNetworkConfiguration::Active) { + ptr->state = QNetworkConfiguration::Active; + emit configurationChanged(ptr); + } + } + } + + while (!priorActiveConnections.isEmpty()) + delete this->activeConnections.take(priorActiveConnections.takeFirst()); + + while (!identifiers.isEmpty()) { + // These configurations are not active + QNetworkConfigurationPrivatePointer ptr = + accessPointConfigurations.value(identifiers.takeFirst()); + + if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + ptr->state = QNetworkConfiguration::Discovered; + emit configurationChanged(ptr); + } + } + } + } +} + +void QNetworkManagerEngine::activeConnectionPropertiesChanged(const QString &path, + const QMap &properties) +{ + QNetworkManagerConnectionActive *activeConnection = activeConnections.value(path); + + if (!activeConnection) + return; + + const QString id = QString::number(qHash(activeConnection->serviceName() + ' ' + + activeConnection->connection().path())); + + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + if (ptr) { + if (activeConnection->state() == 2 && + ptr->state != QNetworkConfiguration::Active) { + ptr->state = QNetworkConfiguration::Active; + emit configurationChanged(ptr); + } + } +} + +void QNetworkManagerEngine::deviceAdded(const QDBusObjectPath &path) +{ + QNetworkManagerInterfaceDevice device(path.path()); + if (device.deviceType() == DEVICE_TYPE_802_11_WIRELESS) { + QNetworkManagerInterfaceDeviceWireless *wirelessDevice = + new QNetworkManagerInterfaceDeviceWireless(device.connectionInterface()->path()); + wirelessDevices.insert(path.path(), wirelessDevice); + + wirelessDevice->setConnections(); + connect(wirelessDevice, SIGNAL(accessPointAdded(QString,QDBusObjectPath)), + this, SLOT(newAccessPoint(QString,QDBusObjectPath))); + connect(wirelessDevice, SIGNAL(accessPointRemoved(QString,QDBusObjectPath)), + this, SLOT(removeAccessPoint(QString,QDBusObjectPath))); + connect(wirelessDevice, SIGNAL(propertiesChanged(QString,QMap)), + this, SLOT(devicePropertiesChanged(QString,QMap))); + + foreach (const QDBusObjectPath &apPath, wirelessDevice->getAccessPoints()) + newAccessPoint(QString(), apPath); + } +} + +void QNetworkManagerEngine::deviceRemoved(const QDBusObjectPath &path) +{ + delete wirelessDevices.value(path.path()); +} + +void QNetworkManagerEngine::newConnection(const QDBusObjectPath &path, + QNetworkManagerSettings *settings) +{ + if (!settings) + settings = qobject_cast(sender()); + + if (!settings) + return; + + QNetworkManagerSettingsConnection *connection = + new QNetworkManagerSettingsConnection(settings->connectionInterface()->service(), + path.path()); + connections.append(connection); + + connect(connection, SIGNAL(removed(QString)), this, SLOT(removeConnection(QString))); + connect(connection, SIGNAL(updated(const QNmSettingsMap&)), + this, SLOT(updateConnection(const QNmSettingsMap&))); + + const QString service = connection->connectionInterface()->service(); + const QString settingsPath = connection->connectionInterface()->path(); + + QNetworkConfigurationPrivate *cpPriv = + parseConnection(service, settingsPath, connection->getSettings()); + + // Check if connection is active. + foreach (const QDBusObjectPath &acPath, interface->activeConnections()) { + QNetworkManagerConnectionActive activeConnection(acPath.path()); + + if (activeConnection.serviceName() == service && + activeConnection.connection().path() == settingsPath && + activeConnection.state() == 2) { + cpPriv->state |= QNetworkConfiguration::Active; + break; + } + } + + QNetworkConfigurationPrivatePointer ptr(cpPriv); + accessPointConfigurations.insert(ptr->id, ptr); + emit configurationAdded(ptr); +} + +void QNetworkManagerEngine::removeConnection(const QString &path) +{ + QNetworkManagerSettingsConnection *connection = + qobject_cast(sender()); + if (!connection) + return; + + connections.removeAll(connection); + + const QString id = QString::number(qHash(connection->connectionInterface()->service() + ' ' + + connection->connectionInterface()->path())); + + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(id); + ptr->isValid = false; + emit configurationRemoved(ptr); +} + +void QNetworkManagerEngine::updateConnection(const QNmSettingsMap &settings) +{ + QNetworkManagerSettingsConnection *connection = + qobject_cast(sender()); + if (!connection) + return; + + const QString service = connection->connectionInterface()->service(); + const QString settingsPath = connection->connectionInterface()->path(); + + qDebug() << "Should parse connection directly into existing configuration"; + QNetworkConfigurationPrivate *cpPriv = parseConnection(service, settingsPath, settings); + + // Check if connection is active. + foreach (const QDBusObjectPath &acPath, interface->activeConnections()) { + QNetworkManagerConnectionActive activeConnection(acPath.path()); + + if (activeConnection.serviceName() == service && + activeConnection.connection().path() == settingsPath && + activeConnection.state() == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { + cpPriv->state |= QNetworkConfiguration::Active; + break; + } + } + + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(cpPriv->id); + + ptr->isValid = cpPriv->isValid; + ptr->name = cpPriv->name; + ptr->id = cpPriv->id; + ptr->state = cpPriv->state; + + emit configurationChanged(ptr); + delete cpPriv; +} + +void QNetworkManagerEngine::activationFinished(QDBusPendingCallWatcher *watcher) +{ + QDBusPendingReply reply = *watcher; + if (reply.isError()) { + qDebug() << "error connecting NM connection"; + } else { + QDBusObjectPath result = reply.value(); + + QNetworkManagerConnectionActive activeConnection(result.path()); + + const QString id = QString::number(qHash(activeConnection.serviceName() + ' ' + + activeConnection.connection().path())); + + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + if (ptr) { + if (activeConnection.state() == 2 && + ptr->state != QNetworkConfiguration::Active) { + ptr->state = QNetworkConfiguration::Active; + emit configurationChanged(ptr); + } + } + } +} + +void QNetworkManagerEngine::newAccessPoint(const QString &path, const QDBusObjectPath &objectPath) +{ + QNetworkManagerInterfaceAccessPoint *accessPoint = + new QNetworkManagerInterfaceAccessPoint(objectPath.path()); + accessPoints.append(accessPoint); + + accessPoint->setConnections(); + connect(accessPoint, SIGNAL(propertiesChanged(QMap)), + this, SLOT(updateAccessPoint(QMap))); + + // Check if configuration for this SSID already exists. + for (int i = 0; i < accessPoints.count(); ++i) { + if (accessPoint != accessPoints.at(i) && + accessPoint->ssid() == accessPoints.at(i)->ssid()) { + return; + } + } + + // Check if configuration exists for connection. + for (int i = 0; i < connections.count(); ++i) { + QNetworkManagerSettingsConnection *connection = connections.at(i); + + if (accessPoint->ssid() == connection->getSsid()) { + const QString service = connection->connectionInterface()->service(); + const QString settingsPath = connection->connectionInterface()->path(); + const QString connectionId = QString::number(qHash(service + ' ' + settingsPath)); + + QNetworkConfigurationPrivatePointer ptr = + accessPointConfigurations.value(connectionId); + ptr->state = QNetworkConfiguration::Discovered; + emit configurationChanged(ptr); + return; + } + } + + // New access point. + QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate); + + ptr->name = accessPoint->ssid(); + ptr->isValid = true; + ptr->id = QString::number(qHash(objectPath.path())); + ptr->type = QNetworkConfiguration::InternetAccessPoint; + ptr->purpose = QNetworkConfiguration::PublicPurpose; + ptr->state = QNetworkConfiguration::Undefined; + + accessPointConfigurations.insert(ptr->id, ptr); + emit configurationAdded(ptr); +} + +void QNetworkManagerEngine::removeAccessPoint(const QString &path, + const QDBusObjectPath &objectPath) +{ + for (int i = 0; i < accessPoints.count(); ++i) { + QNetworkManagerInterfaceAccessPoint *accessPoint = accessPoints.at(i); + + if (accessPoint->connectionInterface()->path() == objectPath.path()) { + accessPoints.removeOne(accessPoint); + + if (configuredAccessPoints.contains(accessPoint)) { + // find connection and change state to Defined + configuredAccessPoints.removeOne(accessPoint); + qDebug() << "At least one connection is no longer discovered."; + } else { + // emit configurationRemoved(cpPriv); + qDebug() << "An unconfigured wifi access point was removed."; + } + + break; + } + } +} + +void QNetworkManagerEngine::updateAccessPoint(const QMap &map) +{ + QNetworkManagerInterfaceAccessPoint *accessPoint = + qobject_cast(sender()); + if (!accessPoint) + return; + + qDebug() << "update access point" << accessPoint; +} + +QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QString &service, + const QString &settingsPath, + const QNmSettingsMap &map) +{ + QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; + cpPriv->name = map.value("connection").value("id").toString(); + cpPriv->isValid = true; + cpPriv->id = QString::number(qHash(service + ' ' + settingsPath)); + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + + cpPriv->purpose = QNetworkConfiguration::PublicPurpose; + + cpPriv->state = QNetworkConfiguration::Defined; + + const QString connectionType = map.value("connection").value("type").toString(); + + if (connectionType == QLatin1String("802-3-ethernet")) { + foreach (const QDBusObjectPath &devicePath, interface->getDevices()) { + QNetworkManagerInterfaceDevice device(devicePath.path()); + if (device.deviceType() == DEVICE_TYPE_802_3_ETHERNET) { + QNetworkManagerInterfaceDeviceWired wiredDevice(device.connectionInterface()->path()); + if (wiredDevice.carrier()) { + cpPriv->state |= QNetworkConfiguration::Discovered; + break; + } + + } + } + } else if (connectionType == QLatin1String("802-11-wireless")) { + const QString connectionSsid = map.value("802-11-wireless").value("ssid").toString(); + + for (int i = 0; i < accessPoints.count(); ++i) { + if (connectionSsid == accessPoints.at(i)->ssid()) { + cpPriv->state |= QNetworkConfiguration::Discovered; + if (!configuredAccessPoints.contains(accessPoints.at(i))) { + configuredAccessPoints.append(accessPoints.at(i)); + + const QString accessPointId = + QString::number(qHash(accessPoints.at(i)->connectionInterface()->path())); + QNetworkConfigurationPrivatePointer ptr = + accessPointConfigurations.take(accessPointId); + emit configurationRemoved(ptr); + } + break; + } + } + } + + return cpPriv; +} + +QNetworkManagerSettingsConnection *QNetworkManagerEngine::connectionFromId(const QString &id) const +{ + for (int i = 0; i < connections.count(); ++i) { + QNetworkManagerSettingsConnection *connection = connections.at(i); + const QString service = connection->connectionInterface()->service(); + const QString settingsPath = connection->connectionInterface()->path(); + + const QString identifier = QString::number(qHash(service + ' ' + settingsPath)); + + if (id == identifier) + return connection; + } + + return 0; +} + +QNetworkSession::State QNetworkManagerEngine::sessionStateForId(const QString &id) +{ + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + + if (!ptr) + return QNetworkSession::Invalid; + + if (!ptr->isValid) + return QNetworkSession::Invalid; + + foreach (const QString &acPath, activeConnections.keys()) { + QNetworkManagerConnectionActive *activeConnection = activeConnections.value(acPath); + + const QString identifier = QString::number(qHash(activeConnection->serviceName() + ' ' + + activeConnection->connection().path())); + + if (id == identifier) { + switch (activeConnection->state()) { + case 0: + return QNetworkSession::Disconnected; + case 1: + return QNetworkSession::Connecting; + case 2: + return QNetworkSession::Connected; + } + } + } + + if ((ptr->state & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) + return QNetworkSession::Disconnected; + else if ((ptr->state & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) + return QNetworkSession::NotAvailable; + else if ((ptr->state & QNetworkConfiguration::Undefined) == QNetworkConfiguration::Undefined) + return QNetworkSession::NotAvailable; + + return QNetworkSession::Invalid; +} + +QT_END_NAMESPACE + diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h new file mode 100644 index 0000000..9e8af3b --- /dev/null +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h @@ -0,0 +1,125 @@ +/**************************************************************************** +** +** 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 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 QNETWORKMANAGERENGINE_P_H +#define QNETWORKMANAGERENGINE_P_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 + +#include "qnetworkmanagerservice.h" + +#include +#include + +QT_BEGIN_NAMESPACE + +class QNetworkManagerEngine : public QNetworkSessionEngine +{ + Q_OBJECT + +public: + QNetworkManagerEngine(QObject *parent = 0); + ~QNetworkManagerEngine(); + + QString getInterfaceFromId(const QString &id); + bool hasIdentifier(const QString &id); + + QString bearerName(const QString &id); + + void connectToId(const QString &id); + void disconnectFromId(const QString &id); + + void requestUpdate(); + + QNetworkSession::State sessionStateForId(const QString &id); + +private Q_SLOTS: + void interfacePropertiesChanged(const QString &path, + const QMap &properties); + void activeConnectionPropertiesChanged(const QString &path, + const QMap &properties); + + void deviceAdded(const QDBusObjectPath &path); + void deviceRemoved(const QDBusObjectPath &path); + + void newConnection(const QDBusObjectPath &path, QNetworkManagerSettings *settings = 0); + void removeConnection(const QString &path); + void updateConnection(const QNmSettingsMap &settings); + void activationFinished(QDBusPendingCallWatcher *watcher); + + void newAccessPoint(const QString &path, const QDBusObjectPath &objectPath); + void removeAccessPoint(const QString &path, const QDBusObjectPath &objectPath); + void updateAccessPoint(const QMap &map); + + void doRequestUpdate(); + +private: + QNetworkConfigurationPrivate *parseConnection(const QString &service, + const QString &settingsPath, + const QNmSettingsMap &map); + QNetworkManagerSettingsConnection *connectionFromId(const QString &id) const; + +private: + QNetworkManagerInterface *interface; + QNetworkManagerSettings *systemSettings; + QNetworkManagerSettings *userSettings; + QHash wirelessDevices; + QHash activeConnections; + QList connections; + QList accessPoints; + QList configuredAccessPoints; +}; + +QT_END_NAMESPACE + +#endif + diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp index e95c2e6..9376324 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp @@ -95,6 +95,7 @@ QNetworkManagerInterface::~QNetworkManagerInterface() { delete d->connectionInterface; delete d; + delete nmDBusHelper; } bool QNetworkManagerInterface::isValid() @@ -692,9 +693,12 @@ bool QNetworkManagerSettingsConnection::setConnections() bool allOk = false; if(!dbusConnection.connect(d->service, d->path, - NM_DBUS_IFACE_SETTINGS_CONNECTION, "NewConnection", + NM_DBUS_IFACE_SETTINGS_CONNECTION, "Updated", this, SIGNAL(updated(QNmSettingsMap)))) { allOk = true; + } else { + QDBusError error = dbusConnection.lastError(); + qDebug() << error.name() << error.message() << error.type(); } nmDBusHelper = new QNmDBusHelper; diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h index 8bed45b..dbed01e 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h @@ -329,8 +329,8 @@ public: Q_SIGNALS: - void updated(QMap< QString, QMap > s); - void removed(const QString &); + void updated(const QNmSettingsMap &settings); + void removed(const QString &path); private: QNmDBusHelper *nmDBusHelper; diff --git a/src/plugins/bearer/networkmanager/qnmdbushelper.cpp b/src/plugins/bearer/networkmanager/qnmdbushelper.cpp index 1d16e55..f93a63d 100644 --- a/src/plugins/bearer/networkmanager/qnmdbushelper.cpp +++ b/src/plugins/bearer/networkmanager/qnmdbushelper.cpp @@ -96,11 +96,14 @@ void QNmDBusHelper::slotPropertiesChanged(QMap map) emit pathForPropertiesChanged( msg.path(), map); } } else if( i.key() == "ActiveAccessPoint") { + emit pathForPropertiesChanged(msg.path(), map); // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value().value().path(); // } else if( i.key() == "Strength") // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value().toUInt(); // else // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value(); + } else if (i.key() == "ActiveConnections") { + emit pathForPropertiesChanged(msg.path(), map); } } } diff --git a/src/plugins/bearer/networkmanager/qnmdbushelper.h b/src/plugins/bearer/networkmanager/qnmdbushelper.h index 9794f98..410b69f 100644 --- a/src/plugins/bearer/networkmanager/qnmdbushelper.h +++ b/src/plugins/bearer/networkmanager/qnmdbushelper.h @@ -42,25 +42,12 @@ #ifndef QNMDBUSHELPERPRIVATE_H #define QNMDBUSHELPERPRIVATE_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 #include #include QT_BEGIN_NAMESPACE -#if !defined(QT_NO_DBUS) && !defined(Q_OS_MAC) - class QNmDBusHelper: public QObject, protected QDBusContext { Q_OBJECT @@ -80,7 +67,6 @@ Q_SIGNALS: void pathForPropertiesChanged(const QString &, QMap); void pathForSettingsRemoved(const QString &); }; -#endif QT_END_NAMESPACE diff --git a/src/plugins/bearer/networkmanager/qnmwifiengine.cpp b/src/plugins/bearer/networkmanager/qnmwifiengine.cpp deleted file mode 100644 index b215023..0000000 --- a/src/plugins/bearer/networkmanager/qnmwifiengine.cpp +++ /dev/null @@ -1,1128 +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 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 "qnmwifiengine.h" - -#include -#include - -#include - -#include -#include -#include "qnetworkmanagerservice.h" - -#include - -QT_BEGIN_NAMESPACE - -Q_GLOBAL_STATIC(QNmWifiEngine, nmWifiEngine) -typedef QList > QNmSettingsAddressMap; - -Q_DECLARE_METATYPE(QNmSettingsAddressMap) - -QNmWifiEngine::QNmWifiEngine(QObject *parent) -: QNetworkSessionEngine(parent) -{ - iface = new QNetworkManagerInterface(); - if(!iface->isValid()) { - return; - } - iface->setConnections(); - connect(iface,SIGNAL(deviceAdded(QDBusObjectPath)), - this,SLOT(addDevice(QDBusObjectPath))); - connect(iface,SIGNAL(deviceRemoved(QDBusObjectPath)), - this,SLOT(removeDevice(QDBusObjectPath))); - - QList list = iface->getDevices(); - - foreach(QDBusObjectPath path, list) { - addDevice(path); - } - - QStringList connectionServices; - connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; - connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; - foreach (QString service, connectionServices) { - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(service); - settingsiface->setConnections(); - connect(settingsiface,SIGNAL(newConnection(QDBusObjectPath)), - this,(SLOT(newConnection(QDBusObjectPath)))); - } - - updated = false; -} - -QNmWifiEngine::~QNmWifiEngine() -{ -} - -QString QNmWifiEngine::getNameForConfiguration(QNetworkManagerInterfaceDevice *devIface) -{ - QString newname; - if (devIface->state() == NM_DEVICE_STATE_ACTIVATED) { - QString path = devIface->ip4config().path(); - QNetworkManagerIp4Config * ipIface; - ipIface = new QNetworkManagerIp4Config(path); - newname = ipIface->domains().join(" "); - } - //fallback to interface name - if(newname.isEmpty()) - newname = devIface->interface().name(); - return newname; -} - - -QList QNmWifiEngine::getConfigurations(bool *ok) -{ -// qWarning() << Q_FUNC_INFO << updated; - if (ok) - *ok = false; - - if(!updated) { - foundConfigurations.clear(); - if(knownSsids.isEmpty()) - getKnownSsids(); // list of ssids that have user configurations. - - scanForAccessPoints(); - getActiveConnectionsPaths(); - knownConnections(); - - accessPointConnections(); - -// findConnections(); - //add access points - updated = true; - } - return QList(); //foundConfigurations; -} - -void QNmWifiEngine::findConnections() -{ - QList list = iface->getDevices(); - - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); - - //// eth - switch (devIface->deviceType()) { -// qWarning() << devIface->connectionInterface()->path(); - - case DEVICE_TYPE_802_3_ETHERNET: - { - QString ident; - QNetworkManagerInterfaceDeviceWired *devWiredIface; - devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); - - ident = devWiredIface->hwAddress(); - - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - cpPriv->name = getNameForConfiguration(devIface); - cpPriv->isValid = true; - cpPriv->id = ident; - cpPriv->internet = devWiredIface->carrier(); - - cpPriv->serviceInterface = devIface->interface(); - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - switch (devIface->state()) { - case NM_DEVICE_STATE_UNKNOWN: - case NM_DEVICE_STATE_UNMANAGED: - case NM_DEVICE_STATE_FAILED: - cpPriv->state = (cpPriv->state | QNetworkConfiguration::Undefined); - break; - case NM_DEVICE_STATE_UNAVAILABLE: - cpPriv->state = (cpPriv->state | QNetworkConfiguration::Defined); - break; - case NM_DEVICE_STATE_PREPARE: - case NM_DEVICE_STATE_CONFIG: - case NM_DEVICE_STATE_NEED_AUTH: - case NM_DEVICE_STATE_IP_CONFIG: - case NM_DEVICE_STATE_DISCONNECTED: - { - cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Discovered - | QNetworkConfiguration::Defined); - } - break; - case NM_DEVICE_STATE_ACTIVATED: - cpPriv->state = (cpPriv->state | QNetworkConfiguration::Active ); - break; - default: - cpPriv->state = (cpPriv->state | QNetworkConfiguration::Undefined); - break; - }; - cpPriv->purpose = QNetworkConfiguration::PublicPurpose; - foundConfigurations.append(cpPriv); - configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); - } - break; - case DEVICE_TYPE_802_11_WIRELESS: - { -// QNetworkManagerInterfaceDeviceWireless *devWirelessIface; -// devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); -// -// //// connections -// QStringList connectionServices; -// connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; -// connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; -// -// QString connPath; -// -// foreach (QString service, connectionServices) { -// QString ident; -// QNetworkManagerSettings *settingsiface; -// settingsiface = new QNetworkManagerSettings(service); -// QList list = settingsiface->listConnections(); -// -// foreach(QDBusObjectPath path, list) { //for each connection path -//qWarning() << path.path(); -// ident = path.path(); -// bool addIt = false; -// QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); -// cpPriv->isValid = true; -// cpPriv->id = ident; -// cpPriv->internet = true; -// -// cpPriv->type = QNetworkConfiguration::InternetAccessPoint; -// cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Discovered -// | QNetworkConfiguration::Defined); -// cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; -// -// QNetworkManagerSettingsConnection *sysIface; -// sysIface = new QNetworkManagerSettingsConnection(service, path.path()); -// cpPriv->name = sysIface->getId();//ii.value().toString(); -//qWarning() << cpPriv->name; -// if(sysIface->getType() == DEVICE_TYPE_802_3_ETHERNET/*type == "802-3-ethernet"*/ -// && devIface->deviceType() == DEVICE_TYPE_802_3_ETHERNET) { -// cpPriv->serviceInterface = devIface->interface(); -// addIt = true; -// } else if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS/*type == "802-11-wireless"*/ -// && devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { -// cpPriv->serviceInterface = devIface->interface(); -// addIt = true; -// // get the wifi interface state first.. do we need this? -// // QString activeAPPath = devWirelessIface->activeAccessPoint().path(); -// } -// -// //#if 0 -// foreach(QString conpath, activeConnectionPaths) { -// QNetworkManagerConnectionActive *aConn; -// aConn = new QNetworkManagerConnectionActive(conpath); -// // in case of accesspoint, specificObject will hold the accessPOintObjectPath -// // qWarning() << aConn->connection().path() << aConn->specificObject().path() << aConn->devices().count(); -// if( aConn->connection().path() == ident) { -// -// QList devs = aConn->devices(); -// foreach(QDBusObjectPath device, devs) { -// QNetworkManagerInterfaceDevice *ifaceDevice; -// ifaceDevice = new QNetworkManagerInterfaceDevice(device.path()); -// cpPriv->serviceInterface = ifaceDevice->interface(); -// cpPriv->state = getStateFlag(ifaceDevice->state()); -// //cpPriv->accessPoint = aConn->specificObject().path(); -// -// break; -// } -// } -// } -// //#endif -// // } //end while connection -// if(addIt) { -// foundConfigurations.append(cpPriv); -// configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); -// } -// } -// } //end each connection service -// -// // ////////////// AccessPoints -//// QList apList = devWirelessIface->getAccessPoints(); -////// qWarning() << apList.count(); -//// foreach(QDBusObjectPath path, apList) { -//// QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); -//// cpPriv = addAccessPoint( devIface->connectionInterface()->path(), path); -//// if(cpPriv->isValid) { -//// foundConfigurations.append(cpPriv); -//// } -//// } - } // end DEVICE_TYPE_802_11_WIRELESS - break; - }; - } //end foreach device -} - -void QNmWifiEngine::knownConnections() -{ -// qWarning() << Q_FUNC_INFO; - //// connections - QStringList connectionServices; - connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; - connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; - - QString connPath; - - foreach (QString service, connectionServices) { - QString ident; - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(service); - QList list = settingsiface->listConnections(); - -// qWarning() <setConnections(); - connect(sysIface, SIGNAL(removed(QString)), - this,SLOT(settingsConnectionRemoved(QString))); - - cpPriv->name = sysIface->getId(); - cpPriv->isValid = true; - cpPriv->id = sysIface->getUuid(); -// cpPriv->id = ident; - cpPriv->internet = true; - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; -//qWarning() << cpPriv->name; - cpPriv->state = getStateForId(cpPriv->id); - - cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; - - if(sysIface->getType() == DEVICE_TYPE_802_3_ETHERNET) { - QString mac = sysIface->getMacAddress(); - if(!mac.length() > 2) { - qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXX" << mac << "type ethernet"; - QString devPath; - devPath = deviceConnectionPath(mac); - - // qWarning() << Q_FUNC_INFO << devPath; - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(devPath); - cpPriv->serviceInterface = devIface->interface(); - QNetworkManagerInterfaceDeviceWired *devWiredIface; - devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); - cpPriv->internet = devWiredIface->carrier(); - - // use this mac addy - } else { - cpPriv->serviceInterface = getBestInterface( DEVICE_TYPE_802_3_ETHERNET, cpPriv->id); - } - - cpPriv->internet = true;//sysIface->isAutoConnect(); - - addIt = true; - } else if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS) { - QString mac = sysIface->getMacAddress();; - if(!mac.length() > 2) { - qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXX" << mac << "type wireless"; - QString devPath; - devPath = deviceConnectionPath(mac); -// qWarning() << Q_FUNC_INFO << devPath; - - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(devPath); - cpPriv->serviceInterface = devIface->interface(); - // use this mac addy - } else { - cpPriv->serviceInterface = getBestInterface( DEVICE_TYPE_802_11_WIRELESS, cpPriv->id); - } - // cpPriv->serviceInterface = devIface->interface(); - addIt = true; - // get the wifi interface state first.. do we need this? - // QString activeAPPath = devWirelessIface->activeAccessPoint().path(); - } - if(addIt) { - foundConfigurations.append(cpPriv); - configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); - } - } //end each connection service - } -} - -void QNmWifiEngine::accessPointConnections() -{ - //qWarning() << Q_FUNC_INFO; - QList list = iface->getDevices(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(path.path()); - if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { - QList apList = availableAccessPoints.uniqueKeys(); - - QList::const_iterator i; - for (i = apList.constBegin(); i != apList.constEnd(); ++i) { - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - cpPriv = addAccessPoint( devIface->connectionInterface()->path(), availableAccessPoints[*i]); - if(cpPriv->isValid) { - foundConfigurations.append(cpPriv); - // qWarning() << "adding" << cpPriv->name << "to things"; - configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); - } - } - } - } -} - -QString QNmWifiEngine::getInterfaceFromId(const QString &id) -{ - return configurationInterface.value(id); -} - -bool QNmWifiEngine::hasIdentifier(const QString &id) -{ - if (configurationInterface.contains(id)) - return true; - foreach (QNetworkConfigurationPrivatePointer cpPriv, getConfigurations()) { - if (cpPriv->id == id) - return true; - } - return false; -} - -QString QNmWifiEngine::bearerName(const QString &id) -{ - QString interface = getInterfaceFromId(id); - - QList list = iface->getDevices(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(path.path()); - if(interface == devIface->interface().name()) { - switch(devIface->deviceType()) { - case DEVICE_TYPE_802_3_ETHERNET/*NM_DEVICE_TYPE_ETHERNET*/: - return QLatin1String("Ethernet"); - break; - case DEVICE_TYPE_802_11_WIRELESS/*NM_DEVICE_TYPE_WIFI*/: - return QLatin1String("WLAN"); - break; - case DEVICE_TYPE_GSM/*NM_DEVICE_TYPE_GSM*/: - return QLatin1String("2G"); - break; - case DEVICE_TYPE_CDMA/*NM_DEVICE_TYPE_CDMA*/: - return QLatin1String("CDMA2000"); - break; - default: - break; - }; - } - } - return QString(); -} - -void QNmWifiEngine::connectToId(const QString &id) -{ -// qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << __FUNCTION__ << id; - activatingConnectionPath = id; - QStringList connectionSettings = getConnectionPathForId(id); - if(connectionSettings.isEmpty()) { - emit connectionError(id, OperationNotSupported); - return; - } - - QDBusObjectPath connectionPath(connectionSettings.at(1)); - QString interface = getInterfaceFromId(id); - - interface = QNetworkInterface::interfaceFromName(interface).hardwareAddress().toLower(); - QString devPath; - devPath = deviceConnectionPath(interface); - QDBusObjectPath devicePath(devPath); - - iface = new QNetworkManagerInterface(); - iface->activateConnection( - connectionSettings.at(0), - connectionPath, - devicePath, - connectionPath); - - connect(iface, SIGNAL(activationFinished(QDBusPendingCallWatcher*)), - this, SLOT(slotActivationFinished(QDBusPendingCallWatcher*))); -} - -void QNmWifiEngine::disconnectFromId(const QString &id) -{ - QString activeConnectionPath = getActiveConnectionPath(id); - //qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << __FUNCTION__ << id << activeConnectionPath ; - - if (!activeConnectionPath.isEmpty()) { - QNetworkManagerConnectionActive *activeCon; - activeCon = new QNetworkManagerConnectionActive(activeConnectionPath); - QNetworkManagerSettingsConnection *settingsCon; - settingsCon = new QNetworkManagerSettingsConnection(activeCon->serviceName(), activeCon->connection().path()); - - if(settingsCon->isAutoConnect()) { -// qWarning() << id << "is autoconnect"; - emit connectionError(id, OperationNotSupported); - //unsupported - } else { -// qWarning() <deactivateConnection(dbpath); - activatingConnectionPath = ""; - } - } -} - -void QNmWifiEngine::requestUpdate() -{ - updated = false; - knownSsids.clear(); - availableAccessPoints.clear(); - //emitConfigurationsChanged(); -} - -QNmWifiEngine *QNmWifiEngine::instance() -{ - QDBusConnection dbusConnection = QDBusConnection::systemBus(); - if (dbusConnection.isConnected()) { - QDBusConnectionInterface *dbiface = dbusConnection.interface(); - QDBusReply reply = dbiface->isServiceRegistered("org.freedesktop.NetworkManager"); - if (reply.isValid() && reply.value()) - return nmWifiEngine(); - } - - return 0; -} - -void QNmWifiEngine::getKnownSsids() -{ - QStringList connectionServices; - connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; - connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; -//qWarning() << Q_FUNC_INFO; - foreach (QString service, connectionServices) { - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(service); - QList list = settingsiface->listConnections(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerSettingsConnection *sysIface; - sysIface = new QNetworkManagerSettingsConnection(service, path.path()); -// qWarning() << sysIface->getSsid(); - knownSsids << sysIface->getSsid(); - } - } -} - -void QNmWifiEngine::getActiveConnectionsPaths() -{ -// qWarning() << Q_FUNC_INFO; - QNetworkManagerInterface *dbIface; - activeConnectionPaths.clear(); - dbIface = new QNetworkManagerInterface; - QList connections = dbIface->activeConnections(); - - foreach(QDBusObjectPath conpath, connections) { - activeConnectionPaths << conpath.path(); -// qWarning() << __FUNCTION__ << conpath.path() << activeConnectionPaths.count(); - - QNetworkManagerConnectionActive *activeConn; - activeConn = new QNetworkManagerConnectionActive(conpath.path()); - -// qWarning() << activeConn->connection().path() /*<< activeConn->specificObject().path() */<< activeConn->devices()[0].path(); - - } -} - -QNetworkConfigurationPrivate * QNmWifiEngine::addAccessPoint( const QString &iPath, QDBusObjectPath path) -{ //foreach accessPoint - //qWarning() << Q_FUNC_INFO << iPath << path.path(); - - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(iPath); - QNetworkManagerInterfaceDeviceWireless *devWirelessIface; - devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(iPath); - - QString activeAPPath = devWirelessIface->activeAccessPoint().path(); - - QNetworkManagerInterfaceAccessPoint *accessPointIface; - accessPointIface = new QNetworkManagerInterfaceAccessPoint(path.path()); - - QString ident = accessPointIface->connectionInterface()->path(); - quint32 nmState = devIface->state(); - - QString ssid = accessPointIface->ssid(); - QString hwAddy = accessPointIface->hwAddress(); - QString sInterface = devIface->interface().name(); - - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - bool addIt = true; - //qWarning() << availableAccessPoints.count() << ssid; - -// if(availableAccessPoints.contains(ssid)) { -// addIt = false; -// -// } -// foreach (QNetworkConfigurationPrivate *cpPriv, foundConfigurations) { -// if (cpPriv->name == ssid) { //weed out duplicate ssid's ?? -// addIt = false; -// break; -// } -// } - - if(addIt) { - - cpPriv->name = ssid; - cpPriv->isValid = true; - cpPriv->id = ident; - cpPriv->internet = true; - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - cpPriv->serviceInterface = devIface->interface(); - - //qWarning() <<__FUNCTION__ << ssid; - - cpPriv->state = getAPState(nmState, knownSsids.contains(cpPriv->name)); - - if(activeAPPath == accessPointIface->connectionInterface()->path()) { - cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Active); - } - if(accessPointIface->flags() == NM_802_11_AP_FLAGS_PRIVACY) - cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; - else - cpPriv->purpose = QNetworkConfiguration::PublicPurpose; - return cpPriv; - } else { - cpPriv->isValid = false; - } - return cpPriv; -} - - - QNetworkConfiguration::StateFlags QNmWifiEngine::getAPState(qint32 nmState, bool isKnown) -{ - QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined; -//qWarning() << nmState << knownSsids; - // this is the state of the wifi device interface - if(isKnown) - state = ( QNetworkConfiguration::Defined); - - switch(nmState) { //device interface state, not AP state - case NM_DEVICE_STATE_UNKNOWN: - case NM_DEVICE_STATE_UNMANAGED: - case NM_DEVICE_STATE_UNAVAILABLE: - state = (QNetworkConfiguration::Undefined); - break; - case NM_DEVICE_STATE_DISCONNECTED: - { - if(isKnown) - state = ( state | QNetworkConfiguration::Discovered); - } - break; - case NM_DEVICE_STATE_PREPARE: - case NM_DEVICE_STATE_CONFIG: - case NM_DEVICE_STATE_NEED_AUTH: - case NM_DEVICE_STATE_IP_CONFIG: - if(isKnown) - state = ( state | QNetworkConfiguration::Discovered); - break; - case NM_DEVICE_STATE_ACTIVATED: - { - if(isKnown) - state = ( state | QNetworkConfiguration::Discovered); - } - break; - }; - return state; -} - -QString QNmWifiEngine::getActiveConnectionPath(const QString &id) -{ - //qWarning() << Q_FUNC_INFO << id; - QStringList connectionSettings = getConnectionPathForId(id); - //qWarning() << Q_FUNC_INFO << id << connectionSettings.count(); - QNetworkManagerInterface * ifaceD; - ifaceD = new QNetworkManagerInterface(); - QList connections = ifaceD->activeConnections(); - foreach(QDBusObjectPath path, connections) { - QNetworkManagerConnectionActive *conDetailsD; - conDetailsD = new QNetworkManagerConnectionActive( path.path()); - if(conDetailsD->connection().path() == connectionSettings.at(1) - && conDetailsD->serviceName() == connectionSettings.at(0)) - return path.path(); - } - return QString(); -} - - QNetworkConfiguration::StateFlags QNmWifiEngine::getStateFlag(quint32 nmstate) - { -// qWarning() << Q_FUNC_INFO << nmstate; - QNetworkConfiguration::StateFlags flag; - switch (nmstate) { - case NM_DEVICE_STATE_UNKNOWN: - case NM_DEVICE_STATE_FAILED: - case NM_DEVICE_STATE_UNMANAGED: - flag = (QNetworkConfiguration::Undefined); - break; - case NM_DEVICE_STATE_PREPARE: - case NM_DEVICE_STATE_CONFIG: - case NM_DEVICE_STATE_NEED_AUTH: - case NM_DEVICE_STATE_IP_CONFIG: - case NM_DEVICE_STATE_UNAVAILABLE: - flag = (QNetworkConfiguration::Defined); - break; - case NM_DEVICE_STATE_DISCONNECTED: - flag = ( flag | QNetworkConfiguration::Discovered ); - break; - case NM_DEVICE_STATE_ACTIVATED: - { - flag = ( flag | QNetworkConfiguration::Discovered - | QNetworkConfiguration::Active ); - } - break; - default: - flag = ( QNetworkConfiguration::Defined); - break; - }; - return flag; - } - -void QNmWifiEngine::updateDeviceInterfaceState(const QString &/*path*/, quint32 nmState) -{ -// qWarning() << Q_FUNC_INFO << path << nmState; - - if(nmState == NM_DEVICE_STATE_ACTIVATED - || nmState == NM_DEVICE_STATE_DISCONNECTED - || nmState == NM_DEVICE_STATE_UNAVAILABLE - || nmState == NM_DEVICE_STATE_FAILED) { - -/* InterfaceLookupError = 0, - ConnectError, - OperationNotSupported, - DisconnectionError, -*/ -// qWarning() << Q_FUNC_INFO << ident; - QNetworkConfiguration::StateFlags state = (QNetworkConfiguration::Defined); - switch (nmState) { - case NM_DEVICE_STATE_UNKNOWN: - case NM_DEVICE_STATE_FAILED: - state = (QNetworkConfiguration::Undefined); - emit connectionError(activatingConnectionPath, ConnectError); - requestUpdate(); -// qWarning() << Q_FUNC_INFO; - break; - case NM_DEVICE_STATE_UNAVAILABLE: - state = (QNetworkConfiguration::Defined); -// emit connectionError(activatingConnectionPath, ConnectError); - requestUpdate(); - break; - case NM_DEVICE_STATE_DISCONNECTED: - state = ( state | QNetworkConfiguration::Discovered ); - requestUpdate(); - break; - case NM_DEVICE_STATE_ACTIVATED: - { - state = ( state | QNetworkConfiguration::Discovered - | QNetworkConfiguration::Active ); - requestUpdate(); - } - break; - default: - state = ( QNetworkConfiguration::Defined); - break; - }; - } -} - -void QNmWifiEngine::addDevice(QDBusObjectPath path) -{ - //qWarning() << Q_FUNC_INFO << path.path(); - QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); - devIface->setConnections(); - connect(devIface,SIGNAL(stateChanged(const QString &, quint32)), - this, SLOT(updateDeviceInterfaceState(const QString&, quint32))); - - if(!devicePaths.contains(path.path())) - devicePaths << path.path(); - - switch(devIface->deviceType()) { - case DEVICE_TYPE_802_3_ETHERNET: - { - QNetworkManagerInterfaceDeviceWired * devWiredIface; - devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); - devWiredIface->setConnections(); - connect(devWiredIface, SIGNAL(propertiesChanged(const QString &,QMap)), - this,SLOT(cmpPropertiesChanged( const QString &, QMap))); - requestUpdate(); - } - break; - case DEVICE_TYPE_802_11_WIRELESS: - { - QNetworkManagerInterfaceDeviceWireless *devWirelessIface; - devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); - devWirelessIface->setConnections(); - - connect(devWirelessIface, SIGNAL(propertiesChanged(const QString &,QMap)), - this,SLOT(cmpPropertiesChanged( const QString &, QMap))); - - connect(devWirelessIface, SIGNAL(accessPointAdded(const QString &,QDBusObjectPath)), - this,SLOT(accessPointAdded(const QString &,QDBusObjectPath))); - - connect(devWirelessIface, SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath)), - this,SLOT(accessPointRemoved(const QString &,QDBusObjectPath))); - requestUpdate(); - - } - break; - default: - break; - }; -} - -void QNmWifiEngine::removeDevice(QDBusObjectPath /*path*/) -{ -// qWarning() << Q_FUNC_INFO << path.path(); -// disconnect(devIface,SIGNAL(stateChanged(const QString &, quint32)), -// this, SLOT(updateDeviceInterfaceState(const QString&, quint32))); -// -// if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { -// // devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); -// // devWirelessIface->setConnections(); -// -// disconnect(devWirelessIface, SIGNAL(propertiesChanged(const QString &,QMap)), -// this,SIGNAL(cmpPropertiesChanged( const QString &, QMap))); -// -// disconnect(devWirelessIface, SIGNAL(accessPointAdded(const QString &,QDBusObjectPath)), -// this,SIGNAL(accessPointAdded(const QString &,QDBusObjectPath))); -// -// disconnect(devWirelessIface, SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath)), -// this,SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath))); -// -// } -} -void QNmWifiEngine::cmpPropertiesChanged(const QString &path, QMap map) -{ - QMapIterator i(map); - while (i.hasNext()) { - i.next(); -// qWarning() << Q_FUNC_INFO << path << i.key() << i.value().toUInt(); - if( i.key() == "State") { //only applies to device interfaces - updateDeviceInterfaceState(path, i.value().toUInt()); - } - if( i.key() == "ActiveAccessPoint") { - } - if( i.key() == "Carrier") { //someone got plugged in - // requestUpdate(); - } - } -} - -void QNmWifiEngine::accessPointRemoved( const QString &aPath, QDBusObjectPath /*oPath*/) -{ - //qWarning() << Q_FUNC_INFO << aPath << oPath.path(); - - if(aPath.contains("devices")) { - requestUpdate(); - } -} - -void QNmWifiEngine::accessPointAdded( const QString &aPath, QDBusObjectPath oPath) -{ - //qWarning() << Q_FUNC_INFO << aPath << oPath.path(); - - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - cpPriv = addAccessPoint( aPath, oPath); - requestUpdate(); -} - -QNetworkConfiguration::StateFlags QNmWifiEngine::getStateForId(const QString &id) -{ - //qWarning() << Q_FUNC_INFO << id; - bool isAvailable = false; - QStringList conPath = getConnectionPathForId(id); - QString aconpath = getActiveConnectionPath(id); - - //qWarning() << Q_FUNC_INFO << id << aconpath; - - if(!aconpath.isEmpty()) { - //active connection - QNetworkManagerConnectionActive *aConn; - aConn = new QNetworkManagerConnectionActive(aconpath); - - QList devs = aConn->devices(); - - foreach(QDBusObjectPath dev, devs) { - //qWarning() << "foreach" << dev.path(); - QNetworkManagerInterfaceDevice *ifaceDevice; - ifaceDevice = new QNetworkManagerInterfaceDevice(dev.path()); - - if(ifaceDevice->deviceType() == DEVICE_TYPE_802_3_ETHERNET) { - - if(isAddressOfConnection(id, ifaceDevice->ip4Address())) { - // this is it! - return getStateFlag(ifaceDevice->state()); - } else { - continue; - } - - if(ifaceDevice->state() == NM_DEVICE_STATE_UNAVAILABLE || - ifaceDevice->state() == NM_DEVICE_STATE_DISCONNECTED) { - isAvailable = true; - - QNetworkManagerInterfaceDeviceWired *devWiredIface; - devWiredIface = new QNetworkManagerInterfaceDeviceWired(ifaceDevice->connectionInterface()->path()); - if(!devWiredIface->carrier()) - return QNetworkConfiguration::Defined; - } //end eth - } else if(ifaceDevice->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { - qWarning() << "FIXME!!!!!!!!!!!!!!!!!"; - } - - return getStateFlag(ifaceDevice->state()); - } - } else { - // not active - //qWarning() << Q_FUNC_INFO << "Not active"; - QNetworkManagerSettingsConnection *sysIface; - sysIface = new QNetworkManagerSettingsConnection(conPath.at(0),conPath.at(1)); - if(sysIface->isValid()) { - if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS) { - QString ssid = sysIface->getSsid(); - bool ok = false; - - if(knownSsids.contains(ssid, Qt::CaseSensitive)) { - foreach(QString onessid, knownSsids) { - // qWarning() << ssid << onessid; - if(onessid == ssid && availableAccessPoints.contains(ssid)) { - // qWarning() < devices = aConn->devices(); - foreach(QDBusObjectPath device, devices) { - QNetworkManagerInterfaceDevice *ifaceDevice; - ifaceDevice = new QNetworkManagerInterfaceDevice(device.path()); - if(ifaceDevice->ip4Address() == ipaddress) { - return true; - } - } - return false; -} - -QNetworkInterface QNmWifiEngine::getBestInterface( quint32 type, const QString &id) -{ - // check active connections first. - QStringList conIdPath = getConnectionPathForId(id); -// qWarning() << Q_FUNC_INFO << id << conIdPath; - - QNetworkInterface interface; - foreach(QString conpath, activeConnectionPaths) { - QNetworkManagerConnectionActive *aConn; - aConn = new QNetworkManagerConnectionActive(conpath); - - if(aConn->connection().path() == conIdPath.at(1) - && aConn->serviceName() == conIdPath.at(0)) { - - QList devs = aConn->devices(); - QNetworkManagerInterfaceDevice *ifaceDevice; - ifaceDevice = new QNetworkManagerInterfaceDevice(devs[0].path()); //just take the first one - interface = ifaceDevice->interface(); - return interface; - } - } - -//try guessing - QList list = iface->getDevices(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); - if(devIface->deviceType() == type /*&& devIface->managed()*/) { - interface = devIface->interface(); - if(devIface->state() == NM_STATE_DISCONNECTED) { - return interface; - } - } - } - return interface; -} - -quint64 QNmWifiEngine::receivedDataForId(const QString &id) const -{ - if(configurationInterface.count() > 1) - return 0; - quint64 result = 0; - - QString devFile; - devFile = configurationInterface.value(id); - QFile rx("/sys/class/net/"+devFile+"/statistics/rx_bytes"); - if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) { - QTextStream in(&rx); - in >> result; - rx.close(); - } - return result; -} - -quint64 QNmWifiEngine::sentDataForId(const QString &id) const -{ - if(configurationInterface.count() > 1) - return 0; - quint64 result = 0; - QString devFile; - devFile = configurationInterface.value(id); - - QFile tx("/sys/class/net/"+devFile+"/statistics/tx_bytes"); - if(tx.exists() && tx.open(QIODevice::ReadOnly | QIODevice::Text)) { - QTextStream in(&tx); - in >> result; - tx.close(); - } - return result; -} - -void QNmWifiEngine::newConnection(QDBusObjectPath /*path*/) -{ - //qWarning() << Q_FUNC_INFO; - requestUpdate(); -} - -void QNmWifiEngine::settingsConnectionRemoved(const QString &/*path*/) -{ - //qWarning() << Q_FUNC_INFO; - requestUpdate(); -} - -void QNmWifiEngine::slotActivationFinished(QDBusPendingCallWatcher *openCall) -{ - QDBusPendingReply reply = *openCall; - if (reply.isError()) { - qWarning() <<"Error" << reply.error().name() << reply.error().message() - < list = iface->getDevices(); - - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(path.path()); - - if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { - -// qWarning() << devIface->connectionInterface()->path(); - - QNetworkManagerInterfaceDeviceWireless *devWirelessIface; - devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); - ////////////// AccessPoints - QList apList = devWirelessIface->getAccessPoints(); - - foreach(QDBusObjectPath path, apList) { - QNetworkManagerInterfaceAccessPoint *accessPointIface; - accessPointIface = new QNetworkManagerInterfaceAccessPoint(path.path()); - QString ssid = accessPointIface->ssid(); - availableAccessPoints.insert(ssid, path); - } - } - } -} - -QString QNmWifiEngine::deviceConnectionPath(const QString &mac) -{ -// qWarning() << __FUNCTION__ << mac; - QString newMac = mac; - newMac = newMac.replace(":","_").toLower(); - //device object path might not contain just mac address - //might contain extra numbers on the end. thanks HAL - foreach(QString device, devicePaths) { - if(device.contains(newMac)) { - newMac = device; - break; - } - } - return newMac; -} - -QStringList QNmWifiEngine::getConnectionPathForId(const QString &uuid) -{ - QStringList connectionServices; - connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; - connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; -//qWarning() << Q_FUNC_INFO; - foreach (QString service, connectionServices) { - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(service); - QList list = settingsiface->listConnections(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerSettingsConnection *sysIface; - sysIface = new QNetworkManagerSettingsConnection(service, path.path()); -// qWarning() << uuid << sysIface->getUuid(); - if(sysIface->getUuid() == uuid) { -// qWarning() <<__FUNCTION__ << service << sysIface->getId() << sysIface->connectionInterface()->path(); - return QStringList() << service << sysIface->connectionInterface()->path(); - } - } - } - return QStringList(); -} - -QT_END_NAMESPACE - diff --git a/src/plugins/bearer/networkmanager/qnmwifiengine.h b/src/plugins/bearer/networkmanager/qnmwifiengine.h deleted file mode 100644 index d651ef4..0000000 --- a/src/plugins/bearer/networkmanager/qnmwifiengine.h +++ /dev/null @@ -1,165 +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 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 QNMWIFIENGINE_P_H -#define QNMWIFIENGINE_P_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 - -#include -#include -#include - -#include "qnetworkmanagerservice.h" - -#include -#include -#include -#include - - - -QT_BEGIN_NAMESPACE - -class QNetworkConfigurationPrivate; - -class QNmWifiEngine : public QNetworkSessionEngine -{ - Q_OBJECT - -public: - QNmWifiEngine(QObject *parent = 0); - ~QNmWifiEngine(); - - QList getConfigurations(bool *ok = 0); - QString getInterfaceFromId(const QString &id); - bool hasIdentifier(const QString &id); - - QString bearerName(const QString &id); - - void connectToId(const QString &id); - void disconnectFromId(const QString &id); - - void requestUpdate(); - - static QNmWifiEngine *instance(); - - QStringList knownSsids; - //inline void emitConfigurationsChanged() { emit configurationsChanged(); } - QNetworkConfigurationPrivate * addAccessPoint(const QString &, QDBusObjectPath ); - - QStringList getConnectionPathForId(const QString &uuid); - //QString getConnectionPathForId(const QString &name = QString()); - quint64 sentDataForId(const QString &id) const; - quint64 receivedDataForId(const QString &id) const; - -private: - bool updated; - QString activatingConnectionPath; - QStringList activeConnectionPaths; - - - QMap availableAccessPoints; - void scanForAccessPoints(); - - QStringList devicePaths; - - void getActiveConnectionsPaths(); - void getKnownSsids(); - void accessPointConnections(); - void knownConnections(); - void findConnections(); - QString deviceConnectionPath(const QString &mac); - - QList foundConfigurations; - // QHash > allConfigurations; - - QNetworkManagerInterface *iface; - - QNetworkConfiguration::StateFlags getAPState(qint32 vState, bool isKnown); - QNetworkConfiguration::StateFlags getStateFlag(quint32 nmstate); - - QString getActiveConnectionPath(const QString &identifier); - QString getNameForConfiguration(QNetworkManagerInterfaceDevice *devIface); - - QNetworkConfiguration::StateFlags getStateForId(const QString &id); - - QNetworkInterface getBestInterface(quint32 type, const QString &conPath); - - QMap configurationInterface; - - bool isAddressOfConnection(const QString &conPath, quint32 ipaddress); - -private slots: - void updateDeviceInterfaceState(const QString &, quint32); - void addDevice(QDBusObjectPath path); - void removeDevice(QDBusObjectPath path); - -Q_SIGNALS: - void configurationChanged(const QNetworkConfiguration& config); - void updateAccessPointState(const QString &, quint32); -// void slotActivationFinished(QDBusPendingCallWatcher*); - -private slots: - void accessPointAdded( const QString &aPath, QDBusObjectPath oPath); - void accessPointRemoved( const QString &aPath, QDBusObjectPath oPath); - void cmpPropertiesChanged(const QString &, QMap map); - void newConnection(QDBusObjectPath); - void settingsConnectionRemoved(const QString &); - void slotActivationFinished(QDBusPendingCallWatcher*); -}; - -QT_END_NAMESPACE - -#endif - - -- cgit v0.12 From b22d0a9c4d6e3309287aefdc1a300e2fc566c2c7 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 10 Dec 2009 16:57:42 +1000 Subject: Remove unused global statics. --- src/plugins/bearer/corewlan/qcorewlanengine.h | 1 - src/plugins/bearer/corewlan/qcorewlanengine.mm | 7 ------- src/plugins/bearer/generic/qgenericengine.cpp | 7 ------- src/plugins/bearer/generic/qgenericengine.h | 2 -- src/plugins/bearer/nativewifi/qnativewifiengine.cpp | 4 ---- src/plugins/bearer/nla/qnlaengine.cpp | 9 --------- src/plugins/bearer/nla/qnlaengine.h | 2 -- 7 files changed, 32 deletions(-) diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.h b/src/plugins/bearer/corewlan/qcorewlanengine.h index 7ccfeea..2be81d1 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.h +++ b/src/plugins/bearer/corewlan/qcorewlanengine.h @@ -70,7 +70,6 @@ public: void requestUpdate(); - static QCoreWlanEngine *instance(); static bool getAllScInterfaces(); private: diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm index 9dea217..c6ea56a 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.mm +++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm @@ -66,8 +66,6 @@ QMap networkInterfaces; QT_BEGIN_NAMESPACE -Q_GLOBAL_STATIC(QCoreWlanEngine, coreWlanEngine) - inline QString cfstringRefToQstring(CFStringRef cfStringRef) { // return QString([cfStringRef UTF8String]); QString retVal; @@ -310,11 +308,6 @@ void QCoreWlanEngine::requestUpdate() emit configurationsChanged(); } -QCoreWlanEngine *QCoreWlanEngine::instance() -{ - return coreWlanEngine(); -} - QList QCoreWlanEngine::scanForSsids(const QString &interfaceName) { QList foundConfigs; diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp index 339ef9c..0d9a958 100644 --- a/src/plugins/bearer/generic/qgenericengine.cpp +++ b/src/plugins/bearer/generic/qgenericengine.cpp @@ -56,8 +56,6 @@ QT_BEGIN_NAMESPACE -Q_GLOBAL_STATIC(QGenericEngine, genericEngine) - static QString qGetInterfaceType(const QString &interface) { #ifdef Q_OS_WIN32 @@ -170,11 +168,6 @@ void QGenericEngine::requestUpdate() QTimer::singleShot(0, this, SLOT(doRequestUpdate())); } -QGenericEngine *QGenericEngine::instance() -{ - return genericEngine(); -} - void QGenericEngine::doRequestUpdate() { // Immediately after connecting with a wireless access point diff --git a/src/plugins/bearer/generic/qgenericengine.h b/src/plugins/bearer/generic/qgenericengine.h index 9359d7f..a671ceb 100644 --- a/src/plugins/bearer/generic/qgenericengine.h +++ b/src/plugins/bearer/generic/qgenericengine.h @@ -71,8 +71,6 @@ public: QNetworkSession::State sessionStateForId(const QString &id); - static QGenericEngine *instance(); - private Q_SLOTS: void doRequestUpdate(); diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp index 5ca49a9..93fc9ca 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp @@ -50,8 +50,6 @@ QT_BEGIN_NAMESPACE -Q_GLOBAL_STATIC(QNativeWifiEngine, nativeWifiEngine) - WlanOpenHandleProto local_WlanOpenHandle = 0; WlanRegisterNotificationProto local_WlanRegisterNotification = 0; WlanEnumInterfacesProto local_WlanEnumInterfaces = 0; @@ -63,8 +61,6 @@ WlanScanProto local_WlanScan = 0; WlanFreeMemoryProto local_WlanFreeMemory = 0; WlanCloseHandleProto local_WlanCloseHandle = 0; - - void qNotificationCallback(WLAN_NOTIFICATION_DATA *data, QNativeWifiEngine *d) { Q_UNUSED(d); diff --git a/src/plugins/bearer/nla/qnlaengine.cpp b/src/plugins/bearer/nla/qnlaengine.cpp index 2ad9cac..47bd8d5 100644 --- a/src/plugins/bearer/nla/qnlaengine.cpp +++ b/src/plugins/bearer/nla/qnlaengine.cpp @@ -53,8 +53,6 @@ QT_BEGIN_NAMESPACE -Q_GLOBAL_STATIC(QNlaEngine, nlaEngine) - QWindowsSockInit2::QWindowsSockInit2() : version(0) { @@ -579,13 +577,6 @@ void QNlaEngine::requestUpdate() nlaThread->forceUpdate(); } -QNlaEngine *QNlaEngine::instance() -{ - return nlaEngine(); -} - #include "qnlaengine.moc" QT_END_NAMESPACE - - diff --git a/src/plugins/bearer/nla/qnlaengine.h b/src/plugins/bearer/nla/qnlaengine.h index 1e66c83..464275d 100644 --- a/src/plugins/bearer/nla/qnlaengine.h +++ b/src/plugins/bearer/nla/qnlaengine.h @@ -92,8 +92,6 @@ public: void requestUpdate(); - static QNlaEngine *instance(); - private: QWindowsSockInit2 winSock; QNlaThread *nlaThread; -- cgit v0.12 From 6f0a0af87c2063cd1dac75134f5cd05291a9196d Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 10 Dec 2009 17:10:53 +1000 Subject: Convert NLA plugin to be incremental. --- src/network/bearer/qnetworkconfigmanager_p.cpp | 12 ++- src/plugins/bearer/nla/qnlaengine.cpp | 101 ++++++++++++++++++++----- src/plugins/bearer/nla/qnlaengine.h | 6 +- 3 files changed, 95 insertions(+), 24 deletions(-) diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 6f833f3..495be4a 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -198,7 +198,7 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() if (nmWifi) { sessionEngines.append(nmWifi); connect(nmWifi, SIGNAL(updateCompleted()), - this, SIGNAL(configurationUpdateComplete())); + this, SLOT(updateConfigurations())); connect(nmWifi, SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer))); connect(nmWifi, SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)), @@ -217,7 +217,7 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() if (generic) { sessionEngines.append(generic); connect(generic, SIGNAL(updateCompleted()), - this, SIGNAL(configurationUpdateComplete())); + this, SLOT(updateConfigurations())); connect(generic, SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer))); connect(generic, SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)), @@ -235,6 +235,14 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() QNetworkSessionEngine *nla = nlaPlugin->create(QLatin1String("nla")); if (nla) { sessionEngines.append(nla); + connect(nla, SIGNAL(updateCompleted()), + this, SLOT(updateConfigurations())); + connect(nla, SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer))); + connect(nla, SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationRemoved(QNetworkConfigurationPrivatePointer))); + connect(nla, SIGNAL(configurationChanged(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationChanged(QNetworkConfigurationPrivatePointer))); } } } diff --git a/src/plugins/bearer/nla/qnlaengine.cpp b/src/plugins/bearer/nla/qnlaengine.cpp index 47bd8d5..a9fc2ee 100644 --- a/src/plugins/bearer/nla/qnlaengine.cpp +++ b/src/plugins/bearer/nla/qnlaengine.cpp @@ -238,21 +238,8 @@ QList QNlaThread::getConfigurations() { QMutexLocker locker(&mutex); - QList foundConfigurations; - - for (int i = 0; i < fetchedConfigurations.count(); ++i) { - QNetworkConfigurationPrivate *config = new QNetworkConfigurationPrivate; - config->name = fetchedConfigurations.at(i)->name; - config->isValid = fetchedConfigurations.at(i)->isValid; - config->id = fetchedConfigurations.at(i)->id; - config->state = fetchedConfigurations.at(i)->state; - config->type = fetchedConfigurations.at(i)->type; - config->roamingSupported = fetchedConfigurations.at(i)->roamingSupported; - config->purpose = fetchedConfigurations.at(i)->purpose; - config->internet = fetchedConfigurations.at(i)->internet; - - foundConfigurations.append(config); - } + QList foundConfigurations = fetchedConfigurations; + fetchedConfigurations.clear(); return foundConfigurations; } @@ -324,7 +311,10 @@ void QNlaThread::run() #ifndef Q_OS_WINCE // Not interested in unrelated IO completion events // although we also don't want to block them - while (WaitForSingleObjectEx(changeEvent, WSA_INFINITE, true) != WAIT_IO_COMPLETION) {} + while (WaitForSingleObjectEx(changeEvent, WSA_INFINITE, true) != WAIT_IO_COMPLETION && + handle) + { + } #else WaitForSingleObject(changeEvent, WSA_INFINITE); #endif @@ -515,7 +505,7 @@ QNlaEngine::QNlaEngine(QObject *parent) { nlaThread = new QNlaThread(this); connect(nlaThread, SIGNAL(networksChanged()), - this, SIGNAL(configurationsChanged())); + this, SLOT(networksChanged())); nlaThread->start(); qApp->processEvents(QEventLoop::ExcludeUserInputEvents); @@ -526,12 +516,57 @@ QNlaEngine::~QNlaEngine() delete nlaThread; } -QList QNlaEngine::getConfigurations(bool *ok) +void QNlaEngine::networksChanged() { - if (ok) - *ok = true; + QStringList previous = accessPointConfigurations.keys(); + + QList foundConfigurations = nlaThread->getConfigurations(); + while (!foundConfigurations.isEmpty()) { + QNetworkConfigurationPrivate *cpPriv = foundConfigurations.takeFirst(); + + previous.removeAll(cpPriv->id); + + if (accessPointConfigurations.contains(cpPriv->id)) { + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(cpPriv->id); + + bool changed = false; + + if (ptr->isValid != cpPriv->isValid) { + ptr->isValid = cpPriv->isValid; + changed = true; + } + + if (ptr->name != cpPriv->name) { + ptr->name = cpPriv->name; + changed = true; + } + + if (ptr->state != cpPriv->state) { + ptr->state = cpPriv->state; + changed = true; + } - return nlaThread->getConfigurations(); + if (changed) + emit configurationChanged(ptr); + + delete cpPriv; + } else { + QNetworkConfigurationPrivatePointer ptr(cpPriv); + + accessPointConfigurations.insert(ptr->id, ptr); + + emit configurationAdded(ptr); + } + } + + while (!previous.isEmpty()) { + QNetworkConfigurationPrivatePointer ptr = + accessPointConfigurations.take(previous.takeFirst()); + + emit configurationRemoved(ptr); + } + + emit updateCompleted(); } QString QNlaEngine::getInterfaceFromId(const QString &id) @@ -577,6 +612,30 @@ void QNlaEngine::requestUpdate() nlaThread->forceUpdate(); } +QNetworkSession::State QNlaEngine::sessionStateForId(const QString &id) +{ + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + + if (!ptr) + return QNetworkSession::Invalid; + + if (!ptr->isValid) { + return QNetworkSession::Invalid; + } else if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + return QNetworkSession::Connected; + } else if ((ptr->state & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + return QNetworkSession::Disconnected; + } else if ((ptr->state & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) { + return QNetworkSession::NotAvailable; + } else if ((ptr->state & QNetworkConfiguration::Undefined) == + QNetworkConfiguration::Undefined) { + return QNetworkSession::NotAvailable; + } + + return QNetworkSession::Invalid; +} + #include "qnlaengine.moc" QT_END_NAMESPACE diff --git a/src/plugins/bearer/nla/qnlaengine.h b/src/plugins/bearer/nla/qnlaengine.h index 464275d..dd038d1 100644 --- a/src/plugins/bearer/nla/qnlaengine.h +++ b/src/plugins/bearer/nla/qnlaengine.h @@ -81,7 +81,6 @@ public: QNlaEngine(QObject *parent = 0); ~QNlaEngine(); - QList getConfigurations(bool *ok = 0); QString getInterfaceFromId(const QString &id); bool hasIdentifier(const QString &id); @@ -92,6 +91,11 @@ public: void requestUpdate(); + QNetworkSession::State sessionStateForId(const QString &id); + +private Q_SLOTS: + void networksChanged(); + private: QWindowsSockInit2 winSock; QNlaThread *nlaThread; -- cgit v0.12 From a60b9d95fddb75a53cde258dbf4b9063a58a88b8 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Fri, 11 Dec 2009 11:27:14 +1000 Subject: Convert Native Wifi plugin to be incremental. --- src/network/bearer/qnetworkconfigmanager_p.cpp | 14 ++- .../bearer/nativewifi/qnativewifiengine.cpp | 115 ++++++++++++++++----- src/plugins/bearer/nativewifi/qnativewifiengine.h | 7 +- 3 files changed, 106 insertions(+), 30 deletions(-) diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 495be4a..c9b10dd 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -251,9 +251,21 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() QBearerEnginePlugin *nativeWifiPlugin = qobject_cast(l->instance(QLatin1String("nativewifi"))); if (nativeWifiPlugin) { - QNetworkSessionEngine *nativeWifi = nativeWifiPlugin->create(QLatin1String("nativewifi")); + QNetworkSessionEngine *nativeWifi = + nativeWifiPlugin->create(QLatin1String("nativewifi")); if (nativeWifi) { sessionEngines.append(nativeWifi); + connect(nativeWifi, SIGNAL(updateCompleted()), + this, SLOT(updateConfigurations())); + connect(nativeWifi, + SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer))); + connect(nativeWifi, + SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationRemoved(QNetworkConfigurationPrivatePointer))); + connect(nativeWifi, + SIGNAL(configurationChanged(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationChanged(QNetworkConfigurationPrivatePointer))); capFlags |= QNetworkConfigurationManager::CanStartAndStopInterfaces; } diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp index 93fc9ca..e65eeea 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp @@ -68,7 +68,7 @@ void qNotificationCallback(WLAN_NOTIFICATION_DATA *data, QNativeWifiEngine *d) switch (data->NotificationCode) { case wlan_notification_acm_connection_complete: case wlan_notification_acm_disconnected: - d->emitConfigurationsChanged(); + QMetaObject::invokeMethod(d, "scanComplete", Qt::QueuedConnection); break; default: qDebug() << "wlan unknown notification"; @@ -96,8 +96,9 @@ QNativeWifiEngine::QNativeWifiEngine(QObject *parent) // On Windows XP SP2 and SP3 only connection and disconnection notifications are available. // We need to poll for changes in available wireless networks. - connect(&pollTimer, SIGNAL(timeout()), this, SIGNAL(configurationsChanged())); + connect(&pollTimer, SIGNAL(timeout()), this, SLOT(scanComplete())); pollTimer.setInterval(10000); + scanComplete(); } QNativeWifiEngine::~QNativeWifiEngine() @@ -105,19 +106,16 @@ QNativeWifiEngine::~QNativeWifiEngine() local_WlanCloseHandle(handle, 0); } -QList QNativeWifiEngine::getConfigurations(bool *ok) +void QNativeWifiEngine::scanComplete() { - if (ok) - *ok = false; - - QList foundConfigurations; + QStringList previous = accessPointConfigurations.keys(); // enumerate interfaces WLAN_INTERFACE_INFO_LIST *interfaceList; DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); if (result != ERROR_SUCCESS) { qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); - return foundConfigurations; + return; } for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { @@ -146,36 +144,66 @@ QList QNativeWifiEngine::getConfigurations(bool network.dot11Ssid.uSSIDLength); } - // don't add duplicate networks - if (seenNetworks.contains(networkName)) - continue; - else - seenNetworks.append(networkName); - - QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; + const QString id = QString::number(qHash(QLatin1String("WLAN:") + networkName)); - cpPriv->isValid = true; + previous.removeAll(id); - cpPriv->name = networkName; - cpPriv->id = QString::number(qHash(QLatin1String("WLAN:") + cpPriv->name)); + QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined; if (!(network.dwFlags & WLAN_AVAILABLE_NETWORK_HAS_PROFILE)) - cpPriv->state = QNetworkConfiguration::Undefined; + state = QNetworkConfiguration::Undefined; if (network.strProfileName[0] != 0) { if (network.bNetworkConnectable) { if (network.dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED) - cpPriv->state = QNetworkConfiguration::Active; + state = QNetworkConfiguration::Active; else - cpPriv->state = QNetworkConfiguration::Discovered; + state = QNetworkConfiguration::Discovered; } else { - cpPriv->state = QNetworkConfiguration::Defined; + state = QNetworkConfiguration::Defined; } } - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + if (seenNetworks.contains(networkName)) + continue; + else + seenNetworks.append(networkName); + + if (accessPointConfigurations.contains(id)) { + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); - foundConfigurations.append(cpPriv); + bool changed = false; + + if (!ptr->isValid) { + ptr->isValid = true; + changed = true; + } + + if (ptr->name != networkName) { + ptr->name = networkName; + changed = true; + } + + if (ptr->state != state) { + ptr->state = state; + changed = true; + } + + if (changed) + emit configurationChanged(ptr); + } else { + QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate); + + ptr->name = networkName; + ptr->isValid = true; + ptr->id = id; + ptr->state = state; + ptr->type = QNetworkConfiguration::InternetAccessPoint; + + accessPointConfigurations.insert(id, ptr); + + emit configurationAdded(ptr); + } } local_WlanFreeMemory(networkList); @@ -183,12 +211,16 @@ QList QNativeWifiEngine::getConfigurations(bool local_WlanFreeMemory(interfaceList); - if (ok) - *ok = true; + while (!previous.isEmpty()) { + QNetworkConfigurationPrivatePointer ptr = + accessPointConfigurations.take(previous.takeFirst()); + + emit configurationRemoved(ptr); + } pollTimer.start(); - return foundConfigurations; + emit updateCompleted(); } QString QNativeWifiEngine::getInterfaceFromId(const QString &id) @@ -227,6 +259,7 @@ QString QNativeWifiEngine::getInterfaceFromId(const QString &id) guid = guid.arg(interface.InterfaceGuid.Data4[i], 2, 16, QChar('0')); local_WlanFreeMemory(connectionAttributes); + local_WlanFreeMemory(interfaceList); return guid.toUpper(); } @@ -234,6 +267,8 @@ QString QNativeWifiEngine::getInterfaceFromId(const QString &id) local_WlanFreeMemory(connectionAttributes); } + local_WlanFreeMemory(interfaceList); + return QString(); } @@ -397,6 +432,32 @@ void QNativeWifiEngine::requestUpdate() if (result != ERROR_SUCCESS) qWarning("%s: WlanScan failed with error %ld\n", __FUNCTION__, result); } + + local_WlanFreeMemory(interfaceList); +} + +QNetworkSession::State QNativeWifiEngine::sessionStateForId(const QString &id) +{ + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + + if (!ptr) + return QNetworkSession::Invalid; + + if (!ptr->isValid) { + return QNetworkSession::Invalid; + } else if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + return QNetworkSession::Connected; + } else if ((ptr->state & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + return QNetworkSession::Disconnected; + } else if ((ptr->state & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) { + return QNetworkSession::NotAvailable; + } else if ((ptr->state & QNetworkConfiguration::Undefined) == + QNetworkConfiguration::Undefined) { + return QNetworkSession::NotAvailable; + } + + return QNetworkSession::Invalid; } QT_END_NAMESPACE diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.h b/src/plugins/bearer/nativewifi/qnativewifiengine.h index 6686ea8..5d6af40 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.h +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.h @@ -60,6 +60,7 @@ QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; +struct WLAN_NOTIFICATION_DATA; class QNativeWifiEngine : public QNetworkSessionEngine { @@ -69,7 +70,6 @@ public: QNativeWifiEngine(QObject *parent = 0); ~QNativeWifiEngine(); - QList getConfigurations(bool *ok = 0); QString getInterfaceFromId(const QString &id); bool hasIdentifier(const QString &id); @@ -80,10 +80,13 @@ public: void requestUpdate(); - inline void emitConfigurationsChanged() { emit configurationsChanged(); } + QNetworkSession::State sessionStateForId(const QString &id); inline bool available() const { return handle != 0; } +public Q_SLOTS: + void scanComplete(); + private: QTimer pollTimer; -- cgit v0.12 From 33ff53925ba6d62ecc868920c6bc914824feec54 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Fri, 11 Dec 2009 12:45:40 +1000 Subject: Remove unused BEARER_ENGINE preprocessor define. --- src/network/bearer/bearer.pri | 2 -- src/network/bearer/qnetworkconfigmanager_p.h | 6 ------ src/network/bearer/qnetworkconfiguration_p.h | 9 ++------- src/network/bearer/qnetworksession_p.h | 11 ++--------- src/plugins/bearer/corewlan/corewlan.pro | 2 -- src/plugins/bearer/generic/generic.pro | 2 -- src/plugins/bearer/nativewifi/nativewifi.pro | 2 -- src/plugins/bearer/networkmanager/networkmanager.pro | 2 +- src/plugins/bearer/nla/nla.pro | 2 -- 9 files changed, 5 insertions(+), 33 deletions(-) diff --git a/src/network/bearer/bearer.pri b/src/network/bearer/bearer.pri index 5bae333..4f6c549 100644 --- a/src/network/bearer/bearer.pri +++ b/src/network/bearer/bearer.pri @@ -69,8 +69,6 @@ symbian { INSTALLS += pkgconfig documentation } else { - DEFINES += BEARER_ENGINE - HEADERS += bearer/qnetworkconfigmanager_p.h \ bearer/qnetworkconfiguration_p.h \ bearer/qnetworksession_p.h \ diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index 37e88d3..a45d534 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -93,13 +93,10 @@ Q_SIGNALS: void onlineStateChanged(bool isOnline); private: -#ifdef BEARER_ENGINE void updateInternetServiceConfiguration(); void abort(); -#endif -#ifdef BEARER_ENGINE public: QList sessionEngines; @@ -108,14 +105,11 @@ private: bool updating; QSet updatingEngines; -#endif private Q_SLOTS: -#ifdef BEARER_ENGINE void configurationAdded(QNetworkConfigurationPrivatePointer ptr); void configurationRemoved(QNetworkConfigurationPrivatePointer ptr); void configurationChanged(QNetworkConfigurationPrivatePointer ptr); -#endif }; QNetworkConfigurationManagerPrivate *qNetworkConfigurationManagerPrivate(); diff --git a/src/network/bearer/qnetworkconfiguration_p.h b/src/network/bearer/qnetworkconfiguration_p.h index 8e69248..365ec95 100644 --- a/src/network/bearer/qnetworkconfiguration_p.h +++ b/src/network/bearer/qnetworkconfiguration_p.h @@ -64,12 +64,9 @@ class QNetworkConfigurationPrivate : public QSharedData { public: QNetworkConfigurationPrivate () - : isValid(false), type(QNetworkConfiguration::Invalid), - roamingSupported(false), purpose(QNetworkConfiguration::UnknownPurpose) + : isValid(false), type(QNetworkConfiguration::Invalid), + roamingSupported(false), purpose(QNetworkConfiguration::UnknownPurpose), internet(false) { -#ifdef BEARER_ENGINE - internet = false; -#endif } ~QNetworkConfigurationPrivate() @@ -86,9 +83,7 @@ public: bool roamingSupported; QNetworkConfiguration::Purpose purpose; -#ifdef BEARER_ENGINE bool internet; -#endif QList serviceNetworkMembers; QNetworkInterface serviceInterface; diff --git a/src/network/bearer/qnetworksession_p.h b/src/network/bearer/qnetworksession_p.h index 0e11b3d..0a45c92 100644 --- a/src/network/bearer/qnetworksession_p.h +++ b/src/network/bearer/qnetworksession_p.h @@ -55,9 +55,7 @@ #include "qnetworkconfigmanager_p.h" #include "qnetworksession.h" -#ifdef BEARER_ENGINE #include "qnetworksessionengine_p.h" -#endif #include "qnetworksession.h" #include @@ -65,9 +63,7 @@ QT_BEGIN_NAMESPACE -#ifdef BEARER_ENGINE class QNetworkSessionEngine; -#endif class QNetworkSessionPrivate : public QObject { @@ -117,12 +113,10 @@ Q_SIGNALS: void quitPendingWaitsForOpened(); private Q_SLOTS: -#ifdef BEARER_ENGINE void networkConfigurationsChanged(); void configurationChanged(const QNetworkConfiguration &config); void forcedSessionClose(const QNetworkConfiguration &config); void connectionError(const QString &id, QNetworkSessionEngine::ConnectionError error); -#endif private: QNetworkConfigurationManager manager; @@ -146,17 +140,16 @@ private: QNetworkSession::State state; bool isActive; -#ifdef BEARER_ENGINE bool opened; QNetworkSessionEngine *engine; -#endif + QNetworkSession::SessionError lastError; QNetworkSession* q; friend class QNetworkSession; -#if defined(BEARER_ENGINE) && defined(BACKEND_NM) +#if defined(BACKEND_NM) QDateTime startTime; void setActiveTimeStamp(); #endif diff --git a/src/plugins/bearer/corewlan/corewlan.pro b/src/plugins/bearer/corewlan/corewlan.pro index ffac6df..ac04e95 100644 --- a/src/plugins/bearer/corewlan/corewlan.pro +++ b/src/plugins/bearer/corewlan/corewlan.pro @@ -11,8 +11,6 @@ contains(QT_CONFIG, corewlan) { } } -DEFINES += BEARER_ENGINE - HEADERS += qcorewlanengine.h SOURCES += qcorewlanengine.mm main.cpp diff --git a/src/plugins/bearer/generic/generic.pro b/src/plugins/bearer/generic/generic.pro index 506417c..0015041 100644 --- a/src/plugins/bearer/generic/generic.pro +++ b/src/plugins/bearer/generic/generic.pro @@ -3,8 +3,6 @@ include(../../qpluginbase.pri) QT += network -DEFINES += BEARER_ENGINE - HEADERS += qgenericengine.h \ ../platformdefs_win.h SOURCES += qgenericengine.cpp main.cpp diff --git a/src/plugins/bearer/nativewifi/nativewifi.pro b/src/plugins/bearer/nativewifi/nativewifi.pro index 3aab552..583edd4 100644 --- a/src/plugins/bearer/nativewifi/nativewifi.pro +++ b/src/plugins/bearer/nativewifi/nativewifi.pro @@ -3,8 +3,6 @@ include(../../qpluginbase.pri) QT += network -DEFINES += BEARER_ENGINE - HEADERS += qnativewifiengine.h platformdefs.h SOURCES += qnativewifiengine.cpp main.cpp diff --git a/src/plugins/bearer/networkmanager/networkmanager.pro b/src/plugins/bearer/networkmanager/networkmanager.pro index 79c68ea..57f7ca7 100644 --- a/src/plugins/bearer/networkmanager/networkmanager.pro +++ b/src/plugins/bearer/networkmanager/networkmanager.pro @@ -3,7 +3,7 @@ include(../../qpluginbase.pri) QT += network dbus -DEFINES += BEARER_ENGINE BACKEND_NM +DEFINES += BACKEND_NM HEADERS += qnmdbushelper.h \ qnetworkmanagerservice.h \ diff --git a/src/plugins/bearer/nla/nla.pro b/src/plugins/bearer/nla/nla.pro index 78f3271..62a920a 100644 --- a/src/plugins/bearer/nla/nla.pro +++ b/src/plugins/bearer/nla/nla.pro @@ -9,8 +9,6 @@ QT += network LIBS += -lWs2 } -DEFINES += BEARER_ENGINE - HEADERS += qnlaengine.h \ ../platformdefs_win.h SOURCES += qnlaengine.cpp main.cpp -- cgit v0.12 From 56c7d0baf1b7611f17938cf0eb920ccdae53e7ed Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 4 Jan 2010 11:19:18 +1000 Subject: Remove bearer.pro. --- src/network/bearer/bearer.pro | 163 ------------------------------------------ 1 file changed, 163 deletions(-) delete mode 100644 src/network/bearer/bearer.pro diff --git a/src/network/bearer/bearer.pro b/src/network/bearer/bearer.pro deleted file mode 100644 index 2255b7c..0000000 --- a/src/network/bearer/bearer.pro +++ /dev/null @@ -1,163 +0,0 @@ -# Qt bearer management library -TEMPLATE = lib -TARGET = QtBearer - -QT += network -include (../../common.pri) - -DEFINES += QT_BUILD_BEARER_LIB QT_MAKEDLL - -#DEFINES += BEARER_MANAGEMENT_DEBUG - -PUBLIC_HEADERS += qnetworkconfiguration.h \ - qnetworksession.h \ - qnetworkconfigmanager.h - -HEADERS += $$PUBLIC_HEADERS -SOURCES += qnetworksession.cpp \ - qnetworkconfigmanager.cpp \ - qnetworkconfiguration.cpp - -symbian: { - exists($${EPOCROOT}epoc32/release/winscw/udeb/cmmanager.lib)| \ - exists($${EPOCROOT}epoc32/release/armv5/lib/cmmanager.lib) { - message("Building with SNAP support") - DEFINES += SNAP_FUNCTIONALITY_AVAILABLE=1 - LIBS += -lcmmanager - } else { - message("Building without SNAP support") - LIBS += -lapengine - } - - INCLUDEPATH += $$APP_LAYER_SYSTEMINCLUDE - - HEADERS += qnetworkconfigmanager_s60_p.h \ - qnetworkconfiguration_s60_p.h \ - qnetworksession_s60_p.h - SOURCES += qnetworkconfigmanager_s60_p.cpp \ - qnetworkconfiguration_s60_p.cpp \ - qnetworksession_s60_p.cpp - - LIBS += -lcommdb \ - -lapsettingshandlerui \ - -lconnmon \ - -lcentralrepository \ - -lesock \ - -linsock \ - -lecom \ - -lefsrv \ - -lnetmeta - - deploy.path = $${EPOCROOT} - exportheaders.sources = $$PUBLIC_HEADERS - exportheaders.path = epoc32/include - - for(header, exportheaders.sources) { - BLD_INF_RULES.prj_exports += "$$header $$deploy.path$$exportheaders.path/$$basename(header)" - } - - bearer_deployment.sources = QtBearer.dll - bearer_deployment.path = /sys/bin - DEPLOYMENT += bearer_deployment - - TARGET.CAPABILITY = All -TCB -} else { - maemo { - QT += dbus - CONFIG += link_pkgconfig - - exists(../debug) { - message("Enabling debug messages.") - DEFINES += BEARER_MANAGEMENT_DEBUG - } - - HEADERS += qnetworksession_maemo_p.h \ - qnetworkconfigmanager_maemo_p.h \ - qnetworkconfiguration_maemo_p.h - - SOURCES += qnetworkconfigmanager_maemo.cpp \ - 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 { - - DEFINES += BEARER_ENGINE - - HEADERS += qnetworkconfigmanager_p.h \ - qnetworkconfiguration_p.h \ - qnetworksession_p.h \ - qnetworksessionengine_p.h \ - qgenericengine_p.h - - SOURCES += qnetworkconfigmanager_p.cpp \ - qnetworksession_p.cpp \ - qnetworksessionengine.cpp \ - qgenericengine.cpp - - unix:!mac:contains(networkmanager_enabled, yes) { - contains(QT_CONFIG,dbus) { - DEFINES += BACKEND_NM - QT += dbus - - HEADERS += qnmdbushelper_p.h \ - qnetworkmanagerservice_p.h \ - qnmwifiengine_unix_p.h - - SOURCES += qnmdbushelper.cpp \ - qnetworkmanagerservice_p.cpp \ - qnmwifiengine_unix.cpp - } else { - message("NetworkManager backend requires Qt DBus support") - } - } - - win32: { - HEADERS += qnlaengine_win_p.h \ - qnetworksessionengine_win_p.h - - !wince*:HEADERS += qnativewifiengine_win_p.h - - SOURCES += qnlaengine_win.cpp - - !wince*:SOURCES += qnativewifiengine_win.cpp - - !wince*:LIBS += -lWs2_32 - wince*:LIBS += -lWs2 - } - } - macx: { - HEADERS += qcorewlanengine_mac_p.h - SOURCES+= qcorewlanengine_mac.mm - LIBS += -framework Foundation -framework SystemConfiguration - - contains(corewlan_enabled, yes) { - isEmpty(QMAKE_MAC_SDK) { - SDK6="yes" - } else { - contains(QMAKE_MAC_SDK, "/Developer/SDKs/MacOSX10.6.sdk") { - SDK6="yes" - } - } - - !isEmpty(SDK6) { - LIBS += -framework CoreWLAN - DEFINES += MAC_SDK_10_6 - } - } - - - } -} - -include(../../features/deploy.pri) -- cgit v0.12 From 2fa4daa2acd0af503f5802eff773f1fa2117a788 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 22 Dec 2009 09:20:17 +1000 Subject: Fix memory leak in NLA engine. --- src/plugins/bearer/nla/qnlaengine.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/plugins/bearer/nla/qnlaengine.cpp b/src/plugins/bearer/nla/qnlaengine.cpp index a9fc2ee..bf0d74f 100644 --- a/src/plugins/bearer/nla/qnlaengine.cpp +++ b/src/plugins/bearer/nla/qnlaengine.cpp @@ -576,15 +576,7 @@ QString QNlaEngine::getInterfaceFromId(const QString &id) bool QNlaEngine::hasIdentifier(const QString &id) { - if (configurationInterface.contains(id.toUInt())) - return true; - - foreach (QNetworkConfigurationPrivate *cpPriv, nlaThread->getConfigurations()) { - if (cpPriv->id == id) - return true; - } - - return false; + return configurationInterface.contains(id.toUInt()); } QString QNlaEngine::bearerName(const QString &id) -- cgit v0.12 From c68598b2bd82abee5da2596949e1e95c9a59e584 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 4 Jan 2010 12:13:14 +1000 Subject: Emit updateCompleted() when requestUpdate() is called. --- src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp | 8 ++++++++ src/plugins/bearer/networkmanager/qnetworkmanagerengine.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp index 3de20a3..0af3675 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp @@ -116,6 +116,7 @@ QNetworkManagerEngine::~QNetworkManagerEngine() void QNetworkManagerEngine::doRequestUpdate() { + emit updateCompleted(); } QString QNetworkManagerEngine::getInterfaceFromId(const QString &id) @@ -319,6 +320,13 @@ void QNetworkManagerEngine::activeConnectionPropertiesChanged(const QString &pat } } +void QNetworkManagerEngine::devicePropertiesChanged(const QString &path, + const QMap &properties) +{ + qDebug() << Q_FUNC_INFO << path; + qDebug() << properties; +} + void QNetworkManagerEngine::deviceAdded(const QDBusObjectPath &path) { QNetworkManagerInterfaceDevice device(path.path()); diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h index 9e8af3b..1636c91 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h @@ -87,6 +87,8 @@ private Q_SLOTS: const QMap &properties); void activeConnectionPropertiesChanged(const QString &path, const QMap &properties); + void devicePropertiesChanged(const QString &path, + const QMap &properties); void deviceAdded(const QDBusObjectPath &path); void deviceRemoved(const QDBusObjectPath &path); -- cgit v0.12 From c3049983cf0ac72ae4a524a0a365ea88e950bfc0 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 4 Jan 2010 17:11:20 +1000 Subject: Convert Core Wlan plugin to be incremental. --- src/network/bearer/qnetworkconfigmanager_p.cpp | 8 + src/plugins/bearer/corewlan/qcorewlanengine.h | 14 +- src/plugins/bearer/corewlan/qcorewlanengine.mm | 239 +++++++++++++++++++++---- 3 files changed, 220 insertions(+), 41 deletions(-) diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index c9b10dd..cb83789 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -186,6 +186,14 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() QNetworkSessionEngine *coreWifi = coreWlanPlugin->create(QLatin1String("corewlan")); if (coreWifi) { sessionEngines.append(coreWifi); + connect(coreWifi, SIGNAL(updateCompleted()), + this, SLOT(updateConfigurations())); + connect(coreWifi, SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer))); + connect(coreWifi, SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationRemoved(QNetworkConfigurationPrivatePointer))); + connect(coreWifi, SIGNAL(configurationChanged(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationChanged(QNetworkConfigurationPrivatePointer))); } } } diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.h b/src/plugins/bearer/corewlan/qcorewlanengine.h index 2be81d1..ea9bcfd 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.h +++ b/src/plugins/bearer/corewlan/qcorewlanengine.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef QCOREWLANENGINE_P_H -#define QCOREWLANENGINE_P_H +#ifndef QCOREWLANENGINE_H +#define QCOREWLANENGINE_H #include @@ -59,7 +59,6 @@ public: QCoreWlanEngine(QObject *parent = 0); ~QCoreWlanEngine(); - QList getConfigurations(bool *ok = 0); QString getInterfaceFromId(const QString &id); bool hasIdentifier(const QString &id); @@ -70,13 +69,18 @@ public: void requestUpdate(); + QNetworkSession::State sessionStateForId(const QString &id); + static bool getAllScInterfaces(); +private Q_SLOTS: + void doRequestUpdate(); + private: bool isWifiReady(const QString &dev); - QMap configurationInterface; + QMap configurationInterface; QTimer pollTimer; - QList scanForSsids(const QString &interfaceName); + QStringList scanForSsids(const QString &interfaceName); QList getWlanProfiles(const QString &interfaceName); diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm index c6ea56a..7e14e69 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.mm +++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm @@ -107,9 +107,9 @@ static QString qGetInterfaceType(const QString &interfaceString) QCoreWlanEngine::QCoreWlanEngine(QObject *parent) : QNetworkSessionEngine(parent) { - getAllScInterfaces(); - connect(&pollTimer, SIGNAL(timeout()), this, SIGNAL(configurationsChanged())); + connect(&pollTimer, SIGNAL(timeout()), this, SLOT(doRequestUpdate())); pollTimer.setInterval(10000); + doRequestUpdate(); } QCoreWlanEngine::~QCoreWlanEngine() @@ -137,6 +137,7 @@ QList QCoreWlanEngine::getWifiConfigurations() return QList (); } +#if 0 QList QCoreWlanEngine::getConfigurations(bool *ok) { if (ok) @@ -202,15 +203,16 @@ QList QCoreWlanEngine::getConfigurations(bool *o pollTimer.start(); return foundConfigurations; } +#endif QString QCoreWlanEngine::getInterfaceFromId(const QString &id) { - return configurationInterface.value(id.toUInt()); + return configurationInterface.value(id); } bool QCoreWlanEngine::hasIdentifier(const QString &id) { - return configurationInterface.contains(id.toUInt()); + return configurationInterface.contains(id); } QString QCoreWlanEngine::bearerName(const QString &id) @@ -304,13 +306,119 @@ void QCoreWlanEngine::disconnectFromId(const QString &id) void QCoreWlanEngine::requestUpdate() { + pollTimer.stop(); + QTimer::singleShot(0, this, SLOT(doRequestUpdate())); +} + +void QCoreWlanEngine::doRequestUpdate() +{ getAllScInterfaces(); - emit configurationsChanged(); + + QStringList previous = accessPointConfigurations.keys(); + + QMapIterator i(networkInterfaces); + while (i.hasNext()) { + i.next(); + if (i.value() == QLatin1String("WLAN")) { + QStringList added = scanForSsids(i.key()); + while (!added.isEmpty()) { + previous.removeAll(added.takeFirst()); + } + } + + qDebug() << "Found configuration" << i.key(); + QNetworkInterface interface = QNetworkInterface::interfaceFromName(i.key()); + + if (!interface.isValid()) + continue; + + uint identifier; + if (interface.index()) + identifier = qHash(QLatin1String("corewlan:") + QString::number(interface.index())); + else + identifier = qHash(QLatin1String("corewlan:") + interface.hardwareAddress()); + + const QString id = QString::number(identifier); + + previous.removeAll(id); + + QString name = interface.humanReadableName(); + if (name.isEmpty()) + name = interface.name(); + + QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined; + + qDebug() << "interface flags:" << interface.flags(); + + if (interface.flags() && QNetworkInterface::IsRunning) + state = QNetworkConfiguration::Defined; + + if (!interface.addressEntries().isEmpty()) + state = QNetworkConfiguration::Active; + + if (accessPointConfigurations.contains(id)) { + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + + bool changed = false; + + if (!ptr->isValid) { + ptr->isValid = true; + changed = true; + } + + if (ptr->name != name) { + ptr->name = name; + changed = true; + } + + if (ptr->id != id) { + ptr->id = id; + changed = true; + } + + if (ptr->state != state) { + ptr->state = state; + changed = true; + } + + if (changed) { + qDebug() << "Configuration changed" << ptr->name << ptr->id; + emit configurationChanged(ptr); + } + } else { + QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate); + + ptr->name = name; + ptr->isValid = true; + ptr->id = id; + ptr->state = state; + ptr->type = QNetworkConfiguration::InternetAccessPoint; + + accessPointConfigurations.insert(id, ptr); + configurationInterface.insert(id, interface.name()); + + qDebug() << "Configuration Added" << ptr->name << ptr->id; + emit configurationAdded(ptr); + } + } + + while (!previous.isEmpty()) { + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(previous.takeFirst()); + + qDebug() << "Configuration Removed" << ptr->name << ptr->id; + configurationInterface.remove(ptr->id); + emit configurationRemoved(ptr); + } + + pollTimer.start(); + + emit updateCompleted(); } -QList QCoreWlanEngine::scanForSsids(const QString &interfaceName) +QStringList QCoreWlanEngine::scanForSsids(const QString &interfaceName) { - QList foundConfigs; + QStringList found; + #if defined(MAC_SDK_10_6) NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; @@ -319,45 +427,80 @@ QList QCoreWlanEngine::scanForSsids(const QStrin NSDictionary *parametersDict = nil; NSArray* apArray = [NSMutableArray arrayWithArray:[currentInterface scanForNetworksWithParameters:parametersDict error:&err]]; - if(!err) { + if (!err) { for(uint row=0; row < [apArray count]; row++ ) { CWNetwork *apNetwork = [apArray objectAtIndex:row]; - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - QString networkSsid = nsstringToQString([apNetwork ssid]); - cpPriv->name = networkSsid; - cpPriv->isValid = true; - cpPriv->id = networkSsid; - cpPriv->internet = true; - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - cpPriv->serviceInterface = QNetworkInterface::interfaceFromName(nsstringToQString([[CWInterface interface] name])); + + const QString networkSsid = nsstringToQString([apNetwork ssid]); + + const QString id = QString::number(qHash(QLatin1String("corewlan:") + networkSsid)); + found.append(id); + + QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined; + + if ([currentInterface.interfaceState intValue] == kCWInterfaceStateRunning) { + QString interfaceSsidString = nsstringToQString([currentInterface ssid]); + qDebug() << "interfaceSsidString:" << interfaceSsidString; + if (networkSsid == nsstringToQString([currentInterface ssid])) + state = QNetworkConfiguration::Active; + } else { + if (isKnownSsid(interfaceName, networkSsid)) + state = QNetworkConfiguration::Discovered; + else + state = QNetworkConfiguration::Defined; + } + qDebug() << "state is:" << state; CWWirelessProfile *networkProfile = apNetwork.wirelessProfile; CW8021XProfile *userNetworkProfile = networkProfile.user8021XProfile; - if(!userNetworkProfile) { - } else { + if (userNetworkProfile) { qWarning() <<"Has profile!" ; } - if( [currentInterface.interfaceState intValue] == kCWInterfaceStateRunning) { - QString interfaceSsidString = nsstringToQString( [currentInterface ssid]); - if( cpPriv->name == interfaceSsidString) { - cpPriv->state |= QNetworkConfiguration::Active; + if (accessPointConfigurations.contains(id)) { + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + + bool changed = false; + + if (!ptr->isValid) { + ptr->isValid = true; + changed = true; } - } else { - if(isKnownSsid(cpPriv->serviceInterface.name(), networkSsid)) { - cpPriv->state = QNetworkConfiguration::Discovered; - } else { - cpPriv->state = QNetworkConfiguration::Defined; + + if (ptr->name != networkSsid) { + ptr->name = networkSsid; + changed = true; } + + if (ptr->id != id) { + ptr->id = id; + changed = true; + } + + if (ptr->state != state) { + ptr->state = state; + changed = true; + } + + if (changed) { + qDebug() << "WLAN Configuration Changed" << interfaceName << ptr->name << ptr->id; + emit configurationChanged(ptr); + } + } else { + QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate); + + ptr->name = networkSsid; + ptr->isValid = true; + ptr->id = id; + ptr->state = state; + ptr->type = QNetworkConfiguration::InternetAccessPoint; + + accessPointConfigurations.insert(id, ptr); + configurationInterface.insert(id, interfaceName); + + qDebug() << "WLAN Configuration Added" << interfaceName << ptr->name << ptr->id; + emit configurationAdded(ptr); } - if(!cpPriv->state) { - cpPriv->state = QNetworkConfiguration::Undefined; - } - if([[apNetwork securityMode ] intValue]== kCWSecurityModeOpen) - cpPriv->purpose = QNetworkConfiguration::PublicPurpose; - else - cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; - foundConfigs.append(cpPriv); } } else { qWarning() << "ERROR scanning for ssids" << nsstringToQString([err localizedDescription]) @@ -367,7 +510,7 @@ QList QCoreWlanEngine::scanForSsids(const QStrin #else Q_UNUSED(interfaceName); #endif - return foundConfigs; + return found; } bool QCoreWlanEngine::isWifiReady(const QString &wifiDeviceName) @@ -449,4 +592,28 @@ bool QCoreWlanEngine::getAllScInterfaces() return true; } +QNetworkSession::State QCoreWlanEngine::sessionStateForId(const QString &id) +{ + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + + if (!ptr) + return QNetworkSession::Invalid; + + if (!ptr->isValid) { + return QNetworkSession::Invalid; + } else if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + return QNetworkSession::Connected; + } else if ((ptr->state & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + return QNetworkSession::Disconnected; + } else if ((ptr->state & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) { + return QNetworkSession::NotAvailable; + } else if ((ptr->state & QNetworkConfiguration::Undefined) == + QNetworkConfiguration::Undefined) { + return QNetworkSession::NotAvailable; + } + + return QNetworkSession::Invalid; +} + QT_END_NAMESPACE -- cgit v0.12 From ca7fe1713ff82dcde8fb2fdfb0664b5dfa830bd7 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 4 Jan 2010 17:26:36 +1000 Subject: Remove some unused functions and debug output. --- src/plugins/bearer/corewlan/qcorewlanengine.h | 1 - src/plugins/bearer/corewlan/qcorewlanengine.mm | 106 +------------------------ 2 files changed, 2 insertions(+), 105 deletions(-) diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.h b/src/plugins/bearer/corewlan/qcorewlanengine.h index ea9bcfd..237680a 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.h +++ b/src/plugins/bearer/corewlan/qcorewlanengine.h @@ -84,7 +84,6 @@ private: QList getWlanProfiles(const QString &interfaceName); - QList getWifiConfigurations(); bool isKnownSsid(const QString &interfaceName, const QString &ssid); }; diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm index 7e14e69..6625443 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.mm +++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm @@ -116,95 +116,6 @@ QCoreWlanEngine::~QCoreWlanEngine() { } -QList QCoreWlanEngine::getWifiConfigurations() -{ - QMapIterator i(networkInterfaces); - while (i.hasNext()) { - i.next(); - QString interfaceName = i.key(); - if (i.value() == "WLAN") { - if(!isWifiReady(interfaceName)) { - qWarning() << "wifi not powered on"; - return QList(); - } else { - // QList profs = getWlanProfiles(interfaceName); - scanForSsids(interfaceName); - } - } else { - - } - } - return QList (); -} - -#if 0 -QList QCoreWlanEngine::getConfigurations(bool *ok) -{ - if (ok) - *ok = true; - NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; - - QList foundConfigurations; - QList wificonfigs = getWifiConfigurations(); - - uint identifier; - QMapIterator i(networkInterfaces); - while (i.hasNext()) { - i.next(); - if (i.value() == "WLAN") { - QList fetchedConfigurations = scanForSsids(i.key()); - for (int i = 0; i < fetchedConfigurations.count(); ++i) { - - QNetworkConfigurationPrivate *config = new QNetworkConfigurationPrivate; - config->name = fetchedConfigurations.at(i)->name; - config->isValid = fetchedConfigurations.at(i)->isValid; - config->id = fetchedConfigurations.at(i)->id; - - config->state = fetchedConfigurations.at(i)->state; - config->type = fetchedConfigurations.at(i)->type; - config->roamingSupported = fetchedConfigurations.at(i)->roamingSupported; - config->purpose = fetchedConfigurations.at(i)->purpose; - config->internet = fetchedConfigurations.at(i)->internet; - config->serviceInterface = fetchedConfigurations.at(i)->serviceInterface; - - identifier = config->name.toUInt(); - configurationInterface[identifier] = config->serviceInterface.name(); - foundConfigurations.append(config); - } - } - - QNetworkInterface interface = QNetworkInterface::interfaceFromName(i.key()); - QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; - const QString humanReadableName = interface.humanReadableName(); - cpPriv->name = humanReadableName.isEmpty() ? interface.name() : humanReadableName; - cpPriv->isValid = true; - - if (interface.index()) - identifier = interface.index(); - else - identifier = qHash(interface.hardwareAddress()); - - cpPriv->id = QString::number(identifier); - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - cpPriv->state = QNetworkConfiguration::Undefined; - - if (interface.flags() & QNetworkInterface::IsRunning) { - cpPriv->state = QNetworkConfiguration::Defined; - cpPriv->internet = true; - } - if ( !interface.addressEntries().isEmpty()) { - cpPriv->state |= QNetworkConfiguration::Active; - cpPriv->internet = true; - } - configurationInterface[identifier] = interface.name(); - foundConfigurations.append(cpPriv); - } - [autoreleasepool release]; - pollTimer.start(); - return foundConfigurations; -} -#endif - QString QCoreWlanEngine::getInterfaceFromId(const QString &id) { return configurationInterface.value(id); @@ -326,7 +237,6 @@ void QCoreWlanEngine::doRequestUpdate() } } - qDebug() << "Found configuration" << i.key(); QNetworkInterface interface = QNetworkInterface::interfaceFromName(i.key()); if (!interface.isValid()) @@ -348,8 +258,6 @@ void QCoreWlanEngine::doRequestUpdate() QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined; - qDebug() << "interface flags:" << interface.flags(); - if (interface.flags() && QNetworkInterface::IsRunning) state = QNetworkConfiguration::Defined; @@ -381,10 +289,8 @@ void QCoreWlanEngine::doRequestUpdate() changed = true; } - if (changed) { - qDebug() << "Configuration changed" << ptr->name << ptr->id; + if (changed) emit configurationChanged(ptr); - } } else { QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate); @@ -397,7 +303,6 @@ void QCoreWlanEngine::doRequestUpdate() accessPointConfigurations.insert(id, ptr); configurationInterface.insert(id, interface.name()); - qDebug() << "Configuration Added" << ptr->name << ptr->id; emit configurationAdded(ptr); } } @@ -405,7 +310,6 @@ void QCoreWlanEngine::doRequestUpdate() while (!previous.isEmpty()) { QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(previous.takeFirst()); - qDebug() << "Configuration Removed" << ptr->name << ptr->id; configurationInterface.remove(ptr->id); emit configurationRemoved(ptr); } @@ -439,8 +343,6 @@ QStringList QCoreWlanEngine::scanForSsids(const QString &interfaceName) QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined; if ([currentInterface.interfaceState intValue] == kCWInterfaceStateRunning) { - QString interfaceSsidString = nsstringToQString([currentInterface ssid]); - qDebug() << "interfaceSsidString:" << interfaceSsidString; if (networkSsid == nsstringToQString([currentInterface ssid])) state = QNetworkConfiguration::Active; } else { @@ -449,7 +351,6 @@ QStringList QCoreWlanEngine::scanForSsids(const QString &interfaceName) else state = QNetworkConfiguration::Defined; } - qDebug() << "state is:" << state; CWWirelessProfile *networkProfile = apNetwork.wirelessProfile; CW8021XProfile *userNetworkProfile = networkProfile.user8021XProfile; @@ -482,10 +383,8 @@ QStringList QCoreWlanEngine::scanForSsids(const QString &interfaceName) changed = true; } - if (changed) { - qDebug() << "WLAN Configuration Changed" << interfaceName << ptr->name << ptr->id; + if (changed) emit configurationChanged(ptr); - } } else { QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate); @@ -498,7 +397,6 @@ QStringList QCoreWlanEngine::scanForSsids(const QString &interfaceName) accessPointConfigurations.insert(id, ptr); configurationInterface.insert(id, interfaceName); - qDebug() << "WLAN Configuration Added" << interfaceName << ptr->name << ptr->id; emit configurationAdded(ptr); } } -- cgit v0.12 From 31e6fc5ae7f7fbe2f23b519cb76dcc579dac1f41 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 5 Jan 2010 09:06:49 +1000 Subject: Bearer Management Integration 2. --- config.tests/mac/corelwan/corewlan.pro | 4 - config.tests/mac/corelwan/corewlantest.mm | 49 --- config.tests/mac/corewlan/corewlan.pro | 4 + config.tests/mac/corewlan/corewlantest.mm | 49 +++ examples/network/bearercloud/bearercloud.pro | 13 +- examples/network/bearercloud/cloud.cpp | 12 +- examples/network/bearercloud/cloud.h | 2 + examples/network/bearermonitor/bearermonitor.pro | 12 +- examples/network/bearermonitor/sessionwidget.cpp | 15 +- src/network/bearer/bearer.pro | 19 +- src/network/bearer/qcorewlanengine_mac.mm | 121 +++--- src/network/bearer/qcorewlanengine_mac_p.h | 3 +- src/network/bearer/qgenericengine.cpp | 39 +- src/network/bearer/qgenericengine_p.h | 2 +- src/network/bearer/qnativewifiengine_win.cpp | 7 +- src/network/bearer/qnativewifiengine_win_p.h | 2 +- src/network/bearer/qnetworkconfigmanager_p.cpp | 3 + src/network/bearer/qnetworkconfigmanager_s60_p.h | 3 + src/network/bearer/qnetworkconfiguration.cpp | 56 ++- src/network/bearer/qnetworkconfiguration.h | 1 + src/network/bearer/qnetworkconfiguration_maemo_p.h | 13 + src/network/bearer/qnetworkconfiguration_p.h | 6 + src/network/bearer/qnetworkconfiguration_s60_p.cpp | 16 + src/network/bearer/qnetworkconfiguration_s60_p.h | 1 + src/network/bearer/qnetworkmanagerservice_p.cpp | 44 +- src/network/bearer/qnetworksession.cpp | 146 ++++--- src/network/bearer/qnetworksession.h | 3 +- src/network/bearer/qnetworksession_maemo.cpp | 47 +- src/network/bearer/qnetworksession_maemo_p.h | 6 +- src/network/bearer/qnetworksession_p.cpp | 32 +- src/network/bearer/qnetworksession_p.h | 4 +- src/network/bearer/qnetworksession_s60_p.cpp | 76 +--- src/network/bearer/qnetworksession_s60_p.h | 3 +- src/network/bearer/qnetworksessionengine_p.h | 2 +- src/network/bearer/qnlaengine_win.cpp | 26 +- src/network/bearer/qnmwifiengine_unix.cpp | 473 ++++++--------------- src/network/bearer/qnmwifiengine_unix_p.h | 7 +- .../qnetworkconfigmanager.pro | 3 +- .../tst_qnetworkconfigmanager.cpp | 8 +- .../qnetworkconfiguration.pro | 3 +- .../tst_qnetworkconfiguration.cpp | 8 +- tests/auto/qnetworksession/lackey/lackey.pro | 3 +- tests/auto/qnetworksession/lackey/main.cpp | 2 +- .../tst_qnetworksession/tst_qnetworksession.cpp | 86 ++-- .../tst_qnetworksession/tst_qnetworksession.pro | 3 +- tests/manual/bearerex/bearerex.cpp | 37 +- tests/manual/bearerex/bearerex.h | 3 + tests/manual/bearerex/bearerex.pro | 11 +- tests/manual/networkmanager/networkmanager.pro | 3 +- tests/manual/networkmanager/nmview.cpp | 2 - tests/manual/networkmanager/nmview.h | 2 + 51 files changed, 696 insertions(+), 799 deletions(-) delete mode 100644 config.tests/mac/corelwan/corewlan.pro delete mode 100644 config.tests/mac/corelwan/corewlantest.mm create mode 100644 config.tests/mac/corewlan/corewlan.pro create mode 100644 config.tests/mac/corewlan/corewlantest.mm diff --git a/config.tests/mac/corelwan/corewlan.pro b/config.tests/mac/corelwan/corewlan.pro deleted file mode 100644 index 54a6c36..0000000 --- a/config.tests/mac/corelwan/corewlan.pro +++ /dev/null @@ -1,4 +0,0 @@ -SOURCES=corewlantest.mm -TARGET=corewlan -LIBS += -framework CoreWLAN -framework Foundation -CONFIG-=app_bundle diff --git a/config.tests/mac/corelwan/corewlantest.mm b/config.tests/mac/corelwan/corewlantest.mm deleted file mode 100644 index bcddf44..0000000 --- a/config.tests/mac/corelwan/corewlantest.mm +++ /dev/null @@ -1,49 +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 Qt Mobility Components. -** -** $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 -#include - -int main() -{ - [CWInterface interfaceWithName:@"en2"]; - return 0; -} diff --git a/config.tests/mac/corewlan/corewlan.pro b/config.tests/mac/corewlan/corewlan.pro new file mode 100644 index 0000000..54a6c36 --- /dev/null +++ b/config.tests/mac/corewlan/corewlan.pro @@ -0,0 +1,4 @@ +SOURCES=corewlantest.mm +TARGET=corewlan +LIBS += -framework CoreWLAN -framework Foundation +CONFIG-=app_bundle diff --git a/config.tests/mac/corewlan/corewlantest.mm b/config.tests/mac/corewlan/corewlantest.mm new file mode 100644 index 0000000..bcddf44 --- /dev/null +++ b/config.tests/mac/corewlan/corewlantest.mm @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** 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 Qt Mobility Components. +** +** $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 +#include + +int main() +{ + [CWInterface interfaceWithName:@"en2"]; + return 0; +} diff --git a/examples/network/bearercloud/bearercloud.pro b/examples/network/bearercloud/bearercloud.pro index 308ddda..75e3049 100644 --- a/examples/network/bearercloud/bearercloud.pro +++ b/examples/network/bearercloud/bearercloud.pro @@ -15,16 +15,9 @@ INCLUDEPATH += ../../src/bearer include(../examples.pri) -qtAddLibrary(QtBearer) +CONFIG += mobility +MOBILITY = bearer CONFIG += console -include(../examples.pri) - - -macx: { - contains(QT_CONFIG,qt_framework):LIBS += -framework QtBearer - INCLUDEPATH += ../../ - contains(CONFIG, debug) { - } -} +symbian:TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData diff --git a/examples/network/bearercloud/cloud.cpp b/examples/network/bearercloud/cloud.cpp index 4a1bde7..61bd88e 100644 --- a/examples/network/bearercloud/cloud.cpp +++ b/examples/network/bearercloud/cloud.cpp @@ -226,7 +226,7 @@ QVariant Cloud::itemChange(GraphicsItemChange change, const QVariant &value) void Cloud::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { - if (session->isActive()) + if (session->isOpen()) session->close(); else session->open(); @@ -258,7 +258,7 @@ void Cloud::stateChanged(QNetworkSession::State state) tooltip += tr("
Interface: %1").arg(interface.humanReadableName()); tooltip += tr("
Id: %1").arg(configuration.identifier()); - const QString bearerName = session->bearerName(); + const QString bearerName = configuration.bearerName(); if (!bearerName.isEmpty()) tooltip += tr("
Bearer: %1").arg(bearerName); @@ -289,10 +289,10 @@ void Cloud::stateChanged(QNetworkSession::State state) s = s.arg(tr("Unknown")); } - if (session->isActive()) - s = s.arg(tr("Active")); + if (session->isOpen()) + s = s.arg(tr("Open")); else - s = s.arg(tr("Inactive")); + s = s.arg(tr("Closed")); tooltip += s; @@ -307,7 +307,7 @@ void Cloud::stateChanged(QNetworkSession::State state) //! [1] void Cloud::newConfigurationActivated() { - const QString bearerName = session->bearerName(); + const QString bearerName = configuration.bearerName(); if (!svgCache.contains(bearerName)) { if (bearerName == QLatin1String("WLAN")) svgCache.insert(bearerName, new QSvgRenderer(QLatin1String(":wlan.svg"))); diff --git a/examples/network/bearercloud/cloud.h b/examples/network/bearercloud/cloud.h index 4ce43df..b542bf7 100644 --- a/examples/network/bearercloud/cloud.h +++ b/examples/network/bearercloud/cloud.h @@ -45,8 +45,10 @@ #include QTM_USE_NAMESPACE +QT_BEGIN_NAMESPACE class QGraphicsTextItem; class QGraphicsSvgItem; +QT_END_NAMESPACE class Cloud : public QObject, public QGraphicsItem { diff --git a/examples/network/bearermonitor/bearermonitor.pro b/examples/network/bearermonitor/bearermonitor.pro index c8fb3c2..acbee71 100644 --- a/examples/network/bearermonitor/bearermonitor.pro +++ b/examples/network/bearermonitor/bearermonitor.pro @@ -17,16 +17,12 @@ INCLUDEPATH += ../../src/bearer include(../examples.pri) -qtAddLibrary(QtBearer) +CONFIG += mobility +MOBILITY = bearer + win32:!wince*:LIBS += -lWs2_32 wince*:LIBS += -lWs2 CONFIG += console -include(../examples.pri) - -macx: { - contains(QT_CONFIG,qt_framework):LIBS += -framework QtBearer - contains(CONFIG, debug) { - } -} +symbian:TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData diff --git a/examples/network/bearermonitor/sessionwidget.cpp b/examples/network/bearermonitor/sessionwidget.cpp index 7633dd7..0277d87 100644 --- a/examples/network/bearermonitor/sessionwidget.cpp +++ b/examples/network/bearermonitor/sessionwidget.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "sessionwidget.h" +#include "qnetworkconfigmanager.h" SessionWidget::SessionWidget(const QNetworkConfiguration &config, QWidget *parent) : QWidget(parent) @@ -79,7 +80,13 @@ void SessionWidget::updateSession() updateSessionState(session->state()); updateSessionError(session->error()); - bearer->setText(session->bearerName()); + if (session->configuration().type() == QNetworkConfiguration::InternetAccessPoint) + bearer->setText(session->configuration().bearerName()); + else { + QNetworkConfigurationManager mgr; + QNetworkConfiguration c = mgr.configurationFromIdentifier(session->sessionProperty("ActiveConfiguration").toString()); + bearer->setText(c.bearerName()); + } interfaceName->setText(session->interface().humanReadableName()); interfaceGuid->setText(session->interface().name()); @@ -140,10 +147,10 @@ void SessionWidget::updateSessionState(QNetworkSession::State state) s = s.arg(tr("Unknown")); } - if (session->isActive()) - s = s.arg(tr("Active")); + if (session->isOpen()) + s = s.arg(tr("Open")); else - s = s.arg(tr("Inactive")); + s = s.arg(tr("Closed")); sessionState->setText(s); } diff --git a/src/network/bearer/bearer.pro b/src/network/bearer/bearer.pro index 2255b7c..ce39db6 100644 --- a/src/network/bearer/bearer.pro +++ b/src/network/bearer/bearer.pro @@ -19,8 +19,7 @@ SOURCES += qnetworksession.cpp \ qnetworkconfiguration.cpp symbian: { - exists($${EPOCROOT}epoc32/release/winscw/udeb/cmmanager.lib)| \ - exists($${EPOCROOT}epoc32/release/armv5/lib/cmmanager.lib) { + contains(snap_enabled, yes) { message("Building with SNAP support") DEFINES += SNAP_FUNCTIONALITY_AVAILABLE=1 LIBS += -lcmmanager @@ -48,21 +47,21 @@ symbian: { -lefsrv \ -lnetmeta + TARGET.CAPABILITY = ALL -TCB + TARGET.UID3 = 0x2002AC81 + deploy.path = $${EPOCROOT} exportheaders.sources = $$PUBLIC_HEADERS exportheaders.path = epoc32/include - for(header, exportheaders.sources) { BLD_INF_RULES.prj_exports += "$$header $$deploy.path$$exportheaders.path/$$basename(header)" } - - bearer_deployment.sources = QtBearer.dll - bearer_deployment.path = /sys/bin - DEPLOYMENT += bearer_deployment - - TARGET.CAPABILITY = All -TCB + + QtBearerManagement.sources = QtBearer.dll + QtBearerManagement.path = /sys/bin + DEPLOYMENT += QtBearerManagement } else { - maemo { + maemo6 { QT += dbus CONFIG += link_pkgconfig diff --git a/src/network/bearer/qcorewlanengine_mac.mm b/src/network/bearer/qcorewlanengine_mac.mm index 5451615..41ec79a 100644 --- a/src/network/bearer/qcorewlanengine_mac.mm +++ b/src/network/bearer/qcorewlanengine_mac.mm @@ -102,7 +102,7 @@ inline QStringList nsarrayToQStringList(void *nsarray) static QString qGetInterfaceType(const QString &interfaceString) { - return networkInterfaces.value(interfaceString); + return networkInterfaces.value(interfaceString, QLatin1String("Unknown")); } QCoreWlanEngine::QCoreWlanEngine(QObject *parent) @@ -115,66 +115,52 @@ QCoreWlanEngine::QCoreWlanEngine(QObject *parent) QCoreWlanEngine::~QCoreWlanEngine() { -} - -QList QCoreWlanEngine::getWifiConfigurations() -{ - QMapIterator i(networkInterfaces); - while (i.hasNext()) { - i.next(); - QString interfaceName = i.key(); - if (i.value() == "WLAN") { - if(!isWifiReady(interfaceName)) { - qWarning() << "wifi not powered on"; - return QList(); - } else { - // QList profs = getWlanProfiles(interfaceName); - scanForSsids(interfaceName); - } - } else { - - } + QNetworkConfigurationPrivate* cpPriv = 0; + foundConfigurations.clear(); + while(!foundConfigurations.isEmpty()) { + cpPriv = foundConfigurations.takeFirst(); + delete cpPriv; } - return QList (); } QList QCoreWlanEngine::getConfigurations(bool *ok) { if (ok) *ok = true; - NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; - - QList foundConfigurations; - QList wificonfigs = getWifiConfigurations(); + foundConfigurations.clear(); uint identifier; QMapIterator i(networkInterfaces); + QNetworkConfigurationPrivate* cpPriv = 0; while (i.hasNext()) { i.next(); if (i.value() == "WLAN") { QList fetchedConfigurations = scanForSsids(i.key()); for (int i = 0; i < fetchedConfigurations.count(); ++i) { - QNetworkConfigurationPrivate *config = new QNetworkConfigurationPrivate; - config->name = fetchedConfigurations.at(i)->name; - config->isValid = fetchedConfigurations.at(i)->isValid; - config->id = fetchedConfigurations.at(i)->id; + QNetworkConfigurationPrivate *config = new QNetworkConfigurationPrivate(); + cpPriv = fetchedConfigurations.at(i); + config->name = cpPriv->name; + config->isValid = cpPriv->isValid; + config->id = cpPriv->id; - config->state = fetchedConfigurations.at(i)->state; - config->type = fetchedConfigurations.at(i)->type; - config->roamingSupported = fetchedConfigurations.at(i)->roamingSupported; - config->purpose = fetchedConfigurations.at(i)->purpose; - config->internet = fetchedConfigurations.at(i)->internet; - config->serviceInterface = fetchedConfigurations.at(i)->serviceInterface; + config->state = cpPriv->state; + config->type = cpPriv->type; + config->roamingSupported = cpPriv->roamingSupported; + config->purpose = cpPriv->purpose; + config->internet = cpPriv->internet; + config->serviceInterface = cpPriv->serviceInterface; + config->bearer = cpPriv->bearer; identifier = config->name.toUInt(); configurationInterface[identifier] = config->serviceInterface.name(); foundConfigurations.append(config); + delete cpPriv; } } QNetworkInterface interface = QNetworkInterface::interfaceFromName(i.key()); - QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; + QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate(); const QString humanReadableName = interface.humanReadableName(); cpPriv->name = humanReadableName.isEmpty() ? interface.name() : humanReadableName; cpPriv->isValid = true; @@ -197,9 +183,10 @@ QList QCoreWlanEngine::getConfigurations(bool *o cpPriv->internet = true; } configurationInterface[identifier] = interface.name(); + cpPriv->bearer = interface.name().isEmpty()? QLatin1String("Unknown") : qGetInterfaceType(interface.name()); foundConfigurations.append(cpPriv); } - [autoreleasepool release]; + pollTimer.start(); return foundConfigurations; } @@ -214,16 +201,6 @@ bool QCoreWlanEngine::hasIdentifier(const QString &id) return configurationInterface.contains(id.toUInt()); } -QString QCoreWlanEngine::bearerName(const QString &id) -{ - QString interface = getInterfaceFromId(id); - - if (interface.isEmpty()) - return QString(); - - return qGetInterfaceType(interface); -} - void QCoreWlanEngine::connectToId(const QString &id) { NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; @@ -239,14 +216,22 @@ void QCoreWlanEngine::connectToId(const QString &id) NSEnumerator *enumerator = [remNets objectEnumerator]; CWWirelessProfile *wProfile; NSUInteger index=0; + CWNetwork *apNetwork; + NSDictionary *parametersDict; + NSArray* apArray; + + CW8021XProfile *user8021XProfile; + NSError *err; + NSMutableDictionary *params; + while ((wProfile = [enumerator nextObject])) { //CWWirelessProfile if(id == nsstringToQString([wProfile ssid])) { - CW8021XProfile *user8021XProfile = nil; + user8021XProfile = nil; user8021XProfile = [ wProfile user8021XProfile]; - NSError *err = nil; - NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0]; + err = nil; + params = [NSMutableDictionary dictionaryWithCapacity:0]; if(user8021XProfile) { [params setValue: user8021XProfile forKey:kCWAssocKey8021XProfile]; @@ -254,17 +239,22 @@ void QCoreWlanEngine::connectToId(const QString &id) [params setValue: [wProfile passphrase] forKey: kCWAssocKeyPassphrase]; } - NSDictionary *parametersDict = nil; - NSArray* apArray = [NSMutableArray arrayWithArray:[wifiInterface scanForNetworksWithParameters:parametersDict error:&err]]; + parametersDict = nil; + apArray = [NSMutableArray arrayWithArray:[wifiInterface scanForNetworksWithParameters:parametersDict error:&err]]; + if(!err) { + for(uint row=0; row < [apArray count]; row++ ) { - CWNetwork *apNetwork = [apArray objectAtIndex:row]; + apNetwork = [apArray objectAtIndex:row]; if([[apNetwork ssid] compare:[wProfile ssid]] == NSOrderedSame) { + bool result = [wifiInterface associateToNetwork: apNetwork parameters:[NSDictionary dictionaryWithDictionary:params] error:&err]; + if(!result) { qWarning() <<"ERROR"<< nsstringToQString([err localizedDescription ]); emit connectionError(id, ConnectError); } else { + [apNetwork release]; [autoreleasepool release]; return; } @@ -274,6 +264,8 @@ void QCoreWlanEngine::connectToId(const QString &id) } index++; } + [apNetwork release]; + emit connectionError(id, InterfaceLookupError); #endif } else { @@ -325,24 +317,21 @@ QList QCoreWlanEngine::scanForSsids(const QStrin NSDictionary *parametersDict = nil; NSArray* apArray = [NSMutableArray arrayWithArray:[currentInterface scanForNetworksWithParameters:parametersDict error:&err]]; + CWNetwork *apNetwork; if(!err) { for(uint row=0; row < [apArray count]; row++ ) { - CWNetwork *apNetwork = [apArray objectAtIndex:row]; + NSAutoreleasePool *looppool = [[NSAutoreleasePool alloc] init]; + + apNetwork = [apArray objectAtIndex:row]; QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); QString networkSsid = nsstringToQString([apNetwork ssid]); cpPriv->name = networkSsid; cpPriv->isValid = true; cpPriv->id = networkSsid; cpPriv->internet = true; + cpPriv->bearer = QLatin1String("WLAN"); cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - cpPriv->serviceInterface = QNetworkInterface::interfaceFromName(nsstringToQString([[CWInterface interface] name])); - - CWWirelessProfile *networkProfile = apNetwork.wirelessProfile; - CW8021XProfile *userNetworkProfile = networkProfile.user8021XProfile; - if(!userNetworkProfile) { - } else { - qWarning() <<"Has profile!" ; - } + cpPriv->serviceInterface = QNetworkInterface::interfaceFromName(interfaceName); if( [currentInterface.interfaceState intValue] == kCWInterfaceStateRunning) { QString interfaceSsidString = nsstringToQString( [currentInterface ssid]); @@ -364,12 +353,14 @@ QList QCoreWlanEngine::scanForSsids(const QStrin else cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; foundConfigs.append(cpPriv); + [looppool release]; } } else { qWarning() << "ERROR scanning for ssids" << nsstringToQString([err localizedDescription]) < getWlanProfiles(const QString &interfaceName); - QList getWifiConfigurations(); bool isKnownSsid(const QString &interfaceName, const QString &ssid); + QList foundConfigurations; + }; QTM_END_NAMESPACE diff --git a/src/network/bearer/qgenericengine.cpp b/src/network/bearer/qgenericengine.cpp index 184a69c..10cea0c 100644 --- a/src/network/bearer/qgenericengine.cpp +++ b/src/network/bearer/qgenericengine.cpp @@ -53,6 +53,13 @@ #include "qnetworksessionengine_win_p.h" #endif +#ifdef Q_OS_LINUX +#include +#include +#include +#include +#endif + QTM_BEGIN_NAMESPACE Q_GLOBAL_STATIC(QGenericEngine, genericEngine) @@ -69,7 +76,7 @@ static QString qGetInterfaceType(const QString &interface) HANDLE handle = CreateFile((TCHAR *)QString("\\\\.\\%1").arg(interface).utf16(), 0, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); if (handle == INVALID_HANDLE_VALUE) - return QString(); + return QLatin1String("Unknown"); oid = OID_GEN_MEDIA_SUPPORTED; bytesWritten = 0; @@ -77,7 +84,7 @@ static QString qGetInterfaceType(const QString &interface) &medium, sizeof(medium), &bytesWritten, 0); if (!result) { CloseHandle(handle); - return QString(); + return QLatin1String("Unknown"); } oid = OID_GEN_PHYSICAL_MEDIUM; @@ -90,7 +97,7 @@ static QString qGetInterfaceType(const QString &interface) if (medium == NdisMedium802_3) return QLatin1String("Ethernet"); else - return QString(); + return QLatin1String("Unknown"); } CloseHandle(handle); @@ -114,11 +121,24 @@ static QString qGetInterfaceType(const QString &interface) #ifdef BEARER_MANAGEMENT_DEBUG qDebug() << medium << physicalMedium; #endif +#elif defined(Q_OS_LINUX) + int sock = socket(AF_INET, SOCK_DGRAM, 0); + + ifreq request; + strncpy(request.ifr_name, interface.toLocal8Bit().data(), sizeof(request.ifr_name)); + if (ioctl(sock, SIOCGIFHWADDR, &request) >= 0) { + switch (request.ifr_hwaddr.sa_family) { + case ARPHRD_ETHER: + return QLatin1String("Ethernet"); + } + } + + close(sock); #else Q_UNUSED(interface); #endif - return QString(); + return QLatin1String("Unknown"); } QGenericEngine::QGenericEngine(QObject *parent) @@ -176,6 +196,11 @@ QList QGenericEngine::getConfigurations(bool *ok cpPriv->id = QString::number(identifier); cpPriv->state = QNetworkConfiguration::Discovered; cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + if (interface.name().isEmpty()) + cpPriv->bearer = QLatin1String("Unknown"); + else + cpPriv->bearer = qGetInterfaceType(interface.name()); + if (interface.flags() & QNetworkInterface::IsUp) cpPriv->state |= QNetworkConfiguration::Active; @@ -199,15 +224,15 @@ bool QGenericEngine::hasIdentifier(const QString &id) return configurationInterface.contains(id.toUInt()); } -QString QGenericEngine::bearerName(const QString &id) +/*QString QGenericEngine::bearerName(const QString &id) { QString interface = getInterfaceFromId(id); if (interface.isEmpty()) - return QString(); + return QLatin1String("Unknown"); return qGetInterfaceType(interface); -} +}*/ void QGenericEngine::connectToId(const QString &id) { diff --git a/src/network/bearer/qgenericengine_p.h b/src/network/bearer/qgenericengine_p.h index 976776e..5c08aa2 100644 --- a/src/network/bearer/qgenericengine_p.h +++ b/src/network/bearer/qgenericengine_p.h @@ -74,7 +74,7 @@ public: QString getInterfaceFromId(const QString &id); bool hasIdentifier(const QString &id); - QString bearerName(const QString &id); + //QString bearerName(const QString &id); void connectToId(const QString &id); void disconnectFromId(const QString &id); diff --git a/src/network/bearer/qnativewifiengine_win.cpp b/src/network/bearer/qnativewifiengine_win.cpp index d8fe5fb..008a9cf 100644 --- a/src/network/bearer/qnativewifiengine_win.cpp +++ b/src/network/bearer/qnativewifiengine_win.cpp @@ -479,6 +479,8 @@ QList QNativeWifiEngine::getConfigurations(bool } cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + cpPriv->bearer = QLatin1String("WLAN"); + foundConfigurations.append(cpPriv); } @@ -537,6 +539,7 @@ QString QNativeWifiEngine::getInterfaceFromId(const QString &id) } local_WlanFreeMemory(connectionAttributes); + local_WlanFreeMemory(interfaceList); } return QString(); @@ -591,10 +594,10 @@ bool QNativeWifiEngine::hasIdentifier(const QString &id) return false; } -QString QNativeWifiEngine::bearerName(const QString &) +/*QString QNativeWifiEngine::bearerName(const QString &) { return QLatin1String("WLAN"); -} +}*/ void QNativeWifiEngine::connectToId(const QString &id) { diff --git a/src/network/bearer/qnativewifiengine_win_p.h b/src/network/bearer/qnativewifiengine_win_p.h index 0d5bcb0..e911746 100644 --- a/src/network/bearer/qnativewifiengine_win_p.h +++ b/src/network/bearer/qnativewifiengine_win_p.h @@ -73,7 +73,7 @@ public: QString getInterfaceFromId(const QString &id); bool hasIdentifier(const QString &id); - QString bearerName(const QString &id); + //QString bearerName(const QString &id); void connectToId(const QString &id); void disconnectFromId(const QString &id); diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 8b15f41..39426d0 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -78,6 +78,7 @@ void QNetworkConfigurationManagerPrivate::configurationAdded(QNetworkConfigurati ptr.data()->roamingSupported = cpPriv->roamingSupported; ptr.data()->purpose = cpPriv->purpose; ptr.data()->internet = cpPriv->internet; + ptr.data()->bearer = cpPriv->bearer; accessPointConfigurations.insert(cpPriv->id, ptr); configurationEngine.insert(cpPriv->id, engine); @@ -135,6 +136,7 @@ void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigura ptr.data()->type != cpPriv->type || ptr.data()->roamingSupported != cpPriv->roamingSupported || ptr.data()->purpose != cpPriv->purpose || + ptr.data()->bearer != cpPriv->bearer || ptr.data()->internet != cpPriv->internet) { const QNetworkConfiguration::StateFlags oldState = ptr.data()->state; @@ -147,6 +149,7 @@ void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigura ptr.data()->roamingSupported = cpPriv->roamingSupported; ptr.data()->purpose = cpPriv->purpose; ptr.data()->internet = cpPriv->internet; + ptr.data()->bearer = cpPriv->bearer; if (!firstUpdate) { QNetworkConfiguration item; diff --git a/src/network/bearer/qnetworkconfigmanager_s60_p.h b/src/network/bearer/qnetworkconfigmanager_s60_p.h index 296d67f..679fa6c 100644 --- a/src/network/bearer/qnetworkconfigmanager_s60_p.h +++ b/src/network/bearer/qnetworkconfigmanager_s60_p.h @@ -63,7 +63,10 @@ #endif class CCommsDatabase; + +QT_BEGIN_NAMESPACE class QTimer; +QT_END_NAMESPACE QTM_BEGIN_NAMESPACE diff --git a/src/network/bearer/qnetworkconfiguration.cpp b/src/network/bearer/qnetworkconfiguration.cpp index c92b356..56907c3 100644 --- a/src/network/bearer/qnetworkconfiguration.cpp +++ b/src/network/bearer/qnetworkconfiguration.cpp @@ -164,9 +164,9 @@ QTM_BEGIN_NAMESPACE QNetworkConfiguration::Defined. If the configuration is a service network this flag is set if at least one of the underlying access points configurations has the Discovered state. - \value Active The configuration is currently used by an open/active network session - (see \l QNetworkSession::isActive()). However this does not mean that the - current process is the entity that created the active session. It merely + \value Active The configuration is currently used by an open network session + (see \l QNetworkSession::isOpen()). However this does not mean that the + current process is the entity that created the open session. It merely indicates that if a new QNetworkSession were to be constructed based on this configuration \l QNetworkSession::state() would return \l QNetworkSession::Connected. This state implies the @@ -344,6 +344,56 @@ QList QNetworkConfiguration::children() const return results; } +/*! + Returns the type of bearer. The string is not translated and + therefore can not be shown to the user. The subsequent table presents the currently known + bearer types: + + \table + \header + \o Value + \o Description + \row + \o Unknown + \o The session is based on an unknown or unspecified bearer type. + \row + \o Ethernet + \o The session is based on Ethernet. + \row + \o WLAN + \o The session is based on Wireless LAN. + \row + \o 2G + \o The session uses CSD, GPRS, HSCSD, EDGE or cdmaOne. + \row + \o CDMA2000 + \o The session uses CDMA. + \row + \o WCDMA + \o The session uses W-CDMA/UMTS. + \row + \o HSPA + \o The session uses High Speed Packet Access. + \row + \o Bluetooth + \o The session uses Bluetooth. + \row + \o WiMAX + \o The session uses WiMAX. + \endtable + + This function returns an empty string if this is an invalid configuration, + a network configuration of type \l QNetworkConfiguration::ServiceNetwork or + \l QNetworkConfiguration::UserChoice. +*/ +QString QNetworkConfiguration::bearerName() const +{ + if (!isValid()) + return QString(); + + return d->bearerName(); +} + QTM_END_NAMESPACE diff --git a/src/network/bearer/qnetworkconfiguration.h b/src/network/bearer/qnetworkconfiguration.h index f8c17d5..860be4b 100644 --- a/src/network/bearer/qnetworkconfiguration.h +++ b/src/network/bearer/qnetworkconfiguration.h @@ -91,6 +91,7 @@ public: StateFlags state() const; Type type() const; Purpose purpose() const; + QString bearerName() const; QString identifier() const; bool isRoamingAvailable() const; QList children() const; diff --git a/src/network/bearer/qnetworkconfiguration_maemo_p.h b/src/network/bearer/qnetworkconfiguration_maemo_p.h index 8d786aa..2597605 100644 --- a/src/network/bearer/qnetworkconfiguration_maemo_p.h +++ b/src/network/bearer/qnetworkconfiguration_maemo_p.h @@ -89,6 +89,19 @@ public: /* 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; diff --git a/src/network/bearer/qnetworkconfiguration_p.h b/src/network/bearer/qnetworkconfiguration_p.h index a3bcd9a..c2834e6 100644 --- a/src/network/bearer/qnetworkconfiguration_p.h +++ b/src/network/bearer/qnetworkconfiguration_p.h @@ -78,6 +78,12 @@ public: } QString name; + QString bearer; + inline QString bearerName() const + { + return bearer; + } + bool isValid; QString id; QNetworkConfiguration::StateFlags state; diff --git a/src/network/bearer/qnetworkconfiguration_s60_p.cpp b/src/network/bearer/qnetworkconfiguration_s60_p.cpp index 61548ba..02115d9 100644 --- a/src/network/bearer/qnetworkconfiguration_s60_p.cpp +++ b/src/network/bearer/qnetworkconfiguration_s60_p.cpp @@ -57,4 +57,20 @@ QNetworkConfigurationPrivate::~QNetworkConfigurationPrivate() serviceNetworkMembers.clear(); } +QString QNetworkConfigurationPrivate::bearerName() const +{ + switch (bearer) { + case QNetworkConfigurationPrivate::BearerEthernet: return QLatin1String("Ethernet"); + case QNetworkConfigurationPrivate::BearerWLAN: return QLatin1String("WLAN"); + case QNetworkConfigurationPrivate::Bearer2G: return QLatin1String("2G"); + case QNetworkConfigurationPrivate::BearerCDMA2000: return QLatin1String("CDMA2000"); + case QNetworkConfigurationPrivate::BearerWCDMA: return QLatin1String("WCDMA"); + case QNetworkConfigurationPrivate::BearerHSPA: return QLatin1String("HSPA"); + case QNetworkConfigurationPrivate::BearerBluetooth: return QLatin1String("Bluetooth"); + case QNetworkConfigurationPrivate::BearerWiMAX: return QLatin1String("WiMAX"); + default: return QLatin1String("Unknown"); + } +} + + QTM_END_NAMESPACE diff --git a/src/network/bearer/qnetworkconfiguration_s60_p.h b/src/network/bearer/qnetworkconfiguration_s60_p.h index 44f8f56..6c87200 100644 --- a/src/network/bearer/qnetworkconfiguration_s60_p.h +++ b/src/network/bearer/qnetworkconfiguration_s60_p.h @@ -87,6 +87,7 @@ public: QList > serviceNetworkMembers; QNetworkConfigurationPrivate::Bearer bearer; + QString bearerName() const; TUint32 numericId; TUint connectionId; diff --git a/src/network/bearer/qnetworkmanagerservice_p.cpp b/src/network/bearer/qnetworkmanagerservice_p.cpp index 2f91af0..5804686 100644 --- a/src/network/bearer/qnetworkmanagerservice_p.cpp +++ b/src/network/bearer/qnetworkmanagerservice_p.cpp @@ -70,7 +70,7 @@ public: }; QNetworkManagerInterface::QNetworkManagerInterface(QObject *parent) - : QObject(parent) + : QObject(parent), nmDBusHelper(0) { d = new QNetworkManagerInterfacePrivate(); d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, @@ -93,6 +93,8 @@ QNetworkManagerInterface::QNetworkManagerInterface(QObject *parent) QNetworkManagerInterface::~QNetworkManagerInterface() { + if (nmDBusHelper) + delete nmDBusHelper; delete d->connectionInterface; delete d; } @@ -195,7 +197,7 @@ public: }; QNetworkManagerInterfaceAccessPoint::QNetworkManagerInterfaceAccessPoint(const QString &dbusPathName, QObject *parent) - : QObject(parent) + : QObject(parent), nmDBusHelper(0) { d = new QNetworkManagerInterfaceAccessPointPrivate(); d->path = dbusPathName; @@ -214,6 +216,8 @@ QNetworkManagerInterfaceAccessPoint::QNetworkManagerInterfaceAccessPoint(const Q QNetworkManagerInterfaceAccessPoint::~QNetworkManagerInterfaceAccessPoint() { + if (nmDBusHelper) + delete nmDBusHelper; delete d->connectionInterface; delete d; } @@ -229,6 +233,9 @@ bool QNetworkManagerInterfaceAccessPoint::setConnections() return false; bool allOk = false; + if (nmDBusHelper) + delete nmDBusHelper; + nmDBusHelper = 0; nmDBusHelper = new QNmDBusHelper; connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), this,SIGNAL(propertiesChanged( const QString &, QMap))); @@ -304,7 +311,7 @@ public: }; QNetworkManagerInterfaceDevice::QNetworkManagerInterfaceDevice(const QString &deviceObjectPath, QObject *parent) - : QObject(parent) + : QObject(parent), nmDBusHelper(0) { d = new QNetworkManagerInterfaceDevicePrivate(); d->path = deviceObjectPath; @@ -322,6 +329,8 @@ QNetworkManagerInterfaceDevice::QNetworkManagerInterfaceDevice(const QString &de QNetworkManagerInterfaceDevice::~QNetworkManagerInterfaceDevice() { + if (nmDBusHelper) + delete nmDBusHelper; delete d->connectionInterface; delete d; } @@ -337,6 +346,9 @@ bool QNetworkManagerInterfaceDevice::setConnections() return false; bool allOk = false; + if (nmDBusHelper) + delete nmDBusHelper; + nmDBusHelper = 0; nmDBusHelper = new QNmDBusHelper; connect(nmDBusHelper,SIGNAL(pathForStateChanged(const QString &, quint32)), this, SIGNAL(stateChanged(const QString&, quint32))); @@ -396,6 +408,7 @@ public: }; QNetworkManagerInterfaceDeviceWired::QNetworkManagerInterfaceDeviceWired(const QString &ifaceDevicePath, QObject *parent) + : QObject(parent), nmDBusHelper(0) { d = new QNetworkManagerInterfaceDeviceWiredPrivate(); d->path = ifaceDevicePath; @@ -413,6 +426,8 @@ QNetworkManagerInterfaceDeviceWired::QNetworkManagerInterfaceDeviceWired(const Q QNetworkManagerInterfaceDeviceWired::~QNetworkManagerInterfaceDeviceWired() { + if (nmDBusHelper) + delete nmDBusHelper; delete d->connectionInterface; delete d; } @@ -430,6 +445,9 @@ bool QNetworkManagerInterfaceDeviceWired::setConnections() bool allOk = false; + if (nmDBusHelper) + delete nmDBusHelper; + nmDBusHelper = 0; nmDBusHelper = new QNmDBusHelper; connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), this,SIGNAL(propertiesChanged( const QString &, QMap))); @@ -473,6 +491,7 @@ public: }; QNetworkManagerInterfaceDeviceWireless::QNetworkManagerInterfaceDeviceWireless(const QString &ifaceDevicePath, QObject *parent) + : QObject(parent), nmDBusHelper(0) { d = new QNetworkManagerInterfaceDeviceWirelessPrivate(); d->path = ifaceDevicePath; @@ -490,6 +509,8 @@ QNetworkManagerInterfaceDeviceWireless::QNetworkManagerInterfaceDeviceWireless(c QNetworkManagerInterfaceDeviceWireless::~QNetworkManagerInterfaceDeviceWireless() { + if (nmDBusHelper) + delete nmDBusHelper; delete d->connectionInterface; delete d; } @@ -505,6 +526,9 @@ bool QNetworkManagerInterfaceDeviceWireless::setConnections() return false; bool allOk = false; + if (nmDBusHelper) + delete nmDBusHelper; + nmDBusHelper = 0; nmDBusHelper = new QNmDBusHelper; connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), this,SIGNAL(propertiesChanged( const QString &, QMap))); @@ -592,7 +616,6 @@ public: QNetworkManagerSettings::QNetworkManagerSettings(const QString &settingsService, QObject *parent) : QObject(parent) { -// qWarning() << __PRETTY_FUNCTION__; d = new QNetworkManagerSettingsPrivate(); d->path = settingsService; d->connectionInterface = new QDBusInterface(settingsService, @@ -655,6 +678,7 @@ public: }; QNetworkManagerSettingsConnection::QNetworkManagerSettingsConnection(const QString &settingsService, const QString &connectionObjectPath, QObject *parent) + : QObject(parent), nmDBusHelper(0) { qDBusRegisterMetaType(); d = new QNetworkManagerSettingsConnectionPrivate(); @@ -676,6 +700,8 @@ QNetworkManagerSettingsConnection::QNetworkManagerSettingsConnection(const QStri QNetworkManagerSettingsConnection::~QNetworkManagerSettingsConnection() { + if (nmDBusHelper) + delete nmDBusHelper; delete d->connectionInterface; delete d; } @@ -697,6 +723,9 @@ bool QNetworkManagerSettingsConnection::setConnections() allOk = true; } + if (nmDBusHelper) + delete nmDBusHelper; + nmDBusHelper = 0; nmDBusHelper = new QNmDBusHelper; connect(nmDBusHelper, SIGNAL(pathForSettingsRemoved(const QString &)), this,SIGNAL(removed( const QString &))); @@ -880,6 +909,7 @@ public: }; QNetworkManagerConnectionActive::QNetworkManagerConnectionActive( const QString &activeConnectionObjectPath, QObject *parent) + : QObject(parent), nmDBusHelper(0) { d = new QNetworkManagerConnectionActivePrivate(); d->path = activeConnectionObjectPath; @@ -897,6 +927,8 @@ QNetworkManagerConnectionActive::QNetworkManagerConnectionActive( const QString QNetworkManagerConnectionActive::~QNetworkManagerConnectionActive() { + if (nmDBusHelper) + delete nmDBusHelper; delete d->connectionInterface; delete d; } @@ -912,6 +944,9 @@ bool QNetworkManagerConnectionActive::setConnections() return false; bool allOk = false; + if (nmDBusHelper) + delete nmDBusHelper; + nmDBusHelper = 0; nmDBusHelper = new QNmDBusHelper; connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), this,SIGNAL(propertiesChanged( const QString &, QMap))); @@ -975,6 +1010,7 @@ public: }; QNetworkManagerIp4Config::QNetworkManagerIp4Config( const QString &deviceObjectPath, QObject *parent) + : QObject(parent) { d = new QNetworkManagerIp4ConfigPrivate(); d->path = deviceObjectPath; diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp index d3a323a..6171350 100644 --- a/src/network/bearer/qnetworksession.cpp +++ b/src/network/bearer/qnetworksession.cpp @@ -46,7 +46,7 @@ #ifdef Q_OS_SYMBIAN #include "qnetworksession_s60_p.h" -#elif MAEMO +#elif Q_WS_MAEMO_6 #include "qnetworksession_maemo_p.h" #else #include "qnetworksession_p.h" @@ -72,34 +72,41 @@ QTM_BEGIN_NAMESPACE QNetworkSession supports session management within the same process and depending on the platform's capabilities may support out-of-process sessions. If the same - network configuration is used by multiple active sessions the underlying network interface is only terminated once + network configuration is used by multiple open sessions the underlying network interface is only terminated once the last session has been closed. \section1 Roaming Applications may connect to the preferredConfigurationChanged() signal in order to receive notifications when a more suitable access point becomes available. - In response to this signal the application may initiate the roaming via migrate() - or may ignore() the new access point. Once the session has roamed the + In response to this signal the application must either initiate the roaming via migrate() + or ignore() the new access point. Once the session has roamed the newConfigurationActivated() signal is emitted. The application may now test the - carrier and can accept() or reject() it. The session will return to the previous - access point if the roaming was rejected. + carrier and must either accept() or reject() it. The session will return to the previous + access point if the roaming was rejected. The subsequent state diagram depicts the required + state transitions. + + \image roaming-states.png - Some platforms may support the notion of forced roaming and application level roaming (ALR). + Some platforms may distinguish forced roaming and application level roaming (ALR). ALR implies that the application controls (via migrate(), ignore(), accept() and reject()) - whether a network session can roam from one network configuration to the next. Such control is useful + whether a network session can roam from one access point to the next. Such control is useful if the application maintains stateful socket connections and wants to control the transition from - one interface to the next. - - Forced roaming implies that the system automatically roams to the next network without + one interface to the next. Forced roaming implies that the system automatically roams to the next network without consulting the application. This has the advantage that the application can make use of roaming features without actually being aware of it. It is expected that the application detects that the underlying socket is broken and automatically reconnects via the new network link. - If the platform supports both modes of roaming an application indicates its preference + If the platform supports both modes of roaming, an application indicates its preference by connecting to the preferredConfigurationChanged() signal. Connecting to this signal means that the application wants to take control over the roaming behavior and therefore implies application - level roaming. + level roaming. If the client does not connect to the preferredConfigurationChanged(), forced roaming + is used. If forced roaming is not supported the network session will not roam by default. + + Some applications may want to suppress any form of roaming altogether. Possible use cases may be + high priority downloads or remote services which cannot handle a roaming enabled client. Clients + can suppress roaming by connecting to the preferredConfigurationChanged() signal and answer each + signal emission with ignore(). \sa QNetworkConfiguration, QNetworkConfigurationManager */ @@ -119,7 +126,7 @@ QTM_BEGIN_NAMESPACE \value Connecting The network session is being established. \value Connected The network session is connected. If the current process wishes to use this session it has to register its interest by calling open(). A network session - is considered to be ready for socket operations if it isActive() and connected. + is considered to be ready for socket operations if it isOpen() and connected. \value Closing The network session is in the process of being shut down. \value Disconnected The network session is not connected. The associated QNetworkConfiguration has the state QNetworkConfiguration::Discovered. @@ -167,9 +174,8 @@ QTM_BEGIN_NAMESPACE details such as proxy settings and \a isSeamless indicates whether roaming will break the sessions IP address. - As a consequence to this signal the application may start the roaming process - by calling migrate() or may chose to ignore() the new access point. If the application - doesn't call either of the two functions the session ignores the migration opportunity. + As a consequence to this signal the application must either start the roaming process + by calling migrate() or choose to ignore() the new access point. If the roaming process is non-seamless the IP address will change which means that a socket becomes invalid. However seamless mobility can ensure that the local IP address @@ -194,7 +200,7 @@ QTM_BEGIN_NAMESPACE This signal is emitted once the session has roamed to the new access point. The application may reopen its socket and test the suitability of the new network link. - Subsequently it may accept() or reject() the new access point. + Subsequently it must either accept() or reject() the new access point. \sa accept(), reject() */ @@ -239,13 +245,13 @@ QNetworkSession::~QNetworkSession() } /*! - Creates an active/open session which increases the session counter on the underlying network interface. + Creates an open session which increases the session counter on the underlying network interface. The system will not terminate a network interface until the session reference counter reaches zero. - Therefore an active session allows an application to register its use of the interface. + Therefore an open session allows an application to register its use of the interface. - The interface is started if it is not active yet. Some platforms may not provide support - for out-of-process sessions. On such platforms the session counter ignores any sessions - held by another process. The platform capabilities can be + As a result of calling open() the interface will be started if it is not connected/up yet. + Some platforms may not provide support for out-of-process sessions. On such platforms the session + counter ignores any sessions held by another process. The platform capabilities can be detected via QNetworkConfigurationManager::capabilities(). Note that this call is asynchronous. Depending on the outcome of this call the results can be enquired @@ -253,7 +259,7 @@ QNetworkSession::~QNetworkSession() It is not a requirement to open a session in order to monitor the underlying network interface. - \sa close(), stop(), isActive() + \sa close(), stop(), isOpen() */ void QNetworkSession::open() { @@ -279,7 +285,7 @@ void QNetworkSession::open() */ bool QNetworkSession::waitForOpened(int msecs) { - if (d->isActive) + if (d->isOpen) return true; if (d->state != Connecting) @@ -297,13 +303,13 @@ bool QNetworkSession::waitForOpened(int msecs) loop->disconnect(); loop->deleteLater(); - return d->isActive; + return d->isOpen; } /*! Decreases the session counter on the associated network configuration. If the session counter reaches zero the active network interface is shut down. This also means that state() will only change from \l Connected to - \l Disconnected if this was the last active session. + \l Disconnected if the current session was the last open session. If the platform does not support out-of-process sessions calling this function does not stop the interface. In this case \l{stop()} has to be used to force a shut down. @@ -312,7 +318,7 @@ bool QNetworkSession::waitForOpened(int msecs) Note that this call is asynchronous. Depending on the outcome of this call the results can be enquired by connecting to the stateChanged(), opened() or error() signals. - \sa open(), stop(), isActive() + \sa open(), stop(), isOpen() */ void QNetworkSession::close() { @@ -320,7 +326,7 @@ void QNetworkSession::close() } /*! - Invalidates all active sessions against the network interface and therefore stops the + Invalidates all open sessions against the network interface and therefore stops the underlying network interface. This function always changes the session's state() flag to \l Disconnected. @@ -341,15 +347,19 @@ QNetworkConfiguration QNetworkSession::configuration() const return d->publicConfig; } -/*! - Returns the type of bearer currently used by this session. The string is not translated and therefore can - not be shown to the user. The subsequent table presents the currently known bearer types: +/* + Returns the type of bearer currently used by this session. The string is not translated and + therefore can not be shown to the user. The subsequent table presents the currently known + bearer types: \table \header \o Value \o Description \row + \o Unknown + \o The session is based on an unknown or unspecified bearer type. + \row \o Ethernet \o The session is based on Ethernet. \row @@ -380,12 +390,14 @@ QNetworkConfiguration QNetworkSession::configuration() const active configuration is returned. Therefore the bearer type may change over time. - This function returns an empty string if this session is based on an invalid configuration. + This function returns an empty string if this session is based on an invalid configuration, or + a network configuration of type \l QNetworkConfiguration::ServiceNetwork with no + \l {QNetworkConfiguration::children()}{children}. */ -QString QNetworkSession::bearerName() const +/*QString QNetworkSession::bearerName() const { return d->bearerName(); -} +}*/ /*! Returns the network interface that is used by this session. @@ -402,25 +414,29 @@ QNetworkInterface QNetworkSession::interface() const } /*! - Returns true if this object holds an active session on the underlying network interface. + Returns true if this session is open. If the number of all open sessions is greater than + zero the underlying network interface will remain connected/up. + The session can be controlled via open() and close(). */ -bool QNetworkSession::isActive() const +bool QNetworkSession::isOpen() const { - return d->isActive; + return d->isOpen; } /*! - Returns the state of the session. If the session is based on a - single access point configuration the state of the session is the same as the state of the - associated network interface. Therefore a network session object can be used to monitor - network interfaces. + Returns the state of the session. + + If the session is based on a single access point configuration the state of the + session is the same as the state of the associated network interface. Therefore + a network session object can be used to monitor network interfaces. A \l QNetworkConfiguration::ServiceNetwork based session summarizes the state of all its children - and therefore returns the \l Connected state if at least one of its sub configurations is connected. + and therefore returns the \l Connected state if at least one of the service network's + \l {QNetworkConfiguration::children()}{children()} configurations is active. - Note that it is not required to hold an active session in order to obtain the network interface state. - A connected but inactive session may be used to monitor network interfaces whereas an active and connected + Note that it is not required to hold an open session in order to obtain the network interface state. + A connected but closed session may be used to monitor network interfaces whereas an open and connected session object may prevent the network interface from being shut down. \sa error(), stateChanged() @@ -463,8 +479,8 @@ QString QNetworkSession::errorString() const \header \o Key \o Description \row - \o ActiveConfigurationIdentifier - \o If the session \l isActive() this property returns the identifier of the + \o ActiveConfiguration + \o If the session \l isOpen() this property returns the identifier of the QNetworkConfiguration that is used by this session; otherwise an empty string. The main purpose of this key is to determine which Internet access point is used @@ -476,7 +492,7 @@ QString QNetworkSession::errorString() const QNetworkSession* session = new QNetworkSession(ap); ... //code activates session - QString ident = session->sessionProperty("ActiveConfigurationIdentifier").toString(); + QString ident = session->sessionProperty("ActiveConfiguration").toString(); if ( ap.type() == QNetworkConfiguration::ServiceNetwork ) { Q_ASSERT( ap.identifier() != ident ); Q_ASSERT( ap.children().contains( mgr.configurationFromIdentifier(ident) ) ); @@ -485,17 +501,17 @@ QString QNetworkSession::errorString() const } \endcode \row - \o UserChoiceConfigurationIdentifier - \o If the session \l isActive() and is bound to a QNetworkConfiguration of type + \o UserChoiceConfiguration + \o If the session \l isOpen() and is bound to a QNetworkConfiguration of type UserChoice, this property returns the identifier of the QNetworkConfiguration that the configuration resolved to when \l open() was called; otherwise an empty string. The purpose of this key is to determine the real QNetworkConfiguration that the - session is using. This key is different to \i ActiveConfigurationIdentifier in that + session is using. This key is different to \i ActiveConfiguration in that this key may return an identifier for either a \l {QNetworkConfiguration::ServiceNetwork}{service network} or a \l {QNetworkConfiguration::InternetAccessPoint}{Internet access points} configurations - whereas \i ActiveConfigurationIdentifier always returns identifiers for + whereas \i ActiveConfiguration always returns identifiers to \l {QNetworkConfiguration::InternetAccessPoint}{Internet access points} configurations. \row \o ConnectInBackground @@ -509,15 +525,15 @@ QVariant QNetworkSession::sessionProperty(const QString& key) const if (!d->publicConfig.isValid()) return QVariant(); - if (key == "ActiveConfigurationIdentifier") { - if (!d->isActive) + if (key == "ActiveConfiguration") { + if (!d->isOpen) return QString(); else return d->activeConfig.identifier(); } - if (key == "UserChoiceConfigurationIdentifier") { - if (!d->isActive || d->publicConfig.type() != QNetworkConfiguration::UserChoice) + if (key == "UserChoiceConfiguration") { + if (!d->isOpen || d->publicConfig.type() != QNetworkConfiguration::UserChoice) return QString(); if (d->serviceConfig.isValid()) @@ -534,13 +550,13 @@ QVariant QNetworkSession::sessionProperty(const QString& key) const \a key. Removing an already set property can be achieved by passing an invalid QVariant. - Note that the \i UserChoiceConfigurationIdentifier and \i ActiveConfigurationIdentifier + Note that the \i UserChoiceConfiguration and \i ActiveConfiguration properties are read only and cannot be changed using this method. */ void QNetworkSession::setSessionProperty(const QString& key, const QVariant& value) { - if (key == "ActiveConfigurationIdentifier" - || key == "UserChoiceConfigurationIdentifier") + if (key == "ActiveConfiguration" + || key == "UserChoiceConfiguration") return; d->setSessionProperty(key, value); @@ -560,16 +576,14 @@ void QNetworkSession::migrate() } /*! - This function indicates that the application does not wish to roam the session. This - is the default behavior if an application doesn't call migrate() in response to a - preferredConfigurationChanged() signal. + This function indicates that the application does not wish to roam the session. \sa migrate() */ void QNetworkSession::ignore() { - //TODO Do we really need this function if we consider that this is - // the default behavior if nobody calls migrate()? + // Needed on at least Symbian platform: the roaming must be explicitly + // ignore()'d or migrate()'d d->ignore(); } @@ -602,7 +616,7 @@ void QNetworkSession::reject() /*! Returns the amount of data sent in bytes; otherwise 0. - This field value includes the usage across all active network + This field value includes the usage across all open network sessions which use the same network interface. If the session is based on a service network configuration the number of @@ -619,7 +633,7 @@ quint64 QNetworkSession::bytesWritten() const /*! Returns the amount of data received in bytes; otherwise 0. - This field value includes the usage across all active network + This field value includes the usage across all open network sessions which use the same network interface. If the session is based on a service network configuration the number of diff --git a/src/network/bearer/qnetworksession.h b/src/network/bearer/qnetworksession.h index 47377c4..7e52674 100644 --- a/src/network/bearer/qnetworksession.h +++ b/src/network/bearer/qnetworksession.h @@ -82,9 +82,8 @@ public: QNetworkSession(const QNetworkConfiguration& connConfig, QObject* parent =0); virtual ~QNetworkSession(); - bool isActive() const; + bool isOpen() const; QNetworkConfiguration configuration() const; - QString bearerName() const; QNetworkInterface interface() const; State state() const; diff --git a/src/network/bearer/qnetworksession_maemo.cpp b/src/network/bearer/qnetworksession_maemo.cpp index c7c7a31..b3afc77 100644 --- a/src/network/bearer/qnetworksession_maemo.cpp +++ b/src/network/bearer/qnetworksession_maemo.cpp @@ -305,14 +305,14 @@ void QNetworkSessionPrivate::updateState(QNetworkSession::State newState) state = newState; if (state == QNetworkSession::Disconnected) { - isActive = false; + isOpen = false; currentNetworkInterface.clear(); if (publicConfig.type() == QNetworkConfiguration::UserChoice) activeConfig.d->state = QNetworkConfiguration::Defined; publicConfig.d->state = QNetworkConfiguration::Defined; } else if (state == QNetworkSession::Connected) { - isActive = true; + isOpen = true; if (publicConfig.type() == QNetworkConfiguration::UserChoice) { activeConfig.d->state = QNetworkConfiguration::Active; activeConfig.d->type = QNetworkConfiguration::InternetAccessPoint; @@ -436,7 +436,7 @@ void QNetworkSessionPrivate::syncStateWithInterface() /* Initially we are not active although the configuration might be in * connected state. */ - isActive = false; + isOpen = false; opened = false; QObject::connect(&manager, SIGNAL(updateCompleted()), this, SLOT(networkConfigurationsChanged())); @@ -684,13 +684,13 @@ void QNetworkSessionPrivate::updateStateFromActiveConfig() clearConfiguration(activeConfig); } - bool oldActive = isActive; - isActive = newActive; + bool oldActive = isOpen; + isOpen = newActive; - if (!oldActive && isActive) + if (!oldActive && isOpen) emit quitPendingWaitsForOpened(); - if (oldActive && !isActive) + if (oldActive && !isOpen) emit q->closed(); if (oldState != state) { @@ -776,7 +776,7 @@ void QNetworkSessionPrivate::open() if (serviceConfig.isValid()) { lastError = QNetworkSession::OperationNotSupportedError; emit q->error(lastError); - } else if (!isActive) { + } else if (!isOpen) { if (publicConfig.type() == QNetworkConfiguration::UserChoice) { /* Caller is trying to connect to default IAP. @@ -810,8 +810,8 @@ void QNetworkSessionPrivate::open() return; } - isActive = (activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active; - if (isActive) + isOpen = (activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active; + if (isOpen) emit quitPendingWaitsForOpened(); } else { /* We seem to be active so inform caller */ @@ -826,7 +826,6 @@ void QNetworkSessionPrivate::do_open() bool st; QString result; QString iap = publicConfig.identifier(); - QString bearer_name; if (state == QNetworkSession::Connected) { #ifdef BEARER_MANAGEMENT_DEBUG @@ -922,14 +921,7 @@ void QNetworkSessionPrivate::do_open() if (!name.isEmpty()) config.d->name = name; - bearer_name = connect_result.connect.network_type; - if (bearer_name == "WLAN_INFRA" || - bearer_name == "WLAN_ADHOC") - currentBearerName = "WLAN"; - else if (bearer_name == "GPRS") - currentBearerName = "HSPA"; - else - currentBearerName = bearer_name; + config.d->iap_type = connect_result.connect.network_type; config.d->isValid = true; config.d->state = QNetworkConfiguration::Active; @@ -1032,9 +1024,9 @@ void QNetworkSessionPrivate::close() if (serviceConfig.isValid()) { lastError = QNetworkSession::OperationNotSupportedError; emit q->error(lastError); - } else if (isActive) { + } else if (isOpen) { opened = false; - isActive = false; + isOpen = false; emit q->closed(); } } @@ -1067,11 +1059,11 @@ void QNetworkSessionPrivate::stop() mgr->configurationChanged((QNetworkConfigurationPrivate*)activeConfig.d.data()); opened = false; - isActive = false; + isOpen = false; } else { opened = false; - isActive = false; + isOpen = false; emit q->closed(); } } @@ -1142,15 +1134,6 @@ QVariant QNetworkSessionPrivate::sessionProperty(const QString& key) const } -QString QNetworkSessionPrivate::bearerName() const -{ - if (!publicConfig.isValid()) - return QString(); - - return currentBearerName; -} - - QString QNetworkSessionPrivate::errorString() const { QString errorStr; diff --git a/src/network/bearer/qnetworksession_maemo_p.h b/src/network/bearer/qnetworksession_maemo_p.h index e233087..892262d 100644 --- a/src/network/bearer/qnetworksession_maemo_p.h +++ b/src/network/bearer/qnetworksession_maemo_p.h @@ -69,7 +69,7 @@ class QNetworkSessionPrivate : public QObject Q_OBJECT public: QNetworkSessionPrivate() : - tx_data(0), rx_data(0), m_activeTime(0), isActive(false), + tx_data(0), rx_data(0), m_activeTime(0), isOpen(false), connectFlags(ICD_CONNECTION_FLAG_USER_EVENT) { } @@ -88,7 +88,6 @@ public: QNetworkInterface currentInterface() const; QVariant sessionProperty(const QString& key) const; void setSessionProperty(const QString& key, const QVariant& value); - QString bearerName() const; void open(); void close(); @@ -142,7 +141,7 @@ private: void cleanupAnyConfiguration(); QNetworkSession::State state; - bool isActive; + bool isOpen; bool opened; icd_connection_flags connectFlags; @@ -152,7 +151,6 @@ private: friend class QNetworkSession; QDateTime startTime; - QString currentBearerName; QString currentNetworkInterface; friend class IcdListener; void updateState(QNetworkSession::State); diff --git a/src/network/bearer/qnetworksession_p.cpp b/src/network/bearer/qnetworksession_p.cpp index c6f9833..1dfc949 100644 --- a/src/network/bearer/qnetworksession_p.cpp +++ b/src/network/bearer/qnetworksession_p.cpp @@ -189,7 +189,7 @@ void QNetworkSessionPrivate::open() if (serviceConfig.isValid()) { lastError = QNetworkSession::OperationNotSupportedError; emit q->error(lastError); - } else if (!isActive) { + } else if (!isOpen) { if ((activeConfig.state() & QNetworkConfiguration::Discovered) != QNetworkConfiguration::Discovered) { lastError =QNetworkSession::InvalidConfigurationError; @@ -206,8 +206,8 @@ void QNetworkSessionPrivate::open() engine->connectToId(activeConfig.identifier()); } - isActive = (activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active; - if (isActive) + isOpen = (activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active; + if (isOpen) emit quitPendingWaitsForOpened(); } } @@ -217,9 +217,9 @@ void QNetworkSessionPrivate::close() if (serviceConfig.isValid()) { lastError = QNetworkSession::OperationNotSupportedError; emit q->error(lastError); - } else if (isActive) { + } else if (isOpen) { opened = false; - isActive = false; + isOpen = false; emit q->closed(); } } @@ -240,7 +240,7 @@ void QNetworkSessionPrivate::stop() } opened = false; - isActive = false; + isOpen = false; emit q->closed(); } } @@ -286,13 +286,13 @@ void QNetworkSessionPrivate::setSessionProperty(const QString& /*key*/, const QV { } -QString QNetworkSessionPrivate::bearerName() const +/*QString QNetworkSessionPrivate::bearerName() const { if (!publicConfig.isValid() || !engine) return QString(); return engine->bearerName(activeConfig.identifier()); -} +}*/ QString QNetworkSessionPrivate::errorString() const { @@ -321,7 +321,7 @@ QNetworkSession::SessionError QNetworkSessionPrivate::error() const quint64 QNetworkSessionPrivate::bytesWritten() const { #if defined(BACKEND_NM) - if( state == QNetworkSession::Connected ) { + if( NetworkManagerAvailable() && state == QNetworkSession::Connected ) { if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { foreach (const QNetworkConfiguration &config, publicConfig.children()) { if ((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { @@ -339,7 +339,7 @@ quint64 QNetworkSessionPrivate::bytesWritten() const quint64 QNetworkSessionPrivate::bytesReceived() const { #if defined(BACKEND_NM) - if( state == QNetworkSession::Connected ) { + if( NetworkManagerAvailable() && state == QNetworkSession::Connected ) { if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { foreach (const QNetworkConfiguration &config, publicConfig.children()) { if ((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { @@ -425,12 +425,12 @@ void QNetworkSessionPrivate::updateStateFromActiveConfig() state = QNetworkSession::NotAvailable; } - bool oldActive = isActive; - isActive = newActive; + bool oldActive = isOpen; + isOpen = newActive; - if (!oldActive && isActive) + if (!oldActive && isOpen) emit quitPendingWaitsForOpened(); - if (oldActive && !isActive) + if (oldActive && !isOpen) emit q->closed(); if (oldState != state) @@ -460,7 +460,7 @@ void QNetworkSessionPrivate::forcedSessionClose(const QNetworkConfiguration &con { if (activeConfig == config) { opened = false; - isActive = false; + isOpen = false; emit q->closed(); @@ -530,7 +530,7 @@ if(serviceName.isEmpty()) QNetworkManagerSettingsConnection *sysIface; sysIface = new QNetworkManagerSettingsConnection(serviceName, path.path()); startTime = QDateTime::fromTime_t(sysIface->getTimestamp()); - // isActive = (publicConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active; + // isOpen = (publicConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active; } if(startTime.isNull()) startTime = QDateTime::currentDateTime(); diff --git a/src/network/bearer/qnetworksession_p.h b/src/network/bearer/qnetworksession_p.h index a2aaa6a..09fcfca 100644 --- a/src/network/bearer/qnetworksession_p.h +++ b/src/network/bearer/qnetworksession_p.h @@ -73,7 +73,7 @@ class QNetworkSessionPrivate : public QObject Q_OBJECT public: QNetworkSessionPrivate() : - tx_data(0), rx_data(0), m_activeTime(0), isActive(false) + tx_data(0), rx_data(0), m_activeTime(0), isOpen(false) { } @@ -143,7 +143,7 @@ private: QNetworkConfiguration activeConfig; QNetworkSession::State state; - bool isActive; + bool isOpen; #ifdef BEARER_ENGINE bool opened; diff --git a/src/network/bearer/qnetworksession_s60_p.cpp b/src/network/bearer/qnetworksession_s60_p.cpp index 764c1c4..f9cb09f 100644 --- a/src/network/bearer/qnetworksession_s60_p.cpp +++ b/src/network/bearer/qnetworksession_s60_p.cpp @@ -53,7 +53,7 @@ QTM_BEGIN_NAMESPACE QNetworkSessionPrivate::QNetworkSessionPrivate() : CActive(CActive::EPriorityStandard), state(QNetworkSession::Invalid), - isActive(false), ipConnectionNotifier(0), iError(QNetworkSession::UnknownSessionError), + isOpen(false), ipConnectionNotifier(0), iError(QNetworkSession::UnknownSessionError), iALREnabled(0) { CActiveScheduler::Add(this); @@ -69,7 +69,7 @@ QNetworkSessionPrivate::QNetworkSessionPrivate() QNetworkSessionPrivate::~QNetworkSessionPrivate() { - isActive = false; + isOpen = false; // Cancel Connection Progress Notifications first. // Note: ConnectionNotifier must be destroyed before Canceling RConnection::Start() @@ -233,7 +233,7 @@ QNetworkSession::SessionError QNetworkSessionPrivate::error() const void QNetworkSessionPrivate::open() { - if (isActive || !publicConfig.d || (state == QNetworkSession::Connecting)) { + if (isOpen || !publicConfig.d || (state == QNetworkSession::Connecting)) { return; } @@ -296,7 +296,7 @@ void QNetworkSessionPrivate::open() error = iDynamicSetdefaultif(&ifr); } - isActive = true; + isOpen = true; // Make sure that state will be Connected newState(QNetworkSession::Connected); emit quitPendingWaitsForOpened(); @@ -333,7 +333,7 @@ void QNetworkSessionPrivate::open() } if (error != KErrNone) { - isActive = false; + isOpen = false; iError = QNetworkSession::UnknownSessionError; emit q->error(iError); if (ipConnectionNotifier) { @@ -372,12 +372,12 @@ TUint QNetworkSessionPrivate::iapClientCount(TUint aIAPId) const void QNetworkSessionPrivate::close(bool allowSignals) { - if (!isActive) { + if (!isOpen) { return; } TUint activeIap = activeConfig.d.data()->numericId; - isActive = false; + isOpen = false; activeConfig = QNetworkConfiguration(); serviceConfig = QNetworkConfiguration(); @@ -419,13 +419,13 @@ void QNetworkSessionPrivate::close(bool allowSignals) void QNetworkSessionPrivate::stop() { - if (!isActive) { + if (!isOpen) { return; } - isActive = false; + isOpen = false; newState(QNetworkSession::Closing); iConnection.Stop(RConnection::EStopAuthoritative); - isActive = true; + isOpen = true; close(false); emit q->closed(); } @@ -510,8 +510,8 @@ void QNetworkSessionPrivate::NewCarrierActive(TAccessPointInfo /*aNewAPInfo*/, T void QNetworkSessionPrivate::Error(TInt /*aError*/) { - if (isActive) { - isActive = false; + if (isOpen) { + isOpen = false; activeConfig = QNetworkConfiguration(); serviceConfig = QNetworkConfiguration(); iError = QNetworkSession::RoamingError; @@ -558,40 +558,6 @@ QNetworkConfiguration QNetworkSessionPrivate::bestConfigFromSNAP(const QNetworkC return config; } -QString QNetworkSessionPrivate::bearerName() const -{ - QNetworkConfiguration config; - if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { - config = publicConfig; - } else if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { - if (activeConfig.isValid()) { - config = activeConfig; - } else { - config = bestConfigFromSNAP(publicConfig); - } - } else if (publicConfig.type() == QNetworkConfiguration::UserChoice) { - if (activeConfig.isValid()) { - config = activeConfig; - } - } - - if (!config.isValid()) { - return QString(); - } - - switch (config.d.data()->bearer) { - case QNetworkConfigurationPrivate::BearerEthernet: return QString("Ethernet"); - case QNetworkConfigurationPrivate::BearerWLAN: return QString("WLAN"); - case QNetworkConfigurationPrivate::Bearer2G: return QString("2G"); - case QNetworkConfigurationPrivate::BearerCDMA2000: return QString("CDMA2000"); - case QNetworkConfigurationPrivate::BearerWCDMA: return QString("WCDMA"); - case QNetworkConfigurationPrivate::BearerHSPA: return QString("HSPA"); - case QNetworkConfigurationPrivate::BearerBluetooth: return QString("Bluetooth"); - case QNetworkConfigurationPrivate::BearerWiMAX: return QString("WiMAX"); - default: return QString(); - } -} - quint64 QNetworkSessionPrivate::bytesWritten() const { return transferredData(KUplinkData); @@ -673,7 +639,7 @@ quint64 QNetworkSessionPrivate::transferredData(TUint dataType) const quint64 QNetworkSessionPrivate::activeTime() const { - if (!isActive || startTime.isNull()) { + if (!isOpen || startTime.isNull()) { return 0; } return startTime.secsTo(QDateTime::currentDateTime()); @@ -785,7 +751,7 @@ void QNetworkSessionPrivate::RunL() } if (error != KErrNone) { - isActive = false; + isOpen = false; iError = QNetworkSession::UnknownSessionError; emit q->error(iError); Cancel(); @@ -802,7 +768,7 @@ void QNetworkSessionPrivate::RunL() iMobility = CActiveCommsMobilityApiExt::NewL(iConnection, *this); } #endif - isActive = true; + isOpen = true; activeConfig = newActiveConfig; activeInterface = interface(activeConfig.d.data()->numericId); if (publicConfig.type() == QNetworkConfiguration::UserChoice) { @@ -818,7 +784,7 @@ void QNetworkSessionPrivate::RunL() } break; case KErrNotFound: // Connection failed - isActive = false; + isOpen = false; activeConfig = QNetworkConfiguration(); serviceConfig = QNetworkConfiguration(); iError = QNetworkSession::InvalidConfigurationError; @@ -832,7 +798,7 @@ void QNetworkSessionPrivate::RunL() case KErrCancel: // Connection attempt cancelled case KErrAlreadyExists: // Connection already exists default: - isActive = false; + isOpen = false; activeConfig = QNetworkConfiguration(); serviceConfig = QNetworkConfiguration(); iError = QNetworkSession::UnknownSessionError; @@ -855,7 +821,7 @@ bool QNetworkSessionPrivate::newState(QNetworkSession::State newState, TUint acc { // Make sure that activeConfig is always updated when SNAP is signaled to be // connected. - if (isActive && publicConfig.type() == QNetworkConfiguration::ServiceNetwork && + if (isOpen && publicConfig.type() == QNetworkConfiguration::ServiceNetwork && newState == QNetworkSession::Connected) { activeConfig = activeConfiguration(accessPointId); activeInterface = interface(activeConfig.d.data()->numericId); @@ -872,12 +838,12 @@ bool QNetworkSessionPrivate::newState(QNetworkSession::State newState, TUint acc } bool emitSessionClosed = false; - if (isActive && state == QNetworkSession::Connected && newState == QNetworkSession::Disconnected) { + if (isOpen && state == QNetworkSession::Connected && newState == QNetworkSession::Disconnected) { // Active & Connected state should change directly to Disconnected state // only when something forces connection to close (eg. when another // application or session stops connection or when network drops // unexpectedly). - isActive = false; + isOpen = false; activeConfig = QNetworkConfiguration(); serviceConfig = QNetworkConfiguration(); iError = QNetworkSession::SessionAbortedError; @@ -903,7 +869,7 @@ bool QNetworkSessionPrivate::newState(QNetworkSession::State newState, TUint acc emit q->stateChanged(state); retVal = true; } - } else if (publicConfig.type() == QNetworkConfiguration::UserChoice && isActive) { + } else if (publicConfig.type() == QNetworkConfiguration::UserChoice && isOpen) { if (activeConfig.d.data()->numericId == accessPointId) { state = newState; emit q->stateChanged(state); diff --git a/src/network/bearer/qnetworksession_s60_p.h b/src/network/bearer/qnetworksession_s60_p.h index cfb99c9..ed322dd 100644 --- a/src/network/bearer/qnetworksession_s60_p.h +++ b/src/network/bearer/qnetworksession_s60_p.h @@ -92,7 +92,6 @@ public: QNetworkInterface currentInterface() const; QVariant sessionProperty(const QString& key) const; void setSessionProperty(const QString& key, const QVariant& value); - QString bearerName() const; void setALREnabled(bool enabled); @@ -158,7 +157,7 @@ private: // data mutable QNetworkInterface activeInterface; QNetworkSession::State state; - bool isActive; + bool isOpen; QNetworkSession* q; QDateTime startTime; diff --git a/src/network/bearer/qnetworksessionengine_p.h b/src/network/bearer/qnetworksessionengine_p.h index 795a209..3977b15 100644 --- a/src/network/bearer/qnetworksessionengine_p.h +++ b/src/network/bearer/qnetworksessionengine_p.h @@ -81,7 +81,7 @@ public: virtual QString getInterfaceFromId(const QString &id) = 0; virtual bool hasIdentifier(const QString &id) = 0; - virtual QString bearerName(const QString &id) = 0; + //virtual QString bearerName(const QString &id) = 0; virtual void connectToId(const QString &id) = 0; virtual void disconnectFromId(const QString &id) = 0; diff --git a/src/network/bearer/qnlaengine_win.cpp b/src/network/bearer/qnlaengine_win.cpp index b606ef4..a3f6017 100644 --- a/src/network/bearer/qnlaengine_win.cpp +++ b/src/network/bearer/qnlaengine_win.cpp @@ -133,7 +133,7 @@ static QString qGetInterfaceType(const QString &interface) HANDLE handle = CreateFile((TCHAR *)QString("\\\\.\\%1").arg(interface).utf16(), 0, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); if (handle == INVALID_HANDLE_VALUE) - return QString(); + return QLatin1String("Unknown"); oid = OID_GEN_MEDIA_SUPPORTED; bytesWritten = 0; @@ -141,7 +141,7 @@ static QString qGetInterfaceType(const QString &interface) &medium, sizeof(medium), &bytesWritten, 0); if (!result) { CloseHandle(handle); - return QString(); + return QLatin1String("Unknown"); } oid = OID_GEN_PHYSICAL_MEDIUM; @@ -154,7 +154,7 @@ static QString qGetInterfaceType(const QString &interface) if (medium == NdisMedium802_3) return QLatin1String("Ethernet"); else - return QString(); + return QLatin1String("Unknown"); } CloseHandle(handle); @@ -181,7 +181,7 @@ static QString qGetInterfaceType(const QString &interface) #endif - return QString(); + return QLatin1String("Unknown"); } class QNlaThread : public QThread @@ -252,6 +252,9 @@ QList QNlaThread::getConfigurations() config->roamingSupported = fetchedConfigurations.at(i)->roamingSupported; config->purpose = fetchedConfigurations.at(i)->purpose; config->internet = fetchedConfigurations.at(i)->internet; + if (QNlaEngine *engine = qobject_cast(parent())) { + config->bearer = engine->bearerName(config->id); + } foundConfigurations.append(config); } @@ -546,12 +549,17 @@ bool QNlaEngine::hasIdentifier(const QString &id) if (configurationInterface.contains(id.toUInt())) return true; - foreach (QNetworkConfigurationPrivate *cpPriv, nlaThread->getConfigurations()) { - if (cpPriv->id == id) - return true; + bool result = false; + QList l = nlaThread->getConfigurations(); + while (!l.isEmpty()) { + QNetworkConfigurationPrivate* cpPriv = l.takeFirst(); + if (!result && cpPriv->id == id) { + result = true; + } + delete cpPriv; } - - return false; + + return result; } QString QNlaEngine::bearerName(const QString &id) diff --git a/src/network/bearer/qnmwifiengine_unix.cpp b/src/network/bearer/qnmwifiengine_unix.cpp index f558fa8..2444919 100644 --- a/src/network/bearer/qnmwifiengine_unix.cpp +++ b/src/network/bearer/qnmwifiengine_unix.cpp @@ -44,6 +44,7 @@ #include #include +#include #include #include @@ -65,7 +66,7 @@ QTM_BEGIN_NAMESPACE QNmWifiEngine::QNmWifiEngine(QObject *parent) : QNetworkSessionEngine(parent) { - iface = new QNetworkManagerInterface(); + iface = new QNetworkManagerInterface(this); if(!iface->isValid()) { return; } @@ -74,6 +75,8 @@ QNmWifiEngine::QNmWifiEngine(QObject *parent) this,SLOT(addDevice(QDBusObjectPath))); connect(iface,SIGNAL(deviceRemoved(QDBusObjectPath)), this,SLOT(removeDevice(QDBusObjectPath))); + connect(iface, SIGNAL(activationFinished(QDBusPendingCallWatcher*)), + this, SLOT(slotActivationFinished(QDBusPendingCallWatcher*))); QList list = iface->getDevices(); @@ -84,9 +87,9 @@ QNmWifiEngine::QNmWifiEngine(QObject *parent) QStringList connectionServices; connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; + QNetworkManagerSettings *settingsiface; foreach (QString service, connectionServices) { - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(service); + settingsiface = new QNetworkManagerSettings(service, this); settingsiface->setConnections(); connect(settingsiface,SIGNAL(newConnection(QDBusObjectPath)), this,(SLOT(newConnection(QDBusObjectPath)))); @@ -107,6 +110,7 @@ QString QNmWifiEngine::getNameForConfiguration(QNetworkManagerInterfaceDevice *d QNetworkManagerIp4Config * ipIface; ipIface = new QNetworkManagerIp4Config(path); newname = ipIface->domains().join(" "); + delete ipIface; } //fallback to interface name if(newname.isEmpty()) @@ -117,17 +121,16 @@ QString QNmWifiEngine::getNameForConfiguration(QNetworkManagerInterfaceDevice *d QList QNmWifiEngine::getConfigurations(bool *ok) { -// qWarning() << Q_FUNC_INFO << updated; if (ok) *ok = false; if(!updated) { foundConfigurations.clear(); if(knownSsids.isEmpty()) - getKnownSsids(); // list of ssids that have user configurations. + updateKnownSsids(); // list of ssids that have user configurations. scanForAccessPoints(); - getActiveConnectionsPaths(); + updateActiveConnectionsPaths(); knownConnections(); accessPointConnections(); @@ -139,160 +142,8 @@ QList QNmWifiEngine::getConfigurations(bool *ok) return foundConfigurations; } -void QNmWifiEngine::findConnections() -{ - QList list = iface->getDevices(); - - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); - - //// eth - switch (devIface->deviceType()) { -// qWarning() << devIface->connectionInterface()->path(); - - case DEVICE_TYPE_802_3_ETHERNET: - { - QString ident; - QNetworkManagerInterfaceDeviceWired *devWiredIface; - devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); - - ident = devWiredIface->hwAddress(); - - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - cpPriv->name = getNameForConfiguration(devIface); - cpPriv->isValid = true; - cpPriv->id = ident; - cpPriv->internet = devWiredIface->carrier(); - - cpPriv->serviceInterface = devIface->interface(); - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - switch (devIface->state()) { - case NM_DEVICE_STATE_UNKNOWN: - case NM_DEVICE_STATE_UNMANAGED: - case NM_DEVICE_STATE_FAILED: - cpPriv->state = (cpPriv->state | QNetworkConfiguration::Undefined); - break; - case NM_DEVICE_STATE_UNAVAILABLE: - cpPriv->state = (cpPriv->state | QNetworkConfiguration::Defined); - break; - case NM_DEVICE_STATE_PREPARE: - case NM_DEVICE_STATE_CONFIG: - case NM_DEVICE_STATE_NEED_AUTH: - case NM_DEVICE_STATE_IP_CONFIG: - case NM_DEVICE_STATE_DISCONNECTED: - { - cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Discovered - | QNetworkConfiguration::Defined); - } - break; - case NM_DEVICE_STATE_ACTIVATED: - cpPriv->state = (cpPriv->state | QNetworkConfiguration::Active ); - break; - default: - cpPriv->state = (cpPriv->state | QNetworkConfiguration::Undefined); - break; - }; - cpPriv->purpose = QNetworkConfiguration::PublicPurpose; - foundConfigurations.append(cpPriv); - configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); - } - break; - case DEVICE_TYPE_802_11_WIRELESS: - { -// QNetworkManagerInterfaceDeviceWireless *devWirelessIface; -// devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); -// -// //// connections -// QStringList connectionServices; -// connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; -// connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; -// -// QString connPath; -// -// foreach (QString service, connectionServices) { -// QString ident; -// QNetworkManagerSettings *settingsiface; -// settingsiface = new QNetworkManagerSettings(service); -// QList list = settingsiface->listConnections(); -// -// foreach(QDBusObjectPath path, list) { //for each connection path -//qWarning() << path.path(); -// ident = path.path(); -// bool addIt = false; -// QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); -// cpPriv->isValid = true; -// cpPriv->id = ident; -// cpPriv->internet = true; -// -// cpPriv->type = QNetworkConfiguration::InternetAccessPoint; -// cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Discovered -// | QNetworkConfiguration::Defined); -// cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; -// -// QNetworkManagerSettingsConnection *sysIface; -// sysIface = new QNetworkManagerSettingsConnection(service, path.path()); -// cpPriv->name = sysIface->getId();//ii.value().toString(); -//qWarning() << cpPriv->name; -// if(sysIface->getType() == DEVICE_TYPE_802_3_ETHERNET/*type == "802-3-ethernet"*/ -// && devIface->deviceType() == DEVICE_TYPE_802_3_ETHERNET) { -// cpPriv->serviceInterface = devIface->interface(); -// addIt = true; -// } else if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS/*type == "802-11-wireless"*/ -// && devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { -// cpPriv->serviceInterface = devIface->interface(); -// addIt = true; -// // get the wifi interface state first.. do we need this? -// // QString activeAPPath = devWirelessIface->activeAccessPoint().path(); -// } -// -// //#if 0 -// foreach(QString conpath, activeConnectionPaths) { -// QNetworkManagerConnectionActive *aConn; -// aConn = new QNetworkManagerConnectionActive(conpath); -// // in case of accesspoint, specificObject will hold the accessPOintObjectPath -// // qWarning() << aConn->connection().path() << aConn->specificObject().path() << aConn->devices().count(); -// if( aConn->connection().path() == ident) { -// -// QList devs = aConn->devices(); -// foreach(QDBusObjectPath device, devs) { -// QNetworkManagerInterfaceDevice *ifaceDevice; -// ifaceDevice = new QNetworkManagerInterfaceDevice(device.path()); -// cpPriv->serviceInterface = ifaceDevice->interface(); -// cpPriv->state = getStateFlag(ifaceDevice->state()); -// //cpPriv->accessPoint = aConn->specificObject().path(); -// -// break; -// } -// } -// } -// //#endif -// // } //end while connection -// if(addIt) { -// foundConfigurations.append(cpPriv); -// configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); -// } -// } -// } //end each connection service -// -// // ////////////// AccessPoints -//// QList apList = devWirelessIface->getAccessPoints(); -////// qWarning() << apList.count(); -//// foreach(QDBusObjectPath path, apList) { -//// QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); -//// cpPriv = addAccessPoint( devIface->connectionInterface()->path(), path); -//// if(cpPriv->isValid) { -//// foundConfigurations.append(cpPriv); -//// } -//// } - } // end DEVICE_TYPE_802_11_WIRELESS - break; - }; - } //end foreach device -} - void QNmWifiEngine::knownConnections() { -// qWarning() << Q_FUNC_INFO; //// connections QStringList connectionServices; connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; @@ -300,21 +151,18 @@ void QNmWifiEngine::knownConnections() QString connPath; + QScopedPointer settingsiface; foreach (QString service, connectionServices) { QString ident; - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(service); + settingsiface.reset(new QNetworkManagerSettings(service)); QList list = settingsiface->listConnections(); -// qWarning() <setConnections(); connect(sysIface, SIGNAL(removed(QString)), this,SLOT(settingsConnectionRemoved(QString))); @@ -322,27 +170,23 @@ void QNmWifiEngine::knownConnections() cpPriv->name = sysIface->getId(); cpPriv->isValid = true; cpPriv->id = sysIface->getUuid(); -// cpPriv->id = ident; cpPriv->internet = true; cpPriv->type = QNetworkConfiguration::InternetAccessPoint; -//qWarning() << cpPriv->name; cpPriv->state = getStateForId(cpPriv->id); cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; + if(sysIface->getType() == DEVICE_TYPE_802_3_ETHERNET) { QString mac = sysIface->getMacAddress(); if(!mac.length() > 2) { - qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXX" << mac << "type ethernet"; QString devPath; devPath = deviceConnectionPath(mac); - // qWarning() << Q_FUNC_INFO << devPath; - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(devPath); - cpPriv->serviceInterface = devIface->interface(); - QNetworkManagerInterfaceDeviceWired *devWiredIface; - devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); + QNetworkManagerInterfaceDevice devIface(devPath); + cpPriv->serviceInterface = devIface.interface(); + QScopedPointer devWiredIface; + devWiredIface.reset(new QNetworkManagerInterfaceDeviceWired(devIface.connectionInterface()->path())); cpPriv->internet = devWiredIface->carrier(); // use this mac addy @@ -356,19 +200,15 @@ void QNmWifiEngine::knownConnections() } else if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS) { QString mac = sysIface->getMacAddress();; if(!mac.length() > 2) { - qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXX" << mac << "type wireless"; QString devPath; devPath = deviceConnectionPath(mac); -// qWarning() << Q_FUNC_INFO << devPath; - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(devPath); - cpPriv->serviceInterface = devIface->interface(); + QNetworkManagerInterfaceDevice devIface(devPath); + cpPriv->serviceInterface = devIface.interface(); // use this mac addy } else { cpPriv->serviceInterface = getBestInterface( DEVICE_TYPE_802_11_WIRELESS, cpPriv->id); } - // cpPriv->serviceInterface = devIface->interface(); addIt = true; // get the wifi interface state first.. do we need this? // QString activeAPPath = devWirelessIface->activeAccessPoint().path(); @@ -376,6 +216,7 @@ void QNmWifiEngine::knownConnections() if(addIt) { foundConfigurations.append(cpPriv); configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); + cpPriv->bearer = bearerName(cpPriv->id); } } //end each connection service } @@ -383,22 +224,21 @@ void QNmWifiEngine::knownConnections() void QNmWifiEngine::accessPointConnections() { - //qWarning() << Q_FUNC_INFO; QList list = iface->getDevices(); + QScopedPointer devIface; foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(path.path()); + devIface.reset(new QNetworkManagerInterfaceDevice(path.path())); if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { QList apList = availableAccessPoints.uniqueKeys(); QList::const_iterator i; for (i = apList.constBegin(); i != apList.constEnd(); ++i) { - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + QNetworkConfigurationPrivate* cpPriv; cpPriv = addAccessPoint( devIface->connectionInterface()->path(), availableAccessPoints[*i]); if(cpPriv->isValid) { foundConfigurations.append(cpPriv); - // qWarning() << "adding" << cpPriv->name << "to things"; configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); + cpPriv->bearer = bearerName(cpPriv->id); } } } @@ -414,46 +254,43 @@ bool QNmWifiEngine::hasIdentifier(const QString &id) { if (configurationInterface.contains(id)) return true; - foreach (QNetworkConfigurationPrivate *cpPriv, getConfigurations()) { - if (cpPriv->id == id) - return true; - } + return false; } QString QNmWifiEngine::bearerName(const QString &id) { QString interface = getInterfaceFromId(id); - + QScopedPointer devIface; QList list = iface->getDevices(); foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(path.path()); + devIface.reset(new QNetworkManagerInterfaceDevice(path.path())); + if(interface == devIface->interface().name()) { + switch(devIface->deviceType()) { - case DEVICE_TYPE_802_3_ETHERNET/*NM_DEVICE_TYPE_ETHERNET*/: - return QLatin1String("Ethernet"); - break; - case DEVICE_TYPE_802_11_WIRELESS/*NM_DEVICE_TYPE_WIFI*/: - return QLatin1String("WLAN"); - break; - case DEVICE_TYPE_GSM/*NM_DEVICE_TYPE_GSM*/: - return QLatin1String("2G"); - break; - case DEVICE_TYPE_CDMA/*NM_DEVICE_TYPE_CDMA*/: - return QLatin1String("CDMA2000"); - break; - default: - break; - }; + case DEVICE_TYPE_802_3_ETHERNET/*NM_DEVICE_TYPE_ETHERNET*/: + return QLatin1String("Ethernet"); + break; + case DEVICE_TYPE_802_11_WIRELESS/*NM_DEVICE_TYPE_WIFI*/: + return QLatin1String("WLAN"); + break; + case DEVICE_TYPE_GSM/*NM_DEVICE_TYPE_GSM*/: + return QLatin1String("2G"); + break; + case DEVICE_TYPE_CDMA/*NM_DEVICE_TYPE_CDMA*/: + return QLatin1String("CDMA2000"); + break; + default: + break; + } } } - return QString(); + return QLatin1String("Unknown"); } void QNmWifiEngine::connectToId(const QString &id) { -// qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << __FUNCTION__ << id; activatingConnectionPath = id; QStringList connectionSettings = getConnectionPathForId(id); if(connectionSettings.isEmpty()) { @@ -469,34 +306,26 @@ void QNmWifiEngine::connectToId(const QString &id) devPath = deviceConnectionPath(interface); QDBusObjectPath devicePath(devPath); - iface = new QNetworkManagerInterface(); iface->activateConnection( connectionSettings.at(0), connectionPath, devicePath, connectionPath); - - connect(iface, SIGNAL(activationFinished(QDBusPendingCallWatcher*)), - this, SLOT(slotActivationFinished(QDBusPendingCallWatcher*))); } void QNmWifiEngine::disconnectFromId(const QString &id) { QString activeConnectionPath = getActiveConnectionPath(id); - //qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << __FUNCTION__ << id << activeConnectionPath ; if (!activeConnectionPath.isEmpty()) { - QNetworkManagerConnectionActive *activeCon; - activeCon = new QNetworkManagerConnectionActive(activeConnectionPath); - QNetworkManagerSettingsConnection *settingsCon; - settingsCon = new QNetworkManagerSettingsConnection(activeCon->serviceName(), activeCon->connection().path()); + QScopedPointer activeCon; + activeCon.reset(new QNetworkManagerConnectionActive(activeConnectionPath)); + QScopedPointer settingsCon; + settingsCon.reset(new QNetworkManagerSettingsConnection(activeCon->serviceName(), activeCon->connection().path())); - if(settingsCon->isAutoConnect()) { -// qWarning() << id << "is autoconnect"; + if(settingsCon->getType() == DEVICE_TYPE_802_3_ETHERNET /*NM_DEVICE_TYPE_ETHERNET*/) { //use depreciated value for now emit connectionError(id, OperationNotSupported); - //unsupported } else { -// qWarning() <deactivateConnection(dbpath); activatingConnectionPath = ""; @@ -525,58 +354,43 @@ QNmWifiEngine *QNmWifiEngine::instance() return 0; } -void QNmWifiEngine::getKnownSsids() +void QNmWifiEngine::updateKnownSsids() { QStringList connectionServices; connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; -//qWarning() << Q_FUNC_INFO; + + QScopedPointer settingsiface; foreach (QString service, connectionServices) { - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(service); + settingsiface.reset(new QNetworkManagerSettings(service)); QList list = settingsiface->listConnections(); foreach(QDBusObjectPath path, list) { - QNetworkManagerSettingsConnection *sysIface; - sysIface = new QNetworkManagerSettingsConnection(service, path.path()); -// qWarning() << sysIface->getSsid(); - knownSsids << sysIface->getSsid(); + QNetworkManagerSettingsConnection sysIface(service, path.path()); + knownSsids << sysIface.getSsid(); } } } -void QNmWifiEngine::getActiveConnectionsPaths() -{ -// qWarning() << Q_FUNC_INFO; - QNetworkManagerInterface *dbIface; +void QNmWifiEngine::updateActiveConnectionsPaths() +{ //need to know which connection paths are currently active/connected + QScopedPointer dbIface; activeConnectionPaths.clear(); - dbIface = new QNetworkManagerInterface; + dbIface.reset(new QNetworkManagerInterface); QList connections = dbIface->activeConnections(); - foreach(QDBusObjectPath conpath, connections) { - activeConnectionPaths << conpath.path(); -// qWarning() << __FUNCTION__ << conpath.path() << activeConnectionPaths.count(); - - QNetworkManagerConnectionActive *activeConn; - activeConn = new QNetworkManagerConnectionActive(conpath.path()); - -// qWarning() << activeConn->connection().path() /*<< activeConn->specificObject().path() */<< activeConn->devices()[0].path(); - - } + activeConnectionPaths << conpath.path(); + } } QNetworkConfigurationPrivate * QNmWifiEngine::addAccessPoint( const QString &iPath, QDBusObjectPath path) -{ //foreach accessPoint - //qWarning() << Q_FUNC_INFO << iPath << path.path(); +{ - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(iPath); - QNetworkManagerInterfaceDeviceWireless *devWirelessIface; - devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(iPath); + QScopedPointer devIface(new QNetworkManagerInterfaceDevice(iPath)); + QScopedPointer devWirelessIface(new QNetworkManagerInterfaceDeviceWireless(iPath)); QString activeAPPath = devWirelessIface->activeAccessPoint().path(); - QNetworkManagerInterfaceAccessPoint *accessPointIface; - accessPointIface = new QNetworkManagerInterfaceAccessPoint(path.path()); + QScopedPointer accessPointIface(new QNetworkManagerInterfaceAccessPoint(path.path())); QString ident = accessPointIface->connectionInterface()->path(); quint32 nmState = devIface->state(); @@ -587,7 +401,6 @@ QNetworkConfigurationPrivate * QNmWifiEngine::addAccessPoint( const QString &iPa QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); bool addIt = true; - //qWarning() << availableAccessPoints.count() << ssid; // if(availableAccessPoints.contains(ssid)) { // addIt = false; @@ -609,8 +422,6 @@ QNetworkConfigurationPrivate * QNmWifiEngine::addAccessPoint( const QString &iPa cpPriv->type = QNetworkConfiguration::InternetAccessPoint; cpPriv->serviceInterface = devIface->interface(); - //qWarning() <<__FUNCTION__ << ssid; - cpPriv->state = getAPState(nmState, knownSsids.contains(cpPriv->name)); if(activeAPPath == accessPointIface->connectionInterface()->path()) { @@ -631,7 +442,6 @@ QNetworkConfigurationPrivate * QNmWifiEngine::addAccessPoint( const QString &iPa QNetworkConfiguration::StateFlags QNmWifiEngine::getAPState(qint32 nmState, bool isKnown) { QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined; -//qWarning() << nmState << knownSsids; // this is the state of the wifi device interface if(isKnown) state = ( QNetworkConfiguration::Defined); @@ -667,15 +477,12 @@ QNetworkConfigurationPrivate * QNmWifiEngine::addAccessPoint( const QString &iPa QString QNmWifiEngine::getActiveConnectionPath(const QString &id) { - //qWarning() << Q_FUNC_INFO << id; - QStringList connectionSettings = getConnectionPathForId(id); - //qWarning() << Q_FUNC_INFO << id << connectionSettings.count(); - QNetworkManagerInterface * ifaceD; - ifaceD = new QNetworkManagerInterface(); - QList connections = ifaceD->activeConnections(); + QStringList connectionSettings = getConnectionPathForId(id); + QNetworkManagerInterface ifaceD; + QList connections = ifaceD.activeConnections(); + QScopedPointer conDetailsD; foreach(QDBusObjectPath path, connections) { - QNetworkManagerConnectionActive *conDetailsD; - conDetailsD = new QNetworkManagerConnectionActive( path.path()); + conDetailsD.reset(new QNetworkManagerConnectionActive( path.path())); if(conDetailsD->connection().path() == connectionSettings.at(1) && conDetailsD->serviceName() == connectionSettings.at(0)) return path.path(); @@ -685,7 +492,6 @@ QString QNmWifiEngine::getActiveConnectionPath(const QString &id) QNetworkConfiguration::StateFlags QNmWifiEngine::getStateFlag(quint32 nmstate) { -// qWarning() << Q_FUNC_INFO << nmstate; QNetworkConfiguration::StateFlags flag; switch (nmstate) { case NM_DEVICE_STATE_UNKNOWN: @@ -718,8 +524,6 @@ QString QNmWifiEngine::getActiveConnectionPath(const QString &id) void QNmWifiEngine::updateDeviceInterfaceState(const QString &/*path*/, quint32 nmState) { -// qWarning() << Q_FUNC_INFO << path << nmState; - if(nmState == NM_DEVICE_STATE_ACTIVATED || nmState == NM_DEVICE_STATE_DISCONNECTED || nmState == NM_DEVICE_STATE_UNAVAILABLE @@ -730,7 +534,6 @@ void QNmWifiEngine::updateDeviceInterfaceState(const QString &/*path*/, quint32 OperationNotSupported, DisconnectionError, */ -// qWarning() << Q_FUNC_INFO << ident; QNetworkConfiguration::StateFlags state = (QNetworkConfiguration::Defined); switch (nmState) { case NM_DEVICE_STATE_UNKNOWN: @@ -738,7 +541,6 @@ void QNmWifiEngine::updateDeviceInterfaceState(const QString &/*path*/, quint32 state = (QNetworkConfiguration::Undefined); emit connectionError(activatingConnectionPath, ConnectError); requestUpdate(); -// qWarning() << Q_FUNC_INFO; break; case NM_DEVICE_STATE_UNAVAILABLE: state = (QNetworkConfiguration::Defined); @@ -765,8 +567,7 @@ void QNmWifiEngine::updateDeviceInterfaceState(const QString &/*path*/, quint32 void QNmWifiEngine::addDevice(QDBusObjectPath path) { - //qWarning() << Q_FUNC_INFO << path.path(); - QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); + QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path(), this); devIface->setConnections(); connect(devIface,SIGNAL(stateChanged(const QString &, quint32)), this, SLOT(updateDeviceInterfaceState(const QString&, quint32))); @@ -778,7 +579,7 @@ void QNmWifiEngine::addDevice(QDBusObjectPath path) case DEVICE_TYPE_802_3_ETHERNET: { QNetworkManagerInterfaceDeviceWired * devWiredIface; - devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); + devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path(), this); devWiredIface->setConnections(); connect(devWiredIface, SIGNAL(propertiesChanged(const QString &,QMap)), this,SLOT(cmpPropertiesChanged( const QString &, QMap))); @@ -788,7 +589,7 @@ void QNmWifiEngine::addDevice(QDBusObjectPath path) case DEVICE_TYPE_802_11_WIRELESS: { QNetworkManagerInterfaceDeviceWireless *devWirelessIface; - devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); + devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path(), this); devWirelessIface->setConnections(); connect(devWirelessIface, SIGNAL(propertiesChanged(const QString &,QMap)), @@ -834,7 +635,6 @@ void QNmWifiEngine::cmpPropertiesChanged(const QString &path, QMap i(map); while (i.hasNext()) { i.next(); -// qWarning() << Q_FUNC_INFO << path << i.key() << i.value().toUInt(); if( i.key() == "State") { //only applies to device interfaces updateDeviceInterfaceState(path, i.value().toUInt()); } @@ -848,8 +648,6 @@ void QNmWifiEngine::cmpPropertiesChanged(const QString &path, QMap devs = aConn->devices(); + QList devs = aConn.devices(); + QScopedPointer ifaceDevice; + QScopedPointer devWiredIface; foreach(QDBusObjectPath dev, devs) { - //qWarning() << "foreach" << dev.path(); - QNetworkManagerInterfaceDevice *ifaceDevice; - ifaceDevice = new QNetworkManagerInterfaceDevice(dev.path()); + ifaceDevice.reset(new QNetworkManagerInterfaceDevice(dev.path())); if(ifaceDevice->deviceType() == DEVICE_TYPE_802_3_ETHERNET) { @@ -898,8 +690,7 @@ QNetworkConfiguration::StateFlags QNmWifiEngine::getStateForId(const QString &id ifaceDevice->state() == NM_DEVICE_STATE_DISCONNECTED) { isAvailable = true; - QNetworkManagerInterfaceDeviceWired *devWiredIface; - devWiredIface = new QNetworkManagerInterfaceDeviceWired(ifaceDevice->connectionInterface()->path()); + devWiredIface.reset(new QNetworkManagerInterfaceDeviceWired(ifaceDevice->connectionInterface()->path())); if(!devWiredIface->carrier()) return QNetworkConfiguration::Defined; } //end eth @@ -911,9 +702,8 @@ QNetworkConfiguration::StateFlags QNmWifiEngine::getStateForId(const QString &id } } else { // not active - //qWarning() << Q_FUNC_INFO << "Not active"; - QNetworkManagerSettingsConnection *sysIface; - sysIface = new QNetworkManagerSettingsConnection(conPath.at(0),conPath.at(1)); + QScopedPointer sysIface; + sysIface.reset(new QNetworkManagerSettingsConnection(conPath.at(0),conPath.at(1))); if(sysIface->isValid()) { if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS) { QString ssid = sysIface->getSsid(); @@ -921,21 +711,16 @@ QNetworkConfiguration::StateFlags QNmWifiEngine::getStateForId(const QString &id if(knownSsids.contains(ssid, Qt::CaseSensitive)) { foreach(QString onessid, knownSsids) { - // qWarning() << ssid << onessid; if(onessid == ssid && availableAccessPoints.contains(ssid)) { - // qWarning() < devices = aConn->devices(); - foreach(QDBusObjectPath device, devices) { - QNetworkManagerInterfaceDevice *ifaceDevice; - ifaceDevice = new QNetworkManagerInterfaceDevice(device.path()); - if(ifaceDevice->ip4Address() == ipaddress) { - return true; - } + + QScopedPointer aConn; + aConn.reset(new QNetworkManagerConnectionActive(aConPath)); + QScopedPointer ifaceDevice; + QList devices = aConn->devices(); + foreach(QDBusObjectPath device, devices) { + ifaceDevice.reset(new QNetworkManagerInterfaceDevice(device.path())); + if(ifaceDevice->ip4Address() == ipaddress) { + return true; } - return false; + } + return false; } QNetworkInterface QNmWifiEngine::getBestInterface( quint32 type, const QString &id) { // check active connections first. - QStringList conIdPath = getConnectionPathForId(id); -// qWarning() << Q_FUNC_INFO << id << conIdPath; + QStringList conIdPath = getConnectionPathForId(id); QNetworkInterface interface; - foreach(QString conpath, activeConnectionPaths) { - QNetworkManagerConnectionActive *aConn; - aConn = new QNetworkManagerConnectionActive(conpath); + QScopedPointer aConn; + foreach(QString conpath, activeConnectionPaths) { + aConn.reset(new QNetworkManagerConnectionActive(conpath)); if(aConn->connection().path() == conIdPath.at(1) && aConn->serviceName() == conIdPath.at(0)) { QList devs = aConn->devices(); - QNetworkManagerInterfaceDevice *ifaceDevice; - ifaceDevice = new QNetworkManagerInterfaceDevice(devs[0].path()); //just take the first one - interface = ifaceDevice->interface(); - return interface; + QNetworkManagerInterfaceDevice ifaceDevice(devs[0].path()); //just take the first one + return ifaceDevice.interface(); } } -//try guessing + //try guessing QList list = iface->getDevices(); + QScopedPointer devIface; foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); + devIface.reset(new QNetworkManagerInterfaceDevice(path.path())); if(devIface->deviceType() == type /*&& devIface->managed()*/) { - interface = devIface->interface(); if(devIface->state() == NM_STATE_DISCONNECTED) { - return interface; + return devIface->interface(); } } } - return interface; + return QNetworkInterface(); } quint64 QNmWifiEngine::receivedDataForId(const QString &id) const @@ -1037,13 +819,11 @@ quint64 QNmWifiEngine::sentDataForId(const QString &id) const void QNmWifiEngine::newConnection(QDBusObjectPath /*path*/) { - //qWarning() << Q_FUNC_INFO; requestUpdate(); } void QNmWifiEngine::settingsConnectionRemoved(const QString &/*path*/) { - //qWarning() << Q_FUNC_INFO; requestUpdate(); } @@ -1054,10 +834,9 @@ void QNmWifiEngine::slotActivationFinished(QDBusPendingCallWatcher *openCall) qWarning() <<"Error" << reply.error().name() << reply.error().message() < list = iface->getDevices(); + QScopedPointer devIface; + QScopedPointer devWirelessIface; + QScopedPointer accessPointIface; foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(path.path()); + devIface.reset(new QNetworkManagerInterfaceDevice(path.path())); if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { -// qWarning() << devIface->connectionInterface()->path(); - - QNetworkManagerInterfaceDeviceWireless *devWirelessIface; - devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); + devWirelessIface.reset(new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path())); ////////////// AccessPoints QList apList = devWirelessIface->getAccessPoints(); foreach(QDBusObjectPath path, apList) { - QNetworkManagerInterfaceAccessPoint *accessPointIface; - accessPointIface = new QNetworkManagerInterfaceAccessPoint(path.path()); + accessPointIface.reset(new QNetworkManagerInterfaceAccessPoint(path.path())); QString ssid = accessPointIface->ssid(); availableAccessPoints.insert(ssid, path); } @@ -1109,19 +886,15 @@ QStringList QNmWifiEngine::getConnectionPathForId(const QString &uuid) QStringList connectionServices; connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; -//qWarning() << Q_FUNC_INFO; + QScopedPointer settingsiface; foreach (QString service, connectionServices) { - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(service); + settingsiface.reset(new QNetworkManagerSettings(service)); QList list = settingsiface->listConnections(); + QScopedPointer sysIface; foreach(QDBusObjectPath path, list) { - QNetworkManagerSettingsConnection *sysIface; - sysIface = new QNetworkManagerSettingsConnection(service, path.path()); -// qWarning() << uuid << sysIface->getUuid(); - if(sysIface->getUuid() == uuid) { -// qWarning() <<__FUNCTION__ << service << sysIface->getId() << sysIface->connectionInterface()->path(); + sysIface.reset(new QNetworkManagerSettingsConnection(service, path.path())); + if(sysIface->getUuid() == uuid) return QStringList() << service << sysIface->connectionInterface()->path(); - } } } return QStringList(); diff --git a/src/network/bearer/qnmwifiengine_unix_p.h b/src/network/bearer/qnmwifiengine_unix_p.h index 1287800..470c8d3 100644 --- a/src/network/bearer/qnmwifiengine_unix_p.h +++ b/src/network/bearer/qnmwifiengine_unix_p.h @@ -112,11 +112,10 @@ private: QStringList devicePaths; - void getActiveConnectionsPaths(); - void getKnownSsids(); + void updateActiveConnectionsPaths(); + void updateKnownSsids(); void accessPointConnections(); void knownConnections(); - void findConnections(); QString deviceConnectionPath(const QString &mac); QList foundConfigurations; @@ -145,8 +144,6 @@ private slots: Q_SIGNALS: void configurationChanged(const QNetworkConfiguration& config); - void updateAccessPointState(const QString &, quint32); -// void slotActivationFinished(QDBusPendingCallWatcher*); private slots: void accessPointAdded( const QString &aPath, QDBusObjectPath oPath); diff --git a/tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro b/tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro index 0b2ed1a..bdd4926 100644 --- a/tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro +++ b/tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro @@ -8,7 +8,8 @@ QT = core network INCLUDEPATH += ../../../src/bearer include(../../../common.pri) -qtAddLibrary(QtBearer) +CONFIG += mobility +MOBILITY = bearer symbian { TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData diff --git a/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp b/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp index 796677d..6ab0e6f 100644 --- a/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp +++ b/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp @@ -44,7 +44,7 @@ #include "qnetworkconfiguration.h" #include "qnetworkconfigmanager.h" -#ifdef MAEMO +#ifdef Q_WS_MAEMO_6 #include #include #endif @@ -66,7 +66,7 @@ private slots: void configurationFromIdentifier(); private: -#ifdef MAEMO +#ifdef Q_WS_MAEMO_6 Maemo::IAPConf *iapconf; Maemo::IAPConf *iapconf2; Maemo::IAPConf *gprsiap; @@ -78,7 +78,7 @@ private: void tst_QNetworkConfigurationManager::initTestCase() { -#ifdef MAEMO +#ifdef Q_WS_MAEMO_6 iapconf = new Maemo::IAPConf("007"); iapconf->setValue("ipv4_type", "AUTO"); iapconf->setValue("wlan_wepkey1", "connt"); @@ -152,7 +152,7 @@ void tst_QNetworkConfigurationManager::initTestCase() void tst_QNetworkConfigurationManager::cleanupTestCase() { -#ifdef MAEMO +#ifdef Q_WS_MAEMO_6 iapconf->clear(); delete iapconf; iapconf2->clear(); diff --git a/tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro b/tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro index 61e4097..c5a08b3 100644 --- a/tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro +++ b/tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro @@ -8,7 +8,8 @@ QT = core network INCLUDEPATH += ../../../src/bearer include(../../../common.pri) -qtAddLibrary(QtBearer) +CONFIG += mobility +MOBILITY = bearer symbian { TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData diff --git a/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp b/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp index cbb13f3..e929a61 100644 --- a/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp +++ b/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp @@ -44,7 +44,7 @@ #include "qnetworkconfiguration.h" #include "qnetworkconfigmanager.h" -#ifdef MAEMO +#ifdef Q_WS_MAEMO_6 #include #include #endif @@ -65,7 +65,7 @@ private slots: void isRoamingAvailable(); private: -#ifdef MAEMO +#ifdef Q_WS_MAEMO_6 Maemo::IAPConf *iapconf; Maemo::IAPConf *iapconf2; Maemo::IAPConf *gprsiap; @@ -77,7 +77,7 @@ private: void tst_QNetworkConfiguration::initTestCase() { -#ifdef MAEMO +#ifdef Q_WS_MAEMO_6 iapconf = new Maemo::IAPConf("007"); iapconf->setValue("ipv4_type", "AUTO"); iapconf->setValue("wlan_wepkey1", "connt"); @@ -150,7 +150,7 @@ void tst_QNetworkConfiguration::initTestCase() void tst_QNetworkConfiguration::cleanupTestCase() { -#ifdef MAEMO +#ifdef Q_WS_MAEMO_6 iapconf->clear(); delete iapconf; iapconf2->clear(); diff --git a/tests/auto/qnetworksession/lackey/lackey.pro b/tests/auto/qnetworksession/lackey/lackey.pro index 4cb8555..b8a006b 100644 --- a/tests/auto/qnetworksession/lackey/lackey.pro +++ b/tests/auto/qnetworksession/lackey/lackey.pro @@ -9,4 +9,5 @@ CONFIG+= testcase include(../../../../common.pri) -qtAddLibrary(QtBearer) +CONFIG += mobility +MOBILITY = bearer diff --git a/tests/auto/qnetworksession/lackey/main.cpp b/tests/auto/qnetworksession/lackey/main.cpp index 53f6f4f..f3a7a07 100644 --- a/tests/auto/qnetworksession/lackey/main.cpp +++ b/tests/auto/qnetworksession/lackey/main.cpp @@ -107,7 +107,7 @@ int main(int argc, char** argv) session->open(); session->waitForOpened(); - } while (!(session && session->isActive())); + } while (!(session && session->isOpen())); qDebug() << "loop done"; diff --git a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp index cbd4c8f..86b3e46 100644 --- a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp +++ b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp @@ -46,7 +46,7 @@ #include #include -#ifdef MAEMO +#ifdef Q_WS_MAEMO_6 #include #include #endif @@ -84,7 +84,7 @@ private: uint inProcessSessionManagementCount; -#ifdef MAEMO +#ifdef Q_WS_MAEMO_6 Maemo::IAPConf *iapconf; Maemo::IAPConf *iapconf2; Maemo::IAPConf *gprsiap; @@ -100,7 +100,7 @@ void tst_QNetworkSession::initTestCase() qRegisterMetaType("QNetworkSession::SessionError"); qRegisterMetaType("QNetworkConfiguration"); -#ifdef MAEMO +#ifdef Q_WS_MAEMO_6 iapconf = new Maemo::IAPConf("007"); iapconf->setValue("ipv4_type", "AUTO"); iapconf->setValue("wlan_wepkey1", "connt"); @@ -186,7 +186,7 @@ void tst_QNetworkSession::cleanupTestCase() "tests in inProcessSessionManagement()"); } -#ifdef MAEMO +#ifdef Q_WS_MAEMO_6 iapconf->clear(); delete iapconf; iapconf2->clear(); @@ -212,7 +212,7 @@ void tst_QNetworkSession::cleanupTestCase() void tst_QNetworkSession::invalidSession() { QNetworkSession session(QNetworkConfiguration(), 0); - QVERIFY(!session.isActive()); + QVERIFY(!session.isOpen()); QVERIFY(session.state() == QNetworkSession::Invalid); } @@ -236,7 +236,7 @@ void tst_QNetworkSession::sessionProperties() QVERIFY(session.configuration() == configuration); - QStringList validBearerNames = QStringList() << QString() + QStringList validBearerNames = QStringList() << QLatin1String("Unknown") << QLatin1String("Ethernet") << QLatin1String("WLAN") << QLatin1String("2G") @@ -246,10 +246,21 @@ void tst_QNetworkSession::sessionProperties() << QLatin1String("Bluetooth") << QLatin1String("WiMAX"); - if (!configuration.isValid()) - QVERIFY(session.bearerName().isEmpty()); - else - QVERIFY(validBearerNames.contains(session.bearerName())); + if (!configuration.isValid()) { + QVERIFY(configuration.bearerName().isEmpty()); + } else { + switch (configuration.type()) + { + case QNetworkConfiguration::ServiceNetwork: + case QNetworkConfiguration::UserChoice: + default: + QVERIFY(configuration.bearerName().isEmpty()); + break; + case QNetworkConfiguration::InternetAccessPoint: + QVERIFY(validBearerNames.contains(configuration.bearerName())); + break; + } + } // QNetworkSession::interface() should return an invalid interface unless // session is in the connected state. @@ -302,9 +313,9 @@ void tst_QNetworkSession::userChoiceSession() QVERIFY(session.configuration() == configuration); - QVERIFY(!session.isActive()); + QVERIFY(!session.isOpen()); - QVERIFY(session.sessionProperty("ActiveConfigurationIdentifier").toString().isEmpty()); + QVERIFY(session.sessionProperty("ActiveConfiguration").toString().isEmpty()); // The remaining tests require the session to be not NotAvailable. @@ -324,7 +335,7 @@ void tst_QNetworkSession::userChoiceSession() session.waitForOpened(); - if (session.isActive()) + if (session.isOpen()) QVERIFY(!sessionOpenedSpy.isEmpty() || !errorSpy.isEmpty()); if (!errorSpy.isEmpty()) { QNetworkSession::SessionError error = @@ -359,7 +370,7 @@ void tst_QNetworkSession::userChoiceSession() QVERIFY(session.interface().isValid()); const QString userChoiceIdentifier = - session.sessionProperty("UserChoiceConfigurationIdentifier").toString(); + session.sessionProperty("UserChoiceConfiguration").toString(); QVERIFY(!userChoiceIdentifier.isEmpty()); QVERIFY(userChoiceIdentifier != configuration.identifier()); @@ -371,12 +382,12 @@ void tst_QNetworkSession::userChoiceSession() QVERIFY(userChoiceConfiguration.type() != QNetworkConfiguration::UserChoice); const QString testIdentifier("abc"); - //resetting UserChoiceConfigurationIdentifier is ignored (read only property) - session.setSessionProperty("UserChoiceConfigurationIdentifier", testIdentifier); - QVERIFY(session.sessionProperty("UserChoiceConfigurationIdentifier").toString() != testIdentifier); + //resetting UserChoiceConfiguration is ignored (read only property) + session.setSessionProperty("UserChoiceConfiguration", testIdentifier); + QVERIFY(session.sessionProperty("UserChoiceConfiguration").toString() != testIdentifier); const QString activeIdentifier = - session.sessionProperty("ActiveConfigurationIdentifier").toString(); + session.sessionProperty("ActiveConfiguration").toString(); QVERIFY(!activeIdentifier.isEmpty()); QVERIFY(activeIdentifier != configuration.identifier()); @@ -387,9 +398,9 @@ void tst_QNetworkSession::userChoiceSession() QVERIFY(activeConfiguration.isValid()); QVERIFY(activeConfiguration.type() == QNetworkConfiguration::InternetAccessPoint); - //resetting ActiveConfigurationIdentifier is ignored (read only property) - session.setSessionProperty("ActiveConfigurationIdentifier", testIdentifier); - QVERIFY(session.sessionProperty("ActiveConfigurationIdentifier").toString() != testIdentifier); + //resetting ActiveConfiguration is ignored (read only property) + session.setSessionProperty("ActiveConfiguration", testIdentifier); + QVERIFY(session.sessionProperty("ActiveConfiguration").toString() != testIdentifier); if (userChoiceConfiguration.type() == QNetworkConfiguration::InternetAccessPoint) { QVERIFY(userChoiceConfiguration == activeConfiguration); @@ -427,7 +438,7 @@ void tst_QNetworkSession::sessionOpenCloseStop() // Test initial state of the session. { QVERIFY(session.configuration() == configuration); - QVERIFY(!session.isActive()); + QVERIFY(!session.isOpen()); // session may be invalid if configuration is removed between when // sessionOpenCloseStop_data() is called and here. QVERIFY((configuration.isValid() && (session.state() != QNetworkSession::Invalid)) || @@ -453,7 +464,7 @@ void tst_QNetworkSession::sessionOpenCloseStop() session.waitForOpened(); - if (session.isActive()) + if (session.isOpen()) QVERIFY(!sessionOpenedSpy.isEmpty() || !errorSpy.isEmpty()); if (!errorSpy.isEmpty()) { QNetworkSession::SessionError error = @@ -517,7 +528,7 @@ void tst_QNetworkSession::sessionOpenCloseStop() // Test opening a second session. { QVERIFY(session2.configuration() == configuration); - QVERIFY(!session2.isActive()); + QVERIFY(!session2.isOpen()); QVERIFY(session2.state() == QNetworkSession::Connected); QVERIFY(session.error() == QNetworkSession::UnknownSessionError); @@ -525,8 +536,8 @@ void tst_QNetworkSession::sessionOpenCloseStop() QTRY_VERIFY(!sessionOpenedSpy2.isEmpty() || !errorSpy2.isEmpty()); - QVERIFY(session.isActive()); - QVERIFY(session2.isActive()); + QVERIFY(session.isOpen()); + QVERIFY(session2.isOpen()); QVERIFY(session.state() == QNetworkSession::Connected); QVERIFY(session2.state() == QNetworkSession::Connected); QVERIFY(session.interface().isValid()); @@ -550,7 +561,7 @@ void tst_QNetworkSession::sessionOpenCloseStop() QTRY_VERIFY(!sessionClosedSpy2.isEmpty() || !errorSpy2.isEmpty()); - QVERIFY(!session2.isActive()); + QVERIFY(!session2.isOpen()); if (!errorSpy2.isEmpty()) { QVERIFY(!errorSpy.isEmpty()); @@ -632,7 +643,7 @@ void tst_QNetworkSession::sessionOpenCloseStop() } } if (roamedSuccessfully) { - QString configId = session.sessionProperty("ActiveConfigurationIdentifier").toString(); + QString configId = session.sessionProperty("ActiveConfiguration").toString(); QNetworkConfiguration config = manager.configurationFromIdentifier(configId); QNetworkSession session3(config); QSignalSpy errorSpy3(&session3, SIGNAL(error(QNetworkSession::SessionError))); @@ -641,7 +652,7 @@ void tst_QNetworkSession::sessionOpenCloseStop() session3.open(); session3.waitForOpened(); - if (session.isActive()) + if (session.isOpen()) QVERIFY(!sessionOpenedSpy3.isEmpty() || !errorSpy3.isEmpty()); session.stop(); @@ -682,9 +693,9 @@ void tst_QNetworkSession::sessionOpenCloseStop() QVERIFY(!sessionClosedSpy2.isEmpty()); #ifndef Q_CC_NOKIAX86 - QVERIFY(!session.isActive()); + QVERIFY(!session.isOpen()); #endif - QVERIFY(!session2.isActive()); + QVERIFY(!session2.isOpen()); } else { // Test closing the second session. { @@ -698,8 +709,8 @@ void tst_QNetworkSession::sessionOpenCloseStop() QVERIFY(sessionClosedSpy.isEmpty()); - QVERIFY(session.isActive()); - QVERIFY(!session2.isActive()); + QVERIFY(session.isOpen()); + QVERIFY(!session2.isOpen()); QVERIFY(session.state() == QNetworkSession::Connected); QVERIFY(session2.state() == QNetworkSession::Connected); QVERIFY(session.interface().isValid()); @@ -724,7 +735,7 @@ void tst_QNetworkSession::sessionOpenCloseStop() QTRY_VERIFY(!sessionClosedSpy.isEmpty() || !errorSpy.isEmpty()); - QVERIFY(!session.isActive()); + QVERIFY(!session.isOpen()); if (expectStateChange) QTRY_VERIFY(!stateChangedSpy.isEmpty() || !errorSpy.isEmpty()); @@ -781,12 +792,15 @@ void tst_QNetworkSession::outOfProcessSession() QList before = manager.allConfigurations(QNetworkConfiguration::Active); - QSignalSpy spy(&manager, SIGNAL(configurationChanged(QNetworkConfiguration))); - + QSignalSpy spy(&manager, SIGNAL(configurationChanged(QNetworkConfiguration))); + // Cannot read/write to processes on WinCE or Symbian. // Easiest alternative is to use sockets for IPC. QLocalServer oopServer; + // First remove possible earlier listening address which would cause listen to fail + // (e.g. previously abruptly ended unit test might cause this) + QLocalServer::removeServer("tst_qnetworksession"); oopServer.listen("tst_qnetworksession"); QProcess lackey; diff --git a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro index 1410601..ccc405e 100644 --- a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro +++ b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro @@ -8,7 +8,8 @@ QT = core network INCLUDEPATH += ../../../../src/bearer include(../../../../common.pri) -qtAddLibrary(QtBearer) +CONFIG += mobility +MOBILITY = bearer wince* { LACKEY.sources = $$OUTPUT_DIR/build/tests/bin/qnetworksessionlackey.exe diff --git a/tests/manual/bearerex/bearerex.cpp b/tests/manual/bearerex/bearerex.cpp index 68590cc..f62d8d2 100644 --- a/tests/manual/bearerex/bearerex.cpp +++ b/tests/manual/bearerex/bearerex.cpp @@ -69,10 +69,6 @@ void BearerEx::createMenus() menuBar()->addAction(act1); connect(act1, SIGNAL(triggered()), this, SLOT(on_showDetailsButton_clicked())); - m_openAction = new QAction(tr("Open Session"), this); - menuBar()->addAction(m_openAction); - connect(m_openAction, SIGNAL(triggered()), this, SLOT(on_openSessionButton_clicked())); - QAction* exitAct = new QAction(tr("Exit"), this); menuBar()->addAction(exitAct); connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); @@ -290,7 +286,7 @@ SessionTab::SessionTab(QNetworkConfiguration* apNetworkConfiguration, } else if (apNetworkConfiguration->type() == QNetworkConfiguration::ServiceNetwork) { snapLineEdit->setText(apNetworkConfiguration->name()+" ("+apNetworkConfiguration->identifier()+")"); } - bearerLineEdit->setText(m_NetworkSession->bearerName()); + bearerLineEdit->setText(apNetworkConfiguration->bearerName()); sentRecDataLineEdit->setText(QString::number(m_NetworkSession->bytesWritten())+ QString(" / ")+ QString::number(m_NetworkSession->bytesReceived())); @@ -341,7 +337,7 @@ void SessionTab::on_sendRequestButton_clicked() void SessionTab::on_openSessionButton_clicked() { m_NetworkSession->open(); - if (m_NetworkSession->isActive()) { + if (m_NetworkSession->isOpen()) { newState(m_NetworkSession->state()); } } @@ -349,7 +345,7 @@ void SessionTab::on_openSessionButton_clicked() void SessionTab::on_closeSessionButton_clicked() { m_NetworkSession->close(); - if (!m_NetworkSession->isActive()) { + if (!m_NetworkSession->isOpen()) { newState(m_NetworkSession->state()); } } @@ -418,7 +414,7 @@ void SessionTab::opened() listItem->setText(QString("S")+QString::number(m_index)+QString(" - ")+QString("Opened")); m_eventListWidget->addItem(listItem); - QVariant identifier = m_NetworkSession->property("ActiveConfigurationIdentifier"); + QVariant identifier = m_NetworkSession->property("ActiveConfiguration"); if (!identifier.isNull()) { QString configId = identifier.toString(); QNetworkConfiguration config = m_ConfigManager->configurationFromIdentifier(configId); @@ -428,7 +424,7 @@ void SessionTab::opened() } if (m_NetworkSession->configuration().type() == QNetworkConfiguration::UserChoice) { - QVariant identifier = m_NetworkSession->property("UserChoiceConfigurationIdentifier"); + QVariant identifier = m_NetworkSession->property("UserChoiceConfiguration"); if (!identifier.isNull()) { QString configId = identifier.toString(); QNetworkConfiguration config = m_ConfigManager->configurationFromIdentifier(configId); @@ -490,22 +486,21 @@ void SessionTab::stateChanged(QNetworkSession::State state) void SessionTab::newState(QNetworkSession::State state) { - if (state == QNetworkSession::Connected) { - QVariant identifier = m_NetworkSession->property("ActiveConfigurationIdentifier"); - if (!identifier.isNull()) { - QString configId = identifier.toString(); - QNetworkConfiguration config = m_ConfigManager->configurationFromIdentifier(configId); - if (config.isValid()) { - iapLineEdit->setText(config.name()+" ("+config.identifier()+")"); - } + QVariant identifier = m_NetworkSession->property("ActiveConfiguration"); + if (state == QNetworkSession::Connected && !identifier.isNull()) { + QString configId = identifier.toString(); + QNetworkConfiguration config = m_ConfigManager->configurationFromIdentifier(configId); + if (config.isValid()) { + iapLineEdit->setText(config.name()+" ("+config.identifier()+")"); + bearerLineEdit->setText(config.bearerName()); } + } else { + bearerLineEdit->setText(m_NetworkSession->configuration().bearerName()); } - bearerLineEdit->setText(m_NetworkSession->bearerName()); - QString active; - if (m_NetworkSession->isActive()) { - active = " (A)"; + if (m_NetworkSession->isOpen()) { + active = " (O)"; } stateLineEdit->setText(stateString(state)+active); } diff --git a/tests/manual/bearerex/bearerex.h b/tests/manual/bearerex/bearerex.h index f18180e..b8a2393 100644 --- a/tests/manual/bearerex/bearerex.h +++ b/tests/manual/bearerex/bearerex.h @@ -51,7 +51,10 @@ #include "qnetworksession.h" #include "xqlistwidget.h" +QT_BEGIN_NAMESPACE class QHttp; +QT_END_NAMESPACE + class SessionTab; QTM_USE_NAMESPACE diff --git a/tests/manual/bearerex/bearerex.pro b/tests/manual/bearerex/bearerex.pro index a870eb1..e480d43 100644 --- a/tests/manual/bearerex/bearerex.pro +++ b/tests/manual/bearerex/bearerex.pro @@ -24,11 +24,6 @@ SOURCES += bearerex.cpp \ main.cpp \ xqlistwidget.cpp -symbian: { - bearerex.sources = Qtbearer.dll - bearerex.path = /sys/bin - DEPLOYMENT += bearerex - - TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData -} -qtAddLibrary(QtBearer) +CONFIG += mobility +MOBILITY = bearer +symbian:TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData diff --git a/tests/manual/networkmanager/networkmanager.pro b/tests/manual/networkmanager/networkmanager.pro index 31b2af1..7ff370a 100644 --- a/tests/manual/networkmanager/networkmanager.pro +++ b/tests/manual/networkmanager/networkmanager.pro @@ -12,7 +12,8 @@ requires(contains(QT_CONFIG,dbus)) INCLUDEPATH += ../../src/bearer include(../../common.pri) -qtAddLibrary(QtBearer) +CONFIG += mobility +MOBILITY = bearer #MOC_DIR = .moc #OBJECTS_DIR = .obj diff --git a/tests/manual/networkmanager/nmview.cpp b/tests/manual/networkmanager/nmview.cpp index ca9d907..fde5cae 100644 --- a/tests/manual/networkmanager/nmview.cpp +++ b/tests/manual/networkmanager/nmview.cpp @@ -188,8 +188,6 @@ void NMView::getActiveConnections() void NMView::update() { -// if(sess) -// qWarning() << __FUNCTION__<< sess->bytesWritten() << sess->bearerName(); // QNetworkManagerInterface *dbIface; // dbIface = new QNetworkManagerInterface; // QList connections = dbIface->activeConnections(); diff --git a/tests/manual/networkmanager/nmview.h b/tests/manual/networkmanager/nmview.h index 641385e..e15aacd 100644 --- a/tests/manual/networkmanager/nmview.h +++ b/tests/manual/networkmanager/nmview.h @@ -49,9 +49,11 @@ QTM_USE_NAMESPACE +QT_BEGIN_NAMESPACE class QListWidget; class QTreeWidget; class QTreeWidgetItem; +QT_END_NAMESPACE class NMView : public QDialog, private Ui::Dialog { -- cgit v0.12 From 4ef1103e6b399cb9421fb001f81af47bca20d2a7 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Wed, 6 Jan 2010 09:35:51 +1000 Subject: Fix failure on Windows after merge. --- src/plugins/bearer/nla/qnlaengine.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/plugins/bearer/nla/qnlaengine.cpp b/src/plugins/bearer/nla/qnlaengine.cpp index be1cd28..51897f0 100644 --- a/src/plugins/bearer/nla/qnlaengine.cpp +++ b/src/plugins/bearer/nla/qnlaengine.cpp @@ -406,8 +406,6 @@ QNetworkConfigurationPrivate *QNlaThread::parseQuerySet(const WSAQUERYSET *query cpPriv->id = QString::number(qHash(QLatin1String("NLA:") + cpPriv->name)); cpPriv->state = QNetworkConfiguration::Defined; cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - if (QNlaEngine *engine = qobject_cast(parent())) - config->bearer = engine->bearerName(config->id); #ifdef BEARER_MANAGEMENT_DEBUG qDebug() << "size:" << querySet->dwSize; @@ -443,6 +441,9 @@ QNetworkConfigurationPrivate *QNlaThread::parseQuerySet(const WSAQUERYSET *query } while (offset != 0 && offset < querySet->lpBlob->cbSize); } + if (QNlaEngine *engine = qobject_cast(parent())) + cpPriv->bearer = engine->bearerName(cpPriv->id); + return cpPriv; } -- cgit v0.12 From b2fc251bb4628a06282d1dcaeda79222b300b912 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Wed, 6 Jan 2010 09:43:03 +1000 Subject: Bearer Management Integration 3. --- src/network/bearer/qcorewlanengine_mac.mm | 16 ++-------------- src/network/bearer/qcorewlanengine_mac_p.h | 2 -- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/src/network/bearer/qcorewlanengine_mac.mm b/src/network/bearer/qcorewlanengine_mac.mm index 41ec79a..6fad457 100644 --- a/src/network/bearer/qcorewlanengine_mac.mm +++ b/src/network/bearer/qcorewlanengine_mac.mm @@ -75,7 +75,7 @@ inline QString cfstringRefToQstring(CFStringRef cfStringRef) { if (CFStringGetCString(CFStringRef(cfStringRef), cstring, maxLength, kCFStringEncodingUTF8)) { retVal = QString::fromUtf8(cstring); } - delete cstring; + delete[] cstring; return retVal; } @@ -315,7 +315,7 @@ QList QCoreWlanEngine::scanForSsids(const QStrin CWInterface *currentInterface = [CWInterface interfaceWithName:qstringToNSString(interfaceName)]; NSError *err = nil; NSDictionary *parametersDict = nil; - NSArray* apArray = [NSMutableArray arrayWithArray:[currentInterface scanForNetworksWithParameters:parametersDict error:&err]]; + NSArray* apArray = [currentInterface scanForNetworksWithParameters:parametersDict error:&err]; CWNetwork *apNetwork; if(!err) { @@ -396,18 +396,6 @@ bool QCoreWlanEngine::isKnownSsid(const QString &interfaceName, const QString &s return false; } -QList QCoreWlanEngine::getWlanProfiles(const QString &interfaceName) -{ - Q_UNUSED(interfaceName) -#if defined(MAC_SDK_10_6) -// for( CW8021XProfile *each8021XProfile in [CW8021XProfile allUser8021XProfiles] ) { -// qWarning() << "Profile name" << nsstringToQString([each8021XProfile ssid]); -// } - -#endif - return QList (); -} - bool QCoreWlanEngine::getAllScInterfaces() { networkInterfaces.clear(); diff --git a/src/network/bearer/qcorewlanengine_mac_p.h b/src/network/bearer/qcorewlanengine_mac_p.h index 6ad093a..5bdba3d 100644 --- a/src/network/bearer/qcorewlanengine_mac_p.h +++ b/src/network/bearer/qcorewlanengine_mac_p.h @@ -88,8 +88,6 @@ private: QTimer pollTimer; QList scanForSsids(const QString &interfaceName); - QList getWlanProfiles(const QString &interfaceName); - bool isKnownSsid(const QString &interfaceName, const QString &ssid); QList foundConfigurations; -- cgit v0.12 From 6cdcb06d6d8fb60f250aa0389e8d545d0d52fb79 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Wed, 6 Jan 2010 10:01:30 +1000 Subject: Fix failures on Mac OS X after merge. --- src/plugins/bearer/corewlan/qcorewlanengine.mm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm index 3ceebbd..2a3fecf 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.mm +++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm @@ -306,6 +306,7 @@ void QCoreWlanEngine::doRequestUpdate() ptr->id = id; ptr->state = state; ptr->type = QNetworkConfiguration::InternetAccessPoint; + ptr->bearer = qGetInterfaceType(interface.name()); accessPointConfigurations.insert(id, ptr); configurationInterface.insert(id, interface.name()); @@ -345,6 +346,8 @@ QStringList QCoreWlanEngine::scanForSsids(const QString &interfaceName) apNetwork = [apArray objectAtIndex:row]; + const QString networkSsid = nsstringToQString([apNetwork ssid]); + const QString id = QString::number(qHash(QLatin1String("corewlan:") + networkSsid)); found.append(id); -- cgit v0.12 From 6b700e2bc14d2b159c2faa6f3fe8ca6d77d42f5b Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Wed, 6 Jan 2010 10:01:55 +1000 Subject: Fix test compile failure when using frameworks on Mac OS X. --- src/network/bearer/qbearerplugin.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/bearer/qbearerplugin.h b/src/network/bearer/qbearerplugin.h index 036d712..970410b 100644 --- a/src/network/bearer/qbearerplugin.h +++ b/src/network/bearer/qbearerplugin.h @@ -42,7 +42,7 @@ #ifndef QBEARERPLUGIN_H #define QBEARERPLUGIN_H -#include "qnetworksessionengine_p.h" +#include #include #include -- cgit v0.12 From bd532d0cb6da5d09e048192171d7f5263e22eca6 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Fri, 4 Dec 2009 09:48:46 +1000 Subject: Fix build on Maemo, force type to qreal. --- src/gui/painting/qpainter.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index fc1863f..ab5773e 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + // QtCore #include #include @@ -5918,7 +5919,7 @@ static QPixmap generateWavyPixmap(qreal maxRadius, const QPen &pen) if (QPixmapCache::find(key, pixmap)) return pixmap; - const qreal halfPeriod = qMax(qreal(2), radiusBase * 1.61803399); // the golden ratio + const qreal halfPeriod = qMax(qreal(2), radiusBase * qreal(1.61803399)); // the golden ratio const int width = qCeil(100 / (2 * halfPeriod)) * (2 * halfPeriod); const int radius = qFloor(radiusBase); -- cgit v0.12 From b2477aec2adad08c4f44ffcdc2f9ad1c0ce4a56b Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 7 Jan 2010 13:03:34 +1000 Subject: Make compile for Symbian. --- src/network/bearer/bearer.pri | 12 ++++---- src/network/bearer/qnetworkconfigmanager.cpp | 36 ++++++++++++++++++++++++ src/network/bearer/qnetworkconfigmanager_s60_p.h | 4 +-- src/network/bearer/qnetworkconfiguration_s60_p.h | 2 +- src/plugins/bearer/bearer.pro | 2 ++ 5 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/network/bearer/bearer.pri b/src/network/bearer/bearer.pri index 4f6c549..766e717 100644 --- a/src/network/bearer/bearer.pri +++ b/src/network/bearer/bearer.pri @@ -4,13 +4,11 @@ HEADERS += bearer/qnetworkconfiguration.h \ bearer/qnetworksession.h \ - bearer/qnetworkconfigmanager.h \ - bearer/qbearerplugin.h + bearer/qnetworkconfigmanager.h SOURCES += bearer/qnetworksession.cpp \ bearer/qnetworkconfigmanager.cpp \ - bearer/qnetworkconfiguration.cpp \ - bearer/qbearerplugin.cpp + bearer/qnetworkconfiguration.cpp symbian { exists($${EPOCROOT}epoc32/release/winscw/udeb/cmmanager.lib)| \ @@ -72,11 +70,13 @@ symbian { HEADERS += bearer/qnetworkconfigmanager_p.h \ bearer/qnetworkconfiguration_p.h \ bearer/qnetworksession_p.h \ - bearer/qnetworksessionengine_p.h + bearer/qnetworksessionengine_p.h \ + bearer/qbearerplugin.h SOURCES += bearer/qnetworkconfigmanager_p.cpp \ bearer/qnetworksession_p.cpp \ - bearer/qnetworksessionengine.cpp + bearer/qnetworksessionengine.cpp \ + bearer/qbearerplugin.cpp contains(QT_CONFIG, networkmanager):DEFINES += BACKEND_NM } diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index 6b73e3c..7f58e07 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -238,6 +238,32 @@ QList QNetworkConfigurationManager::allConfigurations(QNe QList result; QNetworkConfigurationManagerPrivate* conPriv = connManager(); +#ifdef Q_OS_SYMBIAN + QList cpsIdents = conPriv->accessPointConfigurations.keys(); + + //find all InternetAccessPoints + foreach (const QString &ii, cpsIdents) { + QExplicitlySharedDataPointer p = + conPriv->accessPointConfigurations.value(ii); + if ( (p->state & filter) == filter ) { + QNetworkConfiguration pt; + pt.d = conPriv->accessPointConfigurations.value(ii); + result << pt; + } + } + + //find all service networks + cpsIdents = conPriv->snapConfigurations.keys(); + foreach (const QString &ii, cpsIdents) { + QExplicitlySharedDataPointer p = + conPriv->snapConfigurations.value(ii); + if ( (p->state & filter) == filter ) { + QNetworkConfiguration pt; + pt.d = conPriv->snapConfigurations.value(ii); + result << pt; + } + } +#else foreach (QNetworkSessionEngine *engine, conPriv->sessionEngines) { QStringList cpsIdents = engine->accessPointConfigurations.keys(); @@ -264,6 +290,7 @@ QList QNetworkConfigurationManager::allConfigurations(QNe } } } +#endif return result; } @@ -280,6 +307,14 @@ QNetworkConfiguration QNetworkConfigurationManager::configurationFromIdentifier( QNetworkConfiguration item; +#ifdef Q_OS_SYMBIAN + if (conPriv->accessPointConfigurations.contains(identifier)) + item.d = conPriv->accessPointConfigurations.value(identifier); + else if (conPriv->snapConfigurations.contains(identifier)) + item.d = conPriv->snapConfigurations.value(identifier); + else if (conPriv->userChoiceConfigurations.contains(identifier)) + item.d = conPriv->userChoiceConfigurations.value(identifier); +#else foreach (QNetworkSessionEngine *engine, conPriv->sessionEngines) { if (engine->accessPointConfigurations.contains(identifier)) item.d = engine->accessPointConfigurations.value(identifier); @@ -292,6 +327,7 @@ QNetworkConfiguration QNetworkConfigurationManager::configurationFromIdentifier( return item; } +#endif return item; } diff --git a/src/network/bearer/qnetworkconfigmanager_s60_p.h b/src/network/bearer/qnetworkconfigmanager_s60_p.h index 568803d..3378898 100644 --- a/src/network/bearer/qnetworkconfigmanager_s60_p.h +++ b/src/network/bearer/qnetworkconfigmanager_s60_p.h @@ -53,8 +53,8 @@ // We mean it. // -#include -#include +#include +#include "qnetworkconfiguration_s60_p.h" #include #include diff --git a/src/network/bearer/qnetworkconfiguration_s60_p.h b/src/network/bearer/qnetworkconfiguration_s60_p.h index 0973152..5e75c13 100644 --- a/src/network/bearer/qnetworkconfiguration_s60_p.h +++ b/src/network/bearer/qnetworkconfiguration_s60_p.h @@ -53,7 +53,7 @@ // We mean it. // -#include +#include #include QT_BEGIN_NAMESPACE diff --git a/src/plugins/bearer/bearer.pro b/src/plugins/bearer/bearer.pro index 58d2613..05fce8c 100644 --- a/src/plugins/bearer/bearer.pro +++ b/src/plugins/bearer/bearer.pro @@ -1,7 +1,9 @@ TEMPLATE = subdirs +!symbian:!maemo { SUBDIRS += generic contains(QT_CONFIG, dbus):contains(QT_CONFIG, networkmanager):SUBDIRS += networkmanager win32:SUBDIRS += nla win32:!wince*:SUBDIRS += nativewifi macx:SUBDIRS += corewlan +} -- cgit v0.12 From aed972b88e96596114ef8a5a350063744220f8c4 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 11 Jan 2010 12:09:34 +1000 Subject: Return empty bearer name for invalid, ServiceNetwork and UserChoice. --- src/network/bearer/qnetworkconfiguration_s60_p.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/bearer/qnetworkconfiguration_s60_p.cpp b/src/network/bearer/qnetworkconfiguration_s60_p.cpp index 3064840..d01d4d9 100644 --- a/src/network/bearer/qnetworkconfiguration_s60_p.cpp +++ b/src/network/bearer/qnetworkconfiguration_s60_p.cpp @@ -68,7 +68,7 @@ QString QNetworkConfigurationPrivate::bearerName() const case QNetworkConfigurationPrivate::BearerHSPA: return QLatin1String("HSPA"); case QNetworkConfigurationPrivate::BearerBluetooth: return QLatin1String("Bluetooth"); case QNetworkConfigurationPrivate::BearerWiMAX: return QLatin1String("WiMAX"); - default: return QLatin1String("Unknown"); + default: return QString(); } } -- cgit v0.12 From e620ab4a391ea1c86718856b31f6a5c4928a18a7 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 12 Jan 2010 16:15:26 +1000 Subject: Partially convert Symbian backend into a plugin. QNetworkSession functionality not converted yet. --- src/network/bearer/bearer.pri | 30 +- src/network/bearer/qnetworkconfigmanager.cpp | 42 - src/network/bearer/qnetworkconfigmanager_p.cpp | 122 +-- src/network/bearer/qnetworkconfigmanager_p.h | 2 - src/network/bearer/qnetworkconfigmanager_s60_p.cpp | 974 --------------------- src/network/bearer/qnetworkconfigmanager_s60_p.h | 185 ---- src/network/bearer/qnetworkconfiguration.cpp | 4 - src/network/bearer/qnetworkconfiguration_p.h | 1 - src/network/bearer/qnetworkconfiguration_s60_p.cpp | 17 - src/network/bearer/qnetworkconfiguration_s60_p.h | 109 --- src/network/bearer/qnetworksession.cpp | 8 +- src/network/bearer/qnetworksessionengine.cpp | 6 + src/network/bearer/qnetworksessionengine_p.h | 3 + src/plugins/bearer/bearer.pro | 3 +- src/plugins/bearer/corewlan/qcorewlanengine.h | 2 + src/plugins/bearer/corewlan/qcorewlanengine.mm | 5 + src/plugins/bearer/generic/qgenericengine.cpp | 7 + src/plugins/bearer/generic/qgenericengine.h | 2 + .../bearer/nativewifi/qnativewifiengine.cpp | 6 + src/plugins/bearer/nativewifi/qnativewifiengine.h | 2 + .../networkmanager/qnetworkmanagerengine.cpp | 6 + .../bearer/networkmanager/qnetworkmanagerengine.h | 2 + src/plugins/bearer/nla/qnlaengine.cpp | 5 + src/plugins/bearer/nla/qnlaengine.h | 2 + src/plugins/bearer/symbian/main.cpp | 86 ++ src/plugins/bearer/symbian/symbian.pro | 33 + src/plugins/bearer/symbian/symbianengine.cpp | 931 ++++++++++++++++++++ src/plugins/bearer/symbian/symbianengine.h | 201 +++++ src/s60installs/s60installs.pro | 10 +- 29 files changed, 1334 insertions(+), 1472 deletions(-) delete mode 100644 src/network/bearer/qnetworkconfigmanager_s60_p.cpp delete mode 100644 src/network/bearer/qnetworkconfigmanager_s60_p.h delete mode 100644 src/network/bearer/qnetworkconfiguration_s60_p.h create mode 100644 src/plugins/bearer/symbian/main.cpp create mode 100644 src/plugins/bearer/symbian/symbian.pro create mode 100644 src/plugins/bearer/symbian/symbianengine.cpp create mode 100644 src/plugins/bearer/symbian/symbianengine.h diff --git a/src/network/bearer/bearer.pri b/src/network/bearer/bearer.pri index 766e717..169c8b7 100644 --- a/src/network/bearer/bearer.pri +++ b/src/network/bearer/bearer.pri @@ -10,35 +10,11 @@ SOURCES += bearer/qnetworksession.cpp \ bearer/qnetworkconfigmanager.cpp \ bearer/qnetworkconfiguration.cpp -symbian { - exists($${EPOCROOT}epoc32/release/winscw/udeb/cmmanager.lib)| \ - exists($${EPOCROOT}epoc32/release/armv5/lib/cmmanager.lib) { - message("Building with SNAP support") - DEFINES += SNAP_FUNCTIONALITY_AVAILABLE - LIBS += -lcmmanager - } else { - message("Building without SNAP support") - LIBS += -lapengine - } - - INCLUDEPATH += $$APP_LAYER_SYSTEMINCLUDE +symbian_disabled { + HEADERS += bearer/qnetworksession_s60_p.h - HEADERS += bearer/qnetworkconfigmanager_s60_p.h \ - bearer/qnetworkconfiguration_s60_p.h \ - bearer/qnetworksession_s60_p.h - SOURCES += bearer/qnetworkconfigmanager_s60_p.cpp \ - bearer/qnetworkconfiguration_s60_p.cpp \ + SOURCES += bearer/qnetworkconfiguration_s60_p.cpp \ bearer/qnetworksession_s60_p.cpp - - LIBS += -lcommdb \ - -lapsettingshandlerui \ - -lconnmon \ - -lcentralrepository \ - -lesock \ - -linsock \ - -lecom \ - -lefsrv \ - -lnetmeta } else:maemo { QT += dbus CONFIG += link_pkgconfig diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index 7f58e07..f4daf4a 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -41,12 +41,8 @@ #include "qnetworkconfigmanager.h" -#ifdef Q_OS_SYMBIAN -#include "qnetworkconfigmanager_s60_p.h" -#else #include "qnetworkconfigmanager_p.h" #include "qnetworksessionengine_p.h" -#endif #include @@ -54,12 +50,10 @@ QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC(QNetworkConfigurationManagerPrivate, connManager); -#ifndef Q_OS_SYMBIAN QNetworkConfigurationManagerPrivate *qNetworkConfigurationManagerPrivate() { return connManager(); } -#endif /*! \class QNetworkConfigurationManager @@ -238,32 +232,6 @@ QList QNetworkConfigurationManager::allConfigurations(QNe QList result; QNetworkConfigurationManagerPrivate* conPriv = connManager(); -#ifdef Q_OS_SYMBIAN - QList cpsIdents = conPriv->accessPointConfigurations.keys(); - - //find all InternetAccessPoints - foreach (const QString &ii, cpsIdents) { - QExplicitlySharedDataPointer p = - conPriv->accessPointConfigurations.value(ii); - if ( (p->state & filter) == filter ) { - QNetworkConfiguration pt; - pt.d = conPriv->accessPointConfigurations.value(ii); - result << pt; - } - } - - //find all service networks - cpsIdents = conPriv->snapConfigurations.keys(); - foreach (const QString &ii, cpsIdents) { - QExplicitlySharedDataPointer p = - conPriv->snapConfigurations.value(ii); - if ( (p->state & filter) == filter ) { - QNetworkConfiguration pt; - pt.d = conPriv->snapConfigurations.value(ii); - result << pt; - } - } -#else foreach (QNetworkSessionEngine *engine, conPriv->sessionEngines) { QStringList cpsIdents = engine->accessPointConfigurations.keys(); @@ -290,7 +258,6 @@ QList QNetworkConfigurationManager::allConfigurations(QNe } } } -#endif return result; } @@ -307,14 +274,6 @@ QNetworkConfiguration QNetworkConfigurationManager::configurationFromIdentifier( QNetworkConfiguration item; -#ifdef Q_OS_SYMBIAN - if (conPriv->accessPointConfigurations.contains(identifier)) - item.d = conPriv->accessPointConfigurations.value(identifier); - else if (conPriv->snapConfigurations.contains(identifier)) - item.d = conPriv->snapConfigurations.value(identifier); - else if (conPriv->userChoiceConfigurations.contains(identifier)) - item.d = conPriv->userChoiceConfigurations.value(identifier); -#else foreach (QNetworkSessionEngine *engine, conPriv->sessionEngines) { if (engine->accessPointConfigurations.contains(identifier)) item.d = engine->accessPointConfigurations.value(identifier); @@ -327,7 +286,6 @@ QNetworkConfiguration QNetworkConfigurationManager::configurationFromIdentifier( return item; } -#endif return item; } diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index cb83789..c00d6d3 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -59,11 +59,6 @@ QNetworkConfigurationManagerPrivate::~QNetworkConfigurationManagerPrivate() delete sessionEngines.takeFirst(); } -void QNetworkConfigurationManagerPrivate::registerPlatformCapabilities() -{ - capFlags = QNetworkConfigurationManager::ForcedRoaming; -} - void QNetworkConfigurationManagerPrivate::configurationAdded(QNetworkConfigurationPrivatePointer ptr) { if (!firstUpdate) { @@ -177,106 +172,25 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() updating = false; QFactoryLoader *l = loader(); - QStringList keys = l->keys(); - - if (keys.contains(QLatin1String("corewlan"))) { - QBearerEnginePlugin *coreWlanPlugin = - qobject_cast(l->instance(QLatin1String("corewlan"))); - if (coreWlanPlugin) { - QNetworkSessionEngine *coreWifi = coreWlanPlugin->create(QLatin1String("corewlan")); - if (coreWifi) { - sessionEngines.append(coreWifi); - connect(coreWifi, SIGNAL(updateCompleted()), - this, SLOT(updateConfigurations())); - connect(coreWifi, SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), - this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer))); - connect(coreWifi, SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)), - this, SLOT(configurationRemoved(QNetworkConfigurationPrivatePointer))); - connect(coreWifi, SIGNAL(configurationChanged(QNetworkConfigurationPrivatePointer)), - this, SLOT(configurationChanged(QNetworkConfigurationPrivatePointer))); - } - } - } - - if (keys.contains(QLatin1String("networkmanager"))) { - QBearerEnginePlugin *nmPlugin = - qobject_cast(l->instance(QLatin1String("networkmanager"))); - if (nmPlugin) { - QNetworkSessionEngine *nmWifi = nmPlugin->create(QLatin1String("networkmanager")); - if (nmWifi) { - sessionEngines.append(nmWifi); - connect(nmWifi, SIGNAL(updateCompleted()), - this, SLOT(updateConfigurations())); - connect(nmWifi, SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), - this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer))); - connect(nmWifi, SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)), - this, SLOT(configurationRemoved(QNetworkConfigurationPrivatePointer))); - connect(nmWifi, SIGNAL(configurationChanged(QNetworkConfigurationPrivatePointer)), - this, SLOT(configurationChanged(QNetworkConfigurationPrivatePointer))); - } - } - } - - if (keys.contains(QLatin1String("generic"))) { - QBearerEnginePlugin *genericPlugin = - qobject_cast(l->instance(QLatin1String("generic"))); - if (genericPlugin) { - QNetworkSessionEngine *generic = genericPlugin->create(QLatin1String("generic")); - if (generic) { - sessionEngines.append(generic); - connect(generic, SIGNAL(updateCompleted()), - this, SLOT(updateConfigurations())); - connect(generic, SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), - this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer))); - connect(generic, SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)), - this, SLOT(configurationRemoved(QNetworkConfigurationPrivatePointer))); - connect(generic, SIGNAL(configurationChanged(QNetworkConfigurationPrivatePointer)), - this, SLOT(configurationChanged(QNetworkConfigurationPrivatePointer))); - } - } - } - - if (keys.contains(QLatin1String("nla"))) { - QBearerEnginePlugin *nlaPlugin = - qobject_cast(l->instance(QLatin1String("nla"))); - if (nlaPlugin) { - QNetworkSessionEngine *nla = nlaPlugin->create(QLatin1String("nla")); - if (nla) { - sessionEngines.append(nla); - connect(nla, SIGNAL(updateCompleted()), - this, SLOT(updateConfigurations())); - connect(nla, SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), - this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer))); - connect(nla, SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)), - this, SLOT(configurationRemoved(QNetworkConfigurationPrivatePointer))); - connect(nla, SIGNAL(configurationChanged(QNetworkConfigurationPrivatePointer)), - this, SLOT(configurationChanged(QNetworkConfigurationPrivatePointer))); - } - } - } - if (keys.contains(QLatin1String("nativewifi"))) { - QBearerEnginePlugin *nativeWifiPlugin = - qobject_cast(l->instance(QLatin1String("nativewifi"))); - if (nativeWifiPlugin) { - QNetworkSessionEngine *nativeWifi = - nativeWifiPlugin->create(QLatin1String("nativewifi")); - if (nativeWifi) { - sessionEngines.append(nativeWifi); - connect(nativeWifi, SIGNAL(updateCompleted()), - this, SLOT(updateConfigurations())); - connect(nativeWifi, - SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), - this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer))); - connect(nativeWifi, - SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)), - this, SLOT(configurationRemoved(QNetworkConfigurationPrivatePointer))); - connect(nativeWifi, - SIGNAL(configurationChanged(QNetworkConfigurationPrivatePointer)), - this, SLOT(configurationChanged(QNetworkConfigurationPrivatePointer))); - - capFlags |= QNetworkConfigurationManager::CanStartAndStopInterfaces; - } + foreach (const QString &key, l->keys()) { + QBearerEnginePlugin *plugin = qobject_cast(l->instance(key)); + if (plugin) { + QNetworkSessionEngine *engine = plugin->create(key); + if (!engine) + continue; + + sessionEngines.append(engine); + connect(engine, SIGNAL(updateCompleted()), + this, SLOT(updateConfigurations())); + connect(engine, SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer))); + connect(engine, SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationRemoved(QNetworkConfigurationPrivatePointer))); + connect(engine, SIGNAL(configurationChanged(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationChanged(QNetworkConfigurationPrivatePointer))); + + capFlags |= engine->capabilities(); } } } diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index a45d534..d7a813b 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -67,7 +67,6 @@ public: QNetworkConfigurationManagerPrivate() : QObject(0), capFlags(0), firstUpdate(true) { - registerPlatformCapabilities(); updateConfigurations(); } @@ -76,7 +75,6 @@ public: QNetworkConfiguration defaultConfiguration(); QNetworkConfigurationManager::Capabilities capFlags; - void registerPlatformCapabilities(); void performAsyncConfigurationUpdate(); diff --git a/src/network/bearer/qnetworkconfigmanager_s60_p.cpp b/src/network/bearer/qnetworkconfigmanager_s60_p.cpp deleted file mode 100644 index b5bd4d2..0000000 --- a/src/network/bearer/qnetworkconfigmanager_s60_p.cpp +++ /dev/null @@ -1,974 +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 "qnetworkconfigmanager_s60_p.h" - -#include -#include -#include - -#ifdef SNAP_FUNCTIONALITY_AVAILABLE - #include - #include - #include - #include - #include - #include -#else - #include - #include - #include -#endif - -QT_BEGIN_NAMESPACE - -static const int KValueThatWillBeAddedToSNAPId = 1000; -static const int KUserChoiceIAPId = 0; - -QNetworkConfigurationManagerPrivate::QNetworkConfigurationManagerPrivate() - : QObject(0), CActive(CActive::EPriorityIdle), capFlags(0), iFirstUpdate(true), iInitOk(true) -{ - CActiveScheduler::Add(this); - - registerPlatformCapabilities(); - TRAPD(error, ipCommsDB = CCommsDatabase::NewL(EDatabaseTypeIAP)); - if (error != KErrNone) { - iInitOk = false; - return; - } - - TRAP_IGNORE(iConnectionMonitor.ConnectL()); - TRAP_IGNORE(iConnectionMonitor.NotifyEventL(*this)); - -#ifdef SNAP_FUNCTIONALITY_AVAILABLE - TRAP(error, iCmManager.OpenL()); - if (error != KErrNone) { - iInitOk = false; - return; - } -#endif - - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - cpPriv->name = "UserChoice"; - cpPriv->bearer = QNetworkConfigurationPrivate::BearerUnknown; - cpPriv->state = QNetworkConfiguration::Discovered; - cpPriv->isValid = true; - cpPriv->id = QString::number(qHash(KUserChoiceIAPId)); - cpPriv->numericId = KUserChoiceIAPId; - cpPriv->connectionId = 0; - cpPriv->type = QNetworkConfiguration::UserChoice; - cpPriv->purpose = QNetworkConfiguration::UnknownPurpose; - cpPriv->roamingSupported = false; - cpPriv->manager = this; - QExplicitlySharedDataPointer ptr(cpPriv); - userChoiceConfigurations.insert(cpPriv->id, ptr); - - updateConfigurations(); - updateStatesToSnaps(); - - // Start monitoring IAP and/or SNAP changes in Symbian CommsDB - startCommsDatabaseNotifications(); -} - -QNetworkConfigurationManagerPrivate::~QNetworkConfigurationManagerPrivate() -{ - Cancel(); - - QList configIdents = snapConfigurations.keys(); - foreach(QString oldIface, configIdents) { - QExplicitlySharedDataPointer priv = snapConfigurations.take(oldIface); - priv->isValid = false; - priv->id.clear(); - } - - configIdents = accessPointConfigurations.keys(); - foreach(QString oldIface, configIdents) { - QExplicitlySharedDataPointer priv = accessPointConfigurations.take(oldIface); - priv->isValid = false; - priv->id.clear(); - } - - configIdents = userChoiceConfigurations.keys(); - foreach(QString oldIface, configIdents) { - QExplicitlySharedDataPointer priv = userChoiceConfigurations.take(oldIface); - priv->isValid = false; - priv->id.clear(); - priv->manager = 0; - } - - iConnectionMonitor.CancelNotifications(); - iConnectionMonitor.Close(); - -#ifdef SNAP_FUNCTIONALITY_AVAILABLE - iCmManager.Close(); -#endif - - delete ipAccessPointsAvailabilityScanner; - delete ipCommsDB; -} - - -void QNetworkConfigurationManagerPrivate::registerPlatformCapabilities() -{ - capFlags |= QNetworkConfigurationManager::CanStartAndStopInterfaces; - capFlags |= QNetworkConfigurationManager::DirectConnectionRouting; - capFlags |= QNetworkConfigurationManager::SystemSessionSupport; -#ifdef SNAP_FUNCTIONALITY_AVAILABLE - capFlags |= QNetworkConfigurationManager::ApplicationLevelRoaming; - capFlags |= QNetworkConfigurationManager::ForcedRoaming; -#endif - capFlags |= QNetworkConfigurationManager::DataStatistics; -} - -void QNetworkConfigurationManagerPrivate::performAsyncConfigurationUpdate() -{ - if (!iInitOk || iUpdateGoingOn) { - return; - } - iUpdateGoingOn = true; - - stopCommsDatabaseNotifications(); - updateConfigurations(); // Synchronous call - updateAvailableAccessPoints(); // Asynchronous call -} - -void QNetworkConfigurationManagerPrivate::updateConfigurations() -{ - if (!iInitOk) { - return; - } - - TRAP_IGNORE(updateConfigurationsL()); -} - -void QNetworkConfigurationManagerPrivate::updateConfigurationsL() -{ - QList knownConfigs = accessPointConfigurations.keys(); - QList knownSnapConfigs = snapConfigurations.keys(); - -#ifdef SNAP_FUNCTIONALITY_AVAILABLE - // S60 version is >= Series60 3rd Edition Feature Pack 2 - TInt error = KErrNone; - - // Loop through all IAPs - RArray connectionMethods; // IAPs - CleanupClosePushL(connectionMethods); - iCmManager.ConnectionMethodL(connectionMethods); - for(int i = 0; i < connectionMethods.Count(); i++) { - RCmConnectionMethod connectionMethod = iCmManager.ConnectionMethodL(connectionMethods[i]); - CleanupClosePushL(connectionMethod); - TUint32 iapId = connectionMethod.GetIntAttributeL(CMManager::ECmIapId); - QString ident = QString::number(qHash(iapId)); - if (accessPointConfigurations.contains(ident)) { - knownConfigs.removeOne(ident); - } else { - QNetworkConfigurationPrivate* cpPriv = NULL; - TRAP(error, cpPriv = configFromConnectionMethodL(connectionMethod)); - if (error == KErrNone) { - QExplicitlySharedDataPointer ptr(cpPriv); - accessPointConfigurations.insert(cpPriv->id, ptr); - if (!iFirstUpdate) { - QNetworkConfiguration item; - item.d = ptr; - emit configurationAdded(item); - } - } - } - CleanupStack::PopAndDestroy(&connectionMethod); - } - CleanupStack::PopAndDestroy(&connectionMethods); - - // Loop through all SNAPs - RArray destinations; - CleanupClosePushL(destinations); - iCmManager.AllDestinationsL(destinations); - for(int i = 0; i < destinations.Count(); i++) { - RCmDestination destination; - destination = iCmManager.DestinationL(destinations[i]); - CleanupClosePushL(destination); - QString ident = QString::number(qHash(destination.Id()+KValueThatWillBeAddedToSNAPId)); //TODO: Check if it's ok to add 1000 SNAP Id to prevent SNAP ids overlapping IAP ids - if (snapConfigurations.contains(ident)) { - knownSnapConfigs.removeOne(ident); - } else { - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - CleanupStack::PushL(cpPriv); - - HBufC *pName = destination.NameLC(); - cpPriv->name = QString::fromUtf16(pName->Ptr(),pName->Length()); - CleanupStack::PopAndDestroy(pName); - pName = NULL; - - cpPriv->isValid = true; - cpPriv->id = ident; - cpPriv->numericId = destination.Id(); - cpPriv->connectionId = 0; - cpPriv->state = QNetworkConfiguration::Defined; - cpPriv->type = QNetworkConfiguration::ServiceNetwork; - cpPriv->purpose = QNetworkConfiguration::UnknownPurpose; - cpPriv->roamingSupported = false; - cpPriv->manager = this; - - QExplicitlySharedDataPointer ptr(cpPriv); - snapConfigurations.insert(ident, ptr); - if (!iFirstUpdate) { - QNetworkConfiguration item; - item.d = ptr; - emit configurationAdded(item); - } - - CleanupStack::Pop(cpPriv); - } - QExplicitlySharedDataPointer privSNAP = snapConfigurations.value(ident); - - for (int j=0; j < destination.ConnectionMethodCount(); j++) { - RCmConnectionMethod connectionMethod = destination.ConnectionMethodL(j); - CleanupClosePushL(connectionMethod); - - TUint32 iapId = connectionMethod.GetIntAttributeL(CMManager::ECmIapId); - QString iface = QString::number(qHash(iapId)); - // Check that IAP can be found from accessPointConfigurations list - QExplicitlySharedDataPointer priv = accessPointConfigurations.value(iface); - if (priv.data() == 0) { - QNetworkConfigurationPrivate* cpPriv = NULL; - TRAP(error, cpPriv = configFromConnectionMethodL(connectionMethod)); - if (error == KErrNone) { - QExplicitlySharedDataPointer ptr(cpPriv); - ptr.data()->serviceNetworkPtr = privSNAP; - accessPointConfigurations.insert(cpPriv->id, ptr); - if (!iFirstUpdate) { - QNetworkConfiguration item; - item.d = ptr; - emit configurationAdded(item); - } - privSNAP->serviceNetworkMembers.append(ptr); - } - } else { - knownConfigs.removeOne(iface); - // Check that IAP can be found from related SNAP's configuration list - bool iapFound = false; - for (int i=0; iserviceNetworkMembers.count(); i++) { - if (privSNAP->serviceNetworkMembers[i]->numericId == iapId) { - iapFound = true; - break; - } - } - if (!iapFound) { - priv.data()->serviceNetworkPtr = privSNAP; - privSNAP->serviceNetworkMembers.append(priv); - } - } - - CleanupStack::PopAndDestroy(&connectionMethod); - } - - if (privSNAP->serviceNetworkMembers.count() > 1) { - // Roaming is supported only if SNAP contains more than one IAP - privSNAP->roamingSupported = true; - } - - CleanupStack::PopAndDestroy(&destination); - } - CleanupStack::PopAndDestroy(&destinations); - -#else - // S60 version is < Series60 3rd Edition Feature Pack 2 - CCommsDbTableView* pDbTView = ipCommsDB->OpenTableLC(TPtrC(IAP)); - - // Loop through all IAPs - TUint32 apId = 0; - TInt retVal = pDbTView->GotoFirstRecord(); - while (retVal == KErrNone) { - pDbTView->ReadUintL(TPtrC(COMMDB_ID), apId); - QString ident = QString::number(qHash(apId)); - if (accessPointConfigurations.contains(ident)) { - knownConfigs.removeOne(ident); - } else { - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - if (readNetworkConfigurationValuesFromCommsDb(apId, cpPriv)) { - QExplicitlySharedDataPointer ptr(cpPriv); - accessPointConfigurations.insert(ident, ptr); - if (!iFirstUpdate) { - QNetworkConfiguration item; - item.d = ptr; - emit configurationAdded(item); - } - } else { - delete cpPriv; - } - } - retVal = pDbTView->GotoNextRecord(); - } - CleanupStack::PopAndDestroy(pDbTView); -#endif - updateActiveAccessPoints(); - - foreach (QString oldIface, knownConfigs) { - //remove non existing IAP - QExplicitlySharedDataPointer priv = accessPointConfigurations.take(oldIface); - priv->isValid = false; - if (!iFirstUpdate) { - QNetworkConfiguration item; - item.d = priv; - emit configurationRemoved(item); - } - // Remove non existing IAP from SNAPs - QList snapConfigIdents = snapConfigurations.keys(); - foreach (QString iface, snapConfigIdents) { - QExplicitlySharedDataPointer priv2 = snapConfigurations.value(iface); - // => Check if one of the IAPs of the SNAP is active - for (int i=0; iserviceNetworkMembers.count(); i++) { - if (priv2->serviceNetworkMembers[i]->numericId == priv->numericId) { - priv2->serviceNetworkMembers.removeAt(i); - break; - } - } - } - } - foreach (QString oldIface, knownSnapConfigs) { - //remove non existing SNAPs - QExplicitlySharedDataPointer priv = snapConfigurations.take(oldIface); - priv->isValid = false; - if (!iFirstUpdate) { - QNetworkConfiguration item; - item.d = priv; - emit configurationRemoved(item); - } - } - - iFirstUpdate = false; -} - -#ifdef SNAP_FUNCTIONALITY_AVAILABLE -QNetworkConfigurationPrivate* QNetworkConfigurationManagerPrivate::configFromConnectionMethodL( - RCmConnectionMethod& connectionMethod) -{ - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - CleanupStack::PushL(cpPriv); - - TUint32 iapId = connectionMethod.GetIntAttributeL(CMManager::ECmIapId); - QString ident = QString::number(qHash(iapId)); - - HBufC *pName = connectionMethod.GetStringAttributeL(CMManager::ECmName); - CleanupStack::PushL(pName); - cpPriv->name = QString::fromUtf16(pName->Ptr(),pName->Length()); - CleanupStack::PopAndDestroy(pName); - pName = NULL; - - TUint32 bearerId = connectionMethod.GetIntAttributeL(CMManager::ECmCommsDBBearerType); - switch (bearerId) { - case KCommDbBearerCSD: - cpPriv->bearer = QNetworkConfigurationPrivate::Bearer2G; - break; - case KCommDbBearerWcdma: - cpPriv->bearer = QNetworkConfigurationPrivate::BearerWCDMA; - break; - case KCommDbBearerLAN: - cpPriv->bearer = QNetworkConfigurationPrivate::BearerEthernet; - break; - case KCommDbBearerVirtual: - cpPriv->bearer = QNetworkConfigurationPrivate::BearerUnknown; - break; - case KCommDbBearerPAN: - cpPriv->bearer = QNetworkConfigurationPrivate::BearerUnknown; - break; - case KCommDbBearerWLAN: - cpPriv->bearer = QNetworkConfigurationPrivate::BearerWLAN; - break; - default: - cpPriv->bearer = QNetworkConfigurationPrivate::BearerUnknown; - break; - } - - TInt error = KErrNone; - TUint32 bearerType = connectionMethod.GetIntAttributeL(CMManager::ECmBearerType); - switch (bearerType) { - case KUidPacketDataBearerType: - // "Packet data" Bearer => Mapping is done using "Access point name" - TRAP(error, pName = connectionMethod.GetStringAttributeL(CMManager::EPacketDataAPName)); - break; - case KUidWlanBearerType: - // "Wireless LAN" Bearer => Mapping is done using "WLAN network name" = SSID - TRAP(error, pName = connectionMethod.GetStringAttributeL(CMManager::EWlanSSID)); - break; - } - if (!pName) { - // "Data call" Bearer or "High Speed (GSM)" Bearer => Mapping is done using "Dial-up number" - TRAP(error, pName = connectionMethod.GetStringAttributeL(CMManager::EDialDefaultTelNum)); - } - - if (error == KErrNone && pName) { - CleanupStack::PushL(pName); - cpPriv->mappingName = QString::fromUtf16(pName->Ptr(),pName->Length()); - CleanupStack::PopAndDestroy(pName); - pName = NULL; - } - - cpPriv->state = QNetworkConfiguration::Defined; - TBool isConnected = connectionMethod.GetBoolAttributeL(CMManager::ECmConnected); - if (isConnected) { - cpPriv->state = QNetworkConfiguration::Active; - } - - cpPriv->isValid = true; - cpPriv->id = ident; - cpPriv->numericId = iapId; - cpPriv->connectionId = 0; - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - cpPriv->purpose = QNetworkConfiguration::UnknownPurpose; - cpPriv->roamingSupported = false; - cpPriv->manager = this; - - CleanupStack::Pop(cpPriv); - return cpPriv; -} -#else -bool QNetworkConfigurationManagerPrivate::readNetworkConfigurationValuesFromCommsDb( - TUint32 aApId, QNetworkConfigurationPrivate* apNetworkConfiguration) -{ - TRAPD(error, readNetworkConfigurationValuesFromCommsDbL(aApId,apNetworkConfiguration)); - if (error != KErrNone) { - return false; - } - return true; -} - -void QNetworkConfigurationManagerPrivate::readNetworkConfigurationValuesFromCommsDbL( - TUint32 aApId, QNetworkConfigurationPrivate* apNetworkConfiguration) -{ - CApDataHandler* pDataHandler = CApDataHandler::NewLC(*ipCommsDB); - CApAccessPointItem* pAPItem = CApAccessPointItem::NewLC(); - TBuf name; - - CApUtils* pApUtils = CApUtils::NewLC(*ipCommsDB); - TUint32 apId = pApUtils->WapIdFromIapIdL(aApId); - - pDataHandler->AccessPointDataL(apId,*pAPItem); - pAPItem->ReadTextL(EApIapName, name); - if (name.Compare(_L("Easy WLAN")) == 0) { - // "Easy WLAN" won't be accepted to the Configurations list - User::Leave(KErrNotFound); - } - - QString ident = QString::number(qHash(aApId)); - - apNetworkConfiguration->name = QString::fromUtf16(name.Ptr(),name.Length()); - apNetworkConfiguration->isValid = true; - apNetworkConfiguration->id = ident; - apNetworkConfiguration->numericId = aApId; - apNetworkConfiguration->connectionId = 0; - apNetworkConfiguration->state = (QNetworkConfiguration::Defined); - apNetworkConfiguration->type = QNetworkConfiguration::InternetAccessPoint; - apNetworkConfiguration->purpose = QNetworkConfiguration::UnknownPurpose; - apNetworkConfiguration->roamingSupported = false; - switch (pAPItem->BearerTypeL()) { - case EApBearerTypeCSD: - apNetworkConfiguration->bearer = QNetworkConfigurationPrivate::Bearer2G; - break; - case EApBearerTypeGPRS: - apNetworkConfiguration->bearer = QNetworkConfigurationPrivate::Bearer2G; - break; - case EApBearerTypeHSCSD: - apNetworkConfiguration->bearer = QNetworkConfigurationPrivate::BearerHSPA; - break; - case EApBearerTypeCDMA: - apNetworkConfiguration->bearer = QNetworkConfigurationPrivate::BearerCDMA2000; - break; - case EApBearerTypeWLAN: - apNetworkConfiguration->bearer = QNetworkConfigurationPrivate::BearerWLAN; - break; - case EApBearerTypeLAN: - apNetworkConfiguration->bearer = QNetworkConfigurationPrivate::BearerEthernet; - break; - case EApBearerTypeLANModem: - apNetworkConfiguration->bearer = QNetworkConfigurationPrivate::BearerEthernet; - break; - default: - apNetworkConfiguration->bearer = QNetworkConfigurationPrivate::BearerUnknown; - break; - } - apNetworkConfiguration->manager = this; - - CleanupStack::PopAndDestroy(pApUtils); - CleanupStack::PopAndDestroy(pAPItem); - CleanupStack::PopAndDestroy(pDataHandler); -} -#endif - -QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration() -{ - QNetworkConfiguration config; - - if (iInitOk) { - stopCommsDatabaseNotifications(); - TRAP_IGNORE(config = defaultConfigurationL()); - startCommsDatabaseNotifications(); - } - - return config; -} - -QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfigurationL() -{ - QNetworkConfiguration item; - -#ifdef SNAP_FUNCTIONALITY_AVAILABLE - // Check Default Connection (SNAP or IAP) - TCmDefConnValue defaultConnectionValue; - iCmManager.ReadDefConnL(defaultConnectionValue); - if (defaultConnectionValue.iType == ECmDefConnDestination) { - QString iface = QString::number(qHash(defaultConnectionValue.iId+KValueThatWillBeAddedToSNAPId)); - QExplicitlySharedDataPointer priv = snapConfigurations.value(iface); - if (priv.data() != 0) { - item.d = priv; - } - } else if (defaultConnectionValue.iType == ECmDefConnConnectionMethod) { - QString iface = QString::number(qHash(defaultConnectionValue.iId)); - QExplicitlySharedDataPointer priv = accessPointConfigurations.value(iface); - if (priv.data() != 0) { - item.d = priv; - } - } -#endif - - if (!item.isValid()) { - QString iface = QString::number(qHash(KUserChoiceIAPId)); - QExplicitlySharedDataPointer priv = userChoiceConfigurations.value(iface); - if (priv.data() != 0) { - item.d = priv; - } - } - - return item; -} - -void QNetworkConfigurationManagerPrivate::updateActiveAccessPoints() -{ - bool online = false; - QList inactiveConfigs = accessPointConfigurations.keys(); - - TRequestStatus status; - TUint connectionCount; - iConnectionMonitor.GetConnectionCount(connectionCount, status); - User::WaitForRequest(status); - - // Go through all connections and set state of related IAPs to Active - TUint connectionId; - TUint subConnectionCount; - TUint apId; - if (status.Int() == KErrNone) { - for (TUint i = 1; i <= connectionCount; i++) { - iConnectionMonitor.GetConnectionInfo(i, connectionId, subConnectionCount); - iConnectionMonitor.GetUintAttribute(connectionId, subConnectionCount, KIAPId, apId, status); - User::WaitForRequest(status); - QString ident = QString::number(qHash(apId)); - QExplicitlySharedDataPointer priv = accessPointConfigurations.value(ident); - if (priv.data()) { - online = true; - inactiveConfigs.removeOne(ident); - priv.data()->connectionId = connectionId; - // Configuration is Active - changeConfigurationStateTo(priv, QNetworkConfiguration::Active); - } - } - } - - // Make sure that state of rest of the IAPs won't be Active - foreach (QString iface, inactiveConfigs) { - QExplicitlySharedDataPointer priv = accessPointConfigurations.value(iface); - if (priv.data()) { - // Configuration is either Defined or Discovered - changeConfigurationStateAtMaxTo(priv, QNetworkConfiguration::Discovered); - } - } - - if (iOnline != online) { - iOnline = online; - emit this->onlineStateChanged(iOnline); - } -} - -void QNetworkConfigurationManagerPrivate::updateAvailableAccessPoints() -{ - if (!ipAccessPointsAvailabilityScanner) { - ipAccessPointsAvailabilityScanner = new AccessPointsAvailabilityScanner(*this, iConnectionMonitor); - } - if (ipAccessPointsAvailabilityScanner) { - // Scanning may take a while because WLAN scanning will be done (if device supports WLAN). - ipAccessPointsAvailabilityScanner->StartScanning(); - } -} - -void QNetworkConfigurationManagerPrivate::accessPointScanningReady(TBool scanSuccessful, TConnMonIapInfo iapInfo) -{ - iUpdateGoingOn = false; - if (scanSuccessful) { - QList unavailableConfigs = accessPointConfigurations.keys(); - - // Set state of returned IAPs to Discovered - // if state is not already Active - for(TUint i=0; i priv = accessPointConfigurations.value(ident); - if (priv.data()) { - unavailableConfigs.removeOne(ident); - if (priv.data()->state < QNetworkConfiguration::Active) { - // Configuration is either Discovered or Active - changeConfigurationStateAtMinTo(priv, QNetworkConfiguration::Discovered); - } - } - } - - // Make sure that state of rest of the IAPs won't be Discovered or Active - foreach (QString iface, unavailableConfigs) { - QExplicitlySharedDataPointer priv = accessPointConfigurations.value(iface); - if (priv.data()) { - // Configuration is Defined - changeConfigurationStateAtMaxTo(priv, QNetworkConfiguration::Defined); - } - } - } - - updateStatesToSnaps(); - - startCommsDatabaseNotifications(); - - emit this->configurationUpdateComplete(); -} - -void QNetworkConfigurationManagerPrivate::updateStatesToSnaps() -{ - // Go through SNAPs and set correct state to SNAPs - QList snapConfigIdents = snapConfigurations.keys(); - foreach (QString iface, snapConfigIdents) { - bool discovered = false; - bool active = false; - QExplicitlySharedDataPointer priv = snapConfigurations.value(iface); - // => Check if one of the IAPs of the SNAP is discovered or active - // => If one of IAPs is active, also SNAP is active - // => If one of IAPs is discovered but none of the IAPs is active, SNAP is discovered - for (int i=0; iserviceNetworkMembers.count(); i++) { - QExplicitlySharedDataPointer priv2 = priv->serviceNetworkMembers[i]; - if ((priv->serviceNetworkMembers[i]->state & QNetworkConfiguration::Active) - == QNetworkConfiguration::Active) { - active = true; - break; - } else if ((priv->serviceNetworkMembers[i]->state & QNetworkConfiguration::Discovered) - == QNetworkConfiguration::Discovered) { - discovered = true; - } - } - if (active) { - changeConfigurationStateTo(priv, QNetworkConfiguration::Active); - } else if (discovered) { - changeConfigurationStateTo(priv, QNetworkConfiguration::Discovered); - } else { - changeConfigurationStateTo(priv, QNetworkConfiguration::Defined); - } - } -} - -bool QNetworkConfigurationManagerPrivate::changeConfigurationStateTo(QExplicitlySharedDataPointer& sharedData, - QNetworkConfiguration::StateFlags newState) -{ - if (newState != sharedData.data()->state) { - sharedData.data()->state = newState; - QNetworkConfiguration item; - item.d = sharedData; - if (!iFirstUpdate) { - emit configurationChanged(item); - } - return true; - } - return false; -} - -/* changeConfigurationStateAtMinTo function does not overwrite possible better - * state (e.g. Discovered state does not overwrite Active state) but - * makes sure that state is at minimum given state. -*/ -bool QNetworkConfigurationManagerPrivate::changeConfigurationStateAtMinTo(QExplicitlySharedDataPointer& sharedData, - QNetworkConfiguration::StateFlags newState) -{ - if ((newState | sharedData.data()->state) != sharedData.data()->state) { - sharedData.data()->state = (sharedData.data()->state | newState); - QNetworkConfiguration item; - item.d = sharedData; - if (!iFirstUpdate) { - emit configurationChanged(item); - } - return true; - } - return false; -} - -/* changeConfigurationStateAtMaxTo function overwrites possible better - * state (e.g. Discovered state overwrites Active state) and - * makes sure that state is at maximum given state (e.g. Discovered state - * does not overwrite Defined state). -*/ -bool QNetworkConfigurationManagerPrivate::changeConfigurationStateAtMaxTo(QExplicitlySharedDataPointer& sharedData, - QNetworkConfiguration::StateFlags newState) -{ - if ((newState & sharedData.data()->state) != sharedData.data()->state) { - sharedData.data()->state = (newState & sharedData.data()->state); - QNetworkConfiguration item; - item.d = sharedData; - if (!iFirstUpdate) { - emit configurationChanged(item); - } - return true; - } - return false; -} - -void QNetworkConfigurationManagerPrivate::startCommsDatabaseNotifications() -{ - if (!iWaitingCommsDatabaseNotifications) { - iWaitingCommsDatabaseNotifications = ETrue; - if (!IsActive()) { - SetActive(); - // Start waiting for new notification - ipCommsDB->RequestNotification(iStatus); - } - } -} - -void QNetworkConfigurationManagerPrivate::stopCommsDatabaseNotifications() -{ - if (iWaitingCommsDatabaseNotifications) { - iWaitingCommsDatabaseNotifications = EFalse; - if (!IsActive()) { - SetActive(); - // Make sure that notifier recorded events will not be returned - // as soon as the client issues the next RequestNotification() request. - ipCommsDB->RequestNotification(iStatus); - ipCommsDB->CancelRequestNotification(); - } else { - ipCommsDB->CancelRequestNotification(); - } - } -} - -void QNetworkConfigurationManagerPrivate::RunL() -{ - if (iStatus != KErrCancel) { - RDbNotifier::TEvent event = STATIC_CAST(RDbNotifier::TEvent, iStatus.Int()); - switch (event) { - case RDbNotifier::EUnlock: /** All read locks have been removed. */ - case RDbNotifier::ECommit: /** A transaction has been committed. */ - case RDbNotifier::ERollback: /** A transaction has been rolled back */ - case RDbNotifier::ERecover: /** The database has been recovered */ - // Note that if further database events occur while a client is handling - // a request completion, the notifier records the most significant database - // event and this is signalled as soon as the client issues the next - // RequestNotification() request. - // => Stop recording notifications - stopCommsDatabaseNotifications(); - TRAPD(error, updateConfigurationsL()); - if (error == KErrNone) { - updateStatesToSnaps(); - } - iWaitingCommsDatabaseNotifications = true; - break; - default: - // Do nothing - break; - } - } - - if (iWaitingCommsDatabaseNotifications) { - if (!IsActive()) { - SetActive(); - // Start waiting for new notification - ipCommsDB->RequestNotification(iStatus); - } - } -} - -void QNetworkConfigurationManagerPrivate::DoCancel() -{ - ipCommsDB->CancelRequestNotification(); -} - - -void QNetworkConfigurationManagerPrivate::EventL(const CConnMonEventBase& aEvent) -{ - switch (aEvent.EventType()) { - case EConnMonCreateConnection: - { - CConnMonCreateConnection* realEvent; - realEvent = (CConnMonCreateConnection*) &aEvent; - TUint subConnectionCount = 0; - TUint apId; - TUint connectionId = realEvent->ConnectionId(); - TRequestStatus status; - iConnectionMonitor.GetUintAttribute(connectionId, subConnectionCount, KIAPId, apId, status); - User::WaitForRequest(status); - QString ident = QString::number(qHash(apId)); - QExplicitlySharedDataPointer priv = accessPointConfigurations.value(ident); - if (priv.data()) { - priv.data()->connectionId = connectionId; - // Configuration is Active - if (changeConfigurationStateTo(priv, QNetworkConfiguration::Active)) { - updateStatesToSnaps(); - } - if (!iOnline) { - iOnline = true; - emit this->onlineStateChanged(iOnline); - } - } - } - break; - - case EConnMonDeleteConnection: - { - CConnMonDeleteConnection* realEvent; - realEvent = (CConnMonDeleteConnection*) &aEvent; - TUint connectionId = realEvent->ConnectionId(); - QExplicitlySharedDataPointer priv = dataByConnectionId(connectionId); - if (priv.data()) { - priv.data()->connectionId = 0; - // Configuration is either Defined or Discovered - if (changeConfigurationStateAtMaxTo(priv, QNetworkConfiguration::Discovered)) { - updateStatesToSnaps(); - } - } - - bool online = false; - QList iapConfigs = accessPointConfigurations.keys(); - foreach (QString iface, iapConfigs) { - QExplicitlySharedDataPointer priv = accessPointConfigurations.value(iface); - if (priv.data()->state == QNetworkConfiguration::Active) { - online = true; - break; - } - } - if (iOnline != online) { - iOnline = online; - emit this->onlineStateChanged(iOnline); - } - } - break; - - case EConnMonIapAvailabilityChange: - { - CConnMonIapAvailabilityChange* realEvent; - realEvent = (CConnMonIapAvailabilityChange*) &aEvent; - TConnMonIapInfo iaps = realEvent->IapAvailability(); - QList unDiscoveredConfigs = accessPointConfigurations.keys(); - for ( TUint i = 0; i < iaps.Count(); i++ ) { - QString ident = QString::number(qHash(iaps.iIap[i].iIapId)); - QExplicitlySharedDataPointer priv = accessPointConfigurations.value(ident); - if (priv.data()) { - // Configuration is either Discovered or Active - changeConfigurationStateAtMinTo(priv, QNetworkConfiguration::Discovered); - unDiscoveredConfigs.removeOne(ident); - } - } - foreach (QString iface, unDiscoveredConfigs) { - QExplicitlySharedDataPointer priv = accessPointConfigurations.value(iface); - if (priv.data()) { - // Configuration is Defined - changeConfigurationStateAtMaxTo(priv, QNetworkConfiguration::Defined); - } - } - } - break; - - default: - // For unrecognized events - break; - } -} - -QExplicitlySharedDataPointer QNetworkConfigurationManagerPrivate::dataByConnectionId(TUint aConnectionId) -{ - QNetworkConfiguration item; - - QHash >::const_iterator i = - accessPointConfigurations.constBegin(); - while (i != accessPointConfigurations.constEnd()) { - QExplicitlySharedDataPointer priv = i.value(); - if (priv.data()->connectionId == aConnectionId) { - return priv; - } - ++i; - } - - return QExplicitlySharedDataPointer(); -} - -AccessPointsAvailabilityScanner::AccessPointsAvailabilityScanner(QNetworkConfigurationManagerPrivate& owner, - RConnectionMonitor& connectionMonitor) - : CActive(CActive::EPriorityStandard), iOwner(owner), iConnectionMonitor(connectionMonitor) -{ - CActiveScheduler::Add(this); -} - -AccessPointsAvailabilityScanner::~AccessPointsAvailabilityScanner() -{ - Cancel(); -} - -void AccessPointsAvailabilityScanner::DoCancel() -{ - iConnectionMonitor.CancelAsyncRequest(EConnMonGetPckgAttribute); -} - -void AccessPointsAvailabilityScanner::StartScanning() -{ - iConnectionMonitor.GetPckgAttribute(EBearerIdAll, 0, KIapAvailability, iIapBuf, iStatus); - if (!IsActive()) { - SetActive(); - } -} - -void AccessPointsAvailabilityScanner::RunL() -{ - if (iStatus.Int() != KErrNone) { - iIapBuf().iCount = 0; - iOwner.accessPointScanningReady(false,iIapBuf()); - } else { - iOwner.accessPointScanningReady(true,iIapBuf()); - } -} -#include "moc_qnetworkconfigmanager_s60_p.cpp" -QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworkconfigmanager_s60_p.h b/src/network/bearer/qnetworkconfigmanager_s60_p.h deleted file mode 100644 index 3378898..0000000 --- a/src/network/bearer/qnetworkconfigmanager_s60_p.h +++ /dev/null @@ -1,185 +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 purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include "qnetworkconfiguration_s60_p.h" - -#include -#include -#ifdef SNAP_FUNCTIONALITY_AVAILABLE - #include -#endif - -class CCommsDatabase; - -QT_BEGIN_NAMESPACE -class QTimer; -QT_END_NAMESPACE - -QT_BEGIN_NAMESPACE - -class QNetworkSessionPrivate; -class AccessPointsAvailabilityScanner; - -class QNetworkConfigurationManagerPrivate : public QObject, public CActive, public MConnectionMonitorObserver -{ - Q_OBJECT - -public: - QNetworkConfigurationManagerPrivate(); - virtual ~QNetworkConfigurationManagerPrivate(); - - QNetworkConfiguration defaultConfiguration(); - void performAsyncConfigurationUpdate(); - -Q_SIGNALS: - void configurationAdded(const QNetworkConfiguration& config); - void configurationRemoved(const QNetworkConfiguration& config); - void configurationUpdateComplete(); - void configurationChanged(const QNetworkConfiguration& config); - void onlineStateChanged(bool isOnline); - -public Q_SLOTS: - void updateConfigurations(); - -private: - void registerPlatformCapabilities(); - void updateStatesToSnaps(); - bool changeConfigurationStateTo(QExplicitlySharedDataPointer& sharedData, - QNetworkConfiguration::StateFlags newState); - bool changeConfigurationStateAtMinTo(QExplicitlySharedDataPointer& sharedData, - QNetworkConfiguration::StateFlags newState); - bool changeConfigurationStateAtMaxTo(QExplicitlySharedDataPointer& sharedData, - QNetworkConfiguration::StateFlags newState); -#ifdef SNAP_FUNCTIONALITY_AVAILABLE - QNetworkConfigurationPrivate* configFromConnectionMethodL(RCmConnectionMethod& connectionMethod); -#else - bool readNetworkConfigurationValuesFromCommsDb( - TUint32 aApId, QNetworkConfigurationPrivate* apNetworkConfiguration); - void readNetworkConfigurationValuesFromCommsDbL( - TUint32 aApId, QNetworkConfigurationPrivate* apNetworkConfiguration); -#endif - - void updateConfigurationsL(); - void updateActiveAccessPoints(); - void updateAvailableAccessPoints(); - void accessPointScanningReady(TBool scanSuccessful, TConnMonIapInfo iapInfo); - void startCommsDatabaseNotifications(); - void stopCommsDatabaseNotifications(); - - QNetworkConfiguration defaultConfigurationL(); - TBool GetS60PlatformVersion(TUint& aMajor, TUint& aMinor) const; - void startMonitoringIAPData(TUint32 aIapId); - QExplicitlySharedDataPointer dataByConnectionId(TUint aConnectionId); - -protected: // From CActive - void RunL(); - void DoCancel(); - -private: // MConnectionMonitorObserver - void EventL(const CConnMonEventBase& aEvent); - -public: // Data - //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 > accessPointConfigurations; - QHash > snapConfigurations; - QHash > userChoiceConfigurations; - QNetworkConfigurationManager::Capabilities capFlags; - -private: // Data - bool iFirstUpdate; - CCommsDatabase* ipCommsDB; - RConnectionMonitor iConnectionMonitor; - - TBool iWaitingCommsDatabaseNotifications; - TBool iOnline; - TBool iInitOk; - TBool iUpdateGoingOn; - - - AccessPointsAvailabilityScanner* ipAccessPointsAvailabilityScanner; - - friend class QNetworkSessionPrivate; - friend class AccessPointsAvailabilityScanner; - -#ifdef SNAP_FUNCTIONALITY_AVAILABLE - RCmManager iCmManager; -#endif -}; - -class AccessPointsAvailabilityScanner : public CActive -{ -public: - AccessPointsAvailabilityScanner(QNetworkConfigurationManagerPrivate& owner, - RConnectionMonitor& connectionMonitor); - ~AccessPointsAvailabilityScanner(); - - void StartScanning(); - -protected: // From CActive - void RunL(); - void DoCancel(); - -private: // Data - QNetworkConfigurationManagerPrivate& iOwner; - RConnectionMonitor& iConnectionMonitor; - TConnMonIapInfoBuf iIapBuf; -}; - -QT_END_NAMESPACE - -#endif //QNETWORKCONFIGURATIONMANAGERPRIVATE_H diff --git a/src/network/bearer/qnetworkconfiguration.cpp b/src/network/bearer/qnetworkconfiguration.cpp index e1b2828..1585be1 100644 --- a/src/network/bearer/qnetworkconfiguration.cpp +++ b/src/network/bearer/qnetworkconfiguration.cpp @@ -41,11 +41,7 @@ #include "qnetworkconfiguration.h" -#ifdef Q_OS_SYMBIAN -#include "qnetworkconfiguration_s60_p.h" -#else #include "qnetworkconfiguration_p.h" -#endif QT_BEGIN_NAMESPACE diff --git a/src/network/bearer/qnetworkconfiguration_p.h b/src/network/bearer/qnetworkconfiguration_p.h index 68d6ba4..bfc42f5 100644 --- a/src/network/bearer/qnetworkconfiguration_p.h +++ b/src/network/bearer/qnetworkconfiguration_p.h @@ -92,7 +92,6 @@ public: bool internet; QList serviceNetworkMembers; - QNetworkInterface serviceInterface; private: diff --git a/src/network/bearer/qnetworkconfiguration_s60_p.cpp b/src/network/bearer/qnetworkconfiguration_s60_p.cpp index d01d4d9..142415a 100644 --- a/src/network/bearer/qnetworkconfiguration_s60_p.cpp +++ b/src/network/bearer/qnetworkconfiguration_s60_p.cpp @@ -39,24 +39,8 @@ ** ****************************************************************************/ -#include "qnetworkconfiguration_s60_p.h" - QT_BEGIN_NAMESPACE -QNetworkConfigurationPrivate::QNetworkConfigurationPrivate() - : isValid(false), type(QNetworkConfiguration::Invalid), - roamingSupported(false), purpose(QNetworkConfiguration::UnknownPurpose), - bearer(QNetworkConfigurationPrivate::BearerUnknown), numericId(0), - connectionId(0), manager(0) -{ -} - -QNetworkConfigurationPrivate::~QNetworkConfigurationPrivate() -{ - //release pointers to member configurations - serviceNetworkMembers.clear(); -} - QString QNetworkConfigurationPrivate::bearerName() const { switch (bearer) { @@ -72,5 +56,4 @@ QString QNetworkConfigurationPrivate::bearerName() const } } - QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworkconfiguration_s60_p.h b/src/network/bearer/qnetworkconfiguration_s60_p.h deleted file mode 100644 index 5e75c13..0000000 --- a/src/network/bearer/qnetworkconfiguration_s60_p.h +++ /dev/null @@ -1,109 +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 -#include - -QT_BEGIN_NAMESPACE - -class QNetworkConfigurationPrivate : public QSharedData -{ -public: - enum Bearer { - BearerEthernet, - BearerWLAN, - Bearer2G, - BearerCDMA2000, - BearerWCDMA, - BearerHSPA, - BearerBluetooth, - BearerWiMAX, - BearerUnknown = -1 - }; - - QNetworkConfigurationPrivate(); - ~QNetworkConfigurationPrivate(); - - QString name; - bool isValid; - QString id; - QNetworkConfiguration::StateFlags state; - QNetworkConfiguration::Type type; - bool roamingSupported; - QNetworkConfiguration::Purpose purpose; - - QList > serviceNetworkMembers; - - QNetworkConfigurationPrivate::Bearer bearer; - QString bearerName() const; - TUint32 numericId; - TUint connectionId; - - TAny* manager; - - QString mappingName; - - QExplicitlySharedDataPointer serviceNetworkPtr; - -private: - // disallow detaching - QNetworkConfigurationPrivate &operator=(const QNetworkConfigurationPrivate &other); - QNetworkConfigurationPrivate(const QNetworkConfigurationPrivate &other); -}; - -QT_END_NAMESPACE - -#endif //QNETWORKCONFIGURATIONPRIVATE_H - diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp index 74b9787..5f87d95 100644 --- a/src/network/bearer/qnetworksession.cpp +++ b/src/network/bearer/qnetworksession.cpp @@ -44,9 +44,7 @@ #include "qnetworksession.h" -#ifdef Q_OS_SYMBIAN -#include "qnetworksession_s60_p.h" -#elif Q_WS_MAEMO_6 +#if Q_WS_MAEMO_6 #include "qnetworksession_maemo_p.h" #else #include "qnetworksession_p.h" @@ -672,7 +670,7 @@ void QNetworkSession::connectNotify(const char *signal) QObject::connectNotify(signal); //check for preferredConfigurationChanged() signal connect notification //This is not required on all platforms -#ifdef Q_OS_SYMBIAN +#ifdef Q_OS_SYMBIAN_disabled if (qstrcmp(signal, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool))) == 0) { d->setALREnabled(true); } @@ -692,7 +690,7 @@ void QNetworkSession::disconnectNotify(const char *signal) QObject::disconnectNotify(signal); //check for preferredConfigurationChanged() signal disconnect notification //This is not required on all platforms -#ifdef Q_OS_SYMBIAN +#ifdef Q_OS_SYMBIAN_disabled if (qstrcmp(signal, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool))) == 0) { d->setALREnabled(false); } diff --git a/src/network/bearer/qnetworksessionengine.cpp b/src/network/bearer/qnetworksessionengine.cpp index 0aa9d19..0744add 100644 --- a/src/network/bearer/qnetworksessionengine.cpp +++ b/src/network/bearer/qnetworksessionengine.cpp @@ -61,6 +61,12 @@ QNetworkSessionEngine::~QNetworkSessionEngine() priv->isValid = false; priv->id.clear(); } + + foreach (const QString &oldIface, userChoiceConfigurations.keys()) { + QNetworkConfigurationPrivatePointer priv = userChoiceConfigurations.take(oldIface); + priv->isValid = false; + priv->id.clear(); + } } #include "moc_qnetworksessionengine_p.cpp" diff --git a/src/network/bearer/qnetworksessionengine_p.h b/src/network/bearer/qnetworksessionengine_p.h index 202a7dc..a1a3370 100644 --- a/src/network/bearer/qnetworksessionengine_p.h +++ b/src/network/bearer/qnetworksessionengine_p.h @@ -55,6 +55,7 @@ #include "qnetworkconfiguration_p.h" #include "qnetworksession.h" +#include "qnetworkconfigmanager.h" #include #include @@ -94,6 +95,8 @@ public: virtual QNetworkSession::State sessionStateForId(const QString &id) = 0; + virtual QNetworkConfigurationManager::Capabilities capabilities() const = 0; + public: //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 diff --git a/src/plugins/bearer/bearer.pro b/src/plugins/bearer/bearer.pro index 05fce8c..ab0a816 100644 --- a/src/plugins/bearer/bearer.pro +++ b/src/plugins/bearer/bearer.pro @@ -1,9 +1,10 @@ TEMPLATE = subdirs -!symbian:!maemo { +!maemo { SUBDIRS += generic contains(QT_CONFIG, dbus):contains(QT_CONFIG, networkmanager):SUBDIRS += networkmanager win32:SUBDIRS += nla win32:!wince*:SUBDIRS += nativewifi macx:SUBDIRS += corewlan +symbian:SUBDIRS += symbian } diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.h b/src/plugins/bearer/corewlan/qcorewlanengine.h index 45a5ee9..dd07d83 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.h +++ b/src/plugins/bearer/corewlan/qcorewlanengine.h @@ -71,6 +71,8 @@ public: QNetworkSession::State sessionStateForId(const QString &id); + QNetworkConfigurationManager::Capabilities capabilities() const; + static bool getAllScInterfaces(); private Q_SLOTS: diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm index 2a3fecf..7ee0723 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.mm +++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm @@ -512,4 +512,9 @@ QNetworkSession::State QCoreWlanEngine::sessionStateForId(const QString &id) return QNetworkSession::Invalid; } +QNetworkConfigurationManager::Capabilities QCoreWlanEngine::capabilities() const +{ + return QNetworkConfigurationManager::ForcedRoaming; +} + QT_END_NAMESPACE diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp index 9294fad..d50aa75 100644 --- a/src/plugins/bearer/generic/qgenericengine.cpp +++ b/src/plugins/bearer/generic/qgenericengine.cpp @@ -142,6 +142,8 @@ static QString qGetInterfaceType(const QString &interface) QGenericEngine::QGenericEngine(QObject *parent) : QNetworkSessionEngine(parent) { + qDebug() << Q_FUNC_INFO; + connect(&pollTimer, SIGNAL(timeout()), this, SLOT(doRequestUpdate())); pollTimer.setInterval(10000); doRequestUpdate(); @@ -314,5 +316,10 @@ QNetworkSession::State QGenericEngine::sessionStateForId(const QString &id) return QNetworkSession::Invalid; } +QNetworkConfigurationManager::Capabilities QGenericEngine::capabilities() const +{ + return QNetworkConfigurationManager::ForcedRoaming; +} + QT_END_NAMESPACE diff --git a/src/plugins/bearer/generic/qgenericengine.h b/src/plugins/bearer/generic/qgenericengine.h index a671ceb..730301b 100644 --- a/src/plugins/bearer/generic/qgenericengine.h +++ b/src/plugins/bearer/generic/qgenericengine.h @@ -71,6 +71,8 @@ public: QNetworkSession::State sessionStateForId(const QString &id); + QNetworkConfigurationManager::Capabilities capabilities() const; + private Q_SLOTS: void doRequestUpdate(); diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp index 0050770..82ddaf9 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp @@ -461,4 +461,10 @@ QNetworkSession::State QNativeWifiEngine::sessionStateForId(const QString &id) return QNetworkSession::Invalid; } +QNetworkConfigurationManager::Capabilities QNativeWifiEngine::capabilities() const +{ + return QNetworkConfigurationManager::ForcedRoaming | + QNetworkConfigurationManager::CanStartAndStopInterfaces; +} + QT_END_NAMESPACE diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.h b/src/plugins/bearer/nativewifi/qnativewifiengine.h index 511a6a4..9d92562 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.h +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.h @@ -82,6 +82,8 @@ public: QNetworkSession::State sessionStateForId(const QString &id); + QNetworkConfigurationManager::Capabilities capabilities() const; + inline bool available() const { return handle != 0; } public Q_SLOTS: diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp index 20dee1f..e1fcd46 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp @@ -667,5 +667,11 @@ QNetworkSession::State QNetworkManagerEngine::sessionStateForId(const QString &i return QNetworkSession::Invalid; } +QNetworkConfigurationManager::Capabilities QNetworkManagerEngine::capabilities() const +{ + return QNetworkConfigurationManager::ForcedRoaming | + QNetworkConfigurationManager::CanStartAndStopInterfaces; +} + QT_END_NAMESPACE diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h index 1636c91..3752dce 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h @@ -82,6 +82,8 @@ public: QNetworkSession::State sessionStateForId(const QString &id); + QNetworkConfigurationManager::Capabilities capabilities() const; + private Q_SLOTS: void interfacePropertiesChanged(const QString &path, const QMap &properties); diff --git a/src/plugins/bearer/nla/qnlaengine.cpp b/src/plugins/bearer/nla/qnlaengine.cpp index 51897f0..d3e3fd2 100644 --- a/src/plugins/bearer/nla/qnlaengine.cpp +++ b/src/plugins/bearer/nla/qnlaengine.cpp @@ -631,6 +631,11 @@ QNetworkSession::State QNlaEngine::sessionStateForId(const QString &id) return QNetworkSession::Invalid; } +QNetworkConfigurationManager::Capabilities QNlaEngine::capabilities() const +{ + return QNetworkConfigurationManager::ForcedRoaming; +} + #include "qnlaengine.moc" QT_END_NAMESPACE diff --git a/src/plugins/bearer/nla/qnlaengine.h b/src/plugins/bearer/nla/qnlaengine.h index dd038d1..5e80db1 100644 --- a/src/plugins/bearer/nla/qnlaengine.h +++ b/src/plugins/bearer/nla/qnlaengine.h @@ -93,6 +93,8 @@ public: QNetworkSession::State sessionStateForId(const QString &id); + QNetworkConfigurationManager::Capabilities capabilities() const; + private Q_SLOTS: void networksChanged(); diff --git a/src/plugins/bearer/symbian/main.cpp b/src/plugins/bearer/symbian/main.cpp new file mode 100644 index 0000000..8865f4d --- /dev/null +++ b/src/plugins/bearer/symbian/main.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** 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 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 "symbianengine.h" + +#include + +#include + +QT_BEGIN_NAMESPACE + +class QSymbianEnginePlugin : public QBearerEnginePlugin +{ +public: + QSymbianEnginePlugin(); + ~QSymbianEnginePlugin(); + + QStringList keys() const; + QBearerEngine *create(const QString &key) const; +}; + +QSymbianEnginePlugin::QSymbianEnginePlugin() +{ +} + +QSymbianEnginePlugin::~QSymbianEnginePlugin() +{ +} + +QStringList QSymbianEnginePlugin::keys() const +{ + return QStringList() << QLatin1String("symbian"); +} + +QBearerEngine *QSymbianEnginePlugin::create(const QString &key) const +{ + qDebug() << Q_FUNC_INFO; + + if (key == QLatin1String("symbian")) + return new SymbianEngine; + else + return 0; +} + +Q_EXPORT_STATIC_PLUGIN(QSymbianEnginePlugin) +Q_EXPORT_PLUGIN2(qsymbianbearer, QSymbianEnginePlugin) + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/symbian/symbian.pro b/src/plugins/bearer/symbian/symbian.pro new file mode 100644 index 0000000..d3ffb37 --- /dev/null +++ b/src/plugins/bearer/symbian/symbian.pro @@ -0,0 +1,33 @@ +TARGET = qsymbianbearer +include(../../qpluginbase.pri) + +QT += network + +HEADERS += symbianengine.h +SOURCES += symbianengine.cpp main.cpp + +exists($${EPOCROOT}epoc32/release/winscw/udeb/cmmanager.lib)| \ +exists($${EPOCROOT}epoc32/release/armv5/lib/cmmanager.lib) { + message("Building with SNAP support") + DEFINES += SNAP_FUNCTIONALITY_AVAILABLE + LIBS += -lcmmanager +} else { + message("Building without SNAP support") + LIBS += -lapengine +} + +INCLUDEPATH += $$APP_LAYER_SYSTEMINCLUDE + +LIBS += -lcommdb \ + -lapsettingshandlerui \ + -lconnmon \ + -lcentralrepository \ + -lesock \ + -linsock \ + -lecom \ + -lefsrv \ + -lnetmeta + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/bearer +target.path += $$[QT_INSTALL_PLUGINS]/bearer +INSTALLS += target diff --git a/src/plugins/bearer/symbian/symbianengine.cpp b/src/plugins/bearer/symbian/symbianengine.cpp new file mode 100644 index 0000000..8c31990 --- /dev/null +++ b/src/plugins/bearer/symbian/symbianengine.cpp @@ -0,0 +1,931 @@ +/**************************************************************************** +** +** 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 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 "symbianengine.h" + +#include +#include +#include + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + #include + #include + #include + #include + #include + #include +#else + #include + #include + #include +#endif + +QT_BEGIN_NAMESPACE + +static const int KValueThatWillBeAddedToSNAPId = 1000; +static const int KUserChoiceIAPId = 0; + +SymbianNetworkConfigurationPrivate::SymbianNetworkConfigurationPrivate() +: bearer(BearerUnknown), numericId(0), connectionId(0), manager(0) +{ +} + +SymbianNetworkConfigurationPrivate::~SymbianNetworkConfigurationPrivate() +{ +} + +inline SymbianNetworkConfigurationPrivate *toSymbianConfig(QNetworkConfigurationPrivatePointer ptr) +{ + return static_cast(ptr.data()); +} + +SymbianEngine::SymbianEngine(QObject *parent) +: QNetworkSessionEngine(parent), CActive(CActive::EPriorityIdle), iInitOk(true) +{ + qDebug() << Q_FUNC_INFO; + + CActiveScheduler::Add(this); + + TRAPD(error, ipCommsDB = CCommsDatabase::NewL(EDatabaseTypeIAP)); + if (error != KErrNone) { + iInitOk = false; + return; + } + + TRAP_IGNORE(iConnectionMonitor.ConnectL()); + TRAP_IGNORE(iConnectionMonitor.NotifyEventL(*this)); + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + TRAP(error, iCmManager.OpenL()); + if (error != KErrNone) { + iInitOk = false; + return; + } +#endif + + SymbianNetworkConfigurationPrivate *cpPriv = new SymbianNetworkConfigurationPrivate; + cpPriv->name = "UserChoice"; + cpPriv->bearer = SymbianNetworkConfigurationPrivate::BearerUnknown; + cpPriv->state = QNetworkConfiguration::Discovered; + cpPriv->isValid = true; + cpPriv->id = QString::number(qHash(KUserChoiceIAPId)); + cpPriv->numericId = KUserChoiceIAPId; + cpPriv->connectionId = 0; + cpPriv->type = QNetworkConfiguration::UserChoice; + cpPriv->purpose = QNetworkConfiguration::UnknownPurpose; + cpPriv->roamingSupported = false; + cpPriv->manager = this; + + QNetworkConfigurationPrivatePointer ptr(cpPriv); + userChoiceConfigurations.insert(ptr->id, ptr); + + updateConfigurations(); + updateStatesToSnaps(); + + // Start monitoring IAP and/or SNAP changes in Symbian CommsDB + startCommsDatabaseNotifications(); +} + +SymbianEngine::~SymbianEngine() +{ + Cancel(); + + iConnectionMonitor.CancelNotifications(); + iConnectionMonitor.Close(); + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + iCmManager.Close(); +#endif + + delete ipAccessPointsAvailabilityScanner; + delete ipCommsDB; +} + + +QNetworkConfigurationManager::Capabilities SymbianEngine::capabilities() const +{ + QNetworkConfigurationManager::Capabilities capFlags; + + capFlags = QNetworkConfigurationManager::CanStartAndStopInterfaces | + QNetworkConfigurationManager::DirectConnectionRouting | + QNetworkConfigurationManager::SystemSessionSupport | + QNetworkConfigurationManager::DataStatistics; + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + capFlags |= QNetworkConfigurationManager::ApplicationLevelRoaming | + QNetworkConfigurationManager::ForcedRoaming; +#endif + + return capFlags; +} + +void SymbianEngine::requestUpdate() +{ + if (!iInitOk || iUpdateGoingOn) { + return; + } + iUpdateGoingOn = true; + + stopCommsDatabaseNotifications(); + updateConfigurations(); // Synchronous call + updateAvailableAccessPoints(); // Asynchronous call +} + +void SymbianEngine::updateConfigurations() +{ + if (!iInitOk) { + return; + } + + TRAP_IGNORE(updateConfigurationsL()); +} + +void SymbianEngine::updateConfigurationsL() +{ + QList knownConfigs = accessPointConfigurations.keys(); + QList knownSnapConfigs = snapConfigurations.keys(); + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + // S60 version is >= Series60 3rd Edition Feature Pack 2 + TInt error = KErrNone; + + // Loop through all IAPs + RArray connectionMethods; // IAPs + CleanupClosePushL(connectionMethods); + iCmManager.ConnectionMethodL(connectionMethods); + for(int i = 0; i < connectionMethods.Count(); i++) { + RCmConnectionMethod connectionMethod = iCmManager.ConnectionMethodL(connectionMethods[i]); + CleanupClosePushL(connectionMethod); + TUint32 iapId = connectionMethod.GetIntAttributeL(CMManager::ECmIapId); + QString ident = QString::number(qHash(iapId)); + if (accessPointConfigurations.contains(ident)) { + knownConfigs.removeOne(ident); + } else { + SymbianNetworkConfigurationPrivate* cpPriv = NULL; + TRAP(error, cpPriv = configFromConnectionMethodL(connectionMethod)); + if (error == KErrNone) { + QNetworkConfigurationPrivatePointer ptr(cpPriv); + accessPointConfigurations.insert(ptr->id, ptr); + emit configurationAdded(ptr); + } + } + CleanupStack::PopAndDestroy(&connectionMethod); + } + CleanupStack::PopAndDestroy(&connectionMethods); + + // Loop through all SNAPs + RArray destinations; + CleanupClosePushL(destinations); + iCmManager.AllDestinationsL(destinations); + for(int i = 0; i < destinations.Count(); i++) { + RCmDestination destination; + destination = iCmManager.DestinationL(destinations[i]); + CleanupClosePushL(destination); + QString ident = QString::number(qHash(destination.Id()+KValueThatWillBeAddedToSNAPId)); //TODO: Check if it's ok to add 1000 SNAP Id to prevent SNAP ids overlapping IAP ids + if (snapConfigurations.contains(ident)) { + knownSnapConfigs.removeOne(ident); + } else { + SymbianNetworkConfigurationPrivate *cpPriv = new SymbianNetworkConfigurationPrivate; + CleanupStack::PushL(cpPriv); + + HBufC *pName = destination.NameLC(); + cpPriv->name = QString::fromUtf16(pName->Ptr(),pName->Length()); + CleanupStack::PopAndDestroy(pName); + pName = NULL; + + cpPriv->isValid = true; + cpPriv->id = ident; + cpPriv->numericId = destination.Id(); + cpPriv->connectionId = 0; + cpPriv->state = QNetworkConfiguration::Defined; + cpPriv->type = QNetworkConfiguration::ServiceNetwork; + cpPriv->purpose = QNetworkConfiguration::UnknownPurpose; + cpPriv->roamingSupported = false; + cpPriv->manager = this; + + QNetworkConfigurationPrivatePointer ptr(cpPriv); + snapConfigurations.insert(ident, ptr); + emit configurationAdded(ptr); + + CleanupStack::Pop(cpPriv); + } + QNetworkConfigurationPrivatePointer privSNAP = snapConfigurations.value(ident); + + for (int j=0; j < destination.ConnectionMethodCount(); j++) { + RCmConnectionMethod connectionMethod = destination.ConnectionMethodL(j); + CleanupClosePushL(connectionMethod); + + TUint32 iapId = connectionMethod.GetIntAttributeL(CMManager::ECmIapId); + QString iface = QString::number(qHash(iapId)); + // Check that IAP can be found from accessPointConfigurations list + QNetworkConfigurationPrivatePointer priv = accessPointConfigurations.value(iface); + if (!priv) { + SymbianNetworkConfigurationPrivate *cpPriv = NULL; + TRAP(error, cpPriv = configFromConnectionMethodL(connectionMethod)); + if (error == KErrNone) { + QNetworkConfigurationPrivatePointer ptr(cpPriv); + toSymbianConfig(ptr)->serviceNetworkPtr = privSNAP; + accessPointConfigurations.insert(ptr->id, ptr); + emit configurationAdded(ptr); + privSNAP->serviceNetworkMembers.append(ptr); + } + } else { + knownConfigs.removeOne(iface); + // Check that IAP can be found from related SNAP's configuration list + bool iapFound = false; + for (int i = 0; i < privSNAP->serviceNetworkMembers.count(); i++) { + if (toSymbianConfig(privSNAP->serviceNetworkMembers[i])->numericId == iapId) { + iapFound = true; + break; + } + } + if (!iapFound) { + toSymbianConfig(priv)->serviceNetworkPtr = privSNAP; + privSNAP->serviceNetworkMembers.append(priv); + } + } + + CleanupStack::PopAndDestroy(&connectionMethod); + } + + if (privSNAP->serviceNetworkMembers.count() > 1) { + // Roaming is supported only if SNAP contains more than one IAP + privSNAP->roamingSupported = true; + } + + CleanupStack::PopAndDestroy(&destination); + } + CleanupStack::PopAndDestroy(&destinations); + +#else + // S60 version is < Series60 3rd Edition Feature Pack 2 + CCommsDbTableView* pDbTView = ipCommsDB->OpenTableLC(TPtrC(IAP)); + + // Loop through all IAPs + TUint32 apId = 0; + TInt retVal = pDbTView->GotoFirstRecord(); + while (retVal == KErrNone) { + pDbTView->ReadUintL(TPtrC(COMMDB_ID), apId); + QString ident = QString::number(qHash(apId)); + if (accessPointConfigurations.contains(ident)) { + knownConfigs.removeOne(ident); + } else { + SymbianNetworkConfigurationPrivate *cpPriv = new SymbianNetworkConfigurationPrivate; + if (readNetworkConfigurationValuesFromCommsDb(apId, cpPriv)) { + QNetworkConfigurationPrivatePointer ptr(cpPriv); + accessPointConfigurations.insert(ident, ptr); + + emit configurationAdded(ptr); + } else { + delete cpPriv; + } + } + retVal = pDbTView->GotoNextRecord(); + } + CleanupStack::PopAndDestroy(pDbTView); +#endif + updateActiveAccessPoints(); + + foreach (const QString &oldIface, knownConfigs) { + //remove non existing IAP + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(oldIface); + emit configurationRemoved(ptr); + + // Remove non existing IAP from SNAPs + foreach (const QString &iface, snapConfigurations.keys()) { + QNetworkConfigurationPrivatePointer ptr2 = snapConfigurations.value(iface); + // => Check if one of the IAPs of the SNAP is active + for (int i = 0; i < ptr2->serviceNetworkMembers.count(); ++i) { + if (toSymbianConfig(ptr2->serviceNetworkMembers[i])->numericId == + toSymbianConfig(ptr)->numericId) { + ptr2->serviceNetworkMembers.removeAt(i); + break; + } + } + } + } + + foreach (const QString &oldIface, knownSnapConfigs) { + //remove non existing SNAPs + QNetworkConfigurationPrivatePointer ptr = snapConfigurations.take(oldIface); + emit configurationRemoved(ptr); + } +} + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE +SymbianNetworkConfigurationPrivate *SymbianEngine::configFromConnectionMethodL( + RCmConnectionMethod& connectionMethod) +{ + SymbianNetworkConfigurationPrivate *cpPriv = new SymbianNetworkConfigurationPrivate; + CleanupStack::PushL(cpPriv); + + TUint32 iapId = connectionMethod.GetIntAttributeL(CMManager::ECmIapId); + QString ident = QString::number(qHash(iapId)); + + HBufC *pName = connectionMethod.GetStringAttributeL(CMManager::ECmName); + CleanupStack::PushL(pName); + cpPriv->name = QString::fromUtf16(pName->Ptr(),pName->Length()); + CleanupStack::PopAndDestroy(pName); + pName = NULL; + + TUint32 bearerId = connectionMethod.GetIntAttributeL(CMManager::ECmCommsDBBearerType); + switch (bearerId) { + case KCommDbBearerCSD: + cpPriv->bearer = SymbianNetworkConfigurationPrivate::Bearer2G; + break; + case KCommDbBearerWcdma: + cpPriv->bearer = SymbianNetworkConfigurationPrivate::BearerWCDMA; + break; + case KCommDbBearerLAN: + cpPriv->bearer = SymbianNetworkConfigurationPrivate::BearerEthernet; + break; + case KCommDbBearerVirtual: + cpPriv->bearer = SymbianNetworkConfigurationPrivate::BearerUnknown; + break; + case KCommDbBearerPAN: + cpPriv->bearer = SymbianNetworkConfigurationPrivate::BearerUnknown; + break; + case KCommDbBearerWLAN: + cpPriv->bearer = SymbianNetworkConfigurationPrivate::BearerWLAN; + break; + default: + cpPriv->bearer = SymbianNetworkConfigurationPrivate::BearerUnknown; + break; + } + + TInt error = KErrNone; + TUint32 bearerType = connectionMethod.GetIntAttributeL(CMManager::ECmBearerType); + switch (bearerType) { + case KUidPacketDataBearerType: + // "Packet data" Bearer => Mapping is done using "Access point name" + TRAP(error, pName = connectionMethod.GetStringAttributeL(CMManager::EPacketDataAPName)); + break; + case KUidWlanBearerType: + // "Wireless LAN" Bearer => Mapping is done using "WLAN network name" = SSID + TRAP(error, pName = connectionMethod.GetStringAttributeL(CMManager::EWlanSSID)); + break; + } + if (!pName) { + // "Data call" Bearer or "High Speed (GSM)" Bearer => Mapping is done using "Dial-up number" + TRAP(error, pName = connectionMethod.GetStringAttributeL(CMManager::EDialDefaultTelNum)); + } + + if (error == KErrNone && pName) { + CleanupStack::PushL(pName); + cpPriv->mappingName = QString::fromUtf16(pName->Ptr(),pName->Length()); + CleanupStack::PopAndDestroy(pName); + pName = NULL; + } + + cpPriv->state = QNetworkConfiguration::Defined; + TBool isConnected = connectionMethod.GetBoolAttributeL(CMManager::ECmConnected); + if (isConnected) { + cpPriv->state = QNetworkConfiguration::Active; + } + + cpPriv->isValid = true; + cpPriv->id = ident; + cpPriv->numericId = iapId; + cpPriv->connectionId = 0; + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + cpPriv->purpose = QNetworkConfiguration::UnknownPurpose; + cpPriv->roamingSupported = false; + cpPriv->manager = this; + + CleanupStack::Pop(cpPriv); + return cpPriv; +} +#else +bool SymbianEngine::readNetworkConfigurationValuesFromCommsDb( + TUint32 aApId, SymbianNetworkConfigurationPrivate *apNetworkConfiguration) +{ + TRAPD(error, readNetworkConfigurationValuesFromCommsDbL(aApId,apNetworkConfiguration)); + if (error != KErrNone) { + return false; + } + return true; +} + +void SymbianEngine::readNetworkConfigurationValuesFromCommsDbL( + TUint32 aApId, SymbianNetworkConfigurationPrivate *apNetworkConfiguration) +{ + CApDataHandler* pDataHandler = CApDataHandler::NewLC(*ipCommsDB); + CApAccessPointItem* pAPItem = CApAccessPointItem::NewLC(); + TBuf name; + + CApUtils* pApUtils = CApUtils::NewLC(*ipCommsDB); + TUint32 apId = pApUtils->WapIdFromIapIdL(aApId); + + pDataHandler->AccessPointDataL(apId,*pAPItem); + pAPItem->ReadTextL(EApIapName, name); + if (name.Compare(_L("Easy WLAN")) == 0) { + // "Easy WLAN" won't be accepted to the Configurations list + User::Leave(KErrNotFound); + } + + QString ident = QString::number(qHash(aApId)); + + apNetworkConfiguration->name = QString::fromUtf16(name.Ptr(),name.Length()); + apNetworkConfiguration->isValid = true; + apNetworkConfiguration->id = ident; + apNetworkConfiguration->numericId = aApId; + apNetworkConfiguration->connectionId = 0; + apNetworkConfiguration->state = (QNetworkConfiguration::Defined); + apNetworkConfiguration->type = QNetworkConfiguration::InternetAccessPoint; + apNetworkConfiguration->purpose = QNetworkConfiguration::UnknownPurpose; + apNetworkConfiguration->roamingSupported = false; + switch (pAPItem->BearerTypeL()) { + case EApBearerTypeCSD: + apNetworkConfiguration->bearer = SymbianNetworkConfigurationPrivate::Bearer2G; + break; + case EApBearerTypeGPRS: + apNetworkConfiguration->bearer = SymbianNetworkConfigurationPrivate::Bearer2G; + break; + case EApBearerTypeHSCSD: + apNetworkConfiguration->bearer = SymbianNetworkConfigurationPrivate::BearerHSPA; + break; + case EApBearerTypeCDMA: + apNetworkConfiguration->bearer = SymbianNetworkConfigurationPrivate::BearerCDMA2000; + break; + case EApBearerTypeWLAN: + apNetworkConfiguration->bearer = SymbianNetworkConfigurationPrivate::BearerWLAN; + break; + case EApBearerTypeLAN: + apNetworkConfiguration->bearer = SymbianNetworkConfigurationPrivate::BearerEthernet; + break; + case EApBearerTypeLANModem: + apNetworkConfiguration->bearer = SymbianNetworkConfigurationPrivate::BearerEthernet; + break; + default: + apNetworkConfiguration->bearer = SymbianNetworkConfigurationPrivate::BearerUnknown; + break; + } + apNetworkConfiguration->manager = this; + + CleanupStack::PopAndDestroy(pApUtils); + CleanupStack::PopAndDestroy(pAPItem); + CleanupStack::PopAndDestroy(pDataHandler); +} +#endif + +QNetworkConfigurationPrivatePointer SymbianEngine::defaultConfiguration() +{ + QNetworkConfigurationPrivatePointer ptr; + + if (iInitOk) { + stopCommsDatabaseNotifications(); + TRAP_IGNORE(ptr = defaultConfigurationL()); + startCommsDatabaseNotifications(); + } + + return ptr; +} + +QNetworkConfigurationPrivatePointer SymbianEngine::defaultConfigurationL() +{ + QNetworkConfigurationPrivatePointer ptr; + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + // Check Default Connection (SNAP or IAP) + TCmDefConnValue defaultConnectionValue; + iCmManager.ReadDefConnL(defaultConnectionValue); + if (defaultConnectionValue.iType == ECmDefConnDestination) { + QString iface = QString::number(qHash(defaultConnectionValue.iId+KValueThatWillBeAddedToSNAPId)); + ptr = snapConfigurations.value(iface); + } else if (defaultConnectionValue.iType == ECmDefConnConnectionMethod) { + QString iface = QString::number(qHash(defaultConnectionValue.iId)); + ptr = accessPointConfigurations.value(iface); + } +#endif + + if (!ptr->isValid) { + QString iface = QString::number(qHash(KUserChoiceIAPId)); + ptr = userChoiceConfigurations.value(iface); + } + + return ptr; +} + +void SymbianEngine::updateActiveAccessPoints() +{ + bool online = false; + QList inactiveConfigs = accessPointConfigurations.keys(); + + TRequestStatus status; + TUint connectionCount; + iConnectionMonitor.GetConnectionCount(connectionCount, status); + User::WaitForRequest(status); + + // Go through all connections and set state of related IAPs to Active + TUint connectionId; + TUint subConnectionCount; + TUint apId; + if (status.Int() == KErrNone) { + for (TUint i = 1; i <= connectionCount; i++) { + iConnectionMonitor.GetConnectionInfo(i, connectionId, subConnectionCount); + iConnectionMonitor.GetUintAttribute(connectionId, subConnectionCount, KIAPId, apId, status); + User::WaitForRequest(status); + QString ident = QString::number(qHash(apId)); + + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(ident); + if (ptr) { + online = true; + inactiveConfigs.removeOne(ident); + + toSymbianConfig(ptr)->connectionId = connectionId; + + // Configuration is Active + changeConfigurationStateTo(ptr, QNetworkConfiguration::Active); + } + } + } + + // Make sure that state of rest of the IAPs won't be Active + foreach (const QString &iface, inactiveConfigs) { + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(iface); + if (ptr) { + // Configuration is either Defined or Discovered + changeConfigurationStateAtMaxTo(ptr, QNetworkConfiguration::Discovered); + } + } + + if (iOnline != online) { + iOnline = online; + emit this->onlineStateChanged(iOnline); + } +} + +void SymbianEngine::updateAvailableAccessPoints() +{ + if (!ipAccessPointsAvailabilityScanner) { + ipAccessPointsAvailabilityScanner = new AccessPointsAvailabilityScanner(*this, iConnectionMonitor); + } + if (ipAccessPointsAvailabilityScanner) { + // Scanning may take a while because WLAN scanning will be done (if device supports WLAN). + ipAccessPointsAvailabilityScanner->StartScanning(); + } +} + +void SymbianEngine::accessPointScanningReady(TBool scanSuccessful, TConnMonIapInfo iapInfo) +{ + iUpdateGoingOn = false; + if (scanSuccessful) { + QList unavailableConfigs = accessPointConfigurations.keys(); + + // Set state of returned IAPs to Discovered + // if state is not already Active + for(TUint i=0; istate < QNetworkConfiguration::Active) { + // Configuration is either Discovered or Active + changeConfigurationStateAtMinTo(ptr, QNetworkConfiguration::Discovered); + } + } + } + + // Make sure that state of rest of the IAPs won't be Discovered or Active + foreach (const QString &iface, unavailableConfigs) { + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(iface); + if (ptr) { + // Configuration is Defined + changeConfigurationStateAtMaxTo(ptr, QNetworkConfiguration::Defined); + } + } + } + + updateStatesToSnaps(); + + startCommsDatabaseNotifications(); + + qDebug() << Q_FUNC_INFO << "updateCompleted()"; + emit updateCompleted(); +} + +void SymbianEngine::updateStatesToSnaps() +{ + // Go through SNAPs and set correct state to SNAPs + QList snapConfigIdents = snapConfigurations.keys(); + foreach (QString iface, snapConfigIdents) { + bool discovered = false; + bool active = false; + QNetworkConfigurationPrivatePointer ptr = snapConfigurations.value(iface); + // => Check if one of the IAPs of the SNAP is discovered or active + // => If one of IAPs is active, also SNAP is active + // => If one of IAPs is discovered but none of the IAPs is active, SNAP is discovered + for (int i=0; iserviceNetworkMembers.count(); i++) { + if ((ptr->serviceNetworkMembers[i]->state & QNetworkConfiguration::Active) + == QNetworkConfiguration::Active) { + active = true; + break; + } else if ((ptr->serviceNetworkMembers[i]->state & QNetworkConfiguration::Discovered) + == QNetworkConfiguration::Discovered) { + discovered = true; + } + } + if (active) { + changeConfigurationStateTo(ptr, QNetworkConfiguration::Active); + } else if (discovered) { + changeConfigurationStateTo(ptr, QNetworkConfiguration::Discovered); + } else { + changeConfigurationStateTo(ptr, QNetworkConfiguration::Defined); + } + } +} + +bool SymbianEngine::changeConfigurationStateTo(QNetworkConfigurationPrivatePointer ptr, + QNetworkConfiguration::StateFlags newState) +{ + if (newState != ptr->state) { + ptr->state = newState; + emit configurationChanged(ptr); + return true; + } + return false; +} + +/* changeConfigurationStateAtMinTo function does not overwrite possible better + * state (e.g. Discovered state does not overwrite Active state) but + * makes sure that state is at minimum given state. +*/ +bool SymbianEngine::changeConfigurationStateAtMinTo(QNetworkConfigurationPrivatePointer ptr, + QNetworkConfiguration::StateFlags newState) +{ + if ((newState | ptr->state) != ptr->state) { + ptr->state = (ptr->state | newState); + emit configurationChanged(ptr); + return true; + } + return false; +} + +/* changeConfigurationStateAtMaxTo function overwrites possible better + * state (e.g. Discovered state overwrites Active state) and + * makes sure that state is at maximum given state (e.g. Discovered state + * does not overwrite Defined state). +*/ +bool SymbianEngine::changeConfigurationStateAtMaxTo(QNetworkConfigurationPrivatePointer ptr, + QNetworkConfiguration::StateFlags newState) +{ + if ((newState & ptr->state) != ptr->state) { + ptr->state = (newState & ptr->state); + emit configurationChanged(ptr); + return true; + } + return false; +} + +void SymbianEngine::startCommsDatabaseNotifications() +{ + if (!iWaitingCommsDatabaseNotifications) { + iWaitingCommsDatabaseNotifications = ETrue; + if (!IsActive()) { + SetActive(); + // Start waiting for new notification + ipCommsDB->RequestNotification(iStatus); + } + } +} + +void SymbianEngine::stopCommsDatabaseNotifications() +{ + if (iWaitingCommsDatabaseNotifications) { + iWaitingCommsDatabaseNotifications = EFalse; + if (!IsActive()) { + SetActive(); + // Make sure that notifier recorded events will not be returned + // as soon as the client issues the next RequestNotification() request. + ipCommsDB->RequestNotification(iStatus); + ipCommsDB->CancelRequestNotification(); + } else { + ipCommsDB->CancelRequestNotification(); + } + } +} + +void SymbianEngine::RunL() +{ + if (iStatus != KErrCancel) { + RDbNotifier::TEvent event = STATIC_CAST(RDbNotifier::TEvent, iStatus.Int()); + switch (event) { + case RDbNotifier::EUnlock: /** All read locks have been removed. */ + case RDbNotifier::ECommit: /** A transaction has been committed. */ + case RDbNotifier::ERollback: /** A transaction has been rolled back */ + case RDbNotifier::ERecover: /** The database has been recovered */ + // Note that if further database events occur while a client is handling + // a request completion, the notifier records the most significant database + // event and this is signalled as soon as the client issues the next + // RequestNotification() request. + // => Stop recording notifications + stopCommsDatabaseNotifications(); + TRAPD(error, updateConfigurationsL()); + if (error == KErrNone) { + updateStatesToSnaps(); + } + iWaitingCommsDatabaseNotifications = true; + break; + default: + // Do nothing + break; + } + } + + if (iWaitingCommsDatabaseNotifications) { + if (!IsActive()) { + SetActive(); + // Start waiting for new notification + ipCommsDB->RequestNotification(iStatus); + } + } +} + +void SymbianEngine::DoCancel() +{ + ipCommsDB->CancelRequestNotification(); +} + + +void SymbianEngine::EventL(const CConnMonEventBase& aEvent) +{ + switch (aEvent.EventType()) { + case EConnMonCreateConnection: + { + CConnMonCreateConnection* realEvent; + realEvent = (CConnMonCreateConnection*) &aEvent; + TUint subConnectionCount = 0; + TUint apId; + TUint connectionId = realEvent->ConnectionId(); + TRequestStatus status; + iConnectionMonitor.GetUintAttribute(connectionId, subConnectionCount, KIAPId, apId, status); + User::WaitForRequest(status); + QString ident = QString::number(qHash(apId)); + + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(ident); + if (ptr) { + toSymbianConfig(ptr)->connectionId = connectionId; + // Configuration is Active + if (changeConfigurationStateTo(ptr, QNetworkConfiguration::Active)) + updateStatesToSnaps(); + + if (!iOnline) { + iOnline = true; + emit this->onlineStateChanged(iOnline); + } + } + } + break; + + case EConnMonDeleteConnection: + { + CConnMonDeleteConnection* realEvent; + realEvent = (CConnMonDeleteConnection*) &aEvent; + TUint connectionId = realEvent->ConnectionId(); + + QNetworkConfigurationPrivatePointer ptr = dataByConnectionId(connectionId); + if (ptr) { + toSymbianConfig(ptr)->connectionId = 0; + // Configuration is either Defined or Discovered + if (changeConfigurationStateAtMaxTo(ptr, QNetworkConfiguration::Discovered)) + updateStatesToSnaps(); + } + + bool online = false; + foreach (const QString &iface, accessPointConfigurations.keys()) { + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(iface); + if (ptr->state == QNetworkConfiguration::Active) { + online = true; + break; + } + } + if (iOnline != online) { + iOnline = online; + emit this->onlineStateChanged(iOnline); + } + } + break; + + case EConnMonIapAvailabilityChange: + { + CConnMonIapAvailabilityChange* realEvent; + realEvent = (CConnMonIapAvailabilityChange*) &aEvent; + TConnMonIapInfo iaps = realEvent->IapAvailability(); + QList unDiscoveredConfigs = accessPointConfigurations.keys(); + for ( TUint i = 0; i < iaps.Count(); i++ ) { + QString ident = QString::number(qHash(iaps.iIap[i].iIapId)); + + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(ident); + if (ptr) { + // Configuration is either Discovered or Active + changeConfigurationStateAtMinTo(ptr, QNetworkConfiguration::Discovered); + unDiscoveredConfigs.removeOne(ident); + } + } + foreach (const QString &iface, unDiscoveredConfigs) { + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(iface); + if (ptr) { + // Configuration is Defined + changeConfigurationStateAtMaxTo(ptr, QNetworkConfiguration::Defined); + } + } + } + break; + + default: + // For unrecognized events + break; + } +} + +QNetworkConfigurationPrivatePointer SymbianEngine::dataByConnectionId(TUint aConnectionId) +{ + QNetworkConfiguration item; + + QHash::const_iterator i = + accessPointConfigurations.constBegin(); + while (i != accessPointConfigurations.constEnd()) { + QNetworkConfigurationPrivatePointer ptr = i.value(); + if (toSymbianConfig(ptr)->connectionId == aConnectionId) + return ptr; + + ++i; + } + + return QNetworkConfigurationPrivatePointer(); +} + +AccessPointsAvailabilityScanner::AccessPointsAvailabilityScanner(SymbianEngine& owner, + RConnectionMonitor& connectionMonitor) + : CActive(CActive::EPriorityStandard), iOwner(owner), iConnectionMonitor(connectionMonitor) +{ + CActiveScheduler::Add(this); +} + +AccessPointsAvailabilityScanner::~AccessPointsAvailabilityScanner() +{ + Cancel(); +} + +void AccessPointsAvailabilityScanner::DoCancel() +{ + iConnectionMonitor.CancelAsyncRequest(EConnMonGetPckgAttribute); +} + +void AccessPointsAvailabilityScanner::StartScanning() +{ + iConnectionMonitor.GetPckgAttribute(EBearerIdAll, 0, KIapAvailability, iIapBuf, iStatus); + if (!IsActive()) { + SetActive(); + } +} + +void AccessPointsAvailabilityScanner::RunL() +{ + if (iStatus.Int() != KErrNone) { + iIapBuf().iCount = 0; + iOwner.accessPointScanningReady(false,iIapBuf()); + } else { + iOwner.accessPointScanningReady(true,iIapBuf()); + } +} + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/symbian/symbianengine.h b/src/plugins/bearer/symbian/symbianengine.h new file mode 100644 index 0000000..0ca30da --- /dev/null +++ b/src/plugins/bearer/symbian/symbianengine.h @@ -0,0 +1,201 @@ +/**************************************************************************** +** +** 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 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 SYMBIANENGINE_H +#define SYMBIANENGINE_H + +#include +#include + +#include +#include +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + #include +#endif + +class CCommsDatabase; + +QT_BEGIN_NAMESPACE +class QTimer; +QT_END_NAMESPACE + +QT_BEGIN_NAMESPACE + +class QNetworkSessionPrivate; +class AccessPointsAvailabilityScanner; + +class SymbianNetworkConfigurationPrivate : public QNetworkConfigurationPrivate +{ +public: + enum Bearer { + BearerEthernet, + BearerWLAN, + Bearer2G, + BearerCDMA2000, + BearerWCDMA, + BearerHSPA, + BearerBluetooth, + BearerWiMAX, + BearerUnknown = -1 + }; + + SymbianNetworkConfigurationPrivate(); + ~SymbianNetworkConfigurationPrivate(); + + Bearer bearer; + + TUint32 numericId; + TUint connectionId; + + TAny *manager; + + QNetworkConfigurationPrivatePointer serviceNetworkPtr; + + QString mappingName; +}; + +class SymbianEngine : public QNetworkSessionEngine, public CActive, + public MConnectionMonitorObserver +{ + Q_OBJECT + +public: + SymbianEngine(QObject *parent = 0); + virtual ~SymbianEngine(); + + QString getInterfaceFromId(const QString &id) { return QString(); } + bool hasIdentifier(const QString &id) { return false; } + + void connectToId(const QString &id) { } + void disconnectFromId(const QString &id) { } + + void requestUpdate(); + + QNetworkSession::State sessionStateForId(const QString &id) { return QNetworkSession::Invalid; } + + QNetworkConfigurationManager::Capabilities capabilities() const; + + QNetworkConfigurationPrivatePointer defaultConfiguration(); + +Q_SIGNALS: + void onlineStateChanged(bool isOnline); + +public Q_SLOTS: + void updateConfigurations(); + +private: + void updateStatesToSnaps(); + bool changeConfigurationStateTo(QNetworkConfigurationPrivatePointer ptr, + QNetworkConfiguration::StateFlags newState); + bool changeConfigurationStateAtMinTo(QNetworkConfigurationPrivatePointer ptr, + QNetworkConfiguration::StateFlags newState); + bool changeConfigurationStateAtMaxTo(QNetworkConfigurationPrivatePointer ptr, + QNetworkConfiguration::StateFlags newState); +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + SymbianNetworkConfigurationPrivate *configFromConnectionMethodL(RCmConnectionMethod& connectionMethod); +#else + bool readNetworkConfigurationValuesFromCommsDb( + TUint32 aApId, SymbianNetworkConfigurationPrivate *apNetworkConfiguration); + void readNetworkConfigurationValuesFromCommsDbL( + TUint32 aApId, SymbianNetworkConfigurationPrivate *apNetworkConfiguration); +#endif + + void updateConfigurationsL(); + void updateActiveAccessPoints(); + void updateAvailableAccessPoints(); + void accessPointScanningReady(TBool scanSuccessful, TConnMonIapInfo iapInfo); + void startCommsDatabaseNotifications(); + void stopCommsDatabaseNotifications(); + + QNetworkConfigurationPrivatePointer defaultConfigurationL(); + TBool GetS60PlatformVersion(TUint& aMajor, TUint& aMinor) const; + void startMonitoringIAPData(TUint32 aIapId); + QNetworkConfigurationPrivatePointer dataByConnectionId(TUint aConnectionId); + +protected: // From CActive + void RunL(); + void DoCancel(); + +private: // MConnectionMonitorObserver + void EventL(const CConnMonEventBase& aEvent); + +private: // Data + CCommsDatabase* ipCommsDB; + RConnectionMonitor iConnectionMonitor; + + TBool iWaitingCommsDatabaseNotifications; + TBool iOnline; + TBool iInitOk; + TBool iUpdateGoingOn; + + + AccessPointsAvailabilityScanner* ipAccessPointsAvailabilityScanner; + + friend class QNetworkSessionPrivate; + friend class AccessPointsAvailabilityScanner; + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + RCmManager iCmManager; +#endif +}; + +class AccessPointsAvailabilityScanner : public CActive +{ +public: + AccessPointsAvailabilityScanner(SymbianEngine& owner, + RConnectionMonitor& connectionMonitor); + ~AccessPointsAvailabilityScanner(); + + void StartScanning(); + +protected: // From CActive + void RunL(); + void DoCancel(); + +private: // Data + SymbianEngine& iOwner; + RConnectionMonitor& iConnectionMonitor; + TConnMonIapInfoBuf iIapBuf; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/s60installs/s60installs.pro b/src/s60installs/s60installs.pro index 2d9c489..57df601 100644 --- a/src/s60installs/s60installs.pro +++ b/src/s60installs/s60installs.pro @@ -79,7 +79,12 @@ symbian: { DEPLOYMENT += phonon_backend_plugins } - DEPLOYMENT += qtresources qtlibraries imageformats_plugins codecs_plugins graphicssystems_plugins + DEPLOYMENT += qtresources \ + qtlibraries \ + imageformats_plugins \ + codecs_plugins \ + graphicssystems_plugins \ + bearer_plugins contains(QT_CONFIG, svg): { qtlibraries.sources += QtSvg.dll @@ -115,6 +120,9 @@ symbian: { graphicssystems_plugins.sources += qvggraphicssystem.dll } + bearer_plugins.path = c:$$QT_PLUGINS_BASE_DIR/bearer + bearer_plugins.sources += qgenericbearer.dll qsymbianbearer.dll + BLD_INF_RULES.prj_exports += "qt.iby $$CORE_MW_LAYER_IBY_EXPORT_PATH(qt.iby)" BLD_INF_RULES.prj_exports += "qtdemoapps.iby $$CORE_APP_LAYER_IBY_EXPORT_PATH(qtdemoapps.iby)" } -- cgit v0.12 From b840dbe4ddd6937cd76c9c41baa16a8077224acd Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 18 Jan 2010 14:26:49 +1000 Subject: Port session functionality. --- src/network/bearer/bearer.pri | 8 +- src/network/bearer/qnetworkconfigmanager_p.h | 2 +- src/network/bearer/qnetworkconfiguration_p.h | 8 +- src/network/bearer/qnetworkconfiguration_s60_p.cpp | 59 - src/network/bearer/qnetworksession.cpp | 143 ++- src/network/bearer/qnetworksession_p.cpp | 484 --------- src/network/bearer/qnetworksession_p.h | 93 +- src/network/bearer/qnetworksession_s60_p.cpp | 1134 -------------------- src/network/bearer/qnetworksession_s60_p.h | 212 ---- src/network/bearer/qnetworksessionengine_p.h | 2 + src/plugins/bearer/generic/generic.pro | 5 +- src/plugins/bearer/generic/qgenericengine.cpp | 8 +- src/plugins/bearer/generic/qgenericengine.h | 3 + src/plugins/bearer/qnetworksession_impl.cpp | 485 +++++++++ src/plugins/bearer/qnetworksession_impl.h | 136 +++ src/plugins/bearer/symbian/main.cpp | 2 - .../bearer/symbian/qnetworksession_impl.cpp | 1125 +++++++++++++++++++ src/plugins/bearer/symbian/qnetworksession_impl.h | 196 ++++ src/plugins/bearer/symbian/symbian.pro | 8 +- src/plugins/bearer/symbian/symbianengine.cpp | 67 +- src/plugins/bearer/symbian/symbianengine.h | 21 +- .../tst_qnetworksession/tst_qnetworksession.cpp | 16 +- 22 files changed, 2152 insertions(+), 2065 deletions(-) delete mode 100644 src/network/bearer/qnetworkconfiguration_s60_p.cpp delete mode 100644 src/network/bearer/qnetworksession_p.cpp delete mode 100644 src/network/bearer/qnetworksession_s60_p.cpp delete mode 100644 src/network/bearer/qnetworksession_s60_p.h create mode 100644 src/plugins/bearer/qnetworksession_impl.cpp create mode 100644 src/plugins/bearer/qnetworksession_impl.h create mode 100644 src/plugins/bearer/symbian/qnetworksession_impl.cpp create mode 100644 src/plugins/bearer/symbian/qnetworksession_impl.h diff --git a/src/network/bearer/bearer.pri b/src/network/bearer/bearer.pri index 169c8b7..0450961 100644 --- a/src/network/bearer/bearer.pri +++ b/src/network/bearer/bearer.pri @@ -10,12 +10,7 @@ SOURCES += bearer/qnetworksession.cpp \ bearer/qnetworkconfigmanager.cpp \ bearer/qnetworkconfiguration.cpp -symbian_disabled { - HEADERS += bearer/qnetworksession_s60_p.h - - SOURCES += bearer/qnetworkconfiguration_s60_p.cpp \ - bearer/qnetworksession_s60_p.cpp -} else:maemo { +maemo { QT += dbus CONFIG += link_pkgconfig @@ -50,7 +45,6 @@ symbian_disabled { bearer/qbearerplugin.h SOURCES += bearer/qnetworkconfigmanager_p.cpp \ - bearer/qnetworksession_p.cpp \ bearer/qnetworksessionengine.cpp \ bearer/qbearerplugin.cpp diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index d7a813b..4ef1f09 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -110,7 +110,7 @@ private Q_SLOTS: void configurationChanged(QNetworkConfigurationPrivatePointer ptr); }; -QNetworkConfigurationManagerPrivate *qNetworkConfigurationManagerPrivate(); +Q_NETWORK_EXPORT QNetworkConfigurationManagerPrivate *qNetworkConfigurationManagerPrivate(); QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworkconfiguration_p.h b/src/network/bearer/qnetworkconfiguration_p.h index bfc42f5..40aea8b 100644 --- a/src/network/bearer/qnetworkconfiguration_p.h +++ b/src/network/bearer/qnetworkconfiguration_p.h @@ -75,13 +75,15 @@ public: serviceNetworkMembers.clear(); } - QString name; - QString bearer; - inline QString bearerName() const + virtual QString bearerName() const { return bearer; } + QString bearer; + + QString name; + bool isValid; QString id; QNetworkConfiguration::StateFlags state; diff --git a/src/network/bearer/qnetworkconfiguration_s60_p.cpp b/src/network/bearer/qnetworkconfiguration_s60_p.cpp deleted file mode 100644 index 142415a..0000000 --- a/src/network/bearer/qnetworkconfiguration_s60_p.cpp +++ /dev/null @@ -1,59 +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$ -** -****************************************************************************/ - -QT_BEGIN_NAMESPACE - -QString QNetworkConfigurationPrivate::bearerName() const -{ - switch (bearer) { - case QNetworkConfigurationPrivate::BearerEthernet: return QLatin1String("Ethernet"); - case QNetworkConfigurationPrivate::BearerWLAN: return QLatin1String("WLAN"); - case QNetworkConfigurationPrivate::Bearer2G: return QLatin1String("2G"); - case QNetworkConfigurationPrivate::BearerCDMA2000: return QLatin1String("CDMA2000"); - case QNetworkConfigurationPrivate::BearerWCDMA: return QLatin1String("WCDMA"); - case QNetworkConfigurationPrivate::BearerHSPA: return QLatin1String("HSPA"); - case QNetworkConfigurationPrivate::BearerBluetooth: return QLatin1String("Bluetooth"); - case QNetworkConfigurationPrivate::BearerWiMAX: return QLatin1String("WiMAX"); - default: return QString(); - } -} - -QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp index 5f87d95..6b0ccaf 100644 --- a/src/network/bearer/qnetworksession.cpp +++ b/src/network/bearer/qnetworksession.cpp @@ -43,6 +43,8 @@ #include #include "qnetworksession.h" +#include "qnetworksessionengine_p.h" +#include "qnetworkconfigmanager_p.h" #if Q_WS_MAEMO_6 #include "qnetworksession_maemo_p.h" @@ -224,14 +226,25 @@ QT_BEGIN_NAMESPACE \sa QNetworkConfiguration */ QNetworkSession::QNetworkSession(const QNetworkConfiguration& connectionConfig, QObject* parent) - : QObject(parent) +: QObject(parent), d(0) { - d = new QNetworkSessionPrivate; - d->q = this; - d->publicConfig = connectionConfig; - d->syncStateWithInterface(); - QObject::connect(d, SIGNAL(quitPendingWaitsForOpened()), - this, SIGNAL(opened())); + foreach (QNetworkSessionEngine *engine, qNetworkConfigurationManagerPrivate()->sessionEngines) { + if (engine->hasIdentifier(connectionConfig.identifier())) { + d = engine->createSessionBackend(); + d->q = this; + d->publicConfig = connectionConfig; + d->syncStateWithInterface(); + connect(d, SIGNAL(quitPendingWaitsForOpened()), this, SIGNAL(opened())); + connect(d, SIGNAL(error(QNetworkSession::SessionError)), + this, SIGNAL(error(QNetworkSession::SessionError))); + connect(d, SIGNAL(stateChanged(QNetworkSession::State)), + this, SIGNAL(stateChanged(QNetworkSession::State))); + connect(d, SIGNAL(closed()), this, SIGNAL(closed())); + connect(d, SIGNAL(newConfigurationActivated()), + this, SIGNAL(newConfigurationActivated())); + break; + } + } } /*! @@ -261,7 +274,8 @@ QNetworkSession::~QNetworkSession() */ void QNetworkSession::open() { - d->open(); + if (d) + d->open(); } /*! @@ -283,6 +297,9 @@ void QNetworkSession::open() */ bool QNetworkSession::waitForOpened(int msecs) { + if (!d) + return false; + if (d->isOpen) return true; @@ -320,7 +337,8 @@ bool QNetworkSession::waitForOpened(int msecs) */ void QNetworkSession::close() { - d->close(); + if (d) + d->close(); } /*! @@ -332,7 +350,8 @@ void QNetworkSession::close() */ void QNetworkSession::stop() { - d->stop(); + if (d) + d->stop(); } /*! @@ -342,61 +361,9 @@ void QNetworkSession::stop() */ QNetworkConfiguration QNetworkSession::configuration() const { - return d->publicConfig; + return d ? d->publicConfig : QNetworkConfiguration(); } -/* - Returns the type of bearer currently used by this session. The string is not translated and - therefore can not be shown to the user. The subsequent table presents the currently known - bearer types: - - \table - \header - \o Value - \o Description - \row - \o Unknown - \o The session is based on an unknown or unspecified bearer type. - \row - \o Ethernet - \o The session is based on Ethernet. - \row - \o WLAN - \o The session is based on Wireless LAN. - \row - \o 2G - \o The session uses CSD, GPRS, HSCSD, EDGE or cdmaOne. - \row - \o CDMA2000 - \o The session uses CDMA. - \row - \o WCDMA - \o The session uses W-CDMA/UMTS. - \row - \o HSPA - \o The session uses High Speed Packet Access. - \row - \o Bluetooth - \o The session uses Bluetooth. - \row - \o WiMAX - \o The session uses WiMAX. - \endtable - - If the session is based on a network configuration of type - \l QNetworkConfiguration::ServiceNetwork the type of the preferred or currently - active configuration is returned. Therefore the bearer type may change - over time. - - This function returns an empty string if this session is based on an invalid configuration, or - a network configuration of type \l QNetworkConfiguration::ServiceNetwork with no - \l {QNetworkConfiguration::children()}{children}. -*/ -/*QString QNetworkSession::bearerName() const -{ - return d->bearerName(); -}*/ - /*! Returns the network interface that is used by this session. @@ -408,7 +375,7 @@ QNetworkConfiguration QNetworkSession::configuration() const */ QNetworkInterface QNetworkSession::interface() const { - return d->currentInterface(); + return d ? d->currentInterface() : QNetworkInterface(); } /*! @@ -419,7 +386,7 @@ QNetworkInterface QNetworkSession::interface() const */ bool QNetworkSession::isOpen() const { - return d->isOpen; + return d ? d->isOpen : false; } /*! @@ -441,7 +408,7 @@ bool QNetworkSession::isOpen() const */ QNetworkSession::State QNetworkSession::state() const { - return d->state; + return d ? d->state : QNetworkSession::Invalid; } /*! @@ -451,7 +418,7 @@ QNetworkSession::State QNetworkSession::state() const */ QNetworkSession::SessionError QNetworkSession::error() const { - return d->error(); + return d ? d->error() : InvalidConfigurationError; } /*! @@ -462,7 +429,7 @@ QNetworkSession::SessionError QNetworkSession::error() const */ QString QNetworkSession::errorString() const { - return d->errorString(); + return d ? d->errorString() : tr("Invalid configuration."); } /*! @@ -520,6 +487,9 @@ QString QNetworkSession::errorString() const */ QVariant QNetworkSession::sessionProperty(const QString& key) const { + if (!d) + return QVariant(); + if (!d->publicConfig.isValid()) return QVariant(); @@ -553,6 +523,9 @@ QVariant QNetworkSession::sessionProperty(const QString& key) const */ void QNetworkSession::setSessionProperty(const QString& key, const QVariant& value) { + if (!d) + return; + if (key == QLatin1String("ActiveConfiguration") || key == QLatin1String("UserChoiceConfiguration")) { return; @@ -571,7 +544,8 @@ void QNetworkSession::setSessionProperty(const QString& key, const QVariant& val */ void QNetworkSession::migrate() { - d->migrate(); + if (d) + d->migrate(); } /*! @@ -583,7 +557,8 @@ void QNetworkSession::ignore() { // Needed on at least Symbian platform: the roaming must be explicitly // ignore()'d or migrate()'d - d->ignore(); + if (d) + d->ignore(); } /*! @@ -596,7 +571,8 @@ void QNetworkSession::ignore() */ void QNetworkSession::accept() { - d->accept(); + if (d) + d->accept(); } /*! @@ -608,7 +584,8 @@ void QNetworkSession::accept() */ void QNetworkSession::reject() { - d->reject(); + if (d) + d->reject(); } @@ -626,7 +603,7 @@ void QNetworkSession::reject() */ quint64 QNetworkSession::bytesWritten() const { - return d->bytesWritten(); + return d ? d->bytesWritten() : Q_UINT64_C(0); } /*! @@ -643,7 +620,7 @@ quint64 QNetworkSession::bytesWritten() const */ quint64 QNetworkSession::bytesReceived() const { - return d->bytesReceived(); + return d ? d->bytesReceived() : Q_UINT64_C(0); } /*! @@ -651,7 +628,7 @@ quint64 QNetworkSession::bytesReceived() const */ quint64 QNetworkSession::activeTime() const { - return d->activeTime(); + return d ? d->activeTime() : Q_UINT64_C(0); } /*! @@ -670,11 +647,11 @@ void QNetworkSession::connectNotify(const char *signal) QObject::connectNotify(signal); //check for preferredConfigurationChanged() signal connect notification //This is not required on all platforms -#ifdef Q_OS_SYMBIAN_disabled - if (qstrcmp(signal, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool))) == 0) { + if (!d) + return; + + if (qstrcmp(signal, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool))) == 0) d->setALREnabled(true); - } -#endif } /*! @@ -690,11 +667,11 @@ void QNetworkSession::disconnectNotify(const char *signal) QObject::disconnectNotify(signal); //check for preferredConfigurationChanged() signal disconnect notification //This is not required on all platforms -#ifdef Q_OS_SYMBIAN_disabled - if (qstrcmp(signal, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool))) == 0) { + if (!d) + return; + + if (qstrcmp(signal, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool))) == 0) d->setALREnabled(false); - } -#endif } #include "moc_qnetworksession.cpp" diff --git a/src/network/bearer/qnetworksession_p.cpp b/src/network/bearer/qnetworksession_p.cpp deleted file mode 100644 index b615797..0000000 --- a/src/network/bearer/qnetworksession_p.cpp +++ /dev/null @@ -1,484 +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 "qnetworksession_p.h" -#include "qnetworksession.h" -#include "qnetworksessionengine_p.h" -#include "qnetworkconfigmanager_p.h" - -#include -#include -#include - -#include - -QT_BEGIN_NAMESPACE - -static QNetworkSessionEngine *getEngineFromId(const QString &id) -{ - QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); - - foreach (QNetworkSessionEngine *engine, priv->sessionEngines) { - if (engine->hasIdentifier(id)) - return engine; - } - - return 0; -} - -class QNetworkSessionManagerPrivate : public QObject -{ - Q_OBJECT - -public: - QNetworkSessionManagerPrivate(QObject *parent = 0); - ~QNetworkSessionManagerPrivate(); - - void forceSessionClose(const QNetworkConfiguration &config); - -Q_SIGNALS: - void forcedSessionClose(const QNetworkConfiguration &config); -}; - -#include "qnetworksession_p.moc" - -Q_GLOBAL_STATIC(QNetworkSessionManagerPrivate, sessionManager); - -QNetworkSessionManagerPrivate::QNetworkSessionManagerPrivate(QObject *parent) -: QObject(parent) -{ -} - -QNetworkSessionManagerPrivate::~QNetworkSessionManagerPrivate() -{ -} - -void QNetworkSessionManagerPrivate::forceSessionClose(const QNetworkConfiguration &config) -{ - emit forcedSessionClose(config); -} - -void QNetworkSessionPrivate::syncStateWithInterface() -{ - connect(&manager, SIGNAL(updateCompleted()), this, SLOT(networkConfigurationsChanged())); - connect(&manager, SIGNAL(configurationChanged(QNetworkConfiguration)), - this, SLOT(configurationChanged(QNetworkConfiguration))); - connect(sessionManager(), SIGNAL(forcedSessionClose(QNetworkConfiguration)), - this, SLOT(forcedSessionClose(QNetworkConfiguration))); - - opened = false; - isOpen = false; - state = QNetworkSession::Invalid; - lastError = QNetworkSession::UnknownSessionError; - - qRegisterMetaType - ("QNetworkSessionEngine::ConnectionError"); - - switch (publicConfig.type()) { - case QNetworkConfiguration::InternetAccessPoint: - activeConfig = publicConfig; - engine = getEngineFromId(activeConfig.identifier()); - if (engine) { - connect(engine, SIGNAL(connectionError(QString,QNetworkSessionEngine::ConnectionError)), - this, SLOT(connectionError(QString,QNetworkSessionEngine::ConnectionError)), - Qt::QueuedConnection); - } - break; - case QNetworkConfiguration::ServiceNetwork: - serviceConfig = publicConfig; - // Defer setting engine and signals until open(). - // fall through - case QNetworkConfiguration::UserChoice: - // Defer setting serviceConfig and activeConfig until open(). - // fall through - default: - engine = 0; - } - - networkConfigurationsChanged(); -} - -void QNetworkSessionPrivate::open() -{ - if (serviceConfig.isValid()) { - lastError = QNetworkSession::OperationNotSupportedError; - emit q->error(lastError); - } else if (!isOpen) { - if ((activeConfig.state() & QNetworkConfiguration::Discovered) != - QNetworkConfiguration::Discovered) { - lastError =QNetworkSession::InvalidConfigurationError; - emit q->error(lastError); - return; - } - opened = true; - - if ((activeConfig.state() & QNetworkConfiguration::Active) != QNetworkConfiguration::Active && - (activeConfig.state() & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) { - state = QNetworkSession::Connecting; - emit q->stateChanged(state); - - engine->connectToId(activeConfig.identifier()); - } - - isOpen = (activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active; - if (isOpen) - emit quitPendingWaitsForOpened(); - } -} - -void QNetworkSessionPrivate::close() -{ - if (serviceConfig.isValid()) { - lastError = QNetworkSession::OperationNotSupportedError; - emit q->error(lastError); - } else if (isOpen) { - opened = false; - isOpen = false; - emit q->closed(); - } -} - -void QNetworkSessionPrivate::stop() -{ - if (serviceConfig.isValid()) { - lastError = QNetworkSession::OperationNotSupportedError; - emit q->error(lastError); - } else { - if ((activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { - state = QNetworkSession::Closing; - emit q->stateChanged(state); - - engine->disconnectFromId(activeConfig.identifier()); - - sessionManager()->forceSessionClose(activeConfig); - } - - opened = false; - isOpen = false; - emit q->closed(); - } -} - -void QNetworkSessionPrivate::migrate() -{ - qWarning("This platform does not support roaming (%s).", __FUNCTION__); -} - -void QNetworkSessionPrivate::accept() -{ - qWarning("This platform does not support roaming (%s).", __FUNCTION__); -} - -void QNetworkSessionPrivate::ignore() -{ - qWarning("This platform does not support roaming (%s).", __FUNCTION__); -} - -void QNetworkSessionPrivate::reject() -{ - qWarning("This platform does not support roaming (%s).", __FUNCTION__); -} - -QNetworkInterface QNetworkSessionPrivate::currentInterface() const -{ - if (!publicConfig.isValid() || !engine || state != QNetworkSession::Connected) - return QNetworkInterface(); - - QString interface = engine->getInterfaceFromId(activeConfig.identifier()); - - if (interface.isEmpty()) - return QNetworkInterface(); - return QNetworkInterface::interfaceFromName(interface); -} - -QVariant QNetworkSessionPrivate::sessionProperty(const QString& /*key*/) const -{ - return QVariant(); -} - -void QNetworkSessionPrivate::setSessionProperty(const QString& /*key*/, const QVariant& /*value*/) -{ -} - -/*QString QNetworkSessionPrivate::bearerName() const -{ - if (!publicConfig.isValid() || !engine) - return QString(); - - return engine->bearerName(activeConfig.identifier()); -}*/ - -QString QNetworkSessionPrivate::errorString() const -{ - switch (lastError) { - case QNetworkSession::UnknownSessionError: - return tr("Unknown session error."); - case QNetworkSession::SessionAbortedError: - return tr("The session was aborted by the user or system."); - case QNetworkSession::OperationNotSupportedError: - return tr("The requested operation is not supported by the system."); - case QNetworkSession::InvalidConfigurationError: - return tr("The specified configuration cannot be used."); - case QNetworkSession::RoamingError: - return tr("Roaming was aborted or is not possible."); - - } - - return QString(); -} - -QNetworkSession::SessionError QNetworkSessionPrivate::error() const -{ - return lastError; -} - -quint64 QNetworkSessionPrivate::bytesWritten() const -{ -#if defined(BACKEND_NM) && 0 - if( NetworkManagerAvailable() && state == QNetworkSession::Connected ) { - if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { - foreach (const QNetworkConfiguration &config, publicConfig.children()) { - if ((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { - return static_cast(getEngineFromId(config.d->id))->sentDataForId(config.d->id); - } - } - } else { - return static_cast(getEngineFromId(activeConfig.d->id))->sentDataForId(activeConfig.d->id); - } - } -#endif - return tx_data; -} - -quint64 QNetworkSessionPrivate::bytesReceived() const -{ -#if defined(BACKEND_NM) && 0 - if( NetworkManagerAvailable() && state == QNetworkSession::Connected ) { - if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { - foreach (const QNetworkConfiguration &config, publicConfig.children()) { - if ((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { - return static_cast(getEngineFromId(activeConfig.d->id))->receivedDataForId(config.d->id); - } - } - } else { - return static_cast(getEngineFromId(activeConfig.d->id))->receivedDataForId(activeConfig.d->id); - } - } -#endif - return rx_data; -} - -quint64 QNetworkSessionPrivate::activeTime() const -{ -#if defined(BACKEND_NM) - if (startTime.isNull()) { - return 0; - } - if(state == QNetworkSession::Connected ) - return startTime.secsTo(QDateTime::currentDateTime()); -#endif - return m_activeTime; -} - -void QNetworkSessionPrivate::updateStateFromServiceNetwork() -{ - QNetworkSession::State oldState = state; - - foreach (const QNetworkConfiguration &config, serviceConfig.children()) { - if ((config.state() & QNetworkConfiguration::Active) != QNetworkConfiguration::Active) - continue; - - if (activeConfig != config) { - if (engine) { - disconnect(engine, SIGNAL(connectionError(QString,QNetworkSessionEngine::ConnectionError)), - this, SLOT(connectionError(QString,QNetworkSessionEngine::ConnectionError))); - } - - activeConfig = config; - engine = getEngineFromId(activeConfig.identifier()); - if (engine) { - connect(engine, SIGNAL(connectionError(QString,QNetworkSessionEngine::ConnectionError)), - this, SLOT(connectionError(QString,QNetworkSessionEngine::ConnectionError)), - Qt::QueuedConnection); - } - emit q->newConfigurationActivated(); - } - - state = QNetworkSession::Connected; - qDebug() << oldState << "->" << state; - if (state != oldState) - emit q->stateChanged(state); - - return; - } - - if (serviceConfig.children().isEmpty()) - state = QNetworkSession::NotAvailable; - else - state = QNetworkSession::Disconnected; - - qDebug() << oldState << "->" << state; - if (state != oldState) - emit q->stateChanged(state); -} - -void QNetworkSessionPrivate::updateStateFromActiveConfig() -{ - if (!engine) - return; - - QNetworkSession::State oldState = state; - - state = engine->sessionStateForId(activeConfig.identifier()); - - bool oldActive = isOpen; - isOpen = (state == QNetworkSession::Connected) ? opened : false; - - if (!oldActive && isOpen) - emit quitPendingWaitsForOpened(); - if (oldActive && !isOpen) - emit q->closed(); - - if (oldState != state) - emit q->stateChanged(state); -} - -void QNetworkSessionPrivate::networkConfigurationsChanged() -{ - if (serviceConfig.isValid()) - updateStateFromServiceNetwork(); - else - updateStateFromActiveConfig(); -#if defined(BACKEND_NM) && 0 - setActiveTimeStamp(); -#endif -} - -void QNetworkSessionPrivate::configurationChanged(const QNetworkConfiguration &config) -{ - if (serviceConfig.isValid() && (config == serviceConfig || config == activeConfig)) - updateStateFromServiceNetwork(); - else if (config == activeConfig) - updateStateFromActiveConfig(); -} - -void QNetworkSessionPrivate::forcedSessionClose(const QNetworkConfiguration &config) -{ - if (activeConfig == config) { - opened = false; - isOpen = false; - - emit q->closed(); - - lastError = QNetworkSession::SessionAbortedError; - emit q->error(lastError); - } -} - -void QNetworkSessionPrivate::connectionError(const QString &id, QNetworkSessionEngine::ConnectionError error) -{ - if (activeConfig.identifier() == id) { - networkConfigurationsChanged(); - switch (error) { - case QNetworkSessionEngine::OperationNotSupported: - lastError = QNetworkSession::OperationNotSupportedError; - opened = false; - break; - case QNetworkSessionEngine::InterfaceLookupError: - case QNetworkSessionEngine::ConnectError: - case QNetworkSessionEngine::DisconnectionError: - default: - lastError = QNetworkSession::UnknownSessionError; - } - - emit quitPendingWaitsForOpened(); - emit q->error(lastError); - } -} - -#if defined(BACKEND_NM) && 0 -void QNetworkSessionPrivate::setActiveTimeStamp() -{ - if(NetworkManagerAvailable()) { - startTime = QDateTime(); - return; - } - QString connectionIdent = q->configuration().identifier(); - QString interface = currentInterface().hardwareAddress().toLower(); - QString devicePath = "/org/freedesktop/Hal/devices/net_" + interface.replace(":","_"); - - QString path; - QString serviceName; - QNetworkManagerInterface * ifaceD; - ifaceD = new QNetworkManagerInterface(); - - QList connections = ifaceD->activeConnections(); - foreach(QDBusObjectPath conpath, connections) { - QNetworkManagerConnectionActive *conDetails; - conDetails = new QNetworkManagerConnectionActive(conpath.path()); - QDBusObjectPath connection = conDetails->connection(); - serviceName = conDetails->serviceName(); - QList so = conDetails->devices(); - foreach(QDBusObjectPath device, so) { - - if(device.path() == devicePath) { - path = connection.path(); - } - break; - } - } -if(serviceName.isEmpty()) - return; - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(serviceName); - QList list = settingsiface->listConnections(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerSettingsConnection *sysIface; - sysIface = new QNetworkManagerSettingsConnection(serviceName, path.path()); - startTime = QDateTime::fromTime_t(sysIface->getTimestamp()); - // isOpen = (publicConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active; - } - if(startTime.isNull()) - startTime = QDateTime::currentDateTime(); -} -#endif - -QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworksession_p.h b/src/network/bearer/qnetworksession_p.h index cd73c9a..6395250 100644 --- a/src/network/bearer/qnetworksession_p.h +++ b/src/network/bearer/qnetworksession_p.h @@ -53,28 +53,26 @@ // We mean it. // -#include "qnetworkconfigmanager_p.h" #include "qnetworksession.h" -#include "qnetworksessionengine_p.h" +#include "qnetworkconfiguration_p.h" -#include "qnetworksession.h" #include -#include QT_BEGIN_NAMESPACE -class QNetworkSessionEngine; - -class QNetworkSessionPrivate : public QObject +class Q_NETWORK_EXPORT QNetworkSessionPrivate : public QObject { Q_OBJECT + + friend class QNetworkSession; + public: - QNetworkSessionPrivate() : - tx_data(0), rx_data(0), m_activeTime(0), isOpen(false) + QNetworkSessionPrivate() + : state(QNetworkSession::Invalid), isOpen(false) { } - ~QNetworkSessionPrivate() + virtual ~QNetworkSessionPrivate() { } @@ -82,49 +80,46 @@ public: //that the state is immediately updated (w/o actually opening //a session). Also this function should take care of //notification hooks to discover future state changes. - void syncStateWithInterface(); + virtual void syncStateWithInterface() = 0; + + virtual QNetworkInterface currentInterface() const = 0; + virtual QVariant sessionProperty(const QString& key) const = 0; + virtual void setSessionProperty(const QString& key, const QVariant& value) = 0; - QNetworkInterface currentInterface() const; - QVariant sessionProperty(const QString& key) const; - void setSessionProperty(const QString& key, const QVariant& value); - QString bearerName() const; + virtual void open() = 0; + virtual void close() = 0; + virtual void stop() = 0; - void open(); - void close(); - void stop(); - void migrate(); - void accept(); - void ignore(); - void reject(); + virtual void setALREnabled(bool enabled) { } + virtual void migrate() = 0; + virtual void accept() = 0; + virtual void ignore() = 0; + virtual void reject() = 0; - QString errorString() const; //must return translated string - QNetworkSession::SessionError error() const; + virtual QString errorString() const = 0; //must return translated string + virtual QNetworkSession::SessionError error() const = 0; - quint64 bytesWritten() const; - quint64 bytesReceived() const; - quint64 activeTime() const; + virtual quint64 bytesWritten() const = 0; + virtual quint64 bytesReceived() const = 0; + virtual quint64 activeTime() const = 0; -private: - void updateStateFromServiceNetwork(); - void updateStateFromActiveConfig(); +protected: + inline QNetworkConfigurationPrivatePointer privateConfiguration(const QNetworkConfiguration &config) const + { + return config.d; + } Q_SIGNALS: //releases any pending waitForOpened() calls void quitPendingWaitsForOpened(); -private Q_SLOTS: - void networkConfigurationsChanged(); - void configurationChanged(const QNetworkConfiguration &config); - void forcedSessionClose(const QNetworkConfiguration &config); - void connectionError(const QString &id, QNetworkSessionEngine::ConnectionError error); - -private: - QNetworkConfigurationManager manager; - - quint64 tx_data; - quint64 rx_data; - quint64 m_activeTime; + void error(QNetworkSession::SessionError error); + void stateChanged(QNetworkSession::State state); + void closed(); + void newConfigurationActivated(); + void preferredConfigurationChanged(const QNetworkConfiguration &config, bool isSeamless); +protected: // The config set on QNetworkSession. QNetworkConfiguration publicConfig; @@ -140,19 +135,7 @@ private: QNetworkSession::State state; bool isOpen; - bool opened; - - QNetworkSessionEngine *engine; - - QNetworkSession::SessionError lastError; - - QNetworkSession* q; - friend class QNetworkSession; - -#if defined(BACKEND_NM) - QDateTime startTime; - void setActiveTimeStamp(); -#endif + QNetworkSession *q; }; QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworksession_s60_p.cpp b/src/network/bearer/qnetworksession_s60_p.cpp deleted file mode 100644 index 4d427c8..0000000 --- a/src/network/bearer/qnetworksession_s60_p.cpp +++ /dev/null @@ -1,1134 +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 -#include "qnetworksession_s60_p.h" -#include "qnetworkconfiguration_s60_p.h" -#include "qnetworkconfigmanager_s60_p.h" -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -QNetworkSessionPrivate::QNetworkSessionPrivate() - : CActive(CActive::EPriorityStandard), state(QNetworkSession::Invalid), - isOpen(false), ipConnectionNotifier(0), iError(QNetworkSession::UnknownSessionError), - iALREnabled(0) -{ - CActiveScheduler::Add(this); - - // Try to load "Open C" dll dynamically and - // try to attach to setdefaultif function dynamically. - if (iOpenCLibrary.Load(_L("libc")) == KErrNone) { - iDynamicSetdefaultif = (TOpenCSetdefaultifFunction)iOpenCLibrary.Lookup(564); - } - - TRAP_IGNORE(iConnectionMonitor.ConnectL()); -} - -QNetworkSessionPrivate::~QNetworkSessionPrivate() -{ - isOpen = false; - - // Cancel Connection Progress Notifications first. - // Note: ConnectionNotifier must be destroyed before Canceling RConnection::Start() - // => deleting ipConnectionNotifier results RConnection::CancelProgressNotification() - delete ipConnectionNotifier; - ipConnectionNotifier = NULL; - - // Cancel possible RConnection::Start() - Cancel(); - -#ifdef SNAP_FUNCTIONALITY_AVAILABLE - if (iMobility) { - delete iMobility; - iMobility = NULL; - } -#endif - - iConnection.Close(); - iSocketServ.Close(); - if (iDynamicSetdefaultif) { - iDynamicSetdefaultif(0); - } - - iConnectionMonitor.CancelNotifications(); - iConnectionMonitor.Close(); - - iOpenCLibrary.Close(); -} - -void QNetworkSessionPrivate::syncStateWithInterface() -{ - if (!publicConfig.d) { - return; - } - - // Start monitoring changes in IAP states - TRAP_IGNORE(iConnectionMonitor.NotifyEventL(*this)); - - // Check open connections to see if there is already - // an open connection to selected IAP or SNAP - TUint count; - TRequestStatus status; - iConnectionMonitor.GetConnectionCount(count, status); - User::WaitForRequest(status); - if (status.Int() != KErrNone) { - return; - } - - TUint numSubConnections; - TUint connectionId; - for (TUint i = 1; i <= count; i++) { - TInt ret = iConnectionMonitor.GetConnectionInfo(i, connectionId, numSubConnections); - if (ret == KErrNone) { - TUint apId; - iConnectionMonitor.GetUintAttribute(connectionId, 0, KIAPId, apId, status); - User::WaitForRequest(status); - if (status.Int() == KErrNone) { - TInt connectionStatus; - iConnectionMonitor.GetIntAttribute(connectionId, 0, KConnectionStatus, connectionStatus, status); - User::WaitForRequest(status); - if (connectionStatus == KLinkLayerOpen) { - if (state != QNetworkSession::Closing) { - if (newState(QNetworkSession::Connected, apId)) { - return; - } - } - } - } - } - } - - if (state != QNetworkSession::Connected) { - // There were no open connections to used IAP or SNAP - if ((publicConfig.d.data()->state & QNetworkConfiguration::Discovered) == - QNetworkConfiguration::Discovered) { - newState(QNetworkSession::Disconnected); - } else { - newState(QNetworkSession::NotAvailable); - } - } -} - -QNetworkInterface QNetworkSessionPrivate::interface(TUint iapId) const -{ - QString interfaceName; - - TSoInetInterfaceInfo ifinfo; - TPckg ifinfopkg(ifinfo); - TSoInetIfQuery ifquery; - TPckg ifquerypkg(ifquery); - - // Open dummy socket for interface queries - RSocket socket; - TInt retVal = socket.Open(iSocketServ, _L("udp")); - if (retVal != KErrNone) { - return QNetworkInterface(); - } - - // Start enumerating interfaces - socket.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl); - while(socket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, ifinfopkg) == KErrNone) { - ifquery.iName = ifinfo.iName; - TInt err = socket.GetOpt(KSoInetIfQueryByName, KSolInetIfQuery, ifquerypkg); - if(err == KErrNone && ifquery.iZone[1] == iapId) { // IAP ID is index 1 of iZone - if(ifinfo.iAddress.Address() > 0) { - interfaceName = QString::fromUtf16(ifinfo.iName.Ptr(),ifinfo.iName.Length()); - break; - } - } - } - - socket.Close(); - - if (interfaceName.isEmpty()) { - return QNetworkInterface(); - } - - return QNetworkInterface::interfaceFromName(interfaceName); -} - -QNetworkInterface QNetworkSessionPrivate::currentInterface() const -{ - if (!publicConfig.isValid() || state != QNetworkSession::Connected) { - return QNetworkInterface(); - } - - return activeInterface; -} - -QVariant QNetworkSessionPrivate::sessionProperty(const QString& /*key*/) const -{ - return QVariant(); -} - -void QNetworkSessionPrivate::setSessionProperty(const QString& /*key*/, const QVariant& /*value*/) -{ -} - -QString QNetworkSessionPrivate::errorString() const -{ - switch (iError) { - case QNetworkSession::UnknownSessionError: - return tr("Unknown session error."); - case QNetworkSession::SessionAbortedError: - return tr("The session was aborted by the user or system."); - case QNetworkSession::OperationNotSupportedError: - return tr("The requested operation is not supported by the system."); - case QNetworkSession::InvalidConfigurationError: - return tr("The specified configuration cannot be used."); - case QNetworkSession::RoamingError: - return tr("Roaming was aborted or is not possible."); - } - - return QString(); -} - -QNetworkSession::SessionError QNetworkSessionPrivate::error() const -{ - return iError; -} - -void QNetworkSessionPrivate::open() -{ - if (isOpen || !publicConfig.d || (state == QNetworkSession::Connecting)) { - return; - } - - // Cancel notifications from RConnectionMonitor - // => RConnection::ProgressNotification will be used for IAP/SNAP monitoring - iConnectionMonitor.CancelNotifications(); - - TInt error = iSocketServ.Connect(); - if (error != KErrNone) { - // Could not open RSocketServ - newState(QNetworkSession::Invalid); - iError = QNetworkSession::UnknownSessionError; - emit q->error(iError); - syncStateWithInterface(); - return; - } - - error = iConnection.Open(iSocketServ); - if (error != KErrNone) { - // Could not open RConnection - iSocketServ.Close(); - newState(QNetworkSession::Invalid); - iError = QNetworkSession::UnknownSessionError; - emit q->error(iError); - syncStateWithInterface(); - return; - } - - // Use RConnection::ProgressNotification for IAP/SNAP monitoring - // (<=> ConnectionProgressNotifier uses RConnection::ProgressNotification) - if (!ipConnectionNotifier) { - ipConnectionNotifier = new ConnectionProgressNotifier(*this,iConnection); - } - if (ipConnectionNotifier) { - ipConnectionNotifier->StartNotifications(); - } - - if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { - // Search through existing connections. - // If there is already connection which matches to given IAP - // try to attach to existing connection. - TBool connected(EFalse); - TConnectionInfoBuf connInfo; - TUint count; - if (iConnection.EnumerateConnections(count) == KErrNone) { - for (TUint i=1; i<=count; i++) { - // Note: GetConnectionInfo expects 1-based index. - if (iConnection.GetConnectionInfo(i, connInfo) == KErrNone) { - if (connInfo().iIapId == publicConfig.d.data()->numericId) { - if (iConnection.Attach(connInfo, RConnection::EAttachTypeNormal) == KErrNone) { - activeConfig = publicConfig; - activeInterface = interface(activeConfig.d.data()->numericId); - connected = ETrue; - startTime = QDateTime::currentDateTime(); - if (iDynamicSetdefaultif) { - // Use name of the IAP to set default IAP - QByteArray nameAsByteArray = publicConfig.name().toUtf8(); - ifreq ifr; - strcpy(ifr.ifr_name, nameAsByteArray.constData()); - - error = iDynamicSetdefaultif(&ifr); - } - isOpen = true; - // Make sure that state will be Connected - newState(QNetworkSession::Connected); - emit quitPendingWaitsForOpened(); - break; - } - } - } - } - } - if (!connected) { - TCommDbConnPref pref; - pref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); - pref.SetIapId(publicConfig.d.data()->numericId); - iConnection.Start(pref, iStatus); - if (!IsActive()) { - SetActive(); - } - newState(QNetworkSession::Connecting); - } - } else if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { - TConnSnapPref snapPref(publicConfig.d.data()->numericId); - iConnection.Start(snapPref, iStatus); - if (!IsActive()) { - SetActive(); - } - newState(QNetworkSession::Connecting); - } else if (publicConfig.type() == QNetworkConfiguration::UserChoice) { - iKnownConfigsBeforeConnectionStart = ((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager)->accessPointConfigurations.keys(); - iConnection.Start(iStatus); - if (!IsActive()) { - SetActive(); - } - newState(QNetworkSession::Connecting); - } - - if (error != KErrNone) { - isOpen = false; - iError = QNetworkSession::UnknownSessionError; - emit q->error(iError); - if (ipConnectionNotifier) { - ipConnectionNotifier->StopNotifications(); - } - syncStateWithInterface(); - } -} - -TUint QNetworkSessionPrivate::iapClientCount(TUint aIAPId) const -{ - TRequestStatus status; - TUint connectionCount; - iConnectionMonitor.GetConnectionCount(connectionCount, status); - User::WaitForRequest(status); - if (status.Int() == KErrNone) { - for (TUint i = 1; i <= connectionCount; i++) { - TUint connectionId; - TUint subConnectionCount; - iConnectionMonitor.GetConnectionInfo(i, connectionId, subConnectionCount); - TUint apId; - iConnectionMonitor.GetUintAttribute(connectionId, subConnectionCount, KIAPId, apId, status); - User::WaitForRequest(status); - if (apId == aIAPId) { - TConnMonClientEnumBuf buf; - iConnectionMonitor.GetPckgAttribute(connectionId, 0, KClientInfo, buf, status); - User::WaitForRequest(status); - if (status.Int() == KErrNone) { - return buf().iCount; - } - } - } - } - return 0; -} - -void QNetworkSessionPrivate::close(bool allowSignals) -{ - if (!isOpen) { - return; - } - - TUint activeIap = activeConfig.d.data()->numericId; - isOpen = false; - activeConfig = QNetworkConfiguration(); - serviceConfig = QNetworkConfiguration(); - - Cancel(); -#ifdef SNAP_FUNCTIONALITY_AVAILABLE - if (iMobility) { - delete iMobility; - iMobility = NULL; - } -#endif - - if (ipConnectionNotifier) { - ipConnectionNotifier->StopNotifications(); - } - - iConnection.Close(); - iSocketServ.Close(); - if (iDynamicSetdefaultif) { - iDynamicSetdefaultif(0); - } - -#ifdef Q_CC_NOKIAX86 - if ((allowSignals && iapClientCount(activeIap) <= 0) || -#else - if ((allowSignals && iapClientCount(activeIap) <= 1) || -#endif - (publicConfig.type() == QNetworkConfiguration::UserChoice)) { - newState(QNetworkSession::Closing); - } - - syncStateWithInterface(); - if (allowSignals) { - if (publicConfig.type() == QNetworkConfiguration::UserChoice) { - newState(QNetworkSession::Disconnected); - } - emit q->closed(); - } -} - -void QNetworkSessionPrivate::stop() -{ - if (!isOpen) { - return; - } - isOpen = false; - newState(QNetworkSession::Closing); - iConnection.Stop(RConnection::EStopAuthoritative); - isOpen = true; - close(false); - emit q->closed(); -} - -void QNetworkSessionPrivate::migrate() -{ -#ifdef SNAP_FUNCTIONALITY_AVAILABLE - iMobility->MigrateToPreferredCarrier(); -#endif -} - -void QNetworkSessionPrivate::ignore() -{ -#ifdef SNAP_FUNCTIONALITY_AVAILABLE - iMobility->IgnorePreferredCarrier(); - if (!iALRUpgradingConnection) { - newState(QNetworkSession::Disconnected); - } else { - newState(QNetworkSession::Connected,iOldRoamingIap); - } -#endif -} - -void QNetworkSessionPrivate::accept() -{ -#ifdef SNAP_FUNCTIONALITY_AVAILABLE - iMobility->NewCarrierAccepted(); - if (iDynamicSetdefaultif) { - // Use name of the IAP to set default IAP - QByteArray nameAsByteArray = activeConfig.name().toUtf8(); - ifreq ifr; - strcpy(ifr.ifr_name, nameAsByteArray.constData()); - - iDynamicSetdefaultif(&ifr); - } - newState(QNetworkSession::Connected, iNewRoamingIap); -#endif -} - -void QNetworkSessionPrivate::reject() -{ -#ifdef SNAP_FUNCTIONALITY_AVAILABLE - iMobility->NewCarrierRejected(); - if (!iALRUpgradingConnection) { - newState(QNetworkSession::Disconnected); - } else { - newState(QNetworkSession::Connected, iOldRoamingIap); - } -#endif -} - -#ifdef SNAP_FUNCTIONALITY_AVAILABLE -void QNetworkSessionPrivate::PreferredCarrierAvailable(TAccessPointInfo aOldAPInfo, - TAccessPointInfo aNewAPInfo, - TBool aIsUpgrade, - TBool aIsSeamless) -{ - iOldRoamingIap = aOldAPInfo.AccessPoint(); - iNewRoamingIap = aNewAPInfo.AccessPoint(); - newState(QNetworkSession::Roaming); - if (iALREnabled > 0) { - iALRUpgradingConnection = aIsUpgrade; - QList configs = publicConfig.children(); - for (int i=0; i < configs.count(); i++) { - if (configs[i].d.data()->numericId == aNewAPInfo.AccessPoint()) { - emit q->preferredConfigurationChanged(configs[i],aIsSeamless); - } - } - } else { - migrate(); - } -} - -void QNetworkSessionPrivate::NewCarrierActive(TAccessPointInfo /*aNewAPInfo*/, TBool /*aIsSeamless*/) -{ - if (iALREnabled > 0) { - emit q->newConfigurationActivated(); - } else { - accept(); - } -} - -void QNetworkSessionPrivate::Error(TInt /*aError*/) -{ - if (isOpen) { - isOpen = false; - activeConfig = QNetworkConfiguration(); - serviceConfig = QNetworkConfiguration(); - iError = QNetworkSession::RoamingError; - emit q->error(iError); - Cancel(); - if (ipConnectionNotifier) { - ipConnectionNotifier->StopNotifications(); - } - syncStateWithInterface(); - // In some cases IAP is still in Connected state when - // syncStateWithInterface(); is called - // => Following call makes sure that Session state - // changes immediately to Disconnected. - newState(QNetworkSession::Disconnected); - emit q->closed(); - } -} -#endif - -void QNetworkSessionPrivate::setALREnabled(bool enabled) -{ - if (enabled) { - iALREnabled++; - } else { - iALREnabled--; - } -} - -QNetworkConfiguration QNetworkSessionPrivate::bestConfigFromSNAP(const QNetworkConfiguration& snapConfig) const -{ - QNetworkConfiguration config; - QList subConfigurations = snapConfig.children(); - for (int i = 0; i < subConfigurations.count(); i++ ) { - if (subConfigurations[i].state() == QNetworkConfiguration::Active) { - config = subConfigurations[i]; - break; - } else if (!config.isValid() && subConfigurations[i].state() == QNetworkConfiguration::Discovered) { - config = subConfigurations[i]; - } - } - if (!config.isValid() && subConfigurations.count() > 0) { - config = subConfigurations[0]; - } - return config; -} - -quint64 QNetworkSessionPrivate::bytesWritten() const -{ - return transferredData(KUplinkData); -} - -quint64 QNetworkSessionPrivate::bytesReceived() const -{ - return transferredData(KDownlinkData); -} - -quint64 QNetworkSessionPrivate::transferredData(TUint dataType) const -{ - if (!publicConfig.isValid()) { - return 0; - } - - QNetworkConfiguration config; - if (publicConfig.type() == QNetworkConfiguration::UserChoice) { - if (serviceConfig.isValid()) { - config = serviceConfig; - } else { - if (activeConfig.isValid()) { - config = activeConfig; - } - } - } else { - config = publicConfig; - } - - if (!config.isValid()) { - return 0; - } - - TUint count; - TRequestStatus status; - iConnectionMonitor.GetConnectionCount(count, status); - User::WaitForRequest(status); - if (status.Int() != KErrNone) { - return 0; - } - - TUint transferredData = 0; - TUint numSubConnections; - TUint connectionId; - bool configFound; - for (TUint i = 1; i <= count; i++) { - TInt ret = iConnectionMonitor.GetConnectionInfo(i, connectionId, numSubConnections); - if (ret == KErrNone) { - TUint apId; - iConnectionMonitor.GetUintAttribute(connectionId, 0, KIAPId, apId, status); - User::WaitForRequest(status); - if (status.Int() == KErrNone) { - configFound = false; - if (config.type() == QNetworkConfiguration::ServiceNetwork) { - QList configs = config.children(); - for (int i=0; i < configs.count(); i++) { - if (configs[i].d.data()->numericId == apId) { - configFound = true; - break; - } - } - } else if (config.d.data()->numericId == apId) { - configFound = true; - } - if (configFound) { - TUint tData; - iConnectionMonitor.GetUintAttribute(connectionId, 0, dataType, tData, status ); - User::WaitForRequest(status); - if (status.Int() == KErrNone) { - transferredData += tData; - } - } - } - } - } - - return transferredData; -} - -quint64 QNetworkSessionPrivate::activeTime() const -{ - if (!isOpen || startTime.isNull()) { - return 0; - } - return startTime.secsTo(QDateTime::currentDateTime()); -} - -QNetworkConfiguration QNetworkSessionPrivate::activeConfiguration(TUint32 iapId) const -{ - if (iapId == 0) { - _LIT(KSetting, "IAP\\Id"); - iConnection.GetIntSetting(KSetting, iapId); - } - -#ifdef SNAP_FUNCTIONALITY_AVAILABLE - if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { - // Try to search IAP from the used SNAP using IAP Id - QList children = publicConfig.children(); - for (int i=0; i < children.count(); i++) { - if (children[i].d.data()->numericId == iapId) { - return children[i]; - } - } - - // Given IAP Id was not found from the used SNAP - // => Try to search matching IAP using mappingName - // mappingName contains: - // 1. "Access point name" for "Packet data" Bearer - // 2. "WLAN network name" (= SSID) for "Wireless LAN" Bearer - // 3. "Dial-up number" for "Data call Bearer" or "High Speed (GSM)" Bearer - // <=> Note: It's possible that in this case reported IAP is - // clone of the one of the IAPs of the used SNAP - // => If mappingName matches, clone has been found - QNetworkConfiguration pt; - pt.d = ((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager)->accessPointConfigurations.value(QString::number(qHash(iapId))); - if (pt.d) { - for (int i=0; i < children.count(); i++) { - if (children[i].d.data()->mappingName == pt.d.data()->mappingName) { - return children[i]; - } - } - } else { - // Given IAP Id was not found from known IAPs array - return QNetworkConfiguration(); - } - - // Matching IAP was not found from used SNAP - // => IAP from another SNAP is returned - // (Note: Returned IAP matches to given IAP Id) - return pt; - } -#endif - - if (publicConfig.type() == QNetworkConfiguration::UserChoice) { - if (publicConfig.d.data()->manager) { - QNetworkConfiguration pt; - // Try to found User Selected IAP from known IAPs (accessPointConfigurations) - pt.d = ((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager)->accessPointConfigurations.value(QString::number(qHash(iapId))); - if (pt.d) { - return pt; - } else { - // Check if new (WLAN) IAP was created in IAP/SNAP dialog - // 1. Sync internal configurations array to commsdb first - ((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager)->updateConfigurations(); - // 2. Check if new configuration was created during connection creation - QList knownConfigs = ((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager)->accessPointConfigurations.keys(); - if (knownConfigs.count() > iKnownConfigsBeforeConnectionStart.count()) { - // Configuration count increased => new configuration was created - // => Search new, created configuration - QString newIapId; - for (int i=0; i < iKnownConfigsBeforeConnectionStart.count(); i++) { - if (knownConfigs[i] != iKnownConfigsBeforeConnectionStart[i]) { - newIapId = knownConfigs[i]; - break; - } - } - if (newIapId.isEmpty()) { - newIapId = knownConfigs[knownConfigs.count()-1]; - } - pt.d = ((QNetworkConfigurationManagerPrivate*)publicConfig.d.data()->manager)->accessPointConfigurations.value(newIapId); - if (pt.d) { - return pt; - } - } - } - } - return QNetworkConfiguration(); - } - - return publicConfig; -} - -void QNetworkSessionPrivate::RunL() -{ - TInt statusCode = iStatus.Int(); - - switch (statusCode) { - case KErrNone: // Connection created succesfully - { - TInt error = KErrNone; - QNetworkConfiguration newActiveConfig = activeConfiguration(); - if (!newActiveConfig.isValid()) { - error = KErrGeneral; - } else if (iDynamicSetdefaultif) { - // Use name of the IAP to set default IAP - QByteArray nameAsByteArray = newActiveConfig.name().toUtf8(); - ifreq ifr; - strcpy(ifr.ifr_name, nameAsByteArray.constData()); - - error = iDynamicSetdefaultif(&ifr); - } - - if (error != KErrNone) { - isOpen = false; - iError = QNetworkSession::UnknownSessionError; - emit q->error(iError); - Cancel(); - if (ipConnectionNotifier) { - ipConnectionNotifier->StopNotifications(); - } - syncStateWithInterface(); - return; - } - -#ifdef SNAP_FUNCTIONALITY_AVAILABLE - if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { - // Activate ALR monitoring - iMobility = CActiveCommsMobilityApiExt::NewL(iConnection, *this); - } -#endif - isOpen = true; - activeConfig = newActiveConfig; - activeInterface = interface(activeConfig.d.data()->numericId); - if (publicConfig.type() == QNetworkConfiguration::UserChoice) { - QNetworkConfiguration pt; - pt.d = activeConfig.d.data()->serviceNetworkPtr; - serviceConfig = pt; - } - - startTime = QDateTime::currentDateTime(); - - newState(QNetworkSession::Connected); - emit quitPendingWaitsForOpened(); - } - break; - case KErrNotFound: // Connection failed - isOpen = false; - activeConfig = QNetworkConfiguration(); - serviceConfig = QNetworkConfiguration(); - iError = QNetworkSession::InvalidConfigurationError; - emit q->error(iError); - Cancel(); - if (ipConnectionNotifier) { - ipConnectionNotifier->StopNotifications(); - } - syncStateWithInterface(); - break; - case KErrCancel: // Connection attempt cancelled - case KErrAlreadyExists: // Connection already exists - default: - isOpen = false; - activeConfig = QNetworkConfiguration(); - serviceConfig = QNetworkConfiguration(); - iError = QNetworkSession::UnknownSessionError; - emit q->error(iError); - Cancel(); - if (ipConnectionNotifier) { - ipConnectionNotifier->StopNotifications(); - } - syncStateWithInterface(); - break; - } -} - -void QNetworkSessionPrivate::DoCancel() -{ - iConnection.Close(); -} - -bool QNetworkSessionPrivate::newState(QNetworkSession::State newState, TUint accessPointId) -{ - // Make sure that activeConfig is always updated when SNAP is signaled to be - // connected. - if (isOpen && publicConfig.type() == QNetworkConfiguration::ServiceNetwork && - newState == QNetworkSession::Connected) { - activeConfig = activeConfiguration(accessPointId); - activeInterface = interface(activeConfig.d.data()->numericId); - } - - // Make sure that same state is not signaled twice in a row. - if (state == newState) { - return true; - } - - // Make sure that Connecting state does not overwrite Roaming state - if (state == QNetworkSession::Roaming && newState == QNetworkSession::Connecting) { - return false; - } - - bool emitSessionClosed = false; - if (isOpen && state == QNetworkSession::Connected && newState == QNetworkSession::Disconnected) { - // Active & Connected state should change directly to Disconnected state - // only when something forces connection to close (eg. when another - // application or session stops connection or when network drops - // unexpectedly). - isOpen = false; - activeConfig = QNetworkConfiguration(); - serviceConfig = QNetworkConfiguration(); - iError = QNetworkSession::SessionAbortedError; - emit q->error(iError); - Cancel(); - if (ipConnectionNotifier) { - ipConnectionNotifier->StopNotifications(); - } - // Start monitoring changes in IAP states - TRAP_IGNORE(iConnectionMonitor.NotifyEventL(*this)); - emitSessionClosed = true; // Emit SessionClosed after state change has been reported - } - - bool retVal = false; - if (accessPointId == 0) { - state = newState; - emit q->stateChanged(state); - retVal = true; - } else { - if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { - if (publicConfig.d.data()->numericId == accessPointId) { - state = newState; - emit q->stateChanged(state); - retVal = true; - } - } else if (publicConfig.type() == QNetworkConfiguration::UserChoice && isOpen) { - if (activeConfig.d.data()->numericId == accessPointId) { - state = newState; - emit q->stateChanged(state); - retVal = true; - } - } else if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { - QList subConfigurations = publicConfig.children(); - for (int i = 0; i < subConfigurations.count(); i++) { - if (subConfigurations[i].d.data()->numericId == accessPointId) { - if (newState == QNetworkSession::Connected) { - // Make sure that when AccessPoint is reported to be Connected - // also state of the related configuration changes to Active. - subConfigurations[i].d.data()->state = QNetworkConfiguration::Active; - - state = newState; - emit q->stateChanged(state); - retVal = true; - } else { - if (newState == QNetworkSession::Disconnected) { - // Make sure that when AccessPoint is reported to be disconnected - // also state of the related configuration changes from Active to Defined. - subConfigurations[i].d.data()->state = QNetworkConfiguration::Defined; - } - QNetworkConfiguration config = bestConfigFromSNAP(publicConfig); - if ((config.state() == QNetworkConfiguration::Defined) || - (config.state() == QNetworkConfiguration::Discovered)) { - state = newState; - emit q->stateChanged(state); - retVal = true; - } - } - } - } - } - } - - if (emitSessionClosed) { - emit q->closed(); - } - - return retVal; -} - -void QNetworkSessionPrivate::handleSymbianConnectionStatusChange(TInt aConnectionStatus, - TInt aError, - TUint accessPointId) -{ - switch (aConnectionStatus) - { - // Connection unitialised - case KConnectionUninitialised: - break; - - // Starting connetion selection - case KStartingSelection: - break; - - // Selection finished - case KFinishedSelection: - if (aError == KErrNone) - { - // The user successfully selected an IAP to be used - break; - } - else - { - // The user pressed e.g. "Cancel" and did not select an IAP - newState(QNetworkSession::Disconnected,accessPointId); - } - break; - - // Connection failure - case KConnectionFailure: - newState(QNetworkSession::NotAvailable); - break; - - // Prepearing connection (e.g. dialing) - case KPsdStartingConfiguration: - case KPsdFinishedConfiguration: - case KCsdFinishedDialling: - case KCsdScanningScript: - case KCsdGettingLoginInfo: - case KCsdGotLoginInfo: - break; - - // Creating connection (e.g. GPRS activation) - case KCsdStartingConnect: - case KCsdFinishedConnect: - newState(QNetworkSession::Connecting,accessPointId); - break; - - // Starting log in - case KCsdStartingLogIn: - break; - - // Finished login - case KCsdFinishedLogIn: - break; - - // Connection open - case KConnectionOpen: - break; - - case KLinkLayerOpen: - newState(QNetworkSession::Connected,accessPointId); - break; - - // Connection blocked or suspended - case KDataTransferTemporarilyBlocked: - break; - - // Hangup or GRPS deactivation - case KConnectionStartingClose: - newState(QNetworkSession::Closing,accessPointId); - break; - - // Connection closed - case KConnectionClosed: - break; - - case KLinkLayerClosed: - newState(QNetworkSession::Disconnected,accessPointId); - break; - - // Unhandled state - default: - break; - } -} - -void QNetworkSessionPrivate::EventL(const CConnMonEventBase& aEvent) -{ - switch (aEvent.EventType()) - { - case EConnMonConnectionStatusChange: - { - CConnMonConnectionStatusChange* realEvent; - realEvent = (CConnMonConnectionStatusChange*) &aEvent; - - TUint connectionId = realEvent->ConnectionId(); - TInt connectionStatus = realEvent->ConnectionStatus(); - - // Try to Find IAP Id using connection Id - TUint apId = 0; - if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { - QList subConfigurations = publicConfig.children(); - for (int i = 0; i < subConfigurations.count(); i++ ) { - if (subConfigurations[i].d.data()->connectionId == connectionId) { - apId = subConfigurations[i].d.data()->numericId; - break; - } - } - } else if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { - if (publicConfig.d.data()->connectionId == connectionId) { - apId = publicConfig.d.data()->numericId; - } - } - - if (apId > 0) { - handleSymbianConnectionStatusChange(connectionStatus, KErrNone, apId); - } - } - break; - - case EConnMonCreateConnection: - { - CConnMonCreateConnection* realEvent; - realEvent = (CConnMonCreateConnection*) &aEvent; - TUint apId; - TUint connectionId = realEvent->ConnectionId(); - TRequestStatus status; - iConnectionMonitor.GetUintAttribute(connectionId, 0, KIAPId, apId, status); - User::WaitForRequest(status); - if (status.Int() == KErrNone) { - // Store connection id to related AccessPoint Configuration - if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { - QList subConfigurations = publicConfig.children(); - for (int i = 0; i < subConfigurations.count(); i++ ) { - if (subConfigurations[i].d.data()->numericId == apId) { - subConfigurations[i].d.data()->connectionId = connectionId; - break; - } - } - } else if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { - if (publicConfig.d.data()->numericId == apId) { - publicConfig.d.data()->connectionId = connectionId; - } - } - } - } - break; - - case EConnMonDeleteConnection: - { - CConnMonDeleteConnection* realEvent; - realEvent = (CConnMonDeleteConnection*) &aEvent; - TUint connectionId = realEvent->ConnectionId(); - // Remove connection id from related AccessPoint Configuration - if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { - QList subConfigurations = publicConfig.children(); - for (int i = 0; i < subConfigurations.count(); i++ ) { - if (subConfigurations[i].d.data()->connectionId == connectionId) { - subConfigurations[i].d.data()->connectionId = 0; - break; - } - } - } else if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { - if (publicConfig.d.data()->connectionId == connectionId) { - publicConfig.d.data()->connectionId = 0; - } - } - } - break; - - default: - // For unrecognized events - break; - } -} - -ConnectionProgressNotifier::ConnectionProgressNotifier(QNetworkSessionPrivate& owner, RConnection& connection) - : CActive(CActive::EPriorityStandard), iOwner(owner), iConnection(connection) -{ - CActiveScheduler::Add(this); -} - -ConnectionProgressNotifier::~ConnectionProgressNotifier() -{ - Cancel(); -} - -void ConnectionProgressNotifier::StartNotifications() -{ - if (!IsActive()) { - SetActive(); - } - iConnection.ProgressNotification(iProgress, iStatus); -} - -void ConnectionProgressNotifier::StopNotifications() -{ - Cancel(); -} - -void ConnectionProgressNotifier::DoCancel() -{ - iConnection.CancelProgressNotification(); -} - -void ConnectionProgressNotifier::RunL() -{ - if (iStatus == KErrNone) { - iOwner.handleSymbianConnectionStatusChange(iProgress().iStage, iProgress().iError); - - SetActive(); - iConnection.ProgressNotification(iProgress, iStatus); - } -} - -#include "moc_qnetworksession_s60_p.cpp" - -QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworksession_s60_p.h b/src/network/bearer/qnetworksession_s60_p.h deleted file mode 100644 index 9ac5ed8..0000000 --- a/src/network/bearer/qnetworksession_s60_p.h +++ /dev/null @@ -1,212 +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 QNETWORKSESSIONPRIVATE_H -#define QNETWORKSESSIONPRIVATE_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 "qnetworksession.h" - -#include - -#include -#include -#include -#include -#ifdef SNAP_FUNCTIONALITY_AVAILABLE - #include -#endif - -typedef int(*TOpenCSetdefaultifFunction)(const struct ifreq*); - -QT_BEGIN_NAMESPACE - -class ConnectionProgressNotifier; - -#ifdef SNAP_FUNCTIONALITY_AVAILABLE -class QNetworkSessionPrivate : public QObject, public CActive, public MMobilityProtocolResp, - public MConnectionMonitorObserver -#else -class QNetworkSessionPrivate : public QObject, public CActive, public MConnectionMonitorObserver -#endif -{ - Q_OBJECT -public: - QNetworkSessionPrivate(); - ~QNetworkSessionPrivate(); - - //called by QNetworkSession constructor and ensures - //that the state is immediately updated (w/o actually opening - //a session). Also this function should take care of - //notification hooks to discover future state changes. - void syncStateWithInterface(); - - QNetworkInterface currentInterface() const; - QVariant sessionProperty(const QString& key) const; - void setSessionProperty(const QString& key, const QVariant& value); - - void setALREnabled(bool enabled); - - void open(); - void close(bool allowSignals = true); - void stop(); - void migrate(); - void accept(); - void ignore(); - void reject(); - - QString errorString() const; //must return translated string - QNetworkSession::SessionError error() const; - quint64 bytesWritten() const; - quint64 bytesReceived() const; - quint64 activeTime() const; - -#ifdef SNAP_FUNCTIONALITY_AVAILABLE -public: // From MMobilityProtocolResp - void PreferredCarrierAvailable(TAccessPointInfo aOldAPInfo, - TAccessPointInfo aNewAPInfo, - TBool aIsUpgrade, - TBool aIsSeamless); - - void NewCarrierActive(TAccessPointInfo aNewAPInfo, TBool aIsSeamless); - - void Error(TInt aError); -#endif - -Q_SIGNALS: - //releases any pending waitForOpened() calls - void quitPendingWaitsForOpened(); - -protected: // From CActive - void RunL(); - void DoCancel(); - -private: // MConnectionMonitorObserver - void EventL(const CConnMonEventBase& aEvent); - -private: - TUint iapClientCount(TUint aIAPId) const; - quint64 transferredData(TUint dataType) const; - bool newState(QNetworkSession::State newState, TUint accessPointId = 0); - void handleSymbianConnectionStatusChange(TInt aConnectionStatus, TInt aError, TUint accessPointId = 0); - QNetworkConfiguration bestConfigFromSNAP(const QNetworkConfiguration& snapConfig) const; - QNetworkConfiguration activeConfiguration(TUint32 iapId = 0) const; - QNetworkInterface interface(TUint iapId) const; - -private: // data - // The config set on QNetworkSession - mutable 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. - mutable QNetworkConfiguration serviceConfig; - - // This is the actual active configuration currently in use by the session. - // Either a copy of publicConfig or one of serviceConfig.children(). - mutable QNetworkConfiguration activeConfig; - - mutable QNetworkInterface activeInterface; - - QNetworkSession::State state; - bool isOpen; - - QNetworkSession* q; - QDateTime startTime; - - RLibrary iOpenCLibrary; - TOpenCSetdefaultifFunction iDynamicSetdefaultif; - - mutable RSocketServ iSocketServ; - mutable RConnection iConnection; - mutable RConnectionMonitor iConnectionMonitor; - ConnectionProgressNotifier* ipConnectionNotifier; -#ifdef SNAP_FUNCTIONALITY_AVAILABLE - CActiveCommsMobilityApiExt* iMobility; -#endif - - QNetworkSession::SessionError iError; - TInt iALREnabled; - TBool iALRUpgradingConnection; - - QList iKnownConfigsBeforeConnectionStart; - - TUint32 iOldRoamingIap; - TUint32 iNewRoamingIap; - - friend class QNetworkSession; - friend class ConnectionProgressNotifier; -}; - -class ConnectionProgressNotifier : public CActive -{ -public: - ConnectionProgressNotifier(QNetworkSessionPrivate& owner, RConnection& connection); - ~ConnectionProgressNotifier(); - - void StartNotifications(); - void StopNotifications(); - -protected: // From CActive - void RunL(); - void DoCancel(); - -private: // Data - QNetworkSessionPrivate& iOwner; - RConnection& iConnection; - TNifProgressBuf iProgress; - -}; - -QT_END_NAMESPACE - -#endif //QNETWORKSESSIONPRIVATE_H - diff --git a/src/network/bearer/qnetworksessionengine_p.h b/src/network/bearer/qnetworksessionengine_p.h index a1a3370..02772cb 100644 --- a/src/network/bearer/qnetworksessionengine_p.h +++ b/src/network/bearer/qnetworksessionengine_p.h @@ -97,6 +97,8 @@ public: virtual QNetworkConfigurationManager::Capabilities capabilities() const = 0; + virtual QNetworkSessionPrivate *createSessionBackend() = 0; + public: //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 diff --git a/src/plugins/bearer/generic/generic.pro b/src/plugins/bearer/generic/generic.pro index 0015041..d039731 100644 --- a/src/plugins/bearer/generic/generic.pro +++ b/src/plugins/bearer/generic/generic.pro @@ -4,8 +4,11 @@ include(../../qpluginbase.pri) QT += network HEADERS += qgenericengine.h \ + ../qnetworksession_impl.h \ ../platformdefs_win.h -SOURCES += qgenericengine.cpp main.cpp +SOURCES += qgenericengine.cpp \ + ../qnetworksession_impl.cpp \ + main.cpp QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/bearer target.path += $$[QT_INSTALL_PLUGINS]/bearer diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp index d50aa75..e9770e1 100644 --- a/src/plugins/bearer/generic/qgenericengine.cpp +++ b/src/plugins/bearer/generic/qgenericengine.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qgenericengine.h" +#include "../qnetworksession_impl.h" #include @@ -142,8 +143,6 @@ static QString qGetInterfaceType(const QString &interface) QGenericEngine::QGenericEngine(QObject *parent) : QNetworkSessionEngine(parent) { - qDebug() << Q_FUNC_INFO; - connect(&pollTimer, SIGNAL(timeout()), this, SLOT(doRequestUpdate())); pollTimer.setInterval(10000); doRequestUpdate(); @@ -321,5 +320,10 @@ QNetworkConfigurationManager::Capabilities QGenericEngine::capabilities() const return QNetworkConfigurationManager::ForcedRoaming; } +QNetworkSessionPrivate *QGenericEngine::createSessionBackend() +{ + return new QNetworkSessionPrivateImpl; +} + QT_END_NAMESPACE diff --git a/src/plugins/bearer/generic/qgenericengine.h b/src/plugins/bearer/generic/qgenericengine.h index 730301b..04b845e 100644 --- a/src/plugins/bearer/generic/qgenericengine.h +++ b/src/plugins/bearer/generic/qgenericengine.h @@ -50,6 +50,7 @@ QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; +class QNetworkSessionPrivate; class QGenericEngine : public QNetworkSessionEngine { @@ -73,6 +74,8 @@ public: QNetworkConfigurationManager::Capabilities capabilities() const; + QNetworkSessionPrivate *createSessionBackend(); + private Q_SLOTS: void doRequestUpdate(); diff --git a/src/plugins/bearer/qnetworksession_impl.cpp b/src/plugins/bearer/qnetworksession_impl.cpp new file mode 100644 index 0000000..49a2d72 --- /dev/null +++ b/src/plugins/bearer/qnetworksession_impl.cpp @@ -0,0 +1,485 @@ +/**************************************************************************** +** +** 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 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 "qnetworksession_impl.h" + +#include +#include +#include + +#include +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +static QNetworkSessionEngine *getEngineFromId(const QString &id) +{ + QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); + + foreach (QNetworkSessionEngine *engine, priv->sessionEngines) { + if (engine->hasIdentifier(id)) + return engine; + } + + return 0; +} + +class QNetworkSessionManagerPrivate : public QObject +{ + Q_OBJECT + +public: + QNetworkSessionManagerPrivate(QObject *parent = 0); + ~QNetworkSessionManagerPrivate(); + + void forceSessionClose(const QNetworkConfiguration &config); + +Q_SIGNALS: + void forcedSessionClose(const QNetworkConfiguration &config); +}; + +#include "qnetworksession_p.moc" + +Q_GLOBAL_STATIC(QNetworkSessionManagerPrivate, sessionManager); + +QNetworkSessionManagerPrivate::QNetworkSessionManagerPrivate(QObject *parent) +: QObject(parent) +{ +} + +QNetworkSessionManagerPrivate::~QNetworkSessionManagerPrivate() +{ +} + +void QNetworkSessionManagerPrivate::forceSessionClose(const QNetworkConfiguration &config) +{ + emit forcedSessionClose(config); +} + +void QNetworkSessionPrivateImpl::syncStateWithInterface() +{ + connect(&manager, SIGNAL(updateCompleted()), this, SLOT(networkConfigurationsChanged())); + connect(&manager, SIGNAL(configurationChanged(QNetworkConfiguration)), + this, SLOT(configurationChanged(QNetworkConfiguration))); + connect(sessionManager(), SIGNAL(forcedSessionClose(QNetworkConfiguration)), + this, SLOT(forcedSessionClose(QNetworkConfiguration))); + + opened = false; + isOpen = false; + state = QNetworkSession::Invalid; + lastError = QNetworkSession::UnknownSessionError; + + qRegisterMetaType + ("QNetworkSessionEngine::ConnectionError"); + + switch (publicConfig.type()) { + case QNetworkConfiguration::InternetAccessPoint: + activeConfig = publicConfig; + engine = getEngineFromId(activeConfig.identifier()); + if (engine) { + connect(engine, SIGNAL(connectionError(QString,QNetworkSessionEngine::ConnectionError)), + this, SLOT(connectionError(QString,QNetworkSessionEngine::ConnectionError)), + Qt::QueuedConnection); + } + break; + case QNetworkConfiguration::ServiceNetwork: + serviceConfig = publicConfig; + // Defer setting engine and signals until open(). + // fall through + case QNetworkConfiguration::UserChoice: + // Defer setting serviceConfig and activeConfig until open(). + // fall through + default: + engine = 0; + } + + networkConfigurationsChanged(); +} + +void QNetworkSessionPrivateImpl::open() +{ + if (serviceConfig.isValid()) { + lastError = QNetworkSession::OperationNotSupportedError; + emit QNetworkSessionPrivate::error(lastError); + } else if (!isOpen) { + if ((activeConfig.state() & QNetworkConfiguration::Discovered) != + QNetworkConfiguration::Discovered) { + lastError =QNetworkSession::InvalidConfigurationError; + emit QNetworkSessionPrivate::error(lastError); + return; + } + opened = true; + + if ((activeConfig.state() & QNetworkConfiguration::Active) != QNetworkConfiguration::Active && + (activeConfig.state() & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) { + state = QNetworkSession::Connecting; + emit stateChanged(state); + + engine->connectToId(activeConfig.identifier()); + } + + isOpen = (activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active; + if (isOpen) + emit quitPendingWaitsForOpened(); + } +} + +void QNetworkSessionPrivateImpl::close() +{ + if (serviceConfig.isValid()) { + lastError = QNetworkSession::OperationNotSupportedError; + emit QNetworkSessionPrivate::error(lastError); + } else if (isOpen) { + opened = false; + isOpen = false; + emit closed(); + } +} + +void QNetworkSessionPrivateImpl::stop() +{ + if (serviceConfig.isValid()) { + lastError = QNetworkSession::OperationNotSupportedError; + emit QNetworkSessionPrivate::error(lastError); + } else { + if ((activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + state = QNetworkSession::Closing; + emit stateChanged(state); + + engine->disconnectFromId(activeConfig.identifier()); + + sessionManager()->forceSessionClose(activeConfig); + } + + opened = false; + isOpen = false; + emit closed(); + } +} + +void QNetworkSessionPrivateImpl::migrate() +{ + qWarning("This platform does not support roaming (%s).", __FUNCTION__); +} + +void QNetworkSessionPrivateImpl::accept() +{ + qWarning("This platform does not support roaming (%s).", __FUNCTION__); +} + +void QNetworkSessionPrivateImpl::ignore() +{ + qWarning("This platform does not support roaming (%s).", __FUNCTION__); +} + +void QNetworkSessionPrivateImpl::reject() +{ + qWarning("This platform does not support roaming (%s).", __FUNCTION__); +} + +QNetworkInterface QNetworkSessionPrivateImpl::currentInterface() const +{ + if (!publicConfig.isValid() || !engine || state != QNetworkSession::Connected) + return QNetworkInterface(); + + QString interface = engine->getInterfaceFromId(activeConfig.identifier()); + + if (interface.isEmpty()) + return QNetworkInterface(); + return QNetworkInterface::interfaceFromName(interface); +} + +QVariant QNetworkSessionPrivateImpl::sessionProperty(const QString& /*key*/) const +{ + return QVariant(); +} + +void QNetworkSessionPrivateImpl::setSessionProperty(const QString& /*key*/, const QVariant& /*value*/) +{ +} + +/*QString QNetworkSessionPrivateImpl::bearerName() const +{ + if (!publicConfig.isValid() || !engine) + return QString(); + + return engine->bearerName(activeConfig.identifier()); +}*/ + +QString QNetworkSessionPrivateImpl::errorString() const +{ + switch (lastError) { + case QNetworkSession::UnknownSessionError: + return tr("Unknown session error."); + case QNetworkSession::SessionAbortedError: + return tr("The session was aborted by the user or system."); + case QNetworkSession::OperationNotSupportedError: + return tr("The requested operation is not supported by the system."); + case QNetworkSession::InvalidConfigurationError: + return tr("The specified configuration cannot be used."); + case QNetworkSession::RoamingError: + return tr("Roaming was aborted or is not possible."); + + } + + return QString(); +} + +QNetworkSession::SessionError QNetworkSessionPrivateImpl::error() const +{ + return lastError; +} + +quint64 QNetworkSessionPrivateImpl::bytesWritten() const +{ +#if defined(BACKEND_NM) && 0 + if( NetworkManagerAvailable() && state == QNetworkSession::Connected ) { + if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + foreach (const QNetworkConfiguration &config, publicConfig.children()) { + if ((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + return static_cast(getEngineFromId(config.d->id))->sentDataForId(config.d->id); + } + } + } else { + return static_cast(getEngineFromId(activeConfig.d->id))->sentDataForId(activeConfig.d->id); + } + } +#endif + return tx_data; +} + +quint64 QNetworkSessionPrivateImpl::bytesReceived() const +{ +#if defined(BACKEND_NM) && 0 + if( NetworkManagerAvailable() && state == QNetworkSession::Connected ) { + if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + foreach (const QNetworkConfiguration &config, publicConfig.children()) { + if ((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + return static_cast(getEngineFromId(activeConfig.d->id))->receivedDataForId(config.d->id); + } + } + } else { + return static_cast(getEngineFromId(activeConfig.d->id))->receivedDataForId(activeConfig.d->id); + } + } +#endif + return rx_data; +} + +quint64 QNetworkSessionPrivateImpl::activeTime() const +{ +#if defined(BACKEND_NM) + if (startTime.isNull()) { + return 0; + } + if(state == QNetworkSession::Connected ) + return startTime.secsTo(QDateTime::currentDateTime()); +#endif + return m_activeTime; +} + +void QNetworkSessionPrivateImpl::updateStateFromServiceNetwork() +{ + QNetworkSession::State oldState = state; + + foreach (const QNetworkConfiguration &config, serviceConfig.children()) { + if ((config.state() & QNetworkConfiguration::Active) != QNetworkConfiguration::Active) + continue; + + if (activeConfig != config) { + if (engine) { + disconnect(engine, SIGNAL(connectionError(QString,QNetworkSessionEngine::ConnectionError)), + this, SLOT(connectionError(QString,QNetworkSessionEngine::ConnectionError))); + } + + activeConfig = config; + engine = getEngineFromId(activeConfig.identifier()); + if (engine) { + connect(engine, SIGNAL(connectionError(QString,QNetworkSessionEngine::ConnectionError)), + this, SLOT(connectionError(QString,QNetworkSessionEngine::ConnectionError)), + Qt::QueuedConnection); + } + emit newConfigurationActivated(); + } + + state = QNetworkSession::Connected; + qDebug() << oldState << "->" << state; + if (state != oldState) + emit stateChanged(state); + + return; + } + + if (serviceConfig.children().isEmpty()) + state = QNetworkSession::NotAvailable; + else + state = QNetworkSession::Disconnected; + + qDebug() << oldState << "->" << state; + if (state != oldState) + emit stateChanged(state); +} + +void QNetworkSessionPrivateImpl::updateStateFromActiveConfig() +{ + if (!engine) + return; + + QNetworkSession::State oldState = state; + + state = engine->sessionStateForId(activeConfig.identifier()); + + bool oldActive = isOpen; + isOpen = (state == QNetworkSession::Connected) ? opened : false; + + if (!oldActive && isOpen) + emit quitPendingWaitsForOpened(); + if (oldActive && !isOpen) + emit closed(); + + if (oldState != state) + emit stateChanged(state); +} + +void QNetworkSessionPrivateImpl::networkConfigurationsChanged() +{ + if (serviceConfig.isValid()) + updateStateFromServiceNetwork(); + else + updateStateFromActiveConfig(); +#if defined(BACKEND_NM) && 0 + setActiveTimeStamp(); +#endif +} + +void QNetworkSessionPrivateImpl::configurationChanged(const QNetworkConfiguration &config) +{ + if (serviceConfig.isValid() && (config == serviceConfig || config == activeConfig)) + updateStateFromServiceNetwork(); + else if (config == activeConfig) + updateStateFromActiveConfig(); +} + +void QNetworkSessionPrivateImpl::forcedSessionClose(const QNetworkConfiguration &config) +{ + if (activeConfig == config) { + opened = false; + isOpen = false; + + emit closed(); + + lastError = QNetworkSession::SessionAbortedError; + emit QNetworkSessionPrivate::error(lastError); + } +} + +void QNetworkSessionPrivateImpl::connectionError(const QString &id, QNetworkSessionEngine::ConnectionError error) +{ + if (activeConfig.identifier() == id) { + networkConfigurationsChanged(); + switch (error) { + case QNetworkSessionEngine::OperationNotSupported: + lastError = QNetworkSession::OperationNotSupportedError; + opened = false; + break; + case QNetworkSessionEngine::InterfaceLookupError: + case QNetworkSessionEngine::ConnectError: + case QNetworkSessionEngine::DisconnectionError: + default: + lastError = QNetworkSession::UnknownSessionError; + } + + emit quitPendingWaitsForOpened(); + emit QNetworkSessionPrivate::error(lastError); + } +} + +#if defined(BACKEND_NM) && 0 +void QNetworkSessionPrivateImpl::setActiveTimeStamp() +{ + if(NetworkManagerAvailable()) { + startTime = QDateTime(); + return; + } + QString connectionIdent = q->configuration().identifier(); + QString interface = currentInterface().hardwareAddress().toLower(); + QString devicePath = "/org/freedesktop/Hal/devices/net_" + interface.replace(":","_"); + + QString path; + QString serviceName; + QNetworkManagerInterface * ifaceD; + ifaceD = new QNetworkManagerInterface(); + + QList connections = ifaceD->activeConnections(); + foreach(QDBusObjectPath conpath, connections) { + QNetworkManagerConnectionActive *conDetails; + conDetails = new QNetworkManagerConnectionActive(conpath.path()); + QDBusObjectPath connection = conDetails->connection(); + serviceName = conDetails->serviceName(); + QList so = conDetails->devices(); + foreach(QDBusObjectPath device, so) { + + if(device.path() == devicePath) { + path = connection.path(); + } + break; + } + } +if(serviceName.isEmpty()) + return; + QNetworkManagerSettings *settingsiface; + settingsiface = new QNetworkManagerSettings(serviceName); + QList list = settingsiface->listConnections(); + foreach(QDBusObjectPath path, list) { + QNetworkManagerSettingsConnection *sysIface; + sysIface = new QNetworkManagerSettingsConnection(serviceName, path.path()); + startTime = QDateTime::fromTime_t(sysIface->getTimestamp()); + // isOpen = (publicConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active; + } + if(startTime.isNull()) + startTime = QDateTime::currentDateTime(); +} +#endif + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/qnetworksession_impl.h b/src/plugins/bearer/qnetworksession_impl.h new file mode 100644 index 0000000..104d1f0 --- /dev/null +++ b/src/plugins/bearer/qnetworksession_impl.h @@ -0,0 +1,136 @@ +/**************************************************************************** +** +** 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 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 QNETWORKSESSION_IMPL_H +#define QNETWORKSESSION_IMPL_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 +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +class QNetworkSessionEngine; + +class QNetworkSessionPrivateImpl : public QNetworkSessionPrivate +{ + Q_OBJECT +public: + QNetworkSessionPrivateImpl() : + tx_data(0), rx_data(0), m_activeTime(0) + { + } + + ~QNetworkSessionPrivateImpl() + { + } + + //called by QNetworkSession constructor and ensures + //that the state is immediately updated (w/o actually opening + //a session). Also this function should take care of + //notification hooks to discover future state changes. + void syncStateWithInterface(); + + QNetworkInterface currentInterface() const; + QVariant sessionProperty(const QString& key) const; + void setSessionProperty(const QString& key, const QVariant& value); + + void open(); + void close(); + void stop(); + void migrate(); + void accept(); + void ignore(); + void reject(); + + QString errorString() const; //must return translated string + QNetworkSession::SessionError error() const; + + quint64 bytesWritten() const; + quint64 bytesReceived() const; + quint64 activeTime() const; + +private: + void updateStateFromServiceNetwork(); + void updateStateFromActiveConfig(); + +private Q_SLOTS: + void networkConfigurationsChanged(); + void configurationChanged(const QNetworkConfiguration &config); + void forcedSessionClose(const QNetworkConfiguration &config); + void connectionError(const QString &id, QNetworkSessionEngine::ConnectionError error); + +private: + QNetworkConfigurationManager manager; + + quint64 tx_data; + quint64 rx_data; + quint64 m_activeTime; + + bool opened; + + QNetworkSessionEngine *engine; + + QNetworkSession::SessionError lastError; + +#if defined(BACKEND_NM) + QDateTime startTime; + void setActiveTimeStamp(); +#endif +}; + +QT_END_NAMESPACE + +#endif //QNETWORKSESSION_IMPL_H + diff --git a/src/plugins/bearer/symbian/main.cpp b/src/plugins/bearer/symbian/main.cpp index 8865f4d..22d654a 100644 --- a/src/plugins/bearer/symbian/main.cpp +++ b/src/plugins/bearer/symbian/main.cpp @@ -72,8 +72,6 @@ QStringList QSymbianEnginePlugin::keys() const QBearerEngine *QSymbianEnginePlugin::create(const QString &key) const { - qDebug() << Q_FUNC_INFO; - if (key == QLatin1String("symbian")) return new SymbianEngine; else diff --git a/src/plugins/bearer/symbian/qnetworksession_impl.cpp b/src/plugins/bearer/symbian/qnetworksession_impl.cpp new file mode 100644 index 0000000..24948cf --- /dev/null +++ b/src/plugins/bearer/symbian/qnetworksession_impl.cpp @@ -0,0 +1,1125 @@ +/**************************************************************************** +** +** 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 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 "qnetworksession_impl.h" +#include "symbianengine.h" + +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +QNetworkSessionPrivateImpl::QNetworkSessionPrivateImpl(SymbianEngine *engine) + : CActive(CActive::EPriorityStandard), engine(engine), ipConnectionNotifier(0), + iError(QNetworkSession::UnknownSessionError), + iALREnabled(0) +{ + CActiveScheduler::Add(this); + + // Try to load "Open C" dll dynamically and + // try to attach to setdefaultif function dynamically. + if (iOpenCLibrary.Load(_L("libc")) == KErrNone) { + iDynamicSetdefaultif = (TOpenCSetdefaultifFunction)iOpenCLibrary.Lookup(564); + } + + TRAP_IGNORE(iConnectionMonitor.ConnectL()); +} + +QNetworkSessionPrivateImpl::~QNetworkSessionPrivateImpl() +{ + isOpen = false; + + // Cancel Connection Progress Notifications first. + // Note: ConnectionNotifier must be destroyed before Canceling RConnection::Start() + // => deleting ipConnectionNotifier results RConnection::CancelProgressNotification() + delete ipConnectionNotifier; + ipConnectionNotifier = NULL; + + // Cancel possible RConnection::Start() + Cancel(); + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + if (iMobility) { + delete iMobility; + iMobility = NULL; + } +#endif + + iConnection.Close(); + iSocketServ.Close(); + if (iDynamicSetdefaultif) { + iDynamicSetdefaultif(0); + } + + iConnectionMonitor.CancelNotifications(); + iConnectionMonitor.Close(); + + iOpenCLibrary.Close(); +} + +void QNetworkSessionPrivateImpl::syncStateWithInterface() +{ + if (!privateConfiguration(publicConfig)) + return; + + // Start monitoring changes in IAP states + TRAP_IGNORE(iConnectionMonitor.NotifyEventL(*this)); + + // Check open connections to see if there is already + // an open connection to selected IAP or SNAP + TUint count; + TRequestStatus status; + iConnectionMonitor.GetConnectionCount(count, status); + User::WaitForRequest(status); + if (status.Int() != KErrNone) { + return; + } + + TUint numSubConnections; + TUint connectionId; + for (TUint i = 1; i <= count; i++) { + TInt ret = iConnectionMonitor.GetConnectionInfo(i, connectionId, numSubConnections); + if (ret == KErrNone) { + TUint apId; + iConnectionMonitor.GetUintAttribute(connectionId, 0, KIAPId, apId, status); + User::WaitForRequest(status); + if (status.Int() == KErrNone) { + TInt connectionStatus; + iConnectionMonitor.GetIntAttribute(connectionId, 0, KConnectionStatus, connectionStatus, status); + User::WaitForRequest(status); + if (connectionStatus == KLinkLayerOpen) { + if (state != QNetworkSession::Closing) { + if (newState(QNetworkSession::Connected, apId)) { + return; + } + } + } + } + } + } + + if (state != QNetworkSession::Connected) { + // There were no open connections to used IAP or SNAP + if ((privateConfiguration(publicConfig)->state & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + newState(QNetworkSession::Disconnected); + } else { + newState(QNetworkSession::NotAvailable); + } + } +} + +QNetworkInterface QNetworkSessionPrivateImpl::interface(TUint iapId) const +{ + QString interfaceName; + + TSoInetInterfaceInfo ifinfo; + TPckg ifinfopkg(ifinfo); + TSoInetIfQuery ifquery; + TPckg ifquerypkg(ifquery); + + // Open dummy socket for interface queries + RSocket socket; + TInt retVal = socket.Open(iSocketServ, _L("udp")); + if (retVal != KErrNone) { + return QNetworkInterface(); + } + + // Start enumerating interfaces + socket.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl); + while(socket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, ifinfopkg) == KErrNone) { + ifquery.iName = ifinfo.iName; + TInt err = socket.GetOpt(KSoInetIfQueryByName, KSolInetIfQuery, ifquerypkg); + if(err == KErrNone && ifquery.iZone[1] == iapId) { // IAP ID is index 1 of iZone + if(ifinfo.iAddress.Address() > 0) { + interfaceName = QString::fromUtf16(ifinfo.iName.Ptr(),ifinfo.iName.Length()); + break; + } + } + } + + socket.Close(); + + if (interfaceName.isEmpty()) { + return QNetworkInterface(); + } + + return QNetworkInterface::interfaceFromName(interfaceName); +} + +QNetworkInterface QNetworkSessionPrivateImpl::currentInterface() const +{ + if (!publicConfig.isValid() || state != QNetworkSession::Connected) { + return QNetworkInterface(); + } + + return activeInterface; +} + +QVariant QNetworkSessionPrivateImpl::sessionProperty(const QString& /*key*/) const +{ + return QVariant(); +} + +void QNetworkSessionPrivateImpl::setSessionProperty(const QString& /*key*/, const QVariant& /*value*/) +{ +} + +QString QNetworkSessionPrivateImpl::errorString() const +{ + switch (iError) { + case QNetworkSession::UnknownSessionError: + return tr("Unknown session error."); + case QNetworkSession::SessionAbortedError: + return tr("The session was aborted by the user or system."); + case QNetworkSession::OperationNotSupportedError: + return tr("The requested operation is not supported by the system."); + case QNetworkSession::InvalidConfigurationError: + return tr("The specified configuration cannot be used."); + case QNetworkSession::RoamingError: + return tr("Roaming was aborted or is not possible."); + } + + return QString(); +} + +QNetworkSession::SessionError QNetworkSessionPrivateImpl::error() const +{ + return iError; +} + +void QNetworkSessionPrivateImpl::open() +{ + if (isOpen || !privateConfiguration(publicConfig) || (state == QNetworkSession::Connecting)) { + return; + } + + // Cancel notifications from RConnectionMonitor + // => RConnection::ProgressNotification will be used for IAP/SNAP monitoring + iConnectionMonitor.CancelNotifications(); + + TInt error = iSocketServ.Connect(); + if (error != KErrNone) { + // Could not open RSocketServ + newState(QNetworkSession::Invalid); + iError = QNetworkSession::UnknownSessionError; + emit QNetworkSessionPrivate::error(iError); + syncStateWithInterface(); + return; + } + + error = iConnection.Open(iSocketServ); + if (error != KErrNone) { + // Could not open RConnection + iSocketServ.Close(); + newState(QNetworkSession::Invalid); + iError = QNetworkSession::UnknownSessionError; + emit QNetworkSessionPrivate::error(iError); + syncStateWithInterface(); + return; + } + + // Use RConnection::ProgressNotification for IAP/SNAP monitoring + // (<=> ConnectionProgressNotifier uses RConnection::ProgressNotification) + if (!ipConnectionNotifier) { + ipConnectionNotifier = new ConnectionProgressNotifier(*this,iConnection); + } + if (ipConnectionNotifier) { + ipConnectionNotifier->StartNotifications(); + } + + if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { + // Search through existing connections. + // If there is already connection which matches to given IAP + // try to attach to existing connection. + TBool connected(EFalse); + TConnectionInfoBuf connInfo; + TUint count; + if (iConnection.EnumerateConnections(count) == KErrNone) { + for (TUint i=1; i<=count; i++) { + // Note: GetConnectionInfo expects 1-based index. + if (iConnection.GetConnectionInfo(i, connInfo) == KErrNone) { + if (connInfo().iIapId == toSymbianConfig(privateConfiguration(publicConfig))->numericId) { + if (iConnection.Attach(connInfo, RConnection::EAttachTypeNormal) == KErrNone) { + activeConfig = publicConfig; + activeInterface = interface(toSymbianConfig(privateConfiguration(activeConfig))->numericId); + connected = ETrue; + startTime = QDateTime::currentDateTime(); + if (iDynamicSetdefaultif) { + // Use name of the IAP to set default IAP + QByteArray nameAsByteArray = publicConfig.name().toUtf8(); + ifreq ifr; + strcpy(ifr.ifr_name, nameAsByteArray.constData()); + + error = iDynamicSetdefaultif(&ifr); + } + isOpen = true; + // Make sure that state will be Connected + newState(QNetworkSession::Connected); + emit quitPendingWaitsForOpened(); + break; + } + } + } + } + } + if (!connected) { + TCommDbConnPref pref; + pref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); + pref.SetIapId(toSymbianConfig(privateConfiguration(publicConfig))->numericId); + iConnection.Start(pref, iStatus); + if (!IsActive()) { + SetActive(); + } + newState(QNetworkSession::Connecting); + } + } else if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + TConnSnapPref snapPref(toSymbianConfig(privateConfiguration(publicConfig))->numericId); + iConnection.Start(snapPref, iStatus); + if (!IsActive()) { + SetActive(); + } + newState(QNetworkSession::Connecting); + } else if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + iKnownConfigsBeforeConnectionStart = engine->accessPointConfigurations.keys(); + iConnection.Start(iStatus); + if (!IsActive()) { + SetActive(); + } + newState(QNetworkSession::Connecting); + } + + if (error != KErrNone) { + isOpen = false; + iError = QNetworkSession::UnknownSessionError; + emit QNetworkSessionPrivate::error(iError); + if (ipConnectionNotifier) { + ipConnectionNotifier->StopNotifications(); + } + syncStateWithInterface(); + } +} + +TUint QNetworkSessionPrivateImpl::iapClientCount(TUint aIAPId) const +{ + TRequestStatus status; + TUint connectionCount; + iConnectionMonitor.GetConnectionCount(connectionCount, status); + User::WaitForRequest(status); + if (status.Int() == KErrNone) { + for (TUint i = 1; i <= connectionCount; i++) { + TUint connectionId; + TUint subConnectionCount; + iConnectionMonitor.GetConnectionInfo(i, connectionId, subConnectionCount); + TUint apId; + iConnectionMonitor.GetUintAttribute(connectionId, subConnectionCount, KIAPId, apId, status); + User::WaitForRequest(status); + if (apId == aIAPId) { + TConnMonClientEnumBuf buf; + iConnectionMonitor.GetPckgAttribute(connectionId, 0, KClientInfo, buf, status); + User::WaitForRequest(status); + if (status.Int() == KErrNone) { + return buf().iCount; + } + } + } + } + return 0; +} + +void QNetworkSessionPrivateImpl::close(bool allowSignals) +{ + if (!isOpen) { + return; + } + + TUint activeIap = toSymbianConfig(privateConfiguration(activeConfig))->numericId; + isOpen = false; + activeConfig = QNetworkConfiguration(); + serviceConfig = QNetworkConfiguration(); + + Cancel(); +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + if (iMobility) { + delete iMobility; + iMobility = NULL; + } +#endif + + if (ipConnectionNotifier) { + ipConnectionNotifier->StopNotifications(); + } + + iConnection.Close(); + iSocketServ.Close(); + if (iDynamicSetdefaultif) { + iDynamicSetdefaultif(0); + } + +#ifdef Q_CC_NOKIAX86 + if ((allowSignals && iapClientCount(activeIap) <= 0) || +#else + if ((allowSignals && iapClientCount(activeIap) <= 1) || +#endif + (publicConfig.type() == QNetworkConfiguration::UserChoice)) { + newState(QNetworkSession::Closing); + } + + syncStateWithInterface(); + if (allowSignals) { + if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + newState(QNetworkSession::Disconnected); + } + emit closed(); + } +} + +void QNetworkSessionPrivateImpl::stop() +{ + if (!isOpen) { + return; + } + isOpen = false; + newState(QNetworkSession::Closing); + iConnection.Stop(RConnection::EStopAuthoritative); + isOpen = true; + close(false); + emit closed(); +} + +void QNetworkSessionPrivateImpl::migrate() +{ +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + iMobility->MigrateToPreferredCarrier(); +#endif +} + +void QNetworkSessionPrivateImpl::ignore() +{ +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + iMobility->IgnorePreferredCarrier(); + if (!iALRUpgradingConnection) { + newState(QNetworkSession::Disconnected); + } else { + newState(QNetworkSession::Connected,iOldRoamingIap); + } +#endif +} + +void QNetworkSessionPrivateImpl::accept() +{ +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + iMobility->NewCarrierAccepted(); + if (iDynamicSetdefaultif) { + // Use name of the IAP to set default IAP + QByteArray nameAsByteArray = activeConfig.name().toUtf8(); + ifreq ifr; + strcpy(ifr.ifr_name, nameAsByteArray.constData()); + + iDynamicSetdefaultif(&ifr); + } + newState(QNetworkSession::Connected, iNewRoamingIap); +#endif +} + +void QNetworkSessionPrivateImpl::reject() +{ +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + iMobility->NewCarrierRejected(); + if (!iALRUpgradingConnection) { + newState(QNetworkSession::Disconnected); + } else { + newState(QNetworkSession::Connected, iOldRoamingIap); + } +#endif +} + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE +void QNetworkSessionPrivateImpl::PreferredCarrierAvailable(TAccessPointInfo aOldAPInfo, + TAccessPointInfo aNewAPInfo, + TBool aIsUpgrade, + TBool aIsSeamless) +{ + iOldRoamingIap = aOldAPInfo.AccessPoint(); + iNewRoamingIap = aNewAPInfo.AccessPoint(); + newState(QNetworkSession::Roaming); + if (iALREnabled > 0) { + iALRUpgradingConnection = aIsUpgrade; + QList configs = publicConfig.children(); + for (int i=0; i < configs.count(); i++) { + if (toSymbianConfig(privateConfiguration(configs[i]))->numericId == aNewAPInfo.AccessPoint()) { + emit preferredConfigurationChanged(configs[i], aIsSeamless); + } + } + } else { + migrate(); + } +} + +void QNetworkSessionPrivateImpl::NewCarrierActive(TAccessPointInfo /*aNewAPInfo*/, TBool /*aIsSeamless*/) +{ + if (iALREnabled > 0) { + emit newConfigurationActivated(); + } else { + accept(); + } +} + +void QNetworkSessionPrivateImpl::Error(TInt /*aError*/) +{ + if (isOpen) { + isOpen = false; + activeConfig = QNetworkConfiguration(); + serviceConfig = QNetworkConfiguration(); + iError = QNetworkSession::RoamingError; + emit QNetworkSessionPrivate::error(iError); + Cancel(); + if (ipConnectionNotifier) { + ipConnectionNotifier->StopNotifications(); + } + syncStateWithInterface(); + // In some cases IAP is still in Connected state when + // syncStateWithInterface(); is called + // => Following call makes sure that Session state + // changes immediately to Disconnected. + newState(QNetworkSession::Disconnected); + emit closed(); + } +} +#endif + +void QNetworkSessionPrivateImpl::setALREnabled(bool enabled) +{ + if (enabled) { + iALREnabled++; + } else { + iALREnabled--; + } +} + +QNetworkConfiguration QNetworkSessionPrivateImpl::bestConfigFromSNAP(const QNetworkConfiguration& snapConfig) const +{ + QNetworkConfiguration config; + QList subConfigurations = snapConfig.children(); + for (int i = 0; i < subConfigurations.count(); i++ ) { + if (subConfigurations[i].state() == QNetworkConfiguration::Active) { + config = subConfigurations[i]; + break; + } else if (!config.isValid() && subConfigurations[i].state() == QNetworkConfiguration::Discovered) { + config = subConfigurations[i]; + } + } + if (!config.isValid() && subConfigurations.count() > 0) { + config = subConfigurations[0]; + } + return config; +} + +quint64 QNetworkSessionPrivateImpl::bytesWritten() const +{ + return transferredData(KUplinkData); +} + +quint64 QNetworkSessionPrivateImpl::bytesReceived() const +{ + return transferredData(KDownlinkData); +} + +quint64 QNetworkSessionPrivateImpl::transferredData(TUint dataType) const +{ + if (!publicConfig.isValid()) { + return 0; + } + + QNetworkConfiguration config; + if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + if (serviceConfig.isValid()) { + config = serviceConfig; + } else { + if (activeConfig.isValid()) { + config = activeConfig; + } + } + } else { + config = publicConfig; + } + + if (!config.isValid()) { + return 0; + } + + TUint count; + TRequestStatus status; + iConnectionMonitor.GetConnectionCount(count, status); + User::WaitForRequest(status); + if (status.Int() != KErrNone) { + return 0; + } + + TUint transferredData = 0; + TUint numSubConnections; + TUint connectionId; + bool configFound; + for (TUint i = 1; i <= count; i++) { + TInt ret = iConnectionMonitor.GetConnectionInfo(i, connectionId, numSubConnections); + if (ret == KErrNone) { + TUint apId; + iConnectionMonitor.GetUintAttribute(connectionId, 0, KIAPId, apId, status); + User::WaitForRequest(status); + if (status.Int() == KErrNone) { + configFound = false; + if (config.type() == QNetworkConfiguration::ServiceNetwork) { + QList configs = config.children(); + for (int i=0; i < configs.count(); i++) { + if (toSymbianConfig(privateConfiguration(configs[i]))->numericId == apId) { + configFound = true; + break; + } + } + } else if (toSymbianConfig(privateConfiguration(config))->numericId == apId) { + configFound = true; + } + if (configFound) { + TUint tData; + iConnectionMonitor.GetUintAttribute(connectionId, 0, dataType, tData, status ); + User::WaitForRequest(status); + if (status.Int() == KErrNone) { + transferredData += tData; + } + } + } + } + } + + return transferredData; +} + +quint64 QNetworkSessionPrivateImpl::activeTime() const +{ + if (!isOpen || startTime.isNull()) { + return 0; + } + return startTime.secsTo(QDateTime::currentDateTime()); +} + +QNetworkConfiguration QNetworkSessionPrivateImpl::activeConfiguration(TUint32 iapId) const +{ + if (iapId == 0) { + _LIT(KSetting, "IAP\\Id"); + iConnection.GetIntSetting(KSetting, iapId); + } + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + // Try to search IAP from the used SNAP using IAP Id + QList children = publicConfig.children(); + for (int i=0; i < children.count(); i++) { + if (toSymbianConfig(privateConfiguration(children[i]))->numericId == iapId) { + return children[i]; + } + } + + // Given IAP Id was not found from the used SNAP + // => Try to search matching IAP using mappingName + // mappingName contains: + // 1. "Access point name" for "Packet data" Bearer + // 2. "WLAN network name" (= SSID) for "Wireless LAN" Bearer + // 3. "Dial-up number" for "Data call Bearer" or "High Speed (GSM)" Bearer + // <=> Note: It's possible that in this case reported IAP is + // clone of the one of the IAPs of the used SNAP + // => If mappingName matches, clone has been found + QNetworkConfiguration pt = QNetworkConfigurationManager().configurationFromIdentifier(QString::number(qHash(iapId))); + if (privateConfiguration(pt)) { + for (int i=0; i < children.count(); i++) { + if (toSymbianConfig(privateConfiguration(children[i]))->mappingName == toSymbianConfig(privateConfiguration(pt))->mappingName) { + return children[i]; + } + } + } else { + // Given IAP Id was not found from known IAPs array + return QNetworkConfiguration(); + } + + // Matching IAP was not found from used SNAP + // => IAP from another SNAP is returned + // (Note: Returned IAP matches to given IAP Id) + return pt; + } +#endif + + if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + if (engine) { + QNetworkConfiguration pt = QNetworkConfigurationManager().configurationFromIdentifier(QString::number(qHash(iapId))); + // Try to found User Selected IAP from known IAPs (accessPointConfigurations) + if (pt.isValid()) { + return pt; + } else { + // Check if new (WLAN) IAP was created in IAP/SNAP dialog + // 1. Sync internal configurations array to commsdb first + engine->updateConfigurations(); + // 2. Check if new configuration was created during connection creation + QList knownConfigs = engine->accessPointConfigurations.keys(); + if (knownConfigs.count() > iKnownConfigsBeforeConnectionStart.count()) { + // Configuration count increased => new configuration was created + // => Search new, created configuration + QString newIapId; + for (int i=0; i < iKnownConfigsBeforeConnectionStart.count(); i++) { + if (knownConfigs[i] != iKnownConfigsBeforeConnectionStart[i]) { + newIapId = knownConfigs[i]; + break; + } + } + if (newIapId.isEmpty()) { + newIapId = knownConfigs[knownConfigs.count()-1]; + } + pt = QNetworkConfigurationManager().configurationFromIdentifier(newIapId); + if (pt.isValid()) + return pt; + } + } + } + return QNetworkConfiguration(); + } + + return publicConfig; +} + +void QNetworkSessionPrivateImpl::RunL() +{ + TInt statusCode = iStatus.Int(); + + switch (statusCode) { + case KErrNone: // Connection created succesfully + { + TInt error = KErrNone; + QNetworkConfiguration newActiveConfig = activeConfiguration(); + if (!newActiveConfig.isValid()) { + error = KErrGeneral; + } else if (iDynamicSetdefaultif) { + // Use name of the IAP to set default IAP + QByteArray nameAsByteArray = newActiveConfig.name().toUtf8(); + ifreq ifr; + strcpy(ifr.ifr_name, nameAsByteArray.constData()); + + error = iDynamicSetdefaultif(&ifr); + } + + if (error != KErrNone) { + isOpen = false; + iError = QNetworkSession::UnknownSessionError; + emit QNetworkSessionPrivate::error(iError); + Cancel(); + if (ipConnectionNotifier) { + ipConnectionNotifier->StopNotifications(); + } + syncStateWithInterface(); + return; + } + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + // Activate ALR monitoring + iMobility = CActiveCommsMobilityApiExt::NewL(iConnection, *this); + } +#endif + isOpen = true; + activeConfig = newActiveConfig; + activeInterface = interface(toSymbianConfig(privateConfiguration(activeConfig))->numericId); + if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + serviceConfig = QNetworkConfigurationManager().configurationFromIdentifier(toSymbianConfig(privateConfiguration(activeConfig))->serviceNetworkPtr->id); + } + + startTime = QDateTime::currentDateTime(); + + newState(QNetworkSession::Connected); + emit quitPendingWaitsForOpened(); + } + break; + case KErrNotFound: // Connection failed + isOpen = false; + activeConfig = QNetworkConfiguration(); + serviceConfig = QNetworkConfiguration(); + iError = QNetworkSession::InvalidConfigurationError; + emit QNetworkSessionPrivate::error(iError); + Cancel(); + if (ipConnectionNotifier) { + ipConnectionNotifier->StopNotifications(); + } + syncStateWithInterface(); + break; + case KErrCancel: // Connection attempt cancelled + case KErrAlreadyExists: // Connection already exists + default: + isOpen = false; + activeConfig = QNetworkConfiguration(); + serviceConfig = QNetworkConfiguration(); + iError = QNetworkSession::UnknownSessionError; + emit QNetworkSessionPrivate::error(iError); + Cancel(); + if (ipConnectionNotifier) { + ipConnectionNotifier->StopNotifications(); + } + syncStateWithInterface(); + break; + } +} + +void QNetworkSessionPrivateImpl::DoCancel() +{ + iConnection.Close(); +} + +bool QNetworkSessionPrivateImpl::newState(QNetworkSession::State newState, TUint accessPointId) +{ + // Make sure that activeConfig is always updated when SNAP is signaled to be + // connected. + if (isOpen && publicConfig.type() == QNetworkConfiguration::ServiceNetwork && + newState == QNetworkSession::Connected) { + activeConfig = activeConfiguration(accessPointId); + activeInterface = interface(toSymbianConfig(privateConfiguration(activeConfig))->numericId); + } + + // Make sure that same state is not signaled twice in a row. + if (state == newState) { + return true; + } + + // Make sure that Connecting state does not overwrite Roaming state + if (state == QNetworkSession::Roaming && newState == QNetworkSession::Connecting) { + return false; + } + + bool emitSessionClosed = false; + if (isOpen && state == QNetworkSession::Connected && newState == QNetworkSession::Disconnected) { + // Active & Connected state should change directly to Disconnected state + // only when something forces connection to close (eg. when another + // application or session stops connection or when network drops + // unexpectedly). + isOpen = false; + activeConfig = QNetworkConfiguration(); + serviceConfig = QNetworkConfiguration(); + iError = QNetworkSession::SessionAbortedError; + emit QNetworkSessionPrivate::error(iError); + Cancel(); + if (ipConnectionNotifier) { + ipConnectionNotifier->StopNotifications(); + } + // Start monitoring changes in IAP states + TRAP_IGNORE(iConnectionMonitor.NotifyEventL(*this)); + emitSessionClosed = true; // Emit SessionClosed after state change has been reported + } + + bool retVal = false; + if (accessPointId == 0) { + state = newState; + emit stateChanged(state); + retVal = true; + } else { + if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { + if (toSymbianConfig(privateConfiguration(publicConfig))->numericId == accessPointId) { + state = newState; + emit stateChanged(state); + retVal = true; + } + } else if (publicConfig.type() == QNetworkConfiguration::UserChoice && isOpen) { + if (toSymbianConfig(privateConfiguration(activeConfig))->numericId == accessPointId) { + state = newState; + emit stateChanged(state); + retVal = true; + } + } else if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + QList subConfigurations = publicConfig.children(); + for (int i = 0; i < subConfigurations.count(); i++) { + if (toSymbianConfig(privateConfiguration(subConfigurations[i]))->numericId == accessPointId) { + if (newState == QNetworkSession::Connected) { + // Make sure that when AccessPoint is reported to be Connected + // also state of the related configuration changes to Active. + privateConfiguration(subConfigurations[i])->state = QNetworkConfiguration::Active; + + state = newState; + emit stateChanged(state); + retVal = true; + } else { + if (newState == QNetworkSession::Disconnected) { + // Make sure that when AccessPoint is reported to be disconnected + // also state of the related configuration changes from Active to Defined. + privateConfiguration(subConfigurations[i])->state = QNetworkConfiguration::Defined; + } + QNetworkConfiguration config = bestConfigFromSNAP(publicConfig); + if ((config.state() == QNetworkConfiguration::Defined) || + (config.state() == QNetworkConfiguration::Discovered)) { + state = newState; + emit stateChanged(state); + retVal = true; + } + } + } + } + } + } + + if (emitSessionClosed) { + emit closed(); + } + + return retVal; +} + +void QNetworkSessionPrivateImpl::handleSymbianConnectionStatusChange(TInt aConnectionStatus, + TInt aError, + TUint accessPointId) +{ + switch (aConnectionStatus) + { + // Connection unitialised + case KConnectionUninitialised: + break; + + // Starting connetion selection + case KStartingSelection: + break; + + // Selection finished + case KFinishedSelection: + if (aError == KErrNone) + { + // The user successfully selected an IAP to be used + break; + } + else + { + // The user pressed e.g. "Cancel" and did not select an IAP + newState(QNetworkSession::Disconnected,accessPointId); + } + break; + + // Connection failure + case KConnectionFailure: + newState(QNetworkSession::NotAvailable); + break; + + // Prepearing connection (e.g. dialing) + case KPsdStartingConfiguration: + case KPsdFinishedConfiguration: + case KCsdFinishedDialling: + case KCsdScanningScript: + case KCsdGettingLoginInfo: + case KCsdGotLoginInfo: + break; + + // Creating connection (e.g. GPRS activation) + case KCsdStartingConnect: + case KCsdFinishedConnect: + newState(QNetworkSession::Connecting,accessPointId); + break; + + // Starting log in + case KCsdStartingLogIn: + break; + + // Finished login + case KCsdFinishedLogIn: + break; + + // Connection open + case KConnectionOpen: + break; + + case KLinkLayerOpen: + newState(QNetworkSession::Connected,accessPointId); + break; + + // Connection blocked or suspended + case KDataTransferTemporarilyBlocked: + break; + + // Hangup or GRPS deactivation + case KConnectionStartingClose: + newState(QNetworkSession::Closing,accessPointId); + break; + + // Connection closed + case KConnectionClosed: + break; + + case KLinkLayerClosed: + newState(QNetworkSession::Disconnected,accessPointId); + break; + + // Unhandled state + default: + break; + } +} + +void QNetworkSessionPrivateImpl::EventL(const CConnMonEventBase& aEvent) +{ + switch (aEvent.EventType()) + { + case EConnMonConnectionStatusChange: + { + CConnMonConnectionStatusChange* realEvent; + realEvent = (CConnMonConnectionStatusChange*) &aEvent; + + TUint connectionId = realEvent->ConnectionId(); + TInt connectionStatus = realEvent->ConnectionStatus(); + + // Try to Find IAP Id using connection Id + TUint apId = 0; + if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + QList subConfigurations = publicConfig.children(); + for (int i = 0; i < subConfigurations.count(); i++ ) { + if (toSymbianConfig(privateConfiguration(subConfigurations[i]))->connectionId == connectionId) { + apId = toSymbianConfig(privateConfiguration(subConfigurations[i]))->numericId; + break; + } + } + } else if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { + if (toSymbianConfig(privateConfiguration(publicConfig))->connectionId == connectionId) { + apId = toSymbianConfig(privateConfiguration(publicConfig))->numericId; + } + } + + if (apId > 0) { + handleSymbianConnectionStatusChange(connectionStatus, KErrNone, apId); + } + } + break; + + case EConnMonCreateConnection: + { + CConnMonCreateConnection* realEvent; + realEvent = (CConnMonCreateConnection*) &aEvent; + TUint apId; + TUint connectionId = realEvent->ConnectionId(); + TRequestStatus status; + iConnectionMonitor.GetUintAttribute(connectionId, 0, KIAPId, apId, status); + User::WaitForRequest(status); + if (status.Int() == KErrNone) { + // Store connection id to related AccessPoint Configuration + if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + QList subConfigurations = publicConfig.children(); + for (int i = 0; i < subConfigurations.count(); i++ ) { + if (toSymbianConfig(privateConfiguration(subConfigurations[i]))->numericId == apId) { + toSymbianConfig(privateConfiguration(subConfigurations[i]))->connectionId = connectionId; + break; + } + } + } else if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { + if (toSymbianConfig(privateConfiguration(publicConfig))->numericId == apId) { + toSymbianConfig(privateConfiguration(publicConfig))->connectionId = connectionId; + } + } + } + } + break; + + case EConnMonDeleteConnection: + { + CConnMonDeleteConnection* realEvent; + realEvent = (CConnMonDeleteConnection*) &aEvent; + TUint connectionId = realEvent->ConnectionId(); + // Remove connection id from related AccessPoint Configuration + if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { + QList subConfigurations = publicConfig.children(); + for (int i = 0; i < subConfigurations.count(); i++ ) { + if (toSymbianConfig(privateConfiguration(subConfigurations[i]))->connectionId == connectionId) { + toSymbianConfig(privateConfiguration(subConfigurations[i]))->connectionId = 0; + break; + } + } + } else if (publicConfig.type() == QNetworkConfiguration::InternetAccessPoint) { + if (toSymbianConfig(privateConfiguration(publicConfig))->connectionId == connectionId) { + toSymbianConfig(privateConfiguration(publicConfig))->connectionId = 0; + } + } + } + break; + + default: + // For unrecognized events + break; + } +} + +ConnectionProgressNotifier::ConnectionProgressNotifier(QNetworkSessionPrivateImpl &owner, RConnection &connection) + : CActive(CActive::EPriorityStandard), iOwner(owner), iConnection(connection) +{ + CActiveScheduler::Add(this); +} + +ConnectionProgressNotifier::~ConnectionProgressNotifier() +{ + Cancel(); +} + +void ConnectionProgressNotifier::StartNotifications() +{ + if (!IsActive()) { + SetActive(); + } + iConnection.ProgressNotification(iProgress, iStatus); +} + +void ConnectionProgressNotifier::StopNotifications() +{ + Cancel(); +} + +void ConnectionProgressNotifier::DoCancel() +{ + iConnection.CancelProgressNotification(); +} + +void ConnectionProgressNotifier::RunL() +{ + if (iStatus == KErrNone) { + iOwner.handleSymbianConnectionStatusChange(iProgress().iStage, iProgress().iError); + + SetActive(); + iConnection.ProgressNotification(iProgress, iStatus); + } +} + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/symbian/qnetworksession_impl.h b/src/plugins/bearer/symbian/qnetworksession_impl.h new file mode 100644 index 0000000..2e75d96 --- /dev/null +++ b/src/plugins/bearer/symbian/qnetworksession_impl.h @@ -0,0 +1,196 @@ +/**************************************************************************** +** +** 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 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 QNETWORKSESSION_IMPL_H +#define QNETWORKSESSION_IMPL_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 + +#include + +#include +#include +#include +#include +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + #include +#endif + +typedef int(*TOpenCSetdefaultifFunction)(const struct ifreq*); + +QT_BEGIN_NAMESPACE + +class ConnectionProgressNotifier; +class SymbianEngine; + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE +class QNetworkSessionPrivateImpl : public QNetworkSessionPrivate, public CActive, public MMobilityProtocolResp, + public MConnectionMonitorObserver +#else +class QNetworkSessionPrivateImpl : public QNetworkSessionPrivate, public CActive, public MConnectionMonitorObserver +#endif +{ + Q_OBJECT +public: + QNetworkSessionPrivateImpl(SymbianEngine *engine); + ~QNetworkSessionPrivateImpl(); + + //called by QNetworkSession constructor and ensures + //that the state is immediately updated (w/o actually opening + //a session). Also this function should take care of + //notification hooks to discover future state changes. + void syncStateWithInterface(); + + QNetworkInterface currentInterface() const; + QVariant sessionProperty(const QString& key) const; + void setSessionProperty(const QString& key, const QVariant& value); + + void setALREnabled(bool enabled); + + void open(); + inline void close() { close(true); } + void close(bool allowSignals); + void stop(); + void migrate(); + void accept(); + void ignore(); + void reject(); + + QString errorString() const; //must return translated string + QNetworkSession::SessionError error() const; + + quint64 bytesWritten() const; + quint64 bytesReceived() const; + quint64 activeTime() const; + +#ifdef SNAP_FUNCTIONALITY_AVAILABLE +public: // From MMobilityProtocolResp + void PreferredCarrierAvailable(TAccessPointInfo aOldAPInfo, + TAccessPointInfo aNewAPInfo, + TBool aIsUpgrade, + TBool aIsSeamless); + + void NewCarrierActive(TAccessPointInfo aNewAPInfo, TBool aIsSeamless); + + void Error(TInt aError); +#endif + +protected: // From CActive + void RunL(); + void DoCancel(); + +private: // MConnectionMonitorObserver + void EventL(const CConnMonEventBase& aEvent); + +private: + TUint iapClientCount(TUint aIAPId) const; + quint64 transferredData(TUint dataType) const; + bool newState(QNetworkSession::State newState, TUint accessPointId = 0); + void handleSymbianConnectionStatusChange(TInt aConnectionStatus, TInt aError, TUint accessPointId = 0); + QNetworkConfiguration bestConfigFromSNAP(const QNetworkConfiguration& snapConfig) const; + QNetworkConfiguration activeConfiguration(TUint32 iapId = 0) const; + QNetworkInterface interface(TUint iapId) const; + +private: // data + SymbianEngine *engine; + + mutable QNetworkInterface activeInterface; + + QDateTime startTime; + + RLibrary iOpenCLibrary; + TOpenCSetdefaultifFunction iDynamicSetdefaultif; + + mutable RSocketServ iSocketServ; + mutable RConnection iConnection; + mutable RConnectionMonitor iConnectionMonitor; + ConnectionProgressNotifier* ipConnectionNotifier; +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + CActiveCommsMobilityApiExt* iMobility; +#endif + + QNetworkSession::SessionError iError; + TInt iALREnabled; + TBool iALRUpgradingConnection; + + QList iKnownConfigsBeforeConnectionStart; + + TUint32 iOldRoamingIap; + TUint32 iNewRoamingIap; + + friend class ConnectionProgressNotifier; +}; + +class ConnectionProgressNotifier : public CActive +{ +public: + ConnectionProgressNotifier(QNetworkSessionPrivateImpl &owner, RConnection &connection); + ~ConnectionProgressNotifier(); + + void StartNotifications(); + void StopNotifications(); + +protected: // From CActive + void RunL(); + void DoCancel(); + +private: // Data + QNetworkSessionPrivateImpl &iOwner; + RConnection& iConnection; + TNifProgressBuf iProgress; + +}; + +QT_END_NAMESPACE + +#endif //QNETWORKSESSION_IMPL_H + diff --git a/src/plugins/bearer/symbian/symbian.pro b/src/plugins/bearer/symbian/symbian.pro index d3ffb37..9fd1a74 100644 --- a/src/plugins/bearer/symbian/symbian.pro +++ b/src/plugins/bearer/symbian/symbian.pro @@ -3,8 +3,12 @@ include(../../qpluginbase.pri) QT += network -HEADERS += symbianengine.h -SOURCES += symbianengine.cpp main.cpp +HEADERS += symbianengine.h \ + qnetworksession_impl.h + +SOURCES += symbianengine.cpp \ + qnetworksession_impl.cpp \ + main.cpp exists($${EPOCROOT}epoc32/release/winscw/udeb/cmmanager.lib)| \ exists($${EPOCROOT}epoc32/release/armv5/lib/cmmanager.lib) { diff --git a/src/plugins/bearer/symbian/symbianengine.cpp b/src/plugins/bearer/symbian/symbianengine.cpp index 8c31990..f5c5007 100644 --- a/src/plugins/bearer/symbian/symbianengine.cpp +++ b/src/plugins/bearer/symbian/symbianengine.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "symbianengine.h" +#include "qnetworksession_impl.h" #include #include @@ -64,7 +65,7 @@ static const int KValueThatWillBeAddedToSNAPId = 1000; static const int KUserChoiceIAPId = 0; SymbianNetworkConfigurationPrivate::SymbianNetworkConfigurationPrivate() -: bearer(BearerUnknown), numericId(0), connectionId(0), manager(0) +: bearer(BearerUnknown), numericId(0), connectionId(0) { } @@ -72,16 +73,33 @@ SymbianNetworkConfigurationPrivate::~SymbianNetworkConfigurationPrivate() { } -inline SymbianNetworkConfigurationPrivate *toSymbianConfig(QNetworkConfigurationPrivatePointer ptr) -{ - return static_cast(ptr.data()); +QString SymbianNetworkConfigurationPrivate::bearerName() const +{ + switch (bearer) { + case BearerEthernet: + return QLatin1String("Ethernet"); + case BearerWLAN: + return QLatin1String("WLAN"); + case Bearer2G: + return QLatin1String("2G"); + case BearerCDMA2000: + return QLatin1String("CDMA2000"); + case BearerWCDMA: + return QLatin1String("WCDMA"); + case BearerHSPA: + return QLatin1String("HSPA"); + case BearerBluetooth: + return QLatin1String("Bluetooth"); + case BearerWiMAX: + return QLatin1String("WiMAX"); + default: + return QString(); + } } SymbianEngine::SymbianEngine(QObject *parent) : QNetworkSessionEngine(parent), CActive(CActive::EPriorityIdle), iInitOk(true) { - qDebug() << Q_FUNC_INFO; - CActiveScheduler::Add(this); TRAPD(error, ipCommsDB = CCommsDatabase::NewL(EDatabaseTypeIAP)); @@ -112,7 +130,6 @@ SymbianEngine::SymbianEngine(QObject *parent) cpPriv->type = QNetworkConfiguration::UserChoice; cpPriv->purpose = QNetworkConfiguration::UnknownPurpose; cpPriv->roamingSupported = false; - cpPriv->manager = this; QNetworkConfigurationPrivatePointer ptr(cpPriv); userChoiceConfigurations.insert(ptr->id, ptr); @@ -139,6 +156,34 @@ SymbianEngine::~SymbianEngine() delete ipCommsDB; } +QString SymbianEngine::getInterfaceFromId(const QString &id) +{ + qFatal("getInterfaceFromId(%s) not implemented\n", qPrintable(id)); + return QString(); +} + +bool SymbianEngine::hasIdentifier(const QString &id) +{ + return accessPointConfigurations.contains(id) || + snapConfigurations.contains(id) || + userChoiceConfigurations.contains(id); +} + +void SymbianEngine::connectToId(const QString &id) +{ + qFatal("connectToId(%s) not implemented\n", qPrintable(id)); +} + +void SymbianEngine::disconnectFromId(const QString &id) +{ + qFatal("disconnectFromId(%s) not implemented\n", qPrintable(id)); +} + +QNetworkSession::State SymbianEngine::sessionStateForId(const QString &id) +{ + qFatal("sessionStateForId(%s) not implemented\n", qPrintable(id)); + return QNetworkSession::Invalid; +} QNetworkConfigurationManager::Capabilities SymbianEngine::capabilities() const { @@ -157,6 +202,11 @@ QNetworkConfigurationManager::Capabilities SymbianEngine::capabilities() const return capFlags; } +QNetworkSessionPrivate *SymbianEngine::createSessionBackend() +{ + return new QNetworkSessionPrivateImpl(this); +} + void SymbianEngine::requestUpdate() { if (!iInitOk || iUpdateGoingOn) { @@ -239,7 +289,6 @@ void SymbianEngine::updateConfigurationsL() cpPriv->type = QNetworkConfiguration::ServiceNetwork; cpPriv->purpose = QNetworkConfiguration::UnknownPurpose; cpPriv->roamingSupported = false; - cpPriv->manager = this; QNetworkConfigurationPrivatePointer ptr(cpPriv); snapConfigurations.insert(ident, ptr); @@ -428,7 +477,6 @@ SymbianNetworkConfigurationPrivate *SymbianEngine::configFromConnectionMethodL( cpPriv->type = QNetworkConfiguration::InternetAccessPoint; cpPriv->purpose = QNetworkConfiguration::UnknownPurpose; cpPriv->roamingSupported = false; - cpPriv->manager = this; CleanupStack::Pop(cpPriv); return cpPriv; @@ -498,7 +546,6 @@ void SymbianEngine::readNetworkConfigurationValuesFromCommsDbL( apNetworkConfiguration->bearer = SymbianNetworkConfigurationPrivate::BearerUnknown; break; } - apNetworkConfiguration->manager = this; CleanupStack::PopAndDestroy(pApUtils); CleanupStack::PopAndDestroy(pAPItem); diff --git a/src/plugins/bearer/symbian/symbianengine.h b/src/plugins/bearer/symbian/symbianengine.h index 0ca30da..cd5aa43 100644 --- a/src/plugins/bearer/symbian/symbianengine.h +++ b/src/plugins/bearer/symbian/symbianengine.h @@ -80,18 +80,23 @@ public: SymbianNetworkConfigurationPrivate(); ~SymbianNetworkConfigurationPrivate(); + QString bearerName() const; + Bearer bearer; TUint32 numericId; TUint connectionId; - TAny *manager; - QNetworkConfigurationPrivatePointer serviceNetworkPtr; QString mappingName; }; +inline SymbianNetworkConfigurationPrivate *toSymbianConfig(QNetworkConfigurationPrivatePointer ptr) +{ + return static_cast(ptr.data()); +} + class SymbianEngine : public QNetworkSessionEngine, public CActive, public MConnectionMonitorObserver { @@ -101,18 +106,20 @@ public: SymbianEngine(QObject *parent = 0); virtual ~SymbianEngine(); - QString getInterfaceFromId(const QString &id) { return QString(); } - bool hasIdentifier(const QString &id) { return false; } + QString getInterfaceFromId(const QString &id); + bool hasIdentifier(const QString &id); - void connectToId(const QString &id) { } - void disconnectFromId(const QString &id) { } + void connectToId(const QString &id); + void disconnectFromId(const QString &id); void requestUpdate(); - QNetworkSession::State sessionStateForId(const QString &id) { return QNetworkSession::Invalid; } + QNetworkSession::State sessionStateForId(const QString &id); QNetworkConfigurationManager::Capabilities capabilities() const; + QNetworkSessionPrivate *createSessionBackend(); + QNetworkConfigurationPrivatePointer defaultConfiguration(); Q_SIGNALS: diff --git a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp index 061108a..d3923e9 100644 --- a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp +++ b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp @@ -82,7 +82,7 @@ private slots: private: QNetworkConfigurationManager manager; - uint inProcessSessionManagementCount; + int inProcessSessionManagementCount; #ifdef Q_WS_MAEMO_6 Maemo::IAPConf *iapconf; @@ -249,6 +249,9 @@ void tst_QNetworkSession::sessionProperties() if (!configuration.isValid()) { QVERIFY(configuration.bearerName().isEmpty()); } else { + qDebug() << "Type:" << configuration.type() + << "Bearer:" << configuration.bearerName(); + switch (configuration.type()) { case QNetworkConfiguration::ServiceNetwork: @@ -264,6 +267,8 @@ void tst_QNetworkSession::sessionProperties() // QNetworkSession::interface() should return an invalid interface unless // session is in the connected state. + qDebug() << "Session state:" << session.state(); + qDebug() << "Session iface:" << session.interface().isValid() << session.interface().name(); QCOMPARE(session.state() == QNetworkSession::Connected, session.interface().isValid()); if (!configuration.isValid()) { @@ -790,6 +795,8 @@ QDebug operator<<(QDebug debug, const QList &list) void tst_QNetworkSession::outOfProcessSession() { + qDebug() << "START"; + QNetworkConfigurationManager manager; QList before = manager.allConfigurations(QNetworkConfiguration::Active); @@ -805,13 +812,16 @@ void tst_QNetworkSession::outOfProcessSession() QLocalServer::removeServer("tst_qnetworksession"); oopServer.listen("tst_qnetworksession"); + qDebug() << "starting lackey"; QProcess lackey; lackey.start("qnetworksessionlackey"); + qDebug() << lackey.error() << lackey.errorString(); QVERIFY(lackey.waitForStarted()); + qDebug() << "waiting for connection"; QVERIFY(oopServer.waitForNewConnection(-1)); QLocalSocket *oopSocket = oopServer.nextPendingConnection(); - + qDebug() << "got connection"; do { QByteArray output; @@ -875,12 +885,12 @@ void tst_QNetworkSession::outOfProcessSession() break; case 1: QSKIP("No discovered configurations found.", SkipAll); - break; case 2: QSKIP("Lackey could not start session.", SkipAll); default: QSKIP("Lackey failed", SkipAll); } + qDebug("STOP"); } QTEST_MAIN(tst_QNetworkSession) -- cgit v0.12 From 35c7808149558d9798d158605fbd835ea167ca53 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 18 Jan 2010 15:20:33 +1000 Subject: Make compile on Unix. --- src/network/bearer/qnetworksession_p.h | 2 +- .../bearer/networkmanager/qnetworkmanagerengine.cpp | 18 ++++++++++++++++++ .../bearer/networkmanager/qnetworkmanagerengine.h | 2 ++ src/plugins/bearer/qnetworksession_impl.cpp | 2 +- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/network/bearer/qnetworksession_p.h b/src/network/bearer/qnetworksession_p.h index 6395250..a6bb7cb 100644 --- a/src/network/bearer/qnetworksession_p.h +++ b/src/network/bearer/qnetworksession_p.h @@ -90,7 +90,7 @@ public: virtual void close() = 0; virtual void stop() = 0; - virtual void setALREnabled(bool enabled) { } + virtual void setALREnabled(bool /*enabled*/) { } virtual void migrate() = 0; virtual void accept() = 0; virtual void ignore() = 0; diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp index e1fcd46..9064005 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp @@ -41,6 +41,7 @@ #include "qnetworkmanagerengine.h" #include "qnetworkmanagerservice.h" +#include "../qnetworksession_impl.h" #include @@ -238,6 +239,8 @@ void QNetworkManagerEngine::requestUpdate() void QNetworkManagerEngine::interfacePropertiesChanged(const QString &path, const QMap &properties) { + Q_UNUSED(path) + QMapIterator i(properties); while (i.hasNext()) { i.next(); @@ -302,6 +305,8 @@ void QNetworkManagerEngine::interfacePropertiesChanged(const QString &path, void QNetworkManagerEngine::activeConnectionPropertiesChanged(const QString &path, const QMap &properties) { + Q_UNUSED(properties) + QNetworkManagerConnectionActive *activeConnection = activeConnections.value(path); if (!activeConnection) @@ -396,6 +401,8 @@ void QNetworkManagerEngine::newConnection(const QDBusObjectPath &path, void QNetworkManagerEngine::removeConnection(const QString &path) { + Q_UNUSED(path) + QNetworkManagerSettingsConnection *connection = qobject_cast(sender()); if (!connection) @@ -473,6 +480,8 @@ void QNetworkManagerEngine::activationFinished(QDBusPendingCallWatcher *watcher) void QNetworkManagerEngine::newAccessPoint(const QString &path, const QDBusObjectPath &objectPath) { + Q_UNUSED(path) + QNetworkManagerInterfaceAccessPoint *accessPoint = new QNetworkManagerInterfaceAccessPoint(objectPath.path()); accessPoints.append(accessPoint); @@ -524,6 +533,8 @@ void QNetworkManagerEngine::newAccessPoint(const QString &path, const QDBusObjec void QNetworkManagerEngine::removeAccessPoint(const QString &path, const QDBusObjectPath &objectPath) { + Q_UNUSED(path) + for (int i = 0; i < accessPoints.count(); ++i) { QNetworkManagerInterfaceAccessPoint *accessPoint = accessPoints.at(i); @@ -546,6 +557,8 @@ void QNetworkManagerEngine::removeAccessPoint(const QString &path, void QNetworkManagerEngine::updateAccessPoint(const QMap &map) { + Q_UNUSED(map) + QNetworkManagerInterfaceAccessPoint *accessPoint = qobject_cast(sender()); if (!accessPoint) @@ -673,5 +686,10 @@ QNetworkConfigurationManager::Capabilities QNetworkManagerEngine::capabilities() QNetworkConfigurationManager::CanStartAndStopInterfaces; } +QNetworkSessionPrivate *QNetworkManagerEngine::createSessionBackend() +{ + return new QNetworkSessionPrivateImpl; +} + QT_END_NAMESPACE diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h index 3752dce..11255fc 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h @@ -84,6 +84,8 @@ public: QNetworkConfigurationManager::Capabilities capabilities() const; + QNetworkSessionPrivate *createSessionBackend(); + private Q_SLOTS: void interfacePropertiesChanged(const QString &path, const QMap &properties); diff --git a/src/plugins/bearer/qnetworksession_impl.cpp b/src/plugins/bearer/qnetworksession_impl.cpp index 49a2d72..a826fd6 100644 --- a/src/plugins/bearer/qnetworksession_impl.cpp +++ b/src/plugins/bearer/qnetworksession_impl.cpp @@ -79,7 +79,7 @@ Q_SIGNALS: void forcedSessionClose(const QNetworkConfiguration &config); }; -#include "qnetworksession_p.moc" +#include "qnetworksession_impl.moc" Q_GLOBAL_STATIC(QNetworkSessionManagerPrivate, sessionManager); -- cgit v0.12 From a30021ded7501bb122c8f3c37cc9ced96e00e7d2 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 18 Jan 2010 15:20:33 +1000 Subject: Make compile on Unix. --- src/network/bearer/qnetworksession_p.h | 2 +- src/plugins/bearer/networkmanager/networkmanager.pro | 6 ++++-- .../bearer/networkmanager/qnetworkmanagerengine.cpp | 18 ++++++++++++++++++ .../bearer/networkmanager/qnetworkmanagerengine.h | 2 ++ src/plugins/bearer/qnetworksession_impl.cpp | 2 +- 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/network/bearer/qnetworksession_p.h b/src/network/bearer/qnetworksession_p.h index 6395250..a6bb7cb 100644 --- a/src/network/bearer/qnetworksession_p.h +++ b/src/network/bearer/qnetworksession_p.h @@ -90,7 +90,7 @@ public: virtual void close() = 0; virtual void stop() = 0; - virtual void setALREnabled(bool enabled) { } + virtual void setALREnabled(bool /*enabled*/) { } virtual void migrate() = 0; virtual void accept() = 0; virtual void ignore() = 0; diff --git a/src/plugins/bearer/networkmanager/networkmanager.pro b/src/plugins/bearer/networkmanager/networkmanager.pro index 57f7ca7..2050125 100644 --- a/src/plugins/bearer/networkmanager/networkmanager.pro +++ b/src/plugins/bearer/networkmanager/networkmanager.pro @@ -7,12 +7,14 @@ DEFINES += BACKEND_NM HEADERS += qnmdbushelper.h \ qnetworkmanagerservice.h \ - qnetworkmanagerengine.h + qnetworkmanagerengine.h \ + ../qnetworksession_impl.h SOURCES += main.cpp \ qnmdbushelper.cpp \ qnetworkmanagerservice.cpp \ - qnetworkmanagerengine.cpp + qnetworkmanagerengine.cpp \ + ../qnetworksession_impl.cpp QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/bearer target.path += $$[QT_INSTALL_PLUGINS]/bearer diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp index e1fcd46..9064005 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp @@ -41,6 +41,7 @@ #include "qnetworkmanagerengine.h" #include "qnetworkmanagerservice.h" +#include "../qnetworksession_impl.h" #include @@ -238,6 +239,8 @@ void QNetworkManagerEngine::requestUpdate() void QNetworkManagerEngine::interfacePropertiesChanged(const QString &path, const QMap &properties) { + Q_UNUSED(path) + QMapIterator i(properties); while (i.hasNext()) { i.next(); @@ -302,6 +305,8 @@ void QNetworkManagerEngine::interfacePropertiesChanged(const QString &path, void QNetworkManagerEngine::activeConnectionPropertiesChanged(const QString &path, const QMap &properties) { + Q_UNUSED(properties) + QNetworkManagerConnectionActive *activeConnection = activeConnections.value(path); if (!activeConnection) @@ -396,6 +401,8 @@ void QNetworkManagerEngine::newConnection(const QDBusObjectPath &path, void QNetworkManagerEngine::removeConnection(const QString &path) { + Q_UNUSED(path) + QNetworkManagerSettingsConnection *connection = qobject_cast(sender()); if (!connection) @@ -473,6 +480,8 @@ void QNetworkManagerEngine::activationFinished(QDBusPendingCallWatcher *watcher) void QNetworkManagerEngine::newAccessPoint(const QString &path, const QDBusObjectPath &objectPath) { + Q_UNUSED(path) + QNetworkManagerInterfaceAccessPoint *accessPoint = new QNetworkManagerInterfaceAccessPoint(objectPath.path()); accessPoints.append(accessPoint); @@ -524,6 +533,8 @@ void QNetworkManagerEngine::newAccessPoint(const QString &path, const QDBusObjec void QNetworkManagerEngine::removeAccessPoint(const QString &path, const QDBusObjectPath &objectPath) { + Q_UNUSED(path) + for (int i = 0; i < accessPoints.count(); ++i) { QNetworkManagerInterfaceAccessPoint *accessPoint = accessPoints.at(i); @@ -546,6 +557,8 @@ void QNetworkManagerEngine::removeAccessPoint(const QString &path, void QNetworkManagerEngine::updateAccessPoint(const QMap &map) { + Q_UNUSED(map) + QNetworkManagerInterfaceAccessPoint *accessPoint = qobject_cast(sender()); if (!accessPoint) @@ -673,5 +686,10 @@ QNetworkConfigurationManager::Capabilities QNetworkManagerEngine::capabilities() QNetworkConfigurationManager::CanStartAndStopInterfaces; } +QNetworkSessionPrivate *QNetworkManagerEngine::createSessionBackend() +{ + return new QNetworkSessionPrivateImpl; +} + QT_END_NAMESPACE diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h index 3752dce..11255fc 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h @@ -84,6 +84,8 @@ public: QNetworkConfigurationManager::Capabilities capabilities() const; + QNetworkSessionPrivate *createSessionBackend(); + private Q_SLOTS: void interfacePropertiesChanged(const QString &path, const QMap &properties); diff --git a/src/plugins/bearer/qnetworksession_impl.cpp b/src/plugins/bearer/qnetworksession_impl.cpp index 49a2d72..a826fd6 100644 --- a/src/plugins/bearer/qnetworksession_impl.cpp +++ b/src/plugins/bearer/qnetworksession_impl.cpp @@ -79,7 +79,7 @@ Q_SIGNALS: void forcedSessionClose(const QNetworkConfiguration &config); }; -#include "qnetworksession_p.moc" +#include "qnetworksession_impl.moc" Q_GLOBAL_STATIC(QNetworkSessionManagerPrivate, sessionManager); -- cgit v0.12 From a82fbee158bb117e5746fe097505d0a8035bb7d1 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 18 Jan 2010 16:01:05 +1000 Subject: Make compile on Windows. --- src/plugins/bearer/nativewifi/nativewifi.pro | 8 ++++++-- src/plugins/bearer/nativewifi/qnativewifiengine.cpp | 6 ++++++ src/plugins/bearer/nativewifi/qnativewifiengine.h | 2 ++ src/plugins/bearer/nla/nla.pro | 7 +++++-- src/plugins/bearer/nla/qnlaengine.cpp | 7 +++++++ src/plugins/bearer/nla/qnlaengine.h | 2 ++ 6 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/plugins/bearer/nativewifi/nativewifi.pro b/src/plugins/bearer/nativewifi/nativewifi.pro index 583edd4..6e99c62 100644 --- a/src/plugins/bearer/nativewifi/nativewifi.pro +++ b/src/plugins/bearer/nativewifi/nativewifi.pro @@ -3,8 +3,12 @@ include(../../qpluginbase.pri) QT += network -HEADERS += qnativewifiengine.h platformdefs.h -SOURCES += qnativewifiengine.cpp main.cpp +HEADERS += qnativewifiengine.h \ + platformdefs.h \ + ../qnetworksession_impl.h +SOURCES += main.cpp \ + qnativewifiengine.cpp \ + ../qnetworksession_impl.cpp QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/bearer target.path += $$[QT_INSTALL_PLUGINS]/bearer diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp index 82ddaf9..1cd419b 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp @@ -41,6 +41,7 @@ #include "qnativewifiengine.h" #include "platformdefs.h" +#include "../qnetworksession_impl.h" #include @@ -467,4 +468,9 @@ QNetworkConfigurationManager::Capabilities QNativeWifiEngine::capabilities() con QNetworkConfigurationManager::CanStartAndStopInterfaces; } +QNetworkSessionPrivate *QNativeWifiEngine::createSessionBackend() +{ + return new QNetworkSessionPrivateImpl; +} + QT_END_NAMESPACE diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.h b/src/plugins/bearer/nativewifi/qnativewifiengine.h index 9d92562..39b6ea4 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.h +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.h @@ -84,6 +84,8 @@ public: QNetworkConfigurationManager::Capabilities capabilities() const; + QNetworkSessionPrivate *createSessionBackend(); + inline bool available() const { return handle != 0; } public Q_SLOTS: diff --git a/src/plugins/bearer/nla/nla.pro b/src/plugins/bearer/nla/nla.pro index 62a920a..9bd3526 100644 --- a/src/plugins/bearer/nla/nla.pro +++ b/src/plugins/bearer/nla/nla.pro @@ -10,8 +10,11 @@ QT += network } HEADERS += qnlaengine.h \ - ../platformdefs_win.h -SOURCES += qnlaengine.cpp main.cpp + ../platformdefs_win.h \ + ../qnetworksession_impl.h +SOURCES += main.cpp \ + qnlaengine.cpp \ + ../qnetworksession_impl.cpp QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/bearer target.path += $$[QT_INSTALL_PLUGINS]/bearer diff --git a/src/plugins/bearer/nla/qnlaengine.cpp b/src/plugins/bearer/nla/qnlaengine.cpp index d3e3fd2..6c90429 100644 --- a/src/plugins/bearer/nla/qnlaengine.cpp +++ b/src/plugins/bearer/nla/qnlaengine.cpp @@ -40,6 +40,8 @@ ****************************************************************************/ #include "qnlaengine.h" +#include "../qnetworksession_impl.h" + #include #include @@ -636,6 +638,11 @@ QNetworkConfigurationManager::Capabilities QNlaEngine::capabilities() const return QNetworkConfigurationManager::ForcedRoaming; } +QNetworkSessionPrivate *QNlaEngine::createSessionBackend() +{ + return new QNetworkSessionPrivateImpl; +} + #include "qnlaengine.moc" QT_END_NAMESPACE diff --git a/src/plugins/bearer/nla/qnlaengine.h b/src/plugins/bearer/nla/qnlaengine.h index 5e80db1..5f0c294 100644 --- a/src/plugins/bearer/nla/qnlaengine.h +++ b/src/plugins/bearer/nla/qnlaengine.h @@ -95,6 +95,8 @@ public: QNetworkConfigurationManager::Capabilities capabilities() const; + QNetworkSessionPrivate *createSessionBackend(); + private Q_SLOTS: void networksChanged(); -- cgit v0.12 From ce1f282a5b061e4800735b2a39abfad1ee441e18 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Wed, 20 Jan 2010 11:01:04 +1000 Subject: Make compile on Mac OS X. --- src/plugins/bearer/corewlan/corewlan.pro | 8 ++++++-- src/plugins/bearer/corewlan/qcorewlanengine.h | 2 ++ src/plugins/bearer/corewlan/qcorewlanengine.mm | 6 ++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/plugins/bearer/corewlan/corewlan.pro b/src/plugins/bearer/corewlan/corewlan.pro index ac04e95..1660215 100644 --- a/src/plugins/bearer/corewlan/corewlan.pro +++ b/src/plugins/bearer/corewlan/corewlan.pro @@ -11,8 +11,12 @@ contains(QT_CONFIG, corewlan) { } } -HEADERS += qcorewlanengine.h -SOURCES += qcorewlanengine.mm main.cpp +HEADERS += qcorewlanengine.h \ + ../qnetworksession_impl.h + +SOURCES += main.cpp \ + qcorewlanengine.mm \ + ../qnetworksession_impl.cpp QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/bearer target.path += $$[QT_INSTALL_PLUGINS]/bearer diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.h b/src/plugins/bearer/corewlan/qcorewlanengine.h index dd07d83..8fedf4b 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.h +++ b/src/plugins/bearer/corewlan/qcorewlanengine.h @@ -73,6 +73,8 @@ public: QNetworkConfigurationManager::Capabilities capabilities() const; + QNetworkSessionPrivate *createSessionBackend(); + static bool getAllScInterfaces(); private Q_SLOTS: diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm index 7ee0723..404edb4 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.mm +++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qcorewlanengine.h" +#include "../qnetworksession_impl.h" #include @@ -517,4 +518,9 @@ QNetworkConfigurationManager::Capabilities QCoreWlanEngine::capabilities() const return QNetworkConfigurationManager::ForcedRoaming; } +QNetworkSessionPrivate *QCoreWlanEngine::createSessionBackend() +{ + return new QNetworkSessionPrivateImpl; +} + QT_END_NAMESPACE -- cgit v0.12 From 084c9659719ac310630ac0c1a81d013176f9c350 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Fri, 22 Jan 2010 14:22:40 +1000 Subject: Connect up preferredConfigurationChanged() signal. --- src/network/bearer/qnetworksession.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp index 6b0ccaf..78e38ba 100644 --- a/src/network/bearer/qnetworksession.cpp +++ b/src/network/bearer/qnetworksession.cpp @@ -240,6 +240,8 @@ QNetworkSession::QNetworkSession(const QNetworkConfiguration& connectionConfig, connect(d, SIGNAL(stateChanged(QNetworkSession::State)), this, SIGNAL(stateChanged(QNetworkSession::State))); connect(d, SIGNAL(closed()), this, SIGNAL(closed())); + connect(d, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool)), + this, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool))); connect(d, SIGNAL(newConfigurationActivated()), this, SIGNAL(newConfigurationActivated())); break; -- cgit v0.12 From d3b580fe8b2b0c185f0eadbf794156058496eff3 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 25 Jan 2010 09:53:12 +1000 Subject: Return default configuration from engines. --- src/network/bearer/qnetworkconfigmanager_p.cpp | 34 ++++++-------------------- src/network/bearer/qnetworksessionengine_p.h | 2 ++ src/plugins/bearer/generic/qgenericengine.cpp | 5 ++++ src/plugins/bearer/generic/qgenericengine.h | 2 ++ 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index c00d6d3..bc3cfbd 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -212,42 +212,24 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() } /*! - Returns the first active configuration found, if one exists; otherwise returns the first - discovered configuration found, if one exists; otherwise returns an empty configuration. + Returns the default configuration of the first plugin, if one exists; otherwise returns an + invalid configuration. \internal */ QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration() { - QNetworkConfigurationPrivatePointer firstActive; - QNetworkConfigurationPrivatePointer firstDiscovered; - foreach (QNetworkSessionEngine *engine, sessionEngines) { - QHash::const_iterator i = - engine->accessPointConfigurations.constBegin(); - - while (i != engine->accessPointConfigurations.constEnd()) { - QNetworkConfigurationPrivatePointer priv = i.value(); - - if (!firstActive && priv->isValid && - (priv->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) - firstActive = priv; - if (!firstDiscovered && priv->isValid && - (priv->state & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) - firstDiscovered = priv; + QNetworkConfigurationPrivatePointer ptr = engine->defaultConfiguration(); - ++i; + if (ptr) { + QNetworkConfiguration config; + config.d = ptr; + return config; } } - QNetworkConfiguration item; - - if (firstActive) - item.d = firstActive; - else if (firstDiscovered) - item.d = firstDiscovered; - - return item; + return QNetworkConfiguration(); } void QNetworkConfigurationManagerPrivate::performAsyncConfigurationUpdate() diff --git a/src/network/bearer/qnetworksessionengine_p.h b/src/network/bearer/qnetworksessionengine_p.h index 02772cb..029c2c5 100644 --- a/src/network/bearer/qnetworksessionengine_p.h +++ b/src/network/bearer/qnetworksessionengine_p.h @@ -99,6 +99,8 @@ public: virtual QNetworkSessionPrivate *createSessionBackend() = 0; + virtual QNetworkConfigurationPrivatePointer defaultConfiguration() = 0; + public: //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 diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp index e9770e1..55d1ae4 100644 --- a/src/plugins/bearer/generic/qgenericengine.cpp +++ b/src/plugins/bearer/generic/qgenericengine.cpp @@ -325,5 +325,10 @@ QNetworkSessionPrivate *QGenericEngine::createSessionBackend() return new QNetworkSessionPrivateImpl; } +QNetworkConfigurationPrivatePointer QGenericEngine::defaultConfiguration() +{ + return QNetworkConfigurationPrivatePointer(); +} + QT_END_NAMESPACE diff --git a/src/plugins/bearer/generic/qgenericengine.h b/src/plugins/bearer/generic/qgenericengine.h index 04b845e..b44685b 100644 --- a/src/plugins/bearer/generic/qgenericengine.h +++ b/src/plugins/bearer/generic/qgenericengine.h @@ -76,6 +76,8 @@ public: QNetworkSessionPrivate *createSessionBackend(); + QNetworkConfigurationPrivatePointer defaultConfiguration(); + private Q_SLOTS: void doRequestUpdate(); -- cgit v0.12 From 1e06b5e995c6df715da8db53c8375d458277144d Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Fri, 29 Jan 2010 10:30:42 +1000 Subject: Bearer Management Integration 4. --- config.tests/unix/networkmanager/main.cpp | 4 +- .../unix/networkmanager/networkmanager.pro | 3 + examples/network/bearercloud/bearercloud.pro | 2 +- examples/network/bearermonitor/bearermonitor.pro | 2 +- examples/network/bearermonitor/sessionwidget.ui | 426 +++++++++++---------- src/network/bearer/bearer.pro | 9 +- src/network/bearer/qnetworkconfigmanager_maemo.cpp | 1 - src/network/bearer/qnetworkconfiguration_s60_p.cpp | 2 +- src/network/bearer/qnetworksession.cpp | 7 +- src/network/bearer/qnetworksession_maemo_p.h | 11 +- .../qnetworkconfigmanager.pro | 6 + .../qnetworkconfiguration.pro | 6 + .../tst_qnetworksession/tst_qnetworksession.pro | 6 + 13 files changed, 258 insertions(+), 227 deletions(-) diff --git a/config.tests/unix/networkmanager/main.cpp b/config.tests/unix/networkmanager/main.cpp index 6f2bae6..60c6dfc 100644 --- a/config.tests/unix/networkmanager/main.cpp +++ b/config.tests/unix/networkmanager/main.cpp @@ -38,7 +38,9 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ - +#if defined(QT_NO_DBUS) +sjkp //error is no QtDBus +#endif #include int main(int argc, char** argv) diff --git a/config.tests/unix/networkmanager/networkmanager.pro b/config.tests/unix/networkmanager/networkmanager.pro index 554f513..3af4fcb 100644 --- a/config.tests/unix/networkmanager/networkmanager.pro +++ b/config.tests/unix/networkmanager/networkmanager.pro @@ -9,3 +9,6 @@ INCLUDEPATH += . # Input SOURCES += main.cpp +!contains(QT_CONFIG,dbus): { + DEFINES += QT_NO_DBUS +} diff --git a/examples/network/bearercloud/bearercloud.pro b/examples/network/bearercloud/bearercloud.pro index 75e3049..856d3f7 100644 --- a/examples/network/bearercloud/bearercloud.pro +++ b/examples/network/bearercloud/bearercloud.pro @@ -20,4 +20,4 @@ MOBILITY = bearer CONFIG += console -symbian:TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData +symbian:TARGET.CAPABILITY = NetworkServices ReadUserData diff --git a/examples/network/bearermonitor/bearermonitor.pro b/examples/network/bearermonitor/bearermonitor.pro index acbee71..046021a 100644 --- a/examples/network/bearermonitor/bearermonitor.pro +++ b/examples/network/bearermonitor/bearermonitor.pro @@ -25,4 +25,4 @@ wince*:LIBS += -lWs2 CONFIG += console -symbian:TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData +symbian:TARGET.CAPABILITY = NetworkServices ReadUserData diff --git a/examples/network/bearermonitor/sessionwidget.ui b/examples/network/bearermonitor/sessionwidget.ui index f02f306..65ca43b 100644 --- a/examples/network/bearermonitor/sessionwidget.ui +++ b/examples/network/bearermonitor/sessionwidget.ui @@ -7,240 +7,248 @@ 0 0 340 - 220 + 286 Form - + - + - - - Session ID: - - + + + + + Session ID: + + + + + + + + 0 + 0 + + + + + + + + - - - - 0 - 0 - - - - - - - - - - - - - - - - 0 - 0 - - - - Session State: - - - - - - - - 0 - 0 - - - - Invalid - - - - - - - - - - - Configuration: - - - - - - - - 0 - 0 - - - - - - - - - - - - - - - Bearer: - - - - - - - - 0 - 0 - - - - - - - - - - - - - - - Interface Name: - - - - - - - - 0 - 0 - - - - - - - - - - - - - - - Interface GUID: - - + + + + + + 0 + 0 + + + + Session State: + + + + + + + + 0 + 0 + + + + Invalid + + + + - - - - 0 - 0 - - - - - - + + + + + Configuration: + + + + + + + + 0 + 0 + + + + + + + + - - - - - - - Last Error: - - + + + + + Bearer: + + + + + + + + 0 + 0 + + + + + + + + - - - - 0 - 0 - - - - - - + + + + + Interface Name: + + + + + + + + 0 + 0 + + + + + + + + - - - - - - - Error String - - + + + + + Interface GUID: + + + + + + + + 0 + 0 + + + + + + + + - - - - 0 - 0 - - - - - - - - - - - - - - - Open - - + + + + + Last Error: + + + + + + + + 0 + 0 + + + + + + + + - - - Blocking Open - - + + + + + Error String + + + + + + + + 0 + 0 + + + + + + + + - - - Close - - + + + + + Open + + + + + + + Blocking Open + + + + - - - Stop - - + + + + + Close + + + + + + + Stop + + + + diff --git a/src/network/bearer/bearer.pro b/src/network/bearer/bearer.pro index ce39db6..b8e4d06 100644 --- a/src/network/bearer/bearer.pro +++ b/src/network/bearer/bearer.pro @@ -50,19 +50,11 @@ symbian: { TARGET.CAPABILITY = ALL -TCB TARGET.UID3 = 0x2002AC81 - deploy.path = $${EPOCROOT} - exportheaders.sources = $$PUBLIC_HEADERS - exportheaders.path = epoc32/include - for(header, exportheaders.sources) { - BLD_INF_RULES.prj_exports += "$$header $$deploy.path$$exportheaders.path/$$basename(header)" - } - QtBearerManagement.sources = QtBearer.dll QtBearerManagement.path = /sys/bin DEPLOYMENT += QtBearerManagement } else { maemo6 { - QT += dbus CONFIG += link_pkgconfig exists(../debug) { @@ -159,4 +151,5 @@ symbian: { } } +CONFIG += middleware include(../../features/deploy.pri) diff --git a/src/network/bearer/qnetworkconfigmanager_maemo.cpp b/src/network/bearer/qnetworkconfigmanager_maemo.cpp index 795b054..1482fa7 100644 --- a/src/network/bearer/qnetworkconfigmanager_maemo.cpp +++ b/src/network/bearer/qnetworkconfigmanager_maemo.cpp @@ -44,7 +44,6 @@ #include "qnetworkconfigmanager_maemo_p.h" #include -#include #include #include diff --git a/src/network/bearer/qnetworkconfiguration_s60_p.cpp b/src/network/bearer/qnetworkconfiguration_s60_p.cpp index 02115d9..ee50bd5 100644 --- a/src/network/bearer/qnetworkconfiguration_s60_p.cpp +++ b/src/network/bearer/qnetworkconfiguration_s60_p.cpp @@ -68,7 +68,7 @@ QString QNetworkConfigurationPrivate::bearerName() const case QNetworkConfigurationPrivate::BearerHSPA: return QLatin1String("HSPA"); case QNetworkConfigurationPrivate::BearerBluetooth: return QLatin1String("Bluetooth"); case QNetworkConfigurationPrivate::BearerWiMAX: return QLatin1String("WiMAX"); - default: return QLatin1String("Unknown"); + default: return QString(); } } diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp index 6171350..28afcfe 100644 --- a/src/network/bearer/qnetworksession.cpp +++ b/src/network/bearer/qnetworksession.cpp @@ -141,7 +141,7 @@ QTM_BEGIN_NAMESPACE \value UnknownSessionError An unidentified error occurred. \value SessionAbortedError The session was aborted by the user or system. - \value RoamingError The session cannot roam to the new configuration. + \value RoamingError The session cannot roam to a new configuration. \value OperationNotSupportedError The operation is not supported for current configuration. \value InvalidConfigurationError The operation cannot currently be performed for the current configuration. @@ -328,7 +328,10 @@ void QNetworkSession::close() /*! Invalidates all open sessions against the network interface and therefore stops the underlying network interface. This function always changes the session's state() flag to - \l Disconnected. + \l Disconnected. + + On Symbian platform, a 'NetworkControl' capability is required for + full interface-level stop (without the capability, only the current session is stopped). \sa open(), close() */ diff --git a/src/network/bearer/qnetworksession_maemo_p.h b/src/network/bearer/qnetworksession_maemo_p.h index 892262d..e3b7ffb 100644 --- a/src/network/bearer/qnetworksession_maemo_p.h +++ b/src/network/bearer/qnetworksession_maemo_p.h @@ -52,7 +52,6 @@ // // We mean it. // - #include "qnetworkconfigmanager_maemo_p.h" #include "qnetworksession.h" @@ -60,7 +59,9 @@ #include #include +#ifdef Q_WS_MAEMO_6 #include +#endif QTM_BEGIN_NAMESPACE @@ -69,8 +70,12 @@ class QNetworkSessionPrivate : public QObject Q_OBJECT public: QNetworkSessionPrivate() : - tx_data(0), rx_data(0), m_activeTime(0), isOpen(false), - connectFlags(ICD_CONNECTION_FLAG_USER_EVENT) + 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 { } diff --git a/tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro b/tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro index bdd4926..4b60a55 100644 --- a/tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro +++ b/tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro @@ -14,3 +14,9 @@ MOBILITY = bearer symbian { TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData } + +maemo6 { + CONFIG += link_pkgconfig + + PKGCONFIG += conninet +} diff --git a/tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro b/tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro index c5a08b3..3cdb113 100644 --- a/tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro +++ b/tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro @@ -14,3 +14,9 @@ MOBILITY = bearer symbian { TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData } + +maemo6 { + CONFIG += link_pkgconfig + + PKGCONFIG += conninet +} diff --git a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro index ccc405e..18b5c23 100644 --- a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro +++ b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro @@ -20,3 +20,9 @@ wince* { symbian { TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData } + +maemo6 { + CONFIG += link_pkgconfig + + PKGCONFIG += conninet +} -- cgit v0.12 From 0a903bf4995ed65367eb17c024af3f16aef57510 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 1 Feb 2010 15:28:32 +1000 Subject: Add defaultConfiguration() function to all bearer management engines. --- src/plugins/bearer/corewlan/qcorewlanengine.h | 2 ++ src/plugins/bearer/corewlan/qcorewlanengine.mm | 5 +++++ src/plugins/bearer/nativewifi/qnativewifiengine.cpp | 5 +++++ src/plugins/bearer/nativewifi/qnativewifiengine.h | 2 ++ src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp | 5 +++++ src/plugins/bearer/networkmanager/qnetworkmanagerengine.h | 2 ++ src/plugins/bearer/nla/qnlaengine.cpp | 5 +++++ src/plugins/bearer/nla/qnlaengine.h | 2 ++ 8 files changed, 28 insertions(+) diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.h b/src/plugins/bearer/corewlan/qcorewlanengine.h index 8fedf4b..61d80cf 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.h +++ b/src/plugins/bearer/corewlan/qcorewlanengine.h @@ -75,6 +75,8 @@ public: QNetworkSessionPrivate *createSessionBackend(); + QNetworkConfigurationPrivatePointer defaultConfiguration(); + static bool getAllScInterfaces(); private Q_SLOTS: diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm index 404edb4..2cbccb5 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.mm +++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm @@ -523,4 +523,9 @@ QNetworkSessionPrivate *QCoreWlanEngine::createSessionBackend() return new QNetworkSessionPrivateImpl; } +QNetworkConfigurationPrivatePointer QCoreWlanEngine::defaultConfiguration() +{ + return QNetworkConfigurationPrivatePointer(); +} + QT_END_NAMESPACE diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp index 1cd419b..af538a8 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp @@ -473,4 +473,9 @@ QNetworkSessionPrivate *QNativeWifiEngine::createSessionBackend() return new QNetworkSessionPrivateImpl; } +QNetworkConfigurationPrivatePointer QNativeWifiEngine::defaultConfiguration() +{ + return QNetworkConfigurationPrivatePointer(); +} + QT_END_NAMESPACE diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.h b/src/plugins/bearer/nativewifi/qnativewifiengine.h index 39b6ea4..83d9e2c 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.h +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.h @@ -86,6 +86,8 @@ public: QNetworkSessionPrivate *createSessionBackend(); + QNetworkConfigurationPrivatePointer defaultConfiguration(); + inline bool available() const { return handle != 0; } public Q_SLOTS: diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp index 9064005..439772a 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp @@ -691,5 +691,10 @@ QNetworkSessionPrivate *QNetworkManagerEngine::createSessionBackend() return new QNetworkSessionPrivateImpl; } +QNetworkConfigurationPrivatePointer QNetworkManagerEngine::defaultConfiguration() +{ + return QNetworkConfigurationPrivatePointer(); +} + QT_END_NAMESPACE diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h index 11255fc..5f8110c 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h @@ -86,6 +86,8 @@ public: QNetworkSessionPrivate *createSessionBackend(); + QNetworkConfigurationPrivatePointer defaultConfiguration(); + private Q_SLOTS: void interfacePropertiesChanged(const QString &path, const QMap &properties); diff --git a/src/plugins/bearer/nla/qnlaengine.cpp b/src/plugins/bearer/nla/qnlaengine.cpp index 6c90429..0ed62e3 100644 --- a/src/plugins/bearer/nla/qnlaengine.cpp +++ b/src/plugins/bearer/nla/qnlaengine.cpp @@ -643,6 +643,11 @@ QNetworkSessionPrivate *QNlaEngine::createSessionBackend() return new QNetworkSessionPrivateImpl; } +QNetworkConfigurationPrivatePointer QNlaEngine::defaultConfiguration() +{ + return QNetworkConfigurationPrivatePointer(); +} + #include "qnlaengine.moc" QT_END_NAMESPACE diff --git a/src/plugins/bearer/nla/qnlaengine.h b/src/plugins/bearer/nla/qnlaengine.h index 5f0c294..515a13c 100644 --- a/src/plugins/bearer/nla/qnlaengine.h +++ b/src/plugins/bearer/nla/qnlaengine.h @@ -97,6 +97,8 @@ public: QNetworkSessionPrivate *createSessionBackend(); + QNetworkConfigurationPrivatePointer defaultConfiguration(); + private Q_SLOTS: void networksChanged(); -- cgit v0.12 From 29f24e41b91c05d551c7ac16625a2961744c8339 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Wed, 3 Feb 2010 14:52:45 +1000 Subject: Bearer Management Integration 5. --- src/network/bearer/qnetworksession.cpp | 3 ++ tests/auto/qnetworksession/lackey/lackey.pro | 5 +++ tests/auto/qnetworksession/lackey/main.cpp | 19 ++++++--- .../tst_qnetworksession/tst_qnetworksession.cpp | 46 ++++++++++++++++------ .../tst_qnetworksession/tst_qnetworksession.pro | 2 +- 5 files changed, 55 insertions(+), 20 deletions(-) diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp index 28afcfe..0ea773a 100644 --- a/src/network/bearer/qnetworksession.cpp +++ b/src/network/bearer/qnetworksession.cpp @@ -408,6 +408,9 @@ QNetworkConfiguration QNetworkSession::configuration() const This function only returns a valid QNetworkInterface when this session is \l Connected. The returned interface may change as a result of a roaming process. + + Note: this function does not work in Symbian emulator due to the way the + connectivity is emulated on Windows. \sa state() */ diff --git a/tests/auto/qnetworksession/lackey/lackey.pro b/tests/auto/qnetworksession/lackey/lackey.pro index b8a006b..96edf99f 100644 --- a/tests/auto/qnetworksession/lackey/lackey.pro +++ b/tests/auto/qnetworksession/lackey/lackey.pro @@ -9,5 +9,10 @@ CONFIG+= testcase include(../../../../common.pri) +symbian { + # Needed for interprocess communication and opening QNetworkSession + TARGET.CAPABILITY = NetworkControl NetworkServices +} + CONFIG += mobility MOBILITY = bearer diff --git a/tests/auto/qnetworksession/lackey/main.cpp b/tests/auto/qnetworksession/lackey/main.cpp index f3a7a07..cc155f2 100644 --- a/tests/auto/qnetworksession/lackey/main.cpp +++ b/tests/auto/qnetworksession/lackey/main.cpp @@ -54,16 +54,23 @@ QTM_USE_NAMESPACE #define NO_DISCOVERED_CONFIGURATIONS_ERROR 1 #define SESSION_OPEN_ERROR 2 + int main(int argc, char** argv) { QCoreApplication app(argc, argv); QNetworkConfigurationManager manager; QList discovered = +#if defined (Q_OS_SYMBIAN) + // On Symbian, on the first query (before updateConfigurations() call + // the discovered-states are not correct, so defined-state will do. + manager.allConfigurations(QNetworkConfiguration::Defined); +#else manager.allConfigurations(QNetworkConfiguration::Discovered); - - if (discovered.isEmpty()) +#endif + if (discovered.isEmpty()) { return NO_DISCOVERED_CONFIGURATIONS_ERROR; + } // Cannot read/write to processes on WinCE or Symbian. // Easiest alternative is to use sockets for IPC. @@ -85,15 +92,16 @@ int main(int argc, char** argv) qDebug() << "Discovered configurations:" << discovered.count(); if (discovered.isEmpty()) { - qDebug() << "No more configurations"; + qDebug() << "No more discovered configurations"; break; } qDebug() << "Taking first configuration"; QNetworkConfiguration config = discovered.takeFirst(); + if ((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { - qDebug() << config.name() << "is active"; + qDebug() << config.name() << " is active, therefore skipping it (looking for configs in 'discovered' state)."; continue; } @@ -104,12 +112,11 @@ int main(int argc, char** argv) QString output = QString("Starting session for %1\n").arg(config.identifier()); oopSocket.write(output.toAscii()); oopSocket.waitForBytesWritten(); - session->open(); session->waitForOpened(); } while (!(session && session->isOpen())); - qDebug() << "loop done"; + qDebug() << "lackey: loop done"; if (!session) { qDebug() << "Could not start session"; diff --git a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp index 86b3e46..adb8edd 100644 --- a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp +++ b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp @@ -66,6 +66,8 @@ public slots: void cleanupTestCase(); private slots: + + void outOfProcessSession(); void invalidSession(); void sessionProperties_data(); @@ -77,8 +79,6 @@ private slots: void sessionOpenCloseStop_data(); void sessionOpenCloseStop(); - void outOfProcessSession(); - private: QNetworkConfigurationManager manager; @@ -264,7 +264,10 @@ void tst_QNetworkSession::sessionProperties() // QNetworkSession::interface() should return an invalid interface unless // session is in the connected state. +#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__)) + // On Symbian emulator, the support for data bearers is limited QCOMPARE(session.state() == QNetworkSession::Connected, session.interface().isValid()); +#endif if (!configuration.isValid()) { QVERIFY(configuration.state() == QNetworkConfiguration::Undefined && @@ -311,13 +314,14 @@ void tst_QNetworkSession::userChoiceSession() QNetworkSession session(configuration); + // Check that configuration was really set QVERIFY(session.configuration() == configuration); QVERIFY(!session.isOpen()); + // Check that session is not active QVERIFY(session.sessionProperty("ActiveConfiguration").toString().isEmpty()); - // The remaining tests require the session to be not NotAvailable. if (session.state() == QNetworkSession::NotAvailable) QSKIP("Network is not available.", SkipSingle); @@ -367,7 +371,10 @@ void tst_QNetworkSession::userChoiceSession() QTRY_VERIFY(!stateChangedSpy.isEmpty()); QVERIFY(session.state() == QNetworkSession::Connected); +#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__)) + // On Symbian emulator, the support for data bearers is limited QVERIFY(session.interface().isValid()); +#endif const QString userChoiceIdentifier = session.sessionProperty("UserChoiceConfiguration").toString(); @@ -507,7 +514,10 @@ void tst_QNetworkSession::sessionOpenCloseStop() } QVERIFY(session.state() == QNetworkSession::Connected); +#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__)) + // On Symbian emulator, the support for data bearers is limited QVERIFY(session.interface().isValid()); +#endif } else { QFAIL("Timeout waiting for session to open."); } @@ -540,7 +550,10 @@ void tst_QNetworkSession::sessionOpenCloseStop() QVERIFY(session2.isOpen()); QVERIFY(session.state() == QNetworkSession::Connected); QVERIFY(session2.state() == QNetworkSession::Connected); +#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__)) + // On Symbian emulator, the support for data bearers is limited QVERIFY(session.interface().isValid()); +#endif QCOMPARE(session.interface().hardwareAddress(), session2.interface().hardwareAddress()); QCOMPARE(session.interface().index(), session2.interface().index()); } @@ -713,7 +726,10 @@ void tst_QNetworkSession::sessionOpenCloseStop() QVERIFY(!session2.isOpen()); QVERIFY(session.state() == QNetworkSession::Connected); QVERIFY(session2.state() == QNetworkSession::Connected); +#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__)) + // On Symbian emulator, the support for data bearers is limited QVERIFY(session.interface().isValid()); +#endif QCOMPARE(session.interface().hardwareAddress(), session2.interface().hardwareAddress()); QCOMPARE(session.interface().index(), session2.interface().index()); } @@ -786,17 +802,23 @@ QDebug operator<<(QDebug debug, const QList &list) return debug; } +// Note: outOfProcessSession requires that at least one configuration is +// at Discovered -state (Defined is ok for symbian as well, as long as it is possible to open). void tst_QNetworkSession::outOfProcessSession() { +#if defined(Q_OS_SYMBIAN) && defined(__WINS__) + QSKIP("Symbian emulator does not support two [QR]PRocesses linking a dll (QtBearer.dll) with global writeable static data.", SkipAll); +#endif QNetworkConfigurationManager manager; - + // Create a QNetworkConfigurationManager to detect configuration changes made in Lackey. This + // is actually the essence of this testcase - to check that platform mediates/reflects changes + // regardless of process boundaries. The interprocess communication is more like a way to get + // this test-case act correctly and timely. QList before = manager.allConfigurations(QNetworkConfiguration::Active); + QSignalSpy spy(&manager, SIGNAL(configurationChanged(QNetworkConfiguration))); - QSignalSpy spy(&manager, SIGNAL(configurationChanged(QNetworkConfiguration))); - // Cannot read/write to processes on WinCE or Symbian. // Easiest alternative is to use sockets for IPC. - QLocalServer oopServer; // First remove possible earlier listening address which would cause listen to fail // (e.g. previously abruptly ended unit test might cause this) @@ -813,19 +835,17 @@ void tst_QNetworkSession::outOfProcessSession() do { QByteArray output; - if(oopSocket->waitForReadyRead()) + if(oopSocket->waitForReadyRead()) { output = oopSocket->readLine().trimmed(); + } if (output.startsWith("Started session ")) { - QString identifier = QString::fromLocal8Bit(output.mid(16).constData()); - + QString identifier = QString::fromLocal8Bit(output.mid(20).constData()); QNetworkConfiguration changed; do { QTRY_VERIFY(!spy.isEmpty()); - changed = qvariant_cast(spy.takeFirst().at(0)); - } while (changed.identifier() != identifier); QVERIFY((changed.state() & QNetworkConfiguration::Active) == @@ -870,10 +890,10 @@ void tst_QNetworkSession::outOfProcessSession() switch (lackey.exitCode()) { case 0: + qDebug("Lackey returned exit success (0)"); break; case 1: QSKIP("No discovered configurations found.", SkipAll); - break; case 2: QSKIP("Lackey could not start session.", SkipAll); default: diff --git a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro index 18b5c23..f04a8fb 100644 --- a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro +++ b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro @@ -18,7 +18,7 @@ wince* { } symbian { - TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData + TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData PowerMgmt } maemo6 { -- cgit v0.12 From 28f95681f4a6fc2e95180f573b658637a82c4c12 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 18 Jan 2010 13:58:47 +1000 Subject: Start adding network session support into QNetworkAccessManager. --- src/network/access/qnetworkaccessbackend.cpp | 30 ++++++++++++++++++++++++++++ src/network/access/qnetworkaccessbackend_p.h | 4 ++++ src/network/access/qnetworkaccessmanager.cpp | 30 ++++++++++++++++++++++++++++ src/network/access/qnetworkaccessmanager.h | 4 ++++ src/network/access/qnetworkaccessmanager_p.h | 5 ++++- src/network/access/qnetworkreplyimpl.cpp | 4 +++- 6 files changed, 75 insertions(+), 2 deletions(-) diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp index 8ac64d2..54d9dbd 100644 --- a/src/network/access/qnetworkaccessbackend.cpp +++ b/src/network/access/qnetworkaccessbackend.cpp @@ -49,6 +49,8 @@ #include "qnetworkaccesscachebackend_p.h" #include "qabstractnetworkcache.h" +#include "qnetworksession.h" +#include "qhostinfo.h" #include "private/qnoncontiguousbytedevice_p.h" @@ -341,4 +343,32 @@ void QNetworkAccessBackend::sslErrors(const QList &errors) #endif } +void QNetworkAccessBackend::start() +{ + qDebug() << "Checking for localhost"; + QHostInfo hostInfo = QHostInfo::fromName(reply->url.host()); + foreach (const QHostAddress &address, hostInfo.addresses()) { + if (address == QHostAddress::LocalHost || + address == QHostAddress::LocalHostIPv6) { + // Don't need session for local host access. + qDebug() << "Access is to localhost"; + open(); + return; + } + } + + qDebug() << "Connecting session signals"; + connect(manager->session, SIGNAL(opened()), this, SLOT(sessionOpened())); + + qDebug() << "Open session if required"; + if (!manager->session->isOpen()) + manager->session->open(); +} + +void QNetworkAccessBackend::sessionOpened() +{ + qDebug() << "Session opened, calling open()"; + open(); +} + QT_END_NAMESPACE diff --git a/src/network/access/qnetworkaccessbackend_p.h b/src/network/access/qnetworkaccessbackend_p.h index 43d993c..04cc5b0 100644 --- a/src/network/access/qnetworkaccessbackend_p.h +++ b/src/network/access/qnetworkaccessbackend_p.h @@ -111,6 +111,7 @@ public: // socket). virtual void open() = 0; + virtual void start(); virtual void closeDownstreamChannel() = 0; virtual bool waitForDownstreamReadyRead(int msecs) = 0; @@ -186,6 +187,9 @@ protected slots: void sslErrors(const QList &errors); void emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal); +private slots: + void sessionOpened(); + private: friend class QNetworkAccessManager; friend class QNetworkAccessManagerPrivate; diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index e16aedc..38ab1c6 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -59,6 +59,8 @@ #include "QtCore/qvector.h" #include "QtNetwork/qauthenticator.h" #include "QtNetwork/qsslconfiguration.h" +#include "QtNetwork/qnetworkconfigmanager.h" +#include "QtNetwork/qnetworksession.h" QT_BEGIN_NAMESPACE @@ -346,6 +348,9 @@ QNetworkAccessManager::QNetworkAccessManager(QObject *parent) : QObject(*new QNetworkAccessManagerPrivate, parent) { ensureInitialized(); + + d_func()->session = + new QNetworkSession(QNetworkConfigurationManager().defaultConfiguration(), this); } /*! @@ -665,6 +670,31 @@ QNetworkReply *QNetworkAccessManager::deleteResource(const QNetworkRequest &requ } /*! + \since 4.7 + + Sets the network configuration that will be used to \a config. + + \sa configuration() +*/ +void QNetworkAccessManager::setConfiguration(const QNetworkConfiguration &config) +{ + delete d_func()->session; + d_func()->session = new QNetworkSession(config, this); +} + +/*! + \since 4.7 + + Returns the network configuration. + + \sa setConfiguration() +*/ +QNetworkConfiguration QNetworkAccessManager::configuration() const +{ + return d_func()->session->configuration(); +} + +/*! Returns a new QNetworkReply object to handle the operation \a op and request \a req. The device \a outgoingData is always 0 for Get and Head requests, but is the value passed to post() and put() in diff --git a/src/network/access/qnetworkaccessmanager.h b/src/network/access/qnetworkaccessmanager.h index d2fe527..8e1c3b6 100644 --- a/src/network/access/qnetworkaccessmanager.h +++ b/src/network/access/qnetworkaccessmanager.h @@ -62,6 +62,7 @@ class QNetworkReply; class QNetworkProxy; class QNetworkProxyFactory; class QSslError; +class QNetworkConfiguration; class QNetworkReplyImplPrivate; class QNetworkAccessManagerPrivate; @@ -103,6 +104,9 @@ public: QNetworkReply *put(const QNetworkRequest &request, const QByteArray &data); QNetworkReply *deleteResource(const QNetworkRequest &request); + void setConfiguration(const QNetworkConfiguration &config); + QNetworkConfiguration configuration() const; + Q_SIGNALS: #ifndef QT_NO_NETWORKPROXY void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator); diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h index 1749373..4eeff4b 100644 --- a/src/network/access/qnetworkaccessmanager_p.h +++ b/src/network/access/qnetworkaccessmanager_p.h @@ -65,6 +65,7 @@ class QAuthenticator; class QAbstractNetworkCache; class QNetworkAuthenticationCredential; class QNetworkCookieJar; +class QNetworkSession; class QNetworkAccessManagerPrivate: public QObjectPrivate { @@ -74,7 +75,8 @@ public: #ifndef QT_NO_NETWORKPROXY proxyFactory(0), #endif - cookieJarCreated(false) + cookieJarCreated(false), + session(0) { } ~QNetworkAccessManagerPrivate(); @@ -112,6 +114,7 @@ public: bool cookieJarCreated; + QNetworkSession *session; // this cache can be used by individual backends to cache e.g. their TCP connections to a server // and use the connections for multiple requests. diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index 59c7d76..f097a2b 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -82,7 +82,9 @@ void QNetworkReplyImplPrivate::_q_startOperation() return; } - backend->open(); + backend->start(); + + //backend->open(); if (state != Finished) { if (operation == QNetworkAccessManager::GetOperation) pendingNotifications.append(NotifyDownstreamReadyWrite); -- cgit v0.12 From 2149a313e671b22382828b58d2520807a5a061e1 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 19 Jan 2010 10:59:57 +1000 Subject: Progress. --- src/network/access/qnetworkaccessbackend.cpp | 19 +++++++++++++++++++ src/network/access/qnetworkaccessbackend_p.h | 2 ++ src/network/access/qnetworkaccessmanager.cpp | 22 +++++++++++++++++++--- src/network/access/qnetworkaccessmanager.h | 3 +++ src/network/access/qnetworkaccessmanager_p.h | 6 ++++++ 5 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp index 54d9dbd..c712fff 100644 --- a/src/network/access/qnetworkaccessbackend.cpp +++ b/src/network/access/qnetworkaccessbackend.cpp @@ -363,12 +363,31 @@ void QNetworkAccessBackend::start() qDebug() << "Open session if required"; if (!manager->session->isOpen()) manager->session->open(); + else + sessionOpened(); } void QNetworkAccessBackend::sessionOpened() { + manager->sendDebugMessage(QLatin1String("Session opened")); qDebug() << "Session opened, calling open()"; open(); } +void QNetworkAccessBackend::preferredConfigurationChanged(const QNetworkConfiguration &config, + bool isSeamless) +{ + QString message = QString::fromLatin1("preferredConfiguirationChanged %1 %2") + .arg(config.name()) .arg(isSeamless); + + manager->sendDebugMessage(message); + manager->session->ignore(); +} + +void QNetworkAccessBackend::newConfigurationActivated() +{ + manager->sendDebugMessage(QLatin1String("newConfigurationActivated")); + manager->session->reject(); +} + QT_END_NAMESPACE diff --git a/src/network/access/qnetworkaccessbackend_p.h b/src/network/access/qnetworkaccessbackend_p.h index 04cc5b0..62ac736 100644 --- a/src/network/access/qnetworkaccessbackend_p.h +++ b/src/network/access/qnetworkaccessbackend_p.h @@ -189,6 +189,8 @@ protected slots: private slots: void sessionOpened(); + void preferredConfigurationChanged(const QNetworkConfiguration &config, bool isSeamless); + void newConfigurationActivated(); private: friend class QNetworkAccessManager; diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 38ab1c6..b8edefa 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -349,8 +349,8 @@ QNetworkAccessManager::QNetworkAccessManager(QObject *parent) { ensureInitialized(); - d_func()->session = - new QNetworkSession(QNetworkConfigurationManager().defaultConfiguration(), this); + QNetworkConfigurationManager manager; + d_func()->session = new QNetworkSession(manager.defaultConfiguration(), this); } /*! @@ -672,7 +672,7 @@ QNetworkReply *QNetworkAccessManager::deleteResource(const QNetworkRequest &requ /*! \since 4.7 - Sets the network configuration that will be used to \a config. + Sets the network configuration that will be used when creating a network session to \a config. \sa configuration() */ @@ -695,6 +695,22 @@ QNetworkConfiguration QNetworkAccessManager::configuration() const } /*! + \since 4.7 + + Returns the current active network configuration. + + \sa configuration() +*/ +QNetworkConfiguration QNetworkAccessManager::activeConfiguration() const +{ + QNetworkConfigurationManager manager; + + return manager.configurationFromIdentifier( + d_func()->session->sessionProperty(QLatin1String("ActiveConfiguration")).toString()); + +} + +/*! Returns a new QNetworkReply object to handle the operation \a op and request \a req. The device \a outgoingData is always 0 for Get and Head requests, but is the value passed to post() and put() in diff --git a/src/network/access/qnetworkaccessmanager.h b/src/network/access/qnetworkaccessmanager.h index 8e1c3b6..82bbd03 100644 --- a/src/network/access/qnetworkaccessmanager.h +++ b/src/network/access/qnetworkaccessmanager.h @@ -106,6 +106,7 @@ public: void setConfiguration(const QNetworkConfiguration &config); QNetworkConfiguration configuration() const; + QNetworkConfiguration activeConfiguration() const; Q_SIGNALS: #ifndef QT_NO_NETWORKPROXY @@ -117,6 +118,8 @@ Q_SIGNALS: void sslErrors(QNetworkReply *reply, const QList &errors); #endif + void debugMessage(const QString &message); + protected: virtual QNetworkReply *createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData = 0); diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h index 4eeff4b..b6a266c 100644 --- a/src/network/access/qnetworkaccessmanager_p.h +++ b/src/network/access/qnetworkaccessmanager_p.h @@ -101,6 +101,12 @@ public: QNetworkAccessBackend *findBackend(QNetworkAccessManager::Operation op, const QNetworkRequest &request); + void sendDebugMessage(const QString &message) + { + Q_Q(QNetworkAccessManager); + emit q->debugMessage(message); + } + // this is the cache for storing downloaded files QAbstractNetworkCache *networkCache; -- cgit v0.12 From df551752b7f430ab44bb1dd2ad0aa8c2a5187ef8 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 28 Jan 2010 11:27:49 +1000 Subject: Bearer Management Integration. Perform application level roaming when all pending QNetworkReplys have completed. Emit temporary network failure error when connection to network is lost but is possibly recovering due to roaming. Don't save downloads in cache if they are not complete. --- src/network/access/qnetworkaccessbackend.cpp | 24 ++------- src/network/access/qnetworkaccessbackend_p.h | 4 +- src/network/access/qnetworkaccessmanager.cpp | 79 ++++++++++++++++++++++++++++ src/network/access/qnetworkaccessmanager.h | 6 +++ src/network/access/qnetworkaccessmanager_p.h | 11 +++- src/network/access/qnetworkreply.cpp | 4 ++ src/network/access/qnetworkreply.h | 1 + src/network/access/qnetworkreplyimpl.cpp | 29 +++++++++- 8 files changed, 134 insertions(+), 24 deletions(-) diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp index c712fff..22df248 100644 --- a/src/network/access/qnetworkaccessbackend.cpp +++ b/src/network/access/qnetworkaccessbackend.cpp @@ -49,7 +49,6 @@ #include "qnetworkaccesscachebackend_p.h" #include "qabstractnetworkcache.h" -#include "qnetworksession.h" #include "qhostinfo.h" #include "private/qnoncontiguousbytedevice_p.h" @@ -345,22 +344,20 @@ void QNetworkAccessBackend::sslErrors(const QList &errors) void QNetworkAccessBackend::start() { - qDebug() << "Checking for localhost"; QHostInfo hostInfo = QHostInfo::fromName(reply->url.host()); foreach (const QHostAddress &address, hostInfo.addresses()) { if (address == QHostAddress::LocalHost || address == QHostAddress::LocalHostIPv6) { // Don't need session for local host access. - qDebug() << "Access is to localhost"; open(); return; } } - qDebug() << "Connecting session signals"; connect(manager->session, SIGNAL(opened()), this, SLOT(sessionOpened())); + connect(manager->session, SIGNAL(error(QNetworkSession::SessionError)), + this, SLOT(sessionError(QNetworkSession::SessionError))); - qDebug() << "Open session if required"; if (!manager->session->isOpen()) manager->session->open(); else @@ -369,25 +366,12 @@ void QNetworkAccessBackend::start() void QNetworkAccessBackend::sessionOpened() { - manager->sendDebugMessage(QLatin1String("Session opened")); - qDebug() << "Session opened, calling open()"; open(); } -void QNetworkAccessBackend::preferredConfigurationChanged(const QNetworkConfiguration &config, - bool isSeamless) +void QNetworkAccessBackend::sessionError(QNetworkSession::SessionError error) { - QString message = QString::fromLatin1("preferredConfiguirationChanged %1 %2") - .arg(config.name()) .arg(isSeamless); - - manager->sendDebugMessage(message); - manager->session->ignore(); -} - -void QNetworkAccessBackend::newConfigurationActivated() -{ - manager->sendDebugMessage(QLatin1String("newConfigurationActivated")); - manager->session->reject(); + manager->sendDebugMessage(QString::fromLatin1("Session error %1").arg(error)); } QT_END_NAMESPACE diff --git a/src/network/access/qnetworkaccessbackend_p.h b/src/network/access/qnetworkaccessbackend_p.h index 62ac736..08a8a2a 100644 --- a/src/network/access/qnetworkaccessbackend_p.h +++ b/src/network/access/qnetworkaccessbackend_p.h @@ -54,6 +54,7 @@ // #include "qnetworkreplyimpl_p.h" +#include "QtNetwork/qnetworksession.h" #include "QtCore/qobject.h" QT_BEGIN_NAMESPACE @@ -189,8 +190,7 @@ protected slots: private slots: void sessionOpened(); - void preferredConfigurationChanged(const QNetworkConfiguration &config, bool isSeamless); - void newConfigurationActivated(); + void sessionError(QNetworkSession::SessionError error); private: friend class QNetworkAccessManager; diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index b8edefa..3f8ef01 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -351,6 +351,17 @@ QNetworkAccessManager::QNetworkAccessManager(QObject *parent) QNetworkConfigurationManager manager; d_func()->session = new QNetworkSession(manager.defaultConfiguration(), this); + + connect(d_func()->session, SIGNAL(opened()), this, SLOT(_q_sessionOpened())); + connect(d_func()->session, SIGNAL(closed()), this, SLOT(_q_sessionClosed())); + connect(d_func()->session, SIGNAL(stateChanged(QNetworkSession::State)), + this, SLOT(_q_sessionStateChanged(QNetworkSession::State))); + connect(d_func()->session, SIGNAL(error(QNetworkSession::SessionError)), + this, SLOT(_q_sessionError(QNetworkSession::SessionError))); + connect(d_func()->session, SIGNAL(newConfigurationActivated()), + this, SLOT(_q_sessionNewConfigurationActivated())); + connect(d_func()->session, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool)), + this, SLOT(_q_sessionPreferredConfigurationChanged(QNetworkConfiguration,bool))); } /*! @@ -792,6 +803,20 @@ void QNetworkAccessManagerPrivate::_q_replyFinished() QNetworkReply *reply = qobject_cast(q->sender()); if (reply) emit q->finished(reply); + + if (deferredMigration) { + bool repliesPending = false; + foreach (QObject *child, q->children()) { + if (child != reply && child->inherits("QNetworkReply")) { + repliesPending = true; + break; + } + } + if (!repliesPending) { + emit q->debugMessage(QLatin1String("Migrating as there are no pending replies.")); + session->migrate(); + } + } } void QNetworkAccessManagerPrivate::_q_replySslErrors(const QList &errors) @@ -1044,6 +1069,60 @@ QNetworkAccessManagerPrivate::~QNetworkAccessManagerPrivate() { } +void QNetworkAccessManagerPrivate::_q_sessionOpened() +{ + Q_Q(QNetworkAccessManager); +} + +void QNetworkAccessManagerPrivate::_q_sessionClosed() +{ + Q_Q(QNetworkAccessManager); + + emit q->debugMessage(QLatin1String("Session Closed")); +} + +void QNetworkAccessManagerPrivate::_q_sessionError(QNetworkSession::SessionError error) +{ + Q_Q(QNetworkAccessManager); + + emit q->debugMessage(QString::fromLatin1("Session error %1").arg(error)); +} + +void QNetworkAccessManagerPrivate::_q_sessionStateChanged(QNetworkSession::State state) +{ + Q_Q(QNetworkAccessManager); +} + +void QNetworkAccessManagerPrivate::_q_sessionNewConfigurationActivated() +{ + Q_Q(QNetworkAccessManager); + + foreach (QObject *child, q->children()) { + QNetworkReply *reply = qobject_cast(child); + if (reply) { + emit q->debugMessage(QString::fromLatin1("Unexpected reply for %1").arg(reply->url().toString())); + } + } + + session->accept(); +} + +void QNetworkAccessManagerPrivate::_q_sessionPreferredConfigurationChanged(const QNetworkConfiguration &config, bool isSeamless) +{ + Q_Q(QNetworkAccessManager); + + deferredMigration = false; + foreach (QObject *child, q->children()) { + if (child->inherits("QNetworkReply")) { + deferredMigration = true; + break; + } + } + + if (!deferredMigration) + session->migrate(); +} + QT_END_NAMESPACE #include "moc_qnetworkaccessmanager.cpp" diff --git a/src/network/access/qnetworkaccessmanager.h b/src/network/access/qnetworkaccessmanager.h index 82bbd03..14aaf78 100644 --- a/src/network/access/qnetworkaccessmanager.h +++ b/src/network/access/qnetworkaccessmanager.h @@ -129,6 +129,12 @@ private: Q_DECLARE_PRIVATE(QNetworkAccessManager) Q_PRIVATE_SLOT(d_func(), void _q_replyFinished()) Q_PRIVATE_SLOT(d_func(), void _q_replySslErrors(QList)) + Q_PRIVATE_SLOT(d_func(), void _q_sessionOpened()) + Q_PRIVATE_SLOT(d_func(), void _q_sessionClosed()) + Q_PRIVATE_SLOT(d_func(), void _q_sessionError(QNetworkSession::SessionError)) + Q_PRIVATE_SLOT(d_func(), void _q_sessionStateChanged(QNetworkSession::State)) + Q_PRIVATE_SLOT(d_func(), void _q_sessionNewConfigurationActivated()) + Q_PRIVATE_SLOT(d_func(), void _q_sessionPreferredConfigurationChanged(QNetworkConfiguration,bool)) }; QT_END_NAMESPACE diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h index b6a266c..b9e3964 100644 --- a/src/network/access/qnetworkaccessmanager_p.h +++ b/src/network/access/qnetworkaccessmanager_p.h @@ -76,7 +76,8 @@ public: proxyFactory(0), #endif cookieJarCreated(false), - session(0) + session(0), + deferredMigration(false) { } ~QNetworkAccessManagerPrivate(); @@ -107,6 +108,13 @@ public: emit q->debugMessage(message); } + void _q_sessionOpened(); + void _q_sessionClosed(); + void _q_sessionError(QNetworkSession::SessionError error); + void _q_sessionStateChanged(QNetworkSession::State state); + void _q_sessionNewConfigurationActivated(); + void _q_sessionPreferredConfigurationChanged(const QNetworkConfiguration &config, bool isSeamless); + // this is the cache for storing downloaded files QAbstractNetworkCache *networkCache; @@ -121,6 +129,7 @@ public: bool cookieJarCreated; QNetworkSession *session; + bool deferredMigration; // this cache can be used by individual backends to cache e.g. their TCP connections to a server // and use the connections for multiple requests. diff --git a/src/network/access/qnetworkreply.cpp b/src/network/access/qnetworkreply.cpp index 0a8ea5d..e299b5b 100644 --- a/src/network/access/qnetworkreply.cpp +++ b/src/network/access/qnetworkreply.cpp @@ -125,6 +125,10 @@ QNetworkReplyPrivate::QNetworkReplyPrivate() encrypted channel could not be established. The sslErrors() signal should have been emitted. + \value TemporaryNetworkFailureError the connection was broken due + to disconnection from the network, however the system has initiated + roaming to another access point. The request should be resubmitted. + \value ProxyConnectionRefusedError the connection to the proxy server was refused (the proxy server is not accepting requests) diff --git a/src/network/access/qnetworkreply.h b/src/network/access/qnetworkreply.h index 5be4cce..b39557a 100644 --- a/src/network/access/qnetworkreply.h +++ b/src/network/access/qnetworkreply.h @@ -77,6 +77,7 @@ public: TimeoutError, OperationCanceledError, SslHandshakeFailedError, + TemporaryNetworkFailureError, UnknownNetworkError = 99, // proxy errors (101-199): diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index f097a2b..7eca323 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -47,6 +47,7 @@ #include "QtCore/qdatetime.h" #include "QtNetwork/qsslconfiguration.h" #include "qnetworkaccesshttpbackend_p.h" +#include "qnetworkaccessmanager_p.h" #include @@ -516,7 +517,33 @@ void QNetworkReplyImplPrivate::finished() emit q->uploadProgress(0, 0); resumeNotificationHandling(); - completeCacheSave(); + if (manager->d_func()->session->state() == QNetworkSession::Roaming) { + // only content with a known size will fail with a temporary network failure error + if (!totalSize.isNull()) { + qDebug() << "Connection broke during download."; + qDebug() << "Don't worry, we've already started roaming :)"; + + if (bytesDownloaded == totalSize) { + qDebug() << "Luckily download has already finished."; + } else { + qDebug() << "Download hasn't finished"; + + if (q->bytesAvailable() == bytesDownloaded) { + qDebug() << "User hasn't read data from reply, we could continue after reconnect."; + error(QNetworkReply::TemporaryNetworkFailureError, q->tr("Temporary network failure.")); + } else if (q->bytesAvailable() < bytesDownloaded) { + qDebug() << "User has already read data from reply."; + error(QNetworkReply::TemporaryNetworkFailureError, q->tr("Temporary network failure.")); + } + } + } + } + + // if we don't know the total size of or we received everything save the cache + if (totalSize.isNull() || totalSize == -1 || bytesDownloaded == totalSize) + completeCacheSave(); + else + qDebug() << "Not saving cache."; // note: might not be a good idea, since users could decide to delete us // which would delete the backend too... -- cgit v0.12 From 75a0b3e5526b0a6cf01deb60f0dc37b61928206a Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 28 Jan 2010 13:15:50 +1000 Subject: Wait until session is in the connected state before starting transfer. --- src/network/access/qnetworkaccessbackend.cpp | 19 +++++++++++++------ src/network/access/qnetworkaccessbackend_p.h | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp index 22df248..d9bce9d 100644 --- a/src/network/access/qnetworkaccessbackend.cpp +++ b/src/network/access/qnetworkaccessbackend.cpp @@ -354,19 +354,26 @@ void QNetworkAccessBackend::start() } } - connect(manager->session, SIGNAL(opened()), this, SLOT(sessionOpened())); + connect(manager->session, SIGNAL(stateChanged(QNetworkSession::State)), + this, SLOT(sessionStateChanged(QNetworkSession::State))); connect(manager->session, SIGNAL(error(QNetworkSession::SessionError)), this, SLOT(sessionError(QNetworkSession::SessionError))); - if (!manager->session->isOpen()) + switch (manager->session->state()) { + case QNetworkSession::Roaming: + break; + case QNetworkSession::Connected: + open(); + break; + default: manager->session->open(); - else - sessionOpened(); + } } -void QNetworkAccessBackend::sessionOpened() +void QNetworkAccessBackend::sessionStateChanged(QNetworkSession::State state) { - open(); + if (state == QNetworkSession::Connected) + open(); } void QNetworkAccessBackend::sessionError(QNetworkSession::SessionError error) diff --git a/src/network/access/qnetworkaccessbackend_p.h b/src/network/access/qnetworkaccessbackend_p.h index 08a8a2a..7b7821e 100644 --- a/src/network/access/qnetworkaccessbackend_p.h +++ b/src/network/access/qnetworkaccessbackend_p.h @@ -189,7 +189,7 @@ protected slots: void emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal); private slots: - void sessionOpened(); + void sessionStateChanged(QNetworkSession::State state); void sessionError(QNetworkSession::SessionError error); private: -- cgit v0.12 From 72f9a360c5f378092884654257266b4569932336 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 1 Feb 2010 13:25:03 +1000 Subject: Progress. --- src/network/access/qnetworkaccessbackend.cpp | 43 +++++++---------- src/network/access/qnetworkaccessbackend_p.h | 6 +-- src/network/access/qnetworkaccessmanager.cpp | 71 ++++++++++++++++++++++++---- src/network/access/qnetworkreplyimpl.cpp | 40 +++++++++++----- src/network/access/qnetworkreplyimpl_p.h | 3 +- 5 files changed, 109 insertions(+), 54 deletions(-) diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp index d9bce9d..f35cb59 100644 --- a/src/network/access/qnetworkaccessbackend.cpp +++ b/src/network/access/qnetworkaccessbackend.cpp @@ -342,7 +342,12 @@ void QNetworkAccessBackend::sslErrors(const QList &errors) #endif } -void QNetworkAccessBackend::start() +/*! + Starts the backend. Returns true if the backend is started. Returns false if the backend + could not be started due to an unopened or roaming session. The caller should recall this + function once the session has been opened or the roaming process has finished. +*/ +bool QNetworkAccessBackend::start() { QHostInfo hostInfo = QHostInfo::fromName(reply->url.host()); foreach (const QHostAddress &address, hostInfo.addresses()) { @@ -350,35 +355,23 @@ void QNetworkAccessBackend::start() address == QHostAddress::LocalHostIPv6) { // Don't need session for local host access. open(); - return; + return true; } } - connect(manager->session, SIGNAL(stateChanged(QNetworkSession::State)), - this, SLOT(sessionStateChanged(QNetworkSession::State))); - connect(manager->session, SIGNAL(error(QNetworkSession::SessionError)), - this, SLOT(sessionError(QNetworkSession::SessionError))); - - switch (manager->session->state()) { - case QNetworkSession::Roaming: - break; - case QNetworkSession::Connected: - open(); - break; - default: - manager->session->open(); + if (manager->session->isOpen()) { + if (manager->session->state() == QNetworkSession::Connected) { + qDebug() << "Session is open and state is connected"; + open(); + return true; + } else { + qDebug() << "we are roaming, connecting, etc. delay until roaming completes"; + } + } else { + qDebug() << "session not open"; } -} -void QNetworkAccessBackend::sessionStateChanged(QNetworkSession::State state) -{ - if (state == QNetworkSession::Connected) - open(); -} - -void QNetworkAccessBackend::sessionError(QNetworkSession::SessionError error) -{ - manager->sendDebugMessage(QString::fromLatin1("Session error %1").arg(error)); + return false; } QT_END_NAMESPACE diff --git a/src/network/access/qnetworkaccessbackend_p.h b/src/network/access/qnetworkaccessbackend_p.h index 7b7821e..b8b369f 100644 --- a/src/network/access/qnetworkaccessbackend_p.h +++ b/src/network/access/qnetworkaccessbackend_p.h @@ -112,7 +112,7 @@ public: // socket). virtual void open() = 0; - virtual void start(); + virtual bool start(); virtual void closeDownstreamChannel() = 0; virtual bool waitForDownstreamReadyRead(int msecs) = 0; @@ -188,10 +188,6 @@ protected slots: void sslErrors(const QList &errors); void emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal); -private slots: - void sessionStateChanged(QNetworkSession::State state); - void sessionError(QNetworkSession::SessionError error); - private: friend class QNetworkAccessManager; friend class QNetworkAccessManagerPrivate; diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 3f8ef01..a7a81f8 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -807,13 +807,24 @@ void QNetworkAccessManagerPrivate::_q_replyFinished() if (deferredMigration) { bool repliesPending = false; foreach (QObject *child, q->children()) { - if (child != reply && child->inherits("QNetworkReply")) { - repliesPending = true; - break; + if (child != reply && child->inherits("QNetworkReplyImpl")) { + QNetworkReplyImpl *replyImpl = qobject_cast(child); + qDebug() << "reply state is" << replyImpl->d_func()->state; + switch (replyImpl->d_func()->state) { + case QNetworkReplyImplPrivate::Idle: + case QNetworkReplyImplPrivate::Finished: + case QNetworkReplyImplPrivate::Aborted: + break; + case QNetworkReplyImplPrivate::Buffering: + case QNetworkReplyImplPrivate::Working: + repliesPending = true; + break; + } } } if (!repliesPending) { - emit q->debugMessage(QLatin1String("Migrating as there are no pending replies.")); + deferredMigration = false; + qDebug() << "Migrating as there are no pending replies."; session->migrate(); } } @@ -1072,6 +1083,15 @@ QNetworkAccessManagerPrivate::~QNetworkAccessManagerPrivate() void QNetworkAccessManagerPrivate::_q_sessionOpened() { Q_Q(QNetworkAccessManager); + + qDebug() << "Session Opened"; + + // start waiting children + foreach (QObject *child, q->children()) { + QNetworkReplyImpl *reply = qobject_cast(child); + if (reply && reply->d_func()->state == QNetworkReplyImplPrivate::WaitingForSession) + QMetaObject::invokeMethod(reply, "_q_startOperation", Qt::QueuedConnection); + } } void QNetworkAccessManagerPrivate::_q_sessionClosed() @@ -1091,6 +1111,8 @@ void QNetworkAccessManagerPrivate::_q_sessionError(QNetworkSession::SessionError void QNetworkAccessManagerPrivate::_q_sessionStateChanged(QNetworkSession::State state) { Q_Q(QNetworkAccessManager); + + qDebug() << "session state changed to" << state; } void QNetworkAccessManagerPrivate::_q_sessionNewConfigurationActivated() @@ -1098,13 +1120,30 @@ void QNetworkAccessManagerPrivate::_q_sessionNewConfigurationActivated() Q_Q(QNetworkAccessManager); foreach (QObject *child, q->children()) { - QNetworkReply *reply = qobject_cast(child); + QNetworkReplyImpl *reply = qobject_cast(child); if (reply) { - emit q->debugMessage(QString::fromLatin1("Unexpected reply for %1").arg(reply->url().toString())); + switch (reply->d_func()->state) { + case QNetworkReplyImplPrivate::Buffering: + case QNetworkReplyImplPrivate::Working: + emit q->debugMessage(QString::fromLatin1("Unexpected reply for %1") + .arg(reply->url().toString())); + break; + default: + qDebug() << "Testing new interface for" << reply->url(); + ; + } } } + qDebug() << "Accepting new configuration."; session->accept(); + + // start waiting children + foreach (QObject *child, q->children()) { + QNetworkReplyImpl *reply = qobject_cast(child); + if (reply && reply->d_func()->state == QNetworkReplyImplPrivate::WaitingForSession) + QMetaObject::invokeMethod(reply, "_q_startOperation", Qt::QueuedConnection); + } } void QNetworkAccessManagerPrivate::_q_sessionPreferredConfigurationChanged(const QNetworkConfiguration &config, bool isSeamless) @@ -1113,14 +1152,26 @@ void QNetworkAccessManagerPrivate::_q_sessionPreferredConfigurationChanged(const deferredMigration = false; foreach (QObject *child, q->children()) { - if (child->inherits("QNetworkReply")) { - deferredMigration = true; - break; + if (child->inherits("QNetworkReplyImpl")) { + QNetworkReplyImpl *replyImpl = qobject_cast(child); + qDebug() << "reply state is" << replyImpl->d_func()->state; + switch (replyImpl->d_func()->state) { + case QNetworkReplyImplPrivate::Idle: + case QNetworkReplyImplPrivate::Finished: + case QNetworkReplyImplPrivate::Aborted: + break; + case QNetworkReplyImplPrivate::Buffering: + case QNetworkReplyImplPrivate::Working: + deferredMigration = true; + break; + } } } - if (!deferredMigration) + if (!deferredMigration) { + qDebug() << "Migrating as there are no pending replies."; session->migrate(); + } } QT_END_NAMESPACE diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index 7eca323..5d52913 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -83,7 +83,18 @@ void QNetworkReplyImplPrivate::_q_startOperation() return; } - backend->start(); + if (!backend->start()) { + // backend failed to start because the session state is not Connected. + // QNetworkAccessManager will call reply->backend->start() again for us when the session + // state changes. + qDebug() << "Waiting for session for" << url; + state = WaitingForSession; + + if (!manager->d_func()->session->isOpen()) + manager->d_func()->session->open(); + + return; + } //backend->open(); if (state != Finished) { @@ -504,20 +515,10 @@ void QNetworkReplyImplPrivate::finished() if (state == Finished || state == Aborted) return; - state = Finished; - pendingNotifications.clear(); - pauseNotificationHandling(); QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); - if (totalSize.isNull() || totalSize == -1) { - emit q->downloadProgress(bytesDownloaded, bytesDownloaded); - } - - if (bytesUploaded == -1 && (outgoingData || outgoingDataBuffer)) - emit q->uploadProgress(0, 0); - resumeNotificationHandling(); - - if (manager->d_func()->session->state() == QNetworkSession::Roaming) { + if (state == Working && errorCode != QNetworkReply::OperationCanceledError && + manager->d_func()->session->state() == QNetworkSession::Roaming) { // only content with a known size will fail with a temporary network failure error if (!totalSize.isNull()) { qDebug() << "Connection broke during download."; @@ -538,6 +539,19 @@ void QNetworkReplyImplPrivate::finished() } } } + resumeNotificationHandling(); + + state = Finished; + pendingNotifications.clear(); + + pauseNotificationHandling(); + if (totalSize.isNull() || totalSize == -1) { + emit q->downloadProgress(bytesDownloaded, bytesDownloaded); + } + + if (bytesUploaded == -1 && (outgoingData || outgoingDataBuffer)) + emit q->uploadProgress(0, 0); + resumeNotificationHandling(); // if we don't know the total size of or we received everything save the cache if (totalSize.isNull() || totalSize == -1 || bytesDownloaded == totalSize) diff --git a/src/network/access/qnetworkreplyimpl_p.h b/src/network/access/qnetworkreplyimpl_p.h index 168e5cf..861b2b2 100644 --- a/src/network/access/qnetworkreplyimpl_p.h +++ b/src/network/access/qnetworkreplyimpl_p.h @@ -114,7 +114,8 @@ public: Buffering, Working, Finished, - Aborted + Aborted, + WaitingForSession }; typedef QQueue NotificationQueue; -- cgit v0.12 From 280a68446c1f96ae9d19134e4201bc78ee0b072a Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 2 Feb 2010 14:04:15 +1000 Subject: Ensure that default network interface is set appropriately. Default network interface was not always being set when the active network configuration changed. --- src/plugins/bearer/symbian/qnetworksession_impl.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/plugins/bearer/symbian/qnetworksession_impl.cpp b/src/plugins/bearer/symbian/qnetworksession_impl.cpp index 24948cf..619fd9f 100644 --- a/src/plugins/bearer/symbian/qnetworksession_impl.cpp +++ b/src/plugins/bearer/symbian/qnetworksession_impl.cpp @@ -818,6 +818,16 @@ bool QNetworkSessionPrivateImpl::newState(QNetworkSession::State newState, TUint newState == QNetworkSession::Connected) { activeConfig = activeConfiguration(accessPointId); activeInterface = interface(toSymbianConfig(privateConfiguration(activeConfig))->numericId); +#ifdef SNAP_FUNCTIONALITY_AVAILABLE + if (iDynamicSetdefaultif) { + // Use name of the IAP to set default IAP + QByteArray nameAsByteArray = activeConfig.name().toUtf8(); + ifreq ifr; + strcpy(ifr.ifr_name, nameAsByteArray.constData()); + + iDynamicSetdefaultif(&ifr); + } +#endif } // Make sure that same state is not signaled twice in a row. -- cgit v0.12 From 130a461c07ed35d1aeb27c8110efca773773c614 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Wed, 3 Feb 2010 10:59:12 +1000 Subject: Don't try to resolve names to determine if dest is localhost. --- src/network/access/qnetworkaccessbackend.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp index f35cb59..2eebcf9 100644 --- a/src/network/access/qnetworkaccessbackend.cpp +++ b/src/network/access/qnetworkaccessbackend.cpp @@ -349,14 +349,14 @@ void QNetworkAccessBackend::sslErrors(const QList &errors) */ bool QNetworkAccessBackend::start() { - QHostInfo hostInfo = QHostInfo::fromName(reply->url.host()); - foreach (const QHostAddress &address, hostInfo.addresses()) { - if (address == QHostAddress::LocalHost || - address == QHostAddress::LocalHostIPv6) { - // Don't need session for local host access. - open(); - return true; - } + // This is not ideal. + const QString host = reply->url.host(); + if (host == QLatin1String("localhost") || + QHostAddress(host) == QHostAddress::LocalHost || + QHostAddress(host) == QHostAddress::LocalHostIPv6) { + // Don't need an open session for localhost access. + open(); + return true; } if (manager->session->isOpen()) { -- cgit v0.12 From 8f5c1dd293b046e7f51d12b767464345c253943f Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Wed, 3 Feb 2010 11:02:23 +1000 Subject: Don't build generic bearer engine on Symbian. --- src/plugins/bearer/bearer.pro | 7 +++---- src/s60installs/s60installs.pro | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/plugins/bearer/bearer.pro b/src/plugins/bearer/bearer.pro index ab0a816..7347735 100644 --- a/src/plugins/bearer/bearer.pro +++ b/src/plugins/bearer/bearer.pro @@ -1,10 +1,9 @@ TEMPLATE = subdirs -!maemo { -SUBDIRS += generic -contains(QT_CONFIG, dbus):contains(QT_CONFIG, networkmanager):SUBDIRS += networkmanager +!maemo:contains(QT_CONFIG, dbus):contains(QT_CONFIG, networkmanager):SUBDIRS += networkmanager win32:SUBDIRS += nla win32:!wince*:SUBDIRS += nativewifi macx:SUBDIRS += corewlan symbian:SUBDIRS += symbian -} + +isEmpty(SUBDIRS):SUBDIRS += generic diff --git a/src/s60installs/s60installs.pro b/src/s60installs/s60installs.pro index b763786..d0bd59e 100644 --- a/src/s60installs/s60installs.pro +++ b/src/s60installs/s60installs.pro @@ -121,7 +121,7 @@ symbian: { } bearer_plugins.path = c:$$QT_PLUGINS_BASE_DIR/bearer - bearer_plugins.sources += qgenericbearer.dll qsymbianbearer.dll + bearer_plugins.sources += qsymbianbearer.dll BLD_INF_RULES.prj_exports += "qt.iby $$CORE_MW_LAYER_IBY_EXPORT_PATH(qt.iby)" BLD_INF_RULES.prj_exports += "qtdemoapps.iby $$CORE_APP_LAYER_IBY_EXPORT_PATH(qtdemoapps.iby)" -- cgit v0.12 From 038e81412918dafaf50eaf7f9d6757e2677e4bb6 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Wed, 3 Feb 2010 11:58:27 +1000 Subject: Remove debug. --- src/network/access/qnetworkaccessbackend.cpp | 13 +++---------- src/network/access/qnetworkaccessmanager.cpp | 2 -- src/network/access/qnetworkreplyimpl.cpp | 3 --- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp index 2eebcf9..bab6d14 100644 --- a/src/network/access/qnetworkaccessbackend.cpp +++ b/src/network/access/qnetworkaccessbackend.cpp @@ -359,16 +359,9 @@ bool QNetworkAccessBackend::start() return true; } - if (manager->session->isOpen()) { - if (manager->session->state() == QNetworkSession::Connected) { - qDebug() << "Session is open and state is connected"; - open(); - return true; - } else { - qDebug() << "we are roaming, connecting, etc. delay until roaming completes"; - } - } else { - qDebug() << "session not open"; + if (manager->session->isOpen() && manager->session->state() == QNetworkSession::Connected) { + open(); + return true; } return false; diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index a7a81f8..dbcdddf 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -1084,8 +1084,6 @@ void QNetworkAccessManagerPrivate::_q_sessionOpened() { Q_Q(QNetworkAccessManager); - qDebug() << "Session Opened"; - // start waiting children foreach (QObject *child, q->children()) { QNetworkReplyImpl *reply = qobject_cast(child); diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index 5d52913..fbe90ef 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -87,7 +87,6 @@ void QNetworkReplyImplPrivate::_q_startOperation() // backend failed to start because the session state is not Connected. // QNetworkAccessManager will call reply->backend->start() again for us when the session // state changes. - qDebug() << "Waiting for session for" << url; state = WaitingForSession; if (!manager->d_func()->session->isOpen()) @@ -556,8 +555,6 @@ void QNetworkReplyImplPrivate::finished() // if we don't know the total size of or we received everything save the cache if (totalSize.isNull() || totalSize == -1 || bytesDownloaded == totalSize) completeCacheSave(); - else - qDebug() << "Not saving cache."; // note: might not be a good idea, since users could decide to delete us // which would delete the backend too... -- cgit v0.12 From 92eac408783fd4b1e2db2759c3212b580ff24205 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Wed, 3 Feb 2010 15:48:32 +1000 Subject: Fix compile warnings. --- src/network/access/qnetworkaccessmanager.cpp | 63 +++++++++++----------------- 1 file changed, 25 insertions(+), 38 deletions(-) diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index dbcdddf..4e28641 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -805,28 +805,24 @@ void QNetworkAccessManagerPrivate::_q_replyFinished() emit q->finished(reply); if (deferredMigration) { - bool repliesPending = false; foreach (QObject *child, q->children()) { - if (child != reply && child->inherits("QNetworkReplyImpl")) { - QNetworkReplyImpl *replyImpl = qobject_cast(child); - qDebug() << "reply state is" << replyImpl->d_func()->state; - switch (replyImpl->d_func()->state) { - case QNetworkReplyImplPrivate::Idle: - case QNetworkReplyImplPrivate::Finished: - case QNetworkReplyImplPrivate::Aborted: - break; - case QNetworkReplyImplPrivate::Buffering: - case QNetworkReplyImplPrivate::Working: - repliesPending = true; - break; - } + if (child == reply) + continue; + + QNetworkReplyImpl *replyImpl = qobject_cast(child); + if (!replyImpl) + continue; + + QNetworkReplyImplPrivate::State state = replyImpl->d_func()->state; + if (state == QNetworkReplyImplPrivate::Buffering || + state == QNetworkReplyImplPrivate::Working) { + return; } } - if (!repliesPending) { - deferredMigration = false; - qDebug() << "Migrating as there are no pending replies."; - session->migrate(); - } + + deferredMigration = false; + qDebug() << "Migrating as there are no pending replies."; + session->migrate(); } } @@ -1108,8 +1104,6 @@ void QNetworkAccessManagerPrivate::_q_sessionError(QNetworkSession::SessionError void QNetworkAccessManagerPrivate::_q_sessionStateChanged(QNetworkSession::State state) { - Q_Q(QNetworkAccessManager); - qDebug() << "session state changed to" << state; } @@ -1144,32 +1138,25 @@ void QNetworkAccessManagerPrivate::_q_sessionNewConfigurationActivated() } } -void QNetworkAccessManagerPrivate::_q_sessionPreferredConfigurationChanged(const QNetworkConfiguration &config, bool isSeamless) +void QNetworkAccessManagerPrivate::_q_sessionPreferredConfigurationChanged(const QNetworkConfiguration &, bool) { Q_Q(QNetworkAccessManager); - deferredMigration = false; foreach (QObject *child, q->children()) { - if (child->inherits("QNetworkReplyImpl")) { - QNetworkReplyImpl *replyImpl = qobject_cast(child); - qDebug() << "reply state is" << replyImpl->d_func()->state; - switch (replyImpl->d_func()->state) { - case QNetworkReplyImplPrivate::Idle: - case QNetworkReplyImplPrivate::Finished: - case QNetworkReplyImplPrivate::Aborted: - break; - case QNetworkReplyImplPrivate::Buffering: - case QNetworkReplyImplPrivate::Working: + QNetworkReplyImpl *replyImpl = qobject_cast(child); + if (replyImpl) { + QNetworkReplyImplPrivate::State state = replyImpl->d_func()->state; + if (state == QNetworkReplyImplPrivate::Buffering || + state == QNetworkReplyImplPrivate::Working) { deferredMigration = true; - break; + return; } } } - if (!deferredMigration) { - qDebug() << "Migrating as there are no pending replies."; - session->migrate(); - } + deferredMigration = false; + qDebug() << "Migrating as there are no pending replies."; + session->migrate(); } QT_END_NAMESPACE -- cgit v0.12 From 68d510148615b5fb4d3b6ce5faa516c110c53d58 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 4 Feb 2010 09:16:19 +1000 Subject: Only create session when valid configuration is available. Only create a network session when a valid configuration is available. Don't execute session code if a network session has not been created. --- src/network/access/qnetworkaccessbackend.cpp | 5 +++ src/network/access/qnetworkaccessmanager.cpp | 63 +++++++++++++++++++--------- src/network/access/qnetworkaccessmanager_p.h | 2 + src/network/access/qnetworkreplyimpl.cpp | 16 ++++--- 4 files changed, 62 insertions(+), 24 deletions(-) diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp index bab6d14..0bfeb3b 100644 --- a/src/network/access/qnetworkaccessbackend.cpp +++ b/src/network/access/qnetworkaccessbackend.cpp @@ -349,6 +349,11 @@ void QNetworkAccessBackend::sslErrors(const QList &errors) */ bool QNetworkAccessBackend::start() { + if (!manager->session) { + open(); + return true; + } + // This is not ideal. const QString host = reply->url.host(); if (host == QLatin1String("localhost") || diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 4e28641..e17beb9 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -350,18 +350,7 @@ QNetworkAccessManager::QNetworkAccessManager(QObject *parent) ensureInitialized(); QNetworkConfigurationManager manager; - d_func()->session = new QNetworkSession(manager.defaultConfiguration(), this); - - connect(d_func()->session, SIGNAL(opened()), this, SLOT(_q_sessionOpened())); - connect(d_func()->session, SIGNAL(closed()), this, SLOT(_q_sessionClosed())); - connect(d_func()->session, SIGNAL(stateChanged(QNetworkSession::State)), - this, SLOT(_q_sessionStateChanged(QNetworkSession::State))); - connect(d_func()->session, SIGNAL(error(QNetworkSession::SessionError)), - this, SLOT(_q_sessionError(QNetworkSession::SessionError))); - connect(d_func()->session, SIGNAL(newConfigurationActivated()), - this, SLOT(_q_sessionNewConfigurationActivated())); - connect(d_func()->session, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool)), - this, SLOT(_q_sessionPreferredConfigurationChanged(QNetworkConfiguration,bool))); + d_func()->createSession(manager.defaultConfiguration()); } /*! @@ -689,8 +678,7 @@ QNetworkReply *QNetworkAccessManager::deleteResource(const QNetworkRequest &requ */ void QNetworkAccessManager::setConfiguration(const QNetworkConfiguration &config) { - delete d_func()->session; - d_func()->session = new QNetworkSession(config, this); + d_func()->createSession(config); } /*! @@ -702,7 +690,12 @@ void QNetworkAccessManager::setConfiguration(const QNetworkConfiguration &config */ QNetworkConfiguration QNetworkAccessManager::configuration() const { - return d_func()->session->configuration(); + Q_D(const QNetworkAccessManager); + + if (d->session) + return d->session->configuration(); + else + return QNetworkConfiguration(); } /*! @@ -714,11 +707,16 @@ QNetworkConfiguration QNetworkAccessManager::configuration() const */ QNetworkConfiguration QNetworkAccessManager::activeConfiguration() const { - QNetworkConfigurationManager manager; + Q_D(const QNetworkAccessManager); - return manager.configurationFromIdentifier( - d_func()->session->sessionProperty(QLatin1String("ActiveConfiguration")).toString()); + if (d->session) { + QNetworkConfigurationManager manager; + return manager.configurationFromIdentifier( + d->session->sessionProperty(QLatin1String("ActiveConfiguration")).toString()); + } else { + return QNetworkConfiguration(); + } } /*! @@ -800,11 +798,12 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera void QNetworkAccessManagerPrivate::_q_replyFinished() { Q_Q(QNetworkAccessManager); + QNetworkReply *reply = qobject_cast(q->sender()); if (reply) emit q->finished(reply); - if (deferredMigration) { + if (session && deferredMigration) { foreach (QObject *child, q->children()) { if (child == reply) continue; @@ -1076,6 +1075,32 @@ QNetworkAccessManagerPrivate::~QNetworkAccessManagerPrivate() { } +void QNetworkAccessManagerPrivate::createSession(const QNetworkConfiguration &config) +{ + Q_Q(QNetworkAccessManager); + + if (session) + delete session; + + if (!config.isValid()) { + session = 0; + return; + } + + session = new QNetworkSession(config, q); + + QObject::connect(session, SIGNAL(opened()), q, SLOT(_q_sessionOpened())); + QObject::connect(session, SIGNAL(closed()), q, SLOT(_q_sessionClosed())); + QObject::connect(session, SIGNAL(stateChanged(QNetworkSession::State)), + q, SLOT(_q_sessionStateChanged(QNetworkSession::State))); + QObject::connect(session, SIGNAL(error(QNetworkSession::SessionError)), + q, SLOT(_q_sessionError(QNetworkSession::SessionError))); + QObject::connect(session, SIGNAL(newConfigurationActivated()), + q, SLOT(_q_sessionNewConfigurationActivated())); + QObject::connect(session, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool)), + q, SLOT(_q_sessionPreferredConfigurationChanged(QNetworkConfiguration,bool))); +} + void QNetworkAccessManagerPrivate::_q_sessionOpened() { Q_Q(QNetworkAccessManager); diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h index b9e3964..92b2782 100644 --- a/src/network/access/qnetworkaccessmanager_p.h +++ b/src/network/access/qnetworkaccessmanager_p.h @@ -108,6 +108,8 @@ public: emit q->debugMessage(message); } + void createSession(const QNetworkConfiguration &config); + void _q_sessionOpened(); void _q_sessionClosed(); void _q_sessionError(QNetworkSession::SessionError error); diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index fbe90ef..72c378a 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -89,13 +89,18 @@ void QNetworkReplyImplPrivate::_q_startOperation() // state changes. state = WaitingForSession; - if (!manager->d_func()->session->isOpen()) - manager->d_func()->session->open(); + QNetworkSession *session = manager->d_func()->session; + + if (session) { + if (!session->isOpen()) + session->open(); + } else { + qWarning("Backend is waiting for QNetworkSession to connect, but there is none!"); + } return; } - //backend->open(); if (state != Finished) { if (operation == QNetworkAccessManager::GetOperation) pendingNotifications.append(NotifyDownstreamReadyWrite); @@ -516,8 +521,9 @@ void QNetworkReplyImplPrivate::finished() pauseNotificationHandling(); QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); - if (state == Working && errorCode != QNetworkReply::OperationCanceledError && - manager->d_func()->session->state() == QNetworkSession::Roaming) { + QNetworkSession *session = manager->d_func()->session; + if (session && session->state() == QNetworkSession::Roaming && + state == Working && errorCode != QNetworkReply::OperationCanceledError) { // only content with a known size will fail with a temporary network failure error if (!totalSize.isNull()) { qDebug() << "Connection broke during download."; -- cgit v0.12 From dc5350f9325eb0daef6550e7a6ff14a82d030d63 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 4 Feb 2010 16:55:05 +1000 Subject: Migrate in progress http downloads. --- src/network/access/qnetworkaccessbackend_p.h | 1 + src/network/access/qnetworkaccessmanager.cpp | 18 ++++++- src/network/access/qnetworkreplyimpl.cpp | 70 +++++++++++++++++++++++++++- src/network/access/qnetworkreplyimpl_p.h | 6 ++- 4 files changed, 91 insertions(+), 4 deletions(-) diff --git a/src/network/access/qnetworkaccessbackend_p.h b/src/network/access/qnetworkaccessbackend_p.h index b8b369f..830ec7e 100644 --- a/src/network/access/qnetworkaccessbackend_p.h +++ b/src/network/access/qnetworkaccessbackend_p.h @@ -192,6 +192,7 @@ private: friend class QNetworkAccessManager; friend class QNetworkAccessManagerPrivate; friend class QNetworkAccessBackendUploadIODevice; + friend class QNetworkReplyImplPrivate; QNetworkAccessManagerPrivate *manager; QNetworkReplyImplPrivate *reply; }; diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index e17beb9..617e398 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -1155,11 +1155,25 @@ void QNetworkAccessManagerPrivate::_q_sessionNewConfigurationActivated() qDebug() << "Accepting new configuration."; session->accept(); - // start waiting children foreach (QObject *child, q->children()) { QNetworkReplyImpl *reply = qobject_cast(child); - if (reply && reply->d_func()->state == QNetworkReplyImplPrivate::WaitingForSession) + if (!reply) + continue; + + switch (reply->d_func()->state) { + case QNetworkReplyImplPrivate::Buffering: + case QNetworkReplyImplPrivate::Working: + case QNetworkReplyImplPrivate::Reconnecting: + // Migrate existing downloads to new configuration. + reply->d_func()->migrateBackend(); + break; + case QNetworkReplyImplPrivate::WaitingForSession: + // Start waiting requests. QMetaObject::invokeMethod(reply, "_q_startOperation", Qt::QueuedConnection); + break; + default: + qDebug() << "How do we handle replies in state" << reply->d_func()->state; + } } } diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index 72c378a..932d81a 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -58,7 +58,7 @@ inline QNetworkReplyImplPrivate::QNetworkReplyImplPrivate() copyDevice(0), cacheEnabled(false), cacheSaveDevice(0), notificationHandlingPaused(false), - bytesDownloaded(0), lastBytesDownloaded(-1), bytesUploaded(-1), + bytesDownloaded(0), lastBytesDownloaded(-1), bytesUploaded(-1), preMigrationDownloaded(-1), httpStatusCode(0), state(Idle) { @@ -152,6 +152,8 @@ void QNetworkReplyImplPrivate::_q_copyReadyRead() lastBytesDownloaded = bytesDownloaded; QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); + if (preMigrationDownloaded != Q_INT64_C(-1)) + totalSize = totalSize.toLongLong() + preMigrationDownloaded; pauseNotificationHandling(); emit q->downloadProgress(bytesDownloaded, totalSize.isNull() ? Q_INT64_C(-1) : totalSize.toLongLong()); @@ -475,6 +477,8 @@ void QNetworkReplyImplPrivate::appendDownstreamData(QByteDataBuffer &data) QPointer qq = q; QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); + if (preMigrationDownloaded != Q_INT64_C(-1)) + totalSize = totalSize.toLongLong() + preMigrationDownloaded; pauseNotificationHandling(); emit q->downloadProgress(bytesDownloaded, totalSize.isNull() ? Q_INT64_C(-1) : totalSize.toLongLong()); @@ -521,6 +525,8 @@ void QNetworkReplyImplPrivate::finished() pauseNotificationHandling(); QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); + if (preMigrationDownloaded != Q_INT64_C(-1)) + totalSize = totalSize.toLongLong() + preMigrationDownloaded; QNetworkSession *session = manager->d_func()->session; if (session && session->state() == QNetworkSession::Roaming && state == Working && errorCode != QNetworkReply::OperationCanceledError) { @@ -768,6 +774,68 @@ bool QNetworkReplyImpl::event(QEvent *e) return QObject::event(e); } +void QNetworkReplyImplPrivate::migrateBackend() +{ + Q_Q(QNetworkReplyImpl); + + if (state == QNetworkReplyImplPrivate::Finished || + state == QNetworkReplyImplPrivate::Aborted) { + qDebug() << "Network reply is already finished/aborted."; + return; + } + + if (!qobject_cast(backend)) { + qDebug() << "Resume only support by http backend, not migrating."; + return; + } + + if (outgoingData) { + qDebug() << "Request has outgoing data, not migrating."; + return; + } + + qDebug() << "Need to check for only cacheable content."; + + // stop both upload and download + if (outgoingData) + outgoingData->disconnect(q); + if (copyDevice) + copyDevice->disconnect(q); + + state = QNetworkReplyImplPrivate::Reconnecting; + + if (backend) { + backend->deleteLater(); + backend = 0; + } + + RawHeadersList::ConstIterator it = findRawHeader("Accept-Ranges"); + if (it == rawHeaders.constEnd() || it->second == "none") { + qDebug() << "Range header not supported by server/resource."; + qFatal("Should fail with TemporaryNetworkFailure."); + } + + cookedHeaders.clear(); + rawHeaders.clear(); + + preMigrationDownloaded = bytesDownloaded; + + request.setRawHeader("Range", "bytes=" + QByteArray::number(preMigrationDownloaded) + '-'); + + backend = manager->d_func()->findBackend(operation, request); + + if (backend) { + backend->setParent(q); + backend->reply = this; + } + + if (qobject_cast(backend)) { + _q_startOperation(); + } else { + QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); + } +} + QT_END_NAMESPACE #include "moc_qnetworkreplyimpl_p.cpp" diff --git a/src/network/access/qnetworkreplyimpl_p.h b/src/network/access/qnetworkreplyimpl_p.h index 861b2b2..9de16e6 100644 --- a/src/network/access/qnetworkreplyimpl_p.h +++ b/src/network/access/qnetworkreplyimpl_p.h @@ -115,7 +115,8 @@ public: Working, Finished, Aborted, - WaitingForSession + WaitingForSession, + Reconnecting }; typedef QQueue NotificationQueue; @@ -162,6 +163,8 @@ public: QIODevice *copyDevice; QAbstractNetworkCache *networkCache() const; + void migrateBackend(); + bool cacheEnabled; QIODevice *cacheSaveDevice; @@ -178,6 +181,7 @@ public: qint64 bytesDownloaded; qint64 lastBytesDownloaded; qint64 bytesUploaded; + qint64 preMigrationDownloaded; QString httpReasonPhrase; int httpStatusCode; -- cgit v0.12 From df4b88078124fe993795bd436f3093b0120ffce2 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 4 Feb 2010 16:57:47 +1000 Subject: Add hooks for testing. --- src/network/access/qnetworkreply.h | 2 ++ src/network/access/qnetworkreplyimpl.cpp | 7 +++++++ src/network/access/qnetworkreplyimpl_p.h | 2 ++ 3 files changed, 11 insertions(+) diff --git a/src/network/access/qnetworkreply.h b/src/network/access/qnetworkreply.h index b39557a..0f1fe8a 100644 --- a/src/network/access/qnetworkreply.h +++ b/src/network/access/qnetworkreply.h @@ -138,6 +138,8 @@ public: void ignoreSslErrors(const QList &errors); #endif + virtual void migrateBackend() { qWarning("Your backend doesn't support migration!"); } // Testing + public Q_SLOTS: virtual void ignoreSslErrors(); diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index 932d81a..0c7aca8 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -774,6 +774,13 @@ bool QNetworkReplyImpl::event(QEvent *e) return QObject::event(e); } +void QNetworkReplyImpl::migrateBackend() +{ + Q_D(QNetworkReplyImpl); + + d->migrateBackend(); +} + void QNetworkReplyImplPrivate::migrateBackend() { Q_Q(QNetworkReplyImpl); diff --git a/src/network/access/qnetworkreplyimpl_p.h b/src/network/access/qnetworkreplyimpl_p.h index 9de16e6..ac82ca0 100644 --- a/src/network/access/qnetworkreplyimpl_p.h +++ b/src/network/access/qnetworkreplyimpl_p.h @@ -92,6 +92,8 @@ public: Q_INVOKABLE virtual void ignoreSslErrorsImplementation(const QList &errors); #endif + void migrateBackend(); + Q_DECLARE_PRIVATE(QNetworkReplyImpl) Q_PRIVATE_SLOT(d_func(), void _q_startOperation()) Q_PRIVATE_SLOT(d_func(), void _q_copyReadyRead()) -- cgit v0.12 From a307e9662c2b57ad16c2329754ea4795615de125 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Fri, 5 Feb 2010 10:51:25 +1000 Subject: Remove implementation specific functions out of QNetworkSessionEngine. --- src/network/bearer/qnetworksessionengine_p.h | 19 +----- src/plugins/bearer/corewlan/corewlan.pro | 3 +- src/plugins/bearer/corewlan/qcorewlanengine.h | 6 +- src/plugins/bearer/corewlan/qcorewlanengine.mm | 4 +- src/plugins/bearer/generic/generic.pro | 1 + src/plugins/bearer/generic/qgenericengine.cpp | 14 +--- src/plugins/bearer/generic/qgenericengine.h | 6 +- src/plugins/bearer/nativewifi/nativewifi.pro | 4 +- .../bearer/nativewifi/qnativewifiengine.cpp | 4 +- src/plugins/bearer/nativewifi/qnativewifiengine.h | 6 +- .../bearer/networkmanager/networkmanager.pro | 3 +- .../networkmanager/qnetworkmanagerengine.cpp | 4 +- .../bearer/networkmanager/qnetworkmanagerengine.h | 6 +- src/plugins/bearer/nla/nla.pro | 4 +- src/plugins/bearer/nla/qnlaengine.cpp | 4 +- src/plugins/bearer/nla/qnlaengine.h | 7 +- src/plugins/bearer/qnetworksession_impl.cpp | 34 ++++------ src/plugins/bearer/qnetworksession_impl.h | 11 ++-- src/plugins/bearer/qnetworksessionengine_impl.h | 77 ++++++++++++++++++++++ src/plugins/bearer/symbian/symbianengine.cpp | 24 +------ src/plugins/bearer/symbian/symbianengine.h | 8 +-- 21 files changed, 137 insertions(+), 112 deletions(-) create mode 100644 src/plugins/bearer/qnetworksessionengine_impl.h diff --git a/src/network/bearer/qnetworksessionengine_p.h b/src/network/bearer/qnetworksessionengine_p.h index 029c2c5..39c3d17 100644 --- a/src/network/bearer/qnetworksessionengine_p.h +++ b/src/network/bearer/qnetworksessionengine_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) ** @@ -73,28 +73,13 @@ class Q_NETWORK_EXPORT QNetworkSessionEngine : public QObject Q_OBJECT public: - enum ConnectionError { - InterfaceLookupError = 0, - ConnectError, - OperationNotSupported, - DisconnectionError, - }; - QNetworkSessionEngine(QObject *parent = 0); virtual ~QNetworkSessionEngine(); - virtual QString getInterfaceFromId(const QString &id) = 0; virtual bool hasIdentifier(const QString &id) = 0; - //virtual QString bearerName(const QString &id) = 0; - - virtual void connectToId(const QString &id) = 0; - virtual void disconnectFromId(const QString &id) = 0; - virtual void requestUpdate() = 0; - virtual QNetworkSession::State sessionStateForId(const QString &id) = 0; - virtual QNetworkConfigurationManager::Capabilities capabilities() const = 0; virtual QNetworkSessionPrivate *createSessionBackend() = 0; @@ -115,8 +100,6 @@ Q_SIGNALS: void configurationChanged(QNetworkConfigurationPrivatePointer config); void updateCompleted(); - - void connectionError(const QString &id, QNetworkSessionEngine::ConnectionError error); }; typedef QNetworkSessionEngine QBearerEngine; diff --git a/src/plugins/bearer/corewlan/corewlan.pro b/src/plugins/bearer/corewlan/corewlan.pro index 1660215..c59d602 100644 --- a/src/plugins/bearer/corewlan/corewlan.pro +++ b/src/plugins/bearer/corewlan/corewlan.pro @@ -12,7 +12,8 @@ contains(QT_CONFIG, corewlan) { } HEADERS += qcorewlanengine.h \ - ../qnetworksession_impl.h + ../qnetworksession_impl.h \ + ../qnetworksessionengine_impl.h SOURCES += main.cpp \ qcorewlanengine.mm \ diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.h b/src/plugins/bearer/corewlan/qcorewlanengine.h index 61d80cf..7199ace 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.h +++ b/src/plugins/bearer/corewlan/qcorewlanengine.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) ** @@ -42,7 +42,7 @@ #ifndef QCOREWLANENGINE_H #define QCOREWLANENGINE_H -#include +#include "../qnetworksessionengine_impl.h" #include #include @@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; -class QCoreWlanEngine : public QNetworkSessionEngine +class QCoreWlanEngine : public QNetworkSessionEngineImpl { Q_OBJECT diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm index 2cbccb5..ca193ab 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.mm +++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm @@ -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) ** @@ -106,7 +106,7 @@ static QString qGetInterfaceType(const QString &interfaceString) } QCoreWlanEngine::QCoreWlanEngine(QObject *parent) -: QNetworkSessionEngine(parent) +: QNetworkSessionEngineImpl(parent) { connect(&pollTimer, SIGNAL(timeout()), this, SLOT(doRequestUpdate())); pollTimer.setInterval(10000); diff --git a/src/plugins/bearer/generic/generic.pro b/src/plugins/bearer/generic/generic.pro index d039731..dbf96d1 100644 --- a/src/plugins/bearer/generic/generic.pro +++ b/src/plugins/bearer/generic/generic.pro @@ -5,6 +5,7 @@ QT += network HEADERS += qgenericengine.h \ ../qnetworksession_impl.h \ + ../qnetworksessionengine_impl.h \ ../platformdefs_win.h SOURCES += qgenericengine.cpp \ ../qnetworksession_impl.cpp \ diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp index 55d1ae4..dea820d 100644 --- a/src/plugins/bearer/generic/qgenericengine.cpp +++ b/src/plugins/bearer/generic/qgenericengine.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) ** @@ -141,7 +141,7 @@ static QString qGetInterfaceType(const QString &interface) } QGenericEngine::QGenericEngine(QObject *parent) -: QNetworkSessionEngine(parent) +: QNetworkSessionEngineImpl(parent) { connect(&pollTimer, SIGNAL(timeout()), this, SLOT(doRequestUpdate())); pollTimer.setInterval(10000); @@ -162,16 +162,6 @@ bool QGenericEngine::hasIdentifier(const QString &id) return configurationInterface.contains(id); } -/*QString QGenericEngine::bearerName(const QString &id) -{ - QString interface = getInterfaceFromId(id); - - if (interface.isEmpty()) - return QLatin1String("Unknown"); - - return qGetInterfaceType(interface); -}*/ - void QGenericEngine::connectToId(const QString &id) { emit connectionError(id, OperationNotSupported); diff --git a/src/plugins/bearer/generic/qgenericengine.h b/src/plugins/bearer/generic/qgenericengine.h index b44685b..d755228 100644 --- a/src/plugins/bearer/generic/qgenericengine.h +++ b/src/plugins/bearer/generic/qgenericengine.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) ** @@ -42,7 +42,7 @@ #ifndef QGENERICENGINE_H #define QGENERICENGINE_H -#include +#include "../qnetworksessionengine_impl.h" #include #include @@ -52,7 +52,7 @@ QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; class QNetworkSessionPrivate; -class QGenericEngine : public QNetworkSessionEngine +class QGenericEngine : public QNetworkSessionEngineImpl { Q_OBJECT diff --git a/src/plugins/bearer/nativewifi/nativewifi.pro b/src/plugins/bearer/nativewifi/nativewifi.pro index 6e99c62..928d819 100644 --- a/src/plugins/bearer/nativewifi/nativewifi.pro +++ b/src/plugins/bearer/nativewifi/nativewifi.pro @@ -5,7 +5,9 @@ QT += network HEADERS += qnativewifiengine.h \ platformdefs.h \ - ../qnetworksession_impl.h + ../qnetworksession_impl.h \ + ../qnetworksessionengine_impl.h + SOURCES += main.cpp \ qnativewifiengine.cpp \ ../qnetworksession_impl.cpp diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp index af538a8..9f0d4c0 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.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) ** @@ -77,7 +77,7 @@ void qNotificationCallback(WLAN_NOTIFICATION_DATA *data, QNativeWifiEngine *d) } QNativeWifiEngine::QNativeWifiEngine(QObject *parent) -: QNetworkSessionEngine(parent), handle(0) +: QNetworkSessionEngineImpl(parent), handle(0) { DWORD clientVersion; diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.h b/src/plugins/bearer/nativewifi/qnativewifiengine.h index 83d9e2c..41217e2 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.h +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.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) ** @@ -53,7 +53,7 @@ // We mean it. // -#include +#include "../qnetworksessionengine_impl.h" #include @@ -62,7 +62,7 @@ QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; struct WLAN_NOTIFICATION_DATA; -class QNativeWifiEngine : public QNetworkSessionEngine +class QNativeWifiEngine : public QNetworkSessionEngineImpl { Q_OBJECT diff --git a/src/plugins/bearer/networkmanager/networkmanager.pro b/src/plugins/bearer/networkmanager/networkmanager.pro index 2050125..6f271c6 100644 --- a/src/plugins/bearer/networkmanager/networkmanager.pro +++ b/src/plugins/bearer/networkmanager/networkmanager.pro @@ -8,7 +8,8 @@ DEFINES += BACKEND_NM HEADERS += qnmdbushelper.h \ qnetworkmanagerservice.h \ qnetworkmanagerengine.h \ - ../qnetworksession_impl.h + ../qnetworksession_impl.h \ + ../qnetworksessionengine_impl.h SOURCES += main.cpp \ qnmdbushelper.cpp \ diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp index 439772a..129f7d2 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.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) ** @@ -60,7 +60,7 @@ QT_BEGIN_NAMESPACE QNetworkManagerEngine::QNetworkManagerEngine(QObject *parent) -: QNetworkSessionEngine(parent), +: QNetworkSessionEngineImpl(parent), interface(new QNetworkManagerInterface(this)), systemSettings(new QNetworkManagerSettings(NM_DBUS_SERVICE_SYSTEM_SETTINGS, this)), userSettings(new QNetworkManagerSettings(NM_DBUS_SERVICE_USER_SETTINGS, this)) diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h index 5f8110c..f454628 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.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) ** @@ -53,7 +53,7 @@ // We mean it. // -#include +#include "../qnetworksessionengine_impl.h" #include "qnetworkmanagerservice.h" @@ -62,7 +62,7 @@ QT_BEGIN_NAMESPACE -class QNetworkManagerEngine : public QNetworkSessionEngine +class QNetworkManagerEngine : public QNetworkSessionEngineImpl { Q_OBJECT diff --git a/src/plugins/bearer/nla/nla.pro b/src/plugins/bearer/nla/nla.pro index 9bd3526..4c5e492 100644 --- a/src/plugins/bearer/nla/nla.pro +++ b/src/plugins/bearer/nla/nla.pro @@ -11,7 +11,9 @@ QT += network HEADERS += qnlaengine.h \ ../platformdefs_win.h \ - ../qnetworksession_impl.h + ../qnetworksession_impl.h \ + ../qnetworksessionengine_impl.h + SOURCES += main.cpp \ qnlaengine.cpp \ ../qnetworksession_impl.cpp diff --git a/src/plugins/bearer/nla/qnlaengine.cpp b/src/plugins/bearer/nla/qnlaengine.cpp index 0ed62e3..ed802c0 100644 --- a/src/plugins/bearer/nla/qnlaengine.cpp +++ b/src/plugins/bearer/nla/qnlaengine.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) ** @@ -506,7 +506,7 @@ void QNlaThread::fetchConfigurations() } QNlaEngine::QNlaEngine(QObject *parent) -: QNetworkSessionEngine(parent), nlaThread(0) +: QNetworkSessionEngineImpl(parent), nlaThread(0) { nlaThread = new QNlaThread(this); connect(nlaThread, SIGNAL(networksChanged()), diff --git a/src/plugins/bearer/nla/qnlaengine.h b/src/plugins/bearer/nla/qnlaengine.h index 515a13c..fa010b9 100644 --- a/src/plugins/bearer/nla/qnlaengine.h +++ b/src/plugins/bearer/nla/qnlaengine.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) ** @@ -53,7 +53,8 @@ // We mean it. // -#include +#include "../qnetworksessionengine_impl.h" + #include #include @@ -71,7 +72,7 @@ public: int version; }; -class QNlaEngine : public QNetworkSessionEngine +class QNlaEngine : public QNetworkSessionEngineImpl { Q_OBJECT diff --git a/src/plugins/bearer/qnetworksession_impl.cpp b/src/plugins/bearer/qnetworksession_impl.cpp index a826fd6..6de3423 100644 --- a/src/plugins/bearer/qnetworksession_impl.cpp +++ b/src/plugins/bearer/qnetworksession_impl.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) ** @@ -40,9 +40,9 @@ ****************************************************************************/ #include "qnetworksession_impl.h" +#include "qnetworksessionengine_impl.h" #include -#include #include #include @@ -53,13 +53,14 @@ QT_BEGIN_NAMESPACE -static QNetworkSessionEngine *getEngineFromId(const QString &id) +static QNetworkSessionEngineImpl *getEngineFromId(const QString &id) { QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); foreach (QNetworkSessionEngine *engine, priv->sessionEngines) { - if (engine->hasIdentifier(id)) - return engine; + QNetworkSessionEngineImpl *engineImpl = qobject_cast(engine); + if (engineImpl && engineImpl->hasIdentifier(id)) + return engineImpl; } return 0; @@ -110,8 +111,8 @@ void QNetworkSessionPrivateImpl::syncStateWithInterface() state = QNetworkSession::Invalid; lastError = QNetworkSession::UnknownSessionError; - qRegisterMetaType - ("QNetworkSessionEngine::ConnectionError"); + qRegisterMetaType + ("QNetworkSessionEngineImpl::ConnectionError"); switch (publicConfig.type()) { case QNetworkConfiguration::InternetAccessPoint: @@ -239,14 +240,6 @@ void QNetworkSessionPrivateImpl::setSessionProperty(const QString& /*key*/, cons { } -/*QString QNetworkSessionPrivateImpl::bearerName() const -{ - if (!publicConfig.isValid() || !engine) - return QString(); - - return engine->bearerName(activeConfig.identifier()); -}*/ - QString QNetworkSessionPrivateImpl::errorString() const { switch (lastError) { @@ -414,18 +407,19 @@ void QNetworkSessionPrivateImpl::forcedSessionClose(const QNetworkConfiguration } } -void QNetworkSessionPrivateImpl::connectionError(const QString &id, QNetworkSessionEngine::ConnectionError error) +void QNetworkSessionPrivateImpl::connectionError(const QString &id, + QNetworkSessionEngineImpl::ConnectionError error) { if (activeConfig.identifier() == id) { networkConfigurationsChanged(); switch (error) { - case QNetworkSessionEngine::OperationNotSupported: + case QNetworkSessionEngineImpl::OperationNotSupported: lastError = QNetworkSession::OperationNotSupportedError; opened = false; break; - case QNetworkSessionEngine::InterfaceLookupError: - case QNetworkSessionEngine::ConnectError: - case QNetworkSessionEngine::DisconnectionError: + case QNetworkSessionEngineImpl::InterfaceLookupError: + case QNetworkSessionEngineImpl::ConnectError: + case QNetworkSessionEngineImpl::DisconnectionError: default: lastError = QNetworkSession::UnknownSessionError; } diff --git a/src/plugins/bearer/qnetworksession_impl.h b/src/plugins/bearer/qnetworksession_impl.h index 104d1f0..1fd97d3 100644 --- a/src/plugins/bearer/qnetworksession_impl.h +++ b/src/plugins/bearer/qnetworksession_impl.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) ** @@ -53,15 +53,16 @@ // We mean it. // +#include "qnetworksessionengine_impl.h" + #include -#include #include #include QT_BEGIN_NAMESPACE -class QNetworkSessionEngine; +class QNetworkSessionEngineImpl; class QNetworkSessionPrivateImpl : public QNetworkSessionPrivate { @@ -109,7 +110,7 @@ private Q_SLOTS: void networkConfigurationsChanged(); void configurationChanged(const QNetworkConfiguration &config); void forcedSessionClose(const QNetworkConfiguration &config); - void connectionError(const QString &id, QNetworkSessionEngine::ConnectionError error); + void connectionError(const QString &id, QNetworkSessionEngineImpl::ConnectionError error); private: QNetworkConfigurationManager manager; @@ -120,7 +121,7 @@ private: bool opened; - QNetworkSessionEngine *engine; + QNetworkSessionEngineImpl *engine; QNetworkSession::SessionError lastError; diff --git a/src/plugins/bearer/qnetworksessionengine_impl.h b/src/plugins/bearer/qnetworksessionengine_impl.h new file mode 100644 index 0000000..1294cc5 --- /dev/null +++ b/src/plugins/bearer/qnetworksessionengine_impl.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** 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 QNETWORKSESSIONENGINE_IMPL_H +#define QNETWORKSESSIONENGINE_IMPL_H + +#include + +QT_BEGIN_NAMESPACE + +class QNetworkSessionEngineImpl : public QNetworkSessionEngine +{ + Q_OBJECT + +public: + enum ConnectionError { + InterfaceLookupError = 0, + ConnectError, + OperationNotSupported, + DisconnectionError, + }; + + QNetworkSessionEngineImpl(QObject *parent = 0) : QNetworkSessionEngine(parent) { } + ~QNetworkSessionEngineImpl() { } + + virtual void connectToId(const QString &id) = 0; + virtual void disconnectFromId(const QString &id) = 0; + + virtual QString getInterfaceFromId(const QString &id) = 0; + + virtual QNetworkSession::State sessionStateForId(const QString &id) = 0; + +Q_SIGNALS: + void connectionError(const QString &id, ConnectionError error); +}; + +QT_END_NAMESPACE + +#endif // QNETWORKSESSIONENGINE_IMPL_H diff --git a/src/plugins/bearer/symbian/symbianengine.cpp b/src/plugins/bearer/symbian/symbianengine.cpp index f5c5007..3d0ec0f 100644 --- a/src/plugins/bearer/symbian/symbianengine.cpp +++ b/src/plugins/bearer/symbian/symbianengine.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) ** @@ -156,12 +156,6 @@ SymbianEngine::~SymbianEngine() delete ipCommsDB; } -QString SymbianEngine::getInterfaceFromId(const QString &id) -{ - qFatal("getInterfaceFromId(%s) not implemented\n", qPrintable(id)); - return QString(); -} - bool SymbianEngine::hasIdentifier(const QString &id) { return accessPointConfigurations.contains(id) || @@ -169,22 +163,6 @@ bool SymbianEngine::hasIdentifier(const QString &id) userChoiceConfigurations.contains(id); } -void SymbianEngine::connectToId(const QString &id) -{ - qFatal("connectToId(%s) not implemented\n", qPrintable(id)); -} - -void SymbianEngine::disconnectFromId(const QString &id) -{ - qFatal("disconnectFromId(%s) not implemented\n", qPrintable(id)); -} - -QNetworkSession::State SymbianEngine::sessionStateForId(const QString &id) -{ - qFatal("sessionStateForId(%s) not implemented\n", qPrintable(id)); - return QNetworkSession::Invalid; -} - QNetworkConfigurationManager::Capabilities SymbianEngine::capabilities() const { QNetworkConfigurationManager::Capabilities capFlags; diff --git a/src/plugins/bearer/symbian/symbianengine.h b/src/plugins/bearer/symbian/symbianengine.h index cd5aa43..4a4a8c1 100644 --- a/src/plugins/bearer/symbian/symbianengine.h +++ b/src/plugins/bearer/symbian/symbianengine.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) ** @@ -106,16 +106,10 @@ public: SymbianEngine(QObject *parent = 0); virtual ~SymbianEngine(); - QString getInterfaceFromId(const QString &id); bool hasIdentifier(const QString &id); - void connectToId(const QString &id); - void disconnectFromId(const QString &id); - void requestUpdate(); - QNetworkSession::State sessionStateForId(const QString &id); - QNetworkConfigurationManager::Capabilities capabilities() const; QNetworkSessionPrivate *createSessionBackend(); -- cgit v0.12 From b1029a6bd7131d540f76ead8783ed0978f7163aa Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Fri, 5 Feb 2010 11:13:05 +1000 Subject: Rename internal QNetworkSessionEngine* to QBearerEngine*. --- src/network/bearer/bearer.pri | 4 +- src/network/bearer/qbearerengine.cpp | 74 ++++++++++++++ src/network/bearer/qbearerengine_p.h | 107 ++++++++++++++++++++ src/network/bearer/qbearerplugin.h | 4 +- src/network/bearer/qnetworkconfigmanager.cpp | 8 +- src/network/bearer/qnetworkconfigmanager_p.cpp | 8 +- src/network/bearer/qnetworkconfigmanager_p.h | 6 +- src/network/bearer/qnetworksession.cpp | 4 +- src/network/bearer/qnetworksessionengine.cpp | 74 -------------- src/network/bearer/qnetworksessionengine_p.h | 109 --------------------- src/plugins/bearer/corewlan/corewlan.pro | 2 +- src/plugins/bearer/corewlan/qcorewlanengine.h | 4 +- src/plugins/bearer/corewlan/qcorewlanengine.mm | 2 +- src/plugins/bearer/generic/generic.pro | 2 +- src/plugins/bearer/generic/qgenericengine.cpp | 2 +- src/plugins/bearer/generic/qgenericengine.h | 4 +- src/plugins/bearer/nativewifi/nativewifi.pro | 2 +- .../bearer/nativewifi/qnativewifiengine.cpp | 2 +- src/plugins/bearer/nativewifi/qnativewifiengine.h | 4 +- .../bearer/networkmanager/networkmanager.pro | 2 +- .../networkmanager/qnetworkmanagerengine.cpp | 2 +- .../bearer/networkmanager/qnetworkmanagerengine.h | 4 +- src/plugins/bearer/nla/nla.pro | 2 +- src/plugins/bearer/nla/qnlaengine.cpp | 2 +- src/plugins/bearer/nla/qnlaengine.h | 4 +- src/plugins/bearer/qbearerengine_impl.h | 77 +++++++++++++++ src/plugins/bearer/qnetworksession_impl.cpp | 34 +++---- src/plugins/bearer/qnetworksession_impl.h | 8 +- src/plugins/bearer/qnetworksessionengine_impl.h | 77 --------------- src/plugins/bearer/symbian/symbianengine.cpp | 2 +- src/plugins/bearer/symbian/symbianengine.h | 4 +- 31 files changed, 319 insertions(+), 321 deletions(-) create mode 100644 src/network/bearer/qbearerengine.cpp create mode 100644 src/network/bearer/qbearerengine_p.h delete mode 100644 src/network/bearer/qnetworksessionengine.cpp delete mode 100644 src/network/bearer/qnetworksessionengine_p.h create mode 100644 src/plugins/bearer/qbearerengine_impl.h delete mode 100644 src/plugins/bearer/qnetworksessionengine_impl.h diff --git a/src/network/bearer/bearer.pri b/src/network/bearer/bearer.pri index 66b0ca4..14e7c0c 100644 --- a/src/network/bearer/bearer.pri +++ b/src/network/bearer/bearer.pri @@ -40,11 +40,11 @@ maemo { HEADERS += bearer/qnetworkconfigmanager_p.h \ bearer/qnetworkconfiguration_p.h \ bearer/qnetworksession_p.h \ - bearer/qnetworksessionengine_p.h \ + bearer/qbearerengine_p.h \ bearer/qbearerplugin.h SOURCES += bearer/qnetworkconfigmanager_p.cpp \ - bearer/qnetworksessionengine.cpp \ + bearer/qbearerengine.cpp \ bearer/qbearerplugin.cpp contains(QT_CONFIG, networkmanager):DEFINES += BACKEND_NM diff --git a/src/network/bearer/qbearerengine.cpp b/src/network/bearer/qbearerengine.cpp new file mode 100644 index 0000000..4d56047 --- /dev/null +++ b/src/network/bearer/qbearerengine.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** 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 "qbearerengine_p.h" + +QT_BEGIN_NAMESPACE + +QBearerEngine::QBearerEngine(QObject *parent) +: QObject(parent) +{ +} + +QBearerEngine::~QBearerEngine() +{ + foreach (const QString &oldIface, snapConfigurations.keys()) { + QNetworkConfigurationPrivatePointer priv = snapConfigurations.take(oldIface); + priv->isValid = false; + priv->id.clear(); + } + + foreach (const QString &oldIface, accessPointConfigurations.keys()) { + QNetworkConfigurationPrivatePointer priv = accessPointConfigurations.take(oldIface); + priv->isValid = false; + priv->id.clear(); + } + + foreach (const QString &oldIface, userChoiceConfigurations.keys()) { + QNetworkConfigurationPrivatePointer priv = userChoiceConfigurations.take(oldIface); + priv->isValid = false; + priv->id.clear(); + } +} + +#include "moc_qbearerengine_p.cpp" + +QT_END_NAMESPACE diff --git a/src/network/bearer/qbearerengine_p.h b/src/network/bearer/qbearerengine_p.h new file mode 100644 index 0000000..7e96877 --- /dev/null +++ b/src/network/bearer/qbearerengine_p.h @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** 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. +** +** $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 QBEARERENGINE_P_H +#define QBEARERENGINE_P_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_p.h" +#include "qnetworksession.h" +#include "qnetworkconfigmanager.h" + +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QNetworkConfiguration; + +class Q_NETWORK_EXPORT QBearerEngine : public QObject +{ + Q_OBJECT + +public: + QBearerEngine(QObject *parent = 0); + virtual ~QBearerEngine(); + + virtual bool hasIdentifier(const QString &id) = 0; + + virtual void requestUpdate() = 0; + + virtual QNetworkConfigurationManager::Capabilities capabilities() const = 0; + + virtual QNetworkSessionPrivate *createSessionBackend() = 0; + + virtual QNetworkConfigurationPrivatePointer defaultConfiguration() = 0; + +public: + //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 accessPointConfigurations; + QHash snapConfigurations; + QHash userChoiceConfigurations; + +Q_SIGNALS: + void configurationAdded(QNetworkConfigurationPrivatePointer config); + void configurationRemoved(QNetworkConfigurationPrivatePointer config); + void configurationChanged(QNetworkConfigurationPrivatePointer config); + + void updateCompleted(); +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/network/bearer/qbearerplugin.h b/src/network/bearer/qbearerplugin.h index 970410b..1958188 100644 --- a/src/network/bearer/qbearerplugin.h +++ b/src/network/bearer/qbearerplugin.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) ** @@ -42,7 +42,7 @@ #ifndef QBEARERPLUGIN_H #define QBEARERPLUGIN_H -#include +#include "qbearerengine_p.h" #include #include diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index f4daf4a..d46048b 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.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) ** @@ -42,7 +42,7 @@ #include "qnetworkconfigmanager.h" #include "qnetworkconfigmanager_p.h" -#include "qnetworksessionengine_p.h" +#include "qbearerengine_p.h" #include @@ -232,7 +232,7 @@ QList QNetworkConfigurationManager::allConfigurations(QNe QList result; QNetworkConfigurationManagerPrivate* conPriv = connManager(); - foreach (QNetworkSessionEngine *engine, conPriv->sessionEngines) { + foreach (QBearerEngine *engine, conPriv->sessionEngines) { QStringList cpsIdents = engine->accessPointConfigurations.keys(); //find all InternetAccessPoints @@ -274,7 +274,7 @@ QNetworkConfiguration QNetworkConfigurationManager::configurationFromIdentifier( QNetworkConfiguration item; - foreach (QNetworkSessionEngine *engine, conPriv->sessionEngines) { + foreach (QBearerEngine *engine, conPriv->sessionEngines) { if (engine->accessPointConfigurations.contains(identifier)) item.d = engine->accessPointConfigurations.value(identifier); else if (engine->snapConfigurations.contains(identifier)) diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index bc3cfbd..a94fd2f 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.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) ** @@ -176,7 +176,7 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() foreach (const QString &key, l->keys()) { QBearerEnginePlugin *plugin = qobject_cast(l->instance(key)); if (plugin) { - QNetworkSessionEngine *engine = plugin->create(key); + QBearerEngine *engine = plugin->create(key); if (!engine) continue; @@ -195,7 +195,7 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() } } - QNetworkSessionEngine *engine = qobject_cast(sender()); + QBearerEngine *engine = qobject_cast(sender()); if (!updatingEngines.isEmpty() && engine) { int index = sessionEngines.indexOf(engine); if (index >= 0) @@ -219,7 +219,7 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() */ QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration() { - foreach (QNetworkSessionEngine *engine, sessionEngines) { + foreach (QBearerEngine *engine, sessionEngines) { QNetworkConfigurationPrivatePointer ptr = engine->defaultConfiguration(); if (ptr) { diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index 4ef1f09..f6603ce 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_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) ** @@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE -class QNetworkSessionEngine; +class QBearerEngine; class QNetworkConfigurationManagerPrivate : public QObject { @@ -96,7 +96,7 @@ private: void abort(); public: - QList sessionEngines; + QList sessionEngines; private: QSet onlineConfigurations; diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp index c00921f..ba50ed6 100644 --- a/src/network/bearer/qnetworksession.cpp +++ b/src/network/bearer/qnetworksession.cpp @@ -43,7 +43,7 @@ #include #include "qnetworksession.h" -#include "qnetworksessionengine_p.h" +#include "qbearerengine_p.h" #include "qnetworkconfigmanager_p.h" #if Q_WS_MAEMO_6 @@ -228,7 +228,7 @@ QT_BEGIN_NAMESPACE QNetworkSession::QNetworkSession(const QNetworkConfiguration& connectionConfig, QObject* parent) : QObject(parent), d(0) { - foreach (QNetworkSessionEngine *engine, qNetworkConfigurationManagerPrivate()->sessionEngines) { + foreach (QBearerEngine *engine, qNetworkConfigurationManagerPrivate()->sessionEngines) { if (engine->hasIdentifier(connectionConfig.identifier())) { d = engine->createSessionBackend(); d->q = this; diff --git a/src/network/bearer/qnetworksessionengine.cpp b/src/network/bearer/qnetworksessionengine.cpp deleted file mode 100644 index 0744add..0000000 --- a/src/network/bearer/qnetworksessionengine.cpp +++ /dev/null @@ -1,74 +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 "qnetworksessionengine_p.h" - -QT_BEGIN_NAMESPACE - -QNetworkSessionEngine::QNetworkSessionEngine(QObject *parent) -: QObject(parent) -{ -} - -QNetworkSessionEngine::~QNetworkSessionEngine() -{ - foreach (const QString &oldIface, snapConfigurations.keys()) { - QNetworkConfigurationPrivatePointer priv = snapConfigurations.take(oldIface); - priv->isValid = false; - priv->id.clear(); - } - - foreach (const QString &oldIface, accessPointConfigurations.keys()) { - QNetworkConfigurationPrivatePointer priv = accessPointConfigurations.take(oldIface); - priv->isValid = false; - priv->id.clear(); - } - - foreach (const QString &oldIface, userChoiceConfigurations.keys()) { - QNetworkConfigurationPrivatePointer priv = userChoiceConfigurations.take(oldIface); - priv->isValid = false; - priv->id.clear(); - } -} - -#include "moc_qnetworksessionengine_p.cpp" -QT_END_NAMESPACE - diff --git a/src/network/bearer/qnetworksessionengine_p.h b/src/network/bearer/qnetworksessionengine_p.h deleted file mode 100644 index 39c3d17..0000000 --- a/src/network/bearer/qnetworksessionengine_p.h +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** -** -** 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. -** -** $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 QNETWORKSESSIONENGINE_P_H -#define QNETWORKSESSIONENGINE_P_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_p.h" -#include "qnetworksession.h" -#include "qnetworkconfigmanager.h" - -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QNetworkConfiguration; - -class Q_NETWORK_EXPORT QNetworkSessionEngine : public QObject -{ - Q_OBJECT - -public: - QNetworkSessionEngine(QObject *parent = 0); - virtual ~QNetworkSessionEngine(); - - virtual bool hasIdentifier(const QString &id) = 0; - - virtual void requestUpdate() = 0; - - virtual QNetworkConfigurationManager::Capabilities capabilities() const = 0; - - virtual QNetworkSessionPrivate *createSessionBackend() = 0; - - virtual QNetworkConfigurationPrivatePointer defaultConfiguration() = 0; - -public: - //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 accessPointConfigurations; - QHash snapConfigurations; - QHash userChoiceConfigurations; - -Q_SIGNALS: - void configurationAdded(QNetworkConfigurationPrivatePointer config); - void configurationRemoved(QNetworkConfigurationPrivatePointer config); - void configurationChanged(QNetworkConfigurationPrivatePointer config); - - void updateCompleted(); -}; - -typedef QNetworkSessionEngine QBearerEngine; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/bearer/corewlan/corewlan.pro b/src/plugins/bearer/corewlan/corewlan.pro index c59d602..50c72b2 100644 --- a/src/plugins/bearer/corewlan/corewlan.pro +++ b/src/plugins/bearer/corewlan/corewlan.pro @@ -13,7 +13,7 @@ contains(QT_CONFIG, corewlan) { HEADERS += qcorewlanengine.h \ ../qnetworksession_impl.h \ - ../qnetworksessionengine_impl.h + ../qbearerengine_impl.h SOURCES += main.cpp \ qcorewlanengine.mm \ diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.h b/src/plugins/bearer/corewlan/qcorewlanengine.h index 7199ace..54f2027 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.h +++ b/src/plugins/bearer/corewlan/qcorewlanengine.h @@ -42,7 +42,7 @@ #ifndef QCOREWLANENGINE_H #define QCOREWLANENGINE_H -#include "../qnetworksessionengine_impl.h" +#include "../qbearerengine_impl.h" #include #include @@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; -class QCoreWlanEngine : public QNetworkSessionEngineImpl +class QCoreWlanEngine : public QBearerEngineImpl { Q_OBJECT diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm index ca193ab..fff65e4 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.mm +++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm @@ -106,7 +106,7 @@ static QString qGetInterfaceType(const QString &interfaceString) } QCoreWlanEngine::QCoreWlanEngine(QObject *parent) -: QNetworkSessionEngineImpl(parent) +: QBearerEngineImpl(parent) { connect(&pollTimer, SIGNAL(timeout()), this, SLOT(doRequestUpdate())); pollTimer.setInterval(10000); diff --git a/src/plugins/bearer/generic/generic.pro b/src/plugins/bearer/generic/generic.pro index dbf96d1..1d141fd 100644 --- a/src/plugins/bearer/generic/generic.pro +++ b/src/plugins/bearer/generic/generic.pro @@ -5,7 +5,7 @@ QT += network HEADERS += qgenericengine.h \ ../qnetworksession_impl.h \ - ../qnetworksessionengine_impl.h \ + ../qbearerengine_impl.h \ ../platformdefs_win.h SOURCES += qgenericengine.cpp \ ../qnetworksession_impl.cpp \ diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp index dea820d..c6ab4df 100644 --- a/src/plugins/bearer/generic/qgenericengine.cpp +++ b/src/plugins/bearer/generic/qgenericengine.cpp @@ -141,7 +141,7 @@ static QString qGetInterfaceType(const QString &interface) } QGenericEngine::QGenericEngine(QObject *parent) -: QNetworkSessionEngineImpl(parent) +: QBearerEngineImpl(parent) { connect(&pollTimer, SIGNAL(timeout()), this, SLOT(doRequestUpdate())); pollTimer.setInterval(10000); diff --git a/src/plugins/bearer/generic/qgenericengine.h b/src/plugins/bearer/generic/qgenericengine.h index d755228..cd9a976 100644 --- a/src/plugins/bearer/generic/qgenericengine.h +++ b/src/plugins/bearer/generic/qgenericengine.h @@ -42,7 +42,7 @@ #ifndef QGENERICENGINE_H #define QGENERICENGINE_H -#include "../qnetworksessionengine_impl.h" +#include "../qbearerengine_impl.h" #include #include @@ -52,7 +52,7 @@ QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; class QNetworkSessionPrivate; -class QGenericEngine : public QNetworkSessionEngineImpl +class QGenericEngine : public QBearerEngineImpl { Q_OBJECT diff --git a/src/plugins/bearer/nativewifi/nativewifi.pro b/src/plugins/bearer/nativewifi/nativewifi.pro index 928d819..f277a04 100644 --- a/src/plugins/bearer/nativewifi/nativewifi.pro +++ b/src/plugins/bearer/nativewifi/nativewifi.pro @@ -6,7 +6,7 @@ QT += network HEADERS += qnativewifiengine.h \ platformdefs.h \ ../qnetworksession_impl.h \ - ../qnetworksessionengine_impl.h + ../qbearerengine_impl.h SOURCES += main.cpp \ qnativewifiengine.cpp \ diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp index 9f0d4c0..d88534b 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp @@ -77,7 +77,7 @@ void qNotificationCallback(WLAN_NOTIFICATION_DATA *data, QNativeWifiEngine *d) } QNativeWifiEngine::QNativeWifiEngine(QObject *parent) -: QNetworkSessionEngineImpl(parent), handle(0) +: QBearerEngineImpl(parent), handle(0) { DWORD clientVersion; diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.h b/src/plugins/bearer/nativewifi/qnativewifiengine.h index 41217e2..a9a9375 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.h +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.h @@ -53,7 +53,7 @@ // We mean it. // -#include "../qnetworksessionengine_impl.h" +#include "../qbearerengine_impl.h" #include @@ -62,7 +62,7 @@ QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; struct WLAN_NOTIFICATION_DATA; -class QNativeWifiEngine : public QNetworkSessionEngineImpl +class QNativeWifiEngine : public QBearerEngineImpl { Q_OBJECT diff --git a/src/plugins/bearer/networkmanager/networkmanager.pro b/src/plugins/bearer/networkmanager/networkmanager.pro index 6f271c6..5bac121 100644 --- a/src/plugins/bearer/networkmanager/networkmanager.pro +++ b/src/plugins/bearer/networkmanager/networkmanager.pro @@ -9,7 +9,7 @@ HEADERS += qnmdbushelper.h \ qnetworkmanagerservice.h \ qnetworkmanagerengine.h \ ../qnetworksession_impl.h \ - ../qnetworksessionengine_impl.h + ../qbearerengine_impl.h SOURCES += main.cpp \ qnmdbushelper.cpp \ diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp index 129f7d2..2c550f0 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp @@ -60,7 +60,7 @@ QT_BEGIN_NAMESPACE QNetworkManagerEngine::QNetworkManagerEngine(QObject *parent) -: QNetworkSessionEngineImpl(parent), +: QBearerEngineImpl(parent), interface(new QNetworkManagerInterface(this)), systemSettings(new QNetworkManagerSettings(NM_DBUS_SERVICE_SYSTEM_SETTINGS, this)), userSettings(new QNetworkManagerSettings(NM_DBUS_SERVICE_USER_SETTINGS, this)) diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h index f454628..848f166 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h @@ -53,7 +53,7 @@ // We mean it. // -#include "../qnetworksessionengine_impl.h" +#include "../qbearerengine_impl.h" #include "qnetworkmanagerservice.h" @@ -62,7 +62,7 @@ QT_BEGIN_NAMESPACE -class QNetworkManagerEngine : public QNetworkSessionEngineImpl +class QNetworkManagerEngine : public QBearerEngineImpl { Q_OBJECT diff --git a/src/plugins/bearer/nla/nla.pro b/src/plugins/bearer/nla/nla.pro index 4c5e492..5ba171e 100644 --- a/src/plugins/bearer/nla/nla.pro +++ b/src/plugins/bearer/nla/nla.pro @@ -12,7 +12,7 @@ QT += network HEADERS += qnlaengine.h \ ../platformdefs_win.h \ ../qnetworksession_impl.h \ - ../qnetworksessionengine_impl.h + ../qbeaerengine_impl.h SOURCES += main.cpp \ qnlaengine.cpp \ diff --git a/src/plugins/bearer/nla/qnlaengine.cpp b/src/plugins/bearer/nla/qnlaengine.cpp index ed802c0..fbfac17 100644 --- a/src/plugins/bearer/nla/qnlaengine.cpp +++ b/src/plugins/bearer/nla/qnlaengine.cpp @@ -506,7 +506,7 @@ void QNlaThread::fetchConfigurations() } QNlaEngine::QNlaEngine(QObject *parent) -: QNetworkSessionEngineImpl(parent), nlaThread(0) +: QBearerEngineImpl(parent), nlaThread(0) { nlaThread = new QNlaThread(this); connect(nlaThread, SIGNAL(networksChanged()), diff --git a/src/plugins/bearer/nla/qnlaengine.h b/src/plugins/bearer/nla/qnlaengine.h index fa010b9..14c5201 100644 --- a/src/plugins/bearer/nla/qnlaengine.h +++ b/src/plugins/bearer/nla/qnlaengine.h @@ -53,7 +53,7 @@ // We mean it. // -#include "../qnetworksessionengine_impl.h" +#include "../qbearerengine_impl.h" #include @@ -72,7 +72,7 @@ public: int version; }; -class QNlaEngine : public QNetworkSessionEngineImpl +class QNlaEngine : public QBearerEngineImpl { Q_OBJECT diff --git a/src/plugins/bearer/qbearerengine_impl.h b/src/plugins/bearer/qbearerengine_impl.h new file mode 100644 index 0000000..6fffe27 --- /dev/null +++ b/src/plugins/bearer/qbearerengine_impl.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** 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 QBEARERENGINE_IMPL_H +#define QBEARERENGINE_IMPL_H + +#include + +QT_BEGIN_NAMESPACE + +class QBearerEngineImpl : public QBearerEngine +{ + Q_OBJECT + +public: + enum ConnectionError { + InterfaceLookupError = 0, + ConnectError, + OperationNotSupported, + DisconnectionError, + }; + + QBearerEngineImpl(QObject *parent = 0) : QBearerEngine(parent) { } + ~QBearerEngineImpl() { } + + virtual void connectToId(const QString &id) = 0; + virtual void disconnectFromId(const QString &id) = 0; + + virtual QString getInterfaceFromId(const QString &id) = 0; + + virtual QNetworkSession::State sessionStateForId(const QString &id) = 0; + +Q_SIGNALS: + void connectionError(const QString &id, ConnectionError error); +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/bearer/qnetworksession_impl.cpp b/src/plugins/bearer/qnetworksession_impl.cpp index 6de3423..c823d89 100644 --- a/src/plugins/bearer/qnetworksession_impl.cpp +++ b/src/plugins/bearer/qnetworksession_impl.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ #include "qnetworksession_impl.h" -#include "qnetworksessionengine_impl.h" +#include "qbearerengine_impl.h" #include #include @@ -53,12 +53,12 @@ QT_BEGIN_NAMESPACE -static QNetworkSessionEngineImpl *getEngineFromId(const QString &id) +static QBearerEngineImpl *getEngineFromId(const QString &id) { QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); - foreach (QNetworkSessionEngine *engine, priv->sessionEngines) { - QNetworkSessionEngineImpl *engineImpl = qobject_cast(engine); + foreach (QBearerEngine *engine, priv->sessionEngines) { + QBearerEngineImpl *engineImpl = qobject_cast(engine); if (engineImpl && engineImpl->hasIdentifier(id)) return engineImpl; } @@ -111,16 +111,16 @@ void QNetworkSessionPrivateImpl::syncStateWithInterface() state = QNetworkSession::Invalid; lastError = QNetworkSession::UnknownSessionError; - qRegisterMetaType - ("QNetworkSessionEngineImpl::ConnectionError"); + qRegisterMetaType + ("QBearerEngineImpl::ConnectionError"); switch (publicConfig.type()) { case QNetworkConfiguration::InternetAccessPoint: activeConfig = publicConfig; engine = getEngineFromId(activeConfig.identifier()); if (engine) { - connect(engine, SIGNAL(connectionError(QString,QNetworkSessionEngine::ConnectionError)), - this, SLOT(connectionError(QString,QNetworkSessionEngine::ConnectionError)), + connect(engine, SIGNAL(connectionError(QString,QBearerEngine::ConnectionError)), + this, SLOT(connectionError(QString,QBearerEngine::ConnectionError)), Qt::QueuedConnection); } break; @@ -322,15 +322,15 @@ void QNetworkSessionPrivateImpl::updateStateFromServiceNetwork() if (activeConfig != config) { if (engine) { - disconnect(engine, SIGNAL(connectionError(QString,QNetworkSessionEngine::ConnectionError)), - this, SLOT(connectionError(QString,QNetworkSessionEngine::ConnectionError))); + disconnect(engine, SIGNAL(connectionError(QString,QBearerEngine::ConnectionError)), + this, SLOT(connectionError(QString,QBearerEngine::ConnectionError))); } activeConfig = config; engine = getEngineFromId(activeConfig.identifier()); if (engine) { - connect(engine, SIGNAL(connectionError(QString,QNetworkSessionEngine::ConnectionError)), - this, SLOT(connectionError(QString,QNetworkSessionEngine::ConnectionError)), + connect(engine, SIGNAL(connectionError(QString,QBearerEngine::ConnectionError)), + this, SLOT(connectionError(QString,QBearerEngine::ConnectionError)), Qt::QueuedConnection); } emit newConfigurationActivated(); @@ -408,18 +408,18 @@ void QNetworkSessionPrivateImpl::forcedSessionClose(const QNetworkConfiguration } void QNetworkSessionPrivateImpl::connectionError(const QString &id, - QNetworkSessionEngineImpl::ConnectionError error) + QBearerEngineImpl::ConnectionError error) { if (activeConfig.identifier() == id) { networkConfigurationsChanged(); switch (error) { - case QNetworkSessionEngineImpl::OperationNotSupported: + case QBearerEngineImpl::OperationNotSupported: lastError = QNetworkSession::OperationNotSupportedError; opened = false; break; - case QNetworkSessionEngineImpl::InterfaceLookupError: - case QNetworkSessionEngineImpl::ConnectError: - case QNetworkSessionEngineImpl::DisconnectionError: + case QBearerEngineImpl::InterfaceLookupError: + case QBearerEngineImpl::ConnectError: + case QBearerEngineImpl::DisconnectionError: default: lastError = QNetworkSession::UnknownSessionError; } diff --git a/src/plugins/bearer/qnetworksession_impl.h b/src/plugins/bearer/qnetworksession_impl.h index 1fd97d3..0126a99 100644 --- a/src/plugins/bearer/qnetworksession_impl.h +++ b/src/plugins/bearer/qnetworksession_impl.h @@ -53,7 +53,7 @@ // We mean it. // -#include "qnetworksessionengine_impl.h" +#include "qbearerengine_impl.h" #include #include @@ -62,7 +62,7 @@ QT_BEGIN_NAMESPACE -class QNetworkSessionEngineImpl; +class QBearerEngineImpl; class QNetworkSessionPrivateImpl : public QNetworkSessionPrivate { @@ -110,7 +110,7 @@ private Q_SLOTS: void networkConfigurationsChanged(); void configurationChanged(const QNetworkConfiguration &config); void forcedSessionClose(const QNetworkConfiguration &config); - void connectionError(const QString &id, QNetworkSessionEngineImpl::ConnectionError error); + void connectionError(const QString &id, QBearerEngineImpl::ConnectionError error); private: QNetworkConfigurationManager manager; @@ -121,7 +121,7 @@ private: bool opened; - QNetworkSessionEngineImpl *engine; + QBearerEngineImpl *engine; QNetworkSession::SessionError lastError; diff --git a/src/plugins/bearer/qnetworksessionengine_impl.h b/src/plugins/bearer/qnetworksessionengine_impl.h deleted file mode 100644 index 1294cc5..0000000 --- a/src/plugins/bearer/qnetworksessionengine_impl.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** 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 QNETWORKSESSIONENGINE_IMPL_H -#define QNETWORKSESSIONENGINE_IMPL_H - -#include - -QT_BEGIN_NAMESPACE - -class QNetworkSessionEngineImpl : public QNetworkSessionEngine -{ - Q_OBJECT - -public: - enum ConnectionError { - InterfaceLookupError = 0, - ConnectError, - OperationNotSupported, - DisconnectionError, - }; - - QNetworkSessionEngineImpl(QObject *parent = 0) : QNetworkSessionEngine(parent) { } - ~QNetworkSessionEngineImpl() { } - - virtual void connectToId(const QString &id) = 0; - virtual void disconnectFromId(const QString &id) = 0; - - virtual QString getInterfaceFromId(const QString &id) = 0; - - virtual QNetworkSession::State sessionStateForId(const QString &id) = 0; - -Q_SIGNALS: - void connectionError(const QString &id, ConnectionError error); -}; - -QT_END_NAMESPACE - -#endif // QNETWORKSESSIONENGINE_IMPL_H diff --git a/src/plugins/bearer/symbian/symbianengine.cpp b/src/plugins/bearer/symbian/symbianengine.cpp index 3d0ec0f..2d0b5ee 100644 --- a/src/plugins/bearer/symbian/symbianengine.cpp +++ b/src/plugins/bearer/symbian/symbianengine.cpp @@ -98,7 +98,7 @@ QString SymbianNetworkConfigurationPrivate::bearerName() const } SymbianEngine::SymbianEngine(QObject *parent) -: QNetworkSessionEngine(parent), CActive(CActive::EPriorityIdle), iInitOk(true) +: QBearerEngine(parent), CActive(CActive::EPriorityIdle), iInitOk(true) { CActiveScheduler::Add(this); diff --git a/src/plugins/bearer/symbian/symbianengine.h b/src/plugins/bearer/symbian/symbianengine.h index 4a4a8c1..587585b 100644 --- a/src/plugins/bearer/symbian/symbianengine.h +++ b/src/plugins/bearer/symbian/symbianengine.h @@ -42,7 +42,7 @@ #ifndef SYMBIANENGINE_H #define SYMBIANENGINE_H -#include +#include #include #include @@ -97,7 +97,7 @@ inline SymbianNetworkConfigurationPrivate *toSymbianConfig(QNetworkConfiguration return static_cast(ptr.data()); } -class SymbianEngine : public QNetworkSessionEngine, public CActive, +class SymbianEngine : public QBearerEngine, public CActive, public MConnectionMonitorObserver { Q_OBJECT -- cgit v0.12 From c470f8d1523ec974a7f0e1cb61ef13f0e953c500 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Fri, 5 Feb 2010 13:59:49 +1000 Subject: Fix Network Manager and CoreWlan config tests. --- config.tests/unix/networkmanager/main.cpp | 5 +++-- config.tests/unix/networkmanager/networkmanager.pro | 4 ---- configure | 4 +++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/config.tests/unix/networkmanager/main.cpp b/config.tests/unix/networkmanager/main.cpp index f8b3d3c..7b91ae0 100644 --- a/config.tests/unix/networkmanager/main.cpp +++ b/config.tests/unix/networkmanager/main.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) ** @@ -40,8 +40,9 @@ ****************************************************************************/ #if defined(QT_NO_DBUS) -sjkp //error is no QtDBus +#error Qt is not configured with DBus support. #endif + #include int main(int argc, char** argv) diff --git a/config.tests/unix/networkmanager/networkmanager.pro b/config.tests/unix/networkmanager/networkmanager.pro index 686286d..c41204f 100644 --- a/config.tests/unix/networkmanager/networkmanager.pro +++ b/config.tests/unix/networkmanager/networkmanager.pro @@ -1,7 +1,3 @@ SOURCES = main.cpp CONFIG -= qt dylib mac:CONFIG -= app_bundle - -!contains(QT_CONFIG,dbus): { - DEFINES += QT_NO_DBUS -} \ No newline at end of file diff --git a/configure b/configure index 13f58c8..a55e9ee 100755 --- a/configure +++ b/configure @@ -7587,7 +7587,9 @@ fi echo "OpenSSL support ........ $CFG_OPENSSL $OPENSSL_LINKAGE" echo "Alsa support ........... $CFG_ALSA" echo "NetworkManager support . $CFG_NETWORKMANAGER" -echo "CoreWlan support ....... $CFG_COREWLAN" +if [ "$PLATFORM_MAC" = "yes" ]; then + echo "CoreWlan support ....... $CFG_COREWLAN" +fi echo [ "$CFG_PTMALLOC" != "no" ] && echo "Use ptmalloc ........... $CFG_PTMALLOC" -- cgit v0.12 From 10628947d5ab1cfcd571ada10c0eab4b7f1f02ac Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 8 Feb 2010 10:16:34 +1000 Subject: Display session statistics. --- examples/network/bearermonitor/sessionwidget.cpp | 18 ++++++++- examples/network/bearermonitor/sessionwidget.h | 5 ++- examples/network/bearermonitor/sessionwidget.ui | 50 +++++++++++++++++++++++- 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/examples/network/bearermonitor/sessionwidget.cpp b/examples/network/bearermonitor/sessionwidget.cpp index d03c5bf..46ffb20 100644 --- a/examples/network/bearermonitor/sessionwidget.cpp +++ b/examples/network/bearermonitor/sessionwidget.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) ** @@ -43,7 +43,7 @@ #include "qnetworkconfigmanager.h" SessionWidget::SessionWidget(const QNetworkConfiguration &config, QWidget *parent) -: QWidget(parent) +: QWidget(parent), statsTimer(-1) { setupUi(this); @@ -75,11 +75,25 @@ SessionWidget::~SessionWidget() delete session; } +void SessionWidget::timerEvent(QTimerEvent *e) +{ + if (e->timerId() == statsTimer) { + rxData->setText(QString::number(session->bytesReceived())); + txData->setText(QString::number(session->bytesWritten())); + activeTime->setText(QString::number(session->activeTime())); + } +} + void SessionWidget::updateSession() { updateSessionState(session->state()); updateSessionError(session->error()); + if (session->state() == QNetworkSession::Connected) + statsTimer = startTimer(1000); + else + killTimer(statsTimer); + if (session->configuration().type() == QNetworkConfiguration::InternetAccessPoint) bearer->setText(session->configuration().bearerName()); else { diff --git a/examples/network/bearermonitor/sessionwidget.h b/examples/network/bearermonitor/sessionwidget.h index 868de3a..cc9c067 100644 --- a/examples/network/bearermonitor/sessionwidget.h +++ b/examples/network/bearermonitor/sessionwidget.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) ** @@ -56,6 +56,8 @@ public: SessionWidget(const QNetworkConfiguration &config, QWidget *parent = 0); ~SessionWidget(); + void timerEvent(QTimerEvent *); + private: void updateSessionState(QNetworkSession::State state); void updateSessionError(QNetworkSession::SessionError error); @@ -69,6 +71,7 @@ private Q_SLOTS: private: QNetworkSession *session; + int statsTimer; }; #endif diff --git a/examples/network/bearermonitor/sessionwidget.ui b/examples/network/bearermonitor/sessionwidget.ui index 65ca43b..45135f5 100644 --- a/examples/network/bearermonitor/sessionwidget.ui +++ b/examples/network/bearermonitor/sessionwidget.ui @@ -7,7 +7,7 @@ 0 0 340 - 286 + 276 @@ -215,6 +215,54 @@ + + + + + 0 + + + Qt::AlignCenter + + + + + + + 0 + + + Qt::AlignCenter + + + + + + + + + + + Active Time: + + + + + + + + 0 + 0 + + + + 0 seconds + + + + + + -- cgit v0.12 From 5096692696b18df82914fc1f63597e00c24fa5d2 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 8 Feb 2010 10:45:09 +1000 Subject: Remove remaining Network Manager ifdef'ed code from common code. --- src/network/bearer/bearer.pri | 2 - .../bearer/networkmanager/networkmanager.pro | 2 - .../networkmanager/qnetworkmanagerengine.cpp | 61 +++++++++++++ .../bearer/networkmanager/qnetworkmanagerengine.h | 4 + src/plugins/bearer/qbearerengine_impl.h | 4 + src/plugins/bearer/qnetworksession_impl.cpp | 100 +++------------------ src/plugins/bearer/qnetworksession_impl.h | 13 +-- 7 files changed, 86 insertions(+), 100 deletions(-) diff --git a/src/network/bearer/bearer.pri b/src/network/bearer/bearer.pri index 14e7c0c..7dc9195 100644 --- a/src/network/bearer/bearer.pri +++ b/src/network/bearer/bearer.pri @@ -46,7 +46,5 @@ maemo { SOURCES += bearer/qnetworkconfigmanager_p.cpp \ bearer/qbearerengine.cpp \ bearer/qbearerplugin.cpp - - contains(QT_CONFIG, networkmanager):DEFINES += BACKEND_NM } diff --git a/src/plugins/bearer/networkmanager/networkmanager.pro b/src/plugins/bearer/networkmanager/networkmanager.pro index 5bac121..bf0d29a 100644 --- a/src/plugins/bearer/networkmanager/networkmanager.pro +++ b/src/plugins/bearer/networkmanager/networkmanager.pro @@ -3,8 +3,6 @@ include(../../qpluginbase.pri) QT += network dbus -DEFINES += BACKEND_NM - HEADERS += qnmdbushelper.h \ qnetworkmanagerservice.h \ qnetworkmanagerengine.h \ diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp index 2c550f0..9a9bdad 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp @@ -680,6 +680,67 @@ QNetworkSession::State QNetworkManagerEngine::sessionStateForId(const QString &i return QNetworkSession::Invalid; } +quint64 QNetworkManagerEngine::bytesWritten(const QString &id) +{ + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + if (ptr && (ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + const QString networkInterface = getInterfaceFromId(id); + if (!networkInterface.isEmpty()) { + const QString devFile = QLatin1String("/sys/class/net/") + + networkInterface + + QLatin1String("/statistics/tx_bytes"); + + quint64 result = Q_UINT64_C(0); + + QFile tx(devFile); + if (tx.exists() && tx.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream in(&tx); + in >> result; + tx.close(); + } + + return result; + } + } + + return Q_UINT64_C(0); +} + +quint64 QNetworkManagerEngine::bytesReceived(const QString &id) +{ + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + if (ptr && (ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + const QString networkInterface = getInterfaceFromId(id); + if (!networkInterface.isEmpty()) { + const QString devFile = QLatin1String("/sys/class/net/") + + networkInterface + + QLatin1String("/statistics/rx_bytes"); + + quint64 result = Q_UINT64_C(0); + + QFile tx(devFile); + if (tx.exists() && tx.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream in(&tx); + in >> result; + tx.close(); + } + + return result; + } + } + + return Q_UINT64_C(0); +} + +quint64 QNetworkManagerEngine::startTime(const QString &id) +{ + QNetworkManagerSettingsConnection *connection = connectionFromId(id); + if (connection) + return connection->getTimestamp(); + else + return Q_UINT64_C(0); +} + QNetworkConfigurationManager::Capabilities QNetworkManagerEngine::capabilities() const { return QNetworkConfigurationManager::ForcedRoaming | diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h index 848f166..70efc05 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h @@ -82,6 +82,10 @@ public: QNetworkSession::State sessionStateForId(const QString &id); + quint64 bytesWritten(const QString &id); + quint64 bytesReceived(const QString &id); + quint64 startTime(const QString &id); + QNetworkConfigurationManager::Capabilities capabilities() const; QNetworkSessionPrivate *createSessionBackend(); diff --git a/src/plugins/bearer/qbearerengine_impl.h b/src/plugins/bearer/qbearerengine_impl.h index 6fffe27..3772639 100644 --- a/src/plugins/bearer/qbearerengine_impl.h +++ b/src/plugins/bearer/qbearerengine_impl.h @@ -68,6 +68,10 @@ public: virtual QNetworkSession::State sessionStateForId(const QString &id) = 0; + virtual quint64 bytesWritten(const QString &) { return Q_UINT64_C(0); } + virtual quint64 bytesReceived(const QString &) { return Q_UINT64_C(0); } + virtual quint64 startTime(const QString &) { return Q_UINT64_C(0); } + Q_SIGNALS: void connectionError(const QString &id, ConnectionError error); }; diff --git a/src/plugins/bearer/qnetworksession_impl.cpp b/src/plugins/bearer/qnetworksession_impl.cpp index c823d89..8f95e77 100644 --- a/src/plugins/bearer/qnetworksession_impl.cpp +++ b/src/plugins/bearer/qnetworksession_impl.cpp @@ -266,50 +266,26 @@ QNetworkSession::SessionError QNetworkSessionPrivateImpl::error() const quint64 QNetworkSessionPrivateImpl::bytesWritten() const { -#if defined(BACKEND_NM) && 0 - if( NetworkManagerAvailable() && state == QNetworkSession::Connected ) { - if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { - foreach (const QNetworkConfiguration &config, publicConfig.children()) { - if ((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { - return static_cast(getEngineFromId(config.d->id))->sentDataForId(config.d->id); - } - } - } else { - return static_cast(getEngineFromId(activeConfig.d->id))->sentDataForId(activeConfig.d->id); - } - } -#endif - return tx_data; + if (engine && state == QNetworkSession::Connected) + return engine->bytesWritten(activeConfig.identifier()); + else + return Q_UINT64_C(0); } quint64 QNetworkSessionPrivateImpl::bytesReceived() const { -#if defined(BACKEND_NM) && 0 - if( NetworkManagerAvailable() && state == QNetworkSession::Connected ) { - if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { - foreach (const QNetworkConfiguration &config, publicConfig.children()) { - if ((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { - return static_cast(getEngineFromId(activeConfig.d->id))->receivedDataForId(config.d->id); - } - } - } else { - return static_cast(getEngineFromId(activeConfig.d->id))->receivedDataForId(activeConfig.d->id); - } - } -#endif - return rx_data; + if (engine && state == QNetworkSession::Connected) + return engine->bytesReceived(activeConfig.identifier()); + else + return Q_UINT64_C(0); } quint64 QNetworkSessionPrivateImpl::activeTime() const { -#if defined(BACKEND_NM) - if (startTime.isNull()) { - return 0; - } - if(state == QNetworkSession::Connected ) - return startTime.secsTo(QDateTime::currentDateTime()); -#endif - return m_activeTime; + if (state == QNetworkSession::Connected && startTime != Q_UINT64_C(0)) + return QDateTime::currentDateTime().toTime_t() - startTime; + else + return Q_UINT64_C(0); } void QNetworkSessionPrivateImpl::updateStateFromServiceNetwork() @@ -381,9 +357,8 @@ void QNetworkSessionPrivateImpl::networkConfigurationsChanged() updateStateFromServiceNetwork(); else updateStateFromActiveConfig(); -#if defined(BACKEND_NM) && 0 - setActiveTimeStamp(); -#endif + + startTime = engine->startTime(activeConfig.identifier()); } void QNetworkSessionPrivateImpl::configurationChanged(const QNetworkConfiguration &config) @@ -429,51 +404,4 @@ void QNetworkSessionPrivateImpl::connectionError(const QString &id, } } -#if defined(BACKEND_NM) && 0 -void QNetworkSessionPrivateImpl::setActiveTimeStamp() -{ - if(NetworkManagerAvailable()) { - startTime = QDateTime(); - return; - } - QString connectionIdent = q->configuration().identifier(); - QString interface = currentInterface().hardwareAddress().toLower(); - QString devicePath = "/org/freedesktop/Hal/devices/net_" + interface.replace(":","_"); - - QString path; - QString serviceName; - QNetworkManagerInterface * ifaceD; - ifaceD = new QNetworkManagerInterface(); - - QList connections = ifaceD->activeConnections(); - foreach(QDBusObjectPath conpath, connections) { - QNetworkManagerConnectionActive *conDetails; - conDetails = new QNetworkManagerConnectionActive(conpath.path()); - QDBusObjectPath connection = conDetails->connection(); - serviceName = conDetails->serviceName(); - QList so = conDetails->devices(); - foreach(QDBusObjectPath device, so) { - - if(device.path() == devicePath) { - path = connection.path(); - } - break; - } - } -if(serviceName.isEmpty()) - return; - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(serviceName); - QList list = settingsiface->listConnections(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerSettingsConnection *sysIface; - sysIface = new QNetworkManagerSettingsConnection(serviceName, path.path()); - startTime = QDateTime::fromTime_t(sysIface->getTimestamp()); - // isOpen = (publicConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active; - } - if(startTime.isNull()) - startTime = QDateTime::currentDateTime(); -} -#endif - QT_END_NAMESPACE diff --git a/src/plugins/bearer/qnetworksession_impl.h b/src/plugins/bearer/qnetworksession_impl.h index 0126a99..7349e77 100644 --- a/src/plugins/bearer/qnetworksession_impl.h +++ b/src/plugins/bearer/qnetworksession_impl.h @@ -68,8 +68,8 @@ class QNetworkSessionPrivateImpl : public QNetworkSessionPrivate { Q_OBJECT public: - QNetworkSessionPrivateImpl() : - tx_data(0), rx_data(0), m_activeTime(0) + QNetworkSessionPrivateImpl() + : startTime(0) { } @@ -115,20 +115,13 @@ private Q_SLOTS: private: QNetworkConfigurationManager manager; - quint64 tx_data; - quint64 rx_data; - quint64 m_activeTime; - bool opened; QBearerEngineImpl *engine; QNetworkSession::SessionError lastError; -#if defined(BACKEND_NM) - QDateTime startTime; - void setActiveTimeStamp(); -#endif + quint64 startTime; }; QT_END_NAMESPACE -- cgit v0.12 From 992af6c30d5e1216bf7a6db2521c16f0b508e396 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 8 Feb 2010 10:50:14 +1000 Subject: Missed this in a previous commit. --- src/plugins/bearer/qbearerengine_impl.h | 2 +- src/plugins/bearer/qnetworksession_impl.cpp | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/plugins/bearer/qbearerengine_impl.h b/src/plugins/bearer/qbearerengine_impl.h index 3772639..740def3 100644 --- a/src/plugins/bearer/qbearerengine_impl.h +++ b/src/plugins/bearer/qbearerengine_impl.h @@ -73,7 +73,7 @@ public: virtual quint64 startTime(const QString &) { return Q_UINT64_C(0); } Q_SIGNALS: - void connectionError(const QString &id, ConnectionError error); + void connectionError(const QString &id, QBearerEngineImpl::ConnectionError error); }; QT_END_NAMESPACE diff --git a/src/plugins/bearer/qnetworksession_impl.cpp b/src/plugins/bearer/qnetworksession_impl.cpp index 8f95e77..de1c91a 100644 --- a/src/plugins/bearer/qnetworksession_impl.cpp +++ b/src/plugins/bearer/qnetworksession_impl.cpp @@ -119,8 +119,8 @@ void QNetworkSessionPrivateImpl::syncStateWithInterface() activeConfig = publicConfig; engine = getEngineFromId(activeConfig.identifier()); if (engine) { - connect(engine, SIGNAL(connectionError(QString,QBearerEngine::ConnectionError)), - this, SLOT(connectionError(QString,QBearerEngine::ConnectionError)), + connect(engine, SIGNAL(connectionError(QString,QBearerEngineImpl::ConnectionError)), + this, SLOT(connectionError(QString,QBearerEngineImpl::ConnectionError)), Qt::QueuedConnection); } break; @@ -298,15 +298,18 @@ void QNetworkSessionPrivateImpl::updateStateFromServiceNetwork() if (activeConfig != config) { if (engine) { - disconnect(engine, SIGNAL(connectionError(QString,QBearerEngine::ConnectionError)), - this, SLOT(connectionError(QString,QBearerEngine::ConnectionError))); + disconnect(engine, + SIGNAL(connectionError(QString,QBearerEngineImpl::ConnectionError)), + this, + SLOT(connectionError(QString,QBearerEngineImpl::ConnectionError))); } activeConfig = config; engine = getEngineFromId(activeConfig.identifier()); if (engine) { - connect(engine, SIGNAL(connectionError(QString,QBearerEngine::ConnectionError)), - this, SLOT(connectionError(QString,QBearerEngine::ConnectionError)), + connect(engine, + SIGNAL(connectionError(QString,QBearerEngineImpl::ConnectionError)), + this, SLOT(connectionError(QString,QBearerEngineImpl::ConnectionError)), Qt::QueuedConnection); } emit newConfigurationActivated(); -- cgit v0.12 From 8df1491dfb261ab41f9f360af8e23fd283ad1ca5 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 8 Feb 2010 11:04:00 +1000 Subject: Calculate default configuration if one is not provided by engines. --- src/network/bearer/qnetworkconfigmanager_p.cpp | 62 +++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index a94fd2f..9ebb0b3 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -173,6 +173,8 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() QFactoryLoader *l = loader(); + QBearerEngine *generic = 0; + foreach (const QString &key, l->keys()) { QBearerEnginePlugin *plugin = qobject_cast(l->instance(key)); if (plugin) { @@ -180,7 +182,11 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() if (!engine) continue; - sessionEngines.append(engine); + if (key == QLatin1String("generic")) + generic = engine; + else + sessionEngines.append(engine); + connect(engine, SIGNAL(updateCompleted()), this, SLOT(updateConfigurations())); connect(engine, SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), @@ -193,6 +199,8 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() capFlags |= engine->capabilities(); } } + + sessionEngines.append(generic); } QBearerEngine *engine = qobject_cast(sender()); @@ -229,6 +237,58 @@ QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration( } } + // Engines don't have a default configuration. + + // Return first active snap + QNetworkConfigurationPrivatePointer firstDiscovered; + + foreach (QBearerEngine *engine, sessionEngines) { + foreach (const QString &id, engine->snapConfigurations.keys()) { + QNetworkConfigurationPrivatePointer ptr = engine->snapConfigurations.value(id); + + if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + QNetworkConfiguration config; + config.d = ptr; + return config; + } else if ((ptr->state & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + firstDiscovered = ptr; + } + } + } + + // No Active SNAPs return first Discovered SNAP. + if (firstDiscovered) { + QNetworkConfiguration config; + config.d = firstDiscovered; + return config; + } + + // No Active or Discovered SNAPs, do same for InternetAccessPoints. + firstDiscovered.reset(); + + foreach (QBearerEngine *engine, sessionEngines) { + foreach (const QString &id, engine->accessPointConfigurations.keys()) { + QNetworkConfigurationPrivatePointer ptr = engine->accessPointConfigurations.value(id); + + if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + QNetworkConfiguration config; + config.d = ptr; + return config; + } else if ((ptr->state & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + firstDiscovered = ptr; + } + } + } + + // No Active InternetAccessPoint return first Discovered InternetAccessPoint. + if (firstDiscovered) { + QNetworkConfiguration config; + config.d = firstDiscovered; + return config; + } + return QNetworkConfiguration(); } -- cgit v0.12 From 76160422d532b2ccf63a5c477f74a6645428c0f7 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 8 Feb 2010 12:51:27 +1000 Subject: Emit signals when access points appear & disappear. --- .../networkmanager/qnetworkmanagerengine.cpp | 66 +++++++++++++++++----- 1 file changed, 51 insertions(+), 15 deletions(-) diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp index 9a9bdad..51afe3e 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp @@ -499,19 +499,21 @@ void QNetworkManagerEngine::newAccessPoint(const QString &path, const QDBusObjec } // Check if configuration exists for connection. - for (int i = 0; i < connections.count(); ++i) { - QNetworkManagerSettingsConnection *connection = connections.at(i); + if (!accessPoint->ssid().isEmpty()) { + for (int i = 0; i < connections.count(); ++i) { + QNetworkManagerSettingsConnection *connection = connections.at(i); - if (accessPoint->ssid() == connection->getSsid()) { - const QString service = connection->connectionInterface()->service(); - const QString settingsPath = connection->connectionInterface()->path(); - const QString connectionId = QString::number(qHash(service + ' ' + settingsPath)); + if (accessPoint->ssid() == connection->getSsid()) { + const QString service = connection->connectionInterface()->service(); + const QString settingsPath = connection->connectionInterface()->path(); + const QString connectionId = QString::number(qHash(service + ' ' + settingsPath)); - QNetworkConfigurationPrivatePointer ptr = - accessPointConfigurations.value(connectionId); - ptr->state = QNetworkConfiguration::Discovered; - emit configurationChanged(ptr); - return; + QNetworkConfigurationPrivatePointer ptr = + accessPointConfigurations.value(connectionId); + ptr->state = QNetworkConfiguration::Discovered; + emit configurationChanged(ptr); + return; + } } } @@ -544,12 +546,32 @@ void QNetworkManagerEngine::removeAccessPoint(const QString &path, if (configuredAccessPoints.contains(accessPoint)) { // find connection and change state to Defined configuredAccessPoints.removeOne(accessPoint); - qDebug() << "At least one connection is no longer discovered."; + for (int i = 0; i < connections.count(); ++i) { + QNetworkManagerSettingsConnection *connection = connections.at(i); + + if (accessPoint->ssid() == connection->getSsid()) { + const QString service = connection->connectionInterface()->service(); + const QString settingsPath = connection->connectionInterface()->path(); + const QString connectionId = + QString::number(qHash(service + ' ' + settingsPath)); + + QNetworkConfigurationPrivatePointer ptr = + accessPointConfigurations.value(connectionId); + ptr->state = QNetworkConfiguration::Defined; + emit configurationChanged(ptr); + return; + } + } } else { - // emit configurationRemoved(cpPriv); - qDebug() << "An unconfigured wifi access point was removed."; + QNetworkConfigurationPrivatePointer ptr = + accessPointConfigurations.take(QString::number(qHash(objectPath.path()))); + + if (ptr) + emit configurationRemoved(ptr); } + delete accessPoint; + break; } } @@ -564,7 +586,21 @@ void QNetworkManagerEngine::updateAccessPoint(const QMap &map if (!accessPoint) return; - qDebug() << "update access point" << accessPoint; + for (int i = 0; i < connections.count(); ++i) { + QNetworkManagerSettingsConnection *connection = connections.at(i); + + if (accessPoint->ssid() == connection->getSsid()) { + const QString service = connection->connectionInterface()->service(); + const QString settingsPath = connection->connectionInterface()->path(); + const QString connectionId = QString::number(qHash(service + ' ' + settingsPath)); + + QNetworkConfigurationPrivatePointer ptr = + accessPointConfigurations.value(connectionId); + ptr->state = QNetworkConfiguration::Discovered; + emit configurationChanged(ptr); + return; + } + } } QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QString &service, -- cgit v0.12 From 2963cb346814d47fd59e04bfd9bcd5fde88d5bd8 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 8 Feb 2010 17:29:45 +1000 Subject: Only add generic engine when it is available. --- src/network/bearer/qnetworkconfigmanager_p.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 9ebb0b3..a624376 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -200,7 +200,8 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() } } - sessionEngines.append(generic); + if (generic) + sessionEngines.append(generic); } QBearerEngine *engine = qobject_cast(sender()); -- cgit v0.12 From c6157559204b61b11537ab0c0aba16eb182b09fe Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 8 Feb 2010 17:37:48 +1000 Subject: Automatically migrate in-progress transfers after roaming. Automatically migrate in-progress transfers after roaming to a new access point for backends that support it. Currently only works for http transfers that do not upload data (i.e. HTTP GET). --- src/network/access/qnetworkaccessmanager.cpp | 35 +++----------------------- src/network/access/qnetworkaccessmanager_p.h | 4 +-- src/network/access/qnetworkreplyimpl.cpp | 37 +++++++++++++++++++--------- src/network/access/qnetworkreplyimpl_p.h | 2 +- 4 files changed, 31 insertions(+), 47 deletions(-) diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 617e398..8df580d 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -802,27 +802,6 @@ void QNetworkAccessManagerPrivate::_q_replyFinished() QNetworkReply *reply = qobject_cast(q->sender()); if (reply) emit q->finished(reply); - - if (session && deferredMigration) { - foreach (QObject *child, q->children()) { - if (child == reply) - continue; - - QNetworkReplyImpl *replyImpl = qobject_cast(child); - if (!replyImpl) - continue; - - QNetworkReplyImplPrivate::State state = replyImpl->d_func()->state; - if (state == QNetworkReplyImplPrivate::Buffering || - state == QNetworkReplyImplPrivate::Working) { - return; - } - } - - deferredMigration = false; - qDebug() << "Migrating as there are no pending replies."; - session->migrate(); - } } void QNetworkAccessManagerPrivate::_q_replySslErrors(const QList &errors) @@ -1136,6 +1115,7 @@ void QNetworkAccessManagerPrivate::_q_sessionNewConfigurationActivated() { Q_Q(QNetworkAccessManager); +#if 0 foreach (QObject *child, q->children()) { QNetworkReplyImpl *reply = qobject_cast(child); if (reply) { @@ -1151,6 +1131,7 @@ void QNetworkAccessManagerPrivate::_q_sessionNewConfigurationActivated() } } } +#endif qDebug() << "Accepting new configuration."; session->accept(); @@ -1183,18 +1164,10 @@ void QNetworkAccessManagerPrivate::_q_sessionPreferredConfigurationChanged(const foreach (QObject *child, q->children()) { QNetworkReplyImpl *replyImpl = qobject_cast(child); - if (replyImpl) { - QNetworkReplyImplPrivate::State state = replyImpl->d_func()->state; - if (state == QNetworkReplyImplPrivate::Buffering || - state == QNetworkReplyImplPrivate::Working) { - deferredMigration = true; - return; - } - } + if (replyImpl) + replyImpl->migrateBackend(); } - deferredMigration = false; - qDebug() << "Migrating as there are no pending replies."; session->migrate(); } diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h index 92b2782..e916158 100644 --- a/src/network/access/qnetworkaccessmanager_p.h +++ b/src/network/access/qnetworkaccessmanager_p.h @@ -76,8 +76,7 @@ public: proxyFactory(0), #endif cookieJarCreated(false), - session(0), - deferredMigration(false) + session(0) { } ~QNetworkAccessManagerPrivate(); @@ -131,7 +130,6 @@ public: bool cookieJarCreated; QNetworkSession *session; - bool deferredMigration; // this cache can be used by individual backends to cache e.g. their TCP connections to a server // and use the connections for multiple requests. diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index 0c7aca8..9721e32 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -477,6 +477,17 @@ void QNetworkReplyImplPrivate::appendDownstreamData(QByteDataBuffer &data) QPointer qq = q; QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); + if (totalSize.isNull()) { + RawHeadersList::ConstIterator it = findRawHeader("Content-Range"); + if (it != rawHeaders.constEnd()) { + int index = it->second.lastIndexOf('/'); + if (index != -1) + totalSize = it->second.mid(index + 1).toLongLong() - preMigrationDownloaded; + } else { + qDebug() << "Could not find Content-Length or Content-Range header"; + } + } + if (preMigrationDownloaded != Q_INT64_C(-1)) totalSize = totalSize.toLongLong() + preMigrationDownloaded; pauseNotificationHandling(); @@ -520,7 +531,8 @@ void QNetworkReplyImplPrivate::appendDownstreamData(QIODevice *data) void QNetworkReplyImplPrivate::finished() { Q_Q(QNetworkReplyImpl); - if (state == Finished || state == Aborted) + + if (state == Finished || state == Aborted || state == WaitingForSession) return; pauseNotificationHandling(); @@ -540,11 +552,10 @@ void QNetworkReplyImplPrivate::finished() } else { qDebug() << "Download hasn't finished"; - if (q->bytesAvailable() == bytesDownloaded) { - qDebug() << "User hasn't read data from reply, we could continue after reconnect."; - error(QNetworkReply::TemporaryNetworkFailureError, q->tr("Temporary network failure.")); - } else if (q->bytesAvailable() < bytesDownloaded) { - qDebug() << "User has already read data from reply."; + if (migrateBackend()) { + return; + } else { + qDebug() << "Could not migrate backend, application needs to send another requeset."; error(QNetworkReply::TemporaryNetworkFailureError, q->tr("Temporary network failure.")); } } @@ -781,24 +792,24 @@ void QNetworkReplyImpl::migrateBackend() d->migrateBackend(); } -void QNetworkReplyImplPrivate::migrateBackend() +bool QNetworkReplyImplPrivate::migrateBackend() { Q_Q(QNetworkReplyImpl); if (state == QNetworkReplyImplPrivate::Finished || state == QNetworkReplyImplPrivate::Aborted) { qDebug() << "Network reply is already finished/aborted."; - return; + return false; } if (!qobject_cast(backend)) { qDebug() << "Resume only support by http backend, not migrating."; - return; + return false; } if (outgoingData) { qDebug() << "Request has outgoing data, not migrating."; - return; + return false; } qDebug() << "Need to check for only cacheable content."; @@ -812,14 +823,14 @@ void QNetworkReplyImplPrivate::migrateBackend() state = QNetworkReplyImplPrivate::Reconnecting; if (backend) { - backend->deleteLater(); + delete backend; backend = 0; } RawHeadersList::ConstIterator it = findRawHeader("Accept-Ranges"); if (it == rawHeaders.constEnd() || it->second == "none") { qDebug() << "Range header not supported by server/resource."; - qFatal("Should fail with TemporaryNetworkFailure."); + return false; } cookedHeaders.clear(); @@ -841,6 +852,8 @@ void QNetworkReplyImplPrivate::migrateBackend() } else { QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); } + + return true; } QT_END_NAMESPACE diff --git a/src/network/access/qnetworkreplyimpl_p.h b/src/network/access/qnetworkreplyimpl_p.h index ac82ca0..89b976f 100644 --- a/src/network/access/qnetworkreplyimpl_p.h +++ b/src/network/access/qnetworkreplyimpl_p.h @@ -165,7 +165,7 @@ public: QIODevice *copyDevice; QAbstractNetworkCache *networkCache() const; - void migrateBackend(); + bool migrateBackend(); bool cacheEnabled; QIODevice *cacheSaveDevice; -- cgit v0.12 From 21abc34acdfa4a675b9c9ff5294726faf0d4c00e Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 9 Feb 2010 12:06:28 +1000 Subject: Add networkAccess property to QNAM. Enables network access via QNAM to be enabled/disabled. --- src/network/access/qnetworkaccessmanager.cpp | 84 ++++++++++++++++++++++++++++ src/network/access/qnetworkaccessmanager.h | 8 +++ src/network/access/qnetworkaccessmanager_p.h | 4 +- 3 files changed, 95 insertions(+), 1 deletion(-) diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 8df580d..7f36570 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -57,6 +57,7 @@ #include "QtCore/qbuffer.h" #include "QtCore/qurl.h" #include "QtCore/qvector.h" +#include "QtCore/qcoreapplication.h" #include "QtNetwork/qauthenticator.h" #include "QtNetwork/qsslconfiguration.h" #include "QtNetwork/qnetworkconfigmanager.h" @@ -162,6 +163,29 @@ static void ensureInitialized() */ /*! + \property QNetworkAccessManager::networkAccess + \brief wheather network access is enabled or disabled through this network access manager. + \since 4.7 + + Network access is enabled by default. + + When network access is disabled the network access manager will not process any new network + requests, all such requests will fail with an error. Requests with URLs with the file:// scheme + will still be processed. + + This property can be used to enable and disable network access for all clients of a single + network access manager instance. +*/ + +/*! + \fn void QNetworkAccessManager::networkAccessChanged(bool enabled) + + This signal is emitted when the value of the \l networkAccess property changes. If \a enabled + is true new requests that access the network will be processed; otherwise new network requests + that require network access will fail with an error. +*/ + +/*! \fn void QNetworkAccessManager::proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator) This signal is emitted whenever a proxy requests authentication @@ -719,6 +743,63 @@ QNetworkConfiguration QNetworkAccessManager::activeConfiguration() const } } +void QNetworkAccessManager::setNetworkAccessEnabled(bool enabled) +{ + Q_D(QNetworkAccessManager); + + if (d->networkAccessEnabled != enabled) { + d->networkAccessEnabled = enabled; + emit networkAccessChanged(enabled); + } +} + +bool QNetworkAccessManager::networkAccessEnabled() const +{ + Q_D(const QNetworkAccessManager); + + return d->networkAccessEnabled; +} + +class QDisabledNetworkReply : public QNetworkReply +{ + Q_OBJECT + +public: + QDisabledNetworkReply(QObject *parent, const QNetworkRequest &req, + const QNetworkAccessManager::Operation op); + ~QDisabledNetworkReply(); + + void abort() { } +protected: + qint64 readData(char *, qint64) { return 0; } +}; + +QDisabledNetworkReply::QDisabledNetworkReply(QObject *parent, + const QNetworkRequest &req, + QNetworkAccessManager::Operation op) +: QNetworkReply(parent) +{ + setRequest(req); + setUrl(req.url()); + setOperation(op); + + qRegisterMetaType("QNetworkReply::NetworkError"); + + QString msg = QCoreApplication::translate("QNetworkAccessManager", + "Network access is disabled."); + setError(UnknownNetworkError, msg); + + QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, + Q_ARG(QNetworkReply::NetworkError, UnknownNetworkError)); + QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); +} + +QDisabledNetworkReply::~QDisabledNetworkReply() +{ +} + +#include "qnetworkaccessmanager.moc" + /*! Returns a new QNetworkReply object to handle the operation \a op and request \a req. The device \a outgoingData is always 0 for Get and @@ -748,6 +829,9 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera return new QFileNetworkReply(this, req, op); } + if (!d->networkAccessEnabled) + return new QDisabledNetworkReply(this, req, op); + QNetworkRequest request = req; if (!request.header(QNetworkRequest::ContentLengthHeader).isValid() && outgoingData && !outgoingData->isSequential()) { diff --git a/src/network/access/qnetworkaccessmanager.h b/src/network/access/qnetworkaccessmanager.h index 14aaf78..371f729 100644 --- a/src/network/access/qnetworkaccessmanager.h +++ b/src/network/access/qnetworkaccessmanager.h @@ -69,6 +69,9 @@ class QNetworkAccessManagerPrivate; class Q_NETWORK_EXPORT QNetworkAccessManager: public QObject { Q_OBJECT + + Q_PROPERTY(bool networkAccess READ networkAccessEnabled WRITE setNetworkAccessEnabled NOTIFY networkAccessChanged) + public: enum Operation { HeadOperation = 1, @@ -108,6 +111,9 @@ public: QNetworkConfiguration configuration() const; QNetworkConfiguration activeConfiguration() const; + void setNetworkAccessEnabled(bool enabled); + bool networkAccessEnabled() const; + Q_SIGNALS: #ifndef QT_NO_NETWORKPROXY void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator); @@ -118,6 +124,8 @@ Q_SIGNALS: void sslErrors(QNetworkReply *reply, const QList &errors); #endif + void networkAccessChanged(bool enabled); + void debugMessage(const QString &message); protected: diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h index e916158..eae08e8 100644 --- a/src/network/access/qnetworkaccessmanager_p.h +++ b/src/network/access/qnetworkaccessmanager_p.h @@ -76,7 +76,8 @@ public: proxyFactory(0), #endif cookieJarCreated(false), - session(0) + session(0), + networkAccessEnabled(true) { } ~QNetworkAccessManagerPrivate(); @@ -130,6 +131,7 @@ public: bool cookieJarCreated; QNetworkSession *session; + bool networkAccessEnabled; // this cache can be used by individual backends to cache e.g. their TCP connections to a server // and use the connections for multiple requests. -- cgit v0.12 From d792ec16f29a7cb34bada871127f701ba9480100 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Wed, 10 Feb 2010 15:08:29 +1000 Subject: Convert Maemo6 backend into plugin. --- src/network/bearer/bearer.pri | 52 +- src/network/bearer/qnetworkconfigmanager_maemo.cpp | 759 ------------- src/network/bearer/qnetworkconfigmanager_maemo_p.h | 141 --- src/network/bearer/qnetworkconfiguration.cpp | 2 +- src/network/bearer/qnetworkconfiguration_maemo_p.h | 122 -- src/network/bearer/qnetworkconfiguration_p.h | 2 +- src/network/bearer/qnetworksession.cpp | 5 - src/network/bearer/qnetworksession_maemo.cpp | 1164 -------------------- src/network/bearer/qnetworksession_maemo_p.h | 170 --- src/network/bearer/qnetworksession_p.h | 8 +- src/plugins/bearer/bearer.pro | 1 + src/plugins/bearer/icd/icd.pro | 22 + src/plugins/bearer/icd/main.cpp | 84 ++ src/plugins/bearer/icd/monitor.cpp | 116 ++ src/plugins/bearer/icd/monitor.h | 116 ++ src/plugins/bearer/icd/qicdengine.cpp | 416 +++++++ src/plugins/bearer/icd/qicdengine.h | 122 ++ src/plugins/bearer/icd/qnetworksession_impl.cpp | 1105 +++++++++++++++++++ src/plugins/bearer/icd/qnetworksession_impl.h | 147 +++ 19 files changed, 2148 insertions(+), 2406 deletions(-) delete mode 100644 src/network/bearer/qnetworkconfigmanager_maemo.cpp delete mode 100644 src/network/bearer/qnetworkconfigmanager_maemo_p.h delete mode 100644 src/network/bearer/qnetworkconfiguration_maemo_p.h delete mode 100644 src/network/bearer/qnetworksession_maemo.cpp delete mode 100644 src/network/bearer/qnetworksession_maemo_p.h create mode 100644 src/plugins/bearer/icd/icd.pro create mode 100644 src/plugins/bearer/icd/main.cpp create mode 100644 src/plugins/bearer/icd/monitor.cpp create mode 100644 src/plugins/bearer/icd/monitor.h create mode 100644 src/plugins/bearer/icd/qicdengine.cpp create mode 100644 src/plugins/bearer/icd/qicdengine.h create mode 100644 src/plugins/bearer/icd/qnetworksession_impl.cpp create mode 100644 src/plugins/bearer/icd/qnetworksession_impl.h 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 - -#include "qnetworkconfigmanager_maemo_p.h" - -#include -#include - -#include -#include -#include -#include -#include - -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 timers; - -public: - IapAddTimer() {} - ~IapAddTimer() {} - - void add(QString& iap_id, QNetworkConfigurationManagerPrivate *d); - void del(QString& iap_id); - void removeAll(); -}; - - -void IapAddTimer::removeAll() -{ - QHashIterator 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 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 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 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 knownConfigs; - - /* All the scanned access points */ - QList 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 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 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 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 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 known_iaps = knownConfigs.values(priv->network_id); - rescan_list: - if (!known_iaps.isEmpty()) { - for (int k=0; kiap_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 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 i(knownConfigs); - while (i.hasNext()) { - i.next(); - SSIDInfo *iap = i.value(); - QString iap_id = iap->iap_id; - //qDebug() << i.key() << ": " << iap_id; - - QExplicitlySharedDataPointer 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 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 -#include -#include - -#include -#include - -QT_BEGIN_NAMESPACE - - -class QNetworkConfigurationManagerPrivate : public QObject -{ - Q_OBJECT -public: - QNetworkConfigurationManagerPrivate() - : QObject(0), capFlags(0), firstUpdate(true), onlineConfigurations(0) - { - registerPlatformCapabilities(); - updateConfigurations(); - } - - virtual ~QNetworkConfigurationManagerPrivate() - { - QList configIdents = snapConfigurations.keys(); - foreach(const QString oldIface, configIdents) { - QExplicitlySharedDataPointer priv = snapConfigurations.take(oldIface); - priv->isValid = false; - priv->id.clear(); - } - - configIdents = accessPointConfigurations.keys(); - foreach(const QString oldIface, configIdents) { - QExplicitlySharedDataPointer priv = accessPointConfigurations.take(oldIface); - priv->isValid = false; - priv->id.clear(); - } - - configIdents = userChoiceConfigurations.keys(); - foreach(const QString oldIface, configIdents) { - QExplicitlySharedDataPointer 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 > accessPointConfigurations; - QHash > snapConfigurations; - QHash > 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 -#include -#include - -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 > 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_maemo.cpp b/src/network/bearer/qnetworksession_maemo.cpp deleted file mode 100644 index 6fb4453..0000000 --- a/src/network/bearer/qnetworksession_maemo.cpp +++ /dev/null @@ -1,1164 +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 - -#include "qnetworksession_maemo_p.h" -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -static QHash properties; - -static QString get_network_interface(); -static DBusConnection *dbus_connection; -static DBusHandlerResult signal_handler(DBusConnection *connection, - DBusMessage *message, - void *user_data); - -#define ICD_DBUS_MATCH "type='signal'," \ - "interface='" ICD_DBUS_INTERFACE "'," \ - "path='" ICD_DBUS_PATH "'" - - -static inline DBusConnection *get_dbus_conn(DBusError *error) -{ - DBusConnection *conn = dbus_bus_get(DBUS_BUS_SYSTEM, error); -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "Listening to bus" << dbus_bus_get_unique_name(conn); -#endif - - return conn; -} - - -/* Helper class that monitors the Icd status messages and - * can change the IAP status accordingly. This is a singleton. - */ -class IcdListener : public QObject -{ - Q_OBJECT - -public: - IcdListener() : first_call(true) { } - friend DBusHandlerResult signal_handler(DBusConnection *connection, - DBusMessage *message, - void *user_data); - void setup(QNetworkSessionPrivate *d); - void cleanup(); - void cleanupSession(QNetworkSessionPrivate *ptr); - - enum IapConnectionStatus { - /* The IAP was connected */ - CONNECTED = 0, - /* The IAP was disconnected */ - DISCONNECTED, - /* The IAP is disconnecting */ - DISCONNECTING, - /* The IAP has a network address, but is not yet fully connected */ - NETWORK_UP - }; - -private: - void icdSignalReceived(QString&, QString&, QString&); - bool first_call; - QHash sessions; -}; - -Q_GLOBAL_STATIC(IcdListener, icdListener); - - -static DBusHandlerResult signal_handler(DBusConnection *, - DBusMessage *message, - void *user_data) -{ - if (dbus_message_is_signal(message, - ICD_DBUS_INTERFACE, - ICD_STATUS_CHANGED_SIG)) { - - IcdListener *icd = (IcdListener *)user_data; - DBusError error; - dbus_error_init(&error); - - char *iap_id = 0; - char *network_type = 0; - char *state = 0; - - if (dbus_message_get_args(message, &error, - DBUS_TYPE_STRING, &iap_id, - DBUS_TYPE_STRING, &network_type, - DBUS_TYPE_STRING, &state, - DBUS_TYPE_INVALID) == FALSE) { - qWarning() << QString("Failed to parse icd status signal: %1").arg(error.message); - } else { - QString _iap_id(iap_id); - QString _network_type(network_type); - QString _state(state); - - icd->icdSignalReceived(_iap_id, _network_type, _state); - } - - dbus_error_free(&error); - return DBUS_HANDLER_RESULT_HANDLED; - } - - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; -} - - -void IcdListener::setup(QNetworkSessionPrivate *d) -{ - if (first_call) { - // We use the old Icd dbus interface like in ConIC - DBusError error; - dbus_error_init(&error); - - dbus_connection = get_dbus_conn(&error); - if (dbus_error_is_set(&error)) { - qWarning() << "Cannot get dbus connection."; - dbus_error_free(&error); - return; - } - - static struct DBusObjectPathVTable icd_vtable; - icd_vtable.message_function = signal_handler; - - dbus_bus_add_match(dbus_connection, ICD_DBUS_MATCH, &error); - if (dbus_error_is_set(&error)) { - qWarning() << "Cannot add match" << ICD_DBUS_MATCH; - dbus_error_free(&error); - return; - } - - if (dbus_connection_register_object_path(dbus_connection, - ICD_DBUS_PATH, - &icd_vtable, - (void*)this) == FALSE) { - qWarning() << "Cannot register dbus signal handler, interface"<< ICD_DBUS_INTERFACE << "path" << ICD_DBUS_PATH; - dbus_error_free(&error); - return; - } - -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "Listening" << ICD_STATUS_CHANGED_SIG << "signal from" << ICD_DBUS_SERVICE; -#endif - first_call = false; - dbus_error_free(&error); - } - - QString id = d->activeConfig.identifier(); - if (!sessions.contains(id)) { - QNetworkSessionPrivate *ptr = d; - sessions.insert(id, ptr); - } -} - - -void IcdListener::icdSignalReceived(QString& iap_id, -#ifdef BEARER_MANAGEMENT_DEBUG - QString& network_type, -#else - QString&, -#endif - QString& state) -{ - if (iap_id == OSSO_IAP_SCAN) // icd sends scan status signals which we will ignore - return; - -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "Status received:" << iap_id << "type" << network_type << "state" << state; -#endif - - if (!sessions.contains(iap_id)) { -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "No session for IAP" << iap_id; -#endif - return; - } - - QNetworkSessionPrivate *session = sessions.value(iap_id); - QNetworkConfiguration ap_conf = session->manager.configurationFromIdentifier(iap_id); - if (!ap_conf.isValid()) { -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "Unknown IAP" << iap_id; -#endif - return; - } - - IapConnectionStatus status; - - if (state == "IDLE") { - status = DISCONNECTED; - } else if (state == "CONNECTED") { - status = CONNECTED; - } else if (state == "NETWORKUP") { - status = NETWORK_UP; - } else { - //qDebug() << "Unknown state" << state; - return; - } - - if (status == DISCONNECTED) { - if (ap_conf.state() == QNetworkConfiguration::Active) { - /* The IAP was just disconnected by Icd */ - session->updateState(QNetworkSession::Disconnected); - } else { -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "Got a network disconnect when in state" << ap_conf.state(); -#endif - } - } else if (status == CONNECTED) { - /* The IAP was just connected by Icd */ - session->updateState(QNetworkSession::Connected); - session->updateIdentifier(iap_id); - - if (session->publicConfig.identifier() == OSSO_IAP_ANY) { -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "IAP" << iap_id << "connected when connecting to" << OSSO_IAP_ANY; -#endif - } else { -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "IAP" << iap_id << "connected"; -#endif - } - } - - return; -} - - -void IcdListener::cleanup() -{ - if (!first_call) { - dbus_bus_remove_match(dbus_connection, ICD_DBUS_MATCH, NULL); - dbus_connection_unref(dbus_connection); - } -} - - -void IcdListener::cleanupSession(QNetworkSessionPrivate *ptr) -{ - if (ptr->publicConfig.type() == QNetworkConfiguration::UserChoice) - (void)sessions.take(ptr->activeConfig.identifier()); - else - (void)sessions.take(ptr->publicConfig.identifier()); -} - - -void QNetworkSessionPrivate::cleanupSession(void) -{ - icdListener()->cleanupSession(this); -} - - -void QNetworkSessionPrivate::updateState(QNetworkSession::State newState) -{ - if( newState != state) { - 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; - - } else if (state == QNetworkSession::Connected) { - isOpen = true; - if (publicConfig.type() == QNetworkConfiguration::UserChoice) { - activeConfig.d->state = QNetworkConfiguration::Active; - activeConfig.d->type = QNetworkConfiguration::InternetAccessPoint; - } - publicConfig.d->state = QNetworkConfiguration::Active; - } - - emit q->stateChanged(newState); - } -} - - -void QNetworkSessionPrivate::updateIdentifier(QString &newId) -{ - if (publicConfig.type() == QNetworkConfiguration::UserChoice) { - activeConfig.d->network_attrs |= ICD_NW_ATTR_IAPNAME; - activeConfig.d->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; - } - } -} - - -quint64 QNetworkSessionPrivate::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 - * necessary. - */ - Maemo::Icd icd; - QList stats_results; - quint64 counter_rx = 0, counter_tx = 0; - - if (!icd.statistics(stats_results)) { - return 0; - } - - foreach (Maemo::IcdStatisticsResult res, stats_results) { - if (res.params.network_attrs & ICD_NW_ATTR_IAPNAME) { - /* network_id is the IAP UUID */ - if (QString(res.params.network_id.data()) == activeConfig.identifier()) { - counter_tx = res.bytes_sent; - counter_rx = res.bytes_received; - } - } else { - /* We probably will never get to this branch */ - QNetworkConfigurationPrivate *d = activeConfig.d.data(); - if (res.params.network_id == d->network_id) { - counter_tx = res.bytes_sent; - counter_rx = res.bytes_received; - } - } - } - - if (sent) - return counter_tx; - else - return counter_rx; -} - - -quint64 QNetworkSessionPrivate::bytesWritten() const -{ - return getStatistics(true); -} - -quint64 QNetworkSessionPrivate::bytesReceived() const -{ - return getStatistics(false); -} - -quint64 QNetworkSessionPrivate::activeTime() const -{ - if (startTime.isNull()) { - return 0; - } - return startTime.secsTo(QDateTime::currentDateTime()); -} - - -QNetworkConfiguration& QNetworkSessionPrivate::copyConfig(QNetworkConfiguration &fromConfig, QNetworkConfiguration &toConfig, bool deepCopy) -{ - if (deepCopy) { - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - QExplicitlySharedDataPointer ptr(cpPriv); - toConfig.d = ptr; - } - - toConfig.d->name = fromConfig.d->name; - toConfig.d->isValid = fromConfig.d->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; - - return toConfig; -} - - -/* This is called by QNetworkSession constructor and it updates the current - * state of the configuration. - */ -void QNetworkSessionPrivate::syncStateWithInterface() -{ - /* Start to listen Icd status messages. */ - icdListener()->setup(this); - - /* Initially we are not active although the configuration might be in - * connected state. - */ - isOpen = false; - opened = false; - - QObject::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; - } - } - - state = QNetworkSession::Invalid; - lastError = QNetworkSession::UnknownSessionError; - - switch (publicConfig.type()) { - case QNetworkConfiguration::InternetAccessPoint: - activeConfig = publicConfig; - break; - case QNetworkConfiguration::ServiceNetwork: - serviceConfig = publicConfig; - break; - case QNetworkConfiguration::UserChoice: - // active config will contain correct data after open() has succeeded - copyConfig(publicConfig, activeConfig); - - /* We create new configuration that holds the actual configuration - * returned by icd. This way publicConfig still contains the - * original user specified configuration. - * - * Note that the new activeConfig configuration is not inserted - * to configurationManager as manager class will get the newly - * connected configuration from gconf when the IAP is saved. - * This configuration manager update is done by IapMonitor class. - * If the ANY connection fails in open(), then the configuration - * data is not saved to gconf and will not be added to - * configuration manager IAP list. - */ -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug()<<"New configuration created for" << publicConfig.identifier(); -#endif - break; - default: - /* Invalid configuration, no point continuing */ - return; - } - - if (!activeConfig.isValid()) - return; - - /* Get the initial state from icd */ - Maemo::Icd icd; - QList state_results; - - /* Update the active config from first connection, this is ok as icd - * supports only one connection anyway. - */ - if (icd.state(state_results) && !state_results.isEmpty()) { - - /* If we did not get full state back, then we are not - * connected and can skip the next part. - */ - if (!(state_results.first().params.network_attrs == 0 && - state_results.first().params.network_id.isEmpty())) { - - /* If we try to connect to specific IAP and we get results back - * that tell the icd is actually connected to another IAP, - * then do not update current state etc. - */ - if (publicConfig.type() == QNetworkConfiguration::UserChoice || - publicConfig.d->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; - break; - case ICD_STATE_CONNECTING: - state = QNetworkSession::Connecting; - if (activeConfig.d.data()) - activeConfig.d->isValid = true; - break; - case ICD_STATE_CONNECTED: - { - if (!state_results.first().error.isEmpty()) - break; - - 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 priv = mgr->accessPointConfigurations.value(activeConfig.d->id); - activeConfig.d = priv; - } - - - 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; - currentNetworkInterface = get_network_interface(); - - Maemo::IAPConf iap_name(activeConfig.d->id); - QString name_value = iap_name.value("name").toString(); - if (!name_value.isEmpty()) - activeConfig.d->name = name_value; - else - activeConfig.d->name = activeConfig.d->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 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"<id<<"added to manager in sync"; -#endif - - } else { - mgr->configurationChanged((QNetworkConfigurationPrivate*)(activeConfig.d.data())); -#ifdef BEARER_MANAGEMENT_DEBUG - //qDebug()<<"Existing configuration"<id<<"updated in manager in sync"; -#endif - } - - } - break; - - case ICD_STATE_DISCONNECTING: - state = QNetworkSession::Closing; - if (activeConfig.d.data()) - activeConfig.d->isValid = true; - break; - default: - break; - } - } - } else { -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "status_req tells icd is not connected"; -#endif - } - } else { -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "status_req did not return any results from icd"; -#endif - } - - networkConfigurationsChanged(); -} - - -void QNetworkSessionPrivate::networkConfigurationsChanged() -{ - if (serviceConfig.isValid()) - updateStateFromServiceNetwork(); - else - updateStateFromActiveConfig(); -} - - -void QNetworkSessionPrivate::updateStateFromServiceNetwork() -{ - QNetworkSession::State oldState = state; - - foreach (const QNetworkConfiguration &config, serviceConfig.children()) { - if ((config.state() & QNetworkConfiguration::Active) != QNetworkConfiguration::Active) - continue; - - if (activeConfig != config) { - activeConfig = config; - emit q->newConfigurationActivated(); - } - - state = QNetworkSession::Connected; - if (state != oldState) - emit q->stateChanged(state); - - return; - } - - if (serviceConfig.children().isEmpty()) - state = QNetworkSession::NotAvailable; - else - state = QNetworkSession::Disconnected; - - if (state != oldState) - emit q->stateChanged(state); -} - - -void QNetworkSessionPrivate::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; -} - - -void QNetworkSessionPrivate::updateStateFromActiveConfig() -{ - QNetworkSession::State oldState = state; - - bool newActive = false; - - if (!activeConfig.d.data()) - return; - - if (!activeConfig.isValid()) { - state = QNetworkSession::Invalid; - clearConfiguration(activeConfig); - } else if ((activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { - state = QNetworkSession::Connected; - newActive = opened; - } else if ((activeConfig.state() & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) { - state = QNetworkSession::Disconnected; - } else if ((activeConfig.state() & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) { - state = QNetworkSession::NotAvailable; - } else if ((activeConfig.state() & QNetworkConfiguration::Undefined) == QNetworkConfiguration::Undefined) { - state = QNetworkSession::NotAvailable; - clearConfiguration(activeConfig); - } - - bool oldActive = isOpen; - isOpen = newActive; - - if (!oldActive && isOpen) - emit quitPendingWaitsForOpened(); - - if (oldActive && !isOpen) - emit q->closed(); - - if (oldState != state) { - emit q->stateChanged(state); - - if (state == QNetworkSession::Disconnected) { -#ifdef BEARER_MANAGEMENT_DEBUG - //qDebug()<<"session aborted error emitted for"<error(lastError); - } - } - -#ifdef BEARER_MANAGEMENT_DEBUG - //qDebug()<<"oldState ="<ifa_next) { - family = ifa->ifa_addr->sa_family; - if (family != AF_INET) { - continue; /* Currently only IPv4 is supported by icd dbus interface */ - } - if (((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr == addr.s_addr) { - iface = QString(ifa->ifa_name); - break; - } - } - - freeifaddrs(ifaddr); - return iface; -} - - -void QNetworkSessionPrivate::open() -{ - if (serviceConfig.isValid()) { - lastError = QNetworkSession::OperationNotSupportedError; - emit q->error(lastError); - } else if (!isOpen) { - - if (publicConfig.type() == QNetworkConfiguration::UserChoice) { - /* Caller is trying to connect to default IAP. - * At this time we will not know the IAP details so we just - * connect and update the active config when the IAP is - * connected. - */ - opened = true; - state = QNetworkSession::Connecting; - emit q->stateChanged(state); - QTimer::singleShot(0, this, SLOT(do_open())); - return; - } - - /* User is connecting to one specific IAP. If that IAP is not - * in discovered state we cannot continue. - */ - if ((activeConfig.state() & QNetworkConfiguration::Discovered) != - QNetworkConfiguration::Discovered) { - lastError =QNetworkSession::InvalidConfigurationError; - emit q->error(lastError); - return; - } - opened = true; - - if ((activeConfig.state() & QNetworkConfiguration::Active) != QNetworkConfiguration::Active) { - state = QNetworkSession::Connecting; - emit q->stateChanged(state); - - QTimer::singleShot(0, this, SLOT(do_open())); - return; - } - - isOpen = (activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active; - if (isOpen) - emit quitPendingWaitsForOpened(); - } else { - /* We seem to be active so inform caller */ - emit quitPendingWaitsForOpened(); - } -} - - -void QNetworkSessionPrivate::do_open() -{ - icd_connection_flags flags = connectFlags; - bool st; - QString result; - QString iap = publicConfig.identifier(); - - if (state == QNetworkSession::Connected) { -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "Already connected to" << activeConfig.identifier(); -#endif - emit q->stateChanged(QNetworkSession::Connected); - emit quitPendingWaitsForOpened(); - return; - } - - Maemo::IcdConnectResult connect_result; - Maemo::Icd icd(ICD_LONG_CONNECT_TIMEOUT); - QNetworkConfiguration config; - if (publicConfig.type() == QNetworkConfiguration::UserChoice) - config = activeConfig; - else - config = publicConfig; - - if (iap == OSSO_IAP_ANY) { -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "connecting to default IAP" << iap; -#endif - st = icd.connect(flags, connect_result); - - } else { - - QList 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.network_id = QByteArray(iap.toLatin1()); - else - param.connect.network_id = config.d->network_id; - params.append(param); - -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug("connecting to %s/%s/0x%x/%s/0x%x/%s", - param.connect.network_id.data(), - param.connect.network_type.toAscii().constData(), - param.connect.network_attrs, - param.connect.service_type.toAscii().constData(), - param.connect.service_attrs, - param.connect.service_id.toAscii().constData()); -#endif - st = icd.connect(flags, params, connect_result); - } - - if (st) { - result = connect_result.connect.network_id.data(); - QString connected_iap = result; - - if (connected_iap.isEmpty()) { -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "connect to"<< iap << "failed, result is empty"; -#endif - updateState(QNetworkSession::Disconnected); - emit quitPendingWaitsForOpened(); - emit q->error(QNetworkSession::InvalidConfigurationError); - if (publicConfig.type() == QNetworkConfiguration::UserChoice) - cleanupAnyConfiguration(); - return; - } - - /* If the user tried to connect to some specific connection (foo) - * and we were already connected to some other connection (bar), - * then we cannot activate this session although icd has a valid - * connection to somewhere. - */ - if ((publicConfig.type() != QNetworkConfiguration::UserChoice) && - (connected_iap != config.identifier())) { - updateState(QNetworkSession::Disconnected); - emit quitPendingWaitsForOpened(); - emit q->error(QNetworkSession::InvalidConfigurationError); - return; - } - - - /* Did we connect to non saved IAP? */ - if (!(config.d->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; - } - - /* User might have changed the IAP name when a new IAP was saved */ - Maemo::IAPConf iap_name(config.d->id); - QString name = iap_name.value("name").toString(); - if (!name.isEmpty()) - config.d->name = name; - - config.d->iap_type = connect_result.connect.network_type; - - config.d->isValid = true; - config.d->state = QNetworkConfiguration::Active; - config.d->type = QNetworkConfiguration::InternetAccessPoint; - - startTime = QDateTime::currentDateTime(); - updateState(QNetworkSession::Connected); - - currentNetworkInterface = get_network_interface(); - -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "connected to" << result << config.d->name << "at" << currentNetworkInterface; -#endif - - /* We first check if the configuration already exists in the manager - * and if it is not found there, we then insert it. Note that this - * is only done for user choice config only because it can be missing - * from config manager list. - */ - - if (publicConfig.d->type == QNetworkConfiguration::UserChoice) { - -#ifdef BEARER_MANAGEMENT_DEBUG -#if 0 - QList configs; - QNetworkConfigurationManagerPrivate *conPriv = (QNetworkConfigurationManagerPrivate*)config.d.data()->manager; - QList cpsIdents = conPriv->accessPointConfigurations.keys(); - foreach( QString ii, cpsIdents) { - QExplicitlySharedDataPointer 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.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 ptr = config.d; - mgr->accessPointConfigurations.insert(result, ptr); - - QNetworkConfiguration item; - item.d = ptr; - emit mgr->configurationAdded(item); - -#ifdef BEARER_MANAGEMENT_DEBUG - //qDebug()<<"New configuration"< 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"<error(QNetworkSession::UnknownSessionError); - } -} - - -void QNetworkSessionPrivate::cleanupAnyConfiguration() -{ -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug()<<"Removing configuration created for" << activeConfig.d->id; -#endif - activeConfig = publicConfig; -} - - -void QNetworkSessionPrivate::close() -{ - if (serviceConfig.isValid()) { - lastError = QNetworkSession::OperationNotSupportedError; - emit q->error(lastError); - } else if (isOpen) { - opened = false; - isOpen = false; - emit q->closed(); - } -} - - -void QNetworkSessionPrivate::stop() -{ - if (serviceConfig.isValid()) { - lastError = QNetworkSession::OperationNotSupportedError; - emit q->error(lastError); - } else { - if ((activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { - state = QNetworkSession::Closing; - emit q->stateChanged(state); - - Maemo::Icd icd; -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "stopping session" << publicConfig.identifier(); -#endif - icd.disconnect(ICD_CONNECTION_FLAG_APPLICATION_EVENT); - startTime = QDateTime(); - - /* Note that the state will go disconnected in - * updateStateFromActiveConfig() which gets called after - * configurationChanged is emitted (below). - */ - - activeConfig.d->state = QNetworkConfiguration::Discovered; - QNetworkConfigurationManagerPrivate *mgr = (QNetworkConfigurationManagerPrivate*)activeConfig.d.data()->manager; - mgr->configurationChanged((QNetworkConfigurationPrivate*)activeConfig.d.data()); - - opened = false; - isOpen = false; - - } else { - opened = false; - isOpen = false; - emit q->closed(); - } - } -} - - -void QNetworkSessionPrivate::migrate() -{ - qWarning("This platform does not support roaming (%s).", __FUNCTION__); -} - - -void QNetworkSessionPrivate::accept() -{ - qWarning("This platform does not support roaming (%s).", __FUNCTION__); -} - - -void QNetworkSessionPrivate::ignore() -{ - qWarning("This platform does not support roaming (%s).", __FUNCTION__); -} - - -void QNetworkSessionPrivate::reject() -{ - qWarning("This platform does not support roaming (%s).", __FUNCTION__); -} - - -QNetworkInterface QNetworkSessionPrivate::currentInterface() const -{ - if (!publicConfig.isValid() || state != QNetworkSession::Connected) - return QNetworkInterface(); - - if (currentNetworkInterface.isEmpty()) - return QNetworkInterface(); - - return QNetworkInterface::interfaceFromName(currentNetworkInterface); -} - - -void QNetworkSessionPrivate::setSessionProperty(const QString& key, const QVariant& value) -{ - if (value.isValid()) { - properties.insert(key, value); - - if (key == "ConnectInBackground") { - bool v = value.toBool(); - if (v) - connectFlags = ICD_CONNECTION_FLAG_APPLICATION_EVENT; - else - connectFlags = ICD_CONNECTION_FLAG_USER_EVENT; - } - } else { - properties.remove(key); - - /* Set default value when property is removed */ - if (key == "ConnectInBackground") - connectFlags = ICD_CONNECTION_FLAG_USER_EVENT; - } -} - - -QVariant QNetworkSessionPrivate::sessionProperty(const QString& key) const -{ - return properties.value(key); -} - - -QString QNetworkSessionPrivate::errorString() const -{ - QString errorStr; - switch(q->error()) { - case QNetworkSession::RoamingError: - errorStr = QObject::tr("Roaming error"); - break; - case QNetworkSession::SessionAbortedError: - errorStr = QObject::tr("Session aborted by user or system"); - break; - default: - case QNetworkSession::UnknownSessionError: - errorStr = QObject::tr("Unidentified Error"); - break; - } - return errorStr; -} - - -QNetworkSession::SessionError QNetworkSessionPrivate::error() const -{ - return QNetworkSession::UnknownSessionError; -} - -#include "qnetworksession_maemo.moc" -#include "moc_qnetworksession_maemo_p.cpp" - -QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworksession_maemo_p.h b/src/network/bearer/qnetworksession_maemo_p.h deleted file mode 100644 index ff294f6..0000000 --- a/src/network/bearer/qnetworksession_maemo_p.h +++ /dev/null @@ -1,170 +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 QNETWORKSESSIONPRIVATE_H -#define QNETWORKSESSIONPRIVATE_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_maemo_p.h" -#include "qnetworksession.h" - -#include -#include -#include - -#ifdef Q_WS_MAEMO_6 -#include -#endif - -QT_BEGIN_NAMESPACE - -class QNetworkSessionPrivate : public QObject -{ - 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 - { - } - - ~QNetworkSessionPrivate() - { - cleanupSession(); - } - - //called by QNetworkSession constructor and ensures - //that the state is immediately updated (w/o actually opening - //a session). Also this function should take care of - //notification hooks to discover future state changes. - void syncStateWithInterface(); - - QNetworkInterface currentInterface() const; - QVariant sessionProperty(const QString& key) const; - void setSessionProperty(const QString& key, const QVariant& value); - - void open(); - void close(); - void stop(); - void migrate(); - void accept(); - void ignore(); - void reject(); - - QString errorString() const; //must return translated string - QNetworkSession::SessionError error() const; - - quint64 bytesWritten() const; - quint64 bytesReceived() const; - quint64 activeTime() const; - -private: - void updateStateFromServiceNetwork(); - void updateStateFromActiveConfig(); - -Q_SIGNALS: - //releases any pending waitForOpened() calls - void quitPendingWaitsForOpened(); - -private Q_SLOTS: - void do_open(); - void networkConfigurationsChanged(); - void configurationChanged(const QNetworkConfiguration &config); - -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; - - 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; - void updateState(QNetworkSession::State); - void updateIdentifier(QString &newId); - quint64 getStatistics(bool sent) const; - void cleanupSession(void); -}; - -QT_END_NAMESPACE - -#endif //QNETWORKSESSIONPRIVATE_H - 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 + +#include + +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 +#include +#include +#include + +#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 +#include + +#include +#include + +#include + +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 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 +#include +#include + +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 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 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; iisValid) { + 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 + +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(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/plugins/bearer/icd/qnetworksession_impl.cpp b/src/plugins/bearer/icd/qnetworksession_impl.cpp new file mode 100644 index 0000000..6cc4a1d --- /dev/null +++ b/src/plugins/bearer/icd/qnetworksession_impl.cpp @@ -0,0 +1,1105 @@ +/**************************************************************************** +** +** 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 "qnetworksession_impl.h" +#include "qicdengine.h" + +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +static QHash properties; + +static QString get_network_interface(); +static DBusConnection *dbus_connection; +static DBusHandlerResult signal_handler(DBusConnection *connection, + DBusMessage *message, + void *user_data); + +#define ICD_DBUS_MATCH "type='signal'," \ + "interface='" ICD_DBUS_INTERFACE "'," \ + "path='" ICD_DBUS_PATH "'" + + +static inline DBusConnection *get_dbus_conn(DBusError *error) +{ + DBusConnection *conn = dbus_bus_get(DBUS_BUS_SYSTEM, error); +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Listening to bus" << dbus_bus_get_unique_name(conn); +#endif + + return conn; +} + + +/* Helper class that monitors the Icd status messages and + * can change the IAP status accordingly. This is a singleton. + */ +class IcdListener : public QObject +{ + Q_OBJECT + +public: + IcdListener() : first_call(true) { } + friend DBusHandlerResult signal_handler(DBusConnection *connection, + DBusMessage *message, + void *user_data); + void setup(QNetworkSessionPrivateImpl *d); + void cleanup(); + void cleanupSession(QNetworkSessionPrivateImpl *ptr); + + enum IapConnectionStatus { + /* The IAP was connected */ + CONNECTED = 0, + /* The IAP was disconnected */ + DISCONNECTED, + /* The IAP is disconnecting */ + DISCONNECTING, + /* The IAP has a network address, but is not yet fully connected */ + NETWORK_UP + }; + +private: + void icdSignalReceived(QString&, QString&, QString&); + bool first_call; + QHash sessions; +}; + +Q_GLOBAL_STATIC(IcdListener, icdListener); + + +static DBusHandlerResult signal_handler(DBusConnection *, + DBusMessage *message, + void *user_data) +{ + if (dbus_message_is_signal(message, + ICD_DBUS_INTERFACE, + ICD_STATUS_CHANGED_SIG)) { + + IcdListener *icd = (IcdListener *)user_data; + DBusError error; + dbus_error_init(&error); + + char *iap_id = 0; + char *network_type = 0; + char *state = 0; + + if (dbus_message_get_args(message, &error, + DBUS_TYPE_STRING, &iap_id, + DBUS_TYPE_STRING, &network_type, + DBUS_TYPE_STRING, &state, + DBUS_TYPE_INVALID) == FALSE) { + qWarning() << QString("Failed to parse icd status signal: %1").arg(error.message); + } else { + QString _iap_id(iap_id); + QString _network_type(network_type); + QString _state(state); + + icd->icdSignalReceived(_iap_id, _network_type, _state); + } + + dbus_error_free(&error); + return DBUS_HANDLER_RESULT_HANDLED; + } + + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + + +void IcdListener::setup(QNetworkSessionPrivateImpl *d) +{ + if (first_call) { + // We use the old Icd dbus interface like in ConIC + DBusError error; + dbus_error_init(&error); + + dbus_connection = get_dbus_conn(&error); + if (dbus_error_is_set(&error)) { + qWarning() << "Cannot get dbus connection."; + dbus_error_free(&error); + return; + } + + static struct DBusObjectPathVTable icd_vtable; + icd_vtable.message_function = signal_handler; + + dbus_bus_add_match(dbus_connection, ICD_DBUS_MATCH, &error); + if (dbus_error_is_set(&error)) { + qWarning() << "Cannot add match" << ICD_DBUS_MATCH; + dbus_error_free(&error); + return; + } + + if (dbus_connection_register_object_path(dbus_connection, + ICD_DBUS_PATH, + &icd_vtable, + (void*)this) == FALSE) { + qWarning() << "Cannot register dbus signal handler, interface"<< ICD_DBUS_INTERFACE << "path" << ICD_DBUS_PATH; + dbus_error_free(&error); + return; + } + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Listening" << ICD_STATUS_CHANGED_SIG << "signal from" << ICD_DBUS_SERVICE; +#endif + first_call = false; + dbus_error_free(&error); + } + + QString id = d->activeConfig.identifier(); + if (!sessions.contains(id)) { + QNetworkSessionPrivateImpl *ptr = d; + sessions.insert(id, ptr); + } +} + + +void IcdListener::icdSignalReceived(QString& iap_id, +#ifdef BEARER_MANAGEMENT_DEBUG + QString& network_type, +#else + QString&, +#endif + QString& state) +{ + if (iap_id == OSSO_IAP_SCAN) // icd sends scan status signals which we will ignore + return; + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Status received:" << iap_id << "type" << network_type << "state" << state; +#endif + + if (!sessions.contains(iap_id)) { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "No session for IAP" << iap_id; +#endif + return; + } + + 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; +#endif + return; + } + + IapConnectionStatus status; + + if (state == "IDLE") { + status = DISCONNECTED; + } else if (state == "CONNECTED") { + status = CONNECTED; + } else if (state == "NETWORKUP") { + status = NETWORK_UP; + } else { + //qDebug() << "Unknown state" << state; + return; + } + + if (status == DISCONNECTED) { + if (ap_conf.state() == QNetworkConfiguration::Active) { + /* The IAP was just disconnected by Icd */ + session->updateState(QNetworkSession::Disconnected); + } else { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Got a network disconnect when in state" << ap_conf.state(); +#endif + } + } else if (status == CONNECTED) { + /* The IAP was just connected by Icd */ + session->updateState(QNetworkSession::Connected); + session->updateIdentifier(iap_id); + + if (session->publicConfig.identifier() == OSSO_IAP_ANY) { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "IAP" << iap_id << "connected when connecting to" << OSSO_IAP_ANY; +#endif + } else { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "IAP" << iap_id << "connected"; +#endif + } + } + + return; +} + + +void IcdListener::cleanup() +{ + if (!first_call) { + dbus_bus_remove_match(dbus_connection, ICD_DBUS_MATCH, NULL); + dbus_connection_unref(dbus_connection); + } +} + + +void IcdListener::cleanupSession(QNetworkSessionPrivateImpl *ptr) +{ + if (ptr->publicConfig.type() == QNetworkConfiguration::UserChoice) + (void)sessions.take(ptr->activeConfig.identifier()); + else + (void)sessions.take(ptr->publicConfig.identifier()); +} + + +void QNetworkSessionPrivateImpl::cleanupSession(void) +{ + icdListener()->cleanupSession(this); +} + + +void QNetworkSessionPrivateImpl::updateState(QNetworkSession::State newState) +{ + if (newState == state) + return; + + state = newState; + + if (state == QNetworkSession::Disconnected) { + isOpen = false; + currentNetworkInterface.clear(); + if (publicConfig.type() == QNetworkConfiguration::UserChoice) + privateConfiguration(activeConfig)->state = QNetworkConfiguration::Defined; + privateConfiguration(publicConfig)->state = QNetworkConfiguration::Defined; + + } else if (state == QNetworkSession::Connected) { + isOpen = true; + if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + privateConfiguration(activeConfig)->state = QNetworkConfiguration::Active; + privateConfiguration(activeConfig)->type = QNetworkConfiguration::InternetAccessPoint; + } + privateConfiguration(publicConfig)->state = QNetworkConfiguration::Active; + } + + emit stateChanged(newState); +} + + +void QNetworkSessionPrivateImpl::updateIdentifier(QString &newId) +{ + if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + toIcdConfig(privateConfiguration(activeConfig))->network_attrs |= ICD_NW_ATTR_IAPNAME; + privateConfiguration(activeConfig)->id = newId; + } else { + toIcdConfig(privateConfiguration(publicConfig))->network_attrs |= ICD_NW_ATTR_IAPNAME; + if (privateConfiguration(publicConfig)->id != newId) { + qWarning() << "Your config id changed from" << privateConfiguration(publicConfig)->id + << "to" << newId; + privateConfiguration(publicConfig)->id = newId; + } + } +} + + +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 + * necessary. + */ + Maemo::Icd icd; + QList stats_results; + quint64 counter_rx = 0, counter_tx = 0; + + if (!icd.statistics(stats_results)) { + return 0; + } + + foreach (Maemo::IcdStatisticsResult res, stats_results) { + if (res.params.network_attrs & ICD_NW_ATTR_IAPNAME) { + /* network_id is the IAP UUID */ + if (QString(res.params.network_id.data()) == activeConfig.identifier()) { + counter_tx = res.bytes_sent; + counter_rx = res.bytes_received; + } + } else { + /* We probably will never get to this branch */ + if (res.params.network_id == toIcdConfig(privateConfiguration(activeConfig))->network_id) { + counter_tx = res.bytes_sent; + counter_rx = res.bytes_received; + } + } + } + + if (sent) + return counter_tx; + else + return counter_rx; +} + + +quint64 QNetworkSessionPrivateImpl::bytesWritten() const +{ + return getStatistics(true); +} + +quint64 QNetworkSessionPrivateImpl::bytesReceived() const +{ + return getStatistics(false); +} + +quint64 QNetworkSessionPrivateImpl::activeTime() const +{ + if (startTime.isNull()) { + return 0; + } + return startTime.secsTo(QDateTime::currentDateTime()); +} + + +QNetworkConfiguration& QNetworkSessionPrivateImpl::copyConfig(QNetworkConfiguration &fromConfig, + QNetworkConfiguration &toConfig, + bool deepCopy) +{ + IcdNetworkConfigurationPrivate *cpPriv; + if (deepCopy) { + cpPriv = new IcdNetworkConfigurationPrivate; + setPrivateConfiguration(toConfig, QNetworkConfigurationPrivatePointer(cpPriv)); + } else { + cpPriv = toIcdConfig(privateConfiguration(toConfig)); + } + + 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. + 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; +} + + +/* This is called by QNetworkSession constructor and it updates the current + * state of the configuration. + */ +void QNetworkSessionPrivateImpl::syncStateWithInterface() +{ + /* Start to listen Icd status messages. */ + icdListener()->setup(this); + + /* Initially we are not active although the configuration might be in + * connected state. + */ + isOpen = false; + opened = false; + + connect(&manager, SIGNAL(updateCompleted()), this, SLOT(networkConfigurationsChanged())); + + connect(&manager, SIGNAL(configurationChanged(QNetworkConfiguration)), + this, SLOT(configurationChanged(QNetworkConfiguration))); + + state = QNetworkSession::Invalid; + lastError = QNetworkSession::UnknownSessionError; + + switch (publicConfig.type()) { + case QNetworkConfiguration::InternetAccessPoint: + activeConfig = publicConfig; + break; + case QNetworkConfiguration::ServiceNetwork: + serviceConfig = publicConfig; + break; + case QNetworkConfiguration::UserChoice: + // active config will contain correct data after open() has succeeded + copyConfig(publicConfig, activeConfig); + + /* We create new configuration that holds the actual configuration + * returned by icd. This way publicConfig still contains the + * original user specified configuration. + * + * Note that the new activeConfig configuration is not inserted + * to configurationManager as manager class will get the newly + * connected configuration from gconf when the IAP is saved. + * This configuration manager update is done by IapMonitor class. + * If the ANY connection fails in open(), then the configuration + * data is not saved to gconf and will not be added to + * configuration manager IAP list. + */ +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug()<<"New configuration created for" << publicConfig.identifier(); +#endif + break; + default: + /* Invalid configuration, no point continuing */ + return; + } + + if (!activeConfig.isValid()) + return; + + /* Get the initial state from icd */ + Maemo::Icd icd; + QList state_results; + + /* Update the active config from first connection, this is ok as icd + * supports only one connection anyway. + */ + if (icd.state(state_results) && !state_results.isEmpty()) { + + /* If we did not get full state back, then we are not + * connected and can skip the next part. + */ + if (!(state_results.first().params.network_attrs == 0 && + state_results.first().params.network_id.isEmpty())) { + + /* If we try to connect to specific IAP and we get results back + * that tell the icd is actually connected to another IAP, + * then do not update current state etc. + */ + if (publicConfig.type() == QNetworkConfiguration::UserChoice || + privateConfiguration(publicConfig)->id == state_results.first().params.network_id) { + + switch (state_results.first().state) { + case ICD_STATE_DISCONNECTED: + state = QNetworkSession::Disconnected; + if (privateConfiguration(activeConfig)) + privateConfiguration(activeConfig)->isValid = true; + break; + case ICD_STATE_CONNECTING: + state = QNetworkSession::Connecting; + 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; + + 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; + 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(privateConfiguration(activeConfig)->id); + QString name_value = iap_name.value("name").toString(); + if (!name_value.isEmpty()) + privateConfiguration(activeConfig)->name = name_value; + else + privateConfiguration(activeConfig)->name = privateConfiguration(activeConfig)->id; + + + // Add the new active configuration to manager or update the old config + 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 (privateConfiguration(activeConfig)) + privateConfiguration(activeConfig)->isValid = true; + break; + default: + break; + } + } + } else { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "status_req tells icd is not connected"; +#endif + } + } else { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "status_req did not return any results from icd"; +#endif + } + + networkConfigurationsChanged(); +} + + +void QNetworkSessionPrivateImpl::networkConfigurationsChanged() +{ + if (serviceConfig.isValid()) + updateStateFromServiceNetwork(); + else + updateStateFromActiveConfig(); +} + + +void QNetworkSessionPrivateImpl::updateStateFromServiceNetwork() +{ + QNetworkSession::State oldState = state; + + foreach (const QNetworkConfiguration &config, serviceConfig.children()) { + if ((config.state() & QNetworkConfiguration::Active) != QNetworkConfiguration::Active) + continue; + + if (activeConfig != config) { + activeConfig = config; + emit newConfigurationActivated(); + } + + state = QNetworkSession::Connected; + if (state != oldState) + emit stateChanged(state); + + return; + } + + if (serviceConfig.children().isEmpty()) + state = QNetworkSession::NotAvailable; + else + state = QNetworkSession::Disconnected; + + if (state != oldState) + emit stateChanged(state); +} + + +void QNetworkSessionPrivateImpl::clearConfiguration(QNetworkConfiguration &config) +{ + 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 QNetworkSessionPrivateImpl::updateStateFromActiveConfig() +{ + QNetworkSession::State oldState = state; + + bool newActive = false; + + if (!privateConfiguration(activeConfig)) + return; + + if (!activeConfig.isValid()) { + state = QNetworkSession::Invalid; + clearConfiguration(activeConfig); + } else if ((activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + state = QNetworkSession::Connected; + newActive = opened; + } else if ((activeConfig.state() & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) { + state = QNetworkSession::Disconnected; + } else if ((activeConfig.state() & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) { + state = QNetworkSession::NotAvailable; + } else if ((activeConfig.state() & QNetworkConfiguration::Undefined) == QNetworkConfiguration::Undefined) { + state = QNetworkSession::NotAvailable; + //clearConfiguration(activeConfig); + } + + bool oldActive = isOpen; + isOpen = newActive; + + if (!oldActive && isOpen) + emit quitPendingWaitsForOpened(); + + if (oldActive && !isOpen) + emit closed(); + + if (oldState != state) { + emit stateChanged(state); + + if (state == QNetworkSession::Disconnected) { +#ifdef BEARER_MANAGEMENT_DEBUG + //qDebug()<<"session aborted error emitted for"<ifa_next) { + family = ifa->ifa_addr->sa_family; + if (family != AF_INET) { + continue; /* Currently only IPv4 is supported by icd dbus interface */ + } + if (((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr == addr.s_addr) { + iface = QString(ifa->ifa_name); + break; + } + } + + freeifaddrs(ifaddr); + return iface; +} + + +void QNetworkSessionPrivateImpl::open() +{ + if (serviceConfig.isValid()) { + lastError = QNetworkSession::OperationNotSupportedError; + emit QNetworkSessionPrivate::error(lastError); + } else if (!isOpen) { + + if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + /* Caller is trying to connect to default IAP. + * At this time we will not know the IAP details so we just + * connect and update the active config when the IAP is + * connected. + */ + opened = true; + state = QNetworkSession::Connecting; + emit stateChanged(state); + QTimer::singleShot(0, this, SLOT(do_open())); + return; + } + + /* User is connecting to one specific IAP. If that IAP is not + * in discovered state we cannot continue. + */ + if ((activeConfig.state() & QNetworkConfiguration::Discovered) != + QNetworkConfiguration::Discovered) { + lastError =QNetworkSession::InvalidConfigurationError; + emit QNetworkSessionPrivate::error(lastError); + return; + } + opened = true; + + if ((activeConfig.state() & QNetworkConfiguration::Active) != QNetworkConfiguration::Active) { + state = QNetworkSession::Connecting; + emit stateChanged(state); + + QTimer::singleShot(0, this, SLOT(do_open())); + return; + } + + isOpen = (activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active; + if (isOpen) + emit quitPendingWaitsForOpened(); + } else { + /* We seem to be active so inform caller */ + emit quitPendingWaitsForOpened(); + } +} + + +void QNetworkSessionPrivateImpl::do_open() +{ + icd_connection_flags flags = connectFlags; + bool st; + QString result; + QString iap = publicConfig.identifier(); + + if (state == QNetworkSession::Connected) { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Already connected to" << activeConfig.identifier(); +#endif + emit stateChanged(QNetworkSession::Connected); + emit quitPendingWaitsForOpened(); + return; + } + + Maemo::IcdConnectResult connect_result; + Maemo::Icd icd(ICD_LONG_CONNECT_TIMEOUT); + QNetworkConfiguration config; + if (publicConfig.type() == QNetworkConfiguration::UserChoice) + config = activeConfig; + else + config = publicConfig; + + if (iap == OSSO_IAP_ANY) { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "connecting to default IAP" << iap; +#endif + st = icd.connect(flags, connect_result); + + } else { + + QList params; + Maemo::ConnectParams param; + 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 = toIcdConfig(privateConfiguration(config))->network_id; + params.append(param); + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug("connecting to %s/%s/0x%x/%s/0x%x/%s", + param.connect.network_id.data(), + param.connect.network_type.toAscii().constData(), + param.connect.network_attrs, + param.connect.service_type.toAscii().constData(), + param.connect.service_attrs, + param.connect.service_id.toAscii().constData()); +#endif + st = icd.connect(flags, params, connect_result); + } + + if (st) { + result = connect_result.connect.network_id.data(); + QString connected_iap = result; + + if (connected_iap.isEmpty()) { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "connect to"<< iap << "failed, result is empty"; +#endif + updateState(QNetworkSession::Disconnected); + emit quitPendingWaitsForOpened(); + emit QNetworkSessionPrivate::error(QNetworkSession::InvalidConfigurationError); + if (publicConfig.type() == QNetworkConfiguration::UserChoice) + cleanupAnyConfiguration(); + return; + } + + /* If the user tried to connect to some specific connection (foo) + * and we were already connected to some other connection (bar), + * then we cannot activate this session although icd has a valid + * connection to somewhere. + */ + if ((publicConfig.type() != QNetworkConfiguration::UserChoice) && + (connected_iap != config.identifier())) { + updateState(QNetworkSession::Disconnected); + emit quitPendingWaitsForOpened(); + emit QNetworkSessionPrivate::error(QNetworkSession::InvalidConfigurationError); + return; + } + + + /* Did we connect to non saved IAP? */ + if (!(toIcdConfig(privateConfiguration(config))->network_attrs & ICD_NW_ATTR_IAPNAME)) { + /* Because the connection succeeded, the IAP is now known. + */ + 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(privateConfiguration(config)->id); + QString name = iap_name.value("name").toString(); + if (!name.isEmpty()) + privateConfiguration(config)->name = name; + + toIcdConfig(privateConfiguration(config))->iap_type = connect_result.connect.network_type; + + privateConfiguration(config)->isValid = true; + privateConfiguration(config)->state = QNetworkConfiguration::Active; + privateConfiguration(config)->type = QNetworkConfiguration::InternetAccessPoint; + + startTime = QDateTime::currentDateTime(); + updateState(QNetworkSession::Connected); + + currentNetworkInterface = get_network_interface(); + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "connected to" << result << config.name() << "at" << currentNetworkInterface; +#endif + + /* We first check if the configuration already exists in the manager + * and if it is not found there, we then insert it. Note that this + * is only done for user choice config only because it can be missing + * from config manager list. + */ + + if (publicConfig.type() == QNetworkConfiguration::UserChoice) { + if (!engine->accessPointConfigurations.contains(result)) { + engine->addSessionConfiguration(privateConfiguration(config)); + } else { + QNetworkConfigurationPrivatePointer priv = + engine->accessPointConfigurations.value(result); + QNetworkConfiguration reference; + setPrivateConfiguration(reference, priv); + copyConfig(config, reference, false); + config = reference; + activeConfig = reference; + engine->changedSessionConfiguration(privateConfiguration(config)); + } + } + + emit quitPendingWaitsForOpened(); + + } else { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "connect to"<< iap << "failed, status:" << connect_result.status; +#endif + updateState(QNetworkSession::Disconnected); + if (publicConfig.type() == QNetworkConfiguration::UserChoice) + cleanupAnyConfiguration(); + emit quitPendingWaitsForOpened(); + emit QNetworkSessionPrivate::error(QNetworkSession::UnknownSessionError); + } +} + + +void QNetworkSessionPrivateImpl::cleanupAnyConfiguration() +{ +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug()<<"Removing configuration created for" << activeConfig.identifier(); +#endif + activeConfig = publicConfig; +} + + +void QNetworkSessionPrivateImpl::close() +{ + if (serviceConfig.isValid()) { + lastError = QNetworkSession::OperationNotSupportedError; + emit QNetworkSessionPrivate::error(lastError); + } else if (isOpen) { + opened = false; + isOpen = false; + emit closed(); + } +} + + +void QNetworkSessionPrivateImpl::stop() +{ + if (serviceConfig.isValid()) { + lastError = QNetworkSession::OperationNotSupportedError; + emit QNetworkSessionPrivate::error(lastError); + } else { + if ((activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + state = QNetworkSession::Closing; + emit stateChanged(state); + + Maemo::Icd icd; +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "stopping session" << publicConfig.identifier(); +#endif + icd.disconnect(ICD_CONNECTION_FLAG_APPLICATION_EVENT); + startTime = QDateTime(); + + /* Note that the state will go disconnected in + * updateStateFromActiveConfig() which gets called after + * configurationChanged is emitted (below). + */ + + privateConfiguration(activeConfig)->state = QNetworkConfiguration::Discovered; + engine->changedSessionConfiguration(privateConfiguration(activeConfig)); + + opened = false; + isOpen = false; + + } else { + opened = false; + isOpen = false; + emit closed(); + } + } +} + + +void QNetworkSessionPrivateImpl::migrate() +{ + qWarning("This platform does not support roaming (%s).", __FUNCTION__); +} + + +void QNetworkSessionPrivateImpl::accept() +{ + qWarning("This platform does not support roaming (%s).", __FUNCTION__); +} + + +void QNetworkSessionPrivateImpl::ignore() +{ + qWarning("This platform does not support roaming (%s).", __FUNCTION__); +} + + +void QNetworkSessionPrivateImpl::reject() +{ + qWarning("This platform does not support roaming (%s).", __FUNCTION__); +} + + +QNetworkInterface QNetworkSessionPrivateImpl::currentInterface() const +{ + if (!publicConfig.isValid() || state != QNetworkSession::Connected) + return QNetworkInterface(); + + if (currentNetworkInterface.isEmpty()) + return QNetworkInterface(); + + return QNetworkInterface::interfaceFromName(currentNetworkInterface); +} + + +void QNetworkSessionPrivateImpl::setSessionProperty(const QString& key, const QVariant& value) +{ + if (value.isValid()) { + properties.insert(key, value); + + if (key == "ConnectInBackground") { + bool v = value.toBool(); + if (v) + connectFlags = ICD_CONNECTION_FLAG_APPLICATION_EVENT; + else + connectFlags = ICD_CONNECTION_FLAG_USER_EVENT; + } + } else { + properties.remove(key); + + /* Set default value when property is removed */ + if (key == "ConnectInBackground") + connectFlags = ICD_CONNECTION_FLAG_USER_EVENT; + } +} + + +QVariant QNetworkSessionPrivateImpl::sessionProperty(const QString& key) const +{ + return properties.value(key); +} + + +QString QNetworkSessionPrivateImpl::errorString() const +{ + QString errorStr; + switch(q->error()) { + case QNetworkSession::RoamingError: + errorStr = QObject::tr("Roaming error"); + break; + case QNetworkSession::SessionAbortedError: + errorStr = QObject::tr("Session aborted by user or system"); + break; + default: + case QNetworkSession::UnknownSessionError: + errorStr = QObject::tr("Unidentified Error"); + break; + } + return errorStr; +} + + +QNetworkSession::SessionError QNetworkSessionPrivateImpl::error() const +{ + return QNetworkSession::UnknownSessionError; +} + +#include "qnetworksession_impl.moc" + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/icd/qnetworksession_impl.h b/src/plugins/bearer/icd/qnetworksession_impl.h new file mode 100644 index 0000000..22e41b3 --- /dev/null +++ b/src/plugins/bearer/icd/qnetworksession_impl.h @@ -0,0 +1,147 @@ +/**************************************************************************** +** +** 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 QNETWORKSESSION_IMPL_H +#define QNETWORKSESSION_IMPL_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 +#include + +//#include "qnetworkconfigmanager_maemo_p.h" +//#include "qnetworksession.h" + +//#include +//#include +#include + +#include + +QT_BEGIN_NAMESPACE + +class QIcdEngine; + +class QNetworkSessionPrivateImpl : public QNetworkSessionPrivate +{ + Q_OBJECT + +public: + QNetworkSessionPrivateImpl(QIcdEngine *engine) + : engine(engine), connectFlags(ICD_CONNECTION_FLAG_USER_EVENT) + { + } + + ~QNetworkSessionPrivateImpl() + { + cleanupSession(); + } + + //called by QNetworkSession constructor and ensures + //that the state is immediately updated (w/o actually opening + //a session). Also this function should take care of + //notification hooks to discover future state changes. + void syncStateWithInterface(); + + QNetworkInterface currentInterface() const; + QVariant sessionProperty(const QString& key) const; + void setSessionProperty(const QString& key, const QVariant& value); + + void open(); + void close(); + void stop(); + + void migrate(); + void accept(); + void ignore(); + void reject(); + + QString errorString() const; //must return translated string + QNetworkSession::SessionError error() const; + + quint64 bytesWritten() const; + quint64 bytesReceived() const; + quint64 activeTime() const; + +private: + void updateStateFromServiceNetwork(); + void updateStateFromActiveConfig(); + +private Q_SLOTS: + void do_open(); + void networkConfigurationsChanged(); + void configurationChanged(const QNetworkConfiguration &config); + +private: + QNetworkConfigurationManager manager; + QIcdEngine *engine; + + QNetworkConfiguration& copyConfig(QNetworkConfiguration &fromConfig, QNetworkConfiguration &toConfig, bool deepCopy = true); + void clearConfiguration(QNetworkConfiguration &config); + void cleanupAnyConfiguration(); + + bool opened; + icd_connection_flags connectFlags; + + QNetworkSession::SessionError lastError; + + QDateTime startTime; + QString currentNetworkInterface; + friend class IcdListener; + void updateState(QNetworkSession::State); + void updateIdentifier(QString &newId); + quint64 getStatistics(bool sent) const; + void cleanupSession(void); +}; + +QT_END_NAMESPACE + +#endif //QNETWORKSESSIONPRIVATE_H + -- cgit v0.12 From 5f885bc5a294cd831f79b5570cb41f3cae2b8b19 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 11 Feb 2010 08:52:32 +1000 Subject: Fix networkAccessEnabled implementation. Move QDisabledNetworkReply to more appropriate source files. Return -1 from QDisabledNetworkReply::readData(). Always allow local access (via QNetworkAccessFileBackend). --- src/network/access/qnetworkaccessmanager.cpp | 47 +++------------------------- src/network/access/qnetworkreplyimpl.cpp | 24 ++++++++++++++ src/network/access/qnetworkreplyimpl_p.h | 14 +++++++++ 3 files changed, 43 insertions(+), 42 deletions(-) diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 7f36570..07a8b1d 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -57,7 +57,6 @@ #include "QtCore/qbuffer.h" #include "QtCore/qurl.h" #include "QtCore/qvector.h" -#include "QtCore/qcoreapplication.h" #include "QtNetwork/qauthenticator.h" #include "QtNetwork/qsslconfiguration.h" #include "QtNetwork/qnetworkconfigmanager.h" @@ -760,46 +759,6 @@ bool QNetworkAccessManager::networkAccessEnabled() const return d->networkAccessEnabled; } -class QDisabledNetworkReply : public QNetworkReply -{ - Q_OBJECT - -public: - QDisabledNetworkReply(QObject *parent, const QNetworkRequest &req, - const QNetworkAccessManager::Operation op); - ~QDisabledNetworkReply(); - - void abort() { } -protected: - qint64 readData(char *, qint64) { return 0; } -}; - -QDisabledNetworkReply::QDisabledNetworkReply(QObject *parent, - const QNetworkRequest &req, - QNetworkAccessManager::Operation op) -: QNetworkReply(parent) -{ - setRequest(req); - setUrl(req.url()); - setOperation(op); - - qRegisterMetaType("QNetworkReply::NetworkError"); - - QString msg = QCoreApplication::translate("QNetworkAccessManager", - "Network access is disabled."); - setError(UnknownNetworkError, msg); - - QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, - Q_ARG(QNetworkReply::NetworkError, UnknownNetworkError)); - QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); -} - -QDisabledNetworkReply::~QDisabledNetworkReply() -{ -} - -#include "qnetworkaccessmanager.moc" - /*! Returns a new QNetworkReply object to handle the operation \a op and request \a req. The device \a outgoingData is always 0 for Get and @@ -829,8 +788,12 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera return new QFileNetworkReply(this, req, op); } - if (!d->networkAccessEnabled) + // Return a disabled network reply if network access is disabled. + // Except if the scheme is empty or file://. + if (!d->networkAccessEnabled && !(req.url().scheme() == QLatin1String("file") || + req.url().scheme().isEmpty())) { return new QDisabledNetworkReply(this, req, op); + } QNetworkRequest request = req; if (!request.header(QNetworkRequest::ContentLengthHeader).isValid() && diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index 9721e32..3cf21f0 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -856,6 +856,30 @@ bool QNetworkReplyImplPrivate::migrateBackend() return true; } +QDisabledNetworkReply::QDisabledNetworkReply(QObject *parent, + const QNetworkRequest &req, + QNetworkAccessManager::Operation op) +: QNetworkReply(parent) +{ + setRequest(req); + setUrl(req.url()); + setOperation(op); + + qRegisterMetaType("QNetworkReply::NetworkError"); + + QString msg = QCoreApplication::translate("QNetworkAccessManager", + "Network access is disabled."); + setError(UnknownNetworkError, msg); + + QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, + Q_ARG(QNetworkReply::NetworkError, UnknownNetworkError)); + QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); +} + +QDisabledNetworkReply::~QDisabledNetworkReply() +{ +} + QT_END_NAMESPACE #include "moc_qnetworkreplyimpl_p.cpp" diff --git a/src/network/access/qnetworkreplyimpl_p.h b/src/network/access/qnetworkreplyimpl_p.h index 89b976f..639361e 100644 --- a/src/network/access/qnetworkreplyimpl_p.h +++ b/src/network/access/qnetworkreplyimpl_p.h @@ -193,6 +193,20 @@ public: Q_DECLARE_PUBLIC(QNetworkReplyImpl) }; +class QDisabledNetworkReply : public QNetworkReply +{ + Q_OBJECT + +public: + QDisabledNetworkReply(QObject *parent, const QNetworkRequest &req, + const QNetworkAccessManager::Operation op); + ~QDisabledNetworkReply(); + + void abort() { } +protected: + qint64 readData(char *, qint64) { return -1; } +}; + QT_END_NAMESPACE #endif -- cgit v0.12 From d7cf6d018f39607ff7315b7851665e72fc488e62 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 11 Feb 2010 09:23:55 +1000 Subject: Connect signals between QNAM and QNetworkReplyImpl. Instead of iterating over children, when network session state changes. --- src/network/access/qnetworkaccessmanager.cpp | 36 ++++------------------------ src/network/access/qnetworkaccessmanager.h | 2 ++ src/network/access/qnetworkreplyimpl.cpp | 20 ++++++++++++++++ src/network/access/qnetworkreplyimpl_p.h | 2 ++ 4 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 07a8b1d..e57702b 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -811,6 +811,8 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera // first step: create the reply QUrl url = request.url(); QNetworkReplyImpl *reply = new QNetworkReplyImpl(this); + if (req.url().scheme() != QLatin1String("file") && !req.url().scheme().isEmpty()) + connect(this, SIGNAL(networkSessionOnline()), reply, SLOT(_q_networkSessionOnline())); QNetworkReplyImplPrivate *priv = reply->d_func(); priv->manager = this; @@ -1131,12 +1133,7 @@ void QNetworkAccessManagerPrivate::_q_sessionOpened() { Q_Q(QNetworkAccessManager); - // start waiting children - foreach (QObject *child, q->children()) { - QNetworkReplyImpl *reply = qobject_cast(child); - if (reply && reply->d_func()->state == QNetworkReplyImplPrivate::WaitingForSession) - QMetaObject::invokeMethod(reply, "_q_startOperation", Qt::QueuedConnection); - } + emit q->networkSessionOnline(); } void QNetworkAccessManagerPrivate::_q_sessionClosed() @@ -1183,37 +1180,14 @@ void QNetworkAccessManagerPrivate::_q_sessionNewConfigurationActivated() qDebug() << "Accepting new configuration."; session->accept(); - foreach (QObject *child, q->children()) { - QNetworkReplyImpl *reply = qobject_cast(child); - if (!reply) - continue; - - switch (reply->d_func()->state) { - case QNetworkReplyImplPrivate::Buffering: - case QNetworkReplyImplPrivate::Working: - case QNetworkReplyImplPrivate::Reconnecting: - // Migrate existing downloads to new configuration. - reply->d_func()->migrateBackend(); - break; - case QNetworkReplyImplPrivate::WaitingForSession: - // Start waiting requests. - QMetaObject::invokeMethod(reply, "_q_startOperation", Qt::QueuedConnection); - break; - default: - qDebug() << "How do we handle replies in state" << reply->d_func()->state; - } - } + emit q->networkSessionOnline(); } void QNetworkAccessManagerPrivate::_q_sessionPreferredConfigurationChanged(const QNetworkConfiguration &, bool) { Q_Q(QNetworkAccessManager); - foreach (QObject *child, q->children()) { - QNetworkReplyImpl *replyImpl = qobject_cast(child); - if (replyImpl) - replyImpl->migrateBackend(); - } + emit q->networkSessionOnline(); session->migrate(); } diff --git a/src/network/access/qnetworkaccessmanager.h b/src/network/access/qnetworkaccessmanager.h index 371f729..f934b22 100644 --- a/src/network/access/qnetworkaccessmanager.h +++ b/src/network/access/qnetworkaccessmanager.h @@ -124,6 +124,8 @@ Q_SIGNALS: void sslErrors(QNetworkReply *reply, const QList &errors); #endif + void networkSessionOnline(); + void networkAccessChanged(bool enabled); void debugMessage(const QString &message); diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index 3cf21f0..a7948c2 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -226,6 +226,26 @@ void QNetworkReplyImplPrivate::_q_bufferOutgoingData() } } +void QNetworkReplyImplPrivate::_q_networkSessionOnline() +{ + Q_Q(QNetworkReplyImpl); + + switch (state) { + case QNetworkReplyImplPrivate::Buffering: + case QNetworkReplyImplPrivate::Working: + case QNetworkReplyImplPrivate::Reconnecting: + // Migrate existing downloads to new network connection. + migrateBackend(); + break; + case QNetworkReplyImplPrivate::WaitingForSession: + // Start waiting requests. + QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); + break; + default: + qDebug() << "How do we handle replies in state" << state; + } +} + void QNetworkReplyImplPrivate::setup(QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice *data) { diff --git a/src/network/access/qnetworkreplyimpl_p.h b/src/network/access/qnetworkreplyimpl_p.h index 639361e..9941fa7 100644 --- a/src/network/access/qnetworkreplyimpl_p.h +++ b/src/network/access/qnetworkreplyimpl_p.h @@ -100,6 +100,7 @@ public: Q_PRIVATE_SLOT(d_func(), void _q_copyReadChannelFinished()) Q_PRIVATE_SLOT(d_func(), void _q_bufferOutgoingData()) Q_PRIVATE_SLOT(d_func(), void _q_bufferOutgoingDataFinished()) + Q_PRIVATE_SLOT(d_func(), void _q_networkSessionOnline()) }; class QNetworkReplyImplPrivate: public QNetworkReplyPrivate @@ -132,6 +133,7 @@ public: void _q_copyReadChannelFinished(); void _q_bufferOutgoingData(); void _q_bufferOutgoingDataFinished(); + void _q_networkSessionOnline(); void setup(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *outgoingData); -- cgit v0.12 From 024b86bce25511aeb4b0f935e36ec43c52c802ca Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 11 Feb 2010 09:51:30 +1000 Subject: Remove functions used for testing. --- src/network/access/qnetworkreply.h | 2 -- src/network/access/qnetworkreplyimpl.cpp | 7 ------- src/network/access/qnetworkreplyimpl_p.h | 2 -- 3 files changed, 11 deletions(-) diff --git a/src/network/access/qnetworkreply.h b/src/network/access/qnetworkreply.h index 0f1fe8a..b39557a 100644 --- a/src/network/access/qnetworkreply.h +++ b/src/network/access/qnetworkreply.h @@ -138,8 +138,6 @@ public: void ignoreSslErrors(const QList &errors); #endif - virtual void migrateBackend() { qWarning("Your backend doesn't support migration!"); } // Testing - public Q_SLOTS: virtual void ignoreSslErrors(); diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index a7948c2..b9206be 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -805,13 +805,6 @@ bool QNetworkReplyImpl::event(QEvent *e) return QObject::event(e); } -void QNetworkReplyImpl::migrateBackend() -{ - Q_D(QNetworkReplyImpl); - - d->migrateBackend(); -} - bool QNetworkReplyImplPrivate::migrateBackend() { Q_Q(QNetworkReplyImpl); diff --git a/src/network/access/qnetworkreplyimpl_p.h b/src/network/access/qnetworkreplyimpl_p.h index 9941fa7..7f1ee80 100644 --- a/src/network/access/qnetworkreplyimpl_p.h +++ b/src/network/access/qnetworkreplyimpl_p.h @@ -92,8 +92,6 @@ public: Q_INVOKABLE virtual void ignoreSslErrorsImplementation(const QList &errors); #endif - void migrateBackend(); - Q_DECLARE_PRIVATE(QNetworkReplyImpl) Q_PRIVATE_SLOT(d_func(), void _q_startOperation()) Q_PRIVATE_SLOT(d_func(), void _q_copyReadyRead()) -- cgit v0.12 From 70fc1c298b957b54d498b518ddf786694d3001cc Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 11 Feb 2010 09:54:14 +1000 Subject: Clarify TemporaryNetworkFailureError docs. --- src/network/access/qnetworkreply.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/network/access/qnetworkreply.cpp b/src/network/access/qnetworkreply.cpp index e299b5b..dd5cace 100644 --- a/src/network/access/qnetworkreply.cpp +++ b/src/network/access/qnetworkreply.cpp @@ -127,7 +127,8 @@ QNetworkReplyPrivate::QNetworkReplyPrivate() \value TemporaryNetworkFailureError the connection was broken due to disconnection from the network, however the system has initiated - roaming to another access point. The request should be resubmitted. + roaming to another access point. The request should be resubmitted + and will be processed as soon as the connection is re-established. \value ProxyConnectionRefusedError the connection to the proxy server was refused (the proxy server is not accepting requests) -- cgit v0.12 From 47b96ccf100da33910cbc534035c00aa4b2b533d Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 11 Feb 2010 10:15:03 +1000 Subject: Don't try to migrate finished or aborted requests. --- src/network/access/qnetworkreplyimpl.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index b9206be..f4e8264 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -573,7 +573,11 @@ void QNetworkReplyImplPrivate::finished() qDebug() << "Download hasn't finished"; if (migrateBackend()) { - return; + // either we are migrating or the request is finished/aborted + if (state == Reconnecting) { + resumeNotificationHandling(); + return; // exit early if we are migrating. + } } else { qDebug() << "Could not migrate backend, application needs to send another requeset."; error(QNetworkReply::TemporaryNetworkFailureError, q->tr("Temporary network failure.")); @@ -812,7 +816,7 @@ bool QNetworkReplyImplPrivate::migrateBackend() if (state == QNetworkReplyImplPrivate::Finished || state == QNetworkReplyImplPrivate::Aborted) { qDebug() << "Network reply is already finished/aborted."; - return false; + return true; } if (!qobject_cast(backend)) { -- cgit v0.12 From 20cffd52ab81d01ca0a45058dfa894df9ce26c5a Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 11 Feb 2010 10:27:32 +1000 Subject: Move check for range header support to before deleting backend. --- src/network/access/qnetworkreplyimpl.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index f4e8264..70bf238 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -829,6 +829,12 @@ bool QNetworkReplyImplPrivate::migrateBackend() return false; } + RawHeadersList::ConstIterator it = findRawHeader("Accept-Ranges"); + if (it == rawHeaders.constEnd() || it->second == "none") { + qDebug() << "Range header not supported by server/resource."; + return false; + } + qDebug() << "Need to check for only cacheable content."; // stop both upload and download @@ -844,12 +850,6 @@ bool QNetworkReplyImplPrivate::migrateBackend() backend = 0; } - RawHeadersList::ConstIterator it = findRawHeader("Accept-Ranges"); - if (it == rawHeaders.constEnd() || it->second == "none") { - qDebug() << "Range header not supported by server/resource."; - return false; - } - cookedHeaders.clear(); rawHeaders.clear(); -- cgit v0.12 From 329572a097e529b0ee330097d31212b091975180 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 11 Feb 2010 10:32:29 +1000 Subject: Add comments to private state enums. --- src/network/access/qnetworkreplyimpl_p.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/network/access/qnetworkreplyimpl_p.h b/src/network/access/qnetworkreplyimpl_p.h index 7f1ee80..ec413cc 100644 --- a/src/network/access/qnetworkreplyimpl_p.h +++ b/src/network/access/qnetworkreplyimpl_p.h @@ -111,13 +111,13 @@ public: }; enum State { - Idle, - Buffering, - Working, - Finished, - Aborted, - WaitingForSession, - Reconnecting + Idle, // The reply is idle. + Buffering, // The reply is buffering outgoing data. + Working, // The reply is uploading/downloading data. + Finished, // The reply has finished. + Aborted, // The reply has been aborted. + WaitingForSession, // The reply is waiting for the session to open before connecting. + Reconnecting // The reply will reconnect to once roaming has completed. }; typedef QQueue NotificationQueue; -- cgit v0.12 From 02df547ddf8aabb680511135f98a5188438de6d4 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 11 Feb 2010 11:02:47 +1000 Subject: Rename and remove unused private slots. --- src/network/access/qnetworkaccessbackend.cpp | 5 +- src/network/access/qnetworkaccessmanager.cpp | 86 ++++++---------------------- src/network/access/qnetworkaccessmanager.h | 8 +-- src/network/access/qnetworkaccessmanager_p.h | 13 ++--- src/network/access/qnetworkreplyimpl.cpp | 4 +- 5 files changed, 31 insertions(+), 85 deletions(-) diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp index 0bfeb3b..1d23cdc 100644 --- a/src/network/access/qnetworkaccessbackend.cpp +++ b/src/network/access/qnetworkaccessbackend.cpp @@ -349,7 +349,7 @@ void QNetworkAccessBackend::sslErrors(const QList &errors) */ bool QNetworkAccessBackend::start() { - if (!manager->session) { + if (!manager->networkSession) { open(); return true; } @@ -364,7 +364,8 @@ bool QNetworkAccessBackend::start() return true; } - if (manager->session->isOpen() && manager->session->state() == QNetworkSession::Connected) { + if (manager->networkSession->isOpen() && + manager->networkSession->state() == QNetworkSession::Connected) { open(); return true; } diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index e57702b..3324e09 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -715,8 +715,8 @@ QNetworkConfiguration QNetworkAccessManager::configuration() const { Q_D(const QNetworkAccessManager); - if (d->session) - return d->session->configuration(); + if (d->networkSession) + return d->networkSession->configuration(); else return QNetworkConfiguration(); } @@ -732,11 +732,11 @@ QNetworkConfiguration QNetworkAccessManager::activeConfiguration() const { Q_D(const QNetworkAccessManager); - if (d->session) { + if (d->networkSession) { QNetworkConfigurationManager manager; return manager.configurationFromIdentifier( - d->session->sessionProperty(QLatin1String("ActiveConfiguration")).toString()); + d->networkSession->sessionProperty(QLatin1String("ActiveConfiguration")).toString()); } else { return QNetworkConfiguration(); } @@ -1107,89 +1107,41 @@ void QNetworkAccessManagerPrivate::createSession(const QNetworkConfiguration &co { Q_Q(QNetworkAccessManager); - if (session) - delete session; + if (networkSession) + delete networkSession; if (!config.isValid()) { - session = 0; + networkSession = 0; return; } - session = new QNetworkSession(config, q); - - QObject::connect(session, SIGNAL(opened()), q, SLOT(_q_sessionOpened())); - QObject::connect(session, SIGNAL(closed()), q, SLOT(_q_sessionClosed())); - QObject::connect(session, SIGNAL(stateChanged(QNetworkSession::State)), - q, SLOT(_q_sessionStateChanged(QNetworkSession::State))); - QObject::connect(session, SIGNAL(error(QNetworkSession::SessionError)), - q, SLOT(_q_sessionError(QNetworkSession::SessionError))); - QObject::connect(session, SIGNAL(newConfigurationActivated()), - q, SLOT(_q_sessionNewConfigurationActivated())); - QObject::connect(session, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool)), - q, SLOT(_q_sessionPreferredConfigurationChanged(QNetworkConfiguration,bool))); -} - -void QNetworkAccessManagerPrivate::_q_sessionOpened() -{ - Q_Q(QNetworkAccessManager); - - emit q->networkSessionOnline(); -} - -void QNetworkAccessManagerPrivate::_q_sessionClosed() -{ - Q_Q(QNetworkAccessManager); - - emit q->debugMessage(QLatin1String("Session Closed")); -} + networkSession = new QNetworkSession(config, q); -void QNetworkAccessManagerPrivate::_q_sessionError(QNetworkSession::SessionError error) -{ - Q_Q(QNetworkAccessManager); - - emit q->debugMessage(QString::fromLatin1("Session error %1").arg(error)); -} - -void QNetworkAccessManagerPrivate::_q_sessionStateChanged(QNetworkSession::State state) -{ - qDebug() << "session state changed to" << state; + QObject::connect(networkSession, SIGNAL(opened()), q, SIGNAL(networkSessionOnline())); + QObject::connect(networkSession, SIGNAL(newConfigurationActivated()), + q, SLOT(_q_networkSessionNewConfigurationActivated())); + QObject::connect(networkSession, + SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool)), + q, + SLOT(_q_networkSessionPreferredConfigurationChanged(QNetworkConfiguration,bool))); } -void QNetworkAccessManagerPrivate::_q_sessionNewConfigurationActivated() +void QNetworkAccessManagerPrivate::_q_networkSessionNewConfigurationActivated() { Q_Q(QNetworkAccessManager); -#if 0 - foreach (QObject *child, q->children()) { - QNetworkReplyImpl *reply = qobject_cast(child); - if (reply) { - switch (reply->d_func()->state) { - case QNetworkReplyImplPrivate::Buffering: - case QNetworkReplyImplPrivate::Working: - emit q->debugMessage(QString::fromLatin1("Unexpected reply for %1") - .arg(reply->url().toString())); - break; - default: - qDebug() << "Testing new interface for" << reply->url(); - ; - } - } - } -#endif - - qDebug() << "Accepting new configuration."; - session->accept(); + networkSession->accept(); emit q->networkSessionOnline(); } -void QNetworkAccessManagerPrivate::_q_sessionPreferredConfigurationChanged(const QNetworkConfiguration &, bool) +void QNetworkAccessManagerPrivate::_q_networkSessionPreferredConfigurationChanged(const QNetworkConfiguration &, bool) { Q_Q(QNetworkAccessManager); emit q->networkSessionOnline(); - session->migrate(); + networkSession->migrate(); } QT_END_NAMESPACE diff --git a/src/network/access/qnetworkaccessmanager.h b/src/network/access/qnetworkaccessmanager.h index f934b22..a0aa2d8 100644 --- a/src/network/access/qnetworkaccessmanager.h +++ b/src/network/access/qnetworkaccessmanager.h @@ -139,12 +139,8 @@ private: Q_DECLARE_PRIVATE(QNetworkAccessManager) Q_PRIVATE_SLOT(d_func(), void _q_replyFinished()) Q_PRIVATE_SLOT(d_func(), void _q_replySslErrors(QList)) - Q_PRIVATE_SLOT(d_func(), void _q_sessionOpened()) - Q_PRIVATE_SLOT(d_func(), void _q_sessionClosed()) - Q_PRIVATE_SLOT(d_func(), void _q_sessionError(QNetworkSession::SessionError)) - Q_PRIVATE_SLOT(d_func(), void _q_sessionStateChanged(QNetworkSession::State)) - Q_PRIVATE_SLOT(d_func(), void _q_sessionNewConfigurationActivated()) - Q_PRIVATE_SLOT(d_func(), void _q_sessionPreferredConfigurationChanged(QNetworkConfiguration,bool)) + Q_PRIVATE_SLOT(d_func(), void _q_networkSessionNewConfigurationActivated()) + Q_PRIVATE_SLOT(d_func(), void _q_networkSessionPreferredConfigurationChanged(QNetworkConfiguration,bool)) }; QT_END_NAMESPACE diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h index eae08e8..0ac49db 100644 --- a/src/network/access/qnetworkaccessmanager_p.h +++ b/src/network/access/qnetworkaccessmanager_p.h @@ -76,7 +76,7 @@ public: proxyFactory(0), #endif cookieJarCreated(false), - session(0), + networkSession(0), networkAccessEnabled(true) { } ~QNetworkAccessManagerPrivate(); @@ -110,12 +110,9 @@ public: void createSession(const QNetworkConfiguration &config); - void _q_sessionOpened(); - void _q_sessionClosed(); - void _q_sessionError(QNetworkSession::SessionError error); - void _q_sessionStateChanged(QNetworkSession::State state); - void _q_sessionNewConfigurationActivated(); - void _q_sessionPreferredConfigurationChanged(const QNetworkConfiguration &config, bool isSeamless); + void _q_networkSessionNewConfigurationActivated(); + void _q_networkSessionPreferredConfigurationChanged(const QNetworkConfiguration &config, + bool isSeamless); // this is the cache for storing downloaded files QAbstractNetworkCache *networkCache; @@ -130,7 +127,7 @@ public: bool cookieJarCreated; - QNetworkSession *session; + QNetworkSession *networkSession; bool networkAccessEnabled; // this cache can be used by individual backends to cache e.g. their TCP connections to a server diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index 70bf238..afa7307 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -89,7 +89,7 @@ void QNetworkReplyImplPrivate::_q_startOperation() // state changes. state = WaitingForSession; - QNetworkSession *session = manager->d_func()->session; + QNetworkSession *session = manager->d_func()->networkSession; if (session) { if (!session->isOpen()) @@ -559,7 +559,7 @@ void QNetworkReplyImplPrivate::finished() QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); if (preMigrationDownloaded != Q_INT64_C(-1)) totalSize = totalSize.toLongLong() + preMigrationDownloaded; - QNetworkSession *session = manager->d_func()->session; + QNetworkSession *session = manager->d_func()->networkSession; if (session && session->state() == QNetworkSession::Roaming && state == Working && errorCode != QNetworkReply::OperationCanceledError) { // only content with a known size will fail with a temporary network failure error -- cgit v0.12 From 12b70a4c52f57255da9586a0f92324557d400c8e Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 11 Feb 2010 11:12:15 +1000 Subject: Remove debug. --- src/network/access/qnetworkaccessmanager.h | 2 -- src/network/access/qnetworkaccessmanager_p.h | 6 ------ 2 files changed, 8 deletions(-) diff --git a/src/network/access/qnetworkaccessmanager.h b/src/network/access/qnetworkaccessmanager.h index a0aa2d8..6fdb678 100644 --- a/src/network/access/qnetworkaccessmanager.h +++ b/src/network/access/qnetworkaccessmanager.h @@ -128,8 +128,6 @@ Q_SIGNALS: void networkAccessChanged(bool enabled); - void debugMessage(const QString &message); - protected: virtual QNetworkReply *createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData = 0); diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h index 0ac49db..568894c 100644 --- a/src/network/access/qnetworkaccessmanager_p.h +++ b/src/network/access/qnetworkaccessmanager_p.h @@ -102,12 +102,6 @@ public: QNetworkAccessBackend *findBackend(QNetworkAccessManager::Operation op, const QNetworkRequest &request); - void sendDebugMessage(const QString &message) - { - Q_Q(QNetworkAccessManager); - emit q->debugMessage(message); - } - void createSession(const QNetworkConfiguration &config); void _q_networkSessionNewConfigurationActivated(); -- cgit v0.12 From c2b9767dfc0fb2f26ff52bdded36c76c0a23f938 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 11 Feb 2010 12:42:42 +1000 Subject: Fix after reworking to use signals/slots. --- src/network/access/qnetworkaccessmanager.cpp | 2 -- src/network/access/qnetworkreplyimpl.cpp | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 3324e09..9c1e268 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -1139,8 +1139,6 @@ void QNetworkAccessManagerPrivate::_q_networkSessionPreferredConfigurationChange { Q_Q(QNetworkAccessManager); - emit q->networkSessionOnline(); - networkSession->migrate(); } diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index afa7307..81d4d0d 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -574,7 +574,7 @@ void QNetworkReplyImplPrivate::finished() if (migrateBackend()) { // either we are migrating or the request is finished/aborted - if (state == Reconnecting) { + if (state == Reconnecting || state == WaitingForSession) { resumeNotificationHandling(); return; // exit early if we are migrating. } -- cgit v0.12 From f16733d41b8377a703c594b069cc592466e03a11 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 11 Feb 2010 13:38:15 +1000 Subject: We don't need to migrate cached replies. --- src/network/access/qnetworkreplyimpl.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index 81d4d0d..7f12fb8 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -829,6 +829,11 @@ bool QNetworkReplyImplPrivate::migrateBackend() return false; } + if (copyDevice) { + qDebug() << "Request is serviced from cache, not migrating."; + return true; + } + RawHeadersList::ConstIterator it = findRawHeader("Accept-Ranges"); if (it == rawHeaders.constEnd() || it->second == "none") { qDebug() << "Range header not supported by server/resource."; @@ -837,12 +842,6 @@ bool QNetworkReplyImplPrivate::migrateBackend() qDebug() << "Need to check for only cacheable content."; - // stop both upload and download - if (outgoingData) - outgoingData->disconnect(q); - if (copyDevice) - copyDevice->disconnect(q); - state = QNetworkReplyImplPrivate::Reconnecting; if (backend) { -- cgit v0.12 From 0f99aa42829c1d1b29dfbd8945cc96b0d21b3939 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 11 Feb 2010 13:49:52 +1000 Subject: Update copyright year to 2010. --- src/network/bearer/qbearerengine.cpp | 2 +- src/network/bearer/qbearerplugin.cpp | 2 +- src/network/bearer/qnetworkconfigmanager.h | 2 +- src/network/bearer/qnetworkconfiguration.h | 2 +- src/network/bearer/qnetworksession.h | 2 +- src/plugins/bearer/corewlan/main.cpp | 2 +- src/plugins/bearer/generic/main.cpp | 2 +- src/plugins/bearer/icd/qnetworksession_impl.h | 4 ++-- src/plugins/bearer/nativewifi/main.cpp | 2 +- src/plugins/bearer/nativewifi/platformdefs.h | 2 +- src/plugins/bearer/networkmanager/main.cpp | 2 +- src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp | 2 +- src/plugins/bearer/networkmanager/qnetworkmanagerservice.h | 2 +- src/plugins/bearer/networkmanager/qnmdbushelper.cpp | 2 +- src/plugins/bearer/networkmanager/qnmdbushelper.h | 2 +- src/plugins/bearer/nla/main.cpp | 2 +- src/plugins/bearer/platformdefs_win.h | 2 +- src/plugins/bearer/symbian/main.cpp | 2 +- src/plugins/bearer/symbian/qnetworksession_impl.cpp | 2 +- src/plugins/bearer/symbian/qnetworksession_impl.h | 2 +- 20 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/network/bearer/qbearerengine.cpp b/src/network/bearer/qbearerengine.cpp index 4d56047..bd2ca6c 100644 --- a/src/network/bearer/qbearerengine.cpp +++ b/src/network/bearer/qbearerengine.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/qbearerplugin.cpp b/src/network/bearer/qbearerplugin.cpp index 7b81b13..2ee90d4 100644 --- a/src/network/bearer/qbearerplugin.cpp +++ b/src/network/bearer/qbearerplugin.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/qnetworkconfigmanager.h b/src/network/bearer/qnetworkconfigmanager.h index b7ab72b..83c4939 100644 --- a/src/network/bearer/qnetworkconfigmanager.h +++ b/src/network/bearer/qnetworkconfigmanager.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/qnetworkconfiguration.h b/src/network/bearer/qnetworkconfiguration.h index dede2b1..8d45cf6 100644 --- a/src/network/bearer/qnetworkconfiguration.h +++ b/src/network/bearer/qnetworkconfiguration.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.h b/src/network/bearer/qnetworksession.h index 6138166..06d5eb7 100644 --- a/src/network/bearer/qnetworksession.h +++ b/src/network/bearer/qnetworksession.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/plugins/bearer/corewlan/main.cpp b/src/plugins/bearer/corewlan/main.cpp index ce0611e..010976a 100644 --- a/src/plugins/bearer/corewlan/main.cpp +++ b/src/plugins/bearer/corewlan/main.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/plugins/bearer/generic/main.cpp b/src/plugins/bearer/generic/main.cpp index a7df023..8ba9f40 100644 --- a/src/plugins/bearer/generic/main.cpp +++ b/src/plugins/bearer/generic/main.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/plugins/bearer/icd/qnetworksession_impl.h b/src/plugins/bearer/icd/qnetworksession_impl.h index 22e41b3..b7461dc 100644 --- a/src/plugins/bearer/icd/qnetworksession_impl.h +++ b/src/plugins/bearer/icd/qnetworksession_impl.h @@ -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 diff --git a/src/plugins/bearer/nativewifi/main.cpp b/src/plugins/bearer/nativewifi/main.cpp index 64ed73d..6bb2a2b 100644 --- a/src/plugins/bearer/nativewifi/main.cpp +++ b/src/plugins/bearer/nativewifi/main.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/plugins/bearer/nativewifi/platformdefs.h b/src/plugins/bearer/nativewifi/platformdefs.h index 38fbae4..57ae852 100644 --- a/src/plugins/bearer/nativewifi/platformdefs.h +++ b/src/plugins/bearer/nativewifi/platformdefs.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/plugins/bearer/networkmanager/main.cpp b/src/plugins/bearer/networkmanager/main.cpp index b561415..6725252 100644 --- a/src/plugins/bearer/networkmanager/main.cpp +++ b/src/plugins/bearer/networkmanager/main.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/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp index 3843f27..9d603b5 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.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/plugins/bearer/networkmanager/qnetworkmanagerservice.h b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h index dbed01e..81903ec 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.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/plugins/bearer/networkmanager/qnmdbushelper.cpp b/src/plugins/bearer/networkmanager/qnmdbushelper.cpp index f93a63d..d5e20f3 100644 --- a/src/plugins/bearer/networkmanager/qnmdbushelper.cpp +++ b/src/plugins/bearer/networkmanager/qnmdbushelper.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/plugins/bearer/networkmanager/qnmdbushelper.h b/src/plugins/bearer/networkmanager/qnmdbushelper.h index 410b69f..862290c 100644 --- a/src/plugins/bearer/networkmanager/qnmdbushelper.h +++ b/src/plugins/bearer/networkmanager/qnmdbushelper.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/plugins/bearer/nla/main.cpp b/src/plugins/bearer/nla/main.cpp index 541d2c5..54269a4 100644 --- a/src/plugins/bearer/nla/main.cpp +++ b/src/plugins/bearer/nla/main.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/plugins/bearer/platformdefs_win.h b/src/plugins/bearer/platformdefs_win.h index f2f44a1..37d099c 100644 --- a/src/plugins/bearer/platformdefs_win.h +++ b/src/plugins/bearer/platformdefs_win.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/plugins/bearer/symbian/main.cpp b/src/plugins/bearer/symbian/main.cpp index 22d654a..37eddee 100644 --- a/src/plugins/bearer/symbian/main.cpp +++ b/src/plugins/bearer/symbian/main.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/plugins/bearer/symbian/qnetworksession_impl.cpp b/src/plugins/bearer/symbian/qnetworksession_impl.cpp index 619fd9f..7762fb5 100644 --- a/src/plugins/bearer/symbian/qnetworksession_impl.cpp +++ b/src/plugins/bearer/symbian/qnetworksession_impl.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/plugins/bearer/symbian/qnetworksession_impl.h b/src/plugins/bearer/symbian/qnetworksession_impl.h index 2e75d96..30f51e1 100644 --- a/src/plugins/bearer/symbian/qnetworksession_impl.h +++ b/src/plugins/bearer/symbian/qnetworksession_impl.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) ** -- cgit v0.12 From 0f90f7bdef4b8f821b00e039038fb83a01bc217b Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 11 Feb 2010 14:07:05 +1000 Subject: Remove debug. --- src/network/access/qnetworkreplyimpl.cpp | 49 ++++++++-------------- .../bearer/nativewifi/qnativewifiengine.cpp | 2 +- .../networkmanager/qnetworkmanagerengine.cpp | 10 +---- .../networkmanager/qnetworkmanagerservice.cpp | 1 - src/plugins/bearer/nla/qnlaengine.cpp | 4 +- src/plugins/bearer/qnetworksession_impl.cpp | 2 - src/plugins/bearer/symbian/symbianengine.cpp | 1 - 7 files changed, 21 insertions(+), 48 deletions(-) diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index 7f12fb8..7f66b25 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -242,7 +242,7 @@ void QNetworkReplyImplPrivate::_q_networkSessionOnline() QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); break; default: - qDebug() << "How do we handle replies in state" << state; + ; } } @@ -503,8 +503,6 @@ void QNetworkReplyImplPrivate::appendDownstreamData(QByteDataBuffer &data) int index = it->second.lastIndexOf('/'); if (index != -1) totalSize = it->second.mid(index + 1).toLongLong() - preMigrationDownloaded; - } else { - qDebug() << "Could not find Content-Length or Content-Range header"; } } @@ -564,14 +562,7 @@ void QNetworkReplyImplPrivate::finished() state == Working && errorCode != QNetworkReply::OperationCanceledError) { // only content with a known size will fail with a temporary network failure error if (!totalSize.isNull()) { - qDebug() << "Connection broke during download."; - qDebug() << "Don't worry, we've already started roaming :)"; - - if (bytesDownloaded == totalSize) { - qDebug() << "Luckily download has already finished."; - } else { - qDebug() << "Download hasn't finished"; - + if (bytesDownloaded != totalSize) { if (migrateBackend()) { // either we are migrating or the request is finished/aborted if (state == Reconnecting || state == WaitingForSession) { @@ -579,8 +570,8 @@ void QNetworkReplyImplPrivate::finished() return; // exit early if we are migrating. } } else { - qDebug() << "Could not migrate backend, application needs to send another requeset."; - error(QNetworkReply::TemporaryNetworkFailureError, q->tr("Temporary network failure.")); + error(QNetworkReply::TemporaryNetworkFailureError, + q->tr("Temporary network failure.")); } } } @@ -809,38 +800,34 @@ bool QNetworkReplyImpl::event(QEvent *e) return QObject::event(e); } +/* + Migrates the backend of the QNetworkReply to a new network connection if required. Returns + true if the reply is migrated or it is not required; otherwise returns false. +*/ bool QNetworkReplyImplPrivate::migrateBackend() { Q_Q(QNetworkReplyImpl); - if (state == QNetworkReplyImplPrivate::Finished || - state == QNetworkReplyImplPrivate::Aborted) { - qDebug() << "Network reply is already finished/aborted."; + // Network reply is already finished or aborted, don't need to migrate. + if (state == Finished || state == Aborted) return true; - } - if (!qobject_cast(backend)) { - qDebug() << "Resume only support by http backend, not migrating."; + // Resume only supported by http backend, not migrating. + if (!qobject_cast(backend)) return false; - } - if (outgoingData) { - qDebug() << "Request has outgoing data, not migrating."; + // Request has outgoing data, not migrating. + if (outgoingData) return false; - } - if (copyDevice) { - qDebug() << "Request is serviced from cache, not migrating."; + // Request is serviced from the cache, don't need to migrate. + if (copyDevice) return true; - } + // Range header is not supported by server/resource, can't migrate. RawHeadersList::ConstIterator it = findRawHeader("Accept-Ranges"); - if (it == rawHeaders.constEnd() || it->second == "none") { - qDebug() << "Range header not supported by server/resource."; + if (it == rawHeaders.constEnd() || it->second == "none") return false; - } - - qDebug() << "Need to check for only cacheable content."; state = QNetworkReplyImplPrivate::Reconnecting; diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp index d88534b..e4ab0aa 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp @@ -72,7 +72,7 @@ void qNotificationCallback(WLAN_NOTIFICATION_DATA *data, QNativeWifiEngine *d) QMetaObject::invokeMethod(d, "scanComplete", Qt::QueuedConnection); break; default: - qDebug() << "wlan unknown notification"; + ; } } diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp index 51afe3e..3f3e1bd 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp @@ -134,9 +134,6 @@ QString QNetworkManagerEngine::getInterfaceFromId(const QString &id) if (devices.isEmpty()) continue; - if (devices.count() > 1) - qDebug() << "multiple network interfaces for" << id; - QNetworkManagerInterfaceDevice device(devices.at(0).path()); return device.interface().name(); } @@ -328,8 +325,6 @@ void QNetworkManagerEngine::activeConnectionPropertiesChanged(const QString &pat void QNetworkManagerEngine::devicePropertiesChanged(const QString &path, const QMap &properties) { - qDebug() << Q_FUNC_INFO << path; - qDebug() << properties; } void QNetworkManagerEngine::deviceAdded(const QDBusObjectPath &path) @@ -428,7 +423,6 @@ void QNetworkManagerEngine::updateConnection(const QNmSettingsMap &settings) const QString service = connection->connectionInterface()->service(); const QString settingsPath = connection->connectionInterface()->path(); - qDebug() << "Should parse connection directly into existing configuration"; QNetworkConfigurationPrivate *cpPriv = parseConnection(service, settingsPath, settings); // Check if connection is active. @@ -457,9 +451,7 @@ void QNetworkManagerEngine::updateConnection(const QNmSettingsMap &settings) void QNetworkManagerEngine::activationFinished(QDBusPendingCallWatcher *watcher) { QDBusPendingReply reply = *watcher; - if (reply.isError()) { - qDebug() << "error connecting NM connection"; - } else { + if (!reply.isError()) { QDBusObjectPath result = reply.value(); QNetworkManagerConnectionActive activeConnection(result.path()); diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp index 9d603b5..f7fedbf 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp @@ -723,7 +723,6 @@ bool QNetworkManagerSettingsConnection::setConnections() allOk = true; } else { QDBusError error = dbusConnection.lastError(); - qDebug() << error.name() << error.message() << error.type(); } if (nmDBusHelper) diff --git a/src/plugins/bearer/nla/qnlaengine.cpp b/src/plugins/bearer/nla/qnlaengine.cpp index fbfac17..2001c0b 100644 --- a/src/plugins/bearer/nla/qnlaengine.cpp +++ b/src/plugins/bearer/nla/qnlaengine.cpp @@ -480,10 +480,8 @@ void QNlaThread::fetchConfigurations() if (error == WSA_E_NO_MORE) break; - if (error == WSAEFAULT) { - qDebug() << "buffer not big enough" << bufferLength; + if (error == WSAEFAULT) break; - } qWarning("WSALookupServiceNext error %d", WSAGetLastError()); break; diff --git a/src/plugins/bearer/qnetworksession_impl.cpp b/src/plugins/bearer/qnetworksession_impl.cpp index de1c91a..3fe844a 100644 --- a/src/plugins/bearer/qnetworksession_impl.cpp +++ b/src/plugins/bearer/qnetworksession_impl.cpp @@ -316,7 +316,6 @@ void QNetworkSessionPrivateImpl::updateStateFromServiceNetwork() } state = QNetworkSession::Connected; - qDebug() << oldState << "->" << state; if (state != oldState) emit stateChanged(state); @@ -328,7 +327,6 @@ void QNetworkSessionPrivateImpl::updateStateFromServiceNetwork() else state = QNetworkSession::Disconnected; - qDebug() << oldState << "->" << state; if (state != oldState) emit stateChanged(state); } diff --git a/src/plugins/bearer/symbian/symbianengine.cpp b/src/plugins/bearer/symbian/symbianengine.cpp index 2d0b5ee..e25eda4 100644 --- a/src/plugins/bearer/symbian/symbianengine.cpp +++ b/src/plugins/bearer/symbian/symbianengine.cpp @@ -663,7 +663,6 @@ void SymbianEngine::accessPointScanningReady(TBool scanSuccessful, TConnMonIapIn startCommsDatabaseNotifications(); - qDebug() << Q_FUNC_INFO << "updateCompleted()"; emit updateCompleted(); } -- cgit v0.12 From b8f21f8cd5b1dd900313675e0c8ffe976a5beded Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 11 Feb 2010 14:26:37 +1000 Subject: Fix documentation. --- src/network/access/qnetworkaccessmanager.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 9c1e268..7dc9203 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -163,7 +163,9 @@ static void ensureInitialized() /*! \property QNetworkAccessManager::networkAccess - \brief wheather network access is enabled or disabled through this network access manager. + \brief states whether network access is enabled or disabled through this network access + manager. + \since 4.7 Network access is enabled by default. @@ -742,6 +744,12 @@ QNetworkConfiguration QNetworkAccessManager::activeConfiguration() const } } +/*! + \since 4.7 + + Enables network access via this QNetworkAccessManager if \a enabled is true; otherwise disables + access. +*/ void QNetworkAccessManager::setNetworkAccessEnabled(bool enabled) { Q_D(QNetworkAccessManager); @@ -752,6 +760,12 @@ void QNetworkAccessManager::setNetworkAccessEnabled(bool enabled) } } +/*! + \since 4.7 + + Returns true if network access via this QNetworkAccessManager is enabled; otherwise returns + false. +*/ bool QNetworkAccessManager::networkAccessEnabled() const { Q_D(const QNetworkAccessManager); -- cgit v0.12 From b8c971b3841858f70c6355a704617a869db8a694 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 11 Feb 2010 14:35:54 +1000 Subject: Tag new classes as since 4.7. --- src/network/bearer/qnetworkconfigmanager.cpp | 2 ++ src/network/bearer/qnetworkconfiguration.cpp | 2 ++ src/network/bearer/qnetworksession.cpp | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index d46048b..8673f52 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -61,6 +61,8 @@ QNetworkConfigurationManagerPrivate *qNetworkConfigurationManagerPrivate() \brief The QNetworkConfigurationManager class manages the network configurations provided by the system. + \since 4.7 + \inmodule QtNetwork \ingroup bearer diff --git a/src/network/bearer/qnetworkconfiguration.cpp b/src/network/bearer/qnetworkconfiguration.cpp index cf10677..9246645 100644 --- a/src/network/bearer/qnetworkconfiguration.cpp +++ b/src/network/bearer/qnetworkconfiguration.cpp @@ -50,6 +50,8 @@ QT_BEGIN_NAMESPACE \brief The QNetworkConfiguration class provides an abstraction of one or more access point configurations. + \since 4.7 + \inmodule QtNetwork \ingroup bearer diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp index f9bb9ea..3e77354 100644 --- a/src/network/bearer/qnetworksession.cpp +++ b/src/network/bearer/qnetworksession.cpp @@ -55,6 +55,8 @@ QT_BEGIN_NAMESPACE \brief The QNetworkSession class provides control over the system's access points and enables session management for cases when multiple clients access the same access point. + \since 4.7 + \inmodule QtNetwork \ingroup bearer -- cgit v0.12 From 3591386484957cc4c93aece442f673246700b3b2 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 11 Feb 2010 14:54:21 +1000 Subject: Document networkSessionOnline() signal and mark as internal. --- src/network/access/qnetworkaccessmanager.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 7dc9203..9a351dc 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -187,6 +187,18 @@ static void ensureInitialized() */ /*! + \fn void QNetworkAccessManager::networkSessionOnline() + + \since 4.7 + + \internal + + This signal is emitted when the status of the network session changes into a usable state. + It is used to signal QNetworkReply's to start or migrate their network operation once the + network session has been opened / roamed. +*/ + +/*! \fn void QNetworkAccessManager::proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator) This signal is emitted whenever a proxy requests authentication -- cgit v0.12 From b5fe99c0105a9791e34a8b959822430497a4aeb9 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 11 Feb 2010 15:06:45 +1000 Subject: Fix public includes. --- src/network/bearer/bearer.pri | 2 +- src/network/bearer/qbearerplugin.cpp | 2 +- src/network/bearer/qbearerplugin.h | 82 -------------------------- src/network/bearer/qbearerplugin_p.h | 82 ++++++++++++++++++++++++++ src/network/bearer/qnetworkconfigmanager.h | 2 +- src/network/bearer/qnetworkconfigmanager_p.cpp | 2 +- src/network/bearer/qnetworksession.h | 3 +- src/plugins/bearer/corewlan/main.cpp | 2 +- src/plugins/bearer/generic/main.cpp | 2 +- src/plugins/bearer/icd/main.cpp | 2 +- src/plugins/bearer/nativewifi/main.cpp | 2 +- src/plugins/bearer/networkmanager/main.cpp | 2 +- src/plugins/bearer/nla/main.cpp | 2 +- src/plugins/bearer/symbian/main.cpp | 2 +- 14 files changed, 94 insertions(+), 95 deletions(-) delete mode 100644 src/network/bearer/qbearerplugin.h create mode 100644 src/network/bearer/qbearerplugin_p.h diff --git a/src/network/bearer/bearer.pri b/src/network/bearer/bearer.pri index c03c615..44e97fd 100644 --- a/src/network/bearer/bearer.pri +++ b/src/network/bearer/bearer.pri @@ -7,7 +7,7 @@ HEADERS += bearer/qnetworkconfiguration.h \ bearer/qnetworkconfiguration_p.h \ bearer/qnetworksession_p.h \ bearer/qbearerengine_p.h \ - bearer/qbearerplugin.h + bearer/qbearerplugin_p.h SOURCES += bearer/qnetworksession.cpp \ bearer/qnetworkconfigmanager.cpp \ diff --git a/src/network/bearer/qbearerplugin.cpp b/src/network/bearer/qbearerplugin.cpp index 2ee90d4..4509fd0 100644 --- a/src/network/bearer/qbearerplugin.cpp +++ b/src/network/bearer/qbearerplugin.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qbearerplugin.h" +#include "qbearerplugin_p.h" #include diff --git a/src/network/bearer/qbearerplugin.h b/src/network/bearer/qbearerplugin.h deleted file mode 100644 index 1958188..0000000 --- a/src/network/bearer/qbearerplugin.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** 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. -** -** $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 QBEARERPLUGIN_H -#define QBEARERPLUGIN_H - -#include "qbearerengine_p.h" - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Network) - -struct Q_NETWORK_EXPORT QBearerEngineFactoryInterface : public QFactoryInterface -{ - virtual QBearerEngine *create(const QString &key = QString()) const = 0; -}; - -#define QBearerEngineFactoryInterface_iid "com.trolltech.Qt.QBearerEngineFactoryInterface" -Q_DECLARE_INTERFACE(QBearerEngineFactoryInterface, QBearerEngineFactoryInterface_iid) - -class Q_NETWORK_EXPORT QBearerEnginePlugin : public QObject, public QBearerEngineFactoryInterface -{ - Q_OBJECT - Q_INTERFACES(QBearerEngineFactoryInterface:QFactoryInterface) - -public: - explicit QBearerEnginePlugin(QObject *parent = 0); - virtual ~QBearerEnginePlugin(); - - virtual QStringList keys() const = 0; - virtual QBearerEngine *create(const QString &key = QString()) const = 0; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif - diff --git a/src/network/bearer/qbearerplugin_p.h b/src/network/bearer/qbearerplugin_p.h new file mode 100644 index 0000000..1958188 --- /dev/null +++ b/src/network/bearer/qbearerplugin_p.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** 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. +** +** $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 QBEARERPLUGIN_H +#define QBEARERPLUGIN_H + +#include "qbearerengine_p.h" + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Network) + +struct Q_NETWORK_EXPORT QBearerEngineFactoryInterface : public QFactoryInterface +{ + virtual QBearerEngine *create(const QString &key = QString()) const = 0; +}; + +#define QBearerEngineFactoryInterface_iid "com.trolltech.Qt.QBearerEngineFactoryInterface" +Q_DECLARE_INTERFACE(QBearerEngineFactoryInterface, QBearerEngineFactoryInterface_iid) + +class Q_NETWORK_EXPORT QBearerEnginePlugin : public QObject, public QBearerEngineFactoryInterface +{ + Q_OBJECT + Q_INTERFACES(QBearerEngineFactoryInterface:QFactoryInterface) + +public: + explicit QBearerEnginePlugin(QObject *parent = 0); + virtual ~QBearerEnginePlugin(); + + virtual QStringList keys() const = 0; + virtual QBearerEngine *create(const QString &key = QString()) const = 0; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif + diff --git a/src/network/bearer/qnetworkconfigmanager.h b/src/network/bearer/qnetworkconfigmanager.h index 83c4939..a34e456 100644 --- a/src/network/bearer/qnetworkconfigmanager.h +++ b/src/network/bearer/qnetworkconfigmanager.h @@ -43,7 +43,7 @@ #define QNETWORKCONFIGURATIONMANAGER_H #include -#include "qnetworkconfiguration.h" +#include QT_BEGIN_HEADER diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index a624376..66d5982 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ #include "qnetworkconfigmanager_p.h" -#include "qbearerplugin.h" +#include "qbearerplugin_p.h" #include diff --git a/src/network/bearer/qnetworksession.h b/src/network/bearer/qnetworksession.h index 06d5eb7..3c8d913 100644 --- a/src/network/bearer/qnetworksession.h +++ b/src/network/bearer/qnetworksession.h @@ -47,8 +47,7 @@ #include #include #include -#include "qnetworkconfiguration.h" - +#include QT_BEGIN_HEADER diff --git a/src/plugins/bearer/corewlan/main.cpp b/src/plugins/bearer/corewlan/main.cpp index 010976a..5be8c0e 100644 --- a/src/plugins/bearer/corewlan/main.cpp +++ b/src/plugins/bearer/corewlan/main.cpp @@ -41,7 +41,7 @@ #include "qcorewlanengine.h" -#include +#include #include diff --git a/src/plugins/bearer/generic/main.cpp b/src/plugins/bearer/generic/main.cpp index 8ba9f40..ba85d93 100644 --- a/src/plugins/bearer/generic/main.cpp +++ b/src/plugins/bearer/generic/main.cpp @@ -41,7 +41,7 @@ #include "qgenericengine.h" -#include +#include #include diff --git a/src/plugins/bearer/icd/main.cpp b/src/plugins/bearer/icd/main.cpp index 8984d2c..b131ccb 100644 --- a/src/plugins/bearer/icd/main.cpp +++ b/src/plugins/bearer/icd/main.cpp @@ -41,7 +41,7 @@ #include "qicdengine.h" -#include +#include #include diff --git a/src/plugins/bearer/nativewifi/main.cpp b/src/plugins/bearer/nativewifi/main.cpp index 6bb2a2b..d77462e 100644 --- a/src/plugins/bearer/nativewifi/main.cpp +++ b/src/plugins/bearer/nativewifi/main.cpp @@ -46,7 +46,7 @@ #include #include -#include +#include #include diff --git a/src/plugins/bearer/networkmanager/main.cpp b/src/plugins/bearer/networkmanager/main.cpp index 6725252..f62b847 100644 --- a/src/plugins/bearer/networkmanager/main.cpp +++ b/src/plugins/bearer/networkmanager/main.cpp @@ -41,7 +41,7 @@ #include "qnetworkmanagerengine.h" -#include +#include #include diff --git a/src/plugins/bearer/nla/main.cpp b/src/plugins/bearer/nla/main.cpp index 54269a4..479a933 100644 --- a/src/plugins/bearer/nla/main.cpp +++ b/src/plugins/bearer/nla/main.cpp @@ -41,7 +41,7 @@ #include "qnlaengine.h" -#include +#include #include diff --git a/src/plugins/bearer/symbian/main.cpp b/src/plugins/bearer/symbian/main.cpp index 37eddee..0321451 100644 --- a/src/plugins/bearer/symbian/main.cpp +++ b/src/plugins/bearer/symbian/main.cpp @@ -41,7 +41,7 @@ #include "symbianengine.h" -#include +#include #include -- cgit v0.12 From 34450eb48e56677395601bf155a6a05752b326ad Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 11 Feb 2010 16:27:44 +1000 Subject: Use provided typedef for QNetworkConfigurationPrivatePointer. --- src/network/bearer/qnetworkconfigmanager.cpp | 6 ++---- src/network/bearer/qnetworkconfigmanager_p.cpp | 10 +++++----- src/network/bearer/qnetworkconfiguration.cpp | 5 ++--- src/plugins/bearer/generic/qgenericengine.cpp | 5 ++--- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index 8673f52..8ca2537 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -239,8 +239,7 @@ QList QNetworkConfigurationManager::allConfigurations(QNe //find all InternetAccessPoints foreach (const QString &ii, cpsIdents) { - QExplicitlySharedDataPointer p = - engine->accessPointConfigurations.value(ii); + QNetworkConfigurationPrivatePointer p = engine->accessPointConfigurations.value(ii); if ((p->state & filter) == filter) { QNetworkConfiguration pt; pt.d = engine->accessPointConfigurations.value(ii); @@ -251,8 +250,7 @@ QList QNetworkConfigurationManager::allConfigurations(QNe //find all service networks cpsIdents = engine->snapConfigurations.keys(); foreach (const QString &ii, cpsIdents) { - QExplicitlySharedDataPointer p = - engine->snapConfigurations.value(ii); + QNetworkConfigurationPrivatePointer p = engine->snapConfigurations.value(ii); if ((p->state & filter) == filter) { QNetworkConfiguration pt; pt.d = engine->snapConfigurations.value(ii); diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 66d5982..01a85a5 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -121,7 +121,7 @@ void QNetworkConfigurationManagerPrivate::updateInternetServiceConfiguration() serviceNetwork->state = QNetworkConfiguration::Defined; serviceNetwork->type = QNetworkConfiguration::ServiceNetwork; - QExplicitlySharedDataPointer ptr(serviceNetwork); + QNetworkConfigurationPrivatePointer ptr(serviceNetwork); generic->snapConfigurations.insert(serviceNetwork->id, ptr); @@ -132,17 +132,17 @@ void QNetworkConfigurationManagerPrivate::updateInternetServiceConfiguration() } } - QExplicitlySharedDataPointer ptr = + QNetworkConfigurationPrivatePointer ptr = generic->snapConfigurations.value(QLatin1String("Internet Service Network")); - QList > serviceNetworkMembers; + QList serviceNetworkMembers; - QHash >::const_iterator i = + QHash::const_iterator i = generic->accessPointConfigurations.constBegin(); QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Defined; while (i != generic->accessPointConfigurations.constEnd()) { - QExplicitlySharedDataPointer child = i.value(); + QNetworkConfigurationPrivatePointer child = i.value(); if (child.data()->internet && ((child.data()->state & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined)) { diff --git a/src/network/bearer/qnetworkconfiguration.cpp b/src/network/bearer/qnetworkconfiguration.cpp index 9246645..8c11d9c 100644 --- a/src/network/bearer/qnetworkconfiguration.cpp +++ b/src/network/bearer/qnetworkconfiguration.cpp @@ -326,10 +326,9 @@ QList QNetworkConfiguration::children() const if (type() != QNetworkConfiguration::ServiceNetwork || !isValid() ) return results; - QMutableListIterator > iter(d->serviceNetworkMembers); - QExplicitlySharedDataPointer p(0); + QMutableListIterator iter(d->serviceNetworkMembers); while(iter.hasNext()) { - p = iter.next(); + QNetworkConfigurationPrivatePointer p = iter.next(); //if we have an invalid member get rid of it -> was deleted earlier on if (!p->isValid) iter.remove(); diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp index c6ab4df..dba2c08 100644 --- a/src/plugins/bearer/generic/qgenericengine.cpp +++ b/src/plugins/bearer/generic/qgenericengine.cpp @@ -224,8 +224,7 @@ void QGenericEngine::doRequestUpdate() state |= QNetworkConfiguration::Active; if (accessPointConfigurations.contains(id)) { - QExplicitlySharedDataPointer ptr = - accessPointConfigurations.value(id); + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); bool changed = false; @@ -269,7 +268,7 @@ void QGenericEngine::doRequestUpdate() } while (!previous.isEmpty()) { - QExplicitlySharedDataPointer ptr = + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(previous.takeFirst()); configurationInterface.remove(ptr->id); -- cgit v0.12 From f11b682818e0d6fbd9cc75ee59b51bc6d6723c19 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 11 Feb 2010 17:01:44 +1000 Subject: Add 'We mean it.' header. --- src/network/bearer/qbearerplugin_p.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/network/bearer/qbearerplugin_p.h b/src/network/bearer/qbearerplugin_p.h index 1958188..36709c2 100644 --- a/src/network/bearer/qbearerplugin_p.h +++ b/src/network/bearer/qbearerplugin_p.h @@ -39,8 +39,19 @@ ** ****************************************************************************/ -#ifndef QBEARERPLUGIN_H -#define QBEARERPLUGIN_H +#ifndef QBEARERPLUGIN_P_H +#define QBEARERPLUGIN_P_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 "qbearerengine_p.h" -- cgit v0.12 From cb9cf8fbe9dd54c011490ee814c0692e61b729df Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Fri, 12 Feb 2010 11:08:50 +1000 Subject: Fix compiler warning, unused variable. --- src/network/access/qnetworkaccessmanager.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 9a351dc..312f744 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -1163,8 +1163,6 @@ void QNetworkAccessManagerPrivate::_q_networkSessionNewConfigurationActivated() void QNetworkAccessManagerPrivate::_q_networkSessionPreferredConfigurationChanged(const QNetworkConfiguration &, bool) { - Q_Q(QNetworkAccessManager); - networkSession->migrate(); } -- cgit v0.12 From cc1268a6cbc9797e2a9137f7a0389f3d144a8c0a Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Fri, 12 Feb 2010 11:14:49 +1000 Subject: Move http resume code into http backend. Adds two new virtual functions to QNetworkAccessBackend: bool canResume() const; and void setResumeOffset(quint64) canResume() is used to query the existing backend if resuming is supported for the current request. setResumeOffset() is used to set an additional offset which should be applied when the backend posts the request. The default implementation of canResume() returns false (resuming not supported). The default implementation of setResumeOffset() does nothing. --- src/network/access/qnetworkaccessbackend_p.h | 4 ++ src/network/access/qnetworkaccesshttpbackend.cpp | 48 ++++++++++++++++++++++++ src/network/access/qnetworkaccesshttpbackend_p.h | 5 +++ src/network/access/qnetworkreplyimpl.cpp | 21 ++--------- 4 files changed, 60 insertions(+), 18 deletions(-) diff --git a/src/network/access/qnetworkaccessbackend_p.h b/src/network/access/qnetworkaccessbackend_p.h index 830ec7e..eab011c 100644 --- a/src/network/access/qnetworkaccessbackend_p.h +++ b/src/network/access/qnetworkaccessbackend_p.h @@ -162,6 +162,10 @@ public: // This will possibly enable buffering of the upload data. virtual bool needsResetableUploadData() { return false; } + // Returns true if backend is able to resume downloads. + virtual bool canResume() const { return false; } + virtual void setResumeOffset(quint64 offset) { Q_UNUSED(offset); } + protected: // Create the device used for reading the upload data QNonContiguousByteDevice* createUploadByteDevice(); diff --git a/src/network/access/qnetworkaccesshttpbackend.cpp b/src/network/access/qnetworkaccesshttpbackend.cpp index 8e02723..aa6a820 100644 --- a/src/network/access/qnetworkaccesshttpbackend.cpp +++ b/src/network/access/qnetworkaccesshttpbackend.cpp @@ -296,6 +296,7 @@ QNetworkAccessHttpBackend::QNetworkAccessHttpBackend() #ifndef QT_NO_OPENSSL , pendingSslConfiguration(0), pendingIgnoreAllSslErrors(false) #endif + , resumeOffset(0) { } @@ -533,6 +534,28 @@ void QNetworkAccessHttpBackend::postRequest() httpRequest.setUrl(url()); QList headers = request().rawHeaderList(); + if (resumeOffset != 0) { + if (headers.contains("Range")) { + // Need to adjust resume offset for user specified range + + headers.removeOne("Range"); + + // We've already verified that requestRange starts with "bytes=", see canResume. + QByteArray requestRange = request().rawHeader("Range").mid(6); + + int index = requestRange.indexOf('-'); + + quint64 requestStartOffset = requestRange.left(index).toULongLong(); + quint64 requestEndOffset = requestRange.mid(index + 1).toULongLong(); + + requestRange = "bytes=" + QByteArray::number(resumeOffset + requestStartOffset) + + '-' + QByteArray::number(requestEndOffset); + + httpRequest.setHeaderField("Range", requestRange); + } else { + httpRequest.setHeaderField("Range", "bytes=" + QByteArray::number(resumeOffset) + '-'); + } + } foreach (const QByteArray &header, headers) httpRequest.setHeaderField(header, request().rawHeader(header)); @@ -1108,6 +1131,31 @@ QNetworkCacheMetaData QNetworkAccessHttpBackend::fetchCacheMetaData(const QNetwo return metaData; } +bool QNetworkAccessHttpBackend::canResume() const +{ + // Only GET operation supports resuming. + if (operation() != QNetworkAccessManager::GetOperation) + return false; + + // Can only resume if server/resource supports Range header. + if (httpReply->headerField("Accept-Ranges", "none") == "none") + return false; + + // We only support resuming for byte ranges. + if (request().hasRawHeader("Range")) { + QByteArray range = request().rawHeader("Range"); + if (!range.startsWith("bytes=")) + return false; + } + + return true; +} + +void QNetworkAccessHttpBackend::setResumeOffset(quint64 offset) +{ + resumeOffset = offset; +} + QT_END_NAMESPACE #endif // QT_NO_HTTP diff --git a/src/network/access/qnetworkaccesshttpbackend_p.h b/src/network/access/qnetworkaccesshttpbackend_p.h index 0eaf003..e5cc0ab 100644 --- a/src/network/access/qnetworkaccesshttpbackend_p.h +++ b/src/network/access/qnetworkaccesshttpbackend_p.h @@ -99,6 +99,9 @@ public: // we return true since HTTP needs to send PUT/POST data again after having authenticated bool needsResetableUploadData() { return true; } + bool canResume() const; + void setResumeOffset(quint64 offset); + private slots: void replyReadyRead(); void replyFinished(); @@ -120,6 +123,8 @@ private: QList pendingIgnoreSslErrorsList; #endif + quint64 resumeOffset; + void disconnectFromHttp(); void setupConnection(); void validateCache(QHttpNetworkRequest &httpRequest, bool &loadedFromCache); diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index 7f66b25..2906caa 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -497,15 +497,6 @@ void QNetworkReplyImplPrivate::appendDownstreamData(QByteDataBuffer &data) QPointer qq = q; QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); - if (totalSize.isNull()) { - RawHeadersList::ConstIterator it = findRawHeader("Content-Range"); - if (it != rawHeaders.constEnd()) { - int index = it->second.lastIndexOf('/'); - if (index != -1) - totalSize = it->second.mid(index + 1).toLongLong() - preMigrationDownloaded; - } - } - if (preMigrationDownloaded != Q_INT64_C(-1)) totalSize = totalSize.toLongLong() + preMigrationDownloaded; pauseNotificationHandling(); @@ -812,8 +803,8 @@ bool QNetworkReplyImplPrivate::migrateBackend() if (state == Finished || state == Aborted) return true; - // Resume only supported by http backend, not migrating. - if (!qobject_cast(backend)) + // Backend does not support resuming download. + if (!backend->canResume()) return false; // Request has outgoing data, not migrating. @@ -824,11 +815,6 @@ bool QNetworkReplyImplPrivate::migrateBackend() if (copyDevice) return true; - // Range header is not supported by server/resource, can't migrate. - RawHeadersList::ConstIterator it = findRawHeader("Accept-Ranges"); - if (it == rawHeaders.constEnd() || it->second == "none") - return false; - state = QNetworkReplyImplPrivate::Reconnecting; if (backend) { @@ -841,13 +827,12 @@ bool QNetworkReplyImplPrivate::migrateBackend() preMigrationDownloaded = bytesDownloaded; - request.setRawHeader("Range", "bytes=" + QByteArray::number(preMigrationDownloaded) + '-'); - backend = manager->d_func()->findBackend(operation, request); if (backend) { backend->setParent(q); backend->reply = this; + backend->setResumeOffset(bytesDownloaded); } if (qobject_cast(backend)) { -- cgit v0.12 From c08afbfd96d7b8205fd2d0ff3e3e28f76aa3323f Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Fri, 12 Feb 2010 15:03:50 +1000 Subject: Fix build on Windows. On Windows interface is #defined to struct. Make sure that qnetworksession.h is included before qplatformdefs.h. --- src/network/access/qnetworkaccessbackend.cpp | 1 + src/network/access/qnetworkaccessbackend_p.h | 1 - src/network/access/qnetworkaccessmanager.cpp | 3 ++- src/network/access/qnetworkreplyimpl.cpp | 1 + src/network/bearer/qnetworksession.h | 1 - 5 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp index 1d23cdc..4441993 100644 --- a/src/network/access/qnetworkaccessbackend.cpp +++ b/src/network/access/qnetworkaccessbackend.cpp @@ -46,6 +46,7 @@ #include "qnetworkreply_p.h" #include "QtCore/qhash.h" #include "QtCore/qmutex.h" +#include "QtNetwork/qnetworksession.h" #include "qnetworkaccesscachebackend_p.h" #include "qabstractnetworkcache.h" diff --git a/src/network/access/qnetworkaccessbackend_p.h b/src/network/access/qnetworkaccessbackend_p.h index eab011c..9bc15e5 100644 --- a/src/network/access/qnetworkaccessbackend_p.h +++ b/src/network/access/qnetworkaccessbackend_p.h @@ -54,7 +54,6 @@ // #include "qnetworkreplyimpl_p.h" -#include "QtNetwork/qnetworksession.h" #include "QtCore/qobject.h" QT_BEGIN_NAMESPACE diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 312f744..bb5ff6c 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -47,6 +47,8 @@ #include "qnetworkcookie.h" #include "qabstractnetworkcache.h" +#include "QtNetwork/qnetworksession.h" + #include "qnetworkaccesshttpbackend_p.h" #include "qnetworkaccessftpbackend_p.h" #include "qnetworkaccessfilebackend_p.h" @@ -60,7 +62,6 @@ #include "QtNetwork/qauthenticator.h" #include "QtNetwork/qsslconfiguration.h" #include "QtNetwork/qnetworkconfigmanager.h" -#include "QtNetwork/qnetworksession.h" QT_BEGIN_NAMESPACE diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index 2906caa..8951d08 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -46,6 +46,7 @@ #include "QtCore/qcoreapplication.h" #include "QtCore/qdatetime.h" #include "QtNetwork/qsslconfiguration.h" +#include "QtNetwork/qnetworksession.h" #include "qnetworkaccesshttpbackend_p.h" #include "qnetworkaccessmanager_p.h" diff --git a/src/network/bearer/qnetworksession.h b/src/network/bearer/qnetworksession.h index 3c8d913..1c0dce0 100644 --- a/src/network/bearer/qnetworksession.h +++ b/src/network/bearer/qnetworksession.h @@ -43,7 +43,6 @@ #define QNETWORKSESSION_H #include -#include #include #include #include -- cgit v0.12 From ddd65592cae3b1ec4ea64c721c44c3ac2fee4660 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Fri, 12 Feb 2010 15:12:48 +1000 Subject: Fix build on Windows, typo. --- src/plugins/bearer/nla/nla.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/bearer/nla/nla.pro b/src/plugins/bearer/nla/nla.pro index 5ba171e..5148b09 100644 --- a/src/plugins/bearer/nla/nla.pro +++ b/src/plugins/bearer/nla/nla.pro @@ -12,7 +12,7 @@ QT += network HEADERS += qnlaengine.h \ ../platformdefs_win.h \ ../qnetworksession_impl.h \ - ../qbeaerengine_impl.h + ../qbearerengine_impl.h SOURCES += main.cpp \ qnlaengine.cpp \ -- cgit v0.12 From 21aeae2a2258ab8e5083a0607c3b98579bf6fc58 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 15 Feb 2010 13:03:24 +1000 Subject: Expand documentation for QNAM::setConfiguration() and friends. --- .../src_network_access_qnetworkaccessmanager.cpp | 9 ++++++ src/network/access/qnetworkaccessmanager.cpp | 33 +++++++++++++++++++--- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp b/doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp index 643d0dd..5db6676 100644 --- a/doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp +++ b/doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp @@ -60,3 +60,12 @@ connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), connect(reply, SIGNAL(sslErrors(QList)), this, SLOT(slotSslErrors(QList))); //! [1] + +//! [2] +QNetworkConfigurationManager manager; +networkAccessManager->setConfiguration(manager.defaultConfiguration()); +//! [2] + +//! [3] +networkAccessManager->setConfiguration(QNetworkConfiguration()); +//! [3] diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index d9ad085..69b57e5 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -710,9 +710,25 @@ QNetworkReply *QNetworkAccessManager::deleteResource(const QNetworkRequest &requ /*! \since 4.7 - Sets the network configuration that will be used when creating a network session to \a config. + Sets the network configuration that will be used when creating the + \l {QNetworkSession}{network session} to \a config. - \sa configuration() + The network configuration is used to create and open a network session before any request that + requires network access is process. If no network configuration is explicitly set via this + function the network configuration returned by + QNetworkConfigurationManager::defaultConfiguration() will be used. + + To restore the default network configuration set the network configuration to the value + returned from QNetworkConfigurationManager::defaultConfiguration(). + + \snippet doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp 2 + + If an invalid network configuration is set, a network session will not be created. In this + case network requests will be processed regardless, but may fail. For example: + + \snippet doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp 3 + + \sa configuration(), QNetworkSession */ void QNetworkAccessManager::setConfiguration(const QNetworkConfiguration &config) { @@ -722,9 +738,10 @@ void QNetworkAccessManager::setConfiguration(const QNetworkConfiguration &config /*! \since 4.7 - Returns the network configuration. + Returns the network configuration that will be used to create the + \l {QNetworkSession}{network session} which will be used when processing network requests. - \sa setConfiguration() + \sa setConfiguration(), activeConfiguration() */ QNetworkConfiguration QNetworkAccessManager::configuration() const { @@ -741,6 +758,14 @@ QNetworkConfiguration QNetworkAccessManager::configuration() const Returns the current active network configuration. + If the network configuration returned by configuration() is of type + QNetworkConfiguration::ServiceNetwork this function will return the current active child + network configuration of that configuration. Otherwise returns the same network configuration + as configuration(). + + Use this function to return the actual network configuration currently in use by the network + session. + \sa configuration() */ QNetworkConfiguration QNetworkAccessManager::activeConfiguration() const -- cgit v0.12 From 1afc8234c3a0ab38671f6078cf6a865ba81c73f7 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 15 Feb 2010 14:18:42 +1000 Subject: Reorder members to remove hole. --- src/network/access/qnetworkaccessmanager_p.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h index 568894c..8a1f19d 100644 --- a/src/network/access/qnetworkaccessmanager_p.h +++ b/src/network/access/qnetworkaccessmanager_p.h @@ -75,9 +75,9 @@ public: #ifndef QT_NO_NETWORKPROXY proxyFactory(0), #endif - cookieJarCreated(false), networkSession(0), - networkAccessEnabled(true) + networkAccessEnabled(true), + cookieJarCreated(false) { } ~QNetworkAccessManagerPrivate(); @@ -119,11 +119,11 @@ public: QNetworkProxyFactory *proxyFactory; #endif - bool cookieJarCreated; - QNetworkSession *networkSession; bool networkAccessEnabled; + bool cookieJarCreated; + // this cache can be used by individual backends to cache e.g. their TCP connections to a server // and use the connections for multiple requests. QNetworkAccessCache objectCache; -- cgit v0.12 From 4089401868dd62972a750c3e668a2998071de97c Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 15 Feb 2010 15:17:55 +1000 Subject: Use snippets. --- .../src_network_bearer_qnetworkconfigmanager.cpp | 49 ++++++++++++++++++++++ src/network/bearer/qnetworkconfigmanager.cpp | 9 +--- 2 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 doc/src/snippets/code/src_network_bearer_qnetworkconfigmanager.cpp diff --git a/doc/src/snippets/code/src_network_bearer_qnetworkconfigmanager.cpp b/doc/src/snippets/code/src_network_bearer_qnetworkconfigmanager.cpp new file mode 100644 index 0000000..e2cc4df --- /dev/null +++ b/doc/src/snippets/code/src_network_bearer_qnetworkconfigmanager.cpp @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** 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 documentation 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$ +** +****************************************************************************/ + +//! [0] +QNetworkConfigurationManager mgr; +QList activeConfigs = mgr.allConfigurations(QNetworkConfiguration::Active) +if (activeConfigs.count() > 0) + Q_ASSERT(mgr.isOnline()) +else + Q_ASSERT(!mgr.isOnline()) +//! [0] diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index 8ca2537..2e37e01 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -296,14 +296,7 @@ QNetworkConfiguration QNetworkConfigurationManager::configurationFromIdentifier( This is equivalent to the following code snippet: - \code - QNetworkConfigurationManager mgr; - QList activeConfigs = mgr.allConfigurations(QNetworkConfiguration::Active) - if (activeConfigs.count() > 0) - Q_ASSERT(mgr.isOnline()) - else - Q_ASSERT(!mgr.isOnline()) - \endcode + \snippet doc/src/snippets/code/src_network_bearer_qnetworkconfigmanager.cpp 0 \sa onlineStateChanged() */ -- cgit v0.12 From 4fb59e0a8d40083f545dd43a370bd6d7b7b4cd35 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 15 Feb 2010 15:18:26 +1000 Subject: Optimise iterations over QHash. --- src/network/bearer/qbearerengine.cpp | 25 ++++++++++----------- src/network/bearer/qnetworkconfigmanager.cpp | 20 ++++++++--------- src/network/bearer/qnetworkconfigmanager_p.cpp | 30 +++++++++++++++----------- 3 files changed, 41 insertions(+), 34 deletions(-) diff --git a/src/network/bearer/qbearerengine.cpp b/src/network/bearer/qbearerengine.cpp index bd2ca6c..58d64f2 100644 --- a/src/network/bearer/qbearerengine.cpp +++ b/src/network/bearer/qbearerengine.cpp @@ -50,22 +50,23 @@ QBearerEngine::QBearerEngine(QObject *parent) QBearerEngine::~QBearerEngine() { - foreach (const QString &oldIface, snapConfigurations.keys()) { - QNetworkConfigurationPrivatePointer priv = snapConfigurations.take(oldIface); - priv->isValid = false; - priv->id.clear(); + QHash::Iterator it; + QHash::Iterator end; + for (it = snapConfigurations.begin(), end = snapConfigurations.end(); it != end; ++it) { + it.value()->isValid = false; + it.value()->id.clear(); } - foreach (const QString &oldIface, accessPointConfigurations.keys()) { - QNetworkConfigurationPrivatePointer priv = accessPointConfigurations.take(oldIface); - priv->isValid = false; - priv->id.clear(); + for (it = accessPointConfigurations.begin(), end = accessPointConfigurations.end(); + it != end; ++it) { + it.value()->isValid = false; + it.value()->id.clear(); } - foreach (const QString &oldIface, userChoiceConfigurations.keys()) { - QNetworkConfigurationPrivatePointer priv = userChoiceConfigurations.take(oldIface); - priv->isValid = false; - priv->id.clear(); + for (it = userChoiceConfigurations.begin(), end = userChoiceConfigurations.end(); + it != end; ++it) { + it.value()->isValid = false; + it.value()->id.clear(); } } diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index 2e37e01..f54a985 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -235,25 +235,25 @@ QList QNetworkConfigurationManager::allConfigurations(QNe QNetworkConfigurationManagerPrivate* conPriv = connManager(); foreach (QBearerEngine *engine, conPriv->sessionEngines) { - QStringList cpsIdents = engine->accessPointConfigurations.keys(); + QHash::Iterator it; + QHash::Iterator end; //find all InternetAccessPoints - foreach (const QString &ii, cpsIdents) { - QNetworkConfigurationPrivatePointer p = engine->accessPointConfigurations.value(ii); - if ((p->state & filter) == filter) { + for (it = engine->accessPointConfigurations.begin(), + end = engine->accessPointConfigurations.end(); it != end; ++it) { + if ((it.value()->state & filter) == filter) { QNetworkConfiguration pt; - pt.d = engine->accessPointConfigurations.value(ii); + pt.d = it.value(); result << pt; } } //find all service networks - cpsIdents = engine->snapConfigurations.keys(); - foreach (const QString &ii, cpsIdents) { - QNetworkConfigurationPrivatePointer p = engine->snapConfigurations.value(ii); - if ((p->state & filter) == filter) { + for (it = engine->snapConfigurations.begin(), + end = engine->snapConfigurations.end(); it != end; ++it) { + if ((it.value()->state & filter) == filter) { QNetworkConfiguration pt; - pt.d = engine->snapConfigurations.value(ii); + pt.d = it.value(); result << pt; } } diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 01a85a5..b7a30b8 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -244,16 +244,19 @@ QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration( QNetworkConfigurationPrivatePointer firstDiscovered; foreach (QBearerEngine *engine, sessionEngines) { - foreach (const QString &id, engine->snapConfigurations.keys()) { - QNetworkConfigurationPrivatePointer ptr = engine->snapConfigurations.value(id); + QHash::Iterator it; + QHash::Iterator end; - if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + for (it = engine->snapConfigurations.begin(), end = engine->snapConfigurations.end(); + it != end; ++it) { + if ((it.value()->state & QNetworkConfiguration::Active) == + QNetworkConfiguration::Active) { QNetworkConfiguration config; - config.d = ptr; + config.d = it.value(); return config; - } else if ((ptr->state & QNetworkConfiguration::Discovered) == + } else if ((it.value()->state & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) { - firstDiscovered = ptr; + firstDiscovered = it.value(); } } } @@ -269,16 +272,19 @@ QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration( firstDiscovered.reset(); foreach (QBearerEngine *engine, sessionEngines) { - foreach (const QString &id, engine->accessPointConfigurations.keys()) { - QNetworkConfigurationPrivatePointer ptr = engine->accessPointConfigurations.value(id); + QHash::Iterator it; + QHash::Iterator end; - if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + for (it = engine->accessPointConfigurations.begin(), + end = engine->accessPointConfigurations.end(); it != end; ++it) { + if ((it.value()->state & QNetworkConfiguration::Active) == + QNetworkConfiguration::Active) { QNetworkConfiguration config; - config.d = ptr; + config.d = it.value(); return config; - } else if ((ptr->state & QNetworkConfiguration::Discovered) == + } else if ((it.value()->state & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) { - firstDiscovered = ptr; + firstDiscovered = it.value(); } } } -- cgit v0.12 From 868d5fc208acbe9579b2c70637cccdd355263c11 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 15 Feb 2010 15:24:24 +1000 Subject: Simplify. --- src/network/bearer/qnetworkconfigmanager_p.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index b7a30b8..4367654 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -55,8 +55,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, QNetworkConfigurationManagerPrivate::~QNetworkConfigurationManagerPrivate() { - while (!sessionEngines.isEmpty()) - delete sessionEngines.takeFirst(); + qDeleteAll(sessionEngines); } void QNetworkConfigurationManagerPrivate::configurationAdded(QNetworkConfigurationPrivatePointer ptr) -- cgit v0.12 From af9843fe530d4c09226cc45b223bbf357e6bfb41 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 15 Feb 2010 15:30:39 +1000 Subject: Remove unused code. --- src/network/bearer/qnetworkconfigmanager_p.cpp | 56 -------------------------- src/network/bearer/qnetworkconfigmanager_p.h | 3 -- 2 files changed, 59 deletions(-) diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 4367654..bc354c1 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -109,62 +109,6 @@ void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigura emit onlineStateChanged(online); } -void QNetworkConfigurationManagerPrivate::updateInternetServiceConfiguration() -{ -#if 0 - if (!generic->snapConfigurations.contains(QLatin1String("Internet Service Network"))) { - QNetworkConfigurationPrivate *serviceNetwork = new QNetworkConfigurationPrivate; - serviceNetwork->name = tr("Internet"); - serviceNetwork->isValid = true; - serviceNetwork->id = QLatin1String("Internet Service Network"); - serviceNetwork->state = QNetworkConfiguration::Defined; - serviceNetwork->type = QNetworkConfiguration::ServiceNetwork; - - QNetworkConfigurationPrivatePointer ptr(serviceNetwork); - - generic->snapConfigurations.insert(serviceNetwork->id, ptr); - - if (!firstUpdate) { - QNetworkConfiguration item; - item.d = ptr; - emit configurationAdded(item); - } - } - - QNetworkConfigurationPrivatePointer ptr = - generic->snapConfigurations.value(QLatin1String("Internet Service Network")); - - QList serviceNetworkMembers; - - QHash::const_iterator i = - generic->accessPointConfigurations.constBegin(); - - QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Defined; - while (i != generic->accessPointConfigurations.constEnd()) { - QNetworkConfigurationPrivatePointer child = i.value(); - - if (child.data()->internet && ((child.data()->state & QNetworkConfiguration::Defined) - == QNetworkConfiguration::Defined)) { - serviceNetworkMembers.append(child); - - state |= child.data()->state; - } - - ++i; - } - - - if (ptr.data()->state != state || ptr.data()->serviceNetworkMembers != serviceNetworkMembers) { - ptr.data()->state = state; - ptr.data()->serviceNetworkMembers = serviceNetworkMembers; - - QNetworkConfiguration item; - item.d = ptr; - emit configurationChanged(item); - } -#endif -} - void QNetworkConfigurationManagerPrivate::updateConfigurations() { if (firstUpdate) { diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index f6603ce..e178c2d 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -90,9 +90,6 @@ Q_SIGNALS: void configurationChanged(const QNetworkConfiguration& config); void onlineStateChanged(bool isOnline); -private: - void updateInternetServiceConfiguration(); - void abort(); public: -- cgit v0.12 From dce74fe14ceb0e297850c73bfa7e7f4938eedd35 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 15 Feb 2010 15:35:17 +1000 Subject: Change docs: "phone" -> "device". --- src/network/bearer/qnetworkconfiguration.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/bearer/qnetworkconfiguration.cpp b/src/network/bearer/qnetworkconfiguration.cpp index 8c11d9c..c551dc5 100644 --- a/src/network/bearer/qnetworkconfiguration.cpp +++ b/src/network/bearer/qnetworkconfiguration.cpp @@ -157,7 +157,7 @@ QT_BEGIN_NAMESPACE QNetworkSession. An example of a discovered configuration could be a WLAN which is within in range. If the device moves out of range the discovered flag is dropped. A second example is a GPRS configuration which generally - remains discovered for as long as the phone has network coverage. A + remains discovered for as long as the device has network coverage. A configuration that has this state is also in state QNetworkConfiguration::Defined. If the configuration is a service network this flag is set if at least one of the underlying access points -- cgit v0.12 From f8c5151b96a6c1961e90fd3162975357cac3f06b Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 16 Feb 2010 09:43:32 +1000 Subject: Add QT_MODULE headers. --- src/network/bearer/qnetworkconfigmanager.h | 2 ++ src/network/bearer/qnetworkconfiguration.h | 2 ++ src/network/bearer/qnetworksession.h | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/network/bearer/qnetworkconfigmanager.h b/src/network/bearer/qnetworkconfigmanager.h index a34e456..73041fe 100644 --- a/src/network/bearer/qnetworkconfigmanager.h +++ b/src/network/bearer/qnetworkconfigmanager.h @@ -49,6 +49,8 @@ QT_BEGIN_HEADER QT_BEGIN_NAMESPACE +QT_MODULE(Network) + class QNetworkConfigurationManagerPrivate; class Q_NETWORK_EXPORT QNetworkConfigurationManager : public QObject { diff --git a/src/network/bearer/qnetworkconfiguration.h b/src/network/bearer/qnetworkconfiguration.h index 8d45cf6..dad6198 100644 --- a/src/network/bearer/qnetworkconfiguration.h +++ b/src/network/bearer/qnetworkconfiguration.h @@ -51,6 +51,8 @@ QT_BEGIN_HEADER QT_BEGIN_NAMESPACE +QT_MODULE(Network) + class QNetworkConfigurationPrivate; class Q_NETWORK_EXPORT QNetworkConfiguration { diff --git a/src/network/bearer/qnetworksession.h b/src/network/bearer/qnetworksession.h index 1c0dce0..18437f6 100644 --- a/src/network/bearer/qnetworksession.h +++ b/src/network/bearer/qnetworksession.h @@ -52,6 +52,8 @@ QT_BEGIN_HEADER QT_BEGIN_NAMESPACE +QT_MODULE(Network) + class QNetworkSessionPrivate; class Q_NETWORK_EXPORT QNetworkSession : public QObject { -- cgit v0.12 From 6ade9920551f16154dda548041b5ba7bbddf78eb Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 16 Feb 2010 10:17:48 +1000 Subject: Always build generic plugin when building NetworkManager plugin. --- src/plugins/bearer/bearer.pro | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/plugins/bearer/bearer.pro b/src/plugins/bearer/bearer.pro index 95c9851..6ce1f0d 100644 --- a/src/plugins/bearer/bearer.pro +++ b/src/plugins/bearer/bearer.pro @@ -1,6 +1,8 @@ TEMPLATE = subdirs -!maemo:contains(QT_CONFIG, dbus):contains(QT_CONFIG, networkmanager):SUBDIRS += networkmanager +!maemo:contains(QT_CONFIG, dbus):contains(QT_CONFIG, networkmanager) { + SUBDIRS += networkmanager generic +} win32:SUBDIRS += nla win32:!wince*:SUBDIRS += nativewifi macx:SUBDIRS += corewlan -- cgit v0.12 From 4b47b11f2c504961d7d4dff164c3f015f4bd9445 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 16 Feb 2010 10:25:34 +1000 Subject: Don't block forever if no bearer plugins are loaded. --- src/network/bearer/qnetworkconfigmanager_p.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index bc354c1..141d522 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -244,6 +244,11 @@ QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration( void QNetworkConfigurationManagerPrivate::performAsyncConfigurationUpdate() { + if (sessionEngines.isEmpty()) { + emit configurationUpdateComplete(); + return; + } + updating = true; for (int i = 0; i < sessionEngines.count(); ++i) { -- cgit v0.12 From 81c7817ecb83e2dcbbdae59607bdc1311b9ef38f Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 16 Feb 2010 10:34:22 +1000 Subject: Make this a warning. --- .../auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp index 48db6cb..1cafa47 100644 --- a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp +++ b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp @@ -182,8 +182,8 @@ void tst_QNetworkSession::cleanupTestCase() if (!(manager.capabilities() & QNetworkConfigurationManager::SystemSessionSupport) && (manager.capabilities() & QNetworkConfigurationManager::CanStartAndStopInterfaces) && inProcessSessionManagementCount == 0) { - QFAIL("No usable configurations found to complete all possible " - "tests in inProcessSessionManagement()"); + qWarning("No usable configurations found to complete all possible tests in " + "inProcessSessionManagement()"); } #ifdef Q_WS_MAEMO_6 -- cgit v0.12 From 4f7dc1642d66850deed0395f8b713af7a21d8957 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 16 Feb 2010 10:55:58 +1000 Subject: Remove debug output. --- src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp index f7fedbf..7617e94 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp @@ -624,7 +624,7 @@ QNetworkManagerSettings::QNetworkManagerSettings(const QString &settingsService, dbusConnection); if (!d->connectionInterface->isValid()) { d->valid = false; - qWarning() << "Could not find NetworkManagerSettings"; + //qWarning() << "Could not find NetworkManagerSettings"; return; } d->valid = true; @@ -689,7 +689,7 @@ QNetworkManagerSettingsConnection::QNetworkManagerSettingsConnection(const QStri NM_DBUS_IFACE_SETTINGS_CONNECTION, dbusConnection, parent); if (!d->connectionInterface->isValid()) { - qWarning() << "Could not find NetworkManagerSettingsConnection"; + //qWarning() << "Could not find NetworkManagerSettingsConnection"; d->valid = false; return; } @@ -921,7 +921,7 @@ QNetworkManagerConnectionActive::QNetworkManagerConnectionActive( const QString dbusConnection, parent); if (!d->connectionInterface->isValid()) { d->valid = false; - qWarning() << "Could not find NetworkManagerSettingsConnection"; + //qWarning() << "Could not find NetworkManagerSettingsConnection"; return; } d->valid = true; @@ -1022,7 +1022,7 @@ QNetworkManagerIp4Config::QNetworkManagerIp4Config( const QString &deviceObjectP dbusConnection, parent); if (!d->connectionInterface->isValid()) { d->valid = false; - qWarning() << "Could not find NetworkManagerIp4Config"; + //qWarning() << "Could not find NetworkManagerIp4Config"; return; } d->valid = true; -- cgit v0.12 From 13a880f23b01856770a3afc12b1a47121ef04349 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 16 Feb 2010 11:21:28 +1000 Subject: Fix segfault. manager may be 0. --- src/network/access/qnetworkreplyimpl.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index 8951d08..2175686 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -549,21 +549,24 @@ void QNetworkReplyImplPrivate::finished() QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); if (preMigrationDownloaded != Q_INT64_C(-1)) totalSize = totalSize.toLongLong() + preMigrationDownloaded; - QNetworkSession *session = manager->d_func()->networkSession; - if (session && session->state() == QNetworkSession::Roaming && - state == Working && errorCode != QNetworkReply::OperationCanceledError) { - // only content with a known size will fail with a temporary network failure error - if (!totalSize.isNull()) { - if (bytesDownloaded != totalSize) { - if (migrateBackend()) { - // either we are migrating or the request is finished/aborted - if (state == Reconnecting || state == WaitingForSession) { - resumeNotificationHandling(); - return; // exit early if we are migrating. + + if (!manager.isNull()) { + QNetworkSession *session = manager->d_func()->networkSession; + if (session && session->state() == QNetworkSession::Roaming && + state == Working && errorCode != QNetworkReply::OperationCanceledError) { + // only content with a known size will fail with a temporary network failure error + if (!totalSize.isNull()) { + if (bytesDownloaded != totalSize) { + if (migrateBackend()) { + // either we are migrating or the request is finished/aborted + if (state == Reconnecting || state == WaitingForSession) { + resumeNotificationHandling(); + return; // exit early if we are migrating. + } + } else { + error(QNetworkReply::TemporaryNetworkFailureError, + q->tr("Temporary network failure.")); } - } else { - error(QNetworkReply::TemporaryNetworkFailureError, - q->tr("Temporary network failure.")); } } } -- cgit v0.12 From 0d950606bf2d4e8d63d552420c7517eea69b3a83 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 16 Feb 2010 13:47:31 +1000 Subject: Fix QNetworkSession unit test. Make sure test can find lackey process. Always connect lackey to tests IPC socket. --- tests/auto/qnetworksession/lackey/lackey.pro | 6 +++++- tests/auto/qnetworksession/lackey/main.cpp | 16 ++++++++-------- .../tst_qnetworksession/tst_qnetworksession.cpp | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/tests/auto/qnetworksession/lackey/lackey.pro b/tests/auto/qnetworksession/lackey/lackey.pro index 3ed9850..8fbdd58 100644 --- a/tests/auto/qnetworksession/lackey/lackey.pro +++ b/tests/auto/qnetworksession/lackey/lackey.pro @@ -1,8 +1,12 @@ SOURCES += main.cpp -TARGET = qnetworksessionlackey +TARGET = lackey QT = core network +DESTDIR = ./ + +win32:CONFIG += console + symbian { # Needed for interprocess communication and opening QNetworkSession TARGET.CAPABILITY = NetworkControl NetworkServices diff --git a/tests/auto/qnetworksession/lackey/main.cpp b/tests/auto/qnetworksession/lackey/main.cpp index 1e40485..41e935a 100644 --- a/tests/auto/qnetworksession/lackey/main.cpp +++ b/tests/auto/qnetworksession/lackey/main.cpp @@ -59,6 +59,14 @@ int main(int argc, char** argv) { QCoreApplication app(argc, argv); + // Cannot read/write to processes on WinCE or Symbian. + // Easiest alternative is to use sockets for IPC. + + QLocalSocket oopSocket; + + oopSocket.connectToServer("tst_qnetworksession"); + oopSocket.waitForConnected(-1); + QNetworkConfigurationManager manager; QList discovered = #if defined (Q_OS_SYMBIAN) @@ -72,14 +80,6 @@ int main(int argc, char** argv) return NO_DISCOVERED_CONFIGURATIONS_ERROR; } - // Cannot read/write to processes on WinCE or Symbian. - // Easiest alternative is to use sockets for IPC. - - QLocalSocket oopSocket; - - oopSocket.connectToServer("tst_qnetworksession"); - oopSocket.waitForConnected(-1); - qDebug() << "Lackey started"; QNetworkSession *session = 0; diff --git a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp index 1cafa47..4ef3a4f 100644 --- a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp +++ b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp @@ -836,7 +836,7 @@ void tst_QNetworkSession::outOfProcessSession() qDebug() << "starting lackey"; QProcess lackey; - lackey.start("qnetworksessionlackey"); + lackey.start("lackey/lackey"); qDebug() << lackey.error() << lackey.errorString(); QVERIFY(lackey.waitForStarted()); -- cgit v0.12 From d1d81d48dff6b3285d9016d8f3354630926463d8 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Wed, 17 Feb 2010 12:48:07 +1000 Subject: Disable NLA plugin, build generic on win32 and mac. The NLA plugin locks up on exit for some programs, though not all. Disable for now until cause is found. Always build generic plugin on win32 and mac. --- src/plugins/bearer/bearer.pro | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/plugins/bearer/bearer.pro b/src/plugins/bearer/bearer.pro index 6ce1f0d..7ba62b3 100644 --- a/src/plugins/bearer/bearer.pro +++ b/src/plugins/bearer/bearer.pro @@ -3,9 +3,11 @@ TEMPLATE = subdirs !maemo:contains(QT_CONFIG, dbus):contains(QT_CONFIG, networkmanager) { SUBDIRS += networkmanager generic } -win32:SUBDIRS += nla +#win32:SUBDIRS += nla +win32:SUBDIRS += generic win32:!wince*:SUBDIRS += nativewifi macx:SUBDIRS += corewlan +macx:SUBDIRS += generic symbian:SUBDIRS += symbian maemo6:contains(QT_CONFIG, dbus):SUBDIRS += icd -- cgit v0.12 From 49f63d8f37fcd45ebe527f3554ff7b4c34d8545e Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 18 Feb 2010 10:12:24 +1000 Subject: Don't load NetworkManager plugin in NetworkManager is not available. --- src/plugins/bearer/networkmanager/main.cpp | 13 +++++++++---- src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp | 8 ++++++++ src/plugins/bearer/networkmanager/qnetworkmanagerengine.h | 2 ++ .../bearer/networkmanager/qnetworkmanagerservice.cpp | 3 +-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/plugins/bearer/networkmanager/main.cpp b/src/plugins/bearer/networkmanager/main.cpp index f62b847..6c97a22 100644 --- a/src/plugins/bearer/networkmanager/main.cpp +++ b/src/plugins/bearer/networkmanager/main.cpp @@ -72,10 +72,15 @@ QStringList QNetworkManagerEnginePlugin::keys() const QBearerEngine *QNetworkManagerEnginePlugin::create(const QString &key) const { - if (key == QLatin1String("networkmanager")) - return new QNetworkManagerEngine; - else - return 0; + if (key == QLatin1String("networkmanager")) { + QNetworkManagerEngine *engine = new QNetworkManagerEngine; + if (engine->networkManagerAvailable()) + return engine; + else + delete engine; + } + + return 0; } Q_EXPORT_STATIC_PLUGIN(QNetworkManagerEnginePlugin) diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp index 3f3e1bd..4c8928c 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp @@ -65,6 +65,9 @@ QNetworkManagerEngine::QNetworkManagerEngine(QObject *parent) systemSettings(new QNetworkManagerSettings(NM_DBUS_SERVICE_SYSTEM_SETTINGS, this)), userSettings(new QNetworkManagerSettings(NM_DBUS_SERVICE_USER_SETTINGS, this)) { + if (!interface->isValid()) + return; + interface->setConnections(); connect(interface, SIGNAL(deviceAdded(QDBusObjectPath)), this, SLOT(deviceAdded(QDBusObjectPath))); @@ -115,6 +118,11 @@ QNetworkManagerEngine::~QNetworkManagerEngine() { } +bool QNetworkManagerEngine::networkManagerAvailable() const +{ + return interface->isValid(); +} + void QNetworkManagerEngine::doRequestUpdate() { emit updateCompleted(); diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h index 70efc05..ca1f857 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h @@ -70,6 +70,8 @@ public: QNetworkManagerEngine(QObject *parent = 0); ~QNetworkManagerEngine(); + bool networkManagerAvailable() const; + QString getInterfaceFromId(const QString &id); bool hasIdentifier(const QString &id); diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp index 7617e94..5dc0ea4 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp @@ -78,7 +78,6 @@ QNetworkManagerInterface::QNetworkManagerInterface(QObject *parent) NM_DBUS_INTERFACE, dbusConnection); if (!d->connectionInterface->isValid()) { - qWarning() << "Could not find NetworkManager"; d->valid = false; return; } @@ -321,7 +320,7 @@ QNetworkManagerInterfaceDevice::QNetworkManagerInterfaceDevice(const QString &de dbusConnection); if (!d->connectionInterface->isValid()) { d->valid = false; - qWarning() << "Could not find NetworkManager"; + qWarning() << "Could not find NetworkManagerInterfaceDevice"; return; } d->valid = true; -- cgit v0.12 From e0eb03ec78330b5b2bd064267db71992d81d88c5 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 18 Feb 2010 14:24:20 +1000 Subject: Allow QNAM to be created as a global variable. QNetworkConfigurationManager cannot be loaded before QApplication as the plugins it loads may create timers. Which fail because timers can only be created in threads created with QThread. --- src/network/access/qnetworkaccessmanager.cpp | 10 +++++++--- src/network/access/qnetworkaccessmanager_p.h | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 69b57e5..ea60f98 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -386,9 +386,6 @@ QNetworkAccessManager::QNetworkAccessManager(QObject *parent) : QObject(*new QNetworkAccessManagerPrivate, parent) { ensureInitialized(); - - QNetworkConfigurationManager manager; - d_func()->createSession(manager.defaultConfiguration()); } /*! @@ -847,6 +844,13 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera return new QDisabledNetworkReply(this, req, op); } + if (d->initializeSession && !d->networkSession) { + QNetworkConfigurationManager manager; + d->createSession(manager.defaultConfiguration()); + + d->initializeSession = false; + } + QNetworkRequest request = req; if (!request.header(QNetworkRequest::ContentLengthHeader).isValid() && outgoingData && !outgoingData->isSequential()) { diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h index 8a1f19d..8d772f0 100644 --- a/src/network/access/qnetworkaccessmanager_p.h +++ b/src/network/access/qnetworkaccessmanager_p.h @@ -77,6 +77,7 @@ public: #endif networkSession(0), networkAccessEnabled(true), + initializeSession(true), cookieJarCreated(false) { } ~QNetworkAccessManagerPrivate(); @@ -121,6 +122,7 @@ public: QNetworkSession *networkSession; bool networkAccessEnabled; + bool initializeSession; bool cookieJarCreated; -- cgit v0.12 From 46e84339a9eaf1587528c20a4c9e05bc1b549afd Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Fri, 19 Feb 2010 12:02:29 +1000 Subject: Create unit-test in parent directory. --- tests/auto/qnetworksession/qnetworksession.pro | 2 +- tests/auto/qnetworksession/test/test.pro | 26 + .../qnetworksession/test/tst_qnetworksession.cpp | 919 +++++++++++++++++++++ .../tst_qnetworksession/tst_qnetworksession.cpp | 919 --------------------- .../tst_qnetworksession/tst_qnetworksession.pro | 15 - 5 files changed, 946 insertions(+), 935 deletions(-) create mode 100644 tests/auto/qnetworksession/test/test.pro create mode 100644 tests/auto/qnetworksession/test/tst_qnetworksession.cpp delete mode 100644 tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp delete mode 100644 tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro diff --git a/tests/auto/qnetworksession/qnetworksession.pro b/tests/auto/qnetworksession/qnetworksession.pro index 14dbb3e..a85925b 100644 --- a/tests/auto/qnetworksession/qnetworksession.pro +++ b/tests/auto/qnetworksession/qnetworksession.pro @@ -1,2 +1,2 @@ TEMPLATE = subdirs -SUBDIRS = lackey tst_qnetworksession +SUBDIRS = lackey test diff --git a/tests/auto/qnetworksession/test/test.pro b/tests/auto/qnetworksession/test/test.pro new file mode 100644 index 0000000..d248b10 --- /dev/null +++ b/tests/auto/qnetworksession/test/test.pro @@ -0,0 +1,26 @@ +load(qttest_p4) +SOURCES += tst_qnetworksession.cpp +HEADERS += ../../qbearertestcommon.h + +QT = core network + +TARGET = tst_qnetworksession +CONFIG(debug_and_release) { + CONFIG(debug, debug|release) { + DESTDIR = ../debug + } else { + DESTDIR = ../release + } +} else { + DESTDIR = .. +} + +symbian { + TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData PowerMgmt +} + +maemo6 { + CONFIG += link_pkgconfig + + PKGCONFIG += conninet +} diff --git a/tests/auto/qnetworksession/test/tst_qnetworksession.cpp b/tests/auto/qnetworksession/test/tst_qnetworksession.cpp new file mode 100644 index 0000000..4ef3a4f --- /dev/null +++ b/tests/auto/qnetworksession/test/tst_qnetworksession.cpp @@ -0,0 +1,919 @@ +/**************************************************************************** +** +** 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 test suite 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 +#include +#include +#include "../../qbearertestcommon.h" +#include +#include + +#ifdef Q_WS_MAEMO_6 +#include +#include +#endif + +QT_USE_NAMESPACE + +Q_DECLARE_METATYPE(QNetworkConfiguration) +Q_DECLARE_METATYPE(QNetworkSession::State); +Q_DECLARE_METATYPE(QNetworkSession::SessionError); + +class tst_QNetworkSession : public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + +private slots: + + void outOfProcessSession(); + void invalidSession(); + + void sessionProperties_data(); + void sessionProperties(); + + void userChoiceSession_data(); + void userChoiceSession(); + + void sessionOpenCloseStop_data(); + void sessionOpenCloseStop(); + +private: + QNetworkConfigurationManager manager; + + int inProcessSessionManagementCount; + +#ifdef Q_WS_MAEMO_6 + Maemo::IAPConf *iapconf; + Maemo::IAPConf *iapconf2; + Maemo::IAPConf *gprsiap; +#define MAX_IAPS 10 + Maemo::IAPConf *iaps[MAX_IAPS]; + QProcess *icd_stub; +#endif +}; + +void tst_QNetworkSession::initTestCase() +{ + qRegisterMetaType("QNetworkSession::State"); + qRegisterMetaType("QNetworkSession::SessionError"); + qRegisterMetaType("QNetworkConfiguration"); + +#ifdef Q_WS_MAEMO_6 + iapconf = new Maemo::IAPConf("007"); + iapconf->setValue("ipv4_type", "AUTO"); + iapconf->setValue("wlan_wepkey1", "connt"); + iapconf->setValue("wlan_wepdefkey", 1); + iapconf->setValue("wlan_ssid", QByteArray("JamesBond")); + iapconf->setValue("name", "James Bond"); + iapconf->setValue("type", "WLAN_INFRA"); + + gprsiap = new Maemo::IAPConf("This-is-GPRS-IAP"); + gprsiap->setValue("ask_password", false); + gprsiap->setValue("gprs_accesspointname", "internet"); + gprsiap->setValue("gprs_password", ""); + gprsiap->setValue("gprs_username", ""); + gprsiap->setValue("ipv4_autodns", true); + gprsiap->setValue("ipv4_type", "AUTO"); + gprsiap->setValue("sim_imsi", "244070123456789"); + gprsiap->setValue("name", "MI6"); + gprsiap->setValue("type", "GPRS"); + + iapconf2 = new Maemo::IAPConf("osso.net"); + iapconf2->setValue("ipv4_type", "AUTO"); + iapconf2->setValue("wlan_wepkey1", "osso.net"); + iapconf2->setValue("wlan_wepdefkey", 1); + iapconf2->setValue("wlan_ssid", QByteArray("osso.net")); + iapconf2->setValue("name", "osso.net"); + iapconf2->setValue("type", "WLAN_INFRA"); + iapconf2->setValue("wlan_security", "WEP"); + + /* Create large number of IAPs in the gconf and see what happens */ + fflush(stdout); + printf("Creating %d IAPS: ", MAX_IAPS); + for (int i=0; isetValue("name", QString("test-iap-")+num); + iaps[i]->setValue("type", "WLAN_INFRA"); + iaps[i]->setValue("wlan_ssid", QString(QString("test-ssid-")+num).toAscii()); + iaps[i]->setValue("wlan_security", "WPA_PSK"); + iaps[i]->setValue("EAP_wpa_preshared_passphrase", QString("test-passphrase-")+num); + printf("."); + fflush(stdout); + } + printf("\n"); + fflush(stdout); + + icd_stub = new QProcess(this); + icd_stub->start("/usr/bin/icd2_stub.py"); + QTest::qWait(1000); + + // Add a known network to scan list that icd2 stub returns + QProcess dbus_send; + // 007 network + dbus_send.start("dbus-send --type=method_call --system " + "--dest=com.nokia.icd2 /com/nokia/icd2 " + "com.nokia.icd2.testing.add_available_network " + "string:'' uint32:0 string:'' " + "string:WLAN_INFRA uint32:5000011 array:byte:48,48,55"); + dbus_send.waitForFinished(); + + // osso.net network + dbus_send.start("dbus-send --type=method_call --system " + "--dest=com.nokia.icd2 /com/nokia/icd2 " + "com.nokia.icd2.testing.add_available_network " + "string:'' uint32:0 string:'' " + "string:WLAN_INFRA uint32:83886097 array:byte:111,115,115,111,46,110,101,116"); + dbus_send.waitForFinished(); +#endif + + inProcessSessionManagementCount = -1; + + QSignalSpy spy(&manager, SIGNAL(updateCompleted())); + manager.updateConfigurations(); + QTRY_VERIFY(spy.count() == 1); +} + +void tst_QNetworkSession::cleanupTestCase() +{ + if (!(manager.capabilities() & QNetworkConfigurationManager::SystemSessionSupport) && + (manager.capabilities() & QNetworkConfigurationManager::CanStartAndStopInterfaces) && + inProcessSessionManagementCount == 0) { + qWarning("No usable configurations found to complete all possible tests in " + "inProcessSessionManagement()"); + } + +#ifdef Q_WS_MAEMO_6 + iapconf->clear(); + delete iapconf; + iapconf2->clear(); + delete iapconf2; + gprsiap->clear(); + delete gprsiap; + + printf("Deleting %d IAPS : ", MAX_IAPS); + for (int i=0; iclear(); + delete iaps[i]; + printf("."); + fflush(stdout); + } + printf("\n"); + qDebug() << "Deleted" << MAX_IAPS << "IAPs"; + + icd_stub->terminate(); + icd_stub->waitForFinished(); +#endif +} + +void tst_QNetworkSession::invalidSession() +{ + QNetworkSession session(QNetworkConfiguration(), 0); + QVERIFY(!session.isOpen()); + QVERIFY(session.state() == QNetworkSession::Invalid); +} + +void tst_QNetworkSession::sessionProperties_data() +{ + QTest::addColumn("configuration"); + + QTest::newRow("invalid configuration") << QNetworkConfiguration(); + + foreach (const QNetworkConfiguration &config, manager.allConfigurations()) { + const QString name = config.name().isEmpty() ? QString("") : config.name(); + QTest::newRow(name.toLocal8Bit().constData()) << config; + } +} + +void tst_QNetworkSession::sessionProperties() +{ + QFETCH(QNetworkConfiguration, configuration); + + QNetworkSession session(configuration); + + QVERIFY(session.configuration() == configuration); + + QStringList validBearerNames = QStringList() << QLatin1String("Unknown") + << QLatin1String("Ethernet") + << QLatin1String("WLAN") + << QLatin1String("2G") + << QLatin1String("CDMA2000") + << QLatin1String("WCDMA") + << QLatin1String("HSPA") + << QLatin1String("Bluetooth") + << QLatin1String("WiMAX"); + + if (!configuration.isValid()) { + QVERIFY(configuration.bearerName().isEmpty()); + } else { + qDebug() << "Type:" << configuration.type() + << "Bearer:" << configuration.bearerName(); + + switch (configuration.type()) + { + case QNetworkConfiguration::ServiceNetwork: + case QNetworkConfiguration::UserChoice: + default: + QVERIFY(configuration.bearerName().isEmpty()); + break; + case QNetworkConfiguration::InternetAccessPoint: + QVERIFY(validBearerNames.contains(configuration.bearerName())); + break; + } + } + + // QNetworkSession::interface() should return an invalid interface unless + // session is in the connected state. + qDebug() << "Session state:" << session.state(); + qDebug() << "Session iface:" << session.interface().isValid() << session.interface().name(); +#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__)) + // On Symbian emulator, the support for data bearers is limited + QCOMPARE(session.state() == QNetworkSession::Connected, session.interface().isValid()); +#endif + + if (!configuration.isValid()) { + QVERIFY(configuration.state() == QNetworkConfiguration::Undefined && + session.state() == QNetworkSession::Invalid); + } else { + switch (configuration.state()) { + case QNetworkConfiguration::Undefined: + QVERIFY(session.state() == QNetworkSession::NotAvailable); + break; + case QNetworkConfiguration::Defined: + QVERIFY(session.state() == QNetworkSession::NotAvailable); + break; + case QNetworkConfiguration::Discovered: + QVERIFY(session.state() == QNetworkSession::Connecting || + session.state() == QNetworkSession::Disconnected); + break; + case QNetworkConfiguration::Active: + QVERIFY(session.state() == QNetworkSession::Connected || + session.state() == QNetworkSession::Closing || + session.state() == QNetworkSession::Roaming); + break; + default: + QFAIL("Invalid configuration state"); + }; + } +} + +void tst_QNetworkSession::userChoiceSession_data() +{ + QTest::addColumn("configuration"); + + QNetworkConfiguration config = manager.defaultConfiguration(); + if (config.type() == QNetworkConfiguration::UserChoice) + QTest::newRow("UserChoice") << config; + else + QSKIP("Default configuration is not a UserChoice configuration.", SkipAll); +} + +void tst_QNetworkSession::userChoiceSession() +{ + QFETCH(QNetworkConfiguration, configuration); + + QVERIFY(configuration.type() == QNetworkConfiguration::UserChoice); + + QNetworkSession session(configuration); + + // Check that configuration was really set + QVERIFY(session.configuration() == configuration); + + QVERIFY(!session.isOpen()); + + // Check that session is not active + QVERIFY(session.sessionProperty("ActiveConfiguration").toString().isEmpty()); + + // The remaining tests require the session to be not NotAvailable. + if (session.state() == QNetworkSession::NotAvailable) + QSKIP("Network is not available.", SkipSingle); + + QSignalSpy sessionOpenedSpy(&session, SIGNAL(opened())); + QSignalSpy sessionClosedSpy(&session, SIGNAL(closed())); + QSignalSpy stateChangedSpy(&session, SIGNAL(stateChanged(QNetworkSession::State))); + QSignalSpy errorSpy(&session, SIGNAL(error(QNetworkSession::SessionError))); + + // Test opening the session. + { + bool expectStateChange = session.state() != QNetworkSession::Connected; + + session.open(); + + session.waitForOpened(); + + if (session.isOpen()) + QVERIFY(!sessionOpenedSpy.isEmpty() || !errorSpy.isEmpty()); + if (!errorSpy.isEmpty()) { + QNetworkSession::SessionError error = + qvariant_cast(errorSpy.first().at(0)); + if (error == QNetworkSession::OperationNotSupportedError) { + // The session needed to bring up the interface, + // but the operation is not supported. + QSKIP("Configuration does not support open().", SkipSingle); + } else if (error == QNetworkSession::InvalidConfigurationError) { + // The session needed to bring up the interface, but it is not possible for the + // specified configuration. + if ((session.configuration().state() & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + QFAIL("Failed to open session for Discovered configuration."); + } else { + QSKIP("Cannot test session for non-Discovered configuration.", SkipSingle); + } + } else if (error == QNetworkSession::UnknownSessionError) { + QSKIP("Unknown session error.", SkipSingle); + } else { + QFAIL("Error opening session."); + } + } else if (!sessionOpenedSpy.isEmpty()) { + QCOMPARE(sessionOpenedSpy.count(), 1); + QVERIFY(sessionClosedSpy.isEmpty()); + QVERIFY(errorSpy.isEmpty()); + + if (expectStateChange) + QTRY_VERIFY(!stateChangedSpy.isEmpty()); + + QVERIFY(session.state() == QNetworkSession::Connected); +#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__)) + // On Symbian emulator, the support for data bearers is limited + QVERIFY(session.interface().isValid()); +#endif + + const QString userChoiceIdentifier = + session.sessionProperty("UserChoiceConfiguration").toString(); + + QVERIFY(!userChoiceIdentifier.isEmpty()); + QVERIFY(userChoiceIdentifier != configuration.identifier()); + + QNetworkConfiguration userChoiceConfiguration = + manager.configurationFromIdentifier(userChoiceIdentifier); + + QVERIFY(userChoiceConfiguration.isValid()); + QVERIFY(userChoiceConfiguration.type() != QNetworkConfiguration::UserChoice); + + const QString testIdentifier("abc"); + //resetting UserChoiceConfiguration is ignored (read only property) + session.setSessionProperty("UserChoiceConfiguration", testIdentifier); + QVERIFY(session.sessionProperty("UserChoiceConfiguration").toString() != testIdentifier); + + const QString activeIdentifier = + session.sessionProperty("ActiveConfiguration").toString(); + + QVERIFY(!activeIdentifier.isEmpty()); + QVERIFY(activeIdentifier != configuration.identifier()); + + QNetworkConfiguration activeConfiguration = + manager.configurationFromIdentifier(activeIdentifier); + + QVERIFY(activeConfiguration.isValid()); + QVERIFY(activeConfiguration.type() == QNetworkConfiguration::InternetAccessPoint); + + //resetting ActiveConfiguration is ignored (read only property) + session.setSessionProperty("ActiveConfiguration", testIdentifier); + QVERIFY(session.sessionProperty("ActiveConfiguration").toString() != testIdentifier); + + if (userChoiceConfiguration.type() == QNetworkConfiguration::InternetAccessPoint) { + QVERIFY(userChoiceConfiguration == activeConfiguration); + } else { + QVERIFY(userChoiceConfiguration.type() == QNetworkConfiguration::ServiceNetwork); + QVERIFY(userChoiceConfiguration.children().contains(activeConfiguration)); + } + } else { + QFAIL("Timeout waiting for session to open."); + } + } +} + +void tst_QNetworkSession::sessionOpenCloseStop_data() +{ + QTest::addColumn("configuration"); + QTest::addColumn("forceSessionStop"); + + foreach (const QNetworkConfiguration &config, manager.allConfigurations()) { + const QString name = config.name().isEmpty() ? QString("") : config.name(); + QTest::newRow((name + QLatin1String(" close")).toLocal8Bit().constData()) + << config << false; + QTest::newRow((name + QLatin1String(" stop")).toLocal8Bit().constData()) + << config << true; + } + + inProcessSessionManagementCount = 0; +} + +void tst_QNetworkSession::sessionOpenCloseStop() +{ + QFETCH(QNetworkConfiguration, configuration); + QFETCH(bool, forceSessionStop); + + QNetworkSession session(configuration); + + // Test initial state of the session. + { + QVERIFY(session.configuration() == configuration); + QVERIFY(!session.isOpen()); + // session may be invalid if configuration is removed between when + // sessionOpenCloseStop_data() is called and here. + QVERIFY((configuration.isValid() && (session.state() != QNetworkSession::Invalid)) || + (!configuration.isValid() && (session.state() == QNetworkSession::Invalid))); + QVERIFY(session.error() == QNetworkSession::UnknownSessionError); + } + + // The remaining tests require the session to be not NotAvailable. + if (session.state() == QNetworkSession::NotAvailable) + QSKIP("Network is not available.", SkipSingle); + + QSignalSpy sessionOpenedSpy(&session, SIGNAL(opened())); + QSignalSpy sessionClosedSpy(&session, SIGNAL(closed())); + QSignalSpy stateChangedSpy(&session, SIGNAL(stateChanged(QNetworkSession::State))); + QSignalSpy errorSpy(&session, SIGNAL(error(QNetworkSession::SessionError))); + + // Test opening the session. + { + QNetworkSession::State previousState = session.state(); + bool expectStateChange = previousState != QNetworkSession::Connected; + + session.open(); + + session.waitForOpened(); + + if (session.isOpen()) + QVERIFY(!sessionOpenedSpy.isEmpty() || !errorSpy.isEmpty()); + if (!errorSpy.isEmpty()) { + QNetworkSession::SessionError error = + qvariant_cast(errorSpy.first().at(0)); + + QVERIFY(session.state() == previousState); + + if (error == QNetworkSession::OperationNotSupportedError) { + // The session needed to bring up the interface, + // but the operation is not supported. + QSKIP("Configuration does not support open().", SkipSingle); + } else if (error == QNetworkSession::InvalidConfigurationError) { + // The session needed to bring up the interface, but it is not possible for the + // specified configuration. + if ((session.configuration().state() & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + QFAIL("Failed to open session for Discovered configuration."); + } else { + QSKIP("Cannot test session for non-Discovered configuration.", SkipSingle); + } + } else if (error == QNetworkSession::UnknownSessionError) { + QSKIP("Unknown Session error.", SkipSingle); + } else { + QFAIL("Error opening session."); + } + } else if (!sessionOpenedSpy.isEmpty()) { + QCOMPARE(sessionOpenedSpy.count(), 1); + QVERIFY(sessionClosedSpy.isEmpty()); + QVERIFY(errorSpy.isEmpty()); + + if (expectStateChange) { + QTRY_VERIFY(stateChangedSpy.count() >= 2); + + QNetworkSession::State state = + qvariant_cast(stateChangedSpy.at(0).at(0)); + QVERIFY(state == QNetworkSession::Connecting); + + state = qvariant_cast(stateChangedSpy.at(1).at(0)); + QVERIFY(state == QNetworkSession::Connected); + } + + QVERIFY(session.state() == QNetworkSession::Connected); +#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__)) + // On Symbian emulator, the support for data bearers is limited + QVERIFY(session.interface().isValid()); +#endif + } else { + QFAIL("Timeout waiting for session to open."); + } + } + + sessionOpenedSpy.clear(); + sessionClosedSpy.clear(); + stateChangedSpy.clear(); + errorSpy.clear(); + + QNetworkSession session2(configuration); + + QSignalSpy sessionOpenedSpy2(&session2, SIGNAL(opened())); + QSignalSpy sessionClosedSpy2(&session2, SIGNAL(closed())); + QSignalSpy stateChangedSpy2(&session2, SIGNAL(stateChanged(QNetworkSession::State))); + QSignalSpy errorSpy2(&session2, SIGNAL(error(QNetworkSession::SessionError))); + + // Test opening a second session. + { + QVERIFY(session2.configuration() == configuration); + QVERIFY(!session2.isOpen()); + QVERIFY(session2.state() == QNetworkSession::Connected); + QVERIFY(session.error() == QNetworkSession::UnknownSessionError); + + session2.open(); + + QTRY_VERIFY(!sessionOpenedSpy2.isEmpty() || !errorSpy2.isEmpty()); + + QVERIFY(session.isOpen()); + QVERIFY(session2.isOpen()); + QVERIFY(session.state() == QNetworkSession::Connected); + QVERIFY(session2.state() == QNetworkSession::Connected); +#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__)) + // On Symbian emulator, the support for data bearers is limited + QVERIFY(session.interface().isValid()); +#endif + QCOMPARE(session.interface().hardwareAddress(), session2.interface().hardwareAddress()); + QCOMPARE(session.interface().index(), session2.interface().index()); + } + + sessionOpenedSpy2.clear(); + + if (forceSessionStop) { + // Test forcing the second session to stop the interface. + QNetworkSession::State previousState = session.state(); +#ifdef Q_CC_NOKIAX86 + // For S60 emulator builds: RConnection::Stop does not work on all Emulators + bool expectStateChange = false; +#else + bool expectStateChange = previousState != QNetworkSession::Disconnected; +#endif + + session2.stop(); + + QTRY_VERIFY(!sessionClosedSpy2.isEmpty() || !errorSpy2.isEmpty()); + + QVERIFY(!session2.isOpen()); + + if (!errorSpy2.isEmpty()) { + QVERIFY(!errorSpy.isEmpty()); + + // check for SessionAbortedError + QNetworkSession::SessionError error = + qvariant_cast(errorSpy.first().at(0)); + QNetworkSession::SessionError error2 = + qvariant_cast(errorSpy2.first().at(0)); + + QVERIFY(error == QNetworkSession::SessionAbortedError); + QVERIFY(error2 == QNetworkSession::SessionAbortedError); + + QCOMPARE(errorSpy.count(), 1); + QCOMPARE(errorSpy2.count(), 1); + + errorSpy.clear(); + errorSpy2.clear(); + } + + QVERIFY(errorSpy.isEmpty()); + QVERIFY(errorSpy2.isEmpty()); + + if (expectStateChange) + QTRY_VERIFY(stateChangedSpy2.count() >= 2 || !errorSpy2.isEmpty()); + + if (!errorSpy2.isEmpty()) { + QVERIFY(session2.state() == previousState); + QVERIFY(session.state() == previousState); + + QNetworkSession::SessionError error = + qvariant_cast(errorSpy2.first().at(0)); + if (error == QNetworkSession::OperationNotSupportedError) { + // The session needed to bring down the interface, + // but the operation is not supported. + QSKIP("Configuration does not support stop().", SkipSingle); + } else if (error == QNetworkSession::InvalidConfigurationError) { + // The session needed to bring down the interface, but it is not possible for the + // specified configuration. + if ((session.configuration().state() & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + QFAIL("Failed to stop session for Discovered configuration."); + } else { + QSKIP("Cannot test session for non-Discovered configuration.", SkipSingle); + } + } else { + QFAIL("Error stopping session."); + } + } else if (!sessionClosedSpy2.isEmpty()) { + if (expectStateChange) { + if (configuration.type() == QNetworkConfiguration::ServiceNetwork) { + bool roamedSuccessfully = false; + + QCOMPARE(stateChangedSpy2.count(), 4); + + QNetworkSession::State state = + qvariant_cast(stateChangedSpy2.at(0).at(0)); + QVERIFY(state == QNetworkSession::Connecting); + + state = qvariant_cast(stateChangedSpy2.at(1).at(0)); + QVERIFY(state == QNetworkSession::Connected); + + state = qvariant_cast(stateChangedSpy2.at(2).at(0)); + QVERIFY(state == QNetworkSession::Closing); + + state = qvariant_cast(stateChangedSpy2.at(3).at(0)); + QVERIFY(state == QNetworkSession::Disconnected); + + QTRY_VERIFY(stateChangedSpy.count() > 0); + state = qvariant_cast(stateChangedSpy.at(0).at(0)); + if (state == QNetworkSession::Roaming) { + QTRY_VERIFY(!errorSpy.isEmpty() || stateChangedSpy.count() > 1); + if (stateChangedSpy.count() > 1) { + state = qvariant_cast(stateChangedSpy.at(1).at(0)); + if (state == QNetworkSession::Connected) { + roamedSuccessfully = true; + QTRY_VERIFY(session2.state() == QNetworkSession::Disconnected); + } + } + } + if (roamedSuccessfully) { + QString configId = session.sessionProperty("ActiveConfiguration").toString(); + QNetworkConfiguration config = manager.configurationFromIdentifier(configId); + QNetworkSession session3(config); + QSignalSpy errorSpy3(&session3, SIGNAL(error(QNetworkSession::SessionError))); + QSignalSpy sessionOpenedSpy3(&session3, SIGNAL(opened())); + + session3.open(); + session3.waitForOpened(); + + if (session.isOpen()) + QVERIFY(!sessionOpenedSpy3.isEmpty() || !errorSpy3.isEmpty()); + + session.stop(); + + QTRY_VERIFY(session.state() == QNetworkSession::Disconnected); + QTRY_VERIFY(session3.state() == QNetworkSession::Disconnected); + } +#ifndef Q_CC_NOKIAX86 + if (!roamedSuccessfully) + QVERIFY(!errorSpy.isEmpty()); +#endif + } else { + QCOMPARE(stateChangedSpy2.count(), 2); + + QNetworkSession::State state = + qvariant_cast(stateChangedSpy2.at(0).at(0)); + QVERIFY(state == QNetworkSession::Closing); + + state = qvariant_cast(stateChangedSpy2.at(1).at(0)); + QVERIFY(state == QNetworkSession::Disconnected); + } + + QTRY_VERIFY(!sessionClosedSpy.isEmpty()); + QVERIFY(session.state() == QNetworkSession::Disconnected); + QVERIFY(session2.state() == QNetworkSession::Disconnected); + } + + QVERIFY(errorSpy2.isEmpty()); + + ++inProcessSessionManagementCount; + } else { + QFAIL("Timeout waiting for session to stop."); + } + +#ifndef Q_CC_NOKIAX86 + QVERIFY(!sessionClosedSpy.isEmpty()); +#endif + QVERIFY(!sessionClosedSpy2.isEmpty()); + +#ifndef Q_CC_NOKIAX86 + QVERIFY(!session.isOpen()); +#endif + QVERIFY(!session2.isOpen()); + } else { + // Test closing the second session. + { + int stateChangedCountBeforeClose = stateChangedSpy2.count(); + session2.close(); + + QTRY_VERIFY(!sessionClosedSpy2.isEmpty()); +#ifndef Q_CC_NOKIAX86 + QVERIFY(stateChangedSpy2.count() == stateChangedCountBeforeClose); +#endif + + QVERIFY(sessionClosedSpy.isEmpty()); + + QVERIFY(session.isOpen()); + QVERIFY(!session2.isOpen()); + QVERIFY(session.state() == QNetworkSession::Connected); + QVERIFY(session2.state() == QNetworkSession::Connected); +#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__)) + // On Symbian emulator, the support for data bearers is limited + QVERIFY(session.interface().isValid()); +#endif + QCOMPARE(session.interface().hardwareAddress(), session2.interface().hardwareAddress()); + QCOMPARE(session.interface().index(), session2.interface().index()); + } + + sessionClosedSpy2.clear(); + + // Test closing the first session. + { +#ifdef Q_CC_NOKIAX86 + // For S60 emulator builds: RConnection::Close does not actually + // close network connection on all Emulators + bool expectStateChange = false; +#else + bool expectStateChange = session.state() != QNetworkSession::Disconnected && + manager.capabilities() & QNetworkConfigurationManager::SystemSessionSupport; +#endif + + session.close(); + + QTRY_VERIFY(!sessionClosedSpy.isEmpty() || !errorSpy.isEmpty()); + + QVERIFY(!session.isOpen()); + + if (expectStateChange) + QTRY_VERIFY(!stateChangedSpy.isEmpty() || !errorSpy.isEmpty()); + + if (!errorSpy.isEmpty()) { + QNetworkSession::SessionError error = + qvariant_cast(errorSpy.first().at(0)); + if (error == QNetworkSession::OperationNotSupportedError) { + // The session needed to bring down the interface, + // but the operation is not supported. + QSKIP("Configuration does not support close().", SkipSingle); + } else if (error == QNetworkSession::InvalidConfigurationError) { + // The session needed to bring down the interface, but it is not possible for the + // specified configuration. + if ((session.configuration().state() & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + QFAIL("Failed to close session for Discovered configuration."); + } else { + QSKIP("Cannot test session for non-Discovered configuration.", SkipSingle); + } + } else { + QFAIL("Error closing session."); + } + } else if (!sessionClosedSpy.isEmpty()) { + QVERIFY(sessionOpenedSpy.isEmpty()); + QCOMPARE(sessionClosedSpy.count(), 1); + if (expectStateChange) + QVERIFY(!stateChangedSpy.isEmpty()); + QVERIFY(errorSpy.isEmpty()); + + if (expectStateChange) + QTRY_VERIFY(session.state() == QNetworkSession::Disconnected); + + ++inProcessSessionManagementCount; + } else { + QFAIL("Timeout waiting for session to close."); + } + } + } +} + +QDebug operator<<(QDebug debug, const QList &list) +{ + debug.nospace() << "( "; + foreach (const QNetworkConfiguration &config, list) + debug.nospace() << config.identifier() << ", "; + debug.nospace() << ")\n"; + return debug; +} + +// Note: outOfProcessSession requires that at least one configuration is +// at Discovered -state (Defined is ok for symbian as well, as long as it is possible to open). +void tst_QNetworkSession::outOfProcessSession() +{ + qDebug() << "START"; + +#if defined(Q_OS_SYMBIAN) && defined(__WINS__) + QSKIP("Symbian emulator does not support two [QR]PRocesses linking a dll (QtBearer.dll) with global writeable static data.", SkipAll); +#endif + QNetworkConfigurationManager manager; + // Create a QNetworkConfigurationManager to detect configuration changes made in Lackey. This + // is actually the essence of this testcase - to check that platform mediates/reflects changes + // regardless of process boundaries. The interprocess communication is more like a way to get + // this test-case act correctly and timely. + QList before = manager.allConfigurations(QNetworkConfiguration::Active); + QSignalSpy spy(&manager, SIGNAL(configurationChanged(QNetworkConfiguration))); + + // Cannot read/write to processes on WinCE or Symbian. + // Easiest alternative is to use sockets for IPC. + QLocalServer oopServer; + // First remove possible earlier listening address which would cause listen to fail + // (e.g. previously abruptly ended unit test might cause this) + QLocalServer::removeServer("tst_qnetworksession"); + oopServer.listen("tst_qnetworksession"); + + qDebug() << "starting lackey"; + QProcess lackey; + lackey.start("lackey/lackey"); + qDebug() << lackey.error() << lackey.errorString(); + QVERIFY(lackey.waitForStarted()); + + qDebug() << "waiting for connection"; + QVERIFY(oopServer.waitForNewConnection(-1)); + QLocalSocket *oopSocket = oopServer.nextPendingConnection(); + qDebug() << "got connection"; + do { + QByteArray output; + + if (oopSocket->waitForReadyRead()) + output = oopSocket->readLine().trimmed(); + + if (output.startsWith("Started session ")) { + QString identifier = QString::fromLocal8Bit(output.mid(20).constData()); + QNetworkConfiguration changed; + + do { + QTRY_VERIFY(!spy.isEmpty()); + changed = qvariant_cast(spy.takeFirst().at(0)); + } while (changed.identifier() != identifier); + + QVERIFY((changed.state() & QNetworkConfiguration::Active) == + QNetworkConfiguration::Active); + + QVERIFY(!before.contains(changed)); + + QList after = + manager.allConfigurations(QNetworkConfiguration::Active); + + QVERIFY(after.contains(changed)); + + spy.clear(); + + oopSocket->write("stop\n"); + oopSocket->waitForBytesWritten(); + + do { + QTRY_VERIFY(!spy.isEmpty()); + + changed = qvariant_cast(spy.takeFirst().at(0)); + } while (changed.identifier() != identifier); + + QVERIFY((changed.state() & QNetworkConfiguration::Active) != + QNetworkConfiguration::Active); + + QList afterStop = + manager.allConfigurations(QNetworkConfiguration::Active); + + QVERIFY(!afterStop.contains(changed)); + + oopSocket->disconnectFromServer(); + oopSocket->waitForDisconnected(-1); + + lackey.waitForFinished(); + } + // This is effected by QTBUG-4903, process will always report as running + //} while (lackey.state() == QProcess::Running); + + // Workaround: the socket in the lackey will disconnect on exit + } while (oopSocket->state() == QLocalSocket::ConnectedState); + + switch (lackey.exitCode()) { + case 0: + qDebug("Lackey returned exit success (0)"); + break; + case 1: + QSKIP("No discovered configurations found.", SkipAll); + case 2: + QSKIP("Lackey could not start session.", SkipAll); + default: + QSKIP("Lackey failed", SkipAll); + } + qDebug("STOP"); +} + +QTEST_MAIN(tst_QNetworkSession) + +#include "tst_qnetworksession.moc" + diff --git a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp deleted file mode 100644 index 4ef3a4f..0000000 --- a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp +++ /dev/null @@ -1,919 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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 -#include -#include -#include "../../qbearertestcommon.h" -#include -#include - -#ifdef Q_WS_MAEMO_6 -#include -#include -#endif - -QT_USE_NAMESPACE - -Q_DECLARE_METATYPE(QNetworkConfiguration) -Q_DECLARE_METATYPE(QNetworkSession::State); -Q_DECLARE_METATYPE(QNetworkSession::SessionError); - -class tst_QNetworkSession : public QObject -{ - Q_OBJECT - -public slots: - void initTestCase(); - void cleanupTestCase(); - -private slots: - - void outOfProcessSession(); - void invalidSession(); - - void sessionProperties_data(); - void sessionProperties(); - - void userChoiceSession_data(); - void userChoiceSession(); - - void sessionOpenCloseStop_data(); - void sessionOpenCloseStop(); - -private: - QNetworkConfigurationManager manager; - - int inProcessSessionManagementCount; - -#ifdef Q_WS_MAEMO_6 - Maemo::IAPConf *iapconf; - Maemo::IAPConf *iapconf2; - Maemo::IAPConf *gprsiap; -#define MAX_IAPS 10 - Maemo::IAPConf *iaps[MAX_IAPS]; - QProcess *icd_stub; -#endif -}; - -void tst_QNetworkSession::initTestCase() -{ - qRegisterMetaType("QNetworkSession::State"); - qRegisterMetaType("QNetworkSession::SessionError"); - qRegisterMetaType("QNetworkConfiguration"); - -#ifdef Q_WS_MAEMO_6 - iapconf = new Maemo::IAPConf("007"); - iapconf->setValue("ipv4_type", "AUTO"); - iapconf->setValue("wlan_wepkey1", "connt"); - iapconf->setValue("wlan_wepdefkey", 1); - iapconf->setValue("wlan_ssid", QByteArray("JamesBond")); - iapconf->setValue("name", "James Bond"); - iapconf->setValue("type", "WLAN_INFRA"); - - gprsiap = new Maemo::IAPConf("This-is-GPRS-IAP"); - gprsiap->setValue("ask_password", false); - gprsiap->setValue("gprs_accesspointname", "internet"); - gprsiap->setValue("gprs_password", ""); - gprsiap->setValue("gprs_username", ""); - gprsiap->setValue("ipv4_autodns", true); - gprsiap->setValue("ipv4_type", "AUTO"); - gprsiap->setValue("sim_imsi", "244070123456789"); - gprsiap->setValue("name", "MI6"); - gprsiap->setValue("type", "GPRS"); - - iapconf2 = new Maemo::IAPConf("osso.net"); - iapconf2->setValue("ipv4_type", "AUTO"); - iapconf2->setValue("wlan_wepkey1", "osso.net"); - iapconf2->setValue("wlan_wepdefkey", 1); - iapconf2->setValue("wlan_ssid", QByteArray("osso.net")); - iapconf2->setValue("name", "osso.net"); - iapconf2->setValue("type", "WLAN_INFRA"); - iapconf2->setValue("wlan_security", "WEP"); - - /* Create large number of IAPs in the gconf and see what happens */ - fflush(stdout); - printf("Creating %d IAPS: ", MAX_IAPS); - for (int i=0; isetValue("name", QString("test-iap-")+num); - iaps[i]->setValue("type", "WLAN_INFRA"); - iaps[i]->setValue("wlan_ssid", QString(QString("test-ssid-")+num).toAscii()); - iaps[i]->setValue("wlan_security", "WPA_PSK"); - iaps[i]->setValue("EAP_wpa_preshared_passphrase", QString("test-passphrase-")+num); - printf("."); - fflush(stdout); - } - printf("\n"); - fflush(stdout); - - icd_stub = new QProcess(this); - icd_stub->start("/usr/bin/icd2_stub.py"); - QTest::qWait(1000); - - // Add a known network to scan list that icd2 stub returns - QProcess dbus_send; - // 007 network - dbus_send.start("dbus-send --type=method_call --system " - "--dest=com.nokia.icd2 /com/nokia/icd2 " - "com.nokia.icd2.testing.add_available_network " - "string:'' uint32:0 string:'' " - "string:WLAN_INFRA uint32:5000011 array:byte:48,48,55"); - dbus_send.waitForFinished(); - - // osso.net network - dbus_send.start("dbus-send --type=method_call --system " - "--dest=com.nokia.icd2 /com/nokia/icd2 " - "com.nokia.icd2.testing.add_available_network " - "string:'' uint32:0 string:'' " - "string:WLAN_INFRA uint32:83886097 array:byte:111,115,115,111,46,110,101,116"); - dbus_send.waitForFinished(); -#endif - - inProcessSessionManagementCount = -1; - - QSignalSpy spy(&manager, SIGNAL(updateCompleted())); - manager.updateConfigurations(); - QTRY_VERIFY(spy.count() == 1); -} - -void tst_QNetworkSession::cleanupTestCase() -{ - if (!(manager.capabilities() & QNetworkConfigurationManager::SystemSessionSupport) && - (manager.capabilities() & QNetworkConfigurationManager::CanStartAndStopInterfaces) && - inProcessSessionManagementCount == 0) { - qWarning("No usable configurations found to complete all possible tests in " - "inProcessSessionManagement()"); - } - -#ifdef Q_WS_MAEMO_6 - iapconf->clear(); - delete iapconf; - iapconf2->clear(); - delete iapconf2; - gprsiap->clear(); - delete gprsiap; - - printf("Deleting %d IAPS : ", MAX_IAPS); - for (int i=0; iclear(); - delete iaps[i]; - printf("."); - fflush(stdout); - } - printf("\n"); - qDebug() << "Deleted" << MAX_IAPS << "IAPs"; - - icd_stub->terminate(); - icd_stub->waitForFinished(); -#endif -} - -void tst_QNetworkSession::invalidSession() -{ - QNetworkSession session(QNetworkConfiguration(), 0); - QVERIFY(!session.isOpen()); - QVERIFY(session.state() == QNetworkSession::Invalid); -} - -void tst_QNetworkSession::sessionProperties_data() -{ - QTest::addColumn("configuration"); - - QTest::newRow("invalid configuration") << QNetworkConfiguration(); - - foreach (const QNetworkConfiguration &config, manager.allConfigurations()) { - const QString name = config.name().isEmpty() ? QString("") : config.name(); - QTest::newRow(name.toLocal8Bit().constData()) << config; - } -} - -void tst_QNetworkSession::sessionProperties() -{ - QFETCH(QNetworkConfiguration, configuration); - - QNetworkSession session(configuration); - - QVERIFY(session.configuration() == configuration); - - QStringList validBearerNames = QStringList() << QLatin1String("Unknown") - << QLatin1String("Ethernet") - << QLatin1String("WLAN") - << QLatin1String("2G") - << QLatin1String("CDMA2000") - << QLatin1String("WCDMA") - << QLatin1String("HSPA") - << QLatin1String("Bluetooth") - << QLatin1String("WiMAX"); - - if (!configuration.isValid()) { - QVERIFY(configuration.bearerName().isEmpty()); - } else { - qDebug() << "Type:" << configuration.type() - << "Bearer:" << configuration.bearerName(); - - switch (configuration.type()) - { - case QNetworkConfiguration::ServiceNetwork: - case QNetworkConfiguration::UserChoice: - default: - QVERIFY(configuration.bearerName().isEmpty()); - break; - case QNetworkConfiguration::InternetAccessPoint: - QVERIFY(validBearerNames.contains(configuration.bearerName())); - break; - } - } - - // QNetworkSession::interface() should return an invalid interface unless - // session is in the connected state. - qDebug() << "Session state:" << session.state(); - qDebug() << "Session iface:" << session.interface().isValid() << session.interface().name(); -#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__)) - // On Symbian emulator, the support for data bearers is limited - QCOMPARE(session.state() == QNetworkSession::Connected, session.interface().isValid()); -#endif - - if (!configuration.isValid()) { - QVERIFY(configuration.state() == QNetworkConfiguration::Undefined && - session.state() == QNetworkSession::Invalid); - } else { - switch (configuration.state()) { - case QNetworkConfiguration::Undefined: - QVERIFY(session.state() == QNetworkSession::NotAvailable); - break; - case QNetworkConfiguration::Defined: - QVERIFY(session.state() == QNetworkSession::NotAvailable); - break; - case QNetworkConfiguration::Discovered: - QVERIFY(session.state() == QNetworkSession::Connecting || - session.state() == QNetworkSession::Disconnected); - break; - case QNetworkConfiguration::Active: - QVERIFY(session.state() == QNetworkSession::Connected || - session.state() == QNetworkSession::Closing || - session.state() == QNetworkSession::Roaming); - break; - default: - QFAIL("Invalid configuration state"); - }; - } -} - -void tst_QNetworkSession::userChoiceSession_data() -{ - QTest::addColumn("configuration"); - - QNetworkConfiguration config = manager.defaultConfiguration(); - if (config.type() == QNetworkConfiguration::UserChoice) - QTest::newRow("UserChoice") << config; - else - QSKIP("Default configuration is not a UserChoice configuration.", SkipAll); -} - -void tst_QNetworkSession::userChoiceSession() -{ - QFETCH(QNetworkConfiguration, configuration); - - QVERIFY(configuration.type() == QNetworkConfiguration::UserChoice); - - QNetworkSession session(configuration); - - // Check that configuration was really set - QVERIFY(session.configuration() == configuration); - - QVERIFY(!session.isOpen()); - - // Check that session is not active - QVERIFY(session.sessionProperty("ActiveConfiguration").toString().isEmpty()); - - // The remaining tests require the session to be not NotAvailable. - if (session.state() == QNetworkSession::NotAvailable) - QSKIP("Network is not available.", SkipSingle); - - QSignalSpy sessionOpenedSpy(&session, SIGNAL(opened())); - QSignalSpy sessionClosedSpy(&session, SIGNAL(closed())); - QSignalSpy stateChangedSpy(&session, SIGNAL(stateChanged(QNetworkSession::State))); - QSignalSpy errorSpy(&session, SIGNAL(error(QNetworkSession::SessionError))); - - // Test opening the session. - { - bool expectStateChange = session.state() != QNetworkSession::Connected; - - session.open(); - - session.waitForOpened(); - - if (session.isOpen()) - QVERIFY(!sessionOpenedSpy.isEmpty() || !errorSpy.isEmpty()); - if (!errorSpy.isEmpty()) { - QNetworkSession::SessionError error = - qvariant_cast(errorSpy.first().at(0)); - if (error == QNetworkSession::OperationNotSupportedError) { - // The session needed to bring up the interface, - // but the operation is not supported. - QSKIP("Configuration does not support open().", SkipSingle); - } else if (error == QNetworkSession::InvalidConfigurationError) { - // The session needed to bring up the interface, but it is not possible for the - // specified configuration. - if ((session.configuration().state() & QNetworkConfiguration::Discovered) == - QNetworkConfiguration::Discovered) { - QFAIL("Failed to open session for Discovered configuration."); - } else { - QSKIP("Cannot test session for non-Discovered configuration.", SkipSingle); - } - } else if (error == QNetworkSession::UnknownSessionError) { - QSKIP("Unknown session error.", SkipSingle); - } else { - QFAIL("Error opening session."); - } - } else if (!sessionOpenedSpy.isEmpty()) { - QCOMPARE(sessionOpenedSpy.count(), 1); - QVERIFY(sessionClosedSpy.isEmpty()); - QVERIFY(errorSpy.isEmpty()); - - if (expectStateChange) - QTRY_VERIFY(!stateChangedSpy.isEmpty()); - - QVERIFY(session.state() == QNetworkSession::Connected); -#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__)) - // On Symbian emulator, the support for data bearers is limited - QVERIFY(session.interface().isValid()); -#endif - - const QString userChoiceIdentifier = - session.sessionProperty("UserChoiceConfiguration").toString(); - - QVERIFY(!userChoiceIdentifier.isEmpty()); - QVERIFY(userChoiceIdentifier != configuration.identifier()); - - QNetworkConfiguration userChoiceConfiguration = - manager.configurationFromIdentifier(userChoiceIdentifier); - - QVERIFY(userChoiceConfiguration.isValid()); - QVERIFY(userChoiceConfiguration.type() != QNetworkConfiguration::UserChoice); - - const QString testIdentifier("abc"); - //resetting UserChoiceConfiguration is ignored (read only property) - session.setSessionProperty("UserChoiceConfiguration", testIdentifier); - QVERIFY(session.sessionProperty("UserChoiceConfiguration").toString() != testIdentifier); - - const QString activeIdentifier = - session.sessionProperty("ActiveConfiguration").toString(); - - QVERIFY(!activeIdentifier.isEmpty()); - QVERIFY(activeIdentifier != configuration.identifier()); - - QNetworkConfiguration activeConfiguration = - manager.configurationFromIdentifier(activeIdentifier); - - QVERIFY(activeConfiguration.isValid()); - QVERIFY(activeConfiguration.type() == QNetworkConfiguration::InternetAccessPoint); - - //resetting ActiveConfiguration is ignored (read only property) - session.setSessionProperty("ActiveConfiguration", testIdentifier); - QVERIFY(session.sessionProperty("ActiveConfiguration").toString() != testIdentifier); - - if (userChoiceConfiguration.type() == QNetworkConfiguration::InternetAccessPoint) { - QVERIFY(userChoiceConfiguration == activeConfiguration); - } else { - QVERIFY(userChoiceConfiguration.type() == QNetworkConfiguration::ServiceNetwork); - QVERIFY(userChoiceConfiguration.children().contains(activeConfiguration)); - } - } else { - QFAIL("Timeout waiting for session to open."); - } - } -} - -void tst_QNetworkSession::sessionOpenCloseStop_data() -{ - QTest::addColumn("configuration"); - QTest::addColumn("forceSessionStop"); - - foreach (const QNetworkConfiguration &config, manager.allConfigurations()) { - const QString name = config.name().isEmpty() ? QString("") : config.name(); - QTest::newRow((name + QLatin1String(" close")).toLocal8Bit().constData()) - << config << false; - QTest::newRow((name + QLatin1String(" stop")).toLocal8Bit().constData()) - << config << true; - } - - inProcessSessionManagementCount = 0; -} - -void tst_QNetworkSession::sessionOpenCloseStop() -{ - QFETCH(QNetworkConfiguration, configuration); - QFETCH(bool, forceSessionStop); - - QNetworkSession session(configuration); - - // Test initial state of the session. - { - QVERIFY(session.configuration() == configuration); - QVERIFY(!session.isOpen()); - // session may be invalid if configuration is removed between when - // sessionOpenCloseStop_data() is called and here. - QVERIFY((configuration.isValid() && (session.state() != QNetworkSession::Invalid)) || - (!configuration.isValid() && (session.state() == QNetworkSession::Invalid))); - QVERIFY(session.error() == QNetworkSession::UnknownSessionError); - } - - // The remaining tests require the session to be not NotAvailable. - if (session.state() == QNetworkSession::NotAvailable) - QSKIP("Network is not available.", SkipSingle); - - QSignalSpy sessionOpenedSpy(&session, SIGNAL(opened())); - QSignalSpy sessionClosedSpy(&session, SIGNAL(closed())); - QSignalSpy stateChangedSpy(&session, SIGNAL(stateChanged(QNetworkSession::State))); - QSignalSpy errorSpy(&session, SIGNAL(error(QNetworkSession::SessionError))); - - // Test opening the session. - { - QNetworkSession::State previousState = session.state(); - bool expectStateChange = previousState != QNetworkSession::Connected; - - session.open(); - - session.waitForOpened(); - - if (session.isOpen()) - QVERIFY(!sessionOpenedSpy.isEmpty() || !errorSpy.isEmpty()); - if (!errorSpy.isEmpty()) { - QNetworkSession::SessionError error = - qvariant_cast(errorSpy.first().at(0)); - - QVERIFY(session.state() == previousState); - - if (error == QNetworkSession::OperationNotSupportedError) { - // The session needed to bring up the interface, - // but the operation is not supported. - QSKIP("Configuration does not support open().", SkipSingle); - } else if (error == QNetworkSession::InvalidConfigurationError) { - // The session needed to bring up the interface, but it is not possible for the - // specified configuration. - if ((session.configuration().state() & QNetworkConfiguration::Discovered) == - QNetworkConfiguration::Discovered) { - QFAIL("Failed to open session for Discovered configuration."); - } else { - QSKIP("Cannot test session for non-Discovered configuration.", SkipSingle); - } - } else if (error == QNetworkSession::UnknownSessionError) { - QSKIP("Unknown Session error.", SkipSingle); - } else { - QFAIL("Error opening session."); - } - } else if (!sessionOpenedSpy.isEmpty()) { - QCOMPARE(sessionOpenedSpy.count(), 1); - QVERIFY(sessionClosedSpy.isEmpty()); - QVERIFY(errorSpy.isEmpty()); - - if (expectStateChange) { - QTRY_VERIFY(stateChangedSpy.count() >= 2); - - QNetworkSession::State state = - qvariant_cast(stateChangedSpy.at(0).at(0)); - QVERIFY(state == QNetworkSession::Connecting); - - state = qvariant_cast(stateChangedSpy.at(1).at(0)); - QVERIFY(state == QNetworkSession::Connected); - } - - QVERIFY(session.state() == QNetworkSession::Connected); -#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__)) - // On Symbian emulator, the support for data bearers is limited - QVERIFY(session.interface().isValid()); -#endif - } else { - QFAIL("Timeout waiting for session to open."); - } - } - - sessionOpenedSpy.clear(); - sessionClosedSpy.clear(); - stateChangedSpy.clear(); - errorSpy.clear(); - - QNetworkSession session2(configuration); - - QSignalSpy sessionOpenedSpy2(&session2, SIGNAL(opened())); - QSignalSpy sessionClosedSpy2(&session2, SIGNAL(closed())); - QSignalSpy stateChangedSpy2(&session2, SIGNAL(stateChanged(QNetworkSession::State))); - QSignalSpy errorSpy2(&session2, SIGNAL(error(QNetworkSession::SessionError))); - - // Test opening a second session. - { - QVERIFY(session2.configuration() == configuration); - QVERIFY(!session2.isOpen()); - QVERIFY(session2.state() == QNetworkSession::Connected); - QVERIFY(session.error() == QNetworkSession::UnknownSessionError); - - session2.open(); - - QTRY_VERIFY(!sessionOpenedSpy2.isEmpty() || !errorSpy2.isEmpty()); - - QVERIFY(session.isOpen()); - QVERIFY(session2.isOpen()); - QVERIFY(session.state() == QNetworkSession::Connected); - QVERIFY(session2.state() == QNetworkSession::Connected); -#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__)) - // On Symbian emulator, the support for data bearers is limited - QVERIFY(session.interface().isValid()); -#endif - QCOMPARE(session.interface().hardwareAddress(), session2.interface().hardwareAddress()); - QCOMPARE(session.interface().index(), session2.interface().index()); - } - - sessionOpenedSpy2.clear(); - - if (forceSessionStop) { - // Test forcing the second session to stop the interface. - QNetworkSession::State previousState = session.state(); -#ifdef Q_CC_NOKIAX86 - // For S60 emulator builds: RConnection::Stop does not work on all Emulators - bool expectStateChange = false; -#else - bool expectStateChange = previousState != QNetworkSession::Disconnected; -#endif - - session2.stop(); - - QTRY_VERIFY(!sessionClosedSpy2.isEmpty() || !errorSpy2.isEmpty()); - - QVERIFY(!session2.isOpen()); - - if (!errorSpy2.isEmpty()) { - QVERIFY(!errorSpy.isEmpty()); - - // check for SessionAbortedError - QNetworkSession::SessionError error = - qvariant_cast(errorSpy.first().at(0)); - QNetworkSession::SessionError error2 = - qvariant_cast(errorSpy2.first().at(0)); - - QVERIFY(error == QNetworkSession::SessionAbortedError); - QVERIFY(error2 == QNetworkSession::SessionAbortedError); - - QCOMPARE(errorSpy.count(), 1); - QCOMPARE(errorSpy2.count(), 1); - - errorSpy.clear(); - errorSpy2.clear(); - } - - QVERIFY(errorSpy.isEmpty()); - QVERIFY(errorSpy2.isEmpty()); - - if (expectStateChange) - QTRY_VERIFY(stateChangedSpy2.count() >= 2 || !errorSpy2.isEmpty()); - - if (!errorSpy2.isEmpty()) { - QVERIFY(session2.state() == previousState); - QVERIFY(session.state() == previousState); - - QNetworkSession::SessionError error = - qvariant_cast(errorSpy2.first().at(0)); - if (error == QNetworkSession::OperationNotSupportedError) { - // The session needed to bring down the interface, - // but the operation is not supported. - QSKIP("Configuration does not support stop().", SkipSingle); - } else if (error == QNetworkSession::InvalidConfigurationError) { - // The session needed to bring down the interface, but it is not possible for the - // specified configuration. - if ((session.configuration().state() & QNetworkConfiguration::Discovered) == - QNetworkConfiguration::Discovered) { - QFAIL("Failed to stop session for Discovered configuration."); - } else { - QSKIP("Cannot test session for non-Discovered configuration.", SkipSingle); - } - } else { - QFAIL("Error stopping session."); - } - } else if (!sessionClosedSpy2.isEmpty()) { - if (expectStateChange) { - if (configuration.type() == QNetworkConfiguration::ServiceNetwork) { - bool roamedSuccessfully = false; - - QCOMPARE(stateChangedSpy2.count(), 4); - - QNetworkSession::State state = - qvariant_cast(stateChangedSpy2.at(0).at(0)); - QVERIFY(state == QNetworkSession::Connecting); - - state = qvariant_cast(stateChangedSpy2.at(1).at(0)); - QVERIFY(state == QNetworkSession::Connected); - - state = qvariant_cast(stateChangedSpy2.at(2).at(0)); - QVERIFY(state == QNetworkSession::Closing); - - state = qvariant_cast(stateChangedSpy2.at(3).at(0)); - QVERIFY(state == QNetworkSession::Disconnected); - - QTRY_VERIFY(stateChangedSpy.count() > 0); - state = qvariant_cast(stateChangedSpy.at(0).at(0)); - if (state == QNetworkSession::Roaming) { - QTRY_VERIFY(!errorSpy.isEmpty() || stateChangedSpy.count() > 1); - if (stateChangedSpy.count() > 1) { - state = qvariant_cast(stateChangedSpy.at(1).at(0)); - if (state == QNetworkSession::Connected) { - roamedSuccessfully = true; - QTRY_VERIFY(session2.state() == QNetworkSession::Disconnected); - } - } - } - if (roamedSuccessfully) { - QString configId = session.sessionProperty("ActiveConfiguration").toString(); - QNetworkConfiguration config = manager.configurationFromIdentifier(configId); - QNetworkSession session3(config); - QSignalSpy errorSpy3(&session3, SIGNAL(error(QNetworkSession::SessionError))); - QSignalSpy sessionOpenedSpy3(&session3, SIGNAL(opened())); - - session3.open(); - session3.waitForOpened(); - - if (session.isOpen()) - QVERIFY(!sessionOpenedSpy3.isEmpty() || !errorSpy3.isEmpty()); - - session.stop(); - - QTRY_VERIFY(session.state() == QNetworkSession::Disconnected); - QTRY_VERIFY(session3.state() == QNetworkSession::Disconnected); - } -#ifndef Q_CC_NOKIAX86 - if (!roamedSuccessfully) - QVERIFY(!errorSpy.isEmpty()); -#endif - } else { - QCOMPARE(stateChangedSpy2.count(), 2); - - QNetworkSession::State state = - qvariant_cast(stateChangedSpy2.at(0).at(0)); - QVERIFY(state == QNetworkSession::Closing); - - state = qvariant_cast(stateChangedSpy2.at(1).at(0)); - QVERIFY(state == QNetworkSession::Disconnected); - } - - QTRY_VERIFY(!sessionClosedSpy.isEmpty()); - QVERIFY(session.state() == QNetworkSession::Disconnected); - QVERIFY(session2.state() == QNetworkSession::Disconnected); - } - - QVERIFY(errorSpy2.isEmpty()); - - ++inProcessSessionManagementCount; - } else { - QFAIL("Timeout waiting for session to stop."); - } - -#ifndef Q_CC_NOKIAX86 - QVERIFY(!sessionClosedSpy.isEmpty()); -#endif - QVERIFY(!sessionClosedSpy2.isEmpty()); - -#ifndef Q_CC_NOKIAX86 - QVERIFY(!session.isOpen()); -#endif - QVERIFY(!session2.isOpen()); - } else { - // Test closing the second session. - { - int stateChangedCountBeforeClose = stateChangedSpy2.count(); - session2.close(); - - QTRY_VERIFY(!sessionClosedSpy2.isEmpty()); -#ifndef Q_CC_NOKIAX86 - QVERIFY(stateChangedSpy2.count() == stateChangedCountBeforeClose); -#endif - - QVERIFY(sessionClosedSpy.isEmpty()); - - QVERIFY(session.isOpen()); - QVERIFY(!session2.isOpen()); - QVERIFY(session.state() == QNetworkSession::Connected); - QVERIFY(session2.state() == QNetworkSession::Connected); -#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__)) - // On Symbian emulator, the support for data bearers is limited - QVERIFY(session.interface().isValid()); -#endif - QCOMPARE(session.interface().hardwareAddress(), session2.interface().hardwareAddress()); - QCOMPARE(session.interface().index(), session2.interface().index()); - } - - sessionClosedSpy2.clear(); - - // Test closing the first session. - { -#ifdef Q_CC_NOKIAX86 - // For S60 emulator builds: RConnection::Close does not actually - // close network connection on all Emulators - bool expectStateChange = false; -#else - bool expectStateChange = session.state() != QNetworkSession::Disconnected && - manager.capabilities() & QNetworkConfigurationManager::SystemSessionSupport; -#endif - - session.close(); - - QTRY_VERIFY(!sessionClosedSpy.isEmpty() || !errorSpy.isEmpty()); - - QVERIFY(!session.isOpen()); - - if (expectStateChange) - QTRY_VERIFY(!stateChangedSpy.isEmpty() || !errorSpy.isEmpty()); - - if (!errorSpy.isEmpty()) { - QNetworkSession::SessionError error = - qvariant_cast(errorSpy.first().at(0)); - if (error == QNetworkSession::OperationNotSupportedError) { - // The session needed to bring down the interface, - // but the operation is not supported. - QSKIP("Configuration does not support close().", SkipSingle); - } else if (error == QNetworkSession::InvalidConfigurationError) { - // The session needed to bring down the interface, but it is not possible for the - // specified configuration. - if ((session.configuration().state() & QNetworkConfiguration::Discovered) == - QNetworkConfiguration::Discovered) { - QFAIL("Failed to close session for Discovered configuration."); - } else { - QSKIP("Cannot test session for non-Discovered configuration.", SkipSingle); - } - } else { - QFAIL("Error closing session."); - } - } else if (!sessionClosedSpy.isEmpty()) { - QVERIFY(sessionOpenedSpy.isEmpty()); - QCOMPARE(sessionClosedSpy.count(), 1); - if (expectStateChange) - QVERIFY(!stateChangedSpy.isEmpty()); - QVERIFY(errorSpy.isEmpty()); - - if (expectStateChange) - QTRY_VERIFY(session.state() == QNetworkSession::Disconnected); - - ++inProcessSessionManagementCount; - } else { - QFAIL("Timeout waiting for session to close."); - } - } - } -} - -QDebug operator<<(QDebug debug, const QList &list) -{ - debug.nospace() << "( "; - foreach (const QNetworkConfiguration &config, list) - debug.nospace() << config.identifier() << ", "; - debug.nospace() << ")\n"; - return debug; -} - -// Note: outOfProcessSession requires that at least one configuration is -// at Discovered -state (Defined is ok for symbian as well, as long as it is possible to open). -void tst_QNetworkSession::outOfProcessSession() -{ - qDebug() << "START"; - -#if defined(Q_OS_SYMBIAN) && defined(__WINS__) - QSKIP("Symbian emulator does not support two [QR]PRocesses linking a dll (QtBearer.dll) with global writeable static data.", SkipAll); -#endif - QNetworkConfigurationManager manager; - // Create a QNetworkConfigurationManager to detect configuration changes made in Lackey. This - // is actually the essence of this testcase - to check that platform mediates/reflects changes - // regardless of process boundaries. The interprocess communication is more like a way to get - // this test-case act correctly and timely. - QList before = manager.allConfigurations(QNetworkConfiguration::Active); - QSignalSpy spy(&manager, SIGNAL(configurationChanged(QNetworkConfiguration))); - - // Cannot read/write to processes on WinCE or Symbian. - // Easiest alternative is to use sockets for IPC. - QLocalServer oopServer; - // First remove possible earlier listening address which would cause listen to fail - // (e.g. previously abruptly ended unit test might cause this) - QLocalServer::removeServer("tst_qnetworksession"); - oopServer.listen("tst_qnetworksession"); - - qDebug() << "starting lackey"; - QProcess lackey; - lackey.start("lackey/lackey"); - qDebug() << lackey.error() << lackey.errorString(); - QVERIFY(lackey.waitForStarted()); - - qDebug() << "waiting for connection"; - QVERIFY(oopServer.waitForNewConnection(-1)); - QLocalSocket *oopSocket = oopServer.nextPendingConnection(); - qDebug() << "got connection"; - do { - QByteArray output; - - if (oopSocket->waitForReadyRead()) - output = oopSocket->readLine().trimmed(); - - if (output.startsWith("Started session ")) { - QString identifier = QString::fromLocal8Bit(output.mid(20).constData()); - QNetworkConfiguration changed; - - do { - QTRY_VERIFY(!spy.isEmpty()); - changed = qvariant_cast(spy.takeFirst().at(0)); - } while (changed.identifier() != identifier); - - QVERIFY((changed.state() & QNetworkConfiguration::Active) == - QNetworkConfiguration::Active); - - QVERIFY(!before.contains(changed)); - - QList after = - manager.allConfigurations(QNetworkConfiguration::Active); - - QVERIFY(after.contains(changed)); - - spy.clear(); - - oopSocket->write("stop\n"); - oopSocket->waitForBytesWritten(); - - do { - QTRY_VERIFY(!spy.isEmpty()); - - changed = qvariant_cast(spy.takeFirst().at(0)); - } while (changed.identifier() != identifier); - - QVERIFY((changed.state() & QNetworkConfiguration::Active) != - QNetworkConfiguration::Active); - - QList afterStop = - manager.allConfigurations(QNetworkConfiguration::Active); - - QVERIFY(!afterStop.contains(changed)); - - oopSocket->disconnectFromServer(); - oopSocket->waitForDisconnected(-1); - - lackey.waitForFinished(); - } - // This is effected by QTBUG-4903, process will always report as running - //} while (lackey.state() == QProcess::Running); - - // Workaround: the socket in the lackey will disconnect on exit - } while (oopSocket->state() == QLocalSocket::ConnectedState); - - switch (lackey.exitCode()) { - case 0: - qDebug("Lackey returned exit success (0)"); - break; - case 1: - QSKIP("No discovered configurations found.", SkipAll); - case 2: - QSKIP("Lackey could not start session.", SkipAll); - default: - QSKIP("Lackey failed", SkipAll); - } - qDebug("STOP"); -} - -QTEST_MAIN(tst_QNetworkSession) - -#include "tst_qnetworksession.moc" - diff --git a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro deleted file mode 100644 index cad388c..0000000 --- a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro +++ /dev/null @@ -1,15 +0,0 @@ -load(qttest_p4) -SOURCES += tst_qnetworksession.cpp -HEADERS += ../../qbearertestcommon.h - -QT = core network - -symbian { - TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData PowerMgmt -} - -maemo6 { - CONFIG += link_pkgconfig - - PKGCONFIG += conninet -} -- cgit v0.12 From bc5b362ae8754ba4bd9d12ddbf9c4a7e21502ff4 Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Mon, 22 Feb 2010 08:49:46 +1000 Subject: Fixed qnetworksession test on Mac. Don't use an app bundle for this helper app. --- tests/auto/qnetworksession/lackey/lackey.pro | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/auto/qnetworksession/lackey/lackey.pro b/tests/auto/qnetworksession/lackey/lackey.pro index 8fbdd58..5db6743 100644 --- a/tests/auto/qnetworksession/lackey/lackey.pro +++ b/tests/auto/qnetworksession/lackey/lackey.pro @@ -6,6 +6,7 @@ QT = core network DESTDIR = ./ win32:CONFIG += console +mac:CONFIG -= app_bundle symbian { # Needed for interprocess communication and opening QNetworkSession -- cgit v0.12 From a56597916b275a2f0d2e3b9f8ac3653eeb4e2e91 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 22 Feb 2010 11:23:24 +1000 Subject: Add locking to bearer code. QNetworkConfigurationManagerPrivate and QBearerEngine derived classes need to be thread-safe. --- src/network/bearer/qbearerengine.cpp | 2 +- src/network/bearer/qbearerengine_p.h | 19 ++-- src/network/bearer/qnetworkconfigmanager.cpp | 84 +++++++++++++++- src/network/bearer/qnetworkconfigmanager_p.cpp | 109 ++++++--------------- src/network/bearer/qnetworkconfigmanager_p.h | 22 ++--- src/network/bearer/qnetworksession.cpp | 2 +- src/plugins/bearer/corewlan/qcorewlanengine.mm | 22 +++++ src/plugins/bearer/generic/qgenericengine.cpp | 10 ++ src/plugins/bearer/icd/qicdengine.cpp | 10 ++ .../bearer/nativewifi/qnativewifiengine.cpp | 14 +++ .../networkmanager/qnetworkmanagerengine.cpp | 50 ++++++++++ src/plugins/bearer/nla/qnlaengine.cpp | 10 ++ src/plugins/bearer/qnetworksession_impl.cpp | 2 +- src/plugins/bearer/symbian/symbianengine.cpp | 44 +++++++++ 14 files changed, 297 insertions(+), 103 deletions(-) diff --git a/src/network/bearer/qbearerengine.cpp b/src/network/bearer/qbearerengine.cpp index 58d64f2..eb851cc 100644 --- a/src/network/bearer/qbearerengine.cpp +++ b/src/network/bearer/qbearerengine.cpp @@ -44,7 +44,7 @@ QT_BEGIN_NAMESPACE QBearerEngine::QBearerEngine(QObject *parent) -: QObject(parent) +: QObject(parent), mutex(QMutex::Recursive) { } diff --git a/src/network/bearer/qbearerengine_p.h b/src/network/bearer/qbearerengine_p.h index 7e96877..5e12b0f 100644 --- a/src/network/bearer/qbearerengine_p.h +++ b/src/network/bearer/qbearerengine_p.h @@ -63,6 +63,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -72,6 +73,8 @@ class Q_NETWORK_EXPORT QBearerEngine : public QObject { Q_OBJECT + friend class QNetworkConfigurationManager; + public: QBearerEngine(QObject *parent = 0); virtual ~QBearerEngine(); @@ -86,7 +89,14 @@ public: virtual QNetworkConfigurationPrivatePointer defaultConfiguration() = 0; -public: +Q_SIGNALS: + void configurationAdded(QNetworkConfigurationPrivatePointer config); + void configurationRemoved(QNetworkConfigurationPrivatePointer config); + void configurationChanged(QNetworkConfigurationPrivatePointer config); + + void updateCompleted(); + +protected: //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 @@ -94,12 +104,7 @@ public: QHash snapConfigurations; QHash userChoiceConfigurations; -Q_SIGNALS: - void configurationAdded(QNetworkConfigurationPrivatePointer config); - void configurationRemoved(QNetworkConfigurationPrivatePointer config); - void configurationChanged(QNetworkConfigurationPrivatePointer config); - - void updateCompleted(); + mutable QMutex mutex; }; QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index f54a985..e960323 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -206,7 +206,81 @@ QNetworkConfigurationManager::~QNetworkConfigurationManager() */ QNetworkConfiguration QNetworkConfigurationManager::defaultConfiguration() const { - return connManager()->defaultConfiguration(); + QNetworkConfigurationManagerPrivate *conPriv = connManager(); + + foreach (QBearerEngine *engine, conPriv->engines()) { + QNetworkConfigurationPrivatePointer ptr = engine->defaultConfiguration(); + + if (ptr) { + QNetworkConfiguration config; + config.d = ptr; + return config; + } + } + + // Engines don't have a default configuration. + + // Return first active snap + QNetworkConfigurationPrivatePointer firstDiscovered; + + foreach (QBearerEngine *engine, conPriv->engines()) { + QHash::Iterator it; + QHash::Iterator end; + + QMutexLocker locker(&engine->mutex); + + for (it = engine->snapConfigurations.begin(), end = engine->snapConfigurations.end(); + it != end; ++it) { + if ((it.value()->state & QNetworkConfiguration::Active) == + QNetworkConfiguration::Active) { + QNetworkConfiguration config; + config.d = it.value(); + return config; + } else if ((it.value()->state & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + firstDiscovered = it.value(); + } + } + } + + // No Active SNAPs return first Discovered SNAP. + if (firstDiscovered) { + QNetworkConfiguration config; + config.d = firstDiscovered; + return config; + } + + // No Active or Discovered SNAPs, do same for InternetAccessPoints. + firstDiscovered.reset(); + + foreach (QBearerEngine *engine, conPriv->engines()) { + QHash::Iterator it; + QHash::Iterator end; + + QMutexLocker locker(&engine->mutex); + + for (it = engine->accessPointConfigurations.begin(), + end = engine->accessPointConfigurations.end(); it != end; ++it) { + if ((it.value()->state & QNetworkConfiguration::Active) == + QNetworkConfiguration::Active) { + QNetworkConfiguration config; + config.d = it.value(); + return config; + } else if ((it.value()->state & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + firstDiscovered = it.value(); + } + } + } + + // No Active InternetAccessPoint return first Discovered InternetAccessPoint. + if (firstDiscovered) { + QNetworkConfiguration config; + config.d = firstDiscovered; + return config; + } + + return QNetworkConfiguration(); } /*! @@ -234,10 +308,12 @@ QList QNetworkConfigurationManager::allConfigurations(QNe QList result; QNetworkConfigurationManagerPrivate* conPriv = connManager(); - foreach (QBearerEngine *engine, conPriv->sessionEngines) { + foreach (QBearerEngine *engine, conPriv->engines()) { QHash::Iterator it; QHash::Iterator end; + QMutexLocker locker(&engine->mutex); + //find all InternetAccessPoints for (it = engine->accessPointConfigurations.begin(), end = engine->accessPointConfigurations.end(); it != end; ++it) { @@ -274,7 +350,9 @@ QNetworkConfiguration QNetworkConfigurationManager::configurationFromIdentifier( QNetworkConfiguration item; - foreach (QBearerEngine *engine, conPriv->sessionEngines) { + foreach (QBearerEngine *engine, conPriv->engines()) { + QMutexLocker locker(&engine->mutex); + if (engine->accessPointConfigurations.contains(identifier)) item.d = engine->accessPointConfigurations.value(identifier); else if (engine->snapConfigurations.contains(identifier)) diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 141d522..6ac61b3 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -47,19 +47,34 @@ #include #include #include +#include QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, (QBearerEngineFactoryInterface_iid, QLatin1String("/bearer"))) +QNetworkConfigurationManagerPrivate::QNetworkConfigurationManagerPrivate() +: capFlags(0), firstUpdate(true), mutex(QMutex::Recursive) +{ + updateConfigurations(); + + moveToThread(QCoreApplicationPrivate::mainThread()); + foreach (QBearerEngine *engine, sessionEngines) + engine->moveToThread(QCoreApplicationPrivate::mainThread()); +} + QNetworkConfigurationManagerPrivate::~QNetworkConfigurationManagerPrivate() { + QMutexLocker locker(&mutex); + qDeleteAll(sessionEngines); } void QNetworkConfigurationManagerPrivate::configurationAdded(QNetworkConfigurationPrivatePointer ptr) { + QMutexLocker locker(&mutex); + if (!firstUpdate) { QNetworkConfiguration item; item.d = ptr; @@ -75,6 +90,8 @@ void QNetworkConfigurationManagerPrivate::configurationAdded(QNetworkConfigurati void QNetworkConfigurationManagerPrivate::configurationRemoved(QNetworkConfigurationPrivatePointer ptr) { + QMutexLocker locker(&mutex); + ptr->isValid = false; if (!firstUpdate) { @@ -90,6 +107,8 @@ void QNetworkConfigurationManagerPrivate::configurationRemoved(QNetworkConfigura void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigurationPrivatePointer ptr) { + QMutexLocker locker(&mutex); + if (!firstUpdate) { QNetworkConfiguration item; item.d = ptr; @@ -111,6 +130,8 @@ void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigura void QNetworkConfigurationManagerPrivate::updateConfigurations() { + QMutexLocker locker(&mutex); + if (firstUpdate) { updating = false; @@ -163,87 +184,10 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() firstUpdate = false; } -/*! - Returns the default configuration of the first plugin, if one exists; otherwise returns an - invalid configuration. - - \internal -*/ -QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration() -{ - foreach (QBearerEngine *engine, sessionEngines) { - QNetworkConfigurationPrivatePointer ptr = engine->defaultConfiguration(); - - if (ptr) { - QNetworkConfiguration config; - config.d = ptr; - return config; - } - } - - // Engines don't have a default configuration. - - // Return first active snap - QNetworkConfigurationPrivatePointer firstDiscovered; - - foreach (QBearerEngine *engine, sessionEngines) { - QHash::Iterator it; - QHash::Iterator end; - - for (it = engine->snapConfigurations.begin(), end = engine->snapConfigurations.end(); - it != end; ++it) { - if ((it.value()->state & QNetworkConfiguration::Active) == - QNetworkConfiguration::Active) { - QNetworkConfiguration config; - config.d = it.value(); - return config; - } else if ((it.value()->state & QNetworkConfiguration::Discovered) == - QNetworkConfiguration::Discovered) { - firstDiscovered = it.value(); - } - } - } - - // No Active SNAPs return first Discovered SNAP. - if (firstDiscovered) { - QNetworkConfiguration config; - config.d = firstDiscovered; - return config; - } - - // No Active or Discovered SNAPs, do same for InternetAccessPoints. - firstDiscovered.reset(); - - foreach (QBearerEngine *engine, sessionEngines) { - QHash::Iterator it; - QHash::Iterator end; - - for (it = engine->accessPointConfigurations.begin(), - end = engine->accessPointConfigurations.end(); it != end; ++it) { - if ((it.value()->state & QNetworkConfiguration::Active) == - QNetworkConfiguration::Active) { - QNetworkConfiguration config; - config.d = it.value(); - return config; - } else if ((it.value()->state & QNetworkConfiguration::Discovered) == - QNetworkConfiguration::Discovered) { - firstDiscovered = it.value(); - } - } - } - - // No Active InternetAccessPoint return first Discovered InternetAccessPoint. - if (firstDiscovered) { - QNetworkConfiguration config; - config.d = firstDiscovered; - return config; - } - - return QNetworkConfiguration(); -} - void QNetworkConfigurationManagerPrivate::performAsyncConfigurationUpdate() { + QMutexLocker locker(&mutex); + if (sessionEngines.isEmpty()) { emit configurationUpdateComplete(); return; @@ -257,4 +201,11 @@ void QNetworkConfigurationManagerPrivate::performAsyncConfigurationUpdate() } } +QList QNetworkConfigurationManagerPrivate::engines() +{ + QMutexLocker locker(&mutex); + + return sessionEngines; +} + QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index e178c2d..c7e988e 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -56,20 +56,17 @@ #include "qnetworkconfigmanager.h" #include "qnetworkconfiguration_p.h" +#include + QT_BEGIN_NAMESPACE class QBearerEngine; -class QNetworkConfigurationManagerPrivate : public QObject +class Q_NETWORK_EXPORT QNetworkConfigurationManagerPrivate : public QObject { Q_OBJECT public: - QNetworkConfigurationManagerPrivate() - : QObject(0), capFlags(0), firstUpdate(true) - { - updateConfigurations(); - } - + QNetworkConfigurationManagerPrivate(); virtual ~QNetworkConfigurationManagerPrivate(); QNetworkConfiguration defaultConfiguration(); @@ -78,7 +75,7 @@ public: void performAsyncConfigurationUpdate(); - bool firstUpdate; + QList engines(); public slots: void updateConfigurations(); @@ -92,14 +89,17 @@ Q_SIGNALS: void abort(); -public: +private: + QMutex mutex; + QList sessionEngines; -private: QSet onlineConfigurations; - bool updating; QSet updatingEngines; + bool updating; + + bool firstUpdate; private Q_SLOTS: void configurationAdded(QNetworkConfigurationPrivatePointer ptr); diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp index 3e77354..6a82791 100644 --- a/src/network/bearer/qnetworksession.cpp +++ b/src/network/bearer/qnetworksession.cpp @@ -225,7 +225,7 @@ QT_BEGIN_NAMESPACE QNetworkSession::QNetworkSession(const QNetworkConfiguration& connectionConfig, QObject* parent) : QObject(parent), d(0) { - foreach (QBearerEngine *engine, qNetworkConfigurationManagerPrivate()->sessionEngines) { + foreach (QBearerEngine *engine, qNetworkConfigurationManagerPrivate()->engines()) { if (engine->hasIdentifier(connectionConfig.identifier())) { d = engine->createSessionBackend(); d->q = this; diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm index fff65e4..a5384d1 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.mm +++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm @@ -121,16 +121,22 @@ QCoreWlanEngine::~QCoreWlanEngine() QString QCoreWlanEngine::getInterfaceFromId(const QString &id) { + QMutexLocker locker(&mutex); + return configurationInterface.value(id); } bool QCoreWlanEngine::hasIdentifier(const QString &id) { + QMutexLocker locker(&mutex); + return configurationInterface.contains(id); } void QCoreWlanEngine::connectToId(const QString &id) { + QMutexLocker locker(&mutex); + NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; QString interfaceString = getInterfaceFromId(id); @@ -205,6 +211,8 @@ void QCoreWlanEngine::connectToId(const QString &id) void QCoreWlanEngine::disconnectFromId(const QString &id) { + QMutexLocker locker(&mutex); + QString interfaceString = getInterfaceFromId(id); if(networkInterfaces.value(getInterfaceFromId(id)) == "WLAN") { //wifi only for now #if defined(MAC_SDK_10_6) @@ -225,12 +233,16 @@ void QCoreWlanEngine::disconnectFromId(const QString &id) void QCoreWlanEngine::requestUpdate() { + QMutexLocker locker(&mutex); + pollTimer.stop(); QTimer::singleShot(0, this, SLOT(doRequestUpdate())); } void QCoreWlanEngine::doRequestUpdate() { + QMutexLocker locker(&mutex); + getAllScInterfaces(); QStringList previous = accessPointConfigurations.keys(); @@ -330,6 +342,8 @@ void QCoreWlanEngine::doRequestUpdate() QStringList QCoreWlanEngine::scanForSsids(const QString &interfaceName) { + QMutexLocker locker(&mutex); + QStringList found; #if defined(MAC_SDK_10_6) @@ -422,6 +436,8 @@ QStringList QCoreWlanEngine::scanForSsids(const QString &interfaceName) bool QCoreWlanEngine::isWifiReady(const QString &wifiDeviceName) { + QMutexLocker locker(&mutex); + #if defined(MAC_SDK_10_6) CWInterface *defaultInterface = [CWInterface interfaceWithName: qstringToNSString(wifiDeviceName)]; if([defaultInterface power]) @@ -434,6 +450,8 @@ bool QCoreWlanEngine::isWifiReady(const QString &wifiDeviceName) bool QCoreWlanEngine::isKnownSsid(const QString &interfaceName, const QString &ssid) { + QMutexLocker locker(&mutex); + #if defined(MAC_SDK_10_6) CWInterface *wifiInterface = [CWInterface interfaceWithName: qstringToNSString(interfaceName)]; CWConfiguration *userConfig = [wifiInterface configuration]; @@ -451,6 +469,8 @@ bool QCoreWlanEngine::isKnownSsid(const QString &interfaceName, const QString &s bool QCoreWlanEngine::getAllScInterfaces() { + QMutexLocker locker(&mutex); + networkInterfaces.clear(); NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; @@ -491,6 +511,8 @@ bool QCoreWlanEngine::getAllScInterfaces() QNetworkSession::State QCoreWlanEngine::sessionStateForId(const QString &id) { + QMutexLocker locker(&mutex); + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); if (!ptr) diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp index dba2c08..a95b14b 100644 --- a/src/plugins/bearer/generic/qgenericengine.cpp +++ b/src/plugins/bearer/generic/qgenericengine.cpp @@ -154,11 +154,15 @@ QGenericEngine::~QGenericEngine() QString QGenericEngine::getInterfaceFromId(const QString &id) { + QMutexLocker locker(&mutex); + return configurationInterface.value(id); } bool QGenericEngine::hasIdentifier(const QString &id) { + QMutexLocker locker(&mutex); + return configurationInterface.contains(id); } @@ -174,12 +178,16 @@ void QGenericEngine::disconnectFromId(const QString &id) void QGenericEngine::requestUpdate() { + QMutexLocker locker(&mutex); + pollTimer.stop(); QTimer::singleShot(0, this, SLOT(doRequestUpdate())); } void QGenericEngine::doRequestUpdate() { + QMutexLocker locker(&mutex); + // Immediately after connecting with a wireless access point // QNetworkInterface::allInterfaces() will sometimes return an empty list. Calling it again a // second time results in a non-empty list. If we loose interfaces we will end up removing @@ -282,6 +290,8 @@ void QGenericEngine::doRequestUpdate() QNetworkSession::State QGenericEngine::sessionStateForId(const QString &id) { + QMutexLocker locker(&mutex); + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); if (!ptr) diff --git a/src/plugins/bearer/icd/qicdengine.cpp b/src/plugins/bearer/icd/qicdengine.cpp index 3233eda..f10042a 100644 --- a/src/plugins/bearer/icd/qicdengine.cpp +++ b/src/plugins/bearer/icd/qicdengine.cpp @@ -100,6 +100,8 @@ QIcdEngine::~QIcdEngine() bool QIcdEngine::hasIdentifier(const QString &id) { + QMutexLocker locker(&mutex); + return accessPointConfigurations.contains(id) || snapConfigurations.contains(id) || userChoiceConfigurations.contains(id); @@ -107,6 +109,8 @@ bool QIcdEngine::hasIdentifier(const QString &id) void QIcdEngine::requestUpdate() { + QMutexLocker locker(&mutex); + QTimer::singleShot(0, this, SLOT(doRequestUpdate())); } @@ -156,6 +160,8 @@ static uint32_t getNetworkAttrs(bool is_iap_id, void QIcdEngine::doRequestUpdate() { + QMutexLocker locker(&mutex); + QStringList previous = accessPointConfigurations.keys(); /* All the scanned access points */ @@ -371,6 +377,8 @@ void QIcdEngine::doRequestUpdate() void QIcdEngine::deleteConfiguration(const QString &iap_id) { + QMutexLocker locker(&mutex); + /* Called when IAPs are deleted in gconf, in this case we do not scan * or read all the IAPs from gconf because it might take too much power * (multiple applications would need to scan and read all IAPs from gconf) @@ -409,6 +417,8 @@ QNetworkSessionPrivate *QIcdEngine::createSessionBackend() QNetworkConfigurationPrivatePointer QIcdEngine::defaultConfiguration() { + QMutexLocker locker(&mutex); + // Here we just return [ANY] request to icd and let the icd decide which IAP to connect. return userChoiceConfigurations.value(OSSO_IAP_ANY); } diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp index e4ab0aa..c8015d8 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp @@ -109,6 +109,8 @@ QNativeWifiEngine::~QNativeWifiEngine() void QNativeWifiEngine::scanComplete() { + QMutexLocker locker(&mutex); + QStringList previous = accessPointConfigurations.keys(); // enumerate interfaces @@ -227,6 +229,8 @@ void QNativeWifiEngine::scanComplete() QString QNativeWifiEngine::getInterfaceFromId(const QString &id) { + QMutexLocker locker(&mutex); + // enumerate interfaces WLAN_INTERFACE_INFO_LIST *interfaceList; DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); @@ -276,6 +280,8 @@ QString QNativeWifiEngine::getInterfaceFromId(const QString &id) bool QNativeWifiEngine::hasIdentifier(const QString &id) { + QMutexLocker locker(&mutex); + // enumerate interfaces WLAN_INTERFACE_INFO_LIST *interfaceList; DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); @@ -330,6 +336,8 @@ bool QNativeWifiEngine::hasIdentifier(const QString &id) void QNativeWifiEngine::connectToId(const QString &id) { + QMutexLocker locker(&mutex); + WLAN_INTERFACE_INFO_LIST *interfaceList; DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); if (result != ERROR_SUCCESS) { @@ -393,6 +401,8 @@ void QNativeWifiEngine::connectToId(const QString &id) void QNativeWifiEngine::disconnectFromId(const QString &id) { + QMutexLocker locker(&mutex); + QString interface = getInterfaceFromId(id); if (interface.isEmpty()) { @@ -421,6 +431,8 @@ void QNativeWifiEngine::disconnectFromId(const QString &id) void QNativeWifiEngine::requestUpdate() { + QMutexLocker locker(&mutex); + // enumerate interfaces WLAN_INTERFACE_INFO_LIST *interfaceList; DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); @@ -440,6 +452,8 @@ void QNativeWifiEngine::requestUpdate() QNetworkSession::State QNativeWifiEngine::sessionStateForId(const QString &id) { + QMutexLocker locker(&mutex); + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); if (!ptr) diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp index 4c8928c..5c6efe3 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp @@ -120,6 +120,8 @@ QNetworkManagerEngine::~QNetworkManagerEngine() bool QNetworkManagerEngine::networkManagerAvailable() const { + QMutexLocker locker(&mutex); + return interface->isValid(); } @@ -130,6 +132,8 @@ void QNetworkManagerEngine::doRequestUpdate() QString QNetworkManagerEngine::getInterfaceFromId(const QString &id) { + QMutexLocker locker(&mutex); + foreach (const QDBusObjectPath &acPath, interface->activeConnections()) { QNetworkManagerConnectionActive activeConnection(acPath.path()); @@ -152,6 +156,8 @@ QString QNetworkManagerEngine::getInterfaceFromId(const QString &id) bool QNetworkManagerEngine::hasIdentifier(const QString &id) { + QMutexLocker locker(&mutex); + if (connectionFromId(id)) return true; @@ -170,6 +176,8 @@ bool QNetworkManagerEngine::hasIdentifier(const QString &id) QString QNetworkManagerEngine::bearerName(const QString &id) { + QMutexLocker locker(&mutex); + QNetworkManagerSettingsConnection *connection = connectionFromId(id); if (!connection) @@ -192,6 +200,8 @@ QString QNetworkManagerEngine::bearerName(const QString &id) void QNetworkManagerEngine::connectToId(const QString &id) { + QMutexLocker locker(&mutex); + QNetworkManagerSettingsConnection *connection = connectionFromId(id); if (!connection) @@ -223,6 +233,8 @@ void QNetworkManagerEngine::connectToId(const QString &id) void QNetworkManagerEngine::disconnectFromId(const QString &id) { + QMutexLocker locker(&mutex); + foreach (const QDBusObjectPath &acPath, interface->activeConnections()) { QNetworkManagerConnectionActive activeConnection(acPath.path()); @@ -238,12 +250,16 @@ void QNetworkManagerEngine::disconnectFromId(const QString &id) void QNetworkManagerEngine::requestUpdate() { + QMutexLocker locker(&mutex); + QTimer::singleShot(0, this, SLOT(doRequestUpdate())); } void QNetworkManagerEngine::interfacePropertiesChanged(const QString &path, const QMap &properties) { + QMutexLocker locker(&mutex); + Q_UNUSED(path) QMapIterator i(properties); @@ -310,6 +326,8 @@ void QNetworkManagerEngine::interfacePropertiesChanged(const QString &path, void QNetworkManagerEngine::activeConnectionPropertiesChanged(const QString &path, const QMap &properties) { + QMutexLocker locker(&mutex); + Q_UNUSED(properties) QNetworkManagerConnectionActive *activeConnection = activeConnections.value(path); @@ -333,10 +351,14 @@ void QNetworkManagerEngine::activeConnectionPropertiesChanged(const QString &pat void QNetworkManagerEngine::devicePropertiesChanged(const QString &path, const QMap &properties) { + Q_UNUSED(path); + Q_UNUSED(properties); } void QNetworkManagerEngine::deviceAdded(const QDBusObjectPath &path) { + QMutexLocker locker(&mutex); + QNetworkManagerInterfaceDevice device(path.path()); if (device.deviceType() == DEVICE_TYPE_802_11_WIRELESS) { QNetworkManagerInterfaceDeviceWireless *wirelessDevice = @@ -358,12 +380,16 @@ void QNetworkManagerEngine::deviceAdded(const QDBusObjectPath &path) void QNetworkManagerEngine::deviceRemoved(const QDBusObjectPath &path) { + QMutexLocker locker(&mutex); + delete wirelessDevices.value(path.path()); } void QNetworkManagerEngine::newConnection(const QDBusObjectPath &path, QNetworkManagerSettings *settings) { + QMutexLocker locker(&mutex); + if (!settings) settings = qobject_cast(sender()); @@ -404,6 +430,8 @@ void QNetworkManagerEngine::newConnection(const QDBusObjectPath &path, void QNetworkManagerEngine::removeConnection(const QString &path) { + QMutexLocker locker(&mutex); + Q_UNUSED(path) QNetworkManagerSettingsConnection *connection = @@ -423,6 +451,8 @@ void QNetworkManagerEngine::removeConnection(const QString &path) void QNetworkManagerEngine::updateConnection(const QNmSettingsMap &settings) { + QMutexLocker locker(&mutex); + QNetworkManagerSettingsConnection *connection = qobject_cast(sender()); if (!connection) @@ -458,6 +488,8 @@ void QNetworkManagerEngine::updateConnection(const QNmSettingsMap &settings) void QNetworkManagerEngine::activationFinished(QDBusPendingCallWatcher *watcher) { + QMutexLocker locker(&mutex); + QDBusPendingReply reply = *watcher; if (!reply.isError()) { QDBusObjectPath result = reply.value(); @@ -480,6 +512,8 @@ void QNetworkManagerEngine::activationFinished(QDBusPendingCallWatcher *watcher) void QNetworkManagerEngine::newAccessPoint(const QString &path, const QDBusObjectPath &objectPath) { + QMutexLocker locker(&mutex); + Q_UNUSED(path) QNetworkManagerInterfaceAccessPoint *accessPoint = @@ -535,6 +569,8 @@ void QNetworkManagerEngine::newAccessPoint(const QString &path, const QDBusObjec void QNetworkManagerEngine::removeAccessPoint(const QString &path, const QDBusObjectPath &objectPath) { + QMutexLocker locker(&mutex); + Q_UNUSED(path) for (int i = 0; i < accessPoints.count(); ++i) { @@ -579,6 +615,8 @@ void QNetworkManagerEngine::removeAccessPoint(const QString &path, void QNetworkManagerEngine::updateAccessPoint(const QMap &map) { + QMutexLocker locker(&mutex); + Q_UNUSED(map) QNetworkManagerInterfaceAccessPoint *accessPoint = @@ -607,6 +645,8 @@ QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QStri const QString &settingsPath, const QNmSettingsMap &map) { + QMutexLocker locker(&mutex); + QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; cpPriv->name = map.value("connection").value("id").toString(); cpPriv->isValid = true; @@ -664,6 +704,8 @@ QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QStri QNetworkManagerSettingsConnection *QNetworkManagerEngine::connectionFromId(const QString &id) const { + QMutexLocker locker(&mutex); + for (int i = 0; i < connections.count(); ++i) { QNetworkManagerSettingsConnection *connection = connections.at(i); const QString service = connection->connectionInterface()->service(); @@ -680,6 +722,8 @@ QNetworkManagerSettingsConnection *QNetworkManagerEngine::connectionFromId(const QNetworkSession::State QNetworkManagerEngine::sessionStateForId(const QString &id) { + QMutexLocker locker(&mutex); + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); if (!ptr) @@ -718,6 +762,8 @@ QNetworkSession::State QNetworkManagerEngine::sessionStateForId(const QString &i quint64 QNetworkManagerEngine::bytesWritten(const QString &id) { + QMutexLocker locker(&mutex); + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); if (ptr && (ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { const QString networkInterface = getInterfaceFromId(id); @@ -744,6 +790,8 @@ quint64 QNetworkManagerEngine::bytesWritten(const QString &id) quint64 QNetworkManagerEngine::bytesReceived(const QString &id) { + QMutexLocker locker(&mutex); + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); if (ptr && (ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { const QString networkInterface = getInterfaceFromId(id); @@ -770,6 +818,8 @@ quint64 QNetworkManagerEngine::bytesReceived(const QString &id) quint64 QNetworkManagerEngine::startTime(const QString &id) { + QMutexLocker locker(&mutex); + QNetworkManagerSettingsConnection *connection = connectionFromId(id); if (connection) return connection->getTimestamp(); diff --git a/src/plugins/bearer/nla/qnlaengine.cpp b/src/plugins/bearer/nla/qnlaengine.cpp index 2001c0b..ff334e5 100644 --- a/src/plugins/bearer/nla/qnlaengine.cpp +++ b/src/plugins/bearer/nla/qnlaengine.cpp @@ -521,6 +521,8 @@ QNlaEngine::~QNlaEngine() void QNlaEngine::networksChanged() { + QMutexLocker locker(&mutex); + QStringList previous = accessPointConfigurations.keys(); QList foundConfigurations = nlaThread->getConfigurations(); @@ -574,11 +576,15 @@ void QNlaEngine::networksChanged() QString QNlaEngine::getInterfaceFromId(const QString &id) { + QMutexLocker locker(&mutex); + return configurationInterface.value(id.toUInt()); } bool QNlaEngine::hasIdentifier(const QString &id) { + QMutexLocker locker(&mutex); + return configurationInterface.contains(id.toUInt()); } @@ -604,11 +610,15 @@ void QNlaEngine::disconnectFromId(const QString &id) void QNlaEngine::requestUpdate() { + QMutexLocker locker(&mutex); + nlaThread->forceUpdate(); } QNetworkSession::State QNlaEngine::sessionStateForId(const QString &id) { + QMutexLocker locker(&mutex); + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); if (!ptr) diff --git a/src/plugins/bearer/qnetworksession_impl.cpp b/src/plugins/bearer/qnetworksession_impl.cpp index 3fe844a..f41fdba 100644 --- a/src/plugins/bearer/qnetworksession_impl.cpp +++ b/src/plugins/bearer/qnetworksession_impl.cpp @@ -57,7 +57,7 @@ static QBearerEngineImpl *getEngineFromId(const QString &id) { QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); - foreach (QBearerEngine *engine, priv->sessionEngines) { + foreach (QBearerEngine *engine, priv->engines()) { QBearerEngineImpl *engineImpl = qobject_cast(engine); if (engineImpl && engineImpl->hasIdentifier(id)) return engineImpl; diff --git a/src/plugins/bearer/symbian/symbianengine.cpp b/src/plugins/bearer/symbian/symbianengine.cpp index e25eda4..0331026 100644 --- a/src/plugins/bearer/symbian/symbianengine.cpp +++ b/src/plugins/bearer/symbian/symbianengine.cpp @@ -158,6 +158,8 @@ SymbianEngine::~SymbianEngine() bool SymbianEngine::hasIdentifier(const QString &id) { + QMutexLocker locker(&mutex); + return accessPointConfigurations.contains(id) || snapConfigurations.contains(id) || userChoiceConfigurations.contains(id); @@ -187,6 +189,8 @@ QNetworkSessionPrivate *SymbianEngine::createSessionBackend() void SymbianEngine::requestUpdate() { + QMutexLocker locker(&mutex); + if (!iInitOk || iUpdateGoingOn) { return; } @@ -199,6 +203,8 @@ void SymbianEngine::requestUpdate() void SymbianEngine::updateConfigurations() { + QMutexLocker locker(&mutex); + if (!iInitOk) { return; } @@ -208,6 +214,8 @@ void SymbianEngine::updateConfigurations() void SymbianEngine::updateConfigurationsL() { + QMutexLocker locker(&mutex); + QList knownConfigs = accessPointConfigurations.keys(); QList knownSnapConfigs = snapConfigurations.keys(); @@ -381,6 +389,8 @@ void SymbianEngine::updateConfigurationsL() SymbianNetworkConfigurationPrivate *SymbianEngine::configFromConnectionMethodL( RCmConnectionMethod& connectionMethod) { + QMutexLocker locker(&mutex); + SymbianNetworkConfigurationPrivate *cpPriv = new SymbianNetworkConfigurationPrivate; CleanupStack::PushL(cpPriv); @@ -463,6 +473,8 @@ SymbianNetworkConfigurationPrivate *SymbianEngine::configFromConnectionMethodL( bool SymbianEngine::readNetworkConfigurationValuesFromCommsDb( TUint32 aApId, SymbianNetworkConfigurationPrivate *apNetworkConfiguration) { + QMutexLocker locker(&mutex); + TRAPD(error, readNetworkConfigurationValuesFromCommsDbL(aApId,apNetworkConfiguration)); if (error != KErrNone) { return false; @@ -473,6 +485,8 @@ bool SymbianEngine::readNetworkConfigurationValuesFromCommsDb( void SymbianEngine::readNetworkConfigurationValuesFromCommsDbL( TUint32 aApId, SymbianNetworkConfigurationPrivate *apNetworkConfiguration) { + QMutexLocker locker(&mutex); + CApDataHandler* pDataHandler = CApDataHandler::NewLC(*ipCommsDB); CApAccessPointItem* pAPItem = CApAccessPointItem::NewLC(); TBuf name; @@ -533,6 +547,8 @@ void SymbianEngine::readNetworkConfigurationValuesFromCommsDbL( QNetworkConfigurationPrivatePointer SymbianEngine::defaultConfiguration() { + QMutexLocker locker(&mutex); + QNetworkConfigurationPrivatePointer ptr; if (iInitOk) { @@ -546,6 +562,8 @@ QNetworkConfigurationPrivatePointer SymbianEngine::defaultConfiguration() QNetworkConfigurationPrivatePointer SymbianEngine::defaultConfigurationL() { + QMutexLocker locker(&mutex); + QNetworkConfigurationPrivatePointer ptr; #ifdef SNAP_FUNCTIONALITY_AVAILABLE @@ -571,6 +589,8 @@ QNetworkConfigurationPrivatePointer SymbianEngine::defaultConfigurationL() void SymbianEngine::updateActiveAccessPoints() { + QMutexLocker locker(&mutex); + bool online = false; QList inactiveConfigs = accessPointConfigurations.keys(); @@ -620,6 +640,8 @@ void SymbianEngine::updateActiveAccessPoints() void SymbianEngine::updateAvailableAccessPoints() { + QMutexLocker locker(&mutex); + if (!ipAccessPointsAvailabilityScanner) { ipAccessPointsAvailabilityScanner = new AccessPointsAvailabilityScanner(*this, iConnectionMonitor); } @@ -631,6 +653,8 @@ void SymbianEngine::updateAvailableAccessPoints() void SymbianEngine::accessPointScanningReady(TBool scanSuccessful, TConnMonIapInfo iapInfo) { + QMutexLocker locker(&mutex); + iUpdateGoingOn = false; if (scanSuccessful) { QList unavailableConfigs = accessPointConfigurations.keys(); @@ -668,6 +692,8 @@ void SymbianEngine::accessPointScanningReady(TBool scanSuccessful, TConnMonIapIn void SymbianEngine::updateStatesToSnaps() { + QMutexLocker locker(&mutex); + // Go through SNAPs and set correct state to SNAPs QList snapConfigIdents = snapConfigurations.keys(); foreach (QString iface, snapConfigIdents) { @@ -700,6 +726,8 @@ void SymbianEngine::updateStatesToSnaps() bool SymbianEngine::changeConfigurationStateTo(QNetworkConfigurationPrivatePointer ptr, QNetworkConfiguration::StateFlags newState) { + QMutexLocker locker(&mutex); + if (newState != ptr->state) { ptr->state = newState; emit configurationChanged(ptr); @@ -715,6 +743,8 @@ bool SymbianEngine::changeConfigurationStateTo(QNetworkConfigurationPrivatePoint bool SymbianEngine::changeConfigurationStateAtMinTo(QNetworkConfigurationPrivatePointer ptr, QNetworkConfiguration::StateFlags newState) { + QMutexLocker locker(&mutex); + if ((newState | ptr->state) != ptr->state) { ptr->state = (ptr->state | newState); emit configurationChanged(ptr); @@ -731,6 +761,8 @@ bool SymbianEngine::changeConfigurationStateAtMinTo(QNetworkConfigurationPrivate bool SymbianEngine::changeConfigurationStateAtMaxTo(QNetworkConfigurationPrivatePointer ptr, QNetworkConfiguration::StateFlags newState) { + QMutexLocker locker(&mutex); + if ((newState & ptr->state) != ptr->state) { ptr->state = (newState & ptr->state); emit configurationChanged(ptr); @@ -741,6 +773,8 @@ bool SymbianEngine::changeConfigurationStateAtMaxTo(QNetworkConfigurationPrivate void SymbianEngine::startCommsDatabaseNotifications() { + QMutexLocker locker(&mutex); + if (!iWaitingCommsDatabaseNotifications) { iWaitingCommsDatabaseNotifications = ETrue; if (!IsActive()) { @@ -753,6 +787,8 @@ void SymbianEngine::startCommsDatabaseNotifications() void SymbianEngine::stopCommsDatabaseNotifications() { + QMutexLocker locker(&mutex); + if (iWaitingCommsDatabaseNotifications) { iWaitingCommsDatabaseNotifications = EFalse; if (!IsActive()) { @@ -769,6 +805,8 @@ void SymbianEngine::stopCommsDatabaseNotifications() void SymbianEngine::RunL() { + QMutexLocker locker(&mutex); + if (iStatus != KErrCancel) { RDbNotifier::TEvent event = STATIC_CAST(RDbNotifier::TEvent, iStatus.Int()); switch (event) { @@ -805,12 +843,16 @@ void SymbianEngine::RunL() void SymbianEngine::DoCancel() { + QMutexLocker locker(&mutex); + ipCommsDB->CancelRequestNotification(); } void SymbianEngine::EventL(const CConnMonEventBase& aEvent) { + QMutexLocker locker(&mutex); + switch (aEvent.EventType()) { case EConnMonCreateConnection: { @@ -902,6 +944,8 @@ void SymbianEngine::EventL(const CConnMonEventBase& aEvent) QNetworkConfigurationPrivatePointer SymbianEngine::dataByConnectionId(TUint aConnectionId) { + QMutexLocker locker(&mutex); + QNetworkConfiguration item; QHash::const_iterator i = -- cgit v0.12 From 0f761d9d95bc187cb786ce7dc03a7d8c9ad9d779 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 22 Feb 2010 12:27:39 +1000 Subject: Increase try verify timeout. --- .../declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp | 2 +- tests/auto/declarative/qmlgraphicsimage/tst_qmlgraphicsimage.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp b/tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp index 183f7e4..bb978d1 100644 --- a/tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp +++ b/tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp @@ -60,7 +60,7 @@ #define TRY_WAIT(expr) \ do { \ - for (int ii = 0; ii < 6; ++ii) { \ + for (int ii = 0; ii < 60; ++ii) { \ if ((expr)) break; \ QTest::qWait(50); \ } \ diff --git a/tests/auto/declarative/qmlgraphicsimage/tst_qmlgraphicsimage.cpp b/tests/auto/declarative/qmlgraphicsimage/tst_qmlgraphicsimage.cpp index 503b05e..a25dcd2 100644 --- a/tests/auto/declarative/qmlgraphicsimage/tst_qmlgraphicsimage.cpp +++ b/tests/auto/declarative/qmlgraphicsimage/tst_qmlgraphicsimage.cpp @@ -59,7 +59,7 @@ #define TRY_WAIT(expr) \ do { \ - for (int ii = 0; ii < 6; ++ii) { \ + for (int ii = 0; ii < 60; ++ii) { \ if ((expr)) break; \ QTest::qWait(50); \ } \ -- cgit v0.12 From 2e4f20d8c541db2c68e82be3261355ccc59fd10d Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 22 Feb 2010 15:53:16 +1000 Subject: Change initialization order. --- src/network/bearer/qnetworkconfigmanager_p.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 6ac61b3..1ac10c5 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -55,7 +55,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, (QBearerEngineFactoryInterface_iid, QLatin1String("/bearer"))) QNetworkConfigurationManagerPrivate::QNetworkConfigurationManagerPrivate() -: capFlags(0), firstUpdate(true), mutex(QMutex::Recursive) +: capFlags(0), mutex(QMutex::Recursive), firstUpdate(true) { updateConfigurations(); -- cgit v0.12 From 0771d24f2ea3ba46c8e825b8720561258f9646ce Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 23 Feb 2010 11:35:41 +1000 Subject: Fix build on Symbian. --- src/plugins/bearer/symbian/qnetworksession_impl.cpp | 4 ++-- src/plugins/bearer/symbian/symbianengine.cpp | 7 +++++++ src/plugins/bearer/symbian/symbianengine.h | 3 +++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/plugins/bearer/symbian/qnetworksession_impl.cpp b/src/plugins/bearer/symbian/qnetworksession_impl.cpp index 7762fb5..9af1fe9 100644 --- a/src/plugins/bearer/symbian/qnetworksession_impl.cpp +++ b/src/plugins/bearer/symbian/qnetworksession_impl.cpp @@ -322,7 +322,7 @@ void QNetworkSessionPrivateImpl::open() } newState(QNetworkSession::Connecting); } else if (publicConfig.type() == QNetworkConfiguration::UserChoice) { - iKnownConfigsBeforeConnectionStart = engine->accessPointConfigurations.keys(); + iKnownConfigsBeforeConnectionStart = engine->accessPointConfigurationIdentifiers(); iConnection.Start(iStatus); if (!IsActive()) { SetActive(); @@ -699,7 +699,7 @@ QNetworkConfiguration QNetworkSessionPrivateImpl::activeConfiguration(TUint32 ia // 1. Sync internal configurations array to commsdb first engine->updateConfigurations(); // 2. Check if new configuration was created during connection creation - QList knownConfigs = engine->accessPointConfigurations.keys(); + QStringList knownConfigs = engine->accessPointConfigurationIdentifiers(); if (knownConfigs.count() > iKnownConfigsBeforeConnectionStart.count()) { // Configuration count increased => new configuration was created // => Search new, created configuration diff --git a/src/plugins/bearer/symbian/symbianengine.cpp b/src/plugins/bearer/symbian/symbianengine.cpp index 0331026..b3c9cb3 100644 --- a/src/plugins/bearer/symbian/symbianengine.cpp +++ b/src/plugins/bearer/symbian/symbianengine.cpp @@ -560,6 +560,13 @@ QNetworkConfigurationPrivatePointer SymbianEngine::defaultConfiguration() return ptr; } +QStringList SymbianEngine::accessPointConfigurationIdentifiers() +{ + QMutexLocker locker(&mutex); + + return accessPointConfigurations.keys(); +} + QNetworkConfigurationPrivatePointer SymbianEngine::defaultConfigurationL() { QMutexLocker locker(&mutex); diff --git a/src/plugins/bearer/symbian/symbianengine.h b/src/plugins/bearer/symbian/symbianengine.h index 587585b..5448813 100644 --- a/src/plugins/bearer/symbian/symbianengine.h +++ b/src/plugins/bearer/symbian/symbianengine.h @@ -42,6 +42,7 @@ #ifndef SYMBIANENGINE_H #define SYMBIANENGINE_H +#include #include #include @@ -116,6 +117,8 @@ public: QNetworkConfigurationPrivatePointer defaultConfiguration(); + QStringList accessPointConfigurationIdentifiers(); + Q_SIGNALS: void onlineStateChanged(bool isOnline); -- cgit v0.12 From 055fa76e7575be55899127de2d254e0f0e90a1db Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 23 Feb 2010 13:12:44 +1000 Subject: Make compile on Maemo6. --- src/plugins/bearer/icd/main.cpp | 2 +- src/plugins/bearer/icd/qicdengine.h | 14 +++++++++++--- src/plugins/bearer/icd/qnetworksession_impl.cpp | 9 ++++----- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/plugins/bearer/icd/main.cpp b/src/plugins/bearer/icd/main.cpp index b131ccb..ad1a918 100644 --- a/src/plugins/bearer/icd/main.cpp +++ b/src/plugins/bearer/icd/main.cpp @@ -41,7 +41,7 @@ #include "qicdengine.h" -#include +#include #include diff --git a/src/plugins/bearer/icd/qicdengine.h b/src/plugins/bearer/icd/qicdengine.h index 30b5711..6ebe40d 100644 --- a/src/plugins/bearer/icd/qicdengine.h +++ b/src/plugins/bearer/icd/qicdengine.h @@ -80,8 +80,6 @@ class QIcdEngine : public QBearerEngine { Q_OBJECT - friend class QNetworkSessionPrivateImpl; - public: QIcdEngine(QObject *parent = 0); ~QIcdEngine(); @@ -98,15 +96,25 @@ public: void deleteConfiguration(const QString &iap_id); -private: + inline QNetworkConfigurationPrivatePointer configuration(const QString &id) + { + QMutexLocker locker(&mutex); + + return accessPointConfigurations.value(id); + } + inline void addSessionConfiguration(QNetworkConfigurationPrivatePointer ptr) { + QMutexLocker locker(&mutex); + accessPointConfigurations.insert(ptr->id, ptr); emit configurationAdded(ptr); } inline void changedSessionConfiguration(QNetworkConfigurationPrivatePointer ptr) { + QMutexLocker locker(&mutex); + emit configurationChanged(ptr); } diff --git a/src/plugins/bearer/icd/qnetworksession_impl.cpp b/src/plugins/bearer/icd/qnetworksession_impl.cpp index 6cc4a1d..a9e93e0 100644 --- a/src/plugins/bearer/icd/qnetworksession_impl.cpp +++ b/src/plugins/bearer/icd/qnetworksession_impl.cpp @@ -560,7 +560,7 @@ void QNetworkSessionPrivateImpl::syncStateWithInterface() // Add the new active configuration to manager or update the old config - if (!(engine->accessPointConfigurations.contains(privateConfiguration(activeConfig)->id))) + if (!engine->hasIdentifier(privateConfiguration(activeConfig)->id)) engine->addSessionConfiguration(privateConfiguration(activeConfig)); else engine->changedSessionConfiguration(privateConfiguration(activeConfig)); @@ -924,11 +924,10 @@ void QNetworkSessionPrivateImpl::do_open() */ if (publicConfig.type() == QNetworkConfiguration::UserChoice) { - if (!engine->accessPointConfigurations.contains(result)) { + if (!engine->hasIdentifier(result)) { engine->addSessionConfiguration(privateConfiguration(config)); - } else { - QNetworkConfigurationPrivatePointer priv = - engine->accessPointConfigurations.value(result); + } else { + QNetworkConfigurationPrivatePointer priv = engine->configuration(result); QNetworkConfiguration reference; setPrivateConfiguration(reference, priv); copyConfig(config, reference, false); -- cgit v0.12 From cfed63b7b8ef0be1d5da583b52b7e88902383e06 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Wed, 24 Feb 2010 06:47:40 +1000 Subject: Make this function non-static. --- src/plugins/bearer/corewlan/qcorewlanengine.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.h b/src/plugins/bearer/corewlan/qcorewlanengine.h index 54f2027..044b433 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.h +++ b/src/plugins/bearer/corewlan/qcorewlanengine.h @@ -77,7 +77,7 @@ public: QNetworkConfigurationPrivatePointer defaultConfiguration(); - static bool getAllScInterfaces(); + bool getAllScInterfaces(); private Q_SLOTS: void doRequestUpdate(); -- cgit v0.12