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::{ffi, Subprocess, SubprocessFlags};
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            let callback = &*(data as *mut P);
54            (*callback)()
55        }
56        let child_setup = Some(child_setup_func::<P> as _);
57        unsafe extern "C" fn destroy_notify_func<P: Fn() + 'static>(data: glib::ffi::gpointer) {
58            let _callback = Box_::from_raw(data as *mut P);
59        }
60        let destroy_call3 = Some(destroy_notify_func::<P> as _);
61        let super_callback0: Box_<P> = child_setup_data;
62        unsafe {
63            ffi::g_subprocess_launcher_set_child_setup(
64                self.to_glib_none().0,
65                child_setup,
66                Box_::into_raw(super_callback0) as *mut _,
67                destroy_call3,
68            );
69        }
70    }
71
72    #[doc(alias = "g_subprocess_launcher_set_cwd")]
73    pub fn set_cwd(&self, cwd: impl AsRef<std::path::Path>) {
74        unsafe {
75            ffi::g_subprocess_launcher_set_cwd(
76                self.to_glib_none().0,
77                cwd.as_ref().to_glib_none().0,
78            );
79        }
80    }
81
82    #[doc(alias = "g_subprocess_launcher_set_flags")]
83    pub fn set_flags(&self, flags: SubprocessFlags) {
84        unsafe {
85            ffi::g_subprocess_launcher_set_flags(self.to_glib_none().0, flags.into_glib());
86        }
87    }
88
89    #[cfg(unix)]
90    #[cfg_attr(docsrs, doc(cfg(unix)))]
91    #[doc(alias = "g_subprocess_launcher_set_stderr_file_path")]
92    pub fn set_stderr_file_path(&self, path: Option<impl AsRef<std::path::Path>>) {
93        unsafe {
94            ffi::g_subprocess_launcher_set_stderr_file_path(
95                self.to_glib_none().0,
96                path.as_ref().map(|p| p.as_ref()).to_glib_none().0,
97            );
98        }
99    }
100
101    #[cfg(unix)]
102    #[cfg_attr(docsrs, doc(cfg(unix)))]
103    #[doc(alias = "g_subprocess_launcher_set_stdin_file_path")]
104    pub fn set_stdin_file_path(&self, path: Option<impl AsRef<std::path::Path>>) {
105        unsafe {
106            ffi::g_subprocess_launcher_set_stdin_file_path(
107                self.to_glib_none().0,
108                path.as_ref().map(|p| p.as_ref()).to_glib_none().0,
109            );
110        }
111    }
112
113    #[cfg(unix)]
114    #[cfg_attr(docsrs, doc(cfg(unix)))]
115    #[doc(alias = "g_subprocess_launcher_set_stdout_file_path")]
116    pub fn set_stdout_file_path(&self, path: Option<impl AsRef<std::path::Path>>) {
117        unsafe {
118            ffi::g_subprocess_launcher_set_stdout_file_path(
119                self.to_glib_none().0,
120                path.as_ref().map(|p| p.as_ref()).to_glib_none().0,
121            );
122        }
123    }
124
125    #[doc(alias = "g_subprocess_launcher_setenv")]
126    pub fn setenv(
127        &self,
128        variable: impl AsRef<std::ffi::OsStr>,
129        value: impl AsRef<std::ffi::OsStr>,
130        overwrite: bool,
131    ) {
132        unsafe {
133            ffi::g_subprocess_launcher_setenv(
134                self.to_glib_none().0,
135                variable.as_ref().to_glib_none().0,
136                value.as_ref().to_glib_none().0,
137                overwrite.into_glib(),
138            );
139        }
140    }
141
142    //#[doc(alias = "g_subprocess_launcher_spawn")]
143    //pub fn spawn(&self, error: &mut glib::Error, argv0: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> Subprocess {
144    //    unsafe { TODO: call ffi:g_subprocess_launcher_spawn() }
145    //}
146
147    #[doc(alias = "g_subprocess_launcher_spawnv")]
148    #[doc(alias = "spawnv")]
149    pub fn spawn(&self, argv: &[&std::ffi::OsStr]) -> Result<Subprocess, glib::Error> {
150        unsafe {
151            let mut error = std::ptr::null_mut();
152            let ret = ffi::g_subprocess_launcher_spawnv(
153                self.to_glib_none().0,
154                argv.to_glib_none().0,
155                &mut error,
156            );
157            if error.is_null() {
158                Ok(from_glib_full(ret))
159            } else {
160                Err(from_glib_full(error))
161            }
162        }
163    }
164
165    #[doc(alias = "g_subprocess_launcher_unsetenv")]
166    pub fn unsetenv(&self, variable: impl AsRef<std::ffi::OsStr>) {
167        unsafe {
168            ffi::g_subprocess_launcher_unsetenv(
169                self.to_glib_none().0,
170                variable.as_ref().to_glib_none().0,
171            );
172        }
173    }
174}