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.

125 lines
2.1 KiB

  1. /*
  2. * LCTrace.cpp
  3. *
  4. * Author: BreenH
  5. *
  6. * Tracing code for the licensing core.
  7. */
  8. #ifdef DBG
  9. /*
  10. * Includes
  11. */
  12. #include "precomp.h"
  13. #include "lctrace.h"
  14. #include "lcreg.h"
  15. /*
  16. * Constants
  17. */
  18. #define LCTRACE_FMT_MSG_SIZE 256
  19. /*
  20. * Globals
  21. */
  22. ULONG g_ulTraceLevel;
  23. /*
  24. * Function Prototypes
  25. */
  26. LPCSTR
  27. TraceLevelString(
  28. ULONG ulTraceLevel
  29. );
  30. /*
  31. * Function Implementations
  32. */
  33. VOID
  34. TraceInitialize(
  35. VOID
  36. )
  37. {
  38. DWORD cbSize;
  39. DWORD dwStatus;
  40. DWORD dwType;
  41. g_ulTraceLevel = LCTRACETYPE_NONE;
  42. cbSize = sizeof(DWORD);
  43. dwStatus = RegQueryValueEx(
  44. GetBaseKey(),
  45. LCREG_TRACEVALUE,
  46. NULL,
  47. &dwType,
  48. (LPBYTE)&g_ulTraceLevel,
  49. &cbSize
  50. );
  51. if (dwStatus == ERROR_SUCCESS)
  52. {
  53. ASSERT(cbSize == sizeof(DWORD));
  54. ASSERT(dwType == REG_DWORD);
  55. if (g_ulTraceLevel != LCTRACETYPE_NONE)
  56. {
  57. DbgPrint("LSCORE: Trace Message: Trace initialized to 0x%x\n", g_ulTraceLevel);
  58. }
  59. }
  60. }
  61. VOID __cdecl
  62. TracePrint(
  63. ULONG ulTraceLevel,
  64. LPCSTR pFormat,
  65. ...
  66. )
  67. {
  68. int cbPrinted;
  69. va_list vaList;
  70. CHAR szFormattedMessage[LCTRACE_FMT_MSG_SIZE];
  71. if ((ulTraceLevel & g_ulTraceLevel) == 0)
  72. {
  73. return;
  74. }
  75. va_start(vaList, pFormat);
  76. cbPrinted = _vsnprintf(szFormattedMessage, LCTRACE_FMT_MSG_SIZE, pFormat, vaList);
  77. va_end(vaList);
  78. if (cbPrinted == -1)
  79. {
  80. DbgPrint("LSCORE: Trace Message: Next trace message too long.\n");
  81. szFormattedMessage[LCTRACE_FMT_MSG_SIZE - 1] = (CHAR)NULL;
  82. }
  83. DbgPrint("LSCORE: %s: %s\n", TraceLevelString(ulTraceLevel), szFormattedMessage);
  84. }
  85. LPCSTR
  86. TraceLevelString(
  87. ULONG ulTraceLevel
  88. )
  89. {
  90. #define TLS_CASE(x) case x: return(#x)
  91. switch(ulTraceLevel)
  92. {
  93. TLS_CASE(LCTRACETYPE_API);
  94. TLS_CASE(LCTRACETYPE_INFO);
  95. TLS_CASE(LCTRACETYPE_WARNING);
  96. TLS_CASE(LCTRACETYPE_ERROR);
  97. TLS_CASE(LCTRACETYPE_ALL);
  98. default: return("Trace Level Unknown");
  99. }
  100. }
  101. #endif