os/persistentdata/loggingservices/eventlogger/LogServ/src/LOGMAIN.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/loggingservices/eventlogger/LogServ/src/LOGMAIN.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,174 @@
     1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include "LOGMAIN.H"
    1.20 +#include "LOGREC.H"
    1.21 +#include "LOGCOMP.H"
    1.22 +#include "logservpanic.h"
    1.23 +#include "LOGQUERY.H"
    1.24 +#include "LogServDatabaseTransactionInterface.h"
    1.25 +#include "LogServCacheConfig.h"
    1.26 +#include "LogCliServShared.h"
    1.27 +#include "LogServDatabaseChangeInterface.h"
    1.28 +#include "LogServSqlStrings.h"
    1.29 +
    1.30 +CLogMaintenance::CLogMaintenance(MLogServDatabaseTransactionInterface& aDatabase, TInt aPriority)
    1.31 +: CLogActive(aPriority), iDatabase(aDatabase)
    1.32 +	{
    1.33 +	}
    1.34 +
    1.35 +CLogMaintenance::~CLogMaintenance()
    1.36 +	{
    1.37 +	Cancel();
    1.38 +	delete iRecover;
    1.39 +	delete iCompact;
    1.40 +	}
    1.41 +
    1.42 +void CLogMaintenance::ConstructL()
    1.43 +	{
    1.44 +	iRecover = new(ELeave)CLogRecover(iDatabase, Priority());
    1.45 +	iCompact = new(ELeave)CLogCompact(iDatabase, Priority());
    1.46 +	}
    1.47 +
    1.48 +CLogMaintenance* CLogMaintenance::NewL(MLogServDatabaseTransactionInterface& aDatabase, TInt aPriority)
    1.49 +	{
    1.50 +	CLogMaintenance* self = new(ELeave)CLogMaintenance(aDatabase, aPriority);
    1.51 +	CleanupStack::PushL(self);
    1.52 +	self->ConstructL();
    1.53 +	CleanupStack::Pop();
    1.54 +	return self;
    1.55 +	}
    1.56 +
    1.57 +void CLogMaintenance::Start(TBool aPurge, TRequestStatus& aStatus)
    1.58 +	{
    1.59 +	iState = ELogRecover;
    1.60 +	iPurge = aPurge;
    1.61 +
    1.62 +	Queue(aStatus);
    1.63 +	TRequestStatus* status = &iStatus;
    1.64 +	User::RequestComplete(status, KErrNone);
    1.65 +	SetActive();
    1.66 +	}
    1.67 +
    1.68 +TBool CLogMaintenance::DoNextL()
    1.69 +	{
    1.70 +	switch(iState)
    1.71 +		{
    1.72 +		// Recover the database
    1.73 +		case ELogRecover:
    1.74 +			if (iRecover->Start(iStatus))
    1.75 +				{
    1.76 +				iState = ELogGetConfig;
    1.77 +				return ETrue;
    1.78 +				}
    1.79 +			// Fall Through
    1.80 +
    1.81 +		// Get the log configuration
    1.82 +		case ELogGetConfig:
    1.83 +			if (iPurge)
    1.84 +				{
    1.85 +				iConfig = iDatabase.DTICacheConfig().Config();				
    1.86 +				TRequestStatus* status = &iStatus;
    1.87 +				User::RequestComplete(status, KErrNone);
    1.88 +				iState = iConfig.iMaxEventAge == 0 ? ELogCompact : ELogPurgeMainAge;
    1.89 +				return ETrue;
    1.90 +				}
    1.91 +			// Fall through
    1.92 +
    1.93 +		// Purge old events from the log
    1.94 +		case ELogPurgeMainAge:
    1.95 +			if (iPurge)
    1.96 +				{
    1.97 +				// Get the max age
    1.98 +				TTime date;
    1.99 +				date.UniversalTime();
   1.100 +				date -= TTimeIntervalSeconds(iConfig.iMaxEventAge);
   1.101 +
   1.102 +				ClearLogL(date, iStatus);
   1.103 +				iState = ELogCompact;
   1.104 +				return ETrue;
   1.105 +				}
   1.106 +
   1.107 +		// Compact the database
   1.108 +		case ELogCompact:
   1.109 +			iCompact->Start(iStatus);
   1.110 +			iState = ELogComplete;
   1.111 +			return ETrue;
   1.112 +
   1.113 +		case ELogComplete:
   1.114 +			break;
   1.115 +
   1.116 +		default:
   1.117 +			__ASSERT_DEBUG(EFalse, Panic(ELogNoSuchState7));
   1.118 +		};
   1.119 +
   1.120 +	return EFalse;
   1.121 +	}
   1.122 +
   1.123 +void CLogMaintenance::DoRunL()
   1.124 +	{
   1.125 +	if (DoNextL())
   1.126 +		SetActive();
   1.127 +	}
   1.128 +
   1.129 +void CLogMaintenance::DoCancel()
   1.130 +	{
   1.131 +	iRecover->Cancel();
   1.132 +	iCompact->Cancel();
   1.133 +
   1.134 +	CLogActive::DoCancel();
   1.135 +	}
   1.136 +
   1.137 +void CLogMaintenance::DoComplete(TInt& aStatus)
   1.138 +	{
   1.139 +	// Ignore all errors
   1.140 +	aStatus = KErrNone;
   1.141 +	}
   1.142 +
   1.143 +// aDate is expected to be UTC  
   1.144 +void CLogMaintenance::ClearLogL(const TTime& aDate, TRequestStatus& aStatus)
   1.145 +	{
   1.146 +	TBuf<KLogMaxDateLength> date;
   1.147 +	aDate.FormatL(date, LogUtils::DateFormatForLocale());
   1.148 +    // Get list of events to purge
   1.149 +    TheSql.Format(KLogSqlSelectOldestString, &date);
   1.150 +    RLogDbView view;
   1.151 +    view.PrepareLC(iDatabase.DTIDatabase(), TheSql);
   1.152 +	if(view.FirstL())
   1.153 +		{
   1.154 +        static TDbColNo idColNo = 0;
   1.155 +        if(idColNo == 0)
   1.156 +            {
   1.157 +            CDbColSet* cs = view.ColSetL();
   1.158 +            idColNo = cs->ColNo(KLogFieldIdString);
   1.159 +            delete cs;
   1.160 +            }
   1.161 +        iDatabase.DTIBeginWithRollBackProtectionLC();
   1.162 +		do
   1.163 +			{
   1.164 +			view.GetL();
   1.165 +			const TLogId id = view.ColInt32(idColNo);
   1.166 +			view.DeleteL();
   1.167 +			iDatabase.DTIChangeInterface().DCISubmitChangedEventContextL(ELogChangeTypeEventDeleted, id);
   1.168 +			}
   1.169 +		while(view.NextL());
   1.170 +		// Commit changes
   1.171 +		iDatabase.DTICommitAndCancelRollbackProtectionL();
   1.172 +		}
   1.173 +	CleanupStack::PopAndDestroy(&view);
   1.174 +	// Complete the request
   1.175 +	TRequestStatus* status = &aStatus;
   1.176 +	User::RequestComplete(status, KErrNone);
   1.177 +	}