From: Visarion Alexandru <viorel.visarion@xxxxxxxxx> Learn to get/set the listen devices that spice graphics is using. When setting the listen devices, first remove the 'listen' attribute to avoid the inconsistencies checks between the 'listen' attribute and the 'address' attribute of the 'listen' node. --- .../libvirt-gconfig-domain-graphics-spice.c | 84 ++++++++++++++++++++++ .../libvirt-gconfig-domain-graphics-spice.h | 4 ++ libvirt-gconfig/libvirt-gconfig.sym | 2 + 3 files changed, 90 insertions(+) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c index 079ea27..133eb1f 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c @@ -157,6 +157,90 @@ void gvir_config_domain_graphics_spice_set_image_compression compression); } +/** + * gvir_config_domain_graphics_spice_set_listen_devices: + * @graphics: a #GVirConfigDomainGraphicsSpice + * @listens: (in) (element-type LibvirtGConfig.DomainGraphicsListen): listens + * + * This method is used to set the various listen nodes a #GVirConfigDomainGraphicsSpice + * device can handle. +*/ +void gvir_config_domain_graphics_spice_set_listen_devices(GVirConfigDomainGraphicsSpice *graphics, + GList *listens) +{ + GList *it; + + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_GRAPHICS_SPICE(graphics)); + + gvir_config_object_remove_attribute (GVIR_CONFIG_OBJECT(graphics), + "listen"); + gvir_config_object_delete_children (GVIR_CONFIG_OBJECT (graphics), + "listen", NULL); + + for (it = listens; it != NULL; it = it->next) { + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_GRAPHICS_LISTEN(it->data)); + + gvir_config_object_attach_add(GVIR_CONFIG_OBJECT(graphics), + GVIR_CONFIG_OBJECT(it->data)); + } +} + +struct ListenData { + GVirConfigXmlDoc *doc; + const gchar *schema; + GList *listen_devices; +}; + +static gboolean add_listen(xmlNodePtr node, gpointer opaque) +{ + struct ListenData* data = (struct ListenData*)opaque; + GVirConfigObject *object; + + if (g_strcmp0((const gchar *)node->name, "listen") != 0) + return TRUE; + + object = gvir_config_object_new_from_tree + (GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_LISTEN_ADDRESS, + data->doc, + data->schema, + node); + if (object != NULL) + data->listen_devices = g_list_append(data->listen_devices, object); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_domain_graphics_spice_get_listen_devices: + * + * Gets all the listen not of #GVirConfigDomainGraphicsSpice + * + * Returns: (element-type LibvirtGConfig.DomainGraphicsListen) (transfer full): + * a newly allocated #GList of #GVirConfigDomainGraphicsListen. + */ +GList * +gvir_config_domain_graphics_spice_get_listen_devices(GVirConfigDomainGraphicsSpice *graphics) +{ + struct ListenData data; + + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_GRAPHICS_SPICE(graphics), NULL); + + g_object_get(G_OBJECT(graphics), "doc", &data.doc, NULL); + g_return_val_if_fail(data.doc != NULL, NULL); + data.schema = gvir_config_object_get_schema(GVIR_CONFIG_OBJECT(graphics)); + data.listen_devices = NULL; + + gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(graphics), + NULL, + add_listen, + &data); + g_clear_object(&data.doc); + + return data.listen_devices; +} + void gvir_config_domain_graphics_spice_set_gl(GVirConfigDomainGraphicsSpice *graphics, gboolean gl) { diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h index 25c132e..faf3c7a 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h @@ -95,6 +95,10 @@ gvir_config_domain_graphics_spice_get_image_compression void gvir_config_domain_graphics_spice_set_gl(GVirConfigDomainGraphicsSpice *graphics, gboolean gl); +void gvir_config_domain_graphics_spice_set_listen_devices(GVirConfigDomainGraphicsSpice *graphics, + GList *listens); +GList *gvir_config_domain_graphics_spice_get_listen_devices(GVirConfigDomainGraphicsSpice *graphics); + G_END_DECLS #endif /* __LIBVIRT_GCONFIG_DOMAIN_GRAPHICS_SPICE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index e30ad04..e4f50de 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -749,7 +749,9 @@ global: gvir_config_domain_graphics_listen_address_set_address; gvir_config_domain_graphics_listen_address_set_inet_address; gvir_config_domain_graphics_listen_get_type; + gvir_config_domain_graphics_spice_get_listen_devices; gvir_config_domain_graphics_spice_set_gl; + gvir_config_domain_graphics_spice_set_listen_devices; gvir_config_domain_graphics_vnc_get_listen_devices; gvir_config_domain_graphics_vnc_set_listen_devices; -- 2.7.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list