From def37e4e0dfad0fefab8f8911cfc4b54da3e74e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Wed, 20 Mar 2013 10:21:19 +0100 Subject: [PATCH] cli: nmc_property_get_gvalue() nmc_property_set_gvalue() Functions to - get property value and return it in GValue - set property value from GValue --- cli/src/settings.c | 35 +++++++++++++++++++++++++++++++++++ cli/src/settings.h | 2 ++ 2 files changed, 37 insertions(+) diff --git a/cli/src/settings.c b/cli/src/settings.c index 176e75cba..1e889fb8d 100644 --- a/cli/src/settings.c +++ b/cli/src/settings.c @@ -4664,6 +4664,41 @@ nmc_setting_get_property_desc (NMSetting *setting, const char *prop) nmcli_desc ? nmcli_desc : ""); } +/* + * Gets setting:prop property value and returns it in 'value'. + * Caller is responsible for freeing the GValue resources using g_value_unset() + */ +gboolean +nmc_property_get_gvalue (NMSetting *setting, const char *prop, GValue *value) +{ + GParamSpec *param_spec; + + param_spec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (setting)), prop); + if (param_spec) { + memset (value, 0, sizeof (GValue)); + g_value_init (value, G_PARAM_SPEC_VALUE_TYPE (param_spec)); + g_object_get_property (G_OBJECT (setting), prop, value); + return TRUE; + } + return FALSE; +} + +/* + * Sets setting:prop property value from 'value'. + */ +gboolean +nmc_property_set_gvalue (NMSetting *setting, const char *prop, GValue *value) +{ + GParamSpec *param_spec; + + param_spec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (setting)), prop); + if (param_spec && G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (param_spec)) { + g_object_set_property (G_OBJECT (setting), prop, value); + return TRUE; + } + return FALSE; +} + /*----------------------------------------------------------------------------*/ static gboolean diff --git a/cli/src/settings.h b/cli/src/settings.h index 1b42f3c44..12be7f8c0 100644 --- a/cli/src/settings.h +++ b/cli/src/settings.h @@ -76,6 +76,8 @@ gboolean nmc_setting_remove_property_option (NMSetting *setting, GError **error); void nmc_property_set_default_value (NMSetting *setting, const char *prop); +gboolean nmc_property_get_gvalue (NMSetting *setting, const char *prop, GValue *value); +gboolean nmc_property_set_gvalue (NMSetting *setting, const char *prop, GValue *value); gboolean setting_details (NMSetting *ssetting, NmCli *nmc);