/** * ide_compile_commands_load_async: * @self: An #IdeCompileCommands * @file: a #GFile * @cancellable: (nullable): a #GCancellable, or %NULL * @callback: the callback for the async operation * @user_data: user data for @callback * * Asynchronously loads the contents of the requested @file and parses * the JSON command database contained within. * * You may only call this function once on an #IdeCompileCommands object. * If there is a failure, you must create a new #IdeCompileCommands instance * instead of calling this function again. * * See also: ide_compile_commands_load_finish() * * Since: 3.28 */ void ide_compile_commands_load_async (IdeCompileCommands *self, GFile *file, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { g_autoptr(GTask) task = NULL; IDE_ENTRY; g_return_if_fail (IDE_IS_COMPILE_COMMANDS (self)); g_return_if_fail (self->has_loaded == FALSE); g_return_if_fail (G_IS_FILE (file)); g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); self->has_loaded = TRUE; task = g_task_new (self, cancellable, callback, user_data); g_task_set_priority (task, G_PRIORITY_LOW); g_task_set_source_tag (task, ide_compile_commands_load_async); g_task_set_task_data (task, g_object_ref (file), g_object_unref); g_task_run_in_thread (task, ide_compile_commands_load_worker); IDE_EXIT; }
static void gdk_clipboard_store_default_async (GdkClipboard *clipboard, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard); GTask *task; task = g_task_new (clipboard, cancellable, callback, user_data); g_task_set_priority (task, io_priority); g_task_set_source_tag (task, gdk_clipboard_store_default_async); if (priv->local) { g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, _("This clipboard cannot store data.")); } else { g_task_return_boolean (task, TRUE); } g_object_unref (task); }
/** * ide_compile_commands_load: * @self: An #IdeCompileCommands * @file: a #GFile * @cancellable: (nullable): a #GCancellable, or %NULL * @error: A location for a #GError, or %NULL * * Synchronously loads the contents of the requested @file and parses * the JSON command database contained within. * * You may only call this function once on an #IdeCompileCommands object. * If there is a failure, you must create a new #IdeCompileCommands instance * instead of calling this function again. * * See also: ide_compile_commands_load_async() * * Returns: %TRUE if successful; otherwise %FALSE and @error is set. * * Since: 3.28 */ gboolean ide_compile_commands_load (IdeCompileCommands *self, GFile *file, GCancellable *cancellable, GError **error) { g_autoptr(GTask) task = NULL; gboolean ret; IDE_ENTRY; g_return_val_if_fail (IDE_IS_COMPILE_COMMANDS (self), FALSE); g_return_val_if_fail (self->has_loaded == FALSE, FALSE); g_return_val_if_fail (G_IS_FILE (file), FALSE); g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE); self->has_loaded = TRUE; task = g_task_new (self, cancellable, NULL, NULL); g_task_set_priority (task, G_PRIORITY_LOW); g_task_set_source_tag (task, ide_compile_commands_load); g_task_set_task_data (task, g_object_ref (file), g_object_unref); g_task_run_in_thread_sync (task, ide_compile_commands_load_worker); ret = g_task_propagate_boolean (task, error); IDE_RETURN (ret); }
static void dspy_introspection_model_init_async (GAsyncInitable *initiable, gint io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { DspyIntrospectionModel *self = (DspyIntrospectionModel *)initiable; GDBusConnection *bus = NULL; DspyConnection *connection = NULL; g_autoptr(GTask) task = NULL; g_assert (DSPY_IS_INTROSPECTION_MODEL (self)); g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); task = g_task_new (self, cancellable, callback, user_data); g_task_set_source_tag (task, dspy_introspection_model_init_async); g_task_set_task_data (task, g_new0 (gint, 1), g_free); g_task_set_priority (task, io_priority); if (self->name == NULL || !(connection = dspy_name_get_connection (self->name)) || !(bus = dspy_connection_get_connection (connection))) { g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_INITIALIZED, "%s has not been intialized with a name", G_OBJECT_TYPE_NAME (self)); return; } dspy_introspection_model_introspect (task, bus, "/"); }
/** * g_io_scheduler_push_job: * @job_func: a #GIOSchedulerJobFunc. * @user_data: data to pass to @job_func * @notify: (allow-none): a #GDestroyNotify for @user_data, or %NULL * @io_priority: the <link linkend="io-priority">I/O priority</link> * of the request. * @cancellable: optional #GCancellable object, %NULL to ignore. * * Schedules the I/O job to run in another thread. * * @notify will be called on @user_data after @job_func has returned, * regardless whether the job was cancelled or has run to completion. * * If @cancellable is not %NULL, it can be used to cancel the I/O job * by calling g_cancellable_cancel() or by calling * g_io_scheduler_cancel_all_jobs(). * * Deprecated: use #GThreadPool or g_task_run_in_thread() **/ void g_io_scheduler_push_job (GIOSchedulerJobFunc job_func, gpointer user_data, GDestroyNotify notify, gint io_priority, GCancellable *cancellable) { GIOSchedulerJob *job; GTask *task; g_return_if_fail (job_func != NULL); job = g_slice_new0 (GIOSchedulerJob); job->job_func = job_func; job->data = user_data; job->destroy_notify = notify; if (cancellable) job->cancellable = g_object_ref (cancellable); job->context = g_main_context_ref_thread_default (); G_LOCK (active_jobs); active_jobs = g_list_prepend (active_jobs, job); job->active_link = active_jobs; G_UNLOCK (active_jobs); task = g_task_new (NULL, cancellable, NULL, NULL); g_task_set_task_data (task, job, (GDestroyNotify)g_io_job_free); g_task_set_priority (task, io_priority); g_task_run_in_thread (task, io_job_thread); g_object_unref (task); }
static void gdk_clipboard_read_local_async (GdkClipboard *clipboard, GdkContentFormats *formats, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard); GdkContentFormats *content_formats; const char *mime_type; GTask *task; task = g_task_new (clipboard, cancellable, callback, user_data); g_task_set_priority (task, io_priority); g_task_set_source_tag (task, gdk_clipboard_read_local_async); if (priv->content == NULL) { g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, _("Cannot read from empty clipboard.")); g_object_unref (task); return; } content_formats = gdk_content_provider_ref_formats (priv->content); content_formats = gdk_content_formats_union_serialize_mime_types (content_formats); mime_type = gdk_content_formats_match_mime_type (content_formats, formats); if (mime_type != NULL) { GOutputStream *output_stream; GIOStream *stream; stream = gdk_pipe_io_stream_new (); output_stream = g_io_stream_get_output_stream (stream); gdk_clipboard_write_async (clipboard, mime_type, output_stream, io_priority, cancellable, gdk_clipboard_read_local_write_done, g_object_ref (output_stream)); g_task_set_task_data (task, (gpointer) mime_type, NULL); g_task_return_pointer (task, g_object_ref (g_io_stream_get_input_stream (stream)), g_object_unref); g_object_unref (stream); } else { g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, _("No compatible formats to transfer clipboard contents.")); } gdk_content_formats_unref (content_formats); g_object_unref (task); }
static void g_tls_connection_base_handshake_async (GTlsConnection *conn, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GTask *thread_task, *caller_task; caller_task = g_task_new (conn, cancellable, callback, user_data); g_task_set_source_tag (caller_task, g_tls_connection_base_handshake_async); g_task_set_priority (caller_task, io_priority); thread_task = g_task_new (conn, cancellable, handshake_thread_completed, caller_task); g_task_set_source_tag (thread_task, g_tls_connection_base_handshake_async); g_task_set_priority (thread_task, io_priority); g_task_run_in_thread (thread_task, async_handshake_thread); g_object_unref (thread_task); }
static void g_tls_connection_base_close_async (GIOStream *stream, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GTask *task; task = g_task_new (stream, cancellable, callback, user_data); g_task_set_source_tag (task, g_tls_connection_base_close_async); g_task_set_priority (task, io_priority); g_task_run_in_thread (task, close_thread); g_object_unref (task); }
static void g_async_initable_real_init_async (GAsyncInitable *initable, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GTask *task; g_return_if_fail (G_IS_INITABLE (initable)); 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); }
/** * media_art_remove_async: * @artist: artist the media art belongs to * @album: (allow-none): album the media art belongs or %NULL * @source_object: (allow-none): the #GObject this task belongs to, * can be %NULL. * @io_priority: the [I/O priority][io-priority] of the request * @cancellable: (allow-none): optional #GCancellable object, %NULL to * ignore * @callback: (scope async): a #GAsyncReadyCallback to call when the * request is satisfied * @user_data: (closure): the data to pass to callback function * * Removes media art for given album/artist provided. Precisely the * same operation as media_art_remove() is performing, but * asynchronously. * * When all i/o for the operation is finished the @callback will be * called. * * In case of a partial error the callback will be called with any * succeeding items and no error, and on the next request the error * will be reported. If a request is cancelled the callback will be * called with %G_IO_ERROR_CANCELLED. * * During an async request no other sync and async calls are allowed, * and will result in %G_IO_ERROR_PENDING errors. * * Any outstanding i/o request with higher priority (lower numerical * value) will be executed before an outstanding request with lower * priority. Default priority is %G_PRIORITY_DEFAULT. * * Since: 0.7.0 */ void media_art_remove_async (const gchar *artist, const gchar *album, gint io_priority, GObject *source_object, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GTask *task; task = g_task_new (source_object, cancellable, callback, user_data); g_task_set_task_data (task, remove_data_new (artist, album), (GDestroyNotify) remove_data_free); g_task_set_priority (task, io_priority); g_task_run_in_thread (task, remove_thread); g_object_unref (task); }
static void g_unix_input_stream_close_async (GInputStream *stream, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GTask *task; GError *error = NULL; task = g_task_new (stream, cancellable, callback, user_data); g_task_set_priority (task, io_priority); if (g_unix_input_stream_close (stream, cancellable, &error)) g_task_return_boolean (task, TRUE); else g_task_return_error (task, error); g_object_unref (task); }
static void ide_git_vcs_list_status_async (IdeVcs *vcs, GFile *directory_or_file, gboolean include_descendants, gint io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { IdeGitVcs *self = (IdeGitVcs *)vcs; g_autoptr(GTask) task = NULL; ListStatus *state; IDE_ENTRY; g_return_if_fail (IDE_IS_GIT_VCS (self)); g_return_if_fail (!directory_or_file || G_IS_FILE (directory_or_file)); g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); g_mutex_lock (&self->repository_mutex); state = g_slice_new0 (ListStatus); state->directory_or_file = g_object_ref (directory_or_file); state->repository_location = ggit_repository_get_location (self->repository); state->recursive = !!include_descendants; g_mutex_unlock (&self->repository_mutex); task = g_task_new (self, cancellable, callback, user_data); g_task_set_source_tag (task, ide_git_vcs_list_status_async); g_task_set_priority (task, io_priority); g_task_set_return_on_cancel (task, TRUE); g_task_set_task_data (task, state, list_status_free); if (state->repository_location == NULL) g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED, "No repository loaded"); else g_task_run_in_thread (task, ide_git_vcs_list_status_worker); IDE_EXIT; }
static void gbp_flatpak_dependency_updater_update_async (IdeDependencyUpdater *updater, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GbpFlatpakDependencyUpdater *self = (GbpFlatpakDependencyUpdater *)updater; GbpFlatpakDownloadStage *stage = NULL; g_autoptr(GTask) task = NULL; IdeBuildPipeline *pipeline; IdeBuildManager *manager; IdeContext *context; g_assert (GBP_IS_FLATPAK_DEPENDENCY_UPDATER (self)); g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); task = g_task_new (self, cancellable, callback, user_data); g_task_set_source_tag (task, gbp_flatpak_dependency_updater_update_async); g_task_set_priority (task, G_PRIORITY_LOW); context = ide_object_get_context (IDE_OBJECT (self)); g_assert (IDE_IS_CONTEXT (context)); manager = ide_context_get_build_manager (context); g_assert (IDE_IS_BUILD_MANAGER (manager)); pipeline = ide_build_manager_get_pipeline (manager); g_assert (!pipeline || IDE_IS_BUILD_PIPELINE (pipeline)); if (pipeline == NULL) { g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED, "Cannot update flatpak dependencies until build pipeline is initialized"); return; } /* Find the downloads stage and tell it to download updates one time */ ide_build_pipeline_foreach_stage (pipeline, find_download_stage_cb, &stage); if (stage == NULL) { /* Synthesize success if they weren't using flatpak. */ g_task_return_boolean (task, TRUE); return; } gbp_flatpak_download_stage_force_update (stage); /* Ensure downloads and everything past it is invalidated */ ide_build_pipeline_invalidate_phase (pipeline, IDE_BUILD_PHASE_DOWNLOADS); /* Start building all the way up to the project configure so that * the user knows if the updates broke their configuration or anything. */ ide_build_manager_rebuild_async (manager, IDE_BUILD_PHASE_CONFIGURE, NULL, gbp_flatpak_dependency_updater_update_cb, g_steal_pointer (&task)); }