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_ADDRESS_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 protected override void setStruct(GObject* obj) 68 { 69 gUnixFDList = cast(GUnixFDList*)obj; 70 super.setStruct(obj); 71 } 72 73 /** 74 * Sets our main struct and passes it to the parent class. 75 */ 76 public this (GUnixFDList* gUnixFDList, bool ownedRef = false) 77 { 78 this.gUnixFDList = gUnixFDList; 79 super(cast(GObject*)gUnixFDList, ownedRef); 80 } 81 82 83 /** */ 84 public static GType getType() 85 { 86 return g_unix_fd_list_get_type(); 87 } 88 89 /** 90 * Creates a new #GUnixFDList containing no file descriptors. 91 * 92 * Returns: a new #GUnixFDList 93 * 94 * Since: 2.24 95 * 96 * Throws: ConstructionException GTK+ fails to create the object. 97 */ 98 public this() 99 { 100 auto p = g_unix_fd_list_new(); 101 102 if(p is null) 103 { 104 throw new ConstructionException("null returned by new"); 105 } 106 107 this(cast(GUnixFDList*) p, true); 108 } 109 110 /** 111 * Creates a new #GUnixFDList containing the file descriptors given in 112 * @fds. The file descriptors become the property of the new list and 113 * may no longer be used by the caller. The array itself is owned by 114 * the caller. 115 * 116 * Each file descriptor in the array should be set to close-on-exec. 117 * 118 * If @n_fds is -1 then @fds must be terminated with -1. 119 * 120 * Params: 121 * fds = the initial list of file descriptors 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 }