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.

225 lines
5.2 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. private:
  59. BOOL m_Initialized;
  60. protected:
  61. //
  62. // Queue of pending messages for a single channel.
  63. //
  64. typedef struct _QueuedChannelBuffer {
  65. DWORD len;
  66. BSTR buf;
  67. } QUEUEDCHANNELBUFFER, *PQUEUEDCHANNELBUFFER;
  68. typedef std::deque<QUEUEDCHANNELBUFFER, CRemoteDesktopAllocator<QUEUEDCHANNELBUFFER> > InputBufferQueue;
  69. //
  70. // Channel Map
  71. //
  72. typedef struct ChannelMapEntry
  73. {
  74. InputBufferQueue inputBufferQueue;
  75. CRemoteDesktopDataChannel *channelObject;
  76. #if DBG
  77. DWORD bytesSent;
  78. DWORD bytesRead;
  79. #endif
  80. } CHANNELMAPENTRY, *PCHANNELMAPENTRY;
  81. typedef std::map<CComBSTR, PCHANNELMAPENTRY, CompareBSTR, CRemoteDesktopAllocator<PCHANNELMAPENTRY> > ChannelMap;
  82. ChannelMap m_ChannelMap;
  83. //
  84. // ThreadLock
  85. //
  86. CRITICAL_SECTION m_cs;
  87. #if DBG
  88. LONG m_LockCount;
  89. #endif
  90. //
  91. // ThreadLock/ThreadUnlock an instance of this class.
  92. //
  93. VOID ThreadLock();
  94. VOID ThreadUnlock();
  95. protected:
  96. //
  97. // Invoked by the Subclass when the next message is ready.
  98. //
  99. virtual VOID DataReady(BSTR msg);
  100. //
  101. // Send Function to be Implemented by Subclass
  102. //
  103. // The underlying data storage for the msg is a BSTR so that it is compatible
  104. // with COM methods.
  105. //
  106. virtual HRESULT SendData(PREMOTEDESKTOP_CHANNELBUFHEADER msg) = 0;
  107. //
  108. // ISAFRemoteDesktopChannelMgr Helper Methods
  109. //
  110. HRESULT OpenDataChannel_(BSTR name, ISAFRemoteDesktopDataChannel **channel);
  111. //
  112. // The subclass implements this for returning the data channel, specific
  113. // to the current platform.
  114. //
  115. virtual CRemoteDesktopDataChannel *OpenPlatformSpecificDataChannel(
  116. BSTR channelName,
  117. ISAFRemoteDesktopDataChannel **channel
  118. ) = 0;
  119. public:
  120. //
  121. // Constructor/Destructor
  122. //
  123. CRemoteDesktopChannelMgr();
  124. ~CRemoteDesktopChannelMgr();
  125. //
  126. // Remove an existing data channel.
  127. //
  128. virtual HRESULT RemoveChannel(BSTR channel);
  129. //
  130. // Read the next message from a data channel.
  131. //
  132. HRESULT ReadChannelData(BSTR channel, BSTR *msg);
  133. //
  134. // Send a buffer on the data channel.
  135. //
  136. HRESULT SendChannelData(BSTR channel, BSTR outputBuf);
  137. //
  138. // Initialize an instance of this class.
  139. //
  140. virtual HRESULT Initialize();
  141. //
  142. // Return this class name.
  143. //
  144. virtual const LPTSTR ClassName() { return TEXT("CRemoteDesktopChannelMgr"); }
  145. };
  146. ///////////////////////////////////////////////////////
  147. //
  148. // Inline Members
  149. //
  150. inline VOID CRemoteDesktopChannelMgr::ThreadLock()
  151. {
  152. DC_BEGIN_FN("CRemoteDesktopChannelMgr::ThreadLock");
  153. #if DBG
  154. m_LockCount++;
  155. //TRC_NRM((TB, TEXT("ThreadLock count is now %ld."), m_LockCount));
  156. #endif
  157. EnterCriticalSection(&m_cs);
  158. DC_END_FN();
  159. }
  160. inline VOID CRemoteDesktopChannelMgr::ThreadUnlock()
  161. {
  162. DC_BEGIN_FN("CRemoteDesktopChannelMgr::ThreadUnlock");
  163. #if DBG
  164. m_LockCount--;
  165. //TRC_NRM((TB, TEXT("ThreadLock count is now %ld."), m_LockCount));
  166. ASSERT(m_LockCount >= 0);
  167. #endif
  168. LeaveCriticalSection(&m_cs);
  169. DC_END_FN();
  170. }
  171. #endif //__DATACHANNELMGR_H__