|
1 // Copyright (c) 2005-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 the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // cftransport.inl |
|
15 // |
|
16 // |
|
17 |
|
18 inline TCookie::TCookie() |
|
19 : iType(ENull), |
|
20 iChipsFollowing(0) |
|
21 { |
|
22 } |
|
23 |
|
24 // Cookies are not constructed arbitarily, instead having been generated they are bitwise copied. Consequently we don't trouble to |
|
25 // provide clever comparison operators or a copy operation, nor to ensure consistent initialisation of padding fields |
|
26 inline TBool TCookie::operator==(const TCookie& aRHS) const |
|
27 { |
|
28 ASSERT(iChipsFollowing==0 && aRHS.iChipsFollowing==0); //This is private (transport's use) information which must not be set here. |
|
29 return Mem::Compare((const TUint8*) this, sizeof(*this), (const TUint8*) &aRHS, sizeof(*this)) == 0; |
|
30 } |
|
31 |
|
32 inline TCookieAccessor::TCookieAccessor(const TCookie& aCookie) |
|
33 : iCookie(aCookie) |
|
34 { |
|
35 } |
|
36 |
|
37 inline TBool TCookieAccessor::IsNull() const |
|
38 { |
|
39 return iCookie.iType == TCookie::ENull; |
|
40 } |
|
41 |
|
42 inline TCookie::TVariety TCookieAccessor::Variety() const |
|
43 { |
|
44 return static_cast<TCookie::TVariety>(iCookie.iType); |
|
45 } |
|
46 |
|
47 inline TWorkerId TCookieAccessor::WorkerId() const |
|
48 { |
|
49 return static_cast<TWorkerId>(iCookie.iWorkerId); |
|
50 } |
|
51 |
|
52 inline TAny* TCookieAccessor::Ptr() const |
|
53 { |
|
54 return iCookie.iUn.iObjPtr.iPtr; |
|
55 } |
|
56 |
|
57 inline TUint8 TCookieAccessor::PtrSalt() const |
|
58 { |
|
59 ASSERT(Variety() == TCookie::EDispatchItfPtr || Variety() == TCookie::EDispatchItfPtrListener); |
|
60 return iCookie.iSalt; |
|
61 } |
|
62 |
|
63 inline TInt TCookieAccessor::LegacyCode() const |
|
64 { |
|
65 ASSERT(Variety() == TCookie::ELegacyId); |
|
66 return iCookie.iUn.iLegacyCode; |
|
67 } |
|
68 |
|
69 |
|
70 inline TCookieOp::TCookieOp(TCookie& aCookie) |
|
71 : TCookieAccessor(aCookie), |
|
72 iCookie(aCookie) |
|
73 { |
|
74 } |
|
75 |
|
76 /** Initialise cookie with a pointer to an object interface |
|
77 */ |
|
78 inline void TCookieOp::SetInterface(TAny* aDispatchItf, TUint8 aSalt, TWorkerId aWorkerId) |
|
79 { |
|
80 iCookie.iType = TCookie::EDispatchItfPtr; |
|
81 ASSERT(aWorkerId >= 0 && aWorkerId <= 255); |
|
82 iCookie.iWorkerId = (TUint8) aWorkerId; |
|
83 iCookie.iSalt = aSalt; |
|
84 iCookie.iUn.iObjPtr.iPtr = aDispatchItf; |
|
85 } |
|
86 |
|
87 /** Initialise pseudo-cookie for a legacy message message handler |
|
88 */ |
|
89 inline void TCookieOp::SetLegacyMessageCode(TWorkerId aWorkerId, TInt aLegacyCode) |
|
90 { |
|
91 iCookie.iType = TCookie::ELegacyId; |
|
92 ASSERT(aWorkerId >= 0 && aWorkerId <= 255); |
|
93 iCookie.iWorkerId = (TUint8) aWorkerId; |
|
94 iCookie.iUn.iLegacyCode = aLegacyCode; |
|
95 } |
|
96 |
|
97 inline void TCookieOp::SetNull() |
|
98 { |
|
99 iCookie.iType = TCookie::ENull; |
|
100 iCookie.iUn.iObjPtr.iPtr = NULL; // unnecessary really, but safety net against those who don't validate type |
|
101 } |
|
102 |
|
103 inline TCFMessage2::TCFMessage2() |
|
104 { |
|
105 } |
|
106 |
|
107 inline TCFMessage2::TCFMessage2(const TCookie& aCookie, const TDesC8& aData) |
|
108 { |
|
109 reinterpret_cast<TCookie&>(*RawBlock()) = aCookie; |
|
110 __ASSERT_ALWAYS(aData.Size() <= sizeof(*this) - sizeof(TCookie), User::Panic(KCFChannelPanic, ECFChanMsgTooBig)); |
|
111 TPtr8(const_cast<TUint8*>(RawBlock()) + sizeof(TCookie), sizeof(*this) - sizeof(TCookie)).Copy(aData); |
|
112 } |
|
113 |
|
114 inline const TCookie& TCFMessage2::Cookie() const |
|
115 { |
|
116 return reinterpret_cast<const TCookie&>(*RawBlock()); |
|
117 } |
|
118 |
|
119 inline TPtrC8 TCFMessage2::Data() const |
|
120 { |
|
121 return TPtrC8(RawBlock() + sizeof(TCookie), sizeof(*this) - sizeof(TCookie)); |
|
122 } |
|
123 /* |
|
124 inline TInt TCFMessage2::MaxEmbeddedMessageSize() |
|
125 { |
|
126 return MaxRawBlockSize() - sizeof(TCookie); |
|
127 } |
|
128 */ |
|
129 inline THeapStoredMessage* THeapStoredMessage::New(RAllocator& aHeap, const TCookie& aCookie, const TDesC8& aData) |
|
130 { |
|
131 THeapStoredMessage* self = reinterpret_cast<THeapStoredMessage*>(aHeap.Alloc( |
|
132 sizeof(THeapStoredMessage) + aData.Length() - 1)); // 1 being the sizeof(iSerialiseData); can't ref directly (CW issue) |
|
133 if(self) |
|
134 { |
|
135 self->iCookie = aCookie; |
|
136 self->iData.Set(self->iSerialisedData, aData.Length()); |
|
137 Mem::Copy(self->iSerialisedData, aData.Ptr(), aData.Length()); |
|
138 } |
|
139 return self; |
|
140 } |
|
141 |
|
142 inline const TCookie& THeapStoredMessage::Cookie() const |
|
143 { |
|
144 return iCookie; |
|
145 } |
|
146 |
|
147 inline const TPtrC8& THeapStoredMessage::Data() const |
|
148 { |
|
149 return iData; |
|
150 } |
|
151 |
|
152 |
|
153 |
|
154 // |
|
155 // Thread knowledge |
|
156 // |
|
157 |
|
158 inline TBool TWorkerThreadDataBase::IsValid() const |
|
159 { |
|
160 return iHeap != 0; |
|
161 } |
|
162 |
|
163 inline CWorkerThreadDataGlobalsBase::CWorkerThreadDataGlobalsBase() |
|
164 { |
|
165 } |
|
166 |
|
167 inline CWorkerThreadDataGlobalsBase::~CWorkerThreadDataGlobalsBase() |
|
168 { |
|
169 User::Free(iWorkers); |
|
170 } |
|
171 |
|
172 inline void CWorkerThreadDataGlobalsBase::ConstructL(TInt aWorkerDataSize, TInt TUpperThreadIdBound) |
|
173 { |
|
174 iWorkers = reinterpret_cast<TWorkerThreadDataBase*>(User::AllocZL(aWorkerDataSize * (TUpperThreadIdBound + 1))); |
|
175 } |
|
176 |
|
177 template<class TWTD, TInt TUpperThreadIdBound> |
|
178 inline CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>* CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>::NewL() |
|
179 { |
|
180 CWorkerThreadDataGlobals* self = new(ELeave) CWorkerThreadDataGlobals(); |
|
181 CleanupStack::PushL(self); |
|
182 self->ConstructL(sizeof(TWTD), TUpperThreadIdBound); |
|
183 CleanupStack::Pop(self); |
|
184 return self; |
|
185 } |
|
186 |
|
187 template<class TWTD, TInt TUpperThreadIdBound> |
|
188 inline void CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>::ConstructL(TInt aWorkerDataSize, TWorkerId aUpperBoundId) |
|
189 { |
|
190 CWorkerThreadDataGlobalsBase::ConstructL(aWorkerDataSize, aUpperBoundId); |
|
191 for(TInt i = 0; i <= TUpperThreadIdBound; ++i) |
|
192 { |
|
193 new(reinterpret_cast<TUint8*>(iWorkers) + i * aWorkerDataSize) TWTD; |
|
194 } |
|
195 } |
|
196 |
|
197 template<class TWTD, TInt TUpperThreadIdBound> |
|
198 inline TWorkerId CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>::UpperBoundWorkerId() const |
|
199 { |
|
200 return TUpperThreadIdBound; |
|
201 } |
|
202 |
|
203 template<class TWTD, TInt TUpperThreadIdBound> |
|
204 inline TWTD* CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>::GetWorkerGlobals(TWorkerId aWorker) const |
|
205 { |
|
206 __ASSERT_DEBUG(aWorker >= 0 && aWorker <= UpperBoundWorkerId(), Panic(ECFTransInvalidWorkerId)); |
|
207 return reinterpret_cast<TWTD*>(reinterpret_cast<TUint8*>(iWorkers) + sizeof(TWTD) * aWorker); |
|
208 } |
|
209 |
|
210 template<class TWTD, TInt TUpperThreadIdBound> |
|
211 inline TBool CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>::WorkerPresent(TWorkerId aId) const |
|
212 { |
|
213 return GetWorkerGlobals(aId)->IsValid(); |
|
214 } |
|
215 |
|
216 template<class TWTD, TInt TUpperThreadIdBound> |
|
217 inline RAllocator& CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>::WorkerHeap(TWorkerId aWorkerId) const |
|
218 { |
|
219 return *(GetWorkerGlobals(aWorkerId)->iHeap); |
|
220 } |
|
221 |
|
222 template<class TWTD, TInt TUpperThreadIdBound> |
|
223 inline void CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>::PanicWorker(TWorkerId aWorkerId, const TDesC& aCategory, TInt aReason) const |
|
224 { |
|
225 GetWorkerGlobals(aWorkerId)->iThread.Panic(aCategory, aReason); |
|
226 } |
|
227 |
|
228 template<class TWTD, TInt TUpperThreadIdBound> |
|
229 inline CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>::CWorkerThreadDataGlobals() |
|
230 : CWorkerThreadDataGlobalsBase() |
|
231 { |
|
232 } |
|
233 |
|
234 template<class TWTD, TInt TUpperThreadIdBound> |
|
235 inline CWorkerThreadRegister<TWTD, TUpperThreadIdBound>* CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::NewL(TWorkerId aSelfId, CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>* aGlobalThreadRegister) |
|
236 { |
|
237 return new(ELeave) CWorkerThreadRegister(aSelfId, aGlobalThreadRegister); |
|
238 } |
|
239 |
|
240 template<class TWTD, TInt TUpperThreadIdBound> |
|
241 inline TWTD* CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::GetWorkerGlobals(TWorkerId aWorker) const |
|
242 { |
|
243 __ASSERT_DEBUG(iGlobals != NULL, Panic(ECFTransThreadRegisterUnspecified)); |
|
244 __ASSERT_DEBUG(aWorker >= 0 && aWorker <= TUpperThreadIdBound, Panic(ECFTransInvalidWorkerId)); |
|
245 return iGlobals->GetWorkerGlobals(aWorker); |
|
246 } |
|
247 |
|
248 template<class TWTD, TInt TUpperThreadIdBound> |
|
249 inline TWorkerId CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::UpperBoundWorkerId() const |
|
250 { |
|
251 return TUpperThreadIdBound; |
|
252 } |
|
253 |
|
254 template<class TWTD, TInt TUpperThreadIdBound> |
|
255 inline TBool CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::WorkerPresent(TWorkerId aWorker) const |
|
256 { |
|
257 __ASSERT_DEBUG(iGlobals != NULL, Panic(ECFTransThreadRegisterUnspecified)); |
|
258 __ASSERT_DEBUG(aWorker >= 0 && aWorker <= TUpperThreadIdBound, Panic(ECFTransInvalidWorkerId)); |
|
259 return iGlobals->WorkerPresent(aWorker); |
|
260 } |
|
261 |
|
262 template<class TWTD, TInt TUpperThreadIdBound> |
|
263 inline RAllocator& CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::WorkerHeap(TWorkerId aWorker) const |
|
264 { |
|
265 __ASSERT_DEBUG(iGlobals != NULL, Panic(ECFTransThreadRegisterUnspecified)); |
|
266 __ASSERT_DEBUG(aWorker >= 0 && aWorker <= TUpperThreadIdBound, Panic(ECFTransInvalidWorkerId)); |
|
267 return iGlobals->WorkerHeap(aWorker); |
|
268 } |
|
269 |
|
270 template<class TWTD, TInt TUpperThreadIdBound> |
|
271 inline void CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::PanicWorker(TWorkerId aWorkerId, const TDesC& aCategory, TInt aReason) const |
|
272 { |
|
273 GetWorkerGlobals(aWorkerId)->iThread.Panic(aCategory, aReason); |
|
274 } |
|
275 |
|
276 template<class TWTD, TInt TUpperThreadIdBound> |
|
277 inline TWorkerId CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::SelfWorkerId() const |
|
278 { |
|
279 return iSelfId; |
|
280 } |
|
281 |
|
282 template<class TWTD, TInt TUpperThreadIdBound> |
|
283 inline TWTD* CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::GetSelfWorkerGlobals() const |
|
284 { |
|
285 __ASSERT_DEBUG(iGlobals != NULL, Panic(ECFTransThreadRegisterUnspecified)); |
|
286 return iGlobals->GetWorkerGlobals(iSelfId); |
|
287 } |
|
288 |
|
289 template<class TWTD, TInt TUpperThreadIdBound> |
|
290 inline void CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::SetGlobalThreadRegister(CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>* aGlobalThreadRegister) |
|
291 { |
|
292 iGlobals = aGlobalThreadRegister; |
|
293 } |
|
294 |
|
295 template<class TWTD, TInt TUpperThreadIdBound> |
|
296 inline CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::CWorkerThreadRegister(TWorkerId aSelfId, CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>* aGlobalThreadRegister) |
|
297 : iSelfId(aSelfId), |
|
298 iGlobals(aGlobalThreadRegister) |
|
299 { |
|
300 } |
|
301 |
|
302 inline TBool RCFInterfaceBase::IsOpen() const |
|
303 { |
|
304 return !TCookieAccessor(iRecipient).IsNull(); |
|
305 } |