1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module glib.Child;
26 
27 private import glib.Source;
28 private import glib.c.functions;
29 public  import glib.c.types;
30 
31 
32 /** */
33 public struct Child
34 {
35 
36 	/**
37 	 * Sets a function to be called when the child indicated by @pid
38 	 * exits, at a default priority, #G_PRIORITY_DEFAULT.
39 	 *
40 	 * If you obtain @pid from g_spawn_async() or g_spawn_async_with_pipes()
41 	 * you will need to pass #G_SPAWN_DO_NOT_REAP_CHILD as flag to
42 	 * the spawn function for the child watching to work.
43 	 *
44 	 * Note that on platforms where #GPid must be explicitly closed
45 	 * (see g_spawn_close_pid()) @pid must not be closed while the
46 	 * source is still active. Typically, you will want to call
47 	 * g_spawn_close_pid() in the callback function for the source.
48 	 *
49 	 * GLib supports only a single callback per process id.
50 	 * On POSIX platforms, the same restrictions mentioned for
51 	 * g_child_watch_source_new() apply to this function.
52 	 *
53 	 * This internally creates a main loop source using
54 	 * g_child_watch_source_new() and attaches it to the main loop context
55 	 * using g_source_attach(). You can do these steps manually if you
56 	 * need greater control.
57 	 *
58 	 * Params:
59 	 *     pid = process id to watch. On POSIX the positive pid of a child
60 	 *         process. On Windows a handle for a process (which doesn't have to be
61 	 *         a child).
62 	 *     function_ = function to call
63 	 *     data = data to pass to @function
64 	 *
65 	 * Returns: the ID (greater than 0) of the event source.
66 	 *
67 	 * Since: 2.4
68 	 */
69 	public static uint childWatchAdd(GPid pid, GChildWatchFunc function_, void* data)
70 	{
71 		return g_child_watch_add(pid, function_, data);
72 	}
73 
74 	/**
75 	 * Sets a function to be called when the child indicated by @pid
76 	 * exits, at the priority @priority.
77 	 *
78 	 * If you obtain @pid from g_spawn_async() or g_spawn_async_with_pipes()
79 	 * you will need to pass #G_SPAWN_DO_NOT_REAP_CHILD as flag to
80 	 * the spawn function for the child watching to work.
81 	 *
82 	 * In many programs, you will want to call g_spawn_check_exit_status()
83 	 * in the callback to determine whether or not the child exited
84 	 * successfully.
85 	 *
86 	 * Also, note that on platforms where #GPid must be explicitly closed
87 	 * (see g_spawn_close_pid()) @pid must not be closed while the source
88 	 * is still active.  Typically, you should invoke g_spawn_close_pid()
89 	 * in the callback function for the source.
90 	 *
91 	 * GLib supports only a single callback per process id.
92 	 * On POSIX platforms, the same restrictions mentioned for
93 	 * g_child_watch_source_new() apply to this function.
94 	 *
95 	 * This internally creates a main loop source using
96 	 * g_child_watch_source_new() and attaches it to the main loop context
97 	 * using g_source_attach(). You can do these steps manually if you
98 	 * need greater control.
99 	 *
100 	 * Params:
101 	 *     priority = the priority of the idle source. Typically this will be in the
102 	 *         range between #G_PRIORITY_DEFAULT_IDLE and #G_PRIORITY_HIGH_IDLE.
103 	 *     pid = process to watch. On POSIX the positive pid of a child process. On
104 	 *         Windows a handle for a process (which doesn't have to be a child).
105 	 *     function_ = function to call
106 	 *     data = data to pass to @function
107 	 *     notify = function to call when the idle is removed, or %NULL
108 	 *
109 	 * Returns: the ID (greater than 0) of the event source.
110 	 *
111 	 * Since: 2.4
112 	 */
113 	public static uint childWatchAddFull(int priority, GPid pid, GChildWatchFunc function_, void* data, GDestroyNotify notify)
114 	{
115 		return g_child_watch_add_full(priority, pid, function_, data, notify);
116 	}
117 
118 	/**
119 	 * Creates a new child_watch source.
120 	 *
121 	 * The source will not initially be associated with any #GMainContext
122 	 * and must be added to one with g_source_attach() before it will be
123 	 * executed.
124 	 *
125 	 * Note that child watch sources can only be used in conjunction with
126 	 * `g_spawn...` when the %G_SPAWN_DO_NOT_REAP_CHILD flag is used.
127 	 *
128 	 * Note that on platforms where #GPid must be explicitly closed
129 	 * (see g_spawn_close_pid()) @pid must not be closed while the
130 	 * source is still active. Typically, you will want to call
131 	 * g_spawn_close_pid() in the callback function for the source.
132 	 *
133 	 * On POSIX platforms, the following restrictions apply to this API
134 	 * due to limitations in POSIX process interfaces:
135 	 *
136 	 * * @pid must be a child of this process
137 	 * * @pid must be positive
138 	 * * the application must not call `waitpid` with a non-positive
139 	 * first argument, for instance in another thread
140 	 * * the application must not wait for @pid to exit by any other
141 	 * mechanism, including `waitpid(pid, ...)` or a second child-watch
142 	 * source for the same @pid
143 	 * * the application must not ignore `SIGCHLD`
144 	 *
145 	 * If any of those conditions are not met, this and related APIs will
146 	 * not work correctly. This can often be diagnosed via a GLib warning
147 	 * stating that `ECHILD` was received by `waitpid`.
148 	 *
149 	 * Calling `waitpid` for specific processes other than @pid remains a
150 	 * valid thing to do.
151 	 *
152 	 * Params:
153 	 *     pid = process to watch. On POSIX the positive pid of a child process. On
154 	 *         Windows a handle for a process (which doesn't have to be a child).
155 	 *
156 	 * Returns: the newly-created child watch source
157 	 *
158 	 * Since: 2.4
159 	 */
160 	public static Source childWatchSourceNew(GPid pid)
161 	{
162 		auto __p = g_child_watch_source_new(pid);
163 
164 		if(__p is null)
165 		{
166 			return null;
167 		}
168 
169 		return new Source(cast(GSource*) __p, true);
170 	}
171 }