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