|
1 // Copyright (c) 1997-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 // Buffer Manager for Protocols(Buffer) |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 |
|
21 Buffer Manager for Protocols(Buffer) |
|
22 |
|
23 @internalComponent |
|
24 */ |
|
25 #include <es_mbuf.h> |
|
26 #include <comms-infras/commsbufpanic.h> |
|
27 |
|
28 // |
|
29 // MBUF |
|
30 // |
|
31 |
|
32 EXPORT_C void RMBuf::Init(TMBufType aType) |
|
33 /** |
|
34 Initialises MBuf's members |
|
35 @param aType A MBuf type |
|
36 */ |
|
37 { |
|
38 iCommsBufMetaData.iType = aType; |
|
39 iCommsBufMetaData.iLength = iCommsBufMetaData.iRawSize; |
|
40 iCommsBufMetaData.iOffset = iCommsBufMetaData.iRawDataOffset; |
|
41 iCommsBufMetaData.iNext = NULL; |
|
42 (static_cast<RMBufChain&>(iCommsBufMetaData.iNextPkt)).Init(); |
|
43 } |
|
44 |
|
45 EXPORT_C void RMBuf::Free() |
|
46 { |
|
47 RCommsBuf::Free(); |
|
48 } |
|
49 |
|
50 EXPORT_C RMBuf* RMBuf::AllocL() |
|
51 /** |
|
52 Allocates memory for a RMBuf object - the size of the mbuf to be allocate will depend on the available pool |
|
53 chains, eg. 128, 256 etc... |
|
54 |
|
55 @return A pointer to the RMBuf |
|
56 @leave KErrNoMemory On allocation failure |
|
57 */ |
|
58 { |
|
59 RMBufAllocator allocator; |
|
60 return AllocL(allocator); |
|
61 } |
|
62 |
|
63 EXPORT_C RMBuf* RMBuf::AllocL(TUint aSize) |
|
64 /** |
|
65 Allocates memory for a RMBuf object. Multiple RMBuf's maybe allocated internally if the |
|
66 requested size is greater than the maximum size of the RMBuf on the available pool chains. |
|
67 |
|
68 @param aSize The requested size for the RMBuf |
|
69 |
|
70 @return A pointer to the RMBuf |
|
71 @leave KErrNoMemory On allocation failure |
|
72 */ |
|
73 { |
|
74 RMBufAllocator allocator; |
|
75 return AllocL(aSize, allocator); |
|
76 } |
|
77 |
|
78 EXPORT_C RMBuf* RMBuf::Alloc() |
|
79 /** |
|
80 Allocates memory for a RMBuf object - the size of the mbuf to be allocate will depend on the available pool |
|
81 chains, eg. 128, 256 etc... |
|
82 |
|
83 @return A pointer to the RMBuf or NULL on allocation failure |
|
84 */ |
|
85 { |
|
86 RMBufAllocator allocator; |
|
87 return Alloc(allocator); |
|
88 } |
|
89 |
|
90 EXPORT_C RMBuf* RMBuf::Alloc(TUint aSize) |
|
91 /** |
|
92 Allocates memory for a RMBuf object. Multiple RMBuf's maybe allocated internally if the |
|
93 requested size is greater than the maximum size of the RMBuf on the available pool chains. |
|
94 |
|
95 @param aSize The requested size for the RMBuf |
|
96 |
|
97 @return A pointer to the RMBuf or NULL on allocation failure |
|
98 */ |
|
99 { |
|
100 RMBufAllocator allocator; |
|
101 return Alloc(aSize, allocator); |
|
102 } |
|
103 |
|
104 EXPORT_C RMBuf* RMBuf::AllocL(RMBufAllocator& aRMBufAllocator) |
|
105 /** |
|
106 Allocates memory for a RMBuf object using a given RMBufAllocator. Multiple RMBuf's maybe allocated internally if the |
|
107 requested size is greater than the maximum size of the RMBuf on the available pool chains. |
|
108 |
|
109 @see RMBufAllocator |
|
110 |
|
111 @param aRMBufAllocator RMBufAllocator object |
|
112 |
|
113 @return A pointer to the RMBuf |
|
114 @leave KErrNoMemory On allocation failure |
|
115 */ |
|
116 { |
|
117 return AllocL(KMBufSmallSize, aRMBufAllocator); |
|
118 } |
|
119 |
|
120 EXPORT_C RMBuf* RMBuf::AllocL(TUint aSize, RMBufAllocator& aRMBufAllocator) |
|
121 /** |
|
122 Allocates memory for a RMBuf object using a given RMBufAllocator and a given size. Multiple RMBuf's maybe allocated internally if the |
|
123 requested size is greater than the maximum size of the RMBuf on the available pool chains. |
|
124 |
|
125 @see RMBufAllocator |
|
126 |
|
127 @param aSize The requested size for the RMBuf |
|
128 @param aRMBufAllocator RMBufAllocator object |
|
129 |
|
130 @return A pointer to the RMBuf |
|
131 @leave KErrNoMemory On allocation failure |
|
132 */ |
|
133 { |
|
134 RMBuf* buf = static_cast<RMBuf*>(RCommsBuf::Alloc(aSize, aRMBufAllocator)); |
|
135 |
|
136 if (!buf) |
|
137 { |
|
138 User::Leave(KErrNoMBufs); |
|
139 } |
|
140 return buf; |
|
141 } |
|
142 |
|
143 EXPORT_C RMBuf* RMBuf::Alloc(RMBufAllocator& aRMBufAllocator) |
|
144 /** |
|
145 Allocates memory for a RMBuf object using a given RMBufAllocator. Multiple RMBuf's maybe allocated internally if the |
|
146 requested size is greater than the maximum size of the RMBuf on the available pool chains. |
|
147 |
|
148 @see RMBufAllocator |
|
149 |
|
150 @param aRMBufAllocator RMBufAllocator object |
|
151 |
|
152 @return A pointer to the RMBuf or NULL on allocation failure |
|
153 */ |
|
154 { |
|
155 return static_cast<RMBuf*>(RCommsBuf::Alloc(KMBufSmallSize, aRMBufAllocator)); |
|
156 } |
|
157 |
|
158 EXPORT_C RMBuf* RMBuf::Alloc(TUint aSize, RMBufAllocator& aRMBufAllocator) |
|
159 /** |
|
160 Allocates memory for a RMBuf object using a given RMBufAllocator and a given size. Multiple RMBuf's maybe allocated internally if the |
|
161 requested size is greater than the maximum size of the RMBuf on the available pool chains. |
|
162 |
|
163 @see RMBufAllocator |
|
164 |
|
165 @param aSize The requested size for the RMBuf |
|
166 @param aRMBufAllocator RMBufAllocator object |
|
167 |
|
168 @return A pointer to the RMBuf or NULL on allocation failure |
|
169 */ |
|
170 { |
|
171 return static_cast<RMBuf*>(RCommsBuf::Alloc(aSize, aRMBufAllocator)); |
|
172 } |
|
173 |
|
174 |
|
175 EXPORT_C RMBuf* RMBuf::Last() |
|
176 /** |
|
177 Last MBuf in a chain. |
|
178 Not really supposed to be in RMBuf, |
|
179 but putting it here allows the code to |
|
180 be shared by RMBufChain and RMBufQ |
|
181 @return A pointer to the last MBuf in the chain |
|
182 */ |
|
183 { |
|
184 RMBuf* p = NULL; |
|
185 TMBufIter m(this); |
|
186 |
|
187 while (m.More()) |
|
188 { |
|
189 p = m; |
|
190 m++; |
|
191 } |
|
192 return p; |
|
193 } |
|
194 |
|
195 EXPORT_C void RMBuf::__DbgPut(TUint8 aVal, TInt aOffset) |
|
196 { |
|
197 __ASSERT_ALWAYS((aOffset >= 0) && (aOffset <= iCommsBufMetaData.iLength), CommsBuf::Panic(EMBuf_BadOffset)); |
|
198 *(Ptr()+aOffset) = aVal; |
|
199 } |
|
200 |
|
201 EXPORT_C TUint8 RMBuf::__DbgGet(TInt aOffset) const |
|
202 { |
|
203 __ASSERT_ALWAYS((aOffset >= 0) && (aOffset <= iCommsBufMetaData.iLength), CommsBuf::Panic(EMBuf_BadOffset)); |
|
204 return *(Ptr()+aOffset); |
|
205 } |