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.

740 lines
18 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. History:
  6. --*/
  7. //
  8. // CookerUtils.cpp
  9. //
  10. #include "precomp.h"
  11. #include <wbemint.h>
  12. #include "cookerutils.h"
  13. #include "strutils.h"
  14. #include <comdef.h>
  15. //////////////////////////////////////////////////////////////
  16. //
  17. //
  18. // Helper Functions
  19. //
  20. //
  21. //////////////////////////////////////////////////////////////
  22. BOOL IsCookingClass( IWbemClassObject* pCookingClassObject )
  23. {
  24. HRESULT hResult = WBEM_NO_ERROR;
  25. IWbemQualifierSet *pCookingClassQualifierSet = NULL;
  26. hResult = pCookingClassObject->GetQualifierSet( &pCookingClassQualifierSet );
  27. // Verify "AutoCook" qualifier
  28. // ===========================
  29. if ( SUCCEEDED( hResult ) )
  30. {
  31. CAutoRelease arQualifierSet( (IUnknown*)pCookingClassQualifierSet );
  32. _variant_t vVal;
  33. hResult = pCookingClassQualifierSet->Get( WMI_COOKER_AUTOCOOK_QUALIFIER, 0, &vVal, NULL );
  34. if ( SUCCEEDED( hResult ) )
  35. {
  36. if ( vVal.vt != VT_I4 )
  37. {
  38. hResult = WBEM_E_INVALID_QUALIFIER;
  39. }
  40. else
  41. {
  42. if (WMI_COOKER_VERSION != V_I4(&vVal))
  43. hResult = WBEM_E_INVALID_CLASS;
  44. }
  45. }
  46. }
  47. return SUCCEEDED( hResult );
  48. }
  49. // Table of the counter types and their Cooking type values
  50. struct _CookingTypeRec
  51. {
  52. DWORD dwType;
  53. WCHAR * wcsName;
  54. DWORD dwReqProp;
  55. }
  56. g_aCookingRecs[] =
  57. {
  58. 0x00000000, L"PERF_COUNTER_RAWCOUNT_HEX", REQ_1VALUE,
  59. // BEGIN COOKER_ONLY
  60. 0x00000001, L"COOKER_AVERAGE", REQ_2VALUE,
  61. 0x00000002, L"COOKER_MIN", REQ_2VALUE,
  62. 0x00000003, L"COOKER_MAX", REQ_2VALUE,
  63. 0x00000004, L"COOKER_RANGE", REQ_2VALUE,
  64. 0x00000005, L"COOKER_VARIANCE", REQ_2VALUE,
  65. // END COOKER_ONLY
  66. 0x00000100, L"PERF_COUNTER_LARGE_RAWCOUNT_HEX", REQ_1VALUE,
  67. 0x00000B00, L"PERF_COUNTER_TEXT", REQ_NONE,
  68. 0x00010000, L"PERF_COUNTER_RAWCOUNT", REQ_1VALUE,
  69. 0x00010100, L"PERF_COUNTER_LARGE_RAWCOUNT", REQ_1VALUE,
  70. 0x00012000, L"PERF_DOUBLE_RAW", REQ_1VALUE,
  71. 0x00400400, L"PERF_COUNTER_DELTA", REQ_2VALUE,
  72. 0x00400500, L"PERF_COUNTER_LARGE_DELTA", REQ_2VALUE,
  73. 0x00410400, L"PERF_SAMPLE_COUNTER", REQ_2VALUE|REQ_TIME|REQ_FREQ,
  74. 0x00450400, L"PERF_COUNTER_QUEUELEN_TYPE", REQ_2VALUE|REQ_TIME,
  75. 0x00450500, L"PERF_COUNTER_LARGE_QUEUELEN_TYPE", REQ_2VALUE|REQ_TIME,
  76. 0x00550500, L"PERF_COUNTER_100NS_QUEUELEN_TYPE", REQ_2VALUE|REQ_TIME,
  77. 0x00650500, L"PERF_COUNTER_OBJ_TIME_QUEUELEN_TYPE", REQ_2VALUE|REQ_TIME,
  78. 0x10410400, L"PERF_COUNTER_COUNTER", REQ_2VALUE|REQ_TIME|REQ_FREQ,
  79. 0x10410500, L"PERF_COUNTER_BULK_COUNT", REQ_2VALUE|REQ_TIME|REQ_FREQ,
  80. 0x20020400, L"PERF_RAW_FRACTION", REQ_1VALUE|REQ_BASE,
  81. 0x20410500, L"PERF_COUNTER_TIMER", REQ_2VALUE|REQ_TIME,
  82. 0x20470500, L"PERF_PRECISION_SYSTEM_TIMER", REQ_2VALUE|REQ_TIME,
  83. 0x20510500, L"PERF_100NSEC_TIMER", REQ_2VALUE|REQ_TIME,
  84. 0x20570500, L"PERF_PRECISION_100NS_TIMER", REQ_2VALUE|REQ_TIME,
  85. 0x20610500, L"PERF_OBJ_TIME_TIMER", REQ_2VALUE|REQ_TIME,
  86. 0x20670500, L"PERF_PRECISION_OBJECT_TIMER", REQ_2VALUE|REQ_TIME,
  87. 0x20C20400, L"PERF_SAMPLE_FRACTION", REQ_2VALUE|REQ_BASE,
  88. 0x21410500, L"PERF_COUNTER_TIMER_INV", REQ_2VALUE|REQ_TIME,
  89. 0x21510500, L"PERF_100NSEC_TIMER_INV", REQ_2VALUE|REQ_TIME,
  90. 0x22410500, L"PERF_COUNTER_MULTI_TIMER", REQ_2VALUE|REQ_TIME,
  91. 0x22510500, L"PERF_100NSEC_MULTI_TIMER", REQ_2VALUE|REQ_TIME,
  92. 0x23410500, L"PERF_COUNTER_MULTI_TIMER_INV", REQ_2VALUE|REQ_TIME,
  93. 0x23510500, L"PERF_100NSEC_MULTI_TIMER_INV", REQ_2VALUE|REQ_TIME,
  94. 0x30020400, L"PERF_AVERAGE_TIMER", REQ_2VALUE|REQ_BASE|REQ_FREQ,
  95. 0x30240500, L"PERF_ELAPSED_TIME", REQ_1VALUE|REQ_TIME|REQ_FREQ,
  96. 0x40000200, L"PERF_COUNTER_NODATA", REQ_NONE,
  97. 0x40020500, L"PERF_AVERAGE_BULK", REQ_2VALUE|REQ_BASE,
  98. 0x40030401, L"PERF_SAMPLE_BASE", REQ_NONE,
  99. 0x40030402, L"PERF_AVERAGE_BASE", REQ_NONE,
  100. 0x40030403, L"PERF_RAW_BASE", REQ_NONE,
  101. 0x40030500, L"PERF_PRECISION_TIMESTAMP", REQ_NONE,
  102. 0x40030503, L"PERF_LARGE_RAW_BASE", REQ_NONE,
  103. 0x42030500, L"PERF_COUNTER_MULTI_BASE", REQ_NONE,
  104. 0x80000000, L"PERF_COUNTER_HISTOGRAM_TYPE", REQ_NONE,
  105. };
  106. HRESULT FindCounterType( WCHAR* pwcsString, DWORD* pdwType, DWORD *pdwReqProp)
  107. {
  108. HRESULT hRes = WBEM_S_NO_ERROR;
  109. DWORD dwLeft = 0,
  110. dwRight = sizeof( g_aCookingRecs ) / sizeof( _CookingTypeRec );
  111. while ( ( dwLeft < dwRight ) && SUCCEEDED( hRes ) )
  112. {
  113. // Found it
  114. if ( wbem_wcsicmp( g_aCookingRecs[dwLeft].wcsName, pwcsString ) == 0 )
  115. {
  116. *pdwType = g_aCookingRecs[dwLeft].dwType;
  117. *pdwReqProp = g_aCookingRecs[dwLeft].dwReqProp;
  118. break;
  119. }
  120. dwLeft++;
  121. }
  122. if ( dwLeft >= dwRight )
  123. {
  124. hRes = WBEM_E_NOT_FOUND;
  125. }
  126. return hRes;
  127. }
  128. BOOL IsSingleton(IWbemClassObject * pCls){
  129. HRESULT hr;
  130. if (pCls){
  131. IWbemQualifierSet * pQS = NULL;
  132. hr = pCls->GetQualifierSet(&pQS);
  133. CAutoRelease rm1(pQS);
  134. if (SUCCEEDED(hr)){
  135. _variant_t VarBool;
  136. hr = pQS->Get(L"singleton",0,&VarBool,NULL);
  137. if (SUCCEEDED(hr) &&
  138. VarBool.vt == VT_BOOL &&
  139. V_BOOL(&VarBool) == VARIANT_TRUE){
  140. return TRUE;
  141. }
  142. }
  143. };
  144. return FALSE;
  145. }
  146. //
  147. // returns TRUE if the property qualifier set has the CookingType
  148. // qualifier and if the CookingType is recognized
  149. //
  150. ///////////////////////////////////////////////////////////////////
  151. BOOL IsCookingProperty( BSTR strPropName, IWbemClassObject* pCookingClassObject, DWORD* pdwCounterType, DWORD * pdwReqProp )
  152. {
  153. HRESULT hResult = WBEM_NO_ERROR;
  154. IWbemQualifierSet* pPropQualSet = NULL;
  155. _variant_t vVal;
  156. hResult = pCookingClassObject->GetPropertyQualifierSet( (LPCWSTR)strPropName, &pPropQualSet );
  157. if ( SUCCEEDED( hResult ) )
  158. {
  159. CAutoRelease arPropQualSet( (IUnknown*)pPropQualSet );
  160. hResult = pPropQualSet->Get( WMI_COOKER_COOKING_PROPERTY_ATTRIBUTE, 0, &vVal, NULL );
  161. if ( SUCCEEDED ( hResult ) )
  162. {
  163. if ( vVal.vt == VT_BSTR )
  164. {
  165. hResult = FindCounterType( V_BSTR( &vVal ), pdwCounterType, pdwReqProp );
  166. }
  167. else
  168. {
  169. hResult = E_FAIL;
  170. }
  171. }
  172. }
  173. return SUCCEEDED( hResult );
  174. }
  175. LPWSTR GetKey( IWbemObjectAccess* pObj )
  176. ///////////////////////////////////////////////////////////////////////////////
  177. //
  178. //
  179. //
  180. // Parameters:
  181. //
  182. //
  183. ///////////////////////////////////////////////////////////////////////////////
  184. {
  185. WMISTATUS dwStatus = WBEM_NO_ERROR;
  186. IWbemClassObject* pClassObj = NULL;
  187. LPWSTR wszKeyName = NULL;
  188. LPWSTR wszTempKeyPtr = NULL;
  189. _variant_t var;
  190. pObj->QueryInterface( IID_IWbemClassObject, (void**)&pClassObj );
  191. CAutoRelease arClassObj( pClassObj );
  192. dwStatus = pClassObj->Get( L"__RELPATH", 0, &var, NULL, NULL );
  193. if ( SUCCEEDED( dwStatus ) )
  194. {
  195. if ( var.vt != VT_BSTR )
  196. {
  197. dwStatus = WBEM_E_FAILED;
  198. }
  199. else
  200. {
  201. wszTempKeyPtr = wcsstr( var.bstrVal, L"=" );
  202. wszTempKeyPtr++;
  203. wszKeyName = new WCHAR[ wcslen( wszTempKeyPtr ) + 1 ];
  204. wcscpy( wszKeyName, wszTempKeyPtr );
  205. }
  206. }
  207. return wszKeyName;
  208. }
  209. WMISTATUS CopyBlob( _IWmiObject* pIntSource, _IWmiObject* pIntTarget )
  210. {
  211. WMISTATUS dwStatus = WBEM_NO_ERROR;
  212. dwStatus = pIntTarget->CopyInstanceData( 0L, pIntSource );
  213. return dwStatus;
  214. }
  215. WMISTATUS CopyBlob( IWbemClassObject* pSource, IWbemClassObject* pTarget )
  216. {
  217. HRESULT dwStatus = E_NOINTERFACE ;
  218. HRESULT hr1,hr2;
  219. _IWmiObject* pIntTarget = NULL;
  220. _IWmiObject* pIntSource = NULL;
  221. hr1 = pTarget->QueryInterface( IID__IWmiObject, (void**)&pIntTarget );
  222. CAutoRelease arIntTarget( pIntTarget );
  223. hr2 = pSource->QueryInterface( IID__IWmiObject, (void**)&pIntSource );
  224. CAutoRelease arIntSource( pIntSource );
  225. if ( SUCCEEDED(hr1) && SUCCEEDED(hr2) )
  226. {
  227. dwStatus = CopyBlob( pIntSource, pIntTarget );
  228. }
  229. return dwStatus;
  230. }
  231. WMISTATUS CloneAccess(IWbemObjectAccess* pOriginal, IWbemObjectAccess** ppClone)
  232. //////////////////////////////////////////////////////////////
  233. //
  234. // Returns a IWbemObjectAccess clone of an IWbemObjectAccess
  235. // object.
  236. //
  237. // Parameters:
  238. // pOriginal - the original object
  239. // ppClone - the cloned object
  240. //
  241. //////////////////////////////////////////////////////////////
  242. //ok
  243. {
  244. WMISTATUS dwStatus = WBEM_NO_ERROR;
  245. IWbemClassObject* pOurClassObj = NULL;
  246. IWbemClassObject* pClonedClassObj = NULL;
  247. IWbemObjectAccess* pClonedAccessObj = NULL;
  248. // Get the IWbemClassObject interface for the object
  249. // =================================================
  250. dwStatus = pOriginal->QueryInterface(IID_IWbemClassObject, (PVOID*)&pOurClassObj);
  251. if ( SUCCEEDED( dwStatus ) )
  252. {
  253. // Clone the object
  254. // ================
  255. dwStatus = pOurClassObj->Clone(&pClonedClassObj);
  256. pOurClassObj->Release();
  257. }
  258. if ( SUCCEEDED( dwStatus ) )
  259. {
  260. // Get the IWbemObjectAccess interface for the cloned object
  261. // =========================================================
  262. dwStatus = pClonedClassObj->QueryInterface(IID_IWbemObjectAccess, (PVOID*)&pClonedAccessObj);
  263. pClonedClassObj->Release();
  264. }
  265. if ( SUCCEEDED( dwStatus ) )
  266. {
  267. // Copy the cloned object into the returned parameter (refcount == 1)
  268. // ==================================================================
  269. *ppClone = pClonedAccessObj;
  270. }
  271. return dwStatus;
  272. }
  273. BOOL IsHiPerfObj(IWbemObjectAccess* pObject){
  274. HRESULT hr;
  275. _variant_t Var;
  276. hr = pObject->Get(L"__SUPERCLASS",0,&Var,NULL,NULL);
  277. if (SUCCEEDED(hr))
  278. {
  279. if (Var.vt == VT_BSTR) {
  280. hr = (0 == _wcsicmp(Var.bstrVal,L"Win32_PerfFormattedData"))?S_OK:E_FAIL;
  281. } else {
  282. hr = E_FAIL;
  283. }
  284. }
  285. return SUCCEEDED(hr);
  286. }
  287. BOOL IsHiPerf( IWbemObjectAccess* pObject )
  288. {
  289. WMISTATUS hr = WBEM_NO_ERROR;
  290. IWbemQualifierSet* pQualSet = NULL;
  291. hr = pObject->GetQualifierSet( &pQualSet );
  292. CAutoRelease arQualSet( pQualSet );
  293. // Verify the "Hiperf" class qualifier
  294. // ===================================
  295. if (SUCCEEDED(hr))
  296. {
  297. _variant_t var;
  298. hr = pQualSet->Get( WMI_COOKER_HIPERF_QUALIFIER, 0, &var, NULL );
  299. if ( SUCCEEDED(hr) && ( ( var.vt != VT_BOOL ) || ( var.boolVal != VARIANT_TRUE ) ) )
  300. {
  301. hr = WBEM_E_INVALID_QUALIFIER;
  302. }
  303. }
  304. // Verify the "Cooked" class qualifier
  305. // ===================================
  306. if (SUCCEEDED(hr))
  307. {
  308. _variant_t var;
  309. hr = pQualSet->Get( WMI_COOKER_COOKING_QUALIFIER, 0, &var, NULL );
  310. if ( SUCCEEDED(hr) && ( ( var.vt != VT_BOOL ) || ( var.boolVal != VARIANT_TRUE ) ) )
  311. {
  312. hr = WBEM_E_INVALID_QUALIFIER;
  313. }
  314. }
  315. // Verify the "AutoCook" class qualifier
  316. // =====================================
  317. if (SUCCEEDED(hr))
  318. {
  319. _variant_t var;
  320. hr = pQualSet->Get( WMI_COOKER_AUTOCOOK_QUALIFIER, 0, &var, NULL );
  321. if (SUCCEEDED(hr))
  322. {
  323. if ( var.vt != VT_I4 )
  324. {
  325. hr = WBEM_E_INVALID_QUALIFIER;
  326. }
  327. else
  328. {
  329. if (WMI_COOKER_VERSION != V_I4(&var))
  330. hr = WBEM_E_INVALID_CLASS;
  331. }
  332. }
  333. }
  334. // Verify the "AutoCook_RawClass" class qualifier
  335. // ==============================================
  336. if (SUCCEEDED(hr))
  337. {
  338. _variant_t var;
  339. hr = pQualSet->Get( WMI_COOKER_RAWCLASS_QUALIFIER, 0, &var, NULL );
  340. if ( SUCCEEDED(hr) && ( var.vt != VT_BSTR ) )
  341. {
  342. hr = WBEM_E_INVALID_QUALIFIER;
  343. }
  344. }
  345. // verify the "AutoCook_RawDeafult" class qualifier if there
  346. // ==========================================================
  347. if (SUCCEEDED(hr))
  348. {
  349. _variant_t var;
  350. hr = pQualSet->Get( WMI_COOKER_AUTOCOOK_RAWDEFAULT, 0, &var, NULL );
  351. if ( SUCCEEDED(hr) )
  352. {
  353. if ((var.vt != VT_I4) ||
  354. (V_I4(&var) != AUTOCOOK_RAWDEFAULT_CURRENT_ACCEPTED))
  355. {
  356. hr = WBEM_E_INVALID_QUALIFIER;
  357. }
  358. else // good qualifier, see the properties
  359. {
  360. HRESULT hr1 = pObject->Get(WMI_COOKER_REQ_TIMESTAMP_PERFTIME,0,NULL,NULL,NULL);
  361. HRESULT hr2 = pObject->Get(WMI_COOKER_REQ_TIMESTAMP_SYS100NS,0,NULL,NULL,NULL);
  362. HRESULT hr3 = pObject->Get(WMI_COOKER_REQ_TIMESTAMP_OBJECT ,0,NULL,NULL,NULL);
  363. HRESULT hr4 = pObject->Get(WMI_COOKER_REQ_FREQUENCY_PERFTIME,0,NULL,NULL,NULL);
  364. HRESULT hr5 = pObject->Get(WMI_COOKER_REQ_FREQUENCY_SYS100NS,0,NULL,NULL,NULL);
  365. HRESULT hr6 = pObject->Get(WMI_COOKER_REQ_FREQUENCY_OBJECT ,0,NULL,NULL,NULL);
  366. if (SUCCEEDED(hr1) &&
  367. SUCCEEDED(hr2) &&
  368. SUCCEEDED(hr3) &&
  369. SUCCEEDED(hr4) &&
  370. SUCCEEDED(hr5) &&
  371. SUCCEEDED(hr6))
  372. {
  373. // ok
  374. }
  375. else
  376. {
  377. hr = WBEM_E_INVALID_CLASS;
  378. }
  379. }
  380. }
  381. else
  382. {
  383. // this qualifier is optional
  384. hr = WBEM_NO_ERROR;
  385. }
  386. }
  387. return SUCCEEDED(hr);
  388. }
  389. BOOL IsHiPerf( IWbemServices* pNamespace, LPCWSTR wszObject )
  390. {
  391. IWbemClassObject* pObject = NULL;
  392. // Get the WMI object
  393. BSTR strObject = SysAllocString(wszObject);
  394. if (!strObject)
  395. {
  396. return FALSE;
  397. }
  398. CAutoFree fme(strObject);
  399. HRESULT hr = pNamespace->GetObject( strObject, 0, NULL, &pObject, NULL );
  400. CAutoRelease arObject( pObject );
  401. if (SUCCEEDED(hr)) {
  402. IWbemQualifierSet* pQualSet = NULL;
  403. hr = pObject->GetQualifierSet( &pQualSet );
  404. CAutoRelease arQualSet( pQualSet );
  405. // Verify the "Hiperf" class qualifier
  406. if ( SUCCEEDED(hr) ){
  407. _variant_t var;
  408. hr = pQualSet->Get( WMI_COOKER_HIPERF_QUALIFIER, 0, &var, NULL );
  409. if ( SUCCEEDED(hr) &&
  410. ( (var.vt != VT_BOOL) ||
  411. (var.boolVal != VARIANT_TRUE)) ){
  412. hr = WBEM_E_INVALID_QUALIFIER;
  413. }
  414. }
  415. // Verify the "Cooked" class qualifier
  416. if ( SUCCEEDED(hr) ){
  417. _variant_t var;
  418. hr = pQualSet->Get( WMI_COOKER_COOKING_QUALIFIER, 0, &var, NULL );
  419. if ( SUCCEEDED(hr) &&
  420. ( (var.vt != VT_BOOL) ||
  421. (var.boolVal != VARIANT_TRUE)) ){
  422. hr = WBEM_E_INVALID_QUALIFIER;
  423. }
  424. }
  425. // Verify the "AutoCook" class qualifier
  426. if ( SUCCEEDED(hr) ){
  427. _variant_t var;
  428. hr = pQualSet->Get( WMI_COOKER_AUTOCOOK_QUALIFIER, 0, &var, NULL );
  429. if ( SUCCEEDED(hr) )
  430. {
  431. if (var.vt != VT_I4 )
  432. {
  433. hr = WBEM_E_INVALID_QUALIFIER;
  434. }
  435. else
  436. {
  437. if (WMI_COOKER_VERSION != V_I4(&var))
  438. hr = WBEM_E_INVALID_CLASS;
  439. }
  440. }
  441. }
  442. // Verify the "AutoCook_RawClass" class qualifier
  443. // ==============================================
  444. if ( SUCCEEDED(hr) )
  445. {
  446. _variant_t varRawClass;
  447. hr = pQualSet->Get( WMI_COOKER_RAWCLASS_QUALIFIER, 0, &varRawClass, NULL );
  448. if ( SUCCEEDED(hr) )
  449. {
  450. if ( varRawClass.vt == VT_BSTR )
  451. {
  452. IWbemClassObject * pRawClass = NULL;
  453. hr = pNamespace->GetObject(V_BSTR(&varRawClass),0,NULL,&pRawClass,NULL);
  454. CAutoRelease rm1(pRawClass);
  455. if (SUCCEEDED(hr)){
  456. IWbemQualifierSet * pQS = NULL;
  457. hr = pRawClass->GetQualifierSet(&pQS);
  458. CAutoRelease rm2(pQS);
  459. if (SUCCEEDED(hr)){
  460. // verify the hiperf qualifier on the RAW class
  461. _variant_t varH;
  462. hr = pQS->Get(WMI_COOKER_HIPERF_QUALIFIER, 0, &varH, NULL);
  463. if ( SUCCEEDED(hr) &&
  464. ( (varH.vt != VT_BOOL) ||
  465. (varH.boolVal != VARIANT_TRUE)) ){
  466. hr = WBEM_E_INVALID_QUALIFIER;
  467. };
  468. }
  469. } else {
  470. hr = WBEM_E_INVALID_CLASS;
  471. }
  472. } else {
  473. hr = WBEM_E_INVALID_QUALIFIER;
  474. }
  475. }
  476. }
  477. // verify the "AutoCook_RawDeafult" class qualifier if there
  478. // ==========================================================
  479. if ( SUCCEEDED(hr) ){
  480. _variant_t var;
  481. hr = pQualSet->Get( WMI_COOKER_AUTOCOOK_RAWDEFAULT, 0, &var, NULL );
  482. if ( SUCCEEDED(hr) )
  483. {
  484. if ((var.vt != VT_I4) ||
  485. (V_I4(&var) != AUTOCOOK_RAWDEFAULT_CURRENT_ACCEPTED))
  486. {
  487. hr = WBEM_E_INVALID_QUALIFIER;
  488. }
  489. else // good qualifier, see the properties
  490. {
  491. HRESULT hr1 = pObject->Get(WMI_COOKER_REQ_TIMESTAMP_PERFTIME,0,NULL,NULL,NULL);
  492. HRESULT hr2 = pObject->Get(WMI_COOKER_REQ_TIMESTAMP_SYS100NS,0,NULL,NULL,NULL);
  493. HRESULT hr3 = pObject->Get(WMI_COOKER_REQ_TIMESTAMP_OBJECT ,0,NULL,NULL,NULL);
  494. HRESULT hr4 = pObject->Get(WMI_COOKER_REQ_FREQUENCY_PERFTIME,0,NULL,NULL,NULL);
  495. HRESULT hr5 = pObject->Get(WMI_COOKER_REQ_FREQUENCY_SYS100NS,0,NULL,NULL,NULL);
  496. HRESULT hr6 = pObject->Get(WMI_COOKER_REQ_FREQUENCY_OBJECT ,0,NULL,NULL,NULL);
  497. if (SUCCEEDED(hr1) &&
  498. SUCCEEDED(hr2) &&
  499. SUCCEEDED(hr3) &&
  500. SUCCEEDED(hr4) &&
  501. SUCCEEDED(hr5) &&
  502. SUCCEEDED(hr6))
  503. {
  504. // ok
  505. }
  506. else
  507. {
  508. hr = WBEM_E_INVALID_CLASS;
  509. }
  510. }
  511. }
  512. else
  513. {
  514. // this qualifier is optional
  515. hr = WBEM_NO_ERROR;
  516. }
  517. }
  518. return SUCCEEDED(hr);
  519. }
  520. return FALSE;
  521. }
  522. WMISTATUS GetRawClassName( IWbemClassObject* pCookingInst, WCHAR** pwszRawClassName )
  523. {
  524. WMISTATUS dwStatus = WBEM_NO_ERROR;
  525. IWbemQualifierSet* pQualSet = NULL; // The Instance qualifier set
  526. _variant_t varRawInstName; // The raw instance name
  527. dwStatus = pCookingInst->GetQualifierSet( &pQualSet );
  528. CAutoRelease adQualSet( pQualSet );
  529. if ( SUCCEEDED( dwStatus ) )
  530. {
  531. dwStatus = pQualSet->Get( WMI_COOKER_RAWCLASS_QUALIFIER, 0, &varRawInstName, NULL );
  532. if ( SUCCEEDED( dwStatus ) )
  533. {
  534. if ( VT_BSTR == varRawInstName.vt )
  535. {
  536. // TODO: Is there a more efficient way to pass back the string value than a strcpy?
  537. // ================================================================================
  538. WCHAR* wszRawClassName = new WCHAR[wcslen( varRawInstName.bstrVal ) + 1];
  539. if ( NULL != wszRawClassName )
  540. {
  541. wcscpy( wszRawClassName, varRawInstName.bstrVal );
  542. *pwszRawClassName = wszRawClassName;
  543. }
  544. else
  545. {
  546. dwStatus = WBEM_E_OUT_OF_MEMORY;
  547. }
  548. }
  549. else
  550. {
  551. dwStatus = WBEM_E_TYPE_MISMATCH;
  552. }
  553. }
  554. }
  555. return dwStatus;
  556. }
  557. WMISTATUS GetClassName( IWbemObjectAccess* pAccess, WCHAR** pwszClassName )
  558. {
  559. WMISTATUS dwStatus = WBEM_NO_ERROR;
  560. IWbemClassObject* pObject = NULL;
  561. _variant_t vVal;
  562. dwStatus = pAccess->QueryInterface( IID_IWbemClassObject, (void**)&pObject );
  563. CAutoRelease ar(pObject);
  564. if ( SUCCEEDED( dwStatus ) )
  565. {
  566. dwStatus = pObject->Get(L"__CLASS", 0, &vVal, NULL, NULL );
  567. if ( vVal.vt != VT_BSTR )
  568. {
  569. dwStatus = E_FAIL;
  570. }
  571. if ( SUCCEEDED( dwStatus ) )
  572. {
  573. WCHAR* wszClassName = new WCHAR[ wcslen( vVal.bstrVal ) + 1 ];
  574. if ( NULL != wszClassName )
  575. {
  576. wcscpy( wszClassName, vVal.bstrVal );
  577. *pwszClassName = wszClassName;
  578. }
  579. else
  580. {
  581. dwStatus = WBEM_E_OUT_OF_MEMORY;
  582. }
  583. }
  584. }
  585. return dwStatus;
  586. }