os/persistentdata/loggingservices/eventlogger/LogServ/src/LogDynBuf.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/LogDynBuf.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,72 @@
     1.4 +// Copyright (c) 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 +#include "LogDynBuf.h"
    1.19 +
    1.20 +/**
    1.21 +Constructs RLogDynBuf object with the specified granularity.
    1.22 +
    1.23 +@param aGranularity RLogDynBuf granularity. 
    1.24 +@endcode
    1.25 +
    1.26 +@leave KErrNoMemory Out of memory.
    1.27 +*/
    1.28 +void RLogDynBuf::CreateLC(TInt aGranularity)
    1.29 +	{
    1.30 +	iGranularity = aGranularity;
    1.31 +	iBuf.CreateL(aGranularity);
    1.32 +	CleanupClosePushL(*this);
    1.33 +	}
    1.34 +
    1.35 +/**
    1.36 +Destroys the buffer
    1.37 +*/
    1.38 +void RLogDynBuf::Close()
    1.39 +	{
    1.40 +	iBuf.Close();	
    1.41 +	}
    1.42 +
    1.43 +/**
    1.44 +Attempts to append aStr to the end of the buffer. If the buffer has not enough available space,
    1.45 +AppendL() will try to expand the buffer before the append operation.
    1.46 +
    1.47 +@param aStr 16-bit desrpiptor to be appended to the end of the buffer.
    1.48 +
    1.49 +@leave KErrNoMemory Out of memory.
    1.50 +*/	
    1.51 +void RLogDynBuf::AppendL(const TDesC& aStr)
    1.52 +	{
    1.53 +	DoAllocL(aStr.Length());
    1.54 +	iBuf.Append(aStr);
    1.55 +	}
    1.56 +
    1.57 +/**
    1.58 +If aLen is bigger than the available buffer space, the buffer will be expanded.
    1.59 +
    1.60 +@param aLen The new size of the buffer, in bytes.  
    1.61 +
    1.62 +@leave KErrNoMemory Out of memory.
    1.63 +*/
    1.64 +void RLogDynBuf::DoAllocL(TInt aLen)
    1.65 +	{
    1.66 +	__ASSERT_DEBUG(aLen >= 0, User::Invariant());
    1.67 +	const TInt len = iBuf.Length();
    1.68 +	TInt maxLen = iBuf.MaxLength();
    1.69 +	TInt available = maxLen - len;
    1.70 +	TInt overflow = aLen - available;
    1.71 +	if(overflow > 0)
    1.72 +		{
    1.73 +		iBuf.ReAllocL(maxLen + (overflow / iGranularity + 1) * iGranularity);
    1.74 +		}
    1.75 +	}