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