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