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