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.

268 lines
6.8 KiB

  1. /***************************************************************************
  2. *
  3. * File: hwsdebug.c
  4. *
  5. * INTEL Corporation Proprietary Information
  6. * Copyright (c) 1996 Intel Corporation.
  7. *
  8. * This listing is supplied under the terms of a license agreement
  9. * with INTEL Corporation and may not be used, copied, nor disclosed
  10. * except in accordance with the terms of that agreement.
  11. *
  12. ***************************************************************************
  13. *
  14. * $Workfile: hwsdebug.c $
  15. * $Revision: 1.13 $
  16. * $Modtime: 13 Dec 1996 11:44:24 $
  17. * $Log: S:\sturgeon\src\h245ws\vcs\hwsdebug.c_v $
  18. *
  19. * Rev 1.13 13 Dec 1996 12:12:50 SBELL1
  20. * moved ifdef _cplusplus to after includes
  21. *
  22. * Rev 1.12 11 Dec 1996 13:41:56 SBELL1
  23. * Put in UNICODE tracing stuff.
  24. *
  25. * Rev 1.11 01 Oct 1996 14:49:22 EHOWARDX
  26. * Revision 1.9 copied to tip.
  27. *
  28. * Rev 1.9 May 28 1996 10:40:14 plantz
  29. * Change vsprintf to wvsprintf.
  30. *
  31. * Rev 1.8 29 Apr 1996 17:13:16 unknown
  32. * Fine-tuning instance-specific name.
  33. *
  34. * Rev 1.7 29 Apr 1996 13:04:56 EHOWARDX
  35. *
  36. * Added timestamp and instance-specific short name.
  37. *
  38. * Rev 1.6 Apr 24 1996 16:20:56 plantz
  39. * Removed include winsock2.h and incommon.h
  40. *
  41. * Rev 1.4.1.0 Apr 24 1996 16:19:54 plantz
  42. * Removed include winsock2.h and callcont.h
  43. *
  44. * Rev 1.4 01 Apr 1996 14:20:34 unknown
  45. * Shutdown redesign.
  46. *
  47. * Rev 1.3 22 Mar 1996 16:04:18 EHOWARDX
  48. * Added #if defined(_DEBUG) around whole file.
  49. *
  50. * Rev 1.2 22 Mar 1996 15:25:28 EHOWARDX
  51. * Changed to use ISR_HookDbgStr instead of OutputDebugString.
  52. *
  53. * Rev 1.1 14 Mar 1996 17:01:00 EHOWARDX
  54. *
  55. * NT4.0 testing; got rid of HwsAssert(); got rid of TPKT/WSCB.
  56. *
  57. * Rev 1.0 08 Mar 1996 20:22:14 unknown
  58. * Initial revision.
  59. *
  60. ***************************************************************************/
  61. #if defined(DBG) && !defined(ISRDBG)
  62. #include <windows.h>
  63. #include <stdio.h>
  64. #include <stdarg.h>
  65. #if defined(__cplusplus)
  66. extern "C"
  67. {
  68. #endif // (__cplusplus)
  69. DWORD g_dwLinkDbgLevel = 0;
  70. BOOL g_fLinkDbgInitialized = FALSE;
  71. void LinkDbgInit() {
  72. #define H323_REGKEY_ROOT \
  73. TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\H323TSP")
  74. #define H323_REGVAL_DEBUGLEVEL \
  75. TEXT("DebugLevel")
  76. #define H323_REGVAL_LINKDEBUGLEVEL \
  77. TEXT("LinkDebugLevel")
  78. HKEY hKey;
  79. LONG lStatus;
  80. DWORD dwValue;
  81. DWORD dwValueSize;
  82. DWORD dwValueType;
  83. LPSTR pszValue;
  84. LPSTR pszKey = H323_REGKEY_ROOT;
  85. // only call this once
  86. g_fLinkDbgInitialized = TRUE;
  87. // open registry subkey
  88. lStatus = RegOpenKeyEx(
  89. HKEY_LOCAL_MACHINE,
  90. pszKey,
  91. 0,
  92. KEY_READ,
  93. &hKey
  94. );
  95. // validate return code
  96. if (lStatus != ERROR_SUCCESS) {
  97. return; // bail...
  98. }
  99. // initialize values
  100. dwValueType = REG_DWORD;
  101. dwValueSize = sizeof(DWORD);
  102. // retrieve link debug level
  103. pszValue = H323_REGVAL_LINKDEBUGLEVEL;
  104. // query for registry value
  105. lStatus = RegQueryValueEx(
  106. hKey,
  107. pszValue,
  108. NULL,
  109. &dwValueType,
  110. (LPBYTE)&dwValue,
  111. &dwValueSize
  112. );
  113. // validate return code
  114. if (lStatus != ERROR_SUCCESS) {
  115. // initialize values
  116. dwValueType = REG_DWORD;
  117. dwValueSize = sizeof(DWORD);
  118. // retrieve tsp debug level
  119. pszValue = H323_REGVAL_DEBUGLEVEL;
  120. // query for registry value
  121. lStatus = RegQueryValueEx(
  122. hKey,
  123. pszValue,
  124. NULL,
  125. &dwValueType,
  126. (LPBYTE)&dwValue,
  127. &dwValueSize
  128. );
  129. }
  130. // validate return code
  131. if (lStatus == ERROR_SUCCESS) {
  132. // update debug level
  133. g_dwLinkDbgLevel = dwValue;
  134. }
  135. // close key
  136. RegCloseKey(hKey);
  137. }
  138. /*****************************************************************************
  139. *
  140. * TYPE: Global System
  141. *
  142. * PROCEDURE: HwsTrace
  143. *
  144. * DESCRIPTION:
  145. * Trace function for HWS
  146. *
  147. * INPUT:
  148. * dwInst Instance identifier for trace message
  149. * dwLevel Trace level as defined below
  150. * pszFormat sprintf string format with 1-N parameters
  151. *
  152. * Trace Level (byLevel) Definitions:
  153. * HWS_CRITICAL Progammer errors that should never happen
  154. * HWS_ERROR Errors that need to be fixed
  155. * HWS_WARNING The user could have problems if not corrected
  156. * HWS_NOTIFY Status, events, settings...
  157. * HWS_TRACE Trace info that will not overrun the system
  158. * HWS_TEMP Trace info that may be reproduced in heavy loops
  159. *
  160. * RETURN VALUE:
  161. * None
  162. *
  163. *****************************************************************************/
  164. void HwsTrace (DWORD dwInst,
  165. BYTE byLevel,
  166. #ifdef UNICODE_TRACE
  167. LPTSTR pszFormat,
  168. #else
  169. LPSTR pszFormat,
  170. #endif
  171. ...)
  172. {
  173. #define DEBUG_FORMAT_HEADER "LINK "
  174. #define DEBUG_FORMAT_TIMESTAMP "[%02u:%02u:%02u.%03u"
  175. #define DEBUG_FORMAT_THREADID ",tid=%x] "
  176. #define MAX_DEBUG_STRLEN 512
  177. va_list Args;
  178. SYSTEMTIME SystemTime;
  179. char szDebugMessage[MAX_DEBUG_STRLEN+1];
  180. int nLengthRemaining;
  181. int nLength = 0;
  182. // make sure initialized
  183. if (g_fLinkDbgInitialized == FALSE) {
  184. LinkDbgInit();
  185. }
  186. // validate debug log level
  187. if ((DWORD)(BYTE)byLevel > g_dwLinkDbgLevel) {
  188. return; // bail...
  189. }
  190. // retrieve local time
  191. GetLocalTime(&SystemTime);
  192. // add component header to the debug message
  193. nLength += sprintf(&szDebugMessage[nLength],
  194. DEBUG_FORMAT_HEADER
  195. );
  196. // add timestamp to the debug message
  197. nLength += sprintf(&szDebugMessage[nLength],
  198. DEBUG_FORMAT_TIMESTAMP,
  199. SystemTime.wHour,
  200. SystemTime.wMinute,
  201. SystemTime.wSecond,
  202. SystemTime.wMilliseconds
  203. );
  204. // add thread id to the debug message
  205. nLength += sprintf(&szDebugMessage[nLength],
  206. DEBUG_FORMAT_THREADID,
  207. GetCurrentThreadId()
  208. );
  209. // point at first argument
  210. va_start(Args, pszFormat);
  211. // determine number of bytes left in buffer
  212. nLengthRemaining = sizeof(szDebugMessage) - nLength;
  213. // add user specified debug message
  214. _vsnprintf(&szDebugMessage[nLength],
  215. nLengthRemaining,
  216. pszFormat,
  217. Args
  218. );
  219. // release pointer
  220. va_end(Args);
  221. // output message to specified sink
  222. OutputDebugString(szDebugMessage);
  223. OutputDebugString("\n");
  224. } // HwsTrace()
  225. #endif // DBG
  226. #if defined(__cplusplus)
  227. }
  228. #endif // (__cplusplus)