[libvirt-glib PATCHv3 26/27] Add GVirConfigDomainVideo

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



--
v2: use g_return_if_fail to test function args for sanity
v3: rename to GVirConfigDomainVideo
---
 libvirt-gconfig/Makefile.am                    |    2 +
 libvirt-gconfig/libvirt-gconfig-domain-video.c |  133 ++++++++++++++++++++++++
 libvirt-gconfig/libvirt-gconfig-domain-video.h |   82 +++++++++++++++
 libvirt-gconfig/libvirt-gconfig.h              |    1 +
 libvirt-gconfig/libvirt-gconfig.sym            |    8 ++
 libvirt-gconfig/tests/test-domain-create.c     |    8 ++
 6 files changed, 234 insertions(+), 0 deletions(-)
 create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-video.c
 create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-video.h

diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am
index a596ad9..e91c601 100644
--- a/libvirt-gconfig/Makefile.am
+++ b/libvirt-gconfig/Makefile.am
@@ -23,6 +23,7 @@ GCONFIG_HEADER_FILES = \
 			libvirt-gconfig-domain-os.h \
 			libvirt-gconfig-domain-snapshot.h \
 			libvirt-gconfig-domain-timer.h \
+			libvirt-gconfig-domain-video.h \
 			libvirt-gconfig-helpers.h \
 			libvirt-gconfig-interface.h \
 			libvirt-gconfig-network.h \
@@ -49,6 +50,7 @@ GCONFIG_SOURCE_FILES = \
 			libvirt-gconfig-domain-os.c \
 			libvirt-gconfig-domain-snapshot.c \
 			libvirt-gconfig-domain-timer.c \
+			libvirt-gconfig-domain-video.c \
 			libvirt-gconfig-enum-types.c \
 			libvirt-gconfig-helpers.c \
 			libvirt-gconfig-interface.c \
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-video.c b/libvirt-gconfig/libvirt-gconfig-domain-video.c
new file mode 100644
index 0000000..80ecf6b
--- /dev/null
+++ b/libvirt-gconfig/libvirt-gconfig-domain-video.c
@@ -0,0 +1,133 @@
+/*
+ * libvirt-gobject-config-domain-video.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_VIDEO_GET_PRIVATE(obj)                         \
+        (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_DOMAIN_VIDEO, GVirConfigDomainVideoPrivate))
+
+struct _GVirConfigDomainVideoPrivate
+{
+    gboolean unused;
+};
+
+G_DEFINE_TYPE(GVirConfigDomainVideo, gvir_config_domain_video, GVIR_TYPE_CONFIG_DOMAIN_DEVICE);
+
+
+static void gvir_config_domain_video_class_init(GVirConfigDomainVideoClass *klass)
+{
+    g_type_class_add_private(klass, sizeof(GVirConfigDomainVideoPrivate));
+}
+
+
+static void gvir_config_domain_video_init(GVirConfigDomainVideo *video)
+{
+    GVirConfigDomainVideoPrivate *priv;
+
+    DEBUG("Init GVirConfigDomainVideo=%p", video);
+
+    priv = video->priv = GVIR_CONFIG_DOMAIN_VIDEO_GET_PRIVATE(video);
+
+    memset(priv, 0, sizeof(*priv));
+}
+
+
+GVirConfigDomainVideo *gvir_config_domain_video_new(void)
+{
+    GVirConfigObject *object;
+
+    object = gvir_config_object_new(GVIR_TYPE_CONFIG_DOMAIN_VIDEO,
+                                    "video", NULL);
+    return GVIR_CONFIG_DOMAIN_VIDEO(object);
+}
+
+GVirConfigDomainVideo *gvir_config_domain_video_new_from_xml(const gchar *xml,
+                                                             GError **error)
+{
+    GVirConfigObject *object;
+
+    object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_DOMAIN_VIDEO,
+                                             "video", NULL, xml, error);
+    return GVIR_CONFIG_DOMAIN_VIDEO(object);
+}
+
+void gvir_config_domain_video_set_model(GVirConfigDomainVideo *video,
+                                        GVirConfigDomainVideoModel model)
+{
+    xmlNodePtr node;
+    const char *model_str;
+
+    g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_VIDEO(video));
+    node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(video),
+                                            "model");
+    g_return_if_fail(node != NULL);
+    model_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_DOMAIN_VIDEO_MODEL,
+                                           model);
+    g_return_if_fail(model_str != NULL);
+    xmlNewProp(node, (xmlChar*)"type", (xmlChar*)model_str);
+}
+
+void gvir_config_domain_video_set_vram(GVirConfigDomainVideo *video,
+                                       guint kbytes)
+{
+    xmlNodePtr node;
+    char *vram_str;
+
+    node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(video));
+    if (node == NULL)
+        return;
+    node = gvir_config_xml_get_element(node, "model", NULL);
+    if (node == NULL)
+        return;
+    vram_str = g_strdup_printf("%u", kbytes);
+    xmlNewProp(node, (xmlChar*)"vram", (xmlChar*)vram_str);
+    g_free(vram_str);
+}
+
+void gvir_config_domain_video_set_heads(GVirConfigDomainVideo *video,
+                                        guint head_count)
+{
+    xmlNodePtr node;
+    char *heads_str;
+
+    node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(video));
+    if (node == NULL)
+        return;
+    node = gvir_config_xml_get_element(node, "model", NULL);
+    if (node == NULL)
+        return;
+    heads_str = g_strdup_printf("%u", head_count);
+    xmlNewProp(node, (xmlChar*)"heads", (xmlChar*)heads_str);
+    g_free(heads_str);
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-video.h b/libvirt-gconfig/libvirt-gconfig-domain-video.h
new file mode 100644
index 0000000..4790e56
--- /dev/null
+++ b/libvirt-gconfig/libvirt-gconfig-domain-video.h
@@ -0,0 +1,82 @@
+/*
+ * libvirt-gobject-domain-video.c: 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_VIDEO_H__
+#define __LIBVIRT_GCONFIG_DOMAIN_VIDEO_H__
+
+G_BEGIN_DECLS
+
+#define GVIR_TYPE_CONFIG_DOMAIN_VIDEO            (gvir_config_domain_video_get_type ())
+#define GVIR_CONFIG_DOMAIN_VIDEO(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_DOMAIN_VIDEO, GVirConfigDomainVideo))
+#define GVIR_CONFIG_DOMAIN_VIDEO_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_DOMAIN_VIDEO, GVirConfigDomainVideoClass))
+#define GVIR_IS_CONFIG_DOMAIN_VIDEO(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_DOMAIN_VIDEO))
+#define GVIR_IS_CONFIG_DOMAIN_VIDEO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_DOMAIN_VIDEO))
+#define GVIR_CONFIG_DOMAIN_VIDEO_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_DOMAIN_VIDEO, GVirConfigDomainVideoClass))
+
+typedef struct _GVirConfigDomainVideo GVirConfigDomainVideo;
+typedef struct _GVirConfigDomainVideoPrivate GVirConfigDomainVideoPrivate;
+typedef struct _GVirConfigDomainVideoClass GVirConfigDomainVideoClass;
+
+struct _GVirConfigDomainVideo
+{
+    GVirConfigDomainDevice parent;
+
+    GVirConfigDomainVideoPrivate *priv;
+
+    /* Do not add fields to this struct */
+};
+
+struct _GVirConfigDomainVideoClass
+{
+    GVirConfigDomainDeviceClass parent_class;
+
+    gpointer padding[20];
+};
+
+typedef enum {
+    GVIR_CONFIG_DOMAIN_VIDEO_MODEL_VGA,
+    GVIR_CONFIG_DOMAIN_VIDEO_MODEL_CIRRUS,
+    GVIR_CONFIG_DOMAIN_VIDEO_MODEL_VMVGA,
+    GVIR_CONFIG_DOMAIN_VIDEO_MODEL_XEN,
+    GVIR_CONFIG_DOMAIN_VIDEO_MODEL_VBOX,
+    GVIR_CONFIG_DOMAIN_VIDEO_MODEL_QXL
+} GVirConfigDomainVideoModel;
+
+GType gvir_config_domain_video_get_type(void);
+
+GVirConfigDomainVideo *gvir_config_domain_video_new(void);
+GVirConfigDomainVideo *gvir_config_domain_video_new_from_xml(const gchar *xml,
+                                                             GError **error);
+void gvir_config_domain_video_set_model(GVirConfigDomainVideo *video,
+                                        GVirConfigDomainVideoModel model);
+void gvir_config_domain_video_set_vram(GVirConfigDomainVideo *video,
+                                       guint kbytes);
+void gvir_config_domain_video_set_heads(GVirConfigDomainVideo *video,
+                                        guint head_count);
+
+G_END_DECLS
+
+#endif /* __LIBVIRT_GCONFIG_DOMAIN_VIDEO_H__ */
diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h
index 3619c1d..064bae6 100644
--- a/libvirt-gconfig/libvirt-gconfig.h
+++ b/libvirt-gconfig/libvirt-gconfig.h
@@ -40,6 +40,7 @@
 #include <libvirt-gconfig/libvirt-gconfig-domain-os.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-snapshot.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-timer.h>
+#include <libvirt-gconfig/libvirt-gconfig-domain-video.h>
 #include <libvirt-gconfig/libvirt-gconfig-enum-types.h>
 #include <libvirt-gconfig/libvirt-gconfig-helpers.h>
 #include <libvirt-gconfig/libvirt-gconfig-interface.h>
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index ba036ab..ae97a92 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -87,6 +87,14 @@ LIBVIRT_GOBJECT_0.0.1 {
 	gvir_config_domain_timer_new;
 	gvir_config_domain_timer_new_from_xml;
 
+	gvir_config_domain_video_get_type;
+	gvir_config_domain_video_model_get_type;
+	gvir_config_domain_video_new;
+	gvir_config_domain_video_new_from_xml;
+	gvir_config_domain_video_set_model;
+	gvir_config_domain_video_set_vram;
+	gvir_config_domain_video_set_heads;
+
 	gvir_config_interface_get_type;
 	gvir_config_interface_new;
 	gvir_config_interface_new_from_xml;
diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c
index 34cc2dc..bade013 100644
--- a/libvirt-gconfig/tests/test-domain-create.c
+++ b/libvirt-gconfig/tests/test-domain-create.c
@@ -120,6 +120,14 @@ int main(void)
     gvir_config_domain_graphics_spice_set_port(graphics, 1234);
     devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(graphics));
 
+    /* video node */
+    GVirConfigDomainVideo *video;
+
+    video = gvir_config_domain_video_new();
+    gvir_config_domain_video_set_model(video,
+                                       GVIR_CONFIG_DOMAIN_VIDEO_MODEL_QXL);
+    devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(video));
+
 
     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


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]