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.

274 lines
11 KiB

  1. #ifndef __CLIENT_UTILS_H__
  2. #define __CLIENT_UTILS_H__
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #ifdef TRACELOG
  7. #include <tchar.h>
  8. #include <stdio.h>
  9. #include <stdarg.h>
  10. #include <windows.h>
  11. #include <winbase.h>
  12. #include <rtutils.h>
  13. #include "tapi.h"
  14. #define MAXDEBUGSTRINGLENGTH 1024
  15. #define TL_ERROR ((DWORD)0x00010000 | TRACE_USE_MASK)
  16. #define TL_WARN ((DWORD)0x00020000 | TRACE_USE_MASK)
  17. #define TL_INFO ((DWORD)0x00040000 | TRACE_USE_MASK)
  18. #define TL_TRACE ((DWORD)0x00080000 | TRACE_USE_MASK)
  19. #define TL_EVENT ((DWORD)0x00100000 | TRACE_USE_MASK)
  20. BOOL TRACELogRegister(LPCTSTR szName);
  21. void TRACELogDeRegister();
  22. void TRACELogPrint(IN DWORD dwDbgLevel, IN LPCSTR DbgMessage, IN ...);
  23. extern char *TraceLevel(DWORD dwDbgLevel);
  24. extern void TAPIFormatMessage(HRESULT hr, LPVOID lpMsgBuf);
  25. #define TRACELOGREGISTER(arg) TRACELogRegister(arg)
  26. #define TRACELOGDEREGISTER() TRACELogDeRegister()
  27. #define LOG(arg) TRACELogPrint arg
  28. extern char sg_szTraceName[100];
  29. extern DWORD sg_dwTracingToDebugger;
  30. extern DWORD sg_dwDebuggerMask;
  31. extern DWORD sg_dwTraceID;
  32. #define DECLARE_TRACELOG_CLASS(x) \
  33. void TRACELogPrint(IN DWORD dwDbgLevel, IN LPCSTR lpszFormat, IN ...) \
  34. { \
  35. char szTraceBuf[MAXDEBUGSTRINGLENGTH + 1]; \
  36. va_list arglist; \
  37. \
  38. if ( ( sg_dwTracingToDebugger > 0 ) && \
  39. ( 0 != ( dwDbgLevel & sg_dwDebuggerMask ) ) ) \
  40. { \
  41. SYSTEMTIME SystemTime; \
  42. GetLocalTime(&SystemTime); \
  43. \
  44. wsprintfA(szTraceBuf, \
  45. "%s:[%02u:%02u:%02u.%03u,tid=%x:] [%s] (%p) %s::", \
  46. sg_szTraceName, \
  47. SystemTime.wHour, \
  48. SystemTime.wMinute, \
  49. SystemTime.wSecond, \
  50. SystemTime.wMilliseconds, \
  51. GetCurrentThreadId(), \
  52. TraceLevel(dwDbgLevel), \
  53. this, \
  54. _T(#x)); \
  55. \
  56. va_list ap; \
  57. va_start(ap, lpszFormat); \
  58. \
  59. _vsnprintf(&szTraceBuf[lstrlenA(szTraceBuf)], \
  60. MAXDEBUGSTRINGLENGTH - lstrlenA(szTraceBuf), \
  61. lpszFormat, \
  62. ap \
  63. ); \
  64. \
  65. lstrcatA (szTraceBuf, "\n"); \
  66. \
  67. OutputDebugStringA (szTraceBuf); \
  68. \
  69. va_end(ap); \
  70. } \
  71. \
  72. if (sg_dwTraceID != INVALID_TRACEID) \
  73. { \
  74. wsprintfA(szTraceBuf, "[%s] (%p) %s::%s", TraceLevel(dwDbgLevel), this, _T(#x), lpszFormat); \
  75. \
  76. va_start(arglist, lpszFormat); \
  77. TraceVprintfExA(sg_dwTraceID, dwDbgLevel | TRACE_USE_MSEC, szTraceBuf, arglist); \
  78. va_end(arglist); \
  79. } \
  80. } \
  81. \
  82. void TRACELogPrint(IN DWORD dwDbgLevel,IN HRESULT hr, IN LPCSTR lpszFormat, IN ...) \
  83. { \
  84. char szTraceBuf[MAXDEBUGSTRINGLENGTH + 1]; \
  85. LPVOID lpMsgBuf = NULL; \
  86. va_list arglist; \
  87. \
  88. TAPIFormatMessage(hr, &lpMsgBuf); \
  89. \
  90. if ( ( sg_dwTracingToDebugger > 0 ) && \
  91. ( 0 != ( dwDbgLevel & sg_dwDebuggerMask ) ) ) \
  92. { \
  93. SYSTEMTIME SystemTime; \
  94. GetLocalTime(&SystemTime); \
  95. \
  96. wsprintfA(szTraceBuf, \
  97. "%s:[%02u:%02u:%02u.%03u,tid=%x:] [%s] (%p) %s::", \
  98. sg_szTraceName, \
  99. SystemTime.wHour, \
  100. SystemTime.wMinute, \
  101. SystemTime.wSecond, \
  102. SystemTime.wMilliseconds, \
  103. GetCurrentThreadId(), \
  104. TraceLevel(dwDbgLevel), \
  105. this, \
  106. _T(#x) \
  107. ); \
  108. \
  109. va_list ap; \
  110. va_start(ap, lpszFormat); \
  111. \
  112. _vsnprintf(&szTraceBuf[lstrlenA(szTraceBuf)], \
  113. MAXDEBUGSTRINGLENGTH - lstrlenA(szTraceBuf), \
  114. lpszFormat, \
  115. ap \
  116. ); \
  117. \
  118. wsprintfA(&szTraceBuf[lstrlenA(szTraceBuf)], \
  119. " Returned[%lx] %s\n", \
  120. hr, \
  121. lpMsgBuf); \
  122. \
  123. OutputDebugStringA (szTraceBuf); \
  124. \
  125. va_end(ap); \
  126. } \
  127. \
  128. if (sg_dwTraceID != INVALID_TRACEID) \
  129. { \
  130. wsprintfA(szTraceBuf, "[%s] (%p) %s::%s Returned[%lx] %s", TraceLevel(dwDbgLevel), this, _T(#x), lpszFormat,hr, lpMsgBuf ); \
  131. \
  132. va_start(arglist, lpszFormat); \
  133. TraceVprintfExA(sg_dwTraceID, dwDbgLevel | TRACE_USE_MSEC, szTraceBuf, arglist); \
  134. va_end(arglist); \
  135. } \
  136. \
  137. if(lpMsgBuf != NULL) \
  138. { \
  139. LocalFree( lpMsgBuf ); \
  140. } \
  141. } \
  142. \
  143. static void StaticTRACELogPrint(IN DWORD dwDbgLevel, IN LPCSTR lpszFormat, IN ...) \
  144. { \
  145. char szTraceBuf[MAXDEBUGSTRINGLENGTH + 1]; \
  146. va_list arglist; \
  147. \
  148. if ( ( sg_dwTracingToDebugger > 0 ) && \
  149. ( 0 != ( dwDbgLevel & sg_dwDebuggerMask ) ) ) \
  150. { \
  151. SYSTEMTIME SystemTime; \
  152. GetLocalTime(&SystemTime); \
  153. \
  154. wsprintfA(szTraceBuf, \
  155. "%s:[%02u:%02u:%02u.%03u,tid=%x:] [%s] %s::", \
  156. sg_szTraceName, \
  157. SystemTime.wHour, \
  158. SystemTime.wMinute, \
  159. SystemTime.wSecond, \
  160. SystemTime.wMilliseconds, \
  161. GetCurrentThreadId(), \
  162. TraceLevel(dwDbgLevel), \
  163. _T(#x)); \
  164. \
  165. va_list ap; \
  166. va_start(ap, lpszFormat); \
  167. \
  168. _vsnprintf(&szTraceBuf[lstrlenA(szTraceBuf)], \
  169. MAXDEBUGSTRINGLENGTH - lstrlenA(szTraceBuf), \
  170. lpszFormat, \
  171. ap \
  172. ); \
  173. \
  174. lstrcatA (szTraceBuf, "\n"); \
  175. \
  176. OutputDebugStringA (szTraceBuf); \
  177. \
  178. va_end(ap); \
  179. } \
  180. \
  181. if (sg_dwTraceID != INVALID_TRACEID) \
  182. { \
  183. wsprintfA(szTraceBuf, "[%s] %s::%s", TraceLevel(dwDbgLevel), _T(#x), lpszFormat); \
  184. \
  185. va_start(arglist, lpszFormat); \
  186. TraceVprintfExA(sg_dwTraceID, dwDbgLevel | TRACE_USE_MSEC, szTraceBuf, arglist); \
  187. va_end(arglist); \
  188. } \
  189. } \
  190. \
  191. static void StaticTRACELogPrint(IN DWORD dwDbgLevel,IN HRESULT hr, IN LPCSTR lpszFormat, IN ...) \
  192. { \
  193. char szTraceBuf[MAXDEBUGSTRINGLENGTH + 1]; \
  194. LPVOID lpMsgBuf = NULL; \
  195. va_list arglist; \
  196. \
  197. TAPIFormatMessage(hr, &lpMsgBuf); \
  198. \
  199. if ( ( sg_dwTracingToDebugger > 0 ) && \
  200. ( 0 != ( dwDbgLevel & sg_dwDebuggerMask ) ) ) \
  201. { \
  202. SYSTEMTIME SystemTime; \
  203. GetLocalTime(&SystemTime); \
  204. \
  205. wsprintfA(szTraceBuf, \
  206. "%s:[%02u:%02u:%02u.%03u,tid=%x:] [%s] %s::", \
  207. sg_szTraceName, \
  208. SystemTime.wHour, \
  209. SystemTime.wMinute, \
  210. SystemTime.wSecond, \
  211. SystemTime.wMilliseconds, \
  212. GetCurrentThreadId(), \
  213. TraceLevel(dwDbgLevel), \
  214. _T(#x) \
  215. ); \
  216. \
  217. va_list ap; \
  218. va_start(ap, lpszFormat); \
  219. \
  220. _vsnprintf(&szTraceBuf[lstrlenA(szTraceBuf)], \
  221. MAXDEBUGSTRINGLENGTH - lstrlenA(szTraceBuf), \
  222. lpszFormat, \
  223. ap \
  224. ); \
  225. \
  226. wsprintfA(&szTraceBuf[lstrlenA(szTraceBuf)], \
  227. " Returned[%lx] %s\n", \
  228. hr, \
  229. lpMsgBuf); \
  230. \
  231. OutputDebugStringA (szTraceBuf); \
  232. \
  233. va_end(ap); \
  234. } \
  235. \
  236. if (sg_dwTraceID != INVALID_TRACEID) \
  237. { \
  238. wsprintfA(szTraceBuf, "[%s] %s::%s Returned[%lx] %s", TraceLevel(dwDbgLevel), _T(#x), lpszFormat,hr, lpMsgBuf ); \
  239. \
  240. va_start(arglist, lpszFormat); \
  241. TraceVprintfExA(sg_dwTraceID, dwDbgLevel | TRACE_USE_MSEC, szTraceBuf, arglist); \
  242. va_end(arglist); \
  243. } \
  244. \
  245. if(lpMsgBuf != NULL) \
  246. { \
  247. LocalFree( lpMsgBuf ); \
  248. } \
  249. }
  250. #else // TRACELOG not defined
  251. #define TRACELOGREGISTER(arg)
  252. #define TRACELOGDEREGISTER()
  253. #define LOG(arg)
  254. #define STATICLOG(arg)
  255. #define DECLARE_TRACELOG_CLASS(x)
  256. #endif // TRACELOG
  257. #ifdef __cplusplus
  258. }
  259. #endif
  260. #endif //__CLIENT_UTILS_H_