1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/comms-infras/cftransport.inl Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,305 @@
1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// 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
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// cftransport.inl
1.18 +//
1.19 +//
1.20 +
1.21 +inline TCookie::TCookie()
1.22 +: iType(ENull),
1.23 + iChipsFollowing(0)
1.24 + {
1.25 + }
1.26 +
1.27 +// Cookies are not constructed arbitarily, instead having been generated they are bitwise copied. Consequently we don't trouble to
1.28 +// provide clever comparison operators or a copy operation, nor to ensure consistent initialisation of padding fields
1.29 +inline TBool TCookie::operator==(const TCookie& aRHS) const
1.30 + {
1.31 + ASSERT(iChipsFollowing==0 && aRHS.iChipsFollowing==0); //This is private (transport's use) information which must not be set here.
1.32 + return Mem::Compare((const TUint8*) this, sizeof(*this), (const TUint8*) &aRHS, sizeof(*this)) == 0;
1.33 + }
1.34 +
1.35 +inline TCookieAccessor::TCookieAccessor(const TCookie& aCookie)
1.36 +: iCookie(aCookie)
1.37 + {
1.38 + }
1.39 +
1.40 +inline TBool TCookieAccessor::IsNull() const
1.41 + {
1.42 + return iCookie.iType == TCookie::ENull;
1.43 + }
1.44 +
1.45 +inline TCookie::TVariety TCookieAccessor::Variety() const
1.46 + {
1.47 + return static_cast<TCookie::TVariety>(iCookie.iType);
1.48 + }
1.49 +
1.50 +inline TWorkerId TCookieAccessor::WorkerId() const
1.51 + {
1.52 + return static_cast<TWorkerId>(iCookie.iWorkerId);
1.53 + }
1.54 +
1.55 +inline TAny* TCookieAccessor::Ptr() const
1.56 + {
1.57 + return iCookie.iUn.iObjPtr.iPtr;
1.58 + }
1.59 +
1.60 +inline TUint8 TCookieAccessor::PtrSalt() const
1.61 + {
1.62 + ASSERT(Variety() == TCookie::EDispatchItfPtr || Variety() == TCookie::EDispatchItfPtrListener);
1.63 + return iCookie.iSalt;
1.64 + }
1.65 +
1.66 +inline TInt TCookieAccessor::LegacyCode() const
1.67 + {
1.68 + ASSERT(Variety() == TCookie::ELegacyId);
1.69 + return iCookie.iUn.iLegacyCode;
1.70 + }
1.71 +
1.72 +
1.73 +inline TCookieOp::TCookieOp(TCookie& aCookie)
1.74 +: TCookieAccessor(aCookie),
1.75 +iCookie(aCookie)
1.76 + {
1.77 + }
1.78 +
1.79 +/** Initialise cookie with a pointer to an object interface
1.80 +*/
1.81 +inline void TCookieOp::SetInterface(TAny* aDispatchItf, TUint8 aSalt, TWorkerId aWorkerId)
1.82 + {
1.83 + iCookie.iType = TCookie::EDispatchItfPtr;
1.84 + ASSERT(aWorkerId >= 0 && aWorkerId <= 255);
1.85 + iCookie.iWorkerId = (TUint8) aWorkerId;
1.86 + iCookie.iSalt = aSalt;
1.87 + iCookie.iUn.iObjPtr.iPtr = aDispatchItf;
1.88 + }
1.89 +
1.90 +/** Initialise pseudo-cookie for a legacy message message handler
1.91 +*/
1.92 +inline void TCookieOp::SetLegacyMessageCode(TWorkerId aWorkerId, TInt aLegacyCode)
1.93 + {
1.94 + iCookie.iType = TCookie::ELegacyId;
1.95 + ASSERT(aWorkerId >= 0 && aWorkerId <= 255);
1.96 + iCookie.iWorkerId = (TUint8) aWorkerId;
1.97 + iCookie.iUn.iLegacyCode = aLegacyCode;
1.98 + }
1.99 +
1.100 +inline void TCookieOp::SetNull()
1.101 + {
1.102 + iCookie.iType = TCookie::ENull;
1.103 + iCookie.iUn.iObjPtr.iPtr = NULL; // unnecessary really, but safety net against those who don't validate type
1.104 + }
1.105 +
1.106 +inline TCFMessage2::TCFMessage2()
1.107 + {
1.108 + }
1.109 +
1.110 +inline TCFMessage2::TCFMessage2(const TCookie& aCookie, const TDesC8& aData)
1.111 + {
1.112 + reinterpret_cast<TCookie&>(*RawBlock()) = aCookie;
1.113 + __ASSERT_ALWAYS(aData.Size() <= sizeof(*this) - sizeof(TCookie), User::Panic(KCFChannelPanic, ECFChanMsgTooBig));
1.114 + TPtr8(const_cast<TUint8*>(RawBlock()) + sizeof(TCookie), sizeof(*this) - sizeof(TCookie)).Copy(aData);
1.115 + }
1.116 +
1.117 +inline const TCookie& TCFMessage2::Cookie() const
1.118 + {
1.119 + return reinterpret_cast<const TCookie&>(*RawBlock());
1.120 + }
1.121 +
1.122 +inline TPtrC8 TCFMessage2::Data() const
1.123 + {
1.124 + return TPtrC8(RawBlock() + sizeof(TCookie), sizeof(*this) - sizeof(TCookie));
1.125 + }
1.126 +/*
1.127 +inline TInt TCFMessage2::MaxEmbeddedMessageSize()
1.128 + {
1.129 + return MaxRawBlockSize() - sizeof(TCookie);
1.130 + }
1.131 +*/
1.132 +inline THeapStoredMessage* THeapStoredMessage::New(RAllocator& aHeap, const TCookie& aCookie, const TDesC8& aData)
1.133 + {
1.134 + THeapStoredMessage* self = reinterpret_cast<THeapStoredMessage*>(aHeap.Alloc(
1.135 + sizeof(THeapStoredMessage) + aData.Length() - 1)); // 1 being the sizeof(iSerialiseData); can't ref directly (CW issue)
1.136 + if(self)
1.137 + {
1.138 + self->iCookie = aCookie;
1.139 + self->iData.Set(self->iSerialisedData, aData.Length());
1.140 + Mem::Copy(self->iSerialisedData, aData.Ptr(), aData.Length());
1.141 + }
1.142 + return self;
1.143 + }
1.144 +
1.145 +inline const TCookie& THeapStoredMessage::Cookie() const
1.146 + {
1.147 + return iCookie;
1.148 + }
1.149 +
1.150 +inline const TPtrC8& THeapStoredMessage::Data() const
1.151 + {
1.152 + return iData;
1.153 + }
1.154 +
1.155 +
1.156 +
1.157 +//
1.158 +// Thread knowledge
1.159 +//
1.160 +
1.161 +inline TBool TWorkerThreadDataBase::IsValid() const
1.162 + {
1.163 + return iHeap != 0;
1.164 + }
1.165 +
1.166 +inline CWorkerThreadDataGlobalsBase::CWorkerThreadDataGlobalsBase()
1.167 + {
1.168 + }
1.169 +
1.170 +inline CWorkerThreadDataGlobalsBase::~CWorkerThreadDataGlobalsBase()
1.171 + {
1.172 + User::Free(iWorkers);
1.173 + }
1.174 +
1.175 +inline void CWorkerThreadDataGlobalsBase::ConstructL(TInt aWorkerDataSize, TInt TUpperThreadIdBound)
1.176 + {
1.177 + iWorkers = reinterpret_cast<TWorkerThreadDataBase*>(User::AllocZL(aWorkerDataSize * (TUpperThreadIdBound + 1)));
1.178 + }
1.179 +
1.180 +template<class TWTD, TInt TUpperThreadIdBound>
1.181 +inline CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>* CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>::NewL()
1.182 + {
1.183 + CWorkerThreadDataGlobals* self = new(ELeave) CWorkerThreadDataGlobals();
1.184 + CleanupStack::PushL(self);
1.185 + self->ConstructL(sizeof(TWTD), TUpperThreadIdBound);
1.186 + CleanupStack::Pop(self);
1.187 + return self;
1.188 + }
1.189 +
1.190 +template<class TWTD, TInt TUpperThreadIdBound>
1.191 +inline void CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>::ConstructL(TInt aWorkerDataSize, TWorkerId aUpperBoundId)
1.192 + {
1.193 + CWorkerThreadDataGlobalsBase::ConstructL(aWorkerDataSize, aUpperBoundId);
1.194 + for(TInt i = 0; i <= TUpperThreadIdBound; ++i)
1.195 + {
1.196 + new(reinterpret_cast<TUint8*>(iWorkers) + i * aWorkerDataSize) TWTD;
1.197 + }
1.198 + }
1.199 +
1.200 +template<class TWTD, TInt TUpperThreadIdBound>
1.201 +inline TWorkerId CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>::UpperBoundWorkerId() const
1.202 + {
1.203 + return TUpperThreadIdBound;
1.204 + }
1.205 +
1.206 +template<class TWTD, TInt TUpperThreadIdBound>
1.207 +inline TWTD* CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>::GetWorkerGlobals(TWorkerId aWorker) const
1.208 + {
1.209 + __ASSERT_DEBUG(aWorker >= 0 && aWorker <= UpperBoundWorkerId(), Panic(ECFTransInvalidWorkerId));
1.210 + return reinterpret_cast<TWTD*>(reinterpret_cast<TUint8*>(iWorkers) + sizeof(TWTD) * aWorker);
1.211 + }
1.212 +
1.213 +template<class TWTD, TInt TUpperThreadIdBound>
1.214 +inline TBool CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>::WorkerPresent(TWorkerId aId) const
1.215 + {
1.216 + return GetWorkerGlobals(aId)->IsValid();
1.217 + }
1.218 +
1.219 +template<class TWTD, TInt TUpperThreadIdBound>
1.220 +inline RAllocator& CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>::WorkerHeap(TWorkerId aWorkerId) const
1.221 + {
1.222 + return *(GetWorkerGlobals(aWorkerId)->iHeap);
1.223 + }
1.224 +
1.225 +template<class TWTD, TInt TUpperThreadIdBound>
1.226 +inline void CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>::PanicWorker(TWorkerId aWorkerId, const TDesC& aCategory, TInt aReason) const
1.227 + {
1.228 + GetWorkerGlobals(aWorkerId)->iThread.Panic(aCategory, aReason);
1.229 + }
1.230 +
1.231 +template<class TWTD, TInt TUpperThreadIdBound>
1.232 +inline CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>::CWorkerThreadDataGlobals()
1.233 +: CWorkerThreadDataGlobalsBase()
1.234 + {
1.235 + }
1.236 +
1.237 +template<class TWTD, TInt TUpperThreadIdBound>
1.238 +inline CWorkerThreadRegister<TWTD, TUpperThreadIdBound>* CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::NewL(TWorkerId aSelfId, CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>* aGlobalThreadRegister)
1.239 + {
1.240 + return new(ELeave) CWorkerThreadRegister(aSelfId, aGlobalThreadRegister);
1.241 + }
1.242 +
1.243 +template<class TWTD, TInt TUpperThreadIdBound>
1.244 +inline TWTD* CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::GetWorkerGlobals(TWorkerId aWorker) const
1.245 + {
1.246 + __ASSERT_DEBUG(iGlobals != NULL, Panic(ECFTransThreadRegisterUnspecified));
1.247 + __ASSERT_DEBUG(aWorker >= 0 && aWorker <= TUpperThreadIdBound, Panic(ECFTransInvalidWorkerId));
1.248 + return iGlobals->GetWorkerGlobals(aWorker);
1.249 + }
1.250 +
1.251 +template<class TWTD, TInt TUpperThreadIdBound>
1.252 +inline TWorkerId CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::UpperBoundWorkerId() const
1.253 + {
1.254 + return TUpperThreadIdBound;
1.255 + }
1.256 +
1.257 +template<class TWTD, TInt TUpperThreadIdBound>
1.258 +inline TBool CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::WorkerPresent(TWorkerId aWorker) const
1.259 + {
1.260 + __ASSERT_DEBUG(iGlobals != NULL, Panic(ECFTransThreadRegisterUnspecified));
1.261 + __ASSERT_DEBUG(aWorker >= 0 && aWorker <= TUpperThreadIdBound, Panic(ECFTransInvalidWorkerId));
1.262 + return iGlobals->WorkerPresent(aWorker);
1.263 + }
1.264 +
1.265 +template<class TWTD, TInt TUpperThreadIdBound>
1.266 +inline RAllocator& CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::WorkerHeap(TWorkerId aWorker) const
1.267 + {
1.268 + __ASSERT_DEBUG(iGlobals != NULL, Panic(ECFTransThreadRegisterUnspecified));
1.269 + __ASSERT_DEBUG(aWorker >= 0 && aWorker <= TUpperThreadIdBound, Panic(ECFTransInvalidWorkerId));
1.270 + return iGlobals->WorkerHeap(aWorker);
1.271 + }
1.272 +
1.273 +template<class TWTD, TInt TUpperThreadIdBound>
1.274 +inline void CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::PanicWorker(TWorkerId aWorkerId, const TDesC& aCategory, TInt aReason) const
1.275 + {
1.276 + GetWorkerGlobals(aWorkerId)->iThread.Panic(aCategory, aReason);
1.277 + }
1.278 +
1.279 +template<class TWTD, TInt TUpperThreadIdBound>
1.280 +inline TWorkerId CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::SelfWorkerId() const
1.281 + {
1.282 + return iSelfId;
1.283 + }
1.284 +
1.285 +template<class TWTD, TInt TUpperThreadIdBound>
1.286 +inline TWTD* CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::GetSelfWorkerGlobals() const
1.287 + {
1.288 + __ASSERT_DEBUG(iGlobals != NULL, Panic(ECFTransThreadRegisterUnspecified));
1.289 + return iGlobals->GetWorkerGlobals(iSelfId);
1.290 + }
1.291 +
1.292 +template<class TWTD, TInt TUpperThreadIdBound>
1.293 +inline void CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::SetGlobalThreadRegister(CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>* aGlobalThreadRegister)
1.294 + {
1.295 + iGlobals = aGlobalThreadRegister;
1.296 + }
1.297 +
1.298 +template<class TWTD, TInt TUpperThreadIdBound>
1.299 +inline CWorkerThreadRegister<TWTD, TUpperThreadIdBound>::CWorkerThreadRegister(TWorkerId aSelfId, CWorkerThreadDataGlobals<TWTD, TUpperThreadIdBound>* aGlobalThreadRegister)
1.300 +: iSelfId(aSelfId),
1.301 +iGlobals(aGlobalThreadRegister)
1.302 + {
1.303 + }
1.304 +
1.305 +inline TBool RCFInterfaceBase::IsOpen() const
1.306 + {
1.307 + return !TCookieAccessor(iRecipient).IsNull();
1.308 + }