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