source: appstream-generator/build/girepo/gio/AsyncResultT.d

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

Initial release

File size: 6.1 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.AsyncResultT;
22
23public  import gi.gio;
24public  import gi.giotypes;
25public  import glib.ErrorG;
26public  import glib.GException;
27public  import gobject.ObjectG;
28
29
30/**
31 * Provides a base class for implementing asynchronous function results.
32 *
33 * Asynchronous operations are broken up into two separate operations
34 * which are chained together by a #GAsyncReadyCallback. To begin
35 * an asynchronous operation, provide a #GAsyncReadyCallback to the
36 * asynchronous function. This callback will be triggered when the
37 * operation has completed, and will be passed a #GAsyncResult instance
38 * filled with the details of the operation's success or failure, the
39 * object the asynchronous function was started for and any error codes
40 * returned. The asynchronous callback function is then expected to call
41 * the corresponding "_finish()" function, passing the object the
42 * function was called for, the #GAsyncResult instance, and (optionally)
43 * an @error to grab any error conditions that may have occurred.
44 *
45 * The "_finish()" function for an operation takes the generic result
46 * (of type #GAsyncResult) and returns the specific result that the
47 * operation in question yields (e.g. a #GFileEnumerator for a
48 * "enumerate children" operation). If the result or error status of the
49 * operation is not needed, there is no need to call the "_finish()"
50 * function; GIO will take care of cleaning up the result and error
51 * information after the #GAsyncReadyCallback returns. You can pass
52 * %NULL for the #GAsyncReadyCallback if you don't need to take any
53 * action at all after the operation completes. Applications may also
54 * take a reference to the #GAsyncResult and call "_finish()" later;
55 * however, the "_finish()" function may be called at most once.
56 *
57 * Example of a typical asynchronous operation flow:
58 * |[<!-- language="C" -->
59 * void _theoretical_frobnitz_async (Theoretical         *t,
60 * GCancellable        *c,
61 * GAsyncReadyCallback  cb,
62 * gpointer             u);
63 *
64 * gboolean _theoretical_frobnitz_finish (Theoretical   *t,
65 * GAsyncResult  *res,
66 * GError       **e);
67 *
68 * static void
69 * frobnitz_result_func (GObject      *source_object,
70 * GAsyncResult *res,
71 * gpointer      user_data)
72 * {
73 * gboolean success = FALSE;
74 *
75 * success = _theoretical_frobnitz_finish (source_object, res, NULL);
76 *
77 * if (success)
78 * g_printf ("Hurray!\n");
79 * else
80 * g_printf ("Uh oh!\n");
81 *
82 * ...
83 *
84 * }
85 *
86 * int main (int argc, void *argv[])
87 * {
88 * ...
89 *
90 * _theoretical_frobnitz_async (theoretical_data,
91 * NULL,
92 * frobnitz_result_func,
93 * NULL);
94 *
95 * ...
96 * }
97 * ]|
98 *
99 * The callback for an asynchronous operation is called only once, and is
100 * always called, even in the case of a cancelled operation. On cancellation
101 * the result is a %G_IO_ERROR_CANCELLED error.
102 *
103 * ## I/O Priority # {#io-priority}
104 *
105 * Many I/O-related asynchronous operations have a priority parameter,
106 * which is used in certain cases to determine the order in which
107 * operations are executed. They are not used to determine system-wide
108 * I/O scheduling. Priorities are integers, with lower numbers indicating
109 * higher priority. It is recommended to choose priorities between
110 * %G_PRIORITY_LOW and %G_PRIORITY_HIGH, with %G_PRIORITY_DEFAULT
111 * as a default.
112 */
113public template AsyncResultT(TStruct)
114{
115        /** Get the main Gtk struct */
116        public GAsyncResult* getAsyncResultStruct()
117        {
118                return cast(GAsyncResult*)getStruct();
119        }
120
121
122        /**
123         * Gets the source object from a #GAsyncResult.
124         *
125         * Returns: a new reference to the source object for the @res,
126         *     or %NULL if there is none.
127         */
128        public ObjectG getSourceObject()
129        {
130                auto p = g_async_result_get_source_object(getAsyncResultStruct());
131               
132                if(p is null)
133                {
134                        return null;
135                }
136               
137                return ObjectG.getDObject!(ObjectG)(cast(GObject*) p, true);
138        }
139
140        /**
141         * Gets the user data from a #GAsyncResult.
142         *
143         * Returns: the user data for @res.
144         */
145        public void* getUserData()
146        {
147                return g_async_result_get_user_data(getAsyncResultStruct());
148        }
149
150        /**
151         * Checks if @res has the given @source_tag (generally a function
152         * pointer indicating the function @res was created by).
153         *
154         * Params:
155         *     sourceTag = an application-defined tag
156         *
157         * Returns: %TRUE if @res has the indicated @source_tag, %FALSE if
158         *     not.
159         *
160         * Since: 2.34
161         */
162        public bool isTagged(void* sourceTag)
163        {
164                return g_async_result_is_tagged(getAsyncResultStruct(), sourceTag) != 0;
165        }
166
167        /**
168         * If @res is a #GSimpleAsyncResult, this is equivalent to
169         * g_simple_async_result_propagate_error(). Otherwise it returns
170         * %FALSE.
171         *
172         * This can be used for legacy error handling in async *_finish()
173         * wrapper functions that traditionally handled #GSimpleAsyncResult
174         * error returns themselves rather than calling into the virtual method.
175         * This should not be used in new code; #GAsyncResult errors that are
176         * set by virtual methods should also be extracted by virtual methods,
177         * to enable subclasses to chain up correctly.
178         *
179         * Returns: %TRUE if @error is has been filled in with an error from
180         *     @res, %FALSE if not.
181         *
182         * Since: 2.34
183         *
184         * Throws: GException on failure.
185         */
186        public bool legacyPropagateError()
187        {
188                GError* err = null;
189               
190                auto p = g_async_result_legacy_propagate_error(getAsyncResultStruct(), &err) != 0;
191               
192                if (err !is null)
193                {
194                        throw new GException( new ErrorG(err) );
195                }
196               
197                return p;
198        }
199}
Note: See TracBrowser for help on using the repository browser.