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