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