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