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