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.InetSocketAddress;
26 
27 private import gio.InetAddress;
28 private import gio.SocketAddress;
29 private import gio.c.functions;
30 public  import gio.c.types;
31 private import glib.ConstructionException;
32 private import glib.Str;
33 private import gobject.ObjectG;
34 public  import gtkc.giotypes;
35 
36 
37 /**
38  * An IPv4 or IPv6 socket address; that is, the combination of a
39  * #GInetAddress and a port number.
40  */
41 public class InetSocketAddress : SocketAddress
42 {
43 	/** the main Gtk struct */
44 	protected GInetSocketAddress* gInetSocketAddress;
45 
46 	/** Get the main Gtk struct */
47 	public GInetSocketAddress* getInetSocketAddressStruct(bool transferOwnership = false)
48 	{
49 		if (transferOwnership)
50 			ownedRef = false;
51 		return gInetSocketAddress;
52 	}
53 
54 	/** the main Gtk struct as a void* */
55 	protected override void* getStruct()
56 	{
57 		return cast(void*)gInetSocketAddress;
58 	}
59 
60 	protected override void setStruct(GObject* obj)
61 	{
62 		gInetSocketAddress = cast(GInetSocketAddress*)obj;
63 		super.setStruct(obj);
64 	}
65 
66 	/**
67 	 * Sets our main struct and passes it to the parent class.
68 	 */
69 	public this (GInetSocketAddress* gInetSocketAddress, bool ownedRef = false)
70 	{
71 		this.gInetSocketAddress = gInetSocketAddress;
72 		super(cast(GSocketAddress*)gInetSocketAddress, ownedRef);
73 	}
74 
75 
76 	/** */
77 	public static GType getType()
78 	{
79 		return g_inet_socket_address_get_type();
80 	}
81 
82 	/**
83 	 * Creates a new #GInetSocketAddress for @address and @port.
84 	 *
85 	 * Params:
86 	 *     address = a #GInetAddress
87 	 *     port = a port number
88 	 *
89 	 * Returns: a new #GInetSocketAddress
90 	 *
91 	 * Since: 2.22
92 	 *
93 	 * Throws: ConstructionException GTK+ fails to create the object.
94 	 */
95 	public this(InetAddress address, ushort port)
96 	{
97 		auto p = g_inet_socket_address_new((address is null) ? null : address.getInetAddressStruct(), port);
98 
99 		if(p is null)
100 		{
101 			throw new ConstructionException("null returned by new");
102 		}
103 
104 		this(cast(GInetSocketAddress*) p, true);
105 	}
106 
107 	/**
108 	 * Creates a new #GInetSocketAddress for @address and @port.
109 	 *
110 	 * If @address is an IPv6 address, it can also contain a scope ID
111 	 * (separated from the address by a `%`).
112 	 *
113 	 * Params:
114 	 *     address = the string form of an IP address
115 	 *     port = a port number
116 	 *
117 	 * Returns: a new #GInetSocketAddress, or %NULL if @address cannot be
118 	 *     parsed.
119 	 *
120 	 * Since: 2.40
121 	 *
122 	 * Throws: ConstructionException GTK+ fails to create the object.
123 	 */
124 	public this(string address, uint port)
125 	{
126 		auto p = g_inet_socket_address_new_from_string(Str.toStringz(address), port);
127 
128 		if(p is null)
129 		{
130 			throw new ConstructionException("null returned by new_from_string");
131 		}
132 
133 		this(cast(GInetSocketAddress*) p, true);
134 	}
135 
136 	/**
137 	 * Gets @address's #GInetAddress.
138 	 *
139 	 * Returns: the #GInetAddress for @address, which must be
140 	 *     g_object_ref()'d if it will be stored
141 	 *
142 	 * Since: 2.22
143 	 */
144 	public InetAddress getAddress()
145 	{
146 		auto p = g_inet_socket_address_get_address(gInetSocketAddress);
147 
148 		if(p is null)
149 		{
150 			return null;
151 		}
152 
153 		return ObjectG.getDObject!(InetAddress)(cast(GInetAddress*) p);
154 	}
155 
156 	/**
157 	 * Gets the `sin6_flowinfo` field from @address,
158 	 * which must be an IPv6 address.
159 	 *
160 	 * Returns: the flowinfo field
161 	 *
162 	 * Since: 2.32
163 	 */
164 	public uint getFlowinfo()
165 	{
166 		return g_inet_socket_address_get_flowinfo(gInetSocketAddress);
167 	}
168 
169 	/**
170 	 * Gets @address's port.
171 	 *
172 	 * Returns: the port for @address
173 	 *
174 	 * Since: 2.22
175 	 */
176 	public ushort getPort()
177 	{
178 		return g_inet_socket_address_get_port(gInetSocketAddress);
179 	}
180 
181 	/**
182 	 * Gets the `sin6_scope_id` field from @address,
183 	 * which must be an IPv6 address.
184 	 *
185 	 * Returns: the scope id field
186 	 *
187 	 * Since: 2.32
188 	 */
189 	public uint getScopeId()
190 	{
191 		return g_inet_socket_address_get_scope_id(gInetSocketAddress);
192 	}
193 }