1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the plugins 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 http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://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 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QNETWORKSESSION_IMPL_H
43 #define QNETWORKSESSION_IMPL_H
44 
45 //
46 //  W A R N I N G
47 //  -------------
48 //
49 // This file is not part of the Qt API.  It exists purely as an
50 // implementation detail.  This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 
56 #include <QtNetwork/private/qnetworksession_p.h>
57 
58 #include <QDateTime>
59 
60 #include <e32base.h>
61 #include <commdbconnpref.h>
62 #include <es_sock.h>
63 #include <rconnmon.h>
64 #ifdef SNAP_FUNCTIONALITY_AVAILABLE
65     #include <comms-infras/cs_mobility_apiext.h>
66 #endif
67 
68 QT_BEGIN_NAMESPACE
69 
70 class ConnectionProgressNotifier;
71 class ConnectionStarter;
72 class SymbianEngine;
73 
74 typedef void (*TOpenCUnSetdefaultifFunction)();
75 
76 class QNetworkSessionPrivateImpl : public QNetworkSessionPrivate
77 #ifdef SNAP_FUNCTIONALITY_AVAILABLE
78                                  , public MMobilityProtocolResp
79 #endif
80 {
81     Q_OBJECT
82 public:
83     QNetworkSessionPrivateImpl(SymbianEngine *engine);
84     ~QNetworkSessionPrivateImpl();
85 
86     //called by QNetworkSession constructor and ensures
87     //that the state is immediately updated (w/o actually opening
88     //a session). Also this function should take care of
89     //notification hooks to discover future state changes.
90     void syncStateWithInterface();
91 
92 #ifndef QT_NO_NETWORKINTERFACE
93     QNetworkInterface currentInterface() const;
94 #endif
95     QVariant sessionProperty(const QString& key) const;
96     void setSessionProperty(const QString& key, const QVariant& value);
97 
98     void setALREnabled(bool enabled);
99 
100     void open();
close()101     inline void close() { close(true); }
102     void close(bool allowSignals);
103     void stop();
104     void migrate();
105     void accept();
106     void ignore();
107     void reject();
108 
109     QString errorString() const; //must return translated string
110     QNetworkSession::SessionError error() const;
111 
112     quint64 bytesWritten() const;
113     quint64 bytesReceived() const;
114     quint64 activeTime() const;
115 
116     RConnection* nativeSession();
117 #ifdef SNAP_FUNCTIONALITY_AVAILABLE
118 public: // From MMobilityProtocolResp
119     void PreferredCarrierAvailable(TAccessPointInfo aOldAPInfo,
120                                    TAccessPointInfo aNewAPInfo,
121                                    TBool aIsUpgrade,
122                                    TBool aIsSeamless);
123 
124     void NewCarrierActive(TAccessPointInfo aNewAPInfo, TBool aIsSeamless);
125 
126     void Error(TInt aError);
127 #endif
128 
129 protected: // From CActive
130     void ConnectionStartComplete(TInt statusCode);
131     void DoCancel();
132 
133 private Q_SLOTS:
134     void configurationStateChanged(quint32 accessPointId, quint32 connMonId,
135                                    QNetworkSession::State newState);
136     void configurationRemoved(QNetworkConfigurationPrivatePointer config);
137     void configurationAdded(QNetworkConfigurationPrivatePointer config);
138 
139 private:
140     TUint iapClientCount(TUint aIAPId) const;
141     quint64 transferredData(TUint dataType) const;
142     bool newState(QNetworkSession::State newState, TUint accessPointId = 0);
143     void handleSymbianConnectionStatusChange(TInt aConnectionStatus, TInt aError, TUint accessPointId = 0);
144     QNetworkConfiguration bestConfigFromSNAP(const QNetworkConfiguration& snapConfig) const;
145     QNetworkConfiguration activeConfiguration(TUint32 iapId = 0) const;
146     bool activeIapId(TUint32 &iapId) const;
147     void updateCurrentIap(TUint32 iapId);
148 #ifndef QT_NO_NETWORKINTERFACE
149     QNetworkInterface interface(TUint iapId) const;
150 #endif
151 
152 #if defined(SNAP_FUNCTIONALITY_AVAILABLE)
153     bool easyWlanTrueIapId(TUint32 &trueIapId) const;
154 #endif
155 
156     void closeHandles();
157 
158 private: // data
159     SymbianEngine *engine;
160 
161 #ifndef QT_NO_NETWORKINTERFACE
162     mutable QNetworkInterface activeInterface;
163 #endif
164 
165     QDateTime startTime;
166 
167     mutable RSocketServ &iSocketServ; //not owned, shared from QtCore
168     mutable RConnection iConnection;
169     mutable RConnectionMonitor iConnectionMonitor;
170     ConnectionProgressNotifier* ipConnectionNotifier;
171     ConnectionStarter* ipConnectionStarter;
172 
173     bool iHandleStateNotificationsFromManager;
174     bool iFirstSync;
175     bool iStoppedByUser;
176     bool iClosedByUser;
177 
178 #ifdef SNAP_FUNCTIONALITY_AVAILABLE
179     CActiveCommsMobilityApiExt* iMobility;
180 #endif
181 
182     QNetworkSession::SessionError iError;
183     TInt iALREnabled;
184     TBool iALRUpgradingConnection;
185     TBool iConnectInBackground;
186 
187     QList<QString> iKnownConfigsBeforeConnectionStart;
188 
189     TUint32 iOldRoamingIap;
190     TUint32 iNewRoamingIap;
191     TUint32 iCurrentIap;
192 
193     bool isOpening;
194 
195     friend class ConnectionProgressNotifier;
196     friend class ConnectionStarter;
197 };
198 
199 class ConnectionProgressNotifier : public CActive
200 {
201 public:
202     ConnectionProgressNotifier(QNetworkSessionPrivateImpl &owner, RConnection &connection);
203     ~ConnectionProgressNotifier();
204 
205     void StartNotifications();
206     void StopNotifications();
207 
208 protected: // From CActive
209     void RunL();
210     void DoCancel();
211 
212 private: // Data
213     QNetworkSessionPrivateImpl &iOwner;
214     RConnection& iConnection;
215     TNifProgressBuf iProgress;
216 
217 };
218 
219 class ConnectionStarter : public CActive
220 {
221 public:
222     ConnectionStarter(QNetworkSessionPrivateImpl &owner, RConnection &connection);
223     ~ConnectionStarter();
224 
225     void Start();
226     void Start(TConnPref &pref);
227 protected:
228     void RunL();
229     TInt RunError(TInt err);
230     void DoCancel();
231 
232 private: // Data
233     QNetworkSessionPrivateImpl &iOwner;
234     RConnection& iConnection;
235 };
236 
237 QT_END_NAMESPACE
238 
239 #endif //QNETWORKSESSION_IMPL_H
240 
241