--- 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 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list