mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-01 06:00:12 +01:00
libnm: add direct property type "int64"
This commit is contained in:
parent
5e7400c832
commit
710c54760c
3 changed files with 143 additions and 0 deletions
|
|
@ -276,6 +276,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_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;
|
||||
|
|
@ -585,6 +586,52 @@ _nm_properties_override(GArray *properties_override, const NMSettInfoProperty *p
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define _nm_setting_property_define_direct_int64(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) >= G_MININT64); \
|
||||
G_STATIC_ASSERT((min_value) <= (default_value)); \
|
||||
G_STATIC_ASSERT((default_value) <= (max_value)); \
|
||||
G_STATIC_ASSERT((max_value) <= G_MAXINT64); \
|
||||
\
|
||||
_param_spec = \
|
||||
g_param_spec_int64("" 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_int64, \
|
||||
.direct_offset = \
|
||||
NM_STRUCT_OFFSET_ENSURE_TYPE(gint64, private_struct_type, private_struct_field), \
|
||||
__VA_ARGS__); \
|
||||
} \
|
||||
G_STMT_END
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define _nm_setting_property_define_direct_uint64(properties_override, \
|
||||
obj_properties, \
|
||||
prop_name, \
|
||||
|
|
|
|||
|
|
@ -729,6 +729,14 @@ _nm_setting_property_get_property_direct(GObject *object,
|
|||
g_value_set_uint(value, *p_val);
|
||||
return;
|
||||
}
|
||||
case NM_VALUE_TYPE_INT64:
|
||||
{
|
||||
const gint64 *p_val =
|
||||
_nm_setting_get_private(setting, sett_info, property_info->direct_offset);
|
||||
|
||||
g_value_set_int64(value, *p_val);
|
||||
return;
|
||||
}
|
||||
case NM_VALUE_TYPE_UINT64:
|
||||
{
|
||||
const guint64 *p_val =
|
||||
|
|
@ -840,6 +848,17 @@ _nm_setting_property_set_property_direct(GObject *object,
|
|||
nm_assert(*p_val == v);
|
||||
goto out_notify;
|
||||
}
|
||||
case NM_VALUE_TYPE_INT64:
|
||||
{
|
||||
gint64 *p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset);
|
||||
gint64 v;
|
||||
|
||||
v = g_value_get_int64(value);
|
||||
if (*p_val == v)
|
||||
return;
|
||||
*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);
|
||||
|
|
@ -963,6 +982,17 @@ _init_direct(NMSetting *setting)
|
|||
*p_val = def_val;
|
||||
break;
|
||||
}
|
||||
case NM_VALUE_TYPE_INT64:
|
||||
{
|
||||
gint64 *p_val =
|
||||
_nm_setting_get_private(setting, sett_info, property_info->direct_offset);
|
||||
gint64 def_val;
|
||||
|
||||
def_val = NM_G_PARAM_SPEC_GET_DEFAULT_INT64(property_info->param_spec);
|
||||
nm_assert(*p_val == 0);
|
||||
*p_val = def_val;
|
||||
break;
|
||||
}
|
||||
case NM_VALUE_TYPE_UINT64:
|
||||
{
|
||||
guint64 *p_val =
|
||||
|
|
@ -1037,6 +1067,7 @@ _finalize_direct(NMSetting *setting)
|
|||
case NM_VALUE_TYPE_BOOL:
|
||||
case NM_VALUE_TYPE_INT32:
|
||||
case NM_VALUE_TYPE_UINT32:
|
||||
case NM_VALUE_TYPE_INT64:
|
||||
case NM_VALUE_TYPE_UINT64:
|
||||
case NM_VALUE_TYPE_ENUM:
|
||||
case NM_VALUE_TYPE_FLAGS:
|
||||
|
|
@ -1105,6 +1136,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_INT64:
|
||||
{
|
||||
gint64 val;
|
||||
|
||||
val =
|
||||
*((gint64 *) _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_INT64(property_info->param_spec))
|
||||
return NULL;
|
||||
return g_variant_new_int64(val);
|
||||
}
|
||||
case NM_VALUE_TYPE_UINT64:
|
||||
{
|
||||
guint64 val;
|
||||
|
|
@ -1378,6 +1420,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_INT64:
|
||||
{
|
||||
const GParamSpecInt64 *param_spec;
|
||||
gint64 *p_val;
|
||||
gint64 v;
|
||||
|
||||
if (g_variant_is_of_type(value, G_VARIANT_TYPE_INT64))
|
||||
v = g_variant_get_int64(value);
|
||||
else {
|
||||
if (!_variant_get_value_transform(property_info,
|
||||
value,
|
||||
G_TYPE_INT64,
|
||||
g_value_get_int64,
|
||||
&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_INT64(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_UINT64:
|
||||
{
|
||||
const GParamSpecUInt64 *param_spec;
|
||||
|
|
@ -2406,6 +2475,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_INT64:
|
||||
return *((const gint64 *) p_a) == *((const gint64 *) p_b);
|
||||
case NM_VALUE_TYPE_UINT64:
|
||||
return *((const guint64 *) p_a) == *((const guint64 *) p_b);
|
||||
case NM_VALUE_TYPE_ENUM:
|
||||
|
|
@ -3459,6 +3530,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_int64 =
|
||||
NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_INT64,
|
||||
.direct_type = NM_VALUE_TYPE_INT64,
|
||||
.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_uint64 =
|
||||
NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_UINT64,
|
||||
.direct_type = NM_VALUE_TYPE_UINT64,
|
||||
|
|
|
|||
|
|
@ -4490,6 +4490,22 @@ 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_INT64) {
|
||||
const GParamSpecInt64 *pspec;
|
||||
|
||||
g_assert(sip->property_type == &nm_sett_info_propert_type_direct_int64);
|
||||
g_assert(g_variant_type_equal(sip->property_type->dbus_type, "x"));
|
||||
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_INT64);
|
||||
|
||||
pspec = NM_G_PARAM_SPEC_CAST_INT64(sip->param_spec);
|
||||
g_assert_cmpint(pspec->minimum, <=, pspec->maximum);
|
||||
g_assert_cmpint(pspec->default_value, >=, pspec->minimum);
|
||||
g_assert_cmpint(pspec->default_value, <=, pspec->maximum);
|
||||
|
||||
can_set_including_default = TRUE;
|
||||
} else if (sip->property_type->direct_type == NM_VALUE_TYPE_UINT64) {
|
||||
const GParamSpecUInt64 *pspec;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue