]> git.saurik.com Git - wxWidgets.git/blame - include/wx/process.h
added test for __MACH__ for Mac OS X compilation
[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
19#include "wx/defs.h"
20#include "wx/object.h"
21#include "wx/event.h"
f6bcfd97
BP
22
23#if wxUSE_STREAMS
8b33ae2d 24#include "wx/stream.h"
f6bcfd97 25#endif
cf447356 26
5336ece4
VZ
27// Process Event handling
28class WXDLLEXPORT wxProcessEvent : public wxEvent
cf447356 29{
5336ece4 30DECLARE_DYNAMIC_CLASS(wxProcessEvent)
cf447356 31
5336ece4
VZ
32public:
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 }
cf447356 39
5336ece4
VZ
40 // accessors
41 // PID of process which terminated
42 int GetPid() { return m_pid; }
cf447356 43
5336ece4
VZ
44 // the exit code
45 int GetExitCode() { return m_exitcode; }
cf447356 46
5336ece4
VZ
47public:
48 int m_pid, m_exitcode;
49};
cf447356 50
5336ece4
VZ
51// A wxProcess object should be passed to wxExecute - than its OnTerminate()
52// function will be called when the process terminates.
53class WXDLLEXPORT wxProcess : public wxEvtHandler
cf447356 54{
5336ece4
VZ
55DECLARE_DYNAMIC_CLASS(wxProcess)
56
57public:
cd6ce4a9
VZ
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); }
cf447356 62
cd6ce4a9
VZ
63 virtual ~wxProcess();
64
65 // may be overridden to be notified about process termination
5336ece4 66 virtual void OnTerminate(int pid, int status);
cf447356 67
cd6ce4a9
VZ
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
7e84f02d
VZ
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
f6bcfd97 78#if wxUSE_STREAMS
8b33ae2d 79 // Pipe handling
cd6ce4a9 80 wxInputStream *GetInputStream() const { return m_inputStream; }
f6bcfd97 81 wxInputStream *GetErrorStream() const { return m_errorStream; }
cd6ce4a9 82 wxOutputStream *GetOutputStream() const { return m_outputStream; }
8b33ae2d 83
f6bcfd97
BP
84 // close the output stream indicating that nothing more will be written
85 void CloseOutput() { delete m_outputStream; m_outputStream = NULL; }
86
cd6ce4a9 87 // implementation only (for wxExecute)
f6bcfd97
BP
88 void SetPipeStreams(wxInputStream *inStream,
89 wxOutputStream *outStream,
90 wxInputStream *errStream);
91#endif // wxUSE_STREAMS
8b33ae2d 92
5336ece4 93protected:
cd6ce4a9
VZ
94 void Init(wxEvtHandler *parent, int id, bool redirect);
95
5336ece4 96 int m_id;
cd6ce4a9 97
f6bcfd97
BP
98#if wxUSE_STREAMS
99 wxInputStream *m_inputStream,
100 *m_errorStream;
cd6ce4a9 101 wxOutputStream *m_outputStream;
f6bcfd97 102#endif // wxUSE_STREAMS
cd6ce4a9
VZ
103
104 bool m_redirect;
cf447356
GL
105};
106
107typedef void (wxObject::*wxProcessEventFunction)(wxProcessEvent&);
108
82a5f02c
RR
109#define EVT_END_PROCESS(id, func) \
110 wxEventTableEntry( wxEVT_END_PROCESS, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxProcessEventFunction) & func, NULL),
cf447356
GL
111
112#endif
34138703 113 // _WX_PROCESSH__