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.

233 lines
4.1 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. //
  5. // File: tls236.cpp
  6. //
  7. // Contents:
  8. //
  9. // History:
  10. //
  11. //---------------------------------------------------------------------------
  12. #include "pch.cpp"
  13. CClientMgr* g_ClientMgr=NULL;
  14. ////////////////////////////////////////////////////////
  15. //
  16. // CClient Class
  17. //
  18. ////////////////////////////////////////////////////////
  19. CClient::CClient(
  20. IN PMHANDLE hClient
  21. ) :
  22. m_hClient(hClient)
  23. /*++
  24. Abstract:
  25. Constructor for CClient class.
  26. Parameter:
  27. hClient : client handle
  28. Return:
  29. None.
  30. ++*/
  31. {
  32. }
  33. //------------------------------------------------------
  34. CClient::~CClient()
  35. /*++
  36. Abstract:
  37. Destructor for CClient class
  38. Parameter:
  39. None
  40. Return:
  41. None
  42. ++*/
  43. {
  44. for(list<PointerType>::iterator it = m_AllocatedMemory.begin();
  45. it != m_AllocatedMemory.end();
  46. it++)
  47. {
  48. HLOCAL ptr = (*it).GetPointer();
  49. FREE(ptr);
  50. }
  51. // m_AllocatedMemory.erase(m_AllocatedMemory.begin(), m_AllocatedMemory.end());
  52. }
  53. //------------------------------------------------------
  54. HLOCAL
  55. CClient::AllocateMemory(
  56. IN MEMORYPOINTERTYPE ptrType,
  57. IN DWORD dwSize
  58. )
  59. /*++
  60. Abstract:
  61. Allocate/store memory allocated into memory list.
  62. Parameter:
  63. dwSize - Number of byte to allocate.
  64. Return:
  65. Same as from LocalAlloc().
  66. ++*/
  67. {
  68. HLOCAL ptr = NULL;
  69. DWORD dwStatus = ERROR_SUCCESS;
  70. ptr = MALLOC(dwSize);
  71. if(ptr != NULL)
  72. {
  73. //
  74. // Append to allocated list.
  75. //
  76. m_AllocatedMemory.push_back( PointerType(ptrType, ptr) );
  77. }
  78. if(dwStatus != ERROR_SUCCESS)
  79. {
  80. if(ptr != NULL)
  81. {
  82. FREE(ptr);
  83. ptr = NULL;
  84. }
  85. }
  86. return ptr;
  87. }
  88. ////////////////////////////////////////////////////////
  89. //
  90. // CClientMgr
  91. //
  92. ////////////////////////////////////////////////////////
  93. CClientMgr::~CClientMgr()
  94. {
  95. Cleanup();
  96. }
  97. //------------------------------------------------------
  98. void
  99. CClientMgr::Cleanup()
  100. /*++
  101. ++*/
  102. {
  103. MapHandleToClient::iterator it;
  104. m_HandleMapLock.Lock();
  105. for(it = m_HandleMap.begin(); it != m_HandleMap.end(); it++)
  106. {
  107. assert( ((*it).second)->GetRefCount() == 1 );
  108. }
  109. m_HandleMapLock.UnLock();
  110. //
  111. // Always perform cleanup
  112. //
  113. // m_HandleMap.erase(m_HandleMap.begin(), m_HandleMap.end());
  114. }
  115. //------------------------------------------------------
  116. CClient*
  117. CClientMgr::FindClient(
  118. IN PMHANDLE hClient
  119. )
  120. /*++
  121. Abstract:
  122. Routine to find client object, add client object if not found.
  123. Parameter:
  124. hClient - Client handle
  125. Return:
  126. ++*/
  127. {
  128. MapHandleToClient::iterator it;
  129. CClient*ptr = NULL;
  130. DWORD dwStatus = ERROR_SUCCESS;
  131. m_HandleMapLock.Lock();
  132. it = m_HandleMap.find(hClient);
  133. if( it == m_HandleMap.end() )
  134. {
  135. CClient* pClient;
  136. pClient = new CClient(hClient);
  137. if(pClient != NULL)
  138. {
  139. m_HandleMap[hClient] = pClient;
  140. // pair<PMHANDLE, CClient*> m(hClient, pClient);
  141. //m_HandleMap.insert( m );
  142. // m_HandleMap.insert( pair<PMHANDLE, CClient*>(hClient, pClient) );
  143. it = m_HandleMap.find(hClient);
  144. assert(it != m_HandleMap.end());
  145. }
  146. }
  147. if(it != m_HandleMap.end())
  148. {
  149. ptr = (*it).second;
  150. }
  151. m_HandleMapLock.UnLock();
  152. return ptr;
  153. }
  154. //------------------------------------------------------
  155. BOOL
  156. CClientMgr::DestroyClient(
  157. IN PMHANDLE hClient
  158. )
  159. /*++
  160. ++*/
  161. {
  162. MapHandleToClient::iterator it;
  163. BOOL bSuccess = FALSE;
  164. m_HandleMapLock.Lock();
  165. it = m_HandleMap.find(hClient);
  166. if(it != m_HandleMap.end())
  167. {
  168. delete (*it).second;
  169. m_HandleMap.erase(it);
  170. bSuccess = TRUE;
  171. }
  172. m_HandleMapLock.UnLock();
  173. return bSuccess;
  174. }