|
1 /* |
|
2 * Copyright (c) 2002-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: Implementations of methods of CMdSGarbageCollector class* |
|
15 */ |
|
16 |
|
17 #include "mdsgarbagecollector.h" |
|
18 |
|
19 #include <e32svr.h> // RDebug |
|
20 |
|
21 CMdSGarbageCollector::CMdSGarbageCollector(MMdSGarbageCollectorObserver& aObserver) |
|
22 : CActive( CActive::EPriorityLow ), iDelay(0), iNewDelay(0), iObserver( aObserver ) |
|
23 { |
|
24 CActiveScheduler::Add( this ); |
|
25 } |
|
26 |
|
27 CMdSGarbageCollector::~CMdSGarbageCollector() |
|
28 { |
|
29 Cancel(); |
|
30 iTimer.Close(); |
|
31 } |
|
32 |
|
33 void CMdSGarbageCollector::ConstructL() |
|
34 { |
|
35 User::LeaveIfError( iTimer.CreateLocal() ); |
|
36 } |
|
37 |
|
38 CMdSGarbageCollector* CMdSGarbageCollector::NewL(MMdSGarbageCollectorObserver& aObserver) |
|
39 { |
|
40 CMdSGarbageCollector* self = CMdSGarbageCollector::NewLC(aObserver); |
|
41 CleanupStack::Pop( self ); |
|
42 return self; |
|
43 } |
|
44 |
|
45 CMdSGarbageCollector* CMdSGarbageCollector::NewLC(MMdSGarbageCollectorObserver& aObserver) |
|
46 { |
|
47 CMdSGarbageCollector* self = new ( ELeave ) CMdSGarbageCollector(aObserver); |
|
48 CleanupStack::PushL( self ); |
|
49 self->ConstructL(); |
|
50 return self; |
|
51 } |
|
52 |
|
53 void CMdSGarbageCollector::Start( TInt aDelay ) |
|
54 { |
|
55 #ifdef _DEBUG |
|
56 RDebug::Print( _L("CMdSGarbageCollector::Start - delay: %d"), aDelay ); |
|
57 #endif |
|
58 if ( aDelay < 0 ) |
|
59 { |
|
60 return; |
|
61 } |
|
62 |
|
63 const TInt KSecondsToMicroseconds = 1000000; |
|
64 const TInt KMaxInterval = KMaxTInt / KSecondsToMicroseconds; |
|
65 |
|
66 if( IsActive() ) |
|
67 { |
|
68 if ( iNewDelay.Int() == 0 ) |
|
69 { |
|
70 // check if interval is less or equal to 2147 seconds (35 minutes and 47 seconds) |
|
71 if( aDelay <= KMaxInterval ) |
|
72 iNewDelay = aDelay * KSecondsToMicroseconds; |
|
73 else |
|
74 iNewDelay = KMaxTInt; |
|
75 } |
|
76 return; |
|
77 } |
|
78 |
|
79 #ifdef _DEBUG |
|
80 RDebug::Print( _L("CMdSGarbageCollector::Start(%d)"), aDelay ); // test |
|
81 #endif |
|
82 |
|
83 // check if interval is less or equal to 2147 seconds (35 minutes and 47 seconds) |
|
84 if( aDelay <= KMaxInterval ) |
|
85 iDelay = aDelay * KSecondsToMicroseconds; |
|
86 else |
|
87 iDelay = KMaxTInt; |
|
88 |
|
89 iTimer.After( iStatus, iDelay ); // start timer |
|
90 |
|
91 SetActive(); |
|
92 } |
|
93 |
|
94 void CMdSGarbageCollector::RunL() |
|
95 { |
|
96 if( iStatus == KErrNone ) |
|
97 { |
|
98 const TBool startAgain = iObserver.StartGarbageCollectionL(); |
|
99 |
|
100 if ( startAgain ) |
|
101 { |
|
102 iTimer.After( iStatus, iDelay ); // start timer |
|
103 SetActive(); |
|
104 } |
|
105 else if ( iNewDelay.Int() > 0 ) |
|
106 { |
|
107 iDelay = iNewDelay; |
|
108 iNewDelay = 0; |
|
109 iTimer.After( iStatus, iDelay ); // start timer |
|
110 SetActive(); |
|
111 } |
|
112 } |
|
113 } |
|
114 |
|
115 void CMdSGarbageCollector::DoCancel() |
|
116 { |
|
117 #ifdef _DEBUG |
|
118 RDebug::Print( _L("CMdSGarbageCollector::DoCancel") ); |
|
119 #endif |
|
120 iTimer.Cancel(); |
|
121 } |
|
122 |
|
123 #ifdef _DEBUG |
|
124 TInt CMdSGarbageCollector::RunError( TInt aError ) |
|
125 { |
|
126 #else |
|
127 TInt CMdSGarbageCollector::RunError( TInt /*aError*/ ) |
|
128 { |
|
129 #endif |
|
130 #ifdef _DEBUG |
|
131 RDebug::Print( _L("CMdSGarbageCollector::RunError %d"), aError ); |
|
132 #endif |
|
133 return KErrNone; |
|
134 } |
|
135 |
|
136 void CMdSGarbageCollector::Pause() |
|
137 { |
|
138 #ifdef _DEBUG |
|
139 RDebug::Print( _L("CMdSGarbageCollector::Pause") ); |
|
140 #endif |
|
141 DoCancel(); |
|
142 } |
|
143 |
|
144 void CMdSGarbageCollector::Resume() |
|
145 { |
|
146 #ifdef _DEBUG |
|
147 RDebug::Print( _L("CMdSGarbageCollector::Resume") ); |
|
148 #endif |
|
149 |
|
150 if( !IsActive() ) |
|
151 { |
|
152 if ( iDelay.Int() > 0 ) |
|
153 { |
|
154 iTimer.After( iStatus, iDelay ); // start timer |
|
155 SetActive(); |
|
156 } |
|
157 } |
|
158 } |