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.

321 lines
8.2 KiB

  1. //***************************************************************************
  2. //
  3. // GLOBAL.H
  4. //
  5. // Module: HEALTHMON SERVER AGENT
  6. //
  7. // Purpose: Global helper functions, defines, macros...
  8. //
  9. // Copyright (c)1999 Microsoft Corporation, All Rights Reserved
  10. //
  11. //***************************************************************************
  12. #if !defined( __GLOBAL_H )
  13. #define __GLOBAL_H
  14. #include <crtdbg.h>
  15. #include <stdio.h>
  16. #include <tchar.h>
  17. #include <vector>
  18. #include "wmihelper.h"
  19. extern IWbemServices* g_pIWbemServices;
  20. extern IWbemServices* g_pIWbemServicesCIMV2;
  21. extern IWbemObjectSink* g_pSystemEventSink;
  22. extern IWbemObjectSink* g_pDataGroupEventSink;
  23. extern IWbemObjectSink* g_pDataCollectorEventSink;
  24. extern IWbemObjectSink* g_pDataCollectorPerInstanceEventSink;
  25. extern IWbemObjectSink* g_pDataCollectorStatisticsEventSink;
  26. extern IWbemObjectSink* g_pThresholdEventSink;
  27. //extern IWbemObjectSink* g_pThresholdInstanceEventSink;
  28. extern IWbemObjectSink* g_pActionEventSink;
  29. extern IWbemObjectSink* g_pActionTriggerEventSink;
  30. extern HINSTANCE g_hResLib;
  31. //#define MAX_INT 0x7fff
  32. //#define MAX_UINT 0xffff
  33. #define MAX_LONG 0x7fffffffL
  34. #define MAX_ULONG 0xffffffffL
  35. #define MAX_I64 0x7fffffffffffffffL
  36. #define MAX_UI64 0xffffffffffffffffL
  37. #define MAX_FLOAT 3.402823E+38F
  38. #define MAX_DOUBLE 1.797693E+308
  39. #define MIN_DOUBLE -1.7E+307
  40. //#define MY_OUTPUT_TO_FILE 1
  41. #ifdef _DEBUG
  42. #ifdef MY_OUTPUT_TO_FILE
  43. extern FILE* debug_f;
  44. #define MY_OUTPUT(msg, iLevel)\
  45. {\
  46. TCHAR l_buf[1024];\
  47. SYSTEMTIME l_st;\
  48. if (iLevel >= 4) {\
  49. GetLocalTime(&l_st);\
  50. wsprintf(l_buf, L"%02d:%02d:%02d %08x %d, %S, %s\n",\
  51. l_st.wHour, l_st.wMinute, l_st.wSecond,\
  52. GetCurrentThreadId(), (int)__LINE__, __FILE__, (msg));\
  53. OutputDebugString(l_buf);\
  54. _ftprintf(debug_f, l_buf);\
  55. fflush(debug_f);\
  56. }\
  57. }
  58. #else
  59. #define MY_OUTPUT(msg, iLevel)\
  60. {\
  61. TCHAR l_buf[1024];\
  62. SYSTEMTIME l_st;\
  63. if (iLevel >= 4) {\
  64. GetLocalTime(&l_st);\
  65. wsprintf(l_buf, L"%02d:%02d:%02d %08x %d, %S, %s\n",\
  66. l_st.wHour, l_st.wMinute, l_st.wSecond,\
  67. GetCurrentThreadId(), (int)__LINE__, __FILE__, msg);\
  68. OutputDebugString(l_buf);\
  69. }\
  70. }
  71. #endif
  72. #else
  73. #ifdef MY_OUTPUT_TO_FILE
  74. extern FILE* debug_f;
  75. #define MY_OUTPUT(msg, iLevel)\
  76. {\
  77. TCHAR l_buf[1024];\
  78. SYSTEMTIME l_st;\
  79. if (iLevel >= 4) {\
  80. GetLocalTime(&l_st);\
  81. wsprintf(l_buf, L"%02d:%02d:%02d %08x %d, %S, %s\n",\
  82. l_st.wHour, l_st.wMinute, l_st.wSecond,\
  83. GetCurrentThreadId(), (int)__LINE__, __FILE__, (msg));\
  84. _ftprintf(debug_f, l_buf);\
  85. fflush(debug_f);\
  86. }\
  87. }
  88. #else
  89. #define MY_OUTPUT(msg, iLevel)
  90. ;
  91. #endif
  92. #endif
  93. #ifdef _DEBUG
  94. #ifdef MY_OUTPUT_TO_FILE
  95. extern FILE* debug_f;
  96. #define MY_OUTPUT2(msg, arg1, iLevel)\
  97. {\
  98. TCHAR l_msg[1024];\
  99. TCHAR l_buf[1024];\
  100. SYSTEMTIME l_st;\
  101. if (iLevel >= 4) {\
  102. GetLocalTime(&l_st);\
  103. wsprintf(l_msg, (msg), (arg1));\
  104. wsprintf(l_buf, L"%02d:%02d:%02d %08x %d, %S, %s\n",\
  105. l_st.wHour, l_st.wMinute, l_st.wSecond,\
  106. GetCurrentThreadId(), (int)__LINE__, __FILE__, l_msg);\
  107. OutputDebugString(l_buf);\
  108. _ftprintf(debug_f, l_buf);\
  109. fflush(debug_f);\
  110. }\
  111. }
  112. #else
  113. #define MY_OUTPUT2(msg, arg1, iLevel)\
  114. {\
  115. TCHAR l_msg[1024];\
  116. TCHAR l_buf[1024];\
  117. SYSTEMTIME l_st;\
  118. if (iLevel >= 4) {\
  119. GetLocalTime(&l_st);\
  120. wsprintf(l_msg, (msg), (arg1));\
  121. wsprintf(l_buf, L"%02d:%02d:%02d %08x %d, %S, %s\n",\
  122. l_st.wHour, l_st.wMinute, l_st.wSecond,\
  123. GetCurrentThreadId(), (int)__LINE__, __FILE__, l_msg);\
  124. OutputDebugString(l_buf);\
  125. }\
  126. }
  127. #endif
  128. #else
  129. #ifdef MY_OUTPUT_TO_FILE
  130. extern FILE* debug_f;
  131. #define MY_OUTPUT2(msg, arg1, iLevel)\
  132. {\
  133. TCHAR l_msg[1024];\
  134. TCHAR l_buf[1024];\
  135. SYSTEMTIME l_st;\
  136. if (iLevel >= 4) {\
  137. GetLocalTime(&l_st);\
  138. wsprintf(l_msg, (msg), (arg1));\
  139. wsprintf(l_buf, L"%02d:%02d:%02d %08x %d, %S, %s\n",\
  140. l_st.wHour, l_st.wMinute, l_st.wSecond,\
  141. GetCurrentThreadId(), (int)__LINE__, __FILE__, l_msg);\
  142. _ftprintf(debug_f, l_buf);\
  143. fflush(debug_f);\
  144. }\
  145. }
  146. #else
  147. #define MY_OUTPUT2(msg, arg1, iLevel)
  148. ;
  149. #endif
  150. #endif
  151. // _ASSERT(condition);
  152. #ifdef _DEBUG
  153. extern FILE* debug_f;
  154. #define MY_ASSERT(condition)\
  155. {\
  156. if (!(condition)) {\
  157. TCHAR l_buf[1024];\
  158. SYSTEMTIME l_st;\
  159. GetLocalTime(&l_st);\
  160. wsprintf(l_buf, L"%02d:%02d:%02d %08x %d, %S\n",\
  161. l_st.wHour, l_st.wMinute, l_st.wSecond,\
  162. GetCurrentThreadId(), (int)__LINE__, __FILE__);\
  163. _ftprintf(debug_f, l_buf);\
  164. fflush(debug_f);\
  165. DebugBreak();\
  166. }\
  167. }
  168. #else
  169. extern FILE* debug_f;
  170. #define MY_ASSERT(condition)\
  171. {\
  172. if (!(condition)) {\
  173. TCHAR l_buf[1024];\
  174. SYSTEMTIME l_st;\
  175. GetLocalTime(&l_st);\
  176. wsprintf(l_buf, L"%02d:%02d:%02d %08x %d, %S\n",\
  177. l_st.wHour, l_st.wMinute, l_st.wSecond,\
  178. GetCurrentThreadId(), (int)__LINE__, __FILE__);\
  179. _ftprintf(debug_f, l_buf);\
  180. fflush(debug_f);\
  181. }\
  182. }
  183. #endif
  184. // _ASSERT((hres_condition)==S_OK);
  185. #ifdef _DEBUG
  186. extern FILE* debug_f;
  187. #define MY_HRESASSERT(hres_condition)\
  188. {\
  189. if ((hres_condition)!=S_OK) {\
  190. TCHAR l_buf[1024];\
  191. SYSTEMTIME l_st;\
  192. GetLocalTime(&l_st);\
  193. wsprintf(l_buf, L"%02d:%02d:%02d %08x %d, %S 0x%08x\n",\
  194. l_st.wHour, l_st.wMinute, l_st.wSecond,\
  195. GetCurrentThreadId(), (int)__LINE__, __FILE__, (hres_condition));\
  196. _ftprintf(debug_f, l_buf);\
  197. fflush(debug_f);\
  198. DebugBreak();\
  199. }\
  200. }
  201. #else
  202. extern FILE* debug_f;
  203. #define MY_HRESASSERT(hres_condition)\
  204. {\
  205. if ((hres_condition)!=S_OK) {\
  206. TCHAR l_buf[1024];\
  207. SYSTEMTIME l_st;\
  208. GetLocalTime(&l_st);\
  209. wsprintf(l_buf, L"%02d:%02d:%02d %08x %d, %S 0x%08x\n",\
  210. l_st.wHour, l_st.wMinute, l_st.wSecond,\
  211. GetCurrentThreadId(), (int)__LINE__, __FILE__, (hres_condition));\
  212. _ftprintf(debug_f, l_buf);\
  213. fflush(debug_f);\
  214. }\
  215. }
  216. #endif
  217. //#define HM_POLLING_INTERVAL 10
  218. #define HM_POLLING_INTERVAL 1
  219. // HM_RESET is a special state that is temporary to the object until it is done reseting
  220. // It is not known of outside of the agent.
  221. enum HM_STATE {HM_GOOD, HM_COLLECTING, HM_RESET, HM_INFO, HM_DISABLED, HM_SCHEDULEDOUT, HM_RESERVED1, HM_RESERVED2, HM_WARNING, HM_CRITICAL};
  222. enum HM_CONDITION {HM_LT, HM_GT, HM_EQ, HM_NE, HM_GE, HM_LE, HM_CONTAINS, HM_NOTCONTAINS, HM_ALWAYS};
  223. enum HM_DE_TYPE {HM_PGDE, HM_PMDE, HM_PQDE, HM_EQDE};
  224. //enum HM_UNKNOWN_REASON {HM_UNKNOWN_NONE, HM_UNKNOWN_BADWMI, HM_UNKNOWN_OBJECTNOTFOUND, HM_UNKNOWN_NOINST, HM_UNKNOWN_ENUMFAIL, HM_UNKNOWN_TIMEOUT, HM_UNKNOWN_NULL, HM_UNKNOWN_TOOMANYINSTS, HM_UNKNOWN_BADTHRESHPROP};
  225. #define HMRES_BADWMI 4
  226. #define HMRES_OBJECTNOTFOUND 5
  227. #define HMRES_NOINST 6
  228. #define HMRES_ENUMFAIL 7
  229. #define HMRES_TIMEOUT 8
  230. #define HMRES_OUTAGE 9
  231. #define HMRES_DISABLE 10
  232. #define HMRES_NULLVALUE 11
  233. #define HMRES_DCUNKNOWN 12
  234. #define HMRES_TOOMANYINSTS 13
  235. #define HMRES_BADTHRESHPROP 14
  236. #define HMRES_MISSINGDESC 15
  237. #define HMRES_DESC 16
  238. #define HMRES_BADERROR 17
  239. #define HMRES_OK 18
  240. #define HMRES_COLLECTING 19
  241. #define HMRES_RESET 20
  242. #define HMRES_INFO 21
  243. #define HMRES_DISABLED 22
  244. #define HMRES_SCHEDULEDOUT 23
  245. #define HMRES_RESERVED1 24
  246. #define HMRES_RESERVED2 25
  247. #define HMRES_WARNING 26
  248. #define HMRES_CRITICAL 27
  249. #define HMRES_LT 28
  250. #define HMRES_GT 29
  251. #define HMRES_EQ 30
  252. #define HMRES_NE 31
  253. #define HMRES_GTEQ 32
  254. #define HMRES_LTEQ 33
  255. #define HMRES_CONTAINS 34
  256. #define HMRES_NOTCONTAINS 35
  257. #define HMRES_ALWAYS 36
  258. #define HMRES_ACTION_OUTAGE 37
  259. #define HMRES_ACTION_DISABLE 38
  260. #define HMRES_ACTION_FIRED 39
  261. #define HMRES_ACTION_FAILED 40
  262. #define HMRES_ACTION_ENABLE 41
  263. #define HMRES_ACTION_LOADFAIL 42
  264. #define HMRES_NOMEMORY 43
  265. #define HMRES_SYSTEM_LOADFAIL 44
  266. #define HMRES_DG_LOADFAIL 45
  267. #define HMRES_DC_LOADFAIL 46
  268. #define HMRES_THRESHOLD_LOADFAIL 47
  269. #define HMRES_BADDCPROP 48
  270. typedef struct _tag_TOKENStruct
  271. {
  272. LPTSTR szOrigToken;
  273. LPTSTR szToken;
  274. LPTSTR szReplacementText;
  275. } TOKENSTRUCT;
  276. typedef std::vector<TOKENSTRUCT, std::allocator<TOKENSTRUCT> > TOKENLIST;
  277. typedef struct _tag_REPStruct
  278. {
  279. LPTSTR pStartStr;
  280. int len;
  281. LPTSTR pszReplacementText;
  282. } REPSTRUCT;
  283. typedef std::vector<REPSTRUCT, std::allocator<REPSTRUCT> > REPLIST;
  284. BOOL ReadUI64(LPCWSTR wsz, UNALIGNED unsigned __int64& rui64);
  285. HRESULT ReplaceStr(LPTSTR *pszString, LPTSTR pszOld, LPTSTR pszNew);
  286. #ifdef _DEBUG
  287. #define TRACE_MUTEX(msg)\
  288. {\
  289. TCHAR l_buf[1024];\
  290. SYSTEMTIME l_st;\
  291. GetLocalTime(&l_st);\
  292. wsprintf(l_buf, L"%s %02d:%02d:%02d %08x %d, %S\n",\
  293. (msg), l_st.wHour, l_st.wMinute, l_st.wSecond,\
  294. GetCurrentThreadId(), (int)__LINE__, __FILE__);\
  295. _ftprintf(debug_f, l_buf);\
  296. fflush(debug_f);\
  297. }
  298. #else
  299. #define TRACE_MUTEX(msg)
  300. ;
  301. #endif
  302. #endif // __GLOBAL_H