|
1 // Copyright (c) 2007-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 |
|
15 // |
|
16 |
|
17 #if !defined(__MBuf_inl__) |
|
18 #define __MBuf_inl__ |
|
19 |
|
20 // |
|
21 // MBUF |
|
22 // |
|
23 |
|
24 |
|
25 inline TAny* RMBuf::operator new(TUint /* aSize */, TUint8* aPtr) |
|
26 { |
|
27 return aPtr; |
|
28 } |
|
29 |
|
30 inline void RMBuf::operator delete(TAny*, TUint8* ) |
|
31 { |
|
32 } |
|
33 |
|
34 |
|
35 #ifndef __KERNEL_MODE__ |
|
36 /** |
|
37 Fills with binary zeroes (i.e. 0x00), replacing any existing content. |
|
38 */ |
|
39 inline void RMBuf::FillZ() |
|
40 { Mem::FillZ(RawBase(), iCommsBufMetaData.iRawSize); } |
|
41 |
|
42 /** |
|
43 Returns the size of the MBuf |
|
44 @return the size |
|
45 */ |
|
46 inline TInt RMBuf::Size() const |
|
47 { return RCommsBuf::RawSize(); } |
|
48 |
|
49 /** |
|
50 Returns a pointer to the MBuf data buffer |
|
51 @return A pointer to the MBuf data buffer |
|
52 */ |
|
53 inline TUint8* RMBuf::Buffer() |
|
54 { return (TUint8*)RCommsBuf::RawBase(); } |
|
55 |
|
56 /** |
|
57 Returns a TUnit8 pointer to the begining of MBuf |
|
58 @return A pointer to the begining of MBuf |
|
59 */ |
|
60 inline TUint8* RMBuf::Ptr() |
|
61 { return RCommsBuf::Ptr(); } |
|
62 |
|
63 /** |
|
64 Returns a TUint8 pointer to the end of the MBuf |
|
65 @return A pointer to the end of the MBuf |
|
66 */ |
|
67 inline TUint8* RMBuf::EndPtr() |
|
68 { return Ptr()+RCommsBuf::Length(); } |
|
69 |
|
70 /** |
|
71 Returns a const pointer to the MBuf data buffer |
|
72 @return A const pointer to the MBuf data buffer |
|
73 */ |
|
74 inline const TUint8* RMBuf::Buffer() const |
|
75 { return RCommsBuf::RawBase(); } |
|
76 |
|
77 /** |
|
78 Returns a const TUnit8 pointer to the begining of MBuf |
|
79 @return A const pointer to the begining of MBuf |
|
80 */ |
|
81 inline const TUint8* RMBuf::Ptr() const |
|
82 { return (TUint8*)RCommsBuf::RawBase()+RCommsBuf::Offset(); } |
|
83 |
|
84 /** |
|
85 Returns a const TUint8 pointer to the end of the MBuf |
|
86 @return A const pointer to the end of the MBuf |
|
87 */ |
|
88 inline const TUint8* RMBuf::EndPtr() const |
|
89 { return Ptr()+RCommsBuf::Length(); } |
|
90 |
|
91 /** |
|
92 Returns the offset of the MBuf |
|
93 @return the offset |
|
94 */ |
|
95 inline TInt RMBuf::Offset() const |
|
96 { return RCommsBuf::Offset(); } |
|
97 |
|
98 /** |
|
99 Returns the length of the MBuf |
|
100 @return the length |
|
101 */ |
|
102 inline TInt RMBuf::Length() const |
|
103 { return RCommsBuf::Length(); } |
|
104 |
|
105 /** |
|
106 Returns the offset of the last byte of the MBuf |
|
107 @return the offset |
|
108 */ |
|
109 inline TInt RMBuf::End() const |
|
110 { return RCommsBuf::Offset()+RCommsBuf::Length(); } |
|
111 |
|
112 /** |
|
113 Returns the Type of the MBuf (EMBufFree, EMBufData, EMBufHeader) |
|
114 @return type of the MBuf |
|
115 */ |
|
116 inline TMBufType RMBuf::Type() const |
|
117 { return static_cast<TMBufType>(iCommsBufMetaData.iType); } |
|
118 #endif |
|
119 /** |
|
120 Returns the Next MBuf (as MBuf*) |
|
121 @return a pointer to the next MBuf |
|
122 */ |
|
123 inline RMBuf* RMBuf::Next() |
|
124 { return static_cast<RMBuf*>(iCommsBufMetaData.iNext); } |
|
125 |
|
126 /** |
|
127 Returns the next packet in the chain (as a reference to RMBufChain) |
|
128 @return A reference to the next Packet (as a reference to RMBufChain) |
|
129 */ |
|
130 inline RMBufChain& RMBuf::NextPkt() |
|
131 { return static_cast<RMBufChain&>(iCommsBufMetaData.iNextPkt); } |
|
132 |
|
133 /** |
|
134 Returns the Next MBuf (as const MBuf*) |
|
135 @return a pointer to the next MBuf |
|
136 */ |
|
137 inline const RMBuf* RMBuf::Next() const |
|
138 { return static_cast<const RMBuf*>(RCommsBuf::Next()); } |
|
139 |
|
140 /** |
|
141 Returns the next packet in the chain (as a const reference to RMBufChain) |
|
142 @return A reference to the next Packet (as a const reference to RMBufChain) |
|
143 */ |
|
144 inline const RMBufChain& RMBuf::NextPkt() const |
|
145 { return static_cast<const RMBufChain&>(iCommsBufMetaData.iNextPkt); } |
|
146 |
|
147 /** |
|
148 Links a MBuf |
|
149 @param aBuf the buf to be linked |
|
150 */ |
|
151 inline void RMBuf::Link(RMBuf* aBuf) |
|
152 { RCommsBuf::SetNext(aBuf); } |
|
153 |
|
154 /** |
|
155 Unlinks the following MBuf |
|
156 */ |
|
157 inline void RMBuf::Unlink() |
|
158 { RCommsBuf::SetNext(NULL); } |
|
159 |
|
160 /** |
|
161 Links a packet to the chain |
|
162 @param aChain the chain to be linked |
|
163 */ |
|
164 inline void RMBuf::LinkPkt(RMBufChain &aChain) |
|
165 { iCommsBufMetaData.iNextPkt = aChain; } |
|
166 #ifndef __KERNEL_MODE__ |
|
167 /** |
|
168 Unlinks the packet next to the MBuf |
|
169 */ |
|
170 inline void RMBuf::UnlinkPkt() |
|
171 { NextPkt().Init(); } |
|
172 |
|
173 /** |
|
174 Sets the type of the MBuf (EMBufFree, EMBufData, EMBufHeader) |
|
175 @param aType A type |
|
176 */ |
|
177 inline void RMBuf::SetType(TMBufType aType) |
|
178 { iCommsBufMetaData.iType = aType; } |
|
179 |
|
180 /** |
|
181 Sets the offset |
|
182 @param aOffset A offset |
|
183 */ |
|
184 inline void RMBuf::SetOffset(TInt aOffset) |
|
185 { iCommsBufMetaData.iOffset = iCommsBufMetaData.iRawDataOffset + aOffset; } |
|
186 |
|
187 /** |
|
188 Sets the length |
|
189 @param aLength the length |
|
190 */ |
|
191 inline void RMBuf::SetLength(TInt aLength) |
|
192 { iCommsBufMetaData.iLength = aLength; } |
|
193 |
|
194 /** |
|
195 Sets data (actually sets the length and the offset) |
|
196 @param aOffset the offset |
|
197 @param aLength the length of the data (# of bytes) |
|
198 */ |
|
199 inline void RMBuf::SetData(TInt aOffset, TInt aLength) |
|
200 { RCommsBuf::SetDataRange(aOffset, aLength); } |
|
201 |
|
202 /** |
|
203 Adjust the begining of the MBuf |
|
204 */ |
|
205 inline void RMBuf::AdjustStart(TInt aLen) |
|
206 { RCommsBuf::AdjustDataStart(aLen); } |
|
207 |
|
208 /** |
|
209 Adjust the end of the MBuf |
|
210 */ |
|
211 inline void RMBuf::AdjustEnd(TInt aLen) |
|
212 { RCommsBuf::AdjustDataEnd(aLen); } |
|
213 |
|
214 #ifdef _DEBUG_SOCKET_FUNCTIONS |
|
215 /** |
|
216 Put the data into the MBuf |
|
217 @param aVal The value to put |
|
218 @param aOffset The Offset (=0 if not stated) |
|
219 */ |
|
220 inline void RMBuf::Put(TUint8 aVal, TInt aOffset) |
|
221 { __DbgPut(aVal, aOffset); } |
|
222 |
|
223 /** |
|
224 Get the data from the MBuf |
|
225 @param aOffset the offset (=0 if not stated) |
|
226 @return the data in TUint8 |
|
227 */ |
|
228 inline TUint8 RMBuf::Get(TInt aOffset) const |
|
229 { return __DbgGet(aOffset); } |
|
230 #else |
|
231 |
|
232 /** |
|
233 Put the data into the MBuf |
|
234 @param aVal The value to put |
|
235 @param aOffset The Offset (=0 if not stated) |
|
236 */ |
|
237 inline void RMBuf::Put(TUint8 aVal, TInt aOffset) |
|
238 { *(Ptr()+aOffset) = aVal; } |
|
239 |
|
240 /** |
|
241 Get the data from the MBuf |
|
242 @param aOffset the offset (=0 if not stated) |
|
243 @return the data in TUint8 |
|
244 */ |
|
245 inline TUint8 RMBuf::Get(TInt aOffset) const |
|
246 { return *(Ptr()+aOffset); } |
|
247 #endif |
|
248 |
|
249 // |
|
250 // MBUF ITERATOR |
|
251 // |
|
252 |
|
253 /** |
|
254 Constructor |
|
255 @param aChain where iterator points to |
|
256 */ |
|
257 inline TMBufIter::TMBufIter(RMBuf* aChain) |
|
258 : iIterator(aChain) |
|
259 { } |
|
260 |
|
261 /** |
|
262 Constructor |
|
263 @param aChain where iterator points to |
|
264 */ |
|
265 inline TMBufIter::TMBufIter(RMBufChain& aChain) |
|
266 : iIterator(aChain) |
|
267 { } |
|
268 |
|
269 /** |
|
270 Provides access to the MBuf |
|
271 */ |
|
272 inline TMBufIter& TMBufIter::operator =(RMBuf* aChain) |
|
273 { iIterator = aChain; return *this; } |
|
274 |
|
275 /** |
|
276 Provides access to the MBuf Chain |
|
277 */ |
|
278 inline TMBufIter& TMBufIter::operator =(RMBufChain& aChain) |
|
279 { iIterator = aChain; return *this; } |
|
280 |
|
281 /** |
|
282 iterate to next position operator |
|
283 */ |
|
284 inline RMBuf* TMBufIter::operator ++(TInt) |
|
285 { |
|
286 RMBuf* buf = static_cast<RMBuf*>(iIterator.Current()); |
|
287 ++iIterator; |
|
288 return buf; |
|
289 } |
|
290 |
|
291 /** |
|
292 Returns MBuf |
|
293 @return a MBuf |
|
294 */ |
|
295 inline TMBufIter::operator RMBuf* () |
|
296 { return MBuf (); |
|
297 } |
|
298 |
|
299 /** |
|
300 if there are more objects |
|
301 @return True if there is more objects |
|
302 */ |
|
303 inline TBool TMBufIter::More() |
|
304 { return !(iIterator.AtEnd()); } |
|
305 |
|
306 /** |
|
307 Returns MBuf |
|
308 @return a MBuf |
|
309 */ |
|
310 inline RMBuf* TMBufIter::MBuf() |
|
311 { return static_cast<RMBuf*>(iIterator.Current()); } |
|
312 |
|
313 #endif // KERNEL_MODE |
|
314 |
|
315 #endif // __MBuf_inl__ |