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.SocketConnectableT;
26 
27 public  import gio.SocketAddressEnumerator;
28 public  import glib.Str;
29 public  import gobject.ObjectG;
30 public  import gtkc.gio;
31 public  import gtkc.giotypes;
32 
33 
34 /**
35  * Objects that describe one or more potential socket endpoints
36  * implement #GSocketConnectable. Callers can then use
37  * g_socket_connectable_enumerate() to get a #GSocketAddressEnumerator
38  * to try out each socket address in turn until one succeeds, as shown
39  * in the sample code below.
40  * 
41  * |[<!-- language="C" -->
42  * MyConnectionType *
43  * connect_to_host (const char    *hostname,
44  * guint16        port,
45  * GCancellable  *cancellable,
46  * GError       **error)
47  * {
48  * MyConnection *conn = NULL;
49  * GSocketConnectable *addr;
50  * GSocketAddressEnumerator *enumerator;
51  * GSocketAddress *sockaddr;
52  * GError *conn_error = NULL;
53  * 
54  * addr = g_network_address_new (hostname, port);
55  * enumerator = g_socket_connectable_enumerate (addr);
56  * g_object_unref (addr);
57  * 
58  * // Try each sockaddr until we succeed. Record the first connection error,
59  * // but not any further ones (since they'll probably be basically the same
60  * // as the first).
61  * while (!conn && (sockaddr = g_socket_address_enumerator_next (enumerator, cancellable, error))
62  * {
63  * conn = connect_to_sockaddr (sockaddr, conn_error ? NULL : &conn_error);
64  * g_object_unref (sockaddr);
65  * }
66  * g_object_unref (enumerator);
67  * 
68  * if (conn)
69  * {
70  * if (conn_error)
71  * {
72  * // We couldn't connect to the first address, but we succeeded
73  * // in connecting to a later address.
74  * g_error_free (conn_error);
75  * }
76  * return conn;
77  * }
78  * else if (error)
79  * {
80  * /// Either initial lookup failed, or else the caller cancelled us.
81  * if (conn_error)
82  * g_error_free (conn_error);
83  * return NULL;
84  * }
85  * else
86  * {
87  * g_error_propagate (error, conn_error);
88  * return NULL;
89  * }
90  * }
91  * ]|
92  */
93 public template SocketConnectableT(TStruct)
94 {
95 	/** Get the main Gtk struct */
96 	public GSocketConnectable* getSocketConnectableStruct(bool transferOwnership = false)
97 	{
98 		if (transferOwnership)
99 			ownedRef = false;
100 		return cast(GSocketConnectable*)getStruct();
101 	}
102 
103 
104 	/**
105 	 * Creates a #GSocketAddressEnumerator for @connectable.
106 	 *
107 	 * Returns: a new #GSocketAddressEnumerator.
108 	 *
109 	 * Since: 2.22
110 	 */
111 	public SocketAddressEnumerator enumerate()
112 	{
113 		auto p = g_socket_connectable_enumerate(getSocketConnectableStruct());
114 		
115 		if(p is null)
116 		{
117 			return null;
118 		}
119 		
120 		return ObjectG.getDObject!(SocketAddressEnumerator)(cast(GSocketAddressEnumerator*) p, true);
121 	}
122 
123 	/**
124 	 * Creates a #GSocketAddressEnumerator for @connectable that will
125 	 * return #GProxyAddresses for addresses that you must connect
126 	 * to via a proxy.
127 	 *
128 	 * If @connectable does not implement
129 	 * g_socket_connectable_proxy_enumerate(), this will fall back to
130 	 * calling g_socket_connectable_enumerate().
131 	 *
132 	 * Returns: a new #GSocketAddressEnumerator.
133 	 *
134 	 * Since: 2.26
135 	 */
136 	public SocketAddressEnumerator proxyEnumerate()
137 	{
138 		auto p = g_socket_connectable_proxy_enumerate(getSocketConnectableStruct());
139 		
140 		if(p is null)
141 		{
142 			return null;
143 		}
144 		
145 		return ObjectG.getDObject!(SocketAddressEnumerator)(cast(GSocketAddressEnumerator*) p, true);
146 	}
147 
148 	/**
149 	 * Format a #GSocketConnectable as a string. This is a human-readable format for
150 	 * use in debugging output, and is not a stable serialization format. It is not
151 	 * suitable for use in user interfaces as it exposes too much information for a
152 	 * user.
153 	 *
154 	 * If the #GSocketConnectable implementation does not support string formatting,
155 	 * the implementation’s type name will be returned as a fallback.
156 	 *
157 	 * Returns: the formatted string
158 	 *
159 	 * Since: 2.48
160 	 */
161 	public override string toString()
162 	{
163 		auto retStr = g_socket_connectable_to_string(getSocketConnectableStruct());
164 		
165 		scope(exit) Str.freeString(retStr);
166 		return Str.toString(retStr);
167 	}
168 }