static void do_sparql_query_async_connection_cb (GObject *const object, GAsyncResult *const result, GTask *const task) { g_autoptr(GError) error = NULL; TrackerSparqlConnection *const conn = tracker_sparql_connection_get_finish ( result, &error ); if (error) { g_task_return_error (task, g_error_copy (error)); return; } SparqlQueryWork *const work = sparql_query_work_get (task); work->connection = conn; tracker_sparql_connection_query_async ( conn, work->sparql, g_task_get_cancellable (task), (GAsyncReadyCallback) do_sparql_query_async_cursor_cb, task ); }
static void ide_async_helper_cb (GObject *object, GAsyncResult *result, gpointer user_data) { g_autoptr(GTask) task = user_data; GPtrArray *funcs; GError *error = NULL; g_return_if_fail (G_IS_TASK (task)); g_return_if_fail (G_IS_TASK (result)); funcs = g_task_get_task_data (task); if (!g_task_propagate_boolean (G_TASK (result), &error)) { g_task_return_error (task, error); return; } g_ptr_array_remove_index (funcs, 0); if (funcs->len) { IdeAsyncStep step; step = g_ptr_array_index (funcs, 0); step (g_task_get_source_object (task), g_task_get_cancellable (task), ide_async_helper_cb, g_object_ref (task)); } else g_task_return_boolean (task, TRUE); }
static void on_get_user_id_ready (GObject *source_object, GAsyncResult *res, gpointer user_data) { GTask *task = G_TASK (user_data); gpointer *info = g_task_get_source_object (task); GClueClientInfoPrivate *priv = GCLUE_CLIENT_INFO (info)->priv; GError *error = NULL; GVariant *results = NULL; results = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error); if (results == NULL) { g_task_return_error (task, error); g_object_unref (task); return; } g_assert (g_variant_n_children (results) > 0); g_variant_get_child (results, 0, "u", &priv->user_id); g_variant_unref (results); g_dbus_proxy_call (priv->dbus_proxy, "GetConnectionUnixProcessID", g_variant_new ("(s)", priv->bus_name), G_DBUS_CALL_FLAGS_NONE, -1, g_task_get_cancellable (task), on_get_pid_ready, task); }
static void discover_file_cb (GObject *object, GAsyncResult *result, gpointer user_data) { IdeAutotoolsBuildSystem *self; g_autoptr(GTask) task = user_data; g_autoptr(GFile) file = NULL; GError *error = NULL; g_return_if_fail (G_IS_TASK (task)); self = g_task_get_source_object (task); file = ide_autotools_build_system_discover_file_finish (self, result, &error); if (!file) { g_task_return_error (task, error); return; } g_object_set (self, "project-file", file, NULL); ide_autotools_build_system_parse_async (self, file, g_task_get_cancellable (task), parse_cb, g_object_ref (task)); }
static void photos_fetch_ids_job_query_executed (GObject *source_object, GAsyncResult *res, gpointer user_data) { GCancellable *cancellable; GTask *task = G_TASK (user_data); TrackerSparqlConnection *connection = TRACKER_SPARQL_CONNECTION (source_object); TrackerSparqlCursor *cursor; /* TODO: Use g_autoptr */ GError *error; cancellable = g_task_get_cancellable (task); error = NULL; cursor = tracker_sparql_connection_query_finish (connection, res, &error); if (error != NULL) { g_task_return_error (task, error); return; } tracker_sparql_cursor_next_async (cursor, cancellable, photos_fetch_ids_job_cursor_next, g_object_ref (task)); g_object_unref (cursor); }
static void populate_cache__get_local_makefile_cb (GObject *object, GAsyncResult *result, gpointer user_data) { IdeAutotoolsBuildSystem *self = (IdeAutotoolsBuildSystem *)object; g_autoptr(GTask) task = user_data; g_autoptr(GFile) makefile = NULL; IdeContext *context; GError *error = NULL; IDE_ENTRY; g_assert (IDE_IS_AUTOTOOLS_BUILD_SYSTEM (self)); g_assert (G_IS_TASK (task)); makefile = ide_autotools_build_system_get_local_makefile_finish (self, result, &error); if (makefile == NULL) { g_task_return_error (task, error); IDE_EXIT; } context = ide_object_get_context (IDE_OBJECT (self)); ide_makecache_new_for_makefile_async (context, makefile, g_task_get_cancellable (task), populate_cache__new_makecache_cb, g_object_ref (task)); IDE_EXIT; }
static void ide_run_manager_do_install_before_run (IdeRunManager *self, GTask *task) { IdeBuildManager *build_manager; IdeContext *context; g_assert (IDE_IS_RUN_MANAGER (self)); g_assert (G_IS_TASK (task)); context = ide_object_get_context (IDE_OBJECT (self)); build_manager = ide_context_get_build_manager (context); /* * First we need to make sure the target is up to date and installed * so that all the dependent resources are available. */ self->busy = TRUE; g_signal_connect_object (task, "notify::completed", G_CALLBACK (ide_run_manager_task_completed), self, G_CONNECT_SWAPPED); ide_build_manager_install_async (build_manager, g_task_get_cancellable (task), ide_run_manager_install_cb, g_object_ref (task)); ide_run_manager_notify_busy (self); }
static void photos_thumbnailer_generate_thumbnail_save_to_stream (GObject *source_object, GAsyncResult *res, gpointer user_data) { GCancellable *cancellable; g_autoptr (GTask) task = G_TASK (user_data); PhotosThumbnailerGenerateData *data; cancellable = g_task_get_cancellable (task); data = g_task_get_task_data (task); { g_autoptr (GError) error = NULL; if (!gdk_pixbuf_save_to_stream_finish (res, &error)) { g_task_return_error (task, g_steal_pointer (&error)); goto out; } } g_output_stream_close_async (G_OUTPUT_STREAM (data->stream), G_PRIORITY_DEFAULT, cancellable, photos_thumbnailer_generate_thumbnail_stream_close, g_object_ref (task)); out: return; }
static void query_cb (GObject *const object, GAsyncResult *const result, GTask *const task) { g_autoptr(GError) error = NULL; g_autoptr(TrackerSparqlCursor) cursor = nul_sparql_query_util_query_finish ( result, &error ); if (error) { nul_error ("failed to execute query: %s", error->message); } AsyncSparqlWork *const work = async_sparql_work_get (task); work->cursor = g_object_ref_sink (cursor); work->builder = g_variant_builder_new (VARDICT_ARRAY); tracker_sparql_cursor_next_async ( cursor, g_task_get_cancellable (task), (GAsyncReadyCallback) next_cb, task ); }
static inline gboolean handle_query_async (NulMusicService *const self, GDBusMethodInvocation *const invo, gchar const *const sparql, CursorConvertItemFunc const convert_item_func) { AsyncSparqlWork *const work = g_new0 (AsyncSparqlWork, 1); work->sparql = g_strdup (sparql); work->invo = invo; work->func = convert_item_func; GTask *const task = g_task_new ( NULL, NULL, (GAsyncReadyCallback) done_cb, self ); g_task_set_task_data (task, work, (GDestroyNotify) async_sparql_work_free); nul_sparql_query_util_query_async ( sparql, g_task_get_cancellable (task), (GAsyncReadyCallback) query_cb, task ); return TRUE; }
static void ide_thread_pool_worker (gpointer data, gpointer user_data) { WorkItem *work_item = data; gpointer source_object; gpointer task_data; GCancellable *cancellable; g_assert (work_item != NULL); EGG_COUNTER_DEC (QueuedTasks); if (work_item->type == TYPE_TASK) { source_object = g_task_get_source_object (work_item->task.task); task_data = g_task_get_task_data (work_item->task.task); cancellable = g_task_get_cancellable (work_item->task.task); work_item->task.func (work_item->task.task, source_object, task_data, cancellable); g_object_unref (work_item->task.task); } else if (work_item->type == TYPE_FUNC) { work_item->func.callback (work_item->func.data); } g_slice_free (WorkItem, work_item); }
static void on_dbus_proxy_ready (GObject *source_object, GAsyncResult *res, gpointer user_data) { GTask *task = G_TASK (user_data); gpointer *info = g_task_get_source_object (task); GClueClientInfoPrivate *priv = GCLUE_CLIENT_INFO (info)->priv; GError *error = NULL; priv->dbus_proxy = g_dbus_proxy_new_for_bus_finish (res, &error); if (priv->dbus_proxy == NULL) { g_task_return_error (task, error); g_object_unref (task); return; } g_dbus_proxy_call (priv->dbus_proxy, "GetConnectionUnixUser", g_variant_new ("(s)", priv->bus_name), G_DBUS_CALL_FLAGS_NONE, -1, g_task_get_cancellable (task), on_get_user_id_ready, task); }
static void photos_glib_file_copy_read (GObject *source_object, GAsyncResult *res, gpointer user_data) { GCancellable *cancellable; GFile *source = G_FILE (source_object); g_autoptr (GFileInputStream) istream = NULL; g_autoptr (GTask) task = G_TASK (user_data); PhotosGLibFileCopyData *data; cancellable = g_task_get_cancellable (task); data = (PhotosGLibFileCopyData *) g_task_get_task_data (task); { g_autoptr (GError) error = NULL; istream = g_file_read_finish (source, res, &error); if (error != NULL) { g_task_return_error (task, g_steal_pointer (&error)); goto out; } } g_output_stream_splice_async (G_OUTPUT_STREAM (data->ostream), G_INPUT_STREAM (istream), G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, data->io_priority, cancellable, photos_glib_file_copy_splice, g_object_ref (task)); out: return; }
static void photos_base_item_create_thumbnail_in_thread_func (gpointer data, gpointer user_data) { GTask *task = G_TASK (data); PhotosBaseItem *self; GCancellable *cancellable; GError *error; gboolean op_res; self = PHOTOS_BASE_ITEM (g_task_get_source_object (task)); cancellable = g_task_get_cancellable (task); error = NULL; op_res = PHOTOS_BASE_ITEM_GET_CLASS (self)->create_thumbnail (self, cancellable, &error); if (error != NULL) { g_task_return_error (task, error); goto out; } g_task_return_boolean (task, op_res); out: g_object_unref (task); }
static void proxy_lookup_cb (GObject *object, GAsyncResult *result, gpointer user_data) { GTask *task = user_data; GProxyAddressEnumeratorPrivate *priv = g_task_get_task_data (task); g_clear_error (&priv->last_error); priv->proxies = g_proxy_resolver_lookup_finish (G_PROXY_RESOLVER (object), result, &priv->last_error); priv->next_proxy = priv->proxies; if (priv->last_error) { complete_async (task); return; } else { next_enumerator (priv); if (priv->addr_enum) { g_socket_address_enumerator_next_async (priv->addr_enum, g_task_get_cancellable (task), address_enumerate_cb, task); return; } } complete_async (task); }
static void address_enumerate_cb (GObject *object, GAsyncResult *result, gpointer user_data) { GTask *task = user_data; GProxyAddressEnumeratorPrivate *priv = g_task_get_task_data (task); g_clear_error (&priv->last_error); priv->proxy_address = g_socket_address_enumerator_next_finish (priv->addr_enum, result, &priv->last_error); if (priv->proxy_address) { if (!priv->supports_hostname && !priv->dest_ips) { GResolver *resolver; resolver = g_resolver_get_default(); g_resolver_lookup_by_name_async (resolver, priv->dest_hostname, g_task_get_cancellable (task), dest_hostname_lookup_cb, task); g_object_unref (resolver); return; } return_result (task); } else next_proxy (task); }
static void next_proxy (GTask *task) { GProxyAddressEnumeratorPrivate *priv = g_task_get_task_data (task); if (*priv->next_proxy) { g_object_unref (priv->addr_enum); priv->addr_enum = NULL; if (priv->dest_ips) { g_resolver_free_addresses (priv->dest_ips); priv->dest_ips = NULL; } next_enumerator (priv); if (priv->addr_enum) { g_socket_address_enumerator_next_async (priv->addr_enum, g_task_get_cancellable (task), address_enumerate_cb, task); return; } } complete_async (task); }
static void ide_autotools_build_system_get_build_targets_cb (GObject *object, GAsyncResult *result, gpointer user_data) { IdeAutotoolsBuildSystem *self = (IdeAutotoolsBuildSystem *)object; g_autoptr(IdeMakecache) makecache = NULL; g_autoptr(GTask) task = user_data; GError *error = NULL; g_assert (IDE_IS_AUTOTOOLS_BUILD_SYSTEM (self)); g_assert (G_IS_TASK (task)); makecache = ide_autotools_build_system_get_makecache_finish (self, result, &error); if (makecache == NULL) { g_task_return_error (task, error); return; } ide_makecache_get_build_targets_async (makecache, g_task_get_cancellable (task), ide_autotools_build_system_get_build_targets_cb2, g_object_ref (task)); }
static gboolean accept_ready (GSocket *accept_socket, GIOCondition condition, gpointer user_data) { GTask *task = user_data; GError *error = NULL; GSocket *socket; GObject *source_object; socket = g_socket_accept (accept_socket, g_task_get_cancellable (task), &error); if (socket) { source_object = g_object_get_qdata (G_OBJECT (accept_socket), source_quark); if (source_object) g_object_set_qdata_full (G_OBJECT (task), source_quark, g_object_ref (source_object), g_object_unref); g_task_return_pointer (task, socket, g_object_unref); } else { g_task_return_error (task, error); } g_object_unref (task); return FALSE; }
static void socket_connect_complete (GObject *object, GAsyncResult *result, gpointer user_data) { SoupSocket *sock = SOUP_SOCKET (object); GTask *task = user_data; SoupConnection *conn = g_task_get_source_object (task); SoupConnectionPrivate *priv = SOUP_CONNECTION_GET_PRIVATE (conn); GError *error = NULL; if (!soup_socket_connect_finish_internal (sock, result, &error)) { socket_connect_finished (task, sock, error); return; } priv->proxy_uri = soup_socket_get_http_proxy_uri (sock); if (priv->ssl && !priv->proxy_uri) { soup_socket_handshake_async (sock, priv->remote_uri->host, g_task_get_cancellable (task), socket_handshake_complete, task); return; } socket_connect_finished (task, sock, NULL); }
WebSoupRequestAsyncData(GTask* task, WebKitSoupRequestGeneric* requestGeneric) : task(task) , request(requestGeneric) , cancellable(g_task_get_cancellable(task)) { // If the struct contains a null request, it is because the request failed. g_object_add_weak_pointer(G_OBJECT(request), reinterpret_cast<void**>(&request)); }
static void do_run_async (IdeRunManager *self, GTask *task) { IdeBuildTarget *build_target; IdeContext *context; IdeConfigurationManager *config_manager; IdeConfiguration *config; IdeRuntime *runtime; g_autoptr(IdeRunner) runner = NULL; GCancellable *cancellable; g_assert (IDE_IS_RUN_MANAGER (self)); g_assert (G_IS_TASK (task)); build_target = g_task_get_task_data (task); context = ide_object_get_context (IDE_OBJECT (self)); g_assert (IDE_IS_BUILD_TARGET (build_target)); g_assert (IDE_IS_CONTEXT (context)); config_manager = ide_context_get_configuration_manager (context); config = ide_configuration_manager_get_current (config_manager); runtime = ide_configuration_get_runtime (config); if (runtime == NULL) { g_task_return_new_error (task, IDE_RUNTIME_ERROR, IDE_RUNTIME_ERROR_NO_SUCH_RUNTIME, "%s “%s”", _("Failed to locate runtime"), ide_configuration_get_runtime_id (config)); IDE_EXIT; } runner = ide_runtime_create_runner (runtime, build_target); cancellable = g_task_get_cancellable (task); g_assert (IDE_IS_RUNNER (runner)); g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); /* * If the current handler has a callback specified (our default "run" handler * does not), then we need to allow that handler to prepare the runner. */ if (self->handler != NULL && self->handler->handler != NULL) self->handler->handler (self, runner, self->handler->handler_data); g_signal_emit (self, signals [RUN], 0, runner); ide_runner_run_async (runner, cancellable, ide_run_manager_run_cb, g_object_ref (task)); }
static void photos_glib_file_create_create (GObject *source_object, GAsyncResult *res, gpointer user_data) { GCancellable *cancellable; GFile *file = G_FILE (source_object); g_autoptr (GFileOutputStream) stream = NULL; g_autoptr (GTask) task = G_TASK (user_data); PhotosGLibFileCreateData *data; cancellable = g_task_get_cancellable (task); data = (PhotosGLibFileCreateData *) g_task_get_task_data (task); { g_autoptr (GError) error = NULL; stream = g_file_create_finish (file, res, &error); if (error != NULL) { g_autoptr (GFile) unique_file = NULL; g_autofree gchar *filename = NULL; if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS)) { g_task_return_error (task, g_steal_pointer (&error)); goto out; } if (data->count == G_MAXUINT) { g_task_return_new_error (task, PHOTOS_ERROR, 0, "Exceeded number of copies of a file"); goto out; } data->count++; filename = photos_glib_file_create_data_get_filename (data); unique_file = g_file_get_child (data->dir, filename); g_file_create_async (unique_file, data->flags, data->io_priority, cancellable, photos_glib_file_create_create, g_object_ref (task)); goto out; } } g_task_return_pointer (task, g_object_ref (stream), g_object_unref); out: return; }
static void read_stream (LatexilaPostProcessor *pp) { g_input_stream_read_async (pp->priv->stream, &pp->priv->buffer, BUFFER_SIZE, G_PRIORITY_DEFAULT, g_task_get_cancellable (pp->priv->task), (GAsyncReadyCallback) read_stream_cb, pp); }
static void do_read (GAsyncReadyCallback callback, GTask *task, ConnectAsyncData *data) { GInputStream *in; in = g_io_stream_get_input_stream (data->io_stream); g_input_stream_read_async (in, data->buffer + data->offset, data->length - data->offset, g_task_get_priority (task), g_task_get_cancellable (task), callback, task); }
static void do_write (GAsyncReadyCallback callback, GTask *task, ConnectAsyncData *data) { GOutputStream *out; out = g_io_stream_get_output_stream (data->io_stream); g_output_stream_write_async (out, data->buffer + data->offset, data->length - data->offset, g_task_get_priority (task), g_task_get_cancellable (task), callback, task); }
static void g_task_return_error (GTask *task, const GError *error) { /* set result to temp memory location */ if (task->ret) { g_simple_async_result_set_op_res_gpointer (task->res, task->sample, (GDestroyNotify) cd_color_xyz_free); } else { g_simple_async_result_set_from_error (task->res, error); } /* deallocate */ if (g_task_get_cancellable (task) != NULL) { g_cancellable_disconnect (g_task_get_cancellable (task), g_task_get_cancellable (task)_id); g_object_unref (g_task_get_cancellable (task)); } g_object_unref (task->res); g_object_unref (sensor); g_slice_free (CdSensorTaskData, task); }
static void photos_thumbnailer_generate_thumbnail_replace (GObject *source_object, GAsyncResult *res, gpointer user_data) { GCancellable *cancellable; GFile *thumbnail_file = G_FILE (source_object); g_autoptr (GFileOutputStream) stream = NULL; g_autoptr (GTask) task = G_TASK (user_data); PhotosThumbnailerGenerateData *data; const gchar *prgname; g_autofree gchar *original_height_str = NULL; g_autofree gchar *original_width_str = NULL; g_autofree gchar *uri = NULL; cancellable = g_task_get_cancellable (task); data = g_task_get_task_data (task); { g_autoptr (GError) error = NULL; stream = g_file_replace_finish (thumbnail_file, res, &error); if (error != NULL) { g_task_return_error (task, g_steal_pointer (&error)); goto out; } } g_assert_null (data->stream); data->stream = g_object_ref (stream); original_height_str = g_strdup_printf ("%" G_GINT64_FORMAT, data->original_height); original_width_str = g_strdup_printf ("%" G_GINT64_FORMAT, data->original_width); prgname = g_get_prgname (); uri = g_file_get_uri (data->file); gdk_pixbuf_save_to_stream_async (data->pixbuf_thumbnail, G_OUTPUT_STREAM (stream), "png", cancellable, photos_thumbnailer_generate_thumbnail_save_to_stream, g_object_ref (task), "tEXt::Software", prgname, "tEXt::Thumb::URI", uri, "tEXt::Thumb::Image::Height", original_height_str, "tEXt::Thumb::Image::Width", original_width_str, NULL); out: return; }
static void decorator_cancel_active_tasks (TrackerDecorator *decorator) { TrackerDecoratorPrivate *priv = decorator->priv; GHashTableIter iter; GTask *task; g_hash_table_iter_init (&iter, priv->tasks); while (g_hash_table_iter_next (&iter, NULL, (gpointer*) &task)) { g_cancellable_cancel (g_task_get_cancellable (task)); } g_hash_table_remove_all (priv->tasks); }
static gboolean gvir_input_stream_read_ready(GVirStream *stream, GVirStreamIOCondition cond, void *opaque) { GVirInputStream *input_stream = GVIR_INPUT_STREAM(opaque); GVirInputStreamPrivate *priv = input_stream->priv; GTask *task = priv->task; GCancellable *cancellable = g_task_get_cancellable(task); GError *error = NULL; gssize result; priv->task = NULL; if (!(cond & GVIR_STREAM_IO_CONDITION_READABLE)) { g_warn_if_reached(); g_task_return_new_error(task, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "%s", "Expected stream to be readable"); goto cleanup; } result = gvir_stream_receive(stream, priv->buffer, priv->count, cancellable, &error); if (error != NULL) { if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) { g_warn_if_reached(); g_task_return_new_error(task, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "%s", "Expected stream to be readable"); g_error_free (error); } else { g_task_return_error(task, error); } goto cleanup; } g_task_return_int(task, result); cleanup: g_object_unref(task); return FALSE; }