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.

351 lines
11 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1998-2000 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: IOData.h
  6. * Content: Structure definitions for IOData for the DNSerial service provider
  7. *
  8. *
  9. * History:
  10. * Date By Reason
  11. * ==== == ======
  12. * 11/25/98 jtk Created
  13. * 09/14/99 jtk Dereived from Locals.h
  14. ***************************************************************************/
  15. #ifndef __IODDATA_H__
  16. #define __IODDATA_H__
  17. #undef DPF_SUBCOMP
  18. #define DPF_SUBCOMP DN_SUBCOMP_MODEM
  19. //**********************************************************************
  20. // Constant definitions
  21. //**********************************************************************
  22. //
  23. // enumerated types for what action to take when a send completes
  24. //
  25. typedef enum _SEND_COMPLETE_ACTION
  26. {
  27. SEND_COMPLETE_ACTION_UNKNOWN = 0, // unknown value
  28. SEND_COMPLETE_ACTION_NONE, // no action
  29. SEND_COMPLETE_ACTION_COMPLETE_COMMAND // complete command
  30. } SEND_COMPLETE_ACTION;
  31. //
  32. // enumerated values for state of reads
  33. //
  34. typedef enum _READ_STATE
  35. {
  36. READ_STATE_UNKNOWN, // unknown state
  37. // READ_STATE_INITIALIZE, // initialize state machine
  38. READ_STATE_READ_HEADER, // read header information
  39. READ_STATE_READ_DATA // read message data
  40. } READ_STATE;
  41. typedef enum _NT_IO_OPERATION_TYPE
  42. {
  43. NT_IO_OPERATION_UNKNOWN,
  44. NT_IO_OPERATION_RECEIVE,
  45. NT_IO_OPERATION_SEND
  46. } NT_IO_OPERATION_TYPE;
  47. //**********************************************************************
  48. // Macro definitions
  49. //**********************************************************************
  50. //**********************************************************************
  51. // Structure definitions
  52. //**********************************************************************
  53. //
  54. // forward class and structure references
  55. //
  56. //typedef struct _RECEIVE_BUFFER RECEIVE_BUFFER;
  57. class CModemCommandData;
  58. class CDataPort;
  59. class CIOData;
  60. class CModemThreadPool;
  61. //
  62. // structure used to prefix a message on the wire for framing
  63. //
  64. #pragma pack( push, 1 )
  65. typedef struct _MESSAGE_HEADER
  66. {
  67. BYTE SerialSignature; // serial signature
  68. BYTE MessageTypeToken; // token to indicate message type
  69. WORD wMessageSize; // message data size
  70. WORD wMessageCRC; // CRC of message data
  71. WORD wHeaderCRC; // CRC of header
  72. } MESSAGE_HEADER;
  73. #pragma pack( pop )
  74. //
  75. // class containing all data for I/O completion
  76. //
  77. class CIOData
  78. {
  79. public:
  80. CDataPort *DataPort( void ) const { return m_pDataPort; }
  81. #undef DPF_MODNAME
  82. #define DPF_MODNAME "CIOData::SetDataPort"
  83. void SetDataPort( CDataPort *const pDataPort )
  84. {
  85. DNASSERT( ( m_pDataPort == NULL ) || ( pDataPort == NULL ) );
  86. m_pDataPort = pDataPort;
  87. }
  88. #ifdef WIN95
  89. BOOL Win9xOperationPending( void ) const { return m_fWin9xOperationPending; }
  90. void SetWin9xOperationPending( const BOOL fOperationPending ) { m_fWin9xOperationPending = fOperationPending; }
  91. #endif // WIN95
  92. #ifdef WINNT
  93. NT_IO_OPERATION_TYPE NTIOOperationType( void ) const { return m_NTIOOperationType; }
  94. #undef DPF_MODNAME
  95. #define DPF_MODNAME "CIOData::SetNTIOOperationType"
  96. void SetNTIOOperationType( const NT_IO_OPERATION_TYPE OperationType )
  97. {
  98. DNASSERT( ( OperationType == NT_IO_OPERATION_UNKNOWN ) ||
  99. ( m_NTIOOperationType == NT_IO_OPERATION_UNKNOWN ) );
  100. m_NTIOOperationType = OperationType;
  101. }
  102. #endif // WINNT
  103. OVERLAPPED *Overlap( void ) { return &m_Overlap; }
  104. #ifdef WIN95
  105. HANDLE OverlapEvent( void ) const { return m_Overlap.hEvent; }
  106. #undef DPF_MODNAME
  107. #define DPF_MODNAME "CIOData::SetOverlapEvent"
  108. void SetOverlapEvent( const HANDLE hEvent )
  109. {
  110. DNASSERT( ( m_Overlap.hEvent == NULL ) || ( hEvent == NULL ) );
  111. m_Overlap.hEvent = hEvent;
  112. }
  113. #endif // WIN95
  114. #undef DPF_MODNAME
  115. #define DPF_MODNAME "CIOData::IODataFromOverlap"
  116. static CIOData *IODataFromOverlap( OVERLAPPED *const pOverlap )
  117. {
  118. DNASSERT( pOverlap != NULL );
  119. DBG_CASSERT( sizeof( BYTE* ) == sizeof( pOverlap ) );
  120. DBG_CASSERT( sizeof( CIOData* ) == sizeof( BYTE* ) );
  121. return reinterpret_cast<CIOData*>( &reinterpret_cast<BYTE*>( pOverlap )[ -OFFSETOF( CIOData, m_Overlap ) ] );
  122. }
  123. protected:
  124. OVERLAPPED m_Overlap; // overlapped I/O structure
  125. #ifdef WINNT
  126. NT_IO_OPERATION_TYPE m_NTIOOperationType;
  127. #endif // WINNT
  128. CDataPort *m_pDataPort; // pointer to data port associated with this IO request
  129. #ifdef WIN95
  130. BOOL m_fWin9xOperationPending; // this structure has been initialized and the operation is pending on Win9x
  131. #endif // WIN95
  132. //
  133. // prevent unwarranted copies
  134. //
  135. CIOData( const CIOData & );
  136. CIOData& operator=( const CIOData & );
  137. };
  138. //
  139. // all data for a read operation
  140. //
  141. class CModemReadIOData : public CIOData
  142. {
  143. public:
  144. #undef DPF_MODNAME
  145. #define DPF_MODNAME "CModemReadIOData::AddRef"
  146. void AddRef( void )
  147. {
  148. DNASSERT( m_lRefCount != 0 );
  149. DNInterlockedIncrement( &m_lRefCount );
  150. }
  151. #undef DPF_MODNAME
  152. #define DPF_MODNAME "CModemReadIOData::DecRef"
  153. void DecRef( void )
  154. {
  155. DNASSERT( m_lRefCount != 0 );
  156. if ( DNInterlockedDecrement( &m_lRefCount ) == 0 )
  157. {
  158. ReturnSelfToPool();
  159. }
  160. }
  161. CBilink m_OutstandingReadListLinkage; // links to the unbound list
  162. //
  163. // I/O variables
  164. //
  165. DWORD m_dwWin9xReceiveErrorReturn; // Win9x error return
  166. DWORD jkm_dwOverlappedBytesReceived; // used in GetOverlappedResult()
  167. DWORD jkm_dwImmediateBytesReceived; // used as an immediate for ReadFile()
  168. //
  169. // read state
  170. //
  171. READ_STATE m_ReadState; // state of READ
  172. DWORD m_dwBytesToRead; // bytes to read
  173. DWORD m_dwReadOffset; // destination offset into read buffer
  174. //
  175. // read buffers
  176. //
  177. SPRECEIVEDBUFFER m_SPReceivedBuffer; // received buffer data that is handed to the application
  178. union
  179. {
  180. MESSAGE_HEADER MessageHeader; // template for message header
  181. BYTE ReceivedData[ MAX_MESSAGE_SIZE ]; // full buffer for received data
  182. } m_ReceiveBuffer;
  183. READ_STATE ReadState( void ) const { return m_ReadState; }
  184. #undef DPF_MODNAME
  185. #define DPF_MODNAME "CModemReadIOData::SetReadState"
  186. void SetReadState( const READ_STATE ReadState )
  187. {
  188. DNASSERT( ( m_ReadState == READ_STATE_UNKNOWN ) ||
  189. ( ReadState == READ_STATE_UNKNOWN ) ||
  190. ( ( m_ReadState == READ_STATE_READ_HEADER ) && ( ReadState == READ_STATE_READ_DATA ) ) ); // valid header read, start reading data
  191. m_ReadState = ReadState;
  192. }
  193. #undef DPF_MODNAME
  194. #define DPF_MODNAME "CModemReadIOData::SetThreadPool"
  195. void SetThreadPool( CModemThreadPool *const pThreadPool )
  196. {
  197. DNASSERT( ( m_pThreadPool == NULL ) || ( pThreadPool == NULL ) );
  198. m_pThreadPool = pThreadPool;
  199. }
  200. #undef DPF_MODNAME
  201. #define DPF_MODNAME "CModemReadIOData::ReadDataFromBilink"
  202. static CModemReadIOData *ReadDataFromBilink( CBilink *const pBilink )
  203. {
  204. DNASSERT( pBilink != NULL );
  205. DBG_CASSERT( sizeof( BYTE* ) == sizeof( pBilink ) );
  206. DBG_CASSERT( sizeof( CIOData* ) == sizeof( BYTE* ) );
  207. return reinterpret_cast<CModemReadIOData*>( &reinterpret_cast<BYTE*>( pBilink )[ -OFFSETOF( CModemReadIOData, m_OutstandingReadListLinkage ) ] );
  208. }
  209. #undef DPF_MODNAME
  210. #define DPF_MODNAME "CModemReadIOData::ReadDataFromSPReceivedBuffer"
  211. static CModemReadIOData *ReadDataFromSPReceivedBuffer( SPRECEIVEDBUFFER *const pSPReceivedBuffer )
  212. {
  213. DNASSERT( pSPReceivedBuffer != NULL );
  214. DBG_CASSERT( sizeof( BYTE* ) == sizeof( pSPReceivedBuffer ) );
  215. DBG_CASSERT( sizeof( CModemReadIOData* ) == sizeof( BYTE* ) );
  216. return reinterpret_cast<CModemReadIOData*>( &reinterpret_cast<BYTE*>( pSPReceivedBuffer )[ -OFFSETOF( CModemReadIOData, m_SPReceivedBuffer ) ] );
  217. }
  218. //
  219. // functions for managing read IO data pool
  220. //
  221. static BOOL PoolAllocFunction( void* pvItem, void* pvContext );
  222. static void PoolInitFunction( void* pvItem, void* pvContext );
  223. static void PoolReleaseFunction( void* pvItem );
  224. static void PoolDeallocFunction( void* pvItem );
  225. private:
  226. void ReturnSelfToPool( void );
  227. BYTE m_Sig[4]; // debugging signature ('RIOD')
  228. volatile LONG m_lRefCount;
  229. CModemThreadPool *m_pThreadPool;
  230. //
  231. // prevent unwarranted copies
  232. //
  233. CModemReadIOData( const CModemReadIOData & );
  234. CModemReadIOData& operator=( const CModemReadIOData & );
  235. };
  236. //
  237. // all data for a write operation
  238. //
  239. class CModemWriteIOData : public CIOData
  240. {
  241. public:
  242. CModemWriteIOData *m_pNext; // link to next write in the send queue (see CSendQueue)
  243. CBilink m_OutstandingWriteListLinkage; // links to the outstanding write list
  244. BUFFERDESC *m_pBuffers; // pointer to outgoing buffers
  245. UINT_PTR m_uBufferCount; // count of outgoing buffers
  246. CModemCommandData *m_pCommand; // associated command
  247. SEND_COMPLETE_ACTION m_SendCompleteAction; // enumerated value indicating the action to take
  248. // when a send completes
  249. //
  250. // I/O variables
  251. //
  252. HRESULT jkm_hSendResult;
  253. DWORD jkm_dwOverlappedBytesSent; // used in GetOverlappedResult()
  254. DWORD jkm_dwImmediateBytesSent; // used as an immediate for WriteFile()
  255. //
  256. // Since the following is a packed structure, put it at the end
  257. // to preserve as much alignment as possible with the
  258. // above fields
  259. //
  260. union
  261. {
  262. MESSAGE_HEADER MessageHeader; // data prepended on a write
  263. BYTE Data[ MAX_MESSAGE_SIZE ]; // data buffer to flatten outgoing data
  264. } m_DataBuffer;
  265. static CModemWriteIOData *WriteDataFromBilink( CBilink *const pBilink )
  266. {
  267. DNASSERT( pBilink != NULL );
  268. DBG_CASSERT( sizeof( BYTE* ) == sizeof( pBilink ) );
  269. DBG_CASSERT( sizeof( CModemWriteIOData* ) == sizeof( BYTE* ) );
  270. return reinterpret_cast<CModemWriteIOData*>( &reinterpret_cast<BYTE*>( pBilink )[ -OFFSETOF( CModemWriteIOData, m_OutstandingWriteListLinkage ) ] );
  271. }
  272. //
  273. // functions for managing write IO data pool
  274. //
  275. static BOOL PoolAllocFunction( void* pvItem, void* pvContext );
  276. static void PoolInitFunction( void* pvItem, void* pvContext );
  277. static void PoolReleaseFunction( void* pvItem );
  278. static void PoolDeallocFunction( void* pvItem );
  279. private:
  280. BYTE m_Sig[4]; // debugging signature ('WIOD')
  281. //
  282. // prevent unwarranted copies
  283. //
  284. CModemWriteIOData( const CModemWriteIOData & );
  285. CModemWriteIOData& operator=( const CModemWriteIOData & );
  286. };
  287. //**********************************************************************
  288. // Variable definitions
  289. //**********************************************************************
  290. //**********************************************************************
  291. // Function prototypes
  292. //**********************************************************************
  293. #undef DPF_MODNAME
  294. #endif // __IODDATA_H__