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.

172 lines
5.5 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1998-2000 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: ComPortData.h
  6. * Content: Serial communications port data management class
  7. *
  8. *
  9. * History:
  10. * Date By Reason
  11. * ==== == ======
  12. * 01/20/1998 jtk Created
  13. * 04/25/2000 jtk Derived from ComPort class
  14. ***************************************************************************/
  15. #ifndef __COM_PORT_DATA_H__
  16. #define __COM_PORT_DATA_H__
  17. //**********************************************************************
  18. // Constant definitions
  19. //**********************************************************************
  20. //
  21. // maximum length of comport string
  22. //
  23. #define MAX_COMPORT_LENGTH 10
  24. //
  25. // enumerated values for noting which components have been initialized
  26. //
  27. typedef enum _COMPORT_PARSE_KEY_INDEX
  28. {
  29. COMPORT_PARSE_KEY_DEVICE = 0,
  30. COMPORT_PARSE_KEY_BAUDRATE,
  31. COMPORT_PARSE_KEY_STOPBITS,
  32. COMPORT_PARSE_KEY_PARITY,
  33. COMPORT_PARSE_KEY_FLOWCONTROL,
  34. // this must be the last item
  35. COMPORT_PARSE_KEY_MAX
  36. } COMPORT_PARSE_KEY_INDEX;
  37. //**********************************************************************
  38. // Macro definitions
  39. //**********************************************************************
  40. //**********************************************************************
  41. // Structure definitions
  42. //**********************************************************************
  43. //
  44. // string blocks for parsing com port parameters
  45. //
  46. typedef enum _ADDRESS_TYPE ADDRESS_TYPE;
  47. typedef struct _STRING_BLOCK STRING_BLOCK;
  48. extern STRING_BLOCK g_BaudRate[];
  49. extern const DWORD g_dwBaudRateCount;
  50. extern STRING_BLOCK g_StopBits[];
  51. extern const DWORD g_dwStopBitsCount;
  52. extern STRING_BLOCK g_Parity[];
  53. extern const DWORD g_dwParityCount;
  54. extern STRING_BLOCK g_FlowControl[];
  55. extern const DWORD g_dwFlowControlCount;
  56. //**********************************************************************
  57. // Variable definitions
  58. //**********************************************************************
  59. //**********************************************************************
  60. // Function prototypes
  61. //**********************************************************************
  62. //**********************************************************************
  63. // Class definition
  64. //**********************************************************************
  65. class CComPortData
  66. {
  67. public:
  68. CComPortData();
  69. ~CComPortData();
  70. HRESULT CComPortData::ComPortDataFromDP8Addresses( IDirectPlay8Address *const pHostAddress,
  71. IDirectPlay8Address *const pDeviceAddress );
  72. IDirectPlay8Address *CComPortData::DP8AddressFromComPortData( const ADDRESS_TYPE AddressType ) const;
  73. DWORD GetDeviceID( void ) const { return m_dwDeviceID; }
  74. HRESULT SetDeviceID( const DWORD dwDeviceID );
  75. SP_BAUD_RATE GetBaudRate( void ) const { return m_BaudRate; }
  76. HRESULT SetBaudRate( const SP_BAUD_RATE BaudRate );
  77. SP_STOP_BITS GetStopBits( void ) const { return m_StopBits; }
  78. HRESULT SetStopBits( const SP_STOP_BITS StopBits );
  79. SP_PARITY_TYPE GetParity( void ) const { return m_Parity; }
  80. HRESULT SetParity( const SP_PARITY_TYPE Parity );
  81. SP_FLOW_CONTROL GetFlowControl( void ) const { return m_FlowControl; }
  82. HRESULT SetFlowControl( const SP_FLOW_CONTROL FlowControl );
  83. void ClearComPortName( void ) { memset( &m_ComPortName, 0x00, sizeof( m_ComPortName ) ); }
  84. TCHAR *ComPortName( void ) { return m_ComPortName; }
  85. BOOL IsEqual ( const CComPortData *const pOtherData ) const;
  86. void Copy( const CComPortData *const pOtherData );
  87. void Reset( void )
  88. {
  89. SetDeviceID( INVALID_DEVICE_ID );
  90. SetBaudRate( CBR_57600 );
  91. SetStopBits( ONESTOPBIT );
  92. SetParity( NOPARITY );
  93. SetFlowControl( FLOW_NONE );
  94. memset( &m_ComponentInitializationState, 0x00, sizeof( m_ComponentInitializationState ) );
  95. }
  96. protected:
  97. private:
  98. DWORD m_dwDeviceID;
  99. //
  100. // com port information
  101. //
  102. TCHAR m_ComPortName[ MAX_COMPORT_LENGTH ]; // name of com port
  103. //
  104. // communications parameters
  105. //
  106. SP_BAUD_RATE m_BaudRate; // baud rate
  107. SP_STOP_BITS m_StopBits; // stop bits
  108. SP_PARITY_TYPE m_Parity; // parity
  109. SP_FLOW_CONTROL m_FlowControl; // flow control
  110. //
  111. // values indicating which components have been initialized
  112. //
  113. SP_ADDRESS_COMPONENT_STATE m_ComponentInitializationState[ COMPORT_PARSE_KEY_MAX ];
  114. static HRESULT ParseDevice( const void *const pAddressComponent,
  115. const DWORD dwComponentSize,
  116. const DWORD dwComponentType,
  117. void *const pContext );
  118. static HRESULT ParseBaud( const void *const pAddressComponent,
  119. const DWORD dwComponentSize,
  120. const DWORD dwComponentType,
  121. void *const pContext );
  122. static HRESULT ParseStopBits( const void *const pAddressComponent,
  123. const DWORD dwComponentSize,
  124. const DWORD dwComponentType,
  125. void *const pContext );
  126. static HRESULT ParseParity( const void *const pAddressComponent,
  127. const DWORD dwComponentSize,
  128. const DWORD dwComponentType,
  129. void *const pContext );
  130. static HRESULT ParseFlowControl( const void *const pAddressComponent,
  131. const DWORD dwComponentSize,
  132. const DWORD dwComponentType,
  133. void *const pContext );
  134. // prevent unwarranted copies
  135. CComPortData( const CComPortData & );
  136. CComPortData& operator=( const CComPortData & );
  137. };
  138. #endif // __COM_PORT_DATA_H__