Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
3.5 KiB

  1. /*-----------------------------------------------------------------------------
  2. *
  3. * File: wiacache.h
  4. * Author: Samuel Clement (samclem)
  5. * Date: Thu Sep 09 15:02:42 1999
  6. *
  7. * Copyright (c) 1999 Microsoft Corporation
  8. *
  9. * Description:
  10. *
  11. * This declares the CWiaCacheManager this object is used to cache various
  12. * things that we want to keep around. For example, we always want to keep
  13. * the devices around. We also want to keep thumbnails cached.
  14. *
  15. * History:
  16. * 09 Sep 1999: Created.
  17. *----------------------------------------------------------------------------*/
  18. #ifndef _WIACACHE_H_
  19. #define _WIACACHE_H_
  20. struct THUMBNAILCACHEITEM
  21. {
  22. BYTE* pbThumb;
  23. DWORD cbThumb;
  24. };
  25. typedef CInterfaceCache<CComBSTR,IWiaItem> CWiaItemCache;
  26. typedef std::map<CComBSTR, THUMBNAILCACHEITEM*> CThumbnailCache;
  27. /*-----------------------------------------------------------------------------
  28. *
  29. * Class: CWiaCacheManager
  30. * Synopsis: This is a singleton class which handles managing the WIA
  31. * protocol. This handles cacheing device pointers and bitmap
  32. * data so that it only needs to be transfered once. It exists
  33. * for the entire lifetime of the DLL.
  34. *
  35. * Note: You must call CWiaCacheManager::Init() before trying to
  36. * use this object.
  37. * In order to free te memory it contains you must call
  38. * CWiaCacheManager::DeInit().
  39. * You cannot actually directly create an instance of this class
  40. * instead you must do this:
  41. *
  42. * CWiaCacheManager* pCache = CWiaCacheManager::GetInstance();
  43. * CFoo::CFoo() : m_pWiaCache( CWiaCacheManager::GetInstance() )
  44. *
  45. *--(samclem)-----------------------------------------------------------------*/
  46. class CWiaCacheManager
  47. {
  48. public:
  49. DECLARE_TRACKED_OBJECT
  50. // Device caching methods
  51. bool GetDevice( CComBSTR bstrId, IWiaItem** ppDevice );
  52. bool AddDevice( CComBSTR bstrId, IWiaItem* pDevice );
  53. bool RemoveDevice( CComBSTR bstrId );
  54. // thumbnail caching methods (including allocation). In order
  55. // to cache a thumbnail it must be allocated using
  56. // AllocThumbnail() which puts it on our local heap
  57. bool GetThumbnail( CComBSTR bstrFullItemName, BYTE** ppbThumb, DWORD* pcbThumb );
  58. bool AddThumbnail( CComBSTR bstrFullItemName, BYTE* pbThumb, DWORD cbThumb );
  59. bool RemoveThumbnail( CComBSTR bstrFullItemName );
  60. bool AllocThumbnail( DWORD cbThumb, BYTE** ppbThumb );
  61. void FreeThumbnail( BYTE* pbThumb );
  62. // this is the only way to get an instance of this class. You
  63. // cannot new or declare this class a a stack variable it will
  64. // fail to compile.
  65. static inline CWiaCacheManager* GetInstance()
  66. {
  67. Assert( sm_pManagerInstance != NULL && "Need to call CWiaCacheManager::Init() first" );
  68. return sm_pManagerInstance;
  69. }
  70. private:
  71. // Construction/Descruction methods
  72. CWiaCacheManager();
  73. ~CWiaCacheManager();
  74. bool Initialize();
  75. // We are thread safe, so we need to provide methods for locking
  76. // and unlocking ourselves.
  77. inline void Lock() { EnterCriticalSection( &m_cs ); }
  78. inline void Unlock() { LeaveCriticalSection( &m_cs ); }
  79. // member variables
  80. CWiaItemCache m_icItemCache;
  81. CThumbnailCache m_tcThumbnails;
  82. CRITICAL_SECTION m_cs;
  83. HANDLE m_hThumbHeap;
  84. // single static instance, setup in Init()
  85. static CWiaCacheManager* sm_pManagerInstance;
  86. public:
  87. // Static initialization and destruction which need to called in
  88. // order to use this object
  89. static bool Init();
  90. static bool Uninit();
  91. };
  92. #endif //_WIACACHE_H_