Source code of Windows XP (NT5)
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.

149 lines
3.3 KiB

  1. //****************************************************************************
  2. //
  3. // Module: ULS.DLL
  4. // File: request.cpp
  5. // Content: CReqMgr and CRequest classes implementation
  6. //
  7. // Copyright (c) Microsoft Corporation 1996-1997
  8. //
  9. //****************************************************************************
  10. #include "ulsp.h"
  11. #include "request.h"
  12. //****************************************************************************
  13. // CReqMgr::CReqMgr(void)
  14. //
  15. // Purpose: Constructor for the CReqMgr class
  16. //
  17. // Parameters: None
  18. //****************************************************************************
  19. CReqMgr::CReqMgr(void)
  20. {
  21. uNextReqID = REQUEST_ID_INIT;
  22. return;
  23. }
  24. //****************************************************************************
  25. // CReqMgr::~CReqMgr(void)
  26. //
  27. // Purpose: Destructor for the CReqMgr class
  28. //
  29. // Parameters: None
  30. //****************************************************************************
  31. CReqMgr::~CReqMgr(void)
  32. {
  33. COM_REQ_INFO *pRequest;
  34. HANDLE hEnum;
  35. // Free all the pending request
  36. //
  37. ReqList.Enumerate(&hEnum);
  38. while (ReqList.Next(&hEnum, (LPVOID *)&pRequest) == NOERROR)
  39. {
  40. ::MemFree (pRequest);
  41. }
  42. ReqList.Flush();
  43. return;
  44. }
  45. //****************************************************************************
  46. // HRESULT
  47. // CReqMgr::NewRequest (COM_REQ_INFO *pri)
  48. //
  49. // Purpose: Add a new pending request
  50. //
  51. // Parameters: None
  52. //****************************************************************************
  53. HRESULT
  54. CReqMgr::NewRequest (COM_REQ_INFO *pri)
  55. {
  56. COM_REQ_INFO *pRequest;
  57. HRESULT hr;
  58. // Allocate a new request node
  59. //
  60. pri->uReqID = uNextReqID;
  61. pRequest = (COM_REQ_INFO *) ::MemAlloc (sizeof (COM_REQ_INFO));
  62. if (pRequest == NULL)
  63. {
  64. return ILS_E_MEMORY;
  65. };
  66. *pRequest = *pri;
  67. // Append the new request to the list
  68. //
  69. hr = ReqList.Append((PVOID)pRequest);
  70. if (FAILED(hr))
  71. {
  72. delete pRequest;
  73. }
  74. else
  75. {
  76. if (++uNextReqID == ILS_INVALID_REQ_ID)
  77. uNextReqID = REQUEST_ID_INIT;
  78. };
  79. return hr;
  80. }
  81. //****************************************************************************
  82. // HRESULT
  83. // CReqMgr::FindRequest (COM_REQ_INFO *pri, BOOL fRemove)
  84. //
  85. // Purpose: Find the request.
  86. //
  87. // Parameters: None
  88. //****************************************************************************
  89. HRESULT
  90. CReqMgr::FindRequest (COM_REQ_INFO *pri, BOOL fRemove)
  91. {
  92. COM_REQ_INFO *pRequest;
  93. ULONG uMatchingID;
  94. HANDLE hEnum;
  95. HRESULT hr;
  96. // Get the ID we want to match
  97. //
  98. uMatchingID = (pri->uMsgID != 0 ? pri->uMsgID : pri->uReqID);
  99. // Look for the request matching the message ID
  100. //
  101. ReqList.Enumerate(&hEnum);
  102. while (ReqList.Next(&hEnum, (PVOID *)&pRequest) == NOERROR)
  103. {
  104. if (uMatchingID == (pri->uMsgID != 0 ? pRequest->uMsgID :
  105. pRequest->uReqID))
  106. {
  107. break;
  108. };
  109. };
  110. if (pRequest != NULL)
  111. {
  112. // Return the request associates
  113. //
  114. *pri = *pRequest;
  115. // Remove the request
  116. //
  117. if (fRemove)
  118. {
  119. ReqList.Remove((PVOID)pRequest);
  120. ::MemFree (pRequest);
  121. };
  122. hr = NOERROR;
  123. }
  124. else
  125. {
  126. hr = ILS_E_FAIL;
  127. };
  128. return hr;
  129. }