summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-06-28 19:17:19 +0200
committerThomas Haller <thaller@redhat.com>2021-07-12 13:56:32 +0200
commit7556b4f382f0cdb382dd96d728a8ceff2efa6487 (patch)
tree7421da91870e2d657cc0aac2bb8610d5bb891ea8
parent233776c2c7b8be99fac1e6a09a7c7fe1d3c85986 (diff)
downloadNetworkManager-7556b4f382f0cdb382dd96d728a8ceff2efa6487.tar.gz
libnm: add direct_offset for string properties
And, as an example used for property "connection.stable-id".
-rw-r--r--src/libnm-core-impl/nm-setting-connection.c13
-rw-r--r--src/libnm-core-impl/nm-setting-private.h64
-rw-r--r--src/libnm-core-impl/nm-setting.c26
-rw-r--r--src/libnm-core-impl/tests/test-setting.c6
4 files changed, 103 insertions, 6 deletions
diff --git a/src/libnm-core-impl/nm-setting-connection.c b/src/libnm-core-impl/nm-setting-connection.c
index f833aea7c0..61e1cca122 100644
--- a/src/libnm-core-impl/nm-setting-connection.c
+++ b/src/libnm-core-impl/nm-setting-connection.c
@@ -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:
diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h
index dcfd4e6154..cf7e0d7541 100644
--- a/src/libnm-core-impl/nm-setting-private.h
+++ b/src/libnm-core-impl/nm-setting-private.h
@@ -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, \
diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c
index c3b324d603..9a4e202b19 100644
--- a/src/libnm-core-impl/nm-setting.c
+++ b/src/libnm-core-impl/nm-setting.c
@@ -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);
diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c
index beec0aff88..85b96d899a 100644
--- a/src/libnm-core-impl/tests/test-setting.c
+++ b/src/libnm-core-impl/tests/test-setting.c
@@ -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();