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.SocketAddressEnumerator;
26 
27 private import gio.AsyncResultIF;
28 private import gio.Cancellable;
29 private import gio.SocketAddress;
30 private import gio.c.functions;
31 public  import gio.c.types;
32 private import glib.ErrorG;
33 private import glib.GException;
34 private import gobject.ObjectG;
35 public  import gtkc.giotypes;
36 
37 
38 /**
39  * #GSocketAddressEnumerator is an enumerator type for #GSocketAddress
40  * instances. It is returned by enumeration functions such as
41  * g_socket_connectable_enumerate(), which returns a #GSocketAddressEnumerator
42  * to list each #GSocketAddress which could be used to connect to that
43  * #GSocketConnectable.
44  * 
45  * Enumeration is typically a blocking operation, so the asynchronous methods
46  * g_socket_address_enumerator_next_async() and
47  * g_socket_address_enumerator_next_finish() should be used where possible.
48  * 
49  * Each #GSocketAddressEnumerator can only be enumerated once. Once
50  * g_socket_address_enumerator_next() has returned %NULL (and no error), further
51  * enumeration with that #GSocketAddressEnumerator is not possible, and it can
52  * be unreffed.
53  */
54 public class SocketAddressEnumerator : ObjectG
55 {
56 	/** the main Gtk struct */
57 	protected GSocketAddressEnumerator* gSocketAddressEnumerator;
58 
59 	/** Get the main Gtk struct */
60 	public GSocketAddressEnumerator* getSocketAddressEnumeratorStruct(bool transferOwnership = false)
61 	{
62 		if (transferOwnership)
63 			ownedRef = false;
64 		return gSocketAddressEnumerator;
65 	}
66 
67 	/** the main Gtk struct as a void* */
68 	protected override void* getStruct()
69 	{
70 		return cast(void*)gSocketAddressEnumerator;
71 	}
72 
73 	/**
74 	 * Sets our main struct and passes it to the parent class.
75 	 */
76 	public this (GSocketAddressEnumerator* gSocketAddressEnumerator, bool ownedRef = false)
77 	{
78 		this.gSocketAddressEnumerator = gSocketAddressEnumerator;
79 		super(cast(GObject*)gSocketAddressEnumerator, ownedRef);
80 	}
81 
82 
83 	/** */
84 	public static GType getType()
85 	{
86 		return g_socket_address_enumerator_get_type();
87 	}
88 
89 	/**
90 	 * Retrieves the next #GSocketAddress from @enumerator. Note that this
91 	 * may block for some amount of time. (Eg, a #GNetworkAddress may need
92 	 * to do a DNS lookup before it can return an address.) Use
93 	 * g_socket_address_enumerator_next_async() if you need to avoid
94 	 * blocking.
95 	 *
96 	 * If @enumerator is expected to yield addresses, but for some reason
97 	 * is unable to (eg, because of a DNS error), then the first call to
98 	 * g_socket_address_enumerator_next() will return an appropriate error
99 	 * in *@error. However, if the first call to
100 	 * g_socket_address_enumerator_next() succeeds, then any further
101 	 * internal errors (other than @cancellable being triggered) will be
102 	 * ignored.
103 	 *
104 	 * Params:
105 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
106 	 *
107 	 * Returns: a #GSocketAddress (owned by the caller), or %NULL on
108 	 *     error (in which case *@error will be set) or if there are no
109 	 *     more addresses.
110 	 *
111 	 * Throws: GException on failure.
112 	 */
113 	public SocketAddress next(Cancellable cancellable)
114 	{
115 		GError* err = null;
116 
117 		auto __p = g_socket_address_enumerator_next(gSocketAddressEnumerator, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
118 
119 		if (err !is null)
120 		{
121 			throw new GException( new ErrorG(err) );
122 		}
123 
124 		if(__p is null)
125 		{
126 			return null;
127 		}
128 
129 		return ObjectG.getDObject!(SocketAddress)(cast(GSocketAddress*) __p, true);
130 	}
131 
132 	/**
133 	 * Asynchronously retrieves the next #GSocketAddress from @enumerator
134 	 * and then calls @callback, which must call
135 	 * g_socket_address_enumerator_next_finish() to get the result.
136 	 *
137 	 * It is an error to call this multiple times before the previous callback has finished.
138 	 *
139 	 * Params:
140 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
141 	 *     callback = a #GAsyncReadyCallback to call when the request
142 	 *         is satisfied
143 	 *     userData = the data to pass to callback function
144 	 */
145 	public void nextAsync(Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
146 	{
147 		g_socket_address_enumerator_next_async(gSocketAddressEnumerator, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
148 	}
149 
150 	/**
151 	 * Retrieves the result of a completed call to
152 	 * g_socket_address_enumerator_next_async(). See
153 	 * g_socket_address_enumerator_next() for more information about
154 	 * error handling.
155 	 *
156 	 * Params:
157 	 *     result = a #GAsyncResult
158 	 *
159 	 * Returns: a #GSocketAddress (owned by the caller), or %NULL on
160 	 *     error (in which case *@error will be set) or if there are no
161 	 *     more addresses.
162 	 *
163 	 * Throws: GException on failure.
164 	 */
165 	public SocketAddress nextFinish(AsyncResultIF result)
166 	{
167 		GError* err = null;
168 
169 		auto __p = g_socket_address_enumerator_next_finish(gSocketAddressEnumerator, (result is null) ? null : result.getAsyncResultStruct(), &err);
170 
171 		if (err !is null)
172 		{
173 			throw new GException( new ErrorG(err) );
174 		}
175 
176 		if(__p is null)
177 		{
178 			return null;
179 		}
180 
181 		return ObjectG.getDObject!(SocketAddress)(cast(GSocketAddress*) __p, true);
182 	}
183 }