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.

132 lines
4.0 KiB

  1. // Connection.h: interface for the CConnection class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_CONNECTION_H__59B02D24_0BC7_11D2_BDCC_00C04FA35447__INCLUDED_)
  5. #define AFX_CONNECTION_H__59B02D24_0BC7_11D2_BDCC_00C04FA35447__INCLUDED_
  6. #if _MSC_VER >= 1000
  7. #pragma once
  8. #endif // _MSC_VER >= 1000
  9. #define SCHEMA_MAJOR_VERSION 2
  10. #define SCHEMA_MINOR_VERSION 1
  11. #define IDS_STRING_HMCATSTATUS_QUERY _T("select * from __InstanceModificationEvent where TargetInstance isa \"HMCatStatus\"")
  12. #define IDS_STRING_HMEVENT_QUERY _T("select * from __InstanceCreationEvent where TargetInstance isa \"HMEvent\"")
  13. #define IDS_STRING_HMMACHSTATUS_QUERY _T("select * from __InstanceModificationEvent where TargetInstance isa \"HMMachStatus\"")
  14. #define IDS_STRING_HMSYSTEMSTATUS_QUERY _T("select * from __InstanceModificationEvent where TargetInstance isa \"Microsoft_HMSystemStatus\"")
  15. #define IDS_STRING_HMCONFIGCREATE_QUERY _T("select * from __InstanceCreationEvent where TargetInstance isa \"Microsoft_HMConfiguration\"")
  16. #define IDS_STRING_HMCONFIGDELETE_QUERY _T("select * from __InstanceDeletionEvent where TargetInstance isa \"Microsoft_HMConfiguration\"")
  17. enum HMClassType { HMEvent, HMMachStatus, HMCatStatus, HMSystemStatus, HMConfig, AsyncQuery };
  18. //////////////////////////////////////////////////////////////////////
  19. // class CEventRegistrationEntry
  20. //////////////////////////////////////////////////////////////////////
  21. class CEventRegistrationEntry : public CObject
  22. {
  23. DECLARE_DYNCREATE(CEventRegistrationEntry)
  24. // Constructors
  25. public:
  26. CEventRegistrationEntry();
  27. CEventRegistrationEntry(CString sQuery, IWbemObjectSink* pSink);
  28. // Destructor
  29. public:
  30. ~CEventRegistrationEntry();
  31. // SetStatus
  32. public:
  33. HRESULT NotifyConsole(long lFlag, HRESULT hr);
  34. // SendEvents
  35. HRESULT SendInstances(IWbemServices*& pServices, long lFlag);
  36. // Attributes
  37. public:
  38. CString m_sQuery;
  39. BOOL m_bRegistered;
  40. IWbemObjectSink* m_pSink;
  41. HMClassType m_eType;
  42. BSTR m_bsClassName;
  43. };
  44. //////////////////////////////////////////////////////////////////////
  45. // class CConnection
  46. //////////////////////////////////////////////////////////////////////
  47. class CConnection : public CObject
  48. {
  49. DECLARE_DYNCREATE(CConnection)
  50. public:
  51. // Constructor/Destructor
  52. CConnection(BSTR bsMachineName, IWbemLocator* pIWbemLocator);
  53. CConnection();
  54. virtual ~CConnection();
  55. // Helper functions
  56. public:
  57. BOOL AddEventEntry(const CString& sQuery, IWbemObjectSink*& pSink);
  58. BOOL RemoveEventEntry(IWbemObjectSink*& pSink);
  59. int GetEventConsumerCount() { return (int)m_EventConsumers.GetSize(); }
  60. private:
  61. void StartMonitor();
  62. void StopMonitor();
  63. void Init();
  64. // Event operations
  65. HRESULT RegisterAllEvents();
  66. void UnRegisterAllEvents();
  67. void RemoveAllEventEntries();
  68. inline HRESULT NotifyConsole(HRESULT hRes);
  69. // Connection Operation
  70. HRESULT Connect();
  71. inline BOOL PingMachine();
  72. inline void SetConnectionStatus(BOOL bFlag);
  73. inline HRESULT IsAgentReady();
  74. inline HRESULT IsAgentCorrectVersion();
  75. // Winmgmt Namespace operations
  76. private:
  77. inline HRESULT ConnectToNamespace(BSTR bsNamespace = NULL);
  78. // data members
  79. public:
  80. IWbemServices* m_pIWbemServices;
  81. BOOL m_bAvailable;
  82. HRESULT m_hrLastConnectResult;
  83. private:
  84. IWbemLocator* m_pIWbemLocator;
  85. BSTR m_bsMachineName;
  86. CString m_sNamespace;
  87. BOOL m_bFirstConnect;
  88. DWORD m_dwPollInterval;
  89. CTypedPtrArray<CObArray,CEventRegistrationEntry*> m_EventConsumers;
  90. //zzz Connection/Registration sync. object
  91. HANDLE m_hReadyToConnect;
  92. // Static thread function to monitor connection status
  93. protected:
  94. static unsigned int __stdcall MonitorConnection(void *pv);
  95. void CheckConnection();
  96. protected:
  97. HANDLE m_hThread; // thread handle
  98. unsigned m_threadID; // thread id
  99. struct threadData // thread data structure
  100. {
  101. CConnection* m_bkptr;
  102. HANDLE m_hDie;
  103. HANDLE m_hDead;
  104. }
  105. m_threadData;
  106. };
  107. #endif // !defined(AFX_CONNECTION_H__59B02D24_0BC7_11D2_BDCC_00C04FA35447__INCLUDED_)