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.

387 lines
8.3 KiB

  1. // File DataElement.inl
  2. //
  3. // Copyright (c) 2000 Microsoft Corporation
  4. //
  5. // 03/25/00 v-marfin : Added new function GetObjectPathBasedOnTypeGUID()
  6. // 03/27/00 v-marfin : 62510 Modified CreateNewChildRule() so that when a new data collector
  7. // is created, this function can be called to create a new
  8. // threshold without showing the property pages. The new collector
  9. // will set the default values.
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // WMI Operations
  15. /////////////////////////////////////////////////////////////////////////////
  16. inline HRESULT CDataElement::EnumerateChildren()
  17. {
  18. TRACEX(_T("CDataElement::EnumerateChildren\n"));
  19. if( m_pRuleListener == NULL )
  20. {
  21. m_pRuleListener = new CRuleConfigListener;
  22. m_pRuleListener->SetObjectPtr(this);
  23. m_pRuleListener->Create();
  24. }
  25. else
  26. {
  27. IncrementActiveSinkCount();
  28. }
  29. HRESULT hr = S_OK;
  30. CString sQuery;
  31. sQuery.Format(IDS_STRING_DE2R_ASSOC_QUERY,GetGuid());
  32. IWbemObjectSink* pSink = m_pRuleListener->GetSink();
  33. if( !CHECKHRESULT(hr = CnxExecQueryAsync(GetSystemName(),sQuery,pSink)) )
  34. {
  35. TRACE(_T("FAILED : CConnectionManager::RegisterEventNotification failed!\n"));
  36. }
  37. return hr;
  38. }
  39. //*********************************************************
  40. // GetObjectPathBasedOnTypeGUID v-marfin : new function
  41. //*********************************************************
  42. inline CString CDataElement::GetObjectPathBasedOnTypeGUID()
  43. {
  44. TRACEX(_T("CDataElement::GetObjectPath\n"));
  45. CString sPath;
  46. sPath.Format(IDS_STRING_MOF_OBJECTPATH,IDS_STRING_MOF_HMDE_CONFIG,GetTypeGuid());
  47. return sPath;
  48. }
  49. inline CString CDataElement::GetObjectPath()
  50. {
  51. TRACEX(_T("CDataElement::GetObjectPath\n"));
  52. CString sPath;
  53. sPath.Format(IDS_STRING_MOF_OBJECTPATH,IDS_STRING_MOF_HMDE_CONFIG,GetGuid());
  54. return sPath;
  55. }
  56. inline CString CDataElement::GetStatusObjectPath()
  57. {
  58. TRACEX(_T("CDataElement::GetStatusObjectPath\n"));
  59. CString sPath;
  60. sPath.Format(IDS_STRING_MOF_OBJECTPATH,IDS_STRING_MOF_HMDE_STATUS,GetGuid());
  61. return sPath;
  62. }
  63. inline CHMEvent* CDataElement::GetStatusClassObject()
  64. {
  65. TRACEX(_T("CDataElement::GetStatusClassObject\n"));
  66. CHMEvent* pClassObject = new CHMDataElementStatus;
  67. pClassObject->SetMachineName(GetSystemName());
  68. if( ! CHECKHRESULT(pClassObject->GetObject(GetStatusObjectPath())) )
  69. {
  70. delete pClassObject;
  71. return NULL;
  72. }
  73. pClassObject->GetAllProperties();
  74. return pClassObject;
  75. }
  76. /*
  77. inline void CDataElement::DeleteClassObject()
  78. {
  79. TRACEX(_T("CDataElement::DeleteClassObject\n"));
  80. // get associator path
  81. CWbemClassObject Associator;
  82. Associator.SetMachineName(GetSystemName());
  83. CString sQuery;
  84. sQuery.Format(IDS_STRING_DE2DG_REF_QUERY,GetGuid());
  85. BSTR bsQuery = sQuery.AllocSysString();
  86. if( ! CHECKHRESULT(Associator.ExecQuery(bsQuery)) )
  87. {
  88. ::SysFreeString(bsQuery);
  89. return;
  90. }
  91. ::SysFreeString(bsQuery);
  92. ULONG ulReturned = 0L;
  93. if( Associator.GetNextObject(ulReturned) != S_OK )
  94. {
  95. ASSERT(FALSE);
  96. return;
  97. }
  98. CString sAssociatorPath;
  99. Associator.GetProperty(_T("__path"),sAssociatorPath);
  100. Associator.Destroy();
  101. // delete the instance
  102. Associator.SetMachineName(GetSystemName());
  103. BSTR bsInstanceName = sAssociatorPath.AllocSysString();
  104. CHECKHRESULT(Associator.DeleteInstance(bsInstanceName));
  105. ::SysFreeString(bsInstanceName);
  106. }
  107. */
  108. /////////////////////////////////////////////////////////////////////////////
  109. // Clipboard Operations
  110. /////////////////////////////////////////////////////////////////////////////
  111. inline bool CDataElement::Cut()
  112. {
  113. TRACEX(_T("CDataElement::Cut\n"));
  114. return false;
  115. }
  116. inline bool CDataElement::Copy()
  117. {
  118. TRACEX(_T("CDataElement::Copy\n"));
  119. return false;
  120. }
  121. inline bool CDataElement::Paste()
  122. {
  123. TRACEX(_T("CDataElement::Paste\n"));
  124. return false;
  125. }
  126. /////////////////////////////////////////////////////////////////////////////
  127. // Scope Item Members
  128. /////////////////////////////////////////////////////////////////////////////
  129. inline CScopePaneItem* CDataElement::CreateScopeItem()
  130. {
  131. TRACEX(_T("CDataElement::CreateScopeItem\n"));
  132. CDataElementScopeItem * pNewItem = new CDataElementScopeItem;
  133. pNewItem->SetObjectPtr(this);
  134. return pNewItem;
  135. }
  136. /////////////////////////////////////////////////////////////////////////////
  137. // New Child Creation Members
  138. /////////////////////////////////////////////////////////////////////////////
  139. inline void CDataElement::CreateNewChildRule(BOOL bJustCreateAndReturn, CRule** pCreatedRule, CString sThresholdName)
  140. {
  141. TRACEX(_T("CDataElement::CreateNewChildRule\n"));
  142. CString sName = GetUniqueChildName(IDS_STRING_RULE_FMT);
  143. CRule* pNewRule = new CRule;
  144. // If a threshold name is passed, use it
  145. pNewRule->SetName((sThresholdName.IsEmpty()) ? sName : sThresholdName);
  146. CreateChild(pNewRule,IDS_STRING_MOF_HMR_CONFIG,IDS_STRING_MOF_HMC2C_ASSOC);
  147. // v-marfin : 62510 Added this check so that when a new data collector
  148. // is created, this function can be called to create a new
  149. // threshold without showing the property pages. The new collector
  150. // will set the default values.
  151. if (bJustCreateAndReturn)
  152. {
  153. *pCreatedRule = pNewRule;
  154. return;
  155. }
  156. if( pNewRule->GetScopeItemCount() )
  157. {
  158. CScopePaneItem* pItem = pNewRule->GetScopeItem(0);
  159. if( pItem )
  160. {
  161. pItem->SelectItem();
  162. pItem->InvokePropertySheet();
  163. }
  164. }
  165. }
  166. /////////////////////////////////////////////////////////////////////////////
  167. // Type GUID
  168. /////////////////////////////////////////////////////////////////////////////
  169. inline CString CDataElement::GetTypeGuid()
  170. {
  171. TRACEX(_T("CDataElement::GetTypeGuid\n"));
  172. return m_sTypeGuid;
  173. }
  174. inline void CDataElement::SetTypeGuid(const CString& sGuid)
  175. {
  176. TRACEX(_T("CDataElement::SetTypeGuid\n"));
  177. TRACEARGs(sGuid);
  178. m_sTypeGuid = sGuid;
  179. if( m_sTypeGuid == IDS_STRING_MOF_HMDET_FILE_INFO )
  180. {
  181. SetType(IDM_FILE_INFO);
  182. }
  183. else if( m_sTypeGuid == IDS_STRING_MOF_HMDET_WMI_INSTANCE )
  184. {
  185. SetType(IDM_GENERIC_WMI_INSTANCE);
  186. }
  187. else if( m_sTypeGuid == IDS_STRING_MOF_HMDET_WMI_QUERY )
  188. {
  189. SetType(IDM_GENERIC_WMI_QUERY);
  190. }
  191. else if( m_sTypeGuid == IDS_STRING_MOF_HMDET_WMI_POLLED_QUERY )
  192. {
  193. SetType(IDM_GENERIC_WMI_POLLED_QUERY);
  194. }
  195. else if( m_sTypeGuid == IDS_STRING_MOF_HMDET_SNMP )
  196. {
  197. SetType(IDM_SNMP);
  198. }
  199. else if( m_sTypeGuid == IDS_STRING_MOF_HMDET_HTTP )
  200. {
  201. SetType(IDM_HTTP_ADDRESS);
  202. }
  203. else if( m_sTypeGuid == IDS_STRING_MOF_HMDET_SERVICE )
  204. {
  205. SetType(IDM_SERVICE);
  206. }
  207. else if( m_sTypeGuid == IDS_STRING_MOF_HMDET_PERFMON )
  208. {
  209. SetType(IDM_PERFMON);
  210. }
  211. else if( m_sTypeGuid == IDS_STRING_MOF_HMDET_NTEVENT )
  212. {
  213. SetType(IDM_NT_EVENTS);
  214. }
  215. else if( m_sTypeGuid == IDS_STRING_MOF_HMDET_SMTP )
  216. {
  217. SetType(IDM_SMTP);
  218. }
  219. else if( m_sTypeGuid == IDS_STRING_MOF_HMDET_FTP )
  220. {
  221. SetType(IDM_FTP);
  222. }
  223. else if( m_sTypeGuid == IDS_STRING_MOF_HMDET_ICMP )
  224. {
  225. SetType(IDM_ICMP);
  226. }
  227. else if(m_sTypeGuid == IDS_STRING_MOF_HMDET_COM_PLUS )
  228. {
  229. SetType(IDM_COM_PLUS);
  230. }
  231. }
  232. inline int CDataElement::GetType()
  233. {
  234. TRACEX(_T("CDataElement::GetType\n"));
  235. return m_iType;
  236. }
  237. inline void CDataElement::SetType(int iType)
  238. {
  239. TRACEX(_T("CDataElement::SetType\n"));
  240. TRACEARGn(iType);
  241. m_iType = iType;
  242. }
  243. inline CString CDataElement::GetUITypeName()
  244. {
  245. TRACEX(_T("CDataElement::GetUITypeName\n"));
  246. CString sTypeName;
  247. switch( GetType() )
  248. {
  249. case IDM_GENERIC_WMI_INSTANCE:
  250. {
  251. sTypeName.LoadString(IDS_STRING_WMI_INSTANCE_FMT);
  252. }
  253. break;
  254. case IDM_GENERIC_WMI_QUERY:
  255. {
  256. sTypeName.LoadString(IDS_STRING_WMI_EVENT_QUERY_FMT);
  257. }
  258. break;
  259. case IDM_GENERIC_WMI_POLLED_QUERY:
  260. {
  261. sTypeName.LoadString(IDS_STRING_WMI_QUERY_FMT);
  262. }
  263. break;
  264. case IDM_NT_EVENTS:
  265. {
  266. sTypeName.LoadString(IDS_STRING_EVENT_LOG_FMT);
  267. }
  268. break;
  269. case IDM_PERFMON:
  270. {
  271. sTypeName.LoadString(IDS_STRING_PERFMON_FMT);
  272. }
  273. break;
  274. case IDM_SERVICE:
  275. {
  276. sTypeName.LoadString(IDS_STRING_SERVICE_FMT);
  277. }
  278. break;
  279. case IDM_HTTP_ADDRESS:
  280. {
  281. sTypeName.LoadString(IDS_STRING_HTTP_FMT);
  282. }
  283. break;
  284. case IDM_SMTP:
  285. {
  286. sTypeName.LoadString(IDS_STRING_SMTP_FMT);
  287. }
  288. break;
  289. case IDM_FTP:
  290. {
  291. sTypeName.LoadString(IDS_STRING_FTP_FMT);
  292. }
  293. break;
  294. case IDM_FILE_INFO:
  295. {
  296. sTypeName.LoadString(IDS_STRING_FILE_INFO_FMT);
  297. }
  298. break;
  299. case IDM_ICMP:
  300. {
  301. sTypeName.LoadString(IDS_STRING_ICMP_FMT);
  302. }
  303. break;
  304. default:
  305. {
  306. sTypeName.LoadString(IDS_STRING_WMI_INSTANCE_FMT);
  307. }
  308. break;
  309. }
  310. sTypeName = sTypeName.Left(sTypeName.GetLength()-3);
  311. return sTypeName;
  312. }