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 	public static GType getType()
80 	{
81 		return g_socket_address_get_type();
82 	}
83 
84 	/**
85 	 * Creates a #GSocketAddress subclass corresponding to the native
86 	 * struct sockaddr @native.
87 	 *
88 	 * Params:
89 	 *     native = a pointer to a struct sockaddr
90 	 *     len = the size of the memory location pointed to by @native
91 	 *
92 	 * Return: a new #GSocketAddress if @native could successfully
93 	 *     be converted, otherwise %NULL
94 	 *
95 	 * Since: 2.22
96 	 *
97 	 * Throws: ConstructionException GTK+ fails to create the object.
98 	 */
99 	public this(void* native, size_t len)
100 	{
101 		auto p = g_socket_address_new_from_native(native, len);
102 		
103 		if(p is null)
104 		{
105 			throw new ConstructionException("null returned by new_from_native");
106 		}
107 		
108 		this(cast(GSocketAddress*) p, true);
109 	}
110 
111 	/**
112 	 * Gets the socket family type of @address.
113 	 *
114 	 * Return: the socket family type of @address
115 	 *
116 	 * Since: 2.22
117 	 */
118 	public GSocketFamily getFamily()
119 	{
120 		return g_socket_address_get_family(gSocketAddress);
121 	}
122 
123 	/**
124 	 * Gets the size of @address's native struct sockaddr.
125 	 * You can use this to allocate memory to pass to
126 	 * g_socket_address_to_native().
127 	 *
128 	 * Return: the size of the native struct sockaddr that
129 	 *     @address represents
130 	 *
131 	 * Since: 2.22
132 	 */
133 	public ptrdiff_t getNativeSize()
134 	{
135 		return g_socket_address_get_native_size(gSocketAddress);
136 	}
137 
138 	/**
139 	 * Converts a #GSocketAddress to a native struct sockaddr, which can
140 	 * be passed to low-level functions like connect() or bind().
141 	 *
142 	 * If not enough space is available, a %G_IO_ERROR_NO_SPACE error
143 	 * is returned. If the address type is not known on the system
144 	 * then a %G_IO_ERROR_NOT_SUPPORTED error is returned.
145 	 *
146 	 * Params:
147 	 *     dest = a pointer to a memory location that will contain the native
148 	 *         struct sockaddr
149 	 *     destlen = the size of @dest. Must be at least as large as
150 	 *         g_socket_address_get_native_size()
151 	 *
152 	 * Return: %TRUE if @dest was filled in, %FALSE on error
153 	 *
154 	 * Since: 2.22
155 	 *
156 	 * Throws: GException on failure.
157 	 */
158 	public bool toNative(void* dest, size_t destlen)
159 	{
160 		GError* err = null;
161 		
162 		auto p = g_socket_address_to_native(gSocketAddress, dest, destlen, &err) != 0;
163 		
164 		if (err !is null)
165 		{
166 			throw new GException( new ErrorG(err) );
167 		}
168 		
169 		return p;
170 	}
171 }