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 
56 	/** Get the main Gtk struct */
57 	public GSrvTarget* getSrvTargetStruct()
58 	{
59 		return gSrvTarget;
60 	}
61 
62 	/** the main Gtk struct as a void* */
63 	protected void* getStruct()
64 	{
65 		return cast(void*)gSrvTarget;
66 	}
67 
68 	/**
69 	 * Sets our main struct and passes it to the parent class.
70 	 */
71 	public this (GSrvTarget* gSrvTarget)
72 	{
73 		this.gSrvTarget = gSrvTarget;
74 	}
75 
76 	/**
77 	 */
78 
79 	public static GType getType()
80 	{
81 		return g_srv_target_get_type();
82 	}
83 
84 	/**
85 	 * Creates a new #GSrvTarget with the given parameters.
86 	 *
87 	 * You should not need to use this; normally #GSrvTargets are
88 	 * created by #GResolver.
89 	 *
90 	 * Params:
91 	 *     hostname = the host that the service is running on
92 	 *     port = the port that the service is running on
93 	 *     priority = the target's priority
94 	 *     weight = the target's weight
95 	 *
96 	 * Return: a new #GSrvTarget.
97 	 *
98 	 * Since: 2.22
99 	 *
100 	 * Throws: ConstructionException GTK+ fails to create the object.
101 	 */
102 	public this(string hostname, ushort port, ushort priority, ushort weight)
103 	{
104 		auto p = g_srv_target_new(Str.toStringz(hostname), port, priority, weight);
105 		
106 		if(p is null)
107 		{
108 			throw new ConstructionException("null returned by new");
109 		}
110 		
111 		this(cast(GSrvTarget*) p);
112 	}
113 
114 	/**
115 	 * Copies @target
116 	 *
117 	 * Return: a copy of @target
118 	 *
119 	 * Since: 2.22
120 	 */
121 	public SrvTarget copy()
122 	{
123 		auto p = g_srv_target_copy(gSrvTarget);
124 		
125 		if(p is null)
126 		{
127 			return null;
128 		}
129 		
130 		return ObjectG.getDObject!(SrvTarget)(cast(GSrvTarget*) p);
131 	}
132 
133 	/**
134 	 * Frees @target
135 	 *
136 	 * Since: 2.22
137 	 */
138 	public void free()
139 	{
140 		g_srv_target_free(gSrvTarget);
141 	}
142 
143 	/**
144 	 * Gets @target's hostname (in ASCII form; if you are going to present
145 	 * this to the user, you should use g_hostname_is_ascii_encoded() to
146 	 * check if it contains encoded Unicode segments, and use
147 	 * g_hostname_to_unicode() to convert it if it does.)
148 	 *
149 	 * Return: @target's hostname
150 	 *
151 	 * Since: 2.22
152 	 */
153 	public string getHostname()
154 	{
155 		return Str.toString(g_srv_target_get_hostname(gSrvTarget));
156 	}
157 
158 	/**
159 	 * Gets @target's port
160 	 *
161 	 * Return: @target's port
162 	 *
163 	 * Since: 2.22
164 	 */
165 	public ushort getPort()
166 	{
167 		return g_srv_target_get_port(gSrvTarget);
168 	}
169 
170 	/**
171 	 * Gets @target's priority. You should not need to look at this;
172 	 * #GResolver already sorts the targets according to the algorithm in
173 	 * RFC 2782.
174 	 *
175 	 * Return: @target's priority
176 	 *
177 	 * Since: 2.22
178 	 */
179 	public ushort getPriority()
180 	{
181 		return g_srv_target_get_priority(gSrvTarget);
182 	}
183 
184 	/**
185 	 * Gets @target's weight. You should not need to look at this;
186 	 * #GResolver already sorts the targets according to the algorithm in
187 	 * RFC 2782.
188 	 *
189 	 * Return: @target's weight
190 	 *
191 	 * Since: 2.22
192 	 */
193 	public ushort getWeight()
194 	{
195 		return g_srv_target_get_weight(gSrvTarget);
196 	}
197 
198 	/**
199 	 * Sorts @targets in place according to the algorithm in RFC 2782.
200 	 *
201 	 * Params:
202 	 *     targets = a #GList of #GSrvTarget
203 	 *
204 	 * Return: the head of the sorted list.
205 	 *
206 	 * Since: 2.22
207 	 */
208 	public static ListG listSort(ListG targets)
209 	{
210 		auto p = g_srv_target_list_sort((targets is null) ? null : targets.getListGStruct());
211 		
212 		if(p is null)
213 		{
214 			return null;
215 		}
216 		
217 		return new ListG(cast(GList*) p);
218 	}
219 }