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.

564 lines
6.9 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. COMM_DEVICE
  5. Abstract:
  6. This module contains the definition for the COMM_DEVICE class.
  7. Author:
  8. Ramon J. San Andres (ramonsa) 08-Jul-91
  9. Environment:
  10. ULIB, User Mode
  11. Notes:
  12. --*/
  13. #if !defined (_COMM_DEVICE_)
  14. #define _COMM_DEVICE_
  15. DECLARE_CLASS( FSN_FILE );
  16. DECLARE_CLASS( FILE_STREAM );
  17. DECLARE_CLASS( COMM_DEVICE );
  18. //
  19. // PARITY
  20. //
  21. enum PARITY {
  22. COMM_PARITY_NONE = NOPARITY,
  23. COMM_PARITY_EVEN = EVENPARITY,
  24. COMM_PARITY_ODD = ODDPARITY,
  25. COMM_PARITY_MARK = MARKPARITY,
  26. COMM_PARITY_SPACE = SPACEPARITY
  27. };
  28. //
  29. // STOP BITS
  30. //
  31. enum STOPBITS {
  32. COMM_STOPBITS_1 = ONESTOPBIT,
  33. COMM_STOPBITS_15 = ONE5STOPBITS,
  34. COMM_STOPBITS_2 = TWOSTOPBITS
  35. };
  36. //
  37. // DTR control
  38. //
  39. enum DTR_CONTROL {
  40. DTR_ENABLE = DTR_CONTROL_ENABLE,
  41. DTR_DISABLE = DTR_CONTROL_DISABLE,
  42. DTR_HANDSHAKE = DTR_CONTROL_HANDSHAKE
  43. };
  44. //
  45. // RTS control
  46. //
  47. enum RTS_CONTROL {
  48. RTS_ENABLE = RTS_CONTROL_ENABLE,
  49. RTS_DISABLE = RTS_CONTROL_DISABLE,
  50. RTS_HANDSHAKE = RTS_CONTROL_HANDSHAKE,
  51. RTS_TOGGLE = RTS_CONTROL_TOGGLE
  52. };
  53. class COMM_DEVICE : public OBJECT {
  54. public:
  55. DECLARE_CAST_MEMBER_FUNCTION( COMM_DEVICE );
  56. ULIB_EXPORT
  57. DECLARE_CONSTRUCTOR( COMM_DEVICE );
  58. VIRTUAL
  59. ULIB_EXPORT
  60. ~COMM_DEVICE(
  61. );
  62. NONVIRTUAL
  63. ULIB_EXPORT
  64. BOOLEAN
  65. Initialize (
  66. IN PCPATH PortName,
  67. OUT PBOOLEAN OpenError DEFAULT NULL
  68. );
  69. NONVIRTUAL
  70. ULIB_EXPORT
  71. BOOLEAN
  72. CommitState (
  73. );
  74. NONVIRTUAL
  75. ULONG
  76. QueryBaudRate (
  77. ) CONST;
  78. NONVIRTUAL
  79. ULONG
  80. QueryDataBits (
  81. ) CONST;
  82. NONVIRTUAL
  83. DTR_CONTROL
  84. QueryDtrControl (
  85. ) CONST;
  86. NONVIRTUAL
  87. BOOLEAN
  88. QueryIdsr (
  89. ) CONST;
  90. NONVIRTUAL
  91. BOOLEAN
  92. QueryOcts (
  93. ) CONST;
  94. NONVIRTUAL
  95. BOOLEAN
  96. QueryOdsr (
  97. ) CONST;
  98. NONVIRTUAL
  99. PARITY
  100. QueryParity (
  101. ) CONST;
  102. NONVIRTUAL
  103. RTS_CONTROL
  104. QueryRtsControl (
  105. ) CONST;
  106. NONVIRTUAL
  107. STOPBITS
  108. QueryStopBits (
  109. ) CONST;
  110. NONVIRTUAL
  111. ULIB_EXPORT
  112. BOOLEAN
  113. QueryTimeOut (
  114. ) CONST;
  115. NONVIRTUAL
  116. BOOLEAN
  117. QueryXon (
  118. ) CONST;
  119. NONVIRTUAL
  120. BOOLEAN
  121. ReadState (
  122. );
  123. NONVIRTUAL
  124. ULIB_EXPORT
  125. BOOLEAN
  126. SetBaudRate (
  127. IN ULONG BaudRate
  128. );
  129. NONVIRTUAL
  130. ULIB_EXPORT
  131. BOOLEAN
  132. SetDataBits (
  133. IN ULONG DataBits
  134. );
  135. NONVIRTUAL
  136. ULIB_EXPORT
  137. BOOLEAN
  138. SetDtrControl (
  139. IN DTR_CONTROL DtrControl
  140. );
  141. NONVIRTUAL
  142. ULIB_EXPORT
  143. BOOLEAN
  144. SetIdsr (
  145. IN BOOLEAN Idsr
  146. );
  147. NONVIRTUAL
  148. ULIB_EXPORT
  149. BOOLEAN
  150. SetOcts (
  151. IN BOOLEAN Octs
  152. );
  153. NONVIRTUAL
  154. ULIB_EXPORT
  155. BOOLEAN
  156. SetOdsr (
  157. IN BOOLEAN Odsr
  158. );
  159. NONVIRTUAL
  160. ULIB_EXPORT
  161. BOOLEAN
  162. SetParity (
  163. IN PARITY Parity
  164. );
  165. NONVIRTUAL
  166. ULIB_EXPORT
  167. BOOLEAN
  168. SetRtsControl (
  169. IN RTS_CONTROL RtsControl
  170. );
  171. NONVIRTUAL
  172. ULIB_EXPORT
  173. BOOLEAN
  174. SetStopBits (
  175. IN STOPBITS StopBits
  176. );
  177. NONVIRTUAL
  178. ULIB_EXPORT
  179. BOOLEAN
  180. SetTimeOut (
  181. IN BOOLEAN TimeOut
  182. );
  183. NONVIRTUAL
  184. ULIB_EXPORT
  185. BOOLEAN
  186. SetXon (
  187. IN BOOLEAN Xon
  188. );
  189. protected:
  190. private:
  191. VOID
  192. Construct (
  193. );
  194. NONVIRTUAL
  195. VOID
  196. Destroy (
  197. );
  198. HANDLE _Handle; // Handle to the port
  199. DCB _Dcb; // DCB Structure.
  200. #if DBG==1
  201. BOOLEAN _Initialized; // Object has been initialized
  202. #endif // DBG
  203. };
  204. INLINE
  205. ULONG
  206. COMM_DEVICE::QueryBaudRate (
  207. ) CONST
  208. /*++
  209. Routine Description:
  210. Queries the baud rate
  211. Arguments:
  212. none
  213. Return Value:
  214. ULONG - The baud rate.
  215. --*/
  216. {
  217. DebugAssert( _Initialized );
  218. return (ULONG)_Dcb.BaudRate;
  219. }
  220. INLINE
  221. ULONG
  222. COMM_DEVICE::QueryDataBits (
  223. ) CONST
  224. /*++
  225. Routine Description:
  226. Queries the number of data bits
  227. Arguments:
  228. none
  229. Return Value:
  230. ULONG - The number of data bits
  231. --*/
  232. {
  233. DebugAssert( _Initialized );
  234. return (ULONG)_Dcb.ByteSize;
  235. }
  236. INLINE
  237. DTR_CONTROL
  238. COMM_DEVICE::QueryDtrControl (
  239. ) CONST
  240. /*++
  241. Routine Description:
  242. Queries the DTR control
  243. Arguments:
  244. none
  245. Return Value:
  246. DTR_CONTROL - The DTR control
  247. --*/
  248. {
  249. DebugAssert( _Initialized );
  250. return (DTR_CONTROL)_Dcb.fDtrControl;
  251. }
  252. INLINE
  253. BOOLEAN
  254. COMM_DEVICE::QueryIdsr (
  255. ) CONST
  256. /*++
  257. Routine Description:
  258. Queries whether DSR sensitivity is enabled or disabled
  259. Arguments:
  260. none
  261. Return Value:
  262. BOOLEAN - TRUE if DSR sensitivity enabled. FALSE otherwise.
  263. --*/
  264. {
  265. DebugAssert( _Initialized );
  266. return ( _Dcb.fDsrSensitivity != 0 );
  267. }
  268. INLINE
  269. BOOLEAN
  270. COMM_DEVICE::QueryOcts (
  271. ) CONST
  272. /*++
  273. Routine Description:
  274. Queries whether hanshaking using the CTS circuit is enabled or not.
  275. Arguments:
  276. none
  277. Return Value:
  278. BOOLEAN - TRUE if handshaking enabled. FALSE otherwise.
  279. --*/
  280. {
  281. DebugAssert( _Initialized );
  282. return ( _Dcb.fOutxCtsFlow != 0 );
  283. }
  284. INLINE
  285. BOOLEAN
  286. COMM_DEVICE::QueryOdsr (
  287. ) CONST
  288. /*++
  289. Routine Description:
  290. Queries whether handshaking using the DSR circuit is enabled or not
  291. Arguments:
  292. none
  293. Return Value:
  294. BOOLEAN - TRUE if handshaking enabled. FALSE otherwise.
  295. --*/
  296. {
  297. DebugAssert( _Initialized );
  298. return ( _Dcb.fOutxDsrFlow != 0 );
  299. }
  300. INLINE
  301. PARITY
  302. COMM_DEVICE::QueryParity (
  303. ) CONST
  304. /*++
  305. Routine Description:
  306. Queries the parity
  307. Arguments:
  308. none
  309. Return Value:
  310. BYTE - The parity value.
  311. --*/
  312. {
  313. DebugAssert( _Initialized );
  314. return (PARITY)_Dcb.Parity;
  315. }
  316. INLINE
  317. RTS_CONTROL
  318. COMM_DEVICE::QueryRtsControl (
  319. ) CONST
  320. /*++
  321. Routine Description:
  322. Queries the RTS control
  323. Arguments:
  324. none
  325. Return Value:
  326. RTS_CONTROL - The RTS control
  327. --*/
  328. {
  329. DebugAssert( _Initialized );
  330. return (RTS_CONTROL)_Dcb.fRtsControl;
  331. }
  332. INLINE
  333. STOPBITS
  334. COMM_DEVICE::QueryStopBits (
  335. ) CONST
  336. /*++
  337. Routine Description:
  338. Queries the number of stop bits
  339. Arguments:
  340. none
  341. Return Value:
  342. BYTE - The number of stop bits
  343. --*/
  344. {
  345. DebugAssert( _Initialized );
  346. return (STOPBITS)_Dcb.StopBits;
  347. }
  348. INLINE
  349. BOOLEAN
  350. COMM_DEVICE::QueryXon (
  351. ) CONST
  352. /*++
  353. Routine Description:
  354. Queries whether XON/XOFF protocol is enabled or not.
  355. Arguments:
  356. none
  357. Return Value:
  358. BOOLEAN - TRUE if protocol enabled, FALSE otherwise
  359. --*/
  360. {
  361. DebugAssert( _Initialized );
  362. return ( _Dcb.fInX && _Dcb.fOutX );
  363. }
  364. #endif // _COMM_DEVICE_