Source code of Windows XP (NT5)
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.

107 lines
3.4 KiB

  1. //******************************************************************************
  2. //
  3. // Copyright (c) 1999-2000, Microsoft Corporation, All rights reserved
  4. //
  5. //*****************************************************************************
  6. #ifndef __WBEM_MONITOR_PROVIDER__H_
  7. #define __WBEM_MONITOR_PROVIDER__H_
  8. #include "monitor.h"
  9. #include <map>
  10. class CMonitorProvider :
  11. public CUnkBase<IWbemEventProvider, &IID_IWbemEventProvider>
  12. {
  13. protected:
  14. STDMETHOD(ProvideEvents)(IWbemObjectSink* pSink, long lFlags);
  15. protected:
  16. CEssNamespace* m_pNamespace;
  17. IWbemEventSink* m_pSink;
  18. CCritSec m_cs;
  19. typedef std::map<WString, CMonitor*, WSiless> TMap;
  20. typedef TMap::iterator TIterator;
  21. TMap m_mapMonitors;
  22. _IWmiObject* m_pAssertClass;
  23. _IWmiObject* m_pRetractClass;
  24. _IWmiObject* m_pGoingUpClass;
  25. _IWmiObject* m_pGoingDownClass;
  26. _IWmiObject* m_pErrorClass;
  27. long m_lNameHandle;
  28. long m_lObjectHandle;
  29. long m_lCountHandle;
  30. long m_lNewHandle;
  31. public:
  32. CMonitorProvider(CLifeControl* pControl = NULL);
  33. ~CMonitorProvider();
  34. HRESULT SetNamespace(CEssNamespace* pNamespace);
  35. HRESULT Shutdown();
  36. HRESULT AddMonitor(LPCWSTR wszName, LPCWSTR wszQuery, long lFlags,
  37. IWbemContext* pContext);
  38. HRESULT RemoveMonitor(LPCWSTR wszName, IWbemContext* pContext);
  39. static HRESULT GetMonitorInfo(IWbemClassObject* pMonitorObj,
  40. BSTR* pstrKey, BSTR* pstrQuery, long* plFlags);
  41. protected:
  42. friend class CFiringMonitorCallback;
  43. INTERNAL IWbemEventSink* GetSink() {return m_pSink;}
  44. HRESULT ConstructAssert(LPCWSTR wszName, _IWmiObject* pObj, bool bEvent,
  45. DWORD dwTotalCount, _IWmiObject** ppEvent);
  46. HRESULT ConstructRetract(LPCWSTR wszName, _IWmiObject* pObj, bool bEvent,
  47. DWORD dwTotalCount, _IWmiObject** ppEvent);
  48. HRESULT ConstructGoingUp(LPCWSTR wszName, DWORD dwNumMatching,
  49. _IWmiObject** ppEvent);
  50. HRESULT ConstructGoingDown(LPCWSTR wszName, DWORD dwNumMatching,
  51. _IWmiObject** ppEvent);
  52. HRESULT ConstructError(LPCWSTR wszName, HRESULT hresError,
  53. IWbemClassObject* pErrorObj, _IWmiObject** ppEvent);
  54. private:
  55. HRESULT GetInstance(_IWmiObject* pClass, LPCWSTR wszName, DWORD dwCount,
  56. _IWmiObject** ppEvent);
  57. HRESULT SetObject(_IWmiObject* pEvent, _IWmiObject* pObj, bool bFromEvent);
  58. };
  59. class CFiringMonitorCallback : public CMonitorCallback
  60. {
  61. protected:
  62. long m_lRef;
  63. CMonitorProvider* m_pProvider;
  64. WString m_wsName;
  65. IWbemEventSink* m_pSink;
  66. public:
  67. CFiringMonitorCallback(CMonitorProvider* pProvider, LPCWSTR wszName);
  68. ~CFiringMonitorCallback();
  69. HRESULT Initialize();
  70. LPCWSTR GetName() {return m_wsName;}
  71. virtual ULONG STDMETHODCALLTYPE AddRef();
  72. virtual ULONG STDMETHODCALLTYPE Release();
  73. virtual HRESULT Assert(_IWmiObject* pObj, LPCWSTR wszPath, bool bEvent,
  74. DWORD dwTotalCount);
  75. virtual HRESULT Retract(_IWmiObject* pObj, LPCWSTR wszPath, bool bEvent,
  76. DWORD dwTotalCount);
  77. virtual HRESULT GoingUp(DWORD dwNumMatching);
  78. virtual HRESULT GoingDown(DWORD dwNumMatching);
  79. virtual HRESULT Error(HRESULT hresError, IWbemClassObject* pErrorObj);
  80. protected:
  81. bool CheckSink();
  82. HRESULT FireEvent(_IWmiObject* pEvent);
  83. };
  84. #endif