sl@0: // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: #include "LogDynBuf.h" sl@0: sl@0: /** sl@0: Constructs RLogDynBuf object with the specified granularity. sl@0: sl@0: @param aGranularity RLogDynBuf granularity. sl@0: @endcode sl@0: sl@0: @leave KErrNoMemory Out of memory. sl@0: */ sl@0: void RLogDynBuf::CreateLC(TInt aGranularity) sl@0: { sl@0: iGranularity = aGranularity; sl@0: iBuf.CreateL(aGranularity); sl@0: CleanupClosePushL(*this); sl@0: } sl@0: sl@0: /** sl@0: Destroys the buffer sl@0: */ sl@0: void RLogDynBuf::Close() sl@0: { sl@0: iBuf.Close(); sl@0: } sl@0: sl@0: /** sl@0: Attempts to append aStr to the end of the buffer. If the buffer has not enough available space, sl@0: AppendL() will try to expand the buffer before the append operation. sl@0: sl@0: @param aStr 16-bit desrpiptor to be appended to the end of the buffer. sl@0: sl@0: @leave KErrNoMemory Out of memory. sl@0: */ sl@0: void RLogDynBuf::AppendL(const TDesC& aStr) sl@0: { sl@0: DoAllocL(aStr.Length()); sl@0: iBuf.Append(aStr); sl@0: } sl@0: sl@0: /** sl@0: If aLen is bigger than the available buffer space, the buffer will be expanded. sl@0: sl@0: @param aLen The new size of the buffer, in bytes. sl@0: sl@0: @leave KErrNoMemory Out of memory. sl@0: */ sl@0: void RLogDynBuf::DoAllocL(TInt aLen) sl@0: { sl@0: __ASSERT_DEBUG(aLen >= 0, User::Invariant()); sl@0: const TInt len = iBuf.Length(); sl@0: TInt maxLen = iBuf.MaxLength(); sl@0: TInt available = maxLen - len; sl@0: TInt overflow = aLen - available; sl@0: if(overflow > 0) sl@0: { sl@0: iBuf.ReAllocL(maxLen + (overflow / iGranularity + 1) * iGranularity); sl@0: } sl@0: }