|
1 /* |
|
2 * Copyright (c) 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "afdatabasecleaner.h" |
|
19 |
|
20 CAfDatabaseCleaner::~CAfDatabaseCleaner() |
|
21 { |
|
22 Cancel(); |
|
23 } |
|
24 |
|
25 CAfDatabaseCleaner::CAfDatabaseCleaner(RDbStoreDatabase &database) : CActive(EPriorityIdle), mDatabase(database), mCleanupStep(Initial) |
|
26 { |
|
27 CActiveScheduler::Add(this); |
|
28 } |
|
29 |
|
30 void CAfDatabaseCleaner::StartCleanup() |
|
31 { |
|
32 if (!IsActive()) { |
|
33 mCleanupStep = Initial; |
|
34 SetActive(); |
|
35 CompleteSelf(KErrNone); |
|
36 } |
|
37 } |
|
38 |
|
39 void CAfDatabaseCleaner::RunL() |
|
40 { |
|
41 if (KErrNone == iStatus.Int()) { |
|
42 switch (mCleanupStep) { |
|
43 case Initial: |
|
44 { |
|
45 User::LeaveIfError(mIncrementalInterface.Compact(mDatabase, mStep)); |
|
46 mCleanupStep = Continuation; |
|
47 SetActive(); |
|
48 CompleteSelf(KErrNone); |
|
49 break; |
|
50 } |
|
51 case Continuation: |
|
52 { |
|
53 User::LeaveIfError(mIncrementalInterface.Next(mStep)); |
|
54 if (mStep != 0) { |
|
55 SetActive(); |
|
56 CompleteSelf(KErrNone); |
|
57 } else { |
|
58 mIncrementalInterface.Close(); |
|
59 } |
|
60 break; |
|
61 } |
|
62 default: |
|
63 User::Leave(KErrArgument); |
|
64 } |
|
65 } |
|
66 } |
|
67 |
|
68 void CAfDatabaseCleaner::DoCancel() |
|
69 { |
|
70 mIncrementalInterface.Close(); |
|
71 } |
|
72 |
|
73 void CAfDatabaseCleaner::CompleteSelf(TInt completionCode) |
|
74 { |
|
75 TRequestStatus* status = &iStatus; |
|
76 User::RequestComplete(status, completionCode); |
|
77 } |
|
78 |
|
79 TInt CAfDatabaseCleaner::RunError(TInt /*aError*/) |
|
80 { |
|
81 mIncrementalInterface.Close(); |
|
82 return KErrNone; |
|
83 } |