comparison host/tools/Utils/win32/SubProcess.h @ 76:435cced73e2f ecos-v1_3_1-release

eCos v1.3.1 merged from eCos master repository on 2000-03-27-23:22:51-BST
author jlarmour
date Tue, 28 Mar 2000 14:10:45 +0000
parents
children
comparison
equal deleted inserted replaced
75:41bf073c0c32 76:435cced73e2f
1 //####COPYRIGHTBEGIN####
2 //
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
5 //
6 // This program is part of the eCos host tools.
7 //
8 // This program is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
11 // any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 // more details.
17 //
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 //
22 // ----------------------------------------------------------------------------
23 //
24 //####COPYRIGHTEND####
25 //===========================================================================
26 //#####DESCRIPTIONBEGIN####
27 //
28 // Author(s): sdf
29 // Contact(s): sdf
30 // Date: 1998/08/11
31 // Version: 0.01
32 // Purpose:
33 // Description: Interface of the subprocess clas
34 // Requires:
35 // Provides:
36 // See also:
37 // Known bugs:
38 // Usage:
39 //
40 //####DESCRIPTIONEND####
41 //
42 //===========================================================================
43 #ifndef _SUBPROCESS_H
44 #define _SUBPROCESS_H
45
46 #define WM_SUBPROCESS (WM_USER+42)
47
48 #include "eCosStd.h"
49 #include "Collections.h"
50
51 class CSubprocess {
52 // Class to spawn subprocesses.
53
54 public:
55
56 // ctors and dtors. Nothing exciting here.
57 CSubprocess(bool bVerbose=false);
58 virtual ~CSubprocess();
59
60 // Get the process exit code. This can be:
61 // exit code of process (if terminated)
62 // 0xffffffff (if process not yet run)
63 // GetLastError result (if process could not be run)
64 DWORD GetExitCode() { return m_dwExitCode; }
65
66 // Close the process's stdin
67 void CloseInput();
68
69 // Various forms of the Run function. In each case the result is the process ID created (0 if failure)
70
71 // Run a process (blocking)
72 unsigned int Run(String &strOutput,LPCTSTR pszCmd,LPCTSTR pszDir=_T(""));
73 #ifdef _WIN32
74 // Run a process (non-blocking): caller gets WM_SUBPROCESS messages:
75 // wParam is the this pointer, lParam is text string [for process output]
76 // which callee deletes, or 0 [for process completion]
77 unsigned int Run(HWND hwndParent, LPCTSTR pszCmd,LPCTSTR pszDir=_T("")); // post messages to given window
78 unsigned int Run(DWORD dwParentThreadId,LPCTSTR pszCmd,LPCTSTR pszDir=_T("")); // post messages to given thread
79 #endif
80
81 // Run (non-blocking and discarding output)
82 static unsigned int Run(LPCTSTR pszCmd,LPCTSTR pszDir=_T(""));
83
84 // Run (blocking and sending output to callback)
85 unsigned int Run(LogFunc *pfnLog,void * pLogparam,LPCTSTR pszCmd,LPCTSTR pszDir=_T(""));
86
87 // Kill the process:
88 bool Kill();
89
90 // Kill the process and its children the Cygwin way (requires ps and kill)
91 void CygKill();
92
93 // Send some input to the process:
94 void Send (LPCTSTR psz);
95
96 protected:
97 LogFunc *m_pfnLogfunc;
98 void *m_pLogparam;
99 bool m_bAutoDelete;
100 DWORD m_dwExitCode;
101 static const UINT PROCESS_KILL_EXIT_CODE;
102 bool m_bVerbose;
103 bool m_bThreadRunning;
104 HANDLE m_hrPipe;
105 HANDLE m_hwPipe;
106 unsigned int CreateProcess();
107
108 struct CygProcessInfo {
109 int nPid;
110 int nPpid;
111 int nPgid;
112 int nWinpid;
113 };
114
115 String * m_pstrOutput;
116 HANDLE m_hThread;
117 void Post (LPARAM lParam);
118 DWORD m_idProcess;
119
120 HANDLE m_hProcess;
121 void Output(LPCTSTR psz);
122 String m_strCmd,m_strDir;
123 #ifdef _WIN32
124 HWND m_hwndParent;
125 #endif
126 DWORD m_dwParentThreadId;
127 static DWORD WINAPI ThreadFunc(LPVOID pParam) { return ((CSubprocess *)pParam)->ThreadFunc(); }
128 DWORD ThreadFunc();
129 };
130
131 #endif