|
1 /* |
|
2 * Copyright (c) 2006-2008 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_CATALOGSHTTPDOWNLOADMANAGER_H |
|
20 #define C_CATALOGSHTTPDOWNLOADMANAGER_H |
|
21 |
|
22 #include <DownloadMgrClient.h> |
|
23 |
|
24 #include "catalogstransportoperationid.h" |
|
25 #include "catalogshttpsession.h" // RCatalogsHttpOperationArray |
|
26 #include "catalogshttpsessionmanager.h" |
|
27 #include "catalogsconnectionmethod.h" |
|
28 #include "catalogsaccesspointobserver.h" |
|
29 |
|
30 class MCatalogsHttpConfig; |
|
31 class CCatalogsHttpConfig; |
|
32 class CCatalogsHttpDownload; |
|
33 class MCatalogsHttpOperation; |
|
34 class MCatalogsHttpObserver; |
|
35 class MCatalogsHttpSessionManager; |
|
36 class MCatalogsHttpTransactionManager; |
|
37 class CCatalogsHttpConnectionManager; |
|
38 class CCatalogsHttpSession; |
|
39 class CCatalogsConnection; |
|
40 class CCatalogsNetworkManager; |
|
41 |
|
42 /** |
|
43 * HTTP file download manager |
|
44 * |
|
45 */ |
|
46 class CCatalogsHttpDownloadManager : |
|
47 public CActive, |
|
48 public MHttpDownloadMgrObserver, |
|
49 public MCatalogsAccessPointObserver |
|
50 { |
|
51 public: // Constructors and destructor |
|
52 |
|
53 /** |
|
54 * Creator |
|
55 * |
|
56 * @param aSessionId Session ID |
|
57 * @return A new download manager |
|
58 */ |
|
59 static CCatalogsHttpDownloadManager* NewL( |
|
60 MCatalogsHttpSessionManager& aManager, |
|
61 CCatalogsHttpSession& aSession, |
|
62 TInt32 aSessionId, |
|
63 MCatalogsHttpTransactionManager& aTransactionManager, |
|
64 CCatalogsHttpConnectionManager& aConnectionManager, |
|
65 TBool aCleanup ); |
|
66 |
|
67 |
|
68 /** |
|
69 * Destructor |
|
70 */ |
|
71 virtual ~CCatalogsHttpDownloadManager(); |
|
72 |
|
73 public: // New methods |
|
74 |
|
75 /** |
|
76 * Creates a new download operation |
|
77 * |
|
78 * @param aUrl URL to download |
|
79 * @param aStart If true, download is started automatically. Otherwise |
|
80 * the caller must start it explicitly. Default: true |
|
81 * @param aObserver Observer for the download. Must be given if the |
|
82 * default observer in the session configuration is NULL. Default: NULL |
|
83 * |
|
84 * @return A new download operation |
|
85 */ |
|
86 MCatalogsHttpOperation* CreateDownloadL( const TDesC16& aUrl, |
|
87 TBool aStart, MCatalogsHttpObserver* aObserver ); |
|
88 |
|
89 MCatalogsHttpOperation* CreateDownloadL( const TDesC8& aUrl, |
|
90 TBool aStart, MCatalogsHttpObserver* aObserver ); |
|
91 |
|
92 /** |
|
93 * Download getter |
|
94 * |
|
95 * Returns the download that matches the id or NULL |
|
96 * |
|
97 * @param aId Download ID |
|
98 * @return Download or NULL |
|
99 */ |
|
100 MCatalogsHttpOperation* Download( |
|
101 const TCatalogsTransportOperationId& aId ) const; |
|
102 |
|
103 |
|
104 /** |
|
105 * Returns a list of current downloads |
|
106 * @return Download list |
|
107 */ |
|
108 const RCatalogsHttpOperationArray& CurrentDownloads() const; |
|
109 |
|
110 |
|
111 /** |
|
112 * Returns an array of downloads restored from the previous session. |
|
113 * |
|
114 * The client should always call this method and either delete the |
|
115 * downloads or restore them after setting the observer for them. |
|
116 * |
|
117 * @return Array of restored downloads |
|
118 */ |
|
119 const RCatalogsHttpOperationArray& RestoredDownloads() const; |
|
120 |
|
121 |
|
122 /** |
|
123 * Cancels all downloads |
|
124 */ |
|
125 void CancelAll(); |
|
126 |
|
127 |
|
128 /** |
|
129 * |
|
130 */ |
|
131 void NotifyCancelAll(); |
|
132 |
|
133 /** |
|
134 * Deletes restored downloads |
|
135 */ |
|
136 void DeleteRestoredDownloads(); |
|
137 |
|
138 /** |
|
139 * Default download configuration getter |
|
140 * |
|
141 * @return Default download configuration |
|
142 */ |
|
143 MCatalogsHttpConfig& DefaultConfig() const; |
|
144 |
|
145 |
|
146 /** |
|
147 * Moves a download from restored downloads to current downloads |
|
148 * |
|
149 * @param aDownload Download to move |
|
150 * @return KErrNone if successful, otherwise a Symbian error code |
|
151 * @note A restored download is moved to current downloads |
|
152 * when it is started but this method can be used to move it there |
|
153 * earlier. |
|
154 */ |
|
155 TInt MoveRestoredDlToCurrentDls( |
|
156 MCatalogsHttpOperation& aDownload ); |
|
157 |
|
158 public: |
|
159 |
|
160 void AddRef(); |
|
161 |
|
162 |
|
163 TInt Release(); |
|
164 |
|
165 void SetConnectionMethodL( |
|
166 const TCatalogsConnectionMethod& aMethod ); |
|
167 |
|
168 |
|
169 void SetConnectionL( |
|
170 CCatalogsConnection& aConnection ); |
|
171 |
|
172 TInt32 SessionId() const; |
|
173 |
|
174 |
|
175 void RemoveDownload( MCatalogsHttpOperation* aDownload ); |
|
176 |
|
177 |
|
178 MCatalogsHttpOperation* CreateDlTransactionL( |
|
179 const TDesC8& aUrl, |
|
180 MCatalogsHttpObserver& aObserver, |
|
181 const CCatalogsHttpConfig& aConfig ); |
|
182 |
|
183 |
|
184 TInt StartOperation( MCatalogsHttpOperation* aOperation ); |
|
185 |
|
186 TInt PauseOperation( MCatalogsHttpOperation* aOperation ); |
|
187 |
|
188 TInt CompleteOperation( MCatalogsHttpOperation* aOperation ); |
|
189 |
|
190 |
|
191 void ReportConnectionStatus( TBool aActive ); |
|
192 |
|
193 TInt OperationPriorityChanged( MCatalogsHttpOperation* aOperation ); |
|
194 |
|
195 |
|
196 CCatalogsHttpConnectionCreator& ConnectionCreatorL(); |
|
197 |
|
198 |
|
199 CCatalogsHttpConnectionManager& ConnectionManager(); |
|
200 |
|
201 CDocumentHandler& DocumentHandler(); |
|
202 |
|
203 TInt NewDownloadId(); |
|
204 |
|
205 RHttpDownload& CreatePlatformDownloadL( const TDesC8& aUrl ); |
|
206 |
|
207 public: // From MHttpDownloadMngrObserver |
|
208 |
|
209 /** |
|
210 * Handles events from Download manager |
|
211 */ |
|
212 virtual void HandleDMgrEventL( RHttpDownload& aDownload, |
|
213 THttpDownloadEvent aEvent ); |
|
214 |
|
215 |
|
216 public: // from MCatalogsAccessPointObserver |
|
217 |
|
218 virtual void HandleAccessPointEventL( |
|
219 const TCatalogsConnectionMethod& aAp, |
|
220 const TCatalogsAccessPointEvent& aEvent ); |
|
221 |
|
222 |
|
223 protected: // CActive |
|
224 |
|
225 virtual void RunL(); |
|
226 virtual void DoCancel(); |
|
227 virtual TInt RunError( TInt aError ); |
|
228 |
|
229 private: // Constructors |
|
230 |
|
231 /** |
|
232 * Constructor |
|
233 */ |
|
234 CCatalogsHttpDownloadManager( |
|
235 MCatalogsHttpSessionManager& aManager, |
|
236 CCatalogsHttpSession& aSession, |
|
237 TInt32 aSessionId, |
|
238 MCatalogsHttpTransactionManager& aTransactionManager, |
|
239 CCatalogsHttpConnectionManager& aConnectionManager ); |
|
240 |
|
241 /** |
|
242 * 2nd phase constructor |
|
243 */ |
|
244 void ConstructL( TBool aCleanup ); |
|
245 |
|
246 |
|
247 private: |
|
248 |
|
249 /** |
|
250 * Restores downloads from previous session |
|
251 */ |
|
252 void RestoreDownloadsL(); |
|
253 |
|
254 |
|
255 /** |
|
256 * Searches for the given download from the given array and returns |
|
257 * an index to it or KErrNotFound. |
|
258 * |
|
259 * @param aArray Array to search from |
|
260 * @param aDownload Download to find |
|
261 * @return Index to the download in iDownloads |
|
262 */ |
|
263 TInt FindInDownloads( |
|
264 const RCatalogsHttpOperationArray& aArray, |
|
265 RHttpDownload* aDownload ) const; |
|
266 |
|
267 |
|
268 /** |
|
269 * Searches for the given download from the given array and returns |
|
270 * an index to it or KErrNotFound. |
|
271 * |
|
272 * @param aArray Array to search from |
|
273 * @param aDownload Download to find |
|
274 * @return Index to the download in iDownloads |
|
275 */ |
|
276 TInt FindInDownloads( |
|
277 const RCatalogsHttpOperationArray& aArray, |
|
278 MCatalogsHttpOperation* aDownload ) const; |
|
279 |
|
280 |
|
281 private: |
|
282 |
|
283 /** |
|
284 * Download events |
|
285 */ |
|
286 class TDownloadEvent |
|
287 { |
|
288 public: |
|
289 RHttpDownload* iDownload; // not owned |
|
290 THttpDownloadEvent iEvent; |
|
291 |
|
292 TDownloadEvent( RHttpDownload& aDownload, |
|
293 THttpDownloadEvent& aEvent ) : |
|
294 iDownload( &aDownload ), iEvent( aEvent ) |
|
295 { |
|
296 } |
|
297 }; |
|
298 |
|
299 |
|
300 /** |
|
301 * Sets this object active if event queue has unhandled events |
|
302 */ |
|
303 void ContinueEventHandling(); |
|
304 |
|
305 /** |
|
306 * Removes events from event queue that belong to the same |
|
307 * RHttpDownload as aEvent |
|
308 */ |
|
309 void RemoveUnhandledEvents( |
|
310 const TDownloadEvent& aEvent ); |
|
311 |
|
312 void RemoveUnhandledProgressEvents( |
|
313 const TDownloadEvent& aEvent ); |
|
314 |
|
315 /** |
|
316 * Deletes downloads that have not been paused by the user |
|
317 */ |
|
318 void DeleteHangingDownloads(); |
|
319 |
|
320 |
|
321 private: |
|
322 |
|
323 MCatalogsHttpSessionManager& iManager; |
|
324 CCatalogsHttpSession& iSession; |
|
325 MCatalogsHttpTransactionManager& iTrManager; |
|
326 CCatalogsHttpConnectionManager& iConnectionManager; |
|
327 CCatalogsNetworkManager* iNetworkManager; // Not owned |
|
328 TInt32 iSessionId; |
|
329 RHttpDownloadMgr iDmgr; |
|
330 |
|
331 // All downloads except those that are in Restored |
|
332 RCatalogsHttpOperationArray iDownloads; |
|
333 RCatalogsHttpOperationArray iRestoredDownloads; |
|
334 |
|
335 CCatalogsHttpConfig* iDefaultConfig; // owned |
|
336 TBool iCancellingAll; |
|
337 |
|
338 TInt iRefCount; |
|
339 |
|
340 RFs iFs; |
|
341 TCatalogsConnectionMethod iCurrentAp; |
|
342 |
|
343 RArray<TDownloadEvent> iEventQueue; |
|
344 TInt iCurrentDlId; // id of the last created download |
|
345 }; |
|
346 |
|
347 #endif // C_CATALOGSHTTPDOWNLOADMANAGER_H |