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