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.SocketAddress;
26 
27 private import gio.SocketConnectableIF;
28 private import gio.SocketConnectableT;
29 private import glib.ConstructionException;
30 private import glib.ErrorG;
31 private import glib.GException;
32 private import gobject.ObjectG;
33 private import gtkc.gio;
34 public  import gtkc.giotypes;
35 
36 
37 /**
38  * #GSocketAddress is the equivalent of struct sockaddr in the BSD
39  * sockets API. This is an abstract class; use #GInetSocketAddress
40  * for internet sockets, or #GUnixSocketAddress for UNIX domain sockets.
41  */
42 public class SocketAddress : ObjectG, SocketConnectableIF
43 {
44 	/** the main Gtk struct */
45 	protected GSocketAddress* gSocketAddress;
46 
47 	/** Get the main Gtk struct */
48 	public GSocketAddress* getSocketAddressStruct()
49 	{
50 		return gSocketAddress;
51 	}
52 
53 	/** the main Gtk struct as a void* */
54 	protected override void* getStruct()
55 	{
56 		return cast(void*)gSocketAddress;
57 	}
58 
59 	protected override void setStruct(GObject* obj)
60 	{
61 		gSocketAddress = cast(GSocketAddress*)obj;
62 		super.setStruct(obj);
63 	}
64 
65 	/**
66 	 * Sets our main struct and passes it to the parent class.
67 	 */
68 	public this (GSocketAddress* gSocketAddress, bool ownedRef = false)
69 	{
70 		this.gSocketAddress = gSocketAddress;
71 		super(cast(GObject*)gSocketAddress, ownedRef);
72 	}
73 
74 	// add the SocketConnectable capabilities
75 	mixin SocketConnectableT!(GSocketAddress);
76 
77 	/**
78 	 */
79 
80 	public static GType getType()
81 	{
82 		return g_socket_address_get_type();
83 	}
84 
85 	/**
86 	 * Creates a #GSocketAddress subclass corresponding to the native
87 	 * struct sockaddr @native.
88 	 *
89 	 * Params:
90 	 *     native = a pointer to a struct sockaddr
91 	 *     len = the size of the memory location pointed to by @native
92 	 *
93 	 * Return: a new #GSocketAddress if @native could successfully
94 	 *     be converted, otherwise %NULL
95 	 *
96 	 * Since: 2.22
97 	 *
98 	 * Throws: ConstructionException GTK+ fails to create the object.
99 	 */
100 	public this(void* native, size_t len)
101 	{
102 		auto p = g_socket_address_new_from_native(native, len);
103 		
104 		if(p is null)
105 		{
106 			throw new ConstructionException("null returned by new_from_native");
107 		}
108 		
109 		this(cast(GSocketAddress*) p, true);
110 	}
111 
112 	/**
113 	 * Gets the socket family type of @address.
114 	 *
115 	 * Return: the socket family type of @address
116 	 *
117 	 * Since: 2.22
118 	 */
119 	public GSocketFamily getFamily()
120 	{
121 		return g_socket_address_get_family(gSocketAddress);
122 	}
123 
124 	/**
125 	 * Gets the size of @address's native struct sockaddr.
126 	 * You can use this to allocate memory to pass to
127 	 * g_socket_address_to_native().
128 	 *
129 	 * Return: the size of the native struct sockaddr that
130 	 *     @address represents
131 	 *
132 	 * Since: 2.22
133 	 */
134 	public ptrdiff_t getNativeSize()
135 	{
136 		return g_socket_address_get_native_size(gSocketAddress);
137 	}
138 
139 	/**
140 	 * Converts a #GSocketAddress to a native struct sockaddr, which can
141 	 * be passed to low-level functions like connect() or bind().
142 	 *
143 	 * If not enough space is available, a %G_IO_ERROR_NO_SPACE error
144 	 * is returned. If the address type is not known on the system
145 	 * then a %G_IO_ERROR_NOT_SUPPORTED error is returned.
146 	 *
147 	 * Params:
148 	 *     dest = a pointer to a memory location that will contain the native
149 	 *         struct sockaddr
150 	 *     destlen = the size of @dest. Must be at least as large as
151 	 *         g_socket_address_get_native_size()
152 	 *
153 	 * Return: %TRUE if @dest was filled in, %FALSE on error
154 	 *
155 	 * Since: 2.22
156 	 *
157 	 * Throws: GException on failure.
158 	 */
159 	public bool toNative(void* dest, size_t destlen)
160 	{
161 		GError* err = null;
162 		
163 		auto p = g_socket_address_to_native(gSocketAddress, dest, destlen, &err) != 0;
164 		
165 		if (err !is null)
166 		{
167 			throw new GException( new ErrorG(err) );
168 		}
169 		
170 		return p;
171 	}
172 }