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.

221 lines
4.7 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. DataChannelMgr.h
  5. Abstract:
  6. This module contains an implementation of the ISAFRemoteDesktopDataChannel
  7. and ISAFRemoteDesktopChannelMgr interfaces. These interfaces are designed
  8. to abstract out-of-band data channel access for the Salem project.
  9. The classes implemented in this module achieve this objective by
  10. multiplexing multiple data channels into a single data channel that is
  11. implemented by the remote control-specific Salem layer.
  12. Author:
  13. Tad Brockway 02/00
  14. Revision History:
  15. --*/
  16. #ifndef __DATACHANNELMGR_H__
  17. #define __DATACHANNELMGR_H__
  18. #include <RemoteDesktopTopLevelObject.h>
  19. #include <RemoteDesktopChannels.h>
  20. #include "RemoteDesktopUtils.h"
  21. #include <rdschan.h>
  22. #include <atlbase.h>
  23. #pragma warning (disable: 4786)
  24. #include <map>
  25. #include <deque>
  26. #include <vector>
  27. ///////////////////////////////////////////////////////
  28. //
  29. // CRemoteDesktopDataChannel
  30. //
  31. class CRemoteDesktopChannelMgr;
  32. class ATL_NO_VTABLE CRemoteDesktopDataChannel :
  33. public CRemoteDesktopTopLevelObject
  34. {
  35. friend CRemoteDesktopChannelMgr;
  36. protected:
  37. CComBSTR m_ChannelName;
  38. //
  39. // Called to return our ISAFRemoteDesktopDataChannel interface.
  40. //
  41. virtual HRESULT GetISAFRemoteDesktopDataChannel(
  42. ISAFRemoteDesktopDataChannel **channel
  43. ) = 0;
  44. //
  45. // Called by the data channel manager when data is ready on our channel.
  46. //
  47. virtual VOID DataReady() = 0;
  48. };
  49. ///////////////////////////////////////////////////////
  50. //
  51. // CRemoteDesktopChannelMgr
  52. //
  53. class ATL_NO_VTABLE CRemoteDesktopChannelMgr :
  54. public CRemoteDesktopTopLevelObject
  55. {
  56. friend CRemoteDesktopDataChannel;
  57. public:
  58. protected:
  59. //
  60. // Queue of pending messages for a single channel.
  61. //
  62. typedef struct _QueuedChannelBuffer {
  63. DWORD len;
  64. BSTR buf;
  65. } QUEUEDCHANNELBUFFER, *PQUEUEDCHANNELBUFFER;
  66. typedef std::deque<QUEUEDCHANNELBUFFER, CRemoteDesktopAllocator<QUEUEDCHANNELBUFFER> > InputBufferQueue;
  67. //
  68. // Channel Map
  69. //
  70. typedef struct ChannelMapEntry
  71. {
  72. InputBufferQueue inputBufferQueue;
  73. CRemoteDesktopDataChannel *channelObject;
  74. #if DBG
  75. DWORD bytesSent;
  76. DWORD bytesRead;
  77. #endif
  78. } CHANNELMAPENTRY, *PCHANNELMAPENTRY;
  79. typedef std::map<CComBSTR, PCHANNELMAPENTRY, CompareBSTR, CRemoteDesktopAllocator<PCHANNELMAPENTRY> > ChannelMap;
  80. ChannelMap m_ChannelMap;
  81. //
  82. // ThreadLock
  83. //
  84. CRITICAL_SECTION m_cs;
  85. #if DBG
  86. LONG m_LockCount;
  87. #endif
  88. //
  89. // ThreadLock/ThreadUnlock an instance of this class.
  90. //
  91. VOID ThreadLock();
  92. VOID ThreadUnlock();
  93. protected:
  94. //
  95. // Invoked by the Subclass when the next message is ready.
  96. //
  97. virtual VOID DataReady(BSTR msg);
  98. //
  99. // Send Function to be Implemented by Subclass
  100. //
  101. // The underlying data storage for the msg is a BSTR so that it is compatible
  102. // with COM methods.
  103. //
  104. virtual HRESULT SendData(PREMOTEDESKTOP_CHANNELBUFHEADER msg) = 0;
  105. //
  106. // ISAFRemoteDesktopChannelMgr Helper Methods
  107. //
  108. HRESULT OpenDataChannel_(BSTR name, ISAFRemoteDesktopDataChannel **channel);
  109. //
  110. // The subclass implements this for returning the data channel, specific
  111. // to the current platform.
  112. //
  113. virtual CRemoteDesktopDataChannel *OpenPlatformSpecificDataChannel(
  114. BSTR channelName,
  115. ISAFRemoteDesktopDataChannel **channel
  116. ) = 0;
  117. public:
  118. //
  119. // Constructor/Destructor
  120. //
  121. CRemoteDesktopChannelMgr();
  122. ~CRemoteDesktopChannelMgr();
  123. //
  124. // Remove an existing data channel.
  125. //
  126. VOID RemoveChannel(BSTR channel);
  127. //
  128. // Read the next message from a data channel.
  129. //
  130. HRESULT ReadChannelData(BSTR channel, BSTR *msg);
  131. //
  132. // Send a buffer on the data channel.
  133. //
  134. HRESULT SendChannelData(BSTR channel, BSTR outputBuf);
  135. //
  136. // Initialize an instance of this class.
  137. //
  138. virtual HRESULT Initialize() { return S_OK; }
  139. //
  140. // Return this class name.
  141. //
  142. virtual const LPTSTR ClassName() { return TEXT("CRemoteDesktopChannelMgr"); }
  143. };
  144. ///////////////////////////////////////////////////////
  145. //
  146. // Inline Members
  147. //
  148. inline VOID CRemoteDesktopChannelMgr::ThreadLock()
  149. {
  150. DC_BEGIN_FN("CRemoteDesktopChannelMgr::ThreadLock");
  151. #if DBG
  152. m_LockCount++;
  153. //TRC_NRM((TB, TEXT("ThreadLock count is now %ld."), m_LockCount));
  154. #endif
  155. EnterCriticalSection(&m_cs);
  156. DC_END_FN();
  157. }
  158. inline VOID CRemoteDesktopChannelMgr::ThreadUnlock()
  159. {
  160. DC_BEGIN_FN("CRemoteDesktopChannelMgr::ThreadUnlock");
  161. #if DBG
  162. m_LockCount--;
  163. //TRC_NRM((TB, TEXT("ThreadLock count is now %ld."), m_LockCount));
  164. ASSERT(m_LockCount >= 0);
  165. #endif
  166. LeaveCriticalSection(&m_cs);
  167. DC_END_FN();
  168. }
  169. #endif //__DATACHANNELMGR_H__