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