|
1 /* |
|
2 * Copyright (c) 2010 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: Implementation of a nested active object used to handle deletion |
|
15 * of large number of messages by breaking them into smaller chunks |
|
16 * |
|
17 */ |
|
18 |
|
19 // Include Files |
|
20 // |
|
21 |
|
22 |
|
23 #include "NestedAO.h" |
|
24 #include "baseplugindelayedops.h" |
|
25 #include "baseplugindelayedopsprivate.h" |
|
26 |
|
27 //Class CNestedAO |
|
28 |
|
29 // -------------------------------------------------------------------------- |
|
30 // CNestedAO::NewL |
|
31 // ------------ |
|
32 CNestedAO* CNestedAO::NewL( MDeletionHandler& aDeletionHandler ) |
|
33 { |
|
34 CNestedAO* self = new(ELeave) CNestedAO( aDeletionHandler ); |
|
35 CleanupStack::PushL( self ); |
|
36 self->ConstructL(); |
|
37 CleanupStack::Pop( self ); |
|
38 return self; |
|
39 } |
|
40 // -------------------------------------------------------------------------- |
|
41 // CNestedAO::CNestedAO |
|
42 // ------------ |
|
43 CNestedAO::CNestedAO( MDeletionHandler& aDeletionHandler ) |
|
44 : CTimer( EPriorityIdle ), iDeletionHandler( aDeletionHandler ), iRc( KErrNone ) |
|
45 { |
|
46 } |
|
47 // -------------------------------------------------------------------------- |
|
48 // CNestedAO::ConstructL() |
|
49 // ------------ |
|
50 void CNestedAO::ConstructL() |
|
51 { |
|
52 CTimer::ConstructL(); |
|
53 iNestedWait = new( ELeave ) CActiveSchedulerWait(); |
|
54 CActiveScheduler::Add( this ); |
|
55 } |
|
56 // -------------------------------------------------------------------------- |
|
57 // CNestedAO::~CNestedAO |
|
58 // ------------ |
|
59 CNestedAO::~CNestedAO() |
|
60 { |
|
61 Cancel(); |
|
62 delete iNestedWait; |
|
63 } |
|
64 // -------------------------------------------------------------------------- |
|
65 // CNestedAO::DeleteMessagesAsync |
|
66 // Used to delete messages asynchronously |
|
67 // Deleting a small number of messages at a time |
|
68 // ------------ |
|
69 void CNestedAO::DeleteMessagesAsync() |
|
70 { |
|
71 iDeletionIndex = 0; |
|
72 After( KWaitIntervalInMicroSecs ); //to invoke RunL after 100 microseconds |
|
73 iNestedWait->Start(); |
|
74 } |
|
75 // -------------------------------------------------------------------------- |
|
76 // CNestedAO::DoCancel |
|
77 // ------------ |
|
78 void CNestedAO::DoCancel() |
|
79 { |
|
80 iRc = KErrCancel; |
|
81 Stop(); |
|
82 } |
|
83 // -------------------------------------------------------------------------- |
|
84 // CNestedAO::RunL |
|
85 // ------------ |
|
86 void CNestedAO::RunL() |
|
87 { |
|
88 iRc = iStatus.Int(); |
|
89 if ( iStatus.Int() == KErrNone ) |
|
90 { |
|
91 TBool done = iDeletionHandler.DeleteMessagesInChunksL( iDeletionIndex ); |
|
92 if( !done ) |
|
93 { |
|
94 //Increment deletionidex |
|
95 iDeletionIndex+=KSizeOfChunk; |
|
96 After( KWaitIntervalInMicroSecs ); |
|
97 } |
|
98 else |
|
99 { |
|
100 Stop(); |
|
101 } |
|
102 } |
|
103 else |
|
104 { |
|
105 Stop(); |
|
106 } |
|
107 } |
|
108 |
|
109 // -------------------------------------------------------------------------- |
|
110 // CNestedAO::Stop |
|
111 // Stops the scheduler from running |
|
112 // Called after all messages are processed |
|
113 // or in error condition |
|
114 // ------------ |
|
115 void CNestedAO::Stop() |
|
116 { |
|
117 if( iNestedWait->IsStarted() ) |
|
118 { |
|
119 // Stop the nested active scheduler (flow-of-control will pick up immediately following the |
|
120 // call to iWait.Start(). |
|
121 iNestedWait->AsyncStop(); |
|
122 } // end if |
|
123 } |