From: "Zeeshan Ali (Khattak)" <zeeshanak@xxxxxxxxx> - gvir_config_object_add_child_with_type() - gvir_config_object_get_child() - gvir_config_object_get_child_with_type() --- libvirt-gconfig/libvirt-gconfig-object-private.h | 8 ++++ libvirt-gconfig/libvirt-gconfig-object.c | 47 ++++++++++++++++++++-- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-object-private.h b/libvirt-gconfig/libvirt-gconfig-object-private.h index a6b7395..eb2cc09 100644 --- a/libvirt-gconfig/libvirt-gconfig-object-private.h +++ b/libvirt-gconfig/libvirt-gconfig-object-private.h @@ -55,6 +55,9 @@ void gvir_config_object_set_node_content_uint64(GVirConfigObject *object, guint64 value); GVirConfigObject *gvir_config_object_add_child(GVirConfigObject *object, const char *child_name); +GVirConfigObject *gvir_config_object_add_child_with_type(GVirConfigObject *object, + const char *child_name, + GType child_type); void gvir_config_object_add_child_with_attribute(GVirConfigObject *object, const char *child_name, const char *attr_name, @@ -96,6 +99,11 @@ void gvir_config_object_foreach_child(GVirConfigObject *object, gboolean gvir_config_object_set_namespace(GVirConfigObject *object, const char *ns, const char *ns_uri); +GVirConfigObject *gvir_config_object_get_child(GVirConfigObject *object, + const gchar *child_name); +GVirConfigObject *gvir_config_object_get_child_with_type(GVirConfigObject *object, + const gchar *child_name, + GType child_type); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c index ee3584a..3dac59a 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.c +++ b/libvirt-gconfig/libvirt-gconfig-object.c @@ -366,8 +366,9 @@ gvir_config_object_foreach_child(GVirConfigObject *object, } G_GNUC_INTERNAL GVirConfigObject * -gvir_config_object_add_child(GVirConfigObject *object, - const char *child_name) +gvir_config_object_add_child_with_type(GVirConfigObject *object, + const char *child_name, + GType child_type) { xmlNodePtr new_node; xmlNodePtr old_node; @@ -380,18 +381,27 @@ gvir_config_object_add_child(GVirConfigObject *object, FALSE); if (old_node != NULL) { xmlFreeNode(new_node); - return GVIR_CONFIG_OBJECT(g_object_new(GVIR_CONFIG_TYPE_OBJECT, + return GVIR_CONFIG_OBJECT(g_object_new(child_type, "doc", object->priv->doc, "node", old_node, NULL)); } - return GVIR_CONFIG_OBJECT(g_object_new(GVIR_CONFIG_TYPE_OBJECT, + return GVIR_CONFIG_OBJECT(g_object_new(child_type, "doc", object->priv->doc, "node", new_node, NULL)); } +G_GNUC_INTERNAL GVirConfigObject * +gvir_config_object_add_child(GVirConfigObject *object, + const char *child_name) +{ + return gvir_config_object_add_child_with_type(object, + child_name, + GVIR_CONFIG_TYPE_OBJECT); +} + G_GNUC_INTERNAL void gvir_config_object_add_child_with_attribute(GVirConfigObject *object, const char *child_name, @@ -865,3 +875,32 @@ gvir_config_object_set_namespace(GVirConfigObject *object, const char *ns, return TRUE; } + +G_GNUC_INTERNAL GVirConfigObject * +gvir_config_object_get_child_with_type(GVirConfigObject *object, + const gchar *child_name, + GType child_type) +{ + xmlNodePtr node; + + g_return_val_if_fail(GVIR_CONFIG_IS_OBJECT(object), NULL); + g_return_val_if_fail(child_name != NULL, NULL); + + node = gvir_config_xml_get_element(object->priv->node, child_name, NULL); + g_return_val_if_fail(node != NULL, NULL); + + return gvir_config_object_new_from_tree(child_type, + object->priv->doc, + object->priv->schema, + node); +} + +G_GNUC_INTERNAL GVirConfigObject * +gvir_config_object_get_child(GVirConfigObject *object, + const gchar *child_name) +{ + return gvir_config_object_get_child_with_type(object, + child_name, + GVIR_CONFIG_TYPE_OBJECT); +} + -- 1.7.7.6 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list