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