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