|
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 |
|
16 #include "es_commsbuf_internal.h" |
|
17 #include "commsbufpondintf.h" |
|
18 #include "commsbufpool.h" |
|
19 |
|
20 EXPORT_C RCommsBuf* RCommsBuf::Alloc(TUint aSize, TCommsBufAllocator& aAllocator) |
|
21 /** |
|
22 Allocates memory for a RCommsBuf object. |
|
23 |
|
24 @param aSize Requested total size |
|
25 @param aAllocator A handle to the allocator |
|
26 |
|
27 @return RCommsBuf A pointer to the allocated RCommsBuf object if allocation is success |
|
28 or NULL if allocation is failed |
|
29 */ |
|
30 { |
|
31 return aAllocator.iPond.Alloc(aSize, aSize, KMaxTInt); |
|
32 } |
|
33 |
|
34 EXPORT_C void RCommsBuf::Append(const TDesC8& aSrc) |
|
35 /** |
|
36 Append data onto the end of RCommsBuf data. The length of the |
|
37 CommsBuf data is incremented to reflect the new content |
|
38 |
|
39 @param aSrc Data to append |
|
40 */ |
|
41 { |
|
42 __ASSERT_COMMSBUF(); |
|
43 __ASSERT_ALWAYS(AppendLimit() >= aSrc.Length(), CommsBuf::Panic(EMBuf_IndexOutofRange)); |
|
44 Mem::Copy(const_cast<TUint8*>(Ptr()) + iCommsBufMetaData.iLength, aSrc.Ptr(), aSrc.Length()); |
|
45 AdjustDataEnd(aSrc.Length()); |
|
46 } |
|
47 |
|
48 EXPORT_C void RCommsBuf::Prepend(const TDesC8& aSrc) |
|
49 /** |
|
50 Prepend data onto the beginning of RCommsBuf data. The length and offset of the |
|
51 will be adjusted to reflect the new content |
|
52 |
|
53 @param aSrc Data to append |
|
54 */ |
|
55 { |
|
56 __ASSERT_COMMSBUF(); |
|
57 __ASSERT_ALWAYS(PrependLimit() >= aSrc.Length(), CommsBuf::Panic(EMBuf_IndexOutofRange)); |
|
58 Mem::Copy(const_cast<TUint8*>(Ptr()) - aSrc.Length(), aSrc.Ptr(), aSrc.Length()); |
|
59 SetDataRange(Offset() - aSrc.Length(), iCommsBufMetaData.iLength + aSrc.Length()); |
|
60 } |
|
61 |
|
62 EXPORT_C void RCommsBuf::Free() |
|
63 /** |
|
64 Frees the RCommsBuf |
|
65 */ |
|
66 { |
|
67 Pool()->Pond().Free(this); |
|
68 } |
|
69 |
|
70 EXPORT_C void RCommsBuf::Write(const TDesC8& aSrc, TInt aOffset /* =0 */) |
|
71 /** |
|
72 The supplied descriptor will be written to the specified offset within the RCommsBuf data |
|
73 |
|
74 @param aSrc Data to be written |
|
75 @param aOffset Offset within the CommsBuf |
|
76 |
|
77 @panic MBuf::11 If the given offset is negative |
|
78 */ |
|
79 { |
|
80 __ASSERT_COMMSBUF(); |
|
81 __ASSERT_ALWAYS(aOffset>=0, CommsBuf::Panic(EMBuf_NegativeOffset)); |
|
82 SetDataRange(aOffset, 0); // Set the write offset and make the length as 0 |
|
83 Append(aSrc); // Append the data |
|
84 } |
|
85 |
|
86 EXPORT_C void RCommsBuf::Read(TDes8& aDest, TInt aOffset /* =0 */) const |
|
87 /** |
|
88 The supplied descriptor will be read from the specified offset within the RCommsBuf data |
|
89 |
|
90 @param aDes Descriptor to write |
|
91 @param aOffset The offset |
|
92 |
|
93 @panic MBuf::11 If the given offset is negative or greater than the length of the CommsBuf data |
|
94 */ |
|
95 { |
|
96 __ASSERT_COMMSBUF(); |
|
97 __ASSERT_ALWAYS(aOffset>=0 && aOffset<Length(), CommsBuf::Panic(EMBuf_BadOffset)); |
|
98 TPtr8 src(const_cast<TUint8*>(Ptr()) + aOffset, Length() - aOffset, Length() - aOffset); |
|
99 aDest.Copy(src); |
|
100 } |
|
101 |