|
1 /* |
|
2 * Copyright (c) 2007-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: CIAUpdateContentOperationManager |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef IA_UPDATE_CONTENT_OPERATION_MANAGER_H |
|
20 #define IA_UPDATE_CONTENT_OPERATION_MANAGER_H |
|
21 |
|
22 |
|
23 #include <e32base.h> |
|
24 #include <e32cmn.h> |
|
25 |
|
26 #include "iaupdatecontentoperationobserver.h" |
|
27 |
|
28 class CIAUpdateBaseNode; |
|
29 class CIAUpdateNode; |
|
30 class MIAUpdateOperation; |
|
31 class MNcdPurchaseDetails; |
|
32 |
|
33 |
|
34 /** |
|
35 * CIAUpdateContentOperationManager |
|
36 * This will provide base functionality that can handle installing |
|
37 * of hidden dependency nodes when one operation is requested |
|
38 * for one visible node. |
|
39 * |
|
40 * @note Functions of this class trust that node dependencies do not loop. |
|
41 * If dependency loops are set into nodes, then the operations may go |
|
42 * into forever loop. So, when dependency links between nodes are created, |
|
43 * the loops need to be handled already then. |
|
44 */ |
|
45 class CIAUpdateContentOperationManager : public CActive, |
|
46 public MIAUpdateContentOperationObserver |
|
47 { |
|
48 |
|
49 public: |
|
50 |
|
51 /** |
|
52 * This defines the possible types of operations. |
|
53 */ |
|
54 enum TContentOperationType |
|
55 { |
|
56 /** |
|
57 * No content operation is created for this. |
|
58 */ |
|
59 ENoContentOperation, |
|
60 |
|
61 /** |
|
62 * Purchase operation should be created for this. |
|
63 */ |
|
64 EPurchaseOperation, |
|
65 |
|
66 /** |
|
67 * Download operation should be created for this. |
|
68 */ |
|
69 EDownloadOperation, |
|
70 |
|
71 /** |
|
72 * Install operation should be created for this. |
|
73 */ |
|
74 EInstallOperation |
|
75 }; |
|
76 |
|
77 |
|
78 /** |
|
79 * @return CIAUpdateContentOperationManager* Created object. |
|
80 * Ownership is transferred. |
|
81 */ |
|
82 static CIAUpdateContentOperationManager* NewL(); |
|
83 |
|
84 /** |
|
85 * @see CIAUpdateContentOperationManager:: NewL |
|
86 */ |
|
87 static CIAUpdateContentOperationManager* NewLC(); |
|
88 |
|
89 |
|
90 /** |
|
91 * Destructor |
|
92 */ |
|
93 virtual ~CIAUpdateContentOperationManager(); |
|
94 |
|
95 |
|
96 /** |
|
97 * If aError contains some base error value |
|
98 * this function will remove the base value |
|
99 * and returns the actual error code. |
|
100 * |
|
101 * @param aError Error code that needs to be checked. |
|
102 * @return TInt Correct error code. |
|
103 */ |
|
104 static TInt CheckErrorCode( TInt aError ); |
|
105 |
|
106 /** |
|
107 * This function can be used to check the last operation type of the |
|
108 * service pack. |
|
109 * |
|
110 * @param aNodeDetails Purchase history details of a node. |
|
111 * @return TContentOperationType Operation type which describes the last |
|
112 * operation that was done for the node. As a default this is EPurchaseOperation, |
|
113 * but if download or install is tried then result is according to that. |
|
114 * If the given node is not a service pack, then ENoContentOperation |
|
115 * is returned. |
|
116 */ |
|
117 static TContentOperationType ServicePackOperationType( |
|
118 MNcdPurchaseDetails& aNodeDetails ); |
|
119 |
|
120 |
|
121 /** |
|
122 * This function will sort the given array according to node depths. |
|
123 * Then, all leaf nodes will be after their dependants in the |
|
124 * array and root nodes are always in the beginning. This function |
|
125 * can be used, for example, if recursion hierarchy is not what is wanted. |
|
126 * |
|
127 * @param aNodes Node array that will be sorted. |
|
128 */ |
|
129 static void SortNodeArray( RPointerArray< CIAUpdateNode >& aNodes ); |
|
130 |
|
131 |
|
132 /** |
|
133 * Uses HandleDependenciesL to create the node list. |
|
134 * |
|
135 * @param aNode Node whose dependencies are gone through. |
|
136 * @param aNodes Array that will contain all the nodes that are part of |
|
137 * the operation directed for this node. |
|
138 * This means that all the wanted node branches that this node depends on |
|
139 * are included into the array. The given node is set as first in the array. |
|
140 * The tree hierarchy will be created recursive and leaves are towards the end |
|
141 * of the array. |
|
142 * @param aAcceptHiddenDependencyNodes If ETrue, then all the hidden |
|
143 * dependency nodes and their branches are included. If EFalse the hidden |
|
144 * dependency nodes are skipped. |
|
145 * @param aAcceptVisibleDependencyNodes If ETrue, then all the non-hidden |
|
146 * dependency nodes and their branches are included. If EFalse the non-hidden |
|
147 * dependency nodes are skipped. |
|
148 */ |
|
149 static void GetOperationNodesL( const CIAUpdateNode& aNode, |
|
150 RPointerArray< CIAUpdateNode >& aNodes, |
|
151 TBool aAcceptHiddenDependencyNodes, |
|
152 TBool aAcceptDependencyVisibleNodes ); |
|
153 |
|
154 |
|
155 /** |
|
156 * @param aNode The head node of the hierarchy whose total content |
|
157 * size is counted. |
|
158 * @param aIncludeDownloaded ETrue if already downloaded node content |
|
159 * should be included into the total size. Else EFalse. |
|
160 * @param aIncludeInstalled ETrue if already installed node content |
|
161 * should be included into the total size. Else EFalse. |
|
162 * @param aAcceptHiddenDependencyNodes If ETrue, then all the hidden |
|
163 * dependency nodes and their branches are included. If EFalse the hidden |
|
164 * dependency nodes are skipped. |
|
165 * @param aAcceptVisibleDependencyNodes If ETrue, then all the non-hidden |
|
166 * dependency nodes and their branches are included. If EFalse the non-hidden |
|
167 * dependency nodes are skipped. |
|
168 * @return TInt The content size of this node and contents it depends on. |
|
169 */ |
|
170 static TInt TotalContentSizeL( const CIAUpdateNode& aNode, |
|
171 TBool aIncludeDownloaded, |
|
172 TBool aIncludeInstalled, |
|
173 TBool aAcceptHiddenDependencyNodes, |
|
174 TBool aAcceptDependencyVisibleNodes ); |
|
175 |
|
176 |
|
177 /** |
|
178 * Starts the operation. |
|
179 * |
|
180 * @param aObserver This observer will be informed when |
|
181 * operation is completed. |
|
182 * @param aOperationType Type of the operation for node content. |
|
183 * @param aNode The main node that will be inserted to the node list. |
|
184 * Hidden nodes that belong to the dependency tree under this node |
|
185 * are also inserted to the list. |
|
186 * @exception Leaves with KErrInUser if the operation has |
|
187 * already been started and not completed. Leaves with |
|
188 * KErrArgument if the node is set as hidden. In other cases, |
|
189 * leaves with system wide error codes. |
|
190 */ |
|
191 void StartL( MIAUpdateContentOperationObserver& aObserver, |
|
192 const TContentOperationType& aOperationType, |
|
193 CIAUpdateNode& aNode ); |
|
194 |
|
195 |
|
196 /** |
|
197 * @return const TContentOperationType& Operation type of the current or last |
|
198 * operation. This value is set when StartL is called. |
|
199 */ |
|
200 const TContentOperationType& OperationType() const; |
|
201 |
|
202 |
|
203 public: // MIAUpdateContentOperationObserver |
|
204 |
|
205 /** |
|
206 * @see MIAUpdateContentOperationObserver::ContentOperationComplete |
|
207 * |
|
208 * This is called when one of the nodes in the node chain has completed. |
|
209 * This does not mean that the operation as a whole has finished yet. |
|
210 * |
|
211 */ |
|
212 virtual void ContentOperationComplete( CIAUpdateBaseNode& aNode, |
|
213 TInt aError ); |
|
214 |
|
215 /** |
|
216 * @see MIAUpdateContentOperationObserver::ContentOperationProgress |
|
217 */ |
|
218 virtual void ContentOperationProgress( CIAUpdateBaseNode& aNode, |
|
219 TInt aProgress, |
|
220 TInt aMaxProgress ); |
|
221 |
|
222 |
|
223 protected: // CActive |
|
224 |
|
225 /** |
|
226 * @see CActive::DoCancel |
|
227 * |
|
228 * Cancels the operation. |
|
229 */ |
|
230 virtual void DoCancel(); |
|
231 |
|
232 /** |
|
233 * @see CActive::RunL |
|
234 * |
|
235 * Calls HandleContentL for the current node from the node list. |
|
236 * If the previous operation has failed, then other operations |
|
237 * will not be continued. Observer is informed about the completion |
|
238 * of the jobs with error code or KErrNone if operation was successfull |
|
239 * as a whole. |
|
240 */ |
|
241 virtual void RunL(); |
|
242 |
|
243 /** |
|
244 * @see CActive::RunError |
|
245 */ |
|
246 virtual TInt RunError( TInt aError ); |
|
247 |
|
248 |
|
249 private: |
|
250 |
|
251 // Prevent these if not implemented |
|
252 CIAUpdateContentOperationManager( |
|
253 const CIAUpdateContentOperationManager& aObject ); |
|
254 CIAUpdateContentOperationManager& operator =( |
|
255 const CIAUpdateContentOperationManager& aObject ); |
|
256 |
|
257 |
|
258 /** |
|
259 * Constructor |
|
260 */ |
|
261 CIAUpdateContentOperationManager(); |
|
262 |
|
263 /** |
|
264 * 2nd. phase constructor |
|
265 */ |
|
266 void ConstructL(); |
|
267 |
|
268 |
|
269 /** |
|
270 * If a progress value was changed. Then, observer is informed. |
|
271 * |
|
272 * @param aProgress Progress value for current operation. |
|
273 * @param aMaxProgress Progress value for current operation. |
|
274 */ |
|
275 void UpdateProgress( TInt aProgress, TInt aMaxProgress ); |
|
276 |
|
277 // Called when all the nodes have been handled or if error has occurred |
|
278 // during operation chain. |
|
279 void CompleteOperation( TInt aError ); |
|
280 |
|
281 |
|
282 // Resets progress values to their defaults. |
|
283 void ResetProgress(); |
|
284 |
|
285 // Resets only current progress values to their defaults. |
|
286 void ResetCurrentProgress(); |
|
287 |
|
288 |
|
289 // Initialize total maximum progress value to according to |
|
290 // the type of the operation. |
|
291 void InitTotalMaxProgressL( |
|
292 const TContentOperationType& aOperationType ); |
|
293 |
|
294 |
|
295 // This function calculates the whole content size of the nodes |
|
296 // in the array. |
|
297 static TInt ArrayTotalContentSizeL( |
|
298 const RPointerArray< CIAUpdateNode >& aNodes, |
|
299 TBool aIncludeDownloaded, |
|
300 TBool aIncludeInstalled ); |
|
301 |
|
302 |
|
303 // Insert this node and all the hidden dependencies under it |
|
304 // into the member node array. |
|
305 // Also, reset all the variables related to this. |
|
306 void SetNodeArrayL( CIAUpdateNode& aNodes ); |
|
307 |
|
308 |
|
309 /** |
|
310 * Handle node dependencies and correct nodes into the array. |
|
311 * |
|
312 * @param aNode Node that is handled. |
|
313 * @param aNodes Node array that will contain the whole dependency hierarchy. |
|
314 * @param aAcceptHiddenDependencyNodes If ETrue, then all the hidden |
|
315 * dependency nodes and their branches are included. If EFalse the hidden |
|
316 * dependency nodes are skipped. |
|
317 * @param aAcceptVisibleDependencyNodes If ETrue, then all the non-hidden |
|
318 * dependency nodes and their branches are included. If EFalse the non-hidden |
|
319 * dependency nodes are skipped. |
|
320 */ |
|
321 static void HandleDependenciesL( |
|
322 const CIAUpdateNode& aNode, |
|
323 RPointerArray< CIAUpdateNode >& aNodes, |
|
324 TBool aAcceptHiddenDependencyNodes, |
|
325 TBool aAcceptVisibleDependencyNodes ); |
|
326 |
|
327 |
|
328 // Creates the operation the corresponds the given operation type and node. |
|
329 // Ownership of the operation is transferred. |
|
330 MIAUpdateOperation* CreateOperationL( |
|
331 const TContentOperationType& aOperationType, |
|
332 CIAUpdateNode& aNode ); |
|
333 |
|
334 |
|
335 // Updates the purchase history of the node with the given |
|
336 // error code. |
|
337 void UpdatePurchaseHistory( |
|
338 CIAUpdateNode& aNode, TInt aError ) const; |
|
339 |
|
340 |
|
341 // Checks if the node is a service pack. |
|
342 static TBool IsServicePack( const CIAUpdateNode& aNode ); |
|
343 |
|
344 |
|
345 // Set the current node for the operation flow |
|
346 void SetCurrentNodeL(); |
|
347 |
|
348 |
|
349 // Check if the operation has been successfully done for the given node. |
|
350 // If aCheckSelfUpdate is ETrue, then also self updates are checked |
|
351 // when install operation is going on. If aCheckSelfUpdate is EFlase, |
|
352 // then check is always passed for self update installs. This is because |
|
353 // self updates will be installed separately later. So, self updates can |
|
354 // not be checked here in the middle of the install flow. |
|
355 TBool CheckNode( const CIAUpdateNode& aNode, |
|
356 TBool aCheckSelfUpdate ) const; |
|
357 |
|
358 |
|
359 private: // data |
|
360 |
|
361 // All the nodes that will be handled by HandleContentL function |
|
362 // during active loops. Does not own nodes. |
|
363 RPointerArray< CIAUpdateNode > iNodes; |
|
364 |
|
365 // The main node that is given when the operation is requested and started. |
|
366 // Not owned. |
|
367 CIAUpdateNode* iNode; |
|
368 |
|
369 // The node that is currently handled with the operation. |
|
370 // Not owned. |
|
371 CIAUpdateNode* iCurrentNode; |
|
372 |
|
373 // When operation is started, the observer is set. |
|
374 // When operation finishes observer is informed and this variable |
|
375 // is set to NULL. |
|
376 // Not owned. |
|
377 MIAUpdateContentOperationObserver* iObserver; |
|
378 |
|
379 // Operation type informs what kind of operations should be created |
|
380 // for the nodes when flow proceeds. |
|
381 TContentOperationType iOperationType; |
|
382 |
|
383 // Current operation. |
|
384 // Owned. |
|
385 MIAUpdateOperation* iOperation; |
|
386 |
|
387 // Defines total maximum progress value for the operation. |
|
388 TInt iTotalMaxProgress; |
|
389 |
|
390 // Defines total progress value for the operation. |
|
391 TInt iTotalProgress; |
|
392 |
|
393 // Defines current maximum progress value for the operation. |
|
394 TInt iCurrentMaxProgress; |
|
395 |
|
396 // Defines progress value for the current operation. |
|
397 TInt iCurrentProgress; |
|
398 |
|
399 // This variable is used to count how many operations |
|
400 // were successfull in the flow. |
|
401 TInt iSuccessCount; |
|
402 |
|
403 }; |
|
404 |
|
405 #endif // IA_UPDATE_CONTENT_OPERATION_MANAGER_H |
|
406 |