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.

205 lines
4.0 KiB

  1. #ifndef _MTRACE_H
  2. #define _MTRACE_H
  3. //
  4. // Copyright (c) Microsoft. All Rights Reserved
  5. //
  6. // THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF Microsoft.
  7. // The copyright notice above does not evidence any
  8. // actual or intended publication of such source code.
  9. //
  10. // OneLiner : MWMIObject interface.
  11. // DevUnit : wlbstest
  12. // Author : Murtaza Hakim
  13. //
  14. // Description:
  15. // -----------
  16. // include files
  17. //
  18. #include <vector>
  19. #include <string>
  20. #include <fstream>
  21. #include <iostream>
  22. #include <windows.h>
  23. #include <winbase.h>
  24. #include <wbemidl.h>
  25. #include <comdef.h>
  26. using namespace std;
  27. //
  28. // use this call to do tracing.
  29. // eg usage.
  30. // TRACE( MTrace::WARNING, "running out of non paged pool\n");
  31. #define TRACE(traceLevel, traceMessage) MYTRACE( (__LINE__ ), (__FILE__), (traceLevel), (traceMessage) );
  32. class MTrace
  33. {
  34. public:
  35. // the trace levels which can be set.
  36. enum TraceLevel
  37. {
  38. FULL_TRACE = 0,
  39. INFO = 1,
  40. WARNING = 2,
  41. SEVERE_ERROR = 3,
  42. NO_TRACE = 100,
  43. };
  44. // the maximum single message size which can be logged.
  45. enum
  46. {
  47. MAX_MESSAGE_SIZE = 2000,
  48. };
  49. //
  50. // Description:
  51. // -----------
  52. // gets instance of MTrace singleton class.
  53. //
  54. // Parameters:
  55. // ----------
  56. // none
  57. //
  58. // Returns:
  59. // -------
  60. // the MTrace singleton object.
  61. static MTrace*
  62. Instance();
  63. //
  64. // Description:
  65. // -----------
  66. // Initialize. The trace object will write the trace data to the screen and the traceFile
  67. // if file is specified.
  68. //
  69. // Parameters:
  70. // ----------
  71. // level IN : level determines what is the high threshold for data to be output.
  72. // traceFile IN : file to store trace output to. Any previous file is deleted when call is
  73. // made.
  74. //
  75. // Returns:
  76. // -------
  77. // none
  78. void
  79. Initialize( TraceLevel level,
  80. string traceFile );
  81. void
  82. Initialize( TraceLevel level );
  83. //
  84. // Description:
  85. // -----------
  86. // Initializes the objects to which the singleton object will write data to.
  87. //
  88. // Parameters:
  89. // ----------
  90. // level IN : level determines what is the high threshold for data to be output.
  91. // traceMessage IN : trace message to be logged.
  92. //
  93. // Returns:
  94. // -------
  95. // none
  96. void
  97. SendTraceOutput( TraceLevel level,
  98. wstring traceMessage );
  99. void
  100. SendTraceOutput( TraceLevel level,
  101. string traceMessage );
  102. //
  103. // Description:
  104. // -----------
  105. // Gets the present trace level
  106. //
  107. // Parameters:
  108. // ----------
  109. // none
  110. //
  111. // Returns:
  112. // -------
  113. // trace level set.
  114. TraceLevel
  115. GetLevel();
  116. //
  117. // Description:
  118. // -----------
  119. // Sets the trace level.
  120. //
  121. // Parameters:
  122. // ----------
  123. // level IN : level to set.
  124. //
  125. // Returns:
  126. // -------
  127. // none
  128. void
  129. SetLevel(TraceLevel level );
  130. protected:
  131. MTrace();
  132. private:
  133. static MTrace* _instance;
  134. string _traceFile;
  135. TraceLevel _level;
  136. void
  137. FormatOutput( TraceLevel level,
  138. string traceMessage );
  139. };
  140. //
  141. // Ensure type safety
  142. typedef class MTrace MTrace;
  143. // helper functions.
  144. //
  145. void
  146. MYTRACE( int lineNum, string fileName, MTrace::TraceLevel level, string traceMessage );
  147. void
  148. MYTRACE( int lineNum, string fileName, MTrace::TraceLevel level, wstring traceMessage );
  149. // utility functions
  150. void
  151. CharToWChar( PCHAR pchCharString,
  152. int iSizeOfCharString,
  153. PWCHAR pwchCharString,
  154. int iSizeOfWideCharString );
  155. void
  156. WCharToChar( PWCHAR pwchWideCharString,
  157. int iSizeOfWCharString,
  158. PCHAR pchCharString,
  159. int iSizeOfCharString );
  160. #endif