summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-08-28 18:51:11 +0200
committerThomas Haller <thaller@redhat.com>2014-10-29 17:33:12 +0100
commitc0574baf17284cce622e07c7bb799f6a614f7b4b (patch)
tree0cf6205518155f11c0c440054a79804c3363284f
parentab29ed50f117f6fcbdddc1ea670ff3b3d66641ae (diff)
downloadNetworkManager-c0574baf17284cce622e07c7bb799f6a614f7b4b.tar.gz
cli: add utility methods for gint64 types
Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r--clients/cli/settings.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/clients/cli/settings.c b/clients/cli/settings.c
index 6a78e5e1f7..11958422eb 100644
--- a/clients/cli/settings.c
+++ b/clients/cli/settings.c
@@ -1955,6 +1955,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)
@@ -2183,6 +2204,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;