bluetooth/btstack/linkmgr/AclDataQ.h
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 2001-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 #ifndef _ACLDATAQ_H
       
    17 #define _ACLDATAQ_H
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <bttypes.h>
       
    21 
       
    22 class CACLDataItem;
       
    23 class CHCIFacade;
       
    24 class CLinkMgrProtocol;
       
    25 
       
    26 /**
       
    27 	HCI ACL Data Packet Buffer Q.
       
    28 
       
    29 	This class will handle the Qing and issuing of ACL Data Packet Buffers.
       
    30 	It pre-allocates Packet buffers on the heap on construction, hence the 
       
    31 	number or size of preallocated buffers should not change after 
       
    32 	construction because ESock doesn't like memory Leaves.
       
    33 
       
    34 	For a UART HCTL implementation of the HCI, we need to be able to buffer 
       
    35 	HCI Data buffers of at least 255+1+4 bytes, since the HC must guarantee to 
       
    36 	be able to accept/buffer data packets of 255 bytes (EXCLUDING the headers).
       
    37 
       
    38 	The general usage includes:
       
    39 	1/ Obtaining items in the 'spare data pool'- for the client to populate 
       
    40 	with data (RemoveFirstSpareItem),
       
    41 	2/ Putting such items back on the 'data fifo' queue, for sending 
       
    42 	(AddItem), and
       
    43 	3/ When we do a send, getting an item to send (FirstItemByConnectionHandle 
       
    44 	and FirstItem) and moving it back to the spare data pool (InvalidateItem).
       
    45 
       
    46 	This class is not intended for derivation, to reuse aggregate.
       
    47 */
       
    48 NONSHARABLE_CLASS(CAclDataQ) : public CBase
       
    49 	{
       
    50 public:
       
    51 	static CAclDataQ* NewL(CLinkMgrProtocol& aProtocol, 
       
    52 		TUint aNumberOfItems, 
       
    53 		TUint16 aDataSize, 
       
    54 		TUint16 aFramingOverhead);
       
    55 	~CAclDataQ();
       
    56 
       
    57 public:
       
    58 	inline TUint	Ceiling() const;
       
    59 	inline TUint	FillLevel() const;
       
    60 	void			AddItem(CACLDataItem& aACLItem);
       
    61 	inline TUint16	ItemSize() const;
       
    62 	void			InvalidateAll();
       
    63 	void			InvalidateByConnH(THCIConnHandle aConn, const CHCIFacade& aHCIFacade);
       
    64 	CACLDataItem*	RemoveFirstSpareItem();
       
    65 	CACLDataItem*	FirstItemByConnectionHandle(const CHCIFacade& aHCIFacade, const THCIConnHandle aConnH);
       
    66 	CACLDataItem*	FirstItem(const CHCIFacade& aHCIFacade, THCIConnHandle& aConnH);
       
    67 	void			PendingItem(CACLDataItem& aItem);
       
    68 	void 			ItemsSent(TUint aNumberOfItemsSent);
       
    69 	void 			ProcessFlush(const CHCIFacade& aHCIFacade, THCIConnHandle aConnH);
       
    70 	
       
    71 private:
       
    72 	CAclDataQ();
       
    73 	void ConstructL(CLinkMgrProtocol& aProtocol, 
       
    74 		TUint aNumberOfItems, 
       
    75 		TUint16 aDataSize, 
       
    76 		TUint16 aFramingOverhead);
       
    77 
       
    78 private: // owned
       
    79 	// size of each item (HCI ACL Data buffer) in the FIFO
       
    80 	TUint16 iItemSize;
       
    81 
       
    82 	// max number of allocated items allowed
       
    83 	TUint iCeiling;
       
    84 
       
    85 	// how many packets are pending on the Q (iDataFifo)
       
    86 	TUint iLevel;
       
    87 
       
    88 	TSglQue<CACLDataItem>	iPreHardwareBuffer;	// A buffer for data prior to it being 
       
    89 	                                            // sent to the hardware buffer.
       
    90 	TSglQue<CACLDataItem>	iSpareDataPool;		// the 'empty' slots
       
    91 	TSglQue<CACLDataItem>	iPendingData;		// Data on the hardware.
       
    92 	};
       
    93 
       
    94 inline TUint CAclDataQ::Ceiling() const
       
    95 /**
       
    96 	Returns the maximum number of packets this Q will hold.
       
    97 */
       
    98 	{
       
    99 	return iCeiling;
       
   100 	}
       
   101 
       
   102 inline TUint CAclDataQ::FillLevel() const
       
   103 /**
       
   104 	Returns the number of packets currently on the Q.
       
   105 */
       
   106 	{
       
   107 	return iLevel;
       
   108 	}
       
   109 
       
   110 inline TUint16 CAclDataQ::ItemSize() const
       
   111 /**
       
   112 	Returns the data size of the packets that can be handled by this Q.
       
   113 */
       
   114 	{
       
   115 	return iItemSize;
       
   116 	}
       
   117 
       
   118 #endif // _ACLDATAQ_H