]>
git.saurik.com Git - wxWidgets.git/blob - src/common/process.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Process termination classes
4 // Author: Guilhem Lavaux
5 // Modified by: Vadim Zeitlin to check error codes, added Detach() method
8 // Copyright: (c) Guilhem Lavaux
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "process.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
31 #include "wx/process.h"
33 // ----------------------------------------------------------------------------
34 // event tables and such
35 // ----------------------------------------------------------------------------
37 DEFINE_EVENT_TYPE(wxEVT_END_PROCESS
)
39 IMPLEMENT_DYNAMIC_CLASS(wxProcess
, wxEvtHandler
)
40 IMPLEMENT_DYNAMIC_CLASS(wxProcessEvent
, wxEvent
)
42 // ============================================================================
43 // wxProcess implementation
44 // ============================================================================
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 void wxProcess::Init(wxEvtHandler
*parent
, int id
, bool redirect
)
53 SetNextHandler(parent
);
56 m_redirect
= redirect
;
61 m_outputStream
= NULL
;
62 #endif // wxUSE_STREAMS
65 // ----------------------------------------------------------------------------
66 // wxProcess termination
67 // ----------------------------------------------------------------------------
69 wxProcess::~wxProcess()
74 delete m_outputStream
;
75 #endif // wxUSE_STREAMS
78 void wxProcess::OnTerminate(int pid
, int status
)
80 wxProcessEvent
event(m_id
, pid
, status
);
82 if ( !ProcessEvent(event
) )
84 //else: the object which processed the event is responsible for deleting
88 void wxProcess::Detach()
93 // ----------------------------------------------------------------------------
94 // process IO redirection
95 // ----------------------------------------------------------------------------
99 void wxProcess::SetPipeStreams(wxInputStream
*inputSstream
,
100 wxOutputStream
*outputStream
,
101 wxInputStream
*errorStream
)
103 m_inputStream
= inputSstream
;
104 m_errorStream
= errorStream
;
105 m_outputStream
= outputStream
;
108 #endif // wxUSE_STREAMS
110 // ----------------------------------------------------------------------------
112 // ----------------------------------------------------------------------------
115 wxKillError
wxProcess::Kill(int pid
, wxSignal sig
)
118 (void)wxKill(pid
, sig
, &rc
);
124 bool wxProcess::Exists(int pid
)
126 switch ( wxProcess::Kill(pid
, wxSIGNONE
) )
129 case wxKILL_ACCESS_DENIED
:
134 case wxKILL_BAD_SIGNAL
:
135 wxFAIL_MSG( _T("unexpected wxProcess::Kill() return code") );
138 case wxKILL_NO_PROCESS
: