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.

338 lines
8.2 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. ClientDataChannelMgr.h
  5. Abstract:
  6. This module implements the CClientDataChannelMgr class, a
  7. Salem client-side data channel manager ... that abstracts
  8. access to the underlying protocol, so it can
  9. be switched out at run-time.
  10. Author:
  11. Tad Brockway 06/00
  12. Revision History:
  13. --*/
  14. #ifndef __CLIENTDATACHANNELMGR_H__
  15. #define __CLIENTDATACHANNELMGR_H__
  16. #include <DataChannelMgr.h>
  17. #include "resource.h"
  18. #include <atlctl.h>
  19. #include <rdchost.h>
  20. #include <rdschan.h>
  21. #include "ClientDataChannelMgrP.h"
  22. #define IDC_EVENT_SOURCE_OBJ 1
  23. //
  24. // Info for all the event functions is entered here
  25. // there is a way to have ATL do this automatically using typelib's
  26. // but it is slower.
  27. //
  28. static _ATL_FUNC_INFO DCEventFuncNoParamsInfo =
  29. {
  30. CC_STDCALL, // Calling convention.
  31. VT_EMPTY, // Return type.
  32. 0, // Number of arguments.
  33. {VT_EMPTY} // Argument types.
  34. };
  35. static _ATL_FUNC_INFO DCEventFuncLongParamInfo =
  36. {
  37. CC_STDCALL, // Calling convention.
  38. VT_EMPTY, // Return type.
  39. 1, // Number of arguments.
  40. {VT_I4} // Argument types.
  41. };
  42. static _ATL_FUNC_INFO DCEventFuncOneStringParamInfo =
  43. {
  44. CC_STDCALL, // Calling convention.
  45. VT_EMPTY, // Return type.
  46. 1, // Number of arguments.
  47. {VT_BSTR} // Argument types
  48. };
  49. ///////////////////////////////////////////////////////
  50. //
  51. // CClientChannelEventSink
  52. //
  53. class CClientDataChannelMgr;
  54. class CClientChannelEventSink :
  55. public IDispEventSimpleImpl<IDC_EVENT_SOURCE_OBJ, CClientChannelEventSink,
  56. &DIID__IDataChannelIOEvents>,
  57. public CRemoteDesktopTopLevelObject
  58. {
  59. public:
  60. CClientDataChannelMgr *m_Obj;
  61. public:
  62. CClientChannelEventSink()
  63. {
  64. m_Obj = NULL;
  65. }
  66. ~CClientChannelEventSink();
  67. BEGIN_SINK_MAP(CClientChannelEventSink)
  68. SINK_ENTRY_INFO(IDC_EVENT_SOURCE_OBJ, DIID__IDataChannelIOEvents,
  69. DISPID_DATACHANNELEVEVENTS_DATAREADY,
  70. DataReady,
  71. &DCEventFuncOneStringParamInfo)
  72. END_SINK_MAP()
  73. void __stdcall DataReady(BSTR data);
  74. //
  75. // Return the name of this class.
  76. //
  77. virtual const LPTSTR ClassName() {
  78. return TEXT("CClientChannelEventSink");
  79. }
  80. };
  81. ///////////////////////////////////////////////////////
  82. //
  83. // ClientDataChannel
  84. //
  85. // Client-Specific Subclass of CRemoteDesktopDataChannel.
  86. //
  87. class ATL_NO_VTABLE ClientDataChannel :
  88. public CRemoteDesktopDataChannel,
  89. public CComObjectRootEx<CComSingleThreadModel>,
  90. public CComCoClass<ClientDataChannel, &CLSID_ClientDataChannel>,
  91. public IConnectionPointContainerImpl<ClientDataChannel>,
  92. public IDispatchImpl<ISAFRemoteDesktopDataChannel, &IID_ISAFRemoteDesktopDataChannel, &LIBID_RDCCLIENTHOSTLib>,
  93. public IProvideClassInfo2Impl<&CLSID_ClientDataChannel, NULL, &LIBID_RDCCLIENTHOSTLib>,
  94. public CProxy_ISAFRemoteDesktopDataChannelEvents< ClientDataChannel >
  95. {
  96. protected:
  97. //
  98. // Scriptable Event Callback Object
  99. //
  100. CComPtr<IDispatch> m_OnChannelDataReady;
  101. //
  102. // Back pointer to the channel manager.
  103. //
  104. CClientDataChannelMgr *m_ChannelMgr;
  105. public:
  106. //
  107. // Constructor/Destructor
  108. //
  109. ClientDataChannel();
  110. virtual ~ClientDataChannel();
  111. //
  112. // Initialize an instance of this class.
  113. //
  114. virtual void Initialize(
  115. CClientDataChannelMgr *mgr,
  116. BSTR channelName
  117. );
  118. DECLARE_REGISTRY_RESOURCEID(IDR_CLIENTDATACHANNEL)
  119. DECLARE_PROTECT_FINAL_CONSTRUCT()
  120. BEGIN_COM_MAP(ClientDataChannel)
  121. COM_INTERFACE_ENTRY(ISAFRemoteDesktopDataChannel)
  122. COM_INTERFACE_ENTRY2(IDispatch, ISAFRemoteDesktopDataChannel)
  123. COM_INTERFACE_ENTRY(IProvideClassInfo)
  124. COM_INTERFACE_ENTRY(IProvideClassInfo2)
  125. COM_INTERFACE_ENTRY(IConnectionPointContainer)
  126. COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
  127. END_COM_MAP()
  128. BEGIN_CONNECTION_POINT_MAP(ClientDataChannel)
  129. CONNECTION_POINT_ENTRY(DIID__ISAFRemoteDesktopDataChannelEvents)
  130. END_CONNECTION_POINT_MAP()
  131. //
  132. // ISAFRemoteDesktopDataChannel Methods
  133. //
  134. // The parent class handles the details of these methods.
  135. //
  136. STDMETHOD(ReceiveChannelData)(/*[out, retval]*/BSTR *data);
  137. STDMETHOD(SendChannelData)(BSTR data);
  138. STDMETHOD(put_OnChannelDataReady)(/*[in]*/ IDispatch * newVal);
  139. STDMETHOD(get_ChannelName)(/*[out, retval]*/ BSTR *pVal);
  140. //
  141. // Called to return our ISAFRemoteDesktopDataChannel interface.
  142. //
  143. virtual HRESULT GetISAFRemoteDesktopDataChannel(
  144. ISAFRemoteDesktopDataChannel **channel
  145. ) {
  146. HRESULT hr;
  147. hr = this->QueryInterface(
  148. IID_ISAFRemoteDesktopDataChannel, (PVOID*)channel
  149. );
  150. return hr;
  151. }
  152. //
  153. // Called by the data channel manager when data is ready on our channel.
  154. //
  155. virtual VOID DataReady();
  156. //
  157. // Return this class name.
  158. //
  159. virtual const LPTSTR ClassName() { return TEXT("ClientDataChannel"); }
  160. };
  161. ///////////////////////////////////////////////////////
  162. //
  163. // CClientDataChannelMgr
  164. //
  165. class CClientDataChannelMgr :
  166. public CRemoteDesktopChannelMgr,
  167. public CComObjectRootEx<CComSingleThreadModel>,
  168. public CComCoClass<CClientDataChannelMgr, &CLSID_ClientRemoteDesktopChannelMgr>,
  169. public IDispatchImpl<ISAFRemoteDesktopChannelMgr, &IID_ISAFRemoteDesktopChannelMgr, &LIBID_RDCCLIENTHOSTLib>
  170. {
  171. protected:
  172. CComPtr<IDataChannelIO> m_IOInterface;
  173. CClientChannelEventSink m_EventSink;
  174. //
  175. // Send Function Invoked by Parent Class
  176. //
  177. // The underlying data storage for the msg is a BSTR so that it is compatible
  178. // with COM methods.
  179. //
  180. virtual HRESULT SendData(PREMOTEDESKTOP_CHANNELBUFHEADER msg);
  181. //
  182. // Help the parent class out by opening the right channel object
  183. // for the platform.
  184. //
  185. virtual CRemoteDesktopDataChannel *OpenPlatformSpecificDataChannel(
  186. BSTR channelName,
  187. ISAFRemoteDesktopDataChannel **channel
  188. )
  189. {
  190. CComObject<ClientDataChannel> *obj;
  191. obj = new CComObject<ClientDataChannel>();
  192. if (obj != NULL) {
  193. obj->Initialize(this, channelName);
  194. obj->QueryInterface(
  195. __uuidof(ISAFRemoteDesktopDataChannel),
  196. (PVOID *)channel
  197. );
  198. // AV if mgr object goes away before datachannel object
  199. this->AddRef();
  200. }
  201. return obj;
  202. }
  203. public:
  204. //
  205. // Release the ref. counter we add to ourself after creating a data channel
  206. //
  207. virtual HRESULT RemoveChannel(BSTR channel) {
  208. HRESULT hr;
  209. hr = CRemoteDesktopChannelMgr::RemoveChannel(channel);
  210. if( SUCCEEDED(hr) ) {
  211. this->Release();
  212. }
  213. return hr;
  214. }
  215. //
  216. // Constructor/Destructor
  217. //
  218. CClientDataChannelMgr();
  219. ~CClientDataChannelMgr();
  220. DECLARE_REGISTRY_RESOURCEID(IDR_CLIENTREMOTEDESTKOPCHANNELMGR)
  221. DECLARE_PROTECT_FINAL_CONSTRUCT()
  222. BEGIN_COM_MAP(CClientDataChannelMgr)
  223. COM_INTERFACE_ENTRY(ISAFRemoteDesktopChannelMgr)
  224. COM_INTERFACE_ENTRY(IDispatch)
  225. END_COM_MAP()
  226. //
  227. // ISAFRemoteDesktopChannelMgr Methods
  228. //
  229. STDMETHOD(OpenDataChannel)(BSTR name, ISAFRemoteDesktopDataChannel **channel)
  230. {
  231. //
  232. // Let the parent handle it.
  233. //
  234. return OpenDataChannel_(name, channel);
  235. }
  236. //
  237. // Set the Data Channel IO Interface. This is implemented by the protocol-
  238. // specific layer.
  239. //
  240. VOID SetIOInterface(IDataChannelIO *val);
  241. //
  242. // Initialize an instance of this class.
  243. //
  244. virtual HRESULT Initialize();
  245. //
  246. // Called on new channel data.
  247. //
  248. HRESULT __stdcall OnChannelsReceivedDataChange(
  249. BSTR data
  250. ) {
  251. //
  252. // Forward to the parent class.
  253. //
  254. DataReady(data);
  255. return S_OK;
  256. }
  257. //
  258. // Return this class name.
  259. //
  260. virtual const LPTSTR ClassName()
  261. { return TEXT("CClientDataChannelMgr"); }
  262. };
  263. #endif //__CLIENTDATACHANNELMGR_H__