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