mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-27 11:40:08 +01:00
libnm: extend to_dbus_fcn() property type for efficiently converting string property
This commit is contained in:
parent
a832781a8a
commit
e435fdfedf
5 changed files with 102 additions and 6 deletions
|
|
@ -1956,12 +1956,12 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass)
|
|||
* description: Token to generate stable IDs.
|
||||
* ---end---
|
||||
*/
|
||||
obj_properties[PROP_STABLE_ID] = g_param_spec_string(
|
||||
NM_SETTING_CONNECTION_STABLE_ID,
|
||||
"",
|
||||
"",
|
||||
NULL,
|
||||
G_PARAM_READWRITE | NM_SETTING_PARAM_FUZZY_IGNORE | G_PARAM_STATIC_STRINGS);
|
||||
_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);
|
||||
|
||||
/**
|
||||
* NMSettingConnection:interface-name:
|
||||
|
|
|
|||
|
|
@ -254,6 +254,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_boolean;
|
||||
extern const NMSettInfoPropertType nm_sett_info_propert_type_string;
|
||||
|
||||
NMSettingVerifyResult
|
||||
_nm_setting_verify(NMSetting *setting, NMConnection *connection, GError **error);
|
||||
|
|
@ -282,6 +283,14 @@ _nm_setting_property_to_dbus_fcn_get_boolean(const NMSettInfoSetting *
|
|||
NMConnectionSerializationFlags flags,
|
||||
const NMConnectionSerializationOptions *options);
|
||||
|
||||
GVariant *
|
||||
_nm_setting_property_to_dbus_fcn_get_string(const NMSettInfoSetting * sett_info,
|
||||
guint property_idx,
|
||||
NMConnection * connection,
|
||||
NMSetting * setting,
|
||||
NMConnectionSerializationFlags flags,
|
||||
const NMConnectionSerializationOptions *options);
|
||||
|
||||
GVariant *_nm_setting_to_dbus(NMSetting * setting,
|
||||
NMConnection * connection,
|
||||
NMConnectionSerializationFlags flags,
|
||||
|
|
@ -449,6 +458,62 @@ _nm_properties_override(GArray *properties_override, const NMSettInfoProperty *p
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define _nm_setting_property_define_string_full(properties_override, \
|
||||
obj_properties, \
|
||||
prop_name, \
|
||||
prop_id, \
|
||||
param_flags, \
|
||||
property_type, \
|
||||
get_fcn, \
|
||||
...) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
GParamSpec * _param_spec; \
|
||||
const NMSettInfoPropertType *const _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(_property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_get_string); \
|
||||
\
|
||||
_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, \
|
||||
.to_dbus_data.get_string = \
|
||||
(const char *(*) (NMSetting *) ) (get_fcn), \
|
||||
__VA_ARGS__); \
|
||||
} \
|
||||
G_STMT_END
|
||||
|
||||
#define _nm_setting_property_define_string(properties_override, \
|
||||
obj_properties, \
|
||||
prop_name, \
|
||||
prop_id, \
|
||||
param_flags, \
|
||||
get_fcn, \
|
||||
...) \
|
||||
_nm_setting_property_define_string_full((properties_override), \
|
||||
(obj_properties), \
|
||||
prop_name, \
|
||||
(prop_id), \
|
||||
(param_flags), \
|
||||
&nm_sett_info_propert_type_string, \
|
||||
(get_fcn), \
|
||||
__VA_ARGS__)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
gboolean _nm_setting_use_legacy_property(NMSetting * setting,
|
||||
GVariant * connection_dict,
|
||||
const char *legacy_property,
|
||||
|
|
|
|||
|
|
@ -548,6 +548,27 @@ _nm_setting_property_to_dbus_fcn_get_boolean(const NMSettInfoSetting *
|
|||
return g_variant_ref(nm_g_variant_singleton_b(val));
|
||||
}
|
||||
|
||||
GVariant *
|
||||
_nm_setting_property_to_dbus_fcn_get_string(const NMSettInfoSetting * sett_info,
|
||||
guint property_idx,
|
||||
NMConnection * connection,
|
||||
NMSetting * setting,
|
||||
NMConnectionSerializationFlags flags,
|
||||
const NMConnectionSerializationOptions *options)
|
||||
{
|
||||
const NMSettInfoProperty *property_info = &sett_info->property_infos[property_idx];
|
||||
const char * val;
|
||||
|
||||
nm_assert(!NM_G_PARAM_SPEC_GET_DEFAULT_STRING(property_info->param_spec));
|
||||
|
||||
val = property_info->to_dbus_data.get_string(setting);
|
||||
if (!val)
|
||||
return NULL;
|
||||
if (!val[0])
|
||||
return g_variant_ref(nm_g_variant_singleton_s_empty());
|
||||
return g_variant_new_string(val);
|
||||
}
|
||||
|
||||
GVariant *
|
||||
_nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * sett_info,
|
||||
guint property_idx,
|
||||
|
|
@ -2377,6 +2398,10 @@ const NMSettInfoPropertType nm_sett_info_propert_type_boolean = NM_SETT_INFO_PRO
|
|||
G_VARIANT_TYPE_BOOLEAN,
|
||||
.to_dbus_fcn = _nm_setting_property_to_dbus_fcn_get_boolean);
|
||||
|
||||
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);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static GenData *
|
||||
|
|
|
|||
|
|
@ -4407,6 +4407,11 @@ check_done:;
|
|||
g_assert(sip->param_spec);
|
||||
g_assert(sip->param_spec->value_type == G_TYPE_BOOLEAN);
|
||||
g_assert(sip->to_dbus_data.get_boolean);
|
||||
} else if (sip->property_type->to_dbus_fcn
|
||||
== _nm_setting_property_to_dbus_fcn_get_string) {
|
||||
g_assert(sip->param_spec);
|
||||
g_assert(sip->param_spec->value_type == G_TYPE_STRING);
|
||||
g_assert(sip->to_dbus_data.get_string);
|
||||
}
|
||||
|
||||
g_assert(!sip->property_type->from_dbus_fcn
|
||||
|
|
|
|||
|
|
@ -712,6 +712,7 @@ struct _NMSettInfoProperty {
|
|||
gpointer none;
|
||||
NMSettInfoPropGPropToDBusFcn gprop_to_dbus_fcn;
|
||||
gboolean (*get_boolean)(NMSetting *);
|
||||
const char *(*get_string)(NMSetting *);
|
||||
};
|
||||
} to_dbus_data;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue