1// Package gio was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gio
3
4import (
5 "unsafe"
6
7 "github.com/ebitengine/purego"
8
9 "github.com/bnema/puregotk/pkg/core"
10 "github.com/bnema/puregotk/v4/glib"
11 "github.com/bnema/puregotk/v4/gobject"
12 "github.com/bnema/puregotk/v4/gobject/types"
13)
14
15// This class contains a set of options for launching child processes,
16// such as where its standard input and output will be directed, the
17// argument list, the environment, and more.
18//
19// While the [class@Gio.Subprocess] class has high level functions covering
20// popular cases, use of this class allows access to more advanced
21// options. It can also be used to launch multiple subprocesses with
22// a similar configuration.
23type SubprocessLauncher struct {
24 gobject.Object
25}
26
27var xSubprocessLauncherGLibType func() types.GType
28
29func SubprocessLauncherGLibType() types.GType {
30 return xSubprocessLauncherGLibType()
31}
32
33func SubprocessLauncherNewFromInternalPtr(ptr uintptr) *SubprocessLauncher {
34 cls := &SubprocessLauncher{}
35 cls.Ptr = ptr
36 return cls
37}
38
39var xNewSubprocessLauncher func(SubprocessFlags) uintptr
40
41// Creates a new #GSubprocessLauncher.
42//
43// The launcher is created with the default options. A copy of the
44// environment of the calling process is made at the time of this call
45// and will be used as the environment that the process is launched in.
46func NewSubprocessLauncher(FlagsVar SubprocessFlags) *SubprocessLauncher {
47 var cls *SubprocessLauncher
48
49 cret := xNewSubprocessLauncher(FlagsVar)
50
51 if cret == 0 {
52 return nil
53 }
54 cls = &SubprocessLauncher{}
55 cls.Ptr = cret
56 return cls
57}
58
59var xSubprocessLauncherClose func(uintptr)
60
61// Closes all the file descriptors previously passed to the object with
62// g_subprocess_launcher_take_fd(), g_subprocess_launcher_take_stderr_fd(), etc.
63//
64// After calling this method, any subsequent calls to g_subprocess_launcher_spawn() or g_subprocess_launcher_spawnv() will
65// return %G_IO_ERROR_CLOSED. This method is idempotent if
66// called more than once.
67//
68// This function is called automatically when the #GSubprocessLauncher
69// is disposed, but is provided separately so that garbage collected
70// language bindings can call it earlier to guarantee when FDs are closed.
71func (x *SubprocessLauncher) Close() {
72
73 xSubprocessLauncherClose(x.GoPointer())
74
75}
76
77var xSubprocessLauncherGetenv func(uintptr, string) string
78
79// Returns the value of the environment variable @variable in the
80// environment of processes launched from this launcher.
81//
82// On UNIX, the returned string can be an arbitrary byte string.
83// On Windows, it will be UTF-8.
84func (x *SubprocessLauncher) Getenv(VariableVar string) string {
85
86 cret := xSubprocessLauncherGetenv(x.GoPointer(), VariableVar)
87 return cret
88}
89
90var xSubprocessLauncherSetChildSetup func(uintptr, uintptr, uintptr, uintptr)
91
92// Sets up a child setup function.
93//
94// The child setup function will be called after fork() but before
95// exec() on the child's side.
96//
97// @destroy_notify will not be automatically called on the child's side
98// of the fork(). It will only be called when the last reference on the
99// #GSubprocessLauncher is dropped or when a new child setup function is
100// given.
101//
102// %NULL can be given as @child_setup to disable the functionality.
103//
104// Child setup functions are only available on UNIX.
105func (x *SubprocessLauncher) SetChildSetup(ChildSetupVar *glib.SpawnChildSetupFunc, UserDataVar uintptr, DestroyNotifyVar *glib.DestroyNotify) {
106
107 var ChildSetupVarRef uintptr
108 if ChildSetupVar != nil {
109 ChildSetupVarPtr := uintptr(unsafe.Pointer(ChildSetupVar))
110 if cbRefPtr, ok := glib.GetCallback(ChildSetupVarPtr); ok {
111 ChildSetupVarRef = cbRefPtr
112 } else {
113 fcb := func(arg0 uintptr) {
114 cbFn := *ChildSetupVar
115 cbFn(arg0)
116 }
117 ChildSetupVarRef = purego.NewCallback(fcb)
118 glib.SaveCallbackWithClosure(ChildSetupVarPtr, ChildSetupVarRef, ChildSetupVar)
119 }
120 }
121
122 var DestroyNotifyVarRef uintptr
123 if DestroyNotifyVar != nil {
124 DestroyNotifyVarPtr := uintptr(unsafe.Pointer(DestroyNotifyVar))
125 if cbRefPtr, ok := glib.GetCallback(DestroyNotifyVarPtr); ok {
126 DestroyNotifyVarRef = cbRefPtr
127 } else {
128 fcb := func(arg0 uintptr) {
129 cbFn := *DestroyNotifyVar
130 cbFn(arg0)
131 }
132 DestroyNotifyVarRef = purego.NewCallback(fcb)
133 glib.SaveCallbackWithClosure(DestroyNotifyVarPtr, DestroyNotifyVarRef, DestroyNotifyVar)
134 }
135 }
136
137 xSubprocessLauncherSetChildSetup(x.GoPointer(), ChildSetupVarRef, UserDataVar, DestroyNotifyVarRef)
138
139}
140
141var xSubprocessLauncherSetCwd func(uintptr, string)
142
143// Sets the current working directory that processes will be launched
144// with.
145//
146// By default processes are launched with the current working directory
147// of the launching process at the time of launch.
148func (x *SubprocessLauncher) SetCwd(CwdVar string) {
149
150 xSubprocessLauncherSetCwd(x.GoPointer(), CwdVar)
151
152}
153
154var xSubprocessLauncherSetEnviron func(uintptr, []string)
155
156// Replace the entire environment of processes launched from this
157// launcher with the given 'environ' variable.
158//
159// Typically you will build this variable by using g_listenv() to copy
160// the process 'environ' and using the functions g_environ_setenv(),
161// g_environ_unsetenv(), etc.
162//
163// As an alternative, you can use g_subprocess_launcher_setenv(),
164// g_subprocess_launcher_unsetenv(), etc.
165//
166// Pass an empty array to set an empty environment. Pass %NULL to inherit the
167// parent process’ environment. As of GLib 2.54, the parent process’ environment
168// will be copied when g_subprocess_launcher_set_environ() is called.
169// Previously, it was copied when the subprocess was executed. This means the
170// copied environment may now be modified (using g_subprocess_launcher_setenv(),
171// etc.) before launching the subprocess.
172//
173// On UNIX, all strings in this array can be arbitrary byte strings.
174// On Windows, they should be in UTF-8.
175func (x *SubprocessLauncher) SetEnviron(EnvVar []string) {
176
177 xSubprocessLauncherSetEnviron(x.GoPointer(), EnvVar)
178
179}
180
181var xSubprocessLauncherSetFlags func(uintptr, SubprocessFlags)
182
183// Sets the flags on the launcher.
184//
185// The default flags are %G_SUBPROCESS_FLAGS_NONE.
186//
187// You may not set flags that specify conflicting options for how to
188// handle a particular stdio stream (eg: specifying both
189// %G_SUBPROCESS_FLAGS_STDIN_PIPE and
190// %G_SUBPROCESS_FLAGS_STDIN_INHERIT).
191//
192// You may also not set a flag that conflicts with a previous call to a
193// function like g_subprocess_launcher_set_stdin_file_path() or
194// g_subprocess_launcher_take_stdout_fd().
195func (x *SubprocessLauncher) SetFlags(FlagsVar SubprocessFlags) {
196
197 xSubprocessLauncherSetFlags(x.GoPointer(), FlagsVar)
198
199}
200
201var xSubprocessLauncherSetStderrFilePath func(uintptr, uintptr)
202
203// Sets the file path to use as the stderr for spawned processes.
204//
205// If @path is %NULL then any previously given path is unset.
206//
207// The file will be created or truncated when the process is spawned, as
208// would be the case if using '2>' at the shell.
209//
210// If you want to send both stdout and stderr to the same file then use
211// %G_SUBPROCESS_FLAGS_STDERR_MERGE.
212//
213// You may not set a stderr file path if a stderr fd is already set or
214// if the launcher flags contain any flags directing stderr elsewhere.
215//
216// This feature is only available on UNIX.
217func (x *SubprocessLauncher) SetStderrFilePath(PathVar *string) {
218
219 PathVarPtr := core.GStrdupNullable(PathVar)
220 defer core.GFreeNullable(PathVarPtr)
221
222 xSubprocessLauncherSetStderrFilePath(x.GoPointer(), PathVarPtr)
223
224}
225
226var xSubprocessLauncherSetStdinFilePath func(uintptr, uintptr)
227
228// Sets the file path to use as the stdin for spawned processes.
229//
230// If @path is %NULL then any previously given path is unset.
231//
232// The file must exist or spawning the process will fail.
233//
234// You may not set a stdin file path if a stdin fd is already set or if
235// the launcher flags contain any flags directing stdin elsewhere.
236//
237// This feature is only available on UNIX.
238func (x *SubprocessLauncher) SetStdinFilePath(PathVar *string) {
239
240 PathVarPtr := core.GStrdupNullable(PathVar)
241 defer core.GFreeNullable(PathVarPtr)
242
243 xSubprocessLauncherSetStdinFilePath(x.GoPointer(), PathVarPtr)
244
245}
246
247var xSubprocessLauncherSetStdoutFilePath func(uintptr, uintptr)
248
249// Sets the file path to use as the stdout for spawned processes.
250//
251// If @path is %NULL then any previously given path is unset.
252//
253// The file will be created or truncated when the process is spawned, as
254// would be the case if using '>' at the shell.
255//
256// You may not set a stdout file path if a stdout fd is already set or
257// if the launcher flags contain any flags directing stdout elsewhere.
258//
259// This feature is only available on UNIX.
260func (x *SubprocessLauncher) SetStdoutFilePath(PathVar *string) {
261
262 PathVarPtr := core.GStrdupNullable(PathVar)
263 defer core.GFreeNullable(PathVarPtr)
264
265 xSubprocessLauncherSetStdoutFilePath(x.GoPointer(), PathVarPtr)
266
267}
268
269var xSubprocessLauncherSetenv func(uintptr, string, string, bool)
270
271// Sets the environment variable @variable in the environment of
272// processes launched from this launcher.
273//
274// On UNIX, both the variable's name and value can be arbitrary byte
275// strings, except that the variable's name cannot contain '='.
276// On Windows, they should be in UTF-8.
277func (x *SubprocessLauncher) Setenv(VariableVar string, ValueVar string, OverwriteVar bool) {
278
279 xSubprocessLauncherSetenv(x.GoPointer(), VariableVar, ValueVar, OverwriteVar)
280
281}
282
283var xSubprocessLauncherSpawn func(uintptr, **glib.Error, string, ...interface{}) uintptr
284
285// Creates a #GSubprocess given a provided varargs list of arguments.
286func (x *SubprocessLauncher) Spawn(ErrorVar **glib.Error, Argv0Var string, varArgs ...interface{}) *Subprocess {
287 var cls *Subprocess
288
289 cret := xSubprocessLauncherSpawn(x.GoPointer(), ErrorVar, Argv0Var, varArgs...)
290
291 if cret == 0 {
292 return nil
293 }
294 cls = &Subprocess{}
295 cls.Ptr = cret
296 return cls
297}
298
299var xSubprocessLauncherSpawnv func(uintptr, []string, **glib.Error) uintptr
300
301// Creates a #GSubprocess given a provided array of arguments.
302func (x *SubprocessLauncher) Spawnv(ArgvVar []string) (*Subprocess, error) {
303 var cls *Subprocess
304 var cerr *glib.Error
305
306 cret := xSubprocessLauncherSpawnv(x.GoPointer(), ArgvVar, &cerr)
307
308 if cret == 0 {
309 return nil, cerr
310 }
311 cls = &Subprocess{}
312 cls.Ptr = cret
313 if cerr == nil {
314 return cls, nil
315 }
316 return cls, cerr
317
318}
319
320var xSubprocessLauncherTakeFd func(uintptr, int, int)
321
322// Transfer an arbitrary file descriptor from parent process to the
323// child. This function takes ownership of the @source_fd; it will be closed
324// in the parent when @self is freed.
325//
326// By default, all file descriptors from the parent will be closed.
327// This function allows you to create (for example) a custom `pipe()` or
328// `socketpair()` before launching the process, and choose the target
329// descriptor in the child.
330//
331// An example use case is GNUPG, which has a command line argument
332// `--passphrase-fd` providing a file descriptor number where it expects
333// the passphrase to be written.
334func (x *SubprocessLauncher) TakeFd(SourceFdVar int, TargetFdVar int) {
335
336 xSubprocessLauncherTakeFd(x.GoPointer(), SourceFdVar, TargetFdVar)
337
338}
339
340var xSubprocessLauncherTakeStderrFd func(uintptr, int)
341
342// Sets the file descriptor to use as the stderr for spawned processes.
343//
344// If @fd is -1 then any previously given fd is unset.
345//
346// Note that the default behaviour is to pass stderr through to the
347// stderr of the parent process.
348//
349// The passed @fd belongs to the #GSubprocessLauncher. It will be
350// automatically closed when the launcher is finalized. The file
351// descriptor will also be closed on the child side when executing the
352// spawned process.
353//
354// You may not set a stderr fd if a stderr file path is already set or
355// if the launcher flags contain any flags directing stderr elsewhere.
356//
357// This feature is only available on UNIX.
358func (x *SubprocessLauncher) TakeStderrFd(FdVar int) {
359
360 xSubprocessLauncherTakeStderrFd(x.GoPointer(), FdVar)
361
362}
363
364var xSubprocessLauncherTakeStdinFd func(uintptr, int)
365
366// Sets the file descriptor to use as the stdin for spawned processes.
367//
368// If @fd is -1 then any previously given fd is unset.
369//
370// Note that if your intention is to have the stdin of the calling
371// process inherited by the child then %G_SUBPROCESS_FLAGS_STDIN_INHERIT
372// is a better way to go about doing that.
373//
374// The passed @fd is noted but will not be touched in the current
375// process. It is therefore necessary that it be kept open by the
376// caller until the subprocess is spawned. The file descriptor will
377// also not be explicitly closed on the child side, so it must be marked
378// O_CLOEXEC if that's what you want.
379//
380// You may not set a stdin fd if a stdin file path is already set or if
381// the launcher flags contain any flags directing stdin elsewhere.
382//
383// This feature is only available on UNIX.
384func (x *SubprocessLauncher) TakeStdinFd(FdVar int) {
385
386 xSubprocessLauncherTakeStdinFd(x.GoPointer(), FdVar)
387
388}
389
390var xSubprocessLauncherTakeStdoutFd func(uintptr, int)
391
392// Sets the file descriptor to use as the stdout for spawned processes.
393//
394// If @fd is -1 then any previously given fd is unset.
395//
396// Note that the default behaviour is to pass stdout through to the
397// stdout of the parent process.
398//
399// The passed @fd is noted but will not be touched in the current
400// process. It is therefore necessary that it be kept open by the
401// caller until the subprocess is spawned. The file descriptor will
402// also not be explicitly closed on the child side, so it must be marked
403// O_CLOEXEC if that's what you want.
404//
405// You may not set a stdout fd if a stdout file path is already set or
406// if the launcher flags contain any flags directing stdout elsewhere.
407//
408// This feature is only available on UNIX.
409func (x *SubprocessLauncher) TakeStdoutFd(FdVar int) {
410
411 xSubprocessLauncherTakeStdoutFd(x.GoPointer(), FdVar)
412
413}
414
415var xSubprocessLauncherUnsetenv func(uintptr, string)
416
417// Removes the environment variable @variable from the environment of
418// processes launched from this launcher.
419//
420// On UNIX, the variable's name can be an arbitrary byte string not
421// containing '='. On Windows, it should be in UTF-8.
422func (x *SubprocessLauncher) Unsetenv(VariableVar string) {
423
424 xSubprocessLauncherUnsetenv(x.GoPointer(), VariableVar)
425
426}
427
428func (c *SubprocessLauncher) GoPointer() uintptr {
429 if c == nil {
430 return 0
431 }
432 return c.Ptr
433}
434
435func (c *SubprocessLauncher) SetGoPointer(ptr uintptr) {
436 c.Ptr = ptr
437}
438
439func init() {
440 core.SetPackageName("GIO", "gio-2.0")
441 core.SetSharedLibraries("GIO", []string{"libgio-2.0.so.0"})
442 var libs []uintptr
443 for _, libPath := range core.GetPaths("GIO") {
444 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
445 if err != nil {
446 panic(err)
447 }
448 libs = append(libs, lib)
449 }
450
451 core.PuregoSafeRegister(&xSubprocessLauncherGLibType, libs, "g_subprocess_launcher_get_type")
452
453 core.PuregoSafeRegister(&xNewSubprocessLauncher, libs, "g_subprocess_launcher_new")
454
455 core.PuregoSafeRegister(&xSubprocessLauncherClose, libs, "g_subprocess_launcher_close")
456 core.PuregoSafeRegister(&xSubprocessLauncherGetenv, libs, "g_subprocess_launcher_getenv")
457 core.PuregoSafeRegister(&xSubprocessLauncherSetChildSetup, libs, "g_subprocess_launcher_set_child_setup")
458 core.PuregoSafeRegister(&xSubprocessLauncherSetCwd, libs, "g_subprocess_launcher_set_cwd")
459 core.PuregoSafeRegister(&xSubprocessLauncherSetEnviron, libs, "g_subprocess_launcher_set_environ")
460 core.PuregoSafeRegister(&xSubprocessLauncherSetFlags, libs, "g_subprocess_launcher_set_flags")
461 core.PuregoSafeRegister(&xSubprocessLauncherSetStderrFilePath, libs, "g_subprocess_launcher_set_stderr_file_path")
462 core.PuregoSafeRegister(&xSubprocessLauncherSetStdinFilePath, libs, "g_subprocess_launcher_set_stdin_file_path")
463 core.PuregoSafeRegister(&xSubprocessLauncherSetStdoutFilePath, libs, "g_subprocess_launcher_set_stdout_file_path")
464 core.PuregoSafeRegister(&xSubprocessLauncherSetenv, libs, "g_subprocess_launcher_setenv")
465 core.PuregoSafeRegister(&xSubprocessLauncherSpawn, libs, "g_subprocess_launcher_spawn")
466 core.PuregoSafeRegister(&xSubprocessLauncherSpawnv, libs, "g_subprocess_launcher_spawnv")
467 core.PuregoSafeRegister(&xSubprocessLauncherTakeFd, libs, "g_subprocess_launcher_take_fd")
468 core.PuregoSafeRegister(&xSubprocessLauncherTakeStderrFd, libs, "g_subprocess_launcher_take_stderr_fd")
469 core.PuregoSafeRegister(&xSubprocessLauncherTakeStdinFd, libs, "g_subprocess_launcher_take_stdin_fd")
470 core.PuregoSafeRegister(&xSubprocessLauncherTakeStdoutFd, libs, "g_subprocess_launcher_take_stdout_fd")
471 core.PuregoSafeRegister(&xSubprocessLauncherUnsetenv, libs, "g_subprocess_launcher_unsetenv")
472
473}