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.

483 lines
7.0 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. CClientDataChannelMgr.cpp
  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 02/00
  12. Revision History:
  13. --*/
  14. #include "stdafx.h"
  15. #ifdef TRC_FILE
  16. #undef TRC_FILE
  17. #endif
  18. #define TRC_FILE "_cldcmg"
  19. #include "ClientDataChannelMgr.h"
  20. #include <TSRDPRemoteDesktop.h>
  21. //#include <rdchost_i.c>
  22. ///////////////////////////////////////////////////////
  23. //
  24. // ClientChannelEventSink Methods
  25. //
  26. CClientChannelEventSink::~CClientChannelEventSink()
  27. {
  28. DC_BEGIN_FN("CClientChannelEventSink::~CClientChannelEventSink");
  29. ASSERT(m_Obj->IsValid());
  30. DC_END_FN();
  31. }
  32. void __stdcall
  33. CClientChannelEventSink::DataReady(
  34. BSTR data
  35. )
  36. {
  37. DC_BEGIN_FN("CClientChannelEventSink::DataReady");
  38. ASSERT(data != NULL);
  39. m_Obj->OnChannelsReceivedDataChange(data);
  40. DC_END_FN();
  41. }
  42. ///////////////////////////////////////////////////////
  43. //
  44. // ClientDataChannel Members
  45. //
  46. ClientDataChannel::ClientDataChannel()
  47. /*++
  48. Routine Description:
  49. Constructor
  50. Arguments:
  51. Return Value:
  52. None.
  53. --*/
  54. {
  55. DC_BEGIN_FN("ClientDataChannel::ClientDataChannel");
  56. DC_END_FN();
  57. }
  58. ClientDataChannel::~ClientDataChannel()
  59. /*++
  60. Routine Description:
  61. Destructor
  62. Arguments:
  63. Return Value:
  64. None.
  65. --*/
  66. {
  67. DC_BEGIN_FN("ClientDataChannel::~ClientDataChannel");
  68. //
  69. // Notify the channel manager that we have gone away.
  70. //
  71. m_ChannelMgr->RemoveChannel(m_ChannelName);
  72. //
  73. // Give up our reference to the channel manager.
  74. //
  75. m_ChannelMgr->Release();
  76. DC_END_FN();
  77. }
  78. void ClientDataChannel::Initialize(
  79. CClientDataChannelMgr *mgr,
  80. BSTR channelName
  81. )
  82. /*++
  83. Routine Description:
  84. Initialize an instance of this class.
  85. Arguments:
  86. Return Value:
  87. None.
  88. --*/
  89. {
  90. DC_BEGIN_FN("ClientDataChannel::Initialize");
  91. m_ChannelMgr = mgr;
  92. m_ChannelMgr->AddRef();
  93. m_ChannelName = channelName;
  94. DC_END_FN();
  95. }
  96. STDMETHODIMP
  97. ClientDataChannel::ReceiveChannelData(
  98. BSTR *data
  99. )
  100. /*++
  101. Routine Description:
  102. Receive the next complete data packet on this channel.
  103. Arguments:
  104. data - The next data packet. Should be released by the
  105. caller.
  106. Return Value:
  107. S_OK on success. Otherwise, an error result is returned.
  108. --*/
  109. {
  110. HRESULT result;
  111. DC_BEGIN_FN("ClientDataChannel::ReceiveChannelData");
  112. result = m_ChannelMgr->ReadChannelData(m_ChannelName, data);
  113. DC_END_FN();
  114. return result;
  115. }
  116. STDMETHODIMP
  117. ClientDataChannel::SendChannelData(
  118. BSTR data
  119. )
  120. /*++
  121. Routine Description:
  122. Send data on this channel.
  123. Arguments:
  124. data - Data to send.
  125. Return Value:
  126. S_OK on success. Otherwise, an error result is returned.
  127. --*/
  128. {
  129. HRESULT hr;
  130. DC_BEGIN_FN("ClientDataChannel::SendChannelData");
  131. hr = m_ChannelMgr->SendChannelData(m_ChannelName, data);
  132. DC_END_FN();
  133. return hr;
  134. }
  135. STDMETHODIMP
  136. ClientDataChannel::put_OnChannelDataReady(
  137. IDispatch * newVal
  138. )
  139. /*++
  140. Routine Description:
  141. SAFRemoteDesktopDataChannel Scriptable Event Object Registration
  142. Properties
  143. Arguments:
  144. Return Value:
  145. S_OK on success. Otherwise, an error status is returned.
  146. --*/
  147. {
  148. DC_BEGIN_FN("ClientDataChannel::put_OnChannelDataReady");
  149. m_OnChannelDataReady = newVal;
  150. DC_END_FN();
  151. return S_OK;
  152. }
  153. STDMETHODIMP
  154. ClientDataChannel::get_ChannelName(
  155. BSTR *pVal
  156. )
  157. /*++
  158. Routine Description:
  159. Return the channel name.
  160. Arguments:
  161. pVal - Returned channel name.
  162. Return Value:
  163. S_OK on success. Otherwise, an error status is returned.
  164. --*/
  165. {
  166. DC_BEGIN_FN("ClientDataChannel::get_ChannelName");
  167. CComBSTR str;
  168. str = m_ChannelName;
  169. *pVal = str.Detach();
  170. DC_END_FN();
  171. return S_OK;
  172. }
  173. /*++
  174. Routine Description:
  175. Called when data is ready on our channel.
  176. Arguments:
  177. pVal - Returned channel name.
  178. Return Value:
  179. S_OK on success. Otherwise, an error status is returned.
  180. --*/
  181. VOID
  182. ClientDataChannel::DataReady()
  183. {
  184. DC_BEGIN_FN("ClientDataChannel::DataReady");
  185. //
  186. // Fire our data ready event.
  187. //
  188. Fire_ChannelDataReady(m_ChannelName, m_OnChannelDataReady);
  189. DC_END_FN();
  190. }
  191. ///////////////////////////////////////////////////////
  192. //
  193. // CClientDataChannelMgr Methods
  194. //
  195. CClientDataChannelMgr::CClientDataChannelMgr()
  196. /*++
  197. Routine Description:
  198. Constructor
  199. Arguments:
  200. tsClient - Backpointer to TS client ActiveX control.
  201. Return Value:
  202. --*/
  203. {
  204. DC_BEGIN_FN("CClientDataChannelMgr::CClientDataChannelMgr");
  205. //
  206. // Not valid until initialized.
  207. //
  208. SetValid(FALSE);
  209. //
  210. // Initialize the event sink.
  211. //
  212. m_EventSink.m_Obj = this;
  213. DC_END_FN();
  214. }
  215. CClientDataChannelMgr::~CClientDataChannelMgr()
  216. /*++
  217. Routine Description:
  218. Destructor
  219. Arguments:
  220. Return Value:
  221. --*/
  222. {
  223. DC_BEGIN_FN("CClientDataChannelMgr::~CClientDataChannelMgr");
  224. //
  225. // Unregister the previously registered event sink.
  226. //
  227. if (m_IOInterface != NULL) {
  228. m_EventSink.DispEventUnadvise(m_IOInterface);
  229. }
  230. //
  231. // Release the IO interface.
  232. //
  233. m_IOInterface = NULL;
  234. DC_END_FN();
  235. }
  236. HRESULT
  237. CClientDataChannelMgr::Initialize()
  238. /*++
  239. Routine Description:
  240. Initialize an instance of this class.
  241. Arguments:
  242. Return Value:
  243. Returns ERROR_SUCCESS on success. Otherwise, an error status is returned.
  244. --*/
  245. {
  246. DC_BEGIN_FN("CClientDataChannelMgr::Initialize");
  247. HRESULT hr;
  248. //
  249. // Shouldn't be valid yet.
  250. //
  251. ASSERT(!IsValid());
  252. //
  253. // Initialize the parent class.
  254. //
  255. hr = CRemoteDesktopChannelMgr::Initialize();
  256. if (hr != S_OK) {
  257. goto CLEANUPANDEXIT;
  258. }
  259. CLEANUPANDEXIT:
  260. SetValid(hr == S_OK);
  261. DC_END_FN();
  262. return hr;
  263. }
  264. VOID
  265. CClientDataChannelMgr::SetIOInterface(
  266. IDataChannelIO *val
  267. )
  268. /*++
  269. Routine Description:
  270. Set the Data Channel IO Interface. This is implemented by the protocol-
  271. specific layer.
  272. Arguments:
  273. val - New IO interface.
  274. Return Value:
  275. ERROR_SUCCESS is returned on success. Otherwise, an error code
  276. is returned.
  277. --*/
  278. {
  279. DC_BEGIN_FN("CClientDataChannelMgr::SetIOInterface");
  280. HRESULT hr;
  281. //
  282. // Unregister the previously registered event sink and register
  283. // the new event sink.
  284. //
  285. if (m_IOInterface != NULL) {
  286. m_EventSink.DispEventUnadvise(m_IOInterface);
  287. }
  288. m_IOInterface = val;
  289. if (val != NULL) {
  290. hr = m_EventSink.DispEventAdvise(m_IOInterface);
  291. if (hr != S_OK) {
  292. TRC_ERR((TB, TEXT("DispEventAdvise: %08X"), hr));
  293. goto CLEANUPANDEXIT;
  294. }
  295. }
  296. CLEANUPANDEXIT:
  297. DC_END_FN();
  298. }
  299. HRESULT
  300. CClientDataChannelMgr::SendData(
  301. PREMOTEDESKTOP_CHANNELBUFHEADER msg
  302. )
  303. /*++
  304. Routine Description:
  305. Send Function Invoked by Parent Class
  306. Arguments:
  307. msg - The underlying data storage for the msg is a BSTR so that
  308. it is compatible with COM methods.
  309. Return Value:
  310. ERROR_SUCCESS is returned on success. Otherwise, an error code
  311. is returned.
  312. --*/
  313. {
  314. DC_BEGIN_FN("CClientDataChannelMgr::SendData");
  315. //
  316. // Hand off to the data IO manager.
  317. //
  318. ASSERT(m_IOInterface != NULL);
  319. HRESULT hr = m_IOInterface->SendData((BSTR)msg);
  320. DC_END_FN();
  321. return hr;
  322. }