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