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  * Conversion parameters:
26  * inFile  = 
27  * outPack = glib
28  * outFile = Child
29  * strct   = 
30  * realStrct=
31  * ctorStrct=
32  * clss    = Child
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_child_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Source
47  * structWrap:
48  * 	- GSource* -> Source
49  * module aliases:
50  * local aliases:
51  * overrides:
52  */
53 
54 module glib.Child;
55 
56 public  import gtkc.glibtypes;
57 
58 private import gtkc.glib;
59 private import glib.ConstructionException;
60 
61 
62 private import glib.Source;
63 
64 
65 
66 
67 /**
68  * The main event loop manages all the available sources of events for
69  * GLib and GTK+ applications. These events can come from any number of
70  * different types of sources such as file descriptors (plain files,
71  * pipes or sockets) and timeouts. New types of event sources can also
72  * be added using g_source_attach().
73  *
74  * To allow multiple independent sets of sources to be handled in
75  * different threads, each source is associated with a GMainContext.
76  * A GMainContext can only be running in a single thread, but
77  * sources can be added to it and removed from it from other threads.
78  *
79  * Each event source is assigned a priority. The default priority,
80  * G_PRIORITY_DEFAULT, is 0. Values less than 0 denote higher priorities.
81  * Values greater than 0 denote lower priorities. Events from high priority
82  * sources are always processed before events from lower priority sources.
83  *
84  * Idle functions can also be added, and assigned a priority. These will
85  * be run whenever no events with a higher priority are ready to be processed.
86  *
87  * The GMainLoop data type represents a main event loop. A GMainLoop is
88  * created with g_main_loop_new(). After adding the initial event sources,
89  * g_main_loop_run() is called. This continuously checks for new events from
90  * each of the event sources and dispatches them. Finally, the processing of
91  * an event from one of the sources leads to a call to g_main_loop_quit() to
92  * exit the main loop, and g_main_loop_run() returns.
93  *
94  * It is possible to create new instances of GMainLoop recursively.
95  * This is often used in GTK+ applications when showing modal dialog
96  * boxes. Note that event sources are associated with a particular
97  * GMainContext, and will be checked and dispatched for all main
98  * loops associated with that GMainContext.
99  *
100  * GTK+ contains wrappers of some of these functions, e.g. gtk_main(),
101  * gtk_main_quit() and gtk_events_pending().
102  *
103  * Creating new source types
104  *
105  * One of the unusual features of the GMainLoop functionality
106  * is that new types of event source can be created and used in
107  * addition to the builtin type of event source. A new event source
108  * type is used for handling GDK events. A new source type is created
109  * by deriving from the GSource structure.
110  * The derived type of source is represented by a structure that has
111  * the GSource structure as a first element, and other elements specific
112  * to the new source type. To create an instance of the new source type,
113  * call g_source_new() passing in the size of the derived structure and
114  * a table of functions. These GSourceFuncs determine the behavior of
115  * the new source type.
116  *
117  * New source types basically interact with the main context
118  * in two ways. Their prepare function in GSourceFuncs can set a timeout
119  * to determine the maximum amount of time that the main loop will sleep
120  * before checking the source again. In addition, or as well, the source
121  * can add file descriptors to the set that the main context checks using
122  * g_source_add_poll().
123  *
124  * <hr>
125  *
126  * Customizing the main loop iteration
127  *
128  * Single iterations of a GMainContext can be run with
129  * g_main_context_iteration(). In some cases, more detailed control
130  * of exactly how the details of the main loop work is desired, for
131  * instance, when integrating the GMainLoop with an external main loop.
132  * In such cases, you can call the component functions of
133  * g_main_context_iteration() directly. These functions are
134  * g_main_context_prepare(), g_main_context_query(),
135  * g_main_context_check() and g_main_context_dispatch().
136  *
137  * The operation of these functions can best be seen in terms
138  * of a state diagram, as shown in Figure 1, “States of a Main Context”.
139  *
140  * Figure 1. States of a Main Context
141  *
142  * On Unix, the GLib mainloop is incompatible with fork(). Any program
143  * using the mainloop must either exec() or exit() from the child
144  * without returning to the mainloop.
145  */
146 public class Child
147 {
148 	
149 	/**
150 	 */
151 	
152 	/**
153 	 * Creates a new child_watch source.
154 	 * The source will not initially be associated with any GMainContext
155 	 * and must be added to one with g_source_attach() before it will be
156 	 * executed.
157 	 * Note that child watch sources can only be used in conjunction with
158 	 * g_spawn... when the G_SPAWN_DO_NOT_REAP_CHILD
159 	 * flag is used.
160 	 * Note that on platforms where GPid must be explicitly closed
161 	 * (see g_spawn_close_pid()) pid must not be closed while the
162 	 * source is still active. Typically, you will want to call
163 	 * g_spawn_close_pid() in the callback function for the source.
164 	 * Note further that using g_child_watch_source_new() is not
165 	 * compatible with calling waitpid with a
166 	 * nonpositive first argument in the application. Calling waitpid()
167 	 * for individual pids will still work fine.
168 	 * Since 2.4
169 	 * Params:
170 	 * pid = process to watch. On POSIX the pid of a child process. On
171 	 * Windows a handle for a process (which doesn't have to be a child).
172 	 * Returns: the newly-created child watch source
173 	 */
174 	public static Source watchSourceNew(GPid pid)
175 	{
176 		// GSource * g_child_watch_source_new (GPid pid);
177 		auto p = g_child_watch_source_new(pid);
178 		
179 		if(p is null)
180 		{
181 			return null;
182 		}
183 		
184 		return new Source(cast(GSource*) p);
185 	}
186 	
187 	/**
188 	 * Sets a function to be called when the child indicated by pid
189 	 * exits, at a default priority, G_PRIORITY_DEFAULT.
190 	 * If you obtain pid from g_spawn_async() or g_spawn_async_with_pipes()
191 	 * you will need to pass G_SPAWN_DO_NOT_REAP_CHILD as flag to
192 	 * the spawn function for the child watching to work.
193 	 * Note that on platforms where GPid must be explicitly closed
194 	 * (see g_spawn_close_pid()) pid must not be closed while the
195 	 * source is still active. Typically, you will want to call
196 	 * g_spawn_close_pid() in the callback function for the source.
197 	 * GLib supports only a single callback per process id.
198 	 * This internally creates a main loop source using
199 	 * g_child_watch_source_new() and attaches it to the main loop context
200 	 * using g_source_attach(). You can do these steps manually if you
201 	 * need greater control.
202 	 * Since 2.4
203 	 * Params:
204 	 * pid = process id to watch. On POSIX the pid of a child process. On
205 	 * Windows a handle for a process (which doesn't have to be a child).
206 	 * data = data to pass to function
207 	 * Returns: the ID (greater than 0) of the event source.
208 	 */
209 	public static uint watchAdd(GPid pid, GChildWatchFunc funct, void* data)
210 	{
211 		// guint g_child_watch_add (GPid pid,  GChildWatchFunc function,  gpointer data);
212 		return g_child_watch_add(pid, funct, data);
213 	}
214 	
215 	/**
216 	 * Sets a function to be called when the child indicated by pid
217 	 * exits, at the priority priority.
218 	 * If you obtain pid from g_spawn_async() or g_spawn_async_with_pipes()
219 	 * you will need to pass G_SPAWN_DO_NOT_REAP_CHILD as flag to
220 	 * the spawn function for the child watching to work.
221 	 * In many programs, you will want to call g_spawn_check_exit_status()
222 	 * in the callback to determine whether or not the child exited
223 	 * successfully.
224 	 * Also, note that on platforms where GPid must be explicitly closed
225 	 * (see g_spawn_close_pid()) pid must not be closed while the source
226 	 * is still active. Typically, you should invoke g_spawn_close_pid()
227 	 * in the callback function for the source.
228 	 * GLib supports only a single callback per process id.
229 	 * This internally creates a main loop source using
230 	 * g_child_watch_source_new() and attaches it to the main loop context
231 	 * using g_source_attach(). You can do these steps manually if you
232 	 * need greater control.
233 	 * Since 2.4
234 	 * Params:
235 	 * priority = the priority of the idle source. Typically this will be in the
236 	 * range between G_PRIORITY_DEFAULT_IDLE and G_PRIORITY_HIGH_IDLE.
237 	 * pid = process to watch. On POSIX the pid of a child process. On
238 	 * Windows a handle for a process (which doesn't have to be a child).
239 	 * data = data to pass to function
240 	 * notify = function to call when the idle is removed, or NULL. [allow-none]
241 	 * Returns: the ID (greater than 0) of the event source. Rename to: g_child_watch_add
242 	 */
243 	public static uint watchAddFull(int priority, GPid pid, GChildWatchFunc funct, void* data, GDestroyNotify notify)
244 	{
245 		// guint g_child_watch_add_full (gint priority,  GPid pid,  GChildWatchFunc function,  gpointer data,  GDestroyNotify notify);
246 		return g_child_watch_add_full(priority, pid, funct, data, notify);
247 	}
248 }