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.UnixFDMessage; 26 27 private import gio.SocketControlMessage; 28 private import gio.UnixFDList; 29 private import gio.c.functions; 30 public import gio.c.types; 31 private import glib.ConstructionException; 32 private import glib.ErrorG; 33 private import glib.GException; 34 private import gobject.ObjectG; 35 public import gtkc.giotypes; 36 37 38 /** 39 * This #GSocketControlMessage contains a #GUnixFDList. 40 * It may be sent using g_socket_send_message() and received using 41 * g_socket_receive_message() over UNIX sockets (ie: sockets in the 42 * %G_SOCKET_FAMILY_UNIX family). The file descriptors are copied 43 * between processes by the kernel. 44 * 45 * For an easier way to send and receive file descriptors over 46 * stream-oriented UNIX sockets, see g_unix_connection_send_fd() and 47 * g_unix_connection_receive_fd(). 48 * 49 * Note that `<gio/gunixfdmessage.h>` belongs to the UNIX-specific GIO 50 * interfaces, thus you have to use the `gio-unix-2.0.pc` pkg-config 51 * file when using it. 52 */ 53 public class UnixFDMessage : SocketControlMessage 54 { 55 /** the main Gtk struct */ 56 protected GUnixFDMessage* gUnixFDMessage; 57 58 /** Get the main Gtk struct */ 59 public GUnixFDMessage* getUnixFDMessageStruct(bool transferOwnership = false) 60 { 61 if (transferOwnership) 62 ownedRef = false; 63 return gUnixFDMessage; 64 } 65 66 /** the main Gtk struct as a void* */ 67 protected override void* getStruct() 68 { 69 return cast(void*)gUnixFDMessage; 70 } 71 72 /** 73 * Sets our main struct and passes it to the parent class. 74 */ 75 public this (GUnixFDMessage* gUnixFDMessage, bool ownedRef = false) 76 { 77 this.gUnixFDMessage = gUnixFDMessage; 78 super(cast(GSocketControlMessage*)gUnixFDMessage, ownedRef); 79 } 80 81 82 /** */ 83 public static GType getType() 84 { 85 return g_unix_fd_message_get_type(); 86 } 87 88 /** 89 * Creates a new #GUnixFDMessage containing an empty file descriptor 90 * list. 91 * 92 * Returns: a new #GUnixFDMessage 93 * 94 * Since: 2.22 95 * 96 * Throws: ConstructionException GTK+ fails to create the object. 97 */ 98 public this() 99 { 100 auto __p = g_unix_fd_message_new(); 101 102 if(__p is null) 103 { 104 throw new ConstructionException("null returned by new"); 105 } 106 107 this(cast(GUnixFDMessage*) __p, true); 108 } 109 110 /** 111 * Creates a new #GUnixFDMessage containing @list. 112 * 113 * Params: 114 * fdList = a #GUnixFDList 115 * 116 * Returns: a new #GUnixFDMessage 117 * 118 * Since: 2.24 119 * 120 * Throws: ConstructionException GTK+ fails to create the object. 121 */ 122 public this(UnixFDList fdList) 123 { 124 auto __p = g_unix_fd_message_new_with_fd_list((fdList is null) ? null : fdList.getUnixFDListStruct()); 125 126 if(__p is null) 127 { 128 throw new ConstructionException("null returned by new_with_fd_list"); 129 } 130 131 this(cast(GUnixFDMessage*) __p, true); 132 } 133 134 /** 135 * Adds a file descriptor to @message. 136 * 137 * The file descriptor is duplicated using dup(). You keep your copy 138 * of the descriptor and the copy contained in @message will be closed 139 * when @message is finalized. 140 * 141 * A possible cause of failure is exceeding the per-process or 142 * system-wide file descriptor limit. 143 * 144 * Params: 145 * fd = a valid open file descriptor 146 * 147 * Returns: %TRUE in case of success, else %FALSE (and @error is set) 148 * 149 * Since: 2.22 150 * 151 * Throws: GException on failure. 152 */ 153 public bool appendFd(int fd) 154 { 155 GError* err = null; 156 157 auto __p = g_unix_fd_message_append_fd(gUnixFDMessage, fd, &err) != 0; 158 159 if (err !is null) 160 { 161 throw new GException( new ErrorG(err) ); 162 } 163 164 return __p; 165 } 166 167 /** 168 * Gets the #GUnixFDList contained in @message. This function does not 169 * return a reference to the caller, but the returned list is valid for 170 * the lifetime of @message. 171 * 172 * Returns: the #GUnixFDList from @message 173 * 174 * Since: 2.24 175 */ 176 public UnixFDList getFdList() 177 { 178 auto __p = g_unix_fd_message_get_fd_list(gUnixFDMessage); 179 180 if(__p is null) 181 { 182 return null; 183 } 184 185 return ObjectG.getDObject!(UnixFDList)(cast(GUnixFDList*) __p); 186 } 187 188 /** 189 * Returns the array of file descriptors that is contained in this 190 * object. 191 * 192 * After this call, the descriptors are no longer contained in 193 * @message. Further calls will return an empty list (unless more 194 * descriptors have been added). 195 * 196 * The return result of this function must be freed with g_free(). 197 * The caller is also responsible for closing all of the file 198 * descriptors. 199 * 200 * If @length is non-%NULL then it is set to the number of file 201 * descriptors in the returned array. The returned array is also 202 * terminated with -1. 203 * 204 * This function never returns %NULL. In case there are no file 205 * descriptors contained in @message, an empty array is returned. 206 * 207 * Returns: an array of file 208 * descriptors 209 * 210 * Since: 2.22 211 */ 212 public int[] stealFds() 213 { 214 int length; 215 216 auto __p = g_unix_fd_message_steal_fds(gUnixFDMessage, &length); 217 218 return __p[0 .. length]; 219 } 220 }