mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-04-19 14:50:39 +02:00
libnm: add direct strv type for NMSetting and use it for "match.interface-name"
G_TYPE_STRV is the last property type in NMSetting that is implemented by directly accessing the GObect property. Note that we have lots of override, non-default implementations that still use GObject properties, but I am talking here about properties that don't have a special implementation and use a G_TYPE_STRV GObject property. Add a "direct" implementation also for strv arrays. The advantage is that we no longer call g_value_get() for various operations, which requires a deep-copy of the strv array. The other advantage is that we will get a unified approach for implementing strv properties. In particular strv arrays need a lot of code to implement, and most settings do it differently. By adding a general mechanism, this code (and behavior) can be unified. Showcase it on "match.interface-name".
This commit is contained in:
parent
f0c565a79f
commit
61ff2b03df
6 changed files with 217 additions and 71 deletions
|
|
@ -32,11 +32,11 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMSettingMatch,
|
|||
* Since: 1.14
|
||||
*/
|
||||
struct _NMSettingMatch {
|
||||
NMSetting parent;
|
||||
GArray *interface_name;
|
||||
GArray *kernel_command_line;
|
||||
GArray *driver;
|
||||
GArray *path;
|
||||
NMSetting parent;
|
||||
NMValueStrv interface_name;
|
||||
GArray *kernel_command_line;
|
||||
GArray *driver;
|
||||
GArray *path;
|
||||
};
|
||||
|
||||
struct _NMSettingMatchClass {
|
||||
|
|
@ -60,7 +60,7 @@ nm_setting_match_get_num_interface_names(NMSettingMatch *setting)
|
|||
{
|
||||
g_return_val_if_fail(NM_IS_SETTING_MATCH(setting), 0);
|
||||
|
||||
return nm_g_array_len(setting->interface_name);
|
||||
return nm_g_array_len(setting->interface_name.arr);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -77,10 +77,11 @@ nm_setting_match_get_interface_name(NMSettingMatch *setting, int idx)
|
|||
{
|
||||
g_return_val_if_fail(NM_IS_SETTING_MATCH(setting), NULL);
|
||||
|
||||
g_return_val_if_fail(setting->interface_name && idx >= 0 && idx < setting->interface_name->len,
|
||||
g_return_val_if_fail(setting->interface_name.arr && idx >= 0
|
||||
&& idx < setting->interface_name.arr->len,
|
||||
NULL);
|
||||
|
||||
return nm_strvarray_get_idx(setting->interface_name, idx);
|
||||
return nm_strvarray_get_idx(setting->interface_name.arr, idx);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -98,7 +99,7 @@ nm_setting_match_add_interface_name(NMSettingMatch *setting, const char *interfa
|
|||
g_return_if_fail(NM_IS_SETTING_MATCH(setting));
|
||||
g_return_if_fail(interface_name);
|
||||
|
||||
nm_strvarray_add(nm_strvarray_ensure(&setting->interface_name), interface_name);
|
||||
nm_strvarray_add(nm_strvarray_ensure(&setting->interface_name.arr), interface_name);
|
||||
_notify(setting, PROP_INTERFACE_NAME);
|
||||
}
|
||||
|
||||
|
|
@ -116,9 +117,10 @@ nm_setting_match_remove_interface_name(NMSettingMatch *setting, int idx)
|
|||
{
|
||||
g_return_if_fail(NM_IS_SETTING_MATCH(setting));
|
||||
|
||||
g_return_if_fail(setting->interface_name && idx >= 0 && idx < setting->interface_name->len);
|
||||
g_return_if_fail(setting->interface_name.arr && idx >= 0
|
||||
&& idx < setting->interface_name.arr->len);
|
||||
|
||||
g_array_remove_index(setting->interface_name, idx);
|
||||
g_array_remove_index(setting->interface_name.arr, idx);
|
||||
_notify(setting, PROP_INTERFACE_NAME);
|
||||
}
|
||||
|
||||
|
|
@ -139,7 +141,7 @@ nm_setting_match_remove_interface_name_by_value(NMSettingMatch *setting, const c
|
|||
g_return_val_if_fail(NM_IS_SETTING_MATCH(setting), FALSE);
|
||||
g_return_val_if_fail(interface_name, FALSE);
|
||||
|
||||
if (nm_strvarray_remove_first(setting->interface_name, interface_name)) {
|
||||
if (nm_strvarray_remove_first(setting->interface_name.arr, interface_name)) {
|
||||
_notify(setting, PROP_INTERFACE_NAME);
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -160,8 +162,8 @@ nm_setting_match_clear_interface_names(NMSettingMatch *setting)
|
|||
{
|
||||
g_return_if_fail(NM_IS_SETTING_MATCH(setting));
|
||||
|
||||
if (nm_g_array_len(setting->interface_name) != 0) {
|
||||
nm_clear_pointer(&setting->interface_name, g_array_unref);
|
||||
if (nm_g_array_len(setting->interface_name.arr) != 0) {
|
||||
nm_clear_pointer(&setting->interface_name.arr, g_array_unref);
|
||||
_notify(setting, PROP_INTERFACE_NAME);
|
||||
}
|
||||
}
|
||||
|
|
@ -185,7 +187,7 @@ nm_setting_match_get_interface_names(NMSettingMatch *setting, guint *length)
|
|||
{
|
||||
g_return_val_if_fail(NM_IS_SETTING_MATCH(setting), NULL);
|
||||
|
||||
return nm_strvarray_get_strv(&setting->interface_name, length);
|
||||
return nm_strvarray_get_strv(&setting->interface_name.arr, length);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
@ -615,9 +617,6 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
|||
NMSettingMatch *self = NM_SETTING_MATCH(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_INTERFACE_NAME:
|
||||
g_value_take_boxed(value, nm_strvarray_get_strv_non_empty_dup(self->interface_name, NULL));
|
||||
break;
|
||||
case PROP_KERNEL_COMMAND_LINE:
|
||||
g_value_take_boxed(value,
|
||||
nm_strvarray_get_strv_non_empty_dup(self->kernel_command_line, NULL));
|
||||
|
|
@ -629,7 +628,7 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
|||
g_value_take_boxed(value, nm_strvarray_get_strv_non_empty_dup(self->path, NULL));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
_nm_setting_property_get_property_direct(object, prop_id, value, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -640,9 +639,6 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps
|
|||
NMSettingMatch *self = NM_SETTING_MATCH(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_INTERFACE_NAME:
|
||||
nm_strvarray_set_strv(&self->interface_name, g_value_get_boxed(value));
|
||||
break;
|
||||
case PROP_KERNEL_COMMAND_LINE:
|
||||
nm_strvarray_set_strv(&self->kernel_command_line, g_value_get_boxed(value));
|
||||
break;
|
||||
|
|
@ -653,7 +649,7 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps
|
|||
nm_strvarray_set_strv(&self->path, g_value_get_boxed(value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
_nm_setting_property_set_property_direct(object, prop_id, value, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -698,9 +694,9 @@ verify(NMSetting *setting, NMConnection *connection, GError **error)
|
|||
NMSettingMatch *self = NM_SETTING_MATCH(setting);
|
||||
guint i;
|
||||
|
||||
if (self->interface_name) {
|
||||
for (i = 0; i < self->interface_name->len; i++) {
|
||||
if (nm_str_is_empty(nm_strvarray_get_idx(self->interface_name, i))) {
|
||||
if (self->interface_name.arr) {
|
||||
for (i = 0; i < self->interface_name.arr->len; i++) {
|
||||
if (nm_str_is_empty(nm_strvarray_get_idx(self->interface_name.arr, i))) {
|
||||
g_set_error(error,
|
||||
NM_CONNECTION_ERROR,
|
||||
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
||||
|
|
@ -770,7 +766,7 @@ finalize(GObject *object)
|
|||
{
|
||||
NMSettingMatch *self = NM_SETTING_MATCH(object);
|
||||
|
||||
nm_clear_pointer(&self->interface_name, g_array_unref);
|
||||
nm_clear_pointer(&self->interface_name.arr, g_array_unref);
|
||||
nm_clear_pointer(&self->kernel_command_line, g_array_unref);
|
||||
nm_clear_pointer(&self->driver, g_array_unref);
|
||||
nm_clear_pointer(&self->path, g_array_unref);
|
||||
|
|
@ -781,8 +777,9 @@ finalize(GObject *object)
|
|||
static void
|
||||
nm_setting_match_class_init(NMSettingMatchClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS(klass);
|
||||
NMSettingClass *setting_class = NM_SETTING_CLASS(klass);
|
||||
GObjectClass *object_class = G_OBJECT_CLASS(klass);
|
||||
NMSettingClass *setting_class = NM_SETTING_CLASS(klass);
|
||||
GArray *properties_override = _nm_sett_info_property_override_create_array();
|
||||
|
||||
object_class->get_property = get_property;
|
||||
object_class->set_property = set_property;
|
||||
|
|
@ -810,12 +807,13 @@ nm_setting_match_class_init(NMSettingMatchClass *klass)
|
|||
*
|
||||
* Since: 1.14
|
||||
**/
|
||||
obj_properties[PROP_INTERFACE_NAME] = g_param_spec_boxed(
|
||||
NM_SETTING_MATCH_INTERFACE_NAME,
|
||||
"",
|
||||
"",
|
||||
G_TYPE_STRV,
|
||||
NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
||||
_nm_setting_property_define_direct_strv(properties_override,
|
||||
obj_properties,
|
||||
NM_SETTING_MATCH_INTERFACE_NAME,
|
||||
PROP_INTERFACE_NAME,
|
||||
NM_SETTING_PARAM_FUZZY_IGNORE,
|
||||
NMSettingMatch,
|
||||
interface_name);
|
||||
|
||||
/**
|
||||
* NMSettingMatch:kernel-command-line
|
||||
|
|
@ -901,5 +899,9 @@ nm_setting_match_class_init(NMSettingMatchClass *klass)
|
|||
|
||||
g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties);
|
||||
|
||||
_nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_MATCH, NULL, NULL, 0);
|
||||
_nm_setting_class_commit(setting_class,
|
||||
NM_META_SETTING_TYPE_MATCH,
|
||||
NULL,
|
||||
properties_override,
|
||||
0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -232,6 +232,14 @@ gboolean _nm_setting_clear_secrets(NMSetting *setting,
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
/* This holds a property of type NM_VALUE_TYPE_STRV. You probably want
|
||||
* to use nm_strvarray_*() API with this. */
|
||||
typedef struct {
|
||||
GArray *arr;
|
||||
} NMValueStrv;
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define NM_SETTING_PARAM_NONE 0
|
||||
|
||||
/* The property of the #NMSetting should be considered during comparisons that
|
||||
|
|
@ -277,6 +285,7 @@ extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_int64;
|
|||
extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_uint64;
|
||||
extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_string;
|
||||
extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_bytes;
|
||||
extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_strv;
|
||||
extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_enum;
|
||||
extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_flags;
|
||||
extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_mac_address;
|
||||
|
|
@ -774,6 +783,42 @@ _nm_properties_override(GArray *properties_override, const NMSettInfoProperty *p
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define _nm_setting_property_define_direct_strv(properties_override, \
|
||||
obj_properties, \
|
||||
prop_name, \
|
||||
prop_id, \
|
||||
param_flags, \
|
||||
private_struct_type, \
|
||||
private_struct_field, \
|
||||
... /* extra NMSettInfoProperty fields */) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
GParamSpec *_param_spec; \
|
||||
\
|
||||
G_STATIC_ASSERT(!NM_FLAGS_ANY((param_flags), ~(NM_SETTING_PARAM_FUZZY_IGNORE))); \
|
||||
\
|
||||
_param_spec = \
|
||||
g_param_spec_boxed("" prop_name "", \
|
||||
"", \
|
||||
"", \
|
||||
G_TYPE_STRV, \
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | (param_flags)); \
|
||||
\
|
||||
(obj_properties)[(prop_id)] = _param_spec; \
|
||||
\
|
||||
_nm_properties_override_gobj((properties_override), \
|
||||
_param_spec, \
|
||||
&nm_sett_info_propert_type_direct_strv, \
|
||||
.direct_offset = \
|
||||
NM_STRUCT_OFFSET_ENSURE_TYPE(NMValueStrv, \
|
||||
private_struct_type, \
|
||||
private_struct_field), \
|
||||
__VA_ARGS__); \
|
||||
} \
|
||||
G_STMT_END
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define _nm_setting_property_define_direct_enum(properties_override, \
|
||||
obj_properties, \
|
||||
prop_name, \
|
||||
|
|
|
|||
|
|
@ -774,6 +774,13 @@ _nm_setting_property_get_property_direct(GObject *object,
|
|||
g_value_set_boxed(value, *p_val);
|
||||
return;
|
||||
}
|
||||
case NM_VALUE_TYPE_STRV:
|
||||
{
|
||||
const NMValueStrv *p_val = _nm_setting_get_private_field(setting, sett_info, property_info);
|
||||
|
||||
g_value_take_boxed(value, nm_strvarray_get_strv_non_empty_dup(p_val->arr, NULL));
|
||||
return;
|
||||
}
|
||||
default:
|
||||
goto out_fail;
|
||||
}
|
||||
|
|
@ -909,6 +916,18 @@ _nm_setting_property_set_property_direct(GObject *object,
|
|||
*p_val = v ? g_bytes_ref(v) : NULL;
|
||||
goto out_notify;
|
||||
}
|
||||
case NM_VALUE_TYPE_STRV:
|
||||
{
|
||||
NMValueStrv *p_val = _nm_setting_get_private_field(setting, sett_info, property_info);
|
||||
const char *const *v;
|
||||
|
||||
v = g_value_get_boxed(value);
|
||||
if (nm_strvarray_equal_strv(p_val->arr, v, -1))
|
||||
return;
|
||||
|
||||
nm_strvarray_set_strv(&p_val->arr, v);
|
||||
goto out_notify;
|
||||
}
|
||||
default:
|
||||
goto out_fail;
|
||||
}
|
||||
|
|
@ -1026,6 +1045,11 @@ _init_direct(NMSetting *setting)
|
|||
nm_assert(!(*((const GBytes *const *)
|
||||
_nm_setting_get_private_field(setting, sett_info, property_info))));
|
||||
break;
|
||||
case NM_VALUE_TYPE_STRV:
|
||||
nm_assert(!((const NMValueStrv *)
|
||||
_nm_setting_get_private_field(setting, sett_info, property_info))
|
||||
->arr);
|
||||
break;
|
||||
default:
|
||||
nm_assert_not_reached();
|
||||
break;
|
||||
|
|
@ -1081,6 +1105,13 @@ _finalize_direct(NMSetting *setting)
|
|||
nm_clear_pointer(p_val, g_bytes_unref);
|
||||
break;
|
||||
}
|
||||
case NM_VALUE_TYPE_STRV:
|
||||
{
|
||||
NMValueStrv *p_val = _nm_setting_get_private_field(setting, sett_info, property_info);
|
||||
|
||||
nm_clear_pointer(&p_val->arr, g_array_unref);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
nm_assert_not_reached();
|
||||
break;
|
||||
|
|
@ -1199,6 +1230,20 @@ _nm_setting_property_to_dbus_fcn_direct(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_
|
|||
return NULL;
|
||||
return nm_g_bytes_to_variant_ay(val);
|
||||
}
|
||||
case NM_VALUE_TYPE_STRV:
|
||||
{
|
||||
const NMValueStrv *val;
|
||||
|
||||
/* Strv properties have always NULL as default. Setting "including_default" has no defined meaning
|
||||
* (but it could have). */
|
||||
nm_assert(!property_info->to_dbus_including_default);
|
||||
|
||||
val =
|
||||
(const NMValueStrv *) _nm_setting_get_private_field(setting, sett_info, property_info);
|
||||
if (!val->arr)
|
||||
return NULL;
|
||||
return g_variant_new_strv((const char *const *) val->arr->data, val->arr->len);
|
||||
}
|
||||
default:
|
||||
return nm_assert_unreachable_val(NULL);
|
||||
}
|
||||
|
|
@ -1545,6 +1590,8 @@ _nm_setting_property_from_dbus_fcn_direct(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS
|
|||
gs_unref_bytes GBytes *v = NULL;
|
||||
GBytes **p_val;
|
||||
|
||||
nm_assert(!property_info->property_type->from_dbus_direct_allow_transform);
|
||||
|
||||
if (!g_variant_is_of_type(value, G_VARIANT_TYPE_BYTESTRING))
|
||||
goto out_error_wrong_dbus_type;
|
||||
|
||||
|
|
@ -1557,6 +1604,28 @@ _nm_setting_property_from_dbus_fcn_direct(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS
|
|||
NM_SWAP(p_val, &v);
|
||||
goto out_notify;
|
||||
}
|
||||
case NM_VALUE_TYPE_STRV:
|
||||
{
|
||||
NMValueStrv *p_val;
|
||||
gs_free const char **ss = NULL;
|
||||
gsize ss_len;
|
||||
|
||||
nm_assert(!property_info->property_type->from_dbus_direct_allow_transform);
|
||||
|
||||
if (!g_variant_is_of_type(value, G_VARIANT_TYPE_STRING_ARRAY))
|
||||
goto out_error_wrong_dbus_type;
|
||||
|
||||
ss = g_variant_get_strv(value, &ss_len);
|
||||
nm_assert(ss_len <= G_MAXUINT);
|
||||
|
||||
p_val = _nm_setting_get_private_field(setting, sett_info, property_info);
|
||||
|
||||
if (nm_strvarray_equal_strv(p_val->arr, ss, ss_len))
|
||||
goto out_unchanged;
|
||||
|
||||
nm_strvarray_set_strv(&p_val->arr, ss);
|
||||
goto out_notify;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
@ -2465,6 +2534,9 @@ _nm_setting_property_compare_fcn_direct(_NM_SETT_INFO_PROP_COMPARE_FCN_ARGS _nm_
|
|||
return nm_streq0(*((const char *const *) p_a), *((const char *const *) p_b));
|
||||
case NM_VALUE_TYPE_BYTES:
|
||||
return nm_g_bytes_equal0(*((const GBytes *const *) p_a), *((const GBytes *const *) p_b));
|
||||
case NM_VALUE_TYPE_STRV:
|
||||
return nm_strvarray_equal(((const NMValueStrv *) p_a)->arr,
|
||||
((const NMValueStrv *) p_b)->arr);
|
||||
default:
|
||||
return nm_assert_unreachable_val(TRUE);
|
||||
}
|
||||
|
|
@ -3529,8 +3601,15 @@ const NMSettInfoPropertType nm_sett_info_propert_type_direct_bytes =
|
|||
.compare_fcn = _nm_setting_property_compare_fcn_direct,
|
||||
.to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct,
|
||||
.from_dbus_fcn = _nm_setting_property_from_dbus_fcn_direct,
|
||||
.from_dbus_is_full = TRUE,
|
||||
.from_dbus_direct_allow_transform = TRUE);
|
||||
.from_dbus_is_full = TRUE);
|
||||
|
||||
const NMSettInfoPropertType nm_sett_info_propert_type_direct_strv =
|
||||
NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_STRING_ARRAY,
|
||||
.direct_type = NM_VALUE_TYPE_STRV,
|
||||
.compare_fcn = _nm_setting_property_compare_fcn_direct,
|
||||
.to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct,
|
||||
.from_dbus_fcn = _nm_setting_property_from_dbus_fcn_direct,
|
||||
.from_dbus_is_full = TRUE);
|
||||
|
||||
const NMSettInfoPropertType nm_sett_info_propert_type_direct_enum =
|
||||
NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_INT32,
|
||||
|
|
|
|||
|
|
@ -4583,6 +4583,12 @@ test_setting_metadata(void)
|
|||
== _nm_setting_property_to_dbus_fcn_direct);
|
||||
g_assert(sip->param_spec);
|
||||
g_assert(sip->param_spec->value_type == G_TYPE_BYTES);
|
||||
} else if (sip->property_type->direct_type == NM_VALUE_TYPE_STRV) {
|
||||
g_assert(g_variant_type_equal(sip->property_type->dbus_type, "as"));
|
||||
g_assert(sip->property_type->to_dbus_fcn
|
||||
== _nm_setting_property_to_dbus_fcn_direct);
|
||||
g_assert(sip->param_spec);
|
||||
g_assert(sip->param_spec->value_type == G_TYPE_STRV);
|
||||
} else
|
||||
g_assert_not_reached();
|
||||
|
||||
|
|
@ -4671,7 +4677,12 @@ check_done:;
|
|||
}
|
||||
if (sip->property_type->from_dbus_fcn == _nm_setting_property_from_dbus_fcn_direct) {
|
||||
/* for the moment, all direct properties allow transformation. */
|
||||
g_assert(sip->property_type->from_dbus_direct_allow_transform);
|
||||
if (NM_IN_SET(sip->property_type->direct_type,
|
||||
NM_VALUE_TYPE_BYTES,
|
||||
NM_VALUE_TYPE_STRV))
|
||||
g_assert(!sip->property_type->from_dbus_direct_allow_transform);
|
||||
else
|
||||
g_assert(sip->property_type->from_dbus_direct_allow_transform);
|
||||
}
|
||||
|
||||
if (sip->property_type->from_dbus_fcn == _nm_setting_property_from_dbus_fcn_gprop)
|
||||
|
|
|
|||
|
|
@ -391,6 +391,7 @@ nm_value_type_to_json(NMValueType value_type, GString *gstr, gconstpointer p_fie
|
|||
nm_json_gstr_append_string(gstr, *((const char *const *) p_field));
|
||||
return;
|
||||
case NM_VALUE_TYPE_BYTES:
|
||||
case NM_VALUE_TYPE_STRV:
|
||||
case NM_VALUE_TYPE_NONE:
|
||||
case NM_VALUE_TYPE_UNSPEC:
|
||||
break;
|
||||
|
|
@ -428,12 +429,12 @@ nm_value_type_from_json(const NMJsonVt *vt,
|
|||
return (nm_jansson_json_as_string(vt, elem, out_val) > 0);
|
||||
|
||||
case NM_VALUE_TYPE_BYTES:
|
||||
case NM_VALUE_TYPE_STRV:
|
||||
case NM_VALUE_TYPE_NONE:
|
||||
case NM_VALUE_TYPE_UNSPEC:
|
||||
break;
|
||||
}
|
||||
nm_assert_not_reached();
|
||||
return FALSE;
|
||||
return nm_assert_unreachable_val(FALSE);
|
||||
}
|
||||
|
||||
#endif /* NM_VALUE_TYPE_DEFINE_FUNCTIONS */
|
||||
|
|
|
|||
|
|
@ -9,25 +9,26 @@
|
|||
typedef enum _nm_packed {
|
||||
NM_VALUE_TYPE_NONE = 0,
|
||||
NM_VALUE_TYPE_UNSPEC = 1,
|
||||
NM_VALUE_TYPE_BOOL = 2,
|
||||
NM_VALUE_TYPE_INT32 = 3,
|
||||
NM_VALUE_TYPE_INT = 4,
|
||||
NM_VALUE_TYPE_INT64 = 5,
|
||||
NM_VALUE_TYPE_UINT32 = 6,
|
||||
NM_VALUE_TYPE_UINT = 7,
|
||||
NM_VALUE_TYPE_UINT64 = 8,
|
||||
|
||||
NM_VALUE_TYPE_BOOL,
|
||||
NM_VALUE_TYPE_INT32,
|
||||
NM_VALUE_TYPE_INT,
|
||||
NM_VALUE_TYPE_INT64,
|
||||
NM_VALUE_TYPE_UINT32,
|
||||
NM_VALUE_TYPE_UINT,
|
||||
NM_VALUE_TYPE_UINT64,
|
||||
|
||||
/* Flags are for G_TYPE_FLAGS. That is, internally they are tracked
|
||||
* as a guint, they have a g_param_spec_flags() property and they are
|
||||
* serialized on D-Bus as "u". */
|
||||
NM_VALUE_TYPE_FLAGS = 9,
|
||||
NM_VALUE_TYPE_FLAGS,
|
||||
|
||||
/* G_TYPE_ENUM */
|
||||
NM_VALUE_TYPE_ENUM = 10,
|
||||
NM_VALUE_TYPE_ENUM,
|
||||
|
||||
NM_VALUE_TYPE_STRING = 11,
|
||||
|
||||
NM_VALUE_TYPE_BYTES = 12,
|
||||
NM_VALUE_TYPE_STRING,
|
||||
NM_VALUE_TYPE_BYTES,
|
||||
NM_VALUE_TYPE_STRV,
|
||||
} NMValueType;
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
@ -112,14 +113,17 @@ nm_value_type_cmp(NMValueType value_type, gconstpointer p_a, gconstpointer p_b)
|
|||
return 0;
|
||||
case NM_VALUE_TYPE_STRING:
|
||||
return nm_strcmp0(*((const char *const *) p_a), *((const char *const *) p_b));
|
||||
|
||||
case NM_VALUE_TYPE_BYTES:
|
||||
return nm_g_bytes_equal0(*((const GBytes *const *) p_a), *((const GBytes *const *) p_b));
|
||||
case NM_VALUE_TYPE_STRV:
|
||||
/* These types have implementation define memory representations. */
|
||||
break;
|
||||
|
||||
case NM_VALUE_TYPE_NONE:
|
||||
case NM_VALUE_TYPE_UNSPEC:
|
||||
break;
|
||||
}
|
||||
nm_assert_not_reached();
|
||||
return 0;
|
||||
return nm_assert_unreachable_val(0);
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
|
|
@ -163,14 +167,12 @@ nm_value_type_copy(NMValueType value_type, gpointer dst, gconstpointer src)
|
|||
*((char **) dst) = g_strdup(*((const char *const *) src));
|
||||
}
|
||||
return;
|
||||
case NM_VALUE_TYPE_BYTES:
|
||||
/* self assignment safe! */
|
||||
if (*((GBytes **) dst) != *((const GBytes *const *) src)) {
|
||||
_nm_unused gs_unref_bytes GBytes *old = *((GBytes **) dst);
|
||||
|
||||
*((GBytes **) dst) = g_bytes_ref(*((GBytes *const *) src));
|
||||
}
|
||||
return;
|
||||
case NM_VALUE_TYPE_BYTES:
|
||||
case NM_VALUE_TYPE_STRV:
|
||||
/* These types have implementation define memory representations. */
|
||||
break;
|
||||
|
||||
case NM_VALUE_TYPE_NONE:
|
||||
case NM_VALUE_TYPE_UNSPEC:
|
||||
break;
|
||||
|
|
@ -212,14 +214,18 @@ nm_value_type_get_from_variant(NMValueType value_type,
|
|||
return;
|
||||
|
||||
case NM_VALUE_TYPE_BYTES:
|
||||
case NM_VALUE_TYPE_STRV:
|
||||
/* These types have implementation define memory representations. */
|
||||
break;
|
||||
|
||||
case NM_VALUE_TYPE_INT:
|
||||
case NM_VALUE_TYPE_UINT:
|
||||
case NM_VALUE_TYPE_ENUM:
|
||||
case NM_VALUE_TYPE_FLAGS:
|
||||
/* These types don't have a defined variant type, because it's not
|
||||
* clear how many bits we would need or how to handle the type. */
|
||||
break;
|
||||
|
||||
/* fall-through */
|
||||
case NM_VALUE_TYPE_NONE:
|
||||
case NM_VALUE_TYPE_UNSPEC:
|
||||
break;
|
||||
|
|
@ -230,8 +236,7 @@ nm_value_type_get_from_variant(NMValueType value_type,
|
|||
static inline GVariant *
|
||||
nm_value_type_to_variant(NMValueType value_type, gconstpointer src)
|
||||
{
|
||||
const char *v_string;
|
||||
const GBytes *v_bytes;
|
||||
const char *v_string;
|
||||
|
||||
switch (value_type) {
|
||||
case NM_VALUE_TYPE_BOOL:
|
||||
|
|
@ -247,9 +252,11 @@ nm_value_type_to_variant(NMValueType value_type, gconstpointer src)
|
|||
case NM_VALUE_TYPE_STRING:
|
||||
v_string = *((const char *const *) src);
|
||||
return v_string ? g_variant_new_string(v_string) : NULL;
|
||||
|
||||
case NM_VALUE_TYPE_BYTES:
|
||||
v_bytes = *((const GBytes *const *) src);
|
||||
return v_bytes ? nm_g_bytes_to_variant_ay(v_bytes) : NULL;
|
||||
case NM_VALUE_TYPE_STRV:
|
||||
/* These types have implementation define memory representations. */
|
||||
break;
|
||||
|
||||
case NM_VALUE_TYPE_INT:
|
||||
case NM_VALUE_TYPE_UINT:
|
||||
|
|
@ -257,14 +264,13 @@ nm_value_type_to_variant(NMValueType value_type, gconstpointer src)
|
|||
case NM_VALUE_TYPE_FLAGS:
|
||||
/* These types don't have a defined variant type, because it's not
|
||||
* clear how many bits we would need or how to handle the type. */
|
||||
break;
|
||||
|
||||
/* fall-through */
|
||||
case NM_VALUE_TYPE_NONE:
|
||||
case NM_VALUE_TYPE_UNSPEC:
|
||||
break;
|
||||
}
|
||||
nm_assert_not_reached();
|
||||
return NULL;
|
||||
return nm_assert_unreachable_val(NULL);
|
||||
}
|
||||
|
||||
static inline const GVariantType *
|
||||
|
|
@ -285,6 +291,8 @@ nm_value_type_get_variant_type(NMValueType value_type)
|
|||
return G_VARIANT_TYPE_STRING;
|
||||
case NM_VALUE_TYPE_BYTES:
|
||||
return G_VARIANT_TYPE_BYTESTRING;
|
||||
case NM_VALUE_TYPE_STRV:
|
||||
return G_VARIANT_TYPE_STRING_ARRAY;
|
||||
|
||||
case NM_VALUE_TYPE_INT:
|
||||
case NM_VALUE_TYPE_UINT:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue