diff -r 666f914201fb -r 2fe1408b6811 epoc32/include/comms-infras/cftransport.inl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/epoc32/include/comms-infras/cftransport.inl Tue Mar 16 16:12:26 2010 +0000 @@ -0,0 +1,305 @@ +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// 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 +// which accompanies this distribution, and is available +// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// cftransport.inl +// +// + +inline TCookie::TCookie() +: iType(ENull), + iChipsFollowing(0) + { + } + +// Cookies are not constructed arbitarily, instead having been generated they are bitwise copied. Consequently we don't trouble to +// provide clever comparison operators or a copy operation, nor to ensure consistent initialisation of padding fields +inline TBool TCookie::operator==(const TCookie& aRHS) const + { + ASSERT(iChipsFollowing==0 && aRHS.iChipsFollowing==0); //This is private (transport's use) information which must not be set here. + return Mem::Compare((const TUint8*) this, sizeof(*this), (const TUint8*) &aRHS, sizeof(*this)) == 0; + } + +inline TCookieAccessor::TCookieAccessor(const TCookie& aCookie) +: iCookie(aCookie) + { + } + +inline TBool TCookieAccessor::IsNull() const + { + return iCookie.iType == TCookie::ENull; + } + +inline TCookie::TVariety TCookieAccessor::Variety() const + { + return static_cast(iCookie.iType); + } + +inline TWorkerId TCookieAccessor::WorkerId() const + { + return static_cast(iCookie.iWorkerId); + } + +inline TAny* TCookieAccessor::Ptr() const + { + return iCookie.iUn.iObjPtr.iPtr; + } + +inline TUint8 TCookieAccessor::PtrSalt() const + { + ASSERT(Variety() == TCookie::EDispatchItfPtr || Variety() == TCookie::EDispatchItfPtrListener); + return iCookie.iSalt; + } + +inline TInt TCookieAccessor::LegacyCode() const + { + ASSERT(Variety() == TCookie::ELegacyId); + return iCookie.iUn.iLegacyCode; + } + + +inline TCookieOp::TCookieOp(TCookie& aCookie) +: TCookieAccessor(aCookie), +iCookie(aCookie) + { + } + +/** Initialise cookie with a pointer to an object interface +*/ +inline void TCookieOp::SetInterface(TAny* aDispatchItf, TUint8 aSalt, TWorkerId aWorkerId) + { + iCookie.iType = TCookie::EDispatchItfPtr; + ASSERT(aWorkerId >= 0 && aWorkerId <= 255); + iCookie.iWorkerId = (TUint8) aWorkerId; + iCookie.iSalt = aSalt; + iCookie.iUn.iObjPtr.iPtr = aDispatchItf; + } + +/** Initialise pseudo-cookie for a legacy message message handler +*/ +inline void TCookieOp::SetLegacyMessageCode(TWorkerId aWorkerId, TInt aLegacyCode) + { + iCookie.iType = TCookie::ELegacyId; + ASSERT(aWorkerId >= 0 && aWorkerId <= 255); + iCookie.iWorkerId = (TUint8) aWorkerId; + iCookie.iUn.iLegacyCode = aLegacyCode; + } + +inline void TCookieOp::SetNull() + { + iCookie.iType = TCookie::ENull; + iCookie.iUn.iObjPtr.iPtr = NULL; // unnecessary really, but safety net against those who don't validate type + } + +inline TCFMessage2::TCFMessage2() + { + } + +inline TCFMessage2::TCFMessage2(const TCookie& aCookie, const TDesC8& aData) + { + reinterpret_cast(*RawBlock()) = aCookie; + __ASSERT_ALWAYS(aData.Size() <= sizeof(*this) - sizeof(TCookie), User::Panic(KCFChannelPanic, ECFChanMsgTooBig)); + TPtr8(const_cast(RawBlock()) + sizeof(TCookie), sizeof(*this) - sizeof(TCookie)).Copy(aData); + } + +inline const TCookie& TCFMessage2::Cookie() const + { + return reinterpret_cast(*RawBlock()); + } + +inline TPtrC8 TCFMessage2::Data() const + { + return TPtrC8(RawBlock() + sizeof(TCookie), sizeof(*this) - sizeof(TCookie)); + } +/* +inline TInt TCFMessage2::MaxEmbeddedMessageSize() + { + return MaxRawBlockSize() - sizeof(TCookie); + } +*/ +inline THeapStoredMessage* THeapStoredMessage::New(RAllocator& aHeap, const TCookie& aCookie, const TDesC8& aData) + { + THeapStoredMessage* self = reinterpret_cast(aHeap.Alloc( + sizeof(THeapStoredMessage) + aData.Length() - 1)); // 1 being the sizeof(iSerialiseData); can't ref directly (CW issue) + if(self) + { + self->iCookie = aCookie; + self->iData.Set(self->iSerialisedData, aData.Length()); + Mem::Copy(self->iSerialisedData, aData.Ptr(), aData.Length()); + } + return self; + } + +inline const TCookie& THeapStoredMessage::Cookie() const + { + return iCookie; + } + +inline const TPtrC8& THeapStoredMessage::Data() const + { + return iData; + } + + + +// +// Thread knowledge +// + +inline TBool TWorkerThreadDataBase::IsValid() const + { + return iHeap != 0; + } + +inline CWorkerThreadDataGlobalsBase::CWorkerThreadDataGlobalsBase() + { + } + +inline CWorkerThreadDataGlobalsBase::~CWorkerThreadDataGlobalsBase() + { + User::Free(iWorkers); + } + +inline void CWorkerThreadDataGlobalsBase::ConstructL(TInt aWorkerDataSize, TInt TUpperThreadIdBound) + { + iWorkers = reinterpret_cast(User::AllocZL(aWorkerDataSize * (TUpperThreadIdBound + 1))); + } + +template +inline CWorkerThreadDataGlobals* CWorkerThreadDataGlobals::NewL() + { + CWorkerThreadDataGlobals* self = new(ELeave) CWorkerThreadDataGlobals(); + CleanupStack::PushL(self); + self->ConstructL(sizeof(TWTD), TUpperThreadIdBound); + CleanupStack::Pop(self); + return self; + } + +template +inline void CWorkerThreadDataGlobals::ConstructL(TInt aWorkerDataSize, TWorkerId aUpperBoundId) + { + CWorkerThreadDataGlobalsBase::ConstructL(aWorkerDataSize, aUpperBoundId); + for(TInt i = 0; i <= TUpperThreadIdBound; ++i) + { + new(reinterpret_cast(iWorkers) + i * aWorkerDataSize) TWTD; + } + } + +template +inline TWorkerId CWorkerThreadDataGlobals::UpperBoundWorkerId() const + { + return TUpperThreadIdBound; + } + +template +inline TWTD* CWorkerThreadDataGlobals::GetWorkerGlobals(TWorkerId aWorker) const + { + __ASSERT_DEBUG(aWorker >= 0 && aWorker <= UpperBoundWorkerId(), Panic(ECFTransInvalidWorkerId)); + return reinterpret_cast(reinterpret_cast(iWorkers) + sizeof(TWTD) * aWorker); + } + +template +inline TBool CWorkerThreadDataGlobals::WorkerPresent(TWorkerId aId) const + { + return GetWorkerGlobals(aId)->IsValid(); + } + +template +inline RAllocator& CWorkerThreadDataGlobals::WorkerHeap(TWorkerId aWorkerId) const + { + return *(GetWorkerGlobals(aWorkerId)->iHeap); + } + +template +inline void CWorkerThreadDataGlobals::PanicWorker(TWorkerId aWorkerId, const TDesC& aCategory, TInt aReason) const + { + GetWorkerGlobals(aWorkerId)->iThread.Panic(aCategory, aReason); + } + +template +inline CWorkerThreadDataGlobals::CWorkerThreadDataGlobals() +: CWorkerThreadDataGlobalsBase() + { + } + +template +inline CWorkerThreadRegister* CWorkerThreadRegister::NewL(TWorkerId aSelfId, CWorkerThreadDataGlobals* aGlobalThreadRegister) + { + return new(ELeave) CWorkerThreadRegister(aSelfId, aGlobalThreadRegister); + } + +template +inline TWTD* CWorkerThreadRegister::GetWorkerGlobals(TWorkerId aWorker) const + { + __ASSERT_DEBUG(iGlobals != NULL, Panic(ECFTransThreadRegisterUnspecified)); + __ASSERT_DEBUG(aWorker >= 0 && aWorker <= TUpperThreadIdBound, Panic(ECFTransInvalidWorkerId)); + return iGlobals->GetWorkerGlobals(aWorker); + } + +template +inline TWorkerId CWorkerThreadRegister::UpperBoundWorkerId() const + { + return TUpperThreadIdBound; + } + +template +inline TBool CWorkerThreadRegister::WorkerPresent(TWorkerId aWorker) const + { + __ASSERT_DEBUG(iGlobals != NULL, Panic(ECFTransThreadRegisterUnspecified)); + __ASSERT_DEBUG(aWorker >= 0 && aWorker <= TUpperThreadIdBound, Panic(ECFTransInvalidWorkerId)); + return iGlobals->WorkerPresent(aWorker); + } + +template +inline RAllocator& CWorkerThreadRegister::WorkerHeap(TWorkerId aWorker) const + { + __ASSERT_DEBUG(iGlobals != NULL, Panic(ECFTransThreadRegisterUnspecified)); + __ASSERT_DEBUG(aWorker >= 0 && aWorker <= TUpperThreadIdBound, Panic(ECFTransInvalidWorkerId)); + return iGlobals->WorkerHeap(aWorker); + } + +template +inline void CWorkerThreadRegister::PanicWorker(TWorkerId aWorkerId, const TDesC& aCategory, TInt aReason) const + { + GetWorkerGlobals(aWorkerId)->iThread.Panic(aCategory, aReason); + } + +template +inline TWorkerId CWorkerThreadRegister::SelfWorkerId() const + { + return iSelfId; + } + +template +inline TWTD* CWorkerThreadRegister::GetSelfWorkerGlobals() const + { + __ASSERT_DEBUG(iGlobals != NULL, Panic(ECFTransThreadRegisterUnspecified)); + return iGlobals->GetWorkerGlobals(iSelfId); + } + +template +inline void CWorkerThreadRegister::SetGlobalThreadRegister(CWorkerThreadDataGlobals* aGlobalThreadRegister) + { + iGlobals = aGlobalThreadRegister; + } + +template +inline CWorkerThreadRegister::CWorkerThreadRegister(TWorkerId aSelfId, CWorkerThreadDataGlobals* aGlobalThreadRegister) +: iSelfId(aSelfId), +iGlobals(aGlobalThreadRegister) + { + } + +inline TBool RCFInterfaceBase::IsOpen() const + { + return !TCookieAccessor(iRecipient).IsNull(); + }