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