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