Skip to main content

gio/auto/
subprocess_launcher.rs

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
5use crate::{Subprocess, SubprocessFlags, ffi};
6use glib::translate::*;
7#[cfg(unix)]
8#[cfg_attr(docsrs, doc(cfg(unix)))]
9use std::boxed::Box as Box_;
10
11glib::wrapper! {
12    #[doc(alias = "GSubprocessLauncher")]
13    pub struct SubprocessLauncher(Object<ffi::GSubprocessLauncher>);
14
15    match fn {
16        type_ => || ffi::g_subprocess_launcher_get_type(),
17    }
18}
19
20impl SubprocessLauncher {
21    #[doc(alias = "g_subprocess_launcher_new")]
22    pub fn new(flags: SubprocessFlags) -> SubprocessLauncher {
23        unsafe { from_glib_full(ffi::g_subprocess_launcher_new(flags.into_glib())) }
24    }
25
26    #[cfg(unix)]
27    #[cfg_attr(docsrs, doc(cfg(unix)))]
28    #[cfg(feature = "v2_68")]
29    #[cfg_attr(docsrs, doc(cfg(feature = "v2_68")))]
30    #[doc(alias = "g_subprocess_launcher_close")]
31    pub fn close(&self) {
32        unsafe {
33            ffi::g_subprocess_launcher_close(self.to_glib_none().0);
34        }
35    }
36
37    #[doc(alias = "g_subprocess_launcher_getenv")]
38    pub fn getenv(&self, variable: impl AsRef<std::path::Path>) -> Option<std::path::PathBuf> {
39        unsafe {
40            from_glib_none(ffi::g_subprocess_launcher_getenv(
41                self.to_glib_none().0,
42                variable.as_ref().to_glib_none().0,
43            ))
44        }
45    }
46
47    #[cfg(unix)]
48    #[cfg_attr(docsrs, doc(cfg(unix)))]
49    #[doc(alias = "g_subprocess_launcher_set_child_setup")]
50    pub fn set_child_setup<P: Fn() + 'static>(&self, child_setup: P) {
51        let child_setup_data: Box_<P> = Box_::new(child_setup);
52        unsafe extern "C" fn child_setup_func<P: Fn() + 'static>(data: glib::ffi::gpointer) {
53            unsafe {
54                let callback = &*(data as *mut P);
55                (*callback)()
56            }
57        }
58        let child_setup = Some(child_setup_func::<P> as _);
59        unsafe extern "C" fn destroy_notify_func<P: Fn() + 'static>(data: glib::ffi::gpointer) {
60            unsafe {
61                let _callback = Box_::from_raw(data as *mut P);
62            }
63        }
64        let destroy_call3 = Some(destroy_notify_func::<P> as _);
65        let super_callback0: Box_<P> = child_setup_data;
66        unsafe {
67            ffi::g_subprocess_launcher_set_child_setup(
68                self.to_glib_none().0,
69                child_setup,
70                Box_::into_raw(super_callback0) as *mut _,
71                destroy_call3,
72            );
73        }
74    }
75
76    #[doc(alias = "g_subprocess_launcher_set_cwd")]
77    pub fn set_cwd(&self, cwd: impl AsRef<std::path::Path>) {
78        unsafe {
79            ffi::g_subprocess_launcher_set_cwd(
80                self.to_glib_none().0,
81                cwd.as_ref().to_glib_none().0,
82            );
83        }
84    }
85
86    #[doc(alias = "g_subprocess_launcher_set_flags")]
87    pub fn set_flags(&self, flags: SubprocessFlags) {
88        unsafe {
89            ffi::g_subprocess_launcher_set_flags(self.to_glib_none().0, flags.into_glib());
90        }
91    }
92
93    #[cfg(unix)]
94    #[cfg_attr(docsrs, doc(cfg(unix)))]
95    #[doc(alias = "g_subprocess_launcher_set_stderr_file_path")]
96    pub fn set_stderr_file_path(&self, path: Option<impl AsRef<std::path::Path>>) {
97        unsafe {
98            ffi::g_subprocess_launcher_set_stderr_file_path(
99                self.to_glib_none().0,
100                path.as_ref().map(|p| p.as_ref()).to_glib_none().0,
101            );
102        }
103    }
104
105    #[cfg(unix)]
106    #[cfg_attr(docsrs, doc(cfg(unix)))]
107    #[doc(alias = "g_subprocess_launcher_set_stdin_file_path")]
108    pub fn set_stdin_file_path(&self, path: Option<impl AsRef<std::path::Path>>) {
109        unsafe {
110            ffi::g_subprocess_launcher_set_stdin_file_path(
111                self.to_glib_none().0,
112                path.as_ref().map(|p| p.as_ref()).to_glib_none().0,
113            );
114        }
115    }
116
117    #[cfg(unix)]
118    #[cfg_attr(docsrs, doc(cfg(unix)))]
119    #[doc(alias = "g_subprocess_launcher_set_stdout_file_path")]
120    pub fn set_stdout_file_path(&self, path: Option<impl AsRef<std::path::Path>>) {
121        unsafe {
122            ffi::g_subprocess_launcher_set_stdout_file_path(
123                self.to_glib_none().0,
124                path.as_ref().map(|p| p.as_ref()).to_glib_none().0,
125            );
126        }
127    }
128
129    #[doc(alias = "g_subprocess_launcher_setenv")]
130    pub fn setenv(
131        &self,
132        variable: impl AsRef<std::ffi::OsStr>,
133        value: impl AsRef<std::ffi::OsStr>,
134        overwrite: bool,
135    ) {
136        unsafe {
137            ffi::g_subprocess_launcher_setenv(
138                self.to_glib_none().0,
139                variable.as_ref().to_glib_none().0,
140                value.as_ref().to_glib_none().0,
141                overwrite.into_glib(),
142            );
143        }
144    }
145
146    //#[doc(alias = "g_subprocess_launcher_spawn")]
147    //pub fn spawn(&self, error: &mut glib::Error, argv0: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> Subprocess {
148    //    unsafe { TODO: call ffi:g_subprocess_launcher_spawn() }
149    //}
150
151    #[doc(alias = "g_subprocess_launcher_spawnv")]
152    #[doc(alias = "spawnv")]
153    pub fn spawn(&self, argv: &[&std::ffi::OsStr]) -> Result<Subprocess, glib::Error> {
154        unsafe {
155            let mut error = std::ptr::null_mut();
156            let ret = ffi::g_subprocess_launcher_spawnv(
157                self.to_glib_none().0,
158                argv.to_glib_none().0,
159                &mut error,
160            );
161            if error.is_null() {
162                Ok(from_glib_full(ret))
163            } else {
164                Err(from_glib_full(error))
165            }
166        }
167    }
168
169    #[doc(alias = "g_subprocess_launcher_unsetenv")]
170    pub fn unsetenv(&self, variable: impl AsRef<std::ffi::OsStr>) {
171        unsafe {
172            ffi::g_subprocess_launcher_unsetenv(
173                self.to_glib_none().0,
174                variable.as_ref().to_glib_none().0,
175            );
176        }
177    }
178}