1 /* |
|
2 * Copyright (c) 2005-2009 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: Queue implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "sconqueue.h" |
|
22 #include "sconpcdconsts.h" |
|
23 #include "debug.h" |
|
24 #include <SWInstDefs.h> // installer errors |
|
25 #include <usif/usiferror.h> |
|
26 |
|
27 // ============================= MEMBER FUNCTIONS =============================== |
|
28 |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CSConTaskQueue::~CSConTaskQueue() |
|
32 // Destructor |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 CSConTaskQueue::~CSConTaskQueue() |
|
36 { |
|
37 TRACE_FUNC; |
|
38 iQueue.ResetAndDestroy(); |
|
39 iQueue.Close(); |
|
40 iTimer.Close(); |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CSConTaskQueue::GetQueueStatus( TInt aTask, TBool aAllTasks, |
|
45 // CSConStatusReply*& aStatus ) |
|
46 // Returns the status of a specified task / all tasks |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 void CSConTaskQueue::GetQueueStatusL( TInt aTask, TBool aAllTasks, |
|
50 CSConStatusReply*& aStatus ) |
|
51 { |
|
52 RArray<TInt> completedTasks; |
|
53 CleanupClosePushL( completedTasks ); |
|
54 if ( aAllTasks ) |
|
55 { |
|
56 //if there are tasks |
|
57 if ( iQueue.Count() > 0 ) |
|
58 { |
|
59 //set iNoTasks as EFalse |
|
60 aStatus->iNoTasks = EFalse; |
|
61 for ( TInt i = 0; i < iQueue.Count(); i++ ) |
|
62 { |
|
63 //Fill reply object |
|
64 CSConTaskReply* taskReply = new (ELeave) CSConTaskReply(); |
|
65 CleanupStack::PushL( taskReply ); |
|
66 taskReply->InitializeL( *iQueue[i] ); |
|
67 User::LeaveIfError( aStatus->iTasks.Append( taskReply ) ); |
|
68 CleanupStack::Pop( taskReply ); |
|
69 TBool complete = iQueue[i]->GetComplete(); |
|
70 |
|
71 //Collect completed task numbers to array for deleting |
|
72 if ( complete ) |
|
73 { |
|
74 completedTasks.Append( iQueue[i]->iTaskId ); |
|
75 } |
|
76 //Otherwise clean all unneccessary data from the reply packet |
|
77 else |
|
78 { |
|
79 taskReply->CleanTaskData(); |
|
80 } |
|
81 } |
|
82 } |
|
83 else |
|
84 { |
|
85 //no task in the queue |
|
86 aStatus->iNoTasks = ETrue; |
|
87 } |
|
88 |
|
89 //Remove completed tasks from queue |
|
90 for ( TInt j = 0; j < completedTasks.Count(); j++ ) |
|
91 { |
|
92 RemoveTask( completedTasks[j] ); |
|
93 } |
|
94 } |
|
95 else if ( aTask > 0 ) |
|
96 { |
|
97 CSConTask* temp = new (ELeave) CSConTask(); |
|
98 temp->iTaskId = aTask; |
|
99 TInt index = iQueue.Find( temp, CSConTaskQueue::Match ); |
|
100 delete temp; |
|
101 |
|
102 TBool complete = EFalse; |
|
103 CSConTaskReply* taskReply(NULL); |
|
104 |
|
105 if ( index != KErrNotFound ) |
|
106 { |
|
107 aStatus->iNoTasks = EFalse; |
|
108 //Fill reply object |
|
109 taskReply = new (ELeave) CSConTaskReply(); |
|
110 CleanupStack::PushL( taskReply ); |
|
111 taskReply->InitializeL( *iQueue[index] ); |
|
112 User::LeaveIfError( aStatus->iTasks.Append( taskReply ) ); |
|
113 CleanupStack::Pop( taskReply ); |
|
114 complete = iQueue[index]->GetComplete(); |
|
115 } |
|
116 else |
|
117 { |
|
118 //no task in the queue |
|
119 aStatus->iNoTasks = ETrue; |
|
120 } |
|
121 |
|
122 //Delete completed tasks from queue |
|
123 if ( complete ) |
|
124 { |
|
125 RemoveTask( aTask ); |
|
126 } |
|
127 //Otherwise clean all unneccessary data from the reply packet |
|
128 else if ( taskReply ) |
|
129 { |
|
130 taskReply->CleanTaskData(); |
|
131 } |
|
132 } |
|
133 else |
|
134 { |
|
135 //no task in the queue |
|
136 aStatus->iNoTasks = ETrue; |
|
137 } |
|
138 CleanupStack::PopAndDestroy( &completedTasks ); // close |
|
139 } |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // CSConTaskQueue::AddNewTask( CSConTask*& aNewTask, TInt aTaskId ) |
|
143 // Adds a new task to queue |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 TInt CSConTaskQueue::AddNewTask( CSConTask*& aNewTask, TInt aTaskId ) |
|
147 { |
|
148 TInt ret( KErrNone ); |
|
149 |
|
150 aNewTask->iTaskId = aTaskId; |
|
151 |
|
152 //Set progress value "task accepted for execution" |
|
153 aNewTask->SetProgressValue( KSConCodeTaskCreated ); |
|
154 aNewTask->SetCompleteValue( EFalse ); |
|
155 |
|
156 if ( iQueue.Count() == 0 ) |
|
157 { |
|
158 StartQueue(); |
|
159 } |
|
160 ret = iQueue.InsertInOrder( aNewTask, CSConTaskQueue::Compare ); |
|
161 return ret; |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // CSConTaskQueue::CompleteTask( TInt aTask, TInt aError ) |
|
166 // Set the task to completed -mode |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 TInt CSConTaskQueue::CompleteTask( TInt aTask, TInt aError ) |
|
170 { |
|
171 LOGGER_WRITE_1( "CSConTaskQueue::CompleteTask aError: %d", aError ); |
|
172 TInt ret(KErrNone); |
|
173 TInt index( KErrNotFound ); |
|
174 |
|
175 CSConTask* temp = new CSConTask(); |
|
176 if (!temp) |
|
177 return KErrNoMemory; |
|
178 |
|
179 temp->iTaskId = aTask; |
|
180 index = iQueue.Find( temp, CSConTaskQueue::Match ); |
|
181 delete temp; |
|
182 |
|
183 if ( index != KErrNotFound ) |
|
184 { |
|
185 TBool complete( ETrue ); |
|
186 TBool notComplete( EFalse ); |
|
187 TInt progress( KSConCodeTaskCompleted ); |
|
188 |
|
189 switch( aError ) |
|
190 { |
|
191 case KErrNone : |
|
192 iQueue[index]->SetCompleteValue( complete ); |
|
193 progress = KSConCodeTaskCompleted; |
|
194 break; |
|
195 case KErrNotFound : |
|
196 iQueue[index]->SetCompleteValue( complete ); |
|
197 progress = KSConCodeNotFound; |
|
198 break; |
|
199 case KErrCompletion : |
|
200 iQueue[index]->SetCompleteValue( notComplete ); |
|
201 progress = KSConCodeTaskPartiallyCompleted; |
|
202 break; |
|
203 |
|
204 // installer specific errors |
|
205 case SwiUI::KSWInstErrUserCancel: |
|
206 LOGGER_WRITE("User cancelled the operation"); |
|
207 iQueue[index]->SetCompleteValue( complete ); |
|
208 progress = KSConCodeInstErrUserCancel; |
|
209 break; |
|
210 case SwiUI::KSWInstErrFileCorrupted: |
|
211 case KErrSifCorruptedPackage: |
|
212 LOGGER_WRITE("File is corrupted"); |
|
213 iQueue[index]->SetCompleteValue( complete ); |
|
214 progress = KSConCodeInstErrFileCorrupted; |
|
215 break; |
|
216 case SwiUI::KSWInstErrInsufficientMemory: |
|
217 case KErrSifNotEnoughSpace: |
|
218 LOGGER_WRITE("Insufficient free memory in the drive to perform the operation"); |
|
219 iQueue[index]->SetCompleteValue( complete ); |
|
220 progress = KSConCodeInstErrInsufficientMemory; |
|
221 break; |
|
222 case SwiUI::KSWInstErrPackageNotSupported: |
|
223 case KErrSifUnsupportedSoftwareType: |
|
224 LOGGER_WRITE("Installation of the package is not supported"); |
|
225 iQueue[index]->SetCompleteValue( complete ); |
|
226 progress = KSConCodeInstErrPackageNotSupported; |
|
227 break; |
|
228 case SwiUI::KSWInstErrSecurityFailure: |
|
229 LOGGER_WRITE("Package cannot be installed due to security error"); |
|
230 iQueue[index]->SetCompleteValue( complete ); |
|
231 progress = KSConCodeInstErrSecurityFailure; |
|
232 break; |
|
233 case SwiUI::KSWInstErrMissingDependency: |
|
234 case KErrSifMissingDependencies: |
|
235 LOGGER_WRITE("Package cannot be installed due to missing dependency"); |
|
236 iQueue[index]->SetCompleteValue( complete ); |
|
237 progress = KSConCodeInstErrMissingDependency; |
|
238 break; |
|
239 case SwiUI::KSWInstErrFileInUse: |
|
240 LOGGER_WRITE("Mandatory file is in use and prevents the operation"); |
|
241 iQueue[index]->SetCompleteValue( complete ); |
|
242 progress = KSConCodeInstErrFileInUse; |
|
243 break; |
|
244 case SwiUI::KSWInstErrGeneralError: |
|
245 case KErrSifUnknown: |
|
246 LOGGER_WRITE("Unknown error"); |
|
247 iQueue[index]->SetCompleteValue( complete ); |
|
248 progress = KSConCodeInstErrGeneralError; |
|
249 break; |
|
250 case SwiUI::KSWInstErrNoRights: |
|
251 LOGGER_WRITE("The package has no rights to perform the operation"); |
|
252 iQueue[index]->SetCompleteValue( complete ); |
|
253 progress = KSConCodeInstErrNoRights; |
|
254 break; |
|
255 case SwiUI::KSWInstErrNetworkFailure: |
|
256 LOGGER_WRITE("Indicates that network failure aborted the operation"); |
|
257 iQueue[index]->SetCompleteValue( complete ); |
|
258 progress = KSConCodeInstErrNetworkFailure; |
|
259 break; |
|
260 case SwiUI::KSWInstErrBusy: |
|
261 LOGGER_WRITE("Installer is busy doing some other operation"); |
|
262 iQueue[index]->SetCompleteValue( complete ); |
|
263 progress = KSConCodeInstErrBusy; |
|
264 break; |
|
265 case SwiUI::KSWInstErrAccessDenied: |
|
266 LOGGER_WRITE("Target location of package is not accessible"); |
|
267 iQueue[index]->SetCompleteValue( complete ); |
|
268 progress = KSConCodeInstErrAccessDenied; |
|
269 break; |
|
270 case SwiUI::KSWInstUpgradeError: |
|
271 LOGGER_WRITE("The package is an invalid upgrade"); |
|
272 iQueue[index]->SetCompleteValue( complete ); |
|
273 progress = KSConCodeInstUpgradeError; |
|
274 break; |
|
275 |
|
276 case KErrSifMissingBasePackage: |
|
277 LOGGER_WRITE("KErrSifMissingBasePackage"); |
|
278 iQueue[index]->SetCompleteValue( complete ); |
|
279 progress = KSConCodeInstErrSifMissingBasePackage; |
|
280 break; |
|
281 case KErrSifOverflow: |
|
282 LOGGER_WRITE("KErrSifOverflow"); |
|
283 iQueue[index]->SetCompleteValue( complete ); |
|
284 progress = KSConCodeInstErrSifOverflow; |
|
285 break; |
|
286 case KErrSifSameVersionAlreadyInstalled: |
|
287 LOGGER_WRITE("KErrSifSameVersionAlreadyInstalled"); |
|
288 iQueue[index]->SetCompleteValue( complete ); |
|
289 progress = KSConCodeInstErrSifSameVersionAlreadyInstalled; |
|
290 break; |
|
291 case KErrSifNewerVersionAlreadyInstalled: |
|
292 LOGGER_WRITE("KErrSifNewerVersionAlreadyInstalled"); |
|
293 iQueue[index]->SetCompleteValue( complete ); |
|
294 progress = KSConCodeInstErrSifNewerVersionAlreadyInstalled; |
|
295 break; |
|
296 case KErrSifAlreadyActivated: |
|
297 LOGGER_WRITE("KErrSifAlreadyActivated"); |
|
298 iQueue[index]->SetCompleteValue( complete ); |
|
299 progress = KSConCodeInstErrSifAlreadyActivated; |
|
300 break; |
|
301 case KErrSifAlreadyDeactivated: |
|
302 LOGGER_WRITE("KErrSifAlreadyDeactivated"); |
|
303 iQueue[index]->SetCompleteValue( complete ); |
|
304 progress = KSConCodeInstErrSifAlreadyDeactivated; |
|
305 break; |
|
306 case KErrSifBadComponentId: |
|
307 LOGGER_WRITE("KErrSifBadComponentId"); |
|
308 iQueue[index]->SetCompleteValue( complete ); |
|
309 progress = KSConCodeInstErrSifBadComponentId; |
|
310 break; |
|
311 case KErrSifBadInstallerConfiguration: |
|
312 LOGGER_WRITE("KErrSifBadInstallerConfiguration"); |
|
313 iQueue[index]->SetCompleteValue( complete ); |
|
314 progress = KSConCodeInstErrSifBadInstallerConfiguration; |
|
315 break; |
|
316 case KErrSifPackageCannotBeInstalledOnThisDevice: |
|
317 LOGGER_WRITE("KErrSifPackageCannotBeInstalledOnThisDevice"); |
|
318 iQueue[index]->SetCompleteValue( complete ); |
|
319 progress = KSConCodeInstErrSifPackageCannotBeInstalledOnThisDevice; |
|
320 break; |
|
321 case KErrSifUnsupportedLanguage: |
|
322 LOGGER_WRITE("KErrSifUnsupportedLanguage"); |
|
323 iQueue[index]->SetCompleteValue( complete ); |
|
324 progress = KSConCodeInstErrSifUnsupportedLanguage; |
|
325 break; |
|
326 case KErrScrWriteOperationInProgress: |
|
327 LOGGER_WRITE("KErrScrWriteOperationInProgress"); |
|
328 iQueue[index]->SetCompleteValue( complete ); |
|
329 progress = KSConCodeInstErrScrWriteOperationInProgress; |
|
330 break; |
|
331 case KErrScrReadOperationInProgress: |
|
332 LOGGER_WRITE("KErrScrReadOperationInProgress"); |
|
333 iQueue[index]->SetCompleteValue( complete ); |
|
334 progress = KSConCodeInstErrScrReadOperationInProgress; |
|
335 break; |
|
336 case KErrScrNoActiveTransaction: |
|
337 LOGGER_WRITE("KErrScrNoActiveTransaction"); |
|
338 iQueue[index]->SetCompleteValue( complete ); |
|
339 progress = KSConCodeInstErrScrNoActiveTransaction; |
|
340 break; |
|
341 case KErrScrUnsupportedLocale: |
|
342 LOGGER_WRITE("KErrScrUnsupportedLocale"); |
|
343 iQueue[index]->SetCompleteValue( complete ); |
|
344 progress = KSConCodeInstErrScrUnsupportedLocale; |
|
345 break; |
|
346 |
|
347 default : |
|
348 iQueue[index]->SetCompleteValue( complete ); |
|
349 if ( aError < KErrNone && aError >= KErrCorruptSurrogateFound ) |
|
350 { |
|
351 // aError is always negative |
|
352 // -> returned errorcode is from KSConCodeFirstSymbianErr...n |
|
353 progress = KSConCodeFirstSymbianErr - aError; |
|
354 } |
|
355 else |
|
356 { |
|
357 progress = KSConCodeConflict; |
|
358 } |
|
359 |
|
360 break; |
|
361 } |
|
362 |
|
363 iQueue[index]->SetProgressValue( progress ); |
|
364 } |
|
365 else |
|
366 { |
|
367 ret = KErrNotFound; |
|
368 } |
|
369 StartQueue(); |
|
370 return ret; |
|
371 } |
|
372 |
|
373 // ----------------------------------------------------------------------------- |
|
374 // CSConTaskQueue::SetTaskProgress( TInt aTask, TInt aProgressValue ) |
|
375 // Set the task progress value |
|
376 // ----------------------------------------------------------------------------- |
|
377 // |
|
378 TInt CSConTaskQueue::SetTaskProgress( TInt aTask, TInt aProgressValue ) |
|
379 { |
|
380 TInt ret( KErrNone ); |
|
381 TInt index( KErrNotFound ); |
|
382 |
|
383 CSConTask* temp = new CSConTask(); |
|
384 if (temp) |
|
385 { |
|
386 temp->iTaskId = aTask; |
|
387 index = iQueue.Find( temp, CSConTaskQueue::Match ); |
|
388 delete temp; |
|
389 |
|
390 if ( index != KErrNotFound ) |
|
391 { |
|
392 iQueue[index]->SetProgressValue( aProgressValue ); |
|
393 } |
|
394 else |
|
395 { |
|
396 ret = KErrNotFound; |
|
397 } |
|
398 } |
|
399 else |
|
400 { |
|
401 ret = KErrNoMemory; |
|
402 } |
|
403 return ret; |
|
404 } |
|
405 |
|
406 // ----------------------------------------------------------------------------- |
|
407 // CSConTaskQueue::GetTask( TInt aTaskId, CSConTask*& aTask ) |
|
408 // Receives a specified task |
|
409 // ----------------------------------------------------------------------------- |
|
410 // |
|
411 TInt CSConTaskQueue::GetTask( TInt aTaskId, CSConTask*& aTask ) |
|
412 { |
|
413 TInt ret( KErrNone ); |
|
414 TInt index; |
|
415 |
|
416 CSConTask* temp = new CSConTask(); |
|
417 if (temp) |
|
418 { |
|
419 temp->iTaskId = aTaskId; |
|
420 index = iQueue.Find( temp, CSConTaskQueue::Match ); |
|
421 delete temp; |
|
422 |
|
423 if ( index != KErrNotFound ) |
|
424 { |
|
425 aTask = iQueue[index]; |
|
426 } |
|
427 else |
|
428 { |
|
429 ret = KErrNotFound; |
|
430 } |
|
431 } |
|
432 else |
|
433 { |
|
434 ret = KErrNoMemory; |
|
435 } |
|
436 return ret; |
|
437 } |
|
438 |
|
439 // ----------------------------------------------------------------------------- |
|
440 // CSConTaskQueue::RemoveTask( TInt aTask ) |
|
441 // Removes a task from the queue |
|
442 // ----------------------------------------------------------------------------- |
|
443 // |
|
444 TInt CSConTaskQueue::RemoveTask( TInt aTask ) |
|
445 { |
|
446 TInt ret(KErrNone); |
|
447 TInt index( KErrNotFound ); |
|
448 |
|
449 CSConTask* temp = new CSConTask(); |
|
450 if (temp) |
|
451 { |
|
452 temp->iTaskId = aTask; |
|
453 index = iQueue.Find( temp, CSConTaskQueue::Match ); |
|
454 delete temp; |
|
455 |
|
456 if ( index != KErrNotFound ) |
|
457 { |
|
458 delete iQueue[index]; |
|
459 iQueue.Remove( index ); |
|
460 iQueue.Compress(); |
|
461 } |
|
462 else |
|
463 { |
|
464 ret = KErrNotFound; |
|
465 } |
|
466 |
|
467 if ( iQueue.Count() == 0 ) |
|
468 { |
|
469 StopQueue(); |
|
470 iQueue.Reset(); |
|
471 } |
|
472 } |
|
473 else |
|
474 { |
|
475 ret = KErrNoMemory; |
|
476 } |
|
477 return ret; |
|
478 } |
|
479 |
|
480 // ----------------------------------------------------------------------------- |
|
481 // CSConTaskQueue::CancelTask( TInt aTask, TBool aAllTasks ) |
|
482 // Cancels a task |
|
483 // ----------------------------------------------------------------------------- |
|
484 // |
|
485 void CSConTaskQueue::CancelTask( TInt aTask, TBool aAllTasks ) |
|
486 { |
|
487 TRACE_FUNC_ENTRY; |
|
488 |
|
489 //Remove the task from the queue |
|
490 if ( aTask > 0 && !aAllTasks ) |
|
491 { |
|
492 RemoveTask( aTask ); |
|
493 } |
|
494 |
|
495 //Remove all tasks from the queue |
|
496 if ( aAllTasks ) |
|
497 { |
|
498 iQueue.ResetAndDestroy(); |
|
499 } |
|
500 |
|
501 TRACE_FUNC_EXIT; |
|
502 } |
|
503 |
|
504 // ----------------------------------------------------------------------------- |
|
505 // CSConTaskQueue::QueueProcessActive() |
|
506 // The status of the process |
|
507 // ----------------------------------------------------------------------------- |
|
508 // |
|
509 TBool CSConTaskQueue::QueueProcessActive() const |
|
510 { |
|
511 return iQueueProcessActive; |
|
512 } |
|
513 |
|
514 // ----------------------------------------------------------------------------- |
|
515 // CSConTaskQueue::ChangeQueueProcessStatus() |
|
516 // Changes the status of the queue process |
|
517 // ----------------------------------------------------------------------------- |
|
518 // |
|
519 void CSConTaskQueue::ChangeQueueProcessStatus() |
|
520 { |
|
521 iQueueProcessActive = !iQueueProcessActive; |
|
522 } |
|
523 |
|
524 // ----------------------------------------------------------------------------- |
|
525 // CSConTaskQueue::Reset() |
|
526 // Resets the queue |
|
527 // ----------------------------------------------------------------------------- |
|
528 // |
|
529 void CSConTaskQueue::Reset() |
|
530 { |
|
531 TRACE_FUNC_ENTRY; |
|
532 iTimer.Cancel(); |
|
533 iQueue.ResetAndDestroy(); |
|
534 TRACE_FUNC_EXIT; |
|
535 } |
|
536 |
|
537 // --------------------------------------------------------- |
|
538 // CSConTaskQueue::Compare( const CSConTask& aFirst, |
|
539 // const CSConTask& aSecond ) |
|
540 // Compares task numbers |
|
541 // --------------------------------------------------------- |
|
542 TInt CSConTaskQueue::Compare( const CSConTask& aFirst, |
|
543 const CSConTask& aSecond ) |
|
544 { |
|
545 if ( aFirst.iTaskId < aSecond.iTaskId ) |
|
546 { |
|
547 return -1; |
|
548 } |
|
549 else if ( aFirst.iTaskId > aSecond.iTaskId ) |
|
550 { |
|
551 return 1; |
|
552 } |
|
553 |
|
554 return 0; |
|
555 } |
|
556 |
|
557 // ----------------------------------------------------------------------------- |
|
558 // CSConTaskQueue::Match( const CSConTask& aFirst, const CSConTask& aSecond ) |
|
559 // Matches the task numbers |
|
560 // ----------------------------------------------------------------------------- |
|
561 // |
|
562 TInt CSConTaskQueue::Match( const CSConTask& aFirst, const CSConTask& aSecond ) |
|
563 { |
|
564 if ( aFirst.iTaskId == aSecond.iTaskId ) |
|
565 { |
|
566 return ETrue; |
|
567 } |
|
568 |
|
569 return EFalse; |
|
570 } |
|
571 // End of file |
|