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