| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtNetwork module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #ifndef QNETWORKSESSION_H |
| 41 | #define QNETWORKSESSION_H |
| 42 | |
| 43 | #if 0 |
| 44 | #pragma qt_class(QNetworkSession) |
| 45 | #endif |
| 46 | |
| 47 | #include <QtNetwork/qtnetworkglobal.h> |
| 48 | #include <QtCore/qobject.h> |
| 49 | #include <QtCore/qstring.h> |
| 50 | #include <QtNetwork/qnetworkinterface.h> |
| 51 | #include <QtCore/qvariant.h> |
| 52 | #include <QtNetwork/qnetworkconfiguration.h> |
| 53 | |
| 54 | QT_WARNING_PUSH |
| 55 | QT_WARNING_DISABLE_DEPRECATED |
| 56 | |
| 57 | #ifndef QT_NO_BEARERMANAGEMENT |
| 58 | |
| 59 | #if defined(Q_OS_WIN) && defined(interface) |
| 60 | #undef interface |
| 61 | #endif |
| 62 | |
| 63 | #include <QtCore/qshareddata.h> |
| 64 | QT_BEGIN_NAMESPACE |
| 65 | |
| 66 | class QNetworkSessionPrivate; |
| 67 | class QT_DEPRECATED_BEARER_MANAGEMENT Q_NETWORK_EXPORT QNetworkSession : public QObject |
| 68 | { |
| 69 | Q_OBJECT |
| 70 | |
| 71 | public: |
| 72 | enum State { |
| 73 | Invalid = 0, |
| 74 | NotAvailable, |
| 75 | Connecting, |
| 76 | Connected, |
| 77 | Closing, |
| 78 | Disconnected, |
| 79 | Roaming |
| 80 | }; |
| 81 | |
| 82 | enum SessionError { |
| 83 | UnknownSessionError = 0, |
| 84 | SessionAbortedError, |
| 85 | RoamingError, |
| 86 | OperationNotSupportedError, |
| 87 | InvalidConfigurationError |
| 88 | }; |
| 89 | |
| 90 | enum UsagePolicy { |
| 91 | NoPolicy = 0, |
| 92 | NoBackgroundTrafficPolicy = 1 |
| 93 | }; |
| 94 | |
| 95 | Q_DECLARE_FLAGS(UsagePolicies, UsagePolicy) |
| 96 | |
| 97 | explicit QNetworkSession(const QNetworkConfiguration &connConfig, QObject *parent = nullptr); |
| 98 | virtual ~QNetworkSession(); |
| 99 | |
| 100 | bool isOpen() const; |
| 101 | QNetworkConfiguration configuration() const; |
| 102 | #ifndef QT_NO_NETWORKINTERFACE |
| 103 | QNetworkInterface interface() const; |
| 104 | #endif |
| 105 | |
| 106 | State state() const; |
| 107 | SessionError error() const; |
| 108 | QString errorString() const; |
| 109 | QVariant sessionProperty(const QString &key) const; |
| 110 | void setSessionProperty(const QString &key, const QVariant &value); |
| 111 | |
| 112 | quint64 bytesWritten() const; |
| 113 | quint64 bytesReceived() const; |
| 114 | quint64 activeTime() const; |
| 115 | |
| 116 | QNetworkSession::UsagePolicies usagePolicies() const; |
| 117 | |
| 118 | bool waitForOpened(int msecs = 30000); |
| 119 | |
| 120 | public Q_SLOTS: |
| 121 | void open(); |
| 122 | void close(); |
| 123 | void stop(); |
| 124 | |
| 125 | //roaming related slots |
| 126 | void migrate(); |
| 127 | void ignore(); |
| 128 | void accept(); |
| 129 | void reject(); |
| 130 | |
| 131 | Q_SIGNALS: |
| 132 | void stateChanged(QNetworkSession::State); |
| 133 | void opened(); |
| 134 | void closed(); |
| 135 | void error(QNetworkSession::SessionError); |
| 136 | void preferredConfigurationChanged(const QNetworkConfiguration &config, bool isSeamless); |
| 137 | void newConfigurationActivated(); |
| 138 | void usagePoliciesChanged(QNetworkSession::UsagePolicies usagePolicies); |
| 139 | |
| 140 | protected: |
| 141 | virtual void connectNotify(const QMetaMethod &signal) override; |
| 142 | virtual void disconnectNotify(const QMetaMethod &signal) override; |
| 143 | |
| 144 | private: |
| 145 | Q_DISABLE_COPY(QNetworkSession) |
| 146 | friend class QNetworkSessionPrivate; |
| 147 | QNetworkSessionPrivate *d; |
| 148 | }; |
| 149 | |
| 150 | QT_END_NAMESPACE |
| 151 | Q_DECLARE_METATYPE(QNetworkSession::State) |
| 152 | Q_DECLARE_METATYPE(QNetworkSession::SessionError) |
| 153 | Q_DECLARE_METATYPE(QNetworkSession::UsagePolicies) |
| 154 | |
| 155 | #endif // QT_NO_BEARERMANAGEMENT |
| 156 | |
| 157 | QT_WARNING_POP |
| 158 | |
| 159 | #endif // QNETWORKSESSION_H |
| 160 | |