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.

237 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. stitrace.h
  5. Abstract:
  6. This file defines functions and types required to support file logging
  7. for all STI components
  8. Author:
  9. Vlad Sadovsky (vlads) 02-Sep-1997
  10. Environment:
  11. User Mode - Win32
  12. Revision History:
  13. 02-Sep-1997 VladS created
  14. --*/
  15. # ifndef _STITRACE_H_
  16. # define _STITRACE_H_
  17. # include <windows.h>
  18. /***********************************************************
  19. * Named constants definitions
  20. ************************************************************/
  21. #define STI_MAX_LOG_SIZE 1000000 // in bytes
  22. #define STI_TRACE_INFORMATION 0x00000001
  23. #define STI_TRACE_WARNING 0x00000002
  24. #define STI_TRACE_ERROR 0x00000004
  25. #define STI_TRACE_ADD_TIME 0x00010000
  26. #define STI_TRACE_ADD_MODULE 0x00020000
  27. #define STI_TRACE_ADD_THREAD 0x00040000
  28. #define STI_TRACE_ADD_PROCESS 0x00080000
  29. #define STI_TRACE_LOG_TOUI 0x00100000
  30. #define STI_TRACE_MESSAGE_TYPE_MASK 0x0000ffff
  31. #define STI_TRACE_MESSAGE_FLAGS_MASK 0xffff0000
  32. #ifndef STIMON_MSG_LOG_MESSAGE
  33. // BUGBUG
  34. #define STIMON_MSG_LOG_MESSAGE WM_USER+205
  35. #endif
  36. #ifdef __cplusplus
  37. //
  38. // Class definitions used only in C++ code
  39. //
  40. #include <base.h>
  41. #include <lock.h>
  42. #include <stistr.h>
  43. #ifndef DLLEXP
  44. //#define DLLEXP __declspec( dllexport )
  45. #define DLLEXP
  46. #endif
  47. /***********************************************************
  48. * Type Definitions
  49. ************************************************************/
  50. #define SIGNATURE_FILE_LOG (DWORD)'SFLa'
  51. #define SIGNATURE_FILE_LOG_FREE (DWORD)'SFLf'
  52. #define STIFILELOG_CHECK_TRUNCATE_ON_BOOT 0x00000001
  53. class STI_FILE_LOG : public BASE {
  54. private:
  55. DWORD m_dwSignature;
  56. LPCTSTR m_lpszSource; // Name of the file , containing log
  57. DWORD m_dwReportMode; // Bit mask , describing which messages types get reported
  58. DWORD m_dwMaxSize; // Maximum size ( in bytes )
  59. HANDLE m_hLogFile;
  60. CRIT_SECT m_CritSect;
  61. HANDLE m_hMutex;
  62. HMODULE m_hDefaultMessageModule;
  63. LONG m_lWrittenHeader;
  64. TCHAR m_szLogFilePath[MAX_PATH];
  65. TCHAR m_szTracerName[16];
  66. TCHAR m_szProcessName[13];
  67. HWND m_hLogWindow ;
  68. VOID
  69. WriteStringToLog(
  70. LPCTSTR pszTextBuffer,
  71. BOOL fFlush=FALSE
  72. );
  73. public:
  74. DLLEXP
  75. STI_FILE_LOG(
  76. IN LPCTSTR lpszTracerName,
  77. IN LPCTSTR lpszLogName,
  78. IN DWORD dwFlags = 0,
  79. IN HMODULE hMessageModule = NULL
  80. );
  81. DLLEXP
  82. ~STI_FILE_LOG( VOID);
  83. // *** IUnknown methods ***
  84. STDMETHODIMP QueryInterface( REFIID riid, LPVOID * ppvObj);
  85. STDMETHODIMP_(ULONG) AddRef( void);
  86. STDMETHODIMP_(ULONG) Release( void);
  87. BOOL
  88. inline
  89. IsValid(VOID)
  90. {
  91. return (( QueryError() == NO_ERROR) && (m_dwSignature == SIGNATURE_FILE_LOG));
  92. }
  93. DWORD
  94. inline
  95. SetReportMode(
  96. DWORD dwNewMode
  97. ) {
  98. DWORD dwOldMode = m_dwReportMode;
  99. m_dwReportMode = dwNewMode;
  100. return dwOldMode;
  101. }
  102. DWORD
  103. inline
  104. QueryReportMode(
  105. VOID
  106. ) {
  107. return m_dwReportMode;
  108. }
  109. VOID
  110. inline
  111. SetLogWindowHandle(
  112. HWND hwnd
  113. )
  114. {
  115. m_hLogWindow = hwnd;
  116. }
  117. VOID
  118. WriteLogSessionHeader(
  119. VOID
  120. );
  121. DLLEXP
  122. void
  123. ReportMessage(
  124. DWORD dwType,
  125. LPCTSTR psz,
  126. ...
  127. );
  128. DLLEXP
  129. void
  130. STI_FILE_LOG::
  131. ReportMessage(
  132. DWORD dwType,
  133. DWORD idMessage,
  134. ...
  135. );
  136. DLLEXP
  137. void
  138. vReportMessage(
  139. DWORD dwType,
  140. LPCTSTR psz,
  141. va_list arglist
  142. );
  143. };
  144. typedef STI_FILE_LOG * LPSTI_FILE_LOG;
  145. #endif // C++
  146. //
  147. // C calls to allow non-C++ code access file logging objects
  148. //
  149. #ifdef __cplusplus
  150. extern "C" {
  151. #endif
  152. HANDLE
  153. WINAPI
  154. CreateStiFileLog(
  155. IN LPCTSTR lpszTracerName,
  156. IN LPCTSTR lpszLogName,
  157. IN DWORD dwReportMode
  158. );
  159. DWORD
  160. WINAPI
  161. CloseStiFileLog(
  162. IN HANDLE hFileLog
  163. );
  164. DWORD
  165. WINAPI
  166. ReportStiLogMessage(
  167. IN HANDLE hFileLog,
  168. IN DWORD dwType,
  169. IN LPCTSTR psz,
  170. ...
  171. );
  172. #ifdef __cplusplus
  173. }
  174. #endif
  175. #endif // _STITRACE_H_
  176. /************************ End of File ***********************/