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.

238 lines
9.6 KiB

  1. // --------------------------------------------------------------------------
  2. // Module Name: KernelResources.h
  3. //
  4. // Copyright (c) 1999-2000, Microsoft Corporation
  5. //
  6. // General class definitions that assist in resource management. These are
  7. // typically stack based objects where constructors initialize to a known
  8. // state. Member functions operate on that resource. Destructors release
  9. // resources when the object goes out of scope.
  10. //
  11. // History: 1999-08-18 vtan created
  12. // 1999-11-16 vtan separate file
  13. // 2000-02-01 vtan moved from Neptune to Whistler
  14. // --------------------------------------------------------------------------
  15. #ifndef _KernelResources_
  16. #define _KernelResources_
  17. // --------------------------------------------------------------------------
  18. // CHandle
  19. //
  20. // Purpose: This class manages any generic HANDLE to an object.
  21. //
  22. // History: 1999-08-18 vtan created
  23. // 2000-02-01 vtan moved from Neptune to Whistler
  24. // --------------------------------------------------------------------------
  25. class CHandle
  26. {
  27. private:
  28. CHandle (void);
  29. CHandle (const CHandle& copyObject);
  30. bool operator == (const CHandle& compareObject) const;
  31. const CHandle& operator = (const CHandle& assignObject);
  32. public:
  33. CHandle (HANDLE handle);
  34. ~CHandle (void);
  35. operator HANDLE (void) const;
  36. private:
  37. HANDLE _handle;
  38. };
  39. // --------------------------------------------------------------------------
  40. // CEvent
  41. //
  42. // Purpose: This class manages a named or un-named event object. Using
  43. // the default constructor will not create an event.
  44. //
  45. // History: 1999-08-18 vtan created
  46. // 2000-02-01 vtan moved from Neptune to Whistler
  47. // --------------------------------------------------------------------------
  48. class CEvent
  49. {
  50. private:
  51. bool operator == (const CEvent& compareObject) const;
  52. public:
  53. CEvent (void);
  54. CEvent (const CEvent& copyObject);
  55. CEvent (const TCHAR *pszName);
  56. ~CEvent (void);
  57. const CEvent& operator = (const CEvent& assignObject);
  58. operator HANDLE (void) const;
  59. NTSTATUS Open (const TCHAR *pszName, DWORD dwAccess);
  60. NTSTATUS Create (const TCHAR *pszName = NULL);
  61. NTSTATUS Set (void) const;
  62. NTSTATUS Reset (void) const;
  63. NTSTATUS Pulse (void) const;
  64. NTSTATUS Wait (DWORD dwMilliseconds, DWORD *pdwWaitResult) const;
  65. NTSTATUS WaitWithMessages (DWORD dwMilliseconds, DWORD *pdwWaitResult) const;
  66. bool IsSignaled (void) const;
  67. private:
  68. NTSTATUS Close (void);
  69. private:
  70. HANDLE _hEvent;
  71. };
  72. // --------------------------------------------------------------------------
  73. // CJob
  74. //
  75. // Purpose: This class manages a named or un-named job object. It hides
  76. // Win32 APIs to manipulate the state of the job object.
  77. //
  78. // History: 1999-10-07 vtan created
  79. // 2000-02-01 vtan moved from Neptune to Whistler
  80. // --------------------------------------------------------------------------
  81. class CJob
  82. {
  83. private:
  84. CJob (const CJob& copyObject);
  85. bool operator == (const CJob& compareObject) const;
  86. const CJob& operator = (const CJob& assignObject);
  87. public:
  88. CJob (const TCHAR *pszName = NULL);
  89. ~CJob (void);
  90. NTSTATUS AddProcess (HANDLE hProcess) const;
  91. NTSTATUS SetCompletionPort (HANDLE hCompletionPort) const;
  92. NTSTATUS SetActiveProcessLimit (DWORD dwActiveProcessLimit) const;
  93. NTSTATUS SetPriorityClass (DWORD dwPriorityClass) const;
  94. NTSTATUS RestrictAccessUIAll (void) const;
  95. private:
  96. HANDLE _hJob;
  97. };
  98. // --------------------------------------------------------------------------
  99. // CMutex
  100. //
  101. // Purpose: This class implements a mutex object management. It's not a
  102. // static class but each class that uses this class should
  103. // declare the member variable as static as only one mutex is
  104. // required to protect a shared resource.
  105. //
  106. // History: 1999-10-13 vtan created
  107. // 2000-02-01 vtan moved from Neptune to Whistler
  108. // --------------------------------------------------------------------------
  109. class CMutex
  110. {
  111. public:
  112. NTSTATUS Initialize (const TCHAR *pszMutexName);
  113. NTSTATUS Terminate (void);
  114. void Acquire (void);
  115. void Release (void);
  116. private:
  117. HANDLE _hMutex;
  118. };
  119. // --------------------------------------------------------------------------
  120. // CCriticalSection
  121. //
  122. // Purpose: This class implements a critical section object management.
  123. //
  124. // History: 1999-11-06 vtan created
  125. // 2000-02-01 vtan moved from Neptune to Whistler
  126. // --------------------------------------------------------------------------
  127. class CCriticalSection
  128. {
  129. public:
  130. CCriticalSection (void);
  131. ~CCriticalSection (void);
  132. void Acquire (void);
  133. void Release (void);
  134. NTSTATUS Status (void) const;
  135. bool IsOwned (void) const;
  136. private:
  137. NTSTATUS _status;
  138. CRITICAL_SECTION _criticalSection;
  139. };
  140. // --------------------------------------------------------------------------
  141. // CModule
  142. //
  143. // Purpose: This class manages a loading an unloading of a dynamic link
  144. // library. The scope of the object determines how long the
  145. // library remains loaded.
  146. //
  147. // History: 1999-08-18 vtan created
  148. // 2000-02-01 vtan moved from Neptune to Whistler
  149. // --------------------------------------------------------------------------
  150. class CModule
  151. {
  152. private:
  153. CModule (void);
  154. CModule (const CModule& copyObject);
  155. bool operator == (const CModule& compareObject) const;
  156. const CModule& operator = (const CModule& assignObject);
  157. public:
  158. CModule (const TCHAR *pszModuleName);
  159. ~CModule (void);
  160. operator HMODULE (void) const;
  161. void* GetProcAddress (LPCSTR pszProcName) const;
  162. private:
  163. HMODULE _hModule;
  164. };
  165. // --------------------------------------------------------------------------
  166. // CFile
  167. //
  168. // Purpose: This class manages a HANDLE to a file object. It is specific
  169. // for files and should not be abused.
  170. //
  171. // History: 1999-08-18 vtan created
  172. // 2000-02-01 vtan moved from Neptune to Whistler
  173. // --------------------------------------------------------------------------
  174. class CFile
  175. {
  176. private:
  177. CFile (const CFile& copyObject);
  178. bool operator == (const CFile& compareObject) const;
  179. const CFile& operator = (const CFile& assignObject);
  180. public:
  181. CFile (void);
  182. ~CFile (void);
  183. LONG Open (const TCHAR *pszFilepath, DWORD dwDesiredAccess, DWORD dwShareMode);
  184. LONG GetSize (DWORD& dwLowSize, DWORD *pdwHighSize) const;
  185. LONG Read (void *pvBuffer, DWORD dwBytesToRead, DWORD *pdwBytesRead) const;
  186. private:
  187. HANDLE _hFile;
  188. };
  189. // --------------------------------------------------------------------------
  190. // CDesktop
  191. //
  192. // Purpose: This class manages an HDESK object.
  193. //
  194. // History: 2001-02-06 vtan created
  195. // --------------------------------------------------------------------------
  196. class CDesktop
  197. {
  198. public:
  199. CDesktop (void);
  200. ~CDesktop (void);
  201. NTSTATUS Set (const TCHAR *pszName);
  202. NTSTATUS SetInput (void);
  203. private:
  204. NTSTATUS Set (void);
  205. private:
  206. HDESK _hDeskCurrent;
  207. HDESK _hDesk;
  208. };
  209. #endif /* _KernelResources_ */