mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-03-16 08:30:37 +01:00
libnm: add direct property type "uint64"
This commit is contained in:
parent
093f434cd0
commit
1059b60873
3 changed files with 144 additions and 0 deletions
|
|
@ -291,6 +291,7 @@ extern const NMSettInfoPropertType nm_sett_info_propert_type_plain_u;
|
|||
extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_boolean;
|
||||
extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_int32;
|
||||
extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_uint32;
|
||||
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_flags;
|
||||
extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_mac_address;
|
||||
|
|
@ -597,6 +598,51 @@ _nm_properties_override(GArray *properties_override, const NMSettInfoProperty *p
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define _nm_setting_property_define_direct_uint64(properties_override, \
|
||||
obj_properties, \
|
||||
prop_name, \
|
||||
prop_id, \
|
||||
min_value, \
|
||||
max_value, \
|
||||
default_value, \
|
||||
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 | NM_SETTING_PARAM_INFERRABLE))); \
|
||||
G_STATIC_ASSERT((min_value) <= (default_value)); \
|
||||
G_STATIC_ASSERT((default_value) == 0 || (default_value) -1u < (max_value)); \
|
||||
G_STATIC_ASSERT((max_value) <= G_MAXUINT64); \
|
||||
\
|
||||
_param_spec = \
|
||||
g_param_spec_uint64("" prop_name "", \
|
||||
"", \
|
||||
"", \
|
||||
(min_value), \
|
||||
(max_value), \
|
||||
(default_value), \
|
||||
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_uint64, \
|
||||
.direct_offset = \
|
||||
NM_STRUCT_OFFSET_ENSURE_TYPE(guint64, private_struct_type, private_struct_field), \
|
||||
__VA_ARGS__); \
|
||||
} \
|
||||
G_STMT_END
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define _nm_setting_property_define_direct_string_full(properties_override, \
|
||||
obj_properties, \
|
||||
prop_name, \
|
||||
|
|
|
|||
|
|
@ -744,6 +744,14 @@ _nm_setting_property_get_property_direct(GObject * object,
|
|||
g_value_set_uint(value, *p_val);
|
||||
return;
|
||||
}
|
||||
case NM_VALUE_TYPE_UINT64:
|
||||
{
|
||||
const guint64 *p_val =
|
||||
_nm_setting_get_private(setting, sett_info, property_info->direct_offset);
|
||||
|
||||
g_value_set_uint64(value, *p_val);
|
||||
return;
|
||||
}
|
||||
case NM_VALUE_TYPE_FLAGS:
|
||||
{
|
||||
const guint *p_val =
|
||||
|
|
@ -831,6 +839,17 @@ _nm_setting_property_set_property_direct(GObject * object,
|
|||
nm_assert(*p_val == v);
|
||||
goto out_notify;
|
||||
}
|
||||
case NM_VALUE_TYPE_UINT64:
|
||||
{
|
||||
guint64 *p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset);
|
||||
guint64 v;
|
||||
|
||||
v = g_value_get_uint64(value);
|
||||
if (*p_val == v)
|
||||
return;
|
||||
*p_val = v;
|
||||
goto out_notify;
|
||||
}
|
||||
case NM_VALUE_TYPE_FLAGS:
|
||||
{
|
||||
guint *p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset);
|
||||
|
|
@ -919,6 +938,17 @@ _init_direct(NMSetting *setting)
|
|||
*p_val = def_val;
|
||||
break;
|
||||
}
|
||||
case NM_VALUE_TYPE_UINT64:
|
||||
{
|
||||
guint64 *p_val =
|
||||
_nm_setting_get_private(setting, sett_info, property_info->direct_offset);
|
||||
guint64 def_val;
|
||||
|
||||
def_val = NM_G_PARAM_SPEC_GET_DEFAULT_UINT64(property_info->param_spec);
|
||||
nm_assert(*p_val == 0);
|
||||
*p_val = def_val;
|
||||
break;
|
||||
}
|
||||
case NM_VALUE_TYPE_FLAGS:
|
||||
{
|
||||
guint *p_val =
|
||||
|
|
@ -967,6 +997,7 @@ _finalize_direct(NMSetting *setting)
|
|||
case NM_VALUE_TYPE_BOOL:
|
||||
case NM_VALUE_TYPE_INT32:
|
||||
case NM_VALUE_TYPE_UINT32:
|
||||
case NM_VALUE_TYPE_UINT64:
|
||||
case NM_VALUE_TYPE_FLAGS:
|
||||
break;
|
||||
case NM_VALUE_TYPE_STRING:
|
||||
|
|
@ -1022,6 +1053,17 @@ _nm_setting_property_to_dbus_fcn_direct(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_
|
|||
return NULL;
|
||||
return g_variant_new_uint32(val);
|
||||
}
|
||||
case NM_VALUE_TYPE_UINT64:
|
||||
{
|
||||
guint64 val;
|
||||
|
||||
val = *(
|
||||
(guint64 *) _nm_setting_get_private(setting, sett_info, property_info->direct_offset));
|
||||
if (!property_info->to_dbus_including_default
|
||||
&& val == NM_G_PARAM_SPEC_GET_DEFAULT_UINT64(property_info->param_spec))
|
||||
return NULL;
|
||||
return g_variant_new_uint64(val);
|
||||
}
|
||||
case NM_VALUE_TYPE_FLAGS:
|
||||
{
|
||||
guint val;
|
||||
|
|
@ -1266,6 +1308,33 @@ _nm_setting_property_from_dbus_fcn_direct(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS
|
|||
*p_val = v;
|
||||
goto out_notify;
|
||||
}
|
||||
case NM_VALUE_TYPE_UINT64:
|
||||
{
|
||||
const GParamSpecUInt64 *param_spec;
|
||||
guint64 * p_val;
|
||||
guint64 v;
|
||||
|
||||
if (g_variant_is_of_type(value, G_VARIANT_TYPE_UINT64))
|
||||
v = g_variant_get_uint64(value);
|
||||
else {
|
||||
if (!_variant_get_value_transform(property_info,
|
||||
value,
|
||||
G_TYPE_UINT64,
|
||||
g_value_get_uint64,
|
||||
&v))
|
||||
goto out_error_wrong_dbus_type;
|
||||
}
|
||||
|
||||
p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset);
|
||||
if (*p_val == v)
|
||||
goto out_unchanged;
|
||||
|
||||
param_spec = NM_G_PARAM_SPEC_CAST_UINT64(property_info->param_spec);
|
||||
if (v < param_spec->minimum || v > param_spec->maximum)
|
||||
goto out_error_param_spec_validation;
|
||||
*p_val = v;
|
||||
goto out_notify;
|
||||
}
|
||||
case NM_VALUE_TYPE_FLAGS:
|
||||
{
|
||||
const GParamSpecFlags *param_spec;
|
||||
|
|
@ -2215,6 +2284,8 @@ _nm_setting_property_compare_fcn_direct(_NM_SETT_INFO_PROP_COMPARE_FCN_ARGS _nm_
|
|||
return *((const gint32 *) p_a) == *((const gint32 *) p_b);
|
||||
case NM_VALUE_TYPE_UINT32:
|
||||
return *((const guint32 *) p_a) == *((const guint32 *) p_b);
|
||||
case NM_VALUE_TYPE_UINT64:
|
||||
return *((const guint64 *) p_a) == *((const guint64 *) p_b);
|
||||
case NM_VALUE_TYPE_FLAGS:
|
||||
return *((const guint *) p_a) == *((const guint *) p_b);
|
||||
case NM_VALUE_TYPE_STRING:
|
||||
|
|
@ -3262,6 +3333,15 @@ const NMSettInfoPropertType nm_sett_info_propert_type_direct_uint32 =
|
|||
.from_dbus_is_full = TRUE,
|
||||
.from_dbus_direct_allow_transform = TRUE);
|
||||
|
||||
const NMSettInfoPropertType nm_sett_info_propert_type_direct_uint64 =
|
||||
NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_UINT64,
|
||||
.direct_type = NM_VALUE_TYPE_UINT64,
|
||||
.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);
|
||||
|
||||
const NMSettInfoPropertType nm_sett_info_propert_type_direct_string =
|
||||
NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_STRING,
|
||||
.direct_type = NM_VALUE_TYPE_STRING,
|
||||
|
|
|
|||
|
|
@ -4489,6 +4489,24 @@ test_setting_metadata(void)
|
|||
|
||||
g_assert_cmpint(pspec->maximum, <=, (guint64) G_MAXUINT32);
|
||||
|
||||
can_set_including_default = TRUE;
|
||||
} else if (sip->property_type->direct_type == NM_VALUE_TYPE_UINT64) {
|
||||
const GParamSpecUInt64 *pspec;
|
||||
|
||||
g_assert(sip->property_type == &nm_sett_info_propert_type_direct_uint64);
|
||||
g_assert(g_variant_type_equal(sip->property_type->dbus_type, "t"));
|
||||
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_UINT64);
|
||||
|
||||
pspec = NM_G_PARAM_SPEC_CAST_UINT64(sip->param_spec);
|
||||
g_assert_cmpuint(pspec->minimum, <=, pspec->maximum);
|
||||
g_assert_cmpuint(pspec->default_value, >=, pspec->minimum);
|
||||
g_assert_cmpuint(pspec->default_value, <=, pspec->maximum);
|
||||
|
||||
g_assert_cmpuint(pspec->maximum, <=, G_MAXUINT64);
|
||||
|
||||
can_set_including_default = TRUE;
|
||||
} else if (sip->property_type->direct_type == NM_VALUE_TYPE_FLAGS) {
|
||||
const GParamSpecFlags *pspec;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue