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.

179 lines
4.0 KiB

  1. /*
  2. * Class:
  3. *
  4. * WmiDebugLog
  5. *
  6. * Description:
  7. *
  8. *
  9. *
  10. * Version:
  11. *
  12. * Initial
  13. *
  14. * Last Changed:
  15. *
  16. * See Source Depot for change history
  17. *
  18. */
  19. #ifndef __WMILOG_H
  20. #define __WMILOG_H
  21. #include <locks.h>
  22. #if 0
  23. #ifdef LOGGINGDEBUG_INIT
  24. class __declspec ( dllexport ) WmiDebugLog
  25. #else
  26. class __declspec ( dllimport ) WmiDebugLog
  27. #endif
  28. #else
  29. class WmiDebugLog
  30. #endif
  31. {
  32. public:
  33. enum WmiDebugContext
  34. {
  35. FILE = 0 ,
  36. DEBUG = 1
  37. } ;
  38. private:
  39. CriticalSection m_CriticalSection ;
  40. static long s_ReferenceCount ;
  41. WmiAllocator &m_Allocator ;
  42. enum WmiDebugContext m_DebugContext ;
  43. BOOL m_Logging ;
  44. BOOL m_Verbose ;
  45. DWORD m_DebugLevel ;
  46. DWORD m_DebugFileSize;
  47. wchar_t *m_DebugComponent ;
  48. wchar_t *m_DebugFile ;
  49. HANDLE m_DebugFileHandle ;
  50. static BOOL s_Initialised ;
  51. static void SetEventNotification () ;
  52. void LoadRegistry_Logging () ;
  53. void LoadRegistry_Level () ;
  54. void LoadRegistry_File () ;
  55. void LoadRegistry_FileSize () ;
  56. void LoadRegistry_Type () ;
  57. void SetRegistry_Logging () ;
  58. void SetRegistry_Level () ;
  59. void SetRegistry_File () ;
  60. void SetRegistry_FileSize () ;
  61. void SetRegistry_Type () ;
  62. void SetDefaultFile () ;
  63. void OpenFileForOutput () ;
  64. void OpenOutput () ;
  65. void CloseOutput () ;
  66. void FlushOutput () ;
  67. void SwapFileOver () ;
  68. void WriteOutput ( const WCHAR *a_DebugOutput ) ;
  69. protected:
  70. public:
  71. WmiDebugLog ( WmiAllocator &a_Allocator ) ;
  72. virtual ~WmiDebugLog () ;
  73. WmiStatusCode Initialize ( const wchar_t *a_DebugComponent ) ;
  74. /*************************************************************************
  75. * There are 3 functions to write to a log file, which may be used in accordance with the following rules:
  76. *
  77. * 1. The user always knows whether he is writing to an ANSI file or a Unicode file, and he
  78. * has to make sure this holds good in the rules 2, 3 and 4 below. This will be changed later to
  79. * make it more flowxible to the user.
  80. * 2. Write() takes wchar_t arguments and the function will write and ANSI or Unicode string
  81. * to the log file depending on what wchar_t maps to, in the compilation.
  82. * 3. WriteW() takes WCHAR arguments only, and expects that the file being written to is a Unicode file.
  83. * 4. WriteA() takes char arguments only, and expects that the file being written to is an ANSI file.
  84. *
  85. ****************************************************************/
  86. void Write ( const wchar_t *a_DebugFormatString , ... ) ;
  87. void Write ( const wchar_t *a_File , const ULONG a_Line , const wchar_t *a_DebugFormatString , ... ) ;
  88. void Flush () ;
  89. void LoadRegistry () ;
  90. void SetRegistry () ;
  91. void SetLevel ( const DWORD &a_DebugLevel ) ;
  92. DWORD GetLevel () ;
  93. void SetContext ( const enum WmiDebugContext &a_DebugContext ) ;
  94. enum WmiDebugContext GetContext () ;
  95. void SetFile ( const wchar_t *a_File ) ;
  96. wchar_t *GetFile () ;
  97. void SetLogging ( BOOL a_Logging = TRUE ) ;
  98. BOOL GetLogging () ;
  99. void SetVerbose ( BOOL a_Verbose = TRUE ) ;
  100. BOOL GetVerbose () ;
  101. void CommitContext () ;
  102. static WmiDebugLog *s_WmiDebugLog ;
  103. static WmiStatusCode Initialize ( WmiAllocator &a_Allocator ) ;
  104. static WmiStatusCode UnInitialize ( WmiAllocator &a_Allocator ) ;
  105. public:
  106. } ;
  107. inline DWORD WmiDebugLog :: GetLevel ()
  108. {
  109. DWORD t_Level = m_DebugLevel ;
  110. return t_Level ;
  111. }
  112. inline wchar_t *WmiDebugLog :: GetFile ()
  113. {
  114. wchar_t *t_File = m_DebugFile ;
  115. return t_File ;
  116. }
  117. inline BOOL WmiDebugLog :: GetLogging ()
  118. {
  119. return m_Logging ;
  120. }
  121. inline void WmiDebugLog :: SetVerbose ( BOOL a_Verbose )
  122. {
  123. m_Verbose = a_Verbose ;
  124. }
  125. inline BOOL WmiDebugLog :: GetVerbose ()
  126. {
  127. return m_Verbose ;
  128. }
  129. #ifdef DBG
  130. #define DebugMacro3(a) { \
  131. \
  132. if ( WmiDebugLog :: s_WmiDebugLog && WmiDebugLog :: s_WmiDebugLog->GetLogging () && ( WmiDebugLog :: s_WmiDebugLog->GetVerbose () || ( WmiDebugLog :: s_WmiDebugLog->GetLevel () & 8 ) ) ) \
  133. { \
  134. {a ; } \
  135. } \
  136. }
  137. #else
  138. #define DebugMacro3(a)
  139. #endif
  140. #endif __WMILOG_H