1 // This file was generated by gir (https://github.com/gtk-rs/gir)
2 // from gir-files (https://github.com/gtk-rs/gir-files)
3 // DO NOT EDIT
4 
5 use crate::AsyncResult;
6 use crate::Cancellable;
7 use crate::Initable;
8 use crate::InputStream;
9 use crate::OutputStream;
10 use crate::SubprocessFlags;
11 use glib::object::IsA;
12 use glib::translate::*;
13 use std::boxed::Box as Box_;
14 use std::fmt;
15 use std::pin::Pin;
16 use std::ptr;
17 
18 glib::wrapper! {
19     #[doc(alias = "GSubprocess")]
20     pub struct Subprocess(Object<ffi::GSubprocess>) @implements Initable;
21 
22     match fn {
23         type_ => || ffi::g_subprocess_get_type(),
24     }
25 }
26 
27 impl Subprocess {
28     //#[doc(alias = "g_subprocess_new")]
29     //pub fn new(flags: SubprocessFlags, error: Option<&mut glib::Error>, argv0: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> Subprocess {
30     //    unsafe { TODO: call ffi:g_subprocess_new() }
31     //}
32 
33     #[doc(alias = "g_subprocess_newv")]
newv( argv: &[&std::ffi::OsStr], flags: SubprocessFlags, ) -> Result<Subprocess, glib::Error>34     pub fn newv(
35         argv: &[&std::ffi::OsStr],
36         flags: SubprocessFlags,
37     ) -> Result<Subprocess, glib::Error> {
38         unsafe {
39             let mut error = ptr::null_mut();
40             let ret = ffi::g_subprocess_newv(argv.to_glib_none().0, flags.into_glib(), &mut error);
41             if error.is_null() {
42                 Ok(from_glib_full(ret))
43             } else {
44                 Err(from_glib_full(error))
45             }
46         }
47     }
48 
49     #[doc(alias = "g_subprocess_communicate")]
communicate<P: IsA<Cancellable>>( &self, stdin_buf: Option<&glib::Bytes>, cancellable: Option<&P>, ) -> Result<(Option<glib::Bytes>, Option<glib::Bytes>), glib::Error>50     pub fn communicate<P: IsA<Cancellable>>(
51         &self,
52         stdin_buf: Option<&glib::Bytes>,
53         cancellable: Option<&P>,
54     ) -> Result<(Option<glib::Bytes>, Option<glib::Bytes>), glib::Error> {
55         unsafe {
56             let mut stdout_buf = ptr::null_mut();
57             let mut stderr_buf = ptr::null_mut();
58             let mut error = ptr::null_mut();
59             let _ = ffi::g_subprocess_communicate(
60                 self.to_glib_none().0,
61                 stdin_buf.to_glib_none().0,
62                 cancellable.map(|p| p.as_ref()).to_glib_none().0,
63                 &mut stdout_buf,
64                 &mut stderr_buf,
65                 &mut error,
66             );
67             if error.is_null() {
68                 Ok((from_glib_full(stdout_buf), from_glib_full(stderr_buf)))
69             } else {
70                 Err(from_glib_full(error))
71             }
72         }
73     }
74 
75     #[doc(alias = "g_subprocess_communicate_async")]
communicate_async< P: IsA<Cancellable>, Q: FnOnce(Result<(Option<glib::Bytes>, Option<glib::Bytes>), glib::Error>) + Send + 'static, >( &self, stdin_buf: Option<&glib::Bytes>, cancellable: Option<&P>, callback: Q, )76     pub fn communicate_async<
77         P: IsA<Cancellable>,
78         Q: FnOnce(Result<(Option<glib::Bytes>, Option<glib::Bytes>), glib::Error>) + Send + 'static,
79     >(
80         &self,
81         stdin_buf: Option<&glib::Bytes>,
82         cancellable: Option<&P>,
83         callback: Q,
84     ) {
85         let user_data: Box_<Q> = Box_::new(callback);
86         unsafe extern "C" fn communicate_async_trampoline<
87             Q: FnOnce(Result<(Option<glib::Bytes>, Option<glib::Bytes>), glib::Error>)
88                 + Send
89                 + 'static,
90         >(
91             _source_object: *mut glib::gobject_ffi::GObject,
92             res: *mut crate::ffi::GAsyncResult,
93             user_data: glib::ffi::gpointer,
94         ) {
95             let mut error = ptr::null_mut();
96             let mut stdout_buf = ptr::null_mut();
97             let mut stderr_buf = ptr::null_mut();
98             let _ = ffi::g_subprocess_communicate_finish(
99                 _source_object as *mut _,
100                 res,
101                 &mut stdout_buf,
102                 &mut stderr_buf,
103                 &mut error,
104             );
105             let result = if error.is_null() {
106                 Ok((from_glib_full(stdout_buf), from_glib_full(stderr_buf)))
107             } else {
108                 Err(from_glib_full(error))
109             };
110             let callback: Box_<Q> = Box_::from_raw(user_data as *mut _);
111             callback(result);
112         }
113         let callback = communicate_async_trampoline::<Q>;
114         unsafe {
115             ffi::g_subprocess_communicate_async(
116                 self.to_glib_none().0,
117                 stdin_buf.to_glib_none().0,
118                 cancellable.map(|p| p.as_ref()).to_glib_none().0,
119                 Some(callback),
120                 Box_::into_raw(user_data) as *mut _,
121             );
122         }
123     }
124 
communicate_async_future( &self, stdin_buf: Option<&glib::Bytes>, ) -> Pin< Box_< dyn std::future::Future< Output = Result<(Option<glib::Bytes>, Option<glib::Bytes>), glib::Error>, > + 'static, >, >125     pub fn communicate_async_future(
126         &self,
127         stdin_buf: Option<&glib::Bytes>,
128     ) -> Pin<
129         Box_<
130             dyn std::future::Future<
131                     Output = Result<(Option<glib::Bytes>, Option<glib::Bytes>), glib::Error>,
132                 > + 'static,
133         >,
134     > {
135         let stdin_buf = stdin_buf.map(ToOwned::to_owned);
136         Box_::pin(crate::GioFuture::new(
137             self,
138             move |obj, cancellable, send| {
139                 obj.communicate_async(
140                     stdin_buf.as_ref().map(::std::borrow::Borrow::borrow),
141                     Some(cancellable),
142                     move |res| {
143                         send.resolve(res);
144                     },
145                 );
146             },
147         ))
148     }
149 
150     #[doc(alias = "g_subprocess_communicate_utf8")]
communicate_utf8<P: IsA<Cancellable>>( &self, stdin_buf: Option<&str>, cancellable: Option<&P>, ) -> Result<(Option<glib::GString>, Option<glib::GString>), glib::Error>151     pub fn communicate_utf8<P: IsA<Cancellable>>(
152         &self,
153         stdin_buf: Option<&str>,
154         cancellable: Option<&P>,
155     ) -> Result<(Option<glib::GString>, Option<glib::GString>), glib::Error> {
156         unsafe {
157             let mut stdout_buf = ptr::null_mut();
158             let mut stderr_buf = ptr::null_mut();
159             let mut error = ptr::null_mut();
160             let _ = ffi::g_subprocess_communicate_utf8(
161                 self.to_glib_none().0,
162                 stdin_buf.to_glib_none().0,
163                 cancellable.map(|p| p.as_ref()).to_glib_none().0,
164                 &mut stdout_buf,
165                 &mut stderr_buf,
166                 &mut error,
167             );
168             if error.is_null() {
169                 Ok((from_glib_full(stdout_buf), from_glib_full(stderr_buf)))
170             } else {
171                 Err(from_glib_full(error))
172             }
173         }
174     }
175 
176     #[doc(alias = "g_subprocess_force_exit")]
force_exit(&self)177     pub fn force_exit(&self) {
178         unsafe {
179             ffi::g_subprocess_force_exit(self.to_glib_none().0);
180         }
181     }
182 
183     #[doc(alias = "g_subprocess_get_exit_status")]
184     #[doc(alias = "get_exit_status")]
exit_status(&self) -> i32185     pub fn exit_status(&self) -> i32 {
186         unsafe { ffi::g_subprocess_get_exit_status(self.to_glib_none().0) }
187     }
188 
189     #[doc(alias = "g_subprocess_get_identifier")]
190     #[doc(alias = "get_identifier")]
identifier(&self) -> Option<glib::GString>191     pub fn identifier(&self) -> Option<glib::GString> {
192         unsafe { from_glib_none(ffi::g_subprocess_get_identifier(self.to_glib_none().0)) }
193     }
194 
195     #[doc(alias = "g_subprocess_get_if_exited")]
196     #[doc(alias = "get_if_exited")]
has_exited(&self) -> bool197     pub fn has_exited(&self) -> bool {
198         unsafe { from_glib(ffi::g_subprocess_get_if_exited(self.to_glib_none().0)) }
199     }
200 
201     #[doc(alias = "g_subprocess_get_if_signaled")]
202     #[doc(alias = "get_if_signaled")]
has_signaled(&self) -> bool203     pub fn has_signaled(&self) -> bool {
204         unsafe { from_glib(ffi::g_subprocess_get_if_signaled(self.to_glib_none().0)) }
205     }
206 
207     #[doc(alias = "g_subprocess_get_status")]
208     #[doc(alias = "get_status")]
status(&self) -> i32209     pub fn status(&self) -> i32 {
210         unsafe { ffi::g_subprocess_get_status(self.to_glib_none().0) }
211     }
212 
213     #[doc(alias = "g_subprocess_get_stderr_pipe")]
214     #[doc(alias = "get_stderr_pipe")]
stderr_pipe(&self) -> Option<InputStream>215     pub fn stderr_pipe(&self) -> Option<InputStream> {
216         unsafe { from_glib_none(ffi::g_subprocess_get_stderr_pipe(self.to_glib_none().0)) }
217     }
218 
219     #[doc(alias = "g_subprocess_get_stdin_pipe")]
220     #[doc(alias = "get_stdin_pipe")]
stdin_pipe(&self) -> Option<OutputStream>221     pub fn stdin_pipe(&self) -> Option<OutputStream> {
222         unsafe { from_glib_none(ffi::g_subprocess_get_stdin_pipe(self.to_glib_none().0)) }
223     }
224 
225     #[doc(alias = "g_subprocess_get_stdout_pipe")]
226     #[doc(alias = "get_stdout_pipe")]
stdout_pipe(&self) -> Option<InputStream>227     pub fn stdout_pipe(&self) -> Option<InputStream> {
228         unsafe { from_glib_none(ffi::g_subprocess_get_stdout_pipe(self.to_glib_none().0)) }
229     }
230 
231     #[doc(alias = "g_subprocess_get_successful")]
232     #[doc(alias = "get_successful")]
is_successful(&self) -> bool233     pub fn is_successful(&self) -> bool {
234         unsafe { from_glib(ffi::g_subprocess_get_successful(self.to_glib_none().0)) }
235     }
236 
237     #[doc(alias = "g_subprocess_get_term_sig")]
238     #[doc(alias = "get_term_sig")]
term_sig(&self) -> i32239     pub fn term_sig(&self) -> i32 {
240         unsafe { ffi::g_subprocess_get_term_sig(self.to_glib_none().0) }
241     }
242 
243     #[cfg(any(not(windows), feature = "dox"))]
244     #[cfg_attr(feature = "dox", doc(cfg(not(windows))))]
245     #[doc(alias = "g_subprocess_send_signal")]
send_signal(&self, signal_num: i32)246     pub fn send_signal(&self, signal_num: i32) {
247         unsafe {
248             ffi::g_subprocess_send_signal(self.to_glib_none().0, signal_num);
249         }
250     }
251 
252     #[doc(alias = "g_subprocess_wait")]
wait<P: IsA<Cancellable>>(&self, cancellable: Option<&P>) -> Result<(), glib::Error>253     pub fn wait<P: IsA<Cancellable>>(&self, cancellable: Option<&P>) -> Result<(), glib::Error> {
254         unsafe {
255             let mut error = ptr::null_mut();
256             let _ = ffi::g_subprocess_wait(
257                 self.to_glib_none().0,
258                 cancellable.map(|p| p.as_ref()).to_glib_none().0,
259                 &mut error,
260             );
261             if error.is_null() {
262                 Ok(())
263             } else {
264                 Err(from_glib_full(error))
265             }
266         }
267     }
268 
269     #[doc(alias = "g_subprocess_wait_async")]
wait_async<P: IsA<Cancellable>, Q: FnOnce(Result<(), glib::Error>) + Send + 'static>( &self, cancellable: Option<&P>, callback: Q, )270     pub fn wait_async<P: IsA<Cancellable>, Q: FnOnce(Result<(), glib::Error>) + Send + 'static>(
271         &self,
272         cancellable: Option<&P>,
273         callback: Q,
274     ) {
275         let user_data: Box_<Q> = Box_::new(callback);
276         unsafe extern "C" fn wait_async_trampoline<
277             Q: FnOnce(Result<(), glib::Error>) + Send + 'static,
278         >(
279             _source_object: *mut glib::gobject_ffi::GObject,
280             res: *mut crate::ffi::GAsyncResult,
281             user_data: glib::ffi::gpointer,
282         ) {
283             let mut error = ptr::null_mut();
284             let _ = ffi::g_subprocess_wait_finish(_source_object as *mut _, res, &mut error);
285             let result = if error.is_null() {
286                 Ok(())
287             } else {
288                 Err(from_glib_full(error))
289             };
290             let callback: Box_<Q> = Box_::from_raw(user_data as *mut _);
291             callback(result);
292         }
293         let callback = wait_async_trampoline::<Q>;
294         unsafe {
295             ffi::g_subprocess_wait_async(
296                 self.to_glib_none().0,
297                 cancellable.map(|p| p.as_ref()).to_glib_none().0,
298                 Some(callback),
299                 Box_::into_raw(user_data) as *mut _,
300             );
301         }
302     }
303 
wait_async_future( &self, ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>>304     pub fn wait_async_future(
305         &self,
306     ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
307         Box_::pin(crate::GioFuture::new(
308             self,
309             move |obj, cancellable, send| {
310                 obj.wait_async(Some(cancellable), move |res| {
311                     send.resolve(res);
312                 });
313             },
314         ))
315     }
316 
317     #[doc(alias = "g_subprocess_wait_check")]
wait_check<P: IsA<Cancellable>>( &self, cancellable: Option<&P>, ) -> Result<(), glib::Error>318     pub fn wait_check<P: IsA<Cancellable>>(
319         &self,
320         cancellable: Option<&P>,
321     ) -> Result<(), glib::Error> {
322         unsafe {
323             let mut error = ptr::null_mut();
324             let _ = ffi::g_subprocess_wait_check(
325                 self.to_glib_none().0,
326                 cancellable.map(|p| p.as_ref()).to_glib_none().0,
327                 &mut error,
328             );
329             if error.is_null() {
330                 Ok(())
331             } else {
332                 Err(from_glib_full(error))
333             }
334         }
335     }
336 
337     #[doc(alias = "g_subprocess_wait_check_async")]
wait_check_async< P: IsA<Cancellable>, Q: FnOnce(Result<(), glib::Error>) + Send + 'static, >( &self, cancellable: Option<&P>, callback: Q, )338     pub fn wait_check_async<
339         P: IsA<Cancellable>,
340         Q: FnOnce(Result<(), glib::Error>) + Send + 'static,
341     >(
342         &self,
343         cancellable: Option<&P>,
344         callback: Q,
345     ) {
346         let user_data: Box_<Q> = Box_::new(callback);
347         unsafe extern "C" fn wait_check_async_trampoline<
348             Q: FnOnce(Result<(), glib::Error>) + Send + 'static,
349         >(
350             _source_object: *mut glib::gobject_ffi::GObject,
351             res: *mut crate::ffi::GAsyncResult,
352             user_data: glib::ffi::gpointer,
353         ) {
354             let mut error = ptr::null_mut();
355             let _ = ffi::g_subprocess_wait_check_finish(_source_object as *mut _, res, &mut error);
356             let result = if error.is_null() {
357                 Ok(())
358             } else {
359                 Err(from_glib_full(error))
360             };
361             let callback: Box_<Q> = Box_::from_raw(user_data as *mut _);
362             callback(result);
363         }
364         let callback = wait_check_async_trampoline::<Q>;
365         unsafe {
366             ffi::g_subprocess_wait_check_async(
367                 self.to_glib_none().0,
368                 cancellable.map(|p| p.as_ref()).to_glib_none().0,
369                 Some(callback),
370                 Box_::into_raw(user_data) as *mut _,
371             );
372         }
373     }
374 
wait_check_async_future( &self, ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>>375     pub fn wait_check_async_future(
376         &self,
377     ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
378         Box_::pin(crate::GioFuture::new(
379             self,
380             move |obj, cancellable, send| {
381                 obj.wait_check_async(Some(cancellable), move |res| {
382                     send.resolve(res);
383                 });
384             },
385         ))
386     }
387 }
388 
389 impl fmt::Display for Subprocess {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result390     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
391         f.write_str("Subprocess")
392     }
393 }
394