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