bluetooth/btstack/avctp/avctpPacketMgr.h
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     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 "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 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalComponent
       
    19 */
       
    20 
       
    21 
       
    22 /*
       
    23  the incoming assembler owns a chain to try to preserve the idea to not allocate
       
    24  the outgoing fragmenter owns the HOutboundSDU
       
    25  
       
    26  the inbound one could change, but it may be ok to only transfer the MBufChain into the HInboundSDU when we are happy that
       
    27  we have something worth holding onto on a queue
       
    28  */
       
    29 
       
    30 #ifndef AVCTPPACKETMGR_H
       
    31 #define AVCTPPACKETMGR_H
       
    32 
       
    33 #include "avctppacket.h"
       
    34 
       
    35 // Forward declarations
       
    36 class CAvctpProtocol;
       
    37 class CAvctpTransport;
       
    38 class CPartialIncomingSdu;
       
    39 class CPartialOutgoingSdu;
       
    40 class HAvctpOutgoingSdu;
       
    41 class RMBufChain;
       
    42 class CAvctpPacketMgr;
       
    43 
       
    44 NONSHARABLE_CLASS(MAvctpSDUSender)
       
    45 	{
       
    46 public:
       
    47 	virtual void Write(HAvctpOutgoingSdu*& aOutgoingSdu, TInt aChannel) =0; 
       
    48 	virtual TInt WriteIpid(HAvctpOutgoingSdu*& aOutgoingSdu) =0; 
       
    49 	virtual TBool IsClearToSend(TInt aChannel) const =0;
       
    50 	};
       
    51 
       
    52 	
       
    53 /**
       
    54 This class helps the Mgr collect together the incoming packet fragments from a muxer
       
    55 */
       
    56 NONSHARABLE_CLASS(CIncomingSduAssembler) : public CBase
       
    57 	{
       
    58 public:
       
    59 	static CIncomingSduAssembler* NewL(CAvctpPacketMgr& aMgr, TInt aChannel);
       
    60 	~CIncomingSduAssembler();
       
    61 
       
    62 	void Reset();	
       
    63 	void AddDataL(TAvctpStartHeaderInfo& aHeaderInfo, RMBufChain& aIncomingPdu);
       
    64 	
       
    65 private:
       
    66 	CIncomingSduAssembler(CAvctpPacketMgr& aMgr, TInt aChannel);
       
    67 	void ConstructL();
       
    68 	
       
    69 	void ProcessNormalPduL(RMBufChain& aIncomingPdu);
       
    70 	void ProcessStartPdu(TAvctpStartHeaderInfo& aHeaderInfo, RMBufChain& aIncomingPdu);
       
    71 	void ProcessContinuePdu(const TAvctpStartHeaderInfo& aHeaderInfo, RMBufChain& aIncomingPdu);
       
    72 	void ProcessEndPduL(const TAvctpStartHeaderInfo& aHeaderInfo, RMBufChain& aIncomingPdu);
       
    73 	
       
    74 private:
       
    75 	static const TInt	KAvctpNormalHeaderMask = 0xf3;
       
    76 	
       
    77 	CAvctpPacketMgr&	iMgr;
       
    78 	RMBufChain			iAccretingSdu;
       
    79 	TUint				iFragmentsReceived;
       
    80 	TAvctpStartHeaderInfo	iStartHeaderInfo;
       
    81 	
       
    82 	/** The spec mandates that Start and Continue fragments have the same length &
       
    83 	that End fragments have a equal or smaller size. NB it doesn't say the size
       
    84 	has to equal the current MTU
       
    85 	*/
       
    86 	TUint				iContinueFragmentSize;
       
    87 	TInt				iChannel;
       
    88 	};
       
    89 	
       
    90 
       
    91 /**
       
    92 This class helps the Mgr fragment the outgoing Sdus from a sap
       
    93 */
       
    94 NONSHARABLE_CLASS(COutgoingSduFragmenter) : public CBase
       
    95 	{
       
    96 public:
       
    97 	enum TWriteState
       
    98 		{
       
    99 		ENormal,
       
   100 		EFragmenting,
       
   101 		};
       
   102 
       
   103 public:
       
   104 	static COutgoingSduFragmenter* NewL(CAvctpPacketMgr& aMgr, TInt aChannel);
       
   105 	~COutgoingSduFragmenter();
       
   106 
       
   107 	TBool HasData();
       
   108 	void Write(HAvctpOutgoingSdu*& aOutgoingSdu);
       
   109 	void CanSend();
       
   110 	void Reset();	
       
   111 	
       
   112 private:
       
   113 	COutgoingSduFragmenter(CAvctpPacketMgr& aMgr, TInt aChannel);
       
   114 	void ConstructL();
       
   115 	
       
   116 	TInt CountFragments(const RMBufChain& aSdu, TInt iMtuUsedToFragment) const;
       
   117 	void DoSendCurrentSDU();
       
   118 	void BeginSendingSdu(TInt aMtu);
       
   119 	void ContinueSendingSdu(TInt aMtu);
       
   120 	
       
   121 	TInt AddHeader(RMBufChain& aPdu, TInt aNumFragments);
       
   122 	
       
   123 	// Callbacks
       
   124 	void StartSendAsyncCallBack();
       
   125 	void CancelSendAsyncCallBack();
       
   126 	static TInt SendAsyncCallBack(TAny* aFragmenter);
       
   127 	
       
   128 	void CheckForCanSend();
       
   129 
       
   130 private:
       
   131 	CAvctpPacketMgr&		iMgr;	
       
   132 	
       
   133 	RMBufChain				iSduData;
       
   134 	TAvctpNormalHeaderInfo	iHeaderInfo;  // FIXME rename
       
   135 	TBTDevAddr				iAddr;
       
   136 	
       
   137 	TInt					iChannel;
       
   138 	TWriteState				iCurrentWriteState;
       
   139 	CAsyncCallBack*			iSendAsyncCallBack;	
       
   140 	};
       
   141 	
       
   142 
       
   143 	
       
   144 NONSHARABLE_CLASS(CAvctpPacketMgr) : public CBase,
       
   145 									 public MAvctpSDUSender
       
   146 	{
       
   147 public:
       
   148 	~CAvctpPacketMgr();
       
   149 	static CAvctpPacketMgr* NewL(CAvctpTransport& aMuxer, CAvctpProtocol& aProtocol);
       
   150 	
       
   151 	// From above
       
   152 	virtual void Write(HAvctpOutgoingSdu*& aOutgoingSdu, TInt aChannel); 
       
   153 	virtual TInt WriteIpid(HAvctpOutgoingSdu*& aOutgoingSdu); 
       
   154 	
       
   155 	// From the transport
       
   156 	void CanSend(TInt aChannel);
       
   157 	void SignalMuxerError(TInt aError,TUint aOperationMask);
       
   158 	TInt NewData(RMBufChain& aIncomingPdu, TInt aChannel);
       
   159 	TBool WouldLikeToSend();
       
   160 	
       
   161 	inline CAvctpTransport& Transport() const;
       
   162 	inline CAvctpProtocol& Protocol() const;
       
   163 	inline TBool IsClearToSend(TInt aChannel) const;
       
   164 	inline const TBTDevAddr& DevAddr() const;
       
   165 	
       
   166 private:
       
   167 	CAvctpPacketMgr(CAvctpTransport& aMuxer, CAvctpProtocol& aProtocol);
       
   168 	void ConstructL();
       
   169 	
       
   170 private:
       
   171 	CAvctpTransport&		iTransport;
       
   172 	CAvctpProtocol&			iProtocol;
       
   173 
       
   174 	TFixedArray<CIncomingSduAssembler*,2>	iIncomingAssemblers;
       
   175 	TFixedArray<COutgoingSduFragmenter*,2>	iOutgoingFragmenters;	
       
   176 
       
   177 	TUint					iIpidSdusSent;
       
   178 	};
       
   179 
       
   180 #include "avctppacketmgr.inl"
       
   181 
       
   182 #endif // AVCTPPACKETMGR_H 
       
   183