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