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 gtkc.glib; 29 public import gtkc.glibtypes; 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 * 51 * This internally creates a main loop source using 52 * g_child_watch_source_new() and attaches it to the main loop context 53 * using g_source_attach(). You can do these steps manually if you 54 * need greater control. 55 * 56 * Params: 57 * pid = process id to watch. On POSIX the positive pid of a child 58 * process. On Windows a handle for a process (which doesn't have to be 59 * a child). 60 * funct = function to call 61 * data = data to pass to @function 62 * 63 * Returns: the ID (greater than 0) of the event source. 64 * 65 * Since: 2.4 66 */ 67 public static uint childWatchAdd(GPid pid, GChildWatchFunc funct, void* data) 68 { 69 return g_child_watch_add(pid, funct, data); 70 } 71 72 /** 73 * Sets a function to be called when the child indicated by @pid 74 * exits, at the priority @priority. 75 * 76 * If you obtain @pid from g_spawn_async() or g_spawn_async_with_pipes() 77 * you will need to pass #G_SPAWN_DO_NOT_REAP_CHILD as flag to 78 * the spawn function for the child watching to work. 79 * 80 * In many programs, you will want to call g_spawn_check_exit_status() 81 * in the callback to determine whether or not the child exited 82 * successfully. 83 * 84 * Also, note that on platforms where #GPid must be explicitly closed 85 * (see g_spawn_close_pid()) @pid must not be closed while the source 86 * is still active. Typically, you should invoke g_spawn_close_pid() 87 * in the callback function for the source. 88 * 89 * GLib supports only a single callback per process id. 90 * 91 * This internally creates a main loop source using 92 * g_child_watch_source_new() and attaches it to the main loop context 93 * using g_source_attach(). You can do these steps manually if you 94 * need greater control. 95 * 96 * Params: 97 * priority = the priority of the idle source. Typically this will be in the 98 * range between #G_PRIORITY_DEFAULT_IDLE and #G_PRIORITY_HIGH_IDLE. 99 * pid = process to watch. On POSIX the positive pid of a child process. On 100 * Windows a handle for a process (which doesn't have to be a child). 101 * funct = function to call 102 * data = data to pass to @function 103 * notify = function to call when the idle is removed, or %NULL 104 * 105 * Returns: the ID (greater than 0) of the event source. 106 * 107 * Since: 2.4 108 */ 109 public static uint childWatchAddFull(int priority, GPid pid, GChildWatchFunc funct, void* data, GDestroyNotify notify) 110 { 111 return g_child_watch_add_full(priority, pid, funct, data, notify); 112 } 113 114 /** 115 * Creates a new child_watch source. 116 * 117 * The source will not initially be associated with any #GMainContext 118 * and must be added to one with g_source_attach() before it will be 119 * executed. 120 * 121 * Note that child watch sources can only be used in conjunction with 122 * `g_spawn...` when the %G_SPAWN_DO_NOT_REAP_CHILD flag is used. 123 * 124 * Note that on platforms where #GPid must be explicitly closed 125 * (see g_spawn_close_pid()) @pid must not be closed while the 126 * source is still active. Typically, you will want to call 127 * g_spawn_close_pid() in the callback function for the source. 128 * 129 * Note further that using g_child_watch_source_new() is not 130 * compatible with calling `waitpid` with a nonpositive first 131 * argument in the application. Calling waitpid() for individual 132 * pids will still work fine. 133 * 134 * Similarly, on POSIX platforms, the @pid passed to this function must 135 * be greater than 0 (i.e. this function must wait for a specific child, 136 * and cannot wait for one of many children by using a nonpositive argument). 137 * 138 * Params: 139 * pid = process to watch. On POSIX the positive pid of a child process. On 140 * Windows a handle for a process (which doesn't have to be a child). 141 * 142 * Returns: the newly-created child watch source 143 * 144 * Since: 2.4 145 */ 146 public static Source childWatchSourceNew(GPid pid) 147 { 148 auto p = g_child_watch_source_new(pid); 149 150 if(p is null) 151 { 152 return null; 153 } 154 155 return new Source(cast(GSource*) p, true); 156 } 157 }