You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
2.8 KiB
93 lines
2.8 KiB
5 years ago
|
From 1bff3d3ca4101639e659c8649731020e7a5c9c10 Mon Sep 17 00:00:00 2001
|
||
|
From: "Eduardo Lima (Etrunko)" <etrunko@redhat.com>
|
||
|
Date: Tue, 3 Oct 2017 17:32:03 -0300
|
||
|
Subject: [PATCH] utils: Factor out basic value type setting from
|
||
|
_set_property_value_from_type()
|
||
|
|
||
|
A simple cosmetic enhancement with the hope to improve code readability.
|
||
|
|
||
|
Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
|
||
|
---
|
||
|
govirt/ovirt-utils.c | 59 ++++++++++++++++++++++++++++++----------------------
|
||
|
1 file changed, 34 insertions(+), 25 deletions(-)
|
||
|
|
||
|
diff --git a/govirt/ovirt-utils.c b/govirt/ovirt-utils.c
|
||
|
index a60c754..a0146fd 100644
|
||
|
--- a/govirt/ovirt-utils.c
|
||
|
+++ b/govirt/ovirt-utils.c
|
||
|
@@ -134,6 +134,39 @@ ovirt_rest_xml_node_get_str_array_from_path(RestXmlNode *node, const char *path,
|
||
|
return (GStrv) g_array_free(array, FALSE);
|
||
|
}
|
||
|
|
||
|
+static gboolean
|
||
|
+_set_property_value_from_basic_type(GValue *value,
|
||
|
+ GType type,
|
||
|
+ const char *value_str)
|
||
|
+{
|
||
|
+ switch(type) {
|
||
|
+ case G_TYPE_BOOLEAN: {
|
||
|
+ gboolean bool_value = ovirt_utils_boolean_from_string(value_str);
|
||
|
+ g_value_set_boolean(value, bool_value);
|
||
|
+ return TRUE;
|
||
|
+ }
|
||
|
+ case G_TYPE_STRING: {
|
||
|
+ g_value_set_string(value, value_str);
|
||
|
+ return TRUE;
|
||
|
+ }
|
||
|
+ case G_TYPE_UINT: {
|
||
|
+ guint uint_value = strtoul(value_str, NULL, 0);
|
||
|
+ g_value_set_uint(value, uint_value);
|
||
|
+ return TRUE;
|
||
|
+ }
|
||
|
+ case G_TYPE_UINT64: {
|
||
|
+ guint64 int64_value = g_ascii_strtoull(value_str, NULL, 0);
|
||
|
+ g_value_set_uint64(value, int64_value);
|
||
|
+ return TRUE;
|
||
|
+ }
|
||
|
+ default: {
|
||
|
+ g_warning("Unexpected type '%s' with value '%s'", g_type_name(type), value_str);
|
||
|
+ }
|
||
|
+ }
|
||
|
+
|
||
|
+ return FALSE;
|
||
|
+}
|
||
|
+
|
||
|
static gboolean
|
||
|
_set_property_value_from_type(GValue *value,
|
||
|
GType type,
|
||
|
@@ -174,31 +207,7 @@ _set_property_value_from_type(GValue *value,
|
||
|
goto end;
|
||
|
}
|
||
|
|
||
|
- switch(type) {
|
||
|
- case G_TYPE_BOOLEAN: {
|
||
|
- gboolean bool_value = ovirt_utils_boolean_from_string(value_str);
|
||
|
- g_value_set_boolean(value, bool_value);
|
||
|
- break;
|
||
|
- }
|
||
|
- case G_TYPE_STRING: {
|
||
|
- g_value_set_string(value, value_str);
|
||
|
- break;
|
||
|
- }
|
||
|
- case G_TYPE_UINT: {
|
||
|
- guint uint_value = strtoul(value_str, NULL, 0);
|
||
|
- g_value_set_uint(value, uint_value);
|
||
|
- break;
|
||
|
- }
|
||
|
- case G_TYPE_UINT64: {
|
||
|
- guint64 int64_value = g_ascii_strtoull(value_str, NULL, 0);
|
||
|
- g_value_set_uint64(value, int64_value);
|
||
|
- break;
|
||
|
- }
|
||
|
- default: {
|
||
|
- g_warning("Unexpected type '%s' with value '%s'", g_type_name(type), value_str);
|
||
|
- ret = FALSE;
|
||
|
- }
|
||
|
- }
|
||
|
+ ret = _set_property_value_from_basic_type(value, type, value_str);
|
||
|
|
||
|
end:
|
||
|
return ret;
|
||
|
--
|
||
|
2.14.4
|