|
1 /* |
|
2 * Copyright (c) 2006 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 the License "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: Implements storage functionality in the DownloadManager |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef CHTTPSTORAGE_H |
|
21 #define CHTTPSTORAGE_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 |
|
26 // CONSTANTS |
|
27 |
|
28 // MACROS |
|
29 //#define ?macro ?macro_def |
|
30 |
|
31 // DATA TYPES |
|
32 //enum ?declaration |
|
33 //typedef ?declaration |
|
34 //extern ?data_type; |
|
35 |
|
36 // FUNCTION PROTOTYPES |
|
37 //?type ?function_name(?arg_list); |
|
38 |
|
39 // FORWARD DECLARATIONS |
|
40 class CHttpDownload; |
|
41 class RFotaEngineSession; |
|
42 class RWriteStream; |
|
43 class CDocumentHandler; |
|
44 class CBuffStorage; |
|
45 |
|
46 |
|
47 // CLASS DECLARATION |
|
48 |
|
49 /** |
|
50 * ?one_line_short_description. |
|
51 * ?other_description_lines |
|
52 * |
|
53 * @lib ?library |
|
54 * @since Series 60 v2.8 |
|
55 */ |
|
56 |
|
57 NONSHARABLE_CLASS( CHttpStorage ) : public CBase |
|
58 { |
|
59 public: // Constructors and destructor |
|
60 |
|
61 enum TStorageMethod |
|
62 { |
|
63 EStoreFile, |
|
64 EStoreFota |
|
65 }; |
|
66 |
|
67 enum TFileCloseOperation |
|
68 { |
|
69 EKeepFile, |
|
70 EDeleteFile, |
|
71 EReplaceFile |
|
72 }; |
|
73 |
|
74 /** |
|
75 * Two-phased constructor. |
|
76 */ |
|
77 static CHttpStorage* NewL( CHttpDownload* aDownload ); |
|
78 |
|
79 /** |
|
80 * Destructor. |
|
81 */ |
|
82 virtual ~CHttpStorage(); |
|
83 |
|
84 public: // New functions |
|
85 |
|
86 /** |
|
87 * Sets storage method. Cannot be set if already storing. |
|
88 * @param aMethod Storage method |
|
89 */ |
|
90 void SetStorageMethod( TStorageMethod aMethod ); |
|
91 |
|
92 /** |
|
93 * Checks if the content file is |
|
94 * @since Series v2.8 Series60 |
|
95 * @return ETrue if content file is valid |
|
96 */ |
|
97 TBool CheckContentFileIntegrityL(); |
|
98 |
|
99 /** |
|
100 * Creates the destination filename from URL |
|
101 * @since Series v2.8 Series60 |
|
102 * @return none. Leaves on error. |
|
103 */ |
|
104 void CreateDestinationFileL(); |
|
105 |
|
106 /** |
|
107 * Closes destination file. Downloaded but not persisted |
|
108 * chunks remains in memory until ResetAndDestroy |
|
109 * @since Series v2.8 Series60 |
|
110 * @return none |
|
111 */ |
|
112 void CloseDestinationFile( TFileCloseOperation aOperation ); |
|
113 |
|
114 /** |
|
115 * Persist received chunk |
|
116 * @since Series 60 v2.8 |
|
117 * @param aBuf new chunk to be added |
|
118 * @return EFalse if content-length had to be updated. |
|
119 */ |
|
120 TBool WriteOutNextBodyDataL( const TDesC8& aBuf ); |
|
121 |
|
122 /** |
|
123 * Called when download is completed. |
|
124 * @since Series 60 v2.8 |
|
125 * @return none |
|
126 */ |
|
127 void OnComplete(); |
|
128 |
|
129 /** |
|
130 * Reinitializes storage. |
|
131 * @since Series 60 v2.8 |
|
132 * @param aOnExit if ETrue content files are not deleted |
|
133 * @return none. |
|
134 */ |
|
135 void ResetAndDestroy(); |
|
136 |
|
137 /** |
|
138 * Adopt file handle from client. |
|
139 */ |
|
140 void AdoptFileHandleL( RFile* aFile ); |
|
141 |
|
142 /** |
|
143 * @return ETrue if the download is progressive |
|
144 */ |
|
145 TBool ProgressiveMode(){ return iProgressiveDownload; }; |
|
146 |
|
147 /** |
|
148 * Set progressive mode download |
|
149 * @param aValue ETrue if progressive mode |
|
150 */ |
|
151 void SetProgressiveMode( TBool aValue ); |
|
152 |
|
153 /** |
|
154 * Updates destination file name |
|
155 * @param aFilename new filename |
|
156 * @param aUserSet filename set by client application |
|
157 * @return none. Leaves on error. |
|
158 */ |
|
159 void UpdateDestinationFilenameL( const TDesC16& aFilename, TBool aUserSet ); |
|
160 |
|
161 /** |
|
162 * Append storage info to buffer |
|
163 * @param aBuf buffer where storage info is to be appended |
|
164 */ |
|
165 void AppendStorageInfoL( TPtr8& aBuf ) const; |
|
166 |
|
167 /** |
|
168 * Loads storage info from file |
|
169 * @param aOutFile open file where storage info is loaded from |
|
170 */ |
|
171 void LoadStorageInfoL( RFile& aInFile ); |
|
172 |
|
173 /** |
|
174 * Returns the destination drive's id. |
|
175 * @since Series v2.8 Series60 |
|
176 * @return id of the destination file's drive |
|
177 */ |
|
178 TUint GetDestinationDriveId(); |
|
179 |
|
180 /** |
|
181 * Updates file extension |
|
182 */ |
|
183 void UpdateExtensionL(); |
|
184 |
|
185 /** |
|
186 * Set size of disk buffer |
|
187 * @param aBufferSize size in bytes |
|
188 */ |
|
189 void SetBufferSizeL( TInt aBufferSize ); |
|
190 |
|
191 /** |
|
192 * Turn on disk buffering |
|
193 */ |
|
194 void EnableBufferingL(); |
|
195 |
|
196 /** |
|
197 * Turn off disk buffering |
|
198 */ |
|
199 void DisableBufferingL(); |
|
200 |
|
201 /** |
|
202 * If buffering enabled, flush data to disk |
|
203 */ |
|
204 void FlushL(); |
|
205 |
|
206 /** |
|
207 *Returns iBufferingEnabled |
|
208 */ |
|
209 inline TBool BufferingEnabled() { return iBufferingEnabled; }; |
|
210 |
|
211 HBufC* LocalFilename()const { return iLocalFilename; }; |
|
212 HBufC* DestFilename()const { return iDestFilename; }; |
|
213 HBufC* DdFileName()const { return iDdFilename; }; |
|
214 TBool DestFNameSet()const { return iDestFNameSet; }; |
|
215 TBool RemovableDest()const { return iRemovableDest; }; |
|
216 TBool ProgressiveDownload()const { return iProgressiveDownload; } |
|
217 TInt32 Length()const { return iLength; }; |
|
218 TInt32 DownloadedSize()const { return iDownloadedSize; }; |
|
219 TInt32 MoDownloadedSize()const{ return iMoDownloadedSize; }; |
|
220 RFile* File(){ return iFile; }; |
|
221 |
|
222 void SetLength( TInt32 aLength ){ iLength = aLength; }; |
|
223 void SetDownloadedSize( TInt32 aSize ){ iDownloadedSize = aSize; iBufferedSize = aSize; }; |
|
224 void SetRemovableDest( TBool aRemovable ){ iRemovableDest = aRemovable; }; |
|
225 void SetLocalFilenameL(const TDesC16& aValue); |
|
226 void SetPartialContentLength( TInt32 aLength ){ iPartialLength = aLength; }; |
|
227 void SetMoDownloadedSize( TInt32 aMoSize ){ iMoDownloadedSize = aMoSize ;}; |
|
228 TBool RFileSetByClient()const { return iRFileSetByClient; }; |
|
229 |
|
230 protected: // New functions |
|
231 |
|
232 /** |
|
233 * Check if there's enough disk space for the content |
|
234 * Returns drive letter where content can be safely stored. |
|
235 * Leaves on error |
|
236 * @since Series v2.8 Series60 |
|
237 * @return Returns drive letter where content can be safely stored. |
|
238 * Leaves on error. |
|
239 */ |
|
240 TInt CheckFreeDiskSpaceL(); |
|
241 |
|
242 /** |
|
243 * Creates the destination content file. |
|
244 * @since Series v2.8 Series60 |
|
245 * @return none. Leaves on error. |
|
246 */ |
|
247 void CreateDestinationFilenameL(); |
|
248 |
|
249 protected: // Functions from base classes |
|
250 |
|
251 private: |
|
252 |
|
253 /** |
|
254 * C++ default constructor. |
|
255 */ |
|
256 CHttpStorage( CHttpDownload* aDownload ); |
|
257 |
|
258 /** |
|
259 * By default Symbian 2nd phase constructor is private. |
|
260 */ |
|
261 void ConstructL(); |
|
262 |
|
263 public: // Data |
|
264 |
|
265 protected: // Data |
|
266 |
|
267 CHttpDownload* iDownload; // Pointer to the download object that owns |
|
268 // this storage class |
|
269 private: // Data |
|
270 |
|
271 CActiveSchedulerWait* iWait; |
|
272 |
|
273 TBool iRFileSetByClient; |
|
274 |
|
275 #ifdef __SYNCML_DM_FOTA |
|
276 RFotaEngineSession* iFotaEngine; |
|
277 RWriteStream* iFotaStream; |
|
278 #endif |
|
279 |
|
280 TBool iProgressiveDownload; // EDlAttrProgressive |
|
281 |
|
282 TBool iRemovableDest; |
|
283 HBufC* iDestFilename; // EDlAttrDestFilename |
|
284 TBool iDestFNameSet; // iDestFilename is set by client app -> |
|
285 // do not delete it in Reset() |
|
286 RFile* iFile; // destination file |
|
287 |
|
288 TInt32 iLength; // EDlAttrLength |
|
289 TInt32 iDownloadedSize; // How much data actually written to finally |
|
290 TInt32 iBufferedSize; // How much data received over the air (but not necessarily all in file yet) |
|
291 TInt32 iMoDownloadedSize; // EDlAttrMultipleMODownloadedSize |
|
292 |
|
293 |
|
294 HBufC* iLocalFilename; // Generated from URL if destination EDlAttrDestFilename |
|
295 // is not specified before start. |
|
296 HBufC* iDdFilename; // Name of DD File. |
|
297 TUint iDriveId; // Unique id of the drive where content is saved. |
|
298 |
|
299 TStorageMethod iStorageMethod; |
|
300 |
|
301 // Reserved pointer for future extension |
|
302 //TAny* iReserved; |
|
303 |
|
304 HBufC8* iWriteBuff; // for buffering download data - owned |
|
305 |
|
306 TBool iBufferingEnabled; |
|
307 |
|
308 TInt iBufferSize; // disk io buffer size - bytes |
|
309 TInt32 iPartialLength; //partial Content Length in case of server Response 206 |
|
310 CBuffStorage *iStorage; |
|
311 HBufC* iTempFilename; // EDlAttrTempFilename |
|
312 |
|
313 public: // Friend classes |
|
314 |
|
315 friend class CBuffStorage; |
|
316 |
|
317 |
|
318 //?friend_class_declaration; |
|
319 protected: // Friend classes |
|
320 //?friend_class_declaration; |
|
321 private: // Friend classes |
|
322 //?friend_class_declaration; |
|
323 |
|
324 }; |
|
325 |
|
326 #endif // CHTTPSTORAGE_H |
|
327 |
|
328 // End of File |