os/persistentdata/loggingservices/eventlogger/LogServ/src/LOGCOMP.CPP
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2002-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 "LOGCOMP.H"
    17 #include "logservpanic.h"
    18 #include "LogServDatabaseTransactionInterface.h"
    19 
    20 // Constants
    21 const TInt KLogMaxWastedSpacePercentage = 25;
    22 const TInt KLogMaxWastedSpace = 128 * 1024;
    23 const TInt KLogMinWastedSpace = 32 * 1024;
    24 
    25 
    26 CLogCompact::CLogCompact(MLogServDatabaseTransactionInterface& aDatabase, TInt aPriority)
    27 : CLogActive(aPriority), iDatabase(aDatabase)
    28 	{
    29 	}
    30 
    31 void CLogCompact::Start(TRequestStatus& aStatus)
    32 	{
    33 	__ASSERT_DEBUG(!IsActive(), Panic(ELogAlreadyActive5));
    34 	
    35 	TInt error = iOperation.UpdateStats(iDatabase.DTIDatabase(), iStep());
    36 	iCompact = EFalse;
    37 
    38 	Queue(aStatus);
    39 	TRequestStatus* st = &iStatus;
    40 	User::RequestComplete(st, error);
    41 	SetActive();
    42 	}
    43 
    44 void CLogCompact::DoRunL()
    45 	{
    46 	if (iStep() > 0)
    47 		{
    48 		iOperation.Next(iStep, iStatus);
    49 		SetActive();
    50 		}
    51 	else if (!iCompact && CompactRequired())
    52 		{
    53 		iOperation.Close();
    54 
    55 		iCompact = ETrue;
    56 		User::LeaveIfError(iOperation.Compact(iDatabase.DTIDatabase(), iStep()));
    57 
    58 		if (iStep() > 0)
    59 			{
    60 			TRequestStatus* st = &iStatus;
    61 			User::RequestComplete(st, KErrNone);
    62 
    63 			SetActive();
    64 			}
    65 		}
    66 	}
    67 
    68 TBool CLogCompact::CompactRequired() const
    69 	{
    70 	RDbDatabase::TSize size = iDatabase.DTIDatabase().Size();
    71 	if (size.iUsage < 0)
    72 		return EFalse;
    73 
    74 	const TInt wastedSpace = (size.iSize * (100 - size.iUsage)) / 100;
    75 	return (wastedSpace > KLogMinWastedSpace && (100 - size.iUsage) > KLogMaxWastedSpacePercentage) || wastedSpace > KLogMaxWastedSpace;
    76 	}
    77 
    78 void CLogCompact::DoComplete(TInt&)
    79 	{
    80 	iOperation.Close();
    81 	}