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 gio.UnixFDList;
26 
27 private import gio.c.functions;
28 public  import gio.c.types;
29 private import glib.ConstructionException;
30 private import glib.ErrorG;
31 private import glib.GException;
32 private import gobject.ObjectG;
33 
34 
35 /**
36  * A #GUnixFDList contains a list of file descriptors.  It owns the file
37  * descriptors that it contains, closing them when finalized.
38  * 
39  * It may be wrapped in a #GUnixFDMessage and sent over a #GSocket in
40  * the %G_SOCKET_FAMILY_UNIX family by using g_socket_send_message()
41  * and received using g_socket_receive_message().
42  * 
43  * Note that `<gio/gunixfdlist.h>` belongs to the UNIX-specific GIO
44  * interfaces, thus you have to use the `gio-unix-2.0.pc` pkg-config
45  * file when using it.
46  */
47 public class UnixFDList : ObjectG
48 {
49 	/** the main Gtk struct */
50 	protected GUnixFDList* gUnixFDList;
51 
52 	/** Get the main Gtk struct */
53 	public GUnixFDList* getUnixFDListStruct(bool transferOwnership = false)
54 	{
55 		if (transferOwnership)
56 			ownedRef = false;
57 		return gUnixFDList;
58 	}
59 
60 	/** the main Gtk struct as a void* */
61 	protected override void* getStruct()
62 	{
63 		return cast(void*)gUnixFDList;
64 	}
65 
66 	/**
67 	 * Sets our main struct and passes it to the parent class.
68 	 */
69 	public this (GUnixFDList* gUnixFDList, bool ownedRef = false)
70 	{
71 		this.gUnixFDList = gUnixFDList;
72 		super(cast(GObject*)gUnixFDList, ownedRef);
73 	}
74 
75 
76 	/** */
77 	public static GType getType()
78 	{
79 		return g_unix_fd_list_get_type();
80 	}
81 
82 	/**
83 	 * Creates a new #GUnixFDList containing no file descriptors.
84 	 *
85 	 * Returns: a new #GUnixFDList
86 	 *
87 	 * Since: 2.24
88 	 *
89 	 * Throws: ConstructionException GTK+ fails to create the object.
90 	 */
91 	public this()
92 	{
93 		auto __p = g_unix_fd_list_new();
94 
95 		if(__p is null)
96 		{
97 			throw new ConstructionException("null returned by new");
98 		}
99 
100 		this(cast(GUnixFDList*) __p, true);
101 	}
102 
103 	/**
104 	 * Creates a new #GUnixFDList containing the file descriptors given in
105 	 * @fds.  The file descriptors become the property of the new list and
106 	 * may no longer be used by the caller.  The array itself is owned by
107 	 * the caller.
108 	 *
109 	 * Each file descriptor in the array should be set to close-on-exec.
110 	 *
111 	 * If @n_fds is -1 then @fds must be terminated with -1.
112 	 *
113 	 * Params:
114 	 *     fds = the initial list of file descriptors
115 	 *
116 	 * Returns: a new #GUnixFDList
117 	 *
118 	 * Since: 2.24
119 	 *
120 	 * Throws: ConstructionException GTK+ fails to create the object.
121 	 */
122 	public this(int[] fds)
123 	{
124 		auto __p = g_unix_fd_list_new_from_array(fds.ptr, cast(int)fds.length);
125 
126 		if(__p is null)
127 		{
128 			throw new ConstructionException("null returned by new_from_array");
129 		}
130 
131 		this(cast(GUnixFDList*) __p, true);
132 	}
133 
134 	/**
135 	 * Adds a file descriptor to @list.
136 	 *
137 	 * The file descriptor is duplicated using dup(). You keep your copy
138 	 * of the descriptor and the copy contained in @list will be closed
139 	 * when @list is finalized.
140 	 *
141 	 * A possible cause of failure is exceeding the per-process or
142 	 * system-wide file descriptor limit.
143 	 *
144 	 * The index of the file descriptor in the list is returned.  If you use
145 	 * this index with g_unix_fd_list_get() then you will receive back a
146 	 * duplicated copy of the same file descriptor.
147 	 *
148 	 * Params:
149 	 *     fd = a valid open file descriptor
150 	 *
151 	 * Returns: the index of the appended fd in case of success, else -1
152 	 *     (and @error is set)
153 	 *
154 	 * Since: 2.24
155 	 *
156 	 * Throws: GException on failure.
157 	 */
158 	public int append(int fd)
159 	{
160 		GError* err = null;
161 
162 		auto __p = g_unix_fd_list_append(gUnixFDList, fd, &err);
163 
164 		if (err !is null)
165 		{
166 			throw new GException( new ErrorG(err) );
167 		}
168 
169 		return __p;
170 	}
171 
172 	/**
173 	 * Gets a file descriptor out of @list.
174 	 *
175 	 * @index_ specifies the index of the file descriptor to get.  It is a
176 	 * programmer error for @index_ to be out of range; see
177 	 * g_unix_fd_list_get_length().
178 	 *
179 	 * The file descriptor is duplicated using dup() and set as
180 	 * close-on-exec before being returned.  You must call close() on it
181 	 * when you are done.
182 	 *
183 	 * A possible cause of failure is exceeding the per-process or
184 	 * system-wide file descriptor limit.
185 	 *
186 	 * Params:
187 	 *     index = the index into the list
188 	 *
189 	 * Returns: the file descriptor, or -1 in case of error
190 	 *
191 	 * Since: 2.24
192 	 *
193 	 * Throws: GException on failure.
194 	 */
195 	public int get(int index)
196 	{
197 		GError* err = null;
198 
199 		auto __p = g_unix_fd_list_get(gUnixFDList, index, &err);
200 
201 		if (err !is null)
202 		{
203 			throw new GException( new ErrorG(err) );
204 		}
205 
206 		return __p;
207 	}
208 
209 	/**
210 	 * Gets the length of @list (ie: the number of file descriptors
211 	 * contained within).
212 	 *
213 	 * Returns: the length of @list
214 	 *
215 	 * Since: 2.24
216 	 */
217 	public int getLength()
218 	{
219 		return g_unix_fd_list_get_length(gUnixFDList);
220 	}
221 
222 	/**
223 	 * Returns the array of file descriptors that is contained in this
224 	 * object.
225 	 *
226 	 * After this call, the descriptors remain the property of @list.  The
227 	 * caller must not close them and must not free the array.  The array is
228 	 * valid only until @list is changed in any way.
229 	 *
230 	 * If @length is non-%NULL then it is set to the number of file
231 	 * descriptors in the returned array. The returned array is also
232 	 * terminated with -1.
233 	 *
234 	 * This function never returns %NULL. In case there are no file
235 	 * descriptors contained in @list, an empty array is returned.
236 	 *
237 	 * Returns: an array of file
238 	 *     descriptors
239 	 *
240 	 * Since: 2.24
241 	 */
242 	public int[] peekFds()
243 	{
244 		int length;
245 
246 		auto __p = g_unix_fd_list_peek_fds(gUnixFDList, &length);
247 
248 		return __p[0 .. length];
249 	}
250 
251 	/**
252 	 * Returns the array of file descriptors that is contained in this
253 	 * object.
254 	 *
255 	 * After this call, the descriptors are no longer contained in
256 	 * @list. Further calls will return an empty list (unless more
257 	 * descriptors have been added).
258 	 *
259 	 * The return result of this function must be freed with g_free().
260 	 * The caller is also responsible for closing all of the file
261 	 * descriptors.  The file descriptors in the array are set to
262 	 * close-on-exec.
263 	 *
264 	 * If @length is non-%NULL then it is set to the number of file
265 	 * descriptors in the returned array. The returned array is also
266 	 * terminated with -1.
267 	 *
268 	 * This function never returns %NULL. In case there are no file
269 	 * descriptors contained in @list, an empty array is returned.
270 	 *
271 	 * Returns: an array of file
272 	 *     descriptors
273 	 *
274 	 * Since: 2.24
275 	 */
276 	public int[] stealFds()
277 	{
278 		int length;
279 
280 		auto __p = g_unix_fd_list_steal_fds(gUnixFDList, &length);
281 
282 		return __p[0 .. length];
283 	}
284 }