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