From: Visarion Alexandru <viorel.visarion(a)gmail.com>
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 | 87 +++++++++++++++++++++-
.../libvirt-gconfig-domain-graphics-spice.h | 4 +
libvirt-gconfig/libvirt-gconfig.sym | 2 +
3 files changed, 92 insertions(+), 1 deletion(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c
b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c
index 079ea27..7e0bd9f 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c
@@ -1,7 +1,8 @@
/*
* libvirt-gconfig-domain-graphics-spice.c: libvirt domain SPICE configuration
*
- * Copyright (C) 2011 Red Hat, Inc.
+ * Copyright (C) 2011-2016 Red Hat, Inc.
+ * Copyright (C) 2016 Visarion Alexandru <viorel.visarion(a)gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -157,6 +158,90 @@ void gvir_config_domain_graphics_spice_set_image_compression
compression);
}
+/**
+ * gvir_config_domain_graphics_spice_set_listen:
+ * @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(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:
+ *
+ * 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(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..1632cc9 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(GVirConfigDomainGraphicsSpice
*graphics,
+ GList *listens);
+GList *gvir_config_domain_graphics_spice_get_listen(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 6898597..6d8be60 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;
gvir_config_domain_graphics_spice_set_gl;
+ gvir_config_domain_graphics_spice_set_listen;
gvir_config_domain_graphics_vnc_get_listen;
gvir_config_domain_graphics_vnc_set_listen;
--
2.7.4