mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-14 09:50:35 +01:00
libnm: add direct_offset for string properties
And, as an example used for property "connection.stable-id".
This commit is contained in:
parent
233776c2c7
commit
7556b4f382
4 changed files with 103 additions and 6 deletions
|
|
@ -1956,12 +1956,13 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass)
|
|||
* description: Token to generate stable IDs.
|
||||
* ---end---
|
||||
*/
|
||||
_nm_setting_property_define_string(properties_override,
|
||||
obj_properties,
|
||||
NM_SETTING_CONNECTION_STABLE_ID,
|
||||
PROP_STABLE_ID,
|
||||
NM_SETTING_PARAM_FUZZY_IGNORE,
|
||||
nm_setting_connection_get_stable_id);
|
||||
_nm_setting_property_define_direct_string(properties_override,
|
||||
obj_properties,
|
||||
NM_SETTING_CONNECTION_STABLE_ID,
|
||||
PROP_STABLE_ID,
|
||||
NM_SETTING_PARAM_FUZZY_IGNORE,
|
||||
NMSettingConnectionPrivate,
|
||||
stable_id);
|
||||
|
||||
/**
|
||||
* NMSettingConnection:interface-name:
|
||||
|
|
|
|||
|
|
@ -287,6 +287,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_string;
|
||||
|
||||
extern const NMSettInfoPropertType nm_sett_info_propert_type_string;
|
||||
|
||||
|
|
@ -478,6 +479,69 @@ _nm_properties_override(GArray *properties_override, const NMSettInfoProperty *p
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define _nm_setting_property_define_direct_string_full(properties_override, \
|
||||
obj_properties, \
|
||||
prop_name, \
|
||||
prop_id, \
|
||||
param_flags, \
|
||||
property_type, \
|
||||
private_struct_type, \
|
||||
private_struct_field, \
|
||||
...) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
GParamSpec * _param_spec; \
|
||||
const NMSettInfoPropertType *_property_type = (property_type); \
|
||||
\
|
||||
G_STATIC_ASSERT(!NM_FLAGS_ANY((param_flags), \
|
||||
~(NM_SETTING_PARAM_SECRET | NM_SETTING_PARAM_FUZZY_IGNORE \
|
||||
| NM_SETTING_PARAM_INFERRABLE \
|
||||
| NM_SETTING_PARAM_REAPPLY_IMMEDIATELY))); \
|
||||
\
|
||||
nm_assert(_property_type); \
|
||||
nm_assert(g_variant_type_equal(_property_type->dbus_type, "s")); \
|
||||
nm_assert(_property_type->direct_type == NM_VALUE_TYPE_STRING); \
|
||||
nm_assert(_property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_direct); \
|
||||
\
|
||||
_param_spec = \
|
||||
g_param_spec_string("" prop_name "", \
|
||||
"", \
|
||||
"", \
|
||||
NULL, \
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | (param_flags)); \
|
||||
\
|
||||
(obj_properties)[(prop_id)] = _param_spec; \
|
||||
\
|
||||
_nm_properties_override_gobj( \
|
||||
(properties_override), \
|
||||
_param_spec, \
|
||||
_property_type, \
|
||||
.direct_offset = \
|
||||
NM_STRUCT_OFFSET_ENSURE_TYPE(char *, private_struct_type, private_struct_field), \
|
||||
__VA_ARGS__); \
|
||||
} \
|
||||
G_STMT_END
|
||||
|
||||
#define _nm_setting_property_define_direct_string(properties_override, \
|
||||
obj_properties, \
|
||||
prop_name, \
|
||||
prop_id, \
|
||||
param_flags, \
|
||||
private_struct_type, \
|
||||
private_struct_field, \
|
||||
...) \
|
||||
_nm_setting_property_define_direct_string_full((properties_override), \
|
||||
(obj_properties), \
|
||||
prop_name, \
|
||||
(prop_id), \
|
||||
(param_flags), \
|
||||
&nm_sett_info_propert_type_direct_string, \
|
||||
private_struct_type, \
|
||||
private_struct_field, \
|
||||
__VA_ARGS__)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define _nm_setting_property_define_string_full(properties_override, \
|
||||
obj_properties, \
|
||||
prop_name, \
|
||||
|
|
|
|||
|
|
@ -565,6 +565,27 @@ _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_STRING:
|
||||
{
|
||||
const char *val;
|
||||
|
||||
/* For string properties that are implemented via this function, the default is always NULL.
|
||||
* In general, having strings default to NULL is most advisable.
|
||||
*
|
||||
* Setting "including_default" for a string makes no sense because a
|
||||
* GVariant of type "s" cannot express NULL. */
|
||||
nm_assert(!NM_G_PARAM_SPEC_GET_DEFAULT_STRING(property_info->param_spec));
|
||||
nm_assert(!property_info->to_dbus_data.including_default);
|
||||
|
||||
val = *((const char *const *) _nm_setting_get_private(setting,
|
||||
sett_info,
|
||||
property_info->direct_offset));
|
||||
if (!val)
|
||||
return NULL;
|
||||
if (!val[0])
|
||||
return g_variant_ref(nm_g_variant_singleton_s_empty());
|
||||
return g_variant_new_string(val);
|
||||
}
|
||||
default:
|
||||
return nm_assert_unreachable_val(NULL);
|
||||
}
|
||||
|
|
@ -2428,6 +2449,11 @@ const NMSettInfoPropertType nm_sett_info_propert_type_direct_boolean =
|
|||
.direct_type = NM_VALUE_TYPE_BOOL,
|
||||
.to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct);
|
||||
|
||||
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,
|
||||
.to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct);
|
||||
|
||||
const NMSettInfoPropertType nm_sett_info_propert_type_string =
|
||||
NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_STRING,
|
||||
.to_dbus_fcn = _nm_setting_property_to_dbus_fcn_get_string);
|
||||
|
|
|
|||
|
|
@ -4443,6 +4443,12 @@ test_setting_metadata(void)
|
|||
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_STRING) {
|
||||
g_assert(g_variant_type_equal(sip->property_type->dbus_type, "s"));
|
||||
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_STRING);
|
||||
} else
|
||||
g_assert_not_reached();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue