|
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: Handles download of a file |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_CHTTPDOWNLOADWORKER_H |
|
20 #define C_CHTTPDOWNLOADWORKER_H |
|
21 |
|
22 |
|
23 // User include files |
|
24 #include "httptransferworker.h" |
|
25 #include "httptransferobserver.h" |
|
26 #include "httptransferbase.h" |
|
27 |
|
28 // forward declarations |
|
29 class MHttpWorkerObserver; |
|
30 |
|
31 /** |
|
32 * This class downloads on single file. |
|
33 * |
|
34 * @lib httptransfer.lib |
|
35 * @since S60 v3.2 |
|
36 */ |
|
37 NONSHARABLE_CLASS ( CHttpDownloadWorker ) : public CHttpTransferWorker, MHttpNotifyTimerObserver |
|
38 { |
|
39 public: |
|
40 |
|
41 /** |
|
42 * Constructor |
|
43 * |
|
44 * @since S60 v3.2 |
|
45 * @param aObserver Transfer observer |
|
46 * @param aIAPId IAP id |
|
47 * @param aBuffersize Size of the buffer |
|
48 * @param aCallback Call back to workerobserver |
|
49 */ |
|
50 static CHttpDownloadWorker* NewL( MHttpTransferObserver& aObserver, |
|
51 TUint aIAPId, |
|
52 TUint aBufferSize, |
|
53 MHttpWorkerObserver& aCallback ); |
|
54 |
|
55 /** |
|
56 * Constructor |
|
57 * |
|
58 * @since S60 v3.2 |
|
59 * @param aObserver Transfer observer |
|
60 * @param aIAPId IAP id |
|
61 * @param aBufferSize Size of the buffer |
|
62 * @param aCallback Call back to workerobserver |
|
63 */ |
|
64 static CHttpDownloadWorker* NewLC( MHttpTransferObserver& aObserver, |
|
65 TUint aIAPId, |
|
66 TUint aBufferSize, |
|
67 MHttpWorkerObserver& aCallback ); |
|
68 |
|
69 /** |
|
70 * Destructor |
|
71 * |
|
72 * @since S60 v3.2 |
|
73 */ |
|
74 virtual ~CHttpDownloadWorker(); |
|
75 |
|
76 // from base class CHttpTransferWorker |
|
77 |
|
78 /** |
|
79 * From base class CHttpTransferWorker |
|
80 * Stops the transfer of the file |
|
81 * |
|
82 * @since S60 v3.2 |
|
83 */ |
|
84 void CancelTransfer(); |
|
85 |
|
86 /** |
|
87 * From base class CHttpTransferWorker |
|
88 * Starts the processing of a file. |
|
89 * Asynchronous. |
|
90 * |
|
91 * @since S60 v3.2 |
|
92 */ |
|
93 virtual void StartProcessL(); |
|
94 |
|
95 /** |
|
96 * From base class CHttpTransferWorker |
|
97 * Called by framework to notify about transaction events. |
|
98 * |
|
99 * @since S60 v3.2 |
|
100 * @param aTransaction Transaction, where the event occured. |
|
101 * @param aEvent Occured event. |
|
102 */ |
|
103 void MHFRunL( RHTTPTransaction aTransaction, |
|
104 const THTTPEvent& aEvent ); |
|
105 |
|
106 /** |
|
107 * From base class CHttpTransferWorker |
|
108 * Called by framework when leave occurs in handling of |
|
109 * transaction event. |
|
110 * |
|
111 * @since S60 v3.2 |
|
112 * @param aError The leave code that occured. |
|
113 * @param aTransaction The transaction that was being processed |
|
114 * @param aEvent The event that was being processed |
|
115 * @return Error code |
|
116 */ |
|
117 TInt MHFRunError( TInt aError, |
|
118 RHTTPTransaction aTransaction, |
|
119 const THTTPEvent& aEvent ); |
|
120 |
|
121 private: |
|
122 |
|
123 /** |
|
124 * Deletes partially downloaded file from file system. |
|
125 * |
|
126 * @since S60 v3.2 |
|
127 */ |
|
128 void DeleteFileL(); |
|
129 |
|
130 /** |
|
131 * Checks disk space |
|
132 * @param aSize to be written to file |
|
133 * @since S60 v3.2 |
|
134 */ |
|
135 void CheckDiskSpaceL(TInt aSize); |
|
136 |
|
137 /** |
|
138 * Writes the last part of body into a file |
|
139 * |
|
140 * @since S60 v3.2 |
|
141 */ |
|
142 void WriteTailIntoFileL(); |
|
143 |
|
144 /** |
|
145 * Handles the HTTP response data |
|
146 * |
|
147 * @since S60 v3.2 |
|
148 * @param aTransaction HTTP transaction |
|
149 */ |
|
150 void HandleResponseDataL( RHTTPTransaction aTransaction ); |
|
151 |
|
152 /** |
|
153 * Sends HTTP GET request |
|
154 * |
|
155 * @since S60 v3.2 |
|
156 */ |
|
157 void HttpGetL(); |
|
158 |
|
159 /** |
|
160 * Performs the actions needed when download is finished |
|
161 * |
|
162 * @since @S60 v3.2 |
|
163 * @param aTransaction HTTP transaction |
|
164 */ |
|
165 void FinishDownload( RHTTPTransaction aTransaction ); |
|
166 |
|
167 /** |
|
168 * Default constructor |
|
169 * |
|
170 * @since S60 v3.2 |
|
171 * @param aIAPId IAP id |
|
172 * @param aBufferSize Size of the buffer |
|
173 * @param aObserver Transfer observer |
|
174 * @param aCallback Call back for workerobserver |
|
175 */ |
|
176 CHttpDownloadWorker( TUint aIAPId, |
|
177 TUint aBufferSize, |
|
178 MHttpTransferObserver& aObserver, |
|
179 MHttpWorkerObserver& aCallback ); |
|
180 |
|
181 /** |
|
182 * Second phase constructor |
|
183 * |
|
184 * @since S60 v3.2 |
|
185 */ |
|
186 void ConstructL(); |
|
187 |
|
188 /** |
|
189 * Terminates the transfer and informs the client through |
|
190 * TransferComplete. |
|
191 * |
|
192 * @since S60 v3.2 |
|
193 * @param aError Error code |
|
194 */ |
|
195 void CompleteAndNotifyL( TInt aError ); |
|
196 |
|
197 /** |
|
198 * Callback function for timer expirations. |
|
199 * @since Series60 5.0 HN |
|
200 * @param aTimer Timer that has expired. |
|
201 **/ |
|
202 void TimerEventL( CHttpNotifyTimer* aTimer ); |
|
203 |
|
204 private: |
|
205 |
|
206 /** |
|
207 * Size of the downloaded file |
|
208 */ |
|
209 TInt iFileSizeFromHeader; |
|
210 |
|
211 /** |
|
212 * Amount of transferred bytes |
|
213 */ |
|
214 TInt iBytesTransferred; |
|
215 |
|
216 /** |
|
217 * Response body |
|
218 * Own. |
|
219 */ |
|
220 HBufC8* iResponseBody; |
|
221 |
|
222 /** |
|
223 * Timeout timer for current session |
|
224 */ |
|
225 CHttpNotifyTimer* iSessionTimer; |
|
226 |
|
227 }; |
|
228 |
|
229 #endif // C_CHTTPDOWNLOADWORKER_H |