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.

410 lines
8.8 KiB

  1. // File Action.inl
  2. //
  3. //
  4. // Copyright (c) 2000 Microsoft Corporation
  5. //
  6. // 03/18/00 v-marfin : bug 59492 - SetObjectPtr() before calling Create() so object
  7. // has necessary member ptr set.
  8. //
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // WMI Operations
  14. /////////////////////////////////////////////////////////////////////////////
  15. // v-marfin 59492 ---------------------------------------
  16. inline CString CAction::GetStatusObjectPath()
  17. {
  18. TRACEX(_T("CAction::GetStatusObjectPath\n"));
  19. CString sPath;
  20. sPath.Format(IDS_STRING_MOF_OBJECTPATH,IDS_STRING_MOF_HMACTION_STATUS,GetGuid());
  21. return sPath;
  22. }
  23. //-------------------------------------------------------
  24. inline CString CAction::GetObjectPath()
  25. {
  26. TRACEX(_T("CAction::GetObjectPath\n"));
  27. CString sPath;
  28. sPath.Format(IDS_STRING_MOF_OBJECTPATH,IDS_STRING_MOF_HMA_CONFIG,GetGuid());
  29. return sPath;
  30. }
  31. inline CWbemClassObject* CAction::GetConsumerClassObject()
  32. {
  33. TRACEX(_T("CAction::GetConsumerClassObject\n"));
  34. CWbemClassObject* pConfigObject = GetClassObject();
  35. if( ! pConfigObject )
  36. {
  37. return NULL;
  38. }
  39. CString sEventConsumerPath;
  40. pConfigObject->GetProperty(IDS_STRING_MOF_EVENTCONSUMER,sEventConsumerPath);
  41. delete pConfigObject;
  42. pConfigObject = NULL;
  43. if( sEventConsumerPath.IsEmpty() )
  44. {
  45. return NULL;
  46. }
  47. CWbemClassObject* pClassObject = new CWbemClassObject;
  48. if( ! CHECKHRESULT(pClassObject->Create(GetSystemName())) )
  49. {
  50. delete pClassObject;
  51. return NULL;
  52. }
  53. if( ! CHECKHRESULT(pClassObject->GetObject(sEventConsumerPath)) )
  54. {
  55. delete pClassObject;
  56. return NULL;
  57. }
  58. return pClassObject;
  59. }
  60. inline CWbemClassObject* CAction::GetAssociatedConfigObjects()
  61. {
  62. TRACEX(_T("CAction::GetAssociatedConfigObjects\n"));
  63. // execute the query for config objects associated to this action
  64. CWbemClassObject* pConfigObject = new CWbemClassObject;
  65. CString sQuery;
  66. sQuery.Format(IDS_STRING_A2C_ASSOC_QUERY,GetGuid());
  67. if( ! CHECKHRESULT(pConfigObject->Create(GetSystemName())) )
  68. {
  69. return NULL;
  70. }
  71. BSTR bsQuery = sQuery.AllocSysString();
  72. if( ! CHECKHRESULT(pConfigObject->ExecQuery(bsQuery)) )
  73. {
  74. ::SysFreeString(bsQuery);
  75. return NULL;
  76. }
  77. ::SysFreeString(bsQuery);
  78. return pConfigObject;
  79. }
  80. inline CWbemClassObject* CAction::GetAssociationObjects()
  81. {
  82. TRACEX(_T("CAction::GetAssociationObjects\n"));
  83. // execute the query for config objects associated to this action
  84. CWbemClassObject* pAssociationObject = new CWbemClassObject;
  85. CString sQuery;
  86. sQuery.Format(_T("REFERENCES OF {%s} WHERE ResultClass=Microsoft_HMConfigurationActionAssociation Role=ChildPath"),GetObjectPath());
  87. CWbemClassObject Association;
  88. pAssociationObject->Create(GetSystemName());
  89. BSTR bsQuery = sQuery.AllocSysString();
  90. if( ! CHECKHRESULT(pAssociationObject->ExecQuery(bsQuery)) )
  91. {
  92. ::SysFreeString(bsQuery);
  93. return NULL;
  94. }
  95. ::SysFreeString(bsQuery);
  96. return pAssociationObject;
  97. }
  98. inline CWbemClassObject* CAction::GetA2CAssociation(const CString& sConfigGuid)
  99. {
  100. TRACEX(_T("CAction::GetEventFilter\n"));
  101. TRACEARGs(sConfigGuid);
  102. CString sActionPath = GetObjectPath();
  103. CString sQuery;
  104. sQuery.Format(_T("REFERENCES OF {%s} WHERE ResultClass=Microsoft_HMConfigurationActionAssociation Role=ChildPath"),sActionPath);
  105. CWbemClassObject* pAssociation = new CWbemClassObject;
  106. pAssociation->Create(GetSystemName());
  107. BSTR bsQuery = sQuery.AllocSysString();
  108. if( ! CHECKHRESULT(pAssociation->ExecQuery(bsQuery)) )
  109. {
  110. ::SysFreeString(bsQuery);
  111. delete pAssociation;
  112. return NULL;
  113. }
  114. ::SysFreeString(bsQuery);
  115. CString sParentPath;
  116. CString sEventFilterPath;
  117. ULONG ulReturned = 0L;
  118. while( pAssociation->GetNextObject(ulReturned) == S_OK && ulReturned > 0 )
  119. {
  120. pAssociation->GetProperty(_T("ParentPath"),sParentPath);
  121. if( sParentPath.Find(sConfigGuid) != -1 )
  122. {
  123. break;
  124. }
  125. }
  126. return pAssociation;
  127. }
  128. inline CString CAction::GetConditionString(const CString& sConfigGuid)
  129. {
  130. TRACEX(_T("CAction::GetConditionString\n"));
  131. TRACEARGs(sConfigGuid);
  132. CWbemClassObject* pAssociation = GetA2CAssociation(sConfigGuid);
  133. if( ! pAssociation )
  134. {
  135. return _T("");
  136. }
  137. CString sQuery;
  138. CString sCondition;
  139. CString sResString;
  140. pAssociation->GetProperty(_T("Query"),sQuery);
  141. sQuery.MakeUpper();
  142. if( sQuery.Find(_T("TARGETINSTANCE.STATE=0")) != -1 )
  143. {
  144. sResString.LoadString(IDS_STRING_NORMAL);
  145. sCondition += sResString + _T(",");
  146. }
  147. if( sQuery.Find(_T("TARGETINSTANCE.STATE=8")) != -1 )
  148. {
  149. sResString.LoadString(IDS_STRING_WARNING);
  150. sCondition += sResString + _T(",");
  151. }
  152. if( sQuery.Find(_T("TARGETINSTANCE.STATE=9")) != -1 )
  153. {
  154. sResString.LoadString(IDS_STRING_CRITICAL);
  155. sCondition += sResString + _T(",");
  156. }
  157. if( sQuery.Find(_T("TARGETINSTANCE.STATE=7")) != -1 )
  158. {
  159. sResString.LoadString(IDS_STRING_NODATA);
  160. sCondition += sResString + _T(",");
  161. }
  162. if( sQuery.Find(_T("TARGETINSTANCE.STATE=4")) != -1 )
  163. {
  164. sResString.LoadString(IDS_STRING_DISABLED);
  165. sCondition += sResString + _T(",");
  166. }
  167. sCondition.TrimRight(_T(","));
  168. delete pAssociation;
  169. return sCondition;
  170. }
  171. inline bool CAction::CreateStatusListener()
  172. {
  173. if( ! m_pActionStatusListener )
  174. {
  175. m_pActionStatusListener = new CActionStatusListener;
  176. // v-marfin : bug 59492 - SetObjectPtr() before calling Create() so object
  177. // has necessary member ptr set.
  178. m_pActionStatusListener->SetObjectPtr(this);
  179. m_pActionStatusListener->Create();
  180. }
  181. return true;
  182. }
  183. inline void CAction::DestroyStatusListener()
  184. {
  185. if( m_pActionStatusListener )
  186. {
  187. delete m_pActionStatusListener;
  188. m_pActionStatusListener = NULL;
  189. }
  190. }
  191. /////////////////////////////////////////////////////////////////////////////
  192. // Clipboard Operations
  193. /////////////////////////////////////////////////////////////////////////////
  194. inline bool CAction::Cut()
  195. {
  196. TRACEX(_T("CAction::Cut\n"));
  197. return false;
  198. }
  199. inline bool CAction::Copy()
  200. {
  201. TRACEX(_T("CAction::Copy\n"));
  202. return false;
  203. }
  204. inline bool CAction::Paste()
  205. {
  206. TRACEX(_T("CAction::Paste\n"));
  207. return false;
  208. }
  209. /////////////////////////////////////////////////////////////////////////////
  210. // Operations
  211. /////////////////////////////////////////////////////////////////////////////
  212. inline bool CAction::Refresh()
  213. {
  214. TRACEX(_T("CAction::Refresh\n"));
  215. return false;
  216. }
  217. /////////////////////////////////////////////////////////////////////////////
  218. // Scope Item Members
  219. /////////////////////////////////////////////////////////////////////////////
  220. inline CScopePaneItem* CAction::CreateScopeItem()
  221. {
  222. TRACEX(_T("CAction::CreateScopeItem\n"));
  223. CActionScopeItem * pNewItem = new CActionScopeItem;
  224. pNewItem->SetObjectPtr(this);
  225. return pNewItem;
  226. }
  227. /////////////////////////////////////////////////////////////////////////////
  228. // Type GUID
  229. /////////////////////////////////////////////////////////////////////////////
  230. inline CString CAction::GetTypeGuid()
  231. {
  232. TRACEX(_T("CAction::GetTypeGuid\n"));
  233. return m_sTypeGuid;
  234. }
  235. inline void CAction::SetTypeGuid(const CString& sGuid)
  236. {
  237. TRACEX(_T("CAction::SetTypeGuid\n"));
  238. TRACEARGs(sGuid);
  239. m_sTypeGuid = sGuid;
  240. if( m_sTypeGuid == IDS_STRING_MOF_HMAT_CMDLINE )
  241. {
  242. SetType(IDM_ACTION_CMDLINE);
  243. m_sConsumerClassName = _T("CommandLineEventConsumer");
  244. }
  245. else if( m_sTypeGuid == IDS_STRING_MOF_HMAT_EMAIL )
  246. {
  247. SetType(IDM_ACTION_EMAIL);
  248. m_sConsumerClassName = _T("SmtpEventConsumer");
  249. }
  250. else if( m_sTypeGuid == IDS_STRING_MOF_HMAT_TEXTLOG )
  251. {
  252. SetType(IDM_ACTION_LOGFILE);
  253. m_sConsumerClassName = _T("LogFileEventConsumer");
  254. }
  255. else if( m_sTypeGuid == IDS_STRING_MOF_HMAT_NTEVENT )
  256. {
  257. SetType(IDM_ACTION_NTEVENT);
  258. m_sConsumerClassName = _T("NTEventLogEventConsumer");
  259. }
  260. else if( m_sTypeGuid == IDS_STRING_MOF_HMAT_SCRIPT )
  261. {
  262. SetType(IDM_ACTION_SCRIPT);
  263. m_sConsumerClassName = _T("ActiveScriptEventConsumer");
  264. }
  265. else if( m_sTypeGuid == IDS_STRING_MOF_HMAT_PAGING )
  266. {
  267. SetType(IDM_ACTION_PAGING);
  268. m_sConsumerClassName = _T("PagerEventConsumer");
  269. }
  270. }
  271. inline int CAction::GetType()
  272. {
  273. TRACEX(_T("CAction::GetType\n"));
  274. return m_iType;
  275. }
  276. inline void CAction::SetType(int iType)
  277. {
  278. TRACEX(_T("CAction::SetType\n"));
  279. TRACEARGn(iType);
  280. m_iType = iType;
  281. }
  282. inline CString CAction::GetUITypeName()
  283. {
  284. TRACEX(_T("CAction::GetUITypeName\n"));
  285. CString sTypeName;
  286. switch( GetType() )
  287. {
  288. case IDM_ACTION_CMDLINE:
  289. {
  290. sTypeName.LoadString(IDS_STRING_ACTION_CMDLINE_FMT);
  291. }
  292. break;
  293. case IDM_ACTION_EMAIL:
  294. {
  295. sTypeName.LoadString(IDS_STRING_ACTION_EMAIL_FMT);
  296. }
  297. break;
  298. case IDM_ACTION_LOGFILE:
  299. {
  300. sTypeName.LoadString(IDS_STRING_ACTION_LOGFILE_FMT);
  301. }
  302. break;
  303. case IDM_ACTION_NTEVENT:
  304. {
  305. sTypeName.LoadString(IDS_STRING_ACTION_NTEVENT_FMT);
  306. }
  307. break;
  308. case IDM_ACTION_SCRIPT:
  309. {
  310. sTypeName.LoadString(IDS_STRING_ACTION_SCRIPT_FMT);
  311. }
  312. break;
  313. case IDM_ACTION_PAGING:
  314. {
  315. sTypeName.LoadString(IDS_STRING_ACTION_PAGING_FMT);
  316. }
  317. break;
  318. }
  319. sTypeName = sTypeName.Left(sTypeName.GetLength()-3);
  320. return sTypeName;
  321. }