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.

129 lines
2.9 KiB

  1. //=============================================================================
  2. //
  3. // Copyright (c) 1996-1999, Microsoft Corporation, All rights reserved
  4. //
  5. // COREFIND.CPP
  6. //
  7. // This file implements classes needed to search for event filters matching an
  8. // event.
  9. //
  10. // See corefind.h for documentation.
  11. //
  12. // History:
  13. //
  14. // 11/27/96 a-levn Inefficient version compiles.
  15. // 4/13/00 levn Efficient version works.
  16. //
  17. //=============================================================================
  18. #include "precomp.h"
  19. #include <stdio.h>
  20. #include "ess.h"
  21. #include "corefind.h"
  22. CCoreEventProvider::CCoreEventProvider(CLifeControl* pControl)
  23. : TUnkBase(pControl), m_pNamespace(NULL), m_pSink(NULL)
  24. {
  25. }
  26. CCoreEventProvider::~CCoreEventProvider()
  27. {
  28. Shutdown();
  29. }
  30. HRESULT CCoreEventProvider::Shutdown()
  31. {
  32. if ( m_pNamespace )
  33. {
  34. CInEssSharedLock( &m_Lock, TRUE );
  35. if ( m_pSink != NULL )
  36. {
  37. m_pSink->Release();
  38. m_pSink = NULL;
  39. }
  40. }
  41. return WBEM_S_NO_ERROR;
  42. }
  43. HRESULT CCoreEventProvider::SetNamespace( CEssNamespace* pNamespace )
  44. {
  45. _DBG_ASSERT( m_pNamespace == NULL );
  46. //
  47. // don't hold reference, else there would be a circular ref.
  48. // We are guaranteed that as long as the we're alive the namespace will
  49. // be alive.
  50. //
  51. if ( m_Lock.Initialize() )
  52. {
  53. m_pNamespace = pNamespace;
  54. return S_OK;
  55. }
  56. return WBEM_E_OUT_OF_MEMORY;
  57. }
  58. STDMETHODIMP CCoreEventProvider::ProvideEvents( IWbemObjectSink* pSink,
  59. long lFlags )
  60. {
  61. CInEssSharedLock isl( &m_Lock, TRUE );
  62. _DBG_ASSERT( m_pSink == NULL );
  63. HRESULT hres;
  64. hres = pSink->QueryInterface(IID_IWbemEventSink, (void**)&m_pSink);
  65. if(FAILED(hres))
  66. return hres;
  67. return S_OK;
  68. }
  69. HRESULT CCoreEventProvider::Fire( CEventRepresentation& Event,
  70. CEventContext* pContext )
  71. {
  72. //
  73. // it is important to hold the shared lock the entire time because
  74. // we must ensure that we're not going to use the sink after shutdown
  75. // is called.
  76. //
  77. CInEssSharedLock isl( &m_Lock, FALSE );
  78. //
  79. // Check if the sink is active
  80. //
  81. if ( m_pSink == NULL || m_pSink->IsActive() != WBEM_S_NO_ERROR )
  82. {
  83. return WBEM_S_FALSE;
  84. }
  85. //
  86. // Convert to real event
  87. //
  88. IWbemClassObject* pEvent;
  89. HRESULT hres = Event.MakeWbemObject(m_pNamespace, &pEvent);
  90. if(FAILED(hres))
  91. return hres;
  92. CReleaseMe rm2(pEvent);
  93. if ( pContext != NULL && pContext->GetSD() != NULL )
  94. {
  95. hres = SetSD( pEvent, pContext->GetSD() );
  96. if ( FAILED(hres) )
  97. return hres;
  98. }
  99. //
  100. // Fire it
  101. //
  102. hres = m_pSink->Indicate(1, (IWbemClassObject**)&pEvent);
  103. return hres;
  104. }