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.AsyncInitableIF;
26 
27 private import gio.AsyncResultIF;
28 private import gio.Cancellable;
29 private import glib.ErrorG;
30 private import glib.GException;
31 private import glib.Str;
32 private import gobject.ObjectG;
33 private import gtkc.gio;
34 public  import gtkc.giotypes;
35 
36 
37 /**
38  * This is the asynchronous version of #GInitable; it behaves the same
39  * in all ways except that initialization is asynchronous. For more details
40  * see the descriptions on #GInitable.
41  * 
42  * A class may implement both the #GInitable and #GAsyncInitable interfaces.
43  * 
44  * Users of objects implementing this are not intended to use the interface
45  * method directly; instead it will be used automatically in various ways.
46  * For C applications you generally just call g_async_initable_new_async()
47  * directly, or indirectly via a foo_thing_new_async() wrapper. This will call
48  * g_async_initable_init_async() under the cover, calling back with %NULL and
49  * a set %GError on failure.
50  * 
51  * A typical implementation might look something like this:
52  * 
53  * |[<!-- language="C" -->
54  * enum {
55  * NOT_INITIALIZED,
56  * INITIALIZING,
57  * INITIALIZED
58  * };
59  * 
60  * static void
61  * _foo_ready_cb (Foo *self)
62  * {
63  * GList *l;
64  * 
65  * self->priv->state = INITIALIZED;
66  * 
67  * for (l = self->priv->init_results; l != NULL; l = l->next)
68  * {
69  * GTask *task = l->data;
70  * 
71  * if (self->priv->success)
72  * g_task_return_boolean (task, TRUE);
73  * else
74  * g_task_return_new_error (task, ...);
75  * g_object_unref (task);
76  * }
77  * 
78  * g_list_free (self->priv->init_results);
79  * self->priv->init_results = NULL;
80  * }
81  * 
82  * static void
83  * foo_init_async (GAsyncInitable       *initable,
84  * int                   io_priority,
85  * GCancellable         *cancellable,
86  * GAsyncReadyCallback   callback,
87  * gpointer              user_data)
88  * {
89  * Foo *self = FOO (initable);
90  * GTask *task;
91  * 
92  * task = g_task_new (initable, cancellable, callback, user_data);
93  * 
94  * switch (self->priv->state)
95  * {
96  * case NOT_INITIALIZED:
97  * _foo_get_ready (self);
98  * self->priv->init_results = g_list_append (self->priv->init_results,
99  * task);
100  * self->priv->state = INITIALIZING;
101  * break;
102  * case INITIALIZING:
103  * self->priv->init_results = g_list_append (self->priv->init_results,
104  * task);
105  * break;
106  * case INITIALIZED:
107  * if (!self->priv->success)
108  * g_task_return_new_error (task, ...);
109  * else
110  * g_task_return_boolean (task, TRUE);
111  * g_object_unref (task);
112  * break;
113  * }
114  * }
115  * 
116  * static gboolean
117  * foo_init_finish (GAsyncInitable       *initable,
118  * GAsyncResult         *result,
119  * GError              **error)
120  * {
121  * g_return_val_if_fail (g_task_is_valid (result, initable), FALSE);
122  * 
123  * return g_task_propagate_boolean (G_TASK (result), error);
124  * }
125  * 
126  * static void
127  * foo_async_initable_iface_init (gpointer g_iface,
128  * gpointer data)
129  * {
130  * GAsyncInitableIface *iface = g_iface;
131  * 
132  * iface->init_async = foo_init_async;
133  * iface->init_finish = foo_init_finish;
134  * }
135  * ]|
136  *
137  * Since: 2.22
138  */
139 public interface AsyncInitableIF{
140 	/** Get the main Gtk struct */
141 	public GAsyncInitable* getAsyncInitableStruct();
142 
143 	/** the main Gtk struct as a void* */
144 	protected void* getStruct();
145 
146 	/**
147 	 */
148 
149 	/**
150 	 * Helper function for constructing #GAsyncInitable object. This is
151 	 * similar to g_object_new_valist() but also initializes the object
152 	 * asynchronously.
153 	 *
154 	 * When the initialization is finished, @callback will be called. You can
155 	 * then call g_async_initable_new_finish() to get the new object and check
156 	 * for any errors.
157 	 *
158 	 * Params:
159 	 *     objectType = a #GType supporting #GAsyncInitable.
160 	 *     firstPropertyName = the name of the first property, followed by
161 	 *         the value, and other property value pairs, and ended by %NULL.
162 	 *     varArgs = The var args list generated from @first_property_name.
163 	 *     ioPriority = the [I/O priority][io-priority] of the operation
164 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
165 	 *     callback = a #GAsyncReadyCallback to call when the initialization is
166 	 *         finished
167 	 *     userData = the data to pass to callback function
168 	 *
169 	 * Since: 2.22
170 	 */
171 	public static void newValistAsync(GType objectType, string firstPropertyName, void* varArgs, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData);
172 
173 	/**
174 	 * Helper function for constructing #GAsyncInitable object. This is
175 	 * similar to g_object_newv() but also initializes the object asynchronously.
176 	 *
177 	 * When the initialization is finished, @callback will be called. You can
178 	 * then call g_async_initable_new_finish() to get the new object and check
179 	 * for any errors.
180 	 *
181 	 * Params:
182 	 *     objectType = a #GType supporting #GAsyncInitable.
183 	 *     nParameters = the number of parameters in @parameters
184 	 *     parameters = the parameters to use to construct the object
185 	 *     ioPriority = the [I/O priority][io-priority] of the operation
186 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
187 	 *     callback = a #GAsyncReadyCallback to call when the initialization is
188 	 *         finished
189 	 *     userData = the data to pass to callback function
190 	 *
191 	 * Since: 2.22
192 	 */
193 	public static void newvAsync(GType objectType, uint nParameters, GParameter* parameters, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData);
194 
195 	/**
196 	 * Starts asynchronous initialization of the object implementing the
197 	 * interface. This must be done before any real use of the object after
198 	 * initial construction. If the object also implements #GInitable you can
199 	 * optionally call g_initable_init() instead.
200 	 *
201 	 * When the initialization is finished, @callback will be called. You can
202 	 * then call g_async_initable_init_finish() to get the result of the
203 	 * initialization.
204 	 *
205 	 * Implementations may also support cancellation. If @cancellable is not
206 	 * %NULL, then initialization can be cancelled by triggering the cancellable
207 	 * object from another thread. If the operation was cancelled, the error
208 	 * %G_IO_ERROR_CANCELLED will be returned. If @cancellable is not %NULL, and
209 	 * the object doesn't support cancellable initialization, the error
210 	 * %G_IO_ERROR_NOT_SUPPORTED will be returned.
211 	 *
212 	 * As with #GInitable, if the object is not initialized, or initialization
213 	 * returns with an error, then all operations on the object except
214 	 * g_object_ref() and g_object_unref() are considered to be invalid, and
215 	 * have undefined behaviour. They will often fail with g_critical() or
216 	 * g_warning(), but this must not be relied on.
217 	 *
218 	 * Implementations of this method must be idempotent: i.e. multiple calls
219 	 * to this function with the same argument should return the same results.
220 	 * Only the first call initializes the object; further calls return the result
221 	 * of the first call. This is so that it's safe to implement the singleton
222 	 * pattern in the GObject constructor function.
223 	 *
224 	 * For classes that also support the #GInitable interface, the default
225 	 * implementation of this method will run the g_initable_init() function
226 	 * in a thread, so if you want to support asynchronous initialization via
227 	 * threads, just implement the #GAsyncInitable interface without overriding
228 	 * any interface methods.
229 	 *
230 	 * Params:
231 	 *     ioPriority = the [I/O priority][io-priority] of the operation
232 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
233 	 *     callback = a #GAsyncReadyCallback to call when the request is satisfied
234 	 *     userData = the data to pass to callback function
235 	 *
236 	 * Since: 2.22
237 	 */
238 	public void initAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData);
239 
240 	/**
241 	 * Finishes asynchronous initialization and returns the result.
242 	 * See g_async_initable_init_async().
243 	 *
244 	 * Params:
245 	 *     res = a #GAsyncResult.
246 	 *
247 	 * Return: %TRUE if successful. If an error has occurred, this function
248 	 *     will return %FALSE and set @error appropriately if present.
249 	 *
250 	 * Since: 2.22
251 	 *
252 	 * Throws: GException on failure.
253 	 */
254 	public bool initFinish(AsyncResultIF res);
255 
256 	/**
257 	 * Finishes the async construction for the various g_async_initable_new
258 	 * calls, returning the created object or %NULL on error.
259 	 *
260 	 * Params:
261 	 *     res = the #GAsyncResult from the callback
262 	 *
263 	 * Return: a newly created #GObject,
264 	 *     or %NULL on error. Free with g_object_unref().
265 	 *
266 	 * Since: 2.22
267 	 *
268 	 * Throws: GException on failure.
269 	 */
270 	public ObjectG newFinish(AsyncResultIF res);
271 }