]>
Commit | Line | Data |
---|---|---|
cf447356 GL |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: process.h | |
3 | // Purpose: wxProcess class | |
4 | // Author: Guilhem Lavaux | |
7e84f02d | 5 | // Modified by: Vadim Zeitlin to check error codes, added Detach() method |
cf447356 GL |
6 | // Created: 24/06/98 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1998 Guilhem Lavaux | |
7e84f02d | 9 | // Licence: wxWindows license |
cf447356 GL |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
34138703 JS |
12 | #ifndef _WX_PROCESSH__ |
13 | #define _WX_PROCESSH__ | |
cf447356 GL |
14 | |
15 | #ifdef __GNUG__ | |
5336ece4 | 16 | #pragma interface "process.h" |
cf447356 GL |
17 | #endif |
18 | ||
19 | #include "wx/defs.h" | |
20 | #include "wx/object.h" | |
21 | #include "wx/event.h" | |
f6bcfd97 BP |
22 | |
23 | #if wxUSE_STREAMS | |
0c850713 | 24 | #include "wx/stream.h" |
f6bcfd97 | 25 | #endif |
cf447356 | 26 | |
2e4df4bf | 27 | // ---------------------------------------------------------------------------- |
5336ece4 VZ |
28 | // A wxProcess object should be passed to wxExecute - than its OnTerminate() |
29 | // function will be called when the process terminates. | |
2e4df4bf VZ |
30 | // ---------------------------------------------------------------------------- |
31 | ||
5336ece4 | 32 | class WXDLLEXPORT wxProcess : public wxEvtHandler |
cf447356 | 33 | { |
5336ece4 VZ |
34 | DECLARE_DYNAMIC_CLASS(wxProcess) |
35 | ||
36 | public: | |
cd6ce4a9 VZ |
37 | wxProcess(wxEvtHandler *parent = (wxEvtHandler *) NULL, int id = -1) |
38 | { Init(parent, id, FALSE); } | |
39 | wxProcess(wxEvtHandler *parent, bool redirect) | |
40 | { Init(parent, -1, redirect); } | |
cf447356 | 41 | |
cd6ce4a9 VZ |
42 | virtual ~wxProcess(); |
43 | ||
44 | // may be overridden to be notified about process termination | |
5336ece4 | 45 | virtual void OnTerminate(int pid, int status); |
cf447356 | 46 | |
cd6ce4a9 VZ |
47 | // call this before passing the object to wxExecute() to redirect the |
48 | // launched process stdin/stdout, then use GetInputStream() and | |
49 | // GetOutputStream() to get access to them | |
50 | void Redirect() { m_redirect = TRUE; } | |
51 | bool IsRedirected() const { return m_redirect; } | |
52 | ||
7e84f02d VZ |
53 | // detach from the parent - should be called by the parent if it's deleted |
54 | // before the process it started terminates | |
55 | void Detach(); | |
56 | ||
f6bcfd97 | 57 | #if wxUSE_STREAMS |
8b33ae2d | 58 | // Pipe handling |
cd6ce4a9 | 59 | wxInputStream *GetInputStream() const { return m_inputStream; } |
f6bcfd97 | 60 | wxInputStream *GetErrorStream() const { return m_errorStream; } |
cd6ce4a9 | 61 | wxOutputStream *GetOutputStream() const { return m_outputStream; } |
8b33ae2d | 62 | |
f6bcfd97 BP |
63 | // close the output stream indicating that nothing more will be written |
64 | void CloseOutput() { delete m_outputStream; m_outputStream = NULL; } | |
65 | ||
cd6ce4a9 | 66 | // implementation only (for wxExecute) |
f6bcfd97 BP |
67 | void SetPipeStreams(wxInputStream *inStream, |
68 | wxOutputStream *outStream, | |
69 | wxInputStream *errStream); | |
70 | #endif // wxUSE_STREAMS | |
8b33ae2d | 71 | |
5336ece4 | 72 | protected: |
cd6ce4a9 VZ |
73 | void Init(wxEvtHandler *parent, int id, bool redirect); |
74 | ||
5336ece4 | 75 | int m_id; |
cd6ce4a9 | 76 | |
f6bcfd97 BP |
77 | #if wxUSE_STREAMS |
78 | wxInputStream *m_inputStream, | |
79 | *m_errorStream; | |
cd6ce4a9 | 80 | wxOutputStream *m_outputStream; |
f6bcfd97 | 81 | #endif // wxUSE_STREAMS |
cd6ce4a9 VZ |
82 | |
83 | bool m_redirect; | |
cf447356 GL |
84 | }; |
85 | ||
2e4df4bf VZ |
86 | // ---------------------------------------------------------------------------- |
87 | // wxProcess events | |
88 | // ---------------------------------------------------------------------------- | |
89 | ||
71b9ed15 VZ |
90 | BEGIN_DECLARE_EVENT_TYPES() |
91 | DECLARE_EVENT_TYPE(wxEVT_END_PROCESS, 440) | |
92 | END_DECLARE_EVENT_TYPES() | |
93 | ||
0c850713 VZ |
94 | class WXDLLEXPORT wxProcessEvent : public wxEvent |
95 | { | |
96 | public: | |
97 | wxProcessEvent(int id = 0, int pid = 0, int exitcode = 0) : wxEvent(id) | |
98 | { | |
99 | m_eventType = wxEVT_END_PROCESS; | |
100 | m_pid = pid; | |
101 | m_exitcode = exitcode; | |
102 | } | |
103 | ||
104 | // accessors | |
105 | // PID of process which terminated | |
106 | int GetPid() { return m_pid; } | |
107 | ||
108 | // the exit code | |
109 | int GetExitCode() { return m_exitcode; } | |
110 | ||
111 | public: | |
112 | int m_pid, m_exitcode; | |
113 | ||
114 | DECLARE_DYNAMIC_CLASS(wxProcessEvent) | |
115 | }; | |
116 | ||
cf447356 GL |
117 | typedef void (wxObject::*wxProcessEventFunction)(wxProcessEvent&); |
118 | ||
82a5f02c | 119 | #define EVT_END_PROCESS(id, func) \ |
2e4df4bf | 120 | DECLARE_EVENT_TABLE_ENTRY( wxEVT_END_PROCESS, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxProcessEventFunction) & func, NULL), |
cf447356 GL |
121 | |
122 | #endif | |
34138703 | 123 | // _WX_PROCESSH__ |