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

[libvirt] [libvirt-glib 1/4] More generic gvir_config_object_add_child()



From: "Zeeshan Ali (Khattak)" <zeeshanak gnome org>

---
 libvirt-gconfig/libvirt-gconfig-domain-channel.c   |    6 ++++--
 libvirt-gconfig/libvirt-gconfig-domain-console.c   |    3 ++-
 libvirt-gconfig/libvirt-gconfig-domain-disk.c      |   18 ++++++++++++------
 libvirt-gconfig/libvirt-gconfig-domain-filesys.c   |    6 ++++--
 libvirt-gconfig/libvirt-gconfig-domain.c           |    6 ++++--
 libvirt-gconfig/libvirt-gconfig-object-private.h   |    5 ++++-
 libvirt-gconfig/libvirt-gconfig-object.c           |   13 ++++++++-----
 .../libvirt-gconfig-storage-pool-source.c          |    3 ++-
 8 files changed, 40 insertions(+), 20 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-domain-channel.c b/libvirt-gconfig/libvirt-gconfig-domain-channel.c
index a4f9527..f81cea2 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-channel.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-channel.c
@@ -77,7 +77,8 @@ void gvir_config_domain_channel_set_target_type(GVirConfigDomainChannel *channel
     g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_CHANNEL(channel));
 
     gvir_config_object_add_child_with_attribute_enum(GVIR_CONFIG_OBJECT(channel),
-                                                     "target", "type",
+                                                     "target", GVIR_CONFIG_TYPE_OBJECT,
+                                                     "type",
                                                      GVIR_CONFIG_TYPE_DOMAIN_CHANNEL_TARGET_TYPE,
                                                      type);
 }
@@ -89,5 +90,6 @@ void gvir_config_domain_channel_set_target_name(GVirConfigDomainChannel *channel
     g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_CHANNEL(channel));
 
     gvir_config_object_add_child_with_attribute(GVIR_CONFIG_OBJECT(channel),
-                                                "target", "name", name);
+                                                "target", GVIR_CONFIG_TYPE_OBJECT,
+                                                "name", name);
 }
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-console.c b/libvirt-gconfig/libvirt-gconfig-domain-console.c
index db97322..954f9d2 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-console.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-console.c
@@ -76,7 +76,8 @@ void gvir_config_domain_console_set_target_type(GVirConfigDomainConsole *console
     g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_CONSOLE(console));
 
     gvir_config_object_add_child_with_attribute_enum(GVIR_CONFIG_OBJECT(console),
-                                                     "target", "type",
+                                                     "target", GVIR_CONFIG_TYPE_OBJECT,
+                                                     "type",
                                                      GVIR_CONFIG_TYPE_DOMAIN_CONSOLE_TARGET_TYPE,
                                                      type);
 }
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.c b/libvirt-gconfig/libvirt-gconfig-domain-disk.c
index a29ea47..d5a5b70 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-disk.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.c
@@ -136,7 +136,8 @@ void gvir_config_domain_disk_set_startup_policy(GVirConfigDomainDisk *disk,
     str = gvir_config_genum_get_nick(GVIR_CONFIG_TYPE_DOMAIN_DISK_STARTUP_POLICY, policy);
     g_return_if_fail(str != NULL);
     gvir_config_object_add_child_with_attribute(GVIR_CONFIG_OBJECT(disk),
-                                                "source", "startupPolicy", str);
+                                                "source", GVIR_CONFIG_TYPE_OBJECT,
+                                                "startupPolicy", str);
 }
 
 void gvir_config_domain_disk_set_source(GVirConfigDomainDisk *disk,
@@ -172,7 +173,8 @@ void gvir_config_domain_disk_set_driver_name(GVirConfigDomainDisk *disk,
 {
     g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK(disk));
     gvir_config_object_add_child_with_attribute(GVIR_CONFIG_OBJECT(disk),
-                                                "driver", "name", driver_name);
+                                                "driver", GVIR_CONFIG_TYPE_OBJECT,
+                                                "name", driver_name);
 }
 
 void gvir_config_domain_disk_set_driver_type(GVirConfigDomainDisk *disk,
@@ -180,7 +182,8 @@ void gvir_config_domain_disk_set_driver_type(GVirConfigDomainDisk *disk,
 {
     g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK(disk));
     gvir_config_object_add_child_with_attribute(GVIR_CONFIG_OBJECT(disk),
-                                                "driver", "type", driver_type);
+                                                "driver", GVIR_CONFIG_TYPE_OBJECT,
+                                                "type", driver_type);
 }
 
 void gvir_config_domain_disk_set_driver_cache(GVirConfigDomainDisk *disk,
@@ -192,7 +195,8 @@ void gvir_config_domain_disk_set_driver_cache(GVirConfigDomainDisk *disk,
     cache_str = gvir_config_genum_get_nick(GVIR_CONFIG_TYPE_DOMAIN_DISK_CACHE_TYPE, cache_type);
     g_return_if_fail(cache_str != NULL);
     gvir_config_object_add_child_with_attribute(GVIR_CONFIG_OBJECT(disk),
-                                                "driver", "cache", cache_str);
+                                                "driver", GVIR_CONFIG_TYPE_OBJECT,
+                                                "cache", cache_str);
 }
 
 void gvir_config_domain_disk_set_target_bus(GVirConfigDomainDisk *disk,
@@ -204,7 +208,8 @@ void gvir_config_domain_disk_set_target_bus(GVirConfigDomainDisk *disk,
     bus_str = gvir_config_genum_get_nick(GVIR_CONFIG_TYPE_DOMAIN_DISK_BUS, bus);
     g_return_if_fail(bus_str != NULL);
     gvir_config_object_add_child_with_attribute(GVIR_CONFIG_OBJECT(disk),
-                                                "target", "bus", bus_str);
+                                                "target", GVIR_CONFIG_TYPE_OBJECT,
+                                                "bus", bus_str);
 }
 
 void gvir_config_domain_disk_set_target_dev(GVirConfigDomainDisk *disk,
@@ -212,7 +217,8 @@ void gvir_config_domain_disk_set_target_dev(GVirConfigDomainDisk *disk,
 {
     g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK(disk));
     gvir_config_object_add_child_with_attribute(GVIR_CONFIG_OBJECT(disk),
-                                                "target", "dev", dev);
+                                                "target", GVIR_CONFIG_TYPE_OBJECT,
+                                                "dev", dev);
 }
 
 GVirConfigDomainDiskType
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-filesys.c b/libvirt-gconfig/libvirt-gconfig-domain-filesys.c
index 904a7a3..8dcdff2 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-filesys.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-filesys.c
@@ -99,7 +99,8 @@ void gvir_config_domain_filesys_set_driver_type(GVirConfigDomainFilesys *filesys
     GVirConfigObject *node;
 
     g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_FILESYS(filesys));
-    node = gvir_config_object_add_child(GVIR_CONFIG_OBJECT(filesys), "driver");
+    node = gvir_config_object_add_child(GVIR_CONFIG_OBJECT(filesys),
+                                        "driver", GVIR_CONFIG_TYPE_OBJECT);
     g_return_if_fail(GVIR_CONFIG_IS_OBJECT(node));
     if (type != GVIR_CONFIG_DOMAIN_FILESYS_DRIVER_DEFAULT)
         gvir_config_object_set_attribute_with_type(
@@ -146,7 +147,8 @@ void gvir_config_domain_filesys_set_target(GVirConfigDomainFilesys *filesys,
 {
     g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_FILESYS(filesys));
     gvir_config_object_add_child_with_attribute(GVIR_CONFIG_OBJECT(filesys),
-                                                "target", "dir", path);
+                                                "target", GVIR_CONFIG_TYPE_OBJECT,
+                                                "dir", path);
 }
 
 void gvir_config_domain_filesys_set_readonly(GVirConfigDomainFilesys *filesys,
diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c
index c8cd1c5..04915ab 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain.c
@@ -401,7 +401,8 @@ void gvir_config_domain_add_device(GVirConfigDomain *domain,
     g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_DEVICE(device));
 
     devices_node = gvir_config_object_add_child(GVIR_CONFIG_OBJECT(domain),
-                                                "devices");
+                                                "devices",
+                                                GVIR_CONFIG_TYPE_OBJECT);
 
     gvir_config_object_attach_add(devices_node, GVIR_CONFIG_OBJECT(device));
     g_object_unref(G_OBJECT(devices_node));
@@ -465,7 +466,8 @@ gboolean gvir_config_domain_set_custom_xml(GVirConfigDomain *domain,
     g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
 
     metadata = gvir_config_object_add_child(GVIR_CONFIG_OBJECT(domain),
-                                            "metadata");
+                                            "metadata",
+                                            GVIR_CONFIG_TYPE_OBJECT);
 
     custom_xml = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_OBJECT,
                                                  NULL, NULL, xml, error);
diff --git a/libvirt-gconfig/libvirt-gconfig-object-private.h b/libvirt-gconfig/libvirt-gconfig-object-private.h
index a6b7395..ba9c676 100644
--- a/libvirt-gconfig/libvirt-gconfig-object-private.h
+++ b/libvirt-gconfig/libvirt-gconfig-object-private.h
@@ -54,13 +54,16 @@ void gvir_config_object_set_node_content_uint64(GVirConfigObject *object,
                                                 const char *node_name,
                                                 guint64 value);
 GVirConfigObject *gvir_config_object_add_child(GVirConfigObject *object,
-                                               const char *child_name);
+                                               const char *child_name,
+                                               GType child_type);
 void gvir_config_object_add_child_with_attribute(GVirConfigObject *object,
                                                  const char *child_name,
+                                                 GType child_type,
                                                  const char *attr_name,
                                                  const char *attr_value);
 void gvir_config_object_add_child_with_attribute_enum(GVirConfigObject *object,
                                                       const char *child_name,
+                                                      GType child_type,
                                                       const char *attr_name,
                                                       GType attr_type,
                                                       unsigned int attr_value);
diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c
index ee3584a..df4836d 100644
--- a/libvirt-gconfig/libvirt-gconfig-object.c
+++ b/libvirt-gconfig/libvirt-gconfig-object.c
@@ -367,7 +367,8 @@ gvir_config_object_foreach_child(GVirConfigObject *object,
 
 G_GNUC_INTERNAL GVirConfigObject *
 gvir_config_object_add_child(GVirConfigObject *object,
-                             const char *child_name)
+                             const char *child_name,
+                             GType child_type)
 {
     xmlNodePtr new_node;
     xmlNodePtr old_node;
@@ -380,13 +381,13 @@ 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));
@@ -395,12 +396,13 @@ gvir_config_object_add_child(GVirConfigObject *object,
 G_GNUC_INTERNAL void
 gvir_config_object_add_child_with_attribute(GVirConfigObject *object,
                                             const char *child_name,
+                                            GType child_type,
                                             const char *attr_name,
                                             const char *attr_value)
 {
     GVirConfigObject *child;
 
-    child = gvir_config_object_add_child(object, child_name);
+    child = gvir_config_object_add_child(object, child_name, child_type);
     gvir_config_object_set_attribute(child, attr_name, attr_value, NULL);
     g_object_unref(G_OBJECT(child));
 }
@@ -408,13 +410,14 @@ gvir_config_object_add_child_with_attribute(GVirConfigObject *object,
 
 void gvir_config_object_add_child_with_attribute_enum(GVirConfigObject *object,
                                                       const char *child_name,
+                                                      GType child_type,
                                                       const char *attr_name,
                                                       GType attr_type,
                                                       unsigned int attr_value)
 {
     GVirConfigObject *child;
 
-    child = gvir_config_object_add_child(object, child_name);
+    child = gvir_config_object_add_child(object, child_name, child_type);
     gvir_config_object_set_attribute_with_type(child, attr_name, attr_type, attr_value, NULL);
     g_object_unref(G_OBJECT(child));
 }
diff --git a/libvirt-gconfig/libvirt-gconfig-storage-pool-source.c b/libvirt-gconfig/libvirt-gconfig-storage-pool-source.c
index d92c692..e78989c 100644
--- a/libvirt-gconfig/libvirt-gconfig-storage-pool-source.c
+++ b/libvirt-gconfig/libvirt-gconfig-storage-pool-source.c
@@ -91,7 +91,8 @@ void gvir_config_storage_pool_source_set_device_path(GVirConfigStoragePoolSource
 
     g_return_if_fail(GVIR_CONFIG_IS_STORAGE_POOL_SOURCE(source));
 
-    node = gvir_config_object_add_child(GVIR_CONFIG_OBJECT(source), "device");
+    node = gvir_config_object_add_child(GVIR_CONFIG_OBJECT(source),
+                                        "device", GVIR_CONFIG_TYPE_OBJECT);
     g_return_if_fail(GVIR_CONFIG_IS_OBJECT(node));
     gvir_config_object_set_attribute(node, "path", device_path, NULL);
     g_object_unref(G_OBJECT(node));
-- 
1.7.7.6


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