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