|
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 // MBuf Manager Extensions |
|
15 // |
|
16 |
|
17 /** |
|
18 @file |
|
19 |
|
20 MBuf Manager Extensions |
|
21 */ |
|
22 |
|
23 |
|
24 #ifndef __NIFMBUF_H__ |
|
25 #define __NIFMBUF_H__ |
|
26 |
|
27 #ifndef __ES_MBUF_H__ |
|
28 #include <es_mbuf.h> |
|
29 #endif |
|
30 |
|
31 #ifndef __ES_SOCK_H__ |
|
32 #include <es_sock.h> |
|
33 #endif |
|
34 |
|
35 |
|
36 // |
|
37 // Support to use single MBufs for containing C++ objects |
|
38 // |
|
39 |
|
40 class RMBufCell |
|
41 /** |
|
42 Support to use single MBufs for containing C++ objects |
|
43 |
|
44 @publishedPartner |
|
45 @released |
|
46 */ |
|
47 { |
|
48 public: |
|
49 IMPORT_C RMBufCell(RMBufCell* aPktHdr); |
|
50 IMPORT_C static TAny* operator new(TUint aSize, TLeave aLeave, TUint aExtra); |
|
51 IMPORT_C static TAny* operator new(TUint aSize, TUint aExtra) __NO_THROW; |
|
52 IMPORT_C static void operator delete(TAny*); |
|
53 static void operator delete(TAny*, TLeave, TUint); |
|
54 static void operator delete(TAny*, TUint); |
|
55 IMPORT_C RMBufCell* CopyL(); |
|
56 // |
|
57 inline RMBufCell() {} // to prevent statement has no effect |
|
58 static inline TAny* operator new(TUint aSize, TLeave aLeave) |
|
59 { return RMBufCell::operator new (aSize, aLeave, 0); } |
|
60 static inline TAny* operator new(TUint aSize) |
|
61 { return RMBufCell::operator new (aSize, 0); } |
|
62 inline RMBuf* MBuf(); |
|
63 // |
|
64 private: |
|
65 RMBuf* iThisMBuf; |
|
66 }; |
|
67 |
|
68 inline RMBuf* RMBufCell::MBuf() |
|
69 { return iThisMBuf; } |
|
70 |
|
71 class RMBufStreamQ : public RMBufQ |
|
72 /** |
|
73 MBuf Stream Queue |
|
74 @publishedPartner |
|
75 @released |
|
76 */ |
|
77 { |
|
78 public: |
|
79 IMPORT_C RMBufStreamQ(); |
|
80 IMPORT_C void TrimStart(TInt aOffset); |
|
81 IMPORT_C void CopyOut(TDes8& aDes); |
|
82 IMPORT_C void CopySegmentL(RMBufChain &aNewChain, TInt aOffset, TInt aLen); |
|
83 IMPORT_C void Append(RMBufChain& aPacket); |
|
84 protected: |
|
85 inline RMBufChain& AsRMBufChain() { return *((RMBufChain*)this); } |
|
86 protected: |
|
87 // Pointers cache |
|
88 TInt iPosition; |
|
89 RMBuf* iMBuf; |
|
90 TInt iOffset; |
|
91 TInt iLength; |
|
92 }; |
|
93 |
|
94 // |
|
95 // Inter-Protocol Information carried in header MBuf |
|
96 // |
|
97 |
|
98 class RMBufPktInfo : public RMBufCell |
|
99 /** |
|
100 Inter-Protocol Information carried in header MBuf |
|
101 |
|
102 @publishedPartner |
|
103 @released |
|
104 */ |
|
105 { |
|
106 public: |
|
107 TSockAddr iSrcAddr; //< Source address of packet according to iProtocol |
|
108 TSockAddr iDstAddr; //< Destination address of packet according to protocol |
|
109 TInt iProtocol; //< ID of protocol who is giving you this |
|
110 TInt iLength; //< Actual length of packet |
|
111 TUint iFlags; //< Packet flags |
|
112 }; |
|
113 |
|
114 // |
|
115 // Holder for MBuf Chain with inter-protocol header split off |
|
116 // |
|
117 |
|
118 class RMBufPacketBase : public RMBufChain |
|
119 /** |
|
120 @publishedPartner |
|
121 @released |
|
122 */ |
|
123 { |
|
124 __DECLARE_CLEANUP |
|
125 public: |
|
126 IMPORT_C RMBufPacketBase(); |
|
127 IMPORT_C void CopyInfoL(RMBufPacketBase& aNewPkt); |
|
128 IMPORT_C void CopyPackedL(RMBufChain& aPacket); |
|
129 IMPORT_C void Pack(); |
|
130 IMPORT_C void SetInfo(RMBufPktInfo* iInfo); |
|
131 IMPORT_C void FreeInfo(); |
|
132 IMPORT_C void Free(); |
|
133 IMPORT_C void TrimStart(TInt aOffset); |
|
134 IMPORT_C void TrimEnd(TInt aOffset); |
|
135 IMPORT_C RMBufPktInfo* Unpack(); |
|
136 IMPORT_C RMBufPktInfo* Info(); |
|
137 IMPORT_C RMBufPktInfo* PeekInfo(); |
|
138 IMPORT_C RMBufPktInfo* NewInfoL(TUint aMBufHdrSize); |
|
139 IMPORT_C RMBufPktInfo* NewInfo(TUint aMBufHdrSize); |
|
140 IMPORT_C static RMBufPktInfo* PeekInfoInChain(RMBufChain& aChain); |
|
141 protected: |
|
142 IMPORT_C RMBufPktInfo* CreateL(RMBufQ& aPacket, TInt aLength, TUint aMBufHdrSize); |
|
143 IMPORT_C RMBufPktInfo* CreateL(TInt aLength, TUint aMBufHdrSize); |
|
144 IMPORT_C RMBufPktInfo* CreateL(const TDesC8 &aDesc, TInt aHdrSize, TUint aMBufHdrSize); |
|
145 IMPORT_C RMBufPktInfo* CreateCopyL(const RMBufQ& aPacket, TInt aOffset, TInt aLength, TInt aHdrSize, TUint aMBufHdrSize); |
|
146 IMPORT_C RMBufPktInfo* CreateCopyL(RMBufStreamQ& aStream, TInt aOffset, TInt aLength, TInt aHdrSize, TUint aMBufHdrSize); |
|
147 IMPORT_C RMBufPktInfo* CreateCopyL(const RMBufPktQ& aList, TInt aHdrSize, TUint aMBufHdrSize); |
|
148 protected: |
|
149 RMBufPktInfo* iInfo; |
|
150 }; |
|
151 |
|
152 template <class T> |
|
153 class RMBufInfoPacketBase : public RMBufPacketBase |
|
154 /** |
|
155 @publishedPartner |
|
156 @released |
|
157 */ |
|
158 { |
|
159 public: |
|
160 /** |
|
161 Splits off the info header |
|
162 @return the packet info header |
|
163 */ |
|
164 inline T* Unpack() |
|
165 { return (T*)RMBufPacketBase::Unpack(); } |
|
166 /** |
|
167 Return pointer to info header |
|
168 @return the info header |
|
169 */ |
|
170 inline T* Info() |
|
171 { return (T*)RMBufPacketBase::Info(); } |
|
172 /** |
|
173 Allows the packet info header to be accessed without unpacking |
|
174 @return the packet info header |
|
175 */ |
|
176 inline T* PeekInfo() |
|
177 { return (T*)RMBufPacketBase::PeekInfo(); } |
|
178 /** |
|
179 Allows the packet info header to be accessed while still on a packet queue |
|
180 @param aChain the chain to be accessed |
|
181 @return the info header |
|
182 */ |
|
183 inline static T* PeekInfoInChain(RMBufChain& aChain) |
|
184 { return (T*)RMBufPacketBase::PeekInfoInChain(aChain); } |
|
185 /** |
|
186 Create an info header |
|
187 @return the info header |
|
188 */ |
|
189 inline T* NewInfoL() |
|
190 { return (T*)RMBufPacketBase::NewInfoL(sizeof(T)); } |
|
191 /** |
|
192 Create an info header |
|
193 @return the info header |
|
194 */ |
|
195 inline T* NewInfo() |
|
196 { return (T*)RMBufPacketBase::NewInfo(sizeof(T)); } |
|
197 /** |
|
198 Create an empty Class T chain of required header size |
|
199 @param aHdrSize the header size |
|
200 @return the info header |
|
201 */ |
|
202 inline T* CreateL(TInt aHdrSize) |
|
203 { return (T*)RMBufPacketBase::CreateL(aHdrSize, sizeof(T)); }; |
|
204 /** |
|
205 Create a Class T chain and header from a descriptor |
|
206 @param aDesc the buffer of data |
|
207 @param aHdrSize the header size |
|
208 @return the info header |
|
209 */ |
|
210 inline T* CreateL(const TDesC8 &aDesc, TInt aHdrSize=0) |
|
211 { return (T*)RMBufPacketBase::CreateL(aDesc, aHdrSize, sizeof(T)); }; |
|
212 /** |
|
213 Create a Class T chain from an received MBuf Queue |
|
214 @param aPacket the MBuf Queue |
|
215 @param aLength the chain length |
|
216 @return the info header |
|
217 */ |
|
218 inline T* CreateL(RMBufQ& aPacket, TInt aLength=0) |
|
219 { return (T*)RMBufPacketBase::CreateL(aPacket, aLength, sizeof(T)); }; |
|
220 /** |
|
221 Create a Class T chain from an received MBuf Queue |
|
222 @param aPacket the MBuf Queue |
|
223 @param aOffset the offset |
|
224 @param aLength the length of the data to be copied |
|
225 @param aHdrSize the header size |
|
226 @param aMBufHdrSize the MBuf Header Size |
|
227 @return the info header |
|
228 */ |
|
229 inline T* CreateCopyL(const RMBufQ& aPacket, TInt aOffset, TInt aLength, TInt aHdrSize=0) |
|
230 { return (T*)RMBufPacketBase::CreateCopyL(aPacket, aOffset, aLength, aHdrSize, sizeof(T)); }; |
|
231 /** |
|
232 Create a Class T chain by copying data from a stream queue (basically an RMBufQ) |
|
233 aOffset and aLength specify location in stream queue. |
|
234 @param aStream the stream queue |
|
235 @param aOffset the offset |
|
236 @param aLength the data length |
|
237 @param aHdrSize the header size |
|
238 @return the info header |
|
239 */ |
|
240 inline T* CreateCopyL(RMBufStreamQ& aStream, TInt aOffset, TInt aLength, TInt aHdrSize=0) |
|
241 { return (T*)RMBufPacketBase::CreateCopyL(aStream, aOffset, aLength, aHdrSize, sizeof(T)); }; |
|
242 /** |
|
243 Build a Class T chain by copying a packet queue list, leaving space on the front |
|
244 for a header. (Very heavily used in PPP option processing). |
|
245 @param aList the packet queue |
|
246 @param aHdrSize the header size |
|
247 @return the info header |
|
248 */ |
|
249 inline T* CreateCopyL(const RMBufPktQ& aList, TInt aHdrSize=0) |
|
250 { return (T*)RMBufPacketBase::CreateCopyL(aList, aHdrSize, sizeof(T)); }; |
|
251 }; |
|
252 |
|
253 /** |
|
254 @publishedPartner |
|
255 @released |
|
256 */ |
|
257 typedef class RMBufInfoPacketBase<RMBufPktInfo> RMBufPacket; |
|
258 |
|
259 enum TMBufExtPanic |
|
260 { |
|
261 EMbExtPanic_MBufAllocTooBig, |
|
262 EMbExtPanic_HeaderTooBig, |
|
263 EMbExtPanic_PacketHeader, |
|
264 EMbExtPanic_PacketHeaderEmpty |
|
265 }; |
|
266 |
|
267 void MBufExtPanic(TMBufExtPanic aPanic); |
|
268 |
|
269 #endif |