|
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "LOGMAIN.H" |
|
17 #include "LOGREC.H" |
|
18 #include "LOGCOMP.H" |
|
19 #include "logservpanic.h" |
|
20 #include "LOGQUERY.H" |
|
21 #include "LogServDatabaseTransactionInterface.h" |
|
22 #include "LogServCacheConfig.h" |
|
23 #include "LogCliServShared.h" |
|
24 #include "LogServDatabaseChangeInterface.h" |
|
25 #include "LogServSqlStrings.h" |
|
26 |
|
27 CLogMaintenance::CLogMaintenance(MLogServDatabaseTransactionInterface& aDatabase, TInt aPriority) |
|
28 : CLogActive(aPriority), iDatabase(aDatabase) |
|
29 { |
|
30 } |
|
31 |
|
32 CLogMaintenance::~CLogMaintenance() |
|
33 { |
|
34 Cancel(); |
|
35 delete iRecover; |
|
36 delete iCompact; |
|
37 } |
|
38 |
|
39 void CLogMaintenance::ConstructL() |
|
40 { |
|
41 iRecover = new(ELeave)CLogRecover(iDatabase, Priority()); |
|
42 iCompact = new(ELeave)CLogCompact(iDatabase, Priority()); |
|
43 } |
|
44 |
|
45 CLogMaintenance* CLogMaintenance::NewL(MLogServDatabaseTransactionInterface& aDatabase, TInt aPriority) |
|
46 { |
|
47 CLogMaintenance* self = new(ELeave)CLogMaintenance(aDatabase, aPriority); |
|
48 CleanupStack::PushL(self); |
|
49 self->ConstructL(); |
|
50 CleanupStack::Pop(); |
|
51 return self; |
|
52 } |
|
53 |
|
54 void CLogMaintenance::Start(TBool aPurge, TRequestStatus& aStatus) |
|
55 { |
|
56 iState = ELogRecover; |
|
57 iPurge = aPurge; |
|
58 |
|
59 Queue(aStatus); |
|
60 TRequestStatus* status = &iStatus; |
|
61 User::RequestComplete(status, KErrNone); |
|
62 SetActive(); |
|
63 } |
|
64 |
|
65 TBool CLogMaintenance::DoNextL() |
|
66 { |
|
67 switch(iState) |
|
68 { |
|
69 // Recover the database |
|
70 case ELogRecover: |
|
71 if (iRecover->Start(iStatus)) |
|
72 { |
|
73 iState = ELogGetConfig; |
|
74 return ETrue; |
|
75 } |
|
76 // Fall Through |
|
77 |
|
78 // Get the log configuration |
|
79 case ELogGetConfig: |
|
80 if (iPurge) |
|
81 { |
|
82 iConfig = iDatabase.DTICacheConfig().Config(); |
|
83 TRequestStatus* status = &iStatus; |
|
84 User::RequestComplete(status, KErrNone); |
|
85 iState = iConfig.iMaxEventAge == 0 ? ELogCompact : ELogPurgeMainAge; |
|
86 return ETrue; |
|
87 } |
|
88 // Fall through |
|
89 |
|
90 // Purge old events from the log |
|
91 case ELogPurgeMainAge: |
|
92 if (iPurge) |
|
93 { |
|
94 // Get the max age |
|
95 TTime date; |
|
96 date.UniversalTime(); |
|
97 date -= TTimeIntervalSeconds(iConfig.iMaxEventAge); |
|
98 |
|
99 ClearLogL(date, iStatus); |
|
100 iState = ELogCompact; |
|
101 return ETrue; |
|
102 } |
|
103 |
|
104 // Compact the database |
|
105 case ELogCompact: |
|
106 iCompact->Start(iStatus); |
|
107 iState = ELogComplete; |
|
108 return ETrue; |
|
109 |
|
110 case ELogComplete: |
|
111 break; |
|
112 |
|
113 default: |
|
114 __ASSERT_DEBUG(EFalse, Panic(ELogNoSuchState7)); |
|
115 }; |
|
116 |
|
117 return EFalse; |
|
118 } |
|
119 |
|
120 void CLogMaintenance::DoRunL() |
|
121 { |
|
122 if (DoNextL()) |
|
123 SetActive(); |
|
124 } |
|
125 |
|
126 void CLogMaintenance::DoCancel() |
|
127 { |
|
128 iRecover->Cancel(); |
|
129 iCompact->Cancel(); |
|
130 |
|
131 CLogActive::DoCancel(); |
|
132 } |
|
133 |
|
134 void CLogMaintenance::DoComplete(TInt& aStatus) |
|
135 { |
|
136 // Ignore all errors |
|
137 aStatus = KErrNone; |
|
138 } |
|
139 |
|
140 // aDate is expected to be UTC |
|
141 void CLogMaintenance::ClearLogL(const TTime& aDate, TRequestStatus& aStatus) |
|
142 { |
|
143 TBuf<KLogMaxDateLength> date; |
|
144 aDate.FormatL(date, LogUtils::DateFormatForLocale()); |
|
145 // Get list of events to purge |
|
146 TheSql.Format(KLogSqlSelectOldestString, &date); |
|
147 RLogDbView view; |
|
148 view.PrepareLC(iDatabase.DTIDatabase(), TheSql); |
|
149 if(view.FirstL()) |
|
150 { |
|
151 static TDbColNo idColNo = 0; |
|
152 if(idColNo == 0) |
|
153 { |
|
154 CDbColSet* cs = view.ColSetL(); |
|
155 idColNo = cs->ColNo(KLogFieldIdString); |
|
156 delete cs; |
|
157 } |
|
158 iDatabase.DTIBeginWithRollBackProtectionLC(); |
|
159 do |
|
160 { |
|
161 view.GetL(); |
|
162 const TLogId id = view.ColInt32(idColNo); |
|
163 view.DeleteL(); |
|
164 iDatabase.DTIChangeInterface().DCISubmitChangedEventContextL(ELogChangeTypeEventDeleted, id); |
|
165 } |
|
166 while(view.NextL()); |
|
167 // Commit changes |
|
168 iDatabase.DTICommitAndCancelRollbackProtectionL(); |
|
169 } |
|
170 CleanupStack::PopAndDestroy(&view); |
|
171 // Complete the request |
|
172 TRequestStatus* status = &aStatus; |
|
173 User::RequestComplete(status, KErrNone); |
|
174 } |