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.

336 lines
6.7 KiB

  1. // HMDataElementStatus.cpp: implementation of the CHMDataElementStatus class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "snapin.h"
  6. #include "HMDataElementStatus.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. IMPLEMENT_DYNCREATE(CHMDataElementStatus,CHMEvent)
  13. //////////////////////////////////////////////////////////////////////
  14. // Construction/Destruction
  15. //////////////////////////////////////////////////////////////////////
  16. CHMDataElementStatus::CHMDataElementStatus()
  17. {
  18. m_iNumberWarnings = 0; // Number of Rules currently in critical state
  19. m_iNumberCriticals = 0;// Number of Rules currently in warning state
  20. m_iState = HMS_UNKNOWN; // The state we are in - rollup from all Microsoft_HMDataGroups.
  21. ZeroMemory(&m_st,sizeof(SYSTEMTIME));
  22. }
  23. CHMDataElementStatus::~CHMDataElementStatus()
  24. {
  25. for( int i = 0; i < m_RuleStatus.GetSize(); i++ )
  26. {
  27. if( GfxCheckObjPtr(m_RuleStatus[i],CHMRuleStatus) )
  28. {
  29. delete m_RuleStatus[i];
  30. }
  31. }
  32. m_RuleStatus.RemoveAll();
  33. for( i = 0; i < m_RolledUpRuleStatus.GetSize(); i++ )
  34. {
  35. if( GfxCheckObjPtr(m_RolledUpRuleStatus[i],CHMEvent) )
  36. {
  37. delete m_RolledUpRuleStatus[i];
  38. }
  39. }
  40. m_RolledUpRuleStatus.RemoveAll();
  41. Destroy();
  42. }
  43. //////////////////////////////////////////////////////////////////////
  44. // Create
  45. //////////////////////////////////////////////////////////////////////
  46. HRESULT CHMDataElementStatus::Create(const CString& sMachineName)
  47. {
  48. HRESULT hr = CHMEvent::Create(sMachineName);
  49. if( !CHECKHRESULT(hr) )
  50. {
  51. return hr;
  52. }
  53. // create the enumerator for Microsoft_HMDataElementStatus object instances
  54. BSTR bsClass = SysAllocString(_T("Microsoft_HMDataCollectorStatus"));
  55. hr = CreateEnumerator(bsClass);
  56. SysFreeString(bsClass);
  57. if( !CHECKHRESULT(hr) )
  58. {
  59. return hr;
  60. }
  61. return hr;
  62. }
  63. HRESULT CHMDataElementStatus::Create(IWbemClassObject* pObject)
  64. {
  65. HRESULT hr = CHMEvent::Create(pObject);
  66. if( !CHECKHRESULT(hr) )
  67. {
  68. return hr;
  69. }
  70. return hr;
  71. }
  72. //////////////////////////////////////////////////////////////////////
  73. // Enumeration Operations
  74. //////////////////////////////////////////////////////////////////////
  75. HRESULT CHMDataElementStatus::EnumerateObjects(ULONG& uReturned)
  76. {
  77. // call GetNextObject to proceed to the next object instance
  78. HRESULT hr = GetNextObject(uReturned);
  79. if( FAILED(hr) || uReturned != 1 )
  80. {
  81. // no more instances
  82. return hr;
  83. }
  84. ASSERT(m_pIWbemClassObject);
  85. if( m_pIWbemClassObject == NULL )
  86. {
  87. ASSERT(0);
  88. return S_FALSE;
  89. }
  90. // process the properties of this object
  91. hr = GetAllProperties();
  92. return hr;
  93. }
  94. //////////////////////////////////////////////////////////////////////
  95. // Property Retrieval Operations
  96. //////////////////////////////////////////////////////////////////////
  97. HRESULT CHMDataElementStatus::GetAllProperties()
  98. {
  99. ASSERT(m_pIWbemClassObject);
  100. if( m_pIWbemClassObject == NULL )
  101. {
  102. ASSERT(FALSE);
  103. return S_FALSE;
  104. }
  105. HRESULT hr = S_OK;
  106. // Name
  107. hr = GetLocaleStringProperty(IDS_STRING_MOF_NAME,m_sName);
  108. // GUID
  109. hr = GetProperty(IDS_STRING_MOF_GUID,m_sGuid);
  110. m_sGuid.TrimLeft(_T("{"));
  111. m_sGuid.TrimRight(_T("}"));
  112. // NumberNormals
  113. hr = GetProperty(IDS_STRING_MOF_NUMBERNORMALS,m_iNumberNormals);
  114. // NumberWarnings
  115. hr = GetProperty(IDS_STRING_MOF_NUMBERWARNINGS,m_iNumberWarnings);
  116. // NumberCriticals
  117. hr = GetProperty(IDS_STRING_MOF_NUMBERCRITICALS,m_iNumberCriticals);
  118. // State
  119. hr = GetProperty(IDS_STRING_MOF_STATE,m_iState);
  120. switch( m_iState )
  121. {
  122. case 0:
  123. {
  124. m_sState.LoadString(IDS_STRING_CRITICAL);
  125. }
  126. break;
  127. case 1:
  128. {
  129. m_sState.LoadString(IDS_STRING_WARNING);
  130. }
  131. break;
  132. case 2:
  133. {
  134. m_sState.LoadString(IDS_STRING_NODATA);
  135. }
  136. break;
  137. case 3:
  138. {
  139. m_sState.LoadString(IDS_STRING_UNKNOWN);
  140. }
  141. break;
  142. case 4:
  143. {
  144. m_sState.LoadString(IDS_STRING_OUTAGE);
  145. }
  146. break;
  147. case 5:
  148. {
  149. m_sState.LoadString(IDS_STRING_DISABLED);
  150. }
  151. break;
  152. case 6:
  153. {
  154. m_sState.LoadString(IDS_STRING_INFORMATION);
  155. }
  156. break;
  157. case 7:
  158. {
  159. m_sState.LoadString(IDS_STRING_RESET);
  160. }
  161. break;
  162. case 8:
  163. {
  164. m_sState.LoadString(IDS_STRING_NORMAL);
  165. }
  166. break;
  167. }
  168. // StatusGUID
  169. hr = GetProperty(IDS_STRING_MOF_STATUSGUID,m_sStatusGuid);
  170. m_sStatusGuid.TrimLeft(_T("{"));
  171. m_sStatusGuid.TrimRight(_T("}"));
  172. // DTime
  173. CTime time;
  174. hr = GetProperty(IDS_STRING_MOF_LOCALTIME,time);
  175. time.GetAsSystemTime(m_st);
  176. CString sTime;
  177. CString sDate;
  178. int iLen = GetTimeFormat(LOCALE_USER_DEFAULT,0L,&m_st,NULL,NULL,0);
  179. iLen = GetTimeFormat(LOCALE_USER_DEFAULT,0L,&m_st,NULL,sTime.GetBuffer(iLen+(sizeof(TCHAR)*1)),iLen);
  180. sTime.ReleaseBuffer();
  181. iLen = GetDateFormat(LOCALE_USER_DEFAULT,0L,&m_st,NULL,NULL,0);
  182. iLen = GetDateFormat(LOCALE_USER_DEFAULT,0L,&m_st,NULL,sDate.GetBuffer(iLen+(sizeof(TCHAR)*1)),iLen);
  183. sDate.ReleaseBuffer();
  184. m_sDateTime = sDate + _T(" ") + sTime;
  185. // Message
  186. hr = GetLocaleStringProperty(IDS_STRING_MOF_MESSAGE,m_sMessage);
  187. if( ! m_sMessage.IsEmpty() )
  188. {
  189. CHMRuleStatusInstance* pRSI = new CHMRuleStatusInstance;
  190. pRSI->SetParent(this);
  191. pRSI->m_sDataElementName = m_sName;
  192. pRSI->m_sSystemName = m_sSystemName;
  193. pRSI->m_sMessage = m_sMessage;
  194. pRSI->m_iState = m_iState;
  195. pRSI->m_sState = m_sState;
  196. pRSI->m_sStatusGuid = m_sStatusGuid;
  197. pRSI->m_sDateTime = m_sDateTime;
  198. pRSI->m_sDTime = m_sDTime;
  199. pRSI->m_st = m_st;
  200. m_RolledUpRuleStatus.Add(pRSI);
  201. // propogate the status back up to the HMSystemStatus instance
  202. // this gives us a roll up of status at each node in the tree
  203. CHMEvent* pParent = GetParent();
  204. CHMRuleStatusInstance* pStatus = NULL;
  205. while(pParent)
  206. {
  207. pStatus = new CHMRuleStatusInstance(*pRSI);
  208. pStatus->SetParent(this);
  209. pParent->m_RolledUpRuleStatus.Add(pStatus);
  210. pParent = pParent->GetParent();
  211. }
  212. }
  213. // Rules
  214. hr = GetProperty(IDS_STRING_MOF_RULES,m_Rules);
  215. long lLower = 0L;
  216. long lUpper = -1L;
  217. if( hr != S_FALSE )
  218. {
  219. m_Rules.GetLBound(1L,&lLower);
  220. m_Rules.GetUBound(1L,&lUpper);
  221. }
  222. for( long i = lLower; i <= lUpper; i++ )
  223. {
  224. IWbemClassObject* pIWBCO = NULL;
  225. m_Rules.GetElement(&i,&pIWBCO);
  226. if( pIWBCO )
  227. {
  228. CHMRuleStatus* pRS = new CHMRuleStatus;
  229. pRS->SetParent(this);
  230. pRS->m_sDataElementName = m_sName;
  231. pRS->m_sSystemName = m_sSystemName;
  232. pRS->Create(pIWBCO);
  233. pRS->GetAllProperties();
  234. m_RuleStatus.Add(pRS);
  235. }
  236. }
  237. return hr;
  238. }
  239. void CHMDataElementStatus::RemoveStatusEvent(CHMEvent* pEvent)
  240. {
  241. for( int i = 0; i < m_RolledUpRuleStatus.GetSize(); i++ )
  242. {
  243. if( pEvent == m_RolledUpRuleStatus[i] )
  244. {
  245. m_RolledUpRuleStatus.RemoveAt(i);
  246. break;
  247. }
  248. }
  249. for( i = 0; i < m_RuleStatus.GetSize(); i++ )
  250. {
  251. m_RuleStatus[i]->RemoveStatusEvent(pEvent);
  252. }
  253. }