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