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.

273 lines
6.1 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1997 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: context.c
  6. * Content: Internal methods for context (handle) management
  7. *
  8. * History:
  9. * Date By Reason
  10. * ======= ======= ======
  11. * 1/18/97 myronth Created it
  12. * 2/12/97 myronth Mass DX5 changes
  13. * 2/26/97 myronth #ifdef'd out DPASYNCDATA stuff (removed dependency)
  14. this includes removing this file from the build
  15. ***************************************************************************/
  16. #include "dplobpr.h"
  17. //--------------------------------------------------------------------------
  18. //
  19. // Functions
  20. //
  21. //--------------------------------------------------------------------------
  22. #undef DPF_MODNAME
  23. #define DPF_MODNAME "PRV_GetNewContextID"
  24. HRESULT PRV_GetNewContextID(LPDPLOBBYI_DPLOBJECT this, LPDWORD lpdwContext)
  25. {
  26. DPF(7, "Entering PRV_GetNewContextID");
  27. DPF(9, "Parameters: 0x%08x, 0x%08x", this, lpdwContext);
  28. ASSERT(this);
  29. ASSERT(lpdwContext);
  30. // Get the current context ID and increment the counter
  31. if(this->bContextWrap)
  32. {
  33. // REVIEW!!!! -- We need to deal with the wrap case, but for
  34. // now just ASSERT if we hit it (it's pretty unlikely)
  35. ASSERT(FALSE);
  36. return DPERR_GENERIC;
  37. }
  38. else
  39. {
  40. *lpdwContext = this->dwContextCurrent++;
  41. return DP_OK;
  42. }
  43. } // PRV_GetNewContextID
  44. #undef DPF_MODNAME
  45. #define DPF_MODNAME "PRV_FindContextNode"
  46. LPDPLOBBYI_CONTEXTNODE PRV_FindContextNode(LPDPLOBBYI_DPLOBJECT this,
  47. DWORD dwContext)
  48. {
  49. LPDPLOBBYI_CONTEXTNODE lpCN;
  50. DPF(7, "Entering PRV_FindContextNode");
  51. DPF(9, "Parameters: 0x%08x, %d", this, dwContext);
  52. ASSERT(this);
  53. // Walk the list of context nodes, looking for the right ID
  54. lpCN = this->ContextHead.lpNext;
  55. while(lpCN != &(this->ContextHead))
  56. {
  57. if(lpCN->dwContext == dwContext)
  58. return lpCN;
  59. else
  60. lpCN = lpCN->lpNext;
  61. }
  62. // We didn't find it
  63. return NULL;
  64. } // PRV_FindContextNode
  65. #undef DPF_MODNAME
  66. #define DPF_MODNAME "PRV_GetAsyncDataFromContext"
  67. LPDPASYNCDATA PRV_GetAsyncDataFromContext(LPDPLOBBYI_DPLOBJECT this,
  68. DWORD dwContext)
  69. {
  70. LPDPLOBBYI_CONTEXTNODE lpCN;
  71. DPF(7, "Entering PRV_GetAsyncDataFromContext");
  72. DPF(9, "Parameters: 0x%08x, %d", this, dwContext);
  73. ASSERT(this);
  74. // Find the node and pull out the AsyncData object
  75. lpCN = PRV_FindContextNode(this, dwContext);
  76. if(lpCN)
  77. return lpCN->lpAD;
  78. else
  79. return NULL;
  80. } // PRV_GetAsyncDataFromContext
  81. #undef DPF_MODNAME
  82. #define DPF_MODNAME "PRV_AddContextNode"
  83. HRESULT PRV_AddContextNode(LPDPLOBBYI_DPLOBJECT this, LPDPASYNCDATA lpAD,
  84. LPDPLOBBYI_CONTEXTNODE * lplpCN)
  85. {
  86. HRESULT hr = DP_OK;
  87. DWORD dwContext;
  88. LPDPLOBBYI_CONTEXTNODE lpCN = NULL;
  89. DPF(7, "Entering PRV_AddContextNode");
  90. DPF(9, "Parameters: 0x%08x, 0x%08x, 0x%08x", this, lpAD, lplpCN);
  91. ASSERT(this);
  92. ASSERT(lpAD);
  93. ASSERT(lplpCN);
  94. // Allocate memory for the new node
  95. lpCN = DPMEM_ALLOC(sizeof(DPLOBBYI_CONTEXTNODE));
  96. if(!lpCN)
  97. {
  98. DPF_ERR("Unable to allocate memory for context node");
  99. return DPERR_OUTOFMEMORY;
  100. }
  101. // Get a new context ID
  102. hr = PRV_GetNewContextID(this, &dwContext);
  103. if(FAILED(hr))
  104. {
  105. DPF_ERR("Unable to get new context ID");
  106. return DPERR_GENERIC;
  107. }
  108. // Fill in the structure
  109. lpCN->dwContext = dwContext;
  110. lpCN->lpAD = lpAD;
  111. // Fill in the output parameter
  112. *lplpCN = lpCN;
  113. // Add the node to the end of the list
  114. this->ContextHead.lpPrev->lpNext = lpCN;
  115. lpCN->lpPrev = this->ContextHead.lpPrev;
  116. this->ContextHead.lpPrev = lpCN;
  117. lpCN->lpNext = &(this->ContextHead);
  118. return DP_OK;
  119. } // PRV_AddContextNode
  120. #undef DPF_MODNAME
  121. #define DPF_MODNAME "PRV_DeleteContextNode"
  122. HRESULT PRV_DeleteContextNode(LPDPLOBBYI_DPLOBJECT this,
  123. LPDPLOBBYI_CONTEXTNODE lpCN)
  124. {
  125. HRESULT hr = DP_OK;
  126. DPF(7, "Entering PRV_DeleteContextNode");
  127. DPF(9, "Parameters: 0x%08x, 0x%08x", this, lpCN);
  128. ASSERT(this);
  129. // Remove the node from the list
  130. lpCN->lpPrev->lpNext = lpCN->lpNext;
  131. lpCN->lpNext->lpPrev = lpCN->lpPrev;
  132. // And delete the node
  133. DPMEM_FREE(lpCN);
  134. return DP_OK;
  135. } // PRV_DeleteContextNode
  136. #undef DPF_MODNAME
  137. #define DPF_MODNAME "PRV_CleanUpContextList"
  138. void PRV_CleanUpContextList(LPDPLOBBYI_DPLOBJECT this)
  139. {
  140. LPDPLOBBYI_CONTEXTNODE lpCN, lpCNNext;
  141. DPF(7, "Entering PRV_CleanUpContextList");
  142. DPF(9, "Parameters: 0x%08x", this);
  143. ASSERT(this);
  144. // Walk the list, cleaning up the nodes
  145. lpCN = this->ContextHead.lpNext;
  146. while(lpCN != &(this->ContextHead))
  147. {
  148. lpCNNext = lpCN->lpNext;
  149. PRV_DeleteContextNode(this, lpCN);
  150. lpCN = lpCNNext;
  151. }
  152. } // PRV_CleanUpContextList
  153. #undef DPF_MODNAME
  154. #define DPF_MODNAME "PRV_CreateAndLinkAsyncDataContext"
  155. HRESULT PRV_CreateAndLinkAsyncDataContext(LPDPLOBBYI_DPLOBJECT this,
  156. LPDPLOBBYI_CONTEXTNODE * lplpCN)
  157. {
  158. LPDPLOBBYI_CONTEXTNODE lpCN = NULL;
  159. LPDPASYNCDATA lpAD = NULL;
  160. HRESULT hr;
  161. DPF(7, "Entering PRV_CreateAndLinkAsyncDataContext");
  162. DPF(9, "Parameters: 0x%08x, 0x%08x", this, lplpCN);
  163. ASSERT(this);
  164. ASSERT(lplpCN);
  165. // Create the AsyncData object
  166. hr = CreateAsyncData(&lpAD);
  167. if(FAILED(hr))
  168. {
  169. DPF_ERR("Unable to create DPAsyncData object");
  170. return hr;
  171. }
  172. // Add a new context node and link it in
  173. hr = PRV_AddContextNode(this, lpAD, &lpCN);
  174. if(FAILED(hr))
  175. {
  176. lpAD->lpVtbl->Release(lpAD);
  177. return hr;
  178. }
  179. // Fill in the output vars
  180. *lplpCN = lpCN;
  181. return DP_OK;
  182. } // PRV_CreateAndLinkAsyncDataContext
  183. #undef DPF_MODNAME
  184. #define DPF_MODNAME "PRV_UnlinkAndReleaseAsyncDataContext"
  185. void PRV_UnlinkAndReleaseAsyncDataContext(LPDPLOBBYI_DPLOBJECT this,
  186. LPDPLOBBYI_CONTEXTNODE lpCN)
  187. {
  188. LPDPASYNCDATA lpAD = NULL;
  189. DPF(7, "Entering PRV_CreateAndLinkAsyncDataContext");
  190. DPF(9, "Parameters: 0x%08x, 0x%08x", this, lpCN);
  191. ASSERT(this);
  192. ASSERT(lpCN);
  193. // Release the AsyncData pointer
  194. lpCN->lpAD->lpVtbl->Release(lpCN->lpAD);
  195. // Remove the context node
  196. PRV_DeleteContextNode(this, lpCN);
  197. } // PRV_UnlinkAndReleaseAsyncDataContext