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.

165 lines
4.3 KiB

  1. // ConnectionManager.h: interface for the CConnectionManager class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_CONNECTIONMANAGER_H__F0E5AFBD_0204_11D2_8355_0000F87A3912__INCLUDED_)
  5. #define AFX_CONNECTIONMANAGER_H__F0E5AFBD_0204_11D2_8355_0000F87A3912__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. #include <ConnMgr.h>
  10. // error reporting defines
  11. #define _ERRORDESCLEN _MAX_PATH*4
  12. #define _ERRORNAMELEN _MAX_PATH
  13. #define _FACILITYLEN _MAX_PATH
  14. //////////////////////////////////////////////////////////////////////
  15. // class CMarshalledConnection
  16. //////////////////////////////////////////////////////////////////////
  17. class CMarshalledConnection
  18. {
  19. // Constructors
  20. public:
  21. CMarshalledConnection();
  22. // Operations
  23. public:
  24. HRESULT Marshal(IConnectionManager* pIConMgr);
  25. HRESULT UnMarshal();
  26. IConnectionManager* GetConnection();
  27. // Attributes
  28. protected:
  29. IConnectionManager* m_pIMarshalledConnectionManager;
  30. LPSTREAM m_lpMarshalStream;
  31. };
  32. //////////////////////////////////////////////////////////////////////
  33. // class CConnectionManager
  34. //////////////////////////////////////////////////////////////////////
  35. class CConnectionManager : public CObject
  36. {
  37. DECLARE_DYNCREATE(CConnectionManager)
  38. // Constructors
  39. public:
  40. CConnectionManager();
  41. // Destructor
  42. public:
  43. virtual ~CConnectionManager();
  44. // Create/Destroy
  45. public:
  46. BOOL Create();
  47. void Destroy();
  48. // Connection Operations
  49. public:
  50. HRESULT GetConnection(const CString& sMachineName, IWbemServices*& pIWbemServices, BOOL& bAvailable );
  51. HRESULT ConnectToNamespace(const CString& sNamespace, IWbemServices*& pIWbemServices);
  52. HRESULT RemoveConnection(const CString& sMachineName, IWbemObjectSink* pSink);
  53. // Query Operations
  54. public:
  55. HRESULT ExecQueryAsync(const CString& sMachineName, const CString& sQuery, IWbemObjectSink*& pSink);
  56. // Event Operations
  57. public:
  58. HRESULT RegisterEventNotification(const CString& sMachineName, const CString& sQuery, IWbemObjectSink*& pSink);
  59. // Error Display Operations
  60. public:
  61. void DisplayErrorMsgBox(HRESULT hr, const CString& sMachineName);
  62. void GetErrorString(HRESULT hr, const CString& sMachineName, CString& sErrorText);
  63. // Marshalling Operations
  64. public:
  65. HRESULT MarshalCnxMgr();
  66. HRESULT UnMarshalCnxMgr();
  67. void CleanUpMarshalCnxMgr();
  68. // Implementation Operations
  69. protected:
  70. void DecodeHResult(HRESULT hr, LPTSTR pszFacility, LPTSTR pszErrorName, LPTSTR pszErrorDesc);
  71. void HandleConnMgrException(HRESULT hr);
  72. // Implementation Attributes
  73. protected:
  74. IConnectionManager* m_pIConnectionManager;
  75. CMap<DWORD,DWORD,CMarshalledConnection*,CMarshalledConnection*> m_MarshalMap;
  76. CTypedPtrList<CPtrList,CMarshalledConnection*> m_MarshalStack;
  77. };
  78. extern CConnectionManager theCnxManager;
  79. inline HRESULT CnxGetConnection(const CString& sMachineName, IWbemServices*& pIWbemServices, BOOL& bAvailable)
  80. {
  81. return theCnxManager.GetConnection(sMachineName,pIWbemServices,bAvailable);
  82. }
  83. inline HRESULT CnxConnectToNamespace(const CString& sNamespace, IWbemServices*& pIWbemServices)
  84. {
  85. return theCnxManager.ConnectToNamespace(sNamespace,pIWbemServices);
  86. }
  87. inline HRESULT CnxRemoveConnection(const CString& sMachineName, IWbemObjectSink* pSink)
  88. {
  89. return theCnxManager.RemoveConnection(sMachineName,pSink);
  90. }
  91. inline BOOL CnxCreate()
  92. {
  93. return theCnxManager.Create();
  94. }
  95. inline void CnxDestroy()
  96. {
  97. theCnxManager.Destroy();
  98. }
  99. inline HRESULT CnxExecQueryAsync(const CString& sMachineName, const CString& sQuery, IWbemObjectSink*& pSink)
  100. {
  101. return theCnxManager.ExecQueryAsync(sMachineName,sQuery,pSink);
  102. }
  103. inline HRESULT CnxRegisterEventNotification(const CString& sMachineName, const CString& sQuery, IWbemObjectSink*& pSink)
  104. {
  105. return theCnxManager.RegisterEventNotification(sMachineName,sQuery,pSink);
  106. }
  107. inline void CnxPropertyPageInit()
  108. {
  109. theCnxManager.MarshalCnxMgr();
  110. }
  111. inline void CnxPropertyPageCreate()
  112. {
  113. theCnxManager.UnMarshalCnxMgr();
  114. }
  115. inline void CnxPropertyPageDestroy()
  116. {
  117. theCnxManager.CleanUpMarshalCnxMgr();
  118. }
  119. inline void CnxDisplayErrorMsgBox(HRESULT hr, const CString& sMachineName)
  120. {
  121. theCnxManager.DisplayErrorMsgBox(hr,sMachineName);
  122. }
  123. inline void CnxGetErrorString(HRESULT hr, const CString& sMachineName, CString& sErrorText)
  124. {
  125. theCnxManager.GetErrorString(hr,sMachineName,sErrorText);
  126. }
  127. #endif // !defined(AFX_CONNECTIONMANAGER_H__F0E5AFBD_0204_11D2_8355_0000F87A3912__INCLUDED_)