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.

203 lines
5.7 KiB

  1. #ifndef __FEVPROV_H__
  2. #define __FEVPROV_H__
  3. #include <unk.h>
  4. #include <comutl.h>
  5. #include <wbemcli.h>
  6. #include <wbemprov.h>
  7. #include <wmimsg.h>
  8. #include "fwdhdr.h"
  9. class CFwdEventProv : public CUnk
  10. {
  11. class XProv : public CImpl< IWbemEventProvider, CFwdEventProv >
  12. {
  13. public:
  14. STDMETHOD(ProvideEvents)( IWbemObjectSink* pSink, long lFlags )
  15. {
  16. return m_pObject->ProvideEvents( pSink, lFlags );
  17. }
  18. XProv( CFwdEventProv* pObj )
  19. : CImpl<IWbemEventProvider, CFwdEventProv> ( pObj ) {}
  20. } m_XProv;
  21. class XQuery : public CImpl<IWbemEventProviderQuerySink, CFwdEventProv>
  22. {
  23. public:
  24. STDMETHOD(NewQuery)( DWORD dwId, LPWSTR wszLanguage, LPWSTR wszQuery )
  25. {
  26. return m_pObject->NewQuery( dwId, wszQuery );
  27. }
  28. STDMETHOD(CancelQuery)( DWORD dwId )
  29. {
  30. return m_pObject->CancelQuery( dwId );
  31. }
  32. XQuery( CFwdEventProv* pObj)
  33. : CImpl<IWbemEventProviderQuerySink, CFwdEventProv> ( pObj ) {}
  34. } m_XQuery;
  35. class XInit : public CImpl<IWbemProviderInit, CFwdEventProv>
  36. {
  37. public:
  38. STDMETHOD(Initialize)( LPWSTR wszUser,
  39. LONG lFlags,
  40. LPWSTR wszNamespace,
  41. LPWSTR wszLocale,
  42. IWbemServices* pNamespace,
  43. IWbemContext* pContext,
  44. IWbemProviderInitSink* pInitSink )
  45. {
  46. return m_pObject->Init( pNamespace, pInitSink );
  47. }
  48. XInit( CFwdEventProv* pObj)
  49. : CImpl<IWbemProviderInit, CFwdEventProv>(pObj) { }
  50. } m_XInit;
  51. //
  52. // the next two interface impls are not associated with this objects's
  53. // identity. Reasons is there would be a circular ref problem if they
  54. // were because we hold onto the receiver, which in turn holds on to
  55. // the send/recv and error sink objects.
  56. //
  57. class XSendReceive : public IWmiMessageSendReceive
  58. {
  59. CFwdEventProv* m_pOwner; // no add-ref or circular reference.
  60. STDMETHOD(QueryInterface)(REFIID riid, void** ppv)
  61. {
  62. if ( riid == IID_IUnknown || riid == IID_IWmiMessageSendReceive )
  63. {
  64. *ppv = this;
  65. return S_OK;
  66. }
  67. return E_NOINTERFACE;
  68. }
  69. STDMETHOD_(ULONG, AddRef)() { return 1; }
  70. STDMETHOD_(ULONG, Release)() { return 1; }
  71. public:
  72. STDMETHOD(SendReceive)( PBYTE pData,
  73. ULONG cData,
  74. PBYTE pAuxData,
  75. ULONG cAuxData,
  76. DWORD dwFlagStatus,
  77. IUnknown* pCtx )
  78. {
  79. return m_pOwner->Receive( pData,
  80. cData,
  81. pAuxData,
  82. cAuxData,
  83. dwFlagStatus,
  84. pCtx );
  85. }
  86. XSendReceive( CFwdEventProv* pOwner ) : m_pOwner( pOwner ) { }
  87. } m_XSendReceive;
  88. class XErrorSink : public IWmiMessageTraceSink
  89. {
  90. CFwdEventProv* m_pOwner; // no add-ref or circular reference.
  91. STDMETHOD(QueryInterface)(REFIID riid, void** ppv)
  92. {
  93. if ( riid == IID_IUnknown || riid == IID_IWmiMessageTraceSink )
  94. {
  95. *ppv = this;
  96. return S_OK;
  97. }
  98. return E_NOINTERFACE;
  99. }
  100. STDMETHOD_(ULONG, AddRef)() { return 1; }
  101. STDMETHOD_(ULONG, Release)() { return 1; }
  102. public:
  103. STDMETHOD(Notify)( HRESULT hRes,
  104. GUID guidSource,
  105. LPCWSTR wszError,
  106. IUnknown* pCtx )
  107. {
  108. return m_pOwner->HandleRecvError( hRes, wszError );
  109. }
  110. XErrorSink( CFwdEventProv* pOwner ) : m_pOwner( pOwner ) { }
  111. } m_XErrorSink;
  112. CWbemPtr<IWbemServices> m_pSvc;
  113. CWbemPtr<IWbemObjectSink> m_pEventSink;
  114. CWbemPtr<IWbemClassObject> m_pEventClass;
  115. CWbemPtr<IWbemClassObject> m_pDataClass;
  116. CWbemPtr<IWmiObjectMarshal> m_pMrsh;
  117. CWbemPtr<IWmiMessageReceiver> m_pDcomRcvr;
  118. CWbemPtr<IWmiMessageReceiver> m_apQueueRcvr[16];
  119. long m_lMachineProp;
  120. long m_lConsumerProp;
  121. long m_lNamespaceProp;
  122. long m_lAuthProp;
  123. long m_lSDProp;
  124. long m_lAccountProp;
  125. long m_lTimeProp;
  126. HRESULT InitializeQueues( BOOL bAllowUnauth );
  127. HRESULT InitializeReceivers( BOOL bAllowUnauth );
  128. HRESULT InitializeEvent( IWbemClassObject* pOriginalEvent,
  129. IWmiMessageReceiverContext* pRecvCtx,
  130. LPCWSTR wszConsumer,
  131. LPCWSTR wszNamespace,
  132. PBYTE pSD,
  133. ULONG cSD,
  134. IWbemClassObject* pEvent );
  135. void* GetInterface( REFIID riid );
  136. public:
  137. CFwdEventProv( CLifeControl* pCtl, IUnknown* pUnk = NULL );
  138. virtual ~CFwdEventProv();
  139. HRESULT Init( IWbemServices* pSvc, IWbemProviderInitSink* pInitSink);
  140. HRESULT ProvideEvents( IWbemObjectSink* pSink, long lFlags );
  141. HRESULT NewQuery( DWORD dwId, LPWSTR wszQuery );
  142. HRESULT CancelQuery( DWORD dwId );
  143. HRESULT HandleRecvError( HRESULT hRes, LPCWSTR wszError );
  144. HRESULT Receive( PBYTE pData,
  145. ULONG cData,
  146. PBYTE pAuxData,
  147. ULONG cAuxData,
  148. DWORD dwFlagStatus,
  149. IUnknown* pCtx );
  150. };
  151. #endif // __FEVPROV_H__