mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-03 23:20:15 +01:00
libnm: add nm_sett_info_propert_type_direct_int32 property type
This commit is contained in:
parent
82e9f43289
commit
e399fda04c
4 changed files with 143 additions and 14 deletions
|
|
@ -289,6 +289,7 @@ extern const NMSettInfoPropertType nm_sett_info_propert_type_plain_i;
|
|||
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_string;
|
||||
extern const NMSettInfoPropertType nm_sett_info_propert_type_direct_mac_address;
|
||||
|
|
@ -564,9 +565,9 @@ _nm_properties_override(GArray *properties_override, const NMSettInfoProperty *p
|
|||
G_STATIC_ASSERT( \
|
||||
!NM_FLAGS_ANY((param_flags), \
|
||||
~(NM_SETTING_PARAM_FUZZY_IGNORE | NM_SETTING_PARAM_INFERRABLE))); \
|
||||
G_STATIC_ASSERT((min_value) <= (guint64) G_MAXUINT32); \
|
||||
G_STATIC_ASSERT((min_value) <= (guint64) (default_value)); \
|
||||
G_STATIC_ASSERT((default_value) <= (guint64) (max_value)); \
|
||||
G_STATIC_ASSERT((max_value) <= (guint64) G_MAXUINT32); \
|
||||
G_STATIC_ASSERT((default_value) <= (guint64) G_MAXUINT32); \
|
||||
\
|
||||
_param_spec = \
|
||||
g_param_spec_uint("" prop_name "", \
|
||||
|
|
@ -591,6 +592,52 @@ _nm_properties_override(GArray *properties_override, const NMSettInfoProperty *p
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define _nm_setting_property_define_direct_int32(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) >= (gint64) (G_MININT32)); \
|
||||
G_STATIC_ASSERT((min_value) <= (gint64) (default_value)); \
|
||||
G_STATIC_ASSERT((default_value) <= (gint64) (max_value)); \
|
||||
G_STATIC_ASSERT((max_value) <= (gint64) G_MAXUINT32); \
|
||||
\
|
||||
_param_spec = \
|
||||
g_param_spec_int("" 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_int32, \
|
||||
.direct_offset = \
|
||||
NM_STRUCT_OFFSET_ENSURE_TYPE(gint32, 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, \
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ typedef struct {
|
|||
char * mac_address;
|
||||
guint16 pan_id;
|
||||
guint16 short_address;
|
||||
gint16 page;
|
||||
gint32 page;
|
||||
gint16 channel;
|
||||
} NMSettingWpanPrivate;
|
||||
|
||||
|
|
@ -265,7 +265,6 @@ nm_setting_wpan_init(NMSettingWpan *setting)
|
|||
|
||||
priv->pan_id = G_MAXUINT16;
|
||||
priv->short_address = G_MAXUINT16;
|
||||
priv->page = NM_SETTING_WPAN_PAGE_DEFAULT;
|
||||
priv->channel = NM_SETTING_WPAN_CHANNEL_DEFAULT;
|
||||
}
|
||||
|
||||
|
|
@ -297,8 +296,9 @@ finalize(GObject *object)
|
|||
static void
|
||||
nm_setting_wpan_class_init(NMSettingWpanClass *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();
|
||||
|
||||
g_type_class_add_private(setting_class, sizeof(NMSettingWpanPrivate));
|
||||
|
||||
|
|
@ -363,13 +363,16 @@ nm_setting_wpan_class_init(NMSettingWpanClass *klass)
|
|||
*
|
||||
* Since: 1.16
|
||||
**/
|
||||
obj_properties[PROP_PAGE] = g_param_spec_int(NM_SETTING_WPAN_PAGE,
|
||||
"",
|
||||
"",
|
||||
G_MININT16,
|
||||
G_MAXINT16,
|
||||
NM_SETTING_WPAN_PAGE_DEFAULT,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
||||
_nm_setting_property_define_direct_int32(properties_override,
|
||||
obj_properties,
|
||||
NM_SETTING_WPAN_PAGE,
|
||||
PROP_PAGE,
|
||||
G_MININT16,
|
||||
G_MAXINT16,
|
||||
NM_SETTING_WPAN_PAGE_DEFAULT,
|
||||
NM_SETTING_PARAM_NONE,
|
||||
NMSettingWpanPrivate,
|
||||
page);
|
||||
|
||||
/**
|
||||
* NMSettingWpan:channel:
|
||||
|
|
@ -389,5 +392,9 @@ nm_setting_wpan_class_init(NMSettingWpanClass *klass)
|
|||
|
||||
g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties);
|
||||
|
||||
_nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_WPAN, NULL, NULL, 0);
|
||||
_nm_setting_class_commit(setting_class,
|
||||
NM_META_SETTING_TYPE_WPAN,
|
||||
NULL,
|
||||
properties_override,
|
||||
NM_SETT_INFO_PRIVATE_OFFSET_FROM_CLASS);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -702,6 +702,14 @@ _nm_setting_property_get_property_direct(GObject * object,
|
|||
g_value_set_boolean(value, *p_val);
|
||||
return;
|
||||
}
|
||||
case NM_VALUE_TYPE_INT32:
|
||||
{
|
||||
const gint32 *p_val =
|
||||
_nm_setting_get_private(setting, sett_info, property_info->direct_offset);
|
||||
|
||||
g_value_set_int(value, *p_val);
|
||||
return;
|
||||
}
|
||||
case NM_VALUE_TYPE_UINT32:
|
||||
{
|
||||
const guint32 *p_val =
|
||||
|
|
@ -762,6 +770,21 @@ _nm_setting_property_set_property_direct(GObject * object,
|
|||
*p_val = v;
|
||||
goto out_notify;
|
||||
}
|
||||
case NM_VALUE_TYPE_INT32:
|
||||
{
|
||||
gint32 *p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset);
|
||||
int v;
|
||||
|
||||
v = g_value_get_int(value);
|
||||
if (*p_val == v)
|
||||
return;
|
||||
*p_val = v;
|
||||
|
||||
/* truncation cannot happen, because the param_spec is supposed to have suitable
|
||||
* minimum/maximum values so that we are in range for int32. */
|
||||
nm_assert(*p_val == v);
|
||||
goto out_notify;
|
||||
}
|
||||
case NM_VALUE_TYPE_UINT32:
|
||||
{
|
||||
guint32 *p_val = _nm_setting_get_private(setting, sett_info, property_info->direct_offset);
|
||||
|
|
@ -833,6 +856,17 @@ _init_direct(NMSetting *setting)
|
|||
*p_val = def_val;
|
||||
break;
|
||||
}
|
||||
case NM_VALUE_TYPE_INT32:
|
||||
{
|
||||
gint32 *p_val =
|
||||
_nm_setting_get_private(setting, sett_info, property_info->direct_offset);
|
||||
int def_val;
|
||||
|
||||
def_val = NM_G_PARAM_SPEC_GET_DEFAULT_INT(property_info->param_spec);
|
||||
nm_assert(*p_val == 0);
|
||||
*p_val = def_val;
|
||||
break;
|
||||
}
|
||||
case NM_VALUE_TYPE_UINT32:
|
||||
{
|
||||
guint32 *p_val =
|
||||
|
|
@ -879,6 +913,7 @@ _finalize_direct(NMSetting *setting)
|
|||
switch (property_info->property_type->direct_type) {
|
||||
case NM_VALUE_TYPE_NONE:
|
||||
case NM_VALUE_TYPE_BOOL:
|
||||
case NM_VALUE_TYPE_INT32:
|
||||
case NM_VALUE_TYPE_UINT32:
|
||||
break;
|
||||
case NM_VALUE_TYPE_STRING:
|
||||
|
|
@ -917,6 +952,17 @@ _nm_setting_property_to_dbus_fcn_direct(const NMSettInfoSetting *
|
|||
return NULL;
|
||||
return g_variant_ref(nm_g_variant_singleton_b(val));
|
||||
}
|
||||
case NM_VALUE_TYPE_INT32:
|
||||
{
|
||||
gint32 val;
|
||||
|
||||
val =
|
||||
*((gint32 *) _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_INT(property_info->param_spec))
|
||||
return NULL;
|
||||
return g_variant_new_int32(val);
|
||||
}
|
||||
case NM_VALUE_TYPE_UINT32:
|
||||
{
|
||||
guint32 val;
|
||||
|
|
@ -1885,6 +1931,8 @@ _nm_setting_property_compare_fcn_direct(const NMSettInfoSetting * sett_info,
|
|||
switch (property_info->property_type->direct_type) {
|
||||
case NM_VALUE_TYPE_BOOL:
|
||||
return *((const bool *) p_a) == *((const bool *) p_b);
|
||||
case NM_VALUE_TYPE_INT32:
|
||||
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_STRING:
|
||||
|
|
@ -2944,6 +2992,14 @@ const NMSettInfoPropertType nm_sett_info_propert_type_direct_boolean =
|
|||
.from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop,
|
||||
.from_dbus_is_full = TRUE);
|
||||
|
||||
const NMSettInfoPropertType nm_sett_info_propert_type_direct_int32 =
|
||||
NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_INT32,
|
||||
.direct_type = NM_VALUE_TYPE_INT32,
|
||||
.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_gprop,
|
||||
.from_dbus_is_full = TRUE);
|
||||
|
||||
const NMSettInfoPropertType nm_sett_info_propert_type_direct_uint32 =
|
||||
NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_UINT32,
|
||||
.direct_type = NM_VALUE_TYPE_UINT32,
|
||||
|
|
|
|||
|
|
@ -4450,6 +4450,25 @@ 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_BOOLEAN);
|
||||
can_set_including_default = TRUE;
|
||||
} else if (sip->property_type->direct_type == NM_VALUE_TYPE_INT32) {
|
||||
const GParamSpecInt *pspec;
|
||||
|
||||
g_assert(sip->property_type == &nm_sett_info_propert_type_direct_int32);
|
||||
g_assert(g_variant_type_equal(sip->property_type->dbus_type, "i"));
|
||||
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_INT);
|
||||
|
||||
pspec = NM_G_PARAM_SPEC_CAST_INT(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);
|
||||
|
||||
g_assert_cmpint(pspec->minimum, >=, (gint64) G_MININT32);
|
||||
g_assert_cmpint(pspec->maximum, <=, (gint64) G_MAXINT32);
|
||||
|
||||
can_set_including_default = TRUE;
|
||||
} else if (sip->property_type->direct_type == NM_VALUE_TYPE_UINT32) {
|
||||
const GParamSpecUInt *pspec;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue