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.

1740 lines
34 KiB

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