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