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