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