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  * Conversion parameters:
26  * inFile  = GUnixConnection.html
27  * outPack = gio
28  * outFile = UnixConnection
29  * strct   = GUnixConnection
30  * realStrct=
31  * ctorStrct=
32  * clss    = UnixConnection
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_unix_connection_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.ErrorG
47  * 	- glib.GException
48  * 	- gio.Cancellable
49  * 	- gio.Credentials
50  * structWrap:
51  * 	- GCancellable* -> Cancellable
52  * 	- GCredentials* -> Credentials
53  * module aliases:
54  * local aliases:
55  * overrides:
56  */
57 
58 module gio.UnixConnection;
59 
60 public  import gtkc.giotypes;
61 
62 private import gtkc.gio;
63 private import glib.ConstructionException;
64 private import gobject.ObjectG;
65 
66 
67 private import glib.ErrorG;
68 private import glib.GException;
69 private import gio.Cancellable;
70 private import gio.Credentials;
71 
72 
73 
74 private import gio.SocketConnection;
75 
76 /**
77  * Description
78  * This is the subclass of GSocketConnection that is created
79  * for UNIX domain sockets.
80  * It contains functions to do some of the UNIX socket specific
81  * functionality like passing file descriptors.
82  * Note that <gio/gunixconnection.h> belongs to
83  * the UNIX-specific GIO interfaces, thus you have to use the
84  * gio-unix-2.0.pc pkg-config file when using it.
85  */
86 public class UnixConnection : SocketConnection
87 {
88 	
89 	/** the main Gtk struct */
90 	protected GUnixConnection* gUnixConnection;
91 	
92 	
93 	public GUnixConnection* getUnixConnectionStruct()
94 	{
95 		return gUnixConnection;
96 	}
97 	
98 	
99 	/** the main Gtk struct as a void* */
100 	protected override void* getStruct()
101 	{
102 		return cast(void*)gUnixConnection;
103 	}
104 	
105 	/**
106 	 * Sets our main struct and passes it to the parent class
107 	 */
108 	public this (GUnixConnection* gUnixConnection)
109 	{
110 		super(cast(GSocketConnection*)gUnixConnection);
111 		this.gUnixConnection = gUnixConnection;
112 	}
113 	
114 	protected override void setStruct(GObject* obj)
115 	{
116 		super.setStruct(obj);
117 		gUnixConnection = cast(GUnixConnection*)obj;
118 	}
119 	
120 	/**
121 	 */
122 	
123 	/**
124 	 * Receives a file descriptor from the sending end of the connection.
125 	 * The sending end has to call g_unix_connection_send_fd() for this
126 	 * to work.
127 	 * As well as reading the fd this also reads a single byte from the
128 	 * stream, as this is required for fd passing to work on some
129 	 * implementations.
130 	 * Since 2.22
131 	 * Params:
132 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
133 	 * Returns: a file descriptor on success, -1 on error.
134 	 * Throws: GException on failure.
135 	 */
136 	public int receiveFd(Cancellable cancellable)
137 	{
138 		// gint g_unix_connection_receive_fd (GUnixConnection *connection,  GCancellable *cancellable,  GError **error);
139 		GError* err = null;
140 		
141 		auto p = g_unix_connection_receive_fd(gUnixConnection, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
142 		
143 		if (err !is null)
144 		{
145 			throw new GException( new ErrorG(err) );
146 		}
147 		
148 		return p;
149 	}
150 	
151 	/**
152 	 * Passes a file descriptor to the recieving side of the
153 	 * connection. The recieving end has to call g_unix_connection_receive_fd()
154 	 * to accept the file descriptor.
155 	 * As well as sending the fd this also writes a single byte to the
156 	 * stream, as this is required for fd passing to work on some
157 	 * implementations.
158 	 * Since 2.22
159 	 * Params:
160 	 * fd = a file descriptor
161 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
162 	 * Returns: a TRUE on success, NULL on error.
163 	 * Throws: GException on failure.
164 	 */
165 	public int sendFd(int fd, Cancellable cancellable)
166 	{
167 		// gboolean g_unix_connection_send_fd (GUnixConnection *connection,  gint fd,  GCancellable *cancellable,  GError **error);
168 		GError* err = null;
169 		
170 		auto p = g_unix_connection_send_fd(gUnixConnection, fd, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
171 		
172 		if (err !is null)
173 		{
174 			throw new GException( new ErrorG(err) );
175 		}
176 		
177 		return p;
178 	}
179 	
180 	/**
181 	 * Receives credentials from the sending end of the connection. The
182 	 * sending end has to call g_unix_connection_send_credentials() (or
183 	 * similar) for this to work.
184 	 * As well as reading the credentials this also reads (and discards) a
185 	 * single byte from the stream, as this is required for credentials
186 	 * passing to work on some implementations.
187 	 * Other ways to exchange credentials with a foreign peer includes the
188 	 * GUnixCredentialsMessage type and g_socket_get_credentials() function.
189 	 * Since 2.26
190 	 * Params:
191 	 * cancellable = A GCancellable or NULL. [allow-none]
192 	 * Returns: Received credentials on success (free with g_object_unref()), NULL if error is set. [transfer full]
193 	 * Throws: GException on failure.
194 	 */
195 	public Credentials receiveCredentials(Cancellable cancellable)
196 	{
197 		// GCredentials * g_unix_connection_receive_credentials  (GUnixConnection *connection,  GCancellable *cancellable,  GError **error);
198 		GError* err = null;
199 		
200 		auto p = g_unix_connection_receive_credentials(gUnixConnection, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
201 		
202 		if (err !is null)
203 		{
204 			throw new GException( new ErrorG(err) );
205 		}
206 		
207 		
208 		if(p is null)
209 		{
210 			return null;
211 		}
212 		
213 		return ObjectG.getDObject!(Credentials)(cast(GCredentials*) p);
214 	}
215 	
216 	/**
217 	 * Passes the credentials of the current user the receiving side
218 	 * of the connection. The recieving end has to call
219 	 * g_unix_connection_receive_credentials() (or similar) to accept the
220 	 * credentials.
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 	 * Other ways to exchange credentials with a foreign peer includes the
225 	 * GUnixCredentialsMessage type and g_socket_get_credentials() function.
226 	 * Since 2.26
227 	 * Params:
228 	 * cancellable = A GCancellable or NULL. [allow-none]
229 	 * Returns: TRUE on success, FALSE if error is set.
230 	 * Throws: GException on failure.
231 	 */
232 	public int sendCredentials(Cancellable cancellable)
233 	{
234 		// gboolean g_unix_connection_send_credentials (GUnixConnection *connection,  GCancellable *cancellable,  GError **error);
235 		GError* err = null;
236 		
237 		auto p = g_unix_connection_send_credentials(gUnixConnection, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
238 		
239 		if (err !is null)
240 		{
241 			throw new GException( new ErrorG(err) );
242 		}
243 		
244 		return p;
245 	}
246 }