diff options
Diffstat (limited to 'src/network/bearer/qnetworksession.cpp')
-rw-r--r-- | src/network/bearer/qnetworksession.cpp | 110 |
1 files changed, 53 insertions, 57 deletions
diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp index 226c3c5..af60a43 100644 --- a/src/network/bearer/qnetworksession.cpp +++ b/src/network/bearer/qnetworksession.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -39,11 +39,12 @@ ** ****************************************************************************/ +#include "qnetworksession.h" +#include "qbearerengine_p.h" + #include <QEventLoop> #include <QTimer> -#include "qnetworksession.h" -#include "qbearerengine_p.h" #include "qnetworkconfigmanager_p.h" #include "qnetworksession_p.h" @@ -165,7 +166,7 @@ QT_BEGIN_NAMESPACE */ /*! - \fn void QNetworkSession::preferredConfigurationChanged(const QNetworkConfiguration& config, bool isSeamless) + \fn void QNetworkSession::preferredConfigurationChanged(const QNetworkConfiguration &config, bool isSeamless) This signal is emitted when the preferred configuration/access point for the session changes. Only sessions which are based on service network configurations @@ -224,32 +225,34 @@ QT_BEGIN_NAMESPACE \sa QNetworkConfiguration */ -QNetworkSession::QNetworkSession(const QNetworkConfiguration& connectionConfig, QObject* parent) -: QObject(parent), d(0) +QNetworkSession::QNetworkSession(const QNetworkConfiguration &connectionConfig, QObject *parent) + : QObject(parent), d(0) { // invalid configuration - if (connectionConfig.identifier().isNull()) - return; - - foreach (QBearerEngine *engine, qNetworkConfigurationManagerPrivate()->engines()) { - 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(preferredConfigurationChanged(QNetworkConfiguration,bool)), - this, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool))); - connect(d, SIGNAL(newConfigurationActivated()), - this, SIGNAL(newConfigurationActivated())); - break; + if (!connectionConfig.identifier().isEmpty()) { + foreach (QBearerEngine *engine, qNetworkConfigurationManagerPrivate()->engines()) { + 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(preferredConfigurationChanged(QNetworkConfiguration,bool)), + this, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool))); + connect(d, SIGNAL(newConfigurationActivated()), + this, SIGNAL(newConfigurationActivated())); + break; + } } } + + qRegisterMetaType<QNetworkSession::State>(); + qRegisterMetaType<QNetworkSession::SessionError>(); } /*! @@ -310,22 +313,20 @@ bool QNetworkSession::waitForOpened(int msecs) if (d->isOpen) return true; - if (d->state != Connecting) + if (!(d->state == Connecting || d->state == Connected)) { return false; + } - QEventLoop* loop = new QEventLoop(this); - QObject::connect(d, SIGNAL(quitPendingWaitsForOpened()), - loop, SLOT(quit())); - QObject::connect(this, SIGNAL(error(QNetworkSession::SessionError)), - loop, SLOT(quit())); + QEventLoop loop; + QObject::connect(d, SIGNAL(quitPendingWaitsForOpened()), &loop, SLOT(quit())); + QObject::connect(this, SIGNAL(error(QNetworkSession::SessionError)), &loop, SLOT(quit())); //final call - if (msecs>=0) - QTimer::singleShot(msecs, loop, SLOT(quit())); + if (msecs >= 0) + QTimer::singleShot(msecs, &loop, SLOT(quit())); - loop->exec(); - loop->disconnect(); - loop->deleteLater(); + // enter the event loop and wait for opened/error/timeout + loop.exec(QEventLoop::ExcludeUserInputEvents | QEventLoop::WaitForMoreEvents); return d->isOpen; } @@ -471,7 +472,7 @@ QString QNetworkSession::errorString() const \code QNetworkConfigurationManager mgr; QNetworkConfiguration ap = mgr.defaultConfiguration(); - QNetworkSession* session = new QNetworkSession(ap); + QNetworkSession *session = new QNetworkSession(ap); ... //code activates session QString ident = session->sessionProperty("ActiveConfiguration").toString(); @@ -516,20 +517,13 @@ QString QNetworkSession::errorString() const has no effect for sessions that do not require polling. \endtable */ -QVariant QNetworkSession::sessionProperty(const QString& key) const +QVariant QNetworkSession::sessionProperty(const QString &key) const { - if (!d) + if (!d || !d->publicConfig.isValid()) return QVariant(); - if (!d->publicConfig.isValid()) - return QVariant(); - - if (key == QLatin1String("ActiveConfiguration")) { - if (!d->isOpen) - return QString(); - else - return d->activeConfig.identifier(); - } + if (key == QLatin1String("ActiveConfiguration")) + return d->isOpen ? d->activeConfig.identifier() : QString(); if (key == QLatin1String("UserChoiceConfiguration")) { if (!d->isOpen || d->publicConfig.type() != QNetworkConfiguration::UserChoice) @@ -552,7 +546,7 @@ QVariant QNetworkSession::sessionProperty(const QString& key) const Note that the \e UserChoiceConfiguration and \e ActiveConfiguration properties are read only and cannot be changed using this method. */ -void QNetworkSession::setSessionProperty(const QString& key, const QVariant& value) +void QNetworkSession::setSessionProperty(const QString &key, const QVariant &value) { if (!d) return; @@ -586,7 +580,7 @@ void QNetworkSession::migrate() */ void QNetworkSession::ignore() { - // Needed on at least Symbian platform: the roaming must be explicitly + // Needed on at least Symbian platform: the roaming must be explicitly // ignore()'d or migrate()'d if (d) d->ignore(); @@ -680,11 +674,12 @@ quint64 QNetworkSession::activeTime() const void QNetworkSession::connectNotify(const char *signal) { QObject::connectNotify(signal); - //check for preferredConfigurationChanged() signal connect notification - //This is not required on all platforms + if (!d) return; + //check for preferredConfigurationChanged() signal connect notification + //This is not required on all platforms if (qstrcmp(signal, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool))) == 0) d->setALREnabled(true); } @@ -692,19 +687,20 @@ void QNetworkSession::connectNotify(const char *signal) /*! \internal - This function is called when the client disconnects from the preferredConfigurationChanged() - signal. + This function is called when the client disconnects from the + preferredConfigurationChanged() signal. \sa connectNotify() */ void QNetworkSession::disconnectNotify(const char *signal) { QObject::disconnectNotify(signal); - //check for preferredConfigurationChanged() signal disconnect notification - //This is not required on all platforms + if (!d) return; + //check for preferredConfigurationChanged() signal disconnect notification + //This is not required on all platforms if (qstrcmp(signal, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool))) == 0) d->setALREnabled(false); } |