[virt-tools-list] [PATCH virt-viewer 1/9] ovirt-foreign-menu: Set new ISO name using GTask API
Eduardo Lima (Etrunko)
etrunko at redhat.com
Thu Jan 19 15:16:19 UTC 2017
On 18/01/17 14:31, Christophe Fergeau wrote:
> On Wed, Jan 18, 2017 at 12:16:52PM -0200, Eduardo Lima (Etrunko) wrote:
>> This is done with the new ovirt_foreign_menu_set_current_iso_name_async
>> function.
>>
>> Signed-off-by: Eduardo Lima (Etrunko) <etrunko at redhat.com>
>> ---
>> src/ovirt-foreign-menu.c | 117 ++++++++++++++++++++++++++++++++++-------------
>> src/ovirt-foreign-menu.h | 10 ++++
>> 2 files changed, 96 insertions(+), 31 deletions(-)
>>
>> diff --git a/src/ovirt-foreign-menu.c b/src/ovirt-foreign-menu.c
>> index a51f2c9..366259a 100644
>> --- a/src/ovirt-foreign-menu.c
>> +++ b/src/ovirt-foreign-menu.c
>> @@ -344,38 +344,102 @@ menu_item_set_active_no_signal(GtkMenuItem *menuitem,
>> }
>>
>>
>> -static void updated_cdrom_cb(GObject *source_object,
>> - GAsyncResult *result,
>> - gpointer user_data)
>> +static void iso_name_set_cb(GObject *source_object,
>> + GAsyncResult *result,
>> + gpointer user_data)
>> {
>> GError *error = NULL;
>> - OvirtForeignMenu *foreign_menu;
>> + GTask *task = G_TASK(user_data);
>> + OvirtForeignMenu *foreign_menu = OVIRT_FOREIGN_MENU(g_task_get_source_object(task));
>> gboolean updated;
>>
>> - foreign_menu = OVIRT_FOREIGN_MENU(user_data);
>> updated = ovirt_cdrom_update_finish(OVIRT_CDROM(source_object),
>> result, &error);
>> - g_debug("Finished updating cdrom content");
>> if (updated) {
>> + g_debug("Finished updating cdrom content: %s", foreign_menu->priv->next_iso_name);
>> g_free(foreign_menu->priv->current_iso_name);
>> foreign_menu->priv->current_iso_name = foreign_menu->priv->next_iso_name;
>> foreign_menu->priv->next_iso_name = NULL;
>> - g_object_notify(G_OBJECT(foreign_menu), "file");
>> + g_task_return_boolean(task, TRUE);
>> + goto end;
>> + }
>> +
>> + /* Reset old state back as we were not successful in switching to
>> + * the new ISO */
>> + g_debug("setting OvirtCdrom:file back to '%s'",
>> + foreign_menu->priv->current_iso_name);
>> + g_object_set(foreign_menu->priv->cdrom, "file",
>> + foreign_menu->priv->current_iso_name, NULL);
>> + g_clear_pointer(&foreign_menu->priv->next_iso_name, g_free);
>> +
>> + if (error != NULL) {
>> + g_warning("failed to update cdrom resource: %s", error->message);
>> + g_task_return_error(task, error);
>> } else {
>> - /* Reset old state back as we were not successful in switching to
>> - * the new ISO */
>> - const char *current_file = foreign_menu->priv->current_iso_name;
>> + g_warn_if_reached();
>> + g_task_return_new_error(task, OVIRT_ERROR, OVIRT_ERROR_FAILED,
>> + "failed to update cdrom resource");
>> + }
>>
>> - if (error != NULL) {
>> - g_warning("failed to update cdrom resource: %s", error->message);
>> - g_clear_error(&error);
>> - }
>> - g_debug("setting OvirtCdrom:file back to '%s'",
>> - current_file?current_file:NULL);
>> - g_object_set(foreign_menu->priv->cdrom, "file", current_file, NULL);
>> +end:
>> + g_object_unref(task);
>> +}
>> +
>> +
>> +void ovirt_foreign_menu_set_current_iso_name_async(OvirtForeignMenu *foreign_menu,
>> + const char *name,
>> + GCancellable *cancellable,
>> + GAsyncReadyCallback callback,
>> + gpointer user_data)
>> +{
>> + GTask *task;
>> +
>> + g_return_if_fail(foreign_menu->priv->cdrom != NULL);
>> + g_return_if_fail(foreign_menu->priv->next_iso_name == NULL);
>> +
>> + if (name) {
>> + g_debug("Updating VM cdrom image to '%s'", name);
>> + foreign_menu->priv->next_iso_name = g_strdup(name);
>> + } else {
>> + g_debug("Removing current cdrom image");
>> + foreign_menu->priv->next_iso_name = NULL;
>> }
>>
>> - g_clear_pointer(&foreign_menu->priv->next_iso_name, g_free);
>> + g_object_set(foreign_menu->priv->cdrom,
>> + "file", name,
>> + NULL);
>> +
>> + task = g_task_new(foreign_menu, cancellable, callback, user_data);
>> + ovirt_cdrom_update_async(foreign_menu->priv->cdrom, TRUE,
>> + foreign_menu->priv->proxy, NULL,
>> + iso_name_set_cb, task);
>
> I think you can pass 'cancellable' to that method.
>
> Apart from this small thing, looks good to me,
>
> Acked-by: Christophe Fergeau <cfergeau at redhat.com>
Fixed and pushed, thanks.
--
Eduardo de Barros Lima (Etrunko)
Software Engineer - RedHat
etrunko at redhat.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/virt-tools-list/attachments/20170119/89273cea/attachment.sig>
More information about the virt-tools-list
mailing list