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.

551 lines
12 KiB

  1. // HMDataElementConfiguration.cpp: implementation of the HMDataElementConfiguration class.
  2. //
  3. // Copyright (c) 2000 Microsoft Corporation
  4. //
  5. // 03/21/00 v-marfin bug 62315 : Moved from below GetAllProperties() to here to ensure
  6. // this property was fetched.
  7. #include "stdafx.h"
  8. #include "snapin.h"
  9. #include "HMDataElementConfiguration.h"
  10. #ifdef _DEBUG
  11. #undef THIS_FILE
  12. static char THIS_FILE[]=__FILE__;
  13. #define new DEBUG_NEW
  14. #endif
  15. IMPLEMENT_DYNCREATE(CHMDataElementConfiguration,CWbemClassObject)
  16. //////////////////////////////////////////////////////////////////////
  17. // Construction/Destruction
  18. //////////////////////////////////////////////////////////////////////
  19. CHMDataElementConfiguration::CHMDataElementConfiguration()
  20. {
  21. m_sName.LoadString(IDS_STRING_UNKNOWN);
  22. m_sDescription.LoadString(IDS_STRING_UNKNOWN);
  23. m_iCollectionIntervalMultiple = 0;
  24. m_iStatisticsWindowSize = 0;
  25. m_iActiveDays = 0;
  26. m_bRequireManualReset = false;
  27. m_bEnable = true;
  28. }
  29. CHMDataElementConfiguration::~CHMDataElementConfiguration()
  30. {
  31. Destroy();
  32. }
  33. //////////////////////////////////////////////////////////////////////
  34. // Create
  35. //////////////////////////////////////////////////////////////////////
  36. HRESULT CHMDataElementConfiguration::Create(const CString& sMachineName)
  37. {
  38. HRESULT hr = CWbemClassObject::Create(sMachineName);
  39. if( !CHECKHRESULT(hr) )
  40. {
  41. return hr;
  42. }
  43. return hr;
  44. }
  45. HRESULT CHMDataElementConfiguration::Create(IWbemClassObject* pObject)
  46. {
  47. HRESULT hr = CWbemClassObject::Create(pObject);
  48. if( !CHECKHRESULT(hr) )
  49. {
  50. return hr;
  51. }
  52. return hr;
  53. }
  54. //////////////////////////////////////////////////////////////////////
  55. // Enumeration Operations
  56. //////////////////////////////////////////////////////////////////////
  57. HRESULT CHMDataElementConfiguration::EnumerateObjects(ULONG& uReturned)
  58. {
  59. // call GetNextObject to proceed to the next object instance
  60. HRESULT hr = GetNextObject(uReturned);
  61. if( FAILED(hr) || uReturned != 1 )
  62. {
  63. // no more instances
  64. return hr;
  65. }
  66. ASSERT(m_pIWbemClassObject);
  67. if( m_pIWbemClassObject == NULL )
  68. {
  69. ASSERT(0);
  70. return S_FALSE;
  71. }
  72. // process the properties of this object
  73. hr = GetAllProperties();
  74. return hr;
  75. }
  76. //////////////////////////////////////////////////////////////////////
  77. // Property Retrieval Operations
  78. //////////////////////////////////////////////////////////////////////
  79. HRESULT CHMDataElementConfiguration::GetAllProperties()
  80. {
  81. ASSERT(m_pIWbemClassObject);
  82. if( m_pIWbemClassObject == NULL )
  83. {
  84. ASSERT(FALSE);
  85. return S_FALSE;
  86. }
  87. HRESULT hr = S_OK;
  88. // Unique identifier
  89. hr = GetProperty(IDS_STRING_MOF_GUID,m_sGUID);
  90. m_sGUID.TrimLeft(_T("{"));
  91. m_sGUID.TrimRight(_T("}"));
  92. // Display name
  93. hr = GetLocaleStringProperty(IDS_STRING_MOF_NAME,m_sName);
  94. // Description
  95. hr = GetLocaleStringProperty(IDS_STRING_MOF_DESCRIPTION,m_sDescription);
  96. // What Namespace we are to look in. Can contain path to a remote machine.
  97. hr = GetProperty(IDS_STRING_MOF_TARGETNAMESPACE,m_sTargetNamespace);
  98. // How often to sample.
  99. hr = GetProperty(IDS_STRING_MOF_COLLECTIONINTERVAL,m_iCollectionIntervalMultiple);
  100. // Number of collection intervals to calculate the statistics across.
  101. // And also determining number of event rule cases.
  102. hr = GetProperty(IDS_STRING_MOF_STATISTICSWINDOW,m_iStatisticsWindowSize);
  103. // Days of the week it is active. One bit per day.
  104. hr = GetProperty(IDS_STRING_MOF_ACTIVEDAYS,m_iActiveDays);
  105. // Hour (24hr) to activate (if day is active). e.g. 9 for 9AM
  106. hr = GetProperty(IDS_STRING_MOF_BEGINTIME,m_BeginTime,false);
  107. if( hr == S_FALSE )
  108. {
  109. m_BeginTime = CTime(1999,12,31,0,0,0);
  110. }
  111. // Hour (24hr) to inactivate. e.g. 1350
  112. hr = GetProperty(IDS_STRING_MOF_ENDTIME,m_EndTime,false);
  113. if( hr == S_FALSE )
  114. {
  115. m_EndTime = CTime(1999,12,31,23,59,59);
  116. }
  117. // For use by the console to aid in the display
  118. hr = GetProperty(IDS_STRING_MOF_TYPEGUID,m_sTypeGUID);
  119. m_sTypeGUID.TrimLeft(_T("{"));
  120. m_sTypeGUID.TrimRight(_T("}"));
  121. hr = GetProperty(IDS_STRING_MOF_REQUIRERESET,m_bRequireManualReset);
  122. // Enable
  123. hr = GetProperty(IDS_STRING_MOF_ENABLE,m_bEnable);
  124. // Statistics Property Names
  125. hr = GetProperty(IDS_STRING_MOF_STATISTICSPROPERTYNAMES,m_saStatisticsPropertyNames);
  126. return hr;
  127. }
  128. HRESULT CHMDataElementConfiguration::SaveEnabledProperty()
  129. {
  130. ASSERT(m_pIWbemClassObject);
  131. if( m_pIWbemClassObject == NULL )
  132. {
  133. ASSERT(FALSE);
  134. return S_FALSE;
  135. }
  136. HRESULT hr = S_OK;
  137. // Enable
  138. hr = SetProperty(IDS_STRING_MOF_ENABLE,m_bEnable);
  139. ASSERT(SUCCEEDED(hr));
  140. hr = SaveAllProperties();
  141. ASSERT(SUCCEEDED(hr));
  142. return hr;
  143. }
  144. HRESULT CHMDataElementConfiguration::SaveAllProperties()
  145. {
  146. HRESULT hr = S_OK;
  147. // Display name
  148. hr = SetProperty(IDS_STRING_MOF_NAME,m_sName);
  149. // Description
  150. hr = SetProperty(IDS_STRING_MOF_DESCRIPTION,m_sDescription);
  151. // What Namespace we are to look in. Can contain path to a remote machine.
  152. hr = SetProperty(IDS_STRING_MOF_TARGETNAMESPACE,m_sTargetNamespace);
  153. // How often to sample.
  154. hr = SetProperty(IDS_STRING_MOF_COLLECTIONINTERVAL,m_iCollectionIntervalMultiple);
  155. // Number of collection intervals to calculate the statistics across.
  156. // And also determining number of event rule cases.
  157. hr = SetProperty(IDS_STRING_MOF_STATISTICSWINDOW,m_iStatisticsWindowSize);
  158. // Days of the week it is active. One bit per day.
  159. hr = SetProperty(IDS_STRING_MOF_ACTIVEDAYS,m_iActiveDays);
  160. // Hour (24hr) to activate (if day is active). e.g. 9 for 9AM
  161. hr = SetProperty(IDS_STRING_MOF_BEGINTIME,m_BeginTime,false);
  162. // Hour (24hr) to inactivate. e.g. 1350
  163. hr = SetProperty(IDS_STRING_MOF_ENDTIME,m_EndTime,false);
  164. // For use by the console to aid in the display
  165. hr = SetProperty(IDS_STRING_MOF_TYPEGUID,m_sTypeGUID);
  166. hr = SetProperty(IDS_STRING_MOF_REQUIRERESET,m_bRequireManualReset);
  167. // Enable
  168. hr = SetProperty(IDS_STRING_MOF_ENABLE,m_bEnable);
  169. // Statistics Property Names
  170. hr = SetProperty(IDS_STRING_MOF_STATISTICSPROPERTYNAMES,m_saStatisticsPropertyNames);
  171. if( ! CHECKHRESULT( hr = CWbemClassObject::SaveAllProperties() ) )
  172. {
  173. TRACE(_T("FAILED : Call to CWbemClassObject::SaveAllProperties failed.\n"));
  174. }
  175. return hr;
  176. }
  177. //////////////////////////////////////////////////////////////////////
  178. // implementation of the CHMPolledGetObjectDataElementConfiguration class
  179. //////////////////////////////////////////////////////////////////////
  180. // Property Retreival Operations
  181. //////////////////////////////////////////////////////////////////////
  182. HRESULT CHMPolledGetObjectDataElementConfiguration::GetAllProperties()
  183. {
  184. HRESULT hr = S_OK;
  185. // Unique identifier
  186. // v-marfin 62315 : Moved from below GetAllProperties() to here to ensure
  187. // this property was fetched.
  188. hr = GetProperty(IDS_STRING_MOF_PATH,m_sObjectPath);
  189. if (!CHECKHRESULT(hr))
  190. {
  191. return hr;
  192. }
  193. if( ! CHECKHRESULT(hr = CHMDataElementConfiguration::GetAllProperties()) )
  194. {
  195. return hr;
  196. }
  197. return hr;
  198. }
  199. HRESULT CHMPolledGetObjectDataElementConfiguration::SaveAllProperties()
  200. {
  201. HRESULT hr = S_OK;
  202. // ObjectPath
  203. hr = SetProperty(IDS_STRING_MOF_PATH,m_sObjectPath);
  204. if( ! CHECKHRESULT(hr = CHMDataElementConfiguration::SaveAllProperties()) )
  205. {
  206. return hr;
  207. }
  208. return hr;
  209. }
  210. //////////////////////////////////////////////////////////////////////
  211. // implementation of the CHMPolledMethodDataElementConfiguration class
  212. CHMPolledMethodDataElementConfiguration::~CHMPolledMethodDataElementConfiguration()
  213. {
  214. DestroyArguments(m_Arguments);
  215. }
  216. void CHMPolledMethodDataElementConfiguration::AddArgument(HMContextArray& Arguments, const CString& sMachineName, const CString& sName, int iType, const CString& sValue)
  217. {
  218. CHMContext* pContext = new CHMContext;
  219. pContext->SetMachineName(sMachineName);
  220. CString sClassName = _T("Microsoft_HMContext");
  221. BSTR bsClassName = sClassName.AllocSysString();
  222. if( ! CHECKHRESULT(pContext->CreateInstance(bsClassName)) )
  223. {
  224. return;
  225. }
  226. pContext->m_iType = iType;
  227. pContext->m_sValue = sValue;
  228. pContext->m_sName = sName;
  229. pContext->SaveAllProperties();
  230. Arguments.Add(pContext);
  231. ::SysFreeString(bsClassName);
  232. }
  233. void CHMPolledMethodDataElementConfiguration::DestroyArguments(HMContextArray& Arguments)
  234. {
  235. for( int i = 0; i < Arguments.GetSize(); i++ )
  236. {
  237. if( GfxCheckObjPtr(Arguments[i],CHMContext) )
  238. {
  239. delete Arguments[i];
  240. }
  241. }
  242. Arguments.RemoveAll();
  243. }
  244. void CHMPolledMethodDataElementConfiguration::CopyArgsToSafeArray(HMContextArray& Arguments, COleSafeArray& Target)
  245. {
  246. Target.CreateOneDim(VT_UNKNOWN,(int)Arguments.GetSize());
  247. for( long i = 0; i < Arguments.GetSize(); i++ )
  248. {
  249. IWbemClassObject* pIWCO = Arguments[i]->GetClassObject();
  250. if( pIWCO )
  251. {
  252. Target.PutElement(&i,pIWCO);
  253. pIWCO->Release();
  254. }
  255. }
  256. }
  257. void CHMPolledMethodDataElementConfiguration::CopyArgsFromSafeArray(COleSafeArray& Arguments, HMContextArray& Target)
  258. {
  259. long lLower = 0L;
  260. long lUpper = -1L;
  261. Arguments.GetLBound(1L,&lLower);
  262. Arguments.GetUBound(1L,&lUpper);
  263. for( long i = lLower; i <= lUpper; i++ )
  264. {
  265. IWbemClassObject* pIWBCO = NULL;
  266. Arguments.GetElement(&i,&pIWBCO);
  267. if( pIWBCO )
  268. {
  269. CHMContext* pHMC = new CHMContext;
  270. pHMC->Create(pIWBCO);
  271. pHMC->GetAllProperties();
  272. Target.Add(pHMC);
  273. }
  274. }
  275. }
  276. //////////////////////////////////////////////////////////////////////
  277. // Property Retreival Operations
  278. //////////////////////////////////////////////////////////////////////
  279. HRESULT CHMPolledMethodDataElementConfiguration::GetAllProperties()
  280. {
  281. HRESULT hr = S_OK;
  282. if( ! CHECKHRESULT(hr = CHMPolledGetObjectDataElementConfiguration::GetAllProperties()) )
  283. {
  284. return hr;
  285. }
  286. // MethodName
  287. hr = GetProperty(IDS_STRING_MOF_METHODNAME,m_sMethodName);
  288. // Arguments
  289. hr = GetProperty(IDS_STRING_MOF_ARGUMENTS,m_arguments);
  290. long lLower = 0L;
  291. long lUpper = -1L;
  292. if( hr != S_FALSE )
  293. {
  294. m_arguments.GetLBound(1L,&lLower);
  295. m_arguments.GetUBound(1L,&lUpper);
  296. }
  297. for( long i = lLower; i <= lUpper; i++ )
  298. {
  299. IWbemClassObject* pIWBCO = NULL;
  300. m_arguments.GetElement(&i,&pIWBCO);
  301. if( pIWBCO )
  302. {
  303. CHMContext* pHMC = new CHMContext;
  304. pHMC->Create(pIWBCO);
  305. pHMC->GetAllProperties();
  306. m_Arguments.Add(pHMC);
  307. }
  308. }
  309. return hr;
  310. }
  311. HRESULT CHMPolledMethodDataElementConfiguration::SaveAllProperties()
  312. {
  313. HRESULT hr = S_OK;
  314. // MethodName
  315. hr = SetProperty(IDS_STRING_MOF_METHODNAME,m_sMethodName);
  316. // Arguments
  317. m_arguments.Destroy();
  318. m_arguments.CreateOneDim(VT_UNKNOWN,(int)m_Arguments.GetSize());
  319. for( long i = 0; i < m_Arguments.GetSize(); i++ )
  320. {
  321. IWbemClassObject* pIWCO = m_Arguments[i]->GetClassObject();
  322. if( pIWCO )
  323. {
  324. m_arguments.PutElement(&i,pIWCO);
  325. pIWCO->Release();
  326. }
  327. }
  328. hr = SetProperty(IDS_STRING_MOF_ARGUMENTS,m_arguments);
  329. if( ! CHECKHRESULT(hr = CHMPolledGetObjectDataElementConfiguration::SaveAllProperties()) )
  330. {
  331. return hr;
  332. }
  333. return hr;
  334. }
  335. //////////////////////////////////////////////////////////////////////
  336. // implementation of the CHMQueryDataElementConfiguration class
  337. //////////////////////////////////////////////////////////////////////
  338. // Property Retreival Operations
  339. //////////////////////////////////////////////////////////////////////
  340. HRESULT CHMQueryDataElementConfiguration::GetAllProperties()
  341. {
  342. HRESULT hr = S_OK;
  343. if( ! CHECKHRESULT(hr = CHMDataElementConfiguration::GetAllProperties()) )
  344. {
  345. return hr;
  346. }
  347. hr = GetProperty(IDS_STRING_MOF_QUERY,m_sQuery);
  348. return hr;
  349. }
  350. HRESULT CHMQueryDataElementConfiguration::SaveAllProperties()
  351. {
  352. HRESULT hr = S_OK;
  353. hr = SetProperty(IDS_STRING_MOF_QUERY,m_sQuery);
  354. if( ! CHECKHRESULT(hr = CHMDataElementConfiguration::SaveAllProperties()) )
  355. {
  356. return hr;
  357. }
  358. return hr;
  359. }