Source code of Windows XP (NT5)
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.

212 lines
4.4 KiB

  1. #ifndef CACHEMGR_HXX
  2. #define CACHEMGR_HXX
  3. #include "priv.h"
  4. class CacheMgr
  5. {
  6. public:
  7. CacheMgr ();
  8. virtual ~CacheMgr();
  9. VOID
  10. InvalidateCache ();
  11. WIN9X_INLINE VOID
  12. InvalidateCacheForUser (
  13. CLogonUserData *pUser );
  14. virtual VOID
  15. EndReadCache (VOID);
  16. VOID
  17. Shutdown ();
  18. static LPVOID
  19. Allocator(DWORD cb);
  20. inline BOOL
  21. bValid() CONST {return m_bValid;}
  22. protected:
  23. PVOID
  24. BeginReadCache (
  25. PCINETMONPORT pIniPort);
  26. virtual BOOL
  27. FreeBuffer (
  28. PCINETMONPORT pIniPort,
  29. PVOID pData) = 0;
  30. virtual BOOL
  31. FetchData (
  32. PCINETMONPORT pIniPort,
  33. PVOID *ppData) = 0;
  34. protected:
  35. BOOL m_bValid;
  36. PCINETMONPORT m_pIniPort;
  37. PVOID m_pData;
  38. private:
  39. typedef struct {
  40. CacheMgr *pCache;
  41. PCINETMONPORT pIniPort;
  42. #if (defined(WINNT32))
  43. CSid *pSidToken;
  44. #endif
  45. } THREADCONTEXT;
  46. typedef THREADCONTEXT *PTHREADCONTEXT;
  47. typedef enum {
  48. CACHE_STATE_INIT = 0,
  49. CACHE_STATE_ACCESSED_VALID,
  50. CACHE_STATE_DATA_VALID,
  51. CACHE_STATE_ACCESSED_VALID_AGAIN,
  52. CACHE_STATE_NOT_ACCESSED_VALID_AGAIN
  53. } CACHESTATE;
  54. CACHESTATE m_dwState;
  55. HANDLE m_hDataReadyEvent;
  56. HANDLE m_hHitEvent;
  57. HANDLE m_hInvalidateCacheEvent;
  58. HANDLE m_hThread;
  59. BOOL m_bCacheStopped;
  60. BOOL m_bAccessed;
  61. BOOL m_bInvalidateFlag;
  62. CCriticalSection CacheRead;
  63. CCriticalSection CacheData;
  64. #ifdef WINNT32
  65. CUserData m_CurUser;
  66. #endif
  67. private:
  68. VOID
  69. SetState (
  70. PCINETMONPORT pIniPort,
  71. CACHESTATE dwState,
  72. BOOL bNewData,
  73. PVOID pNewData);
  74. BOOL
  75. SetupAsyncFetch (
  76. PCINETMONPORT pIniPort);
  77. VOID
  78. TransitState (
  79. PCINETMONPORT pIniPort);
  80. static VOID
  81. WorkingThread (
  82. PTHREADCONTEXT pThreadData);
  83. BOOL
  84. GetFetchTime (
  85. PCINETMONPORT pIniPort,
  86. LPDWORD pdwTime,
  87. PVOID *ppData);
  88. inline DWORD
  89. GetTimeDiff (
  90. DWORD t0,
  91. DWORD t1);
  92. VOID
  93. _InvalidateCache ();
  94. };
  95. class GetPrinterCache: public CacheMgr
  96. {
  97. public:
  98. GetPrinterCache (
  99. PCINETMONPORT pIniPort);
  100. ~GetPrinterCache (
  101. VOID);
  102. typedef struct {
  103. BOOL bRet;
  104. DWORD dwLastError;
  105. DWORD cbSize;
  106. PPRINTER_INFO_2 pInfo;
  107. } GETPRINTER_CACHEDATA;
  108. typedef GETPRINTER_CACHEDATA * PGETPRINTER_CACHEDATA;
  109. BOOL
  110. BeginReadCache (
  111. PPRINTER_INFO_2 *ppInfo);
  112. protected:
  113. virtual BOOL
  114. FreeBuffer (
  115. PCINETMONPORT pIniPort,
  116. PVOID pData);
  117. virtual BOOL
  118. FetchData (
  119. PCINETMONPORT pIniPort,
  120. LPVOID *ppData);
  121. private:
  122. PCINETMONPORT m_pIniPort;
  123. };
  124. class EnumJobsCache: public CacheMgr
  125. {
  126. public:
  127. EnumJobsCache (
  128. PCINETMONPORT pIniPort);
  129. ~EnumJobsCache (
  130. VOID);
  131. BOOL
  132. BeginReadCache (
  133. LPPPJOB_ENUM *ppje);
  134. VOID
  135. EndReadCache (
  136. VOID);
  137. protected:
  138. virtual BOOL
  139. FreeBuffer (
  140. PCINETMONPORT pIniPort,
  141. PVOID pData);
  142. virtual BOOL
  143. FetchData (
  144. PCINETMONPORT pIniPort,
  145. LPVOID *ppData);
  146. private:
  147. typedef struct {
  148. BOOL bRet;
  149. DWORD dwLastError;
  150. DWORD cbSize;
  151. LPPPJOB_ENUM pje;
  152. } ENUMJOBS_CACHEDATA;
  153. typedef ENUMJOBS_CACHEDATA * PENUMJOBS_CACHEDATA;
  154. PCINETMONPORT m_pIniPort;
  155. };
  156. ///////////////////////////////////////////////////////////////////////////////////
  157. // INLINE METHODS
  158. ///////////////////////////////////////////////////////////////////////////////////
  159. #if (!defined(WINNT32))
  160. _inline VOID CacheMgr::InvalidateCacheForUser ( CLogonUserData * /*pUser*/ ) {}
  161. #endif // #if (!defined(WINNT32))
  162. #endif // #ifndef CACHEMGR_H
  163. /***********************************************************************************
  164. ** End of File (cachemgr.hxx)
  165. ***********************************************************************************/