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