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.

434 lines
9.0 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. dbgstate.hxx
  6. Abstract:
  7. Status definitions.
  8. Author:
  9. Steve Kiraly (SteveKi) 2-Mar-1997
  10. Revision History:
  11. --*/
  12. #ifndef _DBGSTATE_HXX_
  13. #define _DBGSTATE_HXX_
  14. #ifdef DBG
  15. /********************************************************************
  16. Automatic status logging.
  17. Use TStatus instead of DWORD:
  18. DWORD dwStatus; -> TStatus Status;
  19. DWORD dwStatus = ERROR_ACCESS_DENIED -> TStatus Status = ERROR_ACCESS_DENIED;
  20. dwStatus = ERROR_SUCCESS -> Status DBGNOCHK = ERROR_SUCCESS;
  21. dwStatus = xxx; -> Status DBGCHK = xxx;
  22. if(dwStatus){ -> if(Status != 0){
  23. Anytime Status is set, the DBGCHK macro must be added before
  24. the '=.'
  25. If the variable must be set to a failure value at compile time
  26. and logging is therefore not needed, then the DBGNOCHK macro
  27. should be used.
  28. There is a method to control the wether a message is
  29. printed if an error value is assigned as well as 3 "benign"
  30. errors that can be ignored.
  31. DBGCFG(Status, DBG_ERROR);
  32. DBGCFG1(Status, DBG_ERROR, ERROR_ACCESS_DENIED);
  33. DBGCFG2(Status, DBG_ERROR, ERROR_INVALID_HANDLE, ERROR_ARENA_TRASHED);
  34. DBGCFG3(Status, DBG_ERROR, ERROR_INVALID_HANDLE, ERROR_ARENA_TRASHED, ERROR_NOT_ENOUGH_MEMORY);
  35. ********************************************************************/
  36. #define DBGCHK .pSetInfo(__LINE__, _T(__FILE__))
  37. #define DBGNOCHK .pNoChk()
  38. #define DBGCFG(TStatusX, Level) (TStatusX).pConfig((Level))
  39. #define DBGCFG1(TStatusX, Level, Safe1) (TStatusX).pConfig((Level), (Safe1))
  40. #define DBGCFG2(TStatusX, Level, Safe1, Safe2) (TStatusX).pConfig((Level), (Safe1), (Safe2))
  41. #define DBGCFG3(TStatusX, Level, Safe1, Safe2, Safe3) (TStatusX).pConfig((Level), (Safe1), (Safe2), (Safe3))
  42. /********************************************************************
  43. Base class for DWORD status.
  44. ********************************************************************/
  45. class TStatusBase {
  46. public:
  47. enum { kUnInitializedValue = 0xabababab };
  48. virtual
  49. TStatusBase::
  50. ~TStatusBase(
  51. VOID
  52. );
  53. DWORD
  54. TStatusBase::
  55. dwGeTStatusBase(
  56. VOID
  57. ) const;
  58. TStatusBase&
  59. TStatusBase::
  60. pSetInfo(
  61. IN UINT uLine,
  62. IN LPCTSTR pszFile
  63. );
  64. TStatusBase&
  65. TStatusBase::
  66. pNoChk(
  67. VOID
  68. );
  69. VOID
  70. TStatusBase::
  71. pConfig(
  72. IN UINT uDbgLevel,
  73. IN DWORD dwStatusSafe1 = -1,
  74. IN DWORD dwStatusSafe2 = -1,
  75. IN DWORD dwStatusSafe3 = -1
  76. );
  77. operator DWORD(
  78. VOID
  79. ) const;
  80. DWORD
  81. TStatusBase::
  82. operator=(
  83. IN DWORD dwStatus
  84. );
  85. protected:
  86. TStatusBase::
  87. TStatusBase(
  88. IN BOOL bStatus,
  89. IN UINT uDbgLevel
  90. );
  91. private:
  92. DWORD m_dwStatus;
  93. DWORD m_dwStatusSafe1;
  94. DWORD m_dwStatusSafe2;
  95. DWORD m_dwStatusSafe3;
  96. UINT m_uDbgLevel;
  97. UINT m_uLine;
  98. LPCTSTR m_pszFile;
  99. };
  100. /********************************************************************
  101. DWORD status class.
  102. ********************************************************************/
  103. class TStatus : public TStatusBase {
  104. public:
  105. TStatus::
  106. TStatus(
  107. IN DWORD dwStatus = kUnInitializedValue
  108. );
  109. TStatus::
  110. ~TStatus(
  111. VOID
  112. );
  113. private:
  114. //
  115. // Don't let clients use operator= without going through the
  116. // base class (i.e., using DBGCHK ).
  117. //
  118. // If you get an error trying to access private member function '=,'
  119. // you are trying to set the status without using the DBGCHK macro.
  120. //
  121. // This is needed to update the line and file, which must be done
  122. // at the macro level (not inline C++ function) since __LINE__ and
  123. // __FILE__ are handled by the preprocessor.
  124. //
  125. DWORD
  126. TStatus::
  127. operator=(
  128. DWORD dwStatus
  129. );
  130. };
  131. /********************************************************************
  132. Base class for BOOL status.
  133. ********************************************************************/
  134. class TStatusBBase {
  135. public:
  136. enum { kUnInitializedValue = 0xabababab };
  137. virtual
  138. TStatusBBase::
  139. ~TStatusBBase(
  140. VOID
  141. );
  142. BOOL
  143. TStatusBBase::
  144. bGetStatus(
  145. VOID
  146. ) const;
  147. TStatusBBase &
  148. TStatusBBase::
  149. pSetInfo(
  150. IN UINT uLine,
  151. IN LPCTSTR pszFile
  152. );
  153. TStatusBBase &
  154. TStatusBBase::
  155. pNoChk(
  156. VOID
  157. );
  158. VOID
  159. TStatusBBase::
  160. pConfig(
  161. IN UINT uDbgLevel,
  162. IN DWORD dwStatusSafe1 = -1,
  163. IN DWORD dwStatusSafe2 = -1,
  164. IN DWORD dwStatusSafe3 = -1
  165. );
  166. operator BOOL(
  167. VOID
  168. ) const;
  169. BOOL
  170. TStatusBBase::
  171. operator=(
  172. IN BOOL bStatus
  173. );
  174. protected:
  175. TStatusBBase::
  176. TStatusBBase(
  177. IN BOOL bStatus,
  178. IN UINT uDbgLevel
  179. );
  180. private:
  181. BOOL m_bStatus;
  182. DWORD m_dwStatusSafe1;
  183. DWORD m_dwStatusSafe2;
  184. DWORD m_dwStatusSafe3;
  185. UINT m_uDbgLevel;
  186. UINT m_uLine;
  187. LPCTSTR m_pszFile;
  188. };
  189. /********************************************************************
  190. BOOL status class.
  191. ********************************************************************/
  192. class TStatusB : public TStatusBBase {
  193. public:
  194. TStatusB::
  195. TStatusB(
  196. IN BOOL bStatus = kUnInitializedValue
  197. );
  198. TStatusB::
  199. ~TStatusB(
  200. VOID
  201. );
  202. private:
  203. //
  204. // Don't let clients use operator= without going through the
  205. // base class (i.e., using DBGCHK ).
  206. //
  207. // If you get an error trying to access private member function '=,'
  208. // you are trying to set the status without using the DBGCHK macro.
  209. //
  210. // This is needed to update the line and file, which must be done
  211. // at the macro level (not inline C++ function) since __LINE__ and
  212. // __FILE__ are handled by the preprocessor.
  213. //
  214. BOOL
  215. TStatusB::
  216. operator=(
  217. IN BOOL bStatus
  218. );
  219. };
  220. /********************************************************************
  221. Base class for HRESULT status.
  222. ********************************************************************/
  223. class TStatusHBase {
  224. public:
  225. enum { kUnInitializedValue = 0xabababab };
  226. virtual
  227. TStatusHBase::
  228. ~TStatusHBase(
  229. VOID
  230. );
  231. HRESULT
  232. TStatusHBase::
  233. hrGetStatus(
  234. VOID
  235. ) const;
  236. TStatusHBase &
  237. TStatusHBase::
  238. pSetInfo(
  239. IN UINT uLine,
  240. IN LPCTSTR pszFile
  241. );
  242. TStatusHBase &
  243. TStatusHBase::
  244. pNoChk(
  245. VOID
  246. );
  247. VOID
  248. TStatusHBase::
  249. pConfig(
  250. IN UINT uDbgLevel,
  251. IN DWORD hrStatusSafe1 = -1,
  252. IN DWORD hrStatusSafe2 = -1,
  253. IN DWORD hrStatusSafe3 = -1
  254. );
  255. operator HRESULT(
  256. VOID
  257. ) const;
  258. HRESULT
  259. TStatusHBase::
  260. operator=(
  261. IN HRESULT hrStatus
  262. );
  263. protected:
  264. TStatusHBase::
  265. TStatusHBase(
  266. IN HRESULT hrStatus,
  267. IN UINT m_uDbgLevel
  268. );
  269. private:
  270. HRESULT m_hrStatus;
  271. HRESULT m_hrStatusSafe1;
  272. HRESULT m_hrStatusSafe2;
  273. HRESULT m_hrStatusSafe3;
  274. UINT m_uDbgLevel;
  275. UINT m_uLine;
  276. LPCTSTR m_pszFile;
  277. };
  278. /********************************************************************
  279. HRESULT status class.
  280. ********************************************************************/
  281. class TStatusH : public TStatusHBase {
  282. public:
  283. TStatusH::
  284. TStatusH(
  285. IN HRESULT hrStatus = kUnInitializedValue
  286. );
  287. TStatusH::
  288. ~TStatusH(
  289. VOID
  290. );
  291. private:
  292. //
  293. // Don't let clients use operator= without going through the
  294. // base class (i.e., using DBGCHK ).
  295. //
  296. // If you get an error trying to access private member function '=,'
  297. // you are trying to set the status without using the DBGCHK macro.
  298. //
  299. // This is needed to update the line and file, which must be done
  300. // at the macro level (not inline C++ function) since __LINE__ and
  301. // __FILE__ are handled by the preprocessor.
  302. //
  303. HRESULT
  304. TStatusH::
  305. operator=(
  306. IN HRESULT hrStatus
  307. );
  308. };
  309. #else
  310. /********************************************************************
  311. Non Debug version TStatusX
  312. ********************************************************************/
  313. #define DBGCHK // Empty
  314. #define DBGNOCHK // Empty
  315. #define DBGCFG(TStatusX, Level) // Empty
  316. #define DBGCFG1(TStatusX, Level, Safe1) // Empty
  317. #define DBGCFG2(TStatusX, Level, Safe1, Safe2) // Empty
  318. #define DBGCFG3(TStatusX, Level, Safe1, Safe2, Safe3) // Empty
  319. #define TStatusB BOOL // BOOL in free build
  320. #define TStatus DWORD // DWORD in free build
  321. #define TStatusH HRESULT // HRESULT in free build
  322. #endif // DBG
  323. #endif // DBGSTATE_HXX