mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-27 14:00:11 +01:00
device/bridge: code cleanup in commit_option()
This commit is contained in:
parent
36ab1e841f
commit
177ee2d7bf
1 changed files with 40 additions and 41 deletions
|
|
@ -329,59 +329,58 @@ commit_option (NMDevice *device, NMSetting *setting, const Option *option, gbool
|
||||||
GParamSpec *pspec;
|
GParamSpec *pspec;
|
||||||
const char *value;
|
const char *value;
|
||||||
|
|
||||||
g_assert (setting);
|
nm_assert (NM_IS_SETTING_BRIDGE (setting));
|
||||||
|
|
||||||
pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (setting), option->name);
|
pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (setting), option->name);
|
||||||
g_assert (pspec);
|
nm_assert (pspec);
|
||||||
|
|
||||||
/* Get the property's value */
|
|
||||||
g_value_init (&val, G_PARAM_SPEC_VALUE_TYPE (pspec));
|
g_value_init (&val, G_PARAM_SPEC_VALUE_TYPE (pspec));
|
||||||
g_object_get_property ((GObject *) setting, option->name, &val);
|
g_object_get_property ((GObject *) setting, option->name, &val);
|
||||||
|
|
||||||
if (option->to_sysfs) {
|
if (option->to_sysfs) {
|
||||||
value = option->to_sysfs(&val);
|
value = option->to_sysfs (&val);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (pspec->value_type) {
|
switch (pspec->value_type) {
|
||||||
case G_TYPE_BOOLEAN:
|
case G_TYPE_BOOLEAN:
|
||||||
value = g_value_get_boolean (&val) ? "1" : "0";
|
value = g_value_get_boolean (&val) ? "1" : "0";
|
||||||
break;
|
break;
|
||||||
case G_TYPE_UINT: {
|
case G_TYPE_UINT: {
|
||||||
char value_buf[100];
|
char value_buf[100];
|
||||||
guint uval;
|
guint uval;
|
||||||
|
|
||||||
|
uval = g_value_get_uint (&val);
|
||||||
|
|
||||||
|
/* zero means "unspecified" for some NM properties but isn't in the
|
||||||
|
* allowed kernel range, so reset the property to the default value.
|
||||||
|
*/
|
||||||
|
if (option->default_if_zero && uval == 0) {
|
||||||
|
g_value_unset (&val);
|
||||||
|
g_value_init (&val, G_PARAM_SPEC_VALUE_TYPE (pspec));
|
||||||
|
g_param_value_set_default (pspec, &val);
|
||||||
uval = g_value_get_uint (&val);
|
uval = g_value_get_uint (&val);
|
||||||
|
|
||||||
/* zero means "unspecified" for some NM properties but isn't in the
|
|
||||||
* allowed kernel range, so reset the property to the default value.
|
|
||||||
*/
|
|
||||||
if (option->default_if_zero && uval == 0) {
|
|
||||||
g_value_unset (&val);
|
|
||||||
g_value_init (&val, G_PARAM_SPEC_VALUE_TYPE (pspec));
|
|
||||||
g_param_value_set_default (pspec, &val);
|
|
||||||
uval = g_value_get_uint (&val);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Linux kernel bridge interfaces use 'centiseconds' for time-based values.
|
|
||||||
* In reality it's not centiseconds, but depends on HZ and USER_HZ, which
|
|
||||||
* is almost always works out to be a multiplier of 100, so we can assume
|
|
||||||
* centiseconds. See clock_t_to_jiffies().
|
|
||||||
*/
|
|
||||||
if (option->user_hz_compensate)
|
|
||||||
uval *= 100;
|
|
||||||
|
|
||||||
nm_sprintf_buf (value_buf, "%u", uval);
|
|
||||||
value = value_buf;
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case G_TYPE_STRING:
|
/* Linux kernel bridge interfaces use 'centiseconds' for time-based values.
|
||||||
value = g_value_get_string (&val);
|
* In reality it's not centiseconds, but depends on HZ and USER_HZ, which
|
||||||
break;
|
* is almost always works out to be a multiplier of 100, so we can assume
|
||||||
default:
|
* centiseconds. See clock_t_to_jiffies().
|
||||||
nm_assert_not_reached ();
|
*/
|
||||||
value = NULL;
|
if (option->user_hz_compensate)
|
||||||
break;
|
uval *= 100;
|
||||||
|
|
||||||
|
nm_sprintf_buf (value_buf, "%u", uval);
|
||||||
|
value = value_buf;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case G_TYPE_STRING:
|
||||||
|
value = g_value_get_string (&val);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
nm_assert_not_reached ();
|
||||||
|
value = NULL;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
|
@ -492,7 +491,7 @@ update_connection (NMDevice *device, NMConnection *connection)
|
||||||
g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
|
g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
|
||||||
|
|
||||||
if (option->from_sysfs) {
|
if (option->from_sysfs) {
|
||||||
option->from_sysfs(str, &value);
|
option->from_sysfs (str, &value);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -530,7 +529,7 @@ update_connection (NMDevice *device, NMConnection *connection)
|
||||||
g_value_set_string (&value, str);
|
g_value_set_string (&value, str);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
nm_assert_not_reached();
|
nm_assert_not_reached ();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue