]> git.saurik.com Git - wxWidgets.git/blame - src/common/process.cpp
Added Ok() member for print data, print dialog, page dialog, page dialog data
[wxWidgets.git] / src / common / process.cpp
CommitLineData
ca7731b7
GL
1/////////////////////////////////////////////////////////////////////////////
2// Name: process.cpp
3// Purpose: Process termination classes
4// Author: Guilhem Lavaux
7e84f02d 5// Modified by: Vadim Zeitlin to check error codes, added Detach() method
ca7731b7
GL
6// Created: 24/06/98
7// RCS-ID: $Id$
8// Copyright: (c) Guilhem Lavaux
7e84f02d 9// Licence: wxWindows license
ca7731b7
GL
10/////////////////////////////////////////////////////////////////////////////
11
50567b69
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
ca7731b7 20#ifdef __GNUG__
5336ece4 21 #pragma implementation "process.h"
ca7731b7
GL
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
5336ece4 28 #pragma hdrstop
ca7731b7
GL
29#endif
30
ca7731b7
GL
31#include "wx/process.h"
32
50567b69
VZ
33// ----------------------------------------------------------------------------
34// event tables and such
35// ----------------------------------------------------------------------------
36
2e4df4bf
VZ
37DEFINE_EVENT_TYPE(wxEVT_END_PROCESS)
38
eebb848a
KB
39IMPLEMENT_DYNAMIC_CLASS(wxProcess, wxEvtHandler)
40IMPLEMENT_DYNAMIC_CLASS(wxProcessEvent, wxEvent)
ca7731b7 41
50567b69
VZ
42// ============================================================================
43// wxProcess implementation
44// ============================================================================
45
46// ----------------------------------------------------------------------------
47// wxProcess creation
48// ----------------------------------------------------------------------------
49
cd6ce4a9 50void wxProcess::Init(wxEvtHandler *parent, int id, bool redirect)
ca7731b7 51{
cd6ce4a9 52 if ( parent )
7e84f02d 53 SetNextHandler(parent);
ca7731b7 54
8b33ae2d 55 m_id = id;
cd6ce4a9 56 m_redirect = redirect;
f6bcfd97
BP
57
58#if wxUSE_STREAMS
cd6ce4a9 59 m_inputStream = NULL;
f6bcfd97 60 m_errorStream = NULL;
cd6ce4a9 61 m_outputStream = NULL;
f6bcfd97 62#endif // wxUSE_STREAMS
8b33ae2d
GL
63}
64
50567b69
VZ
65// ----------------------------------------------------------------------------
66// wxProcess termination
67// ----------------------------------------------------------------------------
68
8b33ae2d
GL
69wxProcess::~wxProcess()
70{
f6bcfd97 71#if wxUSE_STREAMS
cd6ce4a9 72 delete m_inputStream;
f6bcfd97 73 delete m_errorStream;
cd6ce4a9 74 delete m_outputStream;
f6bcfd97 75#endif // wxUSE_STREAMS
ca7731b7
GL
76}
77
5336ece4 78void wxProcess::OnTerminate(int pid, int status)
81d66cf3 79{
7e84f02d 80 wxProcessEvent event(m_id, pid, status);
ca7731b7 81
7e84f02d
VZ
82 if ( !ProcessEvent(event) )
83 delete this;
84 //else: the object which processed the event is responsible for deleting
85 // us!
86}
87
88void wxProcess::Detach()
89{
90 SetNextHandler(NULL);
ca7731b7 91}
8b33ae2d 92
50567b69
VZ
93// ----------------------------------------------------------------------------
94// process IO redirection
95// ----------------------------------------------------------------------------
96
f6bcfd97
BP
97#if wxUSE_STREAMS
98
99void wxProcess::SetPipeStreams(wxInputStream *inputSstream,
100 wxOutputStream *outputStream,
101 wxInputStream *errorStream)
8b33ae2d 102{
f6bcfd97
BP
103 m_inputStream = inputSstream;
104 m_errorStream = errorStream;
105 m_outputStream = outputStream;
8b33ae2d
GL
106}
107
f6bcfd97 108#endif // wxUSE_STREAMS
50567b69
VZ
109
110// ----------------------------------------------------------------------------
111// process killing
112// ----------------------------------------------------------------------------
113
114/* static */
115wxKillError wxProcess::Kill(int pid, wxSignal sig)
116{
117 wxKillError rc;
118 (void)wxKill(pid, sig, &rc);
119
120 return rc;
121}
122
123/* static */
124bool wxProcess::Exists(int pid)
125{
15b663b4 126 switch ( Kill(pid, wxSIGNONE) )
50567b69
VZ
127 {
128 case wxKILL_OK:
129 case wxKILL_ACCESS_DENIED:
130 return TRUE;
131
132 default:
133 case wxKILL_ERROR:
134 case wxKILL_BAD_SIGNAL:
135 wxFAIL_MSG( _T("unexpected wxProcess::Kill() return code") );
136 // fall through
137
138 case wxKILL_NO_PROCESS:
139 return FALSE;
140 }
141}
142