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.

208 lines
4.0 KiB

  1. //=================================================================
  2. //
  3. // EventProvider.cpp -- Generic class for eventing
  4. //
  5. // Copyright (c) 2000-2001 Microsoft Corporation, All Rights Reserved
  6. //
  7. //=================================================================
  8. #include "precomp.h"
  9. #include <assertbreak.h>
  10. #include "FactoryRouter.h"
  11. #include "EventProvider.h"
  12. extern CFactoryRouterData g_FactoryRouterData;
  13. //=================================================================
  14. //
  15. // CEventProvider
  16. //
  17. // abstract base for providing eventing services
  18. //
  19. //
  20. //=================================================================
  21. //
  22. CEventProvider::CEventProvider() :
  23. m_ReferenceCount( 0 )
  24. {
  25. g_FactoryRouterData.AddLock();
  26. }
  27. //
  28. CEventProvider::~CEventProvider()
  29. {
  30. // m_pHandler is a smartptr and will self destruct
  31. // m_pClass is a smartptr and will self destruct
  32. g_FactoryRouterData.ReleaseLock();
  33. }
  34. //
  35. STDMETHODIMP_( ULONG ) CEventProvider::AddRef()
  36. {
  37. LogMessage2(L"*************CEventProvider AddRef: %ld",m_ReferenceCount+1 );
  38. return InterlockedIncrement( &m_ReferenceCount ) ;
  39. }
  40. //
  41. STDMETHODIMP_(ULONG) CEventProvider::Release()
  42. {
  43. LogMessage2(L"*************CEventProvider AddRef: %ld",m_ReferenceCount-1 );
  44. LONG t_ref = InterlockedDecrement( &m_ReferenceCount );
  45. try
  46. {
  47. if (IsVerboseLoggingEnabled())
  48. {
  49. LogMessage2(L"CEventProvider::Release, count is (approx) %d", m_ReferenceCount);
  50. }
  51. }
  52. catch ( ... )
  53. {
  54. }
  55. if ( t_ref == 0 )
  56. {
  57. try
  58. {
  59. LogMessage(L"CFactoryRouter Ref Count = 0");
  60. }
  61. catch ( ... )
  62. {
  63. }
  64. OnFinalRelease();
  65. }
  66. else if (t_ref > 0x80000000)
  67. {
  68. ASSERT_BREAK(DUPLICATE_RELEASE);
  69. LogErrorMessage(L"Duplicate CFactoryRouter Release()");
  70. }
  71. return t_ref ;
  72. }
  73. //
  74. STDMETHODIMP CEventProvider::QueryInterface(
  75. REFIID a_riid,
  76. LPVOID FAR *a_ppvObj
  77. )
  78. {
  79. if( IsEqualIID( a_riid, IID_IUnknown ) )
  80. {
  81. *a_ppvObj = static_cast<IWbemProviderInit *>(this) ;
  82. }
  83. else if( IsEqualIID( a_riid, IID_IWbemProviderInit ) )
  84. {
  85. *a_ppvObj = static_cast<IWbemProviderInit *>(this) ;
  86. }
  87. else if( IsEqualIID( a_riid, IID_IWbemEventProvider ) )
  88. {
  89. *a_ppvObj = static_cast<IWbemEventProvider *>(this) ;
  90. }
  91. else
  92. {
  93. *a_ppvObj = NULL ;
  94. return E_NOINTERFACE ;
  95. }
  96. AddRef() ;
  97. return NOERROR ;
  98. }
  99. //
  100. STDMETHODIMP CEventProvider::Initialize(
  101. LPWSTR a_wszUser,
  102. long a_lFlags,
  103. LPWSTR a_wszNamespace,
  104. LPWSTR a_wszLocale,
  105. IWbemServices *a_pNamespace,
  106. IWbemContext *a_pCtx,
  107. IWbemProviderInitSink *a_pSink
  108. )
  109. {
  110. IWbemClassObjectPtr t_pClass ;
  111. bstr_t bstrClassName(GetClassName(), false);
  112. HRESULT t_hRes = a_pNamespace->GetObject( bstrClassName,
  113. 0,
  114. a_pCtx,
  115. &t_pClass,
  116. NULL ) ;
  117. // ptr initialization routines
  118. SetClass( t_pClass ) ;
  119. return a_pSink->SetStatus( t_hRes, 0 ) ;
  120. }
  121. //
  122. STDMETHODIMP CEventProvider::ProvideEvents(
  123. IWbemObjectSink __RPC_FAR *a_pSink,
  124. long a_lFlags
  125. )
  126. {
  127. SetHandler( a_pSink ) ;
  128. // notify instance
  129. ProvideEvents() ;
  130. return S_OK ;
  131. }
  132. //
  133. void CEventProvider::SetClass(
  134. IWbemClassObject __RPC_FAR *a_pClass
  135. )
  136. {
  137. CInCritSec ics( &m_cs ) ;
  138. m_pClass = a_pClass ;
  139. }
  140. //
  141. IWbemClassObject __RPC_FAR * CEventProvider::GetClass()
  142. {
  143. CInCritSec ics(&m_cs ) ;
  144. IWbemClassObject __RPC_FAR *t_pClass ;
  145. m_pClass->AddRef() ;
  146. t_pClass = m_pClass ;
  147. return t_pClass ;
  148. }
  149. //
  150. void CEventProvider::SetHandler(
  151. IWbemObjectSink __RPC_FAR *a_pHandler
  152. )
  153. {
  154. CInCritSec ics(&m_cs ) ;
  155. m_pHandler = a_pHandler ;
  156. }
  157. //
  158. IWbemObjectSink __RPC_FAR * CEventProvider::GetHandler()
  159. {
  160. IWbemObjectSink __RPC_FAR *t_pHandler ;
  161. CInCritSec ics(&m_cs );
  162. m_pHandler->AddRef();
  163. t_pHandler = m_pHandler ;
  164. return t_pHandler ;
  165. }