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