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.

199 lines
6.1 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1998-2000 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: CommandData.h
  6. * Content: Declaration of class representing a command
  7. *
  8. *
  9. * History:
  10. * Date By Reason
  11. * ==== == ======
  12. * 04/07/99 jtk Derived from SPData.h
  13. ***************************************************************************/
  14. #ifndef __COMMAND_DATA_H__
  15. #define __COMMAND_DATA_H__
  16. #undef DPF_SUBCOMP
  17. #define DPF_SUBCOMP DN_SUBCOMP_MODEM
  18. //**********************************************************************
  19. // Constant definitions
  20. //**********************************************************************
  21. typedef enum
  22. {
  23. COMMAND_STATE_UNKNOWN, // unknown state
  24. COMMAND_STATE_PENDING, // command waiting to be processed
  25. COMMAND_STATE_INPROGRESS, // command is executing
  26. COMMAND_STATE_INPROGRESS_CANNOT_CANCEL, // command is executing, can't be cancelled
  27. COMMAND_STATE_CANCELLING, // command is already being cancelled
  28. } COMMAND_STATE;
  29. typedef enum
  30. {
  31. COMMAND_TYPE_UNKNOWN, // unknown command
  32. COMMAND_TYPE_CONNECT, // connect command
  33. COMMAND_TYPE_LISTEN, // listen command
  34. COMMAND_TYPE_ENUM_QUERY, // enum command
  35. COMMAND_TYPE_SEND, // data send command (enum, enum query, send)
  36. } COMMAND_TYPE;
  37. #define NULL_DESCRIPTOR 0
  38. //**********************************************************************
  39. // Macro definitions
  40. //**********************************************************************
  41. //**********************************************************************
  42. // Structure definitions
  43. //**********************************************************************
  44. //
  45. // forward class and structure references
  46. //
  47. class CModemEndpoint;
  48. //**********************************************************************
  49. // Variable definitions
  50. //**********************************************************************
  51. //**********************************************************************
  52. // Function prototypes
  53. //**********************************************************************
  54. //**********************************************************************
  55. // Class definitions
  56. //**********************************************************************
  57. //
  58. // class for command data
  59. //
  60. class CModemCommandData
  61. {
  62. public:
  63. void Lock( void ) { DNEnterCriticalSection( &m_Lock ); }
  64. void Unlock( void ) { DNLeaveCriticalSection( &m_Lock ); }
  65. DWORD GetDescriptor( void ) const { return m_dwDescriptor; }
  66. void SetDescriptor( void )
  67. {
  68. m_dwDescriptor = m_dwNextDescriptor;
  69. m_dwNextDescriptor++;
  70. if ( m_dwNextDescriptor == NULL_DESCRIPTOR )
  71. {
  72. m_dwNextDescriptor++;
  73. }
  74. SetState( COMMAND_STATE_UNKNOWN );
  75. }
  76. COMMAND_STATE GetState( void ) const { return m_State; }
  77. #undef DPF_MODNAME
  78. #define DPF_MODNAME "CModemCommandData::SetState"
  79. void SetState( const COMMAND_STATE State )
  80. {
  81. DNASSERT( ( ( m_State == COMMAND_STATE_UNKNOWN ) || ( State == COMMAND_STATE_UNKNOWN ) ) ||
  82. ( ( m_State == COMMAND_STATE_PENDING ) && ( State == COMMAND_STATE_INPROGRESS ) ) ||
  83. ( ( m_State == COMMAND_STATE_PENDING ) && ( State == COMMAND_STATE_INPROGRESS_CANNOT_CANCEL ) ) ||
  84. ( ( m_State == COMMAND_STATE_PENDING ) && ( State == COMMAND_STATE_CANCELLING ) ) ||
  85. ( ( m_State == COMMAND_STATE_INPROGRESS ) && ( State == COMMAND_STATE_CANCELLING ) ) );
  86. m_State = State;
  87. }
  88. COMMAND_TYPE GetType( void ) const { return m_Type; }
  89. #undef DPF_MODNAME
  90. #define DPF_MODNAME "CModemCommandData::SetType"
  91. void SetType( const COMMAND_TYPE Type )
  92. {
  93. DNASSERT( ( m_Type == COMMAND_TYPE_UNKNOWN ) || ( Type == COMMAND_TYPE_UNKNOWN ) );
  94. m_Type = Type;
  95. }
  96. CModemEndpoint *GetEndpoint( void ) { return m_pEndpoint; }
  97. #undef DPF_MODNAME
  98. #define DPF_MODNAME "CModemCommandData::SetEndpoint"
  99. void SetEndpoint( CModemEndpoint *const pEndpoint )
  100. {
  101. DNASSERT( ( m_pEndpoint == NULL ) || ( pEndpoint == NULL ) );
  102. m_pEndpoint = pEndpoint;
  103. }
  104. void *GetUserContext( void ){ return m_pUserContext; }
  105. #undef DPF_MODNAME
  106. #define DPF_MODNAME "CModemCommandData::SetUserContext"
  107. void SetUserContext( void *const pUserContext )
  108. {
  109. DNASSERT( ( m_pUserContext == NULL ) || ( pUserContext == NULL ) );
  110. m_pUserContext = pUserContext;
  111. }
  112. void AddToActiveCommandList( CBilink *const pLinkage ) { m_CommandListLinkage.InsertAfter( pLinkage ); }
  113. void RemoveFromActiveCommandList( void ) { m_CommandListLinkage.RemoveFromList(); }
  114. void Reset( void );
  115. //
  116. // pool functions
  117. //
  118. static BOOL PoolAllocFunction( void* pvItem, void* pvContext );
  119. static void PoolInitFunction( void* pvItem, void* pvContext );
  120. static void PoolReleaseFunction( void* pvItem );
  121. static void PoolDeallocFunction( void* pvItem );
  122. void ReturnSelfToPool( void );
  123. #undef DPF_MODNAME
  124. #define DPF_MODNAME "CModemCommandData::AddRef"
  125. void AddRef( void )
  126. {
  127. DPFX(DPFPREP, 8, "AddRef CModemCommandData (%p), refcount = %d", this, m_iRefCount + 1);
  128. DNASSERT( m_iRefCount != 0 );
  129. DNInterlockedIncrement( &m_iRefCount );
  130. }
  131. #undef DPF_MODNAME
  132. #define DPF_MODNAME "CModemCommandData::DecRef"
  133. void DecRef( void )
  134. {
  135. DPFX(DPFPREP, 8, "DecRef CModemCommandData (%p), refcount = %d", this, m_iRefCount - 1);
  136. DNASSERT( m_iRefCount != 0 );
  137. if ( DNInterlockedDecrement( &m_iRefCount ) == 0 )
  138. {
  139. ReturnSelfToPool();
  140. }
  141. }
  142. protected:
  143. private:
  144. #ifndef DPNBUILD_ONLYONETHREAD
  145. DNCRITICAL_SECTION m_Lock;
  146. #endif // !DPNBUILD_ONLYONETHREAD
  147. CBilink m_CommandListLinkage;
  148. volatile DWORD m_dwDescriptor;
  149. volatile DWORD m_dwNextDescriptor;
  150. volatile COMMAND_STATE m_State;
  151. COMMAND_TYPE m_Type;
  152. CModemEndpoint* m_pEndpoint;
  153. void* m_pUserContext;
  154. volatile LONG m_iRefCount;
  155. //
  156. // prevent unwarranted copies
  157. //
  158. CModemCommandData( const CModemCommandData & );
  159. CModemCommandData& operator=( const CModemCommandData & );
  160. };
  161. #undef DPF_MODNAME
  162. #endif // __COMMAND_DATA_H__