diff options
author | Thomas Haller <thaller@redhat.com> | 2017-03-28 18:06:14 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-03-30 13:09:58 +0200 |
commit | f5a0b62765a302c08e7ec4874bf01872524e3de6 (patch) | |
tree | 823062d207582692dda9e9fbaa8c2a4f87eaea80 | |
parent | b9fa0e0a195e9cf7363b563cca7ffec4b5016afd (diff) | |
download | NetworkManager-f5a0b62765a302c08e7ec4874bf01872524e3de6.tar.gz |
cli: use enum property type for connection.lldp
Change in behavior:
- the setter would previoulsy allow "enable" case-insensitive.
Now, it's case sensitive.
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | clients/common/nm-meta-setting-desc.c | 79 | ||||
-rw-r--r-- | clients/common/nm-meta-setting-desc.h | 3 |
3 files changed, 30 insertions, 54 deletions
diff --git a/Makefile.am b/Makefile.am index 1db61f3695..a124c9a28d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3120,6 +3120,8 @@ bin_PROGRAMS += clients/cli/nmcli clients_cli_nmcli_SOURCES = \ \ + shared/nm-utils/nm-enum-utils.c \ + shared/nm-utils/nm-enum-utils.h \ shared/nm-utils/nm-shared-utils.c \ shared/nm-utils/nm-shared-utils.h \ \ diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c index 253c9096e8..9189572d3f 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -25,6 +25,7 @@ #include <arpa/inet.h> #include "nm-common-macros.h" +#include "nm-utils/nm-enum-utils.h" #include "nm-vpn-helpers.h" #include "nm-client-utils.h" @@ -711,6 +712,9 @@ _get_fcn_gobject_enum (ARGS_GET_FCN) : g_strdup_printf ("%"G_GINT64_FORMAT, v); } + /* the gobject_enum.value_infos are currently ignored for the getter. They + * only declare additional aliases for the setter. */ + s = nm_utils_enum_to_str (gtype, (int) v); if (!format_numeric) @@ -938,7 +942,10 @@ _set_fcn_gobject_enum (ARGS_SET_FCN) if (!has_gtype) gtype = gtype_prop; - if (!nm_utils_enum_from_str (gtype, value, &v, NULL)) + if (!_nm_utils_enum_from_str_full (gtype, value, &v, NULL, + property_info->property_typ_data + ? property_info->property_typ_data->subtype.gobject_enum.value_infos + : NULL)) goto fail; g_value_init (&gval, gtype_prop); @@ -1013,6 +1020,9 @@ _values_fcn_gobject_enum (ARGS_VALUES_FCN) property_info->property_name); } + /* the gobject_enum.value_infos are currently ignored for the list of + * values. They only declare additional (hidden) aliases for the setter. */ + v = (char **) nm_utils_enum_get_values (gtype, min, max); if (v) { for (w = v; *w; w++) @@ -2302,54 +2312,6 @@ _set_fcn_connection_metered (ARGS_SET_FCN) } static char * -_get_fcn_connection_lldp (ARGS_GET_FCN) -{ - NMSettingConnection *s_conn = NM_SETTING_CONNECTION (setting); - NMSettingConnectionLldp lldp; - char *tmp, *str; - - lldp = nm_setting_connection_get_lldp (s_conn); - tmp = nm_utils_enum_to_str (nm_setting_connection_lldp_get_type (), lldp); - if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) - str = g_strdup_printf ("%s", tmp && *tmp ? tmp : "default"); - else - str = g_strdup_printf ("%d (%s)", lldp, tmp && *tmp ? tmp : "default"); - g_free (tmp); - return str; -} - -static gboolean -_set_fcn_connection_lldp (ARGS_SET_FCN) -{ - NMSettingConnectionLldp lldp; - gboolean ret; - long int t; - - if (nmc_string_to_int_base (value, 0, TRUE, - NM_SETTING_CONNECTION_LLDP_DEFAULT, - NM_SETTING_CONNECTION_LLDP_ENABLE_RX, - &t)) - lldp = t; - else { - ret = nm_utils_enum_from_str (nm_setting_connection_lldp_get_type (), value, - (int *) &lldp, NULL); - - if (!ret) { - if (g_ascii_strcasecmp (value, "enable") == 0) - lldp = NM_SETTING_CONNECTION_LLDP_ENABLE_RX; - else { - g_set_error (error, 1, 0, _("invalid option '%s', use one of [%s]"), - value, "default,disable,enable-rx,enable"); - return FALSE; - } - } - } - - g_object_set (setting, property_info->property_name, lldp, NULL); - return TRUE; -} - -static char * dcb_flags_to_string (NMSettingDcbFlags flags) { GString *flag_str; @@ -4595,6 +4557,8 @@ static const NMMetaPropertyType _pt_gobject_enum = { #define VALUES_STATIC(...) (((const char *[]) { __VA_ARGS__, NULL })) +#define ENUM_VALUE_INFOS(...) (((const NMUtilsEnumValueInfo []) { __VA_ARGS__, { 0 } })) + #define GET_FCN_WITH_DEFAULT(type, func) \ /* macro that returns @func as const (gboolean(*)(NMSetting*)) type, but checks * that the actual type is (gboolean(*)(type *)). */ \ @@ -5179,12 +5143,19 @@ static const NMMetaPropertyInfo property_infos_connection[] = { }, { .property_name = N_ (NM_SETTING_CONNECTION_LLDP), - .property_type = DEFINE_PROPERTY_TYPE ( - .get_fcn = _get_fcn_connection_lldp, - .set_fcn = _set_fcn_connection_lldp, - ), + .property_type = &_pt_gobject_enum, .property_typ_data = DEFINE_PROPERTY_TYP_DATA ( - .values_static = VALUES_STATIC ("default", "disable", "enable-rx"), + PROPERTY_TYP_DATA_SUBTYPE (gobject_enum, + .get_gtype = nm_setting_connection_lldp_get_type, + .value_infos = ENUM_VALUE_INFOS ( + { + .value = NM_SETTING_CONNECTION_LLDP_ENABLE_RX, + .nick = "enable", + } + ), + ), + .typ_flags = NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT + | NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT, ), }, }; diff --git a/clients/common/nm-meta-setting-desc.h b/clients/common/nm-meta-setting-desc.h index ca37bd884b..fb92012297 100644 --- a/clients/common/nm-meta-setting-desc.h +++ b/clients/common/nm-meta-setting-desc.h @@ -78,6 +78,8 @@ struct _NMMetaPropertyType { char ***out_to_free); }; +struct _NMUtilsEnumValueInfo; + struct _NMMetaPropertyTypData { union { struct { @@ -87,6 +89,7 @@ struct _NMMetaPropertyTypData { GType (*get_gtype) (void); int min; int max; + const struct _NMUtilsEnumValueInfo *value_infos; } gobject_enum; struct { guint32 (*get_fcn) (NMSetting *setting); |