Only the (non-TLS) port can be set on it -- v2: rename to GVirConfigDeviceGraphicsSpice fix node creation (missing "type" attribute) derive GVirConfigDeviceGraphicsSpice from GVirConfigDeviceGraphics use g_return_if_fail to test function args for sanity v3: rename to GVirConfigDomainGraphicsSpice --- libvirt-gconfig/Makefile.am | 2 + .../libvirt-gconfig-domain-graphics-spice.c | 106 ++++++++++++++++++++ .../libvirt-gconfig-domain-graphics-spice.h | 69 +++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 5 + libvirt-gconfig/tests/test-domain-create.c | 7 ++ 6 files changed, 190 insertions(+), 0 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 2ed140f..a596ad9 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -16,6 +16,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-device.h \ libvirt-gconfig-domain-disk.h \ libvirt-gconfig-domain-graphics.h \ + libvirt-gconfig-domain-graphics-spice.h \ libvirt-gconfig-domain-input.h \ libvirt-gconfig-domain-interface.h \ libvirt-gconfig-domain-interface-network.h \ @@ -41,6 +42,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-device.c \ libvirt-gconfig-domain-disk.c \ libvirt-gconfig-domain-graphics.c \ + libvirt-gconfig-domain-graphics-spice.c \ libvirt-gconfig-domain-input.c \ libvirt-gconfig-domain-interface.c \ libvirt-gconfig-domain-interface-network.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c new file mode 100644 index 0000000..e49a818 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c @@ -0,0 +1,106 @@ +/* + * libvirt-gobject-config-domain-graphics-spice.c: libvirt glib integration + * + * Copyright (C) 2011 Red Hat + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Christophe Fergeau <cfergeau@xxxxxxxxx> + */ + +#include <config.h> + +#include <string.h> + +#include <libxml/tree.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-helpers-private.h" +#include "libvirt-gconfig/libvirt-gconfig-object-private.h" + +extern gboolean debugFlag; + +#define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0) + +#define GVIR_CONFIG_DOMAIN_GRAPHICS_SPICE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_DOMAIN_GRAPHICS_SPICE, GVirConfigDomainGraphicsSpicePrivate)) + +struct _GVirConfigDomainGraphicsSpicePrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigDomainGraphicsSpice, gvir_config_domain_graphics_spice, GVIR_TYPE_CONFIG_DOMAIN_GRAPHICS); + + +static void gvir_config_domain_graphics_spice_class_init(GVirConfigDomainGraphicsSpiceClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigDomainGraphicsSpicePrivate)); +} + + +static void gvir_config_domain_graphics_spice_init(GVirConfigDomainGraphicsSpice *graphics_spice) +{ + GVirConfigDomainGraphicsSpicePrivate *priv; + + DEBUG("Init GVirConfigDomainGraphicsSpice=%p", graphics_spice); + + priv = graphics_spice->priv = GVIR_CONFIG_DOMAIN_GRAPHICS_SPICE_GET_PRIVATE(graphics_spice); + + memset(priv, 0, sizeof(*priv)); +} + + +GVirConfigDomainGraphicsSpice *gvir_config_domain_graphics_spice_new(void) +{ + xmlDocPtr doc; + xmlNodePtr node; + + doc = xmlNewDoc((xmlChar *)"1.0"); + node= xmlNewDocNode(doc, NULL, (xmlChar *)"graphics", NULL); + xmlNewProp(doc->children, (xmlChar*)"type", (xmlChar*)"spice"); + xmlDocSetRootElement(doc, node); + return GVIR_CONFIG_DOMAIN_GRAPHICS_SPICE(g_object_new(GVIR_TYPE_CONFIG_DOMAIN_GRAPHICS_SPICE, + "node", node, + NULL)); +} + +GVirConfigDomainGraphicsSpice *gvir_config_domain_graphics_spice_new_from_xml(const gchar *xml, + GError **error) +{ + xmlNodePtr node; + + node = gvir_config_xml_parse(xml, "graphics", error); + if ((error != NULL) && (*error != NULL)) + return NULL; + xmlNewProp(node, (xmlChar*)"type", (xmlChar*)"spice"); + return GVIR_CONFIG_DOMAIN_GRAPHICS_SPICE(g_object_new(GVIR_TYPE_CONFIG_DOMAIN_GRAPHICS_SPICE, + "node", node, + NULL)); +} + +void gvir_config_domain_graphics_spice_set_port(GVirConfigDomainGraphicsSpice *graphics, + unsigned int port) +{ + xmlNodePtr node; + char *port_str; + + g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_GRAPHICS_SPICE(graphics)); + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(graphics)); + g_return_if_fail(node != NULL); + port_str = g_strdup_printf("%u", port); + xmlNewProp(node, (xmlChar*)"port", (xmlChar*)port_str); + g_free(port_str); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h new file mode 100644 index 0000000..11d32a1 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h @@ -0,0 +1,69 @@ +/* + * libvirt-gconfig-domain-graphics-spice.h: libvirt gobject integration + * + * Copyright (C) 2011 Red Hat + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Christophe Fergeau <cfergeau@xxxxxxxxx> + */ + +#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD) +#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly." +#endif + +#ifndef __LIBVIRT_GCONFIG_DOMAIN_GRAPHICS_SPICE_H__ +#define __LIBVIRT_GCONFIG_DOMAIN_GRAPHICS_SPICE_H__ + +G_BEGIN_DECLS + +#define GVIR_TYPE_CONFIG_DOMAIN_GRAPHICS_SPICE (gvir_config_domain_graphics_spice_get_type ()) +#define GVIR_CONFIG_DOMAIN_GRAPHICS_SPICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_DOMAIN_GRAPHICS_SPICE, GVirConfigDomainGraphicsSpice)) +#define GVIR_CONFIG_DOMAIN_GRAPHICS_SPICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_DOMAIN_GRAPHICS_SPICE, GVirConfigDomainGraphicsSpiceClass)) +#define GVIR_IS_CONFIG_DOMAIN_GRAPHICS_SPICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_DOMAIN_GRAPHICS_SPICE)) +#define GVIR_IS_CONFIG_DOMAIN_GRAPHICS_SPICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_DOMAIN_GRAPHICS_SPICE)) +#define GVIR_CONFIG_DOMAIN_GRAPHICS_SPICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_DOMAIN_GRAPHICS_SPICE, GVirConfigDomainGraphicsSpiceClass)) + +typedef struct _GVirConfigDomainGraphicsSpice GVirConfigDomainGraphicsSpice; +typedef struct _GVirConfigDomainGraphicsSpicePrivate GVirConfigDomainGraphicsSpicePrivate; +typedef struct _GVirConfigDomainGraphicsSpiceClass GVirConfigDomainGraphicsSpiceClass; + +struct _GVirConfigDomainGraphicsSpice +{ + GVirConfigDomainGraphics parent; + + GVirConfigDomainGraphicsSpicePrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigDomainGraphicsSpiceClass +{ + GVirConfigDomainGraphicsClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_domain_graphics_spice_get_type(void); + +GVirConfigDomainGraphicsSpice *gvir_config_domain_graphics_spice_new(void); +GVirConfigDomainGraphicsSpice *gvir_config_domain_graphics_spice_new_from_xml(const gchar *xml, + GError **error); +void gvir_config_domain_graphics_spice_set_port(GVirConfigDomainGraphicsSpice *graphics, + unsigned int port); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DOMAIN_GRAPHICS_SPICE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index b3fb0f1..3619c1d 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -33,6 +33,7 @@ #include <libvirt-gconfig/libvirt-gconfig-domain-device.h> #include <libvirt-gconfig/libvirt-gconfig-domain-disk.h> #include <libvirt-gconfig/libvirt-gconfig-domain-graphics.h> +#include <libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h> #include <libvirt-gconfig/libvirt-gconfig-domain-input.h> #include <libvirt-gconfig/libvirt-gconfig-domain-interface.h> #include <libvirt-gconfig/libvirt-gconfig-domain-interface-network.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index e3ba263..ba036ab 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -46,6 +46,11 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_domain_graphics_get_type; + gvir_config_domain_graphics_spice_get_type; + gvir_config_domain_graphics_spice_new; + gvir_config_domain_graphics_spice_new_from_xml; + gvir_config_domain_graphics_spice_set_port; + gvir_config_domain_input_get_type; gvir_config_domain_input_device_type_get_type; gvir_config_domain_input_new; diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index b0ed210..34cc2dc 100644 --- a/libvirt-gconfig/tests/test-domain-create.c +++ b/libvirt-gconfig/tests/test-domain-create.c @@ -113,6 +113,13 @@ int main(void) gvir_config_domain_input_set_bus(input, GVIR_CONFIG_DOMAIN_INPUT_BUS_USB); devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(input)); + /* graphics node */ + GVirConfigDomainGraphicsSpice *graphics; + + graphics = gvir_config_domain_graphics_spice_new(); + gvir_config_domain_graphics_spice_set_port(graphics, 1234); + devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(graphics)); + gvir_config_domain_set_devices(domain, devices); g_list_free(devices); -- 1.7.7.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list