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