]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/process.h
removed duplicate #include
[wxWidgets.git] / include / wx / process.h
... / ...
CommitLineData
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/event.h"
20
21#if wxUSE_STREAMS
22 #include "wx/stream.h"
23#endif
24
25#include "wx/utils.h" // for wxSignal
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
32class WXDLLEXPORT wxProcess : public wxEvtHandler
33{
34public:
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); }
39
40 virtual ~wxProcess();
41
42 // may be overridden to be notified about process termination
43 virtual void OnTerminate(int pid, int status);
44
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
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
55#if wxUSE_STREAMS
56 // Pipe handling
57 wxInputStream *GetInputStream() const { return m_inputStream; }
58 wxInputStream *GetErrorStream() const { return m_errorStream; }
59 wxOutputStream *GetOutputStream() const { return m_outputStream; }
60
61 // close the output stream indicating that nothing more will be written
62 void CloseOutput() { delete m_outputStream; m_outputStream = NULL; }
63
64 // implementation only (for wxExecute)
65 void SetPipeStreams(wxInputStream *inStream,
66 wxOutputStream *outStream,
67 wxInputStream *errStream);
68#endif // wxUSE_STREAMS
69
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
76protected:
77 void Init(wxEvtHandler *parent, int id, bool redirect);
78
79 int m_id;
80
81#if wxUSE_STREAMS
82 wxInputStream *m_inputStream,
83 *m_errorStream;
84 wxOutputStream *m_outputStream;
85#endif // wxUSE_STREAMS
86
87 bool m_redirect;
88
89 DECLARE_DYNAMIC_CLASS(wxProcess)
90};
91
92// ----------------------------------------------------------------------------
93// wxProcess events
94// ----------------------------------------------------------------------------
95
96BEGIN_DECLARE_EVENT_TYPES()
97 DECLARE_EVENT_TYPE(wxEVT_END_PROCESS, 440)
98END_DECLARE_EVENT_TYPES()
99
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
117 // implement the base class pure virtual
118 virtual wxEvent *Clone() const { return new wxProcessEvent(*this); }
119
120public:
121 int m_pid,
122 m_exitcode;
123
124 DECLARE_DYNAMIC_CLASS(wxProcessEvent)
125};
126
127typedef void (wxEvtHandler::*wxProcessEventFunction)(wxProcessEvent&);
128
129#define EVT_END_PROCESS(id, func) \
130 DECLARE_EVENT_TABLE_ENTRY( \
131 wxEVT_END_PROCESS, id, -1, \
132 (wxObjectEventFunction) \
133 (wxEventFunction) \
134 (wxProcessEventFunction) & func, NULL),
135
136#endif
137 // _WX_PROCESSH__