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.

352 lines
8.5 KiB

  1. /*++
  2. Copyright (c) 1998-2000 Microsoft Corporation
  3. Module Name:
  4. w32proc.h
  5. Abstract:
  6. Contains the parent of the Win32 IO processing class hierarchy
  7. for TS Device Redirection, W32ProcObj.
  8. Author:
  9. Madan Appiah (madana) 17-Sep-1998
  10. Revision History:
  11. --*/
  12. #ifndef __W32PROC_H__
  13. #define __W32PROC_H__
  14. #include "proc.h"
  15. #include "w32drprn.h"
  16. #include "w32dispq.h"
  17. #include "thrpool.h"
  18. ///////////////////////////////////////////////////////////////
  19. //
  20. // Registry Key and Value Names.
  21. //
  22. #define REGISTRY_KEY_NAME_SIZE MAX_PATH
  23. #define REGISTRY_VALUE_NAME_SIZE 64
  24. #define REGISTRY_DATA_SIZE 256
  25. #ifndef OS_WINCE
  26. #define REGISTRY_ALLOC_DATA_SIZE (8 * 1024)
  27. #else
  28. #define REGISTRY_ALLOC_DATA_SIZE (4 * 1024)
  29. #endif
  30. // Parent key for device redirection registry values.
  31. #define REG_RDPDR_PARAMETER_PATH \
  32. _T("Software\\Microsoft\\Terminal Server Client\\Default\\AddIns\\RDPDR")
  33. ///////////////////////////////////////////////////////////////
  34. //
  35. // Configurable Value Names and Defaults
  36. //
  37. #define REGISTRY_BACKGROUNDTHREAD_TIMEOUT_NAME _T("ThreadTimeOut")
  38. #define REGISTRY_BACKGROUNDTHREAD_TIMEOUT_DEFAULT INFINITE
  39. ///////////////////////////////////////////////////////////////
  40. //
  41. // Other Defines
  42. //
  43. #define RDPDR_MODULE_NAME _T("rdpdr.dll")
  44. #define KERNEL32_MODULE_NAME _T("kernel32.dll")
  45. #define QUEUE_USER_APC_PROC_NAME _T("QueueUserAPC")
  46. #define MAX_INTEGER_STRING_SIZE 32
  47. class W32ProcObj;
  48. class W32DeviceChangeParam {
  49. public:
  50. W32ProcObj *_instance;
  51. WPARAM _wParam;
  52. LPARAM _lParam;
  53. W32DeviceChangeParam(W32ProcObj *procObj, WPARAM wParam, LPARAM lParam) {
  54. _instance = procObj;
  55. _wParam = wParam;
  56. _lParam = lParam;
  57. }
  58. };
  59. ///////////////////////////////////////////////////////////////
  60. //
  61. // W32ProcObj
  62. //
  63. // W32ProcObj is the parent device IO processing class for
  64. // Win32 TS Device Redirection.
  65. //
  66. class W32ProcObj : public ProcObj {
  67. private:
  68. //
  69. // Asynchronous IO Request Context
  70. //
  71. typedef struct _AsyncIOReqContext {
  72. RDPAsyncFunc_StartIO ioStartFunc;
  73. RDPAsyncFunc_IOComplete ioCompleteFunc;
  74. RDPAsyncFunc_IOCancel ioCancelFunc;
  75. PVOID clientContext;
  76. W32ProcObj *instance;
  77. } ASYNCIOREQCONTEXT, *PASYNCIOREQCONTEXT;
  78. //
  79. // Worker Thread Info
  80. //
  81. typedef struct _ThreadInfo {
  82. // Handle to the thread owning this data
  83. HANDLE hWorkerThread;
  84. // Thread ID
  85. ULONG ulThreadId;
  86. // Waitable Object Array and Corresponding IO Requests
  87. HANDLE waitableObjects[MAXIMUM_WAIT_OBJECTS];
  88. PASYNCIOREQCONTEXT waitingReqs[MAXIMUM_WAIT_OBJECTS];
  89. // Number of Waitable Objects and Corresponding Requests being Tracked
  90. ULONG waitableObjectCount;
  91. // Synchronization event for controlling this thread.
  92. HANDLE controlEvent;
  93. // If set, then the background thread should shut down.
  94. BOOL shutDownFlag;
  95. // The dispatch queue for a single thread instance.
  96. W32DispatchQueue *dispatchQueue;
  97. // Constructor
  98. _ThreadInfo() : hWorkerThread(NULL), ulThreadId(0), waitableObjectCount(0)
  99. {
  100. memset(&waitableObjects[0], 0, sizeof(waitableObjects));
  101. memset(&waitingReqs[0], 0, sizeof(waitingReqs));
  102. }
  103. ~_ThreadInfo()
  104. {
  105. if (hWorkerThread != NULL) {
  106. CloseHandle(hWorkerThread);
  107. hWorkerThread = NULL;
  108. }
  109. }
  110. } THREAD_INFO, *PTHREAD_INFO ;
  111. BOOL ProcessIORequestPacket( PRDPDR_IOREQUEST_PACKET pIoRequestPacket );
  112. ULONG GetClientID( VOID );
  113. //
  114. // True if devices have been scanned for redirection.
  115. //
  116. BOOL _bLocalDevicesScanned;
  117. //
  118. // The object is shutting down.
  119. //
  120. BOOL _isShuttingDown;
  121. //
  122. // The thread pool
  123. //
  124. ThreadPool *_threadPool;
  125. //
  126. // Background Worker Thread Handle
  127. //
  128. PTHREAD_INFO _pWorkerThread;
  129. //
  130. // Background Thread Timeout
  131. //
  132. DWORD _threadTimeout;
  133. //
  134. // Win9x system flag. TRUE if the system is Win9x
  135. // FALSE otherwise.
  136. //
  137. BOOL _bWin9xFlag;
  138. HINSTANCE _hRdpDrModuleHandle;
  139. //
  140. // Initialize a worker thread.
  141. //
  142. ULONG CreateWorkerThreadEntry(PTHREAD_INFO *ppThreadInfo);
  143. //
  144. // Handle a signaled worker thread object that is associated with some kind
  145. // of asynchronous request.
  146. //
  147. VOID ProcessWorkerThreadObject(PTHREAD_INFO pThreadInfo, ULONG offset);
  148. //
  149. // Shutdown an instance of this class.
  150. //
  151. VOID Shutdown();
  152. //
  153. // Handler for asynchronous IO request dispatching.
  154. //
  155. static VOID _DispatchAsyncIORequest_Private(
  156. PASYNCIOREQCONTEXT reqContext,
  157. BOOL cancelled
  158. );
  159. VOID DispatchAsyncIORequest_Private(
  160. PASYNCIOREQCONTEXT reqContext,
  161. BOOL cancelled
  162. );
  163. //
  164. // Track another waitable object in the worker thread.
  165. //
  166. DWORD AddWaitableObjectToWorkerThread(PTHREAD_INFO threadInfo,
  167. HANDLE waitableObject,
  168. PASYNCIOREQCONTEXT reqContext
  169. );
  170. //
  171. // Main Worker Thread Function. Static version invokes
  172. // instance-specific version.
  173. //
  174. static DWORD WINAPI _ObjectWorkerThread(LPVOID lpParam);
  175. ULONG ObjectWorkerThread(VOID);
  176. //
  177. // Check the operation dispatch queue for queued operations.
  178. //
  179. VOID CheckForQueuedOperations(PTHREAD_INFO thread);
  180. //
  181. // Enumerate devices and announce them to the server from the
  182. // worker thread.
  183. //
  184. virtual VOID AnnounceDevicesToServer();
  185. static HANDLE _AnnounceDevicesToServerFunc(W32ProcObj *obj, DWORD *status);
  186. VOID AnnounceDevicesToServerFunc(DWORD *status);
  187. //
  188. // Handle device change notification from a worker thread
  189. //
  190. static HANDLE _OnDeviceChangeFunc(W32DeviceChangeParam *param, DWORD *status);
  191. VOID OnDeviceChangeFunc(DWORD *status, IN WPARAM wParam, IN LPARAM lParam);
  192. protected:
  193. //
  194. // Return the client's host name.
  195. //
  196. virtual VOID GetClientComputerName(
  197. PBYTE pbBuffer,
  198. PULONG pulBufferLen,
  199. PBOOL pbUnicodeFlag,
  200. PULONG pulCodePage
  201. );
  202. public:
  203. //
  204. // Constructor/Destructor
  205. //
  206. W32ProcObj(VCManager *pVCM);
  207. virtual ~W32ProcObj();
  208. //
  209. // Initialize an instance of this class.
  210. //
  211. virtual ULONG Initialize();
  212. //
  213. // Dispatch an asynchronous IO function.
  214. //
  215. // startFunc points to the function that will be called to initiate the IO.
  216. // finishFunc, optionally, points to the function that will be called once
  217. // the IO has completed.
  218. //
  219. virtual DWORD DispatchAsyncIORequest(
  220. IN RDPAsyncFunc_StartIO ioStartFunc,
  221. IN OPTIONAL RDPAsyncFunc_IOComplete ioCompleteFunc = NULL,
  222. IN OPTIONAL RDPAsyncFunc_IOCancel ioCancelFunc = NULL,
  223. IN OPTIONAL PVOID clientContext = NULL
  224. );
  225. //
  226. // Return Configurable Parameters.
  227. //
  228. virtual ULONG GetDWordParameter(LPTSTR lpszValueName,
  229. PULONG lpdwValue);
  230. virtual ULONG GetStringParameter(LPTSTR valueName,
  231. OUT DRSTRING value,
  232. IN ULONG maxSize);
  233. //
  234. // Return a reference to the thread pool.
  235. //
  236. ThreadPool &GetThreadPool() {
  237. return *_threadPool;
  238. }
  239. //
  240. // Returns whether the proc obj is in the middle of shutting down.
  241. //
  242. virtual BOOL IsShuttingDown() {
  243. return _isShuttingDown;
  244. }
  245. //
  246. // Return whether the platform is 9x.
  247. //
  248. virtual BOOL Is9x() {
  249. return _bWin9xFlag;
  250. }
  251. //
  252. // Return the class name.
  253. //
  254. virtual DRSTRING ClassName() { return TEXT("W32ProcObj"); }
  255. virtual void OnDeviceChange(WPARAM wParam, LPARAM lParam);
  256. };
  257. #endif