|
1 /* |
|
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: CSocketsEngine implements an engine for connection |
|
15 * component checking: Interface opening/closing, connecting, |
|
16 * sending/receiving data, etc. |
|
17 * CSocketsEngine is an active object |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 #ifndef __SOCKETSENGINE_H__ |
|
23 #define __SOCKETSENGINE_H__ |
|
24 |
|
25 // INCLUDES |
|
26 #include <in_sock.h> |
|
27 #include <es_sock.h> |
|
28 #include <http.h> |
|
29 #include <commdbconnpref.h> |
|
30 #include <extendedconnpref.h> |
|
31 #include "TimeOutNotify.h" |
|
32 #include "ProgressNotifyHandler.h" |
|
33 #include "datasendnotifyhandler.h" |
|
34 #include "conntest.hrh" |
|
35 #include "alractiveobject.h" |
|
36 |
|
37 // CONSTANTS |
|
38 |
|
39 // FORWARD DECLARATIONS |
|
40 class CSocketsRead; |
|
41 class CSocketsWrite; |
|
42 class CTimeOutTimer; |
|
43 class MUINotify; |
|
44 class CHttpClient; |
|
45 class CProgressNotifier; |
|
46 class CSettingData; |
|
47 class CCustomPrefsData; |
|
48 class CSendTimer; |
|
49 |
|
50 // CLASS DECLARATION |
|
51 |
|
52 /** |
|
53 * CSocketsEngine |
|
54 * |
|
55 * This class is the main engine part of the sockets application. |
|
56 * It establishes a TCP connection using its server name and port |
|
57 * number (performing a DNS lookup operation first, if appropriate). |
|
58 * It creates instances of separate active objects to perform reading |
|
59 * from, and writing to, the socket. |
|
60 */ |
|
61 class CSocketsEngine : public CActive, |
|
62 public MTimeOutNotify, |
|
63 public MProgressNotifyHandler, |
|
64 public MDataSendNotifyHandler, |
|
65 public MMobilityProtocolResp |
|
66 |
|
67 { |
|
68 public: |
|
69 enum TRoamingSetting |
|
70 { |
|
71 ERoamingOff, |
|
72 ERoamingAutomatic, |
|
73 ERoamingManual |
|
74 }; |
|
75 |
|
76 // Utilized when selecting UI menu items |
|
77 enum TRoamingUIState |
|
78 { |
|
79 EIdle, |
|
80 EPendingPreferredCarrier, |
|
81 EPendingNewCarrierActive |
|
82 }; |
|
83 |
|
84 enum TSocketsEngineState |
|
85 { |
|
86 EInterfaceDown, |
|
87 EStartingInterface, |
|
88 EInterfaceUp, |
|
89 EConnecting, |
|
90 EConnected, |
|
91 EListening, |
|
92 ETimedOut, |
|
93 ELookingUp, |
|
94 ELookUpFailed, |
|
95 EConnectFailed, |
|
96 EDisconnecting |
|
97 }; |
|
98 |
|
99 enum TSocketsEngineStartType |
|
100 { |
|
101 EAskIap, |
|
102 EExtPrefs, |
|
103 EExtPrefsInternet, |
|
104 ENoPrefs, |
|
105 ENetworkId, |
|
106 ESnap, |
|
107 ETypeUnknown |
|
108 }; |
|
109 |
|
110 |
|
111 /** |
|
112 * Two-phased constructor. |
|
113 * @param aConsole console to use for ui output |
|
114 * @return a pointer to the created instance of CSocketsEngine |
|
115 */ |
|
116 static CSocketsEngine* NewL(MUINotify& aConsole); |
|
117 |
|
118 /** |
|
119 * Two-phased constructor. |
|
120 * @param aConsole console to use for ui output |
|
121 * @return a pointer to the created instance of CSocketsEngine |
|
122 */ |
|
123 static CSocketsEngine* NewLC(MUINotify& aConsole); |
|
124 |
|
125 /** |
|
126 * Destructor. |
|
127 */ |
|
128 ~CSocketsEngine(); |
|
129 |
|
130 /** |
|
131 * Calls From ConnTestView that are responds to roaming notifications |
|
132 */ |
|
133 void Migrate(); |
|
134 void Ignore(); |
|
135 void AcceptCarrier(); |
|
136 void RejectCarrier(); |
|
137 |
|
138 /** |
|
139 * Register to mobility API |
|
140 */ |
|
141 void RegisterToMobilityAPIL(); |
|
142 |
|
143 /** |
|
144 * UnRegister from mobility API |
|
145 */ |
|
146 void UnRegisterFromMobilityAPI(); |
|
147 |
|
148 /** |
|
149 * Start interface |
|
150 * @param aStartType Define start type (with or without preferences, by nework id) |
|
151 * @param aConnect If True, make connection after startup |
|
152 */ |
|
153 void StartInterfaceL(TSocketsEngineStartType aStartType, TBool aConnect = EFalse); |
|
154 |
|
155 /** |
|
156 * Start interface and possible connection with snap |
|
157 * @param aConnect If True, make connection after startup |
|
158 */ |
|
159 void StartConnWithSnapL(TBool aConnect = EFalse); |
|
160 |
|
161 /** |
|
162 * Starting method for testing RConnection::Close |
|
163 */ |
|
164 void StartCloseInterfaceL(); |
|
165 |
|
166 /** |
|
167 * Stop interface by calling RConnection::Stop |
|
168 */ |
|
169 void StopInterfaceL(); |
|
170 |
|
171 /** |
|
172 * Stop interface by calling RConnection::Close |
|
173 */ |
|
174 void CloseInterface(); |
|
175 |
|
176 /** |
|
177 * Make socket connection |
|
178 */ |
|
179 void ConnectL(); |
|
180 |
|
181 /** |
|
182 * Disconnect socket |
|
183 */ |
|
184 void Disconnect(); |
|
185 |
|
186 /** |
|
187 * Opens a Listening socket |
|
188 */ |
|
189 void ListenL(); |
|
190 |
|
191 /** |
|
192 * Write data to socket |
|
193 * @param aData data to be written |
|
194 */ |
|
195 void WriteL(const TDesC8& aData); |
|
196 |
|
197 /** |
|
198 * Write data to socket (flood) |
|
199 * @param aData data to be written |
|
200 * @param aCount The data will be written aCount times |
|
201 */ |
|
202 void WriteFloodL(const TDesC8& aData, TInt aCount); |
|
203 |
|
204 /** |
|
205 * Write HTTP request over socket |
|
206 * @param aHasBody defines if request has body |
|
207 */ |
|
208 void SendHttpRequestOverSocketL(TBool aHasBody, TBool aDoPerformance); |
|
209 |
|
210 /** |
|
211 * Initiate read of data from socket |
|
212 */ |
|
213 void Read(); |
|
214 |
|
215 /** |
|
216 * Send HTTP request using http framework. |
|
217 * @param aHasBody If true, send body data with POST |
|
218 * @param aDoPerformance If true, calculate performance, no outputs |
|
219 * @param aIsSecure If true, make HTTPS request |
|
220 */ |
|
221 void SendHttpFrameworkRequestL(TBool aHasBody, TBool aDoPerformance, TBool aIsSecure); |
|
222 |
|
223 /** |
|
224 * Print information about active connections and their |
|
225 * clients and sockets |
|
226 */ |
|
227 void ConnectionInfoL(); |
|
228 |
|
229 /** |
|
230 * Print information about interfaces. |
|
231 */ |
|
232 void InterfaceInfoL(); |
|
233 |
|
234 /** |
|
235 * Get socket engine state |
|
236 * @return Socket engine state |
|
237 */ |
|
238 TSocketsEngineState GetSocketEngineState(); |
|
239 |
|
240 /** |
|
241 * Gets Roaming state |
|
242 * @return TRoamingState |
|
243 */ |
|
244 TRoamingUIState GetSocketEngineRoamingState(); |
|
245 |
|
246 /** |
|
247 * Gets MobilityAPIImplementation |
|
248 * @return CALRActiveObject |
|
249 */ |
|
250 CALRActiveObject* CSocketsEngine::GetMobilityAPI(); |
|
251 |
|
252 /** |
|
253 * Get socket engine connection type |
|
254 * @return socket engine connection type |
|
255 */ |
|
256 TSocketsEngineStartType GetSocketEngineConnType(); |
|
257 |
|
258 /** |
|
259 * Set socket engine connection type |
|
260 */ |
|
261 void SetSocketEngineConnType(const CSocketsEngine::TSocketsEngineStartType aConnStartType); |
|
262 |
|
263 /** |
|
264 * Set connection information |
|
265 * @param aData |
|
266 */ |
|
267 void SetConnectionData(const CSettingData* aData); |
|
268 |
|
269 /** |
|
270 * Set Custom preferences data |
|
271 * @param aData |
|
272 */ |
|
273 void SetCustomPrefsData(const CCustomPrefsData* aData); |
|
274 |
|
275 /** |
|
276 * QoS methods |
|
277 */ |
|
278 void SetWLANQoS(TInt aClass); |
|
279 |
|
280 void QoS1(); |
|
281 void QoS2(); |
|
282 |
|
283 /** |
|
284 * Start the sending of the data |
|
285 * @param aData the data to send |
|
286 */ |
|
287 void SendDataL(const TBuf8<KSendDataSize> aData); |
|
288 |
|
289 /** |
|
290 * Actual sending udp packets |
|
291 * Must be public because of the timer calling it |
|
292 */ |
|
293 void DoSendDataL(); |
|
294 |
|
295 public: // MDataSendNotifyHandler |
|
296 /** |
|
297 * The function to be called when data has been sent |
|
298 * @param aAmount the number of packets sent |
|
299 */ |
|
300 void NotifySend(TInt aAmount); |
|
301 |
|
302 public: // from MTimeOutNotify |
|
303 |
|
304 /** |
|
305 * The function to be called when a timeout occurs |
|
306 */ |
|
307 void TimerExpired(); |
|
308 |
|
309 public: // from MProgressNotifyHandler |
|
310 |
|
311 /** |
|
312 * Handle progress notification |
|
313 */ |
|
314 void ProgressNotifyReceivedL(TInt aStage, TInt aError); |
|
315 |
|
316 /** |
|
317 * Handle progress notification error |
|
318 */ |
|
319 void ProgressNotifyError(TInt aStatus); |
|
320 |
|
321 public: // from MMobilityProtocolResp |
|
322 /** |
|
323 * This method is called by middleware to notify that there are no suitable connections available. |
|
324 */ |
|
325 virtual void Error( TInt aError ); |
|
326 |
|
327 /** |
|
328 * This method is called by the middleware to notify a client about a new preferred connection. |
|
329 */ |
|
330 virtual void PreferredCarrierAvailable( |
|
331 TAccessPointInfo aOldAP, |
|
332 TAccessPointInfo aNewAP, |
|
333 TBool aIsUpgrade, |
|
334 TBool aIsSeamless ); |
|
335 /** |
|
336 * This method is called by the middleware to notify a client that a preferred connection has been activated. |
|
337 */ |
|
338 virtual void NewCarrierActive( TAccessPointInfo aNewAP, TBool aIsSeamless ); |
|
339 |
|
340 protected: // from CActive |
|
341 |
|
342 /** |
|
343 * Called when operation completes |
|
344 */ |
|
345 void RunL(); |
|
346 |
|
347 /** |
|
348 * Cancel any outstanding operation |
|
349 */ |
|
350 void DoCancel(); |
|
351 |
|
352 private: // New methods |
|
353 |
|
354 /** |
|
355 * Perform the first phase of two phase construction |
|
356 */ |
|
357 CSocketsEngine(MUINotify& aConsole); |
|
358 |
|
359 /** |
|
360 * Perform the second phase construction of a CSocketsEngine |
|
361 * @param aConsole the console to use for ui output |
|
362 */ |
|
363 void ConstructL(); |
|
364 |
|
365 /** |
|
366 * Initiate a connect operation on a socket |
|
367 * @param aAddr the ip address to connect to |
|
368 */ |
|
369 void ConnectL(const TInetAddr& aAddr); |
|
370 |
|
371 /** |
|
372 * Handle a change in this object's status |
|
373 * @param aNewStatus new status |
|
374 */ |
|
375 void ChangeStatus(TSocketsEngineState aNewStatus); |
|
376 |
|
377 /** |
|
378 * Display text on the console |
|
379 * @param aDes text to display |
|
380 */ |
|
381 void PrintTextToConsole(const TDesC& aDes); |
|
382 |
|
383 public: // for performance testing |
|
384 /** |
|
385 * Marks starting time into memory |
|
386 * |
|
387 */ |
|
388 |
|
389 void UDPFlood(TInt aPackets, TInt aPacketSize, TDesC& aData); |
|
390 /** |
|
391 * Marks starting time into memory |
|
392 */ |
|
393 void inline StartTickCount(); |
|
394 |
|
395 /** |
|
396 * Calculates time interval using tick count and prints it |
|
397 */ |
|
398 void StopTickCount(const TDesC& aComponentName); |
|
399 |
|
400 private: |
|
401 // Member variables |
|
402 TUint32 iStartTime; // for performance testing only |
|
403 TTime iStartTTime; // for performance testing only |
|
404 TTime iThroughputStartTime; // for performance testing only |
|
405 TInt iTroughputDataSize; |
|
406 TCommDbConnPref iPrefs; |
|
407 TConnPrefList* iPrefsList; |
|
408 TExtendedConnPref* iExtPrefs; |
|
409 CCustomPrefsData* iCustomPrefsData; |
|
410 RConnection iConnection; |
|
411 RConnection* iCloseConnection; |
|
412 CProgressNotifier* iProgressNotifier; |
|
413 CProgressNotifier* iTempProgressNotifier; |
|
414 CHttpClient* iHttpClient; |
|
415 TRoamingUIState iRoamingState; |
|
416 TRoamingSetting iRoaming; |
|
417 TSocketsEngineState iEngineStatus; // this object's current status |
|
418 MUINotify& iConsole; // console for displaying text etc |
|
419 CSocketsRead* iSocketsRead; // socket reader active object |
|
420 CSocketsWrite* iSocketsWrite; // socket writer active object |
|
421 RSocket iSocket; // the actual socket |
|
422 RSocket iListeningSocket; |
|
423 RSocketServ iSocketServ; // the socket server |
|
424 RHostResolver iResolver; // DNS name resolver |
|
425 TNameEntry iNameEntry; |
|
426 TNameRecord iNameRecord; |
|
427 CTimeOutTimer* iTimer; // timer active object |
|
428 TInetAddr iAddress; |
|
429 TInt iPort; // port number to connect to |
|
430 TBuf<KMaxServerNameLength> iServerName; // server name to connect to |
|
431 TUint iProtocol; |
|
432 TUint iSocketType; |
|
433 TBool iConnectAfterStartup; |
|
434 TBuf<KMaxServerNameLength> iHttpPage; |
|
435 CSettingData* iSettingData; |
|
436 CSendTimer* iSendTimer; // timer active object |
|
437 HBufC8* iData; // The data to be sent |
|
438 TInt iSendCount; |
|
439 TBool iUseTTime; |
|
440 TBool iIsRegisteredToMobAPI; //flag to mark state of registration to Mob API |
|
441 CALRActiveObject* iMobility; //pointer to mob API instance |
|
442 TSocketsEngineStartType iSockEngineStartType; //type of sock engine connection |
|
443 }; |
|
444 |
|
445 #endif // __SOCKETSENGINE_H__ |
|
446 |