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.UnixUtils; 26 27 private import glib.ErrorG; 28 private import glib.GException; 29 private import glib.Source; 30 private import glib.c.functions; 31 public import glib.c.types; 32 33 34 /** */ 35 public struct UnixUtils 36 { 37 38 /** */ 39 public static GQuark errorQuark() 40 { 41 return g_unix_error_quark(); 42 } 43 44 /** 45 * Sets a function to be called when the IO condition, as specified by 46 * @condition becomes true for @fd. 47 * 48 * @function will be called when the specified IO condition becomes 49 * %TRUE. The function is expected to clear whatever event caused the 50 * IO condition to become true and return %TRUE in order to be notified 51 * when it happens again. If @function returns %FALSE then the watch 52 * will be cancelled. 53 * 54 * The return value of this function can be passed to g_source_remove() 55 * to cancel the watch at any time that it exists. 56 * 57 * The source will never close the fd -- you must do it yourself. 58 * 59 * Params: 60 * fd = a file descriptor 61 * condition = IO conditions to watch for on @fd 62 * function_ = a #GUnixFDSourceFunc 63 * userData = data to pass to @function 64 * 65 * Returns: the ID (greater than 0) of the event source 66 * 67 * Since: 2.36 68 */ 69 public static uint fdAdd(int fd, GIOCondition condition, GUnixFDSourceFunc function_, void* userData) 70 { 71 return g_unix_fd_add(fd, condition, function_, userData); 72 } 73 74 /** 75 * Sets a function to be called when the IO condition, as specified by 76 * @condition becomes true for @fd. 77 * 78 * This is the same as g_unix_fd_add(), except that it allows you to 79 * specify a non-default priority and a provide a #GDestroyNotify for 80 * @user_data. 81 * 82 * Params: 83 * priority = the priority of the source 84 * fd = a file descriptor 85 * condition = IO conditions to watch for on @fd 86 * function_ = a #GUnixFDSourceFunc 87 * userData = data to pass to @function 88 * notify = function to call when the idle is removed, or %NULL 89 * 90 * Returns: the ID (greater than 0) of the event source 91 * 92 * Since: 2.36 93 */ 94 public static uint fdAddFull(int priority, int fd, GIOCondition condition, GUnixFDSourceFunc function_, void* userData, GDestroyNotify notify) 95 { 96 return g_unix_fd_add_full(priority, fd, condition, function_, userData, notify); 97 } 98 99 /** 100 * Creates a #GSource to watch for a particular IO condition on a file 101 * descriptor. 102 * 103 * The source will never close the fd -- you must do it yourself. 104 * 105 * Params: 106 * fd = a file descriptor 107 * condition = IO conditions to watch for on @fd 108 * 109 * Returns: the newly created #GSource 110 * 111 * Since: 2.36 112 */ 113 public static Source fdSourceNew(int fd, GIOCondition condition) 114 { 115 auto __p = g_unix_fd_source_new(fd, condition); 116 117 if(__p is null) 118 { 119 return null; 120 } 121 122 return new Source(cast(GSource*) __p, true); 123 } 124 125 /** 126 * Similar to the UNIX pipe() call, but on modern systems like Linux 127 * uses the pipe2() system call, which atomically creates a pipe with 128 * the configured flags. The only supported flag currently is 129 * %FD_CLOEXEC. If for example you want to configure %O_NONBLOCK, that 130 * must still be done separately with fcntl(). 131 * 132 * This function does not take %O_CLOEXEC, it takes %FD_CLOEXEC as if 133 * for fcntl(); these are different on Linux/glibc. 134 * 135 * Params: 136 * fds = Array of two integers 137 * flags = Bitfield of file descriptor flags, as for fcntl() 138 * 139 * Returns: %TRUE on success, %FALSE if not (and errno will be set). 140 * 141 * Since: 2.30 142 * 143 * Throws: GException on failure. 144 */ 145 public static bool openPipe(int* fds, int flags) 146 { 147 GError* err = null; 148 149 auto __p = g_unix_open_pipe(fds, flags, &err) != 0; 150 151 if (err !is null) 152 { 153 throw new GException( new ErrorG(err) ); 154 } 155 156 return __p; 157 } 158 159 /** 160 * Control the non-blocking state of the given file descriptor, 161 * according to @nonblock. On most systems this uses %O_NONBLOCK, but 162 * on some older ones may use %O_NDELAY. 163 * 164 * Params: 165 * fd = A file descriptor 166 * nonblock = If %TRUE, set the descriptor to be non-blocking 167 * 168 * Returns: %TRUE if successful 169 * 170 * Since: 2.30 171 * 172 * Throws: GException on failure. 173 */ 174 public static bool setFdNonblocking(int fd, bool nonblock) 175 { 176 GError* err = null; 177 178 auto __p = g_unix_set_fd_nonblocking(fd, nonblock, &err) != 0; 179 180 if (err !is null) 181 { 182 throw new GException( new ErrorG(err) ); 183 } 184 185 return __p; 186 } 187 188 /** 189 * A convenience function for g_unix_signal_source_new(), which 190 * attaches to the default #GMainContext. You can remove the watch 191 * using g_source_remove(). 192 * 193 * Params: 194 * signum = Signal number 195 * handler = Callback 196 * userData = Data for @handler 197 * 198 * Returns: An ID (greater than 0) for the event source 199 * 200 * Since: 2.30 201 */ 202 public static uint signalAdd(int signum, GSourceFunc handler, void* userData) 203 { 204 return g_unix_signal_add(signum, handler, userData); 205 } 206 207 /** 208 * A convenience function for g_unix_signal_source_new(), which 209 * attaches to the default #GMainContext. You can remove the watch 210 * using g_source_remove(). 211 * 212 * Params: 213 * priority = the priority of the signal source. Typically this will be in 214 * the range between #G_PRIORITY_DEFAULT and #G_PRIORITY_HIGH. 215 * signum = Signal number 216 * handler = Callback 217 * userData = Data for @handler 218 * notify = #GDestroyNotify for @handler 219 * 220 * Returns: An ID (greater than 0) for the event source 221 * 222 * Since: 2.30 223 */ 224 public static uint signalAddFull(int priority, int signum, GSourceFunc handler, void* userData, GDestroyNotify notify) 225 { 226 return g_unix_signal_add_full(priority, signum, handler, userData, notify); 227 } 228 229 /** 230 * Create a #GSource that will be dispatched upon delivery of the UNIX 231 * signal @signum. In GLib versions before 2.36, only `SIGHUP`, `SIGINT`, 232 * `SIGTERM` can be monitored. In GLib 2.36, `SIGUSR1` and `SIGUSR2` 233 * were added. In GLib 2.54, `SIGWINCH` was added. 234 * 235 * Note that unlike the UNIX default, all sources which have created a 236 * watch will be dispatched, regardless of which underlying thread 237 * invoked g_unix_signal_source_new(). 238 * 239 * For example, an effective use of this function is to handle `SIGTERM` 240 * cleanly; flushing any outstanding files, and then calling 241 * g_main_loop_quit (). It is not safe to do any of this a regular 242 * UNIX signal handler; your handler may be invoked while malloc() or 243 * another library function is running, causing reentrancy if you 244 * attempt to use it from the handler. None of the GLib/GObject API 245 * is safe against this kind of reentrancy. 246 * 247 * The interaction of this source when combined with native UNIX 248 * functions like sigprocmask() is not defined. 249 * 250 * The source will not initially be associated with any #GMainContext 251 * and must be added to one with g_source_attach() before it will be 252 * executed. 253 * 254 * Params: 255 * signum = A signal number 256 * 257 * Returns: A newly created #GSource 258 * 259 * Since: 2.30 260 */ 261 public static Source signalSourceNew(int signum) 262 { 263 auto __p = g_unix_signal_source_new(signum); 264 265 if(__p is null) 266 { 267 return null; 268 } 269 270 return new Source(cast(GSource*) __p, true); 271 } 272 }