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.UnixConnection; 26 27 private import gio.AsyncResultIF; 28 private import gio.Cancellable; 29 private import gio.Credentials; 30 private import gio.SocketConnection; 31 private import gio.c.functions; 32 public import gio.c.types; 33 private import glib.ErrorG; 34 private import glib.GException; 35 private import gobject.ObjectG; 36 public import gtkc.giotypes; 37 38 39 /** 40 * This is the subclass of #GSocketConnection that is created 41 * for UNIX domain sockets. 42 * 43 * It contains functions to do some of the UNIX socket specific 44 * functionality like passing file descriptors. 45 * 46 * Note that `<gio/gunixconnection.h>` belongs to the UNIX-specific 47 * GIO interfaces, thus you have to use the `gio-unix-2.0.pc` 48 * pkg-config file when using it. 49 * 50 * Since: 2.22 51 */ 52 public class UnixConnection : SocketConnection 53 { 54 /** the main Gtk struct */ 55 protected GUnixConnection* gUnixConnection; 56 57 /** Get the main Gtk struct */ 58 public GUnixConnection* getUnixConnectionStruct(bool transferOwnership = false) 59 { 60 if (transferOwnership) 61 ownedRef = false; 62 return gUnixConnection; 63 } 64 65 /** the main Gtk struct as a void* */ 66 protected override void* getStruct() 67 { 68 return cast(void*)gUnixConnection; 69 } 70 71 /** 72 * Sets our main struct and passes it to the parent class. 73 */ 74 public this (GUnixConnection* gUnixConnection, bool ownedRef = false) 75 { 76 this.gUnixConnection = gUnixConnection; 77 super(cast(GSocketConnection*)gUnixConnection, ownedRef); 78 } 79 80 81 /** */ 82 public static GType getType() 83 { 84 return g_unix_connection_get_type(); 85 } 86 87 /** 88 * Receives credentials from the sending end of the connection. The 89 * sending end has to call g_unix_connection_send_credentials() (or 90 * similar) for this to work. 91 * 92 * As well as reading the credentials this also reads (and discards) a 93 * single byte from the stream, as this is required for credentials 94 * passing to work on some implementations. 95 * 96 * Other ways to exchange credentials with a foreign peer includes the 97 * #GUnixCredentialsMessage type and g_socket_get_credentials() function. 98 * 99 * Params: 100 * cancellable = A #GCancellable or %NULL. 101 * 102 * Returns: Received credentials on success (free with 103 * g_object_unref()), %NULL if @error is set. 104 * 105 * Since: 2.26 106 * 107 * Throws: GException on failure. 108 */ 109 public Credentials receiveCredentials(Cancellable cancellable) 110 { 111 GError* err = null; 112 113 auto p = g_unix_connection_receive_credentials(gUnixConnection, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 114 115 if (err !is null) 116 { 117 throw new GException( new ErrorG(err) ); 118 } 119 120 if(p is null) 121 { 122 return null; 123 } 124 125 return ObjectG.getDObject!(Credentials)(cast(GCredentials*) p, true); 126 } 127 128 /** 129 * Asynchronously receive credentials. 130 * 131 * For more details, see g_unix_connection_receive_credentials() which is 132 * the synchronous version of this call. 133 * 134 * When the operation is finished, @callback will be called. You can then call 135 * g_unix_connection_receive_credentials_finish() to get the result of the operation. 136 * 137 * Params: 138 * cancellable = optional #GCancellable object, %NULL to ignore. 139 * callback = a #GAsyncReadyCallback to call when the request is satisfied 140 * userData = the data to pass to callback function 141 * 142 * Since: 2.32 143 */ 144 public void receiveCredentialsAsync(Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 145 { 146 g_unix_connection_receive_credentials_async(gUnixConnection, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 147 } 148 149 /** 150 * Finishes an asynchronous receive credentials operation started with 151 * g_unix_connection_receive_credentials_async(). 152 * 153 * Params: 154 * result = a #GAsyncResult. 155 * 156 * Returns: a #GCredentials, or %NULL on error. 157 * Free the returned object with g_object_unref(). 158 * 159 * Since: 2.32 160 * 161 * Throws: GException on failure. 162 */ 163 public Credentials receiveCredentialsFinish(AsyncResultIF result) 164 { 165 GError* err = null; 166 167 auto p = g_unix_connection_receive_credentials_finish(gUnixConnection, (result is null) ? null : result.getAsyncResultStruct(), &err); 168 169 if (err !is null) 170 { 171 throw new GException( new ErrorG(err) ); 172 } 173 174 if(p is null) 175 { 176 return null; 177 } 178 179 return ObjectG.getDObject!(Credentials)(cast(GCredentials*) p, true); 180 } 181 182 /** 183 * Receives a file descriptor from the sending end of the connection. 184 * The sending end has to call g_unix_connection_send_fd() for this 185 * to work. 186 * 187 * As well as reading the fd this also reads a single byte from the 188 * stream, as this is required for fd passing to work on some 189 * implementations. 190 * 191 * Params: 192 * cancellable = optional #GCancellable object, %NULL to ignore 193 * 194 * Returns: a file descriptor on success, -1 on error. 195 * 196 * Since: 2.22 197 * 198 * Throws: GException on failure. 199 */ 200 public int receiveFd(Cancellable cancellable) 201 { 202 GError* err = null; 203 204 auto p = g_unix_connection_receive_fd(gUnixConnection, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 205 206 if (err !is null) 207 { 208 throw new GException( new ErrorG(err) ); 209 } 210 211 return p; 212 } 213 214 /** 215 * Passes the credentials of the current user the receiving side 216 * of the connection. The receiving end has to call 217 * g_unix_connection_receive_credentials() (or similar) to accept the 218 * credentials. 219 * 220 * As well as sending the credentials this also writes a single NUL 221 * byte to the stream, as this is required for credentials passing to 222 * work on some implementations. 223 * 224 * Other ways to exchange credentials with a foreign peer includes the 225 * #GUnixCredentialsMessage type and g_socket_get_credentials() function. 226 * 227 * Params: 228 * cancellable = A #GCancellable or %NULL. 229 * 230 * Returns: %TRUE on success, %FALSE if @error is set. 231 * 232 * Since: 2.26 233 * 234 * Throws: GException on failure. 235 */ 236 public bool sendCredentials(Cancellable cancellable) 237 { 238 GError* err = null; 239 240 auto p = g_unix_connection_send_credentials(gUnixConnection, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 241 242 if (err !is null) 243 { 244 throw new GException( new ErrorG(err) ); 245 } 246 247 return p; 248 } 249 250 /** 251 * Asynchronously send credentials. 252 * 253 * For more details, see g_unix_connection_send_credentials() which is 254 * the synchronous version of this call. 255 * 256 * When the operation is finished, @callback will be called. You can then call 257 * g_unix_connection_send_credentials_finish() to get the result of the operation. 258 * 259 * Params: 260 * cancellable = optional #GCancellable object, %NULL to ignore. 261 * callback = a #GAsyncReadyCallback to call when the request is satisfied 262 * userData = the data to pass to callback function 263 * 264 * Since: 2.32 265 */ 266 public void sendCredentialsAsync(Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 267 { 268 g_unix_connection_send_credentials_async(gUnixConnection, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 269 } 270 271 /** 272 * Finishes an asynchronous send credentials operation started with 273 * g_unix_connection_send_credentials_async(). 274 * 275 * Params: 276 * result = a #GAsyncResult. 277 * 278 * Returns: %TRUE if the operation was successful, otherwise %FALSE. 279 * 280 * Since: 2.32 281 * 282 * Throws: GException on failure. 283 */ 284 public bool sendCredentialsFinish(AsyncResultIF result) 285 { 286 GError* err = null; 287 288 auto p = g_unix_connection_send_credentials_finish(gUnixConnection, (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 289 290 if (err !is null) 291 { 292 throw new GException( new ErrorG(err) ); 293 } 294 295 return p; 296 } 297 298 /** 299 * Passes a file descriptor to the receiving side of the 300 * connection. The receiving end has to call g_unix_connection_receive_fd() 301 * to accept the file descriptor. 302 * 303 * As well as sending the fd this also writes a single byte to the 304 * stream, as this is required for fd passing to work on some 305 * implementations. 306 * 307 * Params: 308 * fd = a file descriptor 309 * cancellable = optional #GCancellable object, %NULL to ignore. 310 * 311 * Returns: a %TRUE on success, %NULL on error. 312 * 313 * Since: 2.22 314 * 315 * Throws: GException on failure. 316 */ 317 public bool sendFd(int fd, Cancellable cancellable) 318 { 319 GError* err = null; 320 321 auto p = g_unix_connection_send_fd(gUnixConnection, fd, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 322 323 if (err !is null) 324 { 325 throw new GException( new ErrorG(err) ); 326 } 327 328 return p; 329 } 330 }