|
1 /* |
|
2 * Copyright (c) 2005 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 for meeting request utils graveyard cleaner |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // ---------------------------------------------------------------------------- |
|
21 // INCLUDE FILES |
|
22 // ---------------------------------------------------------------------------- |
|
23 // |
|
24 #include "CMRUtilsGraveyardCleaner.h" |
|
25 #include "CMRUtilsCalDbBase.h" |
|
26 #include <ct/RCPointerArray.h> |
|
27 #include <CalIterator.h> |
|
28 #include <CalEntryView.h> |
|
29 |
|
30 // CONSTANTS |
|
31 /// Unnamed namespace for local definitions |
|
32 namespace { |
|
33 |
|
34 enum TPanicCode |
|
35 { |
|
36 EUnexpectedState = 1, |
|
37 ENullUid |
|
38 }; |
|
39 |
|
40 _LIT( KPanicMsg, "CMRUtilsGraveyardCleaner" ); |
|
41 |
|
42 void Panic( TPanicCode aReason ) |
|
43 { |
|
44 User::Panic( KPanicMsg, aReason ); |
|
45 } |
|
46 |
|
47 } // namespace |
|
48 |
|
49 // ---------------------------------------------------------------------------- |
|
50 // MEMBER FUNCTIONS |
|
51 // ---------------------------------------------------------------------------- |
|
52 // |
|
53 |
|
54 // ---------------------------------------------------------------------------- |
|
55 // CMRUtilsGraveyardCleaner::NewL |
|
56 // ---------------------------------------------------------------------------- |
|
57 // |
|
58 CMRUtilsGraveyardCleaner* CMRUtilsGraveyardCleaner::NewL( |
|
59 const CMRUtilsCalDbBase& aNormalDb, |
|
60 CMRUtilsCalDbBase& aTombsDb ) |
|
61 { |
|
62 CMRUtilsGraveyardCleaner* self = |
|
63 new( ELeave ) CMRUtilsGraveyardCleaner( aNormalDb, aTombsDb ); |
|
64 CleanupStack::PushL( self ); |
|
65 self->ConstructL(); |
|
66 CleanupStack::Pop(); |
|
67 return self; |
|
68 } |
|
69 |
|
70 // ---------------------------------------------------------------------------- |
|
71 // CMRUtilsGraveyardCleaner::CMRUtilsGraveyardCleaner |
|
72 // |
|
73 // Constructor. |
|
74 // ---------------------------------------------------------------------------- |
|
75 // |
|
76 CMRUtilsGraveyardCleaner::CMRUtilsGraveyardCleaner( |
|
77 const CMRUtilsCalDbBase& aNormalDb, |
|
78 CMRUtilsCalDbBase& aTombsDb ) |
|
79 : iNormalDb( aNormalDb), |
|
80 iTombsDb( aTombsDb ), |
|
81 iState( ENotActive ) |
|
82 { |
|
83 } |
|
84 |
|
85 // ---------------------------------------------------------------------------- |
|
86 // CMRUtilsGraveyardCleaner::~CMRUtilsGraveyardCleaner |
|
87 // |
|
88 // Destructor. |
|
89 // ---------------------------------------------------------------------------- |
|
90 // |
|
91 CMRUtilsGraveyardCleaner::~CMRUtilsGraveyardCleaner() |
|
92 { |
|
93 delete iIdleCleaner; // also cancels ongoing cleanup |
|
94 delete iTombsEntryIterator; |
|
95 } |
|
96 |
|
97 // ---------------------------------------------------------------------------- |
|
98 // CMRUtilsGraveyardCleaner::ConstructL |
|
99 // ---------------------------------------------------------------------------- |
|
100 // |
|
101 void CMRUtilsGraveyardCleaner::ConstructL() |
|
102 { |
|
103 iIdleCleaner = CIdle::NewL( CActive::EPriorityIdle ); |
|
104 // It is certain that at this point iTombsDb returns valid session pointer |
|
105 iTombsEntryIterator = CCalIter::NewL( *( iTombsDb.Session() ) ); |
|
106 } |
|
107 |
|
108 // ---------------------------------------------------------------------------- |
|
109 // CMRUtilsGraveyardCleaner::ConstructL |
|
110 // ---------------------------------------------------------------------------- |
|
111 // |
|
112 void CMRUtilsGraveyardCleaner::StartIdleCleanupL( |
|
113 TTime aTimeLimitUtc ) |
|
114 { |
|
115 // basically latter check is unnecessary, just double checking |
|
116 if ( iIdleCleaner->IsActive() || iState != ENotActive ) |
|
117 { |
|
118 User::Leave( KErrInUse ); |
|
119 } |
|
120 |
|
121 iTimeLimitUtc = aTimeLimitUtc; |
|
122 iCurrentEntryUid.Set( iTombsEntryIterator->FirstL() ); |
|
123 if ( iCurrentEntryUid != KNullDesC8 ) |
|
124 { |
|
125 iState = EResurrectedItemsCleanup; |
|
126 iIdleCleaner->Start( TCallBack( StepL, this ) ); |
|
127 } |
|
128 } |
|
129 |
|
130 // ---------------------------------------------------------------------------- |
|
131 // CMRUtilsGraveyardCleaner::CurrentStateL |
|
132 // ---------------------------------------------------------------------------- |
|
133 // |
|
134 CMRUtilsGraveyardCleaner::TCleanerState |
|
135 CMRUtilsGraveyardCleaner::CurrentStateL() const |
|
136 { |
|
137 return iState; |
|
138 } |
|
139 |
|
140 // ---------------------------------------------------------------------------- |
|
141 // CMRUtilsGraveyardCleaner::StepL |
|
142 // ---------------------------------------------------------------------------- |
|
143 // |
|
144 TInt CMRUtilsGraveyardCleaner::StepL( TAny* aCleaner ) |
|
145 { |
|
146 TInt retVal( 0 ); |
|
147 CMRUtilsGraveyardCleaner* thisCleaner = |
|
148 static_cast<CMRUtilsGraveyardCleaner*>( aCleaner ); |
|
149 TRAPD( err, retVal = thisCleaner->DoStepL() ); |
|
150 if ( err != KErrNone ) |
|
151 { |
|
152 // Errors are handled just by stopping cleanup, |
|
153 // maybe better luck next time |
|
154 thisCleaner->iState = ENotActive; |
|
155 User::Leave( err ); |
|
156 } |
|
157 return retVal; |
|
158 } |
|
159 |
|
160 // ---------------------------------------------------------------------------- |
|
161 // CMRUtilsGraveyardCleaner::DoStepL |
|
162 // ---------------------------------------------------------------------------- |
|
163 // |
|
164 TInt CMRUtilsGraveyardCleaner::DoStepL() |
|
165 { |
|
166 TInt retVal( 0 ); |
|
167 switch ( iState ) |
|
168 { |
|
169 case EResurrectedItemsCleanup: |
|
170 { |
|
171 CleanupIfResurrectedL( iCurrentEntryUid ); |
|
172 |
|
173 // step iterator |
|
174 iCurrentEntryUid.Set( iTombsEntryIterator->NextL() ); |
|
175 if ( iCurrentEntryUid == KNullDesC8 ) |
|
176 { // EOF, proceed to time limit cleanup phase |
|
177 iState = ETimeLimitCleanup; |
|
178 } |
|
179 retVal = 1; // clenup is not finished yet |
|
180 break; |
|
181 } |
|
182 case ETimeLimitCleanup: |
|
183 { |
|
184 if ( iTimeLimitUtc == Time::NullTTime() ) |
|
185 { |
|
186 iState = ENotActive; |
|
187 } |
|
188 else |
|
189 { |
|
190 TCalTime startTime; |
|
191 startTime.SetTimeUtcL( TCalTime::MinTime() ); |
|
192 TCalTime endTime; |
|
193 endTime.SetTimeUtcL( iTimeLimitUtc ); |
|
194 CalCommon::TCalTimeRange timeRange( startTime, endTime ); |
|
195 |
|
196 // TombsDb surely has entry view when status is 'available' |
|
197 iTombsDb.EntryView()->DeleteL( timeRange, |
|
198 CalCommon::EIncludeAppts, |
|
199 *this ); |
|
200 // CIdle operation is now finished but entry view continues |
|
201 // asynchronously with time range cleanup |
|
202 } |
|
203 retVal = 0; |
|
204 break; |
|
205 } |
|
206 default: |
|
207 { |
|
208 Panic( EUnexpectedState ); |
|
209 break; |
|
210 } |
|
211 } |
|
212 return retVal; |
|
213 } |
|
214 |
|
215 // ---------------------------------------------------------------------------- |
|
216 // CMRUtilsGraveyardCleaner::CleanupIfResurrectedL |
|
217 // ---------------------------------------------------------------------------- |
|
218 // |
|
219 void CMRUtilsGraveyardCleaner::CleanupIfResurrectedL( const TDesC8& aUid ) |
|
220 { |
|
221 __ASSERT_DEBUG( aUid.Length() > 0, Panic( ENullUid ) ); |
|
222 |
|
223 RCPointerArray<CCalEntry> arrayNormal; |
|
224 CleanupClosePushL( arrayNormal ); |
|
225 RCPointerArray<CCalEntry> arrayTombs; |
|
226 CleanupClosePushL( arrayTombs ); |
|
227 |
|
228 // Fetch parent and child entries: |
|
229 iNormalDb.EntryView()->FetchL( aUid, arrayNormal ); |
|
230 iTombsDb.EntryView()->FetchL( aUid, arrayTombs ); |
|
231 |
|
232 TInt normalCount( arrayNormal.Count() ); |
|
233 TInt tombsCount( arrayTombs.Count() ); |
|
234 TInt numChildrenCleaned( 0 ); |
|
235 |
|
236 if ( tombsCount > 0 && normalCount > 0 ) |
|
237 { // tombs found, and at least one of them may have been resurrected |
|
238 |
|
239 // First go through child entries: |
|
240 |
|
241 for ( TInt i( 1 ); i < tombsCount; ++i ) |
|
242 { |
|
243 for ( TInt j( 1 ); j < normalCount; ++j ) |
|
244 { |
|
245 if ( CMRUtilsCalDbBase::Compare( *( arrayTombs[i] ), |
|
246 *( arrayNormal[j] ) ) == 0 ) |
|
247 { // entry was found in normal db -> has been resurrected |
|
248 iTombsDb.EntryView()->DeleteL( *( arrayTombs[i] ) ); |
|
249 numChildrenCleaned++; |
|
250 break; |
|
251 } |
|
252 } |
|
253 } |
|
254 |
|
255 // If all children tombs were deleted we can also check the parent tomb: |
|
256 |
|
257 if ( numChildrenCleaned == tombsCount-1 ) |
|
258 { |
|
259 // This "if" is actually only relevant when parent doesn't have any |
|
260 // children: |
|
261 if ( CMRUtilsCalDbBase::Compare( *( arrayTombs[0] ), |
|
262 *( arrayNormal[0] ) ) == 0 ) |
|
263 { |
|
264 // For some reason after deleting the children the agenda model |
|
265 // can't find parent entry from db, we must re-fetch it first! |
|
266 arrayTombs.ResetAndDestroy(); |
|
267 iTombsDb.EntryView()->FetchL( aUid, arrayTombs ); |
|
268 |
|
269 iTombsDb.EntryView()->DeleteL( *( arrayTombs[0] ) ); |
|
270 } |
|
271 } |
|
272 } |
|
273 |
|
274 CleanupStack::PopAndDestroy( 2 ); // arrayTombs, arrayNormal |
|
275 } |
|
276 |
|
277 // ---------------------------------------------------------------------------- |
|
278 // CMRUtilsGraveyardCleaner::Progress |
|
279 // ---------------------------------------------------------------------------- |
|
280 // |
|
281 void CMRUtilsGraveyardCleaner::Progress( TInt /*aPercentageCompleted*/ ) |
|
282 { |
|
283 // Not interested in progress |
|
284 } |
|
285 |
|
286 // ---------------------------------------------------------------------------- |
|
287 // CMRUtilsGraveyardCleaner::NotifyProgress |
|
288 // ---------------------------------------------------------------------------- |
|
289 // |
|
290 TBool CMRUtilsGraveyardCleaner::NotifyProgress() |
|
291 { |
|
292 // Not interested in progress |
|
293 return EFalse; |
|
294 } |
|
295 |
|
296 // ---------------------------------------------------------------------------- |
|
297 // CMRUtilsGraveyardCleaner::Completed |
|
298 // ---------------------------------------------------------------------------- |
|
299 // |
|
300 void CMRUtilsGraveyardCleaner::Completed( TInt /*aError*/ ) |
|
301 { |
|
302 // Not interested in error code either |
|
303 iState = ENotActive; |
|
304 } |
|
305 |
|
306 // End of file |