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