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.Socket
51  * 	- gio.SocketAddress
52  * structWrap:
53  * 	- GSocket* -> Socket
54  * 	- GSocketAddress* -> SocketAddress
55  * 	- GSocketConnection* -> SocketConnection
56  * module aliases:
57  * local aliases:
58  * overrides:
59  */
60 
61 module gio.SocketConnection;
62 
63 public  import gtkc.giotypes;
64 
65 private import gtkc.gio;
66 private import glib.ConstructionException;
67 private import gobject.ObjectG;
68 
69 
70 private import glib.ErrorG;
71 private import glib.GException;
72 private import gio.Socket;
73 private import gio.SocketAddress;
74 
75 
76 
77 private import gio.IOStream;
78 
79 /**
80  * Description
81  * GSocketConnection is a GIOStream for a connected socket. They
82  * can be created either by GSocketClient when connecting to a host,
83  * or by GSocketListener when accepting a new client.
84  * The type of the GSocketConnection object returned from these calls
85  * depends on the type of the underlying socket that is in use. For
86  * instance, for a TCP/IP connection it will be a GTcpConnection.
87  * Chosing what type of object to construct is done with the socket
88  * connection factory, and it is possible for 3rd parties to register
89  * custom socket connection types for specific combination of socket
90  * family/type/protocol using g_socket_connection_factory_register_type().
91  */
92 public class SocketConnection : IOStream
93 {
94 	
95 	/** the main Gtk struct */
96 	protected GSocketConnection* gSocketConnection;
97 	
98 	
99 	public GSocketConnection* getSocketConnectionStruct()
100 	{
101 		return gSocketConnection;
102 	}
103 	
104 	
105 	/** the main Gtk struct as a void* */
106 	protected override void* getStruct()
107 	{
108 		return cast(void*)gSocketConnection;
109 	}
110 	
111 	/**
112 	 * Sets our main struct and passes it to the parent class
113 	 */
114 	public this (GSocketConnection* gSocketConnection)
115 	{
116 		super(cast(GIOStream*)gSocketConnection);
117 		this.gSocketConnection = gSocketConnection;
118 	}
119 	
120 	protected override void setStruct(GObject* obj)
121 	{
122 		super.setStruct(obj);
123 		gSocketConnection = cast(GSocketConnection*)obj;
124 	}
125 	
126 	/**
127 	 */
128 	
129 	/**
130 	 * Try to get the local address of a socket connection.
131 	 * Since 2.22
132 	 * Returns: a GSocketAddress or NULL on error. Free the returned object with g_object_unref(). [transfer full]
133 	 * Throws: GException on failure.
134 	 */
135 	public SocketAddress getLocalAddress()
136 	{
137 		// GSocketAddress * g_socket_connection_get_local_address  (GSocketConnection *connection,  GError **error);
138 		GError* err = null;
139 		
140 		auto p = g_socket_connection_get_local_address(gSocketConnection, &err);
141 		
142 		if (err !is null)
143 		{
144 			throw new GException( new ErrorG(err) );
145 		}
146 		
147 		
148 		if(p is null)
149 		{
150 			return null;
151 		}
152 		
153 		return ObjectG.getDObject!(SocketAddress)(cast(GSocketAddress*) p);
154 	}
155 	
156 	/**
157 	 * Try to get the remote address of a socket connection.
158 	 * Since 2.22
159 	 * Returns: a GSocketAddress or NULL on error. Free the returned object with g_object_unref(). [transfer full]
160 	 * Throws: GException on failure.
161 	 */
162 	public SocketAddress getRemoteAddress()
163 	{
164 		// GSocketAddress * g_socket_connection_get_remote_address  (GSocketConnection *connection,  GError **error);
165 		GError* err = null;
166 		
167 		auto p = g_socket_connection_get_remote_address(gSocketConnection, &err);
168 		
169 		if (err !is null)
170 		{
171 			throw new GException( new ErrorG(err) );
172 		}
173 		
174 		
175 		if(p is null)
176 		{
177 			return null;
178 		}
179 		
180 		return ObjectG.getDObject!(SocketAddress)(cast(GSocketAddress*) p);
181 	}
182 	
183 	/**
184 	 * Gets the underlying GSocket object of the connection.
185 	 * This can be useful if you want to do something unusual on it
186 	 * not supported by the GSocketConnection APIs.
187 	 * Since 2.22
188 	 * Returns: a GSocketAddress or NULL on error. [transfer none]
189 	 */
190 	public Socket getSocket()
191 	{
192 		// GSocket * g_socket_connection_get_socket (GSocketConnection *connection);
193 		auto p = g_socket_connection_get_socket(gSocketConnection);
194 		
195 		if(p is null)
196 		{
197 			return null;
198 		}
199 		
200 		return ObjectG.getDObject!(Socket)(cast(GSocket*) p);
201 	}
202 	
203 	/**
204 	 * Creates a GSocketConnection subclass of the right type for
205 	 * socket.
206 	 * Since 2.22
207 	 * Params:
208 	 * socket = a GSocket
209 	 * Returns: a GSocketConnection. [transfer full]
210 	 */
211 	public static SocketConnection factoryCreateConnection(Socket socket)
212 	{
213 		// GSocketConnection * g_socket_connection_factory_create_connection  (GSocket *socket);
214 		auto p = g_socket_connection_factory_create_connection((socket is null) ? null : socket.getSocketStruct());
215 		
216 		if(p is null)
217 		{
218 			return null;
219 		}
220 		
221 		return ObjectG.getDObject!(SocketConnection)(cast(GSocketConnection*) p);
222 	}
223 	
224 	/**
225 	 * Looks up the GType to be used when creating socket connections on
226 	 * sockets with the specified family,type and protocol_id.
227 	 * If no type is registered, the GSocketConnection base type is returned.
228 	 * Since 2.22
229 	 * Params:
230 	 * family = a GSocketFamily
231 	 * type = a GSocketType
232 	 * protocolId = a protocol id
233 	 * Returns: a GType
234 	 */
235 	public static GType factoryLookupType(GSocketFamily family, GSocketType type, int protocolId)
236 	{
237 		// GType g_socket_connection_factory_lookup_type  (GSocketFamily family,  GSocketType type,  gint protocol_id);
238 		return g_socket_connection_factory_lookup_type(family, type, protocolId);
239 	}
240 	
241 	/**
242 	 * Looks up the GType to be used when creating socket connections on
243 	 * sockets with the specified family,type and protocol.
244 	 * If no type is registered, the GSocketConnection base type is returned.
245 	 * Since 2.22
246 	 * Params:
247 	 * gType = a GType, inheriting from G_TYPE_SOCKET_CONNECTION
248 	 * family = a GSocketFamily
249 	 * type = a GSocketType
250 	 * protocol = a protocol id
251 	 */
252 	public static void factoryRegisterType(GType gType, GSocketFamily family, GSocketType type, int protocol)
253 	{
254 		// void g_socket_connection_factory_register_type  (GType g_type,  GSocketFamily family,  GSocketType type,  gint protocol);
255 		g_socket_connection_factory_register_type(gType, family, type, protocol);
256 	}
257 }