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.

252 lines
7.3 KiB

  1. /***************************************************************************
  2. *
  3. * Copyright (C) 2001 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dp8simcmd.h
  6. *
  7. * Content: Header for command object class.
  8. *
  9. * History:
  10. * Date By Reason
  11. * ======== ======== =========
  12. * 04/23/01 VanceO Created.
  13. *
  14. ***************************************************************************/
  15. //=============================================================================
  16. // Defines
  17. //=============================================================================
  18. #define CMDTYPE_SENDDATA_IMMEDIATE 1 // command represents a send transmitted right away
  19. #define CMDTYPE_SENDDATA_DELAYED 2 // command represents a send that was artificially delayed
  20. #define CMDTYPE_CONNECT 3 // command represents a connect
  21. #define CMDTYPE_DISCONNECT 4 // command represents a disconnect
  22. #define CMDTYPE_LISTEN 5 // command represents a listen
  23. #define CMDTYPE_ENUMQUERY 6 // command represents an enum query
  24. #define CMDTYPE_ENUMRESPOND 7 // command represents an enum respond
  25. //=============================================================================
  26. // Structures
  27. //=============================================================================
  28. typedef struct _DP8SIMCOMMAND_FPMCONTEXT
  29. {
  30. DWORD dwType; // type of command
  31. PVOID pvUserContext; // user context for command
  32. } DP8SIMCOMMAND_FPMCONTEXT, * PDP8SIMCOMMAND_FPMCONTEXT;
  33. //=============================================================================
  34. // Send object class
  35. //=============================================================================
  36. class CDP8SimCommand
  37. {
  38. public:
  39. inline BOOL IsValidObject(void)
  40. {
  41. if ((this == NULL) || (IsBadWritePtr(this, sizeof(CDP8SimCommand))))
  42. {
  43. return FALSE;
  44. }
  45. if (*((DWORD*) (&this->m_Sig)) != 0x434d4953) // 0x43 0x4d 0x49 0x53 = 'CMIS' = 'SIMC' in Intel order
  46. {
  47. return FALSE;
  48. }
  49. return TRUE;
  50. };
  51. static BOOL FPMAlloc(void* pvItem, void* pvContext)
  52. {
  53. CDP8SimCommand * pDP8SimCommand = (CDP8SimCommand*) pvItem;
  54. pDP8SimCommand->m_Sig[0] = 'S';
  55. pDP8SimCommand->m_Sig[1] = 'I';
  56. pDP8SimCommand->m_Sig[2] = 'M';
  57. pDP8SimCommand->m_Sig[3] = 'c'; // start with lower case so we can tell when it's in the pool or not
  58. pDP8SimCommand->m_lRefCount = 0;
  59. pDP8SimCommand->m_dwType = 0;
  60. pDP8SimCommand->m_pvUserContext = NULL;
  61. pDP8SimCommand->m_hCommand = NULL;
  62. pDP8SimCommand->m_dwCommandDescriptor = 0;
  63. ZeroMemory(&pDP8SimCommand->m_CommandSpecificData, sizeof(pDP8SimCommand->m_CommandSpecificData));
  64. return TRUE;
  65. }
  66. #undef DPF_MODNAME
  67. #define DPF_MODNAME "CDP8SimCommand::FPMInitialize"
  68. static void FPMInitialize(void* pvItem, void* pvContext)
  69. {
  70. CDP8SimCommand * pDP8SimCommand = (CDP8SimCommand*) pvItem;
  71. DP8SIMCOMMAND_FPMCONTEXT * pContext = (DP8SIMCOMMAND_FPMCONTEXT*) pvContext;
  72. pDP8SimCommand->m_lRefCount++; // somebody is getting a pointer to this object
  73. DNASSERT(pDP8SimCommand->m_lRefCount == 1);
  74. pDP8SimCommand->m_dwType = pContext->dwType;
  75. pDP8SimCommand->m_pvUserContext = pContext->pvUserContext;
  76. //
  77. // Change the signature before handing it out.
  78. //
  79. pDP8SimCommand->m_Sig[3] = 'C';
  80. }
  81. #undef DPF_MODNAME
  82. #define DPF_MODNAME "CDP8SimCommand::FPMRelease"
  83. static void FPMRelease(void* pvItem)
  84. {
  85. CDP8SimCommand * pDP8SimCommand = (CDP8SimCommand*) pvItem;
  86. DNASSERT(pDP8SimCommand->m_lRefCount == 0);
  87. DNASSERT(pDP8SimCommand->m_CommandSpecificData.m_pDP8SimEndpointListen == NULL);
  88. //
  89. // Change the signature before putting the object back in the pool.
  90. //
  91. pDP8SimCommand->m_Sig[3] = 'c';
  92. }
  93. #undef DPF_MODNAME
  94. #define DPF_MODNAME "CDP8SimCommand::FPMDealloc"
  95. static void FPMDealloc(void* pvItem)
  96. {
  97. const CDP8SimCommand * pDP8SimCommand = (CDP8SimCommand*) pvItem;
  98. DNASSERT(pDP8SimCommand->m_lRefCount == 0);
  99. DNASSERT(pDP8SimCommand->m_CommandSpecificData.m_pDP8SimEndpointListen == NULL);
  100. }
  101. #undef DPF_MODNAME
  102. #define DPF_MODNAME "CDP8SimCommand::AddRef"
  103. inline void AddRef(void)
  104. {
  105. LONG lResult;
  106. lResult = InterlockedIncrement(&this->m_lRefCount);
  107. DNASSERT(lResult > 0);
  108. DPFX(DPFPREP, 9, "Command 0x%p refcount = %u.", this, lResult);
  109. };
  110. #undef DPF_MODNAME
  111. #define DPF_MODNAME "CDP8SimCommand::Release"
  112. inline void Release(void)
  113. {
  114. LONG lResult;
  115. lResult = InterlockedDecrement(&this->m_lRefCount);
  116. DNASSERT(lResult >= 0);
  117. if (lResult == 0)
  118. {
  119. DPFX(DPFPREP, 9, "Command 0x%p refcount = 0, returning to pool.", this);
  120. //
  121. // Time to return this object to the pool.
  122. //
  123. g_FPOOLCommand.Release(this);
  124. }
  125. else
  126. {
  127. DPFX(DPFPREP, 9, "Command 0x%p refcount = %u.", this, lResult);
  128. }
  129. };
  130. inline DWORD GetType(void) const { return this->m_dwType; };
  131. inline PVOID GetUserContext(void) { return this->m_pvUserContext; };
  132. inline HANDLE GetRealSPCommand(void) const { return this->m_hCommand; };
  133. inline DWORD GetRealSPCommandDescriptor(void) const { return this->m_dwCommandDescriptor; };
  134. #undef DPF_MODNAME
  135. #define DPF_MODNAME "CDP8SimCommand::GetListenEndpoint"
  136. inline CDP8SimEndpoint * GetListenEndpoint(void)
  137. {
  138. DNASSERT(this->m_dwType == CMDTYPE_LISTEN);
  139. return this->m_CommandSpecificData.m_pDP8SimEndpointListen;
  140. };
  141. #undef DPF_MODNAME
  142. #define DPF_MODNAME "CDP8SimCommand::GetMessageSize"
  143. inline DWORD GetMessageSize(void)
  144. {
  145. DNASSERT(this->m_dwType == CMDTYPE_SENDDATA_IMMEDIATE);
  146. return this->m_CommandSpecificData.m_dwMessageSize;
  147. };
  148. inline void SetRealSPCommand(HANDLE hCommand, DWORD dwCommandDescriptor)
  149. {
  150. this->m_hCommand = hCommand;
  151. this->m_dwCommandDescriptor = dwCommandDescriptor;
  152. };
  153. #undef DPF_MODNAME
  154. #define DPF_MODNAME "CDP8SimCommand::SetListenEndpoint"
  155. inline void SetListenEndpoint(CDP8SimEndpoint * const pDP8SimEndpoint)
  156. {
  157. DNASSERT(this->m_dwType == CMDTYPE_LISTEN);
  158. DNASSERT((this->m_CommandSpecificData.m_pDP8SimEndpointListen == NULL) || (pDP8SimEndpoint == NULL));
  159. //
  160. // Note this only sets the pointer, it is the caller's
  161. // responsibility to add or remove the reference as necessary.
  162. //
  163. this->m_CommandSpecificData.m_pDP8SimEndpointListen = pDP8SimEndpoint;
  164. };
  165. #undef DPF_MODNAME
  166. #define DPF_MODNAME "CDP8SimCommand::SetMessageSize"
  167. inline void SetMessageSize(const DWORD dwMessageSize)
  168. {
  169. DNASSERT(this->m_dwType == CMDTYPE_SENDDATA_IMMEDIATE);
  170. DNASSERT((this->m_CommandSpecificData.m_dwMessageSize == 0) || (dwMessageSize == 0));
  171. this->m_CommandSpecificData.m_dwMessageSize = dwMessageSize;
  172. };
  173. private:
  174. BYTE m_Sig[4]; // debugging signature ('SIMC')
  175. LONG m_lRefCount; // number of references for this object
  176. DWORD m_dwType; // type of command
  177. PVOID m_pvUserContext; // user's context for command
  178. HANDLE m_hCommand; // real SP command handle
  179. DWORD m_dwCommandDescriptor; // real SP descriptor for command
  180. union
  181. {
  182. CDP8SimEndpoint * m_pDP8SimEndpointListen; // pointer to listen endpoint, if this is a CMDTYPE_LISTEN command
  183. DWORD m_dwMessageSize; // size of message, if this is a CMDTYPE_SENDDATA_IMMEDIATE command
  184. } m_CommandSpecificData;
  185. };