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.

214 lines
5.6 KiB

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