commsfwutils/commsbufs/mbufmgr/inc/mbuf.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 
       
    19 */
       
    20 
       
    21 #if !defined(__MBuf_h__)
       
    22 #define __MBuf_h__
       
    23 
       
    24 #include <es_commsbuf.h>
       
    25 #include <comms-infras/mbufallocator.h>
       
    26 
       
    27 
       
    28 // iType field of an MBuf
       
    29 enum TMBufType
       
    30 	{
       
    31 	EMBufFree, EMBufData, EMBufHeader
       
    32 	};
       
    33 
       
    34 class RMBufPoolChain;
       
    35 
       
    36 class RMBuf : public RCommsBuf
       
    37 /**
       
    38 RMBuf is a thin wrapper over RCommsBuf providing compatibility for existing code.
       
    39 
       
    40 @publishedPartner
       
    41 @released
       
    42 */
       
    43 	{
       
    44 	friend class CMBufPool;
       
    45 public:
       
    46 	IMPORT_C void Init(TMBufType aType);
       
    47 	IMPORT_C RMBuf* Last();
       
    48 	//
       
    49 	IMPORT_C static RMBuf* Alloc();
       
    50 	IMPORT_C static RMBuf* Alloc(TUint aSize);
       
    51 	IMPORT_C static RMBuf* AllocL();
       
    52 	IMPORT_C static RMBuf* AllocL(TUint aSize);
       
    53 
       
    54 	// Methods to avoid calls to thread local storage
       
    55 	IMPORT_C static RMBuf* Alloc(RMBufAllocator& aRMBufAllocator);
       
    56 	IMPORT_C static RMBuf* Alloc(TUint aSize, RMBufAllocator& aRMBufAllocator);
       
    57 	IMPORT_C static RMBuf* AllocL(RMBufAllocator& aRMBufAllocator);
       
    58 	IMPORT_C static RMBuf* AllocL(TUint aSize, RMBufAllocator& aRMBufAllocator);
       
    59 
       
    60 	IMPORT_C void Free();
       
    61 
       
    62 	inline void FillZ();
       
    63 	//
       
    64 	inline TUint8* Buffer();
       
    65 	inline TUint8* Ptr();
       
    66 	inline TUint8* EndPtr();
       
    67 	inline RMBuf* Next();
       
    68 	inline RMBufChain& NextPkt();
       
    69 	inline TInt Size() const;
       
    70 	inline TInt Offset() const;
       
    71 	inline TInt Length() const;
       
    72 	inline TInt End() const;
       
    73 	inline TMBufType Type() const;
       
    74 	inline const TUint8* Buffer() const;
       
    75 	inline const TUint8* Ptr() const;
       
    76 	inline const TUint8* EndPtr() const;
       
    77 	inline const RMBuf* Next() const;
       
    78 	inline const RMBufChain& NextPkt() const;
       
    79 	//
       
    80 	inline void Link(RMBuf* aBuf);
       
    81 	inline void Unlink();
       
    82 	inline void LinkPkt(RMBufChain &aChain);
       
    83 	inline void UnlinkPkt();
       
    84 	inline void SetType(TMBufType aType);
       
    85 	inline void SetOffset(TInt aOffset);
       
    86 	inline void SetLength(TInt aLength);
       
    87 	inline void SetData(TInt aOffset, TInt aLength);
       
    88 	inline void AdjustStart(TInt aLen);
       
    89 	inline void AdjustEnd(TInt aLen);
       
    90 	inline void Put(TUint8 aVal, TInt aOffset=0);
       
    91 	inline TUint8 Get(TInt aOffset=0) const;
       
    92 
       
    93 
       
    94 private:
       
    95 #ifndef __KERNEL_MODE__
       
    96 	TAny *operator new ( TUint aSize, TUint8* aPtr );
       
    97 	void operator delete ( TAny* aPtr, TUint8*  );
       
    98 
       
    99 // Forbidden ops
       
   100 	RMBuf();
       
   101 	RMBuf(const RMBuf &);
       
   102 	RMBuf& operator=(const RMBuf &);
       
   103 #else
       
   104     RMBuf() : iBuffer(NULL), iSize(0), iNext(NULL), iPoolChain(NULL) {}
       
   105 #endif
       
   106 //
       
   107 
       
   108 private:
       
   109 	IMPORT_C void __DbgPut(TUint8 aVal, TInt aOffset=0);
       
   110 	IMPORT_C TUint8 __DbgGet(TInt aOffset=0) const;
       
   111 	};
       
   112 
       
   113 class TMBufIter
       
   114 /**
       
   115 An iterator to iterate through the RMBuf
       
   116 @publishedPartner
       
   117 @released
       
   118 */
       
   119 	{
       
   120 public:
       
   121 	TMBufIter();
       
   122 	inline TMBufIter(RMBuf* aChain);
       
   123 	inline TMBufIter(RMBufChain& aChain);
       
   124 	inline TMBufIter& operator =(RMBuf* aChain);
       
   125 	inline TMBufIter& operator =(RMBufChain& aChain);
       
   126 	inline RMBuf* operator++(TInt);
       
   127 	inline operator RMBuf* ();
       
   128 	inline TBool More();
       
   129 	inline RMBuf* MBuf();
       
   130 	//
       
   131 protected:
       
   132 	TCommsBufIter iIterator;
       
   133 	};
       
   134 
       
   135 #endif // __rmbuf_h__
       
   136 
       
   137 #if !defined(__MBuf_Ignore_Inlines__)
       
   138 #define __MBufchain_Ignore_Inlines__
       
   139 #include <comms-infras/mbufchain.h>
       
   140 #undef __MBufchain_Ignore_Inlines__
       
   141 #include <comms-infras/mbuf.inl>
       
   142 #endif // __rmbuf_Ignore_Inlines__