1 /* |
|
2 * ============================================================================== |
|
3 * Name : NestedAO.cpp |
|
4 * Part of : Base Plugin |
|
5 * Description : Implementation of a nested active object used to handle deletion |
|
6 * of large number of messages by breaking them into smaller chunks |
|
7 * Version : |
|
8 * |
|
9 * Copyright (c) 2005 - 2010 Nokia Corporation. |
|
10 * This material, including documentation and any related |
|
11 * computer programs, is protected by copyright controlled by |
|
12 * Nokia Corporation. All rights are reserved. Copying, |
|
13 * including reproducing, storing, adapting or translating, any |
|
14 * or all of this material requires the prior written consent of |
|
15 * Nokia Corporation. This material also contains confidential |
|
16 * information which may not be disclosed to others without the |
|
17 * prior written consent of Nokia Corporation. |
|
18 * ============================================================================== |
|
19 */ |
|
20 // Include Files |
|
21 // |
|
22 |
|
23 |
|
24 #include "NestedAO.h" |
|
25 #include "baseplugindelayedops.h" |
|
26 #include "baseplugindelayedopsprivate.h" |
|
27 |
|
28 //Class CNestedAO |
|
29 |
|
30 // -------------------------------------------------------------------------- |
|
31 // CNestedAO::NewL |
|
32 // ------------ |
|
33 CNestedAO* CNestedAO::NewL( MDeletionHandler& aDeletionHandler ) |
|
34 { |
|
35 CNestedAO* self = new(ELeave) CNestedAO( aDeletionHandler ); |
|
36 CleanupStack::PushL( self ); |
|
37 self->ConstructL(); |
|
38 CleanupStack::Pop( self ); |
|
39 return self; |
|
40 } |
|
41 // -------------------------------------------------------------------------- |
|
42 // CNestedAO::CNestedAO |
|
43 // ------------ |
|
44 CNestedAO::CNestedAO( MDeletionHandler& aDeletionHandler ) |
|
45 : CTimer( EPriorityIdle ), iDeletionHandler( aDeletionHandler ), iRc( KErrNone ) |
|
46 { |
|
47 } |
|
48 // -------------------------------------------------------------------------- |
|
49 // CNestedAO::ConstructL() |
|
50 // ------------ |
|
51 void CNestedAO::ConstructL() |
|
52 { |
|
53 CTimer::ConstructL(); |
|
54 iNestedWait = new( ELeave ) CActiveSchedulerWait(); |
|
55 CActiveScheduler::Add( this ); |
|
56 } |
|
57 // -------------------------------------------------------------------------- |
|
58 // CNestedAO::~CNestedAO |
|
59 // ------------ |
|
60 CNestedAO::~CNestedAO() |
|
61 { |
|
62 Cancel(); |
|
63 delete iNestedWait; |
|
64 } |
|
65 // -------------------------------------------------------------------------- |
|
66 // CNestedAO::DeleteMessagesAsync |
|
67 // Used to delete messages asynchronously |
|
68 // Deleting a small number of messages at a time |
|
69 // ------------ |
|
70 void CNestedAO::DeleteMessagesAsync() |
|
71 { |
|
72 iDeletionIndex = 0; |
|
73 After( KWaitIntervalInMicroSecs ); //to invoke RunL after 100 microseconds |
|
74 iNestedWait->Start(); |
|
75 } |
|
76 // -------------------------------------------------------------------------- |
|
77 // CNestedAO::DoCancel |
|
78 // ------------ |
|
79 void CNestedAO::DoCancel() |
|
80 { |
|
81 iRc = KErrCancel; |
|
82 Stop(); |
|
83 } |
|
84 // -------------------------------------------------------------------------- |
|
85 // CNestedAO::RunL |
|
86 // ------------ |
|
87 void CNestedAO::RunL() |
|
88 { |
|
89 iRc = iStatus.Int(); |
|
90 if ( iStatus.Int() == KErrNone ) |
|
91 { |
|
92 TBool done = iDeletionHandler.DeleteMessagesInChunksL( iDeletionIndex ); |
|
93 if( !done ) |
|
94 { |
|
95 //Increment deletionidex |
|
96 iDeletionIndex+=KSizeOfChunk; |
|
97 After( KWaitIntervalInMicroSecs ); |
|
98 } |
|
99 else |
|
100 { |
|
101 Stop(); |
|
102 } |
|
103 } |
|
104 else |
|
105 { |
|
106 Stop(); |
|
107 } |
|
108 } |
|
109 |
|
110 // -------------------------------------------------------------------------- |
|
111 // CNestedAO::Stop |
|
112 // Stops the scheduler from running |
|
113 // Called after all messages are processed |
|
114 // or in error condition |
|
115 // ------------ |
|
116 void CNestedAO::Stop() |
|
117 { |
|
118 if( iNestedWait->IsStarted() ) |
|
119 { |
|
120 // Stop the nested active scheduler (flow-of-control will pick up immediately following the |
|
121 // call to iWait.Start(). |
|
122 iNestedWait->AsyncStop(); |
|
123 } // end if |
|
124 } |
|