qnetworksession.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtNetwork module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QNETWORKSESSION_H
00043 #define QNETWORKSESSION_H
00044 
00045 #include <QtCore/qobject.h>
00046 #include <QtCore/qstring.h>
00047 #include <QtNetwork/qnetworkinterface.h>
00048 #include <QtCore/qvariant.h>
00049 #include <QtNetwork/qnetworkconfiguration.h>
00050 
00051 #ifndef QT_NO_BEARERMANAGEMENT
00052 
00053 #if defined(Q_OS_WIN) && defined(interface)
00054 #undef interface
00055 #endif
00056 
00057 QT_BEGIN_HEADER
00058 
00059 #ifndef QT_MOBILITY_BEARER
00060 #include <QtCore/qshareddata.h>
00061 QT_BEGIN_NAMESPACE
00062 QT_MODULE(Network)
00063 #define QNetworkSessionExport Q_NETWORK_EXPORT
00064 #else
00065 #include "qmobilityglobal.h"
00066 QTM_BEGIN_NAMESPACE
00067 #define QNetworkSessionExport Q_BEARER_EXPORT
00068 #endif
00069 
00070 class QNetworkSessionPrivate;
00071 class QNetworkSessionExport QNetworkSession : public QObject
00072 {
00073     Q_OBJECT
00074 public:
00075     enum State {
00076         Invalid = 0,
00077         NotAvailable,
00078         Connecting,
00079         Connected,
00080         Closing,
00081         Disconnected,
00082         Roaming
00083     };
00084 
00085     enum SessionError {
00086         UnknownSessionError = 0,
00087         SessionAbortedError,
00088         RoamingError,
00089         OperationNotSupportedError,
00090         InvalidConfigurationError
00091     };
00092     explicit QNetworkSession(const QNetworkConfiguration& connConfig, QObject* parent =0);
00093     virtual ~QNetworkSession();
00094 
00095     bool isOpen() const;
00096     QNetworkConfiguration configuration() const;
00097 #ifndef QT_NO_NETWORKINTERFACE
00098     QNetworkInterface interface() const;
00099 #endif
00100 
00101     State state() const;
00102     SessionError error() const;
00103     QString errorString() const;
00104     QVariant sessionProperty(const QString& key) const;
00105     void setSessionProperty(const QString& key, const QVariant& value);
00106 
00107     quint64 bytesWritten() const;
00108     quint64 bytesReceived() const;
00109     quint64 activeTime() const;
00110     
00111     bool waitForOpened(int msecs = 30000);
00112 
00113 public Q_SLOTS:
00114     void open();
00115     void close();
00116     void stop();
00117 
00118     //roaming related slots
00119     void migrate();
00120     void ignore();
00121     void accept();
00122     void reject();
00123 
00124 
00125 Q_SIGNALS:
00126     void stateChanged(QNetworkSession::State);
00127     void opened();
00128     void closed();
00129     void error(QNetworkSession::SessionError);
00130     void preferredConfigurationChanged(const QNetworkConfiguration& config, bool isSeamless);
00131     void newConfigurationActivated();
00132 
00133 protected:
00134     virtual void connectNotify(const char *signal);
00135     virtual void disconnectNotify(const char *signal);
00136 
00137 private:
00138     QNetworkSessionPrivate* d;
00139     friend class QNetworkSessionPrivate;
00140     };
00141 
00142 #ifndef QT_MOBILITY_BEARER
00143 QT_END_NAMESPACE
00144 #else
00145 QTM_END_NAMESPACE
00146 #endif
00147 
00148 QT_END_HEADER
00149 
00150 #endif // QT_NO_BEARERMANAGEMENT
00151 
00152 #endif //QNETWORKSESSION_H