Add libwx-perl
[pkg-perl] / deb-src / libwx-perl / libwx-perl-0.96 / XS / Process.xs
1 #############################################################################
2 ## Name:        XS/Process.xs
3 ## Purpose:     XS for Wx::Process and Wx::ProcessEvent and Wx::Execute
4 ## Author:      Mattia Barbon
5 ## Modified by:
6 ## Created:     11/02/2002
7 ## RCS-ID:      $Id: Process.xs 2186 2007-08-19 21:13:06Z mbarbon $
8 ## Copyright:   (c) 2002-2004, 2006-2007 Mattia Barbon
9 ## Licence:     This program is free software; you can redistribute it and/or
10 ##              modify it under the same terms as Perl itself
11 #############################################################################
12
13 #include <wx/process.h>
14 #include "cpp/process.h"
15 #include <wx/utils.h>
16
17 MODULE=Wx PACKAGE=Wx::ProcessEvent
18
19 wxProcessEvent*
20 wxProcessEvent::new( id = 0, pid = 0, status = 0 )
21     int id
22     int pid
23     int status
24
25 int
26 wxProcessEvent::GetPid()
27
28 int
29 wxProcessEvent::GetExitCode()
30
31 MODULE=Wx PACKAGE=Wx::Process
32
33 wxProcess*
34 wxProcess::new( parent = 0, id = -1 )
35     wxEvtHandler* parent
36     int id
37   CODE:
38     RETVAL = new wxPliProcess( CLASS, parent, id );
39   OUTPUT:
40     RETVAL
41
42 void
43 wxProcess::Destroy()
44   CODE:
45     delete THIS;
46
47 void
48 wxProcess::CloseOutput()
49
50 void
51 wxProcess::Detach()
52
53 wxInputStream*
54 wxProcess::GetErrorStream()
55
56 wxInputStream*
57 wxProcess::GetInputStream()
58
59 wxOutputStream*
60 wxProcess::GetOutputStream()
61
62 bool
63 wxProcess::IsErrorAvailable()
64
65 bool
66 wxProcess::IsInputAvailable()
67
68 bool
69 wxProcess::IsInputOpened()
70
71 #if WXPERL_W_VERSION_LT( 2, 5, 4 )
72 #define wxKILL_NOCHILDREN 0
73 #endif
74
75 wxKillError
76 Kill( pid, signal = wxSIGNONE, flags = wxKILL_NOCHILDREN )
77     int pid
78     wxSignal signal
79     int flags
80   CODE:
81 #if WXPERL_W_VERSION_GE( 2, 5, 4 )
82     RETVAL = wxProcess::Kill( pid, signal, flags );
83 #else
84     RETVAL = wxProcess::Kill( pid, signal );
85 #endif
86   OUTPUT:
87     RETVAL
88
89 bool
90 Exists( pid )
91     int pid
92   CODE:
93     RETVAL = wxProcess::Exists( pid );
94   OUTPUT:
95     RETVAL
96
97 void
98 wxProcess::OnTerminate( pid, status )
99     int pid
100     int status
101   CODE:
102     THIS->wxProcess::OnTerminate( pid, status );
103
104 void
105 wxProcess::Redirect()
106
107 wxProcess*
108 Open( cmd, flags = wxEXEC_ASYNC )
109     wxString cmd
110     int flags
111   CODE:
112     RETVAL = wxProcess::Open( cmd, flags );
113   OUTPUT:
114     RETVAL
115
116 #if WXPERL_W_VERSION_GE( 2, 7, 2 )
117
118 int
119 wxProcess::GetPid()
120
121 #endif
122
123 MODULE=Wx PACKAGE=Wx PREFIX=wx
124
125 long
126 wxExecuteCommand( command, sync = wxEXEC_ASYNC, callback = 0 )
127     wxString command
128     int sync
129     wxProcess* callback
130   CODE:
131     RETVAL = wxExecute( command, sync, callback );
132   OUTPUT:
133     RETVAL
134
135 #if wxUSE_UNICODE
136
137 long
138 wxExecuteArgs( args, sync = wxEXEC_ASYNC, callback = 0 )
139     SV* args
140     int sync
141     wxProcess* callback
142   PREINIT:
143     wxChar** argv;
144     wxChar** t;
145     int n, i;
146   CODE:
147     n = wxPli_av_2_wxcharparray( aTHX_ args, &t );
148     argv = new wxChar*[n+1];
149     memcpy( argv, t, n*sizeof(char*) );
150     argv[n] = 0;
151     RETVAL = wxExecute( argv, sync, callback );
152     for( i = 0; i < n; ++i )
153         delete argv[i];
154     delete[] argv;
155     delete[] t;
156   OUTPUT:
157     RETVAL
158
159 #else
160
161 long
162 wxExecuteArgs( args, sync = wxEXEC_ASYNC, callback = 0 )
163     SV* args
164     int sync
165     wxProcess* callback
166   PREINIT:
167     char** argv;
168     char** t;
169     int n, i;
170   CODE:
171     n = wxPli_av_2_charparray( aTHX_ args, &t );
172     argv = new char*[n+1];
173     memcpy( argv, t, n*sizeof(char*) );
174     argv[n] = 0;
175     RETVAL = wxExecute( argv, sync, callback );
176     for( i = 0; i < n; ++i )
177         delete argv[i];
178     delete[] argv;
179     delete[] t;
180   OUTPUT:
181     RETVAL
182
183 #endif
184
185 void
186 wxExecuteStdout( command )
187     wxString command
188   PREINIT:
189     wxArrayString out;
190     AV* ret;
191     long code;
192   PPCODE:
193     code = wxExecute( command, out );
194     ret = wxPli_stringarray_2_av( aTHX_ out );
195     EXTEND( SP, 2 );
196     PUSHs( sv_2mortal( newSViv( code ) ) );
197     PUSHs( sv_2mortal( newRV_noinc( (SV*)ret ) ) );
198
199 void
200 wxExecuteStdoutStderr( command )
201     wxString command
202   PREINIT:
203     wxArrayString out, err;
204     AV *rout, *rerr;
205     long code;
206   PPCODE:
207     code = wxExecute( command, out, err );
208     rout = wxPli_stringarray_2_av( aTHX_ out );
209     rerr = wxPli_stringarray_2_av( aTHX_ err );
210     EXTEND( SP, 3 );
211     PUSHs( sv_2mortal( newSViv( code ) ) );
212     PUSHs( sv_2mortal( newRV_noinc( (SV*)rout ) ) );
213     PUSHs( sv_2mortal( newRV_noinc( (SV*)rerr ) ) );