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.

230 lines
5.6 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) Microsoft Corporation
  4. //
  5. // SYNOPSIS
  6. //
  7. // Declares the classes CConnectionToServer and CLoggingConnectionToServer.
  8. //
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef CONNECTIONTOSERVER_H
  11. #define CONNECTIONTOSERVER_H
  12. #pragma once
  13. #include "DialogWithWorkerThread.h"
  14. #include "sdoias.h"
  15. class CMachineNode;
  16. class CLoggingMachineNode;
  17. enum CONNECTION_STATUS
  18. {
  19. NO_CONNECTION_ATTEMPTED = 0,
  20. CONNECTING,
  21. CONNECTED,
  22. CONNECTION_ATTEMPT_FAILED,
  23. CONNECTION_INTERRUPTED,
  24. UNKNOWN
  25. };
  26. // Simple class to managing marshalling an interface to a stream.
  27. template <class T>
  28. class InterfaceStream
  29. {
  30. public:
  31. InterfaceStream() throw ();
  32. // Use compiler-generated version.
  33. // ~InterfaceStream() throw ();
  34. HRESULT Put(IUnknown* pUnk) throw ();
  35. HRESULT Get(T** ppv) throw ();
  36. bool IsEmpty() const throw ();
  37. private:
  38. CComPtr<IStream> stream;
  39. // Not implemented.
  40. InterfaceStream(const InterfaceStream&);
  41. InterfaceStream& operator=(const InterfaceStream&);
  42. };
  43. class CConnectionToServer : public CDialogWithWorkerThread<CConnectionToServer>
  44. {
  45. public:
  46. CConnectionToServer(
  47. CMachineNode* pServerNode,
  48. BSTR bstrServerAddress,
  49. BOOL fExtendingIAS,
  50. bool fNeedDictionary = true
  51. ) throw ();
  52. ~CConnectionToServer() throw ();
  53. DWORD DoWorkerThreadAction() throw ();
  54. CONNECTION_STATUS GetConnectionStatus() throw ();
  55. HRESULT GetSdoDictionaryOld(
  56. ISdoDictionaryOld **ppSdoDictionaryOld
  57. ) throw ();
  58. HRESULT GetSdoService(ISdo** ppSdo) throw ();
  59. HRESULT ReloadSdo(
  60. ISdo** ppSdoService,
  61. ISdoDictionaryOld** ppSdoDictionaryOld
  62. ) throw ();
  63. protected:
  64. static const DWORD CONNECT_NO_ERROR = 0;
  65. static const DWORD CONNECT_SERVER_NOT_SUPPORTED = 1;
  66. static const DWORD CONNECT_FAILED = MAXDWORD;
  67. // Start the connect action.
  68. HRESULT BeginConnect() throw ();
  69. private:
  70. // The machine SDO is created by the main thread and marshalled to the
  71. // worker thread.
  72. CComPtr<ISdoMachine> m_spSdoMachine;
  73. InterfaceStream<ISdoMachine> m_spMachineStream;
  74. // The service and dictionary SDOs are created by the worker thread and
  75. // marshalled to the main thread.
  76. InterfaceStream<ISdo> m_spServiceStream;
  77. CComPtr<ISdo> m_spSdo;
  78. InterfaceStream<ISdoDictionaryOld> m_spDnaryStream;
  79. CComPtr<ISdoDictionaryOld> m_spSdoDictionaryOld;
  80. CMachineNode* m_pMachineNode;
  81. CComBSTR m_bstrServerAddress;
  82. BOOL m_fExtendingIAS;
  83. bool m_fNeedDictionary;
  84. wchar_t m_szLocalComputerName[IAS_MAX_COMPUTERNAME_LENGTH];
  85. // Not implemented.
  86. CConnectionToServer(const CConnectionToServer&);
  87. CConnectionToServer& operator=(const CConnectionToServer&);
  88. public:
  89. // This is the ID of the dialog resource we want for this class.
  90. // An enum is used here because the correct value of
  91. // IDD must be initialized before the base class's constructor is called
  92. enum { IDD = IDD_CONNECT_TO_MACHINE };
  93. BEGIN_MSG_MAP(CConnectionToServer)
  94. MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
  95. COMMAND_ID_HANDLER( IDCANCEL, OnCancel )
  96. CHAIN_MSG_MAP(CDialogWithWorkerThread<CConnectionToServer>)
  97. END_MSG_MAP()
  98. LRESULT OnInitDialog(
  99. UINT uMsg,
  100. WPARAM wParam,
  101. LPARAM lParam,
  102. BOOL& bHandled
  103. ) throw ();
  104. LRESULT OnCancel(
  105. UINT uMsg
  106. , WPARAM wParam
  107. , HWND hwnd
  108. , BOOL& bHandled
  109. );
  110. LRESULT OnReceiveThreadMessage(
  111. UINT uMsg
  112. , WPARAM wParam
  113. , LPARAM lParam
  114. , BOOL& bHandled
  115. );
  116. };
  117. class CLoggingConnectionToServer : public CConnectionToServer
  118. {
  119. public:
  120. CLoggingConnectionToServer(
  121. CLoggingMachineNode* pServerNode,
  122. BSTR bstrServerAddress,
  123. BOOL fExtendingIAS
  124. ) throw ();
  125. ~CLoggingConnectionToServer() throw ();
  126. private:
  127. CLoggingMachineNode* m_pMachineNode;
  128. // Not implemented.
  129. CLoggingConnectionToServer(const CLoggingConnectionToServer&);
  130. CLoggingConnectionToServer& operator=(const CLoggingConnectionToServer&);
  131. public:
  132. BEGIN_MSG_MAP(CLoggingConnectionToServer)
  133. MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
  134. CHAIN_MSG_MAP(CConnectionToServer)
  135. END_MSG_MAP()
  136. LRESULT OnInitDialog(
  137. UINT uMsg
  138. , WPARAM wParam
  139. , LPARAM lParam
  140. , BOOL& bHandled
  141. );
  142. LRESULT OnReceiveThreadMessage(
  143. UINT uMsg
  144. , WPARAM wParam
  145. , LPARAM lParam
  146. , BOOL& bHandled
  147. );
  148. };
  149. template <class T>
  150. inline InterfaceStream<T>::InterfaceStream() throw ()
  151. {
  152. }
  153. template <class T>
  154. inline HRESULT InterfaceStream<T>::Put(IUnknown* pUnk) throw ()
  155. {
  156. CComPtr<IStream> newStream;
  157. HRESULT hr = CoMarshalInterThreadInterfaceInStream(
  158. __uuidof(T),
  159. pUnk,
  160. &newStream
  161. );
  162. if (SUCCEEDED(hr))
  163. {
  164. stream = newStream;
  165. }
  166. return hr;
  167. }
  168. template <class T>
  169. inline HRESULT InterfaceStream<T>::Get(T** ppv) throw ()
  170. {
  171. HRESULT hr = CoGetInterfaceAndReleaseStream(
  172. stream,
  173. __uuidof(T),
  174. reinterpret_cast<void**>(ppv)
  175. );
  176. stream.p = 0;
  177. return hr;
  178. }
  179. template <class T>
  180. inline bool InterfaceStream<T>::IsEmpty() const throw ()
  181. {
  182. return stream.p == 0;
  183. }
  184. #endif // CONNECTIONTOSERVER_H