|
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: HTTP client engine, which takes of doing an Http GET request for |
|
15 * the maps server. |
|
16 */ |
|
17 |
|
18 #ifndef __CLIENTENGINE_H__ |
|
19 #define __CLIENTENGINE_H__ |
|
20 |
|
21 #include <http/mhttptransactioncallback.h> |
|
22 #include <http/mhttpauthenticationcallback.h> |
|
23 #include <es_sock.h> |
|
24 #include <cmmanager.h> |
|
25 #include <comms-infras/cs_mobility_apiext.h> |
|
26 #include <etel.h> |
|
27 #include <etelmm.h> |
|
28 |
|
29 #include "reversegeocode.h" |
|
30 |
|
31 class RHTTPSession; |
|
32 class RHTTPTransaction; |
|
33 |
|
34 const TInt KDefaultBufferSize = 256; |
|
35 |
|
36 /* |
|
37 * Enumration for the different states of HTTP GET request. |
|
38 */ |
|
39 enum THttpStatus |
|
40 { |
|
41 EHttpSessionError =0, |
|
42 EHttpExitingApp, |
|
43 EHttpConnecting, |
|
44 EHttpTxCancelled, |
|
45 EHttpHdrReceived, |
|
46 EHttpBytesReceieved, |
|
47 EHttpBodyReceieved, |
|
48 EHttpTxCompleted, |
|
49 EHttpTxSuccess, |
|
50 EHttpTxFailed, |
|
51 EHttpConnectionFailure, |
|
52 EHttpUnknownEvent, |
|
53 EHttpMhfRunError, |
|
54 EHttpAuthNote, |
|
55 EHttpAuthFailed, |
|
56 EHttpAuthRequired, |
|
57 }; |
|
58 |
|
59 enum TMobileRoamingStatus |
|
60 { |
|
61 EMobileNotRegistered = 0x00, |
|
62 EMobileRegHomeNetwork, // home network |
|
63 EMobileNationalRoaming, |
|
64 EMobileInternationalRoaming |
|
65 }; |
|
66 |
|
67 /* |
|
68 * MClientObserver |
|
69 * CClientEngine passes events and responses body data with this interface. |
|
70 * An instance of this class must be provided for construction of CClientEngine. |
|
71 */ |
|
72 class MClientObserver |
|
73 { |
|
74 public: |
|
75 /* |
|
76 * ClientEvent() |
|
77 * |
|
78 * Called when event occurs in CClientEngine. |
|
79 * |
|
80 * @params aEvent Status of the event. |
|
81 */ |
|
82 virtual void ClientEvent( const THttpStatus& aEvent ) = 0; |
|
83 |
|
84 /* |
|
85 * ClientBodyReceived() |
|
86 * |
|
87 * Called when a part of the HTTP body is received. |
|
88 * |
|
89 * @param aBodyData Part of the body data received. (e.g. part of |
|
90 * the received HTML page) |
|
91 */ |
|
92 virtual void ClientBodyReceived( const TDesC8& aBodyData ) = 0; |
|
93 |
|
94 /* |
|
95 * Get registrer network country code |
|
96 * |
|
97 * @return current register n/w info |
|
98 */ |
|
99 virtual RMobilePhone::TMobilePhoneNetworkInfoV2& GetCurrentRegisterNw() = 0; |
|
100 |
|
101 /* |
|
102 * UE is registered to home network? |
|
103 * |
|
104 * @return ETrue if UE is registered at home network else EFalse |
|
105 */ |
|
106 virtual TBool IsRegisteredAtHomeNetwork() = 0; |
|
107 |
|
108 /* |
|
109 * Get home network country code |
|
110 * @param aHomeNwInfoAvailableFlag ETrue if home n/w info available else EFalse |
|
111 * @return user home n/w info |
|
112 */ |
|
113 virtual const RMobilePhone::TMobilePhoneNetworkInfoV1& |
|
114 GetHomeNetworkInfo(TBool& aHomeNwInfoAvailableFlag) = 0; |
|
115 }; |
|
116 |
|
117 |
|
118 /* |
|
119 * Provides simple interface to HTTP Client API. |
|
120 */ |
|
121 NONSHARABLE_CLASS( CClientEngine ): public CActive, |
|
122 public MHTTPTransactionCallback, |
|
123 public MMobilityProtocolResp |
|
124 { |
|
125 |
|
126 //Internal Engine state |
|
127 enum TEngineState |
|
128 { |
|
129 EIdle = 0, |
|
130 EGet |
|
131 }; |
|
132 |
|
133 public: |
|
134 /* |
|
135 * Create a CClientEngine object. |
|
136 * |
|
137 * @params iObserver refernce to the MClientObservers implementation |
|
138 * |
|
139 * @returns A pointer to the created instance of CClientEngine |
|
140 */ |
|
141 static CClientEngine* NewL( MClientObserver& iObserver ); |
|
142 |
|
143 /* |
|
144 * Create a CClientEngine object. This leaves the object on the clean up |
|
145 * stack. |
|
146 * |
|
147 * @params iObserver refernce to the MClientObservers implementation |
|
148 * |
|
149 * @returns A pointer to the created instance of CClientEngine |
|
150 */ |
|
151 static CClientEngine* NewLC( MClientObserver& iObserver ); |
|
152 |
|
153 /* |
|
154 * Destroy the object |
|
155 * |
|
156 */ |
|
157 ~CClientEngine(); |
|
158 |
|
159 /* |
|
160 * Starts a new HTTP GET transaction. |
|
161 * |
|
162 * @param aUri URI to get request. (e.g. http://host.org") |
|
163 */ |
|
164 void IssueHTTPGetL( const TDesC8& aUri, const TConnectionOption aOption ); |
|
165 |
|
166 /* |
|
167 * Closes currently running transaction and frees resources related to it. |
|
168 */ |
|
169 void CancelTransaction(); |
|
170 |
|
171 /* |
|
172 * Closes the connection |
|
173 */ |
|
174 void CloseConnection(); |
|
175 |
|
176 |
|
177 /* |
|
178 * checks if silent connection is allowed |
|
179 * @return ETrue if silent connection is allowed |
|
180 */ |
|
181 TBool SilentConnectionAllowed(); |
|
182 |
|
183 #ifdef REVERSEGEOCODE_UNIT_TESTCASE |
|
184 public: |
|
185 #else |
|
186 private: |
|
187 #endif |
|
188 /* |
|
189 * Perform the second phase construction of a CClientEngine object. |
|
190 */ |
|
191 void ConstructL(); |
|
192 |
|
193 /* |
|
194 * Performs the first phase of two phase construction. |
|
195 * @param iObserver The observer that is notified after the HTTP transcation is over |
|
196 */ |
|
197 CClientEngine( MClientObserver& iObserver ); |
|
198 |
|
199 /* |
|
200 * Sets header value of an HTTP request. |
|
201 * |
|
202 * @param aHeaders Headers of the HTTP request |
|
203 * @param aHdrField Enumerated HTTP header field, e.g. HTTP::EUserAgent |
|
204 * @param aHdrValue New value for header field. |
|
205 */ |
|
206 void SetHeaderL( RHTTPHeaders aHeaders, TInt aHdrField, |
|
207 const TDesC8& aHdrValue ); |
|
208 |
|
209 /* |
|
210 * Sets up the connection |
|
211 * @param aOption The connection option |
|
212 */ |
|
213 void SetupConnectionL( const TConnectionOption aOption ); |
|
214 |
|
215 #ifdef REVERSEGEOCODE_UNIT_TESTCASE |
|
216 public: |
|
217 #else |
|
218 private: |
|
219 #endif |
|
220 //From MHTTPSessionEventCallback |
|
221 /* |
|
222 * Called by framework to notify about transaction events. |
|
223 * |
|
224 * @param aTransaction Transaction, where the event occured. |
|
225 * @param aEvent Occured event. |
|
226 */ |
|
227 void MHFRunL( RHTTPTransaction aTransaction, const THTTPEvent& aEvent ); |
|
228 |
|
229 /* |
|
230 * Called by framework to notify about transaction events. |
|
231 * |
|
232 * @param aTransaction Transaction, where the event occured. |
|
233 * @param aError Error status code. |
|
234 * @param aEvent The event that was being processed when leave occured. |
|
235 * |
|
236 * @retuen KErrNone, if the error was handled. Otherwise the value of aError, or |
|
237 * some other error value. Returning error value causes causes |
|
238 * HTTP-CORE 6 panic. |
|
239 */ |
|
240 TInt MHFRunError( TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent ); |
|
241 |
|
242 |
|
243 #ifdef REVERSEGEOCODE_UNIT_TESTCASE |
|
244 public: |
|
245 #else |
|
246 private: |
|
247 #endif |
|
248 // from MMobilityProtocolResp |
|
249 void PreferredCarrierAvailable( TAccessPointInfo aOldAPInfo, |
|
250 TAccessPointInfo aNewAPInfo, |
|
251 TBool aIsUpgrade, |
|
252 TBool aIsSeamless ); |
|
253 void NewCarrierActive( TAccessPointInfo aNewAPInfo, TBool aIsSeamless ); |
|
254 void Error( TInt aError ); |
|
255 |
|
256 TBool IsDataConnectionAskAlwaysL(); |
|
257 TMobileRoamingStatus UeRegNetworkStatus(); |
|
258 TBool IsVisitorNetwork(const TMobileRoamingStatus& aRoamingStatus) const; |
|
259 TBool IsWlanOnly(const TMobileRoamingStatus& aRoamingStatus, |
|
260 const TCmGenConnSettings& aGenConnSettings) const; |
|
261 |
|
262 #ifdef REVERSEGEOCODE_UNIT_TESTCASE |
|
263 public: |
|
264 #else |
|
265 private: |
|
266 #endif |
|
267 |
|
268 /** |
|
269 * RunL |
|
270 * This method is called on completion of the active object request |
|
271 */ |
|
272 |
|
273 void RunL(); |
|
274 |
|
275 /** |
|
276 * DoCancel |
|
277 * Cancels any outstanding requests |
|
278 */ |
|
279 void DoCancel(); |
|
280 |
|
281 /** |
|
282 * This method is called if the RunL leaves |
|
283 * @param aError The errcode with which it leaves |
|
284 */ |
|
285 TInt RunError(TInt aError); |
|
286 |
|
287 #ifdef REVERSEGEOCODE_UNIT_TESTCASE |
|
288 public: |
|
289 #else |
|
290 private: |
|
291 #endif |
|
292 |
|
293 /** |
|
294 * Submits a HTTP transaction |
|
295 */ |
|
296 void DoHTTPGetL(); |
|
297 |
|
298 #ifdef REVERSEGEOCODE_UNIT_TESTCASE |
|
299 public: |
|
300 #else |
|
301 private: |
|
302 #endif |
|
303 // declare members |
|
304 RSocketServ iSocketServ; |
|
305 RConnection iConnection; |
|
306 TUint32 iSelectedIap; |
|
307 |
|
308 RHTTPSession iSession; |
|
309 RHTTPTransaction iTransaction; |
|
310 |
|
311 MClientObserver& iObserver; // Used for passing body data and events to UI |
|
312 TBool iRunning; // ETrue, if transaction running |
|
313 TBool iConnectionSetupDone; |
|
314 |
|
315 TInt iPrevProfileId; |
|
316 |
|
317 CActiveCommsMobilityApiExt* iMobility; |
|
318 TBool iTransactionOpen; |
|
319 TEngineState iEngineState; |
|
320 HBufC8* iUri; |
|
321 RCmManager iCmManager; |
|
322 |
|
323 }; |
|
324 |
|
325 #endif // __CLIENTENGINE_H__ |
|
326 |
|
327 // End of file |