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(bool transferOwnership = false)
121 	{
122 		if (transferOwnership)
123 			ownedRef = false;
124 		return cast(GAsyncResult*)getStruct();
125 	}
126 
127 
128 	/**
129 	 * Gets the source object from a #GAsyncResult.
130 	 *
131 	 * Returns: a new reference to the source object for the @res,
132 	 *     or %NULL if there is none.
133 	 */
134 	public ObjectG getSourceObject()
135 	{
136 		auto p = g_async_result_get_source_object(getAsyncResultStruct());
137 		
138 		if(p is null)
139 		{
140 			return null;
141 		}
142 		
143 		return ObjectG.getDObject!(ObjectG)(cast(GObject*) p, true);
144 	}
145 
146 	/**
147 	 * Gets the user data from a #GAsyncResult.
148 	 *
149 	 * Returns: the user data for @res.
150 	 */
151 	public void* getUserData()
152 	{
153 		return g_async_result_get_user_data(getAsyncResultStruct());
154 	}
155 
156 	/**
157 	 * Checks if @res has the given @source_tag (generally a function
158 	 * pointer indicating the function @res was created by).
159 	 *
160 	 * Params:
161 	 *     sourceTag = an application-defined tag
162 	 *
163 	 * Returns: %TRUE if @res has the indicated @source_tag, %FALSE if
164 	 *     not.
165 	 *
166 	 * Since: 2.34
167 	 */
168 	public bool isTagged(void* sourceTag)
169 	{
170 		return g_async_result_is_tagged(getAsyncResultStruct(), sourceTag) != 0;
171 	}
172 
173 	/**
174 	 * If @res is a #GSimpleAsyncResult, this is equivalent to
175 	 * g_simple_async_result_propagate_error(). Otherwise it returns
176 	 * %FALSE.
177 	 *
178 	 * This can be used for legacy error handling in async *_finish()
179 	 * wrapper functions that traditionally handled #GSimpleAsyncResult
180 	 * error returns themselves rather than calling into the virtual method.
181 	 * This should not be used in new code; #GAsyncResult errors that are
182 	 * set by virtual methods should also be extracted by virtual methods,
183 	 * to enable subclasses to chain up correctly.
184 	 *
185 	 * Returns: %TRUE if @error is has been filled in with an error from
186 	 *     @res, %FALSE if not.
187 	 *
188 	 * Since: 2.34
189 	 *
190 	 * Throws: GException on failure.
191 	 */
192 	public bool legacyPropagateError()
193 	{
194 		GError* err = null;
195 		
196 		auto p = g_async_result_legacy_propagate_error(getAsyncResultStruct(), &err) != 0;
197 		
198 		if (err !is null)
199 		{
200 			throw new GException( new ErrorG(err) );
201 		}
202 		
203 		return p;
204 	}
205 }