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.

241 lines
7.0 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: SPData.h
  6. * Content: Global information for the DNSerial service provider in class
  7. * format.
  8. *
  9. *
  10. * History:
  11. * Date By Reason
  12. * ==== == ======
  13. * 03/15/99 jtk Derived from Locals.h
  14. ***************************************************************************/
  15. #ifndef __SPDATA_H__
  16. #define __SPDATA_H__
  17. //**********************************************************************
  18. // Constant definitions
  19. //**********************************************************************
  20. //
  21. // enumeration of the states the SP can be in
  22. //
  23. typedef enum
  24. {
  25. SPSTATE_UNINITIALIZED = 0, // uninitialized state
  26. SPSTATE_INITIALIZED, // service provider has been initialized
  27. SPSTATE_CLOSING // service provider is closing
  28. } SPSTATE;
  29. //**********************************************************************
  30. // Macro definitions
  31. //**********************************************************************
  32. //**********************************************************************
  33. // Structure definitions
  34. //**********************************************************************
  35. //
  36. // forward references
  37. //
  38. class CComPortData;
  39. class CDataPort;
  40. class CModemEndpoint;
  41. class CModemThreadPool;
  42. typedef enum _ENDPOINT_TYPE ENDPOINT_TYPE;
  43. //
  44. // class for information used by the provider
  45. //
  46. class CModemSPData
  47. {
  48. public:
  49. CModemSPData();
  50. ~CModemSPData();
  51. #undef DPF_MODNAME
  52. #define DPF_MODNAME "CModemSPData::AddRef"
  53. DWORD AddRef( void )
  54. {
  55. return DNInterlockedIncrement( &m_lRefCount );
  56. }
  57. #undef DPF_MODNAME
  58. #define DPF_MODNAME "CModemSPData::DecRef"
  59. DWORD DecRef( void )
  60. {
  61. DWORD dwReturn;
  62. DNASSERT( m_lRefCount != 0);
  63. dwReturn = DNInterlockedDecrement( &m_lRefCount );
  64. if ( dwReturn == 0 )
  65. {
  66. //
  67. // WARNING, the following function deletes this object!!!
  68. //
  69. DestroyThisObject();
  70. }
  71. return dwReturn;
  72. }
  73. #undef DPF_MODNAME
  74. #define DPF_MODNAME "CModemSPData::ObjectAddRef"
  75. void ObjectAddRef( void )
  76. {
  77. AddRef();
  78. Lock();
  79. if ( DNInterlockedIncrement( &m_lObjectRefCount ) == 1 )
  80. {
  81. DNASSERT( m_hShutdownEvent != NULL );
  82. if ( DNResetEvent( m_hShutdownEvent ) == FALSE )
  83. {
  84. DWORD dwError;
  85. dwError = GetLastError();
  86. DPFX(DPFPREP, 0, "Failed to reset shutdown event!" );
  87. DisplayErrorCode( 0, dwError );
  88. }
  89. }
  90. Unlock();
  91. }
  92. #undef DPF_MODNAME
  93. #define DPF_MODNAME "CModemSPData::ObjectDecRef"
  94. void ObjectDecRef( void )
  95. {
  96. Lock();
  97. if ( DNInterlockedDecrement( &m_lObjectRefCount ) == 0 )
  98. {
  99. if ( DNSetEvent( m_hShutdownEvent ) == FALSE )
  100. {
  101. DWORD dwError;
  102. dwError = GetLastError();
  103. DPFX(DPFPREP, 0, "Failed to set shutdown event!" );
  104. DisplayErrorCode( 0, dwError );
  105. }
  106. }
  107. Unlock();
  108. DecRef();
  109. }
  110. HRESULT Initialize( const SP_TYPE SPType,
  111. IDP8ServiceProviderVtbl *const pVtbl );
  112. void Shutdown( void );
  113. void Deinitialize( void );
  114. void SetCallbackData( const SPINITIALIZEDATA *const pInitData );
  115. void Lock( void ) { DNEnterCriticalSection( &m_Lock ); }
  116. void Unlock( void ) { DNLeaveCriticalSection( &m_Lock ); }
  117. SPSTATE GetState( void ) const { return m_State; }
  118. void SetState( const SPSTATE NewState ) { m_State = NewState; }
  119. CModemThreadPool *GetThreadPool( void ) const { return m_pThreadPool; }
  120. #undef DPF_MODNAME
  121. #define DPF_MODNAME "CModemSPData::SetThreadPool"
  122. void SetThreadPool( CModemThreadPool *const pThreadPool )
  123. {
  124. DNASSERT( ( m_pThreadPool == NULL ) || ( pThreadPool == NULL ) );
  125. m_pThreadPool = pThreadPool;
  126. }
  127. HRESULT BindEndpoint( CModemEndpoint *const pEndpoint,
  128. const DWORD dwDeviceID,
  129. const void *const pDeviceContext );
  130. void UnbindEndpoint( CModemEndpoint *const pEndpoint, const ENDPOINT_TYPE EndpointType );
  131. void LockDataPortData( void ) { DNEnterCriticalSection( &m_DataPortDataLock ); }
  132. void UnlockDataPortData( void ) { DNLeaveCriticalSection( &m_DataPortDataLock ); }
  133. //
  134. // endpoint and data port pool management
  135. //
  136. CModemEndpoint *GetNewEndpoint( void );
  137. CModemEndpoint *EndpointFromHandle( const DPNHANDLE hEndpoint );
  138. void CloseEndpointHandle( CModemEndpoint *const pEndpoint );
  139. CModemEndpoint *GetEndpointAndCloseHandle( const DPNHANDLE hEndpoint );
  140. //
  141. // COM functions
  142. //
  143. SP_TYPE GetType( void ) const { return m_SPType; }
  144. IDP8SPCallback *DP8SPCallbackInterface( void ) { return reinterpret_cast<IDP8SPCallback*>( m_InitData.pIDP ); }
  145. IDP8ServiceProvider *COMInterface( void ) { return reinterpret_cast<IDP8ServiceProvider*>( &m_COMInterface ); }
  146. #undef DPF_MODNAME
  147. #define DPF_MODNAME "CModemSPData::SPDataFromCOMInterface"
  148. static CModemSPData *SPDataFromCOMInterface( IDP8ServiceProvider *const pCOMInterface )
  149. {
  150. DNASSERT( pCOMInterface != NULL );
  151. DBG_CASSERT( sizeof( BYTE* ) == sizeof( pCOMInterface ) );
  152. DBG_CASSERT( sizeof( CModemSPData* ) == sizeof( BYTE* ) );
  153. return reinterpret_cast<CModemSPData*>( &reinterpret_cast<BYTE*>( pCOMInterface )[ -OFFSETOF( CModemSPData, m_COMInterface ) ] );
  154. }
  155. private:
  156. BYTE m_Sig[4]; // debugging signature ('SPDT')
  157. #ifndef DPNBUILD_ONLYONETHREAD
  158. DNCRITICAL_SECTION m_Lock; // lock
  159. #endif // !DPNBUILD_ONLYONETHREAD
  160. volatile LONG m_lRefCount; // reference count
  161. volatile LONG m_lObjectRefCount; // reference count ofo objects (CDataPort, CModemEndpoint, etc.)
  162. DNHANDLE m_hShutdownEvent; // event signalled when all objects are gone
  163. SP_TYPE m_SPType; // SP type
  164. SPSTATE m_State; // status of the service provider
  165. SPINITIALIZEDATA m_InitData; // initialization data
  166. CModemThreadPool *m_pThreadPool; // thread pool for jobs
  167. CHandleTable m_HandleTable; // handle table
  168. #ifndef DPNBUILD_ONLYONETHREAD
  169. DNCRITICAL_SECTION m_DataPortDataLock;
  170. #endif // !DPNBUILD_ONLYONETHREAD
  171. CDataPort *m_DataPortList[ MAX_DATA_PORTS ];
  172. BOOL m_fLockInitialized;
  173. BOOL m_fHandleTableInitialized;
  174. BOOL m_fDataPortDataLockInitialized;
  175. BOOL m_fInterfaceGlobalsInitialized;
  176. struct
  177. {
  178. IDP8ServiceProviderVtbl *m_pCOMVtbl;
  179. } m_COMInterface;
  180. void DestroyThisObject( void );
  181. //
  182. // make copy constructor and assignment operator private and unimplemented
  183. // to prevent unwarranted copies
  184. //
  185. CModemSPData( const CModemSPData & );
  186. CModemSPData& operator=( const CModemSPData & );
  187. };
  188. //**********************************************************************
  189. // Variable definitions
  190. //**********************************************************************
  191. //**********************************************************************
  192. // Function prototypes
  193. //**********************************************************************
  194. #undef DPF_MODNAME
  195. #endif // __SPDATA_H__