|
1 /** @file |
|
2 * Copyright (c) 2007 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: Base class for download / upload worker classes |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // System include files |
|
20 #include <commdbconnpref.h> |
|
21 #include <es_sock.h> |
|
22 #include <stringpool.h> |
|
23 #include <f32file.h> |
|
24 |
|
25 // User include files |
|
26 #include "httptransferworker.h" |
|
27 #include "httptransfertimer.h" |
|
28 |
|
29 // Constants |
|
30 const TUint K30Sec = 30; |
|
31 |
|
32 // ======== MEMBER FUNCTIONS ======== |
|
33 |
|
34 // -------------------------------------------------------------------------- |
|
35 // CHttpTransferWorker::ConstructL() |
|
36 // (See comments in header file) |
|
37 // -------------------------------------------------------------------------- |
|
38 // |
|
39 void CHttpTransferWorker::ConstructL() |
|
40 { |
|
41 // Open HTTP session |
|
42 iSession.OpenL(); |
|
43 |
|
44 // Store the string pool for this HTTP session |
|
45 iStringPool = iSession.StringPool(); |
|
46 |
|
47 // Connect to file server |
|
48 User::LeaveIfError( iFsSession.Connect() ); |
|
49 } |
|
50 |
|
51 // -------------------------------------------------------------------------- |
|
52 // CHttpTransferWorker::~CHttpTransferBase() |
|
53 // (See comments in header file) |
|
54 // -------------------------------------------------------------------------- |
|
55 // |
|
56 CHttpTransferWorker::~CHttpTransferWorker() |
|
57 { |
|
58 |
|
59 if ( iProcessState != EHttpTransactionIdle ) |
|
60 { |
|
61 iHttpTransaction.Close(); |
|
62 iFile.Close(); |
|
63 } |
|
64 |
|
65 // Close HTTP session |
|
66 if( &iSession ) |
|
67 { |
|
68 iSession.Close(); |
|
69 } |
|
70 |
|
71 // Closes the connection |
|
72 delete iConnectionManagerProxy; |
|
73 |
|
74 // Close file server session |
|
75 iFsSession.Close(); |
|
76 |
|
77 // Close connection to the socket server |
|
78 iSocketServer.Close(); |
|
79 |
|
80 |
|
81 delete iProcessedFile; |
|
82 iProcessedFile = NULL; |
|
83 |
|
84 delete iTimer; |
|
85 } |
|
86 |
|
87 // -------------------------------------------------------------------------- |
|
88 // CHttpTransferWorker::ConnectL() |
|
89 // (See comments in header file) |
|
90 // -------------------------------------------------------------------------- |
|
91 // |
|
92 void CHttpTransferWorker::ConnectL() |
|
93 { |
|
94 User::LeaveIfError( iSocketServer.Connect() ); |
|
95 |
|
96 iConnectionManagerProxy = CUpnpConnectionManagerProxy::NewL( iSocketServer ); |
|
97 User::LeaveIfError( iConnectionManagerProxy->EnsureStart() ); |
|
98 |
|
99 RHTTPConnectionInfo connInfo = iSession.ConnectionInfo(); |
|
100 |
|
101 //Attach to socket server |
|
102 connInfo.SetPropertyL( iStringPool.StringF(HTTP::EHttpSocketServ, |
|
103 RHTTPSession::GetTable() ), |
|
104 THTTPHdrVal(iSocketServer.Handle() ) ); |
|
105 |
|
106 //Attach to connection |
|
107 TInt connPtr = reinterpret_cast<TInt>( &iConnectionManagerProxy->ConnectionL() ); |
|
108 connInfo.SetPropertyL( iStringPool.StringF( |
|
109 HTTP::EHttpSocketConnection, |
|
110 RHTTPSession::GetTable() ), |
|
111 THTTPHdrVal(connPtr) ); |
|
112 } |
|
113 |
|
114 // -------------------------------------------------------------------------- |
|
115 // CHttpTransferWorker::SetFile() |
|
116 // (See comments in header file) |
|
117 // -------------------------------------------------------------------------- |
|
118 // |
|
119 void CHttpTransferWorker::SetFileL( CHttpFile& aFile ) |
|
120 { |
|
121 // if iProcessedFile is not deleted yet for some reason |
|
122 // --> delete it |
|
123 delete iProcessedFile; |
|
124 |
|
125 iProcessedFile = &aFile; |
|
126 |
|
127 iProcessState = EHttpWaitingForStart; |
|
128 |
|
129 // Create and start the timer |
|
130 delete iTimer; |
|
131 iTimer = NULL; |
|
132 iTimer = CHttpTransferTimer::NewL( K30Sec, this ); |
|
133 } |
|
134 |
|
135 // -------------------------------------------------------------------------- |
|
136 // CHttpTransferWorker::StartProcessL() |
|
137 // (See comments in header file) |
|
138 // -------------------------------------------------------------------------- |
|
139 // |
|
140 void CHttpTransferWorker::StartProcessL() |
|
141 { |
|
142 delete iTimer; |
|
143 iTimer = NULL; |
|
144 } |
|
145 |
|
146 |
|
147 // -------------------------------------------------------------------------- |
|
148 // CHttpTransferWorker::TrackProgress() |
|
149 // (See comments in header file) |
|
150 // -------------------------------------------------------------------------- |
|
151 // |
|
152 void CHttpTransferWorker::TrackProgress( TBool aValue ) |
|
153 { |
|
154 if ( iProcessedFile ) |
|
155 { |
|
156 iProcessedFile->TrackProgress( aValue ); |
|
157 } |
|
158 } |
|
159 |
|
160 // -------------------------------------------------------------------------- |
|
161 // CHttpTransferWorker::Key() |
|
162 // (See comments in header file) |
|
163 // -------------------------------------------------------------------------- |
|
164 // |
|
165 TAny* CHttpTransferWorker::Key() const |
|
166 { |
|
167 TAny* retval = NULL; |
|
168 |
|
169 if ( iProcessedFile ) |
|
170 { |
|
171 retval = iProcessedFile->Key(); |
|
172 } |
|
173 |
|
174 return retval; |
|
175 } |
|
176 |
|
177 // -------------------------------------------------------------------------- |
|
178 // CHttpTransferWorker::Uri() |
|
179 // (See comments in header file) |
|
180 // -------------------------------------------------------------------------- |
|
181 // |
|
182 const HBufC8* CHttpTransferWorker::Uri() const |
|
183 { |
|
184 const HBufC8* retval = NULL; |
|
185 |
|
186 if ( iProcessedFile ) |
|
187 { |
|
188 retval = iProcessedFile->Uri(); |
|
189 } |
|
190 |
|
191 return retval; |
|
192 } |
|
193 |
|
194 // -------------------------------------------------------------------------- |
|
195 // CHttpTransferWorker::Path() |
|
196 // (See comments in header file) |
|
197 // -------------------------------------------------------------------------- |
|
198 // |
|
199 const HBufC* CHttpTransferWorker::Path() const |
|
200 { |
|
201 const HBufC* retval = NULL; |
|
202 |
|
203 if ( iProcessedFile ) |
|
204 { |
|
205 retval = iProcessedFile->Path(); |
|
206 } |
|
207 |
|
208 return retval; |
|
209 } |
|
210 |
|
211 // -------------------------------------------------------------------------- |
|
212 // CHttpTransferWorker::ProcessOnGoing() |
|
213 // (See comments in header file) |
|
214 // -------------------------------------------------------------------------- |
|
215 // |
|
216 TBool CHttpTransferWorker::ProcessOnGoing() const |
|
217 { |
|
218 TBool retval = EFalse; |
|
219 |
|
220 if ( iProcessState != EHttpTransactionIdle ) |
|
221 { |
|
222 retval = ETrue; |
|
223 } |
|
224 |
|
225 return retval; |
|
226 } |
|
227 |
|
228 // -------------------------------------------------------------------------- |
|
229 // CHttpDownloadWorker::IsWaiting() |
|
230 // (See comments in header file) |
|
231 // -------------------------------------------------------------------------- |
|
232 // |
|
233 TBool CHttpTransferWorker::IsWaiting() const |
|
234 { |
|
235 TBool retval = EFalse; |
|
236 |
|
237 // if its not waiting for start -> true |
|
238 if ( iProcessState == EHttpWaitingForStart ) |
|
239 { |
|
240 retval = ETrue; |
|
241 } |
|
242 |
|
243 return retval; |
|
244 } |
|
245 |
|
246 // -------------------------------------------------------------------------- |
|
247 // CHttpDownloadWorker::SetHeaderL() |
|
248 // (See comments in header file) |
|
249 // -------------------------------------------------------------------------- |
|
250 // |
|
251 void CHttpTransferWorker::SetHeaderL( RHTTPHeaders aHeaders, |
|
252 TInt aHdrField, |
|
253 const TDesC8& aHdrValue ) |
|
254 { |
|
255 RStringF valStr = iStringPool.OpenFStringL( aHdrValue ); |
|
256 CleanupClosePushL( valStr ); |
|
257 THTTPHdrVal val( valStr ); |
|
258 aHeaders.SetFieldL( iStringPool.StringF( aHdrField, |
|
259 RHTTPSession::GetTable() ), val ); |
|
260 CleanupStack::PopAndDestroy( &valStr ); |
|
261 } |
|
262 |
|
263 // -------------------------------------------------------------------------- |
|
264 // CHttpDownloadWorker::SetHeaderL() |
|
265 // (See comments in header file) |
|
266 // -------------------------------------------------------------------------- |
|
267 // |
|
268 void CHttpTransferWorker::SetHeaderL( RHTTPHeaders aHeaders, |
|
269 const TDesC8& aHdrField, |
|
270 const TDesC8& aHdrValue ) |
|
271 { |
|
272 RStringF valStr = iStringPool.OpenFStringL( aHdrValue ); |
|
273 CleanupClosePushL( valStr ); |
|
274 RStringF fieldStr = iStringPool.OpenFStringL( aHdrField ); |
|
275 CleanupClosePushL( fieldStr ); |
|
276 THTTPHdrVal val( valStr ); |
|
277 aHeaders.SetFieldL( fieldStr, val ); |
|
278 CleanupStack::PopAndDestroy( &fieldStr ); |
|
279 CleanupStack::PopAndDestroy( &valStr ); |
|
280 } |
|
281 |
|
282 // -------------------------------------------------------------------------- |
|
283 // CHttpDownloadWorker::ProcessedFile() |
|
284 // (See comments in header file) |
|
285 // -------------------------------------------------------------------------- |
|
286 // |
|
287 CHttpFile* CHttpTransferWorker::ProcessedFile() |
|
288 { |
|
289 return iProcessedFile; |
|
290 } |
|
291 |
|
292 |
|
293 // From base class MHttpTransferTimerObserver |
|
294 |
|
295 // -------------------------------------------------------------------------- |
|
296 // CHttpTransferBase::TimerCallback() |
|
297 // (See comments in header file) |
|
298 // -------------------------------------------------------------------------- |
|
299 // |
|
300 void CHttpTransferWorker::TimerCallback() |
|
301 { |
|
302 // if this method is called the waiting time has exceeded the time limit |
|
303 CancelTransfer(); |
|
304 delete iTimer; |
|
305 iTimer = NULL; |
|
306 } |
|
307 |
|
308 // end of file |