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.

390 lines
7.1 KiB

  1. #ifdef _DEBUG
  2. #define new DEBUG_NEW
  3. #endif
  4. /////////////////////////////////////////////////////////////////////////////
  5. // WMI Operations
  6. /////////////////////////////////////////////////////////////////////////////
  7. inline HRESULT CRule::EnumerateChildren()
  8. {
  9. TRACEX(_T("CRule::EnumerateChildren\n"));
  10. return S_OK;
  11. }
  12. inline CString CRule::GetObjectPath()
  13. {
  14. TRACEX(_T("CRule::GetObjectPath\n"));
  15. CString sPath;
  16. sPath.Format(IDS_STRING_MOF_OBJECTPATH,IDS_STRING_MOF_HMR_CONFIG,GetGuid());
  17. return sPath;
  18. }
  19. inline CString CRule::GetStatusObjectPath()
  20. {
  21. TRACEX(_T("CRule::GetStatusObjectPath\n"));
  22. CString sPath;
  23. sPath.Format(IDS_STRING_MOF_OBJECTPATH,IDS_STRING_MOF_HMR_STATUS,GetGuid());
  24. return sPath;
  25. }
  26. inline CWbemClassObject* CRule::GetParentClassObject()
  27. {
  28. TRACEX(_T("CRule::GetParentClassObject\n"));
  29. CWbemClassObject* pClassObject = new CWbemClassObject;
  30. if( ! CHECKHRESULT(pClassObject->Create(GetSystemName())) )
  31. {
  32. delete pClassObject;
  33. return NULL;
  34. }
  35. CString sQuery;
  36. sQuery.Format(IDS_STRING_R2DE_ASSOC_QUERY,GetGuid());
  37. BSTR bsQuery = sQuery.AllocSysString();
  38. if( ! CHECKHRESULT(pClassObject->ExecQuery(bsQuery)) )
  39. {
  40. delete pClassObject;
  41. ::SysFreeString(bsQuery);
  42. return NULL;
  43. }
  44. ::SysFreeString(bsQuery);
  45. ULONG ulReturned = 0L;
  46. if( pClassObject->GetNextObject(ulReturned) != S_OK )
  47. {
  48. ASSERT(FALSE);
  49. delete pClassObject;
  50. return NULL;
  51. }
  52. ASSERT(ulReturned > 0);
  53. return pClassObject;
  54. }
  55. inline CHMEvent* CRule::GetStatusClassObject()
  56. {
  57. TRACEX(_T("CRule::GetStatusClassObject\n"));
  58. CHMEvent* pClassObject = new CHMRuleStatus;
  59. pClassObject->SetMachineName(GetSystemName());
  60. if( ! CHECKHRESULT(pClassObject->GetObject(GetStatusObjectPath())) )
  61. {
  62. delete pClassObject;
  63. return NULL;
  64. }
  65. pClassObject->GetAllProperties();
  66. return pClassObject;
  67. }
  68. inline CString CRule::GetThresholdString()
  69. {
  70. TRACEX(_T("CRule::GetThresholdString\n"));
  71. CWbemClassObject* pThreshold = GetClassObject();
  72. if( ! GfxCheckObjPtr(pThreshold,CWbemClassObject) )
  73. {
  74. return _T("");
  75. }
  76. CString sExpression;
  77. CString sValue;
  78. int iCondition = -1;
  79. pThreshold->GetProperty(IDS_STRING_MOF_PROPERTYNAME,sValue);
  80. if( sValue.IsEmpty() )
  81. {
  82. delete pThreshold;
  83. return _T("");
  84. }
  85. sExpression += sValue + _T(" ");
  86. pThreshold->GetProperty(IDS_STRING_MOF_RULECONDITION,iCondition);
  87. switch( iCondition )
  88. {
  89. case 0:
  90. {
  91. sValue = _T("<");
  92. }
  93. break;
  94. case 1:
  95. {
  96. sValue = _T(">");
  97. }
  98. break;
  99. case 2:
  100. {
  101. sValue = _T("=");
  102. }
  103. break;
  104. case 3:
  105. {
  106. sValue = _T("!=");
  107. }
  108. break;
  109. case 4:
  110. {
  111. sValue = _T(">=");
  112. }
  113. break;
  114. case 5:
  115. {
  116. sValue = _T("<=");
  117. }
  118. break;
  119. case 6:
  120. {
  121. sValue.LoadString(IDS_STRING_CONTAINS);
  122. }
  123. break;
  124. case 7:
  125. {
  126. sValue.LoadString(IDS_STRING_DOES_NOT_CONTAIN);
  127. }
  128. break;
  129. default:
  130. {
  131. delete pThreshold;
  132. return _T("");
  133. }
  134. break;
  135. }
  136. sExpression += sValue + _T(" ");
  137. pThreshold->GetProperty(IDS_STRING_MOF_RULEVALUE,sValue);
  138. if( sValue.IsEmpty() )
  139. {
  140. delete pThreshold;
  141. return _T("");
  142. }
  143. sExpression += sValue;
  144. delete pThreshold;
  145. return sExpression;
  146. }
  147. /*
  148. inline void CRule::DeleteClassObject()
  149. {
  150. TRACEX(_T("CRule::DeleteClassObject\n"));
  151. // get associator path
  152. CWbemClassObject Associator;
  153. Associator.SetMachineName(GetSystemName());
  154. CString sQuery;
  155. sQuery.Format(IDS_STRING_R2DE_REF_QUERY,GetGuid());
  156. BSTR bsQuery = sQuery.AllocSysString();
  157. if( ! CHECKHRESULT(Associator.ExecQuery(bsQuery)) )
  158. {
  159. ::SysFreeString(bsQuery);
  160. return;
  161. }
  162. ::SysFreeString(bsQuery);
  163. ULONG ulReturned = 0L;
  164. if( Associator.GetNextObject(ulReturned) != S_OK )
  165. {
  166. ASSERT(FALSE);
  167. return;
  168. }
  169. CString sAssociatorPath;
  170. Associator.GetProperty(_T("__path"),sAssociatorPath);
  171. Associator.Destroy();
  172. // delete the instance
  173. Associator.SetMachineName(GetSystemName());
  174. BSTR bsInstanceName = sAssociatorPath.AllocSysString();
  175. CHECKHRESULT(Associator.DeleteInstance(bsInstanceName));
  176. ::SysFreeString(bsInstanceName);
  177. }
  178. */
  179. /////////////////////////////////////////////////////////////////////////////
  180. // Clipboard Operations
  181. /////////////////////////////////////////////////////////////////////////////
  182. inline bool CRule::Cut()
  183. {
  184. TRACEX(_T("CRule::Cut\n"));
  185. return false;
  186. }
  187. inline bool CRule::Copy()
  188. {
  189. TRACEX(_T("CRule::Copy\n"));
  190. return false;
  191. }
  192. inline bool CRule::Paste()
  193. {
  194. TRACEX(_T("CRule::Paste\n"));
  195. return false;
  196. }
  197. /////////////////////////////////////////////////////////////////////////////
  198. // Operations
  199. /////////////////////////////////////////////////////////////////////////////
  200. inline bool CRule::Rename(const CString& sNewName)
  201. {
  202. TRACEX(_T("CRule::Rename\n"));
  203. TRACEARGs(sNewName);
  204. CString sName = sNewName;
  205. CString sThreshold;
  206. sThreshold.LoadString(IDS_STRING_RULE_FMT);
  207. sThreshold = sThreshold.Left(sThreshold.GetLength()-3);
  208. // do we need to autoname this ?
  209. if( sName.Find(sThreshold) == 0 )
  210. {
  211. CWbemClassObject* pRuleObject = GetClassObject();
  212. CString sPropertyName;
  213. CString sCompareValue;
  214. CString sOperator;
  215. int iCondition;
  216. pRuleObject->GetProperty(IDS_STRING_MOF_PROPERTYNAME,sPropertyName);
  217. pRuleObject->GetProperty(IDS_STRING_MOF_COMPAREVALUE,sCompareValue);
  218. pRuleObject->GetProperty(IDS_STRING_MOF_RULECONDITION,iCondition);
  219. delete pRuleObject;
  220. pRuleObject = NULL;
  221. switch( iCondition )
  222. {
  223. case 0:
  224. {
  225. sOperator.LoadString(IDS_STRING_LESS_THAN);
  226. }
  227. break;
  228. case 1:
  229. {
  230. sOperator.LoadString(IDS_STRING_GREATER_THAN);
  231. }
  232. break;
  233. case 2:
  234. {
  235. sOperator.LoadString(IDS_STRING_EQUALS);
  236. }
  237. break;
  238. case 3:
  239. {
  240. sOperator.LoadString(IDS_STRING_DOES_NOT_EQUAL);
  241. }
  242. break;
  243. case 4:
  244. {
  245. sOperator.LoadString(IDS_STRING_GREATER_THAN_EQUAL_TO);
  246. }
  247. break;
  248. case 5:
  249. {
  250. sOperator.LoadString(IDS_STRING_LESS_THAN_EQUAL_TO);
  251. }
  252. break;
  253. case 6:
  254. {
  255. sOperator.LoadString(IDS_STRING_CONTAINS);
  256. }
  257. break;
  258. case 7:
  259. {
  260. sOperator.LoadString(IDS_STRING_DOES_NOT_CONTAIN);
  261. }
  262. break;
  263. case 8:
  264. {
  265. sOperator.LoadString(IDS_STRING_IS_ALWAYS_TRUE);
  266. }
  267. break;
  268. }
  269. if( ! sPropertyName.IsEmpty() && ! sOperator.IsEmpty() && ! sCompareValue.IsEmpty() )
  270. {
  271. if( iCondition != 8 ) // Is Always true is a special case
  272. {
  273. sName.Format(_T("%s %s %s"),sPropertyName,sOperator,sCompareValue);
  274. }
  275. }
  276. else if( ! sOperator.IsEmpty() && iCondition == 8 )
  277. {
  278. sName = sOperator;
  279. }
  280. }
  281. return CHMObject::Rename(sName);
  282. }
  283. inline bool CRule::Refresh()
  284. {
  285. TRACEX(_T("CRule::Refresh\n"));
  286. return false;
  287. }
  288. inline bool CRule::ResetStatus()
  289. {
  290. TRACEX(_T("CRule::ResetStatus\n"));
  291. return false;
  292. }
  293. inline CString CRule::GetUITypeName()
  294. {
  295. TRACEX(_T("CRule::GetUITypeName\n"));
  296. CString sTypeName;
  297. sTypeName.LoadString(IDS_STRING_RULE);
  298. return sTypeName;
  299. }
  300. /////////////////////////////////////////////////////////////////////////////
  301. // Scope Item Members
  302. /////////////////////////////////////////////////////////////////////////////
  303. inline CScopePaneItem* CRule::CreateScopeItem()
  304. {
  305. TRACEX(_T("CRule::CreateScopeItem\n"));
  306. CRuleScopeItem * pNewItem = new CRuleScopeItem;
  307. pNewItem->SetObjectPtr(this);
  308. return pNewItem;
  309. }