commsfwutils/commsbufs/mbufmgrimpl/inc/MBufManager.h
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 1997-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 @internalTechnology
       
    19 */
       
    20 
       
    21 #if !defined(__MBufManager_h__)
       
    22 #define __MBufManager_h__
       
    23 
       
    24 #include "mbufsizeallocator.h"	// for MBufSizeAllocator
       
    25 #include "commsbufpondintf.h"
       
    26 #include "commsbufponddbg.h"
       
    27 #include <es_mbuf.h>
       
    28 #include <elements/rworkerlock.h>
       
    29 #include "commsbufasyncreqinternal.h"
       
    30 
       
    31 class Nif;
       
    32 class CRequestAsyncAlloc;
       
    33 class CMBufPoolManager;
       
    34 class CMBufMemoryAllocator;
       
    35 
       
    36 NONSHARABLE_CLASS(CMBufManager) : public CBase, public MCommsBufPondIntf, public MCommsBufPondDbg
       
    37 /**
       
    38 @file
       
    39 @internalTechnology
       
    40 */
       
    41 	{
       
    42 friend class Nif;
       
    43 
       
    44 private:
       
    45 	CMBufManager();
       
    46 public:
       
    47 	virtual ~CMBufManager();
       
    48 	IMPORT_C static MCommsBufPondIntf* New(RArray <TCommsBufPoolCreateInfo>& aPoolInfo, RLibrary& aLibrary, TInt aMaxHeapSize);
       
    49 
       
    50 	RMBuf* AllocL(TInt aSize);
       
    51 	RMBuf* Alloc(TInt aSize);
       
    52 
       
    53 	static void Panic(TMBufPanic aPanic);
       
    54 	
       
    55 	void CallBackAfterFree();
       
    56 
       
    57 
       
    58 	static CDeltaTimer* Timer();
       
    59 
       
    60 	// Used to reference the single process-wide MBufManager from different threads+DLLs
       
    61 	// Don't try to inline these - if TLS is in use then they need to be in this DLL
       
    62 	static CMBufManager* Context(); // Panics if no context!
       
    63 
       
    64 	RMBuf* Alloc(TInt aSize, TInt aMinMBufSize);
       
    65 	RMBuf* Alloc(TInt aSize, TInt aMinMBufSize, TInt aMaxMBufSize, TBool aIsAllocPool);
       
    66 	RMBuf* Alloc(TInt aSize, const RMBufChain& aMBufChain);
       
    67 
       
    68 	virtual RMBuf* Alloc(TInt aSize, TInt aMinBufSize, TInt aMaxBufSize);
       
    69 	virtual RMBuf* FromHandle(TInt aHandle);
       
    70 	virtual TInt Store(TDes8& aStore) const;
       
    71 	virtual void Free(RCommsBuf* aBuf);
       
    72 	virtual TInt BytesAvailable() const;
       
    73 	virtual TInt BytesAvailable(TInt aSize) const;
       
    74 	virtual TInt NextBufSize(TInt aSize) const;
       
    75 	virtual TInt LargestBufSize() const;
       
    76 	virtual void StartRequest(CCommsBufAsyncRequest& aRequest);
       
    77 	virtual void CancelRequest(CCommsBufAsyncRequest& aRequest);
       
    78 	// A new thread/DLL needs to call this when the TLS handling is in use, ie in the
       
    79 	// thread startup function, having obtained a pointer to the CMBufManager somehow
       
    80 	// (eg caller passed in). Consider it as the thread/dll introducing itself to the
       
    81 	// MBufMgr. "Pleased to meet you..."
       
    82 	virtual void SetContext();
       
    83 	virtual void Release(RLibrary& aLib);
       
    84 	virtual MCommsBufPondDbg& CommsBufPondDbg();
       
    85 	
       
    86 	void WatchDogReset();
       
    87 	
       
    88 private:
       
    89 	CMBufManager(RLibrary& aLibrary);
       
    90 	void ConstructL(RArray <TCommsBufPoolCreateInfo>& aPoolInfo, TInt aMaxHeapSize);
       
    91 	void ConstructL(TInt aMaxHeapSize);
       
    92 
       
    93 	static TInt WatchDogExpire(TAny* aPtr);
       
    94 	static TInt FreeCallBack(TAny* aPtr);
       
    95 	void CompleteAsyncAllocs(TBool aIsAllocPool);
       
    96 
       
    97 private:
       
    98 
       
    99 	RWorkerLock iAsynAllocLock;
       
   100 
       
   101     CMBufPoolManager* iMBufPoolManager;
       
   102 
       
   103 	TDblQue<CCommsBufAsyncRequest> iAllocsPending;
       
   104 	CDeltaTimer* iTimer;					// The global delta timer.
       
   105 	TThreadId iTimerThreadId;
       
   106 	TDeltaTimerEntry iWatchDog;
       
   107 	TBool iWatchDogIsPending;
       
   108 	CAsyncCallBack* iFreeCB;
       
   109 	CRequestAsyncAlloc* iRequestAsyncAlloc;
       
   110 	RLibrary			iLibrary;
       
   111 public:
       
   112 	static void __DbgCheckChain(RMBuf* aMBuf, TMBufType aType, TInt aLength, TInt aSize);
       
   113     virtual RCommsBuf* __DbgBufChain();
       
   114 	virtual RCommsBuf* __DbgBufChain(TUint aBufSize);
       
   115 	virtual void __DbgSetPoolLimit(TInt aCount);
       
   116 	virtual void __DbgSetPoolLimit(TInt aCount, TUint aBufSize);
       
   117 	virtual void __DbgSetFailAfter(TInt aCount=0);
       
   118 	virtual TUint __DbgGetBufSpace();
       
   119 	virtual TUint __DbgGetBufSpace(TUint aBufSize);
       
   120 	virtual TUint __DbgGetBufTotal();
       
   121 	virtual TUint __DbgGetBufTotal(TUint aMufSize);
       
   122 	virtual TInt __DbgGetHeapSize();
       
   123 	
       
   124 	TInt __DbgCheckBuffer(RMBuf* aBuf);
       
   125 
       
   126 private:
       
   127 	TInt iDbgFailAfter;		// fail allocation request of pool within pool chain
       
   128 
       
   129 #ifdef SYMBIAN_NETWORKING_PERFMETRICS
       
   130 	static TBool AddToPerfLog(TAny* aSelf, TDes8& aBuffer, TDes8Overflow* aOverflowHandler);
       
   131 
       
   132 	enum
       
   133 		{
       
   134 		KBucketSize = 128,	// Should be a power of 2 for better perf
       
   135 		KNumBuckets = 13
       
   136 		};
       
   137 	TUint iBuckets[KNumBuckets];
       
   138 	TUint iNumOOBs;
       
   139 #endif
       
   140 	};
       
   141 
       
   142 #endif