|
1 /* |
|
2 * Copyright (c) 2005 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: Fota download client |
|
15 * |
|
16 */ |
|
17 #ifndef FOTADLCLIENT_H |
|
18 #define FOTADLCLIENT_H |
|
19 |
|
20 //All UI related headers |
|
21 #include <QWidget> |
|
22 #include <QtGui/QWidget> |
|
23 #include <QtGui> |
|
24 |
|
25 //All download manager related headers |
|
26 #include <dmcommon.h> |
|
27 #include <downloadmanager.h> |
|
28 #include <download.h> |
|
29 |
|
30 //All user includes |
|
31 #include "FotaSrvDebug.h" |
|
32 |
|
33 using namespace WRT; |
|
34 |
|
35 //Forward declarations |
|
36 class DownloadManagerClient; |
|
37 |
|
38 //Enums for mapping download manager operation status |
|
39 enum DLReturns |
|
40 { |
|
41 EOk = 0, ENotOk |
|
42 }; |
|
43 |
|
44 //Enums for type of download mechanism |
|
45 enum TDownloadType |
|
46 { |
|
47 THttpDownload = 0, //HTTP download mechanism |
|
48 TOmaDL10Download, //OMA DL1.0 download mechanism |
|
49 TUnknownType |
|
50 //Unknown download mechanism |
|
51 }; |
|
52 |
|
53 //Enums for client (fota) side errors. This is used to know why client decided to pause/cancel the download. |
|
54 enum TClientErrorType |
|
55 { |
|
56 ErrorNone = 0, //No error |
|
57 |
|
58 //Device side errors |
|
59 UserCancelled = 100,//User cancelled download |
|
60 NeedMoreMemory, //Memory insufficient to start download |
|
61 |
|
62 //Server side errors |
|
63 InvalidContentType = 200 |
|
64 //Content type invalid. ie. either HTTP nor OMA DL1.0 |
|
65 }; |
|
66 |
|
67 /** |
|
68 * This is the download client class. |
|
69 * |
|
70 * @lib fotaserver |
|
71 * @since SF^4 |
|
72 */ |
|
73 class DownloadClient : public QObject |
|
74 { |
|
75 Q_OBJECT |
|
76 |
|
77 public: |
|
78 /** |
|
79 * Constructor. |
|
80 */ |
|
81 DownloadClient(DownloadManagerClient* aObserver); |
|
82 |
|
83 /** |
|
84 * Destructor. |
|
85 */ |
|
86 ~DownloadClient(); |
|
87 |
|
88 /** |
|
89 * Creates a single download with the download manager |
|
90 * |
|
91 * @since SF^4 |
|
92 * @param url - the source which is to be downloaded |
|
93 * @param type - determines the type of download. Either parallel or sequential. |
|
94 * @return One of DLReturns |
|
95 */ |
|
96 TInt CreateDownload(const QString& url, DownloadType type); |
|
97 |
|
98 /** |
|
99 * Sets the required attributes for the single download. |
|
100 * |
|
101 * @since SF^4 |
|
102 * @return One of DLReturns |
|
103 */ |
|
104 TInt SetDownloadAttributes(); |
|
105 |
|
106 /** |
|
107 * Gets the attribute of the single download |
|
108 * |
|
109 * @since SF^4 |
|
110 * @param attr - the attribute of the download for which value is needed. |
|
111 * @return The value of the attribute. Caller should read the value in right format. |
|
112 */ |
|
113 QVariant GetDownloadAttribute(DownloadAttribute attr); |
|
114 |
|
115 /** |
|
116 * Starts the single download. Download should be created and attributes set before this. |
|
117 * |
|
118 * @since SF^4 |
|
119 * @param None |
|
120 * @return One of DLReturns |
|
121 */ |
|
122 TInt Start(); |
|
123 |
|
124 /** |
|
125 * Pauses the single download. |
|
126 * |
|
127 * @since SF^4 |
|
128 * @param Client reason for pausing the download. |
|
129 * @return One of DLReturns |
|
130 */ |
|
131 TInt Pause(TClientErrorType aReason); |
|
132 |
|
133 /** |
|
134 * Resumes the single download. |
|
135 * |
|
136 * @since SF^4 |
|
137 * @param None |
|
138 * @return One of DLReturns |
|
139 */ |
|
140 TInt Resume(); |
|
141 |
|
142 /** |
|
143 * Cancels the single download. |
|
144 * |
|
145 * @since SF^4 |
|
146 * @param Client reason for cancelling the download. |
|
147 * @return One of DLReturns |
|
148 */ |
|
149 TInt Cancel(TClientErrorType aReason); |
|
150 |
|
151 /** |
|
152 * Restarts the single download. This is equivalent to cancel and start on Download. |
|
153 * |
|
154 * @since SF^4 |
|
155 * @param None |
|
156 * @return None |
|
157 */ |
|
158 TInt Restart(); |
|
159 |
|
160 private slots: |
|
161 |
|
162 /** |
|
163 * The slot which receives all the single download events. |
|
164 * |
|
165 * @since SF^4 |
|
166 * @param event - the download event |
|
167 * @return true, if handled here. Otherwise false. |
|
168 */ |
|
169 bool DownloadEventRecieved(DownloadEvent *event); |
|
170 |
|
171 private: |
|
172 /** |
|
173 * Called to update the progress of download to fota server. This fetches the percentage |
|
174 * of download from download manager. |
|
175 * |
|
176 * @since SF^4 |
|
177 * @param None |
|
178 * @return None |
|
179 */ |
|
180 void UpdateDownloadProgress(); |
|
181 |
|
182 /** |
|
183 * Called when download is complete, either successfully or unsuccessfully. |
|
184 * The arguments to this function is read to know the actual status. |
|
185 * |
|
186 * @since SF^4 |
|
187 * @param dlevent - the event of the single download |
|
188 * @param err0 - the last error occured |
|
189 * @return None |
|
190 */ |
|
191 void HandleDownloadComplete(Download::State dlstate, int err0 = 0); |
|
192 |
|
193 /** |
|
194 * Called to handle the post download interrupt operation when client cancels/pauses download. |
|
195 * |
|
196 * @since SF^4 |
|
197 * @param dlstate - the state of the single download |
|
198 * @param err0 - the last error occured |
|
199 * @return None |
|
200 */ |
|
201 void HandleClientInterrupt(Download::State dlstate, int err0); |
|
202 |
|
203 /** |
|
204 * Called to read the OMA DL1.0 download descriptor. This will update the fota server with size and version. |
|
205 * |
|
206 * @since SF^4 |
|
207 * @param None |
|
208 * @return None |
|
209 */ |
|
210 void ReadDescriptorData(); |
|
211 |
|
212 /** |
|
213 * Called to validate the content type of the download as received in header. |
|
214 * |
|
215 * @since SF^4 |
|
216 * @param aContent - the content type as received in the header |
|
217 * @return One of TDownloadType |
|
218 */ |
|
219 TDownloadType CheckContentType(const QString aContent); |
|
220 |
|
221 void SetSubDownloadAttributes(); |
|
222 |
|
223 private: |
|
224 |
|
225 /** |
|
226 * The Fota download manger client. This is not owned |
|
227 */ |
|
228 DownloadManagerClient* iFotaDlMgrClient; |
|
229 |
|
230 /** |
|
231 * The Download object of the single download |
|
232 */ |
|
233 Download *iDownload; |
|
234 |
|
235 /** |
|
236 * Progress of the download. true when download progressing, otherwise false. |
|
237 */ |
|
238 TBool iProgress; |
|
239 |
|
240 /** |
|
241 * The total size of the download (ie. update package). |
|
242 */ |
|
243 int iTotalSize; |
|
244 |
|
245 /** |
|
246 * To tell if space check has happened or not, before the start of the download. |
|
247 */ |
|
248 bool iSpaceChecked; |
|
249 |
|
250 /** |
|
251 * To tell if client has interrupted download or not. The reason will be in iClientError. |
|
252 */ |
|
253 bool iClientinterrupted; |
|
254 |
|
255 /** |
|
256 * Holds the client error that caused the download to cancel or pause. |
|
257 */ |
|
258 TClientErrorType iClientError; |
|
259 |
|
260 /** |
|
261 * The state of the single download. This corresponds to the state received in the download event slot. |
|
262 */ |
|
263 Download::State iDlState; |
|
264 |
|
265 TDownloadType iContentType; |
|
266 |
|
267 }; |
|
268 |
|
269 #endif // FOTADLCLIENT_H |