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.

320 lines
6.0 KiB

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