|
1 // Copyright (c) 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 #include "LogDynBuf.h" |
|
16 |
|
17 /** |
|
18 Constructs RLogDynBuf object with the specified granularity. |
|
19 |
|
20 @param aGranularity RLogDynBuf granularity. |
|
21 @endcode |
|
22 |
|
23 @leave KErrNoMemory Out of memory. |
|
24 */ |
|
25 void RLogDynBuf::CreateLC(TInt aGranularity) |
|
26 { |
|
27 iGranularity = aGranularity; |
|
28 iBuf.CreateL(aGranularity); |
|
29 CleanupClosePushL(*this); |
|
30 } |
|
31 |
|
32 /** |
|
33 Destroys the buffer |
|
34 */ |
|
35 void RLogDynBuf::Close() |
|
36 { |
|
37 iBuf.Close(); |
|
38 } |
|
39 |
|
40 /** |
|
41 Attempts to append aStr to the end of the buffer. If the buffer has not enough available space, |
|
42 AppendL() will try to expand the buffer before the append operation. |
|
43 |
|
44 @param aStr 16-bit desrpiptor to be appended to the end of the buffer. |
|
45 |
|
46 @leave KErrNoMemory Out of memory. |
|
47 */ |
|
48 void RLogDynBuf::AppendL(const TDesC& aStr) |
|
49 { |
|
50 DoAllocL(aStr.Length()); |
|
51 iBuf.Append(aStr); |
|
52 } |
|
53 |
|
54 /** |
|
55 If aLen is bigger than the available buffer space, the buffer will be expanded. |
|
56 |
|
57 @param aLen The new size of the buffer, in bytes. |
|
58 |
|
59 @leave KErrNoMemory Out of memory. |
|
60 */ |
|
61 void RLogDynBuf::DoAllocL(TInt aLen) |
|
62 { |
|
63 __ASSERT_DEBUG(aLen >= 0, User::Invariant()); |
|
64 const TInt len = iBuf.Length(); |
|
65 TInt maxLen = iBuf.MaxLength(); |
|
66 TInt available = maxLen - len; |
|
67 TInt overflow = aLen - available; |
|
68 if(overflow > 0) |
|
69 { |
|
70 iBuf.ReAllocL(maxLen + (overflow / iGranularity + 1) * iGranularity); |
|
71 } |
|
72 } |