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

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

Initial release

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