]> git.saurik.com Git - wxWidgets.git/blob - include/wx/process.h
Added wxFileName::GetModificationTime()
[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 // A wxProcess object should be passed to wxExecute - than its OnTerminate()
29 // function will be called when the process terminates.
30 // ----------------------------------------------------------------------------
31
32 class WXDLLEXPORT wxProcess : public wxEvtHandler
33 {
34 DECLARE_DYNAMIC_CLASS(wxProcess)
35
36 public:
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); }
41
42 virtual ~wxProcess();
43
44 // may be overridden to be notified about process termination
45 virtual void OnTerminate(int pid, int status);
46
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
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
57 #if wxUSE_STREAMS
58 // Pipe handling
59 wxInputStream *GetInputStream() const { return m_inputStream; }
60 wxInputStream *GetErrorStream() const { return m_errorStream; }
61 wxOutputStream *GetOutputStream() const { return m_outputStream; }
62
63 // close the output stream indicating that nothing more will be written
64 void CloseOutput() { delete m_outputStream; m_outputStream = NULL; }
65
66 // implementation only (for wxExecute)
67 void SetPipeStreams(wxInputStream *inStream,
68 wxOutputStream *outStream,
69 wxInputStream *errStream);
70 #endif // wxUSE_STREAMS
71
72 protected:
73 void Init(wxEvtHandler *parent, int id, bool redirect);
74
75 int m_id;
76
77 #if wxUSE_STREAMS
78 wxInputStream *m_inputStream,
79 *m_errorStream;
80 wxOutputStream *m_outputStream;
81 #endif // wxUSE_STREAMS
82
83 bool m_redirect;
84 };
85
86 // ----------------------------------------------------------------------------
87 // wxProcess events
88 // ----------------------------------------------------------------------------
89
90 BEGIN_DECLARE_EVENT_TYPES()
91 DECLARE_EVENT_TYPE(wxEVT_END_PROCESS, 440)
92 END_DECLARE_EVENT_TYPES()
93
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
117 typedef void (wxObject::*wxProcessEventFunction)(wxProcessEvent&);
118
119 #define EVT_END_PROCESS(id, func) \
120 DECLARE_EVENT_TABLE_ENTRY( wxEVT_END_PROCESS, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxProcessEventFunction) & func, NULL),
121
122 #endif
123 // _WX_PROCESSH__