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