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.

297 lines
11 KiB

  1. //=============================================================================
  2. // Copyright (c) 1998 Microsoft Corporation
  3. // File Name: trace.h
  4. // Abstract:
  5. //
  6. // Author: K.S.Lokesh (lokeshs@) 1-1-98
  7. //=============================================================================
  8. #ifndef _DVMRPTRACE_H_
  9. #define _DVMRPTRACE_H_
  10. #ifdef MIB_DEBUG
  11. #if !DBG
  12. #undef MIB_DEBUG
  13. #endif
  14. #endif
  15. // constants and macros used for tracing
  16. //
  17. #define DVMRP_TRACE_ANY ((DWORD)0xFFFF0000 | TRACE_USE_MASK)
  18. #define DVMRP_TRACE_ERR ((DWORD)0x00010000 | TRACE_USE_MASK)
  19. #define DVMRP_TRACE_ENTER ((DWORD)0x00020000 | TRACE_USE_MASK)
  20. #define DVMRP_TRACE_LEAVE ((DWORD)0x00020000 | TRACE_USE_MASK)
  21. #define DVMRP_TRACE_START ((DWORD)0x00020000 | TRACE_USE_MASK)
  22. #define DVMRP_TRACE_STOP ((DWORD)0x00020000 | TRACE_USE_MASK)
  23. #define DVMRP_TRACE_IF ((DWORD)0x00040000 | TRACE_USE_MASK)
  24. #define DVMRP_TRACE_CONFIG ((DWORD)0x00040000 | TRACE_USE_MASK)
  25. #define DVMRP_TRACE_RECEIVE ((DWORD)0x00100000 | TRACE_USE_MASK)
  26. #define DVMRP_TRACE_SEND ((DWORD)0x00200000 | TRACE_USE_MASK)
  27. #define DVMRP_TRACE_QUERIER ((DWORD)0x00400000 | TRACE_USE_MASK)
  28. #define DVMRP_TRACE_GROUP ((DWORD)0x00400000 | TRACE_USE_MASK)
  29. #define DVMRP_TRACE_MGM ((DWORD)0x00800000 | TRACE_USE_MASK)
  30. #if DBG
  31. #define DVMRP_TRACE_KSL ((DWORD)0x01000000 | TRACE_USE_MASK)
  32. #define DVMRP_TRACE_WORKER ((DWORD)0x01000000 | TRACE_USE_MASK)
  33. #define DVMRP_TRACE_ENTER1 ((DWORD)0x02000000 | TRACE_USE_MASK)
  34. #define DVMRP_TRACE_LEAVE1 ((DWORD)0x02000000 | TRACE_USE_MASK)
  35. #define DVMRP_TRACE_MIB ((DWORD)0x04000000 | TRACE_USE_MASK)
  36. #define DVMRP_TRACE_DYNLOCK ((DWORD)0x08000000 | TRACE_USE_MASK)
  37. #define DVMRP_TRACE_TIMER ((DWORD)0x10000000 | TRACE_USE_MASK)
  38. #define DVMRP_TRACE_CS ((DWORD)0x20000000 | TRACE_USE_MASK)
  39. #define DVMRP_TRACE_TIMER1 ((DWORD)0x40000000 | TRACE_USE_MASK)
  40. #define DVMRP_TRACE_CS1 ((DWORD)0x80000000 | TRACE_USE_MASK)
  41. #else
  42. #define DVMRP_TRACE_KSL ((DWORD)0x00000000 | TRACE_USE_MASK)
  43. #define DVMRP_TRACE_WORKER ((DWORD)0x00000000 | TRACE_USE_MASK)
  44. #define DVMRP_TRACE_ENTER1 ((DWORD)0x00000000 | TRACE_USE_MASK)
  45. #define DVMRP_TRACE_LEAVE1 ((DWORD)0x00000000 | TRACE_USE_MASK)
  46. #define DVMRP_TRACE_MIB ((DWORD)0x00000000 | TRACE_USE_MASK)
  47. #define DVMRP_TRACE_DYNLOCK ((DWORD)0x00000000 | TRACE_USE_MASK)
  48. #define DVMRP_TRACE_TIMER ((DWORD)0x00000000 | TRACE_USE_MASK)
  49. #define DVMRP_TRACE_CS ((DWORD)0x00000000 | TRACE_USE_MASK)
  50. #define DVMRP_TRACE_TIMER1 ((DWORD)0x00000000 | TRACE_USE_MASK)
  51. #define DVMRP_TRACE_CS1 ((DWORD)0x00000000 | TRACE_USE_MASK)
  52. #endif
  53. #ifdef LOCK_DBG
  54. #define ENTER_CRITICAL_SECTION(pcs, type, proc) \
  55. Trace2(CS,"----To enter %s in %s", type, proc); \
  56. EnterCriticalSection(pcs); \
  57. Trace2(CS1,"----Entered %s in %s", type, proc)
  58. #define LEAVE_CRITICAL_SECTION(pcs, type, proc) \
  59. Trace2(CS1,"----Left %s in %s", type, proc); \
  60. LeaveCriticalSection(pcs)
  61. #define WAIT_FOR_SINGLE_OBJECT( event, time, type, proc) \
  62. Trace2(EVENT, "++++To wait for singleObj %s in %s", type, proc); \
  63. WaitForSingleObject(event, time); \
  64. Trace2(EVENT, "++++WaitForSingleObj returned %s in %s", type, proc)
  65. #define SET_EVENT(event, type, proc) \
  66. Trace2(EVENT, "++++SetEvent %s in %s", type, proc); \
  67. SetEvent(event)
  68. #else
  69. #define ENTER_CRITICAL_SECTION(pcs, type, proc) \
  70. EnterCriticalSection(pcs)
  71. #define LEAVE_CRITICAL_SECTION(pcs, type, proc) \
  72. LeaveCriticalSection(pcs)
  73. #define WAIT_FOR_SINGLE_OBJECT( event, time, type, proc) \
  74. WaitForSingleObject(event, time)
  75. #define SET_EVENT(event, type, proc) \
  76. SetEvent(event)
  77. #endif // LOCK_DBG
  78. #define TRACEID Globals.TraceId
  79. #define Trace0(l,a) \
  80. if (TRACEID) TracePrintfEx(TRACEID, DVMRP_TRACE_ ## l, a)
  81. #define Trace1(l,a,b) \
  82. if (TRACEID) TracePrintfEx(TRACEID, DVMRP_TRACE_ ## l, a, b)
  83. #define Trace2(l,a,b,c) \
  84. if (TRACEID) TracePrintfEx(TRACEID, DVMRP_TRACE_ ## l, a, b, c)
  85. #define Trace3(l,a,b,c,d) \
  86. if (TRACEID) TracePrintfEx(TRACEID, DVMRP_TRACE_ ## l, a, b, c, d)
  87. #define Trace4(l,a,b,c,d,e) \
  88. if (TRACEID) TracePrintfEx(TRACEID, DVMRP_TRACE_ ## l, a, b, c, d, e)
  89. #define Trace5(l,a,b,c,d,e,f) \
  90. if (TRACEID) TracePrintfEx(TRACEID, DVMRP_TRACE_ ## l, a, b, c, d, e, f)
  91. #define Trace6(l,a,b,c,d,e,f,g) \
  92. if (TRACEID) TracePrintfEx(TRACEID, DVMRP_TRACE_ ## l, a, b, c, d, e, f,g)
  93. #define Trace7(l,a,b,c,d,e,f,g,h) \
  94. if (TRACEID) TracePrintfEx(TRACEID, DVMRP_TRACE_ ## l, a, b, c, d, e, f,g,h)
  95. #define Trace8(l,a,b,c,d,e,f,g,h,i) \
  96. if (TRACEID) TracePrintfEx(TRACEID, DVMRP_TRACE_ ## l, a, b, c, d, e, f,g,h,i)
  97. #define Trace9(l,a,b,c,d,e,f,g,h,i,j) \
  98. if (TRACEID) TracePrintfEx(TRACEID, DVMRP_TRACE_ ## l, a, b, c, d, e, f,g,h,i,j)
  99. #define TRACEDUMP(l,a,b,c) \
  100. TraceDumpEx(TRACEID,l,a,b,c,TRUE)
  101. #ifdef ENTER_DBG
  102. #define TraceEnter(X) TracePrintfEx(TRACEID, DVMRP_TRACE_ENTER, "Entered: "X)
  103. #define TraceLeave(X) TracePrintfEx(TRACEID, DVMRP_TRACE_ENTER, "Leaving: "X"\n")
  104. #else
  105. #define TraceEnter(X)
  106. #define TraceLeave(X)
  107. #endif // ENTER_DBG
  108. //
  109. // Event logging macros
  110. //
  111. #define LOGLEVEL GlobalConfig.LoggingLevel
  112. #define LOGHANDLE Globals.LogHandle
  113. #define LOGERR RouterLogError
  114. #define LOGERRDATA RouterLogErrorData
  115. #define LOGWARN RouterLogWarning
  116. #define LOGWARNDATA RouterLogWarningData
  117. #define LOGINFO RouterLogInformation
  118. #define LOGWARNDATA RouterLogWarningData
  119. // Error logging
  120. #define Logerr0(msg,err) {\
  121. if (LOGLEVEL >= DVMRP_LOGGING_ERROR) \
  122. RouterLogEventEx(LOGHANDLE,EVENTLOG_ERROR_TYPE,\
  123. (err), DVMRPLOG_ ## msg, ""); \
  124. }
  125. #define Logerr1(msg,Format, a,err) \
  126. if (LOGLEVEL >= DVMRP_LOGGING_ERROR) \
  127. RouterLogEventEx(LOGHANDLE,EVENTLOG_ERROR_TYPE,\
  128. (err), DVMRPLOG_ ## msg, Format, (a))
  129. #define Logerr2(msg,Format, a, b, err) \
  130. if (LOGLEVEL >= DVMRP_LOGGING_ERROR) \
  131. RouterLogEventEx(LOGHANDLE,EVENTLOG_ERROR_TYPE,\
  132. (err), DVMRPLOG_ ## msg, Format,(a),(b))
  133. #define Logerr3(msg,Format, a, b, c, err) \
  134. if (LOGLEVEL >= DVMRP_LOGGING_ERROR) \
  135. RouterLogEventEx(LOGHANDLE,EVENTLOG_ERROR_TYPE,\
  136. (err), DVMRPLOG_ ## msg, Format,(a),(b), (c))
  137. #define Logerr4(msg,Format, a, b, c, d, err) \
  138. if (LOGLEVEL >= DVMRP_LOGGING_ERROR) \
  139. RouterLogEventEx(LOGHANDLE,EVENTLOG_ERROR_TYPE,\
  140. (err), DVMRPLOG_ ## msg, Format,(a),(b), (c), (d))
  141. // Warning logging
  142. #define Logwarn0(msg,err) \
  143. if (LOGLEVEL >= DVMRP_LOGGING_WARN) \
  144. LOGWARN(LOGHANDLE,DVMRPLOG_ ## msg,0,NULL,(err))
  145. #define Logwarn1(msg,a,err) \
  146. if (LOGLEVEL >= DVMRP_LOGGING_WARN) \
  147. LOGWARN(LOGHANDLE,DVMRPLOG_ ## msg,1,&(a),(err))
  148. #define Logwarn2(msg,a,b,err) \
  149. if (LOGLEVEL >= DVMRP_LOGGING_WARN) { \
  150. LPSTR _asz[2] = { (a), (b) }; \
  151. LOGWARN(LOGHANDLE,DVMRPLOG_ ## msg,2,_asz,(err)); \
  152. }
  153. #define Logwarn3(msg,a,b,c,err) \
  154. if (LOGLEVEL >= DVMRP_LOGGING_WARN) { \
  155. LPSTR _asz[3] = { (a), (b), (c) }; \
  156. LOGWARN(LOGHANDLE,DVMRPLOG_ ## msg,3,_asz,(err)); \
  157. }
  158. #define Logwarn4(msg,a,b,c,d,err) \
  159. if (LOGLEVEL >= DVMRP_LOGGING_WARN) { \
  160. LPSTR _asz[4] = { (a), (b), (c), (d) }; \
  161. LOGWARN(LOGHANDLE,DVMRPLOG_ ## msg,4,_asz,(err)); \
  162. }
  163. #define LOGWARNDATA2(msg,a,b,dw,buf) \
  164. if (LOGLEVEL >= DVMRP_LOGGING_WARN) { \
  165. LPSTR _asz[2] = { (a), (b) }; \
  166. LOGWARNDATA(LOGHANDLE,DVMRPLOG_ ## msg,2,_asz,(dw),(buf)); \
  167. }
  168. // Information logging
  169. #define Loginfo0(msg,err) \
  170. if (LOGLEVEL >= DVMRP_LOGGING_INFO) \
  171. LOGINFO(LOGHANDLE,DVMRPLOG_ ## msg,0,NULL,(err))
  172. #define Loginfo1(msg,a,err) \
  173. if (LOGLEVEL >= DVMRP_LOGGING_INFO) \
  174. LOGINFO(LOGHANDLE,DVMRPLOG_ ## msg,1,&(a),(err))
  175. #define Loginfo2(msg,a,b,err) \
  176. if (LOGLEVEL >= DVMRP_LOGGING_INFO) { \
  177. LPSTR _asz[2] = { (a), (b) }; \
  178. LOGINFO(LOGHANDLE,DVMRPLOG_ ## msg,2,_asz,(err)); \
  179. }
  180. #define Loginfo3(msg,a,b,c,err) \
  181. if (LOGLEVEL >= DVMRP_LOGGING_INFO) { \
  182. LPSTR _asz[3] = { (a), (b), (c) }; \
  183. LOGINFO(LOGHANDLE,DVMRPLOG_ ## msg,3,_asz,(err)); \
  184. }
  185. #define Loginfo4(msg,a,b,c,d,err) \
  186. if (LOGLEVEL >= DVMRP_LOGGING_INFO) { \
  187. LPSTR _asz[4] = { (a), (b), (c), (d) }; \
  188. LOGINFO(LOGHANDLE,DVMRPLOG_ ## msg,4,_asz,(err)); \
  189. }
  190. //-----------------------------------------------------------------------------
  191. // INITIALIZE_TRACING_LOGGING
  192. //-----------------------------------------------------------------------------
  193. //
  194. // also set the default logging level. It will be reset during
  195. // StartProtocol(), when logging level is set as part of global config
  196. //
  197. #define INITIALIZE_TRACING_LOGGING() {\
  198. if (!Globals.TraceId) { \
  199. Globals.TraceId = TraceRegister("Dvmrp"); \
  200. } \
  201. \
  202. if (!Globals.LogHandle) { \
  203. Globals.LogHandle = RouterLogRegister("Dvmrp"); \
  204. GlobalConfig.LoggingLevel = DVMRP_LOGGING_WARN; \
  205. } \
  206. }
  207. //-----------------------------------------------------------------------------
  208. // DEINITIALIZE_TRACING_LOGGING
  209. //-----------------------------------------------------------------------------
  210. #define DEINITIALIZE_TRACING_LOGGING() { \
  211. if (!Globals.TraceId) { \
  212. TraceDeregister(Globals.TraceId); \
  213. Globals.TraceId = 0; \
  214. } \
  215. \
  216. if (!Globals.LogHandle) { \
  217. RouterLogDeregister(Globals.LogHandle); \
  218. Globals.LogHandle = NULL; \
  219. } \
  220. }
  221. //
  222. // IP address conversion macro:
  223. // calls inet_ntoa directly on a DWORD, by casting it as an IN_ADDR.
  224. //
  225. #define INET_NTOA(dw) inet_ntoa( *(PIN_ADDR)&(dw) )
  226. #endif // _DVMRPTRACE_H_