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.

122 lines
3.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: process.h
  7. //
  8. // Contents: CProcessThread class definition
  9. //
  10. //----------------------------------------------------------------------------
  11. #define PIPE_BUFFER_SIZE 1024
  12. class CProcessComm;
  13. //+---------------------------------------------------------------------------
  14. //
  15. // Class: CProcessParams
  16. //
  17. // Purpose: Provide simple free store management for PROCESS_PARAMS
  18. //
  19. //----------------------------------------------------------------------------
  20. class CProcessParams : public PROCESS_PARAMS
  21. {
  22. public:
  23. CProcessParams();
  24. ~CProcessParams();
  25. // CProcessParams &operator =(const PROCESS_PARAMS &params);
  26. bool Copy(const PROCESS_PARAMS *params);
  27. private:
  28. void Free();
  29. bool Assign(const PROCESS_PARAMS &params);
  30. };
  31. //+---------------------------------------------------------------------------
  32. //
  33. // Class: CProcessThread (cpt)
  34. //
  35. // Purpose: Class which spawns a process, monitors its success, talks to
  36. // it during execution if necessary, and returns its completion
  37. // status. (each CProcessThread is in its own thread)
  38. //
  39. //----------------------------------------------------------------------------
  40. class CProcessThread : public CThreadComm
  41. {
  42. public:
  43. CProcessThread(CScriptHost *pSH);
  44. ~CProcessThread();
  45. DECLARE_STANDARD_IUNKNOWN(CProcessThread);
  46. DWORD ProcId() { return _piProc.dwProcessId; }
  47. // Thread-Safe member functions. These can be called by any thread to
  48. // get the appropriate information without having to go through
  49. // PostToThread. These are only safe AFTER the process has been started.
  50. HRESULT GetProcessOutput(BSTR *pbstrOutput);
  51. DWORD GetExitCode();
  52. void SetExitCode(DWORD dwExitCode)
  53. {
  54. _dwExitCode = dwExitCode;
  55. _fUseExitCode = TRUE;
  56. }
  57. void Terminate();
  58. ULONG GetDeadTime();
  59. BOOL IsOwner(DWORD dwProcID, long lID)
  60. { return (lID == _lEnvID); }
  61. CScriptHost * ScriptHost()
  62. { return _pSH; }
  63. void SetProcComm(CProcessComm *pPC)
  64. { Assert(!_pPC || !pPC); _pPC = pPC; }
  65. CProcessComm * GetProcComm()
  66. { return _pPC; }
  67. const PROCESS_PARAMS *GetParams() const { return &_ProcParams; }
  68. protected:
  69. virtual DWORD ThreadMain();
  70. virtual BOOL Init();
  71. void HandleThreadMessage();
  72. void HandleProcessExit();
  73. BOOL IsDataInPipe();
  74. void ReadPipeData();
  75. void CheckIoPort();
  76. HRESULT LaunchProcess(const PROCESS_PARAMS *pProcParams);
  77. void GetProcessEnvironment(CStr *pcstr, BOOL fNoEnviron);
  78. private:
  79. CScriptHost *_pSH;
  80. CProcessComm *_pPC; // Not AddRef'd
  81. PROCESS_INFORMATION _piProc;
  82. long _lEnvID;
  83. DWORD _dwExitCode; // Value set explicitely by the process
  84. BOOL _fUseExitCode; // TRUE if _dwExitCode is the code we want
  85. HANDLE _hPipe;
  86. BYTE _abBuffer[PIPE_BUFFER_SIZE];
  87. HANDLE _hJob;
  88. HANDLE _hIoPort;
  89. CStackPtrAry<DWORD, 10> _aryProcIds;
  90. CProcessParams _ProcParams;
  91. _int64 _i64ExitTime;
  92. // Access to the following members must be thread-safe (by calling
  93. // LOCK_LOCALS).
  94. CStr _cstrOutput;
  95. };