bluetooth/btstack/avdtp/avdtpTransportSession.h
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 2003-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:
       
    14 // Defines the avdtp transport session base class
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #ifndef TRANSPORTSESSION_H
       
    24 #define TRANSPORTSESSION_H
       
    25 
       
    26 #include <es_mbuf.h>
       
    27 #include <bt_sock.h>
       
    28 #include <bluetoothav.h>
       
    29 #include "avdtpAllocators.h"
       
    30 
       
    31 class CUserPlaneTransportSession;
       
    32 class CTransportSession;
       
    33 class CTransportChannel;
       
    34 class CAvdtpProtocol;
       
    35 class CAvdtpSAP;
       
    36 class CAVStream;
       
    37 
       
    38 NONSHARABLE_STRUCT(TTransportBinding)
       
    39 	{
       
    40 	CUserPlaneTransportSession* iSession;
       
    41 	CTransportChannel* iChannel;
       
    42 	};
       
    43 
       
    44 
       
    45 // starting off life as RMBufChain - move to RAvdtpMessage later..
       
    46 // but actually it's only muxchannel that needs to do stuff!
       
    47 // so might be best for the pool to reatin just mbufchains and
       
    48 // for muxchannel to prepend mux data later
       
    49 static const TUint KDefaultPacketPool = 8;
       
    50 
       
    51 NONSHARABLE_CLASS(RPacketPool)
       
    52 	{
       
    53 public:
       
    54 	RPacketPool();
       
    55 	TInt Create(TUint aSize, TBool aBalk);
       
    56 	TInt Add(RMBufChain& aChain, TInt& aWrappedChainSize);
       
    57 	TInt Remove(RMBufChain& aReturnedMBufChain);
       
    58 	TInt SetCeiling(TInt aCeiling);
       
    59 	void Close();
       
    60 	TInt Resize(TUint aSize);
       
    61 	inline TBool CanBalk() const;
       
    62 	inline TInt Count() const;
       
    63 	inline void SetBalking(TBool aNewBalkSetting);
       
    64 private:
       
    65 	inline TInt OldestIndex() const;
       
    66 	TInt AllocatePool(TUint aSize);
       
    67 	void AllocatePoolL(TUint aSize);
       
    68 	void CreateEntryL();
       
    69 	void DestroyEntry(TUint aIndex);
       
    70 	
       
    71 private:
       
    72 	RArray<RMBufChain>		iPool;
       
    73 	TUint					iNewestIndex; // the position at which last inbound chain assigned
       
    74 	TUint					iOldestIndex;
       
    75 	TBool					iBalk;	// if false, wrapping occurs
       
    76 	};
       
    77 
       
    78 inline TBool RPacketPool:: CanBalk() const
       
    79 	{
       
    80 	return iBalk;
       
    81 	}
       
    82 	
       
    83 inline TInt RPacketPool::Count() const
       
    84 	{
       
    85 	return iPool.Count();
       
    86 	}
       
    87 	
       
    88 inline void RPacketPool::SetBalking(TBool aNewBalkSetting)
       
    89 	{
       
    90 	iBalk = aNewBalkSetting;
       
    91 	}
       
    92 
       
    93 NONSHARABLE_CLASS(CTransportSession) : public CBase
       
    94 /**
       
    95 	Intended for derivation by all stream bearers
       
    96 	Where there is clear generality the base class provides implementations
       
    97 	However this class can't begin to think what to do on some downcalls so
       
    98 	it mandates that derivers implement these
       
    99 	
       
   100 */
       
   101 	{
       
   102 public:
       
   103 	virtual TInt ActiveOpen()=0;
       
   104 	virtual TInt SetOption(TUint aLevel, TUint aName, const TDesC8 &aOption);
       
   105 	virtual TInt GetOption(TUint aLevel, TUint aName, TDes8& aOption) const;
       
   106 	virtual void Ioctl(TUint aLevel, TUint aName, const TDesC8* aOption);
       
   107 	virtual void CancelIoctl(TUint aLevel, TUint aName);
       
   108 	virtual void Start();
       
   109 	virtual void Shutdown();
       
   110 	virtual void FastShutdown();
       
   111 	virtual TInt Send(RMBufChain& aData, TUint aOptions, TSockAddr* aAddr)=0;
       
   112 	virtual TInt GetData(RMBufChain& aData)=0;
       
   113 	void Ready(const TBTDevAddr& aRemoteAddr); //addr passed cos possibly passive
       
   114 	inline TBTDevAddr RemoteAddress() const;
       
   115 	inline TAvdtpTransportSessionType SessionType() const;
       
   116 	inline void SetRemoteAddress(const TBTDevAddr& aSockAddr);
       
   117 	
       
   118 	void LocalName(TAvdtpSockAddr& aAddr) const;
       
   119 	void RemName(TAvdtpSockAddr& aAddr) const;
       
   120 	TInt SetLocalName(TAvdtpSockAddr& aAddr);
       
   121 	TInt SetRemoteName(TAvdtpSockAddr& aAddr);
       
   122 	~CTransportSession();
       
   123 	
       
   124 protected:
       
   125 	CTransportSession(CAvdtpProtocol& aProtocol,
       
   126 					  CAvdtpSAP& aSAP,
       
   127 					  TAvdtpTransportSessionType aType);
       
   128 	void ConstructL();
       
   129 	inline TSEID SEID() const;
       
   130 	inline void SetSEID(TSEID aSEID);
       
   131 protected:
       
   132 	CAvdtpSAP&			iSAP; // our (parent) SAP
       
   133 	CAvdtpProtocol&		iProtocol;
       
   134 protected:
       
   135 	enum TAvdtpSAPShutdownReceived
       
   136 		{
       
   137 		ENone,
       
   138 		ENormal,
       
   139 		EImmediate,
       
   140 		};
       
   141 	virtual void DoShutdown()=0;
       
   142 	TAvdtpSAPShutdownReceived	iSAPShutdown;
       
   143 private:
       
   144 	// private to stop derivers playing around with session type later
       
   145 	TAvdtpSockAddr		iAddress;
       
   146 	};
       
   147 	
       
   148 
       
   149 NONSHARABLE_CLASS(CUserPlaneTransportSession) : public CTransportSession 
       
   150 	{
       
   151 public:
       
   152 	inline TTSID TSID() const;
       
   153 	inline TSEID SEID() const;
       
   154 	void ChannelError(TInt aError);	// informs stream, which may call back into error
       
   155 	virtual void StreamError(TInt aError);	// default just passes to sap
       
   156 	virtual void StreamReleased();
       
   157 	virtual TInt Send(RMBufChain& aData, TUint aOptions, TSockAddr* aAddr)=0;
       
   158 	virtual TInt GetData(RMBufChain& aData);
       
   159 	virtual void CanSend()=0;
       
   160 	virtual void ReceivePacketLost();
       
   161 	
       
   162 //	void NewData(TUint aCount);
       
   163 	void NewData(RMBufChain& aChain);
       
   164 	virtual TInt ActiveOpen();
       
   165 protected:	
       
   166 	CUserPlaneTransportSession(CAvdtpProtocol& aProtocol,
       
   167 					  CAvdtpSAP& aSAP,
       
   168 					  TAvdtpTransportSessionType aType,
       
   169 					  CAVStream& aStream);
       
   170 	void ConstructL();
       
   171 	~CUserPlaneTransportSession();
       
   172 	void LeaveTransportChannel();
       
   173 	
       
   174 	virtual TInt DoActiveOpen()=0;	// could bring this into this class
       
   175 	virtual void DoShutdown();
       
   176 protected:
       
   177 	RTSID				iTSID;
       
   178 	RPacketPool			iReceivePool;
       
   179 	RPacketPool			iSendPool;
       
   180 	CAVStream*			iStream; // the stream we're part of, may become NULL
       
   181 	CTransportChannel*	iTransportChannel; //non-owned
       
   182 	TBool				iTransportChannelBlocked;
       
   183 	TInt				iRemainingDataInChannel;
       
   184 	};
       
   185 
       
   186 
       
   187 inline TAvdtpTransportSessionType CTransportSession::SessionType() const
       
   188 	{
       
   189 	return iAddress.Session();
       
   190 	}
       
   191 	
       
   192 
       
   193 inline TSEID CTransportSession::SEID() const
       
   194 	{
       
   195 	return iAddress.SEID();
       
   196 	}
       
   197 
       
   198 inline void CTransportSession::SetSEID(TSEID aSEID)
       
   199 	{
       
   200 	iAddress.SetSEID(aSEID);
       
   201 	}
       
   202 
       
   203 inline TSEID CUserPlaneTransportSession::SEID() const
       
   204 	{
       
   205 	return CTransportSession::SEID();
       
   206 	}
       
   207 
       
   208 inline TTSID CUserPlaneTransportSession::TSID() const
       
   209 	{
       
   210 	return iTSID.TSID();
       
   211 	}
       
   212 
       
   213 inline TBTDevAddr CTransportSession::RemoteAddress() const
       
   214 	{
       
   215 	return iAddress.BTAddr();
       
   216 	}
       
   217 	
       
   218 inline void CTransportSession::SetRemoteAddress(const TBTDevAddr& aDevAddr)
       
   219 	{
       
   220 	iAddress.SetBTAddr(aDevAddr);
       
   221 	}
       
   222 	
       
   223 #endif //TRANSPORTSESSION_H