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.

1786 lines
35 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. ProvResv.cpp
  5. Abstract:
  6. History:
  7. --*/
  8. #include "PreComp.h"
  9. #include <wbemint.h>
  10. #include <stdio.h>
  11. #include <NCObjApi.h>
  12. #include "Globals.h"
  13. #include "CGlobals.h"
  14. #include "ProvWsv.h"
  15. #include "ProvObSk.h"
  16. #include "Guids.h"
  17. enum { CALLED = 0, NOTCALLED = -1};
  18. inline int First(LONG& value)
  19. {
  20. return ( value<0 && InterlockedIncrement(&value)==0 );
  21. }
  22. /******************************************************************************
  23. *
  24. * Name:
  25. *
  26. *
  27. * Description:
  28. *
  29. *
  30. *****************************************************************************/
  31. #pragma warning( disable : 4355 )
  32. CInterceptor_IWbemObjectSink :: CInterceptor_IWbemObjectSink (
  33. IWbemObjectSink *a_InterceptedSink ,
  34. IUnknown *a_Unknown ,
  35. CWbemGlobal_IWmiObjectSinkController *a_Controller
  36. ) : ObjectSinkContainerElement (
  37. a_Controller ,
  38. this
  39. ) ,
  40. m_InterceptedSink ( a_InterceptedSink ) ,
  41. m_GateClosed ( FALSE ) ,
  42. m_InProgress ( 0 ) ,
  43. m_Unknown ( a_Unknown ) ,
  44. m_StatusCalled ( NOTCALLED ),
  45. m_SecurityDescriptor ( NULL )
  46. {
  47. InterlockedIncrement ( & DecoupledProviderSubSystem_Globals :: s_CInterceptor_IWbemObjectSink_ObjectsInProgress ) ;
  48. InterlockedIncrement (&DecoupledProviderSubSystem_Globals :: s_ObjectsInProgress);
  49. if ( m_Unknown )
  50. {
  51. m_Unknown->AddRef () ;
  52. }
  53. if ( m_InterceptedSink )
  54. {
  55. m_InterceptedSink->AddRef () ;
  56. }
  57. }
  58. #pragma warning( default : 4355 )
  59. /******************************************************************************
  60. *
  61. * Name:
  62. *
  63. *
  64. * Description:
  65. *
  66. *
  67. *****************************************************************************/
  68. CInterceptor_IWbemObjectSink::~CInterceptor_IWbemObjectSink ()
  69. {
  70. InterlockedDecrement ( & DecoupledProviderSubSystem_Globals :: s_CInterceptor_IWbemObjectSink_ObjectsInProgress ) ;
  71. InterlockedDecrement (&DecoupledProviderSubSystem_Globals :: s_ObjectsInProgress);
  72. }
  73. HRESULT CInterceptor_IWbemObjectSink :: Initialize ( SECURITY_DESCRIPTOR *a_SecurityDescriptor )
  74. {
  75. return DecoupledProviderSubSystem_Globals :: SinkAccessInitialize ( a_SecurityDescriptor , m_SecurityDescriptor ) ;
  76. }
  77. /******************************************************************************
  78. *
  79. * Name:
  80. *
  81. *
  82. * Description:
  83. *
  84. *
  85. *****************************************************************************/
  86. void CInterceptor_IWbemObjectSink :: CallBackRelease ()
  87. {
  88. #if 0
  89. OutputDebugString ( L"\nCInterceptor_IWbemObjectSink :: CallBackRelease ()" ) ;
  90. #endif
  91. if ( m_StatusCalled == NOTCALLED )
  92. {
  93. m_InterceptedSink->SetStatus (
  94. 0 ,
  95. WBEM_E_UNEXPECTED ,
  96. NULL ,
  97. NULL
  98. ) ;
  99. }
  100. if ( m_InterceptedSink )
  101. {
  102. m_InterceptedSink->Release () ;
  103. }
  104. if ( m_Unknown )
  105. {
  106. m_Unknown->Release () ;
  107. }
  108. delete [] (BYTE*) m_SecurityDescriptor;
  109. }
  110. /******************************************************************************
  111. *
  112. * Name:
  113. *
  114. *
  115. * Description:
  116. *
  117. *
  118. *****************************************************************************/
  119. STDMETHODIMP CInterceptor_IWbemObjectSink::QueryInterface (
  120. REFIID iid ,
  121. LPVOID FAR *iplpv
  122. )
  123. {
  124. *iplpv = NULL ;
  125. if ( iid == IID_IUnknown )
  126. {
  127. *iplpv = ( LPVOID ) this ;
  128. }
  129. else if ( iid == IID_IWbemObjectSink )
  130. {
  131. *iplpv = ( LPVOID ) ( IWbemObjectSink * ) this ;
  132. }
  133. else if ( iid == IID_IWbemShutdown )
  134. {
  135. *iplpv = ( LPVOID ) ( IWbemShutdown * ) this ;
  136. }
  137. if ( *iplpv )
  138. {
  139. ( ( LPUNKNOWN ) *iplpv )->AddRef () ;
  140. return ResultFromScode ( S_OK ) ;
  141. }
  142. else
  143. {
  144. return ResultFromScode ( E_NOINTERFACE ) ;
  145. }
  146. }
  147. /******************************************************************************
  148. *
  149. * Name:
  150. *
  151. *
  152. * Description:
  153. *
  154. *
  155. *****************************************************************************/
  156. STDMETHODIMP_(ULONG) CInterceptor_IWbemObjectSink :: AddRef ( void )
  157. {
  158. // printf ( "\nCInterceptor_IWbemObjectSink :: AddRef ()" ) ;
  159. return ObjectSinkContainerElement :: AddRef () ;
  160. }
  161. /******************************************************************************
  162. *
  163. * Name:
  164. *
  165. *
  166. * Description:
  167. *
  168. *
  169. *****************************************************************************/
  170. STDMETHODIMP_(ULONG) CInterceptor_IWbemObjectSink :: Release ( void )
  171. {
  172. #if 0
  173. OutputDebugString ( L"\nCInterceptor_IWbemObjectSink :: Release () " ) ;
  174. #endif
  175. return ObjectSinkContainerElement :: Release () ;
  176. }
  177. /******************************************************************************
  178. *
  179. * Name:
  180. *
  181. *
  182. * Description:
  183. *
  184. *
  185. *****************************************************************************/
  186. HRESULT CInterceptor_IWbemObjectSink :: Indicate (
  187. long a_ObjectCount ,
  188. IWbemClassObject **a_ObjectArray
  189. )
  190. {
  191. HRESULT t_Result = S_OK ;
  192. InterlockedIncrement ( & m_InProgress ) ;
  193. if ( m_GateClosed == 1 )
  194. {
  195. t_Result = WBEM_E_SHUTTING_DOWN ;
  196. }
  197. else
  198. {
  199. t_Result = m_InterceptedSink->Indicate (
  200. a_ObjectCount ,
  201. a_ObjectArray
  202. ) ;
  203. }
  204. InterlockedDecrement ( & m_InProgress ) ;
  205. return t_Result ;
  206. }
  207. /******************************************************************************
  208. *
  209. * Name:
  210. *
  211. *
  212. * Description:
  213. *
  214. *
  215. *****************************************************************************/
  216. HRESULT CInterceptor_IWbemObjectSink :: SetStatus (
  217. long a_Flags ,
  218. HRESULT a_Result ,
  219. BSTR a_StringParam ,
  220. IWbemClassObject *a_ObjectParam
  221. )
  222. {
  223. #if 0
  224. OutputDebugString ( L"\nCInterceptor_IWbemObjectSink :: SetStatus ()" ) ;
  225. #endif
  226. HRESULT t_Result = S_OK ;
  227. InterlockedIncrement ( & m_InProgress ) ;
  228. if ( m_GateClosed == 1 )
  229. {
  230. t_Result = WBEM_E_SHUTTING_DOWN ;
  231. }
  232. else
  233. {
  234. switch ( a_Flags )
  235. {
  236. case WBEM_STATUS_PROGRESS:
  237. {
  238. t_Result = m_InterceptedSink->SetStatus (
  239. a_Flags ,
  240. a_Result ,
  241. a_StringParam ,
  242. a_ObjectParam
  243. ) ;
  244. }
  245. break ;
  246. case WBEM_STATUS_COMPLETE:
  247. {
  248. if (First(m_StatusCalled))
  249. {
  250. t_Result = m_InterceptedSink->SetStatus (
  251. a_Flags ,
  252. a_Result ,
  253. a_StringParam ,
  254. a_ObjectParam
  255. ) ;
  256. }
  257. }
  258. break ;
  259. default:
  260. {
  261. t_Result = WBEM_E_INVALID_PARAMETER ;
  262. }
  263. break ;
  264. }
  265. }
  266. InterlockedDecrement ( & m_InProgress ) ;
  267. return t_Result ;
  268. }
  269. /******************************************************************************
  270. *
  271. * Name:
  272. *
  273. *
  274. * Description:
  275. *
  276. *
  277. *****************************************************************************/
  278. HRESULT CInterceptor_IWbemObjectSink :: Shutdown (
  279. LONG a_Flags ,
  280. ULONG a_MaxMilliSeconds ,
  281. IWbemContext *a_Context
  282. )
  283. {
  284. HRESULT t_Result = S_OK ;
  285. InterlockedIncrement ( & m_GateClosed ) ;
  286. bool t_Acquired = false ;
  287. while ( ! t_Acquired )
  288. {
  289. if ( m_InProgress == 0 )
  290. {
  291. t_Acquired = true ;
  292. if (First(m_StatusCalled))
  293. {
  294. t_Result = m_InterceptedSink->SetStatus (
  295. 0 ,
  296. WBEM_E_SHUTTING_DOWN ,
  297. NULL ,
  298. NULL
  299. ) ;
  300. }
  301. break ;
  302. }
  303. ::Sleep(0);
  304. }
  305. return t_Result ;
  306. }
  307. /******************************************************************************
  308. *
  309. * Name:
  310. *
  311. *
  312. * Description:
  313. *
  314. *
  315. *****************************************************************************/
  316. #pragma warning( disable : 4355 )
  317. CInterceptor_DecoupledIWbemObjectSink :: CInterceptor_DecoupledIWbemObjectSink (
  318. IWbemObjectSink *a_InterceptedSink ,
  319. IUnknown *a_Unknown ,
  320. CWbemGlobal_IWmiObjectSinkController *a_Controller
  321. ) : ObjectSinkContainerElement (
  322. a_Controller ,
  323. this
  324. ) ,
  325. m_InterceptedSink ( a_InterceptedSink ) ,
  326. m_GateClosed ( FALSE ) ,
  327. m_InProgress ( 0 ) ,
  328. m_Unknown ( a_Unknown ) ,
  329. m_StatusCalled ( NOTCALLED )
  330. {
  331. InterlockedIncrement ( & DecoupledProviderSubSystem_Globals :: s_CInterceptor_IWbemObjectSink_ObjectsInProgress ) ;
  332. InterlockedIncrement (&DecoupledProviderSubSystem_Globals :: s_ObjectsInProgress);
  333. if ( m_Unknown )
  334. {
  335. m_Unknown->AddRef () ;
  336. }
  337. if ( m_InterceptedSink )
  338. {
  339. m_InterceptedSink->AddRef () ;
  340. }
  341. }
  342. #pragma warning( default : 4355 )
  343. /******************************************************************************
  344. *
  345. * Name:
  346. *
  347. *
  348. * Description:
  349. *
  350. *
  351. *****************************************************************************/
  352. CInterceptor_DecoupledIWbemObjectSink::~CInterceptor_DecoupledIWbemObjectSink ()
  353. {
  354. InterlockedDecrement ( & DecoupledProviderSubSystem_Globals :: s_CInterceptor_IWbemObjectSink_ObjectsInProgress ) ;
  355. InterlockedDecrement (&DecoupledProviderSubSystem_Globals :: s_ObjectsInProgress);
  356. }
  357. /******************************************************************************
  358. *
  359. * Name:
  360. *
  361. *
  362. * Description:
  363. *
  364. *
  365. *****************************************************************************/
  366. void CInterceptor_DecoupledIWbemObjectSink :: CallBackRelease ()
  367. {
  368. #if 0
  369. OutputDebugString ( L"\nCInterceptor_DecoupledIWbemObjectSink :: CallBackRelease ()" ) ;
  370. #endif
  371. if ( m_StatusCalled == NOTCALLED )
  372. {
  373. m_InterceptedSink->SetStatus (
  374. 0 ,
  375. WBEM_E_UNEXPECTED ,
  376. NULL ,
  377. NULL
  378. ) ;
  379. }
  380. if ( m_InterceptedSink )
  381. {
  382. m_InterceptedSink->Release () ;
  383. }
  384. if ( m_Unknown )
  385. {
  386. m_Unknown->Release () ;
  387. }
  388. }
  389. /******************************************************************************
  390. *
  391. * Name:
  392. *
  393. *
  394. * Description:
  395. *
  396. *
  397. *****************************************************************************/
  398. STDMETHODIMP CInterceptor_DecoupledIWbemObjectSink::QueryInterface (
  399. REFIID iid ,
  400. LPVOID FAR *iplpv
  401. )
  402. {
  403. *iplpv = NULL ;
  404. if ( iid == IID_IUnknown )
  405. {
  406. *iplpv = ( LPVOID ) this ;
  407. }
  408. else if ( iid == IID_IWbemObjectSink )
  409. {
  410. *iplpv = ( LPVOID ) ( IWbemObjectSink * ) this ;
  411. }
  412. else if ( iid == IID_IWbemShutdown )
  413. {
  414. *iplpv = ( LPVOID ) ( IWbemShutdown * ) this ;
  415. }
  416. if ( *iplpv )
  417. {
  418. ( ( LPUNKNOWN ) *iplpv )->AddRef () ;
  419. return ResultFromScode ( S_OK ) ;
  420. }
  421. else
  422. {
  423. return ResultFromScode ( E_NOINTERFACE ) ;
  424. }
  425. }
  426. /******************************************************************************
  427. *
  428. * Name:
  429. *
  430. *
  431. * Description:
  432. *
  433. *
  434. *****************************************************************************/
  435. STDMETHODIMP_(ULONG) CInterceptor_DecoupledIWbemObjectSink :: AddRef ( void )
  436. {
  437. #if 0
  438. OutputDebugString ( L"\nCInterceptor_DecoupledIWbemObjectSink :: AddRef ()" ) ;
  439. #endif
  440. return ObjectSinkContainerElement :: AddRef () ;
  441. }
  442. /******************************************************************************
  443. *
  444. * Name:
  445. *
  446. *
  447. * Description:
  448. *
  449. *
  450. *****************************************************************************/
  451. STDMETHODIMP_(ULONG) CInterceptor_DecoupledIWbemObjectSink :: Release ( void )
  452. {
  453. #if 0
  454. OutputDebugString ( L"\nCInterceptor_DecoupledIWbemObjectSink :: Release () " ) ;
  455. #endif
  456. return ObjectSinkContainerElement :: Release () ;
  457. }
  458. /******************************************************************************
  459. *
  460. * Name:
  461. *
  462. *
  463. * Description:
  464. *
  465. *
  466. *****************************************************************************/
  467. HRESULT CInterceptor_DecoupledIWbemObjectSink :: Indicate (
  468. long a_ObjectCount ,
  469. IWbemClassObject **a_ObjectArray
  470. )
  471. {
  472. HRESULT t_Result = S_OK ;
  473. InterlockedIncrement ( & m_InProgress ) ;
  474. if ( m_GateClosed == 1 )
  475. {
  476. t_Result = WBEM_E_SHUTTING_DOWN ;
  477. }
  478. else
  479. {
  480. t_Result = m_InterceptedSink->Indicate (
  481. a_ObjectCount ,
  482. a_ObjectArray
  483. ) ;
  484. }
  485. InterlockedDecrement ( & m_InProgress ) ;
  486. return t_Result ;
  487. }
  488. /******************************************************************************
  489. *
  490. * Name:
  491. *
  492. *
  493. * Description:
  494. *
  495. *
  496. *****************************************************************************/
  497. HRESULT CInterceptor_DecoupledIWbemObjectSink :: SetStatus (
  498. long a_Flags ,
  499. HRESULT a_Result ,
  500. BSTR a_StringParam ,
  501. IWbemClassObject *a_ObjectParam
  502. )
  503. {
  504. #if 0
  505. OutputDebugString ( L"\nCInterceptor_DecoupledIWbemObjectSink :: SetStatus ()" ) ;
  506. #endif
  507. HRESULT t_Result = S_OK ;
  508. InterlockedIncrement ( & m_InProgress ) ;
  509. if ( m_GateClosed == 1 )
  510. {
  511. t_Result = WBEM_E_SHUTTING_DOWN ;
  512. }
  513. else
  514. {
  515. switch ( a_Flags )
  516. {
  517. case WBEM_STATUS_PROGRESS:
  518. {
  519. t_Result = m_InterceptedSink->SetStatus (
  520. a_Flags ,
  521. a_Result ,
  522. a_StringParam ,
  523. a_ObjectParam
  524. ) ;
  525. }
  526. break ;
  527. case WBEM_STATUS_COMPLETE:
  528. {
  529. if (First(m_StatusCalled))
  530. {
  531. t_Result = m_InterceptedSink->SetStatus (
  532. a_Flags ,
  533. a_Result ,
  534. a_StringParam ,
  535. a_ObjectParam
  536. ) ;
  537. }
  538. }
  539. break ;
  540. default:
  541. {
  542. t_Result = WBEM_E_INVALID_PARAMETER ;
  543. }
  544. break ;
  545. }
  546. }
  547. InterlockedDecrement ( & m_InProgress ) ;
  548. return t_Result ;
  549. }
  550. /******************************************************************************
  551. *
  552. * Name:
  553. *
  554. *
  555. * Description:
  556. *
  557. *
  558. *****************************************************************************/
  559. HRESULT CInterceptor_DecoupledIWbemObjectSink :: Shutdown (
  560. LONG a_Flags ,
  561. ULONG a_MaxMilliSeconds ,
  562. IWbemContext *a_Context
  563. )
  564. {
  565. HRESULT t_Result = S_OK ;
  566. InterlockedIncrement ( & m_GateClosed ) ;
  567. bool t_Acquired = false ;
  568. while ( ! t_Acquired )
  569. {
  570. if ( m_InProgress == 0 )
  571. {
  572. t_Acquired = true ;
  573. if (First(m_StatusCalled))
  574. {
  575. t_Result = m_InterceptedSink->SetStatus (
  576. 0 ,
  577. WBEM_E_SHUTTING_DOWN ,
  578. NULL ,
  579. NULL
  580. ) ;
  581. }
  582. break ;
  583. }
  584. ::Sleep(0);
  585. }
  586. return t_Result ;
  587. }
  588. /******************************************************************************
  589. *
  590. * Name:
  591. *
  592. *
  593. * Description:
  594. *
  595. *
  596. *****************************************************************************/
  597. #pragma warning( disable : 4355 )
  598. CInterceptor_IWbemFilteringObjectSink :: CInterceptor_IWbemFilteringObjectSink (
  599. IWbemObjectSink *a_InterceptedSink ,
  600. IUnknown *a_Unknown ,
  601. CWbemGlobal_IWmiObjectSinkController *a_Controller ,
  602. const BSTR a_QueryLanguage ,
  603. const BSTR a_Query
  604. ) : CInterceptor_IWbemObjectSink (
  605. a_InterceptedSink ,
  606. a_Unknown ,
  607. a_Controller
  608. ) ,
  609. m_Filtering ( FALSE ) ,
  610. m_QueryFilter ( NULL )
  611. {
  612. InterlockedIncrement ( & DecoupledProviderSubSystem_Globals :: s_CInterceptor_IWbemFilteringObjectSink_ObjectsInProgress ) ;
  613. InterlockedIncrement (&DecoupledProviderSubSystem_Globals :: s_ObjectsInProgress);
  614. if ( a_Query )
  615. {
  616. m_Query = SysAllocString ( a_Query ) ;
  617. }
  618. if ( a_QueryLanguage )
  619. {
  620. m_QueryLanguage = SysAllocString ( a_QueryLanguage ) ;
  621. }
  622. }
  623. #pragma warning( default : 4355 )
  624. /******************************************************************************
  625. *
  626. * Name:
  627. *
  628. *
  629. * Description:
  630. *
  631. *
  632. *****************************************************************************/
  633. CInterceptor_IWbemFilteringObjectSink::~CInterceptor_IWbemFilteringObjectSink ()
  634. {
  635. if ( m_QueryFilter )
  636. {
  637. m_QueryFilter->Release () ;
  638. }
  639. if ( m_Query )
  640. {
  641. SysFreeString ( m_Query ) ;
  642. }
  643. if ( m_QueryLanguage )
  644. {
  645. SysFreeString ( m_QueryLanguage ) ;
  646. }
  647. InterlockedDecrement ( & DecoupledProviderSubSystem_Globals :: s_CInterceptor_IWbemFilteringObjectSink_ObjectsInProgress ) ;
  648. InterlockedDecrement (&DecoupledProviderSubSystem_Globals :: s_ObjectsInProgress);
  649. }
  650. /******************************************************************************
  651. *
  652. * Name:
  653. *
  654. *
  655. * Description:
  656. *
  657. *
  658. *****************************************************************************/
  659. /******************************************************************************
  660. *
  661. * Name:
  662. *
  663. *
  664. * Description:
  665. *
  666. *
  667. *****************************************************************************/
  668. HRESULT CInterceptor_IWbemFilteringObjectSink :: Indicate (
  669. long a_ObjectCount ,
  670. IWbemClassObject **a_ObjectArray
  671. )
  672. {
  673. HRESULT t_Result = S_OK ;
  674. #if 0
  675. if ( m_Filtering )
  676. {
  677. for ( LONG t_Index = 0 ; t_Index < a_ObjectCount ; t_Index ++ )
  678. {
  679. if ( SUCCEEDED ( m_QueryFilter->TestObject ( 0 , 0 , IID_IWbemClassObject , ( void * ) a_ObjectArray [ t_Index ] ) ) )
  680. {
  681. t_Result = CInterceptor_IWbemObjectSink :: Indicate (
  682. t_Index ,
  683. & a_ObjectArray [ t_Index ]
  684. ) ;
  685. }
  686. }
  687. }
  688. else
  689. {
  690. t_Result = CInterceptor_IWbemObjectSink :: Indicate (
  691. a_ObjectCount ,
  692. a_ObjectArray
  693. ) ;
  694. }
  695. #else
  696. t_Result = CInterceptor_IWbemObjectSink :: Indicate (
  697. a_ObjectCount ,
  698. a_ObjectArray
  699. ) ;
  700. #endif
  701. return t_Result ;
  702. }
  703. /******************************************************************************
  704. *
  705. * Name:
  706. *
  707. *
  708. * Description:
  709. *
  710. *
  711. *****************************************************************************/
  712. HRESULT CInterceptor_IWbemFilteringObjectSink :: SetStatus (
  713. long a_Flags ,
  714. HRESULT a_Result ,
  715. BSTR a_StringParam ,
  716. IWbemClassObject *a_ObjectParam
  717. )
  718. {
  719. #if 0
  720. OutputDebugString ( L"\nCInterceptor_IWbemFilteringObjectSink :: SetStatus ()" ) ;
  721. #endif
  722. HRESULT t_Result = S_OK ;
  723. switch ( a_Flags )
  724. {
  725. case WBEM_STATUS_PROGRESS:
  726. {
  727. t_Result = CInterceptor_IWbemObjectSink :: SetStatus (
  728. a_Flags ,
  729. a_Result ,
  730. a_StringParam ,
  731. a_ObjectParam
  732. ) ;
  733. }
  734. break ;
  735. case WBEM_STATUS_COMPLETE:
  736. {
  737. t_Result = CInterceptor_IWbemObjectSink :: SetStatus (
  738. a_Flags ,
  739. a_Result ,
  740. a_StringParam ,
  741. a_ObjectParam
  742. ) ;
  743. }
  744. break ;
  745. case WBEM_STATUS_REQUIREMENTS:
  746. {
  747. #if 0
  748. if ( ! InterlockedCompareExchange ( & m_Filtering , 1 , 0 ) )
  749. {
  750. t_Result = ProviderSubSystem_Common_Globals :: CreateInstance (
  751. CLSID_WbemQuery ,
  752. NULL ,
  753. CLSCTX_INPROC_SERVER ,
  754. IID_IWbemQuery ,
  755. ( void ** ) & m_QueryFilter
  756. ) ;
  757. if ( SUCCEEDED ( t_Result ) )
  758. {
  759. t_Result = m_QueryFilter->Parse (
  760. m_QueryLanguage ,
  761. m_Query ,
  762. 0
  763. ) ;
  764. if ( SUCCEEDED ( t_Result ) )
  765. {
  766. }
  767. else
  768. {
  769. t_Result = WBEM_E_CRITICAL_ERROR ;
  770. }
  771. }
  772. else
  773. {
  774. t_Result = WBEM_E_CRITICAL_ERROR ;
  775. }
  776. }
  777. #else
  778. t_Result = CInterceptor_IWbemObjectSink :: SetStatus (
  779. a_Flags ,
  780. a_Result ,
  781. a_StringParam ,
  782. a_ObjectParam
  783. ) ;
  784. #endif
  785. }
  786. break;
  787. default:
  788. {
  789. t_Result = WBEM_E_INVALID_PARAMETER ;
  790. }
  791. break ;
  792. }
  793. return t_Result ;
  794. }
  795. /******************************************************************************
  796. *
  797. * Name:
  798. *
  799. *
  800. * Description:
  801. *
  802. *
  803. *****************************************************************************/
  804. #pragma warning( disable : 4355 )
  805. CInterceptor_DecoupledIWbemCombiningObjectSink :: CInterceptor_DecoupledIWbemCombiningObjectSink (
  806. WmiAllocator &a_Allocator ,
  807. IWbemObjectSink *a_InterceptedSink ,
  808. CWbemGlobal_IWmiObjectSinkController *a_Controller
  809. ) : CWbemGlobal_IWmiObjectSinkController ( a_Allocator ) ,
  810. ObjectSinkContainerElement (
  811. a_Controller ,
  812. this
  813. ) ,
  814. #if 0
  815. m_Internal ( this ) ,
  816. #endif
  817. m_InterceptedSink ( a_InterceptedSink ) ,
  818. m_Event ( NULL ) ,
  819. m_GateClosed ( FALSE ) ,
  820. m_InProgress ( 0 ) ,
  821. m_StatusCalled ( NOTCALLED ) ,
  822. m_SinkCount ( 0 )
  823. {
  824. InterlockedIncrement ( & DecoupledProviderSubSystem_Globals :: s_CInterceptor_IWbemCombiningObjectSink_ObjectsInProgress ) ;
  825. InterlockedIncrement (&DecoupledProviderSubSystem_Globals :: s_ObjectsInProgress) ;
  826. CWbemGlobal_IWmiObjectSinkController :: Initialize () ;
  827. if ( m_InterceptedSink )
  828. {
  829. m_InterceptedSink->AddRef () ;
  830. }
  831. m_Event = OS::CreateEvent ( NULL , FALSE , FALSE , NULL ) ;
  832. DWORD lastError = GetLastError();
  833. }
  834. #pragma warning( default : 4355 )
  835. /******************************************************************************
  836. *
  837. * Name:
  838. *
  839. *
  840. * Description:
  841. *
  842. *
  843. *****************************************************************************/
  844. CInterceptor_DecoupledIWbemCombiningObjectSink::~CInterceptor_DecoupledIWbemCombiningObjectSink ()
  845. {
  846. InterlockedDecrement ( & DecoupledProviderSubSystem_Globals :: s_CInterceptor_IWbemCombiningObjectSink_ObjectsInProgress ) ;
  847. InterlockedDecrement (&DecoupledProviderSubSystem_Globals :: s_ObjectsInProgress);
  848. }
  849. /******************************************************************************
  850. *
  851. * Name:
  852. *
  853. *
  854. * Description:
  855. *
  856. *
  857. *****************************************************************************/
  858. void CInterceptor_DecoupledIWbemCombiningObjectSink :: CallBackRelease ()
  859. {
  860. if ( m_InterceptedSink )
  861. {
  862. m_InterceptedSink->Release () ;
  863. }
  864. if ( m_Event )
  865. {
  866. CloseHandle ( m_Event ) ;
  867. }
  868. CWbemGlobal_IWmiObjectSinkController :: UnInitialize () ;
  869. }
  870. /******************************************************************************
  871. *
  872. * Name:
  873. *
  874. *
  875. * Description:
  876. *
  877. *
  878. *****************************************************************************/
  879. STDMETHODIMP CInterceptor_DecoupledIWbemCombiningObjectSink::QueryInterface (
  880. REFIID iid ,
  881. LPVOID FAR *iplpv
  882. )
  883. {
  884. *iplpv = NULL ;
  885. if ( iid == IID_IUnknown )
  886. {
  887. *iplpv = ( LPVOID ) this ;
  888. }
  889. else if ( iid == IID_IWbemObjectSink )
  890. {
  891. *iplpv = ( LPVOID ) ( IWbemObjectSink * ) this ;
  892. }
  893. else if ( iid == IID_IWbemShutdown )
  894. {
  895. *iplpv = ( LPVOID ) ( IWbemShutdown * ) this ;
  896. }
  897. #if 0
  898. else if ( iid == IID_CWbemCombiningObjectSink )
  899. {
  900. *iplpv = ( LPVOID ) & ( this->m_Internal ) ;
  901. }
  902. #endif
  903. if ( *iplpv )
  904. {
  905. ( ( LPUNKNOWN ) *iplpv )->AddRef () ;
  906. return ResultFromScode ( S_OK ) ;
  907. }
  908. else
  909. {
  910. return ResultFromScode ( E_NOINTERFACE ) ;
  911. }
  912. }
  913. /******************************************************************************
  914. *
  915. * Name:
  916. *
  917. *
  918. * Description:
  919. *
  920. *
  921. *****************************************************************************/
  922. STDMETHODIMP_( ULONG ) CInterceptor_DecoupledIWbemCombiningObjectSink :: AddRef ()
  923. {
  924. #if 0
  925. OutputDebugString ( L"\nCInterceptor_DecoupledIWbemCombiningObjectSink :: AddRef ()" ) ;
  926. #endif
  927. return ObjectSinkContainerElement :: AddRef () ;
  928. }
  929. /******************************************************************************
  930. *
  931. * Name:
  932. *
  933. *
  934. * Description:
  935. *
  936. *
  937. *****************************************************************************/
  938. STDMETHODIMP_(ULONG) CInterceptor_DecoupledIWbemCombiningObjectSink :: Release ()
  939. {
  940. #if 0
  941. OutputDebugString ( L"\nCInterceptor_DecoupledIWbemCombiningObjectSink :: Release ()" ) ;
  942. #endif
  943. return ObjectSinkContainerElement :: Release () ;
  944. }
  945. /******************************************************************************
  946. *
  947. * Name:
  948. *
  949. *
  950. * Description:
  951. *
  952. *
  953. *****************************************************************************/
  954. HRESULT CInterceptor_DecoupledIWbemCombiningObjectSink :: Indicate (
  955. long a_ObjectCount ,
  956. IWbemClassObject **a_ObjectArray
  957. )
  958. {
  959. HRESULT t_Result = S_OK ;
  960. InterlockedIncrement ( & m_InProgress ) ;
  961. if ( m_GateClosed == 1 )
  962. {
  963. t_Result = WBEM_E_SHUTTING_DOWN ;
  964. }
  965. else
  966. {
  967. t_Result = m_InterceptedSink->Indicate (
  968. a_ObjectCount ,
  969. a_ObjectArray
  970. ) ;
  971. }
  972. InterlockedDecrement ( & m_InProgress ) ;
  973. return t_Result ;
  974. }
  975. /******************************************************************************
  976. *
  977. * Name:
  978. *
  979. *
  980. * Description:
  981. *
  982. *
  983. *****************************************************************************/
  984. HRESULT CInterceptor_DecoupledIWbemCombiningObjectSink :: SetStatus (
  985. long a_Flags ,
  986. HRESULT a_Result ,
  987. BSTR a_StringParam ,
  988. IWbemClassObject *a_ObjectParam
  989. )
  990. {
  991. #if 0
  992. OutputDebugString ( L"\nCInterceptor_DecoupledIWbemCombiningObjectSink :: SetStatus ()" ) ;
  993. #endif
  994. HRESULT t_Result = S_OK ;
  995. InterlockedIncrement ( & m_InProgress ) ;
  996. if ( m_GateClosed == 1 )
  997. {
  998. t_Result = WBEM_E_SHUTTING_DOWN ;
  999. }
  1000. else
  1001. {
  1002. if ( FAILED ( a_Result ) )
  1003. {
  1004. ULONG t_SinkCount = InterlockedDecrement ( & m_SinkCount ) ;
  1005. if (t_SinkCount == 0)
  1006. {
  1007. if (First(m_StatusCalled))
  1008. {
  1009. t_Result = m_InterceptedSink->SetStatus (
  1010. WBEM_STATUS_COMPLETE ,
  1011. a_Result ,
  1012. NULL ,
  1013. NULL
  1014. ) ;
  1015. SetEvent ( m_Event ) ;
  1016. }
  1017. }
  1018. }
  1019. else
  1020. {
  1021. ULONG t_SinkCount = InterlockedDecrement ( & m_SinkCount ) ;
  1022. if ( t_SinkCount == 0 )
  1023. {
  1024. if (First(m_StatusCalled))
  1025. {
  1026. t_Result = m_InterceptedSink->SetStatus (
  1027. 0 ,
  1028. S_OK ,
  1029. NULL ,
  1030. NULL
  1031. ) ;
  1032. SetEvent ( m_Event ) ;
  1033. }
  1034. }
  1035. }
  1036. }
  1037. InterlockedDecrement ( & m_InProgress ) ;
  1038. return t_Result ;
  1039. }
  1040. /******************************************************************************
  1041. *
  1042. * Name:
  1043. *
  1044. *
  1045. * Description:
  1046. *
  1047. *
  1048. *****************************************************************************/
  1049. HRESULT CInterceptor_DecoupledIWbemCombiningObjectSink :: Shutdown (
  1050. LONG a_Flags ,
  1051. ULONG a_MaxMilliSeconds ,
  1052. IWbemContext *a_Context
  1053. )
  1054. {
  1055. HRESULT t_Result = S_OK ;
  1056. InterlockedIncrement ( & m_GateClosed ) ;
  1057. bool t_Acquired = false ;
  1058. while ( ! t_Acquired )
  1059. {
  1060. if ( m_InProgress == 0 )
  1061. {
  1062. t_Acquired = true ;
  1063. if (First(m_StatusCalled))
  1064. {
  1065. t_Result = m_InterceptedSink->SetStatus (
  1066. 0 ,
  1067. WBEM_E_SHUTTING_DOWN ,
  1068. NULL ,
  1069. NULL
  1070. ) ;
  1071. }
  1072. break ;
  1073. }
  1074. ::Sleep(0);
  1075. }
  1076. return t_Result ;
  1077. }
  1078. /******************************************************************************
  1079. *
  1080. * Name:
  1081. *
  1082. *
  1083. * Description:
  1084. *
  1085. *
  1086. *****************************************************************************/
  1087. HRESULT CInterceptor_DecoupledIWbemCombiningObjectSink :: Wait ( ULONG a_Timeout )
  1088. {
  1089. HRESULT t_Result = S_OK ;
  1090. ULONG t_Status = WaitForSingleObject ( m_Event , a_Timeout ) ;
  1091. switch ( t_Status )
  1092. {
  1093. case WAIT_TIMEOUT:
  1094. {
  1095. t_Result = WBEM_E_TIMED_OUT ;
  1096. }
  1097. break ;
  1098. case WAIT_OBJECT_0:
  1099. {
  1100. }
  1101. break ;
  1102. default:
  1103. {
  1104. t_Result = WBEM_E_FAILED ;
  1105. }
  1106. break ;
  1107. }
  1108. return t_Result ;
  1109. }
  1110. /******************************************************************************
  1111. *
  1112. * Name:
  1113. *
  1114. *
  1115. * Description:
  1116. *
  1117. *
  1118. *****************************************************************************/
  1119. HRESULT CInterceptor_DecoupledIWbemCombiningObjectSink :: EnQueue ( CInterceptor_DecoupledIWbemObjectSink *a_Sink )
  1120. {
  1121. HRESULT t_Result = S_OK ;
  1122. CWbemGlobal_IWmiObjectSinkController_Container_Iterator t_Iterator ;
  1123. Lock () ;
  1124. WmiStatusCode t_StatusCode = Insert (
  1125. *a_Sink ,
  1126. t_Iterator
  1127. ) ;
  1128. UnLock () ;
  1129. if ( t_StatusCode == e_StatusCode_Success )
  1130. {
  1131. InterlockedIncrement ( & m_SinkCount ) ;
  1132. }
  1133. else
  1134. {
  1135. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1136. }
  1137. return t_Result ;
  1138. }
  1139. /******************************************************************************
  1140. *
  1141. * Name:
  1142. *
  1143. *
  1144. * Description:
  1145. *
  1146. *
  1147. *****************************************************************************/
  1148. void CInterceptor_DecoupledIWbemCombiningObjectSink :: Suspend ()
  1149. {
  1150. InterlockedIncrement ( & m_SinkCount ) ;
  1151. }
  1152. /******************************************************************************
  1153. *
  1154. * Name:
  1155. *
  1156. *
  1157. * Description:
  1158. *
  1159. *
  1160. *****************************************************************************/
  1161. void CInterceptor_DecoupledIWbemCombiningObjectSink :: Resume ()
  1162. {
  1163. ULONG t_ReferenceCount = InterlockedDecrement ( & m_SinkCount ) ;
  1164. if ( t_ReferenceCount == 0 )
  1165. {
  1166. InterlockedIncrement ( & m_InProgress ) ;
  1167. if ( m_GateClosed == 1 )
  1168. {
  1169. }
  1170. else
  1171. {
  1172. if (First(m_StatusCalled))
  1173. {
  1174. HRESULT t_Result = m_InterceptedSink->SetStatus (
  1175. WBEM_STATUS_COMPLETE ,
  1176. S_OK ,
  1177. NULL ,
  1178. NULL
  1179. ) ;
  1180. SetEvent ( m_Event ) ;
  1181. }
  1182. }
  1183. InterlockedDecrement ( & m_InProgress ) ;
  1184. }
  1185. }
  1186. /******************************************************************************
  1187. *
  1188. * Name:
  1189. *
  1190. *
  1191. * Description:
  1192. *
  1193. *
  1194. *****************************************************************************/
  1195. #pragma warning( disable : 4355 )
  1196. CInterceptor_IWbemWaitingObjectSink :: CInterceptor_IWbemWaitingObjectSink (
  1197. WmiAllocator &a_Allocator ,
  1198. CWbemGlobal_IWmiObjectSinkController *a_Controller
  1199. ) : CWbemGlobal_IWmiObjectSinkController ( a_Allocator ) ,
  1200. ObjectSinkContainerElement (
  1201. a_Controller ,
  1202. this
  1203. ) ,
  1204. m_Queue ( a_Allocator ) ,
  1205. m_Event ( NULL ) ,
  1206. m_GateClosed ( FALSE ) ,
  1207. m_InProgress ( 0 ) ,
  1208. m_StatusCalled ( NOTCALLED ) ,
  1209. m_Result ( S_OK ) ,
  1210. m_CriticalSection(NOTHROW_LOCK)
  1211. {
  1212. InterlockedIncrement ( & DecoupledProviderSubSystem_Globals :: s_CInterceptor_IWbemWaitingObjectSink_ObjectsInProgress ) ;
  1213. InterlockedIncrement (&DecoupledProviderSubSystem_Globals :: s_ObjectsInProgress);
  1214. WmiStatusCode t_StatusCode = m_Queue.Initialize () ;
  1215. CWbemGlobal_IWmiObjectSinkController :: Initialize () ;
  1216. m_Event = OS::CreateEvent ( NULL , FALSE , FALSE , NULL ) ;
  1217. DWORD lastError = GetLastError();
  1218. }
  1219. #pragma warning( default : 4355 )
  1220. /******************************************************************************
  1221. *
  1222. * Name:
  1223. *
  1224. *
  1225. * Description:
  1226. *
  1227. *
  1228. *****************************************************************************/
  1229. CInterceptor_IWbemWaitingObjectSink::~CInterceptor_IWbemWaitingObjectSink ()
  1230. {
  1231. if ( m_Event )
  1232. {
  1233. CloseHandle ( m_Event ) ;
  1234. }
  1235. ULONG t_Count = m_Queue.Size();
  1236. for ( ULONG t_Index = 0 ; t_Index < t_Count ; t_Index ++ )
  1237. {
  1238. IWbemClassObject *t_ClassObject ;
  1239. WmiStatusCode t_StatusCode = m_Queue.Top ( t_ClassObject ) ;
  1240. if ( t_StatusCode == e_StatusCode_Success )
  1241. {
  1242. t_ClassObject->Release () ;
  1243. t_StatusCode = m_Queue.DeQueue () ;
  1244. }
  1245. }
  1246. m_Queue.UnInitialize () ;
  1247. CWbemGlobal_IWmiObjectSinkController :: UnInitialize () ;
  1248. InterlockedDecrement ( & DecoupledProviderSubSystem_Globals :: s_CInterceptor_IWbemWaitingObjectSink_ObjectsInProgress ) ;
  1249. InterlockedDecrement (&DecoupledProviderSubSystem_Globals :: s_ObjectsInProgress);
  1250. }
  1251. /******************************************************************************
  1252. *
  1253. * Name:
  1254. *
  1255. *
  1256. * Description:
  1257. *
  1258. *
  1259. *****************************************************************************/
  1260. STDMETHODIMP CInterceptor_IWbemWaitingObjectSink::QueryInterface (
  1261. REFIID iid ,
  1262. LPVOID FAR *iplpv
  1263. )
  1264. {
  1265. *iplpv = NULL ;
  1266. if ( iid == IID_IUnknown )
  1267. {
  1268. *iplpv = ( LPVOID ) this ;
  1269. }
  1270. else if ( iid == IID_IWbemObjectSink )
  1271. {
  1272. *iplpv = ( LPVOID ) ( IWbemObjectSink * ) this ;
  1273. }
  1274. else if ( iid == IID_IWbemShutdown )
  1275. {
  1276. *iplpv = ( LPVOID ) ( IWbemShutdown * ) this ;
  1277. }
  1278. if ( *iplpv )
  1279. {
  1280. ( ( LPUNKNOWN ) *iplpv )->AddRef () ;
  1281. return ResultFromScode ( S_OK ) ;
  1282. }
  1283. else
  1284. {
  1285. return ResultFromScode ( E_NOINTERFACE ) ;
  1286. }
  1287. }
  1288. /******************************************************************************
  1289. *
  1290. * Name:
  1291. *
  1292. *
  1293. * Description:
  1294. *
  1295. *
  1296. *****************************************************************************/
  1297. STDMETHODIMP_( ULONG ) CInterceptor_IWbemWaitingObjectSink :: AddRef ()
  1298. {
  1299. return ObjectSinkContainerElement :: AddRef () ;
  1300. }
  1301. /******************************************************************************
  1302. *
  1303. * Name:
  1304. *
  1305. *
  1306. * Description:
  1307. *
  1308. *
  1309. *****************************************************************************/
  1310. STDMETHODIMP_(ULONG) CInterceptor_IWbemWaitingObjectSink :: Release ()
  1311. {
  1312. #if 0
  1313. OutputDebugString ( L"\nCInterceptor_IWbemWaitingObjectSink :: Release ()" ) ;
  1314. #endif
  1315. return ObjectSinkContainerElement :: Release () ;
  1316. }
  1317. /******************************************************************************
  1318. *
  1319. * Name:
  1320. *
  1321. *
  1322. * Description:
  1323. *
  1324. *
  1325. *****************************************************************************/
  1326. HRESULT CInterceptor_IWbemWaitingObjectSink :: Indicate (
  1327. long a_ObjectCount ,
  1328. IWbemClassObject **a_ObjectArray
  1329. )
  1330. {
  1331. HRESULT t_Result = S_OK ;
  1332. InterlockedIncrement ( & m_InProgress ) ;
  1333. if ( m_GateClosed == 1 )
  1334. {
  1335. t_Result = WBEM_E_SHUTTING_DOWN ;
  1336. }
  1337. else
  1338. {
  1339. LockGuard<CriticalSection> monitor( m_CriticalSection ) ;
  1340. if (monitor.locked())
  1341. {
  1342. for ( LONG t_Index = 0 ; t_Index < a_ObjectCount ; t_Index ++ )
  1343. {
  1344. WmiStatusCode t_StatusCode = m_Queue.EnQueue ( a_ObjectArray [ t_Index ] ) ;
  1345. if ( t_StatusCode == e_StatusCode_Success )
  1346. {
  1347. a_ObjectArray [ t_Index ]->AddRef () ;
  1348. }
  1349. else
  1350. {
  1351. if ( SUCCEEDED ( t_Result ) )
  1352. {
  1353. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1354. }
  1355. }
  1356. }
  1357. }
  1358. else
  1359. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1360. }
  1361. InterlockedDecrement ( & m_InProgress ) ;
  1362. return t_Result ;
  1363. }
  1364. /******************************************************************************
  1365. *
  1366. * Name:
  1367. *
  1368. *
  1369. * Description:
  1370. *
  1371. *
  1372. *****************************************************************************/
  1373. HRESULT CInterceptor_IWbemWaitingObjectSink :: SetStatus (
  1374. long a_Flags ,
  1375. HRESULT a_Result ,
  1376. BSTR a_StringParam ,
  1377. IWbemClassObject *a_ObjectParam
  1378. )
  1379. {
  1380. #if 0
  1381. OutputDebugString ( L"\nCInterceptor_IWbemWaitingObjectSink :: SetStatus ()" ) ;
  1382. #endif
  1383. HRESULT t_Result = S_OK ;
  1384. InterlockedIncrement ( & m_InProgress ) ;
  1385. if ( m_GateClosed == 1 )
  1386. {
  1387. t_Result = WBEM_E_SHUTTING_DOWN ;
  1388. }
  1389. else
  1390. {
  1391. if (First(m_StatusCalled))
  1392. {
  1393. if ( SUCCEEDED ( m_Result ) )
  1394. {
  1395. m_Result = a_Result ;
  1396. }
  1397. SetEvent ( m_Event ) ;
  1398. }
  1399. }
  1400. InterlockedDecrement ( & m_InProgress ) ;
  1401. return t_Result ;
  1402. }
  1403. /******************************************************************************
  1404. *
  1405. * Name:
  1406. *
  1407. *
  1408. * Description:
  1409. *
  1410. *
  1411. *****************************************************************************/
  1412. HRESULT CInterceptor_IWbemWaitingObjectSink :: Shutdown (
  1413. LONG a_Flags ,
  1414. ULONG a_MaxMilliSeconds ,
  1415. IWbemContext *a_Context
  1416. )
  1417. {
  1418. HRESULT t_Result = S_OK ;
  1419. InterlockedIncrement ( & m_GateClosed ) ;
  1420. bool t_Acquired = false ;
  1421. while ( ! t_Acquired )
  1422. {
  1423. if ( m_InProgress == 0 )
  1424. {
  1425. t_Acquired = true ;
  1426. if (First(m_StatusCalled))
  1427. {
  1428. m_Result = WBEM_E_SHUTTING_DOWN ;
  1429. SetEvent ( m_Event ) ;
  1430. }
  1431. break ;
  1432. }
  1433. ::Sleep(0);
  1434. }
  1435. return t_Result ;
  1436. }
  1437. /******************************************************************************
  1438. *
  1439. * Name:
  1440. *
  1441. *
  1442. * Description:
  1443. *
  1444. *
  1445. *****************************************************************************/
  1446. HRESULT CInterceptor_IWbemWaitingObjectSink :: Wait ( ULONG a_Timeout )
  1447. {
  1448. HRESULT t_Result = S_OK ;
  1449. ULONG t_Status = WaitForSingleObject ( m_Event , a_Timeout ) ;
  1450. switch ( t_Status )
  1451. {
  1452. case WAIT_TIMEOUT:
  1453. {
  1454. t_Result = WBEM_E_TIMED_OUT ;
  1455. }
  1456. break ;
  1457. case WAIT_OBJECT_0:
  1458. {
  1459. }
  1460. break ;
  1461. default:
  1462. {
  1463. t_Result = WBEM_E_FAILED ;
  1464. }
  1465. break ;
  1466. }
  1467. return t_Result ;
  1468. }