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 gobject.ObjectG;
29 public  import gtkc.gio;
30 public  import gtkc.giotypes;
31 
32 
33 /**
34  * Objects that describe one or more potential socket endpoints
35  * implement #GSocketConnectable. Callers can then use
36  * g_socket_connectable_enumerate() to get a #GSocketAddressEnumerator
37  * to try out each socket address in turn until one succeeds, as shown
38  * in the sample code below.
39  * 
40  * |[<!-- language="C" -->
41  * MyConnectionType *
42  * connect_to_host (const char    *hostname,
43  * guint16        port,
44  * GCancellable  *cancellable,
45  * GError       **error)
46  * {
47  * MyConnection *conn = NULL;
48  * GSocketConnectable *addr;
49  * GSocketAddressEnumerator *enumerator;
50  * GSocketAddress *sockaddr;
51  * GError *conn_error = NULL;
52  * 
53  * addr = g_network_address_new (hostname, port);
54  * enumerator = g_socket_connectable_enumerate (addr);
55  * g_object_unref (addr);
56  * 
57  * // Try each sockaddr until we succeed. Record the first connection error,
58  * // but not any further ones (since they'll probably be basically the same
59  * // as the first).
60  * while (!conn && (sockaddr = g_socket_address_enumerator_next (enumerator, cancellable, error))
61  * {
62  * conn = connect_to_sockaddr (sockaddr, conn_error ? NULL : &conn_error);
63  * g_object_unref (sockaddr);
64  * }
65  * g_object_unref (enumerator);
66  * 
67  * if (conn)
68  * {
69  * if (conn_error)
70  * {
71  * // We couldn't connect to the first address, but we succeeded
72  * // in connecting to a later address.
73  * g_error_free (conn_error);
74  * }
75  * return conn;
76  * }
77  * else if (error)
78  * {
79  * /// Either initial lookup failed, or else the caller cancelled us.
80  * if (conn_error)
81  * g_error_free (conn_error);
82  * return NULL;
83  * }
84  * else
85  * {
86  * g_error_propagate (error, conn_error);
87  * return NULL;
88  * }
89  * }
90  * ]|
91  */
92 public template SocketConnectableT(TStruct)
93 {
94 	/** Get the main Gtk struct */
95 	public GSocketConnectable* getSocketConnectableStruct()
96 	{
97 		return cast(GSocketConnectable*)getStruct();
98 	}
99 
100 
101 	/**
102 	 * Creates a #GSocketAddressEnumerator for @connectable.
103 	 *
104 	 * Return: a new #GSocketAddressEnumerator.
105 	 *
106 	 * Since: 2.22
107 	 */
108 	public SocketAddressEnumerator enumerate()
109 	{
110 		auto p = g_socket_connectable_enumerate(getSocketConnectableStruct());
111 		
112 		if(p is null)
113 		{
114 			return null;
115 		}
116 		
117 		return ObjectG.getDObject!(SocketAddressEnumerator)(cast(GSocketAddressEnumerator*) p, true);
118 	}
119 
120 	/**
121 	 * Creates a #GSocketAddressEnumerator for @connectable that will
122 	 * return #GProxyAddresses for addresses that you must connect
123 	 * to via a proxy.
124 	 *
125 	 * If @connectable does not implement
126 	 * g_socket_connectable_proxy_enumerate(), this will fall back to
127 	 * calling g_socket_connectable_enumerate().
128 	 *
129 	 * Return: a new #GSocketAddressEnumerator.
130 	 *
131 	 * Since: 2.26
132 	 */
133 	public SocketAddressEnumerator proxyEnumerate()
134 	{
135 		auto p = g_socket_connectable_proxy_enumerate(getSocketConnectableStruct());
136 		
137 		if(p is null)
138 		{
139 			return null;
140 		}
141 		
142 		return ObjectG.getDObject!(SocketAddressEnumerator)(cast(GSocketAddressEnumerator*) p, true);
143 	}
144 }