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 public  import gtkc.glibtypes;
31 
32 
33 /** */
34 public struct Child
35 {
36 
37 	/**
38 	 * Sets a function to be called when the child indicated by @pid
39 	 * exits, at a default priority, #G_PRIORITY_DEFAULT.
40 	 *
41 	 * If you obtain @pid from g_spawn_async() or g_spawn_async_with_pipes()
42 	 * you will need to pass #G_SPAWN_DO_NOT_REAP_CHILD as flag to
43 	 * the spawn function for the child watching to work.
44 	 *
45 	 * Note that on platforms where #GPid must be explicitly closed
46 	 * (see g_spawn_close_pid()) @pid must not be closed while the
47 	 * source is still active. Typically, you will want to call
48 	 * g_spawn_close_pid() in the callback function for the source.
49 	 *
50 	 * GLib supports only a single callback per process id.
51 	 * On POSIX platforms, the same restrictions mentioned for
52 	 * g_child_watch_source_new() apply to this function.
53 	 *
54 	 * This internally creates a main loop source using
55 	 * g_child_watch_source_new() and attaches it to the main loop context
56 	 * using g_source_attach(). You can do these steps manually if you
57 	 * need greater control.
58 	 *
59 	 * Params:
60 	 *     pid = process id to watch. On POSIX the positive pid of a child
61 	 *         process. On Windows a handle for a process (which doesn't have to be
62 	 *         a child).
63 	 *     function_ = function to call
64 	 *     data = data to pass to @function
65 	 *
66 	 * Returns: the ID (greater than 0) of the event source.
67 	 *
68 	 * Since: 2.4
69 	 */
70 	public static uint childWatchAdd(GPid pid, GChildWatchFunc function_, void* data)
71 	{
72 		return g_child_watch_add(pid, function_, data);
73 	}
74 
75 	/**
76 	 * Sets a function to be called when the child indicated by @pid
77 	 * exits, at the priority @priority.
78 	 *
79 	 * If you obtain @pid from g_spawn_async() or g_spawn_async_with_pipes()
80 	 * you will need to pass #G_SPAWN_DO_NOT_REAP_CHILD as flag to
81 	 * the spawn function for the child watching to work.
82 	 *
83 	 * In many programs, you will want to call g_spawn_check_exit_status()
84 	 * in the callback to determine whether or not the child exited
85 	 * successfully.
86 	 *
87 	 * Also, note that on platforms where #GPid must be explicitly closed
88 	 * (see g_spawn_close_pid()) @pid must not be closed while the source
89 	 * is still active.  Typically, you should invoke g_spawn_close_pid()
90 	 * in the callback function for the source.
91 	 *
92 	 * GLib supports only a single callback per process id.
93 	 * On POSIX platforms, the same restrictions mentioned for
94 	 * g_child_watch_source_new() apply to this function.
95 	 *
96 	 * This internally creates a main loop source using
97 	 * g_child_watch_source_new() and attaches it to the main loop context
98 	 * using g_source_attach(). You can do these steps manually if you
99 	 * need greater control.
100 	 *
101 	 * Params:
102 	 *     priority = the priority of the idle source. Typically this will be in the
103 	 *         range between #G_PRIORITY_DEFAULT_IDLE and #G_PRIORITY_HIGH_IDLE.
104 	 *     pid = process to watch. On POSIX the positive pid of a child process. On
105 	 *         Windows a handle for a process (which doesn't have to be a child).
106 	 *     function_ = function to call
107 	 *     data = data to pass to @function
108 	 *     notify = function to call when the idle is removed, or %NULL
109 	 *
110 	 * Returns: the ID (greater than 0) of the event source.
111 	 *
112 	 * Since: 2.4
113 	 */
114 	public static uint childWatchAddFull(int priority, GPid pid, GChildWatchFunc function_, void* data, GDestroyNotify notify)
115 	{
116 		return g_child_watch_add_full(priority, pid, function_, data, notify);
117 	}
118 
119 	/**
120 	 * Creates a new child_watch source.
121 	 *
122 	 * The source will not initially be associated with any #GMainContext
123 	 * and must be added to one with g_source_attach() before it will be
124 	 * executed.
125 	 *
126 	 * Note that child watch sources can only be used in conjunction with
127 	 * `g_spawn...` when the %G_SPAWN_DO_NOT_REAP_CHILD flag is used.
128 	 *
129 	 * Note that on platforms where #GPid must be explicitly closed
130 	 * (see g_spawn_close_pid()) @pid must not be closed while the
131 	 * source is still active. Typically, you will want to call
132 	 * g_spawn_close_pid() in the callback function for the source.
133 	 *
134 	 * On POSIX platforms, the following restrictions apply to this API
135 	 * due to limitations in POSIX process interfaces:
136 	 *
137 	 * * @pid must be a child of this process
138 	 * * @pid must be positive
139 	 * * the application must not call `waitpid` with a non-positive
140 	 * first argument, for instance in another thread
141 	 * * the application must not wait for @pid to exit by any other
142 	 * mechanism, including `waitpid(pid, ...)` or a second child-watch
143 	 * source for the same @pid
144 	 * * the application must not ignore SIGCHILD
145 	 *
146 	 * If any of those conditions are not met, this and related APIs will
147 	 * not work correctly. This can often be diagnosed via a GLib warning
148 	 * stating that `ECHILD` was received by `waitpid`.
149 	 *
150 	 * Calling `waitpid` for specific processes other than @pid remains a
151 	 * valid thing to do.
152 	 *
153 	 * Params:
154 	 *     pid = process to watch. On POSIX the positive pid of a child process. On
155 	 *         Windows a handle for a process (which doesn't have to be a child).
156 	 *
157 	 * Returns: the newly-created child watch source
158 	 *
159 	 * Since: 2.4
160 	 */
161 	public static Source childWatchSourceNew(GPid pid)
162 	{
163 		auto p = g_child_watch_source_new(pid);
164 
165 		if(p is null)
166 		{
167 			return null;
168 		}
169 
170 		return new Source(cast(GSource*) p, true);
171 	}
172 }