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