* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
*
* Author: Alexander Larsson <alexl@redhat.com>
*/
#include "gasyncinitable.h"
#include "gasyncresult.h"
#include "gsimpleasyncresult.h"
+#include "gtask.h"
#include "glibintl.h"
*
* A typical implementation might look something like this:
*
- * |[
+ * |[<!-- language="C" -->
* enum {
* NOT_INITIALIZED,
* INITIALIZING,
/**
* g_async_initable_init_async:
* @initable: a #GAsyncInitable.
- * @io_priority: the <link linkend="io-priority">I/O priority</link>
- * of the operation.
+ * @io_priority: the [I/O priority][io-priority] of the operation
* @cancellable: optional #GCancellable object, %NULL to ignore.
* @callback: a #GAsyncReadyCallback to call when the request is satisfied
* @user_data: the data to pass to callback function
}
static void
-async_init_thread (GSimpleAsyncResult *res,
- GObject *object,
- GCancellable *cancellable)
+async_init_thread (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
+ GCancellable *cancellable)
{
GError *error = NULL;
- if (!g_initable_init (G_INITABLE (object), cancellable, &error))
- g_simple_async_result_take_error (res, error);
+ if (g_initable_init (G_INITABLE (source_object), cancellable, &error))
+ g_task_return_boolean (task, TRUE);
+ else
+ g_task_return_error (task, error);
}
static void
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *res;
+ GTask *task;
g_return_if_fail (G_IS_INITABLE (initable));
- res = g_simple_async_result_new (G_OBJECT (initable), callback, user_data,
- g_async_initable_real_init_async);
- g_simple_async_result_run_in_thread (res, async_init_thread,
- io_priority, cancellable);
- g_object_unref (res);
+ task = g_task_new (initable, cancellable, callback, user_data);
+ g_task_set_priority (task, io_priority);
+ g_task_run_in_thread (task, async_init_thread);
+ g_object_unref (task);
}
static gboolean
GError **error)
{
/* For backward compatibility we have to process GSimpleAsyncResults
- * even if they aren't tagged from g_async_initable_real_init_async.
+ * even though g_async_initable_real_init_async doesn't generate
+ * them any more.
*/
if (G_IS_SIMPLE_ASYNC_RESULT (res))
{
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
if (g_simple_async_result_propagate_error (simple, error))
- return FALSE;
+ return FALSE;
+ else
+ return TRUE;
}
- return TRUE;
+ g_return_val_if_fail (g_task_is_valid (res, initable), FALSE);
+
+ return g_task_propagate_boolean (G_TASK (res), error);
}
/**
* g_async_initable_new_async:
* @object_type: a #GType supporting #GAsyncInitable.
- * @io_priority: the <link linkend="io-priority">I/O priority</link>
- * of the operation.
+ * @io_priority: the [I/O priority][io-priority] of the operation
* @cancellable: optional #GCancellable object, %NULL to ignore.
* @callback: a #GAsyncReadyCallback to call when the initialization is
* finished
* @object_type: a #GType supporting #GAsyncInitable.
* @n_parameters: the number of parameters in @parameters
* @parameters: the parameters to use to construct the object
- * @io_priority: the <link linkend="io-priority">I/O priority</link>
- * of the operation.
+ * @io_priority: the [I/O priority][io-priority] of the operation
* @cancellable: optional #GCancellable object, %NULL to ignore.
* @callback: a #GAsyncReadyCallback to call when the initialization is
* finished
* @first_property_name: the name of the first property, followed by
* the value, and other property value pairs, and ended by %NULL.
* @var_args: The var args list generated from @first_property_name.
- * @io_priority: the <link linkend="io-priority">I/O priority</link>
- * of the operation.
+ * @io_priority: the [I/O priority][io-priority] of the operation
* @cancellable: optional #GCancellable object, %NULL to ignore.
* @callback: a #GAsyncReadyCallback to call when the initialization is
* finished
* Finishes the async construction for the various g_async_initable_new
* calls, returning the created object or %NULL on error.
*
- * Returns: (transfer full): a newly created #GObject, or %NULL on error.
- * Free with g_object_unref().
+ * Returns: (type GObject.Object) (transfer full): a newly created #GObject,
+ * or %NULL on error. Free with g_object_unref().
*
* Since: 2.22
*/