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

Symbian

开发平台:

C/C++

  1. /****************************************************************************
  2.  * 
  3.  *  $Id: qtmcache.h,v 1.1 2003/03/30 22:17:13 milko 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.  *  Memory Cache
  15.  *
  16.  */
  17. #ifndef _QTMCACHE_H_
  18. #define _QTMCACHE_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. /****************************************************************************
  30.  * 
  31.  *  Class:
  32.  * CQTMemCache
  33.  *
  34.  *  Purpose:
  35.  * Enables paging of file sections into memory
  36.  *
  37.  */
  38. class CQTMemCache
  39. {
  40. public:
  41.     /*
  42.      * Constructor/Destructor
  43.      */
  44.     CQTMemCache(void)
  45. : m_pBuffer(NULL)
  46. , m_ulBaseOffset(0)
  47. , m_ulEndOffset(0)
  48. , m_bEnabled(TRUE)
  49.     {
  50. ;
  51.     }
  52.     ~CQTMemCache()
  53.     {
  54. HX_RELEASE(m_pBuffer);
  55.     }
  56.     /*
  57.      * IUnknown methods
  58.      */
  59.     void SetPage(ULONG32 ulBaseOffset, IHXBuffer* pBuffer)
  60.     {
  61. if (m_pBuffer)
  62. {
  63.     m_pBuffer->Release();
  64. }
  65. m_pBuffer = pBuffer;
  66. pBuffer->AddRef();
  67. m_ulBaseOffset = ulBaseOffset;
  68. m_ulEndOffset = ulBaseOffset + m_pBuffer->GetSize();
  69.     }
  70.     void ReleasePage(void)
  71.     {
  72. HX_RELEASE(m_pBuffer);
  73.     }
  74.     BOOL IsInPage(ULONG32 ulBaseOffset, ULONG32 ulSize)
  75.     {
  76. return (m_pBuffer &&
  77. (((LONG32) (ulBaseOffset - m_ulBaseOffset)) >= 0) &&
  78. (((LONG32) (m_ulEndOffset - ulBaseOffset - ulSize)) >= 0));
  79.     }
  80.     // COM semantics is not followed here (no AddRef of pBuffer) 
  81.     // for efficiency reasons.
  82.     void Get(ULONG32 ulBaseOffset,
  83.      IHXBuffer* &pBuffer, ULONG32 &ulPageOffset)
  84.     {
  85. pBuffer = m_pBuffer;
  86. ulPageOffset = ulBaseOffset - m_ulBaseOffset;
  87.     }
  88.     BOOL IsEnabled(void)    { return m_bEnabled; }
  89.     void Enable(BOOL bEnable) { m_bEnabled = bEnable; }
  90. private:
  91.     IHXBuffer* m_pBuffer;
  92.     ULONG32 m_ulBaseOffset;
  93.     ULONG32 m_ulEndOffset;
  94.     BOOL m_bEnabled;
  95. };
  96. #endif  // _QTMCACHE_H_