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
---
libvirt-gconfig/Makefile.am | 2 +
.../libvirt-gconfig-device-graphics-spice.c | 106 ++++++++++++++++++++
.../libvirt-gconfig-device-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-device-graphics-spice.c
create mode 100644 libvirt-gconfig/libvirt-gconfig-device-graphics-spice.h
diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am
index 8aaa827..1be6233 100644
--- a/libvirt-gconfig/Makefile.am
+++ b/libvirt-gconfig/Makefile.am
@@ -15,6 +15,7 @@ GCONFIG_HEADER_FILES = \
libvirt-gconfig-device.h \
libvirt-gconfig-device-disk.h \
libvirt-gconfig-device-graphics.h \
+ libvirt-gconfig-device-graphics-spice.h \
libvirt-gconfig-device-input.h \
libvirt-gconfig-domain.h \
libvirt-gconfig-domain-snapshot.h \
@@ -39,6 +40,7 @@ GCONFIG_SOURCE_FILES = \
libvirt-gconfig-device.c \
libvirt-gconfig-device-disk.c \
libvirt-gconfig-device-graphics.c \
+ libvirt-gconfig-device-graphics-spice.c \
libvirt-gconfig-device-input.c \
libvirt-gconfig-domain.c \
libvirt-gconfig-domain-snapshot.c \
diff --git a/libvirt-gconfig/libvirt-gconfig-device-graphics-spice.c
b/libvirt-gconfig/libvirt-gconfig-device-graphics-spice.c
new file mode 100644
index 0000000..6694f57
--- /dev/null
+++ b/libvirt-gconfig/libvirt-gconfig-device-graphics-spice.c
@@ -0,0 +1,106 @@
+/*
+ * libvirt-gobject-config-device-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(a)gmail.com>
+ */
+
+#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_DEVICE_GRAPHICS_SPICE_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_DEVICE_GRAPHICS_SPICE,
GVirConfigDeviceGraphicsSpicePrivate))
+
+struct _GVirConfigDeviceGraphicsSpicePrivate
+{
+ gboolean unused;
+};
+
+G_DEFINE_TYPE(GVirConfigDeviceGraphicsSpice, gvir_config_device_graphics_spice,
GVIR_TYPE_CONFIG_DEVICE_GRAPHICS);
+
+
+static void
gvir_config_device_graphics_spice_class_init(GVirConfigDeviceGraphicsSpiceClass *klass)
+{
+ g_type_class_add_private(klass, sizeof(GVirConfigDeviceGraphicsSpicePrivate));
+}
+
+
+static void gvir_config_device_graphics_spice_init(GVirConfigDeviceGraphicsSpice
*graphics_spice)
+{
+ GVirConfigDeviceGraphicsSpicePrivate *priv;
+
+ DEBUG("Init GVirConfigDeviceGraphicsSpice=%p", graphics_spice);
+
+ priv = graphics_spice->priv =
GVIR_CONFIG_DEVICE_GRAPHICS_SPICE_GET_PRIVATE(graphics_spice);
+
+ memset(priv, 0, sizeof(*priv));
+}
+
+
+GVirConfigDeviceGraphicsSpice *gvir_config_device_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_DEVICE_GRAPHICS_SPICE(g_object_new(GVIR_TYPE_CONFIG_DEVICE_GRAPHICS_SPICE,
+ "node", node,
+ NULL));
+}
+
+GVirConfigDeviceGraphicsSpice *gvir_config_device_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_DEVICE_GRAPHICS_SPICE(g_object_new(GVIR_TYPE_CONFIG_DEVICE_GRAPHICS_SPICE,
+ "node", node,
+ NULL));
+}
+
+void gvir_config_device_graphics_spice_set_port(GVirConfigDeviceGraphicsSpice *graphics,
+ unsigned int port)
+{
+ xmlNodePtr node;
+ char *port_str;
+
+ g_return_if_fail(GVIR_IS_CONFIG_DEVICE_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-device-graphics-spice.h
b/libvirt-gconfig/libvirt-gconfig-device-graphics-spice.h
new file mode 100644
index 0000000..39cba74
--- /dev/null
+++ b/libvirt-gconfig/libvirt-gconfig-device-graphics-spice.h
@@ -0,0 +1,69 @@
+/*
+ * libvirt-gconfig-device-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(a)gmail.com>
+ */
+
+#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD)
+#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included
directly."
+#endif
+
+#ifndef __LIBVIRT_GCONFIG_DEVICE_GRAPHICS_SPICE_H__
+#define __LIBVIRT_GCONFIG_DEVICE_GRAPHICS_SPICE_H__
+
+G_BEGIN_DECLS
+
+#define GVIR_TYPE_CONFIG_DEVICE_GRAPHICS_SPICE
(gvir_config_device_graphics_spice_get_type ())
+#define GVIR_CONFIG_DEVICE_GRAPHICS_SPICE(obj) (G_TYPE_CHECK_INSTANCE_CAST
((obj), GVIR_TYPE_CONFIG_DEVICE_GRAPHICS_SPICE, GVirConfigDeviceGraphicsSpice))
+#define GVIR_CONFIG_DEVICE_GRAPHICS_SPICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST
((klass), GVIR_TYPE_CONFIG_DEVICE_GRAPHICS_SPICE, GVirConfigDeviceGraphicsSpiceClass))
+#define GVIR_IS_CONFIG_DEVICE_GRAPHICS_SPICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE
((obj), GVIR_TYPE_CONFIG_DEVICE_GRAPHICS_SPICE))
+#define GVIR_IS_CONFIG_DEVICE_GRAPHICS_SPICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE
((klass), GVIR_TYPE_CONFIG_DEVICE_GRAPHICS_SPICE))
+#define GVIR_CONFIG_DEVICE_GRAPHICS_SPICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS
((obj), GVIR_TYPE_CONFIG_DEVICE_GRAPHICS_SPICE, GVirConfigDeviceGraphicsSpiceClass))
+
+typedef struct _GVirConfigDeviceGraphicsSpice GVirConfigDeviceGraphicsSpice;
+typedef struct _GVirConfigDeviceGraphicsSpicePrivate
GVirConfigDeviceGraphicsSpicePrivate;
+typedef struct _GVirConfigDeviceGraphicsSpiceClass GVirConfigDeviceGraphicsSpiceClass;
+
+struct _GVirConfigDeviceGraphicsSpice
+{
+ GVirConfigDeviceGraphics parent;
+
+ GVirConfigDeviceGraphicsSpicePrivate *priv;
+
+ /* Do not add fields to this struct */
+};
+
+struct _GVirConfigDeviceGraphicsSpiceClass
+{
+ GVirConfigDeviceGraphicsClass parent_class;
+
+ gpointer padding[20];
+};
+
+GType gvir_config_device_graphics_spice_get_type(void);
+
+GVirConfigDeviceGraphicsSpice *gvir_config_device_graphics_spice_new(void);
+GVirConfigDeviceGraphicsSpice *gvir_config_device_graphics_spice_new_from_xml(const gchar
*xml,
+ GError
**error);
+void gvir_config_device_graphics_spice_set_port(GVirConfigDeviceGraphicsSpice *graphics,
+ unsigned int port);
+
+G_END_DECLS
+
+#endif /* __LIBVIRT_GCONFIG_DEVICE_GRAPHICS_SPICE_H__ */
diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h
index 8b56655..7e2e531 100644
--- a/libvirt-gconfig/libvirt-gconfig.h
+++ b/libvirt-gconfig/libvirt-gconfig.h
@@ -35,6 +35,7 @@
#include <libvirt-gconfig/libvirt-gconfig-device-input.h>
#include <libvirt-gconfig/libvirt-gconfig-domain-snapshot.h>
#include <libvirt-gconfig/libvirt-gconfig-enum-types.h>
+#include <libvirt-gconfig/libvirt-gconfig-device-graphics-spice.h>
#include <libvirt-gconfig/libvirt-gconfig-helpers.h>
#include <libvirt-gconfig/libvirt-gconfig-interface.h>
#include <libvirt-gconfig/libvirt-gconfig-interface-network.h>
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index 484ae39..71bca2c 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -31,6 +31,11 @@ LIBVIRT_GOBJECT_0.0.1 {
gvir_config_device_graphics_get_type;
+ gvir_config_device_graphics_spice_get_type;
+ gvir_config_device_graphics_spice_new;
+ gvir_config_device_graphics_spice_new_from_xml;
+ gvir_config_device_graphics_spice_set_port;
+
gvir_config_device_input_get_type;
gvir_config_device_input_device_type_get_type;
gvir_config_device_input_new;
diff --git a/libvirt-gconfig/tests/test-domain-create.c
b/libvirt-gconfig/tests/test-domain-create.c
index 63a625f..6b0486e 100644
--- a/libvirt-gconfig/tests/test-domain-create.c
+++ b/libvirt-gconfig/tests/test-domain-create.c
@@ -112,6 +112,13 @@ int main(void)
gvir_config_device_input_set_bus(input, GVIR_CONFIG_DEVICE_INPUT_BUS_USB);
devices = g_list_append(devices, GVIR_CONFIG_DEVICE(input));
+ /* graphics node */
+ GVirConfigDeviceGraphicsSpice *graphics;
+
+ graphics = gvir_config_device_graphics_spice_new();
+ gvir_config_device_graphics_spice_set_port(graphics, 1234);
+ devices = g_list_append(devices, GVIR_CONFIG_DEVICE(graphics));
+
gvir_config_domain_set_devices(domain, devices);
g_list_free(devices);
--
1.7.7.3