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.

550 lines
13 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. channel.h
  5. Abstract:
  6. Common Channel routines.
  7. Author:
  8. Brian Guarraci (briangu) March, 2001.
  9. Revision History:
  10. --*/
  11. #ifndef CHANNEL_H
  12. #define CHANNEL_H
  13. //
  14. // The maximum buffer size an EMS app may write to it's channel
  15. //
  16. #define CHANNEL_MAX_OWRITE_BUFFER_SIZE 0x8000
  17. //
  18. // Channel function types
  19. //
  20. struct _SAC_CHANNEL;
  21. typedef NTSTATUS
  22. (*CHANNEL_FUNC_CREATE)(
  23. IN struct _SAC_CHANNEL* Channel
  24. );
  25. typedef NTSTATUS
  26. (*CHANNEL_FUNC_DESTROY)(
  27. IN struct _SAC_CHANNEL* Channel
  28. );
  29. typedef NTSTATUS
  30. (*CHANNEL_FUNC_OFLUSH)(
  31. IN struct _SAC_CHANNEL* Channel
  32. );
  33. typedef NTSTATUS
  34. (*CHANNEL_FUNC_OECHO)(
  35. IN struct _SAC_CHANNEL* Channel,
  36. IN PCUCHAR Buffer,
  37. IN ULONG BufferSize
  38. );
  39. typedef NTSTATUS
  40. (*CHANNEL_FUNC_OWRITE)(
  41. IN struct _SAC_CHANNEL* Channel,
  42. IN PCUCHAR Buffer,
  43. IN ULONG BufferSize
  44. );
  45. typedef NTSTATUS
  46. (*CHANNEL_FUNC_OREAD)(
  47. IN struct _SAC_CHANNEL* Channel,
  48. IN PUCHAR Buffer,
  49. IN ULONG BufferSize,
  50. OUT PULONG ByteCount
  51. );
  52. typedef NTSTATUS
  53. (*CHANNEL_FUNC_IWRITE)(
  54. IN struct _SAC_CHANNEL* Channel,
  55. IN PCUCHAR Buffer,
  56. IN ULONG BufferSize
  57. );
  58. typedef NTSTATUS
  59. (*CHANNEL_FUNC_IREAD)(
  60. IN struct _SAC_CHANNEL* Channel,
  61. IN PUCHAR Buffer,
  62. IN ULONG BufferSize,
  63. OUT PULONG ByteCount
  64. );
  65. typedef WCHAR
  66. (*CHANNEL_FUNC_IREADLAST)(
  67. IN struct _SAC_CHANNEL* Channel
  68. );
  69. typedef NTSTATUS
  70. (*CHANNEL_FUNC_IBUFFERISFULL)(
  71. IN struct _SAC_CHANNEL* Channel,
  72. OUT BOOLEAN* BufferStatus
  73. );
  74. typedef ULONG
  75. (*CHANNEL_FUNC_IBUFFERLENGTH)(
  76. IN struct _SAC_CHANNEL* Channel
  77. );
  78. //
  79. // This struct is all the information necessary to maintian a single channel.
  80. //
  81. typedef struct _SAC_CHANNEL {
  82. /////////////////////////////////////////
  83. // BEGIN: ATTRIBUTES SET UPON CREATION
  84. /////////////////////////////////////////
  85. //
  86. // Index of the channel in the channel manager's channel array
  87. //
  88. ULONG Index;
  89. //
  90. // Handle for use by Channel applications
  91. //
  92. SAC_CHANNEL_HANDLE Handle;
  93. //
  94. // Events specified by the channel application
  95. //
  96. HANDLE CloseEvent;
  97. PVOID CloseEventObjectBody;
  98. PVOID CloseEventWaitObjectBody;
  99. HANDLE HasNewDataEvent;
  100. PVOID HasNewDataEventObjectBody;
  101. PVOID HasNewDataEventWaitObjectBody;
  102. #if ENABLE_CHANNEL_LOCKING
  103. HANDLE LockEvent;
  104. PVOID LockEventObjectBody;
  105. PVOID LockEventWaitObjectBody;
  106. #endif
  107. HANDLE RedrawEvent;
  108. PVOID RedrawEventObjectBody;
  109. PVOID RedrawEventWaitObjectBody;
  110. /////////////////////////////////////////
  111. // END: ATTRIBUTES SET UPON CREATION
  112. /////////////////////////////////////////
  113. /////////////////////////////////////////
  114. // BEGIN: REQUIRES CHANNEL_ACCESS_ATTRIBUTES
  115. /////////////////////////////////////////
  116. //
  117. // General channel attributes
  118. //
  119. //
  120. // The pointer to the file object used to reference
  121. // the SAC driver for the process that created
  122. // the channel. We use this file object to make
  123. // sure no other process operates on a channel they
  124. // didnt create.
  125. //
  126. PFILE_OBJECT FileObject;
  127. //
  128. // Channel Type
  129. //
  130. // Determines the channel implementation
  131. //
  132. SAC_CHANNEL_TYPE Type;
  133. //
  134. // Channel Status (Active/Inactive)
  135. //
  136. // Active - the channel may send/receive data
  137. // Inactive - channel may not receive data
  138. // if the preserve flag is set, the channel
  139. // will not be reaped until the data is sent
  140. // otherwise the channel is reapable
  141. //
  142. SAC_CHANNEL_STATUS Status;
  143. //
  144. // Channel Name
  145. //
  146. WCHAR Name[SAC_MAX_CHANNEL_NAME_LENGTH+1];
  147. //
  148. // Channel Description
  149. //
  150. WCHAR Description[SAC_MAX_CHANNEL_DESCRIPTION_LENGTH+1];
  151. //
  152. // Channel behavior attribute flags
  153. //
  154. // Example:
  155. //
  156. // SAC_CHANNEL_FLAG_PRESERVE - don't reap the channel until the data
  157. // in the obuffer has been sent
  158. //
  159. SAC_CHANNEL_FLAG Flags;
  160. //
  161. // Channel Attribute type
  162. //
  163. // Application determined identifier that is used primarily
  164. // by the remote management app to determine how to handle
  165. // the channel data
  166. //
  167. GUID ApplicationType;
  168. //
  169. // Status of OBuffer
  170. //
  171. // TRUE when the OBuffer has been flushed
  172. // Otherwise FALSE
  173. //
  174. // This is primarily intended for use with an IOMGR like the console
  175. // manager. For instance, this flag gets set to FALSE when we
  176. // fast-channel-switch to another channel, and set to TRUE when we
  177. // select a channel and flush it's contents to the current channel.
  178. //
  179. // Note: we use ULONG for this so we can use InterlockedExchange
  180. //
  181. ULONG SentToScreen;
  182. /////////////////////////////////////////
  183. // END: REQUIRES CHANNEL_ACCESS_ATTRIBUTES
  184. /////////////////////////////////////////
  185. /////////////////////////////////////////
  186. // BEGIN: REQUIRES CHANNEL_ACCESS_IBUFFER
  187. /////////////////////////////////////////
  188. //
  189. // Common Input Buffer
  190. //
  191. ULONG IBufferIndex;
  192. PUCHAR IBuffer;
  193. ULONG IBufferHasNewData;
  194. /////////////////////////////////////////
  195. // END: REQUIRES CHANNEL_ACCESS_IBUFFER
  196. /////////////////////////////////////////
  197. /////////////////////////////////////////
  198. // BEGIN: REQUIRES CHANNEL_ACCESS_OBUFFER
  199. /////////////////////////////////////////
  200. //
  201. // VTUTF8 Channel Screen details
  202. //
  203. UCHAR CursorRow;
  204. UCHAR CursorCol;
  205. UCHAR CurrentFg;
  206. UCHAR CurrentBg;
  207. UCHAR CurrentAttr;
  208. //
  209. // Output Buffer
  210. PVOID OBuffer;
  211. //
  212. // OBuffer management vars for RawChannels
  213. //
  214. ULONG OBufferIndex;
  215. ULONG OBufferFirstGoodIndex;
  216. //
  217. // This gets set when new data is inserted into OBuffer
  218. //
  219. ULONG OBufferHasNewData;
  220. /////////////////////////////////////////
  221. // END: REQUIRES CHANNEL_ACCESS_OBUFFER
  222. /////////////////////////////////////////
  223. //
  224. // Channel Function VTABLE
  225. //
  226. CHANNEL_FUNC_CREATE Create;
  227. CHANNEL_FUNC_DESTROY Destroy;
  228. CHANNEL_FUNC_OFLUSH OFlush;
  229. CHANNEL_FUNC_OECHO OEcho;
  230. CHANNEL_FUNC_OWRITE OWrite;
  231. CHANNEL_FUNC_OREAD ORead;
  232. CHANNEL_FUNC_IWRITE IWrite;
  233. CHANNEL_FUNC_IREAD IRead;
  234. CHANNEL_FUNC_IREADLAST IReadLast;
  235. CHANNEL_FUNC_IBUFFERISFULL IBufferIsFull;
  236. CHANNEL_FUNC_IBUFFERLENGTH IBufferLength;
  237. //
  238. // Channel access locks
  239. //
  240. SAC_LOCK ChannelAttributeLock;
  241. SAC_LOCK ChannelOBufferLock;
  242. SAC_LOCK ChannelIBufferLock;
  243. } SAC_CHANNEL, *PSAC_CHANNEL;
  244. //
  245. // Macros for managing channel locks
  246. //
  247. #define INIT_CHANNEL_LOCKS(_Channel) \
  248. INITIALIZE_LOCK(_Channel->ChannelAttributeLock); \
  249. INITIALIZE_LOCK(_Channel->ChannelOBufferLock); \
  250. INITIALIZE_LOCK(_Channel->ChannelIBufferLock);
  251. #define ASSERT_CHANNEL_LOCKS_SIGNALED(_Channel) \
  252. ASSERT(LOCK_IS_SIGNALED(_Channel->ChannelAttributeLock)); \
  253. ASSERT(LOCK_HAS_ZERO_REF_COUNT(_Channel->ChannelAttributeLock)); \
  254. ASSERT(LOCK_IS_SIGNALED(_Channel->ChannelOBufferLock)); \
  255. ASSERT(LOCK_HAS_ZERO_REF_COUNT(_Channel->ChannelOBufferLock)); \
  256. ASSERT(LOCK_IS_SIGNALED(_Channel->ChannelIBufferLock)); \
  257. ASSERT(LOCK_HAS_ZERO_REF_COUNT(_Channel->ChannelIBufferLock));
  258. #define LOCK_CHANNEL_ATTRIBUTES(_Channel) \
  259. ACQUIRE_LOCK(_Channel->ChannelAttributeLock)
  260. #define UNLOCK_CHANNEL_ATTRIBUTES(_Channel) \
  261. RELEASE_LOCK(_Channel->ChannelAttributeLock)
  262. #define LOCK_CHANNEL_OBUFFER(_Channel) \
  263. ACQUIRE_LOCK(_Channel->ChannelOBufferLock)
  264. #define UNLOCK_CHANNEL_OBUFFER(_Channel) \
  265. RELEASE_LOCK(_Channel->ChannelOBufferLock)
  266. #define LOCK_CHANNEL_IBUFFER(_Channel) \
  267. ACQUIRE_LOCK(_Channel->ChannelIBufferLock)
  268. #define UNLOCK_CHANNEL_IBUFFER(_Channel) \
  269. RELEASE_LOCK(_Channel->ChannelIBufferLock)
  270. //
  271. // Macros for get/set operations on most of the channel's attributes
  272. //
  273. // Note: If the operation can be done use InterlockedXXX,
  274. // then it should be done here.
  275. //
  276. #define ChannelGetHandle(_Channel) (_Channel->Handle)
  277. #define ChannelGetType(_Channel) (_Channel->Type)
  278. #define ChannelSetType(_Channel, _v) (InterlockedExchange((volatile long *)&(_Channel->Status), _v))
  279. #define ChannelSentToScreen(_Channel) ((BOOLEAN)_Channel->SentToScreen)
  280. #define ChannelSetSentToScreen(_Channel, _f) (InterlockedExchange((volatile long *)&(_Channel->SentToScreen), _f))
  281. #define ChannelHasNewOBufferData(_Channel) ((BOOLEAN)_Channel->OBufferHasNewData)
  282. #define ChannelSetOBufferHasNewData(_Channel, _f) (InterlockedExchange((volatile long *)&(_Channel->OBufferHasNewData), _f))
  283. #define ChannelHasNewIBufferData(_Channel) ((BOOLEAN)_Channel->IBufferHasNewData)
  284. #define ChannelSetIBufferHasNewData(_Channel, _f) (InterlockedExchange((volatile long *)&(_Channel->IBufferHasNewData), _f))
  285. #define ChannelGetFlags(_Channel) (_Channel->Flags)
  286. #define ChannelSetFlags(_Channel, _f) (InterlockedExchange((volatile long *)&(_Channel->Flags), _f))
  287. #define ChannelGetIndex(_Channel) (_Channel->Index)
  288. #define ChannelSetIndex(_Channel, _v) (InterlockedExchange((volatile long *)&(_Channel->Index), _v))
  289. #define ChannelGetFileObject(_Channel) (_Channel->FileObject)
  290. #define ChannelSetFileObject(_Channel, _v) (InterlockedExchangePointer(&(_Channel->FileObject), _v))
  291. #if ENABLE_CHANNEL_LOCKING
  292. #define ChannelHasLockEvent(_Channel) (_Channel->LockEvent ? TRUE : FALSE)
  293. #endif
  294. //
  295. // Prototypes
  296. //
  297. BOOLEAN
  298. ChannelIsValidType(
  299. SAC_CHANNEL_TYPE ChannelType
  300. );
  301. BOOLEAN
  302. ChannelIsActive(
  303. IN PSAC_CHANNEL Channel
  304. );
  305. BOOLEAN
  306. ChannelIsEqual(
  307. IN PSAC_CHANNEL Channel,
  308. IN PSAC_CHANNEL_HANDLE ChannelHandle
  309. );
  310. BOOLEAN
  311. ChannelIsClosed(
  312. IN PSAC_CHANNEL Channel
  313. );
  314. NTSTATUS
  315. ChannelCreate(
  316. OUT PSAC_CHANNEL Channel,
  317. IN PSAC_CHANNEL_OPEN_ATTRIBUTES Attributes,
  318. IN SAC_CHANNEL_HANDLE ChannelHandle
  319. );
  320. NTSTATUS
  321. ChannelClose(
  322. PSAC_CHANNEL Channel
  323. );
  324. NTSTATUS
  325. ChannelDestroy(
  326. IN PSAC_CHANNEL Channel
  327. );
  328. WCHAR
  329. ChannelIReadLast(
  330. IN PSAC_CHANNEL Channel
  331. );
  332. NTSTATUS
  333. ChannelInitializeVTable(
  334. IN PSAC_CHANNEL Channel
  335. );
  336. NTSTATUS
  337. ChannelOWrite(
  338. IN PSAC_CHANNEL Channel,
  339. IN PCUCHAR Buffer,
  340. IN ULONG BufferSize
  341. );
  342. NTSTATUS
  343. ChannelOFlush(
  344. IN PSAC_CHANNEL Channel
  345. );
  346. NTSTATUS
  347. ChannelOEcho(
  348. IN PSAC_CHANNEL Channel,
  349. IN PCUCHAR Buffer,
  350. IN ULONG BufferSize
  351. );
  352. NTSTATUS
  353. ChannelORead(
  354. IN PSAC_CHANNEL Channel,
  355. IN PUCHAR Buffer,
  356. IN ULONG BufferSize,
  357. OUT PULONG ByteCount
  358. );
  359. NTSTATUS
  360. ChannelIWrite(
  361. IN PSAC_CHANNEL Channel,
  362. IN PCUCHAR Buffer,
  363. IN ULONG BufferSize
  364. );
  365. NTSTATUS
  366. ChannelIRead(
  367. IN PSAC_CHANNEL Channel,
  368. IN PUCHAR Buffer,
  369. IN ULONG BufferSize,
  370. OUT PULONG ByteCount
  371. );
  372. WCHAR
  373. ChannelIReadLast(
  374. IN PSAC_CHANNEL Channel
  375. );
  376. NTSTATUS
  377. ChannelIBufferIsFull(
  378. IN PSAC_CHANNEL Channel,
  379. OUT BOOLEAN* BufferStatus
  380. );
  381. ULONG
  382. ChannelIBufferLength(
  383. IN PSAC_CHANNEL Channel
  384. );
  385. NTSTATUS
  386. ChannelGetName(
  387. IN PSAC_CHANNEL Channel,
  388. OUT PWSTR* Name
  389. );
  390. NTSTATUS
  391. ChannelSetName(
  392. IN PSAC_CHANNEL Channel,
  393. IN PCWSTR Name
  394. );
  395. NTSTATUS
  396. ChannelGetDescription(
  397. IN PSAC_CHANNEL Channel,
  398. OUT PWSTR* Name
  399. );
  400. NTSTATUS
  401. ChannelSetDescription(
  402. IN PSAC_CHANNEL Channel,
  403. IN PCWSTR Name
  404. );
  405. NTSTATUS
  406. ChannelSetStatus(
  407. IN PSAC_CHANNEL Channel,
  408. IN SAC_CHANNEL_STATUS Status
  409. );
  410. NTSTATUS
  411. ChannelGetStatus(
  412. IN PSAC_CHANNEL Channel,
  413. OUT SAC_CHANNEL_STATUS* Status
  414. );
  415. NTSTATUS
  416. ChannelSetApplicationType(
  417. IN PSAC_CHANNEL Channel,
  418. IN GUID ApplicationType
  419. );
  420. NTSTATUS
  421. ChannelGetApplicationType(
  422. IN PSAC_CHANNEL Channel,
  423. IN GUID* ApplicationType
  424. );
  425. #if ENABLE_CHANNEL_LOCKING
  426. NTSTATUS
  427. ChannelSetLockEvent(
  428. IN PSAC_CHANNEL Channel
  429. );
  430. #endif
  431. NTSTATUS
  432. ChannelSetRedrawEvent(
  433. IN PSAC_CHANNEL Channel
  434. );
  435. NTSTATUS
  436. ChannelClearRedrawEvent(
  437. IN PSAC_CHANNEL Channel
  438. );
  439. NTSTATUS
  440. ChannelHasRedrawEvent(
  441. IN PSAC_CHANNEL Channel,
  442. OUT PBOOLEAN Present
  443. );
  444. #endif