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.

441 lines
7.5 KiB

  1. // HMRuleConfiguration.cpp: implementation of the CHMRuleConfiguration class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "snapin.h"
  6. #include "HMRuleConfiguration.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. IMPLEMENT_DYNCREATE(CHMRuleConfiguration,CWbemClassObject)
  13. //////////////////////////////////////////////////////////////////////
  14. // Construction/Destruction
  15. //////////////////////////////////////////////////////////////////////
  16. CHMRuleConfiguration::CHMRuleConfiguration()
  17. {
  18. m_iID = 0;
  19. m_iUseFlag = 0;
  20. m_iRuleCondition = 0;
  21. m_iRuleDuration = 0;
  22. m_iState = 0;
  23. m_bEnable = true;
  24. }
  25. CHMRuleConfiguration::~CHMRuleConfiguration()
  26. {
  27. Destroy();
  28. }
  29. //////////////////////////////////////////////////////////////////////
  30. // Create
  31. //////////////////////////////////////////////////////////////////////
  32. HRESULT CHMRuleConfiguration::Create(const CString& sMachineName)
  33. {
  34. HRESULT hr = CWbemClassObject::Create(sMachineName);
  35. if( !CHECKHRESULT(hr) )
  36. {
  37. return hr;
  38. }
  39. return hr;
  40. }
  41. HRESULT CHMRuleConfiguration::Create(IWbemClassObject* pObject)
  42. {
  43. HRESULT hr = CWbemClassObject::Create(pObject);
  44. if( !CHECKHRESULT(hr) )
  45. {
  46. return hr;
  47. }
  48. return hr;
  49. }
  50. //////////////////////////////////////////////////////////////////////
  51. // Enumeration Operations
  52. //////////////////////////////////////////////////////////////////////
  53. HRESULT CHMRuleConfiguration::EnumerateObjects(ULONG& uReturned)
  54. {
  55. // call GetNextObject to proceed to the next object instance
  56. HRESULT hr = GetNextObject(uReturned);
  57. if( FAILED(hr) || uReturned != 1 )
  58. {
  59. // no more instances
  60. return hr;
  61. }
  62. ASSERT(m_pIWbemClassObject);
  63. if( m_pIWbemClassObject == NULL )
  64. {
  65. ASSERT(0);
  66. return S_FALSE;
  67. }
  68. // process the properties of this object
  69. hr = GetAllProperties();
  70. return hr;
  71. }
  72. //////////////////////////////////////////////////////////////////////
  73. // Property Retrieval Operations
  74. //////////////////////////////////////////////////////////////////////
  75. HRESULT CHMRuleConfiguration::GetAllProperties()
  76. {
  77. ASSERT(m_pIWbemClassObject);
  78. if( m_pIWbemClassObject == NULL )
  79. {
  80. ASSERT(FALSE);
  81. return S_FALSE;
  82. }
  83. HRESULT hr = S_OK;
  84. // Unique identifier
  85. hr = GetProperty(IDS_STRING_MOF_GUID,m_sGUID);
  86. m_sGUID.TrimLeft(_T("{"));
  87. m_sGUID.TrimRight(_T("}"));
  88. // Display name
  89. hr = GetLocaleStringProperty(IDS_STRING_MOF_NAME,m_sName);
  90. // Description
  91. hr = GetLocaleStringProperty(IDS_STRING_MOF_DESCRIPTION,m_sDescription);
  92. hr = GetProperty(IDS_STRING_MOF_ID,m_iID);
  93. // What property to look at from the parent instance
  94. hr = GetProperty(IDS_STRING_MOF_PROPERTYNAME,m_sPropertyName);
  95. // Rules against the average value, not the current value.
  96. hr = GetProperty(IDS_STRING_MOF_USEFLAG,m_iUseFlag);
  97. // The condition to use for the Rule.
  98. hr = GetProperty(IDS_STRING_MOF_RULECONDITION,m_iRuleCondition);
  99. switch( m_iRuleCondition )
  100. {
  101. case 0:
  102. {
  103. m_sRuleCondition.LoadString(IDS_STRING_LESS_THAN);
  104. }
  105. break;
  106. case 1:
  107. {
  108. m_sRuleCondition.LoadString(IDS_STRING_GREATER_THAN);
  109. }
  110. break;
  111. case 2:
  112. {
  113. m_sRuleCondition.LoadString(IDS_STRING_EQUALS);
  114. }
  115. break;
  116. case 3:
  117. {
  118. m_sRuleCondition.LoadString(IDS_STRING_DOES_NOT_EQUAL);
  119. }
  120. break;
  121. case 4:
  122. {
  123. m_sRuleCondition.LoadString(IDS_STRING_GREATER_THAN_EQUAL_TO);
  124. }
  125. break;
  126. case 5:
  127. {
  128. m_sRuleCondition.LoadString(IDS_STRING_LESS_THAN_EQUAL_TO);
  129. }
  130. break;
  131. case 6:
  132. {
  133. m_sRuleCondition.LoadString(IDS_STRING_CONTAINS);
  134. }
  135. break;
  136. case 7:
  137. {
  138. m_sRuleCondition.LoadString(IDS_STRING_DOES_NOT_CONTAIN);
  139. }
  140. break;
  141. }
  142. // Value to use for Rule.
  143. hr = GetProperty(IDS_STRING_MOF_RULEVALUE,m_sRuleValue);
  144. // How long the value must remain. In
  145. hr = GetProperty(IDS_STRING_MOF_RULEDURATION,m_iRuleDuration);
  146. // The state we transition to if cross Rule.
  147. hr = GetProperty(IDS_STRING_MOF_STATE,m_iState);
  148. switch( m_iState )
  149. {
  150. case 0:
  151. {
  152. m_sState.LoadString(IDS_STRING_CRITICAL);
  153. }
  154. break;
  155. case 1:
  156. {
  157. m_sState.LoadString(IDS_STRING_WARNING);
  158. }
  159. break;
  160. case 2:
  161. {
  162. m_sState.LoadString(IDS_STRING_INFORMATION);
  163. }
  164. break;
  165. case 3:
  166. {
  167. m_sState.LoadString(IDS_STRING_RESET);
  168. }
  169. break;
  170. }
  171. // Time of origional creation
  172. hr = GetProperty(IDS_STRING_MOF_CREATIONDATE,m_sCreationDate);
  173. // Time of last change
  174. hr = GetProperty(IDS_STRING_MOF_LASTUPDATE,m_sLastUpdate);
  175. // What gets sent to the event. Can contain special
  176. hr = GetProperty(IDS_STRING_MOF_MESSAGE,m_sMessage);
  177. // Enable
  178. hr = GetProperty(IDS_STRING_MOF_ENABLE,m_bEnable);
  179. return hr;
  180. }
  181. HRESULT CHMRuleConfiguration::SaveEnabledProperty()
  182. {
  183. ASSERT(m_pIWbemClassObject);
  184. if( m_pIWbemClassObject == NULL )
  185. {
  186. ASSERT(FALSE);
  187. return S_FALSE;
  188. }
  189. HRESULT hr = S_OK;
  190. // Enable
  191. CString sProperty;
  192. hr = SetProperty(IDS_STRING_MOF_ENABLE,m_bEnable);
  193. ASSERT(SUCCEEDED(hr));
  194. hr = SaveAllProperties();
  195. ASSERT(SUCCEEDED(hr));
  196. return hr;
  197. }
  198. HRESULT CHMRuleConfiguration::SaveAllProperties()
  199. {
  200. ASSERT(m_pIWbemClassObject);
  201. if( m_pIWbemClassObject == NULL )
  202. {
  203. ASSERT(FALSE);
  204. return S_FALSE;
  205. }
  206. HRESULT hr = S_OK;
  207. // Unique identifier
  208. // hr = SetProperty(IDS_STRING_MOF_GUID,m_sGUID);
  209. // Display name
  210. hr = SetProperty(IDS_STRING_MOF_NAME,m_sName);
  211. // Description
  212. hr = SetProperty(IDS_STRING_MOF_DESCRIPTION,m_sDescription);
  213. hr = SetProperty(IDS_STRING_MOF_ID,m_iID);
  214. // What property to look at from the parent instance
  215. hr = SetProperty(IDS_STRING_MOF_PROPERTYNAME,m_sPropertyName);
  216. // Rule against the change, not the current
  217. hr = SetProperty(IDS_STRING_MOF_USEFLAG,m_iUseFlag);
  218. // The condition to use for the Rule.
  219. hr = SetProperty(IDS_STRING_MOF_RULECONDITION,m_iRuleCondition);
  220. // Value to use for Rule.
  221. hr = SetProperty(IDS_STRING_MOF_RULEVALUE,m_sRuleValue);
  222. // How long the value must remain. In
  223. hr = SetProperty(IDS_STRING_MOF_RULEDURATION,m_iRuleDuration);
  224. // The state we transition to if cross Rule.
  225. hr = SetProperty(IDS_STRING_MOF_STATE,m_iState);
  226. // Time of origional creation
  227. hr = SetProperty(IDS_STRING_MOF_CREATIONDATE,m_sCreationDate);
  228. // Time of last change
  229. hr = SetProperty(IDS_STRING_MOF_LASTUPDATE,m_sLastUpdate);
  230. // What gets sent to the event. Can contain special
  231. hr = SetProperty(IDS_STRING_MOF_MESSAGE,m_sMessage);
  232. // Enable
  233. hr = SetProperty(IDS_STRING_MOF_ENABLE,m_bEnable);
  234. hr = CWbemClassObject::SaveAllProperties();
  235. CHECKHRESULT(hr);
  236. return hr;
  237. }
  238. HRESULT CHMRuleConfiguration::SaveAllExpressionProperties()
  239. {
  240. ASSERT(m_pIWbemClassObject);
  241. if( m_pIWbemClassObject == NULL )
  242. {
  243. ASSERT(FALSE);
  244. return S_FALSE;
  245. }
  246. HRESULT hr = S_OK;
  247. // Value to use for Rule.
  248. hr = SetProperty(IDS_STRING_MOF_RULEVALUE,m_sRuleValue);
  249. // The state we transition to if cross Rule.
  250. hr = SetProperty(IDS_STRING_MOF_STATE,m_iState);
  251. // The condition to use for the Rule.
  252. hr = SetProperty(IDS_STRING_MOF_RULECONDITION,m_iRuleCondition);
  253. // What property to look at from the parent instance
  254. hr = SetProperty(IDS_STRING_MOF_PROPERTYNAME,m_sPropertyName);
  255. // Rules against the average value, not the current value.
  256. hr = SetProperty(IDS_STRING_MOF_USEFLAG,m_iUseFlag);
  257. hr = CWbemClassObject::SaveAllProperties();
  258. CHECKHRESULT(hr);
  259. return hr;
  260. }