[libvirt] [libvirt-glib 01/37] Add gvir_config_object_new_child helper

This allows us to factor the code to add an XML node to a config object. --- libvirt-gconfig/libvirt-gconfig-object.c | 72 ++++++++++++++++++------------ libvirt-gconfig/libvirt-gconfig-object.h | 4 ++ libvirt-gconfig/libvirt-gconfig.h | 2 +- 3 files changed, 49 insertions(+), 29 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c index fbdbedd..598ac0c 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.c +++ b/libvirt-gconfig/libvirt-gconfig-object.c @@ -294,35 +294,62 @@ char *gvir_config_object_get_node_content(GVirConfigObject *object, return gvir_config_xml_get_child_element_content_glib(node, node_name); } -/* FIXME: if there are multiple nodes with the same name, this function - * won't behave as expected. Should we get rid of the duplicated node names - * here? - */ -void gvir_config_object_set_node_content(GVirConfigObject *object, - const char *node_name, - const char *value) +void +gvir_config_object_set_child(GVirConfigObject *object, xmlNodePtr child) { xmlNodePtr parent_node; xmlNodePtr old_node; - xmlNodePtr new_node; - xmlChar *encoded_name; parent_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(object)); - encoded_name = xmlEncodeEntitiesReentrant(parent_node->doc, - (xmlChar *)value); - new_node = xmlNewDocNode(parent_node->doc, NULL, - (xmlChar *)node_name, encoded_name); - xmlFree(encoded_name); + g_return_if_fail (parent_node != NULL); - old_node = gvir_config_xml_get_element(parent_node, node_name, NULL); + old_node = gvir_config_xml_get_element(parent_node, child->name, NULL); + /* FIXME: should we make sure there are no multiple occurrences + * of this node? + */ if (old_node) { - old_node = xmlReplaceNode(old_node, new_node); + old_node = xmlReplaceNode(old_node, child); xmlFreeNode(old_node); } else { - xmlAddChild(parent_node, new_node); + xmlAddChild(parent_node, child); } } +xmlNodePtr +gvir_config_object_new_child(GVirConfigObject *object, const char *child_name) +{ + xmlNodePtr new_node; + + new_node = xmlNewDocNode(NULL, NULL, (xmlChar *)child_name, NULL); + gvir_config_object_set_child(object, new_node); + return new_node; +} + +void gvir_config_object_set_node_content(GVirConfigObject *object, + const char *node_name, + const char *value) +{ + xmlNodePtr node; + xmlChar *encoded_data; + + node = gvir_config_object_new_child(object, node_name); + g_return_if_fail(node != NULL); + encoded_data = xmlEncodeEntitiesReentrant(node->doc, + (xmlChar *)value); + xmlNodeSetContent(node, encoded_data); + xmlFree(encoded_data); +} + +void gvir_config_object_set_node_content_uint64(GVirConfigObject *object, + const char *node_name, + guint64 value) +{ + char *str; + str = g_strdup_printf("%"G_GUINT64_FORMAT, value); + gvir_config_object_set_node_content(object, node_name, str); + g_free(str); +} + /* FIXME: how to notify of errors/node not found? */ guint64 gvir_config_object_get_node_content_uint64(GVirConfigObject *object, const char *node_name) @@ -345,17 +372,6 @@ guint64 gvir_config_object_get_node_content_uint64(GVirConfigObject *object, return value; } - -void gvir_config_object_set_node_content_uint64(GVirConfigObject *object, - const char *node_name, - guint64 value) -{ - char *str; - str = g_strdup_printf("%"G_GUINT64_FORMAT, value); - gvir_config_object_set_node_content(object, node_name, str); - g_free(str); -} - GVirConfigObject *gvir_config_object_new_from_xml(GType type, const char *root_name, const char *schema, diff --git a/libvirt-gconfig/libvirt-gconfig-object.h b/libvirt-gconfig/libvirt-gconfig-object.h index 52e4525..8e67b92 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.h +++ b/libvirt-gconfig/libvirt-gconfig-object.h @@ -78,6 +78,10 @@ char *gvir_config_object_get_node_content(GVirConfigObject *object, const char *node_name); guint64 gvir_config_object_get_node_content_uint64(GVirConfigObject *object, const char *node_name); +xmlNodePtr gvir_config_object_new_child(GVirConfigObject *object, + const char *child_name); +void gvir_config_object_set_child(GVirConfigObject *object, + xmlNodePtr child); void gvir_config_object_set_node_content(GVirConfigObject *object, const char *node_name, const char *value); diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index fdc78a4..4e23f0d 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -26,11 +26,11 @@ #include <glib-object.h> #include <libxml/tree.h> -#include <libvirt-gconfig/libvirt-gconfig-helpers.h> #include <libvirt-gconfig/libvirt-gconfig-object.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities.h> #include <libvirt-gconfig/libvirt-gconfig-domain.h> #include <libvirt-gconfig/libvirt-gconfig-domain-snapshot.h> +#include <libvirt-gconfig/libvirt-gconfig-helpers.h> #include <libvirt-gconfig/libvirt-gconfig-interface.h> #include <libvirt-gconfig/libvirt-gconfig-network.h> #include <libvirt-gconfig/libvirt-gconfig-node-device.h> -- 1.7.7

--- libvirt-gconfig/libvirt-gconfig-domain.c | 17 +++-------------- 1 files changed, 3 insertions(+), 14 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c index 3290389..c847c14 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.c +++ b/libvirt-gconfig/libvirt-gconfig-domain.c @@ -223,27 +223,16 @@ GStrv gvir_config_domain_get_features(GVirConfigDomain *domain) void gvir_config_domain_set_features(GVirConfigDomain *domain, const GStrv features) { - xmlNodePtr parent_node; xmlNodePtr features_node; - xmlNodePtr old_node; GStrv it; - parent_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(domain)); - features_node = xmlNewDocNode(parent_node->doc, NULL, - (xmlChar *)"features", NULL); + features_node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(domain), + "features"); for (it = features; *it != NULL; it++) { xmlNodePtr node; - node = xmlNewDocNode(parent_node->doc, NULL, (xmlChar *)*it, NULL); + node = xmlNewDocNode(features_node->doc, NULL, (xmlChar *)*it, NULL); xmlAddChild(features_node, node); } - - old_node = gvir_config_xml_get_element(parent_node, "features", NULL); - if (old_node) { - old_node = xmlReplaceNode(old_node, features_node); - xmlFreeNode(old_node); - } else { - xmlAddChild(parent_node, features_node); - } g_object_notify(G_OBJECT(domain), "features"); } -- 1.7.7

ack On Thu, Nov 10, 2011 at 9:33 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
--- libvirt-gconfig/libvirt-gconfig-domain.c | 17 +++-------------- 1 files changed, 3 insertions(+), 14 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c index 3290389..c847c14 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.c +++ b/libvirt-gconfig/libvirt-gconfig-domain.c @@ -223,27 +223,16 @@ GStrv gvir_config_domain_get_features(GVirConfigDomain *domain) void gvir_config_domain_set_features(GVirConfigDomain *domain, const GStrv features) { - xmlNodePtr parent_node; xmlNodePtr features_node; - xmlNodePtr old_node; GStrv it;
- parent_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(domain)); - features_node = xmlNewDocNode(parent_node->doc, NULL, - (xmlChar *)"features", NULL); + features_node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(domain), + "features"); for (it = features; *it != NULL; it++) { xmlNodePtr node;
- node = xmlNewDocNode(parent_node->doc, NULL, (xmlChar *)*it, NULL); + node = xmlNewDocNode(features_node->doc, NULL, (xmlChar *)*it, NULL); xmlAddChild(features_node, node); } - - old_node = gvir_config_xml_get_element(parent_node, "features", NULL); - if (old_node) { - old_node = xmlReplaceNode(old_node, features_node); - xmlFreeNode(old_node); - } else { - xmlAddChild(parent_node, features_node); - } g_object_notify(G_OBJECT(domain), "features"); } -- 1.7.7
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
-- Marc-André Lureau

--- libvirt-gconfig/Makefile.am | 4 ++ libvirt-gconfig/libvirt-gconfig-clock.c | 82 +++++++++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-clock.h | 68 +++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-timer.c | 82 +++++++++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-timer.h | 68 +++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 2 + libvirt-gconfig/libvirt-gconfig.sym | 8 +++ 7 files changed, 314 insertions(+), 0 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-clock.c create mode 100644 libvirt-gconfig/libvirt-gconfig-clock.h create mode 100644 libvirt-gconfig/libvirt-gconfig-timer.c create mode 100644 libvirt-gconfig/libvirt-gconfig-timer.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 0d15e78..3fd268a 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -8,6 +8,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig.h \ libvirt-gconfig-object.h \ libvirt-gconfig-capabilities.h \ + libvirt-gconfig-clock.h \ libvirt-gconfig-domain.h \ libvirt-gconfig-domain-snapshot.h \ libvirt-gconfig-helpers.h \ @@ -16,6 +17,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-network-filter.h \ libvirt-gconfig-node-device.h \ libvirt-gconfig-secret.h \ + libvirt-gconfig-timer.h \ libvirt-gconfig-storage-pool.h \ libvirt-gconfig-storage-vol.h noinst_HEADERS = \ @@ -23,6 +25,7 @@ noinst_HEADERS = \ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-object.c \ libvirt-gconfig-capabilities.c \ + libvirt-gconfig-clock.c \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-snapshot.c \ libvirt-gconfig-helpers.c \ @@ -31,6 +34,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-network-filter.c \ libvirt-gconfig-node-device.c \ libvirt-gconfig-secret.c \ + libvirt-gconfig-timer.c \ libvirt-gconfig-storage-pool.c \ libvirt-gconfig-storage-vol.c diff --git a/libvirt-gconfig/libvirt-gconfig-clock.c b/libvirt-gconfig/libvirt-gconfig-clock.c new file mode 100644 index 0000000..d2650ad --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-clock.c @@ -0,0 +1,82 @@ +/* + * libvirt-gobject-config_clock.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@redhat.com> + */ + +#include <config.h> + +#include <string.h> + +#include <libxml/tree.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" + +extern gboolean debugFlag; + +#define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0) + +#define GVIR_CONFIG_CLOCK_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_CLOCK, GVirConfigClockPrivate)) + +struct _GVirConfigClockPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigClock, gvir_config_clock, GVIR_TYPE_CONFIG_OBJECT); + + +static void gvir_config_clock_class_init(GVirConfigClockClass *klass) +{ + + g_type_class_add_private(klass, sizeof(GVirConfigClockPrivate)); +} + + +static void gvir_config_clock_init(GVirConfigClock *klock) +{ + GVirConfigClockPrivate *priv; + + DEBUG("Init GVirConfigClock=%p", klock); + + priv = klock->priv = GVIR_CONFIG_CLOCK_GET_PRIVATE(klock); + + memset(priv, 0, sizeof(*priv)); +} + + +GVirConfigClock *gvir_config_clock_new(void) +{ + GVirConfigObject *object; + + object = gvir_config_object_new(GVIR_TYPE_CONFIG_CLOCK, + "clock", NULL); + return GVIR_CONFIG_CLOCK(object); +} + +GVirConfigClock *gvir_config_clock_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_CLOCK, + "clock", NULL, xml, error); + return GVIR_CONFIG_CLOCK(object); +} diff --git a/libvirt-gconfig/libvirt-gconfig-clock.h b/libvirt-gconfig/libvirt-gconfig-clock.h new file mode 100644 index 0000000..fc8850a --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-clock.h @@ -0,0 +1,68 @@ +/* + * libvirt-gobject-clock.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@redhat.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_CLOCK_H__ +#define __LIBVIRT_GCONFIG_CLOCK_H__ + +G_BEGIN_DECLS + +#define GVIR_TYPE_CONFIG_CLOCK (gvir_config_clock_get_type ()) +#define GVIR_CONFIG_CLOCK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_CLOCK, GVirConfigClock)) +#define GVIR_CONFIG_CLOCK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_CLOCK, GVirConfigClockClass)) +#define GVIR_IS_CONFIG_CLOCK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_CLOCK)) +#define GVIR_IS_CONFIG_CLOCK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_CLOCK)) +#define GVIR_CONFIG_CLOCK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_CLOCK, GVirConfigClockClass)) + +typedef struct _GVirConfigClock GVirConfigClock; +typedef struct _GVirConfigClockPrivate GVirConfigClockPrivate; +typedef struct _GVirConfigClockClass GVirConfigClockClass; + +struct _GVirConfigClock +{ + GVirConfigObject parent; + + GVirConfigClockPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigClockClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + + +GType gvir_config_clock_get_type(void); + +GVirConfigClock *gvir_config_clock_new(void); +GVirConfigClock *gvir_config_clock_new_from_xml(const gchar *xml, + GError **error); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CLOCK_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-timer.c b/libvirt-gconfig/libvirt-gconfig-timer.c new file mode 100644 index 0000000..477cc94 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-timer.c @@ -0,0 +1,82 @@ +/* + * libvirt-gobject-config_timer.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@gmail.com> + */ + +#include <config.h> + +#include <string.h> + +#include <libxml/tree.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" + +extern gboolean debugFlag; + +#define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0) + +#define GVIR_CONFIG_TIMER_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_TIMER, GVirConfigTimerPrivate)) + +struct _GVirConfigTimerPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigTimer, gvir_config_timer, GVIR_TYPE_CONFIG_OBJECT); + + +static void gvir_config_timer_class_init(GVirConfigTimerClass *klass) +{ + + g_type_class_add_private(klass, sizeof(GVirConfigTimerPrivate)); +} + + +static void gvir_config_timer_init(GVirConfigTimer *timer) +{ + GVirConfigTimerPrivate *priv; + + DEBUG("Init GVirConfigTimer=%p", timer); + + priv = timer->priv = GVIR_CONFIG_TIMER_GET_PRIVATE(timer); + + memset(priv, 0, sizeof(*priv)); +} + + +GVirConfigTimer *gvir_config_timer_new(void) +{ + GVirConfigObject *object; + + object = gvir_config_object_new(GVIR_TYPE_CONFIG_TIMER, "timer", NULL); + return GVIR_CONFIG_TIMER(object); +} + + +GVirConfigTimer *gvir_config_timer_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_TIMER, + "timer", NULL, xml, error); + return GVIR_CONFIG_TIMER(object); +} diff --git a/libvirt-gconfig/libvirt-gconfig-timer.h b/libvirt-gconfig/libvirt-gconfig-timer.h new file mode 100644 index 0000000..d0c0f4d --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-timer.h @@ -0,0 +1,68 @@ +/* + * libvirt-gobject-timer.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@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_TIMER_H__ +#define __LIBVIRT_GCONFIG_TIMER_H__ + +G_BEGIN_DECLS + +#define GVIR_TYPE_CONFIG_TIMER (gvir_config_timer_get_type ()) +#define GVIR_CONFIG_TIMER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_TIMER, GVirConfigTimer)) +#define GVIR_CONFIG_TIMER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_TIMER, GVirConfigTimerClass)) +#define GVIR_IS_CONFIG_TIMER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_TIMER)) +#define GVIR_IS_CONFIG_TIMER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_TIMER)) +#define GVIR_CONFIG_TIMER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_TIMER, GVirConfigTimerClass)) + +typedef struct _GVirConfigTimer GVirConfigTimer; +typedef struct _GVirConfigTimerPrivate GVirConfigTimerPrivate; +typedef struct _GVirConfigTimerClass GVirConfigTimerClass; + +struct _GVirConfigTimer +{ + GVirConfigObject parent; + + GVirConfigTimerPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigTimerClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + + +GType gvir_config_timer_get_type(void); + +GVirConfigTimer *gvir_config_timer_new(void); +GVirConfigTimer *gvir_config_timer_new_from_xml(const gchar *xml, + GError **error); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_TIMER_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index 4e23f0d..7cb34b0 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -28,6 +28,7 @@ #include <libvirt-gconfig/libvirt-gconfig-object.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities.h> +#include <libvirt-gconfig/libvirt-gconfig-clock.h> #include <libvirt-gconfig/libvirt-gconfig-domain.h> #include <libvirt-gconfig/libvirt-gconfig-domain-snapshot.h> #include <libvirt-gconfig/libvirt-gconfig-helpers.h> @@ -36,6 +37,7 @@ #include <libvirt-gconfig/libvirt-gconfig-node-device.h> #include <libvirt-gconfig/libvirt-gconfig-network-filter.h> #include <libvirt-gconfig/libvirt-gconfig-secret.h> +#include <libvirt-gconfig/libvirt-gconfig-timer.h> #include <libvirt-gconfig/libvirt-gconfig-storage-pool.h> #include <libvirt-gconfig/libvirt-gconfig-storage-vol.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index ed28449..c76faab 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -4,6 +4,10 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_capabilities_new; gvir_config_capabilities_new_from_xml; + gvir_config_clock_get_type; + gvir_config_clock_new; + gvir_config_clock_new_from_xml; + gvir_config_domain_get_type; gvir_config_domain_new; gvir_config_domain_new_from_xml; @@ -54,6 +58,10 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_storage_vol_new; gvir_config_storage_vol_new_from_xml; + gvir_config_timer_get_type; + gvir_config_timer_new; + gvir_config_timer_new_from_xml; + local: *; }; -- 1.7.7

Hi On Thu, Nov 10, 2011 at 9:33 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
+struct _GVirConfigClockPrivate +{ + gboolean unused; +};
(does it really matter if the struct is empty?)
+G_DEFINE_TYPE(GVirConfigClock, gvir_config_clock, GVIR_TYPE_CONFIG_OBJECT); + + +static void gvir_config_clock_class_init(GVirConfigClockClass *klass) +{ + + g_type_class_add_private(klass, sizeof(GVirConfigClockPrivate)); +} + + +static void gvir_config_clock_init(GVirConfigClock *klock) +{ + GVirConfigClockPrivate *priv; + + DEBUG("Init GVirConfigClock=%p", klock); + + priv = klock->priv = GVIR_CONFIG_CLOCK_GET_PRIVATE(klock); + + memset(priv, 0, sizeof(*priv));
in fact, memset is useless here, GObject are always initialized with 0's including private data (from what I understand of gobject code). I am going to send a patch to remove it on the whole code base.
+struct _GVirConfigTimerPrivate +{ + gboolean unused; +};
+ memset(priv, 0, sizeof(*priv));
same remarks here. otherwise looks fine. -- Marc-André Lureau

On Fri, Nov 11, 2011 at 03:33:51PM +0100, Marc-André Lureau wrote:
On Thu, Nov 10, 2011 at 9:33 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
+struct _GVirConfigClockPrivate +{ + gboolean unused; +};
(does it really matter if the struct is empty?)
Yes, there's a runtime warning if sizeof(GVirConfigClockPrivate) == 0 when associating the private structure with the class. Imo these "empty" private structures should be removed at some point, they are here in all classes because of copy/paste.
+G_DEFINE_TYPE(GVirConfigClock, gvir_config_clock, GVIR_TYPE_CONFIG_OBJECT); + + +static void gvir_config_clock_class_init(GVirConfigClockClass *klass) +{ + + g_type_class_add_private(klass, sizeof(GVirConfigClockPrivate)); +} + + +static void gvir_config_clock_init(GVirConfigClock *klock) +{ + GVirConfigClockPrivate *priv; + + DEBUG("Init GVirConfigClock=%p", klock); + + priv = klock->priv = GVIR_CONFIG_CLOCK_GET_PRIVATE(klock); + + memset(priv, 0, sizeof(*priv));
in fact, memset is useless here, GObject are always initialized with 0's including private data (from what I understand of gobject code). I am going to send a patch to remove it on the whole code base.
Yep, this memset is present in the libvirt-gconfig file I used as a copy and paste source, that's why it got everywhere. Christophe

--- libvirt-gconfig/libvirt-gconfig-clock.c | 32 ++++++++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-clock.h | 5 ++++ libvirt-gconfig/libvirt-gconfig-domain.c | 1 + libvirt-gconfig/libvirt-gconfig-domain.h | 1 - libvirt-gconfig/libvirt-gconfig.sym | 2 + 5 files changed, 40 insertions(+), 1 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-clock.c b/libvirt-gconfig/libvirt-gconfig-clock.c index d2650ad..120d3a6 100644 --- a/libvirt-gconfig/libvirt-gconfig-clock.c +++ b/libvirt-gconfig/libvirt-gconfig-clock.c @@ -80,3 +80,35 @@ GVirConfigClock *gvir_config_clock_new_from_xml(const gchar *xml, "clock", NULL, xml, error); return GVIR_CONFIG_CLOCK(object); } + +void gvir_config_clock_set_timezone(GVirConfigClock *klock, + const char *tz) +{ + xmlNodePtr node; + xmlChar *encoded_tz; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(klock)); + if (node == NULL) + return; + + xmlNewProp(node, (xmlChar*)"offset", (xmlChar*)"timezone"); + encoded_tz = xmlEncodeEntitiesReentrant(node->doc, (xmlChar*)tz); + xmlNewProp(node, (xmlChar*)"timezone", encoded_tz); + xmlFree(encoded_tz); +} + +void gvir_config_clock_set_variable_offset(GVirConfigClock *klock, + gint seconds) +{ + xmlNodePtr node; + char *offset_str; + + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(klock), "clock"); + if (node == NULL) + return; + + xmlNewProp(node, (xmlChar*)"offset", (xmlChar*)"variable"); + offset_str = g_strdup_printf("%d", seconds); + xmlNewProp(node, (xmlChar*)"timezone", (xmlChar*)offset_str); + g_free(offset_str); +} diff --git a/libvirt-gconfig/libvirt-gconfig-clock.h b/libvirt-gconfig/libvirt-gconfig-clock.h index fc8850a..26f4b53 100644 --- a/libvirt-gconfig/libvirt-gconfig-clock.h +++ b/libvirt-gconfig/libvirt-gconfig-clock.h @@ -63,6 +63,11 @@ GVirConfigClock *gvir_config_clock_new(void); GVirConfigClock *gvir_config_clock_new_from_xml(const gchar *xml, GError **error); +void gvir_config_clock_set_timezone(GVirConfigClock *klock, + const char *tz); +void gvir_config_clock_set_variable_offset(GVirConfigClock *klock, + gint seconds); + G_END_DECLS #endif /* __LIBVIRT_GCONFIG_CLOCK_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c index c847c14..f80720a 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.c +++ b/libvirt-gconfig/libvirt-gconfig-domain.c @@ -236,3 +236,4 @@ void gvir_config_domain_set_features(GVirConfigDomain *domain, } g_object_notify(G_OBJECT(domain), "features"); } + diff --git a/libvirt-gconfig/libvirt-gconfig-domain.h b/libvirt-gconfig/libvirt-gconfig-domain.h index d9f0c09..6cc8f31 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.h +++ b/libvirt-gconfig/libvirt-gconfig-domain.h @@ -70,7 +70,6 @@ GStrv gvir_config_domain_get_features(GVirConfigDomain *domain); void gvir_config_domain_set_features(GVirConfigDomain *domain, const GStrv features); - G_END_DECLS #endif /* __LIBVIRT_GCONFIG_DOMAIN_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index c76faab..19e926c 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -7,6 +7,8 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_clock_get_type; gvir_config_clock_new; gvir_config_clock_new_from_xml; + gvir_config_clock_set_timezone; + gvir_config_clock_set_variable_offset; gvir_config_domain_get_type; gvir_config_domain_new; -- 1.7.7

Hi On Thu, Nov 10, 2011 at 9:33 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
--- libvirt-gconfig/libvirt-gconfig-clock.c | 32 ++++++++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-clock.h | 5 ++++ libvirt-gconfig/libvirt-gconfig-domain.c | 1 + libvirt-gconfig/libvirt-gconfig-domain.h | 1 - libvirt-gconfig/libvirt-gconfig.sym | 2 + 5 files changed, 40 insertions(+), 1 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-clock.c b/libvirt-gconfig/libvirt-gconfig-clock.c index d2650ad..120d3a6 100644 --- a/libvirt-gconfig/libvirt-gconfig-clock.c +++ b/libvirt-gconfig/libvirt-gconfig-clock.c @@ -80,3 +80,35 @@ GVirConfigClock *gvir_config_clock_new_from_xml(const gchar *xml, "clock", NULL, xml, error); return GVIR_CONFIG_CLOCK(object); } + +void gvir_config_clock_set_timezone(GVirConfigClock *klock, + const char *tz) +{ + xmlNodePtr node; + xmlChar *encoded_tz;
in general, I think we should add g_return_..if_fail() for all public functions, and all arguments. Would you mind adding it in your patches?
+ + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(klock)); + if (node == NULL) + return; + + xmlNewProp(node, (xmlChar*)"offset", (xmlChar*)"timezone"); + encoded_tz = xmlEncodeEntitiesReentrant(node->doc, (xmlChar*)tz); + xmlNewProp(node, (xmlChar*)"timezone", encoded_tz); + xmlFree(encoded_tz);
the (xmlChar*) and (gchar*) casts are very frequent in the code, and make the code harder to read. I wonder if we should have macro such as XCHAR() GCHAR(). I think I have since that in other projects.
+ +void gvir_config_clock_set_variable_offset(GVirConfigClock *klock, + gint seconds) +{ + xmlNodePtr node; + char *offset_str; + + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(klock), "clock"); + if (node == NULL) + return; + + xmlNewProp(node, (xmlChar*)"offset", (xmlChar*)"variable"); + offset_str = g_strdup_printf("%d", seconds); + xmlNewProp(node, (xmlChar*)"timezone", (xmlChar*)offset_str); + g_free(offset_str); +} diff --git a/libvirt-gconfig/libvirt-gconfig-clock.h b/libvirt-gconfig/libvirt-gconfig-clock.h index fc8850a..26f4b53 100644 --- a/libvirt-gconfig/libvirt-gconfig-clock.h +++ b/libvirt-gconfig/libvirt-gconfig-clock.h @@ -63,6 +63,11 @@ GVirConfigClock *gvir_config_clock_new(void); GVirConfigClock *gvir_config_clock_new_from_xml(const gchar *xml, GError **error);
+void gvir_config_clock_set_timezone(GVirConfigClock *klock, + const char *tz); +void gvir_config_clock_set_variable_offset(GVirConfigClock *klock, + gint seconds); + G_END_DECLS
#endif /* __LIBVIRT_GCONFIG_CLOCK_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c index c847c14..f80720a 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.c +++ b/libvirt-gconfig/libvirt-gconfig-domain.c @@ -236,3 +236,4 @@ void gvir_config_domain_set_features(GVirConfigDomain *domain, } g_object_notify(G_OBJECT(domain), "features"); } +
Extra line?
diff --git a/libvirt-gconfig/libvirt-gconfig-domain.h b/libvirt-gconfig/libvirt-gconfig-domain.h index d9f0c09..6cc8f31 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.h +++ b/libvirt-gconfig/libvirt-gconfig-domain.h @@ -70,7 +70,6 @@ GStrv gvir_config_domain_get_features(GVirConfigDomain *domain); void gvir_config_domain_set_features(GVirConfigDomain *domain, const GStrv features);
-
ok :) -- Marc-André Lureau

On Fri, Nov 11, 2011 at 03:39:01PM +0100, Marc-André Lureau wrote:
+void gvir_config_clock_set_timezone(GVirConfigClock *klock, + const char *tz) +{ + xmlNodePtr node; + xmlChar *encoded_tz;
in general, I think we should add g_return_..if_fail() for all public functions, and all arguments. Would you mind adding it in your patches?
Hmm ok So g_return_if_fail(klock != NULL); g_return_if_fail(tz != NULL); ? (just want to be 100% sure we are talking about the same thing :)
+ + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(klock)); + if (node == NULL) + return; + + xmlNewProp(node, (xmlChar*)"offset", (xmlChar*)"timezone"); + encoded_tz = xmlEncodeEntitiesReentrant(node->doc, (xmlChar*)tz); + xmlNewProp(node, (xmlChar*)"timezone", encoded_tz); + xmlFree(encoded_tz);
the (xmlChar*) and (gchar*) casts are very frequent in the code, and make the code harder to read. I wonder if we should have macro such as XCHAR() GCHAR(). I think I have since that in other projects.
libxml2 provides http://xmlsoft.org/html/libxml-xmlstring.html#BAD_CAST which isn't really easy on the eyes. I've got more patches which are not ready for review yet, but which move these casts in only a few helper functions instead of having them everywhere. If you don't mind, I'll address this when all these patches have been sent, is it ok?
diff --git a/libvirt-gconfig/libvirt-gconfig-clock.h b/libvirt-gconfig/libvirt-gconfig-clock.h index fc8850a..26f4b53 100644 --- a/libvirt-gconfig/libvirt-gconfig-clock.h +++ b/libvirt-gconfig/libvirt-gconfig-clock.h @@ -63,6 +63,11 @@ GVirConfigClock *gvir_config_clock_new(void); GVirConfigClock *gvir_config_clock_new_from_xml(const gchar *xml, GError **error);
+void gvir_config_clock_set_timezone(GVirConfigClock *klock, + const char *tz); +void gvir_config_clock_set_variable_offset(GVirConfigClock *klock, + gint seconds); + G_END_DECLS
#endif /* __LIBVIRT_GCONFIG_CLOCK_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c index c847c14..f80720a 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.c +++ b/libvirt-gconfig/libvirt-gconfig-domain.c @@ -236,3 +236,4 @@ void gvir_config_domain_set_features(GVirConfigDomain *domain, } g_object_notify(G_OBJECT(domain), "features"); } +
Extra line?
Removed, though I think it goes away in one of the next commits
diff --git a/libvirt-gconfig/libvirt-gconfig-domain.h b/libvirt-gconfig/libvirt-gconfig-domain.h index d9f0c09..6cc8f31 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.h +++ b/libvirt-gconfig/libvirt-gconfig-domain.h @@ -70,7 +70,6 @@ GStrv gvir_config_domain_get_features(GVirConfigDomain *domain); void gvir_config_domain_set_features(GVirConfigDomain *domain, const GStrv features);
-
ok :)
I've moved this to another commit modifying set_features. The commit introducing it has been pushed already unfortunately. Christophe

On Tue, Nov 15, 2011 at 2:37 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
g_return_if_fail(klock != NULL);
I think better is: g_return_if_fail(GVIR_IS_CONFIG_CLOCK(klock));
libxml2 provides http://xmlsoft.org/html/libxml-xmlstring.html#BAD_CAST which isn't really easy on the eyes. I've got more patches which are not ready for review yet, but which move these casts in only a few helper functions instead of having them everywhere. If you don't mind, I'll address this when all these patches have been sent, is it ok?
sure -- Marc-André Lureau

The implementation is likely to need to be completed later. We might want to store pointers from GVirConfigDomain to the associated GVirConfigClock, from GVirConfigClock to the GVirConfigDomain that contains it. Since I'm not sure yet if they will be needed, I chose to keep the implementation simple. --- libvirt-gconfig/libvirt-gconfig-domain.c | 8 ++++++++ libvirt-gconfig/libvirt-gconfig-domain.h | 2 ++ libvirt-gconfig/libvirt-gconfig.sym | 1 + 3 files changed, 11 insertions(+), 0 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c index f80720a..de60054 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.c +++ b/libvirt-gconfig/libvirt-gconfig-domain.c @@ -237,3 +237,11 @@ void gvir_config_domain_set_features(GVirConfigDomain *domain, g_object_notify(G_OBJECT(domain), "features"); } +void gvir_config_domain_set_clock(GVirConfigDomain *domain, + GVirConfigClock *klock) +{ + xmlNodePtr clock_node; + + clock_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(klock)); + gvir_config_object_set_child(GVIR_CONFIG_OBJECT(domain), clock_node); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain.h b/libvirt-gconfig/libvirt-gconfig-domain.h index 6cc8f31..6f822cf 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.h +++ b/libvirt-gconfig/libvirt-gconfig-domain.h @@ -69,6 +69,8 @@ void gvir_config_domain_set_memory(GVirConfigDomain *domain, guint64 memory); GStrv gvir_config_domain_get_features(GVirConfigDomain *domain); void gvir_config_domain_set_features(GVirConfigDomain *domain, const GStrv features); +void gvir_config_domain_set_clock(GVirConfigDomain *domain, + GVirConfigClock *klock); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 19e926c..30cabf5 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -13,6 +13,7 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_domain_get_type; gvir_config_domain_new; gvir_config_domain_new_from_xml; + gvir_config_domain_set_clock; gvir_config_domain_get_features; gvir_config_domain_set_features; gvir_config_domain_get_memory; -- 1.7.7

On Thu, Nov 10, 2011 at 9:33 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
The implementation is likely to need to be completed later. We might want to store pointers from GVirConfigDomain to the associated GVirConfigClock, from GVirConfigClock to the GVirConfigDomain that contains it. Since I'm not sure yet if they will be needed, I chose to keep the implementation simple.
yup, I think it would be helpful to have GVirConfigObject parent in GVirConfigObject. otherwise, ack
libvirt-gconfig/libvirt-gconfig-domain.c | 8 ++++++++ libvirt-gconfig/libvirt-gconfig-domain.h | 2 ++ libvirt-gconfig/libvirt-gconfig.sym | 1 + 3 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c index f80720a..de60054 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.c +++ b/libvirt-gconfig/libvirt-gconfig-domain.c @@ -237,3 +237,11 @@ void gvir_config_domain_set_features(GVirConfigDomain *domain, g_object_notify(G_OBJECT(domain), "features"); }
+void gvir_config_domain_set_clock(GVirConfigDomain *domain, + GVirConfigClock *klock) +{ + xmlNodePtr clock_node; + + clock_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(klock)); + gvir_config_object_set_child(GVIR_CONFIG_OBJECT(domain), clock_node); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain.h b/libvirt-gconfig/libvirt-gconfig-domain.h index 6cc8f31..6f822cf 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.h +++ b/libvirt-gconfig/libvirt-gconfig-domain.h @@ -69,6 +69,8 @@ void gvir_config_domain_set_memory(GVirConfigDomain *domain, guint64 memory); GStrv gvir_config_domain_get_features(GVirConfigDomain *domain); void gvir_config_domain_set_features(GVirConfigDomain *domain, const GStrv features); +void gvir_config_domain_set_clock(GVirConfigDomain *domain, + GVirConfigClock *klock);
G_END_DECLS
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 19e926c..30cabf5 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -13,6 +13,7 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_domain_get_type; gvir_config_domain_new; gvir_config_domain_new_from_xml; + gvir_config_domain_set_clock; gvir_config_domain_get_features; gvir_config_domain_set_features; gvir_config_domain_get_memory; -- 1.7.7
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
-- Marc-André Lureau

On Fri, Nov 11, 2011 at 03:41:02PM +0100, Marc-André Lureau wrote:
On Thu, Nov 10, 2011 at 9:33 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
The implementation is likely to need to be completed later. We might want to store pointers from GVirConfigDomain to the associated GVirConfigClock, from GVirConfigClock to the GVirConfigDomain that contains it. Since I'm not sure yet if they will be needed, I chose to keep the implementation simple.
yup, I think it would be helpful to have GVirConfigObject parent in GVirConfigObject.
Ok, will have to be done in a another patch :) Christophe

We don't currently have any enum in our API, but we will need some. This commit adds the generation of libvirt-gconfig-enum-types.[ch] using glib-mkenums. These files will register the various enums that will get added to libvirt-gconfig header files with glib. --- configure.ac | 4 ++ libvirt-gconfig/Makefile.am | 21 +++++++++++- .../libvirt-gconfig-enum-types.c.template | 36 ++++++++++++++++++++ .../libvirt-gconfig-enum-types.h.template | 24 +++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + 5 files changed, 85 insertions(+), 1 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-enum-types.c.template create mode 100644 libvirt-gconfig/libvirt-gconfig-enum-types.h.template diff --git a/configure.ac b/configure.ac index 464160c..3281baa 100644 --- a/configure.ac +++ b/configure.ac @@ -52,6 +52,10 @@ PKG_CHECK_MODULES(LIBXML2, libxml-2.0 >= $LIBXML2_REQUIRED) GTK_DOC_CHECK([1.10],[--flavour no-tmpl]) +# Setup GLIB_MKENUMS to use glib-mkenums even if GLib is uninstalled. +GLIB_MKENUMS=`$PKG_CONFIG --variable=glib_mkenums glib-2.0` +AC_SUBST(GLIB_MKENUMS) + dnl Extra link-time flags for Cygwin. dnl Copied from libxml2 configure.in, but I removed mingw changes dnl for now since I'm not supporting mingw at present. - RWMJ diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 3fd268a..a0dec08 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -1,6 +1,9 @@ SUBDIRS = . tests -EXTRA_DIST = libvirt-gconfig.sym +EXTRA_DIST = \ + libvirt-gconfig.sym \ + libvirt-gconfig-enum-types.h.template \ + libvirt-gconfig-enum-types.c.template lib_LTLIBRARIES = libvirt-gconfig-1.0.la @@ -28,6 +31,8 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-clock.c \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-snapshot.c \ + libvirt-gconfig-enum-types.c \ + libvirt-gconfig-enum-types.h \ libvirt-gconfig-helpers.c \ libvirt-gconfig-interface.c \ libvirt-gconfig-network.c \ @@ -64,6 +69,20 @@ libvirt_gconfig_1_0_la_LDFLAGS = \ -Wl,--version-script=$(srcdir)/libvirt-gconfig.sym \ -version-info $(LIBVIRT_GLIB_VERSION_INFO) +BUILT_SOURCES = \ + libvirt-gconfig-enum-types.c \ + libvirt-gconfig-enum-types.h + +libvirt-gconfig-enum-types.h: $(GCONFIG_HEADER_FILES) libvirt-gconfig-enum-types.h.template + $(AM_V_GEN) ( cd $(srcdir) \ + && $(GLIB_MKENUMS) --template libvirt-gconfig-enum-types.h.template $(GCONFIG_HEADER_FILES) ) >libvirt-gconfig-enum-types.h.tmp \ + && sed -e "s/G_TYPE_VIR/GVIR_TYPE/" -e "s/g_vir/gvir/" libvirt-gconfig-enum-types.h.tmp >libvirt-gconfig-enum-types.h + +libvirt-gconfig-enum-types.c: $(GCONFIG_HEADER_FILES) libvirt-gconfig-enum-types.c.template + $(AM_V_GEN) ( cd $(srcdir) \ + && $(GLIB_MKENUMS) --template libvirt-gconfig-enum-types.c.template $(GCONFIG_HEADER_FILES) ) >libvirt-gconfig-enum-types.c.tmp \ + && sed -e "s/G_TYPE_VIR/GVIR_TYPE/" -e "s/g_vir/gvir/" libvirt-gconfig-enum-types.c.tmp >libvirt-gconfig-enum-types.c + if WITH_GOBJECT_INTROSPECTION LibvirtGConfig-1.0.gir: libvirt-gconfig-1.0.la $(G_IR_SCANNER) Makefile.am diff --git a/libvirt-gconfig/libvirt-gconfig-enum-types.c.template b/libvirt-gconfig/libvirt-gconfig-enum-types.c.template new file mode 100644 index 0000000..cccea77 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-enum-types.c.template @@ -0,0 +1,36 @@ +/*** BEGIN file-header ***/ +#include <libvirt-gconfig/libvirt-gconfig.h> + +/*** END file-header ***/ + +/*** BEGIN file-production ***/ +/* enumerations from "@filename@" */ +/*** END file-production ***/ + +/*** BEGIN value-header ***/ +GType +@enum_name@_get_type (void) +{ + static volatile gsize g_define_type_id__volatile = 0; + + if (g_once_init_enter (&g_define_type_id__volatile)) + { + static const G@Type@Value values[] = { +/*** END value-header ***/ + +/*** BEGIN value-production ***/ + { @VALUENAME@, "@VALUENAME@", "@valuenick@" }, +/*** END value-production ***/ + +/*** BEGIN value-tail ***/ + { 0, NULL, NULL } + }; + GType g_define_type_id = + g_@type@_register_static (g_intern_static_string ("@EnumName@"), values); + g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); + } + + return g_define_type_id__volatile; +} + +/*** END value-tail ***/ diff --git a/libvirt-gconfig/libvirt-gconfig-enum-types.h.template b/libvirt-gconfig/libvirt-gconfig-enum-types.h.template new file mode 100644 index 0000000..2cab1c5 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-enum-types.h.template @@ -0,0 +1,24 @@ +/*** BEGIN file-header ***/ +#ifndef __LIBVIRT_GCONFIG_ENUM_TYPES_H__ +#define __LIBVIRT_GCONFIG_ENUM_TYPES_H__ + +#include <libvirt-gconfig/libvirt-gconfig.h> + +G_BEGIN_DECLS +/*** END file-header ***/ + +/*** BEGIN file-production ***/ + +/* enumerations from "@filename@" */ +/*** END file-production ***/ + +/*** BEGIN value-header ***/ +GType @enum_name@_get_type (void) G_GNUC_CONST; +#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type ()) +/*** END value-header ***/ + +/*** BEGIN file-tail ***/ +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_ENUM_TYPES_H__ */ +/*** END file-tail ***/ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index 7cb34b0..26ad20e 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -31,6 +31,7 @@ #include <libvirt-gconfig/libvirt-gconfig-clock.h> #include <libvirt-gconfig/libvirt-gconfig-domain.h> #include <libvirt-gconfig/libvirt-gconfig-domain-snapshot.h> +#include <libvirt-gconfig/libvirt-gconfig-enum-types.h> #include <libvirt-gconfig/libvirt-gconfig-helpers.h> #include <libvirt-gconfig/libvirt-gconfig-interface.h> #include <libvirt-gconfig/libvirt-gconfig-network.h> -- 1.7.7

ack -- Marc-André Lureau

actually, @@ -28,6 +31,8 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-clock.c \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-snapshot.c \ + libvirt-gconfig-enum-types.c \ + libvirt-gconfig-enum-types.h \ libvirt-gconfig-enum-types.h needs to be in HEADERS and installed. On Fri, Nov 11, 2011 at 3:42 PM, Marc-André Lureau <marcandre.lureau@gmail.com> wrote:
ack
-- Marc-André Lureau
-- Marc-André Lureau

On Fri, Nov 11, 2011 at 03:43:41PM +0100, Marc-André Lureau wrote:
actually,
@@ -28,6 +31,8 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-clock.c \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-snapshot.c \ + libvirt-gconfig-enum-types.c \ + libvirt-gconfig-enum-types.h \
libvirt-gconfig-enum-types.h needs to be in HEADERS and installed.
Indeed, thanks. I put it in _SOURCE_FILES because I couldn't put it in _HEADER_FILES because the rule to generate the enum uses _HEADER_FILES, but I didn't think about header installation. Moved to HEADERS Christophe

--- libvirt-gconfig/libvirt-gconfig-clock.c | 19 +++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-clock.h | 8 ++++++++ libvirt-gconfig/libvirt-gconfig.sym | 2 ++ 3 files changed, 29 insertions(+), 0 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-clock.c b/libvirt-gconfig/libvirt-gconfig-clock.c index 120d3a6..dc7932d 100644 --- a/libvirt-gconfig/libvirt-gconfig-clock.c +++ b/libvirt-gconfig/libvirt-gconfig-clock.c @@ -81,6 +81,25 @@ GVirConfigClock *gvir_config_clock_new_from_xml(const gchar *xml, return GVIR_CONFIG_CLOCK(object); } +void gvir_config_clock_set_offset(GVirConfigClock *klock, + GVirConfigClockOffset offset) +{ + GEnumClass *enum_class; + GEnumValue *enum_value; + xmlNodePtr node; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(klock)); + if (node == NULL) + return; + enum_class = g_type_class_ref(GVIR_TYPE_CONFIG_CLOCK_OFFSET); + enum_value = g_enum_get_value(enum_class, offset); + if (enum_value != NULL) + xmlNewProp(node, (xmlChar*)"offset", (xmlChar*)enum_value->value_nick); + + g_type_class_unref(enum_class); + +} + void gvir_config_clock_set_timezone(GVirConfigClock *klock, const char *tz) { diff --git a/libvirt-gconfig/libvirt-gconfig-clock.h b/libvirt-gconfig/libvirt-gconfig-clock.h index 26f4b53..49cacef 100644 --- a/libvirt-gconfig/libvirt-gconfig-clock.h +++ b/libvirt-gconfig/libvirt-gconfig-clock.h @@ -56,6 +56,12 @@ struct _GVirConfigClockClass gpointer padding[20]; }; +typedef enum { + GVIR_CONFIG_CLOCK_UTC, + GVIR_CONFIG_CLOCK_LOCALTIME, + GVIR_CONFIG_CLOCK_TIMEZONE, + GVIR_CONFIG_CLOCK_VARIABLE +} GVirConfigClockOffset; GType gvir_config_clock_get_type(void); @@ -63,6 +69,8 @@ GVirConfigClock *gvir_config_clock_new(void); GVirConfigClock *gvir_config_clock_new_from_xml(const gchar *xml, GError **error); +void gvir_config_clock_set_offset(GVirConfigClock *klock, + GVirConfigClockOffset offset); void gvir_config_clock_set_timezone(GVirConfigClock *klock, const char *tz); void gvir_config_clock_set_variable_offset(GVirConfigClock *klock, diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 30cabf5..f6f1256 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -5,8 +5,10 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_capabilities_new_from_xml; gvir_config_clock_get_type; + gvir_config_clock_offset_get_type; gvir_config_clock_new; gvir_config_clock_new_from_xml; + gvir_config_clock_set_offset; gvir_config_clock_set_timezone; gvir_config_clock_set_variable_offset; -- 1.7.7

Hi On Thu, Nov 10, 2011 at 9:33 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
--- libvirt-gconfig/libvirt-gconfig-clock.c | 19 +++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-clock.h | 8 ++++++++ libvirt-gconfig/libvirt-gconfig.sym | 2 ++ 3 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-clock.c b/libvirt-gconfig/libvirt-gconfig-clock.c index 120d3a6..dc7932d 100644 --- a/libvirt-gconfig/libvirt-gconfig-clock.c +++ b/libvirt-gconfig/libvirt-gconfig-clock.c @@ -81,6 +81,25 @@ GVirConfigClock *gvir_config_clock_new_from_xml(const gchar *xml, return GVIR_CONFIG_CLOCK(object); }
+void gvir_config_clock_set_offset(GVirConfigClock *klock, + GVirConfigClockOffset offset) +{ + GEnumClass *enum_class; + GEnumValue *enum_value; + xmlNodePtr node; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(klock)); + if (node == NULL) + return; + enum_class = g_type_class_ref(GVIR_TYPE_CONFIG_CLOCK_OFFSET); + enum_value = g_enum_get_value(enum_class, offset); + if (enum_value != NULL) + xmlNewProp(node, (xmlChar*)"offset", (xmlChar*)enum_value->value_nick); + + g_type_class_unref(enum_class); + +}
There is an extra ending line. You could rebase so that gvir_config_genum_get_nick() helper is added before this function.
+ void gvir_config_clock_set_timezone(GVirConfigClock *klock, const char *tz) { diff --git a/libvirt-gconfig/libvirt-gconfig-clock.h b/libvirt-gconfig/libvirt-gconfig-clock.h index 26f4b53..49cacef 100644 --- a/libvirt-gconfig/libvirt-gconfig-clock.h +++ b/libvirt-gconfig/libvirt-gconfig-clock.h @@ -56,6 +56,12 @@ struct _GVirConfigClockClass gpointer padding[20]; };
+typedef enum { + GVIR_CONFIG_CLOCK_UTC, + GVIR_CONFIG_CLOCK_LOCALTIME, + GVIR_CONFIG_CLOCK_TIMEZONE, + GVIR_CONFIG_CLOCK_VARIABLE +} GVirConfigClockOffset;
GType gvir_config_clock_get_type(void);
@@ -63,6 +69,8 @@ GVirConfigClock *gvir_config_clock_new(void); GVirConfigClock *gvir_config_clock_new_from_xml(const gchar *xml, GError **error);
+void gvir_config_clock_set_offset(GVirConfigClock *klock, + GVirConfigClockOffset offset); void gvir_config_clock_set_timezone(GVirConfigClock *klock, const char *tz); void gvir_config_clock_set_variable_offset(GVirConfigClock *klock, diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 30cabf5..f6f1256 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -5,8 +5,10 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_capabilities_new_from_xml;
gvir_config_clock_get_type; + gvir_config_clock_offset_get_type; gvir_config_clock_new; gvir_config_clock_new_from_xml; + gvir_config_clock_set_offset; gvir_config_clock_set_timezone; gvir_config_clock_set_variable_offset;
-- 1.7.7
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
-- Marc-André Lureau

On Fri, Nov 11, 2011 at 03:47:36PM +0100, Marc-André Lureau wrote:
On Thu, Nov 10, 2011 at 9:33 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
--- libvirt-gconfig/libvirt-gconfig-clock.c | 19 +++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-clock.h | 8 ++++++++ libvirt-gconfig/libvirt-gconfig.sym | 2 ++ 3 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-clock.c b/libvirt-gconfig/libvirt-gconfig-clock.c index 120d3a6..dc7932d 100644 --- a/libvirt-gconfig/libvirt-gconfig-clock.c +++ b/libvirt-gconfig/libvirt-gconfig-clock.c @@ -81,6 +81,25 @@ GVirConfigClock *gvir_config_clock_new_from_xml(const gchar *xml, return GVIR_CONFIG_CLOCK(object); }
+void gvir_config_clock_set_offset(GVirConfigClock *klock, + GVirConfigClockOffset offset) +{ + GEnumClass *enum_class; + GEnumValue *enum_value; + xmlNodePtr node; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(klock)); + if (node == NULL) + return; + enum_class = g_type_class_ref(GVIR_TYPE_CONFIG_CLOCK_OFFSET); + enum_value = g_enum_get_value(enum_class, offset); + if (enum_value != NULL) + xmlNewProp(node, (xmlChar*)"offset", (xmlChar*)enum_value->value_nick); + + g_type_class_unref(enum_class); + +}
There is an extra ending line.
You could rebase so that gvir_config_genum_get_nick() helper is added before this function.
Good point, I did this, and this got rid of the extra white line at the same time. Christophe

--- libvirt-gconfig/tests/test-domain-create.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index a719ed2..a5c5b99 100644 --- a/libvirt-gconfig/tests/test-domain-create.c +++ b/libvirt-gconfig/tests/test-domain-create.c @@ -33,6 +33,7 @@ const char *features[] = { "foo", "bar", "baz", NULL }; int main(void) { GVirConfigDomain *domain; + GVirConfigClock *klock; char *name; GStrv feat; unsigned int i; @@ -59,6 +60,10 @@ int main(void) } g_strfreev(feat); + klock = gvir_config_clock_new(); + gvir_config_clock_set_offset(klock, GVIR_CONFIG_CLOCK_UTC); + gvir_config_domain_set_clock(domain, klock); + xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(domain)); g_print("%s\n", xml); g_free(xml); -- 1.7.7

ack -- Marc-André Lureau

--- libvirt-gconfig/Makefile.am | 2 + libvirt-gconfig/libvirt-gconfig-os.c | 80 ++++++++++++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-os.h | 67 ++++++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 3 +- libvirt-gconfig/libvirt-gconfig.sym | 4 ++ 5 files changed, 155 insertions(+), 1 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-os.c create mode 100644 libvirt-gconfig/libvirt-gconfig-os.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index a0dec08..384d7a3 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -19,6 +19,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-network.h \ libvirt-gconfig-network-filter.h \ libvirt-gconfig-node-device.h \ + libvirt-gconfig-os.h \ libvirt-gconfig-secret.h \ libvirt-gconfig-timer.h \ libvirt-gconfig-storage-pool.h \ @@ -38,6 +39,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-network.c \ libvirt-gconfig-network-filter.c \ libvirt-gconfig-node-device.c \ + libvirt-gconfig-os.c \ libvirt-gconfig-secret.c \ libvirt-gconfig-timer.c \ libvirt-gconfig-storage-pool.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-os.c b/libvirt-gconfig/libvirt-gconfig-os.c new file mode 100644 index 0000000..b47e859 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-os.c @@ -0,0 +1,80 @@ +/* + * libvirt-gobject-config_os.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@gmail.com> + */ + +#include <config.h> + +#include <string.h> + +#include <libxml/tree.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" + +extern gboolean debugFlag; + +#define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0) + +#define GVIR_CONFIG_OS_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_OS, GVirConfigOsPrivate)) + +struct _GVirConfigOsPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigOs, gvir_config_os, GVIR_TYPE_CONFIG_OBJECT); + + +static void gvir_config_os_class_init(GVirConfigOsClass *klass) +{ + + g_type_class_add_private(klass, sizeof(GVirConfigOsPrivate)); +} + + +static void gvir_config_os_init(GVirConfigOs *os) +{ + GVirConfigOsPrivate *priv; + + DEBUG("Init GVirConfigOs=%p", os); + + priv = os->priv = GVIR_CONFIG_OS_GET_PRIVATE(os); + + memset(priv, 0, sizeof(*priv)); +} + + +GVirConfigOs *gvir_config_os_new(void) +{ + GVirConfigObject *object; + + object = gvir_config_object_new(GVIR_TYPE_CONFIG_OS, "os", NULL); + return GVIR_CONFIG_OS(object); +} + +GVirConfigOs *gvir_config_os_new_from_xml(const gchar *xml, GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_OS, "os", + NULL, xml, error); + return GVIR_CONFIG_OS(object); +} diff --git a/libvirt-gconfig/libvirt-gconfig-os.h b/libvirt-gconfig/libvirt-gconfig-os.h new file mode 100644 index 0000000..716f588 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-os.h @@ -0,0 +1,67 @@ +/* + * libvirt-gobject-os.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@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_OS_H__ +#define __LIBVIRT_GCONFIG_OS_H__ + +G_BEGIN_DECLS + +#define GVIR_TYPE_CONFIG_OS (gvir_config_os_get_type ()) +#define GVIR_CONFIG_OS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_OS, GVirConfigOs)) +#define GVIR_CONFIG_OS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_OS, GVirConfigOsClass)) +#define GVIR_IS_CONFIG_OS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_OS)) +#define GVIR_IS_CONFIG_OS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_OS)) +#define GVIR_CONFIG_OS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_OS, GVirConfigOsClass)) + +typedef struct _GVirConfigOs GVirConfigOs; +typedef struct _GVirConfigOsPrivate GVirConfigOsPrivate; +typedef struct _GVirConfigOsClass GVirConfigOsClass; + +struct _GVirConfigOs +{ + GVirConfigObject parent; + + GVirConfigOsPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigOsClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + + +GType gvir_config_os_get_type(void); + +GVirConfigOs *gvir_config_os_new(void); +GVirConfigOs *gvir_config_os_new_from_xml(const gchar *xml, GError **error); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_OS_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index 26ad20e..482c088 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -35,8 +35,9 @@ #include <libvirt-gconfig/libvirt-gconfig-helpers.h> #include <libvirt-gconfig/libvirt-gconfig-interface.h> #include <libvirt-gconfig/libvirt-gconfig-network.h> -#include <libvirt-gconfig/libvirt-gconfig-node-device.h> #include <libvirt-gconfig/libvirt-gconfig-network-filter.h> +#include <libvirt-gconfig/libvirt-gconfig-node-device.h> +#include <libvirt-gconfig/libvirt-gconfig-os.h> #include <libvirt-gconfig/libvirt-gconfig-secret.h> #include <libvirt-gconfig/libvirt-gconfig-timer.h> #include <libvirt-gconfig/libvirt-gconfig-storage-pool.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index f6f1256..b1dcb81 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -51,6 +51,10 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_object_to_xml; gvir_config_object_validate; + gvir_config_os_get_type; + gvir_config_os_new; + gvir_config_os_new_from_xml; + gvir_config_secret_get_type; gvir_config_secret_new; gvir_config_secret_new_from_xml; -- 1.7.7

ack On Thu, Nov 10, 2011 at 9:33 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
--- libvirt-gconfig/Makefile.am | 2 + libvirt-gconfig/libvirt-gconfig-os.c | 80 ++++++++++++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-os.h | 67 ++++++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 3 +- libvirt-gconfig/libvirt-gconfig.sym | 4 ++ 5 files changed, 155 insertions(+), 1 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-os.c create mode 100644 libvirt-gconfig/libvirt-gconfig-os.h
diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index a0dec08..384d7a3 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -19,6 +19,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-network.h \ libvirt-gconfig-network-filter.h \ libvirt-gconfig-node-device.h \ + libvirt-gconfig-os.h \ libvirt-gconfig-secret.h \ libvirt-gconfig-timer.h \ libvirt-gconfig-storage-pool.h \ @@ -38,6 +39,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-network.c \ libvirt-gconfig-network-filter.c \ libvirt-gconfig-node-device.c \ + libvirt-gconfig-os.c \ libvirt-gconfig-secret.c \ libvirt-gconfig-timer.c \ libvirt-gconfig-storage-pool.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-os.c b/libvirt-gconfig/libvirt-gconfig-os.c new file mode 100644 index 0000000..b47e859 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-os.c @@ -0,0 +1,80 @@ +/* + * libvirt-gobject-config_os.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@gmail.com> + */ + +#include <config.h> + +#include <string.h> + +#include <libxml/tree.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" + +extern gboolean debugFlag; + +#define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0) + +#define GVIR_CONFIG_OS_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_OS, GVirConfigOsPrivate)) + +struct _GVirConfigOsPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigOs, gvir_config_os, GVIR_TYPE_CONFIG_OBJECT); + + +static void gvir_config_os_class_init(GVirConfigOsClass *klass) +{ + + g_type_class_add_private(klass, sizeof(GVirConfigOsPrivate)); +} + + +static void gvir_config_os_init(GVirConfigOs *os) +{ + GVirConfigOsPrivate *priv; + + DEBUG("Init GVirConfigOs=%p", os); + + priv = os->priv = GVIR_CONFIG_OS_GET_PRIVATE(os); + + memset(priv, 0, sizeof(*priv)); +} + + +GVirConfigOs *gvir_config_os_new(void) +{ + GVirConfigObject *object; + + object = gvir_config_object_new(GVIR_TYPE_CONFIG_OS, "os", NULL); + return GVIR_CONFIG_OS(object); +} + +GVirConfigOs *gvir_config_os_new_from_xml(const gchar *xml, GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_OS, "os", + NULL, xml, error); + return GVIR_CONFIG_OS(object); +} diff --git a/libvirt-gconfig/libvirt-gconfig-os.h b/libvirt-gconfig/libvirt-gconfig-os.h new file mode 100644 index 0000000..716f588 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-os.h @@ -0,0 +1,67 @@ +/* + * libvirt-gobject-os.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@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_OS_H__ +#define __LIBVIRT_GCONFIG_OS_H__ + +G_BEGIN_DECLS + +#define GVIR_TYPE_CONFIG_OS (gvir_config_os_get_type ()) +#define GVIR_CONFIG_OS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_OS, GVirConfigOs)) +#define GVIR_CONFIG_OS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_OS, GVirConfigOsClass)) +#define GVIR_IS_CONFIG_OS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_OS)) +#define GVIR_IS_CONFIG_OS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_OS)) +#define GVIR_CONFIG_OS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_OS, GVirConfigOsClass)) + +typedef struct _GVirConfigOs GVirConfigOs; +typedef struct _GVirConfigOsPrivate GVirConfigOsPrivate; +typedef struct _GVirConfigOsClass GVirConfigOsClass; + +struct _GVirConfigOs +{ + GVirConfigObject parent; + + GVirConfigOsPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigOsClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + + +GType gvir_config_os_get_type(void); + +GVirConfigOs *gvir_config_os_new(void); +GVirConfigOs *gvir_config_os_new_from_xml(const gchar *xml, GError **error); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_OS_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index 26ad20e..482c088 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -35,8 +35,9 @@ #include <libvirt-gconfig/libvirt-gconfig-helpers.h> #include <libvirt-gconfig/libvirt-gconfig-interface.h> #include <libvirt-gconfig/libvirt-gconfig-network.h> -#include <libvirt-gconfig/libvirt-gconfig-node-device.h> #include <libvirt-gconfig/libvirt-gconfig-network-filter.h> +#include <libvirt-gconfig/libvirt-gconfig-node-device.h> +#include <libvirt-gconfig/libvirt-gconfig-os.h> #include <libvirt-gconfig/libvirt-gconfig-secret.h> #include <libvirt-gconfig/libvirt-gconfig-timer.h> #include <libvirt-gconfig/libvirt-gconfig-storage-pool.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index f6f1256..b1dcb81 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -51,6 +51,10 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_object_to_xml; gvir_config_object_validate;
+ gvir_config_os_get_type; + gvir_config_os_new; + gvir_config_os_new_from_xml; + gvir_config_secret_get_type; gvir_config_secret_new; gvir_config_secret_new_from_xml; -- 1.7.7
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
-- Marc-André Lureau

We will often need to convert from an enum to its string representation, add an helper for that to avoid duplicating that code. --- libvirt-gconfig/libvirt-gconfig-clock.c | 15 ++++++--------- libvirt-gconfig/libvirt-gconfig-helpers-private.h | 1 + libvirt-gconfig/libvirt-gconfig-helpers.c | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-clock.c b/libvirt-gconfig/libvirt-gconfig-clock.c index dc7932d..3deb725 100644 --- a/libvirt-gconfig/libvirt-gconfig-clock.c +++ b/libvirt-gconfig/libvirt-gconfig-clock.c @@ -27,6 +27,7 @@ #include <libxml/tree.h> #include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-helpers-private.h" extern gboolean debugFlag; @@ -84,20 +85,16 @@ GVirConfigClock *gvir_config_clock_new_from_xml(const gchar *xml, void gvir_config_clock_set_offset(GVirConfigClock *klock, GVirConfigClockOffset offset) { - GEnumClass *enum_class; - GEnumValue *enum_value; xmlNodePtr node; + const char *offset_str; node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(klock)); if (node == NULL) return; - enum_class = g_type_class_ref(GVIR_TYPE_CONFIG_CLOCK_OFFSET); - enum_value = g_enum_get_value(enum_class, offset); - if (enum_value != NULL) - xmlNewProp(node, (xmlChar*)"offset", (xmlChar*)enum_value->value_nick); - - g_type_class_unref(enum_class); - + offset_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_CLOCK_OFFSET, + offset); + if (offset_str != NULL) + xmlNewProp(node, (xmlChar*)"offset", (xmlChar*)offset_str); } void gvir_config_clock_set_timezone(GVirConfigClock *klock, diff --git a/libvirt-gconfig/libvirt-gconfig-helpers-private.h b/libvirt-gconfig/libvirt-gconfig-helpers-private.h index c7a5d6a..59efd24 100644 --- a/libvirt-gconfig/libvirt-gconfig-helpers-private.h +++ b/libvirt-gconfig/libvirt-gconfig-helpers-private.h @@ -40,6 +40,7 @@ xmlChar * gvir_config_xml_get_child_element_content (xmlNode *node, const char *child_name); char *gvir_config_xml_get_child_element_content_glib (xmlNode *node, const char *child_name); +const char *gvir_config_genum_get_nick (GType enum_type, gint value); G_END_DECLS #endif /* __LIBVIRT_GCONFIG_HELPERS_PRIVATE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-helpers.c b/libvirt-gconfig/libvirt-gconfig-helpers.c index 2e28429..d069714 100644 --- a/libvirt-gconfig/libvirt-gconfig-helpers.c +++ b/libvirt-gconfig/libvirt-gconfig-helpers.c @@ -178,3 +178,20 @@ gvir_config_xml_get_child_element_content_glib (xmlNode *node, return copy; } + +const char *gvir_config_genum_get_nick (GType enum_type, gint value) +{ + GEnumClass *enum_class; + GEnumValue *enum_value; + + g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL); + + enum_class = g_type_class_ref(enum_type); + enum_value = g_enum_get_value(enum_class, value); + g_type_class_unref(enum_class); + + if (enum_value != NULL) + return enum_value->value_nick; + + return NULL; +} -- 1.7.7

ack On Thu, Nov 10, 2011 at 9:33 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
We will often need to convert from an enum to its string representation, add an helper for that to avoid duplicating that code. --- libvirt-gconfig/libvirt-gconfig-clock.c | 15 ++++++--------- libvirt-gconfig/libvirt-gconfig-helpers-private.h | 1 + libvirt-gconfig/libvirt-gconfig-helpers.c | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-clock.c b/libvirt-gconfig/libvirt-gconfig-clock.c index dc7932d..3deb725 100644 --- a/libvirt-gconfig/libvirt-gconfig-clock.c +++ b/libvirt-gconfig/libvirt-gconfig-clock.c @@ -27,6 +27,7 @@ #include <libxml/tree.h>
#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-helpers-private.h"
extern gboolean debugFlag;
@@ -84,20 +85,16 @@ GVirConfigClock *gvir_config_clock_new_from_xml(const gchar *xml, void gvir_config_clock_set_offset(GVirConfigClock *klock, GVirConfigClockOffset offset) { - GEnumClass *enum_class; - GEnumValue *enum_value; xmlNodePtr node; + const char *offset_str;
node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(klock)); if (node == NULL) return; - enum_class = g_type_class_ref(GVIR_TYPE_CONFIG_CLOCK_OFFSET); - enum_value = g_enum_get_value(enum_class, offset); - if (enum_value != NULL) - xmlNewProp(node, (xmlChar*)"offset", (xmlChar*)enum_value->value_nick); - - g_type_class_unref(enum_class); - + offset_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_CLOCK_OFFSET, + offset); + if (offset_str != NULL) + xmlNewProp(node, (xmlChar*)"offset", (xmlChar*)offset_str); }
void gvir_config_clock_set_timezone(GVirConfigClock *klock, diff --git a/libvirt-gconfig/libvirt-gconfig-helpers-private.h b/libvirt-gconfig/libvirt-gconfig-helpers-private.h index c7a5d6a..59efd24 100644 --- a/libvirt-gconfig/libvirt-gconfig-helpers-private.h +++ b/libvirt-gconfig/libvirt-gconfig-helpers-private.h @@ -40,6 +40,7 @@ xmlChar * gvir_config_xml_get_child_element_content (xmlNode *node, const char *child_name); char *gvir_config_xml_get_child_element_content_glib (xmlNode *node, const char *child_name); +const char *gvir_config_genum_get_nick (GType enum_type, gint value); G_END_DECLS
#endif /* __LIBVIRT_GCONFIG_HELPERS_PRIVATE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-helpers.c b/libvirt-gconfig/libvirt-gconfig-helpers.c index 2e28429..d069714 100644 --- a/libvirt-gconfig/libvirt-gconfig-helpers.c +++ b/libvirt-gconfig/libvirt-gconfig-helpers.c @@ -178,3 +178,20 @@ gvir_config_xml_get_child_element_content_glib (xmlNode *node,
return copy; } + +const char *gvir_config_genum_get_nick (GType enum_type, gint value) +{ + GEnumClass *enum_class; + GEnumValue *enum_value; + + g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL); + + enum_class = g_type_class_ref(enum_type); + enum_value = g_enum_get_value(enum_class, value); + g_type_class_unref(enum_class); + + if (enum_value != NULL) + return enum_value->value_nick; + + return NULL; +} -- 1.7.7
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
-- Marc-André Lureau

--- libvirt-gconfig/libvirt-gconfig-os.c | 14 ++++++++++++++ libvirt-gconfig/libvirt-gconfig-os.h | 6 ++++++ libvirt-gconfig/libvirt-gconfig.sym | 1 + 3 files changed, 21 insertions(+), 0 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-os.c b/libvirt-gconfig/libvirt-gconfig-os.c index b47e859..d4a04ae 100644 --- a/libvirt-gconfig/libvirt-gconfig-os.c +++ b/libvirt-gconfig/libvirt-gconfig-os.c @@ -27,6 +27,7 @@ #include <libxml/tree.h> #include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-helpers-private.h" extern gboolean debugFlag; @@ -78,3 +79,16 @@ GVirConfigOs *gvir_config_os_new_from_xml(const gchar *xml, GError **error) NULL, xml, error); return GVIR_CONFIG_OS(object); } + +void gvir_config_os_set_os_type(GVirConfigOs *os, GVirConfigOsType type) +{ + xmlNodePtr node; + const char *type_str; + + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(os), "type"); + if (node == NULL) + return; + type_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_OS_TYPE, type); + if (type_str != NULL) + xmlNodeSetContent(node, (xmlChar*)type_str); +} diff --git a/libvirt-gconfig/libvirt-gconfig-os.h b/libvirt-gconfig/libvirt-gconfig-os.h index 716f588..c6498ad 100644 --- a/libvirt-gconfig/libvirt-gconfig-os.h +++ b/libvirt-gconfig/libvirt-gconfig-os.h @@ -56,12 +56,18 @@ struct _GVirConfigOsClass gpointer padding[20]; }; +typedef enum { + GVIR_CONFIG_OS_TYPE_HVM, + GVIR_CONFIG_OS_TYPE_LINUX +} GVirConfigOsType; GType gvir_config_os_get_type(void); GVirConfigOs *gvir_config_os_new(void); GVirConfigOs *gvir_config_os_new_from_xml(const gchar *xml, GError **error); +void gvir_config_os_set_os_type(GVirConfigOs *os, GVirConfigOsType type); + G_END_DECLS #endif /* __LIBVIRT_GCONFIG_OS_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index b1dcb81..176a2e2 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -52,6 +52,7 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_object_validate; gvir_config_os_get_type; + gvir_config_os_type_get_type; gvir_config_os_new; gvir_config_os_new_from_xml; -- 1.7.7

On Thu, Nov 10, 2011 at 9:33 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
--- libvirt-gconfig/libvirt-gconfig-os.c | 14 ++++++++++++++ libvirt-gconfig/libvirt-gconfig-os.h | 6 ++++++ libvirt-gconfig/libvirt-gconfig.sym | 1 + 3 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-os.c b/libvirt-gconfig/libvirt-gconfig-os.c index b47e859..d4a04ae 100644 --- a/libvirt-gconfig/libvirt-gconfig-os.c +++ b/libvirt-gconfig/libvirt-gconfig-os.c @@ -27,6 +27,7 @@ #include <libxml/tree.h>
#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-helpers-private.h"
extern gboolean debugFlag;
@@ -78,3 +79,16 @@ GVirConfigOs *gvir_config_os_new_from_xml(const gchar *xml, GError **error) NULL, xml, error); return GVIR_CONFIG_OS(object); } + +void gvir_config_os_set_os_type(GVirConfigOs *os, GVirConfigOsType type) +{ + xmlNodePtr node; + const char *type_str; + + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(os), "type"); + if (node == NULL) + return;
I would use a couple of g_return_if_fail so that we get warnings of something going wrong instead of silently returning. Same in previous code actually.
+ type_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_OS_TYPE, type); + if (type_str != NULL) + xmlNodeSetContent(node, (xmlChar*)type_str); +}
Perhaps the warning for invalid enum could be put in gvir_config_genum_get_nick(). -- Marc-André Lureau

it's actually missing gvir_config_os_set_os_type in the sym file, that you added in following patch. I would suggest to merge the two patches. -- Marc-André Lureau

On Fri, Nov 11, 2011 at 04:15:46PM +0100, Marc-André Lureau wrote:
it's actually missing gvir_config_os_set_os_type in the sym file, that you added in following patch.
I would suggest to merge the two patches.
Done. Christophe

On Fri, Nov 11, 2011 at 03:58:40PM +0100, Marc-André Lureau wrote:
On Thu, Nov 10, 2011 at 9:33 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
--- libvirt-gconfig/libvirt-gconfig-os.c | 14 ++++++++++++++ libvirt-gconfig/libvirt-gconfig-os.h | 6 ++++++ libvirt-gconfig/libvirt-gconfig.sym | 1 + 3 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-os.c b/libvirt-gconfig/libvirt-gconfig-os.c index b47e859..d4a04ae 100644 --- a/libvirt-gconfig/libvirt-gconfig-os.c +++ b/libvirt-gconfig/libvirt-gconfig-os.c @@ -27,6 +27,7 @@ #include <libxml/tree.h>
#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-helpers-private.h"
extern gboolean debugFlag;
@@ -78,3 +79,16 @@ GVirConfigOs *gvir_config_os_new_from_xml(const gchar *xml, GError **error) NULL, xml, error); return GVIR_CONFIG_OS(object); } + +void gvir_config_os_set_os_type(GVirConfigOs *os, GVirConfigOsType type) +{ + xmlNodePtr node; + const char *type_str; + + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(os), "type"); + if (node == NULL) + return;
I would use a couple of g_return_if_fail so that we get warnings of something going wrong instead of silently returning.
Same in previous code actually.
Ok, I'll make a pass over this once I have addressed the other comments.
+ type_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_OS_TYPE, type); + if (type_str != NULL) + xmlNodeSetContent(node, (xmlChar*)type_str); +}
Perhaps the warning for invalid enum could be put in gvir_config_genum_get_nick().
What do you mean exactly? Having a warning in genum_get_nick and drop the != NULL test? Or only to add the warning in genum_get_nick, and not add a warning here? I can easily add a g_warn_if_reached() in genum_get_nick Christophe

On Tue, Nov 15, 2011 at 3:18 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
What do you mean exactly? Having a warning in genum_get_nick and drop the != NULL test? Or only to add the warning in genum_get_nick, and not add a warning here? I can easily add a g_warn_if_reached() in genum_get_nick
Yeah, I meant putting g_warn_if_reached() in genum_get_nick(). However, thinking a bit more about it, genum_get_nick() shouldn't warn if given a value that has no associated nick, because enums shouldn't be limited to their associated name, and those value would be perfectly valid, but should return NULL and that's it. However, siliently not doing anything is misleading. So instead of if (type_str != NULL) xmlNodeSetContent(node, (xmlChar*)type_str); I would do (or similar): g_return_if_fail (type_str != NULL); xmlNodeSetContent(node, (xmlChar*)type_str); cheers -- Marc-André Lureau

Hey, On Tue, Nov 15, 2011 at 03:33:45PM +0100, Marc-André Lureau wrote:
However, thinking a bit more about it, genum_get_nick() shouldn't warn if given a value that has no associated nick, because enums shouldn't be limited to their associated name, and those value would be perfectly valid, but should return NULL and that's it.
For now I have added a warning to genum_get_nick since we shouldn't get an enum with no associated strings. If this happens, this means something unexpected happened, so it's better to warn about it. We can change this when we have a valid use case for this.
However, siliently not doing anything is misleading. So instead of
if (type_str != NULL) xmlNodeSetContent(node, (xmlChar*)type_str);
I would do (or similar):
g_return_if_fail (type_str != NULL); xmlNodeSetContent(node, (xmlChar*)type_str);
And I did that change too. Christophe

--- libvirt-gconfig/libvirt-gconfig-os.c | 85 ++++++++++++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-os.h | 19 ++++++++ libvirt-gconfig/libvirt-gconfig.sym | 8 +++ 3 files changed, 112 insertions(+), 0 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-os.c b/libvirt-gconfig/libvirt-gconfig-os.c index d4a04ae..cfe827e 100644 --- a/libvirt-gconfig/libvirt-gconfig-os.c +++ b/libvirt-gconfig/libvirt-gconfig-os.c @@ -92,3 +92,88 @@ void gvir_config_os_set_os_type(GVirConfigOs *os, GVirConfigOsType type) if (type_str != NULL) xmlNodeSetContent(node, (xmlChar*)type_str); } + +void gvir_config_os_set_loader(GVirConfigOs *os, const char * loader) +{ + gvir_config_object_set_node_content(GVIR_CONFIG_OBJECT(os), + "loader", loader); +} + +void gvir_config_os_enable_boot_menu(GVirConfigOs *os, gboolean enable) +{ + xmlNodePtr node; + + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(os), "bootmenu"); + if (node == NULL) + return; + if (enable) + xmlNewProp(node, (xmlChar*)"enable", (xmlChar*)"yes"); + else + xmlNewProp(node, (xmlChar*)"enable", (xmlChar*)"no"); +} + +void gvir_config_os_bios_enable_serial(GVirConfigOs *os, gboolean enable) +{ + xmlNodePtr node; + + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(os), "bios"); + if (node == NULL) + return; + if (enable) + xmlNewProp(node, (xmlChar*)"useserial", (xmlChar*)"yes"); + else + xmlNewProp(node, (xmlChar*)"useserial", (xmlChar*)"no"); +} + +void gvir_config_os_set_smbios_mode(GVirConfigOs *os, + GVirConfigOsSmBiosMode mode) +{ + xmlNodePtr node; + const char *mode_str; + + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(os), "smbios"); + if (node == NULL) + return; + mode_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_OS_SM_BIOS_MODE, + mode); + if (mode_str != NULL) + xmlNewProp(node, (xmlChar*)"mode", (xmlChar*)mode_str); +} + +/** + * gvir_config_os_set_boot_devices: + * @boot_devices: (in) (element-type LibvirtGConfig.OsBootDevice): + */ +void gvir_config_os_set_boot_devices(GVirConfigOs *os, GList *boot_devices) +{ + GList *it; + xmlNodePtr os_node; + xmlNodePtr node; + + os_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(os)); + if (os_node == NULL) + return; + + node = os_node->children; + while (node != NULL) { + xmlNodePtr next_node; + next_node = node->next; + if (strcmp("boot", (char *)node->name) == 0) { + xmlUnlinkNode(node); + xmlFreeNode(node); + } + node = next_node; + } + + for (it = boot_devices; it != NULL; it = it->next) { + const char *dev; + + dev = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_OS_BOOT_DEVICE, + GPOINTER_TO_INT(it->data)); + if (dev != NULL) { + node = xmlNewDocNode(NULL, NULL, (xmlChar*)"boot", NULL); + xmlNewProp(node, (xmlChar*)"dev", (xmlChar*)dev); + xmlAddChild(os_node, node); + } + } +} diff --git a/libvirt-gconfig/libvirt-gconfig-os.h b/libvirt-gconfig/libvirt-gconfig-os.h index c6498ad..87027da 100644 --- a/libvirt-gconfig/libvirt-gconfig-os.h +++ b/libvirt-gconfig/libvirt-gconfig-os.h @@ -61,12 +61,31 @@ typedef enum { GVIR_CONFIG_OS_TYPE_LINUX } GVirConfigOsType; +typedef enum { + GVIR_CONFIG_OS_SMBIOS_MODE_EMULATE, + GVIR_CONFIG_OS_SMBIOS_MODE_HOST, + GVIR_CONFIG_OS_SMBIOS_MODE_SYSINFO +} GVirConfigOsSmBiosMode; + +typedef enum { + GVIR_CONFIG_OS_BOOT_DEVICE_FD, + GVIR_CONFIG_OS_BOOT_DEVICE_HD, + GVIR_CONFIG_OS_BOOT_DEVICE_CDROM, + GVIR_CONFIG_OS_BOOT_DEVICE_NETWORK +} GVirConfigOsBootDevice; + GType gvir_config_os_get_type(void); GVirConfigOs *gvir_config_os_new(void); GVirConfigOs *gvir_config_os_new_from_xml(const gchar *xml, GError **error); void gvir_config_os_set_os_type(GVirConfigOs *os, GVirConfigOsType type); +void gvir_config_os_set_boot_devices(GVirConfigOs *os, GList *boot_devices); +void gvir_config_os_set_loader(GVirConfigOs *os, const char * loader); +void gvir_config_os_set_smbios_mode(GVirConfigOs *os, + GVirConfigOsSmBiosMode mode); +void gvir_config_os_enable_boot_menu(GVirConfigOs *os, gboolean enable); +void gvir_config_os_bios_enable_serial(GVirConfigOs *os, gboolean enable); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 176a2e2..3466129 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -52,9 +52,17 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_object_validate; gvir_config_os_get_type; + gvir_config_os_boot_device_get_type; + gvir_config_os_sm_bios_mode_get_type; gvir_config_os_type_get_type; gvir_config_os_new; gvir_config_os_new_from_xml; + gvir_config_os_set_os_type; + gvir_config_os_set_boot_devices; + gvir_config_os_set_loader; + gvir_config_os_set_smbios_mode; + gvir_config_os_enable_boot_menu; + gvir_config_os_bios_enable_serial; gvir_config_secret_get_type; gvir_config_secret_new; -- 1.7.7

Hi Please merge with previous patch.
+ if (enable) + xmlNewProp(node, (xmlChar*)"enable", (xmlChar*)"yes"); + else + xmlNewProp(node, (xmlChar*)"enable", (xmlChar*)"no"); +}
might be useful to have use a gchar * gvir_config_yes_no (bool condition)
+ if (strcmp("boot", (char *)node->name) == 0) {
It could use the safer g_strcmp0. -- Marc-André Lureau

On Fri, Nov 11, 2011 at 04:20:05PM +0100, Marc-André Lureau wrote:
Hi
Please merge with previous patch.
+ if (enable) + xmlNewProp(node, (xmlChar*)"enable", (xmlChar*)"yes"); + else + xmlNewProp(node, (xmlChar*)"enable", (xmlChar*)"no"); +}
might be useful to have use a gchar * gvir_config_yes_no (bool condition)
This is factored in a helper function in one of the patches that hasn't been sent yet.
+ if (strcmp("boot", (char *)node->name) == 0) {
It could use the safer g_strcmp0.
Ah indeed, didn't know about this function, changed. Christophe

--- libvirt-gconfig/libvirt-gconfig-os.c | 32 ++++++++++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-os.h | 2 ++ libvirt-gconfig/libvirt-gconfig.sym | 2 ++ 3 files changed, 36 insertions(+), 0 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-os.c b/libvirt-gconfig/libvirt-gconfig-os.c index cfe827e..3e23493 100644 --- a/libvirt-gconfig/libvirt-gconfig-os.c +++ b/libvirt-gconfig/libvirt-gconfig-os.c @@ -177,3 +177,35 @@ void gvir_config_os_set_boot_devices(GVirConfigOs *os, GList *boot_devices) } } } + +void gvir_config_os_set_arch(GVirConfigOs *os, const char *arch) +{ + xmlNodePtr os_node; + xmlNodePtr os_type_node; + + os_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(os)); + if (os_node == NULL) + return; + + os_type_node = gvir_config_xml_get_element(os_node, "type", NULL); + if (os_type_node == NULL) + return; + + xmlNewProp(os_type_node, (xmlChar*)"arch", (xmlChar*)arch); +} + +void gvir_config_os_set_machine(GVirConfigOs *os, const char *machine) +{ + xmlNodePtr os_node; + xmlNodePtr os_type_node; + + os_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(os)); + if (os_node == NULL) + return; + + os_type_node = gvir_config_xml_get_element(os_node, "type", NULL); + if (os_type_node == NULL) + return; + + xmlNewProp(os_type_node, (xmlChar*)"machine", (xmlChar*)machine); +} diff --git a/libvirt-gconfig/libvirt-gconfig-os.h b/libvirt-gconfig/libvirt-gconfig-os.h index 87027da..b789eb3 100644 --- a/libvirt-gconfig/libvirt-gconfig-os.h +++ b/libvirt-gconfig/libvirt-gconfig-os.h @@ -80,8 +80,10 @@ GVirConfigOs *gvir_config_os_new(void); GVirConfigOs *gvir_config_os_new_from_xml(const gchar *xml, GError **error); void gvir_config_os_set_os_type(GVirConfigOs *os, GVirConfigOsType type); +void gvir_config_os_set_arch(GVirConfigOs *os, const char *arch); void gvir_config_os_set_boot_devices(GVirConfigOs *os, GList *boot_devices); void gvir_config_os_set_loader(GVirConfigOs *os, const char * loader); +void gvir_config_os_set_machine(GVirConfigOs *os, const char *machine); void gvir_config_os_set_smbios_mode(GVirConfigOs *os, GVirConfigOsSmBiosMode mode); void gvir_config_os_enable_boot_menu(GVirConfigOs *os, gboolean enable); diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 3466129..20b0150 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -63,6 +63,8 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_os_set_smbios_mode; gvir_config_os_enable_boot_menu; gvir_config_os_bios_enable_serial; + gvir_config_os_set_machine; + gvir_config_os_set_arch; gvir_config_secret_get_type; gvir_config_secret_new; -- 1.7.7

It could be merged with previous patches. -- Marc-André Lureau

--- libvirt-gconfig/libvirt-gconfig-domain.c | 9 +++++++++ libvirt-gconfig/libvirt-gconfig-domain.h | 2 ++ libvirt-gconfig/libvirt-gconfig.h | 4 +++- libvirt-gconfig/libvirt-gconfig.sym | 1 + 4 files changed, 15 insertions(+), 1 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c index de60054..f88ae69 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.c +++ b/libvirt-gconfig/libvirt-gconfig-domain.c @@ -245,3 +245,12 @@ void gvir_config_domain_set_clock(GVirConfigDomain *domain, clock_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(klock)); gvir_config_object_set_child(GVIR_CONFIG_OBJECT(domain), clock_node); } + +void gvir_config_domain_set_os(GVirConfigDomain *domain, + GVirConfigOs *os) +{ + xmlNodePtr os_node; + + os_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(os)); + gvir_config_object_set_child(GVIR_CONFIG_OBJECT(domain), os_node); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain.h b/libvirt-gconfig/libvirt-gconfig-domain.h index 6f822cf..37effe4 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.h +++ b/libvirt-gconfig/libvirt-gconfig-domain.h @@ -71,6 +71,8 @@ void gvir_config_domain_set_features(GVirConfigDomain *domain, const GStrv features); void gvir_config_domain_set_clock(GVirConfigDomain *domain, GVirConfigClock *klock); +void gvir_config_domain_set_os(GVirConfigDomain *domain, + GVirConfigOs *os); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index 482c088..0f09d4f 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -29,7 +29,6 @@ #include <libvirt-gconfig/libvirt-gconfig-object.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities.h> #include <libvirt-gconfig/libvirt-gconfig-clock.h> -#include <libvirt-gconfig/libvirt-gconfig-domain.h> #include <libvirt-gconfig/libvirt-gconfig-domain-snapshot.h> #include <libvirt-gconfig/libvirt-gconfig-enum-types.h> #include <libvirt-gconfig/libvirt-gconfig-helpers.h> @@ -43,4 +42,7 @@ #include <libvirt-gconfig/libvirt-gconfig-storage-pool.h> #include <libvirt-gconfig/libvirt-gconfig-storage-vol.h> +/* Must come last since it uses types defined in the other headers */ +#include <libvirt-gconfig/libvirt-gconfig-domain.h> + #endif /* __LIBVIRT_GCONFIG_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 20b0150..486b509 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -16,6 +16,7 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_domain_new; gvir_config_domain_new_from_xml; gvir_config_domain_set_clock; + gvir_config_domain_set_os; gvir_config_domain_get_features; gvir_config_domain_set_features; gvir_config_domain_get_memory; -- 1.7.7

On Thu, Nov 10, 2011 at 9:33 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
+/* Must come last since it uses types defined in the other headers */ +#include <libvirt-gconfig/libvirt-gconfig-domain.h>
This is weird, can't libvirt-gconfig/libvirt-gconfig-domain.h include libvirt-gconfig/libvirt-gconfig-clock.h (and others) instead? -- Marc-André Lureau

On Fri, Nov 11, 2011 at 04:25:29PM +0100, Marc-André Lureau wrote:
On Thu, Nov 10, 2011 at 9:33 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
+/* Must come last since it uses types defined in the other headers */ +#include <libvirt-gconfig/libvirt-gconfig-domain.h>
This is weird, can't libvirt-gconfig/libvirt-gconfig-domain.h include libvirt-gconfig/libvirt-gconfig-clock.h (and others) instead?
These headers don't include anything, I wasn't sure this was done on purpose or not, I chose not to add new includes to these files. I'll do what you suggest the next time I get include ordering issues in this file, unless you want this "hack" gone now. Christophe

--- libvirt-gconfig/tests/test-domain-create.c | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-) diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index a5c5b99..8abca00 100644 --- a/libvirt-gconfig/tests/test-domain-create.c +++ b/libvirt-gconfig/tests/test-domain-create.c @@ -33,7 +33,6 @@ const char *features[] = { "foo", "bar", "baz", NULL }; int main(void) { GVirConfigDomain *domain; - GVirConfigClock *klock; char *name; GStrv feat; unsigned int i; @@ -60,10 +59,28 @@ int main(void) } g_strfreev(feat); + /* clock node */ + GVirConfigClock *klock; + klock = gvir_config_clock_new(); gvir_config_clock_set_offset(klock, GVIR_CONFIG_CLOCK_UTC); gvir_config_domain_set_clock(domain, klock); + /* os node */ + GVirConfigOs *os; + GList *devices = NULL; + + os = gvir_config_os_new(); + gvir_config_os_set_os_type(os, GVIR_CONFIG_OS_TYPE_HVM); + gvir_config_os_set_arch(os, "x86_64"); + devices = g_list_append(devices, + GINT_TO_POINTER(GVIR_CONFIG_OS_BOOT_DEVICE_CDROM)); + devices = g_list_append(devices, + GINT_TO_POINTER(GVIR_CONFIG_OS_BOOT_DEVICE_NETWORK)); + gvir_config_os_set_boot_devices(os, devices); + g_list_free(devices); + gvir_config_domain_set_os(domain, os); + xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(domain)); g_print("%s\n", xml); g_free(xml); -- 1.7.7

ack On Thu, Nov 10, 2011 at 9:33 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
--- libvirt-gconfig/tests/test-domain-create.c | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-)
diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index a5c5b99..8abca00 100644 --- a/libvirt-gconfig/tests/test-domain-create.c +++ b/libvirt-gconfig/tests/test-domain-create.c @@ -33,7 +33,6 @@ const char *features[] = { "foo", "bar", "baz", NULL }; int main(void) { GVirConfigDomain *domain; - GVirConfigClock *klock; char *name; GStrv feat; unsigned int i; @@ -60,10 +59,28 @@ int main(void) } g_strfreev(feat);
+ /* clock node */ + GVirConfigClock *klock; + klock = gvir_config_clock_new(); gvir_config_clock_set_offset(klock, GVIR_CONFIG_CLOCK_UTC); gvir_config_domain_set_clock(domain, klock);
+ /* os node */ + GVirConfigOs *os; + GList *devices = NULL; + + os = gvir_config_os_new(); + gvir_config_os_set_os_type(os, GVIR_CONFIG_OS_TYPE_HVM); + gvir_config_os_set_arch(os, "x86_64"); + devices = g_list_append(devices, + GINT_TO_POINTER(GVIR_CONFIG_OS_BOOT_DEVICE_CDROM)); + devices = g_list_append(devices, + GINT_TO_POINTER(GVIR_CONFIG_OS_BOOT_DEVICE_NETWORK)); + gvir_config_os_set_boot_devices(os, devices); + g_list_free(devices); + gvir_config_domain_set_os(domain, os); + xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(domain)); g_print("%s\n", xml); g_free(xml); -- 1.7.7
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
-- Marc-André Lureau

--- libvirt-gconfig/libvirt-gconfig-domain.c | 29 ++++++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-domain.h | 3 ++ libvirt-gconfig/libvirt-gconfig.sym | 2 + libvirt-gconfig/tests/test-domain-create.c | 1 + 4 files changed, 35 insertions(+), 0 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c index f88ae69..41390bd 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.c +++ b/libvirt-gconfig/libvirt-gconfig-domain.c @@ -46,6 +46,7 @@ enum { PROP_0, PROP_NAME, PROP_MEMORY, + PROP_VCPU, PROP_FEATURES }; @@ -63,6 +64,9 @@ static void gvir_config_domain_get_property(GObject *object, case PROP_MEMORY: g_value_set_uint64(value, gvir_config_domain_get_memory(domain)); break; + case PROP_VCPU: + g_value_set_uint64(value, gvir_config_domain_get_vcpus(domain)); + break; case PROP_FEATURES: g_value_take_boxed(value, gvir_config_domain_get_features(domain)); break; @@ -86,6 +90,9 @@ static void gvir_config_domain_set_property(GObject *object, case PROP_MEMORY: gvir_config_domain_set_memory(domain, g_value_get_uint64(value)); break; + case PROP_VCPU: + gvir_config_domain_set_vcpus(domain, g_value_get_uint64(value)); + break; case PROP_FEATURES: gvir_config_domain_set_features(domain, g_value_get_boxed(value)); break; @@ -122,6 +129,15 @@ static void gvir_config_domain_class_init(GVirConfigDomainClass *klass) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property(object_class, + PROP_VCPU, + g_param_spec_uint64("vcpu", + "Virtual CPUs", + "Maximum Number of Guest Virtual CPUs", + 0, G_MAXUINT64, + 1, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); + g_object_class_install_property(object_class, PROP_FEATURES, g_param_spec_boxed("features", "Features", @@ -192,6 +208,19 @@ void gvir_config_domain_set_memory(GVirConfigDomain *domain, guint64 memory) g_object_notify(G_OBJECT(domain), "memory"); } +guint64 gvir_config_domain_get_vcpus(GVirConfigDomain *domain) +{ + return gvir_config_object_get_node_content_uint64(GVIR_CONFIG_OBJECT(domain), + "vcpu"); +} + +void gvir_config_domain_set_vcpus(GVirConfigDomain *domain, guint64 vcpu_count) +{ + gvir_config_object_set_node_content_uint64(GVIR_CONFIG_OBJECT(domain), + "vcpu", vcpu_count); + g_object_notify(G_OBJECT(domain), "vcpu"); +} + /** * gvir_config_domain_get_features: * Returns: (transfer full): diff --git a/libvirt-gconfig/libvirt-gconfig-domain.h b/libvirt-gconfig/libvirt-gconfig-domain.h index 37effe4..3ca6228 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.h +++ b/libvirt-gconfig/libvirt-gconfig-domain.h @@ -66,6 +66,9 @@ char *gvir_config_domain_get_name(GVirConfigDomain *domain); void gvir_config_domain_set_name(GVirConfigDomain *domain, const char *name); guint64 gvir_config_domain_get_memory(GVirConfigDomain *domain); void gvir_config_domain_set_memory(GVirConfigDomain *domain, guint64 memory); +guint64 gvir_config_domain_get_vcpus(GVirConfigDomain *domain); +void gvir_config_domain_set_vcpus(GVirConfigDomain *domain, + guint64 vcpu_count); GStrv gvir_config_domain_get_features(GVirConfigDomain *domain); void gvir_config_domain_set_features(GVirConfigDomain *domain, const GStrv features); diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 486b509..7660070 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -23,6 +23,8 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_domain_set_memory; gvir_config_domain_get_name; gvir_config_domain_set_name; + gvir_config_domain_get_vcpus; + gvir_config_domain_set_vcpus; gvir_config_domain_snapshot_get_type; gvir_config_domain_snapshot_new; diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index 8abca00..af960a9 100644 --- a/libvirt-gconfig/tests/test-domain-create.c +++ b/libvirt-gconfig/tests/test-domain-create.c @@ -49,6 +49,7 @@ int main(void) g_free(name); gvir_config_domain_set_memory(domain, 1234); + gvir_config_domain_set_vcpus(domain, 3); g_assert(gvir_config_domain_get_memory(domain) == 1234); gvir_config_domain_set_features(domain, (const GStrv)features); -- 1.7.7

ack On Thu, Nov 10, 2011 at 9:33 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
--- libvirt-gconfig/libvirt-gconfig-domain.c | 29 ++++++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-domain.h | 3 ++ libvirt-gconfig/libvirt-gconfig.sym | 2 + libvirt-gconfig/tests/test-domain-create.c | 1 + 4 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c index f88ae69..41390bd 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.c +++ b/libvirt-gconfig/libvirt-gconfig-domain.c @@ -46,6 +46,7 @@ enum { PROP_0, PROP_NAME, PROP_MEMORY, + PROP_VCPU, PROP_FEATURES };
@@ -63,6 +64,9 @@ static void gvir_config_domain_get_property(GObject *object, case PROP_MEMORY: g_value_set_uint64(value, gvir_config_domain_get_memory(domain)); break; + case PROP_VCPU: + g_value_set_uint64(value, gvir_config_domain_get_vcpus(domain)); + break; case PROP_FEATURES: g_value_take_boxed(value, gvir_config_domain_get_features(domain)); break; @@ -86,6 +90,9 @@ static void gvir_config_domain_set_property(GObject *object, case PROP_MEMORY: gvir_config_domain_set_memory(domain, g_value_get_uint64(value)); break; + case PROP_VCPU: + gvir_config_domain_set_vcpus(domain, g_value_get_uint64(value)); + break; case PROP_FEATURES: gvir_config_domain_set_features(domain, g_value_get_boxed(value)); break; @@ -122,6 +129,15 @@ static void gvir_config_domain_class_init(GVirConfigDomainClass *klass) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property(object_class, + PROP_VCPU, + g_param_spec_uint64("vcpu", + "Virtual CPUs", + "Maximum Number of Guest Virtual CPUs", + 0, G_MAXUINT64, + 1, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); + g_object_class_install_property(object_class, PROP_FEATURES, g_param_spec_boxed("features", "Features", @@ -192,6 +208,19 @@ void gvir_config_domain_set_memory(GVirConfigDomain *domain, guint64 memory) g_object_notify(G_OBJECT(domain), "memory"); }
+guint64 gvir_config_domain_get_vcpus(GVirConfigDomain *domain) +{ + return gvir_config_object_get_node_content_uint64(GVIR_CONFIG_OBJECT(domain), + "vcpu"); +} + +void gvir_config_domain_set_vcpus(GVirConfigDomain *domain, guint64 vcpu_count) +{ + gvir_config_object_set_node_content_uint64(GVIR_CONFIG_OBJECT(domain), + "vcpu", vcpu_count); + g_object_notify(G_OBJECT(domain), "vcpu"); +} + /** * gvir_config_domain_get_features: * Returns: (transfer full): diff --git a/libvirt-gconfig/libvirt-gconfig-domain.h b/libvirt-gconfig/libvirt-gconfig-domain.h index 37effe4..3ca6228 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.h +++ b/libvirt-gconfig/libvirt-gconfig-domain.h @@ -66,6 +66,9 @@ char *gvir_config_domain_get_name(GVirConfigDomain *domain); void gvir_config_domain_set_name(GVirConfigDomain *domain, const char *name); guint64 gvir_config_domain_get_memory(GVirConfigDomain *domain); void gvir_config_domain_set_memory(GVirConfigDomain *domain, guint64 memory); +guint64 gvir_config_domain_get_vcpus(GVirConfigDomain *domain); +void gvir_config_domain_set_vcpus(GVirConfigDomain *domain, + guint64 vcpu_count); GStrv gvir_config_domain_get_features(GVirConfigDomain *domain); void gvir_config_domain_set_features(GVirConfigDomain *domain, const GStrv features); diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 486b509..7660070 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -23,6 +23,8 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_domain_set_memory; gvir_config_domain_get_name; gvir_config_domain_set_name; + gvir_config_domain_get_vcpus; + gvir_config_domain_set_vcpus;
gvir_config_domain_snapshot_get_type; gvir_config_domain_snapshot_new; diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index 8abca00..af960a9 100644 --- a/libvirt-gconfig/tests/test-domain-create.c +++ b/libvirt-gconfig/tests/test-domain-create.c @@ -49,6 +49,7 @@ int main(void) g_free(name);
gvir_config_domain_set_memory(domain, 1234); + gvir_config_domain_set_vcpus(domain, 3); g_assert(gvir_config_domain_get_memory(domain) == 1234);
gvir_config_domain_set_features(domain, (const GStrv)features); -- 1.7.7
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
-- Marc-André Lureau

This is an abstract type which will be used as a base class for all objects stored in the <devices> section of a domain. --- libvirt-gconfig/Makefile.am | 2 + libvirt-gconfig/libvirt-gconfig-device.c | 62 +++++++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-device.h | 64 ++++++++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 2 + 5 files changed, 131 insertions(+), 0 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-device.c create mode 100644 libvirt-gconfig/libvirt-gconfig-device.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 384d7a3..86a7065 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -12,6 +12,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-object.h \ libvirt-gconfig-capabilities.h \ libvirt-gconfig-clock.h \ + libvirt-gconfig-device.h \ libvirt-gconfig-domain.h \ libvirt-gconfig-domain-snapshot.h \ libvirt-gconfig-helpers.h \ @@ -30,6 +31,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-object.c \ libvirt-gconfig-capabilities.c \ libvirt-gconfig-clock.c \ + libvirt-gconfig-device.c \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-snapshot.c \ libvirt-gconfig-enum-types.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-device.c b/libvirt-gconfig/libvirt-gconfig-device.c new file mode 100644 index 0000000..6250e6d --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-device.c @@ -0,0 +1,62 @@ +/* + * libvirt-gobject-config-device.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@gmail.com> + */ + +#include <config.h> + +#include <string.h> + +#include <libxml/tree.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" + +extern gboolean debugFlag; + +#define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0) + +#define GVIR_CONFIG_DEVICE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_DEVICE, GVirConfigDevicePrivate)) + +struct _GVirConfigDevicePrivate +{ + gboolean unused; +}; + +G_DEFINE_ABSTRACT_TYPE(GVirConfigDevice, gvir_config_device, GVIR_TYPE_CONFIG_OBJECT); + + +static void gvir_config_device_class_init(GVirConfigDeviceClass *klass) +{ + + g_type_class_add_private(klass, sizeof(GVirConfigDevicePrivate)); +} + + +static void gvir_config_device_init(GVirConfigDevice *device) +{ + GVirConfigDevicePrivate *priv; + + DEBUG("Init GVirConfigDevice=%p", device); + + priv = device->priv = GVIR_CONFIG_DEVICE_GET_PRIVATE(device); + + memset(priv, 0, sizeof(*priv)); +} diff --git a/libvirt-gconfig/libvirt-gconfig-device.h b/libvirt-gconfig/libvirt-gconfig-device.h new file mode 100644 index 0000000..abd10c2 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-device.h @@ -0,0 +1,64 @@ +/* + * libvirt-gobject-device.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@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_H__ +#define __LIBVIRT_GCONFIG_DEVICE_H__ + +G_BEGIN_DECLS + +#define GVIR_TYPE_CONFIG_DEVICE (gvir_config_device_get_type ()) +#define GVIR_CONFIG_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_DEVICE, GVirConfigDevice)) +#define GVIR_CONFIG_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_DEVICE, GVirConfigDeviceClass)) +#define GVIR_IS_CONFIG_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_DEVICE)) +#define GVIR_IS_CONFIG_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_DEVICE)) +#define GVIR_CONFIG_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_DEVICE, GVirConfigDeviceClass)) + +typedef struct _GVirConfigDevice GVirConfigDevice; +typedef struct _GVirConfigDevicePrivate GVirConfigDevicePrivate; +typedef struct _GVirConfigDeviceClass GVirConfigDeviceClass; + +struct _GVirConfigDevice +{ + GVirConfigObject parent; + + GVirConfigDevicePrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigDeviceClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + + +GType gvir_config_device_get_type(void); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DEVICE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index 0f09d4f..e13dbdc 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -29,6 +29,7 @@ #include <libvirt-gconfig/libvirt-gconfig-object.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities.h> #include <libvirt-gconfig/libvirt-gconfig-clock.h> +#include <libvirt-gconfig/libvirt-gconfig-device.h> #include <libvirt-gconfig/libvirt-gconfig-domain-snapshot.h> #include <libvirt-gconfig/libvirt-gconfig-enum-types.h> #include <libvirt-gconfig/libvirt-gconfig-helpers.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 7660070..3aaca0b 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -12,6 +12,8 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_clock_set_timezone; gvir_config_clock_set_variable_offset; + gvir_config_device_get_type; + gvir_config_domain_get_type; gvir_config_domain_new; gvir_config_domain_new_from_xml; -- 1.7.7

ack -- Marc-André Lureau

--- libvirt-gconfig/Makefile.am | 2 + libvirt-gconfig/libvirt-gconfig-device-disk.c | 82 +++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-device-disk.h | 68 ++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 4 + 5 files changed, 157 insertions(+), 0 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-device-disk.c create mode 100644 libvirt-gconfig/libvirt-gconfig-device-disk.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 86a7065..82063df 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -13,6 +13,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-capabilities.h \ libvirt-gconfig-clock.h \ libvirt-gconfig-device.h \ + libvirt-gconfig-device-disk.h \ libvirt-gconfig-domain.h \ libvirt-gconfig-domain-snapshot.h \ libvirt-gconfig-helpers.h \ @@ -32,6 +33,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-capabilities.c \ libvirt-gconfig-clock.c \ libvirt-gconfig-device.c \ + libvirt-gconfig-device-disk.c \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-snapshot.c \ libvirt-gconfig-enum-types.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-device-disk.c b/libvirt-gconfig/libvirt-gconfig-device-disk.c new file mode 100644 index 0000000..ba2ef47 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-device-disk.c @@ -0,0 +1,82 @@ +/* + * libvirt-gobject-config-device-disk.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@gmail.com> + */ + +#include <config.h> + +#include <string.h> + +#include <libxml/tree.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" + +extern gboolean debugFlag; + +#define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0) + +#define GVIR_CONFIG_DEVICE_DISK_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_DEVICE_DISK, GVirConfigDeviceDiskPrivate)) + +struct _GVirConfigDeviceDiskPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigDeviceDisk, gvir_config_device_disk, GVIR_TYPE_CONFIG_DEVICE); + + +static void gvir_config_device_disk_class_init(GVirConfigDeviceDiskClass *klass) +{ + + g_type_class_add_private(klass, sizeof(GVirConfigDeviceDiskPrivate)); +} + + +static void gvir_config_device_disk_init(GVirConfigDeviceDisk *disk) +{ + GVirConfigDeviceDiskPrivate *priv; + + DEBUG("Init GVirConfigDeviceDisk=%p", disk); + + priv = disk->priv = GVIR_CONFIG_DEVICE_DISK_GET_PRIVATE(disk); + + memset(priv, 0, sizeof(*priv)); +} + + +GVirConfigDeviceDisk *gvir_config_device_disk_new(void) +{ + GVirConfigObject *object; + + object = gvir_config_object_new(GVIR_TYPE_CONFIG_DEVICE_DISK, + "disk", NULL); + return GVIR_CONFIG_DEVICE_DISK(object); +} + +GVirConfigDeviceDisk *gvir_config_device_disk_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_DEVICE_DISK, + "disk", NULL, xml, error); + return GVIR_CONFIG_DEVICE_DISK(object); +} diff --git a/libvirt-gconfig/libvirt-gconfig-device-disk.h b/libvirt-gconfig/libvirt-gconfig-device-disk.h new file mode 100644 index 0000000..4e9d622 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-device-disk.h @@ -0,0 +1,68 @@ +/* + * libvirt-gobject-device-disk.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@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_DISK_H__ +#define __LIBVIRT_GCONFIG_DEVICE_DISK_H__ + +G_BEGIN_DECLS + +#define GVIR_TYPE_CONFIG_DEVICE_DISK (gvir_config_device_disk_get_type ()) +#define GVIR_CONFIG_DEVICE_DISK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_DEVICE_DISK, GVirConfigDeviceDisk)) +#define GVIR_CONFIG_DEVICE_DISK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_DEVICE_DISK, GVirConfigDeviceDiskClass)) +#define GVIR_IS_CONFIG_DEVICE_DISK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_DEVICE_DISK)) +#define GVIR_IS_CONFIG_DEVICE_DISK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_DEVICE_DISK)) +#define GVIR_CONFIG_DEVICE_DISK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_DEVICE_DISK, GVirConfigDeviceDiskClass)) + +typedef struct _GVirConfigDeviceDisk GVirConfigDeviceDisk; +typedef struct _GVirConfigDeviceDiskPrivate GVirConfigDeviceDiskPrivate; +typedef struct _GVirConfigDeviceDiskClass GVirConfigDeviceDiskClass; + +struct _GVirConfigDeviceDisk +{ + GVirConfigObject parent; + + GVirConfigDeviceDiskPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigDeviceDiskClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + + +GType gvir_config_device_disk_get_type(void); + +GVirConfigDeviceDisk *gvir_config_device_disk_new(void); +GVirConfigDeviceDisk *gvir_config_device_disk_new_from_xml(const gchar *xml, + GError **error); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DEVICE_DISK_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index e13dbdc..01a1af3 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -30,6 +30,7 @@ #include <libvirt-gconfig/libvirt-gconfig-capabilities.h> #include <libvirt-gconfig/libvirt-gconfig-clock.h> #include <libvirt-gconfig/libvirt-gconfig-device.h> +#include <libvirt-gconfig/libvirt-gconfig-device-disk.h> #include <libvirt-gconfig/libvirt-gconfig-domain-snapshot.h> #include <libvirt-gconfig/libvirt-gconfig-enum-types.h> #include <libvirt-gconfig/libvirt-gconfig-helpers.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 3aaca0b..b19e1c1 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -14,6 +14,10 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_device_get_type; + gvir_config_device_disk_get_type; + gvir_config_device_disk_new; + gvir_config_device_disk_new_from_xml; + gvir_config_domain_get_type; gvir_config_domain_new; gvir_config_domain_new_from_xml; -- 1.7.7

+static void gvir_config_device_disk_class_init(GVirConfigDeviceDiskClass *klass) +{ + + g_type_class_add_private(klass, sizeof(GVirConfigDeviceDiskPrivate)); +}
There is an extra line here, in previous patch too. Is that intended? otherwise, ack. -- Marc-André Lureau

On Fri, Nov 11, 2011 at 04:40:56PM +0100, Marc-André Lureau wrote:
+static void gvir_config_device_disk_class_init(GVirConfigDeviceDiskClass *klass) +{ + + g_type_class_add_private(klass, sizeof(GVirConfigDeviceDiskPrivate)); +}
There is an extra line here, in previous patch too. Is that intended?
It's probably present in all the "gobject boilerplate commits" since it was present in the files I used as a c&p template. Let me see if I can fix this... Christophe

--- libvirt-gconfig/libvirt-gconfig-device-disk.c | 46 +++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-device-disk.h | 25 +++++++++++++ libvirt-gconfig/libvirt-gconfig.sym | 6 +++ 3 files changed, 77 insertions(+), 0 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-device-disk.c b/libvirt-gconfig/libvirt-gconfig-device-disk.c index ba2ef47..9981ae8 100644 --- a/libvirt-gconfig/libvirt-gconfig-device-disk.c +++ b/libvirt-gconfig/libvirt-gconfig-device-disk.c @@ -27,6 +27,7 @@ #include <libxml/tree.h> #include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-helpers-private.h" extern gboolean debugFlag; @@ -80,3 +81,48 @@ GVirConfigDeviceDisk *gvir_config_device_disk_new_from_xml(const gchar *xml, "disk", NULL, xml, error); return GVIR_CONFIG_DEVICE_DISK(object); } + +void gvir_config_device_disk_set_type(GVirConfigDeviceDisk *disk, + GVirConfigDeviceDiskType type) +{ + xmlNodePtr node; + const char *type_str; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(disk)); + if (node == NULL) + return; + type_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_DEVICE_DISK_TYPE, + type); + if (type_str != NULL) + xmlNewProp(node, (xmlChar*)"type", (xmlChar*)type_str); +} + +void gvir_config_device_disk_set_guest_device_type(GVirConfigDeviceDisk *disk, + GVirConfigDeviceDiskGuestDeviceType type) +{ + xmlNodePtr node; + const char *type_str; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(disk)); + if (node == NULL) + return; + type_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_DEVICE_DISK_GUEST_DEVICE_TYPE, + type); + if (type_str != NULL) + xmlNewProp(node, (xmlChar*)"device", (xmlChar*)type_str); +} + +void gvir_config_device_disk_set_snapshot_type(GVirConfigDeviceDisk *disk, + GVirConfigDeviceDiskSnapshotType type) +{ + xmlNodePtr node; + const char *type_str; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(disk)); + if (node == NULL) + return; + type_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_DEVICE_DISK_SNAPSHOT_TYPE, + type); + if (type_str != NULL) + xmlNewProp(node, (xmlChar*)"snapshot", (xmlChar*)type_str); +} diff --git a/libvirt-gconfig/libvirt-gconfig-device-disk.h b/libvirt-gconfig/libvirt-gconfig-device-disk.h index 4e9d622..2850672 100644 --- a/libvirt-gconfig/libvirt-gconfig-device-disk.h +++ b/libvirt-gconfig/libvirt-gconfig-device-disk.h @@ -56,6 +56,24 @@ struct _GVirConfigDeviceDiskClass gpointer padding[20]; }; +typedef enum { + GVIR_CONFIG_DEVICE_DISK_FILE, + GVIR_CONFIG_DEVICE_DISK_BLOCK, + GVIR_CONFIG_DEVICE_DISK_DIR, + GVIR_CONFIG_DEVICE_DISK_NETWORK +} GVirConfigDeviceDiskType; + +typedef enum { + GVIR_CONFIG_DEVICE_DISK_GUEST_DEVICE_DISK, + GVIR_CONFIG_DEVICE_DISK_GUEST_DEVICE_FLOPPY, + GVIR_CONFIG_DEVICE_DISK_GUEST_DEVICE_CDROM +} GVirConfigDeviceDiskGuestDeviceType; + +typedef enum { + GVIR_CONFIG_DEVICE_DISK_SNAPSHOT_NO, + GVIR_CONFIG_DEVICE_DISK_SNAPSHOT_INTERNAL, + GVIR_CONFIG_DEVICE_DISK_SNAPSHOT_EXTERNAL +} GVirConfigDeviceDiskSnapshotType; GType gvir_config_device_disk_get_type(void); @@ -63,6 +81,13 @@ GVirConfigDeviceDisk *gvir_config_device_disk_new(void); GVirConfigDeviceDisk *gvir_config_device_disk_new_from_xml(const gchar *xml, GError **error); +void gvir_config_device_disk_set_type(GVirConfigDeviceDisk *disk, + GVirConfigDeviceDiskType type); +void gvir_config_device_disk_set_guest_device_type(GVirConfigDeviceDisk *disk, + GVirConfigDeviceDiskGuestDeviceType type); +void gvir_config_device_disk_set_snapshot_type(GVirConfigDeviceDisk *disk, + GVirConfigDeviceDiskSnapshotType type); + G_END_DECLS #endif /* __LIBVIRT_GCONFIG_DEVICE_DISK_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index b19e1c1..76ffc4c 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -15,8 +15,14 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_device_get_type; gvir_config_device_disk_get_type; + gvir_config_device_disk_guest_device_type_get_type; + gvir_config_device_disk_snapshot_type_get_type; + gvir_config_device_disk_type_get_type; gvir_config_device_disk_new; gvir_config_device_disk_new_from_xml; + gvir_config_device_disk_set_snapshot_type; + gvir_config_device_disk_set_guest_device_type; + gvir_config_device_disk_set_type; gvir_config_domain_get_type; gvir_config_domain_new; -- 1.7.7

Add an "overwrite" boolean argument to indicate what to do when the child we are about to create already exists. --- libvirt-gconfig/libvirt-gconfig-clock.c | 3 +- libvirt-gconfig/libvirt-gconfig-domain.c | 2 +- libvirt-gconfig/libvirt-gconfig-object.c | 39 +++++++++++++++++++++++------ libvirt-gconfig/libvirt-gconfig-object.h | 3 +- libvirt-gconfig/libvirt-gconfig-os.c | 11 +++++--- 5 files changed, 43 insertions(+), 15 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-clock.c b/libvirt-gconfig/libvirt-gconfig-clock.c index 3deb725..7cf35bb 100644 --- a/libvirt-gconfig/libvirt-gconfig-clock.c +++ b/libvirt-gconfig/libvirt-gconfig-clock.c @@ -119,7 +119,8 @@ void gvir_config_clock_set_variable_offset(GVirConfigClock *klock, xmlNodePtr node; char *offset_str; - node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(klock), "clock"); + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(klock), + "clock", TRUE); if (node == NULL) return; diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c index 41390bd..88b46fb 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.c +++ b/libvirt-gconfig/libvirt-gconfig-domain.c @@ -256,7 +256,7 @@ void gvir_config_domain_set_features(GVirConfigDomain *domain, GStrv it; features_node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(domain), - "features"); + "features", TRUE); for (it = features; *it != NULL; it++) { xmlNodePtr node; diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c index 598ac0c..fd7d2d8 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.c +++ b/libvirt-gconfig/libvirt-gconfig-object.c @@ -294,34 +294,57 @@ char *gvir_config_object_get_node_content(GVirConfigObject *object, return gvir_config_xml_get_child_element_content_glib(node, node_name); } -void -gvir_config_object_set_child(GVirConfigObject *object, xmlNodePtr child) +static xmlNodePtr +gvir_config_object_set_child_internal(GVirConfigObject *object, + xmlNodePtr child, + gboolean overwrite) { xmlNodePtr parent_node; xmlNodePtr old_node; parent_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(object)); - g_return_if_fail (parent_node != NULL); + g_return_val_if_fail (parent_node != NULL, NULL); old_node = gvir_config_xml_get_element(parent_node, child->name, NULL); /* FIXME: should we make sure there are no multiple occurrences * of this node? */ if (old_node) { - old_node = xmlReplaceNode(old_node, child); - xmlFreeNode(old_node); + if (overwrite) { + old_node = xmlReplaceNode(old_node, child); + xmlFreeNode(old_node); + } else { + return old_node; + } } else { xmlAddChild(parent_node, child); } + + return NULL; +} + +void +gvir_config_object_set_child(GVirConfigObject *object, xmlNodePtr child) +{ + gvir_config_object_set_child_internal(object, child, TRUE); } xmlNodePtr -gvir_config_object_new_child(GVirConfigObject *object, const char *child_name) +gvir_config_object_new_child(GVirConfigObject *object, + const char *child_name, + gboolean overwrite) { xmlNodePtr new_node; + xmlNodePtr old_node; new_node = xmlNewDocNode(NULL, NULL, (xmlChar *)child_name, NULL); - gvir_config_object_set_child(object, new_node); + old_node = gvir_config_object_set_child_internal(object, new_node, + overwrite); + if ((old_node != NULL) && !overwrite) { + xmlFreeNode(new_node); + return old_node; + } + return new_node; } @@ -332,7 +355,7 @@ void gvir_config_object_set_node_content(GVirConfigObject *object, xmlNodePtr node; xmlChar *encoded_data; - node = gvir_config_object_new_child(object, node_name); + node = gvir_config_object_new_child(object, node_name, TRUE); g_return_if_fail(node != NULL); encoded_data = xmlEncodeEntitiesReentrant(node->doc, (xmlChar *)value); diff --git a/libvirt-gconfig/libvirt-gconfig-object.h b/libvirt-gconfig/libvirt-gconfig-object.h index 8e67b92..096cefb 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.h +++ b/libvirt-gconfig/libvirt-gconfig-object.h @@ -79,7 +79,8 @@ char *gvir_config_object_get_node_content(GVirConfigObject *object, guint64 gvir_config_object_get_node_content_uint64(GVirConfigObject *object, const char *node_name); xmlNodePtr gvir_config_object_new_child(GVirConfigObject *object, - const char *child_name); + const char *child_name, + gboolean overwrite); void gvir_config_object_set_child(GVirConfigObject *object, xmlNodePtr child); void gvir_config_object_set_node_content(GVirConfigObject *object, diff --git a/libvirt-gconfig/libvirt-gconfig-os.c b/libvirt-gconfig/libvirt-gconfig-os.c index 3e23493..394bef5 100644 --- a/libvirt-gconfig/libvirt-gconfig-os.c +++ b/libvirt-gconfig/libvirt-gconfig-os.c @@ -85,7 +85,7 @@ void gvir_config_os_set_os_type(GVirConfigOs *os, GVirConfigOsType type) xmlNodePtr node; const char *type_str; - node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(os), "type"); + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(os), "type", TRUE); if (node == NULL) return; type_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_OS_TYPE, type); @@ -103,7 +103,8 @@ void gvir_config_os_enable_boot_menu(GVirConfigOs *os, gboolean enable) { xmlNodePtr node; - node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(os), "bootmenu"); + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(os), + "bootmenu", TRUE); if (node == NULL) return; if (enable) @@ -116,7 +117,8 @@ void gvir_config_os_bios_enable_serial(GVirConfigOs *os, gboolean enable) { xmlNodePtr node; - node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(os), "bios"); + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(os), + "bios", TRUE); if (node == NULL) return; if (enable) @@ -131,7 +133,8 @@ void gvir_config_os_set_smbios_mode(GVirConfigOs *os, xmlNodePtr node; const char *mode_str; - node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(os), "smbios"); + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(os), + "smbios", TRUE); if (node == NULL) return; mode_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_OS_SM_BIOS_MODE, -- 1.7.7

Having gvir_config_object_add_child() and gvir_config_object_replace_child() would be more obvious (even the internal code should be splitted) On Thu, Nov 10, 2011 at 9:33 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
Add an "overwrite" boolean argument to indicate what to do when the child we are about to create already exists. --- libvirt-gconfig/libvirt-gconfig-clock.c | 3 +- libvirt-gconfig/libvirt-gconfig-domain.c | 2 +- libvirt-gconfig/libvirt-gconfig-object.c | 39 +++++++++++++++++++++++------ libvirt-gconfig/libvirt-gconfig-object.h | 3 +- libvirt-gconfig/libvirt-gconfig-os.c | 11 +++++--- 5 files changed, 43 insertions(+), 15 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-clock.c b/libvirt-gconfig/libvirt-gconfig-clock.c index 3deb725..7cf35bb 100644 --- a/libvirt-gconfig/libvirt-gconfig-clock.c +++ b/libvirt-gconfig/libvirt-gconfig-clock.c @@ -119,7 +119,8 @@ void gvir_config_clock_set_variable_offset(GVirConfigClock *klock, xmlNodePtr node; char *offset_str;
- node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(klock), "clock"); + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(klock), + "clock", TRUE); if (node == NULL) return;
diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c index 41390bd..88b46fb 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.c +++ b/libvirt-gconfig/libvirt-gconfig-domain.c @@ -256,7 +256,7 @@ void gvir_config_domain_set_features(GVirConfigDomain *domain, GStrv it;
features_node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(domain), - "features"); + "features", TRUE); for (it = features; *it != NULL; it++) { xmlNodePtr node;
diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c index 598ac0c..fd7d2d8 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.c +++ b/libvirt-gconfig/libvirt-gconfig-object.c @@ -294,34 +294,57 @@ char *gvir_config_object_get_node_content(GVirConfigObject *object, return gvir_config_xml_get_child_element_content_glib(node, node_name); }
-void -gvir_config_object_set_child(GVirConfigObject *object, xmlNodePtr child) +static xmlNodePtr +gvir_config_object_set_child_internal(GVirConfigObject *object, + xmlNodePtr child, + gboolean overwrite) { xmlNodePtr parent_node; xmlNodePtr old_node;
parent_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(object)); - g_return_if_fail (parent_node != NULL); + g_return_val_if_fail (parent_node != NULL, NULL);
old_node = gvir_config_xml_get_element(parent_node, child->name, NULL); /* FIXME: should we make sure there are no multiple occurrences * of this node? */ if (old_node) { - old_node = xmlReplaceNode(old_node, child); - xmlFreeNode(old_node); + if (overwrite) { + old_node = xmlReplaceNode(old_node, child); + xmlFreeNode(old_node); + } else { + return old_node; + } } else { xmlAddChild(parent_node, child); } + + return NULL; +} + +void +gvir_config_object_set_child(GVirConfigObject *object, xmlNodePtr child) +{ + gvir_config_object_set_child_internal(object, child, TRUE); }
xmlNodePtr -gvir_config_object_new_child(GVirConfigObject *object, const char *child_name) +gvir_config_object_new_child(GVirConfigObject *object, + const char *child_name, + gboolean overwrite) { xmlNodePtr new_node; + xmlNodePtr old_node;
new_node = xmlNewDocNode(NULL, NULL, (xmlChar *)child_name, NULL); - gvir_config_object_set_child(object, new_node); + old_node = gvir_config_object_set_child_internal(object, new_node, + overwrite); + if ((old_node != NULL) && !overwrite) { + xmlFreeNode(new_node); + return old_node; + } + return new_node; }
@@ -332,7 +355,7 @@ void gvir_config_object_set_node_content(GVirConfigObject *object, xmlNodePtr node; xmlChar *encoded_data;
- node = gvir_config_object_new_child(object, node_name); + node = gvir_config_object_new_child(object, node_name, TRUE); g_return_if_fail(node != NULL); encoded_data = xmlEncodeEntitiesReentrant(node->doc, (xmlChar *)value); diff --git a/libvirt-gconfig/libvirt-gconfig-object.h b/libvirt-gconfig/libvirt-gconfig-object.h index 8e67b92..096cefb 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.h +++ b/libvirt-gconfig/libvirt-gconfig-object.h @@ -79,7 +79,8 @@ char *gvir_config_object_get_node_content(GVirConfigObject *object, guint64 gvir_config_object_get_node_content_uint64(GVirConfigObject *object, const char *node_name); xmlNodePtr gvir_config_object_new_child(GVirConfigObject *object, - const char *child_name); + const char *child_name, + gboolean overwrite); void gvir_config_object_set_child(GVirConfigObject *object, xmlNodePtr child); void gvir_config_object_set_node_content(GVirConfigObject *object, diff --git a/libvirt-gconfig/libvirt-gconfig-os.c b/libvirt-gconfig/libvirt-gconfig-os.c index 3e23493..394bef5 100644 --- a/libvirt-gconfig/libvirt-gconfig-os.c +++ b/libvirt-gconfig/libvirt-gconfig-os.c @@ -85,7 +85,7 @@ void gvir_config_os_set_os_type(GVirConfigOs *os, GVirConfigOsType type) xmlNodePtr node; const char *type_str;
- node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(os), "type"); + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(os), "type", TRUE); if (node == NULL) return; type_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_OS_TYPE, type); @@ -103,7 +103,8 @@ void gvir_config_os_enable_boot_menu(GVirConfigOs *os, gboolean enable) { xmlNodePtr node;
- node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(os), "bootmenu"); + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(os), + "bootmenu", TRUE); if (node == NULL) return; if (enable) @@ -116,7 +117,8 @@ void gvir_config_os_bios_enable_serial(GVirConfigOs *os, gboolean enable) { xmlNodePtr node;
- node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(os), "bios"); + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(os), + "bios", TRUE); if (node == NULL) return; if (enable) @@ -131,7 +133,8 @@ void gvir_config_os_set_smbios_mode(GVirConfigOs *os, xmlNodePtr node; const char *mode_str;
- node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(os), "smbios"); + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(os), + "smbios", TRUE); if (node == NULL) return; mode_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_OS_SM_BIOS_MODE, -- 1.7.7
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
-- Marc-André Lureau

On Fri, Nov 11, 2011 at 04:52:11PM +0100, Marc-André Lureau wrote:
Having gvir_config_object_add_child() and gvir_config_object_replace_child() would be more obvious (even the internal code should be splitted)
Thanks for the naming suggestions :) I'm not fully satisfied with how most of the helpers are named, so don't hesitate to suggest better names. One thing that is missing from the _replace_node name is that it's not obvious that this will create a new node if needed. But I made this change anyway, thanks! Christophe

--- libvirt-gconfig/libvirt-gconfig-domain.c | 21 +++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-domain.h | 2 ++ libvirt-gconfig/libvirt-gconfig.sym | 3 ++- 3 files changed, 25 insertions(+), 1 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c index 88b46fb..8f6c50f 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.c +++ b/libvirt-gconfig/libvirt-gconfig-domain.c @@ -283,3 +283,24 @@ void gvir_config_domain_set_os(GVirConfigDomain *domain, os_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(os)); gvir_config_object_set_child(GVIR_CONFIG_OBJECT(domain), os_node); } + +/** + * gvir_config_domain_set_devices: + * @devices: (in) (element-type LibvirtGConfig.Device): + */ +void gvir_config_domain_set_devices(GVirConfigDomain *domain, + GList *devices) +{ + xmlNodePtr devices_node; + GList *it; + + devices_node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(domain), + "devices", TRUE); + for (it = devices; it != NULL; it = it->next) { + GVirConfigDevice *device = GVIR_CONFIG_DEVICE(it->data); + xmlNodePtr node; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(device)); + xmlAddChild(devices_node, node); + } +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain.h b/libvirt-gconfig/libvirt-gconfig-domain.h index 3ca6228..da798e8 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.h +++ b/libvirt-gconfig/libvirt-gconfig-domain.h @@ -76,6 +76,8 @@ void gvir_config_domain_set_clock(GVirConfigDomain *domain, GVirConfigClock *klock); void gvir_config_domain_set_os(GVirConfigDomain *domain, GVirConfigOs *os); +void gvir_config_domain_set_devices(GVirConfigDomain *domain, + GList *devices); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 76ffc4c..963ca53 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -28,13 +28,14 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_domain_new; gvir_config_domain_new_from_xml; gvir_config_domain_set_clock; - gvir_config_domain_set_os; + gvir_config_domain_set_devices; gvir_config_domain_get_features; gvir_config_domain_set_features; gvir_config_domain_get_memory; gvir_config_domain_set_memory; gvir_config_domain_get_name; gvir_config_domain_set_name; + gvir_config_domain_set_os; gvir_config_domain_get_vcpus; gvir_config_domain_set_vcpus; -- 1.7.7

ack -- Marc-André Lureau

--- libvirt-gconfig/libvirt-gconfig-device-disk.c | 88 ++++++++++++++++++++++++- libvirt-gconfig/libvirt-gconfig-device-disk.h | 10 +++ libvirt-gconfig/libvirt-gconfig.sym | 7 ++- 3 files changed, 102 insertions(+), 3 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-device-disk.c b/libvirt-gconfig/libvirt-gconfig-device-disk.c index 9981ae8..29de68b 100644 --- a/libvirt-gconfig/libvirt-gconfig-device-disk.c +++ b/libvirt-gconfig/libvirt-gconfig-device-disk.c @@ -38,7 +38,7 @@ extern gboolean debugFlag; struct _GVirConfigDeviceDiskPrivate { - gboolean unused; + GVirConfigDeviceDiskType type; }; G_DEFINE_TYPE(GVirConfigDeviceDisk, gvir_config_device_disk, GVIR_TYPE_CONFIG_DEVICE); @@ -93,8 +93,10 @@ void gvir_config_device_disk_set_type(GVirConfigDeviceDisk *disk, return; type_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_DEVICE_DISK_TYPE, type); - if (type_str != NULL) + if (type_str != NULL) { xmlNewProp(node, (xmlChar*)"type", (xmlChar*)type_str); + disk->priv->type = type; + } } void gvir_config_device_disk_set_guest_device_type(GVirConfigDeviceDisk *disk, @@ -126,3 +128,85 @@ void gvir_config_device_disk_set_snapshot_type(GVirConfigDeviceDisk *disk, if (type_str != NULL) xmlNewProp(node, (xmlChar*)"snapshot", (xmlChar*)type_str); } + +void gvir_config_device_disk_set_source(GVirConfigDeviceDisk *disk, + const char *source) +{ + xmlNodePtr source_node; + const char *attribute_name; + + if (disk->priv->type == GVIR_CONFIG_DEVICE_DISK_DIR) { + /* I don't know what attribute name to use for 'dir' */ + g_warning("set_source not implemented for 'dir' disk nodes"); + return; + } + + source_node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(disk), + "source", TRUE); + if (source_node == NULL) + return; + + switch (disk->priv->type) { + case GVIR_CONFIG_DEVICE_DISK_FILE: + attribute_name = "file"; + break; + case GVIR_CONFIG_DEVICE_DISK_BLOCK: + attribute_name = "block"; + break; + case GVIR_CONFIG_DEVICE_DISK_NETWORK: + attribute_name = "protocol"; + break; + default: + g_return_if_reached(); + } + xmlNewProp(source_node, (xmlChar*)attribute_name, (xmlChar*)source); +} + +void gvir_config_device_disk_set_driver_name(GVirConfigDeviceDisk *disk, + const char *driver_name) +{ + xmlNodePtr node; + + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(disk), + "driver", FALSE); + if (node == NULL) + return; + xmlNewProp(node, (xmlChar*)"name", (xmlChar*)driver_name); + +} + +void gvir_config_device_disk_set_driver_type(GVirConfigDeviceDisk *disk, + const char *driver_type) +{ + xmlNodePtr node; + + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(disk), + "driver", FALSE); + if (node == NULL) + return; + xmlNewProp(node, (xmlChar*)"type", (xmlChar*)driver_type); +} + +void gvir_config_device_disk_set_target_bus(GVirConfigDeviceDisk *disk, + const char *bus) +{ + xmlNodePtr node; + + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(disk), + "target", FALSE); + if (node == NULL) + return; + xmlNewProp(node, (xmlChar*)"bus", (xmlChar*)bus); +} + +void gvir_config_device_disk_set_target_dev(GVirConfigDeviceDisk *disk, + const char *dev) +{ + xmlNodePtr node; + + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(disk), + "target", FALSE); + if (node == NULL) + return; + xmlNewProp(node, (xmlChar*)"dev", (xmlChar*)dev); +} diff --git a/libvirt-gconfig/libvirt-gconfig-device-disk.h b/libvirt-gconfig/libvirt-gconfig-device-disk.h index 2850672..3e25e9f 100644 --- a/libvirt-gconfig/libvirt-gconfig-device-disk.h +++ b/libvirt-gconfig/libvirt-gconfig-device-disk.h @@ -87,6 +87,16 @@ void gvir_config_device_disk_set_guest_device_type(GVirConfigDeviceDisk *disk, GVirConfigDeviceDiskGuestDeviceType type); void gvir_config_device_disk_set_snapshot_type(GVirConfigDeviceDisk *disk, GVirConfigDeviceDiskSnapshotType type); +void gvir_config_device_disk_set_source(GVirConfigDeviceDisk *disk, + const char *source); +void gvir_config_device_disk_set_driver_name(GVirConfigDeviceDisk *disk, + const char *driver_name); +void gvir_config_device_disk_set_driver_type(GVirConfigDeviceDisk *disk, + const char *driver_type); +void gvir_config_device_disk_set_target_bus(GVirConfigDeviceDisk *disk, + const char *bus); +void gvir_config_device_disk_set_target_dev(GVirConfigDeviceDisk *disk, + const char *dev); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 963ca53..cb0d035 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -20,8 +20,13 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_device_disk_type_get_type; gvir_config_device_disk_new; gvir_config_device_disk_new_from_xml; - gvir_config_device_disk_set_snapshot_type; + gvir_config_device_disk_set_driver_name; + gvir_config_device_disk_set_driver_type; gvir_config_device_disk_set_guest_device_type; + gvir_config_device_disk_set_snapshot_type; + gvir_config_device_disk_set_source; + gvir_config_device_disk_set_target_bus; + gvir_config_device_disk_set_target_dev; gvir_config_device_disk_set_type; gvir_config_domain_get_type; -- 1.7.7

On Thu, Nov 10, 2011 at 9:33 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
--- libvirt-gconfig/libvirt-gconfig-device-disk.c | 88 ++++++++++++++++++++++++- libvirt-gconfig/libvirt-gconfig-device-disk.h | 10 +++ libvirt-gconfig/libvirt-gconfig.sym | 7 ++- 3 files changed, 102 insertions(+), 3 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-device-disk.c b/libvirt-gconfig/libvirt-gconfig-device-disk.c index 9981ae8..29de68b 100644 --- a/libvirt-gconfig/libvirt-gconfig-device-disk.c +++ b/libvirt-gconfig/libvirt-gconfig-device-disk.c @@ -38,7 +38,7 @@ extern gboolean debugFlag;
struct _GVirConfigDeviceDiskPrivate { - gboolean unused; + GVirConfigDeviceDiskType type; };
G_DEFINE_TYPE(GVirConfigDeviceDisk, gvir_config_device_disk, GVIR_TYPE_CONFIG_DEVICE); @@ -93,8 +93,10 @@ void gvir_config_device_disk_set_type(GVirConfigDeviceDisk *disk, return; type_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_DEVICE_DISK_TYPE, type); - if (type_str != NULL) + if (type_str != NULL) { xmlNewProp(node, (xmlChar*)"type", (xmlChar*)type_str); + disk->priv->type = type; + } }
void gvir_config_device_disk_set_guest_device_type(GVirConfigDeviceDisk *disk, @@ -126,3 +128,85 @@ void gvir_config_device_disk_set_snapshot_type(GVirConfigDeviceDisk *disk, if (type_str != NULL) xmlNewProp(node, (xmlChar*)"snapshot", (xmlChar*)type_str); } + +void gvir_config_device_disk_set_source(GVirConfigDeviceDisk *disk, + const char *source) +{ + xmlNodePtr source_node; + const char *attribute_name; + + if (disk->priv->type == GVIR_CONFIG_DEVICE_DISK_DIR) { + /* I don't know what attribute name to use for 'dir' */ + g_warning("set_source not implemented for 'dir' disk nodes"); + return; + } + + source_node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(disk), + "source", TRUE); + if (source_node == NULL) + return; + + switch (disk->priv->type) { + case GVIR_CONFIG_DEVICE_DISK_FILE: + attribute_name = "file"; + break; + case GVIR_CONFIG_DEVICE_DISK_BLOCK: + attribute_name = "block"; + break; + case GVIR_CONFIG_DEVICE_DISK_NETWORK: + attribute_name = "protocol"; + break; + default: + g_return_if_reached(); + }
hmm, if I read domain_conf.c correctly, FILE -> "file" BLOCK -> "dev" DIR -> "dir" NETWORK -> "protocol"
+ xmlNewProp(source_node, (xmlChar*)attribute_name, (xmlChar*)source); +} + +void gvir_config_device_disk_set_driver_name(GVirConfigDeviceDisk *disk, + const char *driver_name) +{ + xmlNodePtr node; + + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(disk), + "driver", FALSE); + if (node == NULL) + return; + xmlNewProp(node, (xmlChar*)"name", (xmlChar*)driver_name); + +} + +void gvir_config_device_disk_set_driver_type(GVirConfigDeviceDisk *disk, + const char *driver_type) +{ + xmlNodePtr node; + + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(disk), + "driver", FALSE); + if (node == NULL) + return; + xmlNewProp(node, (xmlChar*)"type", (xmlChar*)driver_type); +} + +void gvir_config_device_disk_set_target_bus(GVirConfigDeviceDisk *disk, + const char *bus) +{ + xmlNodePtr node; + + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(disk), + "target", FALSE); + if (node == NULL) + return; + xmlNewProp(node, (xmlChar*)"bus", (xmlChar*)bus); +} + +void gvir_config_device_disk_set_target_dev(GVirConfigDeviceDisk *disk, + const char *dev) +{ + xmlNodePtr node; + + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(disk), + "target", FALSE); + if (node == NULL) + return; + xmlNewProp(node, (xmlChar*)"dev", (xmlChar*)dev); +} diff --git a/libvirt-gconfig/libvirt-gconfig-device-disk.h b/libvirt-gconfig/libvirt-gconfig-device-disk.h index 2850672..3e25e9f 100644 --- a/libvirt-gconfig/libvirt-gconfig-device-disk.h +++ b/libvirt-gconfig/libvirt-gconfig-device-disk.h @@ -87,6 +87,16 @@ void gvir_config_device_disk_set_guest_device_type(GVirConfigDeviceDisk *disk, GVirConfigDeviceDiskGuestDeviceType type); void gvir_config_device_disk_set_snapshot_type(GVirConfigDeviceDisk *disk, GVirConfigDeviceDiskSnapshotType type); +void gvir_config_device_disk_set_source(GVirConfigDeviceDisk *disk, + const char *source); +void gvir_config_device_disk_set_driver_name(GVirConfigDeviceDisk *disk, + const char *driver_name); +void gvir_config_device_disk_set_driver_type(GVirConfigDeviceDisk *disk, + const char *driver_type); +void gvir_config_device_disk_set_target_bus(GVirConfigDeviceDisk *disk, + const char *bus); +void gvir_config_device_disk_set_target_dev(GVirConfigDeviceDisk *disk, + const char *dev);
G_END_DECLS
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 963ca53..cb0d035 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -20,8 +20,13 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_device_disk_type_get_type; gvir_config_device_disk_new; gvir_config_device_disk_new_from_xml; - gvir_config_device_disk_set_snapshot_type; + gvir_config_device_disk_set_driver_name; + gvir_config_device_disk_set_driver_type; gvir_config_device_disk_set_guest_device_type; + gvir_config_device_disk_set_snapshot_type; + gvir_config_device_disk_set_source; + gvir_config_device_disk_set_target_bus; + gvir_config_device_disk_set_target_dev; gvir_config_device_disk_set_type;
gvir_config_domain_get_type; -- 1.7.7
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
-- Marc-André Lureau

On Fri, Nov 11, 2011 at 06:43:10PM +0100, Marc-André Lureau wrote:
+ +void gvir_config_device_disk_set_source(GVirConfigDeviceDisk *disk, + const char *source) +{ + xmlNodePtr source_node; + const char *attribute_name; + + if (disk->priv->type == GVIR_CONFIG_DEVICE_DISK_DIR) { + /* I don't know what attribute name to use for 'dir' */ + g_warning("set_source not implemented for 'dir' disk nodes"); + return; + } + + source_node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(disk), + "source", TRUE); + if (source_node == NULL) + return; + + switch (disk->priv->type) { + case GVIR_CONFIG_DEVICE_DISK_FILE: + attribute_name = "file"; + break; + case GVIR_CONFIG_DEVICE_DISK_BLOCK: + attribute_name = "block"; + break; + case GVIR_CONFIG_DEVICE_DISK_NETWORK: + attribute_name = "protocol"; + break; + default: + g_return_if_reached(); + }
hmm, if I read domain_conf.c correctly,
FILE -> "file" BLOCK -> "dev" DIR -> "dir" NETWORK -> "protocol"
Ah thanks, the doc confirms I made a typo, and I can now handle the "dir" type. I'll send a patch to add it to libvirt documentation. Christophe

--- libvirt-gconfig/tests/test-domain-create.c | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-) diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index af960a9..db22eb5 100644 --- a/libvirt-gconfig/tests/test-domain-create.c +++ b/libvirt-gconfig/tests/test-domain-create.c @@ -80,8 +80,27 @@ int main(void) GINT_TO_POINTER(GVIR_CONFIG_OS_BOOT_DEVICE_NETWORK)); gvir_config_os_set_boot_devices(os, devices); g_list_free(devices); + devices = NULL; gvir_config_domain_set_os(domain, os); + /* device node */ + GVirConfigDeviceDisk *disk; + + disk = gvir_config_device_disk_new(); + gvir_config_device_disk_set_type(disk, GVIR_CONFIG_DEVICE_DISK_FILE); + gvir_config_device_disk_set_guest_device_type(disk, GVIR_CONFIG_DEVICE_DISK_GUEST_DEVICE_DISK); + gvir_config_device_disk_set_source(disk, "/tmp/foo/bar"); + gvir_config_device_disk_set_driver_name(disk, "qemu"); + gvir_config_device_disk_set_driver_type(disk, "qcow2"); + gvir_config_device_disk_set_target_bus(disk, "ide"); + gvir_config_device_disk_set_target_dev(disk, "hda"); + + devices = g_list_append(devices, disk); + gvir_config_domain_set_devices(domain, devices); + g_list_free(devices); + devices = NULL; + + xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(domain)); g_print("%s\n", xml); g_free(xml); -- 1.7.7

On Thu, Nov 10, 2011 at 9:33 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
devices = g_list_append(devices, disk); + gvir_config_domain_set_devices(domain, devices); + g_list_free(devices); + devices = NULL;
Hmm, I realize this is a bit more tricky. You give up devices element owner ship but no the container.. I think this is bad, as the list contains invalid objects after leaving the functions. Insead, the set_devices () function should ref the element, and the caller should unref too with g_list_free_full (devices, g_object_unref) -- Marc-André Lureau

On Fri, Nov 11, 2011 at 07:05:18PM +0100, Marc-André Lureau wrote:
On Thu, Nov 10, 2011 at 9:33 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
devices = g_list_append(devices, disk); + gvir_config_domain_set_devices(domain, devices); + g_list_free(devices); + devices = NULL;
Hmm, I realize this is a bit more tricky. You give up devices element owner ship but no the container.. I think this is bad, as the list contains invalid objects after leaving the functions. Insead, the set_devices () function should ref the element, and the caller should unref too with g_list_free_full (devices, g_object_unref)
I know this part is a bit messy, the _set_devices function doesn't keep the device list around so it does not need to get a reference on these. The reason why there is not a g_list_free_full call in the test program is that each GVirConfigObject::finalize function will call xmlFreeDoc(obj->priv->node->doc), but since after calling gvir_config_domain_set_devices, both GVirConfigDomain and GVirConfigDevice* will reference the same document, we will get a double free if we unref all of the objects deriving from GVirConfigObject. I chose to avoid this issue for now by not unreffing anything in the example program. Maybe it would be "better" to have the unref here, but to comment out the xmlFreeDoc() from GVirConfigObject::finalize. This issue is solved the right way in some future patches by using a refcounted GVirConfigXmlDoc which wraps xmlDocPtr. Christophe

This base class is mainly useful as a generic type when we manipulate list of devices regardless of their actual type. --- libvirt-gconfig/libvirt-gconfig-interface.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-interface.c b/libvirt-gconfig/libvirt-gconfig-interface.c index 5e934f6..5eece82 100644 --- a/libvirt-gconfig/libvirt-gconfig-interface.c +++ b/libvirt-gconfig/libvirt-gconfig-interface.c @@ -39,7 +39,7 @@ struct _GVirConfigInterfacePrivate gboolean unused; }; -G_DEFINE_TYPE(GVirConfigInterface, gvir_config_interface, GVIR_TYPE_CONFIG_OBJECT); +G_DEFINE_TYPE(GVirConfigInterface, gvir_config_interface, GVIR_TYPE_CONFIG_DEVICE); static void gvir_config_interface_class_init(GVirConfigInterfaceClass *klass) -- 1.7.7

ack -- Marc-André Lureau

--- libvirt-gconfig/libvirt-gconfig-interface.c | 15 +++++++++++++++ libvirt-gconfig/libvirt-gconfig-interface.h | 11 +++++++++++ libvirt-gconfig/libvirt-gconfig.sym | 2 ++ 3 files changed, 28 insertions(+), 0 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-interface.c b/libvirt-gconfig/libvirt-gconfig-interface.c index 5eece82..d112123 100644 --- a/libvirt-gconfig/libvirt-gconfig-interface.c +++ b/libvirt-gconfig/libvirt-gconfig-interface.c @@ -83,3 +83,18 @@ GVirConfigInterface *gvir_config_interface_new_from_xml(const gchar *xml, return GVIR_CONFIG_INTERFACE(object); } +void gvir_config_interface_set_network_type(GVirConfigInterface *interface, + GVirConfigInterfaceNetworkType type) +{ + xmlNodePtr node; + const char *type_str; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(interface)); + if (node == NULL) + return; + type_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_INTERFACE_NETWORK_TYPE, + type); + if (type_str != NULL) { + xmlNewProp(node, (xmlChar*)"type", (xmlChar*)type_str); + } +} diff --git a/libvirt-gconfig/libvirt-gconfig-interface.h b/libvirt-gconfig/libvirt-gconfig-interface.h index 0728c29..9618611 100644 --- a/libvirt-gconfig/libvirt-gconfig-interface.h +++ b/libvirt-gconfig/libvirt-gconfig-interface.h @@ -56,12 +56,23 @@ struct _GVirConfigInterfaceClass gpointer padding[20]; }; +typedef enum { + GVIR_CONFIG_INTERFACE_TYPE_NETWORK, + GVIR_CONFIG_INTERFACE_TYPE_BRIDGE, + GVIR_CONFIG_INTERFACE_TYPE_USER, + GVIR_CONFIG_INTERFACE_TYPE_ETHERNET, + GVIR_CONFIG_INTERFACE_TYPE_DIRECT, + GVIR_CONFIG_INTERFACE_TYPE_MCAST, + GVIR_CONFIG_INTERFACE_TYPE_SERVER +} GVirConfigInterfaceNetworkType; GType gvir_config_interface_get_type(void); GVirConfigInterface *gvir_config_interface_new(void); GVirConfigInterface *gvir_config_interface_new_from_xml(const gchar *xml, GError **error); +void gvir_config_interface_set_network_type(GVirConfigInterface *interface, + GVirConfigInterfaceNetworkType type); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index cb0d035..e9f1513 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -49,8 +49,10 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_domain_snapshot_new_from_xml; gvir_config_interface_get_type; + gvir_config_interface_network_type_get_type; gvir_config_interface_new; gvir_config_interface_new_from_xml; + gvir_config_interface_set_network_type; gvir_config_network_get_type; gvir_config_network_new; -- 1.7.7

ack -- Marc-André Lureau

On Fri, Nov 11, 2011 at 08:15:02PM +0100, Marc-André Lureau wrote:
it's missing include of libvirt-gconfig-helpers-private.h
This file doesn't use any function from this header, that's why it's not included (I've just checked that compilation goes fine). It will get added when I rework the patch series to have all the xml helpers marked as private. I'll do that when I have adressed all the other comments. Christophe

The way it's done is just a band-aid though. The need for this 'type' member in GVirConfigInterface and GVirConfigDeviceDisk is a clear indication that they should be separate class. --- libvirt-gconfig/libvirt-gconfig-interface.c | 30 ++++++++++++++++++++++++++- libvirt-gconfig/libvirt-gconfig-interface.h | 2 + libvirt-gconfig/libvirt-gconfig.sym | 1 + 3 files changed, 32 insertions(+), 1 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-interface.c b/libvirt-gconfig/libvirt-gconfig-interface.c index d112123..0993ab9 100644 --- a/libvirt-gconfig/libvirt-gconfig-interface.c +++ b/libvirt-gconfig/libvirt-gconfig-interface.c @@ -36,7 +36,7 @@ extern gboolean debugFlag; struct _GVirConfigInterfacePrivate { - gboolean unused; + GVirConfigInterfaceNetworkType type; }; G_DEFINE_TYPE(GVirConfigInterface, gvir_config_interface, GVIR_TYPE_CONFIG_DEVICE); @@ -96,5 +96,33 @@ void gvir_config_interface_set_network_type(GVirConfigInterface *interface, type); if (type_str != NULL) { xmlNewProp(node, (xmlChar*)"type", (xmlChar*)type_str); + interface->priv->type = type; } } + +void gvir_config_interface_set_source(GVirConfigInterface *interface, + const char *source) +{ + xmlNodePtr source_node; + const char *attribute_name; + + if (interface->priv->type != GVIR_CONFIG_INTERFACE_TYPE_NETWORK) { + /* I don't know what attribute name to use for 'dir' */ + g_warning("set_source not implemented for non-'network' interface nodes"); + return; + } + + source_node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(interface), + "source", TRUE); + if (source_node == NULL) + return; + + switch (interface->priv->type) { + case GVIR_CONFIG_INTERFACE_TYPE_NETWORK: + attribute_name = "network"; + break; + default: + g_return_if_reached(); + } + xmlNewProp(source_node, (xmlChar*)attribute_name, (xmlChar*)source); +} diff --git a/libvirt-gconfig/libvirt-gconfig-interface.h b/libvirt-gconfig/libvirt-gconfig-interface.h index 9618611..8de3334 100644 --- a/libvirt-gconfig/libvirt-gconfig-interface.h +++ b/libvirt-gconfig/libvirt-gconfig-interface.h @@ -74,6 +74,8 @@ GVirConfigInterface *gvir_config_interface_new_from_xml(const gchar *xml, void gvir_config_interface_set_network_type(GVirConfigInterface *interface, GVirConfigInterfaceNetworkType type); +void gvir_config_interface_set_source(GVirConfigInterface *interface, + const char *source); G_END_DECLS #endif /* __LIBVIRT_GCONFIG_INTERFACE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index e9f1513..886690e 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -53,6 +53,7 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_interface_new; gvir_config_interface_new_from_xml; gvir_config_interface_set_network_type; + gvir_config_interface_set_source; gvir_config_network_get_type; gvir_config_network_new; -- 1.7.7

On Thu, Nov 10, 2011 at 9:33 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
The way it's done is just a band-aid though. The need for this 'type' member in GVirConfigInterface and GVirConfigDeviceDisk is a clear indication that they should be separate class.
You mean there should be a seperate class for source type? otherwise, patch looks fine -- Marc-André Lureau

On Fri, Nov 11, 2011 at 08:08:37PM +0100, Marc-André Lureau wrote:
On Thu, Nov 10, 2011 at 9:33 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
The way it's done is just a band-aid though. The need for this 'type' member in GVirConfigInterface and GVirConfigDeviceDisk is a clear indication that they should be separate class.
You mean there should be a seperate class for source type?
The interface xml node is <interface type="xxx"> .... </interface> What I meant in the commit message is that instead of trying to handle all possible interface types in a single GVirConfigInterface, we should have one class per interface type (ie <interface type="xxx"> would be represented by one class, and <interface type="yyy"> would be a different class). Since the value of the attribute is not free-form, this is workable. And this is what the "Add GVirConfigInterfaceNetwork" patch does. I haven't done it (yet?) for the GVirConfigDeviceDisk class since for now it was no big deal not to have the specialized classes. Christophe

--- libvirt-gconfig/tests/test-domain-create.c | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-) diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index db22eb5..3f3f973 100644 --- a/libvirt-gconfig/tests/test-domain-create.c +++ b/libvirt-gconfig/tests/test-domain-create.c @@ -83,7 +83,7 @@ int main(void) devices = NULL; gvir_config_domain_set_os(domain, os); - /* device node */ + /* disk node */ GVirConfigDeviceDisk *disk; disk = gvir_config_device_disk_new(); @@ -96,6 +96,17 @@ int main(void) gvir_config_device_disk_set_target_dev(disk, "hda"); devices = g_list_append(devices, disk); + + /* network interface node */ + GVirConfigInterface *interface; + + + interface = gvir_config_interface_new(); + gvir_config_interface_set_network_type(interface, + GVIR_CONFIG_INTERFACE_TYPE_NETWORK); + gvir_config_interface_set_source(interface, "default"); + devices = g_list_append(devices, interface); + gvir_config_domain_set_devices(domain, devices); g_list_free(devices); devices = NULL; -- 1.7.7

ack On Thu, Nov 10, 2011 at 9:33 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
--- libvirt-gconfig/tests/test-domain-create.c | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index db22eb5..3f3f973 100644 --- a/libvirt-gconfig/tests/test-domain-create.c +++ b/libvirt-gconfig/tests/test-domain-create.c @@ -83,7 +83,7 @@ int main(void) devices = NULL; gvir_config_domain_set_os(domain, os);
- /* device node */ + /* disk node */ GVirConfigDeviceDisk *disk;
disk = gvir_config_device_disk_new(); @@ -96,6 +96,17 @@ int main(void) gvir_config_device_disk_set_target_dev(disk, "hda");
devices = g_list_append(devices, disk); + + /* network interface node */ + GVirConfigInterface *interface; + + + interface = gvir_config_interface_new(); + gvir_config_interface_set_network_type(interface, + GVIR_CONFIG_INTERFACE_TYPE_NETWORK); + gvir_config_interface_set_source(interface, "default"); + devices = g_list_append(devices, interface); + gvir_config_domain_set_devices(domain, devices); g_list_free(devices); devices = NULL; -- 1.7.7
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
-- Marc-André Lureau

Make GVirConfigInterface an abstract base class, and move the actual code in subclasses. This will make handling of the various types of network interfaces more understandable and more logical with respect to the corresponding XML. --- libvirt-gconfig/Makefile.am | 2 + .../libvirt-gconfig-interface-network.c | 106 ++++++++++++++++++++ .../libvirt-gconfig-interface-network.h | 70 +++++++++++++ libvirt-gconfig/libvirt-gconfig-interface.c | 71 +------------- libvirt-gconfig/libvirt-gconfig-interface.h | 18 ---- libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 10 +- libvirt-gconfig/tests/test-domain-create.c | 9 +- 8 files changed, 189 insertions(+), 98 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-interface-network.c create mode 100644 libvirt-gconfig/libvirt-gconfig-interface-network.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 82063df..c74d123 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -18,6 +18,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-snapshot.h \ libvirt-gconfig-helpers.h \ libvirt-gconfig-interface.h \ + libvirt-gconfig-interface-network.h \ libvirt-gconfig-network.h \ libvirt-gconfig-network-filter.h \ libvirt-gconfig-node-device.h \ @@ -40,6 +41,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-enum-types.h \ libvirt-gconfig-helpers.c \ libvirt-gconfig-interface.c \ + libvirt-gconfig-interface-network.c \ libvirt-gconfig-network.c \ libvirt-gconfig-network-filter.c \ libvirt-gconfig-node-device.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-interface-network.c b/libvirt-gconfig/libvirt-gconfig-interface-network.c new file mode 100644 index 0000000..304712d --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-interface-network.c @@ -0,0 +1,106 @@ +/* + * libvirt-gobject-config-interface_network-network.c: libvirt glib integration + * + * Copyright (C) 2008 Daniel P. Berrange + * 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: Daniel P. Berrange <berrange@redhat.com> + * Author: Christophe Fergeau <cfergeau@redhat.com> + */ + +#include <config.h> + +#include <string.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-helpers-private.h" + +extern gboolean debugFlag; + +#define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0) + +#define GVIR_CONFIG_INTERFACE_NETWORK_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_INTERFACE_NETWORK, GVirConfigInterfaceNetworkPrivate)) + +struct _GVirConfigInterfaceNetworkPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigInterfaceNetwork, gvir_config_interface_network, GVIR_TYPE_CONFIG_INTERFACE); + + +static void gvir_config_interface_network_class_init(GVirConfigInterfaceNetworkClass *klass) +{ + + g_type_class_add_private(klass, sizeof(GVirConfigInterfaceNetworkPrivate)); +} + + +static void gvir_config_interface_network_init(GVirConfigInterfaceNetwork *conn) +{ + GVirConfigInterfaceNetworkPrivate *priv; + + DEBUG("Init GVirConfigInterfaceNetwork=%p", conn); + + priv = conn->priv = GVIR_CONFIG_INTERFACE_NETWORK_GET_PRIVATE(conn); + + memset(priv, 0, sizeof(*priv)); +} + + +GVirConfigInterfaceNetwork *gvir_config_interface_network_new(void) +{ + xmlDocPtr doc; + xmlNodePtr node; + + doc = xmlNewDoc((xmlChar *)"1.0"); + node= xmlNewDocNode(doc, NULL, (xmlChar *)"interface", NULL); + xmlNewProp(doc->children, (xmlChar*)"type", (xmlChar*)"network"); + xmlDocSetRootElement(doc, node); + return GVIR_CONFIG_INTERFACE_NETWORK(g_object_new(GVIR_TYPE_CONFIG_INTERFACE_NETWORK, + "node", node, + "schema", DATADIR "/libvirt/schemas/interface.rng", + NULL)); +} + +GVirConfigInterfaceNetwork *gvir_config_interface_network_new_from_xml(const gchar *xml, + GError **error) +{ + xmlNodePtr node; + + node = gvir_config_xml_parse(xml, "interface", error); + if ((error != NULL) && (*error != NULL)) + return NULL; + xmlNewProp(node, (xmlChar*)"type", (xmlChar*)"network"); + return GVIR_CONFIG_INTERFACE_NETWORK(g_object_new(GVIR_TYPE_CONFIG_INTERFACE_NETWORK, + "node", node, + "schema", DATADIR "/libvirt/schemas/interface.rng", + NULL)); +} + +void gvir_config_interface_network_set_source(GVirConfigInterfaceNetwork *interface, + const char *source) +{ + xmlNodePtr source_node; + + source_node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(interface), + "source", TRUE); + if (source_node == NULL) + return; + xmlNewProp(source_node, (xmlChar*)"network", (xmlChar*)source); +} diff --git a/libvirt-gconfig/libvirt-gconfig-interface-network.h b/libvirt-gconfig/libvirt-gconfig-interface-network.h new file mode 100644 index 0000000..066709a --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-interface-network.h @@ -0,0 +1,70 @@ +/* + * libvirt-gobject-config-interface-network.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: Daniel P. Berrange <berrange@redhat.com> + * Author: Christophe Fergeau <cfergeau@redhat.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_INTERFACE_NETWORK_H__ +#define __LIBVIRT_GCONFIG_INTERFACE_NETWORK_H__ + +G_BEGIN_DECLS + +#define GVIR_TYPE_CONFIG_INTERFACE_NETWORK (gvir_config_interface_network_get_type ()) +#define GVIR_CONFIG_INTERFACE_NETWORK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_INTERFACE, GVirConfigInterfaceNetwork)) +#define GVIR_CONFIG_INTERFACE_NETWORK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_INTERFACE, GVirConfigInterfaceNetworkClass)) +#define GVIR_IS_CONFIG_INTERFACE_NETWORK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_INTERFACE)) +#define GVIR_IS_CONFIG_INTERFACE_NETWORK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_INTERFACE)) +#define GVIR_CONFIG_INTERFACE_NETWORK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_INTERFACE, GVirConfigInterfaceNetworkClass)) + +typedef struct _GVirConfigInterfaceNetwork GVirConfigInterfaceNetwork; +typedef struct _GVirConfigInterfaceNetworkPrivate GVirConfigInterfaceNetworkPrivate; +typedef struct _GVirConfigInterfaceNetworkClass GVirConfigInterfaceNetworkClass; + +struct _GVirConfigInterfaceNetwork +{ + GVirConfigObject parent; + + GVirConfigInterfaceNetworkPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigInterfaceNetworkClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_interface_network_get_type(void); + +GVirConfigInterfaceNetwork *gvir_config_interface_network_new(void); +GVirConfigInterfaceNetwork *gvir_config_interface_network_new_from_xml(const gchar *xml, + GError **error); + +void gvir_config_interface_network_set_source(GVirConfigInterfaceNetwork *interface, + const char *source); +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_INTERFACE_NETWORK_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-interface.c b/libvirt-gconfig/libvirt-gconfig-interface.c index 0993ab9..c449ba8 100644 --- a/libvirt-gconfig/libvirt-gconfig-interface.c +++ b/libvirt-gconfig/libvirt-gconfig-interface.c @@ -36,10 +36,10 @@ extern gboolean debugFlag; struct _GVirConfigInterfacePrivate { - GVirConfigInterfaceNetworkType type; + gboolean unused; }; -G_DEFINE_TYPE(GVirConfigInterface, gvir_config_interface, GVIR_TYPE_CONFIG_DEVICE); +G_DEFINE_ABSTRACT_TYPE(GVirConfigInterface, gvir_config_interface, GVIR_TYPE_CONFIG_DEVICE); static void gvir_config_interface_class_init(GVirConfigInterfaceClass *klass) @@ -59,70 +59,3 @@ static void gvir_config_interface_init(GVirConfigInterface *conn) memset(priv, 0, sizeof(*priv)); } - - -GVirConfigInterface *gvir_config_interface_new(void) -{ - GVirConfigObject *object; - - object = gvir_config_object_new(GVIR_TYPE_CONFIG_INTERFACE, - "interface", - DATADIR "/libvirt/schemas/interface.rng"); - return GVIR_CONFIG_INTERFACE(object); -} - -GVirConfigInterface *gvir_config_interface_new_from_xml(const gchar *xml, - GError **error) -{ - GVirConfigObject *object; - - object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_INTERFACE, - "interface", - DATADIR "/libvirt/schemas/interface.rng", - xml, error); - return GVIR_CONFIG_INTERFACE(object); -} - -void gvir_config_interface_set_network_type(GVirConfigInterface *interface, - GVirConfigInterfaceNetworkType type) -{ - xmlNodePtr node; - const char *type_str; - - node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(interface)); - if (node == NULL) - return; - type_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_INTERFACE_NETWORK_TYPE, - type); - if (type_str != NULL) { - xmlNewProp(node, (xmlChar*)"type", (xmlChar*)type_str); - interface->priv->type = type; - } -} - -void gvir_config_interface_set_source(GVirConfigInterface *interface, - const char *source) -{ - xmlNodePtr source_node; - const char *attribute_name; - - if (interface->priv->type != GVIR_CONFIG_INTERFACE_TYPE_NETWORK) { - /* I don't know what attribute name to use for 'dir' */ - g_warning("set_source not implemented for non-'network' interface nodes"); - return; - } - - source_node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(interface), - "source", TRUE); - if (source_node == NULL) - return; - - switch (interface->priv->type) { - case GVIR_CONFIG_INTERFACE_TYPE_NETWORK: - attribute_name = "network"; - break; - default: - g_return_if_reached(); - } - xmlNewProp(source_node, (xmlChar*)attribute_name, (xmlChar*)source); -} diff --git a/libvirt-gconfig/libvirt-gconfig-interface.h b/libvirt-gconfig/libvirt-gconfig-interface.h index 8de3334..e14c713 100644 --- a/libvirt-gconfig/libvirt-gconfig-interface.h +++ b/libvirt-gconfig/libvirt-gconfig-interface.h @@ -56,26 +56,8 @@ struct _GVirConfigInterfaceClass gpointer padding[20]; }; -typedef enum { - GVIR_CONFIG_INTERFACE_TYPE_NETWORK, - GVIR_CONFIG_INTERFACE_TYPE_BRIDGE, - GVIR_CONFIG_INTERFACE_TYPE_USER, - GVIR_CONFIG_INTERFACE_TYPE_ETHERNET, - GVIR_CONFIG_INTERFACE_TYPE_DIRECT, - GVIR_CONFIG_INTERFACE_TYPE_MCAST, - GVIR_CONFIG_INTERFACE_TYPE_SERVER -} GVirConfigInterfaceNetworkType; - GType gvir_config_interface_get_type(void); -GVirConfigInterface *gvir_config_interface_new(void); -GVirConfigInterface *gvir_config_interface_new_from_xml(const gchar *xml, - GError **error); -void gvir_config_interface_set_network_type(GVirConfigInterface *interface, - GVirConfigInterfaceNetworkType type); - -void gvir_config_interface_set_source(GVirConfigInterface *interface, - const char *source); G_END_DECLS #endif /* __LIBVIRT_GCONFIG_INTERFACE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index 01a1af3..c0deae9 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -35,6 +35,7 @@ #include <libvirt-gconfig/libvirt-gconfig-enum-types.h> #include <libvirt-gconfig/libvirt-gconfig-helpers.h> #include <libvirt-gconfig/libvirt-gconfig-interface.h> +#include <libvirt-gconfig/libvirt-gconfig-interface-network.h> #include <libvirt-gconfig/libvirt-gconfig-network.h> #include <libvirt-gconfig/libvirt-gconfig-network-filter.h> #include <libvirt-gconfig/libvirt-gconfig-node-device.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 886690e..b89b9d2 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -49,11 +49,11 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_domain_snapshot_new_from_xml; gvir_config_interface_get_type; - gvir_config_interface_network_type_get_type; - gvir_config_interface_new; - gvir_config_interface_new_from_xml; - gvir_config_interface_set_network_type; - gvir_config_interface_set_source; + + gvir_config_interface_network_get_type; + gvir_config_interface_network_new; + gvir_config_interface_network_new_from_xml; + gvir_config_interface_network_set_source; gvir_config_network_get_type; gvir_config_network_new; diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index 3f3f973..fa949f7 100644 --- a/libvirt-gconfig/tests/test-domain-create.c +++ b/libvirt-gconfig/tests/test-domain-create.c @@ -98,13 +98,10 @@ int main(void) devices = g_list_append(devices, disk); /* network interface node */ - GVirConfigInterface *interface; + GVirConfigInterfaceNetwork *interface; - - interface = gvir_config_interface_new(); - gvir_config_interface_set_network_type(interface, - GVIR_CONFIG_INTERFACE_TYPE_NETWORK); - gvir_config_interface_set_source(interface, "default"); + interface = gvir_config_interface_network_new(); + gvir_config_interface_network_set_source(interface, "default"); devices = g_list_append(devices, interface); gvir_config_domain_set_devices(domain, devices); -- 1.7.7

On Thu, Nov 10, 2011 at 9:34 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
Make GVirConfigInterface an abstract base class, and move the actual code in subclasses. This will make handling of the various types of network interfaces more understandable and more logical with respect to the corresponding XML.
I am not really convince about this approach, it breaks a bit the mapping between objects and node. I will let someone else with more familiarity with the XML to discuss this patch. Otherwise it works as expected. -- Marc-André Lureau

On Fri, Nov 11, 2011 at 08:27:48PM +0100, Marc-André Lureau wrote:
On Thu, Nov 10, 2011 at 9:34 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
Make GVirConfigInterface an abstract base class, and move the actual code in subclasses. This will make handling of the various types of network interfaces more understandable and more logical with respect to the corresponding XML.
I am not really convince about this approach, it breaks a bit the mapping between objects and node. I will let someone else with more familiarity with the XML to discuss this patch. Otherwise it works as expected.
The various network interfaces XML descriptions have so many peculiarities that I think it's the only sane way to handle this. The documentation is at http://libvirt.org/formatdomain.html#elementsNICS , and as I read it it's really "if the interface type is XXX, you can have a <target> node with this format, a <mac> node, a <virtualport> node, if it's YYY then the <target> node as this different format, and there is this <script> node that can be used, and with type ZZZ you only have a <source> node" If we try to handle all of this in a single class, it will be really easy to generate non-sensical configs, and with no obvious way from the API to guess what makes sense or not. Having separate classes make it much easier to show which operations are useful/meaningful on what type of interface. Christophe

--- libvirt-gconfig/Makefile.am | 2 + libvirt-gconfig/libvirt-gconfig-device-input.c | 109 ++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-device-input.h | 76 ++++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 7 ++ libvirt-gconfig/tests/test-domain-create.c | 15 +++- 6 files changed, 207 insertions(+), 3 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-device-input.c create mode 100644 libvirt-gconfig/libvirt-gconfig-device-input.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index c74d123..dcb5caa 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -14,6 +14,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-clock.h \ libvirt-gconfig-device.h \ libvirt-gconfig-device-disk.h \ + libvirt-gconfig-device-input.h \ libvirt-gconfig-domain.h \ libvirt-gconfig-domain-snapshot.h \ libvirt-gconfig-helpers.h \ @@ -35,6 +36,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-clock.c \ libvirt-gconfig-device.c \ libvirt-gconfig-device-disk.c \ + libvirt-gconfig-device-input.c \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-snapshot.c \ libvirt-gconfig-enum-types.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-device-input.c b/libvirt-gconfig/libvirt-gconfig-device-input.c new file mode 100644 index 0000000..a1ae1b1 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-device-input.c @@ -0,0 +1,109 @@ +/* + * libvirt-gobject-config-device_input.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@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" + +extern gboolean debugFlag; + +#define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0) + +#define GVIR_CONFIG_DEVICE_INPUT_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_DEVICE_INPUT, GVirConfigDeviceInputPrivate)) + +struct _GVirConfigDeviceInputPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigDeviceInput, gvir_config_device_input, GVIR_TYPE_CONFIG_DEVICE); + + +static void gvir_config_device_input_class_init(GVirConfigDeviceInputClass *klass) +{ + + g_type_class_add_private(klass, sizeof(GVirConfigDeviceInputPrivate)); +} + + +static void gvir_config_device_input_init(GVirConfigDeviceInput *device_input) +{ + GVirConfigDeviceInputPrivate *priv; + + DEBUG("Init GVirConfigDeviceInput=%p", device_input); + + priv = device_input->priv = GVIR_CONFIG_DEVICE_INPUT_GET_PRIVATE(device_input); + + memset(priv, 0, sizeof(*priv)); +} + + +GVirConfigDeviceInput *gvir_config_device_input_new(void) +{ + GVirConfigObject *object; + + object = gvir_config_object_new(GVIR_TYPE_CONFIG_DEVICE_INPUT, + "input", NULL); + return GVIR_CONFIG_DEVICE_INPUT(object); +} + +GVirConfigDeviceInput *gvir_config_device_input_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_DEVICE_INPUT, + "input", NULL, xml, error); + return GVIR_CONFIG_DEVICE_INPUT(object); +} + +void gvir_config_device_input_set_device_type(GVirConfigDeviceInput *input, + GVirConfigDeviceInputDeviceType type) +{ + xmlNodePtr node; + const char *type_str; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(input)); + if (node == NULL) + return; + type_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_DEVICE_INPUT_DEVICE_TYPE, + type); + if (type_str != NULL) + xmlNewProp(node, (xmlChar*)"type", (xmlChar*)type_str); +} + +void gvir_config_device_input_set_bus(GVirConfigDeviceInput *input, + const char *bus) +{ + xmlNodePtr node; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(input)); + if (node == NULL) + return; + xmlNewProp(node, (xmlChar*)"bus", (xmlChar*)bus); +} diff --git a/libvirt-gconfig/libvirt-gconfig-device-input.h b/libvirt-gconfig/libvirt-gconfig-device-input.h new file mode 100644 index 0000000..dbdf991 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-device-input.h @@ -0,0 +1,76 @@ +/* + * libvirt-gobject-device-input.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@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_INPUT_H__ +#define __LIBVIRT_GCONFIG_DEVICE_INPUT_H__ + +G_BEGIN_DECLS + +#define GVIR_TYPE_CONFIG_DEVICE_INPUT (gvir_config_device_input_get_type ()) +#define GVIR_CONFIG_DEVICE_INPUT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_DEVICE_INPUT, GVirConfigDeviceInput)) +#define GVIR_CONFIG_DEVICE_INPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_DEVICE_INPUT, GVirConfigDeviceInputClass)) +#define GVIR_IS_CONFIG_DEVICE_INPUT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_DEVICE_INPUT)) +#define GVIR_IS_CONFIG_DEVICE_INPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_DEVICE_INPUT)) +#define GVIR_CONFIG_DEVICE_INPUT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_DEVICE_INPUT, GVirConfigDeviceInputClass)) + +typedef struct _GVirConfigDeviceInput GVirConfigDeviceInput; +typedef struct _GVirConfigDeviceInputPrivate GVirConfigDeviceInputPrivate; +typedef struct _GVirConfigDeviceInputClass GVirConfigDeviceInputClass; + +struct _GVirConfigDeviceInput +{ + GVirConfigObject parent; + + GVirConfigDeviceInputPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigDeviceInputClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +typedef enum { + GVIR_CONFIG_DEVICE_INPUT_DEVICE_MOUSE, + GVIR_CONFIG_DEVICE_INPUT_DEVICE_TABLET +} GVirConfigDeviceInputDeviceType; + +GType gvir_config_device_input_get_type(void); + +GVirConfigDeviceInput *gvir_config_device_input_new(void); +GVirConfigDeviceInput *gvir_config_device_input_new_from_xml(const gchar *xml, + GError **error); +void gvir_config_device_input_set_device_type(GVirConfigDeviceInput *input, + GVirConfigDeviceInputDeviceType type); +void gvir_config_device_input_set_bus(GVirConfigDeviceInput *input, + const char *bus); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DEVICE_INPUT_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index c0deae9..0f0abb7 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -31,6 +31,7 @@ #include <libvirt-gconfig/libvirt-gconfig-clock.h> #include <libvirt-gconfig/libvirt-gconfig-device.h> #include <libvirt-gconfig/libvirt-gconfig-device-disk.h> +#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-helpers.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index b89b9d2..1904acc 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -29,6 +29,13 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_device_disk_set_target_dev; gvir_config_device_disk_set_type; + gvir_config_device_input_get_type; + gvir_config_device_input_device_type_get_type; + gvir_config_device_input_new; + gvir_config_device_input_new_from_xml; + gvir_config_device_input_set_device_type; + gvir_config_device_input_set_bus; + gvir_config_domain_get_type; gvir_config_domain_new; gvir_config_domain_new_from_xml; diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index fa949f7..a95da77 100644 --- a/libvirt-gconfig/tests/test-domain-create.c +++ b/libvirt-gconfig/tests/test-domain-create.c @@ -94,15 +94,24 @@ int main(void) gvir_config_device_disk_set_driver_type(disk, "qcow2"); gvir_config_device_disk_set_target_bus(disk, "ide"); gvir_config_device_disk_set_target_dev(disk, "hda"); - - devices = g_list_append(devices, disk); + devices = g_list_append(devices, GVIR_CONFIG_DEVICE(disk)); /* network interface node */ GVirConfigInterfaceNetwork *interface; interface = gvir_config_interface_network_new(); gvir_config_interface_network_set_source(interface, "default"); - devices = g_list_append(devices, interface); + devices = g_list_append(devices, GVIR_CONFIG_DEVICE(interface)); + + /* input node */ + GVirConfigDeviceInput *input; + + input = gvir_config_device_input_new(); + gvir_config_device_input_set_device_type(input, + GVIR_CONFIG_DEVICE_INPUT_DEVICE_TABLET); + gvir_config_device_input_set_bus(input, "usb"); + devices = g_list_append(devices, GVIR_CONFIG_DEVICE(input)); + gvir_config_domain_set_devices(domain, devices); g_list_free(devices); -- 1.7.7

just a comment about naming. If we use prefix "Device" before devices class, I think it should be done for the rest of the class for consistency.
+void gvir_config_device_input_set_bus(GVirConfigDeviceInput *input, + const char *bus) +{ + xmlNodePtr node; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(input)); + if (node == NULL) + return; + xmlNewProp(node, (xmlChar*)"bus", (xmlChar*)bus); +}
The bus argument could be an enum too ("xen" (paravirtualized), "ps2" and "usb") -- Marc-André Lureau

On Fri, Nov 11, 2011 at 08:32:30PM +0100, Marc-André Lureau wrote:
just a comment about naming.
If we use prefix "Device" before devices class, I think it should be done for the rest of the class for consistency.
What are you referring to? GVirConfigGraphicsSpice and GVirConfigInterface?
+void gvir_config_device_input_set_bus(GVirConfigDeviceInput *input, + const char *bus) +{ + xmlNodePtr node; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(input)); + if (node == NULL) + return; + xmlNewProp(node, (xmlChar*)"bus", (xmlChar*)bus); +}
The bus argument could be an enum too ("xen" (paravirtualized), "ps2" and "usb")
Ok. Christophe

On Tue, Nov 15, 2011 at 7:25 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
What are you referring to? GVirConfigGraphicsSpice and GVirConfigInterface?
yes, all the classes that are nodes under <devices> -- Marc-André Lureau

On Tue, Nov 15, 2011 at 07:32:49PM +0100, Marc-André Lureau wrote:
On Tue, Nov 15, 2011 at 7:25 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
What are you referring to? GVirConfigGraphicsSpice and GVirConfigInterface?
yes, all the classes that are nodes under <devices>
I dropped the Device from GraphicsSpice because the name was getting really long (not a great reason for doing this). I used the GVirConfigInterface name because there was already such a file in git, so I reused it. GVirConfigInterfaceNetwork look better to me than GVirConfigDeviceInterfaceNetwork (DeviceInterface is awkward imo). So I'd tend to change GraphicsSpice, but keep Interface. Christophe

On Wed, Nov 16, 2011 at 11:04 AM, Christophe Fergeau <cfergeau@redhat.com> wrote:
I dropped the Device from GraphicsSpice because the name was getting really long (not a great reason for doing this). I used the GVirConfigInterface name because there was already such a file in git, so I reused it.
Better being explicit and consistent than taking shortcuts. I am afraid if we drop the Device prefix, we may confuse it with host devices http://libvirt.org/formatnetwork.html. The same applies in libvirt-gobject, let's be consistent. -- Marc-André Lureau

On Wed, Nov 16, 2011 at 01:25:43PM +0100, Marc-André Lureau wrote:
I am afraid if we drop the Device prefix, we may confuse it with host devices http://libvirt.org/formatnetwork.html.
In this case this would be ConfigInterfaceNetwork vs ConfigNetwork. Christophe

Only the (non-TLS) port can be set on it --- libvirt-gconfig/Makefile.am | 2 + libvirt-gconfig/libvirt-gconfig-graphics-spice.c | 98 ++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-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, 182 insertions(+), 0 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-graphics-spice.c create mode 100644 libvirt-gconfig/libvirt-gconfig-graphics-spice.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index dcb5caa..e14d90a 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -17,6 +17,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-device-input.h \ libvirt-gconfig-domain.h \ libvirt-gconfig-domain-snapshot.h \ + libvirt-gconfig-graphics-spice.h \ libvirt-gconfig-helpers.h \ libvirt-gconfig-interface.h \ libvirt-gconfig-interface-network.h \ @@ -41,6 +42,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-snapshot.c \ libvirt-gconfig-enum-types.c \ libvirt-gconfig-enum-types.h \ + libvirt-gconfig-graphics-spice.c \ libvirt-gconfig-helpers.c \ libvirt-gconfig-interface.c \ libvirt-gconfig-interface-network.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-graphics-spice.c b/libvirt-gconfig/libvirt-gconfig-graphics-spice.c new file mode 100644 index 0000000..acb2304 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-graphics-spice.c @@ -0,0 +1,98 @@ +/* + * libvirt-gobject-config-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@gmail.com> + */ + +#include <config.h> + +#include <string.h> + +#include <libxml/tree.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" + +extern gboolean debugFlag; + +#define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0) + +#define GVIR_CONFIG_GRAPHICS_SPICE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_GRAPHICS_SPICE, GVirConfigGraphicsSpicePrivate)) + +struct _GVirConfigGraphicsSpicePrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigGraphicsSpice, gvir_config_graphics_spice, GVIR_TYPE_CONFIG_DEVICE); + + +static void gvir_config_graphics_spice_class_init(GVirConfigGraphicsSpiceClass *klass) +{ + + g_type_class_add_private(klass, sizeof(GVirConfigGraphicsSpicePrivate)); +} + + +static void gvir_config_graphics_spice_init(GVirConfigGraphicsSpice *graphics_spice) +{ + GVirConfigGraphicsSpicePrivate *priv; + + DEBUG("Init GVirConfigGraphicsSpice=%p", graphics_spice); + + priv = graphics_spice->priv = GVIR_CONFIG_GRAPHICS_SPICE_GET_PRIVATE(graphics_spice); + + memset(priv, 0, sizeof(*priv)); +} + + +GVirConfigGraphicsSpice *gvir_config_graphics_spice_new(void) +{ + GVirConfigObject *object; + + object = gvir_config_object_new(GVIR_TYPE_CONFIG_GRAPHICS_SPICE, + "graphics", NULL); + //xmlNewProp(doc->children, (xmlChar*)"type", (xmlChar*)"spice"); + return GVIR_CONFIG_GRAPHICS_SPICE(object); +} + +GVirConfigGraphicsSpice *gvir_config_graphics_spice_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_GRAPHICS_SPICE, + "graphics", NULL, xml, error); +// xmlNewProp(doc->children, (xmlChar*)"type", (xmlChar*)"spice"); + return GVIR_CONFIG_GRAPHICS_SPICE(object); +} + +void gvir_config_graphics_spice_set_port(GVirConfigGraphicsSpice *graphics, + unsigned int port) +{ + xmlNodePtr node; + char *port_str; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(graphics)); + if (node == NULL) + return; + 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-graphics-spice.h b/libvirt-gconfig/libvirt-gconfig-graphics-spice.h new file mode 100644 index 0000000..1266854 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-graphics-spice.h @@ -0,0 +1,69 @@ +/* + * libvirt-gobject-graphics-spice.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@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_GRAPHICS_SPICE_H__ +#define __LIBVIRT_GCONFIG_GRAPHICS_SPICE_H__ + +G_BEGIN_DECLS + +#define GVIR_TYPE_CONFIG_GRAPHICS_SPICE (gvir_config_graphics_spice_get_type ()) +#define GVIR_CONFIG_GRAPHICS_SPICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_GRAPHICS_SPICE, GVirConfigGraphicsSpice)) +#define GVIR_CONFIG_GRAPHICS_SPICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_GRAPHICS_SPICE, GVirConfigGraphicsSpiceClass)) +#define GVIR_IS_CONFIG_GRAPHICS_SPICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_GRAPHICS_SPICE)) +#define GVIR_IS_CONFIG_GRAPHICS_SPICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_GRAPHICS_SPICE)) +#define GVIR_CONFIG_GRAPHICS_SPICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_GRAPHICS_SPICE, GVirConfigGraphicsSpiceClass)) + +typedef struct _GVirConfigGraphicsSpice GVirConfigGraphicsSpice; +typedef struct _GVirConfigGraphicsSpicePrivate GVirConfigGraphicsSpicePrivate; +typedef struct _GVirConfigGraphicsSpiceClass GVirConfigGraphicsSpiceClass; + +struct _GVirConfigGraphicsSpice +{ + GVirConfigObject parent; + + GVirConfigGraphicsSpicePrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigGraphicsSpiceClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_graphics_spice_get_type(void); + +GVirConfigGraphicsSpice *gvir_config_graphics_spice_new(void); +GVirConfigGraphicsSpice *gvir_config_graphics_spice_new_from_xml(const gchar *xml, + GError **error); +void gvir_config_graphics_spice_set_port(GVirConfigGraphicsSpice *graphics, + unsigned int port); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_GRAPHICS_SPICE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index 0f0abb7..218aada 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -34,6 +34,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-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 1904acc..ebe87d1 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -55,6 +55,11 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_domain_snapshot_new; gvir_config_domain_snapshot_new_from_xml; + gvir_config_graphics_spice_get_type; + gvir_config_graphics_spice_new; + gvir_config_graphics_spice_new_from_xml; + gvir_config_graphics_spice_set_port; + gvir_config_interface_get_type; gvir_config_interface_network_get_type; diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index a95da77..539b475 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, "usb"); devices = g_list_append(devices, GVIR_CONFIG_DEVICE(input)); + /* graphics node */ + GVirConfigGraphicsSpice *graphics; + + graphics = gvir_config_graphics_spice_new(); + gvir_config_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

Same comment as for "interface", do we want to have specialized classes for various type. In this case, you should also add a base Graphics class.
+GVirConfigGraphicsSpice *gvir_config_graphics_spice_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_GRAPHICS_SPICE, + "graphics", NULL, xml, error); +// xmlNewProp(doc->children, (xmlChar*)"type", (xmlChar*)"spice"); + return GVIR_CONFIG_GRAPHICS_SPICE(object); +}
This surely shouldn't be commented out. Perhaps it should be done in _init(). -- Marc-André Lureau

On Fri, Nov 11, 2011 at 08:40:58PM +0100, Marc-André Lureau wrote:
Same comment as for "interface", do we want to have specialized classes for various type.
In this case, you should also add a base Graphics class.
Looking at the format again (http://libvirt.org/formatdomain.html#elementsGraphics ) I think we do. I was probably lazy when I did this :)
+GVirConfigGraphicsSpice *gvir_config_graphics_spice_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_GRAPHICS_SPICE, + "graphics", NULL, xml, error); +// xmlNewProp(doc->children, (xmlChar*)"type", (xmlChar*)"spice"); + return GVIR_CONFIG_GRAPHICS_SPICE(object); +}
This surely shouldn't be commented out.
yes this is a mistake, I noticed it after sending the patch series
Perhaps it should be done in _init().
I'm not a big fan of that, if we enforce type="spice" in _init() then it would seem logical to also force the root node name to be "graphics". Christophe

--- libvirt-gconfig/Makefile.am | 2 + libvirt-gconfig/libvirt-gconfig-device-video.c | 133 ++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-device-video.h | 82 +++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 8 ++ libvirt-gconfig/tests/test-domain-create.c | 9 ++ 6 files changed, 235 insertions(+), 0 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-device-video.c create mode 100644 libvirt-gconfig/libvirt-gconfig-device-video.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index e14d90a..71fe027 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-input.h \ + libvirt-gconfig-device-video.h \ libvirt-gconfig-domain.h \ libvirt-gconfig-domain-snapshot.h \ libvirt-gconfig-graphics-spice.h \ @@ -38,6 +39,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-device.c \ libvirt-gconfig-device-disk.c \ libvirt-gconfig-device-input.c \ + libvirt-gconfig-device-video.c \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-snapshot.c \ libvirt-gconfig-enum-types.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-device-video.c b/libvirt-gconfig/libvirt-gconfig-device-video.c new file mode 100644 index 0000000..23736db --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-device-video.c @@ -0,0 +1,133 @@ +/* + * libvirt-gobject-config-device-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@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" + +extern gboolean debugFlag; + +#define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0) + +#define GVIR_CONFIG_DEVICE_VIDEO_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_DEVICE_VIDEO, GVirConfigDeviceVideoPrivate)) + +struct _GVirConfigDeviceVideoPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigDeviceVideo, gvir_config_device_video, GVIR_TYPE_CONFIG_DEVICE); + + +static void gvir_config_device_video_class_init(GVirConfigDeviceVideoClass *klass) +{ + + g_type_class_add_private(klass, sizeof(GVirConfigDeviceVideoPrivate)); +} + + +static void gvir_config_device_video_init(GVirConfigDeviceVideo *device_video) +{ + GVirConfigDeviceVideoPrivate *priv; + + DEBUG("Init GVirConfigDeviceVideo=%p", device_video); + + priv = device_video->priv = GVIR_CONFIG_DEVICE_VIDEO_GET_PRIVATE(device_video); + + memset(priv, 0, sizeof(*priv)); +} + + +GVirConfigDeviceVideo *gvir_config_device_video_new(void) +{ + GVirConfigObject *object; + + object = gvir_config_object_new(GVIR_TYPE_CONFIG_DEVICE_VIDEO, + "video", NULL); + return GVIR_CONFIG_DEVICE_VIDEO(object); +} + +GVirConfigDeviceVideo *gvir_config_device_video_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_DEVICE_VIDEO, + "video", NULL, xml, error); + return GVIR_CONFIG_DEVICE_VIDEO(object); +} + +void gvir_config_device_video_set_model(GVirConfigDeviceVideo *video, + GVirConfigDeviceVideoModel model) +{ + xmlNodePtr node; + const char *model_str; + + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(video), + "model", TRUE); + if (node == NULL) + return; + model_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_DEVICE_VIDEO_MODEL, + model); + if (model_str != NULL) + xmlNewProp(node, (xmlChar*)"type", (xmlChar*)model_str); +} + +void gvir_config_device_video_set_vram(GVirConfigDeviceVideo *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_device_video_set_heads(GVirConfigDeviceVideo *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-device-video.h b/libvirt-gconfig/libvirt-gconfig-device-video.h new file mode 100644 index 0000000..ec83d2e --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-device-video.h @@ -0,0 +1,82 @@ +/* + * libvirt-gobject-device-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@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_VIDEO_H__ +#define __LIBVIRT_GCONFIG_DEVICE_VIDEO_H__ + +G_BEGIN_DECLS + +#define GVIR_TYPE_CONFIG_DEVICE_VIDEO (gvir_config_device_video_get_type ()) +#define GVIR_CONFIG_DEVICE_VIDEO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_DEVICE_VIDEO, GVirConfigDeviceVideo)) +#define GVIR_CONFIG_DEVICE_VIDEO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_DEVICE_VIDEO, GVirConfigDeviceVideoClass)) +#define GVIR_IS_CONFIG_DEVICE_VIDEO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_DEVICE_VIDEO)) +#define GVIR_IS_CONFIG_DEVICE_VIDEO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_DEVICE_VIDEO)) +#define GVIR_CONFIG_DEVICE_VIDEO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_DEVICE_VIDEO, GVirConfigDeviceVideoClass)) + +typedef struct _GVirConfigDeviceVideo GVirConfigDeviceVideo; +typedef struct _GVirConfigDeviceVideoPrivate GVirConfigDeviceVideoPrivate; +typedef struct _GVirConfigDeviceVideoClass GVirConfigDeviceVideoClass; + +struct _GVirConfigDeviceVideo +{ + GVirConfigObject parent; + + GVirConfigDeviceVideoPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigDeviceVideoClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +typedef enum { + GVIR_CONFIG_DEVICE_VIDEO_MODEL_VGA, + GVIR_CONFIG_DEVICE_VIDEO_MODEL_CIRRUS, + GVIR_CONFIG_DEVICE_VIDEO_MODEL_VMVGA, + GVIR_CONFIG_DEVICE_VIDEO_MODEL_XEN, + GVIR_CONFIG_DEVICE_VIDEO_MODEL_VBOX, + GVIR_CONFIG_DEVICE_VIDEO_MODEL_QXL +} GVirConfigDeviceVideoModel; + +GType gvir_config_device_video_get_type(void); + +GVirConfigDeviceVideo *gvir_config_device_video_new(void); +GVirConfigDeviceVideo *gvir_config_device_video_new_from_xml(const gchar *xml, + GError **error); +void gvir_config_device_video_set_model(GVirConfigDeviceVideo *video, + GVirConfigDeviceVideoModel model); +void gvir_config_device_video_set_vram(GVirConfigDeviceVideo *video, + guint kbytes); +void gvir_config_device_video_set_heads(GVirConfigDeviceVideo *video, + guint head_count); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DEVICE_VIDEO_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index 218aada..01c59d0 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -32,6 +32,7 @@ #include <libvirt-gconfig/libvirt-gconfig-device.h> #include <libvirt-gconfig/libvirt-gconfig-device-disk.h> #include <libvirt-gconfig/libvirt-gconfig-device-input.h> +#include <libvirt-gconfig/libvirt-gconfig-device-video.h> #include <libvirt-gconfig/libvirt-gconfig-domain-snapshot.h> #include <libvirt-gconfig/libvirt-gconfig-enum-types.h> #include <libvirt-gconfig/libvirt-gconfig-graphics-spice.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index ebe87d1..6d895fb 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -36,6 +36,14 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_device_input_set_device_type; gvir_config_device_input_set_bus; + gvir_config_device_video_get_type; + gvir_config_device_video_model_get_type; + gvir_config_device_video_new; + gvir_config_device_video_new_from_xml; + gvir_config_device_video_set_model; + gvir_config_device_video_set_vram; + gvir_config_device_video_set_heads; + gvir_config_domain_get_type; gvir_config_domain_new; gvir_config_domain_new_from_xml; diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index 539b475..ba08a9f 100644 --- a/libvirt-gconfig/tests/test-domain-create.c +++ b/libvirt-gconfig/tests/test-domain-create.c @@ -119,6 +119,15 @@ int main(void) gvir_config_graphics_spice_set_port(graphics, 1234); devices = g_list_append(devices, GVIR_CONFIG_DEVICE(graphics)); + /* video node */ + GVirConfigDeviceVideo *video; + + video = gvir_config_device_video_new(); + gvir_config_device_video_set_model(video, + GVIR_CONFIG_DEVICE_VIDEO_MODEL_QXL); + devices = g_list_append(devices, GVIR_CONFIG_DEVICE(video)); + + gvir_config_domain_set_devices(domain, devices); g_list_free(devices); -- 1.7.7

ack On Thu, Nov 10, 2011 at 9:34 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
--- libvirt-gconfig/Makefile.am | 2 + libvirt-gconfig/libvirt-gconfig-device-video.c | 133 ++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-device-video.h | 82 +++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 8 ++ libvirt-gconfig/tests/test-domain-create.c | 9 ++ 6 files changed, 235 insertions(+), 0 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-device-video.c create mode 100644 libvirt-gconfig/libvirt-gconfig-device-video.h
diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index e14d90a..71fe027 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-input.h \ + libvirt-gconfig-device-video.h \ libvirt-gconfig-domain.h \ libvirt-gconfig-domain-snapshot.h \ libvirt-gconfig-graphics-spice.h \ @@ -38,6 +39,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-device.c \ libvirt-gconfig-device-disk.c \ libvirt-gconfig-device-input.c \ + libvirt-gconfig-device-video.c \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-snapshot.c \ libvirt-gconfig-enum-types.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-device-video.c b/libvirt-gconfig/libvirt-gconfig-device-video.c new file mode 100644 index 0000000..23736db --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-device-video.c @@ -0,0 +1,133 @@ +/* + * libvirt-gobject-config-device-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@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" + +extern gboolean debugFlag; + +#define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0) + +#define GVIR_CONFIG_DEVICE_VIDEO_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_DEVICE_VIDEO, GVirConfigDeviceVideoPrivate)) + +struct _GVirConfigDeviceVideoPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigDeviceVideo, gvir_config_device_video, GVIR_TYPE_CONFIG_DEVICE); + + +static void gvir_config_device_video_class_init(GVirConfigDeviceVideoClass *klass) +{ + + g_type_class_add_private(klass, sizeof(GVirConfigDeviceVideoPrivate)); +} + + +static void gvir_config_device_video_init(GVirConfigDeviceVideo *device_video) +{ + GVirConfigDeviceVideoPrivate *priv; + + DEBUG("Init GVirConfigDeviceVideo=%p", device_video); + + priv = device_video->priv = GVIR_CONFIG_DEVICE_VIDEO_GET_PRIVATE(device_video); + + memset(priv, 0, sizeof(*priv)); +} + + +GVirConfigDeviceVideo *gvir_config_device_video_new(void) +{ + GVirConfigObject *object; + + object = gvir_config_object_new(GVIR_TYPE_CONFIG_DEVICE_VIDEO, + "video", NULL); + return GVIR_CONFIG_DEVICE_VIDEO(object); +} + +GVirConfigDeviceVideo *gvir_config_device_video_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_DEVICE_VIDEO, + "video", NULL, xml, error); + return GVIR_CONFIG_DEVICE_VIDEO(object); +} + +void gvir_config_device_video_set_model(GVirConfigDeviceVideo *video, + GVirConfigDeviceVideoModel model) +{ + xmlNodePtr node; + const char *model_str; + + node = gvir_config_object_new_child(GVIR_CONFIG_OBJECT(video), + "model", TRUE); + if (node == NULL) + return; + model_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_DEVICE_VIDEO_MODEL, + model); + if (model_str != NULL) + xmlNewProp(node, (xmlChar*)"type", (xmlChar*)model_str); +} + +void gvir_config_device_video_set_vram(GVirConfigDeviceVideo *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_device_video_set_heads(GVirConfigDeviceVideo *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-device-video.h b/libvirt-gconfig/libvirt-gconfig-device-video.h new file mode 100644 index 0000000..ec83d2e --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-device-video.h @@ -0,0 +1,82 @@ +/* + * libvirt-gobject-device-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@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_VIDEO_H__ +#define __LIBVIRT_GCONFIG_DEVICE_VIDEO_H__ + +G_BEGIN_DECLS + +#define GVIR_TYPE_CONFIG_DEVICE_VIDEO (gvir_config_device_video_get_type ()) +#define GVIR_CONFIG_DEVICE_VIDEO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_DEVICE_VIDEO, GVirConfigDeviceVideo)) +#define GVIR_CONFIG_DEVICE_VIDEO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_DEVICE_VIDEO, GVirConfigDeviceVideoClass)) +#define GVIR_IS_CONFIG_DEVICE_VIDEO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_DEVICE_VIDEO)) +#define GVIR_IS_CONFIG_DEVICE_VIDEO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_DEVICE_VIDEO)) +#define GVIR_CONFIG_DEVICE_VIDEO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_DEVICE_VIDEO, GVirConfigDeviceVideoClass)) + +typedef struct _GVirConfigDeviceVideo GVirConfigDeviceVideo; +typedef struct _GVirConfigDeviceVideoPrivate GVirConfigDeviceVideoPrivate; +typedef struct _GVirConfigDeviceVideoClass GVirConfigDeviceVideoClass; + +struct _GVirConfigDeviceVideo +{ + GVirConfigObject parent; + + GVirConfigDeviceVideoPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigDeviceVideoClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +typedef enum { + GVIR_CONFIG_DEVICE_VIDEO_MODEL_VGA, + GVIR_CONFIG_DEVICE_VIDEO_MODEL_CIRRUS, + GVIR_CONFIG_DEVICE_VIDEO_MODEL_VMVGA, + GVIR_CONFIG_DEVICE_VIDEO_MODEL_XEN, + GVIR_CONFIG_DEVICE_VIDEO_MODEL_VBOX, + GVIR_CONFIG_DEVICE_VIDEO_MODEL_QXL +} GVirConfigDeviceVideoModel; + +GType gvir_config_device_video_get_type(void); + +GVirConfigDeviceVideo *gvir_config_device_video_new(void); +GVirConfigDeviceVideo *gvir_config_device_video_new_from_xml(const gchar *xml, + GError **error); +void gvir_config_device_video_set_model(GVirConfigDeviceVideo *video, + GVirConfigDeviceVideoModel model); +void gvir_config_device_video_set_vram(GVirConfigDeviceVideo *video, + guint kbytes); +void gvir_config_device_video_set_heads(GVirConfigDeviceVideo *video, + guint head_count); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DEVICE_VIDEO_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index 218aada..01c59d0 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -32,6 +32,7 @@ #include <libvirt-gconfig/libvirt-gconfig-device.h> #include <libvirt-gconfig/libvirt-gconfig-device-disk.h> #include <libvirt-gconfig/libvirt-gconfig-device-input.h> +#include <libvirt-gconfig/libvirt-gconfig-device-video.h> #include <libvirt-gconfig/libvirt-gconfig-domain-snapshot.h> #include <libvirt-gconfig/libvirt-gconfig-enum-types.h> #include <libvirt-gconfig/libvirt-gconfig-graphics-spice.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index ebe87d1..6d895fb 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -36,6 +36,14 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_device_input_set_device_type; gvir_config_device_input_set_bus;
+ gvir_config_device_video_get_type; + gvir_config_device_video_model_get_type; + gvir_config_device_video_new; + gvir_config_device_video_new_from_xml; + gvir_config_device_video_set_model; + gvir_config_device_video_set_vram; + gvir_config_device_video_set_heads; + gvir_config_domain_get_type; gvir_config_domain_new; gvir_config_domain_new_from_xml; diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index 539b475..ba08a9f 100644 --- a/libvirt-gconfig/tests/test-domain-create.c +++ b/libvirt-gconfig/tests/test-domain-create.c @@ -119,6 +119,15 @@ int main(void) gvir_config_graphics_spice_set_port(graphics, 1234); devices = g_list_append(devices, GVIR_CONFIG_DEVICE(graphics));
+ /* video node */ + GVirConfigDeviceVideo *video; + + video = gvir_config_device_video_new(); + gvir_config_device_video_set_model(video, + GVIR_CONFIG_DEVICE_VIDEO_MODEL_QXL); + devices = g_list_append(devices, GVIR_CONFIG_DEVICE(video)); + +
gvir_config_domain_set_devices(domain, devices); g_list_free(devices); -- 1.7.7
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
-- Marc-André Lureau

--- libvirt-gconfig/Makefile.am | 6 ++ libvirt-gconfig/libvirt-gconfig-chardev-source.c | 62 ++++++++++++++++ libvirt-gconfig/libvirt-gconfig-chardev-source.h | 64 +++++++++++++++++ libvirt-gconfig/libvirt-gconfig-chardev-target.c | 62 ++++++++++++++++ libvirt-gconfig/libvirt-gconfig-chardev-target.h | 64 +++++++++++++++++ libvirt-gconfig/libvirt-gconfig-device-chardev.c | 82 ++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-device-chardev.h | 71 +++++++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 3 + libvirt-gconfig/libvirt-gconfig.sym | 10 +++ 9 files changed, 424 insertions(+), 0 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-chardev-source.c create mode 100644 libvirt-gconfig/libvirt-gconfig-chardev-source.h create mode 100644 libvirt-gconfig/libvirt-gconfig-chardev-target.c create mode 100644 libvirt-gconfig/libvirt-gconfig-chardev-target.h create mode 100644 libvirt-gconfig/libvirt-gconfig-device-chardev.c create mode 100644 libvirt-gconfig/libvirt-gconfig-device-chardev.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 71fe027..3144955 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -11,8 +11,11 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig.h \ libvirt-gconfig-object.h \ libvirt-gconfig-capabilities.h \ + libvirt-gconfig-chardev-source.h \ + libvirt-gconfig-chardev-target.h \ libvirt-gconfig-clock.h \ libvirt-gconfig-device.h \ + libvirt-gconfig-device-chardev.h \ libvirt-gconfig-device-disk.h \ libvirt-gconfig-device-input.h \ libvirt-gconfig-device-video.h \ @@ -35,8 +38,11 @@ noinst_HEADERS = \ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-object.c \ libvirt-gconfig-capabilities.c \ + libvirt-gconfig-chardev-source.c \ + libvirt-gconfig-chardev-target.c \ libvirt-gconfig-clock.c \ libvirt-gconfig-device.c \ + libvirt-gconfig-device-chardev.c \ libvirt-gconfig-device-disk.c \ libvirt-gconfig-device-input.c \ libvirt-gconfig-device-video.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-chardev-source.c b/libvirt-gconfig/libvirt-gconfig-chardev-source.c new file mode 100644 index 0000000..82eff4f --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-chardev-source.c @@ -0,0 +1,62 @@ +/* + * libvirt-gobject-config-chardev-source.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@gmail.com> + */ + +#include <config.h> + +#include <string.h> + +#include <libxml/tree.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" + +extern gboolean debugFlag; + +#define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0) + +#define GVIR_CONFIG_CHARDEV_SOURCE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_CHARDEV_SOURCE, GVirConfigChardevSourcePrivate)) + +struct _GVirConfigChardevSourcePrivate +{ + gboolean unused; +}; + +G_DEFINE_ABSTRACT_TYPE(GVirConfigChardevSource, gvir_config_chardev_source, GVIR_TYPE_CONFIG_OBJECT); + + +static void gvir_config_chardev_source_class_init(GVirConfigChardevSourceClass *klass) +{ + + g_type_class_add_private(klass, sizeof(GVirConfigChardevSourcePrivate)); +} + + +static void gvir_config_chardev_source_init(GVirConfigChardevSource *chardev_source) +{ + GVirConfigChardevSourcePrivate *priv; + + DEBUG("Init GVirConfigChardevSource=%p", chardev_source); + + priv = chardev_source->priv = GVIR_CONFIG_CHARDEV_SOURCE_GET_PRIVATE(chardev_source); + + memset(priv, 0, sizeof(*priv)); +} diff --git a/libvirt-gconfig/libvirt-gconfig-chardev-source.h b/libvirt-gconfig/libvirt-gconfig-chardev-source.h new file mode 100644 index 0000000..5a4c8fe --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-chardev-source.h @@ -0,0 +1,64 @@ +/* + * libvirt-gobject-chardev-source.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@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_CHARDEV_SOURCE_H__ +#define __LIBVIRT_GCONFIG_CHARDEV_SOURCE_H__ + +G_BEGIN_DECLS + +#define GVIR_TYPE_CONFIG_CHARDEV_SOURCE (gvir_config_chardev_source_get_type ()) +#define GVIR_CONFIG_CHARDEV_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_CHARDEV_SOURCE, GVirConfigChardevSource)) +#define GVIR_CONFIG_CHARDEV_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_CHARDEV_SOURCE, GVirConfigChardevSourceClass)) +#define GVIR_IS_CONFIG_CHARDEV_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_CHARDEV_SOURCE)) +#define GVIR_IS_CONFIG_CHARDEV_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_CHARDEV_SOURCE)) +#define GVIR_CONFIG_CHARDEV_SOURCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_CHARDEV_SOURCE, GVirConfigChardevSourceClass)) + +typedef struct _GVirConfigChardevSource GVirConfigChardevSource; +typedef struct _GVirConfigChardevSourcePrivate GVirConfigChardevSourcePrivate; +typedef struct _GVirConfigChardevSourceClass GVirConfigChardevSourceClass; + +struct _GVirConfigChardevSource +{ + GVirConfigObject parent; + + GVirConfigChardevSourcePrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigChardevSourceClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + + +GType gvir_config_chardev_source_get_type(void); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CHARDEV_SOURCE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-chardev-target.c b/libvirt-gconfig/libvirt-gconfig-chardev-target.c new file mode 100644 index 0000000..a9e5a20 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-chardev-target.c @@ -0,0 +1,62 @@ +/* + * libvirt-gobject-config-chardev-target.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@gmail.com> + */ + +#include <config.h> + +#include <string.h> + +#include <libxml/tree.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" + +extern gboolean debugFlag; + +#define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0) + +#define GVIR_CONFIG_CHARDEV_TARGET_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_CHARDEV_TARGET, GVirConfigChardevTargetPrivate)) + +struct _GVirConfigChardevTargetPrivate +{ + gboolean unused; +}; + +G_DEFINE_ABSTRACT_TYPE(GVirConfigChardevTarget, gvir_config_chardev_target, GVIR_TYPE_CONFIG_OBJECT); + + +static void gvir_config_chardev_target_class_init(GVirConfigChardevTargetClass *klass) +{ + + g_type_class_add_private(klass, sizeof(GVirConfigChardevTargetPrivate)); +} + + +static void gvir_config_chardev_target_init(GVirConfigChardevTarget *chardev_target) +{ + GVirConfigChardevTargetPrivate *priv; + + DEBUG("Init GVirConfigChardevTarget=%p", chardev_target); + + priv = chardev_target->priv = GVIR_CONFIG_CHARDEV_TARGET_GET_PRIVATE(chardev_target); + + memset(priv, 0, sizeof(*priv)); +} diff --git a/libvirt-gconfig/libvirt-gconfig-chardev-target.h b/libvirt-gconfig/libvirt-gconfig-chardev-target.h new file mode 100644 index 0000000..41fd875 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-chardev-target.h @@ -0,0 +1,64 @@ +/* + * libvirt-gobject-chardev-target.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@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_CHARDEV_TARGET_H__ +#define __LIBVIRT_GCONFIG_CHARDEV_TARGET_H__ + +G_BEGIN_DECLS + +#define GVIR_TYPE_CONFIG_CHARDEV_TARGET (gvir_config_chardev_target_get_type ()) +#define GVIR_CONFIG_CHARDEV_TARGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_CHARDEV_TARGET, GVirConfigChardevTarget)) +#define GVIR_CONFIG_CHARDEV_TARGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_CHARDEV_TARGET, GVirConfigChardevTargetClass)) +#define GVIR_IS_CONFIG_CHARDEV_TARGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_CHARDEV_TARGET)) +#define GVIR_IS_CONFIG_CHARDEV_TARGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_CHARDEV_TARGET)) +#define GVIR_CONFIG_CHARDEV_TARGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_CHARDEV_TARGET, GVirConfigChardevTargetClass)) + +typedef struct _GVirConfigChardevTarget GVirConfigChardevTarget; +typedef struct _GVirConfigChardevTargetPrivate GVirConfigChardevTargetPrivate; +typedef struct _GVirConfigChardevTargetClass GVirConfigChardevTargetClass; + +struct _GVirConfigChardevTarget +{ + GVirConfigObject parent; + + GVirConfigChardevTargetPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigChardevTargetClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + + +GType gvir_config_chardev_target_get_type(void); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CHARDEV_TARGET_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-device-chardev.c b/libvirt-gconfig/libvirt-gconfig-device-chardev.c new file mode 100644 index 0000000..d4ec23f --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-device-chardev.c @@ -0,0 +1,82 @@ +/* + * libvirt-gobject-config-device-chardev.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@gmail.com> + */ + +#include <config.h> + +#include <string.h> + +#include <libxml/tree.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" + +extern gboolean debugFlag; + +#define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0) + +#define GVIR_CONFIG_DEVICE_CHARDEV_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_DEVICE_CHARDEV, GVirConfigDeviceChardevPrivate)) + +struct _GVirConfigDeviceChardevPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigDeviceChardev, gvir_config_device_chardev, GVIR_TYPE_CONFIG_DEVICE); + + +static void gvir_config_device_chardev_class_init(GVirConfigDeviceChardevClass *klass) +{ + + g_type_class_add_private(klass, sizeof(GVirConfigDeviceChardevPrivate)); +} + + +static void gvir_config_device_chardev_init(GVirConfigDeviceChardev *chardev) +{ + GVirConfigDeviceChardevPrivate *priv; + + DEBUG("Init GVirConfigDeviceChardev=%p", chardev); + + priv = chardev->priv = GVIR_CONFIG_DEVICE_CHARDEV_GET_PRIVATE(chardev); + + memset(priv, 0, sizeof(*priv)); +} + + +GVirConfigDeviceChardev *gvir_config_device_chardev_new(void) +{ + GVirConfigObject *object; + + object = gvir_config_object_new(GVIR_TYPE_CONFIG_DEVICE_CHARDEV, + "", NULL); + return GVIR_CONFIG_DEVICE_CHARDEV(object); +} + +GVirConfigDeviceChardev *gvir_config_device_chardev_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_DEVICE_CHARDEV, + "", NULL, xml, error); + return GVIR_CONFIG_DEVICE_CHARDEV(object); +} diff --git a/libvirt-gconfig/libvirt-gconfig-device-chardev.h b/libvirt-gconfig/libvirt-gconfig-device-chardev.h new file mode 100644 index 0000000..ff806e7 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-device-chardev.h @@ -0,0 +1,71 @@ +/* + * libvirt-gobject-device-chardev.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@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_CHARDEV_H__ +#define __LIBVIRT_GCONFIG_DEVICE_CHARDEV_H__ + +G_BEGIN_DECLS + +#define GVIR_TYPE_CONFIG_DEVICE_CHARDEV (gvir_config_device_chardev_get_type ()) +#define GVIR_CONFIG_DEVICE_CHARDEV(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_DEVICE_CHARDEV, GVirConfigDeviceChardev)) +#define GVIR_CONFIG_DEVICE_CHARDEV_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_DEVICE_CHARDEV, GVirConfigDeviceChardevClass)) +#define GVIR_IS_CONFIG_DEVICE_CHARDEV(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_DEVICE_CHARDEV)) +#define GVIR_IS_CONFIG_DEVICE_CHARDEV_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_DEVICE_CHARDEV)) +#define GVIR_CONFIG_DEVICE_CHARDEV_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_DEVICE_CHARDEV, GVirConfigDeviceChardevClass)) + +typedef struct _GVirConfigDeviceChardev GVirConfigDeviceChardev; +typedef struct _GVirConfigDeviceChardevPrivate GVirConfigDeviceChardevPrivate; +typedef struct _GVirConfigDeviceChardevClass GVirConfigDeviceChardevClass; + +struct _GVirConfigDeviceChardev +{ + GVirConfigObject parent; + + GVirConfigDeviceChardevPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigDeviceChardevClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_device_chardev_get_type(void); + +GVirConfigDeviceChardev *gvir_config_device_chardev_new(void); +GVirConfigDeviceChardev *gvir_config_device_chardev_new_from_xml(const gchar *xml, + GError **error); +void gvir_config_device_chardev_set_source(GVirConfigDeviceChardev *chardev, + GVirConfigChardevSource *source); +void gvir_config_device_chardev_set_target(GVirConfigDeviceChardev *chardev, + GVirConfigChardevTarget *target); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DEVICE_CHARDEV_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index 01c59d0..28e09b9 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -29,7 +29,10 @@ #include <libvirt-gconfig/libvirt-gconfig-object.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities.h> #include <libvirt-gconfig/libvirt-gconfig-clock.h> +#include <libvirt-gconfig/libvirt-gconfig-chardev-source.h> +#include <libvirt-gconfig/libvirt-gconfig-chardev-target.h> #include <libvirt-gconfig/libvirt-gconfig-device.h> +#include <libvirt-gconfig/libvirt-gconfig-device-chardev.h> #include <libvirt-gconfig/libvirt-gconfig-device-disk.h> #include <libvirt-gconfig/libvirt-gconfig-device-input.h> #include <libvirt-gconfig/libvirt-gconfig-device-video.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 6d895fb..fe4376b 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -4,6 +4,10 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_capabilities_new; gvir_config_capabilities_new_from_xml; + gvir_config_chardev_source_get_type; + + gvir_config_chardev_target_get_type; + gvir_config_clock_get_type; gvir_config_clock_offset_get_type; gvir_config_clock_new; @@ -29,6 +33,12 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_device_disk_set_target_dev; gvir_config_device_disk_set_type; + gvir_config_device_chardev_get_type; + gvir_config_device_chardev_new; + gvir_config_device_chardev_new_from_xml; + gvir_config_device_chardev_set_source; + gvir_config_device_chardev_set_target; + gvir_config_device_input_get_type; gvir_config_device_input_device_type_get_type; gvir_config_device_input_new; -- 1.7.7

On Thu, Nov 10, 2011 at 9:34 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
+ gvir_config_device_chardev_set_source; + gvir_config_device_chardev_set_target;
There is no definition for these symbols in this commit, you could include it here. -- Marc-André Lureau

On Fri, Nov 11, 2011 at 11:52:27PM +0100, Marc-André Lureau wrote:
On Thu, Nov 10, 2011 at 9:34 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
+ gvir_config_device_chardev_set_source; + gvir_config_device_chardev_set_target;
There is no definition for these symbols in this commit, you could include it here.
I moved these to the right commits as well as the corresponding prototypes in header files, thanks for spotting this. Christophe

--- libvirt-gconfig/libvirt-gconfig-chardev-source.c | 44 +++++++++++++++++++++- libvirt-gconfig/libvirt-gconfig-chardev-source.h | 2 + libvirt-gconfig/libvirt-gconfig-device-chardev.c | 18 +++++++++ libvirt-gconfig/libvirt-gconfig.sym | 2 + 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-chardev-source.c b/libvirt-gconfig/libvirt-gconfig-chardev-source.c index 82eff4f..cc11423 100644 --- a/libvirt-gconfig/libvirt-gconfig-chardev-source.c +++ b/libvirt-gconfig/libvirt-gconfig-chardev-source.c @@ -40,12 +40,20 @@ struct _GVirConfigChardevSourcePrivate gboolean unused; }; -G_DEFINE_ABSTRACT_TYPE(GVirConfigChardevSource, gvir_config_chardev_source, GVIR_TYPE_CONFIG_OBJECT); +struct _GVirConfigChardevSourceClassPrivate +{ + char *nick; +}; +typedef struct _GVirConfigChardevSourceClassPrivate GVirConfigChardevSourceClassPrivate; +#define GVIR_CONFIG_CHARDEV_SOURCE_CLASS_GET_PRIVATE(klass) \ + (G_TYPE_CLASS_GET_PRIVATE((klass), GVIR_TYPE_CONFIG_CHARDEV_SOURCE, GVirConfigChardevSourceClassPrivate)) + +G_DEFINE_ABSTRACT_TYPE_WITH_CODE(GVirConfigChardevSource, gvir_config_chardev_source, GVIR_TYPE_CONFIG_OBJECT, + g_type_add_class_private(g_define_type_id, sizeof(GVirConfigChardevSourceClassPrivate))); static void gvir_config_chardev_source_class_init(GVirConfigChardevSourceClass *klass) { - g_type_class_add_private(klass, sizeof(GVirConfigChardevSourcePrivate)); } @@ -60,3 +68,35 @@ static void gvir_config_chardev_source_init(GVirConfigChardevSource *chardev_sou memset(priv, 0, sizeof(*priv)); } + +const char *gvir_config_chardev_source_class_get_nick(GType type) +{ + GVirConfigChardevSourceClass *klass; + GVirConfigChardevSourceClassPrivate *priv; + + klass = g_type_class_peek(type); + if (klass == NULL) + return NULL; + + priv = GVIR_CONFIG_CHARDEV_SOURCE_CLASS_GET_PRIVATE(klass); + if (priv == NULL) + return NULL; + return priv->nick; +} + +void gvir_config_chardev_source_class_set_nick(GType type, const char *nick) +{ + GVirConfigChardevSourceClass *klass; + GVirConfigChardevSourceClassPrivate *priv; + + klass = g_type_class_ref(type); + if (klass == NULL) + return; + + priv = GVIR_CONFIG_CHARDEV_SOURCE_CLASS_GET_PRIVATE(klass); + if (priv == NULL) + return; + g_free(priv->nick); + priv->nick = g_strdup(nick); + g_type_class_unref(klass); +} diff --git a/libvirt-gconfig/libvirt-gconfig-chardev-source.h b/libvirt-gconfig/libvirt-gconfig-chardev-source.h index 5a4c8fe..e306eb2 100644 --- a/libvirt-gconfig/libvirt-gconfig-chardev-source.h +++ b/libvirt-gconfig/libvirt-gconfig-chardev-source.h @@ -58,6 +58,8 @@ struct _GVirConfigChardevSourceClass GType gvir_config_chardev_source_get_type(void); +const char *gvir_config_chardev_source_class_get_nick(GType type); +void gvir_config_chardev_source_class_set_nick(GType type, const char *nick); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig-device-chardev.c b/libvirt-gconfig/libvirt-gconfig-device-chardev.c index d4ec23f..10f3d57 100644 --- a/libvirt-gconfig/libvirt-gconfig-device-chardev.c +++ b/libvirt-gconfig/libvirt-gconfig-device-chardev.c @@ -80,3 +80,21 @@ GVirConfigDeviceChardev *gvir_config_device_chardev_new_from_xml(const gchar *xm "", NULL, xml, error); return GVIR_CONFIG_DEVICE_CHARDEV(object); } + +void gvir_config_device_chardev_set_source(GVirConfigDeviceChardev *chardev, + GVirConfigChardevSource *source) +{ + xmlNodePtr node; + xmlNodePtr source_node; + const char *source_type; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(chardev)); + source_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(source)); + if ((node == NULL) || (source_node == NULL)) + return; + source_type = gvir_config_chardev_source_class_get_nick(G_OBJECT_TYPE(source)); + g_return_if_fail(source_type != NULL); + xmlNewProp(node, (xmlChar*)"type", (xmlChar*)source_type); + + gvir_config_object_set_child(GVIR_CONFIG_OBJECT(chardev), source_node); +} diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index fe4376b..df08b59 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -5,6 +5,8 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_capabilities_new_from_xml; gvir_config_chardev_source_get_type; + gvir_config_chardev_source_class_get_nick; + gvir_config_chardev_source_class_set_nick; gvir_config_chardev_target_get_type; -- 1.7.7

On Thu, Nov 10, 2011 at 9:34 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
+ source_type = gvir_config_chardev_source_class_get_nick(G_OBJECT_TYPE(source));
I don't see why this is necessarily a class method, I virtual method would have the same result (but simpler to use). I don't understand the design of it either. Why not have the chardev type as a chardev property? Why should the child node set it when it is parented? -- Marc-André Lureau

On Sat, Nov 12, 2011 at 12:00:33AM +0100, Marc-André Lureau wrote:
On Thu, Nov 10, 2011 at 9:34 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
+ source_type = gvir_config_chardev_source_class_get_nick(G_OBJECT_TYPE(source));
I don't see why this is necessarily a class method, I virtual method would have the same result (but simpler to use).
A virtual method isn't really a good fit here since this nick really has to be the same for all instances of the same class. Imo it doesn't make much sense to have an object as a parameter (which will be needed to resolve the vfunc) while the function will return something or set something that is not specific to that particular object, but that is a common property of all the objects instanciating this class.
I don't understand the design of it either. Why not have the chardev type as a chardev property? Why should the child node set it when it is parented?
Yes chardevs are a tricky, it took me a bit of time to decide how I wanted to handle them. If you look at http://libvirt.org/formatdomain.html#elementsConsole , it starts by describing the different guest interfaces that are available (serial, parallel, ...) with (generally) an associated <target> attribute. The name of the chardev XML node corresponds to the guest device we want to define (serial, parallel, ...). Then the doc above describes the host interfaces. The host interface type is set with a "type" attribute on the root node. Then depending on this type attribute, we have a different set of possible formats for the <source> node. This is why I coupled the node name with the target attribute, and the type with the source attribute. A chardev device is really a (guest interface, host interface) couple, and most combinations are possible, that's why I chose to build the GVirConfigDeviceChardevNode by combining a GVirConfigChardevSource and a GVirConfigChardevTarget. However, your question and rereading the doc to answer you made me think more about it * it's too much of a simplification to assume the host interface will be defined by a single source node, it can go with a <protocol> node, and there can be several <source> node (see type="udp" and type="tcp") * something I'm not happy with in the current design is that it's really weird to have an empty GVirConfigDeviceChardev node, the xml node can't even have a name since it will only be known when we set a GVirConfigChardevTarget for it Maybe GVirConfigDeviceChardev should be abstract, and we should have GVirConfigDeviceChardevSerial, GVirConfigDeviceChardevConsole, ... And I'll have to think more about the first point... Hope that helps, Christophe

--- libvirt-gconfig/libvirt-gconfig-chardev-target.c | 42 +++++++++++++++++++++- libvirt-gconfig/libvirt-gconfig-chardev-target.h | 2 + libvirt-gconfig/libvirt-gconfig-device-chardev.c | 18 +++++++++ libvirt-gconfig/libvirt-gconfig.sym | 2 + 4 files changed, 63 insertions(+), 1 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-chardev-target.c b/libvirt-gconfig/libvirt-gconfig-chardev-target.c index a9e5a20..64430ea 100644 --- a/libvirt-gconfig/libvirt-gconfig-chardev-target.c +++ b/libvirt-gconfig/libvirt-gconfig-chardev-target.c @@ -40,8 +40,16 @@ struct _GVirConfigChardevTargetPrivate gboolean unused; }; -G_DEFINE_ABSTRACT_TYPE(GVirConfigChardevTarget, gvir_config_chardev_target, GVIR_TYPE_CONFIG_OBJECT); +struct _GVirConfigChardevTargetClassPrivate +{ + char *nick; +}; +typedef struct _GVirConfigChardevTargetClassPrivate GVirConfigChardevTargetClassPrivate; +#define GVIR_CONFIG_CHARDEV_TARGET_CLASS_GET_PRIVATE(klass) \ + (G_TYPE_CLASS_GET_PRIVATE((klass), GVIR_TYPE_CONFIG_CHARDEV_TARGET, GVirConfigChardevTargetClassPrivate)) +G_DEFINE_ABSTRACT_TYPE_WITH_CODE(GVirConfigChardevTarget, gvir_config_chardev_target, GVIR_TYPE_CONFIG_OBJECT, + g_type_add_class_private(g_define_type_id, sizeof(GVirConfigChardevTargetClassPrivate))); static void gvir_config_chardev_target_class_init(GVirConfigChardevTargetClass *klass) { @@ -60,3 +68,35 @@ static void gvir_config_chardev_target_init(GVirConfigChardevTarget *chardev_tar memset(priv, 0, sizeof(*priv)); } + +const char *gvir_config_chardev_target_class_get_nick(GType type) +{ + GVirConfigChardevTargetClass *klass; + GVirConfigChardevTargetClassPrivate *priv; + + klass = g_type_class_peek(type); + if (klass == NULL) + return NULL; + + priv = GVIR_CONFIG_CHARDEV_TARGET_CLASS_GET_PRIVATE(klass); + if (priv == NULL) + return NULL; + return priv->nick; +} + +void gvir_config_chardev_target_class_set_nick(GType type, const char *nick) +{ + GVirConfigChardevTargetClass *klass; + GVirConfigChardevTargetClassPrivate *priv; + + klass = g_type_class_ref(type); + if (klass == NULL) + return; + + priv = GVIR_CONFIG_CHARDEV_TARGET_CLASS_GET_PRIVATE(klass); + if (priv == NULL) + return; + g_free(priv->nick); + priv->nick = g_strdup(nick); + g_type_class_unref(klass); +} diff --git a/libvirt-gconfig/libvirt-gconfig-chardev-target.h b/libvirt-gconfig/libvirt-gconfig-chardev-target.h index 41fd875..53a10a1 100644 --- a/libvirt-gconfig/libvirt-gconfig-chardev-target.h +++ b/libvirt-gconfig/libvirt-gconfig-chardev-target.h @@ -58,6 +58,8 @@ struct _GVirConfigChardevTargetClass GType gvir_config_chardev_target_get_type(void); +const char *gvir_config_chardev_target_class_get_nick(GType type); +void gvir_config_chardev_target_class_set_nick(GType type, const char *nick); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig-device-chardev.c b/libvirt-gconfig/libvirt-gconfig-device-chardev.c index 10f3d57..62859fe 100644 --- a/libvirt-gconfig/libvirt-gconfig-device-chardev.c +++ b/libvirt-gconfig/libvirt-gconfig-device-chardev.c @@ -98,3 +98,21 @@ void gvir_config_device_chardev_set_source(GVirConfigDeviceChardev *chardev, gvir_config_object_set_child(GVIR_CONFIG_OBJECT(chardev), source_node); } + +void gvir_config_device_chardev_set_target(GVirConfigDeviceChardev *chardev, + GVirConfigChardevTarget *target) +{ + xmlNodePtr node; + xmlNodePtr target_node; + const char *target_type; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(chardev)); + target_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(target)); + if ((node == NULL) || (target_node == NULL)) + return; + target_type = gvir_config_chardev_target_class_get_nick(G_OBJECT_TYPE(target)); + g_return_if_fail(target_type != NULL); + xmlNodeSetName(node, (xmlChar*)target_type); + + gvir_config_object_set_child(GVIR_CONFIG_OBJECT(chardev), target_node); +} diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index df08b59..0889a53 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -9,6 +9,8 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_chardev_source_class_set_nick; gvir_config_chardev_target_get_type; + gvir_config_chardev_target_class_get_nick; + gvir_config_chardev_target_class_set_nick; gvir_config_clock_get_type; gvir_config_clock_offset_get_type; -- 1.7.7

--- libvirt-gconfig/Makefile.am | 2 + .../libvirt-gconfig-chardev-source-pty.c | 82 ++++++++++++++++++++ .../libvirt-gconfig-chardev-source-pty.h | 68 ++++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 4 + 5 files changed, 157 insertions(+), 0 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-chardev-source-pty.c create mode 100644 libvirt-gconfig/libvirt-gconfig-chardev-source-pty.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 3144955..8df46f5 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -12,6 +12,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-object.h \ libvirt-gconfig-capabilities.h \ libvirt-gconfig-chardev-source.h \ + libvirt-gconfig-chardev-source-pty.h \ libvirt-gconfig-chardev-target.h \ libvirt-gconfig-clock.h \ libvirt-gconfig-device.h \ @@ -39,6 +40,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-object.c \ libvirt-gconfig-capabilities.c \ libvirt-gconfig-chardev-source.c \ + libvirt-gconfig-chardev-source-pty.c \ libvirt-gconfig-chardev-target.c \ libvirt-gconfig-clock.c \ libvirt-gconfig-device.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-chardev-source-pty.c b/libvirt-gconfig/libvirt-gconfig-chardev-source-pty.c new file mode 100644 index 0000000..f0a2c8d --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-chardev-source-pty.c @@ -0,0 +1,82 @@ +/* + * libvirt-gobject-config-chardev-source-pty.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@gmail.com> + */ + +#include <config.h> + +#include <string.h> + +#include <libxml/tree.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" + +extern gboolean debugFlag; + +#define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0) + +#define GVIR_CONFIG_CHARDEV_SOURCE_PTY_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_CHARDEV_SOURCE_PTY, GVirConfigChardevSourcePtyPrivate)) + +struct _GVirConfigChardevSourcePtyPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigChardevSourcePty, gvir_config_chardev_source_pty, GVIR_TYPE_CONFIG_CHARDEV_SOURCE); + + +static void gvir_config_chardev_source_pty_class_init(GVirConfigChardevSourcePtyClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigChardevSourcePtyPrivate)); + gvir_config_chardev_source_class_set_nick(GVIR_TYPE_CONFIG_CHARDEV_SOURCE_PTY, "pty"); +} + + +static void gvir_config_chardev_source_pty_init(GVirConfigChardevSourcePty *pty) +{ + GVirConfigChardevSourcePtyPrivate *priv; + + DEBUG("Init GVirConfigChardevSourcePty=%p", pty); + + priv = pty->priv = GVIR_CONFIG_CHARDEV_SOURCE_PTY_GET_PRIVATE(pty); + + memset(priv, 0, sizeof(*priv)); +} + + +GVirConfigChardevSourcePty *gvir_config_chardev_source_pty_new(void) +{ + GVirConfigObject *object; + + object = gvir_config_object_new(GVIR_TYPE_CONFIG_CHARDEV_SOURCE_PTY, + "source", NULL); + return GVIR_CONFIG_CHARDEV_SOURCE_PTY(object); +} + +GVirConfigChardevSourcePty *gvir_config_chardev_source_pty_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_CHARDEV_SOURCE_PTY, + "source", NULL, xml, error); + return GVIR_CONFIG_CHARDEV_SOURCE_PTY(object); +} diff --git a/libvirt-gconfig/libvirt-gconfig-chardev-source-pty.h b/libvirt-gconfig/libvirt-gconfig-chardev-source-pty.h new file mode 100644 index 0000000..39b40bc --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-chardev-source-pty.h @@ -0,0 +1,68 @@ +/* + * libvirt-gobject-chardev-source-pty.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@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_CHARDEV_SOURCE_PTY_H__ +#define __LIBVIRT_GCONFIG_CHARDEV_SOURCE_PTY_H__ + +G_BEGIN_DECLS + +#define GVIR_TYPE_CONFIG_CHARDEV_SOURCE_PTY (gvir_config_chardev_source_pty_get_type ()) +#define GVIR_CONFIG_CHARDEV_SOURCE_PTY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_CHARDEV_SOURCE_PTY, GVirConfigChardevSourcePty)) +#define GVIR_CONFIG_CHARDEV_SOURCE_PTY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_CHARDEV_SOURCE_PTY, GVirConfigChardevSourcePtyClass)) +#define GVIR_IS_CONFIG_CHARDEV_SOURCE_PTY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_CHARDEV_SOURCE_PTY)) +#define GVIR_IS_CONFIG_CHARDEV_SOURCE_PTY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_CHARDEV_SOURCE_PTY)) +#define GVIR_CONFIG_CHARDEV_SOURCE_PTY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_CHARDEV_SOURCE_PTY, GVirConfigChardevSourcePtyClass)) + +typedef struct _GVirConfigChardevSourcePty GVirConfigChardevSourcePty; +typedef struct _GVirConfigChardevSourcePtyPrivate GVirConfigChardevSourcePtyPrivate; +typedef struct _GVirConfigChardevSourcePtyClass GVirConfigChardevSourcePtyClass; + +struct _GVirConfigChardevSourcePty +{ + GVirConfigObject parent; + + GVirConfigChardevSourcePtyPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigChardevSourcePtyClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + + +GType gvir_config_chardev_source_pty_get_type(void); + +GVirConfigChardevSourcePty *gvir_config_chardev_source_pty_new(void); +GVirConfigChardevSourcePty *gvir_config_chardev_source_pty_new_from_xml(const gchar *xml, + GError **error); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CHARDEV_SOURCE_PTY_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index 28e09b9..0d338d7 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -30,6 +30,7 @@ #include <libvirt-gconfig/libvirt-gconfig-capabilities.h> #include <libvirt-gconfig/libvirt-gconfig-clock.h> #include <libvirt-gconfig/libvirt-gconfig-chardev-source.h> +#include <libvirt-gconfig/libvirt-gconfig-chardev-source-pty.h> #include <libvirt-gconfig/libvirt-gconfig-chardev-target.h> #include <libvirt-gconfig/libvirt-gconfig-device.h> #include <libvirt-gconfig/libvirt-gconfig-device-chardev.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 0889a53..c9bdd96 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -8,6 +8,10 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_chardev_source_class_get_nick; gvir_config_chardev_source_class_set_nick; + gvir_config_chardev_source_pty_get_type; + gvir_config_chardev_source_pty_new; + gvir_config_chardev_source_pty_new_from_xml; + gvir_config_chardev_target_get_type; gvir_config_chardev_target_class_get_nick; gvir_config_chardev_target_class_set_nick; -- 1.7.7

--- libvirt-gconfig/Makefile.am | 2 + .../libvirt-gconfig-chardev-target-console.c | 83 ++++++++++++++++++++ .../libvirt-gconfig-chardev-target-console.h | 68 ++++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 4 + 5 files changed, 158 insertions(+), 0 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-chardev-target-console.c create mode 100644 libvirt-gconfig/libvirt-gconfig-chardev-target-console.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 8df46f5..12e78fb 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -14,6 +14,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-chardev-source.h \ libvirt-gconfig-chardev-source-pty.h \ libvirt-gconfig-chardev-target.h \ + libvirt-gconfig-chardev-target-console.h \ libvirt-gconfig-clock.h \ libvirt-gconfig-device.h \ libvirt-gconfig-device-chardev.h \ @@ -42,6 +43,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-chardev-source.c \ libvirt-gconfig-chardev-source-pty.c \ libvirt-gconfig-chardev-target.c \ + libvirt-gconfig-chardev-target-console.c \ libvirt-gconfig-clock.c \ libvirt-gconfig-device.c \ libvirt-gconfig-device-chardev.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-chardev-target-console.c b/libvirt-gconfig/libvirt-gconfig-chardev-target-console.c new file mode 100644 index 0000000..6e9a555 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-chardev-target-console.c @@ -0,0 +1,83 @@ +/* + * libvirt-gobject-config-chardev-target-console.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@gmail.com> + */ + +#include <config.h> + +#include <string.h> + +#include <libxml/tree.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" + +extern gboolean debugFlag; + +#define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0) + +#define GVIR_CONFIG_CHARDEV_TARGET_CONSOLE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_CHARDEV_TARGET_CONSOLE, GVirConfigChardevTargetConsolePrivate)) + +struct _GVirConfigChardevTargetConsolePrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigChardevTargetConsole, gvir_config_chardev_target_console, GVIR_TYPE_CONFIG_CHARDEV_TARGET); + + +static void gvir_config_chardev_target_console_class_init(GVirConfigChardevTargetConsoleClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigChardevTargetConsolePrivate)); + gvir_config_chardev_target_class_set_nick(GVIR_TYPE_CONFIG_CHARDEV_TARGET_CONSOLE, + "console"); +} + + +static void gvir_config_chardev_target_console_init(GVirConfigChardevTargetConsole *chardev_target_console) +{ + GVirConfigChardevTargetConsolePrivate *priv; + + DEBUG("Init GVirConfigChardevTargetConsole=%p", chardev_target_console); + + priv = chardev_target_console->priv = GVIR_CONFIG_CHARDEV_TARGET_CONSOLE_GET_PRIVATE(chardev_target_console); + + memset(priv, 0, sizeof(*priv)); +} + + +GVirConfigChardevTargetConsole *gvir_config_chardev_target_console_new(void) +{ + GVirConfigObject *object; + + object = gvir_config_object_new(GVIR_TYPE_CONFIG_CHARDEV_TARGET_CONSOLE, + "target", NULL); + return GVIR_CONFIG_CHARDEV_TARGET_CONSOLE(object); +} + +GVirConfigChardevTargetConsole *gvir_config_chardev_target_console_new_from_xml(gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_CHARDEV_TARGET_CONSOLE, + "target", NULL, xml, error); + return GVIR_CONFIG_CHARDEV_TARGET_CONSOLE(object); +} diff --git a/libvirt-gconfig/libvirt-gconfig-chardev-target-console.h b/libvirt-gconfig/libvirt-gconfig-chardev-target-console.h new file mode 100644 index 0000000..c340690 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-chardev-target-console.h @@ -0,0 +1,68 @@ +/* + * libvirt-gobject-chardev-target-console.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@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_CHARDEV_TARGET_CONSOLE_H__ +#define __LIBVIRT_GCONFIG_CHARDEV_TARGET_CONSOLE_H__ + +G_BEGIN_DECLS + +#define GVIR_TYPE_CONFIG_CHARDEV_TARGET_CONSOLE (gvir_config_chardev_target_console_get_type ()) +#define GVIR_CONFIG_CHARDEV_TARGET_CONSOLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_CHARDEV_TARGET_CONSOLE, GVirConfigChardevTargetConsole)) +#define GVIR_CONFIG_CHARDEV_TARGET_CONSOLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_CHARDEV_TARGET_CONSOLE, GVirConfigChardevTargetConsoleClass)) +#define GVIR_IS_CONFIG_CHARDEV_TARGET_CONSOLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_CHARDEV_TARGET_CONSOLE)) +#define GVIR_IS_CONFIG_CHARDEV_TARGET_CONSOLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_CHARDEV_TARGET_CONSOLE)) +#define GVIR_CONFIG_CHARDEV_TARGET_CONSOLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_CHARDEV_TARGET_CONSOLE, GVirConfigChardevTargetConsoleClass)) + +typedef struct _GVirConfigChardevTargetConsole GVirConfigChardevTargetConsole; +typedef struct _GVirConfigChardevTargetConsolePrivate GVirConfigChardevTargetConsolePrivate; +typedef struct _GVirConfigChardevTargetConsoleClass GVirConfigChardevTargetConsoleClass; + +struct _GVirConfigChardevTargetConsole +{ + GVirConfigObject parent; + + GVirConfigChardevTargetConsolePrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigChardevTargetConsoleClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + + +GType gvir_config_chardev_target_console_get_type(void); + +GVirConfigChardevTargetConsole *gvir_config_chardev_target_console_new(void); +GVirConfigChardevTargetConsole *gvir_config_chardev_target_console_new_from_xml(gchar *xml, + GError **error); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CHARDEV_TARGET_CONSOLE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index 0d338d7..8b4cb62 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -32,6 +32,7 @@ #include <libvirt-gconfig/libvirt-gconfig-chardev-source.h> #include <libvirt-gconfig/libvirt-gconfig-chardev-source-pty.h> #include <libvirt-gconfig/libvirt-gconfig-chardev-target.h> +#include <libvirt-gconfig/libvirt-gconfig-chardev-target-console.h> #include <libvirt-gconfig/libvirt-gconfig-device.h> #include <libvirt-gconfig/libvirt-gconfig-device-chardev.h> #include <libvirt-gconfig/libvirt-gconfig-device-disk.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index c9bdd96..cee96ca 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -16,6 +16,10 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_chardev_target_class_get_nick; gvir_config_chardev_target_class_set_nick; + gvir_config_chardev_target_console_get_type; + gvir_config_chardev_target_console_new; + gvir_config_chardev_target_console_new_from_xml; + gvir_config_clock_get_type; gvir_config_clock_offset_get_type; gvir_config_clock_new; -- 1.7.7

--- libvirt-gconfig/tests/test-domain-create.c | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-) diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index ba08a9f..cca3316 100644 --- a/libvirt-gconfig/tests/test-domain-create.c +++ b/libvirt-gconfig/tests/test-domain-create.c @@ -127,13 +127,30 @@ int main(void) GVIR_CONFIG_DEVICE_VIDEO_MODEL_QXL); devices = g_list_append(devices, GVIR_CONFIG_DEVICE(video)); + /* console node */ + GVirConfigDeviceChardev *chardev; + GVirConfigChardevTargetConsole *console; + GVirConfigChardevSourcePty *pty; + chardev = gvir_config_device_chardev_new(); + pty = gvir_config_chardev_source_pty_new(); + gvir_config_device_chardev_set_source(chardev, + GVIR_CONFIG_CHARDEV_SOURCE(pty)); + + console = gvir_config_chardev_target_console_new(); + gvir_config_device_chardev_set_target(chardev, + GVIR_CONFIG_CHARDEV_TARGET(console)); + devices = g_list_append(devices, GVIR_CONFIG_DEVICE(chardev)); + + + /* attach devices to domain */ gvir_config_domain_set_devices(domain, devices); g_list_free(devices); devices = NULL; + xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(domain)); g_print("%s\n", xml); g_free(xml); -- 1.7.7

hi The functions declaration should be put in -private.h . Marking definition G_GNUC_INTERNAL would also make it more obvious. It would also less confuse gir-scanner which doesn't know about libxml types. On Thu, Nov 10, 2011 at 9:33 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
This allows us to factor the code to add an XML node to a config object. --- libvirt-gconfig/libvirt-gconfig-object.c | 72 ++++++++++++++++++------------ libvirt-gconfig/libvirt-gconfig-object.h | 4 ++ libvirt-gconfig/libvirt-gconfig.h | 2 +- 3 files changed, 49 insertions(+), 29 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c index fbdbedd..598ac0c 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.c +++ b/libvirt-gconfig/libvirt-gconfig-object.c @@ -294,35 +294,62 @@ char *gvir_config_object_get_node_content(GVirConfigObject *object, return gvir_config_xml_get_child_element_content_glib(node, node_name); }
-/* FIXME: if there are multiple nodes with the same name, this function - * won't behave as expected. Should we get rid of the duplicated node names - * here? - */ -void gvir_config_object_set_node_content(GVirConfigObject *object, - const char *node_name, - const char *value) +void +gvir_config_object_set_child(GVirConfigObject *object, xmlNodePtr child) { xmlNodePtr parent_node; xmlNodePtr old_node; - xmlNodePtr new_node; - xmlChar *encoded_name;
parent_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(object)); - encoded_name = xmlEncodeEntitiesReentrant(parent_node->doc, - (xmlChar *)value); - new_node = xmlNewDocNode(parent_node->doc, NULL, - (xmlChar *)node_name, encoded_name); - xmlFree(encoded_name); + g_return_if_fail (parent_node != NULL);
- old_node = gvir_config_xml_get_element(parent_node, node_name, NULL); + old_node = gvir_config_xml_get_element(parent_node, child->name, NULL); + /* FIXME: should we make sure there are no multiple occurrences + * of this node? + */ if (old_node) { - old_node = xmlReplaceNode(old_node, new_node); + old_node = xmlReplaceNode(old_node, child); xmlFreeNode(old_node); } else { - xmlAddChild(parent_node, new_node); + xmlAddChild(parent_node, child); } }
+xmlNodePtr +gvir_config_object_new_child(GVirConfigObject *object, const char *child_name) +{ + xmlNodePtr new_node; + + new_node = xmlNewDocNode(NULL, NULL, (xmlChar *)child_name, NULL); + gvir_config_object_set_child(object, new_node); + return new_node; +} + +void gvir_config_object_set_node_content(GVirConfigObject *object, + const char *node_name, + const char *value) +{ + xmlNodePtr node; + xmlChar *encoded_data; + + node = gvir_config_object_new_child(object, node_name); + g_return_if_fail(node != NULL); + encoded_data = xmlEncodeEntitiesReentrant(node->doc, + (xmlChar *)value); + xmlNodeSetContent(node, encoded_data); + xmlFree(encoded_data); +} + +void gvir_config_object_set_node_content_uint64(GVirConfigObject *object, + const char *node_name, + guint64 value) +{ + char *str; + str = g_strdup_printf("%"G_GUINT64_FORMAT, value); + gvir_config_object_set_node_content(object, node_name, str); + g_free(str); +} + /* FIXME: how to notify of errors/node not found? */ guint64 gvir_config_object_get_node_content_uint64(GVirConfigObject *object, const char *node_name) @@ -345,17 +372,6 @@ guint64 gvir_config_object_get_node_content_uint64(GVirConfigObject *object, return value; }
- -void gvir_config_object_set_node_content_uint64(GVirConfigObject *object, - const char *node_name, - guint64 value) -{ - char *str; - str = g_strdup_printf("%"G_GUINT64_FORMAT, value); - gvir_config_object_set_node_content(object, node_name, str); - g_free(str); -} - GVirConfigObject *gvir_config_object_new_from_xml(GType type, const char *root_name, const char *schema, diff --git a/libvirt-gconfig/libvirt-gconfig-object.h b/libvirt-gconfig/libvirt-gconfig-object.h index 52e4525..8e67b92 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.h +++ b/libvirt-gconfig/libvirt-gconfig-object.h @@ -78,6 +78,10 @@ char *gvir_config_object_get_node_content(GVirConfigObject *object, const char *node_name); guint64 gvir_config_object_get_node_content_uint64(GVirConfigObject *object, const char *node_name); +xmlNodePtr gvir_config_object_new_child(GVirConfigObject *object, + const char *child_name); +void gvir_config_object_set_child(GVirConfigObject *object, + xmlNodePtr child); void gvir_config_object_set_node_content(GVirConfigObject *object, const char *node_name, const char *value); diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index fdc78a4..4e23f0d 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -26,11 +26,11 @@ #include <glib-object.h> #include <libxml/tree.h>
-#include <libvirt-gconfig/libvirt-gconfig-helpers.h> #include <libvirt-gconfig/libvirt-gconfig-object.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities.h> #include <libvirt-gconfig/libvirt-gconfig-domain.h> #include <libvirt-gconfig/libvirt-gconfig-domain-snapshot.h> +#include <libvirt-gconfig/libvirt-gconfig-helpers.h> #include <libvirt-gconfig/libvirt-gconfig-interface.h> #include <libvirt-gconfig/libvirt-gconfig-network.h> #include <libvirt-gconfig/libvirt-gconfig-node-device.h> -- 1.7.7
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
-- Marc-André Lureau

Hey, On Fri, Nov 11, 2011 at 03:28:34PM +0100, Marc-André Lureau wrote:
The functions declaration should be put in -private.h . Marking definition G_GNUC_INTERNAL would also make it more obvious.
It would also less confuse gir-scanner which doesn't know about libxml types.
At this point, I'm undecided whether these functions should be private or not. Having some way to directly manipulate the XML data can be useful when you want to generate some config data not yet handled by libvirt-gconfig, but on the other hand, it makes it really easy to shoot yourself in the foot. I'm fine with marking them private for now. Christophe
On Thu, Nov 10, 2011 at 9:33 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
This allows us to factor the code to add an XML node to a config object. --- libvirt-gconfig/libvirt-gconfig-object.c | 72 ++++++++++++++++++------------ libvirt-gconfig/libvirt-gconfig-object.h | 4 ++ libvirt-gconfig/libvirt-gconfig.h | 2 +- 3 files changed, 49 insertions(+), 29 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c index fbdbedd..598ac0c 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.c +++ b/libvirt-gconfig/libvirt-gconfig-object.c @@ -294,35 +294,62 @@ char *gvir_config_object_get_node_content(GVirConfigObject *object, return gvir_config_xml_get_child_element_content_glib(node, node_name); }
-/* FIXME: if there are multiple nodes with the same name, this function - * won't behave as expected. Should we get rid of the duplicated node names - * here? - */ -void gvir_config_object_set_node_content(GVirConfigObject *object, - const char *node_name, - const char *value) +void +gvir_config_object_set_child(GVirConfigObject *object, xmlNodePtr child) { xmlNodePtr parent_node; xmlNodePtr old_node; - xmlNodePtr new_node; - xmlChar *encoded_name;
parent_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(object)); - encoded_name = xmlEncodeEntitiesReentrant(parent_node->doc, - (xmlChar *)value); - new_node = xmlNewDocNode(parent_node->doc, NULL, - (xmlChar *)node_name, encoded_name); - xmlFree(encoded_name); + g_return_if_fail (parent_node != NULL);
- old_node = gvir_config_xml_get_element(parent_node, node_name, NULL); + old_node = gvir_config_xml_get_element(parent_node, child->name, NULL); + /* FIXME: should we make sure there are no multiple occurrences + * of this node? + */ if (old_node) { - old_node = xmlReplaceNode(old_node, new_node); + old_node = xmlReplaceNode(old_node, child); xmlFreeNode(old_node); } else { - xmlAddChild(parent_node, new_node); + xmlAddChild(parent_node, child); } }
+xmlNodePtr +gvir_config_object_new_child(GVirConfigObject *object, const char *child_name) +{ + xmlNodePtr new_node; + + new_node = xmlNewDocNode(NULL, NULL, (xmlChar *)child_name, NULL); + gvir_config_object_set_child(object, new_node); + return new_node; +} + +void gvir_config_object_set_node_content(GVirConfigObject *object, + const char *node_name, + const char *value) +{ + xmlNodePtr node; + xmlChar *encoded_data; + + node = gvir_config_object_new_child(object, node_name); + g_return_if_fail(node != NULL); + encoded_data = xmlEncodeEntitiesReentrant(node->doc, + (xmlChar *)value); + xmlNodeSetContent(node, encoded_data); + xmlFree(encoded_data); +} + +void gvir_config_object_set_node_content_uint64(GVirConfigObject *object, + const char *node_name, + guint64 value) +{ + char *str; + str = g_strdup_printf("%"G_GUINT64_FORMAT, value); + gvir_config_object_set_node_content(object, node_name, str); + g_free(str); +} + /* FIXME: how to notify of errors/node not found? */ guint64 gvir_config_object_get_node_content_uint64(GVirConfigObject *object, const char *node_name) @@ -345,17 +372,6 @@ guint64 gvir_config_object_get_node_content_uint64(GVirConfigObject *object, return value; }
- -void gvir_config_object_set_node_content_uint64(GVirConfigObject *object, - const char *node_name, - guint64 value) -{ - char *str; - str = g_strdup_printf("%"G_GUINT64_FORMAT, value); - gvir_config_object_set_node_content(object, node_name, str); - g_free(str); -} - GVirConfigObject *gvir_config_object_new_from_xml(GType type, const char *root_name, const char *schema, diff --git a/libvirt-gconfig/libvirt-gconfig-object.h b/libvirt-gconfig/libvirt-gconfig-object.h index 52e4525..8e67b92 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.h +++ b/libvirt-gconfig/libvirt-gconfig-object.h @@ -78,6 +78,10 @@ char *gvir_config_object_get_node_content(GVirConfigObject *object, const char *node_name); guint64 gvir_config_object_get_node_content_uint64(GVirConfigObject *object, const char *node_name); +xmlNodePtr gvir_config_object_new_child(GVirConfigObject *object, + const char *child_name); +void gvir_config_object_set_child(GVirConfigObject *object, + xmlNodePtr child); void gvir_config_object_set_node_content(GVirConfigObject *object, const char *node_name, const char *value); diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index fdc78a4..4e23f0d 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -26,11 +26,11 @@ #include <glib-object.h> #include <libxml/tree.h>
-#include <libvirt-gconfig/libvirt-gconfig-helpers.h> #include <libvirt-gconfig/libvirt-gconfig-object.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities.h> #include <libvirt-gconfig/libvirt-gconfig-domain.h> #include <libvirt-gconfig/libvirt-gconfig-domain-snapshot.h> +#include <libvirt-gconfig/libvirt-gconfig-helpers.h> #include <libvirt-gconfig/libvirt-gconfig-interface.h> #include <libvirt-gconfig/libvirt-gconfig-network.h> #include <libvirt-gconfig/libvirt-gconfig-node-device.h> -- 1.7.7
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
-- Marc-André Lureau

On Tue, Nov 15, 2011 at 12:15:17PM +0100, Christophe Fergeau wrote:
Hey,
On Fri, Nov 11, 2011 at 03:28:34PM +0100, Marc-André Lureau wrote:
The functions declaration should be put in -private.h . Marking definition G_GNUC_INTERNAL would also make it more obvious.
It would also less confuse gir-scanner which doesn't know about libxml types.
At this point, I'm undecided whether these functions should be private or not. Having some way to directly manipulate the XML data can be useful when you want to generate some config data not yet handled by libvirt-gconfig, but on the other hand, it makes it really easy to shoot yourself in the foot. I'm fine with marking them private for now.
Yep, lets be conservative and make them private. If we find a compelling case where we need them public in the future, we can easily revisit the decision. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (3)
-
Christophe Fergeau
-
Daniel P. Berrange
-
Marc-André Lureau