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  * Conversion parameters:
26  * inFile  = GSimpleAsyncResult.html
27  * outPack = gio
28  * outFile = SimpleAsyncResult
29  * strct   = GSimpleAsyncResult
30  * realStrct=
31  * ctorStrct=
32  * clss    = SimpleAsyncResult
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * 	- AsyncResultIF
40  * prefixes:
41  * 	- g_simple_async_result_
42  * 	- g_
43  * omit structs:
44  * omit prefixes:
45  * omit code:
46  * 	- g_simple_async_result_new_take_error
47  * omit signals:
48  * imports:
49  * 	- glib.Str
50  * 	- glib.ErrorG
51  * 	- glib.GException
52  * 	- gobject.ObjectG
53  * 	- gio.Cancellable
54  * 	- gio.AsyncResultIF
55  * 	- gio.AsyncResultT
56  * structWrap:
57  * 	- GCancellable* -> Cancellable
58  * 	- GError* -> ErrorG
59  * 	- GObject* -> ObjectG
60  * module aliases:
61  * local aliases:
62  * overrides:
63  */
64 
65 module gio.SimpleAsyncResult;
66 
67 public  import gtkc.giotypes;
68 
69 private import gtkc.gio;
70 private import glib.ConstructionException;
71 private import gobject.ObjectG;
72 
73 private import glib.Str;
74 private import glib.ErrorG;
75 private import glib.GException;
76 private import gobject.ObjectG;
77 private import gio.Cancellable;
78 private import gio.AsyncResultIF;
79 private import gio.AsyncResultT;
80 
81 
82 private import gobject.ObjectG;
83 
84 /**
85  * Note
86  *
87  *  As of GLib 2.36, GSimpleAsyncResult is deprecated in favor of
88  *  GTask, which provides a simpler API.
89  *
90  * GSimpleAsyncResult implements GAsyncResult.
91  *
92  * GSimpleAsyncResult handles GAsyncReadyCallbacks, error
93  * reporting, operation cancellation and the final state of an operation,
94  * completely transparent to the application. Results can be returned
95  * as a pointer e.g. for functions that return data that is collected
96  * asynchronously, a boolean value for checking the success or failure
97  * of an operation, or a gssize for operations which return the number
98  * of bytes modified by the operation; all of the simple return cases
99  * are covered.
100  *
101  * Most of the time, an application will not need to know of the details
102  * of this API; it is handled transparently, and any necessary operations
103  * are handled by GAsyncResult's interface. However, if implementing a
104  * new GIO module, for writing language bindings, or for complex
105  * applications that need better control of how asynchronous operations
106  * are completed, it is important to understand this functionality.
107  *
108  * GSimpleAsyncResults are tagged with the calling function to ensure
109  * that asynchronous functions and their finishing functions are used
110  * together correctly.
111  *
112  * To create a new GSimpleAsyncResult, call g_simple_async_result_new().
113  * If the result needs to be created for a GError, use
114  * g_simple_async_result_new_from_error() or
115  * g_simple_async_result_new_take_error(). If a GError is not available
116  * (e.g. the asynchronous operation's doesn't take a GError argument),
117  * but the result still needs to be created for an error condition, use
118  * g_simple_async_result_new_error() (or g_simple_async_result_set_error_va()
119  * if your application or binding requires passing a variable argument list
120  * directly), and the error can then be propagated through the use of
121  * g_simple_async_result_propagate_error().
122  *
123  * An asynchronous operation can be made to ignore a cancellation event by
124  * calling g_simple_async_result_set_handle_cancellation() with a
125  * GSimpleAsyncResult for the operation and FALSE. This is useful for
126  * operations that are dangerous to cancel, such as close (which would
127  * cause a leak if cancelled before being run).
128  *
129  * GSimpleAsyncResult can integrate into GLib's event loop, GMainLoop,
130  * or it can use GThreads.
131  * g_simple_async_result_complete() will finish an I/O task directly
132  * from the point where it is called. g_simple_async_result_complete_in_idle()
133  * will finish it from an idle handler in the thread-default main
134  * context. g_simple_async_result_run_in_thread() will run the
135  * job in a separate thread and then deliver the result to the
136  * thread-default main context.
137  *
138  * To set the results of an asynchronous function,
139  * g_simple_async_result_set_op_res_gpointer(),
140  * g_simple_async_result_set_op_res_gboolean(), and
141  * g_simple_async_result_set_op_res_gssize()
142  * are provided, setting the operation's result to a gpointer, gboolean, or
143  * gssize, respectively.
144  *
145  * Likewise, to get the result of an asynchronous function,
146  * g_simple_async_result_get_op_res_gpointer(),
147  * g_simple_async_result_get_op_res_gboolean(), and
148  * g_simple_async_result_get_op_res_gssize() are
149  * provided, getting the operation's result as a gpointer, gboolean, and
150  * gssize, respectively.
151  *
152  * For the details of the requirements implementations must respect, see
153  * GAsyncResult. A typical implementation of an asynchronous operation
154  * using GSimpleAsyncResult looks something like this:
155  *
156  * $(DDOC_COMMENT example)
157  */
158 public class SimpleAsyncResult : ObjectG, AsyncResultIF
159 {
160 	
161 	/** the main Gtk struct */
162 	protected GSimpleAsyncResult* gSimpleAsyncResult;
163 	
164 	
165 	/** Get the main Gtk struct */
166 	public GSimpleAsyncResult* getSimpleAsyncResultStruct()
167 	{
168 		return gSimpleAsyncResult;
169 	}
170 	
171 	
172 	/** the main Gtk struct as a void* */
173 	protected override void* getStruct()
174 	{
175 		return cast(void*)gSimpleAsyncResult;
176 	}
177 	
178 	/**
179 	 * Sets our main struct and passes it to the parent class
180 	 */
181 	public this (GSimpleAsyncResult* gSimpleAsyncResult)
182 	{
183 		super(cast(GObject*)gSimpleAsyncResult);
184 		this.gSimpleAsyncResult = gSimpleAsyncResult;
185 	}
186 	
187 	protected override void setStruct(GObject* obj)
188 	{
189 		super.setStruct(obj);
190 		gSimpleAsyncResult = cast(GSimpleAsyncResult*)obj;
191 	}
192 	
193 	// add the AsyncResult capabilities
194 	mixin AsyncResultT!(GSimpleAsyncResult);
195 	
196 	/**
197 	 */
198 	
199 	/**
200 	 * Creates a GSimpleAsyncResult.
201 	 * The common convention is to create the GSimpleAsyncResult in the
202 	 * function that starts the asynchronous operation and use that same
203 	 * function as the source_tag.
204 	 * If your operation supports cancellation with GCancellable (which it
205 	 * probably should) then you should provide the user's cancellable to
206 	 * g_simple_async_result_set_check_cancellable() immediately after
207 	 * this function returns.
208 	 * Params:
209 	 * sourceObject = a GObject, or NULL. [allow-none]
210 	 * callback = a GAsyncReadyCallback. [scope async]
211 	 * userData = user data passed to callback. [closure]
212 	 * sourceTag = the asynchronous function.
213 	 * Throws: ConstructionException GTK+ fails to create the object.
214 	 */
215 	public this (ObjectG sourceObject, GAsyncReadyCallback callback, void* userData, void* sourceTag)
216 	{
217 		// GSimpleAsyncResult * g_simple_async_result_new (GObject *source_object,  GAsyncReadyCallback callback,  gpointer user_data,  gpointer source_tag);
218 		auto p = g_simple_async_result_new((sourceObject is null) ? null : sourceObject.getObjectGStruct(), callback, userData, sourceTag);
219 		if(p is null)
220 		{
221 			throw new ConstructionException("null returned by g_simple_async_result_new((sourceObject is null) ? null : sourceObject.getObjectGStruct(), callback, userData, sourceTag)");
222 		}
223 		this(cast(GSimpleAsyncResult*) p);
224 	}
225 	
226 	/**
227 	 * Creates a GSimpleAsyncResult from an error condition.
228 	 * Params:
229 	 * sourceObject = a GObject, or NULL. [allow-none]
230 	 * callback = a GAsyncReadyCallback. [scope async]
231 	 * userData = user data passed to callback. [closure]
232 	 * error = a GError
233 	 * Throws: ConstructionException GTK+ fails to create the object.
234 	 */
235 	public this (ObjectG sourceObject, GAsyncReadyCallback callback, void* userData, ErrorG error)
236 	{
237 		// GSimpleAsyncResult * g_simple_async_result_new_from_error  (GObject *source_object,  GAsyncReadyCallback callback,  gpointer user_data,  const GError *error);
238 		auto p = g_simple_async_result_new_from_error((sourceObject is null) ? null : sourceObject.getObjectGStruct(), callback, userData, (error is null) ? null : error.getErrorGStruct());
239 		if(p is null)
240 		{
241 			throw new ConstructionException("null returned by g_simple_async_result_new_from_error((sourceObject is null) ? null : sourceObject.getObjectGStruct(), callback, userData, (error is null) ? null : error.getErrorGStruct())");
242 		}
243 		this(cast(GSimpleAsyncResult*) p);
244 	}
245 	
246 	/**
247 	 * Sets a GCancellable to check before dispatching results.
248 	 * This function has one very specific purpose: the provided cancellable
249 	 * is checked at the time of g_simple_async_result_propagate_error() If
250 	 * it is cancelled, these functions will return an "Operation was
251 	 * cancelled" error (G_IO_ERROR_CANCELLED).
252 	 * Implementors of cancellable asynchronous functions should use this in
253 	 * order to provide a guarantee to their callers that cancelling an
254 	 * async operation will reliably result in an error being returned for
255 	 * that operation (even if a positive result for the operation has
256 	 * already been sent as an idle to the main context to be dispatched).
257 	 * The checking described above is done regardless of any call to the
258 	 * unrelated g_simple_async_result_set_handle_cancellation() function.
259 	 * Since 2.32
260 	 * Params:
261 	 * checkCancellable = a GCancellable to check, or NULL to unset. [allow-none]
262 	 */
263 	public void setCheckCancellable(Cancellable checkCancellable)
264 	{
265 		// void g_simple_async_result_set_check_cancellable  (GSimpleAsyncResult *simple,  GCancellable *check_cancellable);
266 		g_simple_async_result_set_check_cancellable(gSimpleAsyncResult, (checkCancellable is null) ? null : checkCancellable.getCancellableStruct());
267 	}
268 	
269 	/**
270 	 * Sets the operation result within the asynchronous result to a pointer.
271 	 * Params:
272 	 * opRes = a pointer result from an asynchronous function.
273 	 * destroyOpRes = a GDestroyNotify function.
274 	 */
275 	public void setOpResGpointer(void* opRes, GDestroyNotify destroyOpRes)
276 	{
277 		// void g_simple_async_result_set_op_res_gpointer  (GSimpleAsyncResult *simple,  gpointer op_res,  GDestroyNotify destroy_op_res);
278 		g_simple_async_result_set_op_res_gpointer(gSimpleAsyncResult, opRes, destroyOpRes);
279 	}
280 	
281 	/**
282 	 * Gets a pointer result as returned by the asynchronous function.
283 	 * Returns: a pointer from the result.
284 	 */
285 	public void* getOpResGpointer()
286 	{
287 		// gpointer g_simple_async_result_get_op_res_gpointer  (GSimpleAsyncResult *simple);
288 		return g_simple_async_result_get_op_res_gpointer(gSimpleAsyncResult);
289 	}
290 	
291 	/**
292 	 * Sets the operation result within the asynchronous result to
293 	 * the given op_res.
294 	 * Params:
295 	 * opRes = a gssize.
296 	 */
297 	public void setOpResGssize(gssize opRes)
298 	{
299 		// void g_simple_async_result_set_op_res_gssize  (GSimpleAsyncResult *simple,  gssize op_res);
300 		g_simple_async_result_set_op_res_gssize(gSimpleAsyncResult, opRes);
301 	}
302 	
303 	/**
304 	 * Gets a gssize from the asynchronous result.
305 	 * Returns: a gssize returned from the asynchronous function.
306 	 */
307 	public gssize getOpResGssize()
308 	{
309 		// gssize g_simple_async_result_get_op_res_gssize  (GSimpleAsyncResult *simple);
310 		return g_simple_async_result_get_op_res_gssize(gSimpleAsyncResult);
311 	}
312 	
313 	/**
314 	 * Sets the operation result to a boolean within the asynchronous result.
315 	 * Params:
316 	 * opRes = a gboolean.
317 	 */
318 	public void setOpResGboolean(int opRes)
319 	{
320 		// void g_simple_async_result_set_op_res_gboolean  (GSimpleAsyncResult *simple,  gboolean op_res);
321 		g_simple_async_result_set_op_res_gboolean(gSimpleAsyncResult, opRes);
322 	}
323 	
324 	/**
325 	 * Gets the operation result boolean from within the asynchronous result.
326 	 * Returns: TRUE if the operation's result was TRUE, FALSE if the operation's result was FALSE.
327 	 */
328 	public int getOpResGboolean()
329 	{
330 		// gboolean g_simple_async_result_get_op_res_gboolean  (GSimpleAsyncResult *simple);
331 		return g_simple_async_result_get_op_res_gboolean(gSimpleAsyncResult);
332 	}
333 	
334 	/**
335 	 * Gets the source tag for the GSimpleAsyncResult.
336 	 * Returns: a gpointer to the source object for the GSimpleAsyncResult.
337 	 */
338 	public void* getSourceTag()
339 	{
340 		// gpointer g_simple_async_result_get_source_tag  (GSimpleAsyncResult *simple);
341 		return g_simple_async_result_get_source_tag(gSimpleAsyncResult);
342 	}
343 	
344 	/**
345 	 * Ensures that the data passed to the _finish function of an async
346 	 * operation is consistent. Three checks are performed.
347 	 * First, result is checked to ensure that it is really a
348 	 * GSimpleAsyncResult. Second, source is checked to ensure that it
349 	 * matches the source object of result. Third, source_tag is
350 	 * checked to ensure that it is either NULL (as it is when the result was
351 	 * created by g_simple_async_report_error_in_idle() or
352 	 * g_simple_async_report_gerror_in_idle()) or equal to the
353 	 * source_tag argument given to g_simple_async_result_new() (which, by
354 	 * convention, is a pointer to the _async function corresponding to the
355 	 * _finish function from which this function is called).
356 	 * Since 2.20
357 	 * Params:
358 	 * result = the GAsyncResult passed to the _finish function.
359 	 * source = the GObject passed to the _finish function.
360 	 * sourceTag = the asynchronous function.
361 	 * Returns: TRUE if all checks passed or FALSE if any failed.
362 	 */
363 	public static int isValid(GAsyncResult* result, ObjectG source, void* sourceTag)
364 	{
365 		// gboolean g_simple_async_result_is_valid (GAsyncResult *result,  GObject *source,  gpointer source_tag);
366 		return g_simple_async_result_is_valid(result, (source is null) ? null : source.getObjectGStruct(), sourceTag);
367 	}
368 	
369 	/**
370 	 * Sets whether to handle cancellation within the asynchronous operation.
371 	 * This function has nothing to do with
372 	 * g_simple_async_result_set_check_cancellable(). It only refers to the
373 	 * GCancellable passed to g_simple_async_result_run_in_thread().
374 	 * Params:
375 	 * handleCancellation = a gboolean.
376 	 */
377 	public void setHandleCancellation(int handleCancellation)
378 	{
379 		// void g_simple_async_result_set_handle_cancellation  (GSimpleAsyncResult *simple,  gboolean handle_cancellation);
380 		g_simple_async_result_set_handle_cancellation(gSimpleAsyncResult, handleCancellation);
381 	}
382 	
383 	/**
384 	 * Completes an asynchronous I/O job immediately. Must be called in
385 	 * the thread where the asynchronous result was to be delivered, as it
386 	 * invokes the callback directly. If you are in a different thread use
387 	 * g_simple_async_result_complete_in_idle().
388 	 * Calling this function takes a reference to simple for as long as
389 	 * is needed to complete the call.
390 	 */
391 	public void complete()
392 	{
393 		// void g_simple_async_result_complete (GSimpleAsyncResult *simple);
394 		g_simple_async_result_complete(gSimpleAsyncResult);
395 	}
396 	
397 	/**
398 	 * Completes an asynchronous function in an idle handler in the thread-default main
399 	 * loop of the thread that simple was initially created in
400 	 * (and re-pushes that context around the invocation of the callback).
401 	 * Calling this function takes a reference to simple for as long as
402 	 * is needed to complete the call.
403 	 */
404 	public void completeInIdle()
405 	{
406 		// void g_simple_async_result_complete_in_idle  (GSimpleAsyncResult *simple);
407 		g_simple_async_result_complete_in_idle(gSimpleAsyncResult);
408 	}
409 	
410 	/**
411 	 * Runs the asynchronous job in a separate thread and then calls
412 	 * g_simple_async_result_complete_in_idle() on simple to return
413 	 * the result to the appropriate main loop.
414 	 * Calling this function takes a reference to simple for as long as
415 	 * is needed to run the job and report its completion.
416 	 * Params:
417 	 * func = a GSimpleAsyncThreadFunc.
418 	 * ioPriority = the io priority of the request.
419 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
420 	 */
421 	public void runInThread(GSimpleAsyncThreadFunc func, int ioPriority, Cancellable cancellable)
422 	{
423 		// void g_simple_async_result_run_in_thread (GSimpleAsyncResult *simple,  GSimpleAsyncThreadFunc func,  int io_priority,  GCancellable *cancellable);
424 		g_simple_async_result_run_in_thread(gSimpleAsyncResult, func, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct());
425 	}
426 	
427 	/**
428 	 * Sets the result from a GError.
429 	 * Params:
430 	 * error = GError.
431 	 */
432 	public void setFromError(ErrorG error)
433 	{
434 		// void g_simple_async_result_set_from_error  (GSimpleAsyncResult *simple,  const GError *error);
435 		g_simple_async_result_set_from_error(gSimpleAsyncResult, (error is null) ? null : error.getErrorGStruct());
436 	}
437 	
438 	/**
439 	 * Sets the result from error, and takes over the caller's ownership
440 	 * of error, so the caller does not need to free it any more.
441 	 * Since 2.28
442 	 * Params:
443 	 * error = a GError
444 	 */
445 	public void takeError(ErrorG error)
446 	{
447 		// void g_simple_async_result_take_error (GSimpleAsyncResult *simple,  GError *error);
448 		g_simple_async_result_take_error(gSimpleAsyncResult, (error is null) ? null : error.getErrorGStruct());
449 	}
450 	
451 	/**
452 	 * Propagates an error from within the simple asynchronous result to
453 	 * a given destination.
454 	 * If the GCancellable given to a prior call to
455 	 * g_simple_async_result_set_check_cancellable() is cancelled then this
456 	 * function will return TRUE with dest set appropriately.
457 	 * Returns: TRUE if the error was propagated to dest. FALSE otherwise.
458 	 */
459 	public int propagateError()
460 	{
461 		// gboolean g_simple_async_result_propagate_error  (GSimpleAsyncResult *simple,  GError **dest);
462 		GError* err = null;
463 		
464 		auto p = g_simple_async_result_propagate_error(gSimpleAsyncResult, &err);
465 		
466 		if (err !is null)
467 		{
468 			throw new GException( new ErrorG(err) );
469 		}
470 		
471 		return p;
472 	}
473 	
474 	/**
475 	 * Sets an error within the asynchronous result without a GError.
476 	 * Unless writing a binding, see g_simple_async_result_set_error().
477 	 * Params:
478 	 * domain = a GQuark (usually G_IO_ERROR).
479 	 * code = an error code.
480 	 * format = a formatted error reporting string.
481 	 * args = va_list of arguments.
482 	 */
483 	public void setErrorVa(GQuark domain, int code, string format, void* args)
484 	{
485 		// void g_simple_async_result_set_error_va (GSimpleAsyncResult *simple,  GQuark domain,  gint code,  const char *format,  va_list args);
486 		g_simple_async_result_set_error_va(gSimpleAsyncResult, domain, code, Str.toStringz(format), args);
487 	}
488 	
489 	/**
490 	 * Reports an error in an idle function. Similar to
491 	 * g_simple_async_report_error_in_idle(), but takes a GError rather
492 	 * than building a new one.
493 	 * Params:
494 	 * object = a GObject, or NULL. [allow-none]
495 	 * callback = a GAsyncReadyCallback. [scope async]
496 	 * userData = user data passed to callback. [closure]
497 	 * error = the GError to report
498 	 */
499 	public static void simpleAsyncReportGerrorInIdle(ObjectG object, GAsyncReadyCallback callback, void* userData, ErrorG error)
500 	{
501 		// void g_simple_async_report_gerror_in_idle  (GObject *object,  GAsyncReadyCallback callback,  gpointer user_data,  const GError *error);
502 		g_simple_async_report_gerror_in_idle((object is null) ? null : object.getObjectGStruct(), callback, userData, (error is null) ? null : error.getErrorGStruct());
503 	}
504 	
505 	/**
506 	 * Reports an error in an idle function. Similar to
507 	 * g_simple_async_report_gerror_in_idle(), but takes over the caller's
508 	 * ownership of error, so the caller does not have to free it any more.
509 	 * Since 2.28
510 	 * Params:
511 	 * object = a GObject, or NULL. [allow-none]
512 	 * callback = a GAsyncReadyCallback.
513 	 * userData = user data passed to callback.
514 	 * error = the GError to report
515 	 */
516 	public static void simpleAsyncReportTakeGerrorInIdle(ObjectG object, GAsyncReadyCallback callback, void* userData, ErrorG error)
517 	{
518 		// void g_simple_async_report_take_gerror_in_idle  (GObject *object,  GAsyncReadyCallback callback,  gpointer user_data,  GError *error);
519 		g_simple_async_report_take_gerror_in_idle((object is null) ? null : object.getObjectGStruct(), callback, userData, (error is null) ? null : error.getErrorGStruct());
520 	}
521 }