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.

270 lines
6.3 KiB

  1. /*-----------------------------------------------------------------------------
  2. Copyright (c) 1995-1998 Microsoft Corporation
  3. Module Name :
  4. ptable.hxx
  5. Abstract:
  6. Header file for WAMINFO object.
  7. Author:
  8. Lei Jin ( LeiJin ) 13-Oct-1998
  9. Environment:
  10. User Mode - Win32
  11. Project:
  12. W3 services DLL
  13. -----------------------------------------------------------------------------*/
  14. #ifndef __W3SVC_PTABLE_HXX__
  15. #define __W3SVC_PTABLE_HXX__
  16. #include <lkrhash.h>
  17. // Define const and macro.
  18. //
  19. #define uSizeCLSIDStr 39
  20. #define RELEASE(p) {if ( p ) { p->Release(); p = NULL; }}
  21. #define FREEBSTR(p) {if (p) {SysFreeString( p ); p = NULL;}}
  22. // Define application modes currently supported
  23. //
  24. enum EAppMode
  25. {
  26. eAppInProc,
  27. eAppOOPIsolated,
  28. eAppOOPPool
  29. };
  30. // forward declarition
  31. class CWamInfo;
  32. /////////////////////////////////////////////////////////////////////
  33. // CPorcessEntry
  34. // A record that contains per process info, such as process id, process handle, etc.
  35. //
  36. /////////////////////////////////////////////////////////////////////
  37. class CProcessEntry
  38. {
  39. public:
  40. CProcessEntry( DWORD dwProcessId,
  41. HANDLE hProcessHandle,
  42. LPCWSTR pszPackageId
  43. );
  44. ~CProcessEntry();
  45. DWORD QueryProcessId() const;
  46. HANDLE QueryProcessHandle() const;
  47. WCHAR* QueryPackageId() const;
  48. bool IsCrashed() const;
  49. BOOL IsRecycling() const;
  50. bool IsLinkedWithWamInfo() const;
  51. bool FindWamInfo(CWamInfo** ppWamInfo);
  52. void NotifyCrashed();
  53. bool Recycle();
  54. void AddRef();
  55. void Release();
  56. bool AddWamInfoToProcessEntry(CWamInfo* pWamInfo);
  57. bool RemoveWamInfoFromProcessEntry
  58. (
  59. CWamInfo* pWamInfo,
  60. bool* fDelete
  61. );
  62. public:
  63. LIST_ENTRY m_ListHeadOfWamInfo;
  64. DWORD m_dwShutdownTimeLimit;
  65. DWORD m_dwShutdownStartTime;
  66. CWamInfo * m_pShuttingDownCWamInfo;
  67. private:
  68. DWORD m_dwSignature;
  69. DWORD m_dwProcessId;
  70. HANDLE m_hProcessHandle;
  71. long m_cRefs;
  72. WCHAR m_wszPackageId[40]; // 40 >> uSizeCLSIDStr.
  73. bool m_fCrashed;
  74. BOOL m_fRecycling;
  75. };
  76. // Query Process Id.
  77. inline DWORD CProcessEntry::QueryProcessId() const
  78. {
  79. return m_dwProcessId;
  80. }
  81. // Query COM+ application id(GUID).
  82. inline WCHAR* CProcessEntry::QueryPackageId() const
  83. {
  84. return (WCHAR*)m_wszPackageId;
  85. }
  86. // Query Process handle.
  87. inline HANDLE CProcessEntry::QueryProcessHandle() const
  88. {
  89. return m_hProcessHandle;
  90. }
  91. // Check to see fCrashed flag is set.
  92. inline bool CProcessEntry::IsCrashed() const
  93. {
  94. return m_fCrashed;
  95. }
  96. // Check to see if process is recycling
  97. inline BOOL CProcessEntry::IsRecycling() const
  98. {
  99. return m_fRecycling;
  100. }
  101. inline void CProcessEntry::AddRef()
  102. {
  103. InterlockedIncrement(&m_cRefs);
  104. }
  105. // Check to see any linked with any WamInfo.
  106. inline bool CProcessEntry::IsLinkedWithWamInfo() const
  107. {
  108. return IsListEmpty(&m_ListHeadOfWamInfo);
  109. }
  110. // Set m_fCrashed flag to TRUE.
  111. inline void CProcessEntry::NotifyCrashed()
  112. {
  113. InterlockedExchange((PLONG)&m_fCrashed, (LONG)TRUE);
  114. }
  115. ////////////////////////////////////////////////////////////////////
  116. // CProcessEntryHash
  117. // A hash table for CProcessEntry. Implemented using LK-hashing.
  118. // Key is DWORD type, process id.
  119. //
  120. ///////////////////////////////////////////////////////////////////
  121. class CProcessEntryHash
  122. : public CTypedHashTable<CProcessEntryHash, CProcessEntry, DWORD>
  123. {
  124. public:
  125. static DWORD ExtractKey(const CProcessEntry* pEntry);
  126. static DWORD CalcKeyHash(DWORD dwKey);
  127. static bool EqualKeys(DWORD dwKey1, DWORD dwKey2);
  128. static void AddRefRecord(CProcessEntry* pEntry, int nIncr);
  129. CProcessEntryHash
  130. (
  131. double maxload, // Bound on average chain length,
  132. size_t initsize, // Initial size of Hash Table
  133. size_t num_subtbls // #subordinate hash tables.
  134. )
  135. : CTypedHashTable<CProcessEntryHash, CProcessEntry, DWORD>
  136. ("PTable", maxload, initsize, num_subtbls)
  137. {}
  138. };
  139. inline DWORD
  140. CProcessEntryHash::ExtractKey(const CProcessEntry* pEntry)
  141. {
  142. return pEntry->QueryProcessId();
  143. }
  144. inline DWORD
  145. CProcessEntryHash::CalcKeyHash(DWORD dwKey)
  146. {
  147. return dwKey;
  148. }
  149. inline bool
  150. CProcessEntryHash::EqualKeys(DWORD dwKey1, DWORD dwKey2)
  151. {
  152. return (dwKey1 == dwKey2);
  153. }
  154. inline void
  155. CProcessEntryHash::AddRefRecord(CProcessEntry* pEntry, int nIncr)
  156. {
  157. if (nIncr == 1)
  158. {
  159. pEntry->AddRef();
  160. }
  161. else
  162. {
  163. pEntry->Release();
  164. }
  165. }
  166. interface ICOMAdminCatalog2;
  167. ////////////////////////////////////////////////////////////////
  168. // CProcessTable
  169. // Global data structure that manages the hash table.
  170. ////////////////////////////////////////////////////////////////
  171. class CProcessTable
  172. {
  173. public:
  174. CProcessTable();
  175. ~CProcessTable();
  176. void Lock();
  177. void UnLock();
  178. CProcessEntry* AddWamInfoToProcessTable
  179. (
  180. CWamInfo *pWamInfo,
  181. LPCWSTR szPackageId,
  182. DWORD pid
  183. );
  184. bool RemoveWamInfoFromProcessTable
  185. (
  186. CWamInfo *pWamInfo
  187. );
  188. bool FindWamInfo
  189. (
  190. CProcessEntry* pProcessEntry,
  191. CWamInfo** ppWamInfo
  192. );
  193. bool RecycleWamInfo
  194. (
  195. CWamInfo * pWamInfo
  196. );
  197. bool Init();
  198. bool UnInit();
  199. private:
  200. HRESULT ShutdownProcess
  201. (
  202. DWORD dwProcEntryPid
  203. );
  204. DWORD m_dwCnt;
  205. DWORD m_pCurrentProcessId;
  206. CProcessEntryHash m_HashTable;
  207. ICOMAdminCatalog2* m_pCatalog;
  208. CRITICAL_SECTION m_csPTable;
  209. };
  210. inline void CProcessTable::Lock()
  211. {
  212. EnterCriticalSection(&m_csPTable);
  213. }
  214. inline void CProcessTable::UnLock()
  215. {
  216. LeaveCriticalSection(&m_csPTable);
  217. }
  218. #endif __W3SVC_WAMINFO_HXX__