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.

103 lines
2.3 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: watchprocess.h
  4. //
  5. // Module: CMMON32.EXE
  6. //
  7. // Synopsis: Header and Implementation for the CWatchProcessList class.
  8. //
  9. // Copyright (c) 1998 Microsoft Corporation
  10. //
  11. // Author: quintinb Created Header 08/16/99
  12. //
  13. //+----------------------------------------------------------------------------
  14. #include "ArrayPtr.h"
  15. //+---------------------------------------------------------------------------
  16. //
  17. // class CWatchProcessList
  18. //
  19. // Description: Manage to list of process handle.
  20. // Tell whether all the processes are terminated
  21. //
  22. // History: fengsun Created 10/30/97
  23. //
  24. //----------------------------------------------------------------------------
  25. class CWatchProcessList
  26. {
  27. public:
  28. CWatchProcessList();
  29. ~CWatchProcessList();
  30. BOOL IsIdle();
  31. void Add(HANDLE hProcess);
  32. void SetNotIdle() {m_fProcessAdded = FALSE;};
  33. DWORD GetSize() const {return m_ProcessArray.GetSize();}
  34. HANDLE GetProcess(int i) {return m_ProcessArray[i];}
  35. protected:
  36. // an array of process handle
  37. CPtrArray m_ProcessArray;
  38. BOOL m_fProcessAdded;
  39. };
  40. inline CWatchProcessList::CWatchProcessList()
  41. {
  42. m_fProcessAdded = FALSE;
  43. }
  44. inline CWatchProcessList::~CWatchProcessList()
  45. {
  46. for (int i=m_ProcessArray.GetSize()-1; i>=0; i--)
  47. {
  48. CloseHandle((HANDLE)m_ProcessArray[i]);
  49. }
  50. }
  51. inline BOOL CWatchProcessList::IsIdle()
  52. {
  53. if (!m_fProcessAdded)
  54. {
  55. return FALSE;
  56. }
  57. for (int i=m_ProcessArray.GetSize()-1; i>=0; i--)
  58. {
  59. DWORD dwExitCode;
  60. BOOL bRes = GetExitCodeProcess((HANDLE)m_ProcessArray[i],&dwExitCode);
  61. if (!bRes || (dwExitCode != STILL_ACTIVE))
  62. {
  63. CloseHandle((HANDLE)m_ProcessArray[i]);
  64. m_ProcessArray.RemoveAt(i);
  65. }
  66. }
  67. return m_ProcessArray.GetSize() == 0;
  68. }
  69. inline void CWatchProcessList::Add(HANDLE hProcess)
  70. {
  71. //
  72. // CMDIAL calls DuplicateHandle to get the hProcess
  73. // CmMon is responsible to close the handle
  74. //
  75. MYDBGASSERT(hProcess);
  76. //
  77. // It is possible the auto application exited before this function is called
  78. //
  79. m_fProcessAdded = TRUE;
  80. if (hProcess)
  81. {
  82. m_ProcessArray.Add(hProcess);
  83. }
  84. }