]> git.saurik.com Git - wxWidgets.git/blob - include/wx/process.h
oops... fixed a typo
[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 // ----------------------------------------------------------------------------
28 // wxProcessEvent: event used with wxProcess
29 // ----------------------------------------------------------------------------
30
31 class WXDLLEXPORT wxProcessEvent : public wxEvent
32 {
33 DECLARE_DYNAMIC_CLASS(wxProcessEvent)
34
35 public:
36 wxProcessEvent(int id = 0, int pid = 0, int exitcode = 0) : wxEvent(id)
37 {
38 m_eventType = wxEVT_END_PROCESS;
39 m_pid = pid;
40 m_exitcode = exitcode;
41 }
42
43 // accessors
44 // PID of process which terminated
45 int GetPid() { return m_pid; }
46
47 // the exit code
48 int GetExitCode() { return m_exitcode; }
49
50 public:
51 int m_pid, m_exitcode;
52 };
53
54 // ----------------------------------------------------------------------------
55 // A wxProcess object should be passed to wxExecute - than its OnTerminate()
56 // function will be called when the process terminates.
57 // ----------------------------------------------------------------------------
58
59 class WXDLLEXPORT wxProcess : public wxEvtHandler
60 {
61 DECLARE_DYNAMIC_CLASS(wxProcess)
62
63 public:
64 wxProcess(wxEvtHandler *parent = (wxEvtHandler *) NULL, int id = -1)
65 { Init(parent, id, FALSE); }
66 wxProcess(wxEvtHandler *parent, bool redirect)
67 { Init(parent, -1, redirect); }
68
69 virtual ~wxProcess();
70
71 // may be overridden to be notified about process termination
72 virtual void OnTerminate(int pid, int status);
73
74 // call this before passing the object to wxExecute() to redirect the
75 // launched process stdin/stdout, then use GetInputStream() and
76 // GetOutputStream() to get access to them
77 void Redirect() { m_redirect = TRUE; }
78 bool IsRedirected() const { return m_redirect; }
79
80 // detach from the parent - should be called by the parent if it's deleted
81 // before the process it started terminates
82 void Detach();
83
84 #if wxUSE_STREAMS
85 // Pipe handling
86 wxInputStream *GetInputStream() const { return m_inputStream; }
87 wxInputStream *GetErrorStream() const { return m_errorStream; }
88 wxOutputStream *GetOutputStream() const { return m_outputStream; }
89
90 // close the output stream indicating that nothing more will be written
91 void CloseOutput() { delete m_outputStream; m_outputStream = NULL; }
92
93 // implementation only (for wxExecute)
94 void SetPipeStreams(wxInputStream *inStream,
95 wxOutputStream *outStream,
96 wxInputStream *errStream);
97 #endif // wxUSE_STREAMS
98
99 protected:
100 void Init(wxEvtHandler *parent, int id, bool redirect);
101
102 int m_id;
103
104 #if wxUSE_STREAMS
105 wxInputStream *m_inputStream,
106 *m_errorStream;
107 wxOutputStream *m_outputStream;
108 #endif // wxUSE_STREAMS
109
110 bool m_redirect;
111 };
112
113 // ----------------------------------------------------------------------------
114 // wxProcess events
115 // ----------------------------------------------------------------------------
116
117 BEGIN_DECLARE_EVENT_TYPES()
118 DECLARE_EVENT_TYPE(wxEVT_END_PROCESS, 440)
119 END_DECLARE_EVENT_TYPES()
120
121 typedef void (wxObject::*wxProcessEventFunction)(wxProcessEvent&);
122
123 #define EVT_END_PROCESS(id, func) \
124 DECLARE_EVENT_TABLE_ENTRY( wxEVT_END_PROCESS, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxProcessEventFunction) & func, NULL),
125
126 #endif
127 // _WX_PROCESSH__