source: appstream-generator/build/girepo/gio/SimpleAsyncResult.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 20.5 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module gio.SimpleAsyncResult;
22
23private import gi.gio;
24public  import gi.giotypes;
25private import gio.AsyncResultIF;
26private import gio.AsyncResultT;
27private import gio.Cancellable;
28private import glib.ConstructionException;
29private import glib.ErrorG;
30private import glib.GException;
31private import glib.Str;
32private import gobject.ObjectG;
33
34
35/**
36 * As of GLib 2.46, #GSimpleAsyncResult is deprecated in favor of
37 * #GTask, which provides a simpler API.
38 *
39 * #GSimpleAsyncResult implements #GAsyncResult.
40 *
41 * GSimpleAsyncResult handles #GAsyncReadyCallbacks, error
42 * reporting, operation cancellation and the final state of an operation,
43 * completely transparent to the application. Results can be returned
44 * as a pointer e.g. for functions that return data that is collected
45 * asynchronously, a boolean value for checking the success or failure
46 * of an operation, or a #gssize for operations which return the number
47 * of bytes modified by the operation; all of the simple return cases
48 * are covered.
49 *
50 * Most of the time, an application will not need to know of the details
51 * of this API; it is handled transparently, and any necessary operations
52 * are handled by #GAsyncResult's interface. However, if implementing a
53 * new GIO module, for writing language bindings, or for complex
54 * applications that need better control of how asynchronous operations
55 * are completed, it is important to understand this functionality.
56 *
57 * GSimpleAsyncResults are tagged with the calling function to ensure
58 * that asynchronous functions and their finishing functions are used
59 * together correctly.
60 *
61 * To create a new #GSimpleAsyncResult, call g_simple_async_result_new().
62 * If the result needs to be created for a #GError, use
63 * g_simple_async_result_new_from_error() or
64 * g_simple_async_result_new_take_error(). If a #GError is not available
65 * (e.g. the asynchronous operation's doesn't take a #GError argument),
66 * but the result still needs to be created for an error condition, use
67 * g_simple_async_result_new_error() (or g_simple_async_result_set_error_va()
68 * if your application or binding requires passing a variable argument list
69 * directly), and the error can then be propagated through the use of
70 * g_simple_async_result_propagate_error().
71 *
72 * An asynchronous operation can be made to ignore a cancellation event by
73 * calling g_simple_async_result_set_handle_cancellation() with a
74 * #GSimpleAsyncResult for the operation and %FALSE. This is useful for
75 * operations that are dangerous to cancel, such as close (which would
76 * cause a leak if cancelled before being run).
77 *
78 * GSimpleAsyncResult can integrate into GLib's event loop, #GMainLoop,
79 * or it can use #GThreads.
80 * g_simple_async_result_complete() will finish an I/O task directly
81 * from the point where it is called. g_simple_async_result_complete_in_idle()
82 * will finish it from an idle handler in the
83 * [thread-default main context][g-main-context-push-thread-default]
84 * . g_simple_async_result_run_in_thread() will run the
85 * job in a separate thread and then deliver the result to the
86 * thread-default main context.
87 *
88 * To set the results of an asynchronous function,
89 * g_simple_async_result_set_op_res_gpointer(),
90 * g_simple_async_result_set_op_res_gboolean(), and
91 * g_simple_async_result_set_op_res_gssize()
92 * are provided, setting the operation's result to a gpointer, gboolean, or
93 * gssize, respectively.
94 *
95 * Likewise, to get the result of an asynchronous function,
96 * g_simple_async_result_get_op_res_gpointer(),
97 * g_simple_async_result_get_op_res_gboolean(), and
98 * g_simple_async_result_get_op_res_gssize() are
99 * provided, getting the operation's result as a gpointer, gboolean, and
100 * gssize, respectively.
101 *
102 * For the details of the requirements implementations must respect, see
103 * #GAsyncResult.  A typical implementation of an asynchronous operation
104 * using GSimpleAsyncResult looks something like this:
105 *
106 * |[<!-- language="C" -->
107 * static void
108 * baked_cb (Cake    *cake,
109 * gpointer user_data)
110 * {
111 * // In this example, this callback is not given a reference to the cake,
112 * // so the GSimpleAsyncResult has to take a reference to it.
113 * GSimpleAsyncResult *result = user_data;
114 *
115 * if (cake == NULL)
116 * g_simple_async_result_set_error (result,
117 * BAKER_ERRORS,
118 * BAKER_ERROR_NO_FLOUR,
119 * "Go to the supermarket");
120 * else
121 * g_simple_async_result_set_op_res_gpointer (result,
122 * g_object_ref (cake),
123 * g_object_unref);
124 *
125 *
126 * // In this example, we assume that baked_cb is called as a callback from
127 * // the mainloop, so it's safe to complete the operation synchronously here.
128 * // If, however, _baker_prepare_cake () might call its callback without
129 * // first returning to the mainloop — inadvisable, but some APIs do so —
130 * // we would need to use g_simple_async_result_complete_in_idle().
131 * g_simple_async_result_complete (result);
132 * g_object_unref (result);
133 * }
134 *
135 * void
136 * baker_bake_cake_async (Baker              *self,
137 * guint               radius,
138 * GAsyncReadyCallback callback,
139 * gpointer            user_data)
140 * {
141 * GSimpleAsyncResult *simple;
142 * Cake               *cake;
143 *
144 * if (radius < 3)
145 * {
146 * g_simple_async_report_error_in_idle (G_OBJECT (self),
147 * callback,
148 * user_data,
149 * BAKER_ERRORS,
150 * BAKER_ERROR_TOO_SMALL,
151 * "%ucm radius cakes are silly",
152 * radius);
153 * return;
154 * }
155 *
156 * simple = g_simple_async_result_new (G_OBJECT (self),
157 * callback,
158 * user_data,
159 * baker_bake_cake_async);
160 * cake = _baker_get_cached_cake (self, radius);
161 *
162 * if (cake != NULL)
163 * {
164 * g_simple_async_result_set_op_res_gpointer (simple,
165 * g_object_ref (cake),
166 * g_object_unref);
167 * g_simple_async_result_complete_in_idle (simple);
168 * g_object_unref (simple);
169 * // Drop the reference returned by _baker_get_cached_cake();
170 * // the GSimpleAsyncResult has taken its own reference.
171 * g_object_unref (cake);
172 * return;
173 * }
174 *
175 * _baker_prepare_cake (self, radius, baked_cb, simple);
176 * }
177 *
178 * Cake *
179 * baker_bake_cake_finish (Baker        *self,
180 * GAsyncResult *result,
181 * GError      **error)
182 * {
183 * GSimpleAsyncResult *simple;
184 * Cake               *cake;
185 *
186 * g_return_val_if_fail (g_simple_async_result_is_valid (result,
187 * G_OBJECT (self),
188 * baker_bake_cake_async),
189 * NULL);
190 *
191 * simple = (GSimpleAsyncResult *) result;
192 *
193 * if (g_simple_async_result_propagate_error (simple, error))
194 * return NULL;
195 *
196 * cake = CAKE (g_simple_async_result_get_op_res_gpointer (simple));
197 * return g_object_ref (cake);
198 * }
199 * ]|
200 */
201public class SimpleAsyncResult : ObjectG, AsyncResultIF
202{
203        /** the main Gtk struct */
204        protected GSimpleAsyncResult* gSimpleAsyncResult;
205
206        /** Get the main Gtk struct */
207        public GSimpleAsyncResult* getSimpleAsyncResultStruct()
208        {
209                return gSimpleAsyncResult;
210        }
211
212        /** the main Gtk struct as a void* */
213        protected override void* getStruct()
214        {
215                return cast(void*)gSimpleAsyncResult;
216        }
217
218        protected override void setStruct(GObject* obj)
219        {
220                gSimpleAsyncResult = cast(GSimpleAsyncResult*)obj;
221                super.setStruct(obj);
222        }
223
224        /**
225         * Sets our main struct and passes it to the parent class.
226         */
227        public this (GSimpleAsyncResult* gSimpleAsyncResult, bool ownedRef = false)
228        {
229                this.gSimpleAsyncResult = gSimpleAsyncResult;
230                super(cast(GObject*)gSimpleAsyncResult, ownedRef);
231        }
232
233        // add the AsyncResult capabilities
234        mixin AsyncResultT!(GSimpleAsyncResult);
235
236
237        /** */
238        public static GType getType()
239        {
240                return g_simple_async_result_get_type();
241        }
242
243        /**
244         * Creates a #GSimpleAsyncResult.
245         *
246         * The common convention is to create the #GSimpleAsyncResult in the
247         * function that starts the asynchronous operation and use that same
248         * function as the @source_tag.
249         *
250         * If your operation supports cancellation with #GCancellable (which it
251         * probably should) then you should provide the user's cancellable to
252         * g_simple_async_result_set_check_cancellable() immediately after
253         * this function returns.
254         *
255         * Deprecated: Use g_task_new() instead.
256         *
257         * Params:
258         *     sourceObject = a #GObject, or %NULL.
259         *     callback = a #GAsyncReadyCallback.
260         *     userData = user data passed to @callback.
261         *     sourceTag = the asynchronous function.
262         *
263         * Returns: a #GSimpleAsyncResult.
264         *
265         * Throws: ConstructionException GTK+ fails to create the object.
266         */
267        public this(ObjectG sourceObject, GAsyncReadyCallback callback, void* userData, void* sourceTag)
268        {
269                auto p = g_simple_async_result_new((sourceObject is null) ? null : sourceObject.getObjectGStruct(), callback, userData, sourceTag);
270               
271                if(p is null)
272                {
273                        throw new ConstructionException("null returned by new");
274                }
275               
276                this(cast(GSimpleAsyncResult*) p, true);
277        }
278
279        /**
280         * Creates a #GSimpleAsyncResult from an error condition.
281         *
282         * Deprecated: Use g_task_new() and g_task_return_error() instead.
283         *
284         * Params:
285         *     sourceObject = a #GObject, or %NULL.
286         *     callback = a #GAsyncReadyCallback.
287         *     userData = user data passed to @callback.
288         *     error = a #GError
289         *
290         * Returns: a #GSimpleAsyncResult.
291         *
292         * Throws: ConstructionException GTK+ fails to create the object.
293         */
294        public this(ObjectG sourceObject, GAsyncReadyCallback callback, void* userData, ErrorG error)
295        {
296                auto p = g_simple_async_result_new_from_error((sourceObject is null) ? null : sourceObject.getObjectGStruct(), callback, userData, (error is null) ? null : error.getErrorGStruct());
297               
298                if(p is null)
299                {
300                        throw new ConstructionException("null returned by new_from_error");
301                }
302               
303                this(cast(GSimpleAsyncResult*) p, true);
304        }
305
306        /**
307         * Ensures that the data passed to the _finish function of an async
308         * operation is consistent.  Three checks are performed.
309         *
310         * First, @result is checked to ensure that it is really a
311         * #GSimpleAsyncResult.  Second, @source is checked to ensure that it
312         * matches the source object of @result.  Third, @source_tag is
313         * checked to ensure that it is equal to the @source_tag argument given
314         * to g_simple_async_result_new() (which, by convention, is a pointer
315         * to the _async function corresponding to the _finish function from
316         * which this function is called).  (Alternatively, if either
317         * @source_tag or @result's source tag is %NULL, then the source tag
318         * check is skipped.)
319         *
320         * Deprecated: Use #GTask and g_task_is_valid() instead.
321         *
322         * Params:
323         *     result = the #GAsyncResult passed to the _finish function.
324         *     source = the #GObject passed to the _finish function.
325         *     sourceTag = the asynchronous function.
326         *
327         * Returns: #TRUE if all checks passed or #FALSE if any failed.
328         *
329         * Since: 2.20
330         */
331        public static bool isValid(AsyncResultIF result, ObjectG source, void* sourceTag)
332        {
333                return g_simple_async_result_is_valid((result is null) ? null : result.getAsyncResultStruct(), (source is null) ? null : source.getObjectGStruct(), sourceTag) != 0;
334        }
335
336        /**
337         * Completes an asynchronous I/O job immediately. Must be called in
338         * the thread where the asynchronous result was to be delivered, as it
339         * invokes the callback directly. If you are in a different thread use
340         * g_simple_async_result_complete_in_idle().
341         *
342         * Calling this function takes a reference to @simple for as long as
343         * is needed to complete the call.
344         *
345         * Deprecated: Use #GTask instead.
346         */
347        public void complete()
348        {
349                g_simple_async_result_complete(gSimpleAsyncResult);
350        }
351
352        /**
353         * Completes an asynchronous function in an idle handler in the
354         * [thread-default main context][g-main-context-push-thread-default]
355         * of the thread that @simple was initially created in
356         * (and re-pushes that context around the invocation of the callback).
357         *
358         * Calling this function takes a reference to @simple for as long as
359         * is needed to complete the call.
360         *
361         * Deprecated: Use #GTask instead.
362         */
363        public void completeInIdle()
364        {
365                g_simple_async_result_complete_in_idle(gSimpleAsyncResult);
366        }
367
368        /**
369         * Gets the operation result boolean from within the asynchronous result.
370         *
371         * Deprecated: Use #GTask and g_task_propagate_boolean() instead.
372         *
373         * Returns: %TRUE if the operation's result was %TRUE, %FALSE
374         *     if the operation's result was %FALSE.
375         */
376        public bool getOpResGboolean()
377        {
378                return g_simple_async_result_get_op_res_gboolean(gSimpleAsyncResult) != 0;
379        }
380
381        /**
382         * Gets a pointer result as returned by the asynchronous function.
383         *
384         * Deprecated: Use #GTask and g_task_propagate_pointer() instead.
385         *
386         * Returns: a pointer from the result.
387         */
388        public void* getOpResGpointer()
389        {
390                return g_simple_async_result_get_op_res_gpointer(gSimpleAsyncResult);
391        }
392
393        /**
394         * Gets a gssize from the asynchronous result.
395         *
396         * Deprecated: Use #GTask and g_task_propagate_int() instead.
397         *
398         * Returns: a gssize returned from the asynchronous function.
399         */
400        public ptrdiff_t getOpResGssize()
401        {
402                return g_simple_async_result_get_op_res_gssize(gSimpleAsyncResult);
403        }
404
405        /**
406         * Gets the source tag for the #GSimpleAsyncResult.
407         *
408         * Deprecated: Use #GTask and g_task_get_source_tag() instead.
409         *
410         * Returns: a #gpointer to the source object for the #GSimpleAsyncResult.
411         */
412        public void* getSourceTag()
413        {
414                return g_simple_async_result_get_source_tag(gSimpleAsyncResult);
415        }
416
417        /**
418         * Propagates an error from within the simple asynchronous result to
419         * a given destination.
420         *
421         * If the #GCancellable given to a prior call to
422         * g_simple_async_result_set_check_cancellable() is cancelled then this
423         * function will return %TRUE with @dest set appropriately.
424         *
425         * Deprecated: Use #GTask instead.
426         *
427         * Returns: %TRUE if the error was propagated to @dest. %FALSE otherwise.
428         *
429         * Throws: GException on failure.
430         */
431        public bool propagateError()
432        {
433                GError* err = null;
434               
435                auto p = g_simple_async_result_propagate_error(gSimpleAsyncResult, &err) != 0;
436               
437                if (err !is null)
438                {
439                        throw new GException( new ErrorG(err) );
440                }
441               
442                return p;
443        }
444
445        /**
446         * Runs the asynchronous job in a separate thread and then calls
447         * g_simple_async_result_complete_in_idle() on @simple to return
448         * the result to the appropriate main loop.
449         *
450         * Calling this function takes a reference to @simple for as long as
451         * is needed to run the job and report its completion.
452         *
453         * Deprecated: Use #GTask and g_task_run_in_thread() instead.
454         *
455         * Params:
456         *     func = a #GSimpleAsyncThreadFunc.
457         *     ioPriority = the io priority of the request.
458         *     cancellable = optional #GCancellable object, %NULL to ignore.
459         */
460        public void runInThread(GSimpleAsyncThreadFunc func, int ioPriority, Cancellable cancellable)
461        {
462                g_simple_async_result_run_in_thread(gSimpleAsyncResult, func, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct());
463        }
464
465        /**
466         * Sets a #GCancellable to check before dispatching results.
467         *
468         * This function has one very specific purpose: the provided cancellable
469         * is checked at the time of g_simple_async_result_propagate_error() If
470         * it is cancelled, these functions will return an "Operation was
471         * cancelled" error (%G_IO_ERROR_CANCELLED).
472         *
473         * Implementors of cancellable asynchronous functions should use this in
474         * order to provide a guarantee to their callers that cancelling an
475         * async operation will reliably result in an error being returned for
476         * that operation (even if a positive result for the operation has
477         * already been sent as an idle to the main context to be dispatched).
478         *
479         * The checking described above is done regardless of any call to the
480         * unrelated g_simple_async_result_set_handle_cancellation() function.
481         *
482         * Deprecated: Use #GTask instead.
483         *
484         * Params:
485         *     checkCancellable = a #GCancellable to check, or %NULL to unset
486         *
487         * Since: 2.32
488         */
489        public void setCheckCancellable(Cancellable checkCancellable)
490        {
491                g_simple_async_result_set_check_cancellable(gSimpleAsyncResult, (checkCancellable is null) ? null : checkCancellable.getCancellableStruct());
492        }
493
494        /**
495         * Sets an error within the asynchronous result without a #GError.
496         * Unless writing a binding, see g_simple_async_result_set_error().
497         *
498         * Deprecated: Use #GTask and g_task_return_error() instead.
499         *
500         * Params:
501         *     domain = a #GQuark (usually #G_IO_ERROR).
502         *     code = an error code.
503         *     format = a formatted error reporting string.
504         *     args = va_list of arguments.
505         */
506        public void setErrorVa(GQuark domain, int code, string format, void* args)
507        {
508                g_simple_async_result_set_error_va(gSimpleAsyncResult, domain, code, Str.toStringz(format), args);
509        }
510
511        /**
512         * Sets the result from a #GError.
513         *
514         * Deprecated: Use #GTask and g_task_return_error() instead.
515         *
516         * Params:
517         *     error = #GError.
518         */
519        public void setFromError(ErrorG error)
520        {
521                g_simple_async_result_set_from_error(gSimpleAsyncResult, (error is null) ? null : error.getErrorGStruct());
522        }
523
524        /**
525         * Sets whether to handle cancellation within the asynchronous operation.
526         *
527         * This function has nothing to do with
528         * g_simple_async_result_set_check_cancellable().  It only refers to the
529         * #GCancellable passed to g_simple_async_result_run_in_thread().
530         *
531         * Params:
532         *     handleCancellation = a #gboolean.
533         */
534        public void setHandleCancellation(bool handleCancellation)
535        {
536                g_simple_async_result_set_handle_cancellation(gSimpleAsyncResult, handleCancellation);
537        }
538
539        /**
540         * Sets the operation result to a boolean within the asynchronous result.
541         *
542         * Deprecated: Use #GTask and g_task_return_boolean() instead.
543         *
544         * Params:
545         *     opRes = a #gboolean.
546         */
547        public void setOpResGboolean(bool opRes)
548        {
549                g_simple_async_result_set_op_res_gboolean(gSimpleAsyncResult, opRes);
550        }
551
552        /**
553         * Sets the operation result within the asynchronous result to a pointer.
554         *
555         * Deprecated: Use #GTask and g_task_return_pointer() instead.
556         *
557         * Params:
558         *     opRes = a pointer result from an asynchronous function.
559         *     destroyOpRes = a #GDestroyNotify function.
560         */
561        public void setOpResGpointer(void* opRes, GDestroyNotify destroyOpRes)
562        {
563                g_simple_async_result_set_op_res_gpointer(gSimpleAsyncResult, opRes, destroyOpRes);
564        }
565
566        /**
567         * Sets the operation result within the asynchronous result to
568         * the given @op_res.
569         *
570         * Deprecated: Use #GTask and g_task_return_int() instead.
571         *
572         * Params:
573         *     opRes = a #gssize.
574         */
575        public void setOpResGssize(ptrdiff_t opRes)
576        {
577                g_simple_async_result_set_op_res_gssize(gSimpleAsyncResult, opRes);
578        }
579
580        /**
581         * Sets the result from @error, and takes over the caller's ownership
582         * of @error, so the caller does not need to free it any more.
583         *
584         * Deprecated: Use #GTask and g_task_return_error() instead.
585         *
586         * Params:
587         *     error = a #GError
588         *
589         * Since: 2.28
590         */
591        public void takeError(ErrorG error)
592        {
593                g_simple_async_result_take_error(gSimpleAsyncResult, (error is null) ? null : error.getErrorGStruct());
594        }
595
596        /**
597         * Reports an error in an idle function. Similar to
598         * g_simple_async_report_error_in_idle(), but takes a #GError rather
599         * than building a new one.
600         *
601         * Deprecated: Use g_task_report_error().
602         *
603         * Params:
604         *     object = a #GObject, or %NULL
605         *     callback = a #GAsyncReadyCallback.
606         *     userData = user data passed to @callback.
607         *     error = the #GError to report
608         */
609        public static void simpleAsyncReportGerrorInIdle(ObjectG object, GAsyncReadyCallback callback, void* userData, ErrorG error)
610        {
611                g_simple_async_report_gerror_in_idle((object is null) ? null : object.getObjectGStruct(), callback, userData, (error is null) ? null : error.getErrorGStruct());
612        }
613
614        /**
615         * Reports an error in an idle function. Similar to
616         * g_simple_async_report_gerror_in_idle(), but takes over the caller's
617         * ownership of @error, so the caller does not have to free it any more.
618         *
619         * Deprecated: Use g_task_report_error().
620         *
621         * Params:
622         *     object = a #GObject, or %NULL
623         *     callback = a #GAsyncReadyCallback.
624         *     userData = user data passed to @callback.
625         *     error = the #GError to report
626         *
627         * Since: 2.28
628         */
629        public static void simpleAsyncReportTakeGerrorInIdle(ObjectG object, GAsyncReadyCallback callback, void* userData, ErrorG error)
630        {
631                g_simple_async_report_take_gerror_in_idle((object is null) ? null : object.getObjectGStruct(), callback, userData, (error is null) ? null : error.getErrorGStruct());
632        }
633}
Note: See TracBrowser for help on using the repository browser.