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.

2489 lines
64 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright � Microsoft Corporation. All rights reserved.
  4. //
  5. // Instance.CPP
  6. //
  7. // Purpose: Implementation of CInstance class
  8. //
  9. //***************************************************************************
  10. #include "precomp.h"
  11. #include <BrodCast.h>
  12. #include <assertbreak.h>
  13. #include <stopwatch.h>
  14. #include "FWStrings.h"
  15. #define DEPRECATED 1
  16. ////////////////////////////////////////////////////////////////////////
  17. //
  18. // Function: CInstance ctor
  19. //
  20. //
  21. //
  22. // Inputs: IWbemClassObject* - the class we want to wrap
  23. // MethodContext* - since the context is shared, this will be addreffed
  24. // Outputs:
  25. //
  26. // Return:
  27. //
  28. // Comments: pointers should not be NULL
  29. //
  30. ////////////////////////////////////////////////////////////////////////
  31. CInstance::CInstance(IWbemClassObject* piClassObject, MethodContext* pMethodContext)
  32. : m_nRefCount( 1 )
  33. {
  34. ASSERT_BREAK(piClassObject != NULL);
  35. ASSERT_BREAK(pMethodContext != NULL);
  36. // Both these values will be released in the destructor, so they both oughta
  37. // be AddRefed. Note that they are
  38. m_piClassObject = piClassObject;
  39. if ( NULL != piClassObject )
  40. { // this, however, is a copy
  41. m_piClassObject->AddRef();
  42. }
  43. m_pMethodContext = pMethodContext;
  44. if (pMethodContext)
  45. { // this, however, is a copy
  46. m_pMethodContext->AddRef();
  47. }
  48. }
  49. ////////////////////////////////////////////////////////////////////////
  50. //
  51. // Function: CInstance Dtor
  52. //
  53. //
  54. //
  55. // Inputs:
  56. //
  57. // Outputs:
  58. //
  59. // Return:
  60. //
  61. // Comments:
  62. //
  63. ////////////////////////////////////////////////////////////////////////
  64. CInstance::~CInstance()
  65. {
  66. if ( NULL != m_piClassObject )
  67. {
  68. m_piClassObject->Release();
  69. }
  70. if ( NULL != m_pMethodContext )
  71. {
  72. m_pMethodContext->Release();
  73. }
  74. }
  75. ////////////////////////////////////////////////////////////////////////
  76. //
  77. // Function: CInstance::AddRef
  78. //
  79. // Increments our reference count.
  80. //
  81. // Inputs: None.
  82. //
  83. // Outputs: None.
  84. //
  85. // Return: New Reference Count.
  86. //
  87. // Comments: We may want to go to an Interlocked Inc/Dec model at
  88. // some point if Thread Safety on these objects becomes
  89. // an issue.
  90. //
  91. ////////////////////////////////////////////////////////////////////////
  92. LONG CInstance::AddRef( void )
  93. {
  94. return InterlockedIncrement(&m_nRefCount);
  95. }
  96. ////////////////////////////////////////////////////////////////////////
  97. //
  98. // Function: CInstance::Release
  99. //
  100. // Decrements our reference count.
  101. //
  102. // Inputs: None.
  103. //
  104. // Outputs: None.
  105. //
  106. // Return: New Reference Count.
  107. //
  108. // Comments: Deletes the object when the ref count hits 0. We may
  109. // want to go to an Interlocked Inc/Dec model at some
  110. // point if Thread Safety on these objects becomes an issue.
  111. //
  112. ////////////////////////////////////////////////////////////////////////
  113. LONG CInstance::Release( void )
  114. {
  115. LONG nRet = InterlockedDecrement(&m_nRefCount);
  116. ASSERT_BREAK(nRet >= 0);
  117. if ( 0 == nRet )
  118. {
  119. delete this;
  120. }
  121. else if (nRet < 0)
  122. {
  123. // Duplicate release. Let's try to dump the stack
  124. DWORD t_stack[32] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  126. #ifdef _X86_
  127. DWORD *dwEBP;
  128. _asm {
  129. mov dwEBP, ebp
  130. }
  131. dwEBP += 1;
  132. memcpy(&t_stack, dwEBP, sizeof(t_stack));
  133. #endif
  134. CHString sMsg;
  135. sMsg.Format(L"Duplicate release: %08x %08x %08x %08x %08x %08x %08x %08x "
  136. L"%08x %08x %08x %08x %08x %08x %08x %08x "
  137. L"%08x %08x %08x %08x %08x %08x %08x %08x "
  138. L"%08x %08x %08x %08x %08x %08x %08x %08x ",
  139. t_stack[0], t_stack[1], t_stack[2], t_stack[3],
  140. t_stack[4], t_stack[5], t_stack[6], t_stack[7],
  141. t_stack[8], t_stack[9], t_stack[10], t_stack[11],
  142. t_stack[12], t_stack[13], t_stack[14], t_stack[15],
  143. t_stack[16], t_stack[17], t_stack[18], t_stack[19],
  144. t_stack[20], t_stack[21], t_stack[22], t_stack[23],
  145. t_stack[24], t_stack[25], t_stack[26], t_stack[27],
  146. t_stack[28], t_stack[29], t_stack[30], t_stack[31]
  147. );
  148. LogErrorMessage(sMsg);
  149. }
  150. return nRet;
  151. }
  152. ////////////////////////////////////////////////////////////////////////
  153. //
  154. // Function: Commit
  155. //
  156. // returns this CInstance to CIMOM
  157. // will stuff it into the cache someday
  158. // Inputs:
  159. //
  160. // Outputs:
  161. //
  162. // Return:
  163. //
  164. // Comments:
  165. //
  166. ////////////////////////////////////////////////////////////////////////
  167. HRESULT CInstance::Commit(void)
  168. {
  169. return m_pMethodContext->Commit( this );
  170. }
  171. IWbemClassObject* CInstance::GetClassObjectInterface()
  172. {
  173. m_piClassObject->AddRef();
  174. return m_piClassObject;
  175. }
  176. // reference counting //
  177. // string support //
  178. ////////////////////////////////////////////////////////////////////////
  179. //
  180. // Function: Set
  181. //
  182. //
  183. //
  184. // Inputs: Name of property to set
  185. // string to be set
  186. //
  187. // Outputs:
  188. //
  189. // Return: false if you try to set a property that is not a string type
  190. //
  191. // Comments:
  192. //
  193. ////////////////////////////////////////////////////////////////////////
  194. bool CInstance::SetWCHARSplat( LPCWSTR name, LPCWSTR pStr)
  195. {
  196. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  197. bool bRet = false;
  198. DWORD dwLastErr = 0;
  199. ASSERT_BREAK(name != NULL);
  200. if (m_piClassObject && name)
  201. {
  202. // Variant_t handles the VariantInit/VariantClear
  203. variant_t v(pStr);
  204. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  205. HRESULT hr = m_piClassObject->Put(name, 0, &v, NULL);
  206. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  207. ASSERT_BREAK(SUCCEEDED(hr));
  208. bRet = (bool)SUCCEEDED(hr);
  209. if (!bRet)
  210. {
  211. dwLastErr = (hr);
  212. LogError(IDS_FAILED, IDS_SETCHSTRING, name, hr);
  213. }
  214. }
  215. else
  216. {
  217. if (m_piClassObject)
  218. {
  219. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  220. LogError(IDS_InParam, IDS_SETCHSTRING);
  221. }
  222. else
  223. {
  224. dwLastErr = (WBEM_E_FAILED);
  225. LogError(IDS_NOCLASS, IDS_SETCHSTRING);
  226. }
  227. }
  228. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  229. SetLastError(dwLastErr);
  230. return bRet;
  231. }
  232. ////////////////////////////////////////////////////////////////////////
  233. //
  234. // Function: Set
  235. //
  236. //
  237. //
  238. // Inputs: Name of property to set to VT_NULL
  239. //
  240. // Outputs:
  241. //
  242. // Return: false if you try to set a property that is not a string type
  243. //
  244. // Comments:
  245. //
  246. ////////////////////////////////////////////////////////////////////////
  247. bool CInstance::SetNull(LPCWSTR name)
  248. {
  249. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  250. bool bRet = false;
  251. DWORD dwLastErr = 0;
  252. ASSERT_BREAK(name != NULL);
  253. if (m_piClassObject && name)
  254. {
  255. // Variant_t handles the VariantInit/VariantClear
  256. variant_t v;
  257. v.vt = VT_NULL ;
  258. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  259. HRESULT hr = m_piClassObject->Put(name, 0, &v, NULL);
  260. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  261. ASSERT_BREAK(SUCCEEDED(hr));
  262. bRet = (bool)SUCCEEDED(hr);
  263. if (!bRet)
  264. {
  265. dwLastErr = (hr);
  266. LogError(IDS_FAILED, IDS_SETCHSTRING, name, hr);
  267. }
  268. }
  269. else
  270. {
  271. if (m_piClassObject)
  272. {
  273. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  274. LogError(IDS_InParam, IDS_SETCHSTRING);
  275. }
  276. else
  277. {
  278. dwLastErr = (WBEM_E_FAILED);
  279. LogError(IDS_NOCLASS, IDS_SETCHSTRING);
  280. }
  281. }
  282. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  283. SetLastError(dwLastErr);
  284. return bRet;
  285. }
  286. ////////////////////////////////////////////////////////////////////////
  287. //
  288. // Function: SetStringArray
  289. //
  290. //
  291. //
  292. // Inputs: Name of property to set
  293. // string to be set
  294. //
  295. // Outputs:
  296. //
  297. // Return: false if you try to set a property that is not a string array type
  298. //
  299. // Comments:
  300. //
  301. ////////////////////////////////////////////////////////////////////////
  302. bool CInstance::SetStringArray(LPCWSTR name, const SAFEARRAY &strArray)
  303. {
  304. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  305. bool bRet = false;
  306. DWORD dwLastErr = 0;
  307. ASSERT_BREAK(name != NULL);
  308. if (m_piClassObject && name)
  309. {
  310. SAFEARRAY *t_SafeArray = NULL;
  311. HRESULT hr = SafeArrayCopy ( ( SAFEARRAY * ) & strArray , &t_SafeArray );
  312. if ( SUCCEEDED ( hr ) )
  313. {
  314. // Variant_t handles the VariantInit/VariantClear
  315. variant_t v;
  316. v.vt = VT_BSTR | VT_ARRAY ;
  317. v.parray = t_SafeArray ;
  318. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  319. HRESULT hr = m_piClassObject->Put(name, 0, &v, NULL);
  320. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  321. ASSERT_BREAK(SUCCEEDED(hr));
  322. bRet = (bool)SUCCEEDED(hr);
  323. if (!bRet)
  324. {
  325. dwLastErr = (hr);
  326. LogError(IDS_FAILED, IDS_SetStringArray, name, hr);
  327. }
  328. }
  329. else
  330. {
  331. throw CHeap_Exception ( CHeap_Exception :: E_ALLOCATION_ERROR ) ;
  332. }
  333. }
  334. else
  335. {
  336. if (m_piClassObject)
  337. {
  338. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  339. LogError(IDS_InParam, IDS_SetStringArray);
  340. }
  341. else
  342. {
  343. dwLastErr = (WBEM_E_FAILED);
  344. LogError(IDS_NOCLASS, IDS_SetStringArray);
  345. }
  346. }
  347. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  348. SetLastError(dwLastErr);
  349. return bRet;
  350. }
  351. ////////////////////////////////////////////////////////////////////////
  352. //
  353. // Function: Get (CHString)
  354. //
  355. //
  356. //
  357. // Inputs: Name of property to retrieve
  358. // CHString buffer to receive value
  359. // Outputs:
  360. //
  361. // Return: false if you try to get a property that is not a string compatible type
  362. //
  363. // Comments:
  364. //
  365. ////////////////////////////////////////////////////////////////////////
  366. bool CInstance::GetCHString(LPCWSTR name, CHString& str) const
  367. {
  368. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  369. bool bRet = false;
  370. DWORD dwLastErr = 0;
  371. ASSERT_BREAK(name != NULL);
  372. if (m_piClassObject && name)
  373. {
  374. // Variant_t handles the VariantInit/VariantClear
  375. variant_t v;
  376. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  377. HRESULT hr = m_piClassObject->Get(name, 0, &v, NULL, NULL);
  378. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  379. // If bSuccess is TRUE, we don't need to log an error. This keeps Gets on
  380. // null properties from logging an error.
  381. BOOL bSuccess = SUCCEEDED(hr) && (v.vt == VT_BSTR || v.vt == VT_NULL);
  382. ASSERT_BREAK(bSuccess);
  383. if (SUCCEEDED(hr))
  384. {
  385. if ((v.vt == VT_BSTR) && (v.bstrVal != NULL))
  386. {
  387. str = v.bstrVal;
  388. bRet = true;
  389. }
  390. else
  391. {
  392. dwLastErr = (WBEM_S_NO_MORE_DATA);
  393. }
  394. }
  395. if (!bSuccess)
  396. {
  397. if (SUCCEEDED(hr))
  398. {
  399. hr = WBEM_E_TYPE_MISMATCH;
  400. }
  401. dwLastErr = (hr);
  402. LogError(IDS_FAILED, IDS_GETCHSTRING, name, hr);
  403. }
  404. }
  405. else
  406. {
  407. if (m_piClassObject)
  408. {
  409. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  410. LogError(IDS_InParam, IDS_GETCHSTRING);
  411. }
  412. else
  413. {
  414. dwLastErr = (WBEM_E_FAILED);
  415. LogError(IDS_NOCLASS, IDS_GETCHSTRING);
  416. }
  417. }
  418. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  419. SetLastError(dwLastErr);
  420. return bRet;
  421. }
  422. ////////////////////////////////////////////////////////////////////////
  423. //
  424. // Function: GetStringArray
  425. //
  426. //
  427. //
  428. // Inputs: Name of property to retrieve
  429. // SAFEARRAY *& strArray
  430. // Outputs:
  431. //
  432. // Return: false if you try to get a property that is not a string array compatible type
  433. //
  434. // Comments:
  435. //
  436. ////////////////////////////////////////////////////////////////////////
  437. bool CInstance::GetStringArray(LPCWSTR name, SAFEARRAY *& strArray) const
  438. {
  439. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  440. bool bRet = false;
  441. DWORD dwLastErr = 0;
  442. ASSERT_BREAK(name != NULL);
  443. if (m_piClassObject && name)
  444. {
  445. // Variant_t handles the VariantInit/VariantClear
  446. variant_t v;
  447. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  448. HRESULT hr = m_piClassObject->Get(name, 0, &v, NULL, NULL);
  449. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  450. // If bSuccess is TRUE, we don't need to log an error. This keeps Gets on
  451. // null properties from logging an error.
  452. BOOL bSuccess = SUCCEEDED(hr) && (v.vt == (VT_BSTR|VT_ARRAY) ||
  453. v.vt == VT_NULL);
  454. ASSERT_BREAK(bSuccess);
  455. if (SUCCEEDED(hr))
  456. {
  457. if ((v.vt == (VT_BSTR|VT_ARRAY)) && (v.parray != NULL ))
  458. {
  459. if ( SUCCEEDED ( SafeArrayCopy ( v.parray , ( SAFEARRAY ** ) &strArray ) ) )
  460. {
  461. bRet = true ;
  462. }
  463. else
  464. {
  465. throw CHeap_Exception ( CHeap_Exception :: E_ALLOCATION_ERROR ) ;
  466. }
  467. }
  468. else
  469. {
  470. dwLastErr = (WBEM_S_NO_MORE_DATA);
  471. }
  472. }
  473. if (!bSuccess)
  474. {
  475. if (SUCCEEDED(hr))
  476. {
  477. hr = WBEM_E_TYPE_MISMATCH;
  478. }
  479. dwLastErr = (hr);
  480. LogError(IDS_FAILED, IDS_GetStringArray, name, hr);
  481. }
  482. }
  483. else
  484. {
  485. if (m_piClassObject)
  486. {
  487. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  488. LogError(IDS_InParam, IDS_GetStringArray);
  489. }
  490. else
  491. {
  492. dwLastErr = (WBEM_E_FAILED);
  493. LogError(IDS_NOCLASS, IDS_GetStringArray);
  494. }
  495. }
  496. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  497. SetLastError(dwLastErr);
  498. return bRet;
  499. }
  500. bool CInstance::GetWCHAR(LPCWSTR name, WCHAR **pW) const
  501. {
  502. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  503. bool bRet = false;
  504. DWORD dwLastErr = 0;
  505. if (m_piClassObject && name)
  506. {
  507. // Variant_t handles the VariantInit/VariantClear
  508. variant_t v;
  509. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  510. HRESULT hr = m_piClassObject->Get(name, 0, &v, NULL, NULL);
  511. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  512. // If bSuccess is TRUE, we don't need to log an error. This keeps Gets on
  513. // null properties from logging an error.
  514. BOOL bSuccess = SUCCEEDED(hr) && (v.vt == VT_BSTR || v.vt == VT_NULL);
  515. ASSERT_BREAK(bSuccess);
  516. if (SUCCEEDED(hr))
  517. {
  518. if ((v.vt == VT_BSTR) && (v.bstrVal != NULL))
  519. {
  520. size_t uLength = wcslen(v.bstrVal) + 1;
  521. *pW = (WCHAR *)malloc((uLength)*sizeof(WCHAR));
  522. if (*pW == NULL)
  523. {
  524. VariantClear(&v);
  525. throw CHeap_Exception ( CHeap_Exception :: E_ALLOCATION_ERROR ) ;
  526. }
  527. StringCchCopyW( *pW, uLength, v.bstrVal );
  528. bRet = true;
  529. }
  530. else
  531. {
  532. dwLastErr = (WBEM_S_NO_MORE_DATA);
  533. }
  534. }
  535. if (!bSuccess)
  536. {
  537. if (SUCCEEDED(hr))
  538. {
  539. hr = WBEM_E_TYPE_MISMATCH;
  540. }
  541. dwLastErr = (hr);
  542. LogError(IDS_FAILED, IDS_GETCHSTRING, name, hr);
  543. }
  544. }
  545. else
  546. {
  547. if (m_piClassObject)
  548. {
  549. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  550. LogError(IDS_InParam, IDS_GETCHSTRING);
  551. }
  552. else
  553. {
  554. dwLastErr = (WBEM_E_FAILED);
  555. LogError(IDS_NOCLASS, IDS_GETCHSTRING);
  556. }
  557. }
  558. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  559. SetLastError(dwLastErr);
  560. return bRet;
  561. }
  562. // WORD support //
  563. ////////////////////////////////////////////////////////////////////////
  564. //
  565. // Function: Set (WORD)
  566. //
  567. //
  568. //
  569. // Inputs: Name of property to set
  570. // WORD to be set
  571. // Outputs:
  572. //
  573. // Return: false if you try to set a property that is not a WORD compatible type
  574. //
  575. // Comments:
  576. //
  577. ////////////////////////////////////////////////////////////////////////
  578. bool CInstance::SetWORD(LPCWSTR name, WORD w)
  579. {
  580. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  581. bool bRet = false;
  582. DWORD dwLastErr = 0;
  583. ASSERT_BREAK(name);
  584. if (m_piClassObject && name)
  585. {
  586. VARIANT v;
  587. VariantInit(&v);
  588. v.vt = VT_I4;
  589. v.lVal = (long)w;
  590. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  591. HRESULT hr = m_piClassObject->Put(name, 0, &v, NULL);
  592. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  593. ASSERT_BREAK(SUCCEEDED(hr));
  594. bRet = (bool)SUCCEEDED(hr);
  595. VariantClear(&v);
  596. if (!bRet)
  597. {
  598. dwLastErr = (hr);
  599. LogError(IDS_FAILED, IDS_SETWORD, name, hr);
  600. }
  601. }
  602. else
  603. {
  604. if (m_piClassObject)
  605. {
  606. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  607. LogError(IDS_InParam, IDS_SETWORD);
  608. }
  609. else
  610. {
  611. dwLastErr = (WBEM_E_FAILED);
  612. LogError(IDS_NOCLASS, IDS_SETWORD);
  613. }
  614. }
  615. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  616. SetLastError(dwLastErr);
  617. return bRet;
  618. }
  619. ////////////////////////////////////////////////////////////////////////
  620. //
  621. // Function: Get (WORD)
  622. //
  623. //
  624. //
  625. // Inputs: Name of property to retrieve
  626. // WORD buffer to receive value
  627. // Outputs:
  628. //
  629. // Return: false if you try to get a property that is not a WORD compatible type
  630. //
  631. // Comments:
  632. //
  633. ////////////////////////////////////////////////////////////////////////
  634. bool CInstance::GetWORD(LPCWSTR name, WORD& w) const
  635. {
  636. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  637. bool bRet = false;
  638. DWORD dwLastErr = 0;
  639. ASSERT_BREAK(name != NULL);
  640. if (m_piClassObject && name)
  641. {
  642. // Variant_t handles the VariantInit/VariantClear
  643. variant_t v;
  644. CIMTYPE vtType;
  645. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  646. HRESULT hr = m_piClassObject->Get(name, 0, &v, &vtType, NULL);
  647. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  648. // If bSuccess is TRUE, we don't need to log an error. This keeps Gets on
  649. // null properties from logging an error.
  650. BOOL bSuccess = SUCCEEDED(hr) && CIM_UINT16 == vtType;
  651. ASSERT_BREAK(bSuccess);
  652. if (SUCCEEDED(hr))
  653. {
  654. // the CIM type is important here
  655. if( (v.vt == VT_I4) && (CIM_UINT16 == vtType) )
  656. {
  657. w = (WORD)v.lVal;
  658. bRet = true;
  659. }
  660. else
  661. {
  662. dwLastErr = (WBEM_S_NO_MORE_DATA);
  663. }
  664. }
  665. if (!bSuccess)
  666. {
  667. if (SUCCEEDED(hr))
  668. {
  669. hr = WBEM_E_TYPE_MISMATCH;
  670. }
  671. dwLastErr = (hr);
  672. LogError(IDS_FAILED, IDS_GETWORD, name, hr);
  673. }
  674. }
  675. else
  676. {
  677. if (m_piClassObject)
  678. {
  679. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  680. LogError(IDS_InParam, IDS_GETWORD);
  681. }
  682. else
  683. {
  684. dwLastErr = (WBEM_E_FAILED);
  685. LogError(IDS_NOCLASS, IDS_GETWORD);
  686. }
  687. }
  688. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  689. SetLastError(dwLastErr);
  690. return bRet;
  691. }
  692. // DWORD support //
  693. ////////////////////////////////////////////////////////////////////////
  694. //
  695. // Function: Set (DWORD)
  696. //
  697. //
  698. //
  699. // Inputs: Name of property to set
  700. // DWORD to be set
  701. // Outputs:
  702. //
  703. // Return: false if you try to set a property that is not a DWORD compatible type
  704. //
  705. // Comments:
  706. //
  707. ////////////////////////////////////////////////////////////////////////
  708. bool CInstance::SetDWORD(LPCWSTR name, DWORD d)
  709. {
  710. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  711. bool bRet = false;
  712. DWORD dwLastErr = 0;
  713. if (m_piClassObject && name)
  714. {
  715. VARIANT v;
  716. VariantInit(&v);
  717. v.vt = VT_I4;
  718. v.lVal = (long)d;
  719. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  720. HRESULT hr = m_piClassObject->Put(name, 0, &v, NULL);
  721. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  722. ASSERT_BREAK(SUCCEEDED(hr));
  723. bRet = (bool)SUCCEEDED(hr);
  724. if (!bRet)
  725. {
  726. dwLastErr = (hr);
  727. LogError(IDS_FAILED, IDS_SETDWORD, name, hr);
  728. }
  729. VariantClear(&v);
  730. }
  731. else
  732. {
  733. if (m_piClassObject)
  734. {
  735. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  736. LogError(IDS_InParam, IDS_SETDWORD);
  737. }
  738. else
  739. {
  740. dwLastErr = (WBEM_E_FAILED);
  741. LogError(IDS_NOCLASS, IDS_SETDWORD);
  742. }
  743. }
  744. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  745. SetLastError(dwLastErr);
  746. return bRet;
  747. }
  748. ////////////////////////////////////////////////////////////////////////
  749. //
  750. // Function: Get (DWORD)
  751. //
  752. //
  753. //
  754. // Inputs: Name of property to retrieve
  755. // DWORD buffer to receive value
  756. // Outputs:
  757. //
  758. // Return: false if you try to get a property that is not a DWORD compatible type
  759. //
  760. // Comments:
  761. //
  762. ////////////////////////////////////////////////////////////////////////
  763. bool CInstance::GetDWORD(LPCWSTR name, DWORD& d) const
  764. {
  765. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  766. bool bRet = false;
  767. DWORD dwLastErr = 0;
  768. if (m_piClassObject && name)
  769. {
  770. // Variant_t handles the VariantInit/VariantClear
  771. variant_t v;
  772. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  773. HRESULT hr = m_piClassObject->Get(name, 0, &v, NULL, NULL);
  774. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  775. // If bSuccess is TRUE, we don't need to log an error. This keeps Gets on
  776. // null properties from logging an error.
  777. BOOL bSuccess = SUCCEEDED(hr) && (v.vt == VT_I4 || v.vt == VT_NULL);
  778. ASSERT_BREAK(bSuccess);
  779. if (SUCCEEDED(hr))
  780. {
  781. if (v.vt == VT_I4)
  782. {
  783. d = (DWORD)v.lVal;
  784. bRet = true;
  785. }
  786. else
  787. {
  788. dwLastErr = (WBEM_S_NO_MORE_DATA);
  789. }
  790. }
  791. if (!bSuccess)
  792. {
  793. if (SUCCEEDED(hr))
  794. {
  795. hr = WBEM_E_TYPE_MISMATCH;
  796. }
  797. dwLastErr = (hr);
  798. LogError(IDS_FAILED, IDS_GETDWORD, name, hr);
  799. }
  800. }
  801. else
  802. {
  803. if (m_piClassObject)
  804. {
  805. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  806. LogError(IDS_InParam, IDS_GETDWORD);
  807. }
  808. else
  809. {
  810. dwLastErr = (WBEM_E_FAILED);
  811. LogError(IDS_NOCLASS, IDS_GETDWORD);
  812. }
  813. }
  814. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  815. SetLastError(dwLastErr);
  816. return bRet;
  817. }
  818. // DOUBLE support //
  819. ////////////////////////////////////////////////////////////////////////
  820. //
  821. // Function: Set (DOUBLE)
  822. //
  823. //
  824. //
  825. // Inputs: Name of property to set
  826. // DOUBLE to be set
  827. // Outputs:
  828. //
  829. // Return: false if you try to set a property that is not a DOUBLE compatible type
  830. //
  831. // Comments:
  832. //
  833. ////////////////////////////////////////////////////////////////////////
  834. bool CInstance::SetDOUBLE(LPCWSTR name, DOUBLE dub)
  835. {
  836. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  837. bool bRet = false;
  838. DWORD dwLastErr = 0;
  839. if (m_piClassObject && name)
  840. {
  841. VARIANT v;
  842. VariantInit(&v);
  843. V_R8(&v) = dub;
  844. V_VT(&v) = VT_R8;
  845. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  846. HRESULT hr = m_piClassObject->Put(name, 0, &v, NULL);
  847. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  848. ASSERT_BREAK(SUCCEEDED(hr));
  849. bRet = (bool)SUCCEEDED(hr);
  850. VariantClear(&v);
  851. if (!bRet)
  852. {
  853. dwLastErr = (hr);
  854. LogError(IDS_FAILED, IDS_SETDOUBLE, name, hr);
  855. }
  856. }
  857. else
  858. {
  859. if (m_piClassObject)
  860. {
  861. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  862. LogError(IDS_InParam, IDS_SETDOUBLE);
  863. }
  864. else
  865. {
  866. dwLastErr = (WBEM_E_FAILED);
  867. LogError(IDS_NOCLASS, IDS_SETDOUBLE);
  868. }
  869. }
  870. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  871. SetLastError(dwLastErr);
  872. return bRet;
  873. }
  874. ////////////////////////////////////////////////////////////////////////
  875. //
  876. // Function: Get (DOUBLE)
  877. //
  878. //
  879. //
  880. // Inputs: Name of property to retrieve
  881. // DOUBLE buffer to receive value
  882. // Outputs:
  883. //
  884. // Return: false if you try to get a property that is not a DOUBLE compatible type
  885. //
  886. // Comments:
  887. //
  888. ////////////////////////////////////////////////////////////////////////
  889. bool CInstance::GetDOUBLE(LPCWSTR name, DOUBLE& dub) const
  890. {
  891. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  892. bool bRet = false;
  893. DWORD dwLastErr = 0;
  894. if (m_piClassObject && name)
  895. {
  896. // Variant_t handles the VariantInit/VariantClear
  897. variant_t v;
  898. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  899. HRESULT hr = m_piClassObject->Get(name, 0, &v, NULL, NULL);
  900. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  901. // If bSuccess is TRUE, we don't need to log an error. This keeps Gets on
  902. // null properties from logging an error.
  903. BOOL bSuccess = SUCCEEDED(hr) && (v.vt == VT_R8 || v.vt == VT_NULL);
  904. ASSERT_BREAK(bSuccess);
  905. if (SUCCEEDED(hr))
  906. {
  907. if (v.vt == VT_R8)
  908. {
  909. dub = V_R8(&v);
  910. bRet = true;
  911. }
  912. else
  913. {
  914. dwLastErr = (WBEM_S_NO_MORE_DATA);
  915. }
  916. }
  917. if (!bSuccess)
  918. {
  919. if (SUCCEEDED(hr))
  920. {
  921. hr = WBEM_E_TYPE_MISMATCH;
  922. }
  923. dwLastErr = (hr);
  924. LogError(IDS_FAILED, IDS_GETDOUBLE, name, hr);
  925. }
  926. }
  927. else
  928. {
  929. if (m_piClassObject)
  930. {
  931. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  932. LogError(IDS_InParam, IDS_GETDOUBLE);
  933. }
  934. else
  935. {
  936. dwLastErr = (WBEM_E_FAILED);
  937. LogError(IDS_NOCLASS, IDS_GETDOUBLE);
  938. }
  939. }
  940. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  941. SetLastError(dwLastErr);
  942. return bRet;
  943. }
  944. ////////////////////////////////////////////////////////////////////////
  945. //
  946. // Function: Set (Byte)
  947. //
  948. //
  949. //
  950. // Inputs: Name of property to set
  951. // BYTE to be set
  952. // Outputs:
  953. //
  954. // Return: false if you try to set a property that is not a BYTE compatible type
  955. //
  956. // Comments:
  957. //
  958. ////////////////////////////////////////////////////////////////////////
  959. bool CInstance::SetByte(LPCWSTR name, BYTE b)
  960. {
  961. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  962. bool bRet = false;
  963. DWORD dwLastErr = 0;
  964. if (m_piClassObject && name)
  965. {
  966. VARIANT v;
  967. VariantInit(&v);
  968. v.vt = VT_UI1;
  969. v.bVal = (long)b ;
  970. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  971. HRESULT hr = m_piClassObject->Put(name, 0, &v, NULL);
  972. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  973. ASSERT_BREAK(SUCCEEDED(hr));
  974. bRet = (bool)SUCCEEDED(hr);
  975. if (!bRet)
  976. {
  977. dwLastErr = (hr);
  978. LogError(IDS_FAILED, IDS_SETBYTE, name, hr);
  979. }
  980. VariantClear(&v);
  981. }
  982. else
  983. {
  984. if (m_piClassObject)
  985. {
  986. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  987. LogError(IDS_InParam, IDS_SETBYTE);
  988. }
  989. else
  990. {
  991. dwLastErr = (WBEM_E_FAILED);
  992. LogError(IDS_NOCLASS, IDS_SETBYTE);
  993. }
  994. }
  995. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  996. SetLastError(dwLastErr);
  997. return bRet;
  998. }
  999. ////////////////////////////////////////////////////////////////////////
  1000. //
  1001. // Function: SetEmbeddedObject
  1002. //
  1003. //
  1004. //
  1005. // Inputs: Name of property to set
  1006. // CInstance to be set
  1007. // Outputs:
  1008. //
  1009. // Return: false if you try to set a property that is not a IUnknown compatible type
  1010. //
  1011. // Comments: CInstance is not released - responsibility of caller
  1012. //
  1013. ////////////////////////////////////////////////////////////////////////
  1014. bool CInstance::SetEmbeddedObject(LPCWSTR name, CInstance& cInstance )
  1015. {
  1016. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1017. bool bRet = false;
  1018. DWORD dwLastErr = 0;
  1019. if (m_piClassObject && name)
  1020. {
  1021. IWbemClassObject *t_ClassObject = cInstance.GetClassObjectInterface();
  1022. if ( t_ClassObject )
  1023. {
  1024. variant_t v;
  1025. v.vt = VT_UNKNOWN;
  1026. v.punkVal = t_ClassObject;
  1027. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  1028. HRESULT hr = m_piClassObject->Put(name, 0, &v, NULL);
  1029. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1030. ASSERT_BREAK(SUCCEEDED(hr));
  1031. bRet = (bool)SUCCEEDED(hr);
  1032. if (!bRet)
  1033. {
  1034. dwLastErr = (hr);
  1035. LogError(IDS_FAILED, IDS_SetEmbeddedObject, name, hr);
  1036. }
  1037. }
  1038. else
  1039. {
  1040. dwLastErr = (WBEM_E_FAILED);
  1041. }
  1042. }
  1043. else
  1044. {
  1045. if (m_piClassObject)
  1046. {
  1047. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  1048. LogError(IDS_InParam, IDS_SetEmbeddedObject);
  1049. }
  1050. else
  1051. {
  1052. dwLastErr = (WBEM_E_FAILED);
  1053. LogError(IDS_NOCLASS, IDS_SetEmbeddedObject);
  1054. }
  1055. }
  1056. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  1057. SetLastError(dwLastErr);
  1058. return bRet;
  1059. }
  1060. ////////////////////////////////////////////////////////////////////////
  1061. //
  1062. // Function: Get (Byte)
  1063. //
  1064. //
  1065. //
  1066. // Inputs: Name of property to retrieve
  1067. // BYTE buffer to receive value
  1068. // Outputs:
  1069. //
  1070. // Return: false if you try to get a property that is not a DWORD compatible type
  1071. //
  1072. // Comments:
  1073. //
  1074. ////////////////////////////////////////////////////////////////////////
  1075. bool CInstance::GetByte(LPCWSTR name, BYTE& b) const
  1076. {
  1077. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1078. bool bRet = false;
  1079. DWORD dwLastErr = 0;
  1080. if (m_piClassObject && name)
  1081. {
  1082. // Variant_t handles the VariantInit/VariantClear
  1083. variant_t v;
  1084. CIMTYPE vtType;
  1085. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  1086. HRESULT hr = m_piClassObject->Get(name, 0, &v, &vtType, NULL);
  1087. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1088. // If bSuccess is TRUE, we don't need to log an error. This keeps Gets on
  1089. // null properties from logging an error.
  1090. BOOL bSuccess = (SUCCEEDED(hr)) && ((vtType == CIM_SINT8) || (vtType == CIM_UINT8));
  1091. ASSERT_BREAK(bSuccess);
  1092. if (SUCCEEDED(hr))
  1093. {
  1094. if( (v.vt == VT_UI1) && ( (vtType == CIM_SINT8) || (vtType == CIM_UINT8) ) )
  1095. {
  1096. b = v.bVal;
  1097. bRet = true;
  1098. }
  1099. else
  1100. {
  1101. dwLastErr = (WBEM_S_NO_MORE_DATA);
  1102. }
  1103. }
  1104. if (!bSuccess)
  1105. {
  1106. if (SUCCEEDED(hr))
  1107. {
  1108. hr = WBEM_E_TYPE_MISMATCH;
  1109. }
  1110. dwLastErr = (hr);
  1111. LogError(IDS_FAILED, IDS_GETBYTE, name, hr);
  1112. }
  1113. }
  1114. else
  1115. {
  1116. if (m_piClassObject)
  1117. {
  1118. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  1119. LogError(IDS_InParam, IDS_GETBYTE);
  1120. }
  1121. else
  1122. {
  1123. dwLastErr = (WBEM_E_FAILED);
  1124. LogError(IDS_NOCLASS, IDS_GETBYTE);
  1125. }
  1126. }
  1127. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  1128. SetLastError(dwLastErr);
  1129. return bRet;
  1130. }
  1131. ////////////////////////////////////////////////////////////////////////
  1132. //
  1133. // Function: GetEmbeddedObject
  1134. //
  1135. //
  1136. //
  1137. // Inputs: Name of property to retrieve
  1138. // reference to buffer hold pointer to new instance
  1139. // Outputs:
  1140. //
  1141. // Return: false if you try to get a property that is not a object compatible type
  1142. //
  1143. // Comments: Creates CInstance, user is responsible for release
  1144. //
  1145. ////////////////////////////////////////////////////////////////////////
  1146. bool CInstance::GetEmbeddedObject (LPCWSTR name, CInstance** pInstance, MethodContext* pMethodContext) const
  1147. {
  1148. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1149. bool bRet = false;
  1150. DWORD dwLastErr = 0;
  1151. ASSERT_BREAK(m_piClassObject && (pInstance != NULL));
  1152. if (m_piClassObject && name && (pInstance != NULL))
  1153. {
  1154. // Variant_t handles the VariantInit/VariantClear
  1155. variant_t v;
  1156. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  1157. HRESULT hr = m_piClassObject->Get(name, 0, &v, NULL, NULL);
  1158. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1159. // If bSuccess is TRUE, we don't need to log an error. This keeps Gets on
  1160. // null properties from logging an error.
  1161. BOOL bSuccess = SUCCEEDED(hr) && (v.vt == VT_UNKNOWN || v.vt == VT_NULL);
  1162. ASSERT_BREAK(bSuccess);
  1163. if (SUCCEEDED(hr))
  1164. {
  1165. if (v.vt == VT_UNKNOWN)
  1166. {
  1167. IUnknown *t_Unknown = v.punkVal ;
  1168. if ( t_Unknown )
  1169. {
  1170. IWbemClassObject *t_Object = NULL;
  1171. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  1172. HRESULT t_Result = t_Unknown->QueryInterface ( IID_IWbemClassObject , (void**) &t_Object ) ;
  1173. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1174. if ( SUCCEEDED ( t_Result ) )
  1175. {
  1176. *pInstance = new CInstance(t_Object, pMethodContext);
  1177. if (pInstance == NULL)
  1178. {
  1179. throw CHeap_Exception ( CHeap_Exception :: E_ALLOCATION_ERROR ) ;
  1180. }
  1181. bRet = true ;
  1182. }
  1183. else
  1184. {
  1185. dwLastErr = (t_Result);
  1186. }
  1187. }
  1188. else
  1189. {
  1190. dwLastErr = (WBEM_S_NO_MORE_DATA);
  1191. }
  1192. }
  1193. else
  1194. {
  1195. if (bSuccess)
  1196. {
  1197. dwLastErr = (WBEM_S_NO_MORE_DATA);
  1198. }
  1199. }
  1200. }
  1201. if (!bSuccess)
  1202. {
  1203. if (SUCCEEDED(hr))
  1204. {
  1205. hr = WBEM_E_TYPE_MISMATCH;
  1206. }
  1207. dwLastErr = (hr);
  1208. LogError(IDS_FAILED, IDS_GetEmbeddedObject, name, hr);
  1209. }
  1210. }
  1211. else
  1212. {
  1213. if (m_piClassObject)
  1214. {
  1215. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  1216. LogError(IDS_InParam, IDS_GetEmbeddedObject);
  1217. }
  1218. else
  1219. {
  1220. dwLastErr = (WBEM_E_FAILED);
  1221. LogError(IDS_NOCLASS, IDS_GetEmbeddedObject);
  1222. }
  1223. }
  1224. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  1225. SetLastError(dwLastErr);
  1226. return bRet;
  1227. }
  1228. // bool support //
  1229. ////////////////////////////////////////////////////////////////////////
  1230. //
  1231. // Function: Set (bool)
  1232. //
  1233. //
  1234. //
  1235. // Inputs: Name of property to set
  1236. // bool to be set
  1237. // Outputs:
  1238. //
  1239. // Return: false if you try to set a property that is not a bool compatible type
  1240. //
  1241. // Comments:
  1242. //
  1243. ////////////////////////////////////////////////////////////////////////
  1244. bool CInstance::Setbool(LPCWSTR name, bool b)
  1245. {
  1246. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1247. bool bRet = false;
  1248. DWORD dwLastErr = 0;
  1249. if (m_piClassObject && name)
  1250. {
  1251. VARIANT v;
  1252. VariantInit(&v);
  1253. v.vt = VT_BOOL;
  1254. if (b)
  1255. {
  1256. v.boolVal = VARIANT_TRUE;
  1257. }
  1258. else
  1259. {
  1260. v.boolVal = VARIANT_FALSE;
  1261. }
  1262. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  1263. HRESULT hr = m_piClassObject->Put(name, 0, &v, NULL);
  1264. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1265. ASSERT_BREAK(SUCCEEDED(hr));
  1266. bRet = (bool)SUCCEEDED(hr);
  1267. if (!bRet)
  1268. {
  1269. dwLastErr = (hr);
  1270. LogError(IDS_FAILED, IDS_SETBOOL, name, hr);
  1271. }
  1272. VariantClear(&v);
  1273. }
  1274. else
  1275. {
  1276. if (m_piClassObject)
  1277. {
  1278. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  1279. LogError(IDS_InParam, IDS_SETBOOL);
  1280. }
  1281. else
  1282. {
  1283. dwLastErr = (WBEM_E_FAILED);
  1284. LogError(IDS_NOCLASS, IDS_SETBOOL);
  1285. }
  1286. }
  1287. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  1288. SetLastError(dwLastErr);
  1289. return bRet;
  1290. }
  1291. ////////////////////////////////////////////////////////////////////////
  1292. //
  1293. // Function: Get (bool)
  1294. //
  1295. //
  1296. //
  1297. // Inputs: Name of property to retrieve
  1298. // bool buffer to receive value
  1299. // Outputs:
  1300. //
  1301. // Return: false if you try to get a property that is not a bool compatible type
  1302. //
  1303. // Comments:
  1304. //
  1305. ////////////////////////////////////////////////////////////////////////
  1306. bool CInstance::Getbool(LPCWSTR name, bool& b) const
  1307. {
  1308. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1309. bool bRet = false;
  1310. DWORD dwLastErr = 0;
  1311. if (m_piClassObject && name)
  1312. {
  1313. // Variant_t handles the VariantInit/VariantClear
  1314. variant_t v;
  1315. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  1316. HRESULT hr = m_piClassObject->Get(name, 0, &v, NULL, NULL);
  1317. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1318. // If bSuccess is TRUE, we don't need to log an error. This keeps Gets on
  1319. // null properties from logging an error.
  1320. BOOL bSuccess = (SUCCEEDED(hr)) && (v.vt == VT_BOOL || v.vt == VT_NULL);
  1321. ASSERT_BREAK(bSuccess);
  1322. if (SUCCEEDED(hr))
  1323. {
  1324. if (v.vt == VT_BOOL)
  1325. {
  1326. if (v.boolVal)
  1327. {
  1328. b = true;
  1329. }
  1330. else
  1331. {
  1332. b = false;
  1333. }
  1334. bRet = true;
  1335. ASSERT_BREAK((v.boolVal == VARIANT_TRUE) || (v.boolVal == VARIANT_FALSE));
  1336. }
  1337. else
  1338. {
  1339. dwLastErr = (WBEM_S_NO_MORE_DATA);
  1340. }
  1341. }
  1342. if (!bSuccess)
  1343. {
  1344. if (SUCCEEDED(hr))
  1345. {
  1346. hr = WBEM_E_TYPE_MISMATCH;
  1347. }
  1348. dwLastErr = (hr);
  1349. LogError(IDS_FAILED, IDS_GETBOOL, name, hr);
  1350. }
  1351. }
  1352. else
  1353. {
  1354. if (m_piClassObject)
  1355. {
  1356. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  1357. LogError(IDS_InParam, IDS_GETBOOL);
  1358. }
  1359. else
  1360. {
  1361. dwLastErr = (WBEM_E_FAILED);
  1362. LogError(IDS_NOCLASS, IDS_GETBOOL);
  1363. }
  1364. }
  1365. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  1366. SetLastError(dwLastErr);
  1367. return bRet;
  1368. }
  1369. ////////////////////////////////////////////////////////////////////////
  1370. //
  1371. // Function: SetVariant
  1372. //
  1373. //
  1374. //
  1375. // Inputs: const LPCWSTR name - Name of property to set
  1376. // const VARIANT& variant - Value to assign to Name.
  1377. //
  1378. // Outputs:
  1379. //
  1380. // Return: false if the supplied variant type is not correct
  1381. // for the property we are setting.
  1382. //
  1383. // Comments:
  1384. //
  1385. ////////////////////////////////////////////////////////////////////////
  1386. bool CInstance::SetVariant( LPCWSTR name, const VARIANT& variant )
  1387. {
  1388. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1389. bool bRet = false;
  1390. DWORD dwLastErr = 0;
  1391. if (m_piClassObject && name)
  1392. {
  1393. HRESULT hr;
  1394. // I realize the (VARIANT*) cast is ugly, as it is a const,
  1395. // HOWEVER, somewhere nobody seems to understand why we would
  1396. // possibly want to keep things const. I could copy the VARIANT,
  1397. // but that requires the same cast, so under duress, and to reduce
  1398. // redundant code, I'm casting here. Did I mention EXTREME
  1399. // DURESS?
  1400. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  1401. hr = m_piClassObject->Put(name, 0, (VARIANT*) &variant, NULL );
  1402. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1403. ASSERT_BREAK(SUCCEEDED(hr));
  1404. bRet = (bool)SUCCEEDED(hr);
  1405. if (!bRet)
  1406. {
  1407. dwLastErr = (hr);
  1408. LogError(IDS_FAILED, IDS_SETVARIANT, name, hr);
  1409. }
  1410. }
  1411. else
  1412. {
  1413. if (m_piClassObject)
  1414. {
  1415. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  1416. LogError(IDS_InParam, IDS_SETVARIANT);
  1417. }
  1418. else
  1419. {
  1420. dwLastErr = (WBEM_E_FAILED);
  1421. LogError(IDS_NOCLASS, IDS_SETVARIANT);
  1422. }
  1423. }
  1424. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  1425. SetLastError(dwLastErr);
  1426. return bRet;
  1427. }
  1428. ////////////////////////////////////////////////////////////////////////
  1429. //
  1430. // Function: GetVariant
  1431. //
  1432. //
  1433. //
  1434. // Inputs: const LPCWSTR name - Name of property to set
  1435. // VARIANT& variant - Value to assign to Name.
  1436. //
  1437. // Outputs:
  1438. //
  1439. // Return: false if the supplied variant type is not correct
  1440. // for the property we are setting.
  1441. //
  1442. // Comments:
  1443. //
  1444. ////////////////////////////////////////////////////////////////////////
  1445. bool CInstance::GetVariant( LPCWSTR name, VARIANT& variant ) const
  1446. {
  1447. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1448. bool bRet = false;
  1449. DWORD dwLastErr = 0;
  1450. if (m_piClassObject && name)
  1451. {
  1452. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  1453. HRESULT hr = m_piClassObject->Get(name, 0, &variant, NULL, NULL );
  1454. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1455. ASSERT_BREAK(SUCCEEDED(hr));
  1456. bRet = (bool)SUCCEEDED(hr);
  1457. if (!bRet)
  1458. {
  1459. dwLastErr = (hr);
  1460. LogError(IDS_FAILED, IDS_GETVARIANT, name, hr);
  1461. }
  1462. }
  1463. else
  1464. {
  1465. if (m_piClassObject)
  1466. {
  1467. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  1468. LogError(IDS_InParam, IDS_GETVARIANT);
  1469. }
  1470. else
  1471. {
  1472. dwLastErr = (WBEM_E_FAILED);
  1473. LogError(IDS_NOCLASS, IDS_GETVARIANT);
  1474. }
  1475. }
  1476. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  1477. SetLastError(dwLastErr);
  1478. return bRet;
  1479. }
  1480. ////////////////////////////////////////////////////////////////////////
  1481. //
  1482. // Function: SetDateTime
  1483. //
  1484. //
  1485. //
  1486. // Inputs: const LPCWSTR name - Name of property to set
  1487. // const WBEMTime& wbemtime - Value to assign to Name.
  1488. //
  1489. // Outputs:
  1490. //
  1491. // Return: false if the supplied time type is not correct
  1492. // for the property we are setting.
  1493. //
  1494. // Comments:
  1495. //
  1496. ////////////////////////////////////////////////////////////////////////
  1497. bool CInstance::SetDateTime( LPCWSTR name, const WBEMTime& wbemtime )
  1498. {
  1499. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1500. bool bRet = false;
  1501. DWORD dwLastErr = 0;
  1502. if (m_piClassObject && name && (wbemtime.IsOk()))
  1503. {
  1504. //GetDMTF may throw so get htis before modifying variant_t
  1505. BSTR bstrTmp = wbemtime.GetDMTF(true);
  1506. // Variant_t handles the VariantInit/VariantClear
  1507. variant_t v;
  1508. // Time is stored as a BSTR
  1509. v.vt = VT_BSTR;
  1510. v.bstrVal = bstrTmp;
  1511. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  1512. HRESULT hr = m_piClassObject->Put(name, 0, &v, NULL);
  1513. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1514. ASSERT_BREAK(SUCCEEDED(hr));
  1515. bRet = (bool)SUCCEEDED(hr);
  1516. if (!bRet)
  1517. {
  1518. dwLastErr = (hr);
  1519. LogError(IDS_FAILED, IDS_SETDATETIME, name, hr);
  1520. }
  1521. }
  1522. else
  1523. {
  1524. if (m_piClassObject)
  1525. {
  1526. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  1527. LogError(IDS_InParam, IDS_SETDATETIME);
  1528. }
  1529. else
  1530. {
  1531. dwLastErr = (WBEM_E_FAILED);
  1532. LogError(IDS_NOCLASS, IDS_SETDATETIME);
  1533. }
  1534. }
  1535. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  1536. SetLastError(dwLastErr);
  1537. return bRet;
  1538. }
  1539. ////////////////////////////////////////////////////////////////////////
  1540. //
  1541. // Function: GetDateTime
  1542. //
  1543. //
  1544. //
  1545. // Inputs: const LPCWSTR name - Name of property to set
  1546. // WBEMTime& wbemtime - Value to obtain from Name.
  1547. //
  1548. // Outputs:
  1549. //
  1550. // Return: false if the supplied variant type is not correct
  1551. // for the property we are setting.
  1552. //
  1553. // Comments:
  1554. //
  1555. ////////////////////////////////////////////////////////////////////////
  1556. bool CInstance::GetDateTime( LPCWSTR name, WBEMTime& wbemtime ) const
  1557. {
  1558. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1559. bool bRet = false;
  1560. DWORD dwLastErr = 0;
  1561. if (m_piClassObject && name)
  1562. {
  1563. // Variant_t handles the VariantInit/VariantClear
  1564. variant_t v;
  1565. //
  1566. // Get the name as a BSTR and pass it into the
  1567. // wbemtime, which handles the conversion internally
  1568. // like a good little class.
  1569. //
  1570. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  1571. HRESULT hr = m_piClassObject->Get(name, 0, &v, NULL, NULL);
  1572. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1573. // If bSuccess is TRUE, we don't need to log an error. This keeps Gets on
  1574. // null properties from logging an error.
  1575. BOOL bSuccess = (SUCCEEDED(hr)) && (v.vt == VT_BSTR || v.vt == VT_NULL);
  1576. ASSERT_BREAK(bSuccess);
  1577. if (SUCCEEDED(hr))
  1578. {
  1579. if ((v.vt == VT_BSTR) && (v.bstrVal != NULL))
  1580. {
  1581. wbemtime = v.bstrVal;
  1582. bRet = wbemtime.IsOk();
  1583. if (!bRet)
  1584. {
  1585. dwLastErr = (WBEM_E_TYPE_MISMATCH);
  1586. }
  1587. }
  1588. else
  1589. {
  1590. dwLastErr = (WBEM_S_NO_MORE_DATA);
  1591. }
  1592. }
  1593. if (!bSuccess)
  1594. {
  1595. if (SUCCEEDED(hr))
  1596. {
  1597. hr = WBEM_E_TYPE_MISMATCH;
  1598. }
  1599. dwLastErr = (hr);
  1600. LogError(IDS_FAILED, IDS_GETDATETIME, name, hr);
  1601. }
  1602. }
  1603. else
  1604. {
  1605. if (m_piClassObject)
  1606. {
  1607. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  1608. LogError(IDS_InParam, IDS_GETDATETIME);
  1609. }
  1610. else
  1611. {
  1612. dwLastErr = (WBEM_E_FAILED);
  1613. LogError(IDS_NOCLASS, IDS_GETDATETIME);
  1614. }
  1615. }
  1616. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  1617. SetLastError(dwLastErr);
  1618. return bRet;
  1619. }
  1620. ////////////////////////////////////////////////////////////////////////
  1621. //
  1622. // Function: SetTimeSpan
  1623. //
  1624. //
  1625. //
  1626. // Inputs: const LPCWSTR name - Name of property to set
  1627. // const WBEMTimeSpan& wbemtimespan - Value to assign to Name.
  1628. //
  1629. // Outputs:
  1630. //
  1631. // Return: false if the supplied timespan type is not correct
  1632. // for the property we are setting.
  1633. //
  1634. // Comments:
  1635. //
  1636. ////////////////////////////////////////////////////////////////////////
  1637. bool CInstance::SetTimeSpan( LPCWSTR name, const WBEMTimeSpan& wbemtimespan )
  1638. {
  1639. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1640. bool bRet = false;
  1641. DWORD dwLastErr = 0;
  1642. if (m_piClassObject && name && (wbemtimespan.IsOk()))
  1643. {
  1644. //GetBSTR may throw so get this before modifying variant_t
  1645. BSTR bstrTmp = wbemtimespan.GetBSTR();
  1646. // Variant_t handles the VariantInit/VariantClear
  1647. variant_t v;
  1648. // Time is stored as a BSTR
  1649. v.vt = VT_BSTR;
  1650. v.bstrVal = bstrTmp;
  1651. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  1652. HRESULT hr = m_piClassObject->Put(name, 0, &v, NULL);
  1653. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1654. ASSERT_BREAK(SUCCEEDED(hr));
  1655. bRet = (bool)SUCCEEDED(hr);
  1656. if (!bRet)
  1657. {
  1658. dwLastErr = (hr);
  1659. LogError(IDS_FAILED, IDS_SETTIMESPAN, name, hr);
  1660. }
  1661. }
  1662. else
  1663. {
  1664. if (m_piClassObject)
  1665. {
  1666. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  1667. LogError(IDS_InParam, IDS_SETTIMESPAN);
  1668. }
  1669. else
  1670. {
  1671. dwLastErr = (WBEM_E_FAILED);
  1672. LogError(IDS_NOCLASS, IDS_SETTIMESPAN);
  1673. }
  1674. }
  1675. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  1676. SetLastError(dwLastErr);
  1677. return bRet;
  1678. }
  1679. ////////////////////////////////////////////////////////////////////////
  1680. //
  1681. // Function: GetTimeSpan
  1682. //
  1683. //
  1684. //
  1685. // Inputs: const LPCWSTR name - Name of property to set
  1686. // WBEMTimeSpan& wbemtimespan - Value to obtain from Name.
  1687. //
  1688. // Outputs:
  1689. //
  1690. // Return: false if the supplied timespan type is not correct
  1691. // for the property we are setting.
  1692. //
  1693. // Comments:
  1694. //
  1695. ////////////////////////////////////////////////////////////////////////
  1696. bool CInstance::GetTimeSpan( LPCWSTR name, WBEMTimeSpan& wbemtimespan ) const
  1697. {
  1698. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1699. bool bRet = false;
  1700. DWORD dwLastErr = 0;
  1701. if (m_piClassObject && name)
  1702. {
  1703. // Variant_t handles the VariantInit/VariantClear
  1704. variant_t v;
  1705. //
  1706. // Get the name as a BSTR and pass it into the
  1707. // wbemtimespan, which handles the conversion
  1708. // internally like a good little class.
  1709. //
  1710. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  1711. HRESULT hr = m_piClassObject->Get(name, 0, &v, NULL, NULL);
  1712. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1713. // If bSuccess is TRUE, we don't need to log an error. This keeps Gets on
  1714. // null properties from logging an error.
  1715. BOOL bSuccess = (SUCCEEDED(hr)) && (v.vt == VT_BSTR || v.vt == VT_NULL);
  1716. ASSERT_BREAK(bSuccess);
  1717. if (SUCCEEDED(hr))
  1718. {
  1719. if ((v.vt == VT_BSTR) && (v.bstrVal != NULL))
  1720. {
  1721. wbemtimespan = v.bstrVal;
  1722. bRet = wbemtimespan.IsOk();
  1723. // This is freed by the VariantClear
  1724. // SysFreeString(v.bstrVal);
  1725. if (!bRet)
  1726. {
  1727. dwLastErr = (WBEM_E_TYPE_MISMATCH);
  1728. }
  1729. }
  1730. else
  1731. {
  1732. dwLastErr = (WBEM_S_NO_MORE_DATA);
  1733. }
  1734. }
  1735. if (!bSuccess)
  1736. {
  1737. if (SUCCEEDED(hr))
  1738. {
  1739. hr = WBEM_E_TYPE_MISMATCH;
  1740. }
  1741. dwLastErr = (hr);
  1742. LogError(IDS_FAILED, IDS_GETTIMESPAN, name, hr);
  1743. }
  1744. }
  1745. else
  1746. {
  1747. if (m_piClassObject)
  1748. {
  1749. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  1750. LogError(IDS_InParam, IDS_GETTIMESPAN);
  1751. }
  1752. else
  1753. {
  1754. dwLastErr = (WBEM_E_FAILED);
  1755. LogError(IDS_NOCLASS, IDS_GETTIMESPAN);
  1756. }
  1757. }
  1758. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  1759. SetLastError(dwLastErr);
  1760. return bRet;
  1761. }
  1762. ////////////////////////////////////////////////////////////////////////
  1763. //
  1764. // Function: SetWBEMINT64
  1765. //
  1766. //
  1767. //
  1768. // Inputs: const LPCWSTR name - Name of property to set
  1769. // const WBEMINT64& wbemint64 - Value to assign to Name.
  1770. //
  1771. // Outputs:
  1772. //
  1773. // Return: false if the supplied wbemint64 type is not correct
  1774. // for the property we are setting.
  1775. //
  1776. // Comments:
  1777. //
  1778. ////////////////////////////////////////////////////////////////////////
  1779. bool CInstance::SetWBEMINT64( LPCWSTR name, const WBEMINT64& wbemint64 )
  1780. {
  1781. // For right now, this is just a CHString.
  1782. return SetWCHARSplat( name, wbemint64 );
  1783. }
  1784. bool CInstance::SetWBEMINT64( LPCWSTR name, const LONGLONG i64Value )
  1785. {
  1786. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1787. WCHAR szBuff[33];
  1788. _i64tow(i64Value, szBuff, 10);
  1789. return SetWCHARSplat(name, szBuff);
  1790. }
  1791. bool CInstance::SetWBEMINT64( LPCWSTR name, const ULONGLONG i64Value )
  1792. {
  1793. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1794. WCHAR szBuff[33];
  1795. _ui64tow(i64Value, szBuff, 10);
  1796. return SetWCHARSplat(name, szBuff);
  1797. }
  1798. ////////////////////////////////////////////////////////////////////////
  1799. //
  1800. // Function: GetWBEMINT64
  1801. //
  1802. //
  1803. //
  1804. // Inputs: const LPCWSTR name - Name of property to set
  1805. // WBEMINT64& wbemint64 - Value to assign to Name.
  1806. //
  1807. // Outputs:
  1808. //
  1809. // Return: false if the supplied wbemint64 type is not correct
  1810. // for the property we are setting.
  1811. //
  1812. // Comments:
  1813. //
  1814. ////////////////////////////////////////////////////////////////////////
  1815. bool CInstance::GetWBEMINT64( LPCWSTR name, WBEMINT64& wbemint64 ) const
  1816. {
  1817. // For right now, this is just a CHString.
  1818. return GetCHString( name, wbemint64 );
  1819. }
  1820. bool CInstance::GetWBEMINT64( LPCWSTR name, LONGLONG& i64Value) const
  1821. {
  1822. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1823. CHString s;
  1824. bool b = GetWBEMINT64(name, s);
  1825. if (b)
  1826. i64Value = _wtoi64(s);
  1827. return b;
  1828. }
  1829. bool CInstance::GetWBEMINT64( LPCWSTR name, ULONGLONG& i64Value) const
  1830. {
  1831. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1832. CHString s;
  1833. bool b = GetWBEMINT64(name, s);
  1834. if (b)
  1835. i64Value = _wtoi64(s);
  1836. return b;
  1837. }
  1838. ////////////////////////////////////////////////////////////////////////
  1839. //
  1840. // Function: SetWBEMINT16
  1841. //
  1842. //
  1843. //
  1844. // Inputs: const LPCWSTR name - Name of property to set
  1845. // const WBEMINT16& wbemint16 - Value to assign to Name.
  1846. //
  1847. // Outputs:
  1848. //
  1849. // Return: false if the supplied wbemint16 type is not correct
  1850. // for the property we are setting.
  1851. //
  1852. // Comments:
  1853. //
  1854. ////////////////////////////////////////////////////////////////////////
  1855. bool CInstance::SetWBEMINT16( LPCWSTR name, const WBEMINT16& wbemint16 )
  1856. {
  1857. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1858. bool bRet = false;
  1859. DWORD dwLastErr = 0;
  1860. if (m_piClassObject && name)
  1861. {
  1862. VARIANT v;
  1863. VariantInit(&v);
  1864. v.vt = VT_I2;
  1865. v.iVal = wbemint16;
  1866. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  1867. HRESULT hr = m_piClassObject->Put(name, 0, &v, NULL);
  1868. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1869. ASSERT_BREAK(SUCCEEDED(hr));
  1870. bRet = (bool)SUCCEEDED(hr);
  1871. if (!bRet)
  1872. {
  1873. dwLastErr = (hr);
  1874. LogError(IDS_FAILED, IDS_SETWBEMINT16, name, hr);
  1875. }
  1876. VariantClear(&v);
  1877. }
  1878. else
  1879. {
  1880. if (m_piClassObject)
  1881. {
  1882. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  1883. LogError(IDS_InParam, IDS_SETWBEMINT16);
  1884. }
  1885. else
  1886. {
  1887. dwLastErr = (WBEM_E_FAILED);
  1888. LogError(IDS_NOCLASS, IDS_SETWBEMINT16);
  1889. }
  1890. }
  1891. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  1892. SetLastError(dwLastErr);
  1893. return bRet;
  1894. }
  1895. ////////////////////////////////////////////////////////////////////////
  1896. //
  1897. // Function: GetWBEMINT16
  1898. //
  1899. //
  1900. //
  1901. // Inputs: const LPCWSTR name - Name of property to set
  1902. // WBEMINT16& wbemint16 - Value to assign to Name.
  1903. //
  1904. // Outputs:
  1905. //
  1906. // Return: false if the supplied wbemint16 type is not correct
  1907. // for the property we are setting.
  1908. //
  1909. // Comments:
  1910. //
  1911. ////////////////////////////////////////////////////////////////////////
  1912. bool CInstance::GetWBEMINT16( LPCWSTR name, WBEMINT16& wbemint16 ) const
  1913. {
  1914. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1915. bool bRet = false;
  1916. DWORD dwLastErr = 0;
  1917. if (m_piClassObject && name)
  1918. {
  1919. // Variant_t handles the VariantInit/VariantClear
  1920. variant_t v;
  1921. CIMTYPE vtType;
  1922. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  1923. HRESULT hr = m_piClassObject->Get(name, 0, &v, &vtType, NULL);
  1924. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1925. // If bSuccess is TRUE, we don't need to log an error. This keeps Gets on
  1926. // null properties from logging an error.
  1927. BOOL bSuccess = (SUCCEEDED(hr)) && (CIM_SINT16 == vtType) && ((v.vt == VT_I2) || (v.vt == VT_NULL));
  1928. ASSERT_BREAK(bSuccess);
  1929. if (SUCCEEDED(hr))
  1930. {
  1931. if ((vtType == CIM_SINT16) && (v.vt == VT_I2))
  1932. {
  1933. wbemint16 = v.iVal;
  1934. bRet = true;
  1935. }
  1936. else
  1937. {
  1938. dwLastErr = (WBEM_S_NO_MORE_DATA);
  1939. }
  1940. }
  1941. if (!bSuccess)
  1942. {
  1943. if (SUCCEEDED(hr))
  1944. {
  1945. hr = WBEM_E_TYPE_MISMATCH;
  1946. }
  1947. dwLastErr = (hr);
  1948. LogError(IDS_FAILED, IDS_GETWBEMINT16, name, hr);
  1949. }
  1950. }
  1951. else
  1952. {
  1953. if (m_piClassObject)
  1954. {
  1955. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  1956. LogError(IDS_InParam, IDS_GETWBEMINT16);
  1957. }
  1958. else
  1959. {
  1960. dwLastErr = (WBEM_E_FAILED);
  1961. LogError(IDS_NOCLASS, IDS_GETWBEMINT16);
  1962. }
  1963. }
  1964. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  1965. SetLastError(dwLastErr);
  1966. return bRet;
  1967. }
  1968. ////////////////////////////////////////////////////////////////////////
  1969. //
  1970. // Function: IsNull (LPCWSTR)
  1971. //
  1972. // Inputs: Name of property to check
  1973. //
  1974. // Outputs:
  1975. //
  1976. // Return: true if VT_NULL or (VT_BSTR and *bstr == NULL)
  1977. //
  1978. // Comments:
  1979. //
  1980. ////////////////////////////////////////////////////////////////////////
  1981. bool CInstance::IsNull(LPCWSTR name) const
  1982. {
  1983. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1984. bool bRet = true;
  1985. if (m_piClassObject && name)
  1986. {
  1987. // Variant_t handles the VariantInit/VariantClear
  1988. variant_t v;
  1989. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  1990. HRESULT hr = m_piClassObject->Get(name, 0, &v, NULL, NULL);
  1991. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  1992. if (SUCCEEDED(hr))
  1993. {
  1994. if (( v.vt != VT_NULL ) &&
  1995. ( (v.vt != VT_BSTR) || (v.bstrVal != NULL) ))
  1996. {
  1997. bRet = false;
  1998. }
  1999. else
  2000. {
  2001. bRet = true;
  2002. }
  2003. }
  2004. else
  2005. {
  2006. ASSERT_BREAK(0);
  2007. LogError(IDS_FAILED, IDS_CINSTANCEISNULL, name, hr);
  2008. }
  2009. }
  2010. else
  2011. {
  2012. ASSERT_BREAK(0);
  2013. if (m_piClassObject)
  2014. {
  2015. LogError(IDS_InParam, IDS_CINSTANCEISNULL);
  2016. }
  2017. else
  2018. {
  2019. LogError(IDS_NOCLASS, IDS_CINSTANCEISNULL);
  2020. }
  2021. }
  2022. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  2023. return bRet;
  2024. }
  2025. ////////////////////////////////////////////////////////////////////////
  2026. //
  2027. // Function: GetStatus (LPCWSTR, bool&,VARTYPE &)
  2028. //
  2029. //
  2030. //
  2031. // Inputs: Name of property to check
  2032. //
  2033. // Outputs:
  2034. //
  2035. // Return: true if succeeded, false otherwise
  2036. //
  2037. // Comments:
  2038. //
  2039. ////////////////////////////////////////////////////////////////////////
  2040. bool CInstance::GetStatus (LPCWSTR name, bool &a_Exists , VARTYPE &a_VarType ) const
  2041. {
  2042. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  2043. bool t_Status = true ;
  2044. DWORD dwLastErr = 0;
  2045. if (m_piClassObject && name)
  2046. {
  2047. // Variant_t handles the VariantInit/VariantClear
  2048. variant_t v;
  2049. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::WinMgmtTimer);
  2050. HRESULT hr = m_piClassObject->Get(name, 0, &v, NULL, NULL);
  2051. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::FrameworkTimer);
  2052. if (SUCCEEDED(hr))
  2053. {
  2054. a_Exists = true ;
  2055. a_VarType = v.vt ;
  2056. }
  2057. else
  2058. {
  2059. a_Exists = false ;
  2060. }
  2061. }
  2062. else
  2063. {
  2064. if (m_piClassObject)
  2065. {
  2066. dwLastErr = (WBEM_E_INVALID_PARAMETER);
  2067. }
  2068. else
  2069. {
  2070. dwLastErr = (WBEM_E_FAILED);
  2071. }
  2072. t_Status = false ;
  2073. }
  2074. PROVIDER_INSTRUMENTATION_START(m_pMethodContext, StopWatch::ProviderTimer);
  2075. SetLastError(dwLastErr);
  2076. return t_Status ;
  2077. }
  2078. ////////////////////////////////////////////////////////////////////////
  2079. MethodContext* CInstance::GetMethodContext() const
  2080. {
  2081. return m_pMethodContext;
  2082. }
  2083. ////////////////////////////////////////////////////////////////////////
  2084. void CInstance::LogError(LPCWSTR errorStr, LPCWSTR pFunctionName, LPCWSTR pArgs /*= NULL*/, HRESULT hError /*= -1*/) const
  2085. {
  2086. if (IsErrorLoggingEnabled())
  2087. {
  2088. CHString className(IDS_UNKNOWNCLASS);
  2089. // GetCHString("__NAME", className);
  2090. // okay, I'm NOT going through GetCHString to get this
  2091. // why? what happens if it fails? it tries to call this function...
  2092. // can you say "stack overflow?"
  2093. if (m_piClassObject)
  2094. {
  2095. // Variant_t handles the VariantInit/VariantClear
  2096. variant_t v;
  2097. HRESULT hr = m_piClassObject->Get(IDS_CLASS, 0, &v, NULL, NULL);
  2098. ASSERT_BREAK((SUCCEEDED(hr)) && ((v.vt == VT_NULL) || (v.vt == VT_BSTR)));
  2099. if (SUCCEEDED(hr))
  2100. {
  2101. if ( v.bstrVal != NULL
  2102. && v.vt != VT_NULL )
  2103. {
  2104. className = v.bstrVal;
  2105. }
  2106. }
  2107. }
  2108. // intent is that the error string look like:
  2109. // ERROR CInstance(Win32_UnlogicalDisk)::SetDoohicky(argVal) thing broke! error code: 0xFF1234
  2110. if (hError != -1)
  2111. {
  2112. if (pArgs == NULL)
  2113. {
  2114. LogErrorMessage6(L"%s%s)::%s %s error# %X", IDS_CINSTANCEERROR, (LPCWSTR)className, pFunctionName, errorStr, hError);
  2115. }
  2116. else
  2117. {
  2118. LogErrorMessage7(L"%s%s)::%s(%s) %s error# %X", IDS_CINSTANCEERROR, (LPCWSTR)className, pFunctionName, pArgs, errorStr, hError);
  2119. }
  2120. }
  2121. else
  2122. {
  2123. if (pArgs == NULL)
  2124. {
  2125. LogErrorMessage5(L"%s%s)::%s %s", IDS_CINSTANCEERROR, (LPCWSTR)className, pFunctionName, errorStr);
  2126. }
  2127. else
  2128. {
  2129. LogErrorMessage6(L"%s%s)::%s(%s) %s", IDS_CINSTANCEERROR, (LPCWSTR)className, pFunctionName, pArgs, errorStr);
  2130. }
  2131. }
  2132. }
  2133. }
  2134. bool CInstance::SetCHString(LPCWSTR name, const CHString& str)
  2135. {
  2136. return SetWCHARSplat(name, str);
  2137. }
  2138. bool CInstance::SetCHString(LPCWSTR name, LPCWSTR str)
  2139. {
  2140. return SetWCHARSplat(name, str);
  2141. }
  2142. bool CInstance::SetCharSplat(LPCWSTR name, LPCWSTR pStr)
  2143. {
  2144. return SetWCHARSplat(name, pStr);
  2145. }
  2146. bool CInstance::SetCHString(LPCWSTR name, LPCSTR str)
  2147. {
  2148. return SetWCHARSplat(name, CHString(str));
  2149. }
  2150. bool CInstance::SetCharSplat( LPCWSTR name, LPCSTR pStr)
  2151. {
  2152. return SetWCHARSplat(name, CHString(pStr));
  2153. }
  2154. bool CInstance::SetCharSplat(LPCWSTR name, DWORD dwResID)
  2155. {
  2156. ASSERT_BREAK(DEPRECATED);
  2157. SetLastError(WBEM_E_NOT_SUPPORTED);
  2158. return false;
  2159. }