[libvirt-glib 1/4] Implement gvir_config_object_get_attribute_boolean()

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

 



gvir_config_object_set_attribute() converts (TRUE, FALSE) to ("yes", "no"),
but we don't have the corresponding getter. This commit adds this.
---
 libvirt-gconfig/libvirt-gconfig-object-private.h |  4 ++++
 libvirt-gconfig/libvirt-gconfig-object.c         | 20 ++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/libvirt-gconfig/libvirt-gconfig-object-private.h b/libvirt-gconfig/libvirt-gconfig-object-private.h
index 2ec358b..e91c4ef 100644
--- a/libvirt-gconfig/libvirt-gconfig-object-private.h
+++ b/libvirt-gconfig/libvirt-gconfig-object-private.h
@@ -53,6 +53,10 @@ gint gvir_config_object_get_attribute_genum(GVirConfigObject *object,
                                             const char *attr_name,
                                             GType enum_type,
                                             gint default_value);
+gboolean gvir_config_object_get_attribute_boolean(GVirConfigObject *object,
+                                                  const char *node_name,
+                                                  const char *attr_name,
+                                                  gboolean default_value);
 void gvir_config_object_set_node_content(GVirConfigObject *object,
                                          const char *node_name,
                                          const char *value);
diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c
index a8025e6..5557165 100644
--- a/libvirt-gconfig/libvirt-gconfig-object.c
+++ b/libvirt-gconfig/libvirt-gconfig-object.c
@@ -684,6 +684,26 @@ gvir_config_object_get_attribute_uint64(GVirConfigObject *object,
     return g_ascii_strtoull(str, NULL, 0);
 }
 
+
+G_GNUC_INTERNAL gboolean
+gvir_config_object_get_attribute_boolean(GVirConfigObject *object,
+                                         const char *node_name,
+                                         const char *attr_name,
+                                         gboolean default_value)
+{
+    const char *str;
+
+    str = gvir_config_object_get_attribute(object, node_name, attr_name);
+    if (g_strcmp0(str, "yes") == 0) {
+        return TRUE;
+    } else if (g_strcmp0(str, "no") == 0) {
+        return FALSE;
+    } else {
+        return default_value;
+    }
+}
+
+
 GVirConfigObject *gvir_config_object_new_from_xml(GType type,
                                                   const char *root_name,
                                                   const char *schema,
-- 
1.8.4.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]