bfragfct.h
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:3k
源码类别:

Symbian

开发平台:

C/C++

  1. /****************************************************************************
  2.  * 
  3.  *  $Id: bfragfct.h,v 1.3 2003/07/31 17:23:44 jbloedow Exp $
  4.  *
  5.  *  Copyright (C) 1995-1999 RealNetworks, Inc. All rights reserved.
  6.  *  
  7.  *  http://www.real.com/devzone
  8.  *
  9.  *  This program contains proprietary 
  10.  *  information of Progressive Networks, Inc, and is licensed
  11.  *  subject to restrictions on use and distribution.
  12.  *
  13.  *
  14.  *  Buffer Fragment Factory class
  15.  *
  16.  */
  17. #ifndef _BFRAGFCT_H_
  18. #define _BFRAGFCT_H_
  19. /****************************************************************************
  20.  *  Defines
  21.  */
  22. /****************************************************************************
  23.  *  Includes
  24.  */
  25. #include "hxtypes.h"
  26. #include "hxcom.h"
  27. #include "hxcomm.h"
  28. #include "ihxpckts.h"
  29. #include "cringbuf.h"
  30. #include "bfrag.h"
  31. #include "qtffrefcounter.h"
  32. /****************************************************************************
  33.  * 
  34.  *  Class:
  35.  * CQTBufferFragmentFactory
  36.  *
  37.  *  Purpose:
  38.  * Enables paging of file sections into memory
  39.  *
  40.  */
  41. class CBufferFragmentFactory
  42. {
  43. public:
  44.     /*
  45.      * Constructor/Destructor
  46.      */
  47.     CBufferFragmentFactory(ULONG32 ulMaxSize, ULONG32 ulInitialOccupancy = 0);
  48.     /*
  49.      * CBufferFragment methods
  50.      */
  51.     IHXBuffer* WrapFragment(IHXBuffer* pBuffer,
  52.      ULONG32 ulOffset,
  53.      ULONG32 ulSize)
  54.     {
  55. CBufferFragment* pBufferFragment = NULL;
  56. pBufferFragment = (CBufferFragment*) m_pRingBuffer->Get();
  57. if (!pBufferFragment)
  58. {
  59.     pBufferFragment = new CBufferFragment();
  60.     if (pBufferFragment)
  61.     {
  62. pBufferFragment->AddRef();
  63.     }
  64. }
  65. if (pBufferFragment)
  66. {
  67.     pBufferFragment->Init(pBuffer,
  68.   ulOffset,
  69.   ulSize,
  70.   this);
  71. }
  72. return pBufferFragment;
  73.     }
  74.     BOOL Put(CBufferFragment* pBufferFragment)
  75.     {
  76. if (m_pRingBuffer->Put(pBufferFragment))
  77. {
  78.     pBufferFragment->AddRef();
  79.     return TRUE;
  80. }
  81. return FALSE;
  82.     }
  83.     ULONG32 AddRef(void)
  84.     {
  85. return InterlockedIncrement(&m_lRefCount);
  86.     }
  87.     ULONG32 Release(void)
  88.     {
  89. if (InterlockedDecrement(&m_lRefCount) > 0)
  90. {
  91.     return m_lRefCount;
  92. }
  93. delete this;
  94. return 0;
  95.     }
  96. private:
  97.     CRingBuffer* m_pRingBuffer;
  98.     LONG32 m_lRefCount;
  99.     ~CBufferFragmentFactory()
  100.     {
  101. CBufferFragment* pDeadFragment;
  102. while (pDeadFragment = ((CBufferFragment*) m_pRingBuffer->Get()))
  103. {
  104.     pDeadFragment->Release();
  105. }
  106. delete m_pRingBuffer;
  107.     }
  108.     PRIVATE_DESTRUCTORS_ARE_NOT_A_CRIME
  109. };
  110. #endif  // _BFRAGFCT_H_