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.SrvTarget;
26 
27 private import gio.c.functions;
28 public  import gio.c.types;
29 private import glib.ConstructionException;
30 private import glib.ListG;
31 private import glib.Str;
32 private import gobject.ObjectG;
33 public  import gtkc.giotypes;
34 private import gtkd.Loader;
35 
36 
37 /**
38  * SRV (service) records are used by some network protocols to provide
39  * service-specific aliasing and load-balancing. For example, XMPP
40  * (Jabber) uses SRV records to locate the XMPP server for a domain;
41  * rather than connecting directly to "example.com" or assuming a
42  * specific server hostname like "xmpp.example.com", an XMPP client
43  * would look up the "xmpp-client" SRV record for "example.com", and
44  * then connect to whatever host was pointed to by that record.
45  * 
46  * You can use g_resolver_lookup_service() or
47  * g_resolver_lookup_service_async() to find the #GSrvTargets
48  * for a given service. However, if you are simply planning to connect
49  * to the remote service, you can use #GNetworkService's
50  * #GSocketConnectable interface and not need to worry about
51  * #GSrvTarget at all.
52  */
53 public class SrvTarget
54 {
55 	/** the main Gtk struct */
56 	protected GSrvTarget* gSrvTarget;
57 	protected bool ownedRef;
58 
59 	/** Get the main Gtk struct */
60 	public GSrvTarget* getSrvTargetStruct(bool transferOwnership = false)
61 	{
62 		if (transferOwnership)
63 			ownedRef = false;
64 		return gSrvTarget;
65 	}
66 
67 	/** the main Gtk struct as a void* */
68 	protected void* getStruct()
69 	{
70 		return cast(void*)gSrvTarget;
71 	}
72 
73 	/**
74 	 * Sets our main struct and passes it to the parent class.
75 	 */
76 	public this (GSrvTarget* gSrvTarget, bool ownedRef = false)
77 	{
78 		this.gSrvTarget = gSrvTarget;
79 		this.ownedRef = ownedRef;
80 	}
81 
82 	~this ()
83 	{
84 		if ( Linker.isLoaded(LIBRARY_GIO) && ownedRef )
85 			g_srv_target_free(gSrvTarget);
86 	}
87 
88 
89 	/** */
90 	public static GType getType()
91 	{
92 		return g_srv_target_get_type();
93 	}
94 
95 	/**
96 	 * Creates a new #GSrvTarget with the given parameters.
97 	 *
98 	 * You should not need to use this; normally #GSrvTargets are
99 	 * created by #GResolver.
100 	 *
101 	 * Params:
102 	 *     hostname = the host that the service is running on
103 	 *     port = the port that the service is running on
104 	 *     priority = the target's priority
105 	 *     weight = the target's weight
106 	 *
107 	 * Returns: a new #GSrvTarget.
108 	 *
109 	 * Since: 2.22
110 	 *
111 	 * Throws: ConstructionException GTK+ fails to create the object.
112 	 */
113 	public this(string hostname, ushort port, ushort priority, ushort weight)
114 	{
115 		auto __p = g_srv_target_new(Str.toStringz(hostname), port, priority, weight);
116 
117 		if(__p is null)
118 		{
119 			throw new ConstructionException("null returned by new");
120 		}
121 
122 		this(cast(GSrvTarget*) __p);
123 	}
124 
125 	/**
126 	 * Copies @target
127 	 *
128 	 * Returns: a copy of @target
129 	 *
130 	 * Since: 2.22
131 	 */
132 	public SrvTarget copy()
133 	{
134 		auto __p = g_srv_target_copy(gSrvTarget);
135 
136 		if(__p is null)
137 		{
138 			return null;
139 		}
140 
141 		return ObjectG.getDObject!(SrvTarget)(cast(GSrvTarget*) __p, true);
142 	}
143 
144 	/**
145 	 * Frees @target
146 	 *
147 	 * Since: 2.22
148 	 */
149 	public void free()
150 	{
151 		g_srv_target_free(gSrvTarget);
152 		ownedRef = false;
153 	}
154 
155 	/**
156 	 * Gets @target's hostname (in ASCII form; if you are going to present
157 	 * this to the user, you should use g_hostname_is_ascii_encoded() to
158 	 * check if it contains encoded Unicode segments, and use
159 	 * g_hostname_to_unicode() to convert it if it does.)
160 	 *
161 	 * Returns: @target's hostname
162 	 *
163 	 * Since: 2.22
164 	 */
165 	public string getHostname()
166 	{
167 		return Str.toString(g_srv_target_get_hostname(gSrvTarget));
168 	}
169 
170 	/**
171 	 * Gets @target's port
172 	 *
173 	 * Returns: @target's port
174 	 *
175 	 * Since: 2.22
176 	 */
177 	public ushort getPort()
178 	{
179 		return g_srv_target_get_port(gSrvTarget);
180 	}
181 
182 	/**
183 	 * Gets @target's priority. You should not need to look at this;
184 	 * #GResolver already sorts the targets according to the algorithm in
185 	 * RFC 2782.
186 	 *
187 	 * Returns: @target's priority
188 	 *
189 	 * Since: 2.22
190 	 */
191 	public ushort getPriority()
192 	{
193 		return g_srv_target_get_priority(gSrvTarget);
194 	}
195 
196 	/**
197 	 * Gets @target's weight. You should not need to look at this;
198 	 * #GResolver already sorts the targets according to the algorithm in
199 	 * RFC 2782.
200 	 *
201 	 * Returns: @target's weight
202 	 *
203 	 * Since: 2.22
204 	 */
205 	public ushort getWeight()
206 	{
207 		return g_srv_target_get_weight(gSrvTarget);
208 	}
209 
210 	/**
211 	 * Sorts @targets in place according to the algorithm in RFC 2782.
212 	 *
213 	 * Params:
214 	 *     targets = a #GList of #GSrvTarget
215 	 *
216 	 * Returns: the head of the sorted list.
217 	 *
218 	 * Since: 2.22
219 	 */
220 	public static ListG listSort(ListG targets)
221 	{
222 		auto __p = g_srv_target_list_sort((targets is null) ? null : targets.getListGStruct());
223 
224 		if(__p is null)
225 		{
226 			return null;
227 		}
228 
229 		return new ListG(cast(GList*) __p, true);
230 	}
231 }