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.

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