|
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: Comms specific specialization of a shared buffer |
|
14 // |
|
15 |
|
16 #ifndef __COMMSBUF_H__ |
|
17 #define __COMMSBUF_H__ |
|
18 |
|
19 #ifndef __KERNEL_MODE__ |
|
20 #include <e32base.h> |
|
21 #include <comms-infras/commsbufchain.h> |
|
22 #include <comms-infras/commsbufpond.h> |
|
23 #include <comms-infras/commsbufpanic.h> |
|
24 #endif |
|
25 |
|
26 class TCommsBufAllocator; |
|
27 class MCommsBufManagerIntf; |
|
28 class CCommsBufPool; |
|
29 class RCommsBuf; |
|
30 class TShBuf; |
|
31 |
|
32 /** |
|
33 Common (kernel and user-side) CommsBuf meta data. |
|
34 @publishedPartner |
|
35 */ |
|
36 class TCommsBuf |
|
37 { |
|
38 friend class RCommsBuf; |
|
39 friend class RMBuf; |
|
40 friend class DCommsBuf; |
|
41 |
|
42 private: |
|
43 enum {KCanaryDefault = 0xC9C9C9C9}; |
|
44 enum {KCommsBufMetadataSize = (16 * sizeof(TInt))}; |
|
45 |
|
46 inline TCommsBuf(); |
|
47 inline TCommsBuf(TInt aRawDataOffset, TUint aBufSize, TInt aHandle, TInt aPool); |
|
48 inline TCommsBuf(TInt aRawDataOffset, TUint aBufSize, TInt aPool); |
|
49 |
|
50 TInt iFrontCanary; // For overwrite identification |
|
51 TInt iOffset; // The offset of the data within the buffer |
|
52 TInt iLength; // The length of the data |
|
53 RCommsBuf* iNext; // Next RCommsBuf |
|
54 TInt iPool; // Pool identifier that "this" buffer belongs to. Typically a pointer to the CCommsBufPool |
|
55 TInt iHandle; // RShBuf handle. |
|
56 TInt iRawDataOffset; // Raw data offset from the metadata start (backward), metadata start - Raw data offset = RawBase |
|
57 TInt iRawSize; // The raw size of the buffer |
|
58 #ifndef __KERNEL_MODE__ |
|
59 RCommsBufChain iNextPkt; // Next packet. |
|
60 TUint8 iType; // Type of the MBuf. Used by RMBuf |
|
61 TUint8 iReservedBytes[3]; |
|
62 #else |
|
63 TShBuf* iShBuf; |
|
64 TUint8* iCommsBufPtr; |
|
65 #endif |
|
66 /** This large chunk of reserved words is effectively padding up to 64 bytes, ie a multiple |
|
67 of current target cache line length. As the next buffer begins on the next cache line |
|
68 (the space would only then be wasted.), the only conceivable cost is their initialisation. |
|
69 They are initialised in the interests of forward compatibility.*/ |
|
70 TInt iReservedWords[5]; |
|
71 TInt iBackCanary; // For underwrite identification |
|
72 }; |
|
73 |
|
74 #ifndef __KERNEL_MODE__ |
|
75 class RCommsBuf |
|
76 /** |
|
77 Represents the COMMS specific metadata and payload of a shared buffer |
|
78 |
|
79 @publishedPartner |
|
80 @prototype |
|
81 */ |
|
82 { |
|
83 |
|
84 friend class RCommsBufChain; |
|
85 friend class TCommsBufIter; |
|
86 friend class RCommsBufQ; |
|
87 friend class CMBufPool; |
|
88 friend class RMBufChain; |
|
89 friend class CMBufPoolManager; |
|
90 friend class CSystemSharedBufPool; |
|
91 friend class CSystemSharedBufPond; |
|
92 friend class RCommsBufAccessor; |
|
93 |
|
94 public: |
|
95 IMPORT_C static RCommsBuf* Alloc(TUint aSize, TCommsBufAllocator& aAccessor); |
|
96 |
|
97 // Simple access to the data |
|
98 inline TPtrC8 DesC8() const; |
|
99 /* inline TPtr8 RCommsBuf::Des8() |
|
100 This member function was withdrawn because there was no way for changes in the length to be reflected |
|
101 in the underlying descriptor, making it likely that bugs arise. Users who need a modifiable descriptor |
|
102 to access the contents of a single RCommsBuf can construct their own, eg with a RCommsBuf "rb": |
|
103 TPtr8 des(cb.Ptr(), cb.Length(), cb.Length() + cb.AppendLimit()); |
|
104 However they must bear in mind that any change of length of that descriptor will not be reflected in |
|
105 the RCommsBuf, eg could write: |
|
106 UpdateData(des); // some processing function that needs a TDes8 |
|
107 cb.SetDataRange(cb.Offset(), des.Length()); |
|
108 Or if only a const descriptor is used then use the DesC8() member function instead. |
|
109 */ |
|
110 |
|
111 inline const TUint8* RawBase() const; |
|
112 inline TUint8* RawBase(); |
|
113 inline TInt RawSize() const; |
|
114 |
|
115 inline const TUint8* Ptr() const; |
|
116 inline TUint8* Ptr(); |
|
117 inline TInt Length() const; |
|
118 inline TInt Offset() const; |
|
119 |
|
120 inline TUint8 operator[] (TInt aPos) const; |
|
121 inline TUint8& operator[] (TInt aPos); |
|
122 |
|
123 inline void Reset(); // Reset to empty buffer ( zero offset to data, zero data length ) |
|
124 |
|
125 IMPORT_C void Write(const TDesC8& aSrc, TInt aOffset =0); |
|
126 IMPORT_C void Read(TDes8& aDest, TInt aOffset =0) const; |
|
127 |
|
128 inline TInt AppendLimit() const; // Maximum number of bytes which can be appended |
|
129 IMPORT_C void Append(const TDesC8& aSrc); |
|
130 |
|
131 inline TInt PrependLimit() const; // Maximum number of bytes which can be prepended |
|
132 IMPORT_C void Prepend(const TDesC8& aSrc); |
|
133 |
|
134 // Raw manipulation |
|
135 inline void SetDataRange(TInt aOffset, TInt aLength); |
|
136 inline void AdjustDataStart(TInt aDelta); |
|
137 inline void AdjustDataEnd(TInt aDelta); |
|
138 |
|
139 // Free the RCommsBuf |
|
140 IMPORT_C void Free(); |
|
141 |
|
142 protected: |
|
143 |
|
144 inline RCommsBuf* Next(); |
|
145 inline const RCommsBuf* Next() const; |
|
146 inline void SetNext(RCommsBuf* aBuf); |
|
147 inline void SetOffset(TInt aOffset); |
|
148 |
|
149 inline RCommsBuf(); |
|
150 inline RCommsBuf(TInt aRawDataOffset, TUint aBufSize, TInt aHandle, TInt aPool); |
|
151 inline RCommsBuf(TInt aRawDataOffset, TUint aBufSize, TInt aPool); |
|
152 |
|
153 private: |
|
154 |
|
155 inline TAny* operator new(TUint aSize, const TUint8* aPtr) __NO_THROW; |
|
156 inline void operator delete(TAny* aPtr, const TUint8*) __NO_THROW; |
|
157 // Forbidden ops |
|
158 RCommsBuf(const RCommsBuf &); |
|
159 RCommsBuf& operator=(const RCommsBuf &); |
|
160 |
|
161 inline CCommsBufPool* Pool() const; |
|
162 inline TInt Handle() const; |
|
163 |
|
164 inline void AssertCommsBufInvariants() const; |
|
165 |
|
166 #define __ASSERT_COMMSBUF() \ |
|
167 AssertCommsBufInvariants() |
|
168 |
|
169 protected: |
|
170 TCommsBuf iCommsBufMetaData; |
|
171 }; |
|
172 |
|
173 |
|
174 /** |
|
175 Provides explicit access to special commsbuf fields |
|
176 @publishedPartner |
|
177 @prototype |
|
178 */ |
|
179 class RCommsBufAccessor |
|
180 { |
|
181 public: |
|
182 inline RCommsBufAccessor(const RCommsBuf& aCommsBuf); |
|
183 inline TInt Handle() const; |
|
184 |
|
185 protected: |
|
186 const RCommsBuf& iCommsBuf; |
|
187 }; |
|
188 |
|
189 #endif // __KERNEL_MODE__ |
|
190 #include <comms-infras/commsbuf.inl> |
|
191 #endif // __COMMSBUF_H__ |
|
192 |
|
193 |