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.

193 lines
5.0 KiB

  1. /***************************************************************************
  2. *
  3. * Copyright (C) 2001 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dp8simreceive.h
  6. *
  7. * Content: Header for receive object class.
  8. *
  9. * History:
  10. * Date By Reason
  11. * ======== ======== =========
  12. * 05/05/01 VanceO Created.
  13. *
  14. ***************************************************************************/
  15. //=============================================================================
  16. // Receive object class
  17. //=============================================================================
  18. class CDP8SimReceive
  19. {
  20. public:
  21. inline BOOL IsValidObject(void)
  22. {
  23. if ((this == NULL) || (IsBadWritePtr(this, sizeof(CDP8SimReceive))))
  24. {
  25. return FALSE;
  26. }
  27. if (*((DWORD*) (&this->m_Sig)) != 0x524d4953) // 0x52 0x4d 0x49 0x53 = 'RMIS' = 'SIMR' in Intel order
  28. {
  29. return FALSE;
  30. }
  31. return TRUE;
  32. };
  33. static BOOL FPMAlloc(void* pvItem, void* pvContext)
  34. {
  35. CDP8SimReceive * pDP8SimReceive = (CDP8SimReceive*) pvItem;
  36. pDP8SimReceive->m_Sig[0] = 'S';
  37. pDP8SimReceive->m_Sig[1] = 'I';
  38. pDP8SimReceive->m_Sig[2] = 'M';
  39. pDP8SimReceive->m_Sig[3] = 'r'; // start with lower case so we can tell when it's in the pool or not
  40. pDP8SimReceive->m_lRefCount = 0;
  41. pDP8SimReceive->m_pDP8SimEndpoint = NULL;
  42. ZeroMemory(&pDP8SimReceive->m_data, sizeof(pDP8SimReceive->m_data));
  43. pDP8SimReceive->m_dwLatencyAdded = 0;
  44. return TRUE;
  45. }
  46. #undef DPF_MODNAME
  47. #define DPF_MODNAME "CDP8SimReceive::FPMInitialize"
  48. static void FPMInitialize(void* pvItem, void* pvContext)
  49. {
  50. CDP8SimReceive * pDP8SimReceive = (CDP8SimReceive*) pvItem;
  51. SPIE_DATA * pData = (SPIE_DATA*) pvContext;
  52. pDP8SimReceive->m_lRefCount++; // somebody is getting a pointer to this object
  53. DNASSERT(pDP8SimReceive->m_lRefCount == 1);
  54. //
  55. // Get an endpoint reference.
  56. //
  57. pDP8SimReceive->m_pDP8SimEndpoint = (CDP8SimEndpoint*) pData->pEndpointContext;
  58. DNASSERT(pDP8SimReceive->m_pDP8SimEndpoint->IsValidObject());
  59. pDP8SimReceive->m_pDP8SimEndpoint->AddRef();
  60. DNASSERT(pData->pReceivedData->pNext == NULL);
  61. //
  62. // Copy the receive data block.
  63. //
  64. pDP8SimReceive->m_data.hEndpoint = (HANDLE) pDP8SimReceive->m_pDP8SimEndpoint;
  65. pDP8SimReceive->m_data.pEndpointContext = pDP8SimReceive->m_pDP8SimEndpoint->GetUserContext();
  66. pDP8SimReceive->m_data.pReceivedData = pData->pReceivedData;
  67. //
  68. // Change the signature before handing it out.
  69. //
  70. pDP8SimReceive->m_Sig[3] = 'R';
  71. }
  72. #undef DPF_MODNAME
  73. #define DPF_MODNAME "CDP8SimReceive::FPMRelease"
  74. static void FPMRelease(void* pvItem)
  75. {
  76. CDP8SimReceive * pDP8SimReceive = (CDP8SimReceive*) pvItem;
  77. DNASSERT(pDP8SimReceive->m_lRefCount == 0);
  78. //
  79. // Release the endpoint reference.
  80. //
  81. DNASSERT(pDP8SimReceive->m_pDP8SimEndpoint != NULL);
  82. pDP8SimReceive->m_pDP8SimEndpoint->Release();
  83. pDP8SimReceive->m_pDP8SimEndpoint = NULL;
  84. //
  85. // Change the signature before putting the object back in the pool.
  86. //
  87. pDP8SimReceive->m_Sig[3] = 'r';
  88. }
  89. #undef DPF_MODNAME
  90. #define DPF_MODNAME "CDP8SimReceive::FPMDealloc"
  91. static void FPMDealloc(void* pvItem)
  92. {
  93. const CDP8SimReceive * pDP8SimReceive = (CDP8SimReceive*) pvItem;
  94. DNASSERT(pDP8SimReceive->m_lRefCount == 0);
  95. DNASSERT(pDP8SimReceive->m_pDP8SimEndpoint == NULL);
  96. }
  97. #undef DPF_MODNAME
  98. #define DPF_MODNAME "CDP8SimReceive::AddRef"
  99. inline void AddRef(void)
  100. {
  101. LONG lResult;
  102. lResult = InterlockedIncrement(&this->m_lRefCount);
  103. DNASSERT(lResult > 0);
  104. DPFX(DPFPREP, 9, "Receive 0x%p refcount = %u.", this, lResult);
  105. };
  106. #undef DPF_MODNAME
  107. #define DPF_MODNAME "CDP8SimReceive::Release"
  108. inline void Release(void)
  109. {
  110. LONG lResult;
  111. lResult = InterlockedDecrement(&this->m_lRefCount);
  112. DNASSERT(lResult >= 0);
  113. if (lResult == 0)
  114. {
  115. DPFX(DPFPREP, 9, "Receive 0x%p refcount = 0, returning to pool.", this);
  116. //
  117. // Time to return this object to the pool.
  118. //
  119. g_FPOOLReceive.Release(this);
  120. }
  121. else
  122. {
  123. DPFX(DPFPREP, 9, "Receive 0x%p refcount = %u.", this, lResult);
  124. }
  125. };
  126. inline CDP8SimEndpoint * GetEndpoint(void) { return this->m_pDP8SimEndpoint; };
  127. inline SPIE_DATA * GetReceiveDataBlockPtr(void) { return (&this->m_data); };
  128. inline HANDLE GetReceiveDataBlockEndpoint(void) { return this->m_data.hEndpoint; };
  129. inline DWORD GetLatencyAdded(void) const { return this->m_dwLatencyAdded; };
  130. inline void SetLatencyAdded(DWORD dwLatency) { this->m_dwLatencyAdded = dwLatency; };
  131. private:
  132. BYTE m_Sig[4]; // debugging signature ('SIMR')
  133. LONG m_lRefCount; // number of references for this object
  134. CDP8SimEndpoint * m_pDP8SimEndpoint; // pointer to source endpoint
  135. SPIE_DATA m_data; // receive data block
  136. DWORD m_dwLatencyAdded; // the latency added, saved for incrementing statistics on receive indication
  137. };