Leaked source code of windows server 2003
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.

418 lines
15 KiB

  1. // Copyright (c) 2000-2001 Microsoft Corporation, All Rights Reserved
  2. // CJobObjIOActgProps.cpp
  3. //#define _WIN32_WINNT 0x0500
  4. #include "precomp.h"
  5. #include <wbemprov.h>
  6. #include "FRQueryEx.h"
  7. #include <vector>
  8. #include "helpers.h"
  9. #include "CVARIANT.h"
  10. #include "CObjProps.h"
  11. #include "CJobObjIOActgProps.h"
  12. #include <crtdbg.h>
  13. //*****************************************************************************
  14. // BEGIN: Declaration of Win32_JobObjIOActgInfo class properties.
  15. //*****************************************************************************
  16. // WARNING!! MUST KEEP MEMBERS OF THE FOLLOWING ARRAY
  17. // IN SYNCH WITH THE JOB_OBJ_PROPS ENUMERATION DECLARED
  18. // IN CJobObjProps.h !!!
  19. LPCWSTR g_rgJobObjIOActgPropNames[] =
  20. {
  21. { L"Name" },
  22. { L"TotalUserTime" },
  23. { L"TotalKernelTime" },
  24. { L"ThisPeriodTotalUserTime" },
  25. { L"ThisPeriodTotalKernelTime" },
  26. { L"TotalPageFaultCount" },
  27. { L"TotalProcesses" },
  28. { L"ActiveProcesses" },
  29. { L"TotalTerminatedProcesses" },
  30. { L"ReadOperationCount" },
  31. { L"WriteOperationCount" },
  32. { L"OtherOperationCount" },
  33. { L"ReadTransferCount" },
  34. { L"WriteTransferCount" },
  35. { L"OtherTransferCount" },
  36. { L"PeakProcessMemoryUsed" },
  37. { L"PeakJobMemoryUsed" }
  38. };
  39. //*****************************************************************************
  40. // END: Declaration of Win32_JobObjIOActgInfo class properties.
  41. //*****************************************************************************
  42. CJobObjIOActgProps::CJobObjIOActgProps(CHString& chstrNamespace)
  43. : CObjProps(chstrNamespace)
  44. {
  45. }
  46. CJobObjIOActgProps::CJobObjIOActgProps(
  47. HANDLE hJob,
  48. CHString& chstrNamespace)
  49. : CObjProps(chstrNamespace),
  50. m_hJob(hJob)
  51. {
  52. }
  53. CJobObjIOActgProps::~CJobObjIOActgProps()
  54. {
  55. }
  56. // Clients call this to establish which properties
  57. // were requested. This function calls a base class
  58. // helper, which calls our CheckProps function.
  59. // The base class helper finally stores the result
  60. // in the base class member m_dwReqProps.
  61. HRESULT CJobObjIOActgProps::GetWhichPropsReq(
  62. CFrameworkQuery& cfwq)
  63. {
  64. HRESULT hr = S_OK;
  65. // Call base class version for help.
  66. // Base class version will call our
  67. // CheckProps function.
  68. hr = CObjProps::GetWhichPropsReq(
  69. cfwq,
  70. CheckProps);
  71. return hr;
  72. }
  73. DWORD CJobObjIOActgProps::CheckProps(
  74. CFrameworkQuery& Query)
  75. {
  76. DWORD dwReqProps = PROP_NONE_REQUIRED;
  77. // Get the requested properties for this
  78. // specific object...
  79. if (Query.IsPropertyRequired(g_rgJobObjIOActgPropNames[JOIOACTGPROP_ID]))
  80. dwReqProps |= PROP_JOIOActgID;
  81. if (Query.IsPropertyRequired(g_rgJobObjIOActgPropNames[JOIOACTGPROP_TotalUserTime]))
  82. dwReqProps |= PROP_TotalUserTime;
  83. if (Query.IsPropertyRequired(g_rgJobObjIOActgPropNames[JOIOACTGPROP_TotalKernelTime]))
  84. dwReqProps |= PROP_TotalKernelTime;
  85. if (Query.IsPropertyRequired(g_rgJobObjIOActgPropNames[JOIOACTGPROP_ThisPeriodTotalUserTime]))
  86. dwReqProps |= PROP_ThisPeriodTotalUserTime;
  87. if (Query.IsPropertyRequired(g_rgJobObjIOActgPropNames[JOIOACTGPROP_ThisPeriodTotalKernelTime]))
  88. dwReqProps |= PROP_ThisPeriodTotalKernelTime;
  89. if (Query.IsPropertyRequired(g_rgJobObjIOActgPropNames[JOIOACTGPROP_TotalPageFaultCount]))
  90. dwReqProps |= PROP_TotalPageFaultCount;
  91. if (Query.IsPropertyRequired(g_rgJobObjIOActgPropNames[JOIOACTGPROP_TotalProcesses]))
  92. dwReqProps |= PROP_TotalProcesses;
  93. if (Query.IsPropertyRequired(g_rgJobObjIOActgPropNames[JOIOACTGPROP_ActiveProcesses]))
  94. dwReqProps |= PROP_ActiveProcesses;
  95. if (Query.IsPropertyRequired(g_rgJobObjIOActgPropNames[JOIOACTGPROP_TotalTerminatedProcesses]))
  96. dwReqProps |= PROP_TotalTerminatedProcesses;
  97. if (Query.IsPropertyRequired(g_rgJobObjIOActgPropNames[JOIOACTGPROP_ReadOperationCount]))
  98. dwReqProps |= PROP_ReadOperationCount;
  99. if (Query.IsPropertyRequired(g_rgJobObjIOActgPropNames[JOIOACTGPROP_WriteOperationCount]))
  100. dwReqProps |= PROP_WriteOperationCount;
  101. if (Query.IsPropertyRequired(g_rgJobObjIOActgPropNames[JOIOACTGPROP_OtherOperationCount]))
  102. dwReqProps |= PROP_OtherOperationCount;
  103. if (Query.IsPropertyRequired(g_rgJobObjIOActgPropNames[JOIOACTGPROP_ReadTransferCount]))
  104. dwReqProps |= PROP_ReadTransferCount;
  105. if (Query.IsPropertyRequired(g_rgJobObjIOActgPropNames[JOIOACTGPROP_WriteTransferCount]))
  106. dwReqProps |= PROP_WriteTransferCount;
  107. if (Query.IsPropertyRequired(g_rgJobObjIOActgPropNames[JOIOACTGPROP_OtherTransferCount]))
  108. dwReqProps |= PROP_OtherTransferCount;
  109. if (Query.IsPropertyRequired(g_rgJobObjIOActgPropNames[JOIOACTGPROP_PeakProcessMemoryUsed]))
  110. dwReqProps |= PROP_PeakProcessMemoryUsed;
  111. if (Query.IsPropertyRequired(g_rgJobObjIOActgPropNames[JOIOACTGPROP_PeakJobMemoryUsed]))
  112. dwReqProps |= PROP_PeakJobMemoryUsed;
  113. return dwReqProps;
  114. }
  115. void CJobObjIOActgProps::SetHandle(
  116. const HANDLE hJob)
  117. {
  118. m_hJob = hJob;
  119. }
  120. HANDLE& CJobObjIOActgProps::GetHandle()
  121. {
  122. _ASSERT(m_hJob);
  123. return m_hJob;
  124. }
  125. // Sets the key properties from the ObjectPath.
  126. HRESULT CJobObjIOActgProps::SetKeysFromPath(
  127. const BSTR ObjectPath,
  128. IWbemContext __RPC_FAR *pCtx)
  129. {
  130. HRESULT hr = WBEM_S_NO_ERROR;
  131. // This array contains the key field names
  132. CHStringArray rgchstrKeys;
  133. rgchstrKeys.Add(g_rgJobObjIOActgPropNames[JOIOACTGPROP_ID]);
  134. // This array contains the index numbers
  135. // in m_PropMap corresponding to the keys.
  136. short sKeyNum[1];
  137. sKeyNum[0] = JOIOACTGPROP_ID;
  138. hr = CObjProps::SetKeysFromPath(
  139. ObjectPath,
  140. pCtx,
  141. IDS_Win32_JobObjectIOAccountingInfo,
  142. rgchstrKeys,
  143. sKeyNum);
  144. return hr;
  145. }
  146. // Sets the key property from in supplied
  147. // parameter.
  148. HRESULT CJobObjIOActgProps::SetKeysDirect(
  149. std::vector<CVARIANT>& vecvKeys)
  150. {
  151. HRESULT hr = WBEM_S_NO_ERROR;
  152. if(vecvKeys.size() == 1)
  153. {
  154. short sKeyNum[1];
  155. sKeyNum[0] = JOIOACTGPROP_ID;
  156. hr = CObjProps::SetKeysDirect(
  157. vecvKeys,
  158. sKeyNum);
  159. }
  160. else
  161. {
  162. hr = WBEM_E_INVALID_PARAMETER;
  163. }
  164. return hr;
  165. }
  166. // Sets the non-key properties. Only those
  167. // properties requested are set (as determined
  168. // by base class member m_dwReqProps).
  169. HRESULT CJobObjIOActgProps::SetNonKeyReqProps()
  170. {
  171. HRESULT hr = WBEM_S_NO_ERROR;
  172. DWORD dwReqProps = GetReqProps();
  173. _ASSERT(m_hJob);
  174. if(!m_hJob) return WBEM_E_INVALID_PARAMETER;
  175. // Because all the properties of this class
  176. // come from the same underlying win32 job
  177. // object structure, we only need to get that
  178. // structure one time. We only need to get
  179. // it at all if at least one non-key property
  180. // was requested.
  181. if(dwReqProps != PROP_NONE_REQUIRED)
  182. {
  183. // Get the value from the underlying JO:
  184. JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION jobaioai;
  185. JOBOBJECT_EXTENDED_LIMIT_INFORMATION joeli;
  186. BOOL fQIJO = ::QueryInformationJobObject(
  187. m_hJob,
  188. JobObjectBasicAndIoAccountingInformation,
  189. &jobaioai,
  190. sizeof(JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION),
  191. NULL);
  192. if(fQIJO)
  193. {
  194. fQIJO = ::QueryInformationJobObject(
  195. m_hJob,
  196. JobObjectExtendedLimitInformation,
  197. &joeli,
  198. sizeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION),
  199. NULL);
  200. }
  201. if(!fQIJO)
  202. {
  203. _ASSERT(0);
  204. hr = WBEM_E_FAILED;
  205. }
  206. else
  207. {
  208. try // CVARIANT can throw
  209. {
  210. // Get all the requested values...
  211. if(dwReqProps & PROP_TotalUserTime)
  212. {
  213. ULONGLONG llTotalUserTime = (ULONGLONG)jobaioai.BasicInfo.TotalUserTime.QuadPart;
  214. m_PropMap.insert(SHORT2PVARIANT::value_type(
  215. JOIOACTGPROP_TotalUserTime,
  216. new CVARIANT(llTotalUserTime)));
  217. }
  218. if(dwReqProps & PROP_TotalKernelTime)
  219. {
  220. ULONGLONG llTotalKernelTime = (ULONGLONG)jobaioai.BasicInfo.TotalKernelTime.QuadPart;
  221. m_PropMap.insert(SHORT2PVARIANT::value_type(
  222. JOIOACTGPROP_TotalKernelTime,
  223. new CVARIANT(llTotalKernelTime)));
  224. }
  225. if(dwReqProps & PROP_ThisPeriodTotalUserTime)
  226. {
  227. ULONGLONG llThisPeriodTotalUserTime = (ULONGLONG)jobaioai.BasicInfo.ThisPeriodTotalUserTime.QuadPart;
  228. m_PropMap.insert(SHORT2PVARIANT::value_type(
  229. JOIOACTGPROP_ThisPeriodTotalUserTime,
  230. new CVARIANT(llThisPeriodTotalUserTime)));
  231. }
  232. if(dwReqProps & PROP_ThisPeriodTotalKernelTime)
  233. {
  234. ULONGLONG llThisPeriodTotalKernelTime = (ULONGLONG)jobaioai.BasicInfo.ThisPeriodTotalKernelTime.QuadPart;
  235. m_PropMap.insert(SHORT2PVARIANT::value_type(
  236. JOIOACTGPROP_ThisPeriodTotalKernelTime,
  237. new CVARIANT(llThisPeriodTotalKernelTime)));
  238. }
  239. if(dwReqProps & PROP_TotalPageFaultCount)
  240. {
  241. DWORD dwTotalPageFaultCount = jobaioai.BasicInfo.TotalPageFaultCount;
  242. m_PropMap.insert(SHORT2PVARIANT::value_type(
  243. JOIOACTGPROP_TotalPageFaultCount,
  244. new CVARIANT(dwTotalPageFaultCount)));
  245. }
  246. if(dwReqProps & PROP_TotalProcesses)
  247. {
  248. DWORD dwTotalProcesses = jobaioai.BasicInfo.TotalProcesses;
  249. m_PropMap.insert(SHORT2PVARIANT::value_type(
  250. JOIOACTGPROP_TotalProcesses,
  251. new CVARIANT(dwTotalProcesses)));
  252. }
  253. if(dwReqProps & PROP_ActiveProcesses)
  254. {
  255. DWORD dwActiveProcesses = jobaioai.BasicInfo.ActiveProcesses;
  256. m_PropMap.insert(SHORT2PVARIANT::value_type(
  257. JOIOACTGPROP_ActiveProcesses,
  258. new CVARIANT(dwActiveProcesses)));
  259. }
  260. if(dwReqProps & PROP_TotalTerminatedProcesses)
  261. {
  262. DWORD dwTotalTerminatedProcesses = jobaioai.BasicInfo.TotalTerminatedProcesses;
  263. m_PropMap.insert(SHORT2PVARIANT::value_type(
  264. JOIOACTGPROP_TotalTerminatedProcesses,
  265. new CVARIANT(dwTotalTerminatedProcesses)));
  266. }
  267. if(dwReqProps & PROP_ReadOperationCount)
  268. {
  269. ULONGLONG ullReadOperationCount = jobaioai.IoInfo.ReadOperationCount;
  270. m_PropMap.insert(SHORT2PVARIANT::value_type(
  271. JOIOACTGPROP_ReadOperationCount,
  272. new CVARIANT(ullReadOperationCount)));
  273. }
  274. if(dwReqProps & PROP_WriteOperationCount)
  275. {
  276. ULONGLONG ullWriteOperationCount = jobaioai.IoInfo.WriteOperationCount;
  277. m_PropMap.insert(SHORT2PVARIANT::value_type(
  278. JOIOACTGPROP_WriteOperationCount,
  279. new CVARIANT(ullWriteOperationCount)));
  280. }
  281. if(dwReqProps & PROP_OtherOperationCount)
  282. {
  283. ULONGLONG ullOtherOperationCount = jobaioai.IoInfo.OtherOperationCount;
  284. m_PropMap.insert(SHORT2PVARIANT::value_type(
  285. JOIOACTGPROP_OtherOperationCount,
  286. new CVARIANT(ullOtherOperationCount)));
  287. }
  288. if(dwReqProps & PROP_ReadTransferCount)
  289. {
  290. ULONGLONG ullReadTransferCount = jobaioai.IoInfo.ReadTransferCount;
  291. m_PropMap.insert(SHORT2PVARIANT::value_type(
  292. JOIOACTGPROP_ReadTransferCount,
  293. new CVARIANT(ullReadTransferCount)));
  294. }
  295. if(dwReqProps & PROP_WriteTransferCount)
  296. {
  297. ULONGLONG ullWriteTransferCount = jobaioai.IoInfo.WriteTransferCount;
  298. m_PropMap.insert(SHORT2PVARIANT::value_type(
  299. JOIOACTGPROP_WriteTransferCount,
  300. new CVARIANT(ullWriteTransferCount)));
  301. }
  302. if(dwReqProps & PROP_OtherTransferCount)
  303. {
  304. ULONGLONG ullOtherTransferCount = jobaioai.IoInfo.OtherTransferCount;
  305. m_PropMap.insert(SHORT2PVARIANT::value_type(
  306. JOIOACTGPROP_OtherTransferCount,
  307. new CVARIANT(ullOtherTransferCount)));
  308. }
  309. if(dwReqProps & PROP_PeakProcessMemoryUsed)
  310. {
  311. DWORD dwPeakProcessMemoryUsed = joeli.PeakProcessMemoryUsed;
  312. m_PropMap.insert(SHORT2PVARIANT::value_type(
  313. JOIOACTGPROP_PeakProcessMemoryUsed,
  314. new CVARIANT(dwPeakProcessMemoryUsed)));
  315. }
  316. if(dwReqProps & PROP_PeakJobMemoryUsed)
  317. {
  318. DWORD dwPeakJobMemoryUsed = joeli.PeakJobMemoryUsed;
  319. m_PropMap.insert(SHORT2PVARIANT::value_type(
  320. JOIOACTGPROP_PeakJobMemoryUsed,
  321. new CVARIANT(dwPeakJobMemoryUsed)));
  322. }
  323. }
  324. catch(CVARIANTError& cve)
  325. {
  326. hr = cve.GetWBEMError();
  327. }
  328. }
  329. }
  330. return hr;
  331. }
  332. HRESULT CJobObjIOActgProps::LoadPropertyValues(
  333. IWbemClassObject* pIWCO)
  334. {
  335. HRESULT hr = WBEM_S_NO_ERROR;
  336. if(!pIWCO) return E_POINTER;
  337. hr = CObjProps::LoadPropertyValues(
  338. g_rgJobObjIOActgPropNames,
  339. pIWCO);
  340. return hr;
  341. }