/** * gom_repository_migrate_async: * @repository: (in): A #GomRepository. * @version: (in): The version to migrate to. * @migrator: (in) (scope async): A function to perform the migrations. * @migrator_data: (in): User data for @migrator * @callback: (in): A callback to execute upon completion. * @user_data: (in): User data for @callback. * * Asynchronously performs a migration on the underlying database. This will * call @migrator from the SQLite thread for each migration to perform. * * Upon completion, @callback will be executed and it must call * gom_repository_migrate_finish(). */ void gom_repository_migrate_async (GomRepository *repository, guint version, GomRepositoryMigrator migrator, gpointer migrator_data, GAsyncReadyCallback callback, gpointer user_data) { GomRepositoryPrivate *priv; GSimpleAsyncResult *simple; g_return_if_fail(GOM_IS_REPOSITORY(repository)); g_return_if_fail(migrator != NULL); g_return_if_fail(callback != NULL); g_return_if_fail(version >= 1); priv = repository->priv; simple = g_simple_async_result_new(G_OBJECT(repository), callback, user_data, gom_repository_migrate_async); g_object_set_data(G_OBJECT(simple), "version", GINT_TO_POINTER(version)); g_object_set_data(G_OBJECT(simple), "migrator", migrator); g_object_set_data(G_OBJECT(simple), "migrator_data", migrator_data); gom_adapter_queue_write(priv->adapter, gom_repository_migrate_cb, simple); }
void gom_resource_save_async (GomResource *resource, GAsyncReadyCallback callback, gpointer user_data) { GomResourcePrivate *priv; GSimpleAsyncResult *simple; GomAdapter *adapter; g_return_if_fail(GOM_IS_RESOURCE(resource)); g_return_if_fail(callback != NULL); priv = resource->priv; if (!priv->repository) { g_warning("Cannot save resource, no repository set!"); return; } simple = g_simple_async_result_new(G_OBJECT(resource), callback, user_data, gom_resource_save_async); adapter = gom_repository_get_adapter(priv->repository); g_assert(GOM_IS_ADAPTER(adapter)); gom_resource_build_save_cmd(resource, adapter); gom_adapter_queue_write(adapter, gom_resource_save_cb, simple); }
/** * gom_resource_save_sync: * @resource: (in): A #GomResource. * @error: (out): A location for a #GError, or %NULL. * * Returns: %TRUE if successful; otherwise %FALSE. */ gboolean gom_resource_save_sync (GomResource *resource, GError **error) { GomResourcePrivate *priv; GomAdapter *adapter; GAsyncQueue *queue; GSimpleAsyncResult *simple; gboolean ret; g_return_val_if_fail(GOM_IS_RESOURCE(resource), FALSE); priv = resource->priv; if (!priv->repository) { g_set_error(error, GOM_ERROR, GOM_ERROR_COMMAND_NO_REPOSITORY, _("Cannot save resource, no repository set")); return FALSE; } queue = g_async_queue_new(); simple = g_simple_async_result_new(G_OBJECT(resource), NULL, NULL, gom_resource_save_sync); adapter = gom_repository_get_adapter(priv->repository); g_object_set_data(G_OBJECT(simple), "queue", queue); g_assert(GOM_IS_ADAPTER(adapter)); gom_resource_build_save_cmd(resource, adapter); gom_adapter_queue_write(adapter, gom_resource_save_cb, simple); g_async_queue_pop(queue); g_async_queue_unref(queue); if (!(ret = g_simple_async_result_get_op_res_gboolean(simple))) { g_simple_async_result_propagate_error(simple, error); } if (ret) set_post_save_properties(resource); g_object_unref(simple); return ret; }
/** * gom_repository_migrate_sync: * @repository: (in): A #GomRepository. * @version: (in): The version to migrate to. * @migrator: (in) (scope call): A function to perform the migrations. * @migrator_data: (in): User data for @migrator. * @error: a #GError * * Performs a migration on the underlying database. This will * call @migrator from the SQLite thread for each migration to perform. * * Returns: #TRUE in case of success. */ gboolean gom_repository_migrate_sync (GomRepository *repository, guint version, GomRepositoryMigrator migrator, gpointer migrator_data, GError **error) { GomRepositoryPrivate *priv; GSimpleAsyncResult *simple; GAsyncQueue *queue; gboolean ret; g_return_val_if_fail(GOM_IS_REPOSITORY(repository), FALSE); g_return_val_if_fail(migrator != NULL, FALSE); g_return_val_if_fail(version >= 1, FALSE); priv = repository->priv; queue = g_async_queue_new(); simple = g_simple_async_result_new(G_OBJECT(repository), NULL, NULL, gom_repository_migrate_sync); g_object_set_data(G_OBJECT(simple), "version", GINT_TO_POINTER(version)); g_object_set_data(G_OBJECT(simple), "migrator", migrator); g_object_set_data(G_OBJECT(simple), "migrator_data", migrator_data); g_object_set_data(G_OBJECT(simple), "queue", queue); gom_adapter_queue_write(priv->adapter, gom_repository_migrate_cb, simple); g_async_queue_pop(queue); g_async_queue_unref(queue); if (!(ret = g_simple_async_result_get_op_res_gboolean(simple))) { g_simple_async_result_propagate_error(simple, error); } g_object_unref(simple); return ret; }