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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
18 inline TCookie::TCookie()
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
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;
32 inline TCookieAccessor::TCookieAccessor(const TCookie& aCookie)
37 inline TBool TCookieAccessor::IsNull() const
39 return iCookie.iType == TCookie::ENull;
42 inline TCookie::TVariety TCookieAccessor::Variety() const
44 return static_cast<TCookie::TVariety>(iCookie.iType);
47 inline TWorkerId TCookieAccessor::WorkerId() const
49 return static_cast<TWorkerId>(iCookie.iWorkerId);
52 inline TAny* TCookieAccessor::Ptr() const
54 return iCookie.iUn.iObjPtr.iPtr;
57 inline TUint8 TCookieAccessor::PtrSalt() const
59 ASSERT(Variety() == TCookie::EDispatchItfPtr || Variety() == TCookie::EDispatchItfPtrListener);
63 inline TInt TCookieAccessor::LegacyCode() const
65 ASSERT(Variety() == TCookie::ELegacyId);
66 return iCookie.iUn.iLegacyCode;
70 inline TCookieOp::TCookieOp(TCookie& aCookie)
71 : TCookieAccessor(aCookie),
76 /** Initialise cookie with a pointer to an object interface
78 inline void TCookieOp::SetInterface(TAny* aDispatchItf, TUint8 aSalt, TWorkerId aWorkerId)
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;
87 /** Initialise pseudo-cookie for a legacy message message handler
89 inline void TCookieOp::SetLegacyMessageCode(TWorkerId aWorkerId, TInt aLegacyCode)
91 iCookie.iType = TCookie::ELegacyId;
92 ASSERT(aWorkerId >= 0 && aWorkerId <= 255);
93 iCookie.iWorkerId = (TUint8) aWorkerId;
94 iCookie.iUn.iLegacyCode = aLegacyCode;
97 inline void TCookieOp::SetNull()
99 iCookie.iType = TCookie::ENull;
100 iCookie.iUn.iObjPtr.iPtr = NULL; // unnecessary really, but safety net against those who don't validate type
103 inline TCFMessage2::TCFMessage2()
107 inline TCFMessage2::TCFMessage2(const TCookie& aCookie, const TDesC8& aData)
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);
114 inline const TCookie& TCFMessage2::Cookie() const
116 return reinterpret_cast<const TCookie&>(*RawBlock());
119 inline TPtrC8 TCFMessage2::Data() const
121 return TPtrC8(RawBlock() + sizeof(TCookie), sizeof(*this) - sizeof(TCookie));
124 inline TInt TCFMessage2::MaxEmbeddedMessageSize()
126 return MaxRawBlockSize() - sizeof(TCookie);
129 inline THeapStoredMessage* THeapStoredMessage::New(RAllocator& aHeap, const TCookie& aCookie, const TDesC8& aData)
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)
135 self->iCookie = aCookie;
136 self->iData.Set(self->iSerialisedData, aData.Length());
137 Mem::Copy(self->iSerialisedData, aData.Ptr(), aData.Length());
142 inline const TCookie& THeapStoredMessage::Cookie() const
147 inline const TPtrC8& THeapStoredMessage::Data() const
158 inline TBool TWorkerThreadDataBase::IsValid() const
163 inline CWorkerThreadDataGlobalsBase::CWorkerThreadDataGlobalsBase()
167 inline CWorkerThreadDataGlobalsBase::~CWorkerThreadDataGlobalsBase()
169 User::Free(iWorkers);
172 inline void CWorkerThreadDataGlobalsBase::ConstructL(TInt aWorkerDataSize, TInt TUpperThreadIdBound)
174 iWorkers = reinterpret_cast<TWorkerThreadDataBase*>(User::AllocZL(aWorkerDataSize * (TUpperThreadIdBound + 1)));
177 template<class TWTD, TInt TUpperThreadIdBound>
178 inline CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>* CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>::NewL()
180 CWorkerThreadDataGlobals* self = new(ELeave) CWorkerThreadDataGlobals();
181 CleanupStack::PushL(self);
182 self->ConstructL(sizeof(TWTD), TUpperThreadIdBound);
183 CleanupStack::Pop(self);
187 template<class TWTD, TInt TUpperThreadIdBound>
188 inline void CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>::ConstructL(TInt aWorkerDataSize, TWorkerId aUpperBoundId)
190 CWorkerThreadDataGlobalsBase::ConstructL(aWorkerDataSize, aUpperBoundId);
191 for(TInt i = 0; i <= TUpperThreadIdBound; ++i)
193 new(reinterpret_cast<TUint8*>(iWorkers) + i * aWorkerDataSize) TWTD;
197 template<class TWTD, TInt TUpperThreadIdBound>
198 inline TWorkerId CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>::UpperBoundWorkerId() const
200 return TUpperThreadIdBound;
203 template<class TWTD, TInt TUpperThreadIdBound>
204 inline TWTD* CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>::GetWorkerGlobals(TWorkerId aWorker) const
206 __ASSERT_DEBUG(aWorker >= 0 && aWorker <= UpperBoundWorkerId(), Panic(ECFTransInvalidWorkerId));
207 return reinterpret_cast<TWTD*>(reinterpret_cast<TUint8*>(iWorkers) + sizeof(TWTD) * aWorker);
210 template<class TWTD, TInt TUpperThreadIdBound>
211 inline TBool CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>::WorkerPresent(TWorkerId aId) const
213 return GetWorkerGlobals(aId)->IsValid();
216 template<class TWTD, TInt TUpperThreadIdBound>
217 inline RAllocator& CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>::WorkerHeap(TWorkerId aWorkerId) const
219 return *(GetWorkerGlobals(aWorkerId)->iHeap);
222 template<class TWTD, TInt TUpperThreadIdBound>
223 inline void CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>::PanicWorker(TWorkerId aWorkerId, const TDesC& aCategory, TInt aReason) const
225 GetWorkerGlobals(aWorkerId)->iThread.Panic(aCategory, aReason);
228 template<class TWTD, TInt TUpperThreadIdBound>
229 inline CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>::CWorkerThreadDataGlobals()
230 : CWorkerThreadDataGlobalsBase()
234 template<class TWTD, TInt TUpperThreadIdBound>
235 inline CWorkerThreadRegister<TWTD, TUpperThreadIdBound>* CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::NewL(TWorkerId aSelfId, CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>* aGlobalThreadRegister)
237 return new(ELeave) CWorkerThreadRegister(aSelfId, aGlobalThreadRegister);
240 template<class TWTD, TInt TUpperThreadIdBound>
241 inline TWTD* CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::GetWorkerGlobals(TWorkerId aWorker) const
243 __ASSERT_DEBUG(iGlobals != NULL, Panic(ECFTransThreadRegisterUnspecified));
244 __ASSERT_DEBUG(aWorker >= 0 && aWorker <= TUpperThreadIdBound, Panic(ECFTransInvalidWorkerId));
245 return iGlobals->GetWorkerGlobals(aWorker);
248 template<class TWTD, TInt TUpperThreadIdBound>
249 inline TWorkerId CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::UpperBoundWorkerId() const
251 return TUpperThreadIdBound;
254 template<class TWTD, TInt TUpperThreadIdBound>
255 inline TBool CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::WorkerPresent(TWorkerId aWorker) const
257 __ASSERT_DEBUG(iGlobals != NULL, Panic(ECFTransThreadRegisterUnspecified));
258 __ASSERT_DEBUG(aWorker >= 0 && aWorker <= TUpperThreadIdBound, Panic(ECFTransInvalidWorkerId));
259 return iGlobals->WorkerPresent(aWorker);
262 template<class TWTD, TInt TUpperThreadIdBound>
263 inline RAllocator& CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::WorkerHeap(TWorkerId aWorker) const
265 __ASSERT_DEBUG(iGlobals != NULL, Panic(ECFTransThreadRegisterUnspecified));
266 __ASSERT_DEBUG(aWorker >= 0 && aWorker <= TUpperThreadIdBound, Panic(ECFTransInvalidWorkerId));
267 return iGlobals->WorkerHeap(aWorker);
270 template<class TWTD, TInt TUpperThreadIdBound>
271 inline void CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::PanicWorker(TWorkerId aWorkerId, const TDesC& aCategory, TInt aReason) const
273 GetWorkerGlobals(aWorkerId)->iThread.Panic(aCategory, aReason);
276 template<class TWTD, TInt TUpperThreadIdBound>
277 inline TWorkerId CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::SelfWorkerId() const
282 template<class TWTD, TInt TUpperThreadIdBound>
283 inline TWTD* CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::GetSelfWorkerGlobals() const
285 __ASSERT_DEBUG(iGlobals != NULL, Panic(ECFTransThreadRegisterUnspecified));
286 return iGlobals->GetWorkerGlobals(iSelfId);
289 template<class TWTD, TInt TUpperThreadIdBound>
290 inline void CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::SetGlobalThreadRegister(CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>* aGlobalThreadRegister)
292 iGlobals = aGlobalThreadRegister;
295 template<class TWTD, TInt TUpperThreadIdBound>
296 inline CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::CWorkerThreadRegister(TWorkerId aSelfId, CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>* aGlobalThreadRegister)
298 iGlobals(aGlobalThreadRegister)
302 inline TBool RCFInterfaceBase::IsOpen() const
304 return !TCookieAccessor(iRecipient).IsNull();