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