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