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  = GSocketConnection.html
27  * outPack = gio
28  * outFile = SocketConnection
29  * strct   = GSocketConnection
30  * realStrct=
31  * ctorStrct=
32  * clss    = SocketConnection
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_socket_connection_
41  * omit structs:
42  * omit prefixes:
43  * 	- g_tcp_connection_
44  * 	- g_unix_connection_
45  * omit code:
46  * omit signals:
47  * imports:
48  * 	- glib.ErrorG
49  * 	- glib.GException
50  * 	- gio.AsyncResultIF
51  * 	- gio.Cancellable
52  * 	- gio.Socket
53  * 	- gio.SocketAddress
54  * structWrap:
55  * 	- GAsyncResult* -> AsyncResultIF
56  * 	- GCancellable* -> Cancellable
57  * 	- GSocket* -> Socket
58  * 	- GSocketAddress* -> SocketAddress
59  * 	- GSocketConnection* -> SocketConnection
60  * module aliases:
61  * local aliases:
62  * overrides:
63  */
64 
65 module gio.SocketConnection;
66 
67 public  import gtkc.giotypes;
68 
69 private import gtkc.gio;
70 private import glib.ConstructionException;
71 private import gobject.ObjectG;
72 
73 private import glib.ErrorG;
74 private import glib.GException;
75 private import gio.AsyncResultIF;
76 private import gio.Cancellable;
77 private import gio.Socket;
78 private import gio.SocketAddress;
79 
80 
81 private import gio.IOStream;
82 
83 /**
84  * GSocketConnection is a GIOStream for a connected socket. They
85  * can be created either by GSocketClient when connecting to a host,
86  * or by GSocketListener when accepting a new client.
87  *
88  * The type of the GSocketConnection object returned from these calls
89  * depends on the type of the underlying socket that is in use. For
90  * instance, for a TCP/IP connection it will be a GTcpConnection.
91  *
92  * Choosing what type of object to construct is done with the socket
93  * connection factory, and it is possible for 3rd parties to register
94  * custom socket connection types for specific combination of socket
95  * family/type/protocol using g_socket_connection_factory_register_type().
96  */
97 public class SocketConnection : IOStream
98 {
99 	
100 	/** the main Gtk struct */
101 	protected GSocketConnection* gSocketConnection;
102 	
103 	
104 	/** Get the main Gtk struct */
105 	public GSocketConnection* getSocketConnectionStruct()
106 	{
107 		return gSocketConnection;
108 	}
109 	
110 	
111 	/** the main Gtk struct as a void* */
112 	protected override void* getStruct()
113 	{
114 		return cast(void*)gSocketConnection;
115 	}
116 	
117 	/**
118 	 * Sets our main struct and passes it to the parent class
119 	 */
120 	public this (GSocketConnection* gSocketConnection)
121 	{
122 		super(cast(GIOStream*)gSocketConnection);
123 		this.gSocketConnection = gSocketConnection;
124 	}
125 	
126 	protected override void setStruct(GObject* obj)
127 	{
128 		super.setStruct(obj);
129 		gSocketConnection = cast(GSocketConnection*)obj;
130 	}
131 	
132 	/**
133 	 */
134 	
135 	/**
136 	 * Connect connection to the specified remote address.
137 	 * Since 2.32
138 	 * Params:
139 	 * address = a GSocketAddress specifying the remote address.
140 	 * cancellable = a GCancellable or NULL. [allow-none]
141 	 * Returns: TRUE if the connection succeeded, FALSE on error
142 	 * Throws: GException on failure.
143 	 */
144 	public int connect(SocketAddress address, Cancellable cancellable)
145 	{
146 		// gboolean g_socket_connection_connect (GSocketConnection *connection,  GSocketAddress *address,  GCancellable *cancellable,  GError **error);
147 		GError* err = null;
148 		
149 		auto p = g_socket_connection_connect(gSocketConnection, (address is null) ? null : address.getSocketAddressStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
150 		
151 		if (err !is null)
152 		{
153 			throw new GException( new ErrorG(err) );
154 		}
155 		
156 		return p;
157 	}
158 	
159 	/**
160 	 * Asynchronously connect connection to the specified remote address.
161 	 * This clears the "blocking" flag on connection's underlying
162 	 * socket if it is currently set.
163 	 * Use g_socket_connection_connect_finish() to retrieve the result.
164 	 * Since 2.32
165 	 * Params:
166 	 * address = a GSocketAddress specifying the remote address.
167 	 * cancellable = a GCancellable or NULL. [allow-none]
168 	 * callback = a GAsyncReadyCallback. [scope async]
169 	 * userData = user data for the callback. [closure]
170 	 */
171 	public void connectAsync(SocketAddress address, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
172 	{
173 		// void g_socket_connection_connect_async (GSocketConnection *connection,  GSocketAddress *address,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
174 		g_socket_connection_connect_async(gSocketConnection, (address is null) ? null : address.getSocketAddressStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
175 	}
176 	
177 	/**
178 	 * Gets the result of a g_socket_connection_connect_async() call.
179 	 * Since 2.32
180 	 * Params:
181 	 * result = the GAsyncResult
182 	 * Returns: TRUE if the connection succeeded, FALSE on error
183 	 * Throws: GException on failure.
184 	 */
185 	public int connectFinish(AsyncResultIF result)
186 	{
187 		// gboolean g_socket_connection_connect_finish (GSocketConnection *connection,  GAsyncResult *result,  GError **error);
188 		GError* err = null;
189 		
190 		auto p = g_socket_connection_connect_finish(gSocketConnection, (result is null) ? null : result.getAsyncResultTStruct(), &err);
191 		
192 		if (err !is null)
193 		{
194 			throw new GException( new ErrorG(err) );
195 		}
196 		
197 		return p;
198 	}
199 	
200 	/**
201 	 * Checks if connection is connected. This is equivalent to calling
202 	 * g_socket_is_connected() on connection's underlying GSocket.
203 	 * Since 2.32
204 	 * Returns: whether connection is connected
205 	 */
206 	public int isConnected()
207 	{
208 		// gboolean g_socket_connection_is_connected (GSocketConnection *connection);
209 		return g_socket_connection_is_connected(gSocketConnection);
210 	}
211 	
212 	/**
213 	 * Try to get the local address of a socket connection.
214 	 * Since 2.22
215 	 * Returns: a GSocketAddress or NULL on error. Free the returned object with g_object_unref(). [transfer full]
216 	 * Throws: GException on failure.
217 	 */
218 	public SocketAddress getLocalAddress()
219 	{
220 		// GSocketAddress * g_socket_connection_get_local_address  (GSocketConnection *connection,  GError **error);
221 		GError* err = null;
222 		
223 		auto p = g_socket_connection_get_local_address(gSocketConnection, &err);
224 		
225 		if (err !is null)
226 		{
227 			throw new GException( new ErrorG(err) );
228 		}
229 		
230 		
231 		if(p is null)
232 		{
233 			return null;
234 		}
235 		
236 		return ObjectG.getDObject!(SocketAddress)(cast(GSocketAddress*) p);
237 	}
238 	
239 	/**
240 	 * Try to get the remote address of a socket connection.
241 	 * Since 2.22
242 	 * Returns: a GSocketAddress or NULL on error. Free the returned object with g_object_unref(). [transfer full]
243 	 * Throws: GException on failure.
244 	 */
245 	public SocketAddress getRemoteAddress()
246 	{
247 		// GSocketAddress * g_socket_connection_get_remote_address  (GSocketConnection *connection,  GError **error);
248 		GError* err = null;
249 		
250 		auto p = g_socket_connection_get_remote_address(gSocketConnection, &err);
251 		
252 		if (err !is null)
253 		{
254 			throw new GException( new ErrorG(err) );
255 		}
256 		
257 		
258 		if(p is null)
259 		{
260 			return null;
261 		}
262 		
263 		return ObjectG.getDObject!(SocketAddress)(cast(GSocketAddress*) p);
264 	}
265 	
266 	/**
267 	 * Gets the underlying GSocket object of the connection.
268 	 * This can be useful if you want to do something unusual on it
269 	 * not supported by the GSocketConnection APIs.
270 	 * Since 2.22
271 	 * Returns: a GSocketAddress or NULL on error. [transfer none]
272 	 */
273 	public Socket getSocket()
274 	{
275 		// GSocket * g_socket_connection_get_socket (GSocketConnection *connection);
276 		auto p = g_socket_connection_get_socket(gSocketConnection);
277 		
278 		if(p is null)
279 		{
280 			return null;
281 		}
282 		
283 		return ObjectG.getDObject!(Socket)(cast(GSocket*) p);
284 	}
285 	
286 	/**
287 	 * Creates a GSocketConnection subclass of the right type for
288 	 * socket.
289 	 * Since 2.22
290 	 * Params:
291 	 * socket = a GSocket
292 	 * Returns: a GSocketConnection. [transfer full]
293 	 */
294 	public static SocketConnection factoryCreateConnection(Socket socket)
295 	{
296 		// GSocketConnection * g_socket_connection_factory_create_connection  (GSocket *socket);
297 		auto p = g_socket_connection_factory_create_connection((socket is null) ? null : socket.getSocketStruct());
298 		
299 		if(p is null)
300 		{
301 			return null;
302 		}
303 		
304 		return ObjectG.getDObject!(SocketConnection)(cast(GSocketConnection*) p);
305 	}
306 	
307 	/**
308 	 * Looks up the GType to be used when creating socket connections on
309 	 * sockets with the specified family, type and protocol_id.
310 	 * If no type is registered, the GSocketConnection base type is returned.
311 	 * Since 2.22
312 	 * Params:
313 	 * family = a GSocketFamily
314 	 * type = a GSocketType
315 	 * protocolId = a protocol id
316 	 * Returns: a GType
317 	 */
318 	public static GType factoryLookupType(GSocketFamily family, GSocketType type, int protocolId)
319 	{
320 		// GType g_socket_connection_factory_lookup_type  (GSocketFamily family,  GSocketType type,  gint protocol_id);
321 		return g_socket_connection_factory_lookup_type(family, type, protocolId);
322 	}
323 	
324 	/**
325 	 * Looks up the GType to be used when creating socket connections on
326 	 * sockets with the specified family, type and protocol.
327 	 * If no type is registered, the GSocketConnection base type is returned.
328 	 * Since 2.22
329 	 * Params:
330 	 * gType = a GType, inheriting from G_TYPE_SOCKET_CONNECTION
331 	 * family = a GSocketFamily
332 	 * type = a GSocketType
333 	 * protocol = a protocol id
334 	 */
335 	public static void factoryRegisterType(GType gType, GSocketFamily family, GSocketType type, int protocol)
336 	{
337 		// void g_socket_connection_factory_register_type  (GType g_type,  GSocketFamily family,  GSocketType type,  gint protocol);
338 		g_socket_connection_factory_register_type(gType, family, type, protocol);
339 	}
340 }