diff options
author | Thomas Haller <thaller@redhat.com> | 2014-08-28 18:51:11 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2014-11-05 23:49:55 +0100 |
commit | 547c56e0d13652049e5d2e398abacfa1098e0fb1 (patch) | |
tree | cbed73fe7b8956184a38743095eeead8356a3db5 | |
parent | 8bbd90d02a6ed4625fb067c9ea265bf18e4d50ff (diff) | |
download | NetworkManager-547c56e0d13652049e5d2e398abacfa1098e0fb1.tar.gz |
cli: add utility methods for gint64 types
Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r-- | clients/cli/settings.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/clients/cli/settings.c b/clients/cli/settings.c index 136c818641..b6a2f4c2db 100644 --- a/clients/cli/settings.c +++ b/clients/cli/settings.c @@ -1990,6 +1990,27 @@ validate_int (NMSetting *setting, const char* prop, gint val, GError **error) return success; } +static gboolean +validate_int64 (NMSetting *setting, const char* prop, gint64 val, GError **error) +{ + GParamSpec *pspec; + GValue value = G_VALUE_INIT; + gboolean success = TRUE; + + g_value_init (&value, G_TYPE_INT64); + g_value_set_int64 (&value, val); + pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (setting)), prop); + g_assert (G_IS_PARAM_SPEC (pspec)); + if (g_param_value_validate (pspec, &value)) { + GParamSpecInt64 *pspec_int = (GParamSpecInt64 *) pspec; + g_set_error (error, 1, 0, _("'%"G_GINT64_FORMAT"' is not valid; use <%"G_GINT64_FORMAT"-%"G_GINT64_FORMAT">"), + val, pspec_int->minimum, pspec_int->maximum); + success = FALSE; + } + g_value_unset (&value); + return success; +} + /* Validate 'val' number against to uint property spec */ static gboolean validate_uint (NMSetting *setting, const char* prop, guint val, GError **error) @@ -2218,6 +2239,26 @@ nmc_property_set_int (NMSetting *setting, const char *prop, const char *val, GEr } static gboolean +nmc_property_set_int64 (NMSetting *setting, const char *prop, const char *val, GError **error) +{ + long val_int; + + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + if (!nmc_string_to_int (val, FALSE, 0, 0, &val_int)) { + g_set_error (error, 1, 0, _("'%s' is not a valid number (or out of range)"), val); + return FALSE; + } + + /* Validate the number according to the property spec */ + if (!validate_int64 (setting, prop, (gint64) val_int, error)) + return FALSE; + + g_object_set (setting, prop, (gint64) val_int, NULL); + return TRUE; +} + +static gboolean nmc_property_set_bool (NMSetting *setting, const char *prop, const char *val, GError **error) { gboolean val_bool; |