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