os/persistentdata/loggingservices/eventlogger/LogServ/src/LOGCOMP.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/LOGCOMP.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,81 @@
     1.4 +// Copyright (c) 2002-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 "LOGCOMP.H"
    1.20 +#include "logservpanic.h"
    1.21 +#include "LogServDatabaseTransactionInterface.h"
    1.22 +
    1.23 +// Constants
    1.24 +const TInt KLogMaxWastedSpacePercentage = 25;
    1.25 +const TInt KLogMaxWastedSpace = 128 * 1024;
    1.26 +const TInt KLogMinWastedSpace = 32 * 1024;
    1.27 +
    1.28 +
    1.29 +CLogCompact::CLogCompact(MLogServDatabaseTransactionInterface& aDatabase, TInt aPriority)
    1.30 +: CLogActive(aPriority), iDatabase(aDatabase)
    1.31 +	{
    1.32 +	}
    1.33 +
    1.34 +void CLogCompact::Start(TRequestStatus& aStatus)
    1.35 +	{
    1.36 +	__ASSERT_DEBUG(!IsActive(), Panic(ELogAlreadyActive5));
    1.37 +	
    1.38 +	TInt error = iOperation.UpdateStats(iDatabase.DTIDatabase(), iStep());
    1.39 +	iCompact = EFalse;
    1.40 +
    1.41 +	Queue(aStatus);
    1.42 +	TRequestStatus* st = &iStatus;
    1.43 +	User::RequestComplete(st, error);
    1.44 +	SetActive();
    1.45 +	}
    1.46 +
    1.47 +void CLogCompact::DoRunL()
    1.48 +	{
    1.49 +	if (iStep() > 0)
    1.50 +		{
    1.51 +		iOperation.Next(iStep, iStatus);
    1.52 +		SetActive();
    1.53 +		}
    1.54 +	else if (!iCompact && CompactRequired())
    1.55 +		{
    1.56 +		iOperation.Close();
    1.57 +
    1.58 +		iCompact = ETrue;
    1.59 +		User::LeaveIfError(iOperation.Compact(iDatabase.DTIDatabase(), iStep()));
    1.60 +
    1.61 +		if (iStep() > 0)
    1.62 +			{
    1.63 +			TRequestStatus* st = &iStatus;
    1.64 +			User::RequestComplete(st, KErrNone);
    1.65 +
    1.66 +			SetActive();
    1.67 +			}
    1.68 +		}
    1.69 +	}
    1.70 +
    1.71 +TBool CLogCompact::CompactRequired() const
    1.72 +	{
    1.73 +	RDbDatabase::TSize size = iDatabase.DTIDatabase().Size();
    1.74 +	if (size.iUsage < 0)
    1.75 +		return EFalse;
    1.76 +
    1.77 +	const TInt wastedSpace = (size.iSize * (100 - size.iUsage)) / 100;
    1.78 +	return (wastedSpace > KLogMinWastedSpace && (100 - size.iUsage) > KLogMaxWastedSpacePercentage) || wastedSpace > KLogMaxWastedSpace;
    1.79 +	}
    1.80 +
    1.81 +void CLogCompact::DoComplete(TInt&)
    1.82 +	{
    1.83 +	iOperation.Close();
    1.84 +	}