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

[libvirt] [libvirt-glib 08/13] Use gvir_config_object_set_attribute where appropriate



---
 libvirt-gconfig/libvirt-gconfig-domain-clock.c     |   42 +++++--------------
 libvirt-gconfig/libvirt-gconfig-domain-disk.c      |   36 ++++-------------
 .../libvirt-gconfig-domain-graphics-spice.c        |   12 ++----
 libvirt-gconfig/libvirt-gconfig-domain-input.c     |   26 ++++--------
 4 files changed, 32 insertions(+), 84 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-domain-clock.c b/libvirt-gconfig/libvirt-gconfig-domain-clock.c
index b28856c..c78141a 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-clock.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-clock.c
@@ -81,52 +81,32 @@ GVirConfigDomainClock *gvir_config_domain_clock_new_from_xml(const gchar *xml,
 void gvir_config_domain_clock_set_offset(GVirConfigDomainClock *klock,
                                          GVirConfigDomainClockOffset offset)
 {
-    xmlNodePtr node;
-    const char *offset_str;
-
     g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_CLOCK(klock));
 
-    node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(klock));
-    g_return_if_fail(node != NULL);
-    offset_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_DOMAIN_CLOCK_OFFSET,
-                                             offset);
-    g_return_if_fail(offset_str != NULL);
-    xmlNewProp(node, (xmlChar*)"offset", (xmlChar*)offset_str);
+    gvir_config_object_set_attribute_with_type(GVIR_CONFIG_OBJECT(klock),
+                                               "offset",
+                                               GVIR_TYPE_CONFIG_DOMAIN_CLOCK_OFFSET,
+                                               offset,
+                                               NULL);
 }
 
 void gvir_config_domain_clock_set_timezone(GVirConfigDomainClock *klock,
                                            const char *tz)
 {
-    xmlNodePtr node;
-    xmlChar *encoded_tz;
-
     g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_CLOCK(klock));
     g_return_if_fail(tz != NULL);
 
-    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);
+    gvir_config_object_set_attribute(GVIR_CONFIG_OBJECT(klock),
+                                     "timezone", tz, NULL);
 }
 
 void gvir_config_domain_clock_set_variable_offset(GVirConfigDomainClock *klock,
                                                   gint seconds)
 {
-    xmlNodePtr node;
-    char *offset_str;
-
     g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_CLOCK(klock));
 
-    node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(klock));
-    if (node == NULL)
-        return;
-
-    xmlNewProp(node, (xmlChar*)"offset", (xmlChar*)"variable");
-    offset_str = g_strdup_printf("%d", seconds);
-    xmlNewProp(node, (xmlChar*)"adjustment", (xmlChar*)offset_str);
-    g_free(offset_str);
+    gvir_config_object_set_attribute_with_type(GVIR_CONFIG_OBJECT(klock),
+                                               "offset", G_TYPE_STRING,  "variable",
+                                               "adjustment", G_TYPE_INT, seconds,
+                                               NULL);
 }
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.c b/libvirt-gconfig/libvirt-gconfig-domain-disk.c
index 8a9d6e6..dfdb381 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-disk.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.c
@@ -81,50 +81,32 @@ GVirConfigDomainDisk *gvir_config_domain_disk_new_from_xml(const gchar *xml,
 void gvir_config_domain_disk_set_type(GVirConfigDomainDisk *disk,
                                       GVirConfigDomainDiskType type)
 {
-    xmlNodePtr node;
-    const char *type_str;
-
     g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_DISK(disk));
 
-    node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(disk));
-    g_return_if_fail(node != NULL);
-    type_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_DOMAIN_DISK_TYPE,
-                                          type);
-    g_return_if_fail(type_str != NULL);
-    xmlNewProp(node, (xmlChar*)"type", (xmlChar*)type_str);
+    gvir_config_object_set_attribute_with_type(GVIR_CONFIG_OBJECT(disk), "type",
+                                               GVIR_TYPE_CONFIG_DOMAIN_DISK_TYPE,
+                                               type, NULL);
     disk->priv->type = type;
 }
 
 void gvir_config_domain_disk_set_guest_device_type(GVirConfigDomainDisk *disk,
                                                    GVirConfigDomainDiskGuestDeviceType type)
 {
-    xmlNodePtr node;
-    const char *type_str;
-
     g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_DISK(disk));
 
-    node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(disk));
-    g_return_if_fail(node != NULL);
-    type_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_DOMAIN_DISK_GUEST_DEVICE_TYPE,
-                                          type);
-    g_return_if_fail(type_str != NULL);
-    xmlNewProp(node, (xmlChar*)"device", (xmlChar*)type_str);
+    gvir_config_object_set_attribute_with_type(GVIR_CONFIG_OBJECT(disk), "device",
+                                               GVIR_TYPE_CONFIG_DOMAIN_DISK_GUEST_DEVICE_TYPE,
+                                               type, NULL);
 }
 
 void gvir_config_domain_disk_set_snapshot_type(GVirConfigDomainDisk *disk,
                                                GVirConfigDomainDiskSnapshotType type)
 {
-    xmlNodePtr node;
-    const char *type_str;
-
     g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_DISK(disk));
 
-    node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(disk));
-    g_return_if_fail(node != NULL);
-    type_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_DOMAIN_DISK_SNAPSHOT_TYPE,
-                                          type);
-    g_return_if_fail(type_str != NULL);
-    xmlNewProp(node, (xmlChar*)"snapshot", (xmlChar*)type_str);
+    gvir_config_object_set_attribute_with_type(GVIR_CONFIG_OBJECT(disk), "snapshot",
+                                               GVIR_TYPE_CONFIG_DOMAIN_DISK_SNAPSHOT_TYPE,
+                                               type, NULL);
 }
 
 void gvir_config_domain_disk_set_source(GVirConfigDomainDisk *disk,
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c
index e5c2ff8..a5d0775 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c
@@ -90,13 +90,9 @@ GVirConfigDomainGraphicsSpice *gvir_config_domain_graphics_spice_new_from_xml(co
 void gvir_config_domain_graphics_spice_set_port(GVirConfigDomainGraphicsSpice *graphics,
                                          unsigned int port)
 {
-    xmlNodePtr node;
-    char *port_str;
-
     g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_GRAPHICS_SPICE(graphics));
-    node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(graphics));
-    g_return_if_fail(node != NULL);
-    port_str = g_strdup_printf("%u", port);
-    xmlNewProp(node, (xmlChar*)"port", (xmlChar*)port_str);
-    g_free(port_str);
+
+    gvir_config_object_set_attribute_with_type(GVIR_CONFIG_OBJECT(graphics),
+                                               "port", G_TYPE_UINT, port,
+                                               NULL);
 }
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-input.c b/libvirt-gconfig/libvirt-gconfig-domain-input.c
index ad11472..83bc26d 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-input.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-input.c
@@ -81,29 +81,19 @@ GVirConfigDomainInput *gvir_config_domain_input_new_from_xml(const gchar *xml,
 void gvir_config_domain_input_set_device_type(GVirConfigDomainInput *input,
                                               GVirConfigDomainInputDeviceType type)
 {
-    xmlNodePtr node;
-    const char *type_str;
-
     g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_INPUT(input));
-    node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(input));
-    g_return_if_fail(node != NULL);
-    type_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_DOMAIN_INPUT_DEVICE_TYPE,
-                                          type);
-    g_return_if_fail(type_str != NULL);
-    xmlNewProp(node, (xmlChar*)"type", (xmlChar*)type_str);
+
+    gvir_config_object_set_attribute_with_type(GVIR_CONFIG_OBJECT(input), "type",
+                                               GVIR_TYPE_CONFIG_DOMAIN_INPUT_DEVICE_TYPE,
+                                               type, NULL);
 }
 
 void gvir_config_domain_input_set_bus(GVirConfigDomainInput *input,
                                       GVirConfigDomainInputBus bus)
 {
-    xmlNodePtr node;
-    const char *bus_str;
-
     g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_INPUT(input));
-    node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(input));
-    g_return_if_fail(node != NULL);
-    bus_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_DOMAIN_INPUT_BUS,
-                                         bus);
-    g_return_if_fail(bus_str != NULL);
-    xmlNewProp(node, (xmlChar*)"bus", (xmlChar*)bus_str);
+
+    gvir_config_object_set_attribute_with_type(GVIR_CONFIG_OBJECT(input), "bus",
+                                               GVIR_TYPE_CONFIG_DOMAIN_INPUT_BUS,
+                                               bus, NULL);
 }
-- 
1.7.7.3


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