bluetooth/btstack/linkmgr/hostmbufpool.h
branchRCL_3
changeset 22 9f17f914e828
equal deleted inserted replaced
18:f8503e232b0c 22:9f17f914e828
       
     1 // Copyright (c) 2006-2010 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 HOSTMBUFPOOL
       
    17 #define HOSTMBUFPOOL
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <bttypes.h>
       
    21 #include <es_mbuf.h>
       
    22 #include <bluetooth/hcicommandqueueclient.h>
       
    23 
       
    24 #ifdef HOSTCONTROLLER_TO_HOST_FLOW_CONTROL
       
    25 
       
    26 class MHCICommandQueue;
       
    27 
       
    28 
       
    29 NONSHARABLE_CLASS(CHostMBufPool) 
       
    30 	: public CActive
       
    31 	, private MHCICommandQueueClient
       
    32 	{
       
    33 
       
    34 	NONSHARABLE_STRUCT(TPoolBuffer)
       
    35 		{
       
    36 		RMBufChain		iMBufChain;
       
    37 		THCIConnHandle	iCurrentHandle;
       
    38 		TSglQueLink		iLink;
       
    39 		};
       
    40 	
       
    41 public:
       
    42 	static CHostMBufPool* NewL(MHCICommandQueue& aCommandQueue);
       
    43 	~CHostMBufPool();
       
    44 	
       
    45 	RMBufChain TakeBufferL(THCIConnHandle aConnHandle);
       
    46 	
       
    47 	void InvalidateByConnH(THCIConnHandle aConnHandle);
       
    48 	
       
    49 private:
       
    50 	CHostMBufPool(MHCICommandQueue& aCommandQueue);
       
    51 	void ConstructL();
       
    52 	
       
    53 	void DeletePool(TSglQue<TPoolBuffer>& aPool);
       
    54 	void DeleteBuffer(TPoolBuffer*& aBuffer);
       
    55 	void AllocNewBuffer(TPoolBuffer& aBuffer);
       
    56 	TPoolBuffer* CreatePoolBufferL();
       
    57 	void HostNumberOfCompletedPacketsL(THCIConnHandle aConnH, TUint16 aNumPackets);
       
    58 	void TryToAllocQueuedBuffer();
       
    59 	
       
    60 	inline void AddToBufferPool(TPoolBuffer& aBuffer);
       
    61 	inline void RemoveFromBufferPool(TPoolBuffer& aBuffer);
       
    62 	
       
    63 	void Error(TInt aError);
       
    64 	
       
    65 private: // from CActive
       
    66 	void RunL();
       
    67 	void DoCancel();
       
    68 	TInt RunError(TInt aError);
       
    69 	
       
    70 private: // from MHCICommandQueueClient
       
    71 	void MhcqcCommandEventReceived(const THCIEventBase& aEvent, const CHCICommandBase* aRelatedCommand);
       
    72 	void MhcqcCommandErrored(TInt aErrorCode, const CHCICommandBase* aCommand);
       
    73 	
       
    74 private:
       
    75 	MHCICommandQueue& iCmdQ;
       
    76 	
       
    77 	TSglQue<TPoolBuffer> iBufferPool;
       
    78 	TSglQue<TPoolBuffer> iWaitingAllocPool;
       
    79 	TPoolBuffer* iBufferBeingAllocd;
       
    80 	
       
    81 	// We batch up completed packets notifications for a connection handle so that they are 
       
    82 	// only sent every 'x' packets OR if we get a packet for a different connection handle.
       
    83 	TInt iCurrAckHandle; // current handle of packets being batched for completion
       
    84 	TUint iCurrCompletedPackets; // number of packets already completed for current handle
       
    85 	
       
    86 	RMBufAsyncRequest iMBufRequester;
       
    87 	};
       
    88 	
       
    89 inline void CHostMBufPool::AddToBufferPool(TPoolBuffer& aBuffer)
       
    90 	{
       
    91 	iBufferPool.AddLast(aBuffer);
       
    92 	}
       
    93 	
       
    94 inline void CHostMBufPool::RemoveFromBufferPool(TPoolBuffer& aBuffer)
       
    95 	{
       
    96 	iBufferPool.Remove(aBuffer);
       
    97 	}
       
    98 	
       
    99 #endif //HOSTCONTROLLER_TO_HOST_FLOW_CONTROL
       
   100 
       
   101 #endif // HOSTMBUFPOOL