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