summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-04-24 17:41:32 +0200
committerThomas Haller <thaller@redhat.com>2019-04-25 11:38:56 +0200
commitf895fa4f28b1f317ea3dabbc2dcf9441fe24cc57 (patch)
tree616d4bd77b74049b2cdba32e7cb74fa0193f46c3
parent39bd2e1f1542a8bf30d11dd8444685f596d86a87 (diff)
downloadNetworkManager-th/libnm-setting-cleanup.tar.gz
libnm: unify property-to-dbus handling of NMSettingth/libnm-setting-cleanup
Merge the function pointer get_func() into to_dbus_fcn(). Previously, get_func() as handled separately from to_dbus_fnc() (formerly synth_func()). The notion was that synth-func would syntetize properties that are D-Bus only. But that distinction does not seem very helpful to me. Instaed, we want to convert a property to D-Bus. Period. The implementation should be handled uniformly. Hence, now that is all done by property_to_dbus(). Note that property_to_dbus() is also called as default implementation for compare-property. At least, for properties that are backed by a GObject property.
-rw-r--r--libnm-core/nm-core-internal.h5
-rw-r--r--libnm-core/nm-setting-ip4-config.c34
-rw-r--r--libnm-core/nm-setting-ip6-config.c34
-rw-r--r--libnm-core/nm-setting-private.h2
-rw-r--r--libnm-core/nm-setting-sriov.c6
-rw-r--r--libnm-core/nm-setting-tc-config.c34
-rw-r--r--libnm-core/nm-setting-vlan.c8
-rw-r--r--libnm-core/nm-setting-wired.c6
-rw-r--r--libnm-core/nm-setting.c108
-rw-r--r--libnm-core/nm-utils-private.h14
-rw-r--r--libnm-core/nm-utils.c20
11 files changed, 136 insertions, 135 deletions
diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h
index e2f1417e1c..c03e85bee5 100644
--- a/libnm-core/nm-core-internal.h
+++ b/libnm-core/nm-core-internal.h
@@ -662,8 +662,6 @@ GVariant *nm_ip_routing_rule_to_dbus (const NMIPRoutingRule *self);
typedef struct _NMSettInfoSetting NMSettInfoSetting;
typedef struct _NMSettInfoProperty NMSettInfoProperty;
-typedef GVariant *(*NMSettingPropertyGetFunc) (NMSetting *setting,
- const char *property);
typedef GVariant *(*NMSettInfoPropToDBusFcn) (const NMSettInfoSetting *sett_info,
guint property_idx,
NMConnection *connection,
@@ -690,9 +688,6 @@ struct _NMSettInfoProperty {
const GVariantType *dbus_type;
- /* TODO: merge @get_func with @to_dbus_fcn. */
- NMSettingPropertyGetFunc get_func;
-
NMSettInfoPropToDBusFcn to_dbus_fcn;
NMSettInfoPropFromDBusFcn from_dbus_fcn;
NMSettInfoPropMissingFromDBusFcn missing_from_dbus_fcn;
diff --git a/libnm-core/nm-setting-ip4-config.c b/libnm-core/nm-setting-ip4-config.c
index dd3b79b752..0bc81e388d 100644
--- a/libnm-core/nm-setting-ip4-config.c
+++ b/libnm-core/nm-setting-ip4-config.c
@@ -253,19 +253,18 @@ ip4_dns_from_dbus (GVariant *dbus_value,
}
static GVariant *
-ip4_addresses_get (NMSetting *setting,
- const char *property)
+ip4_addresses_get (const NMSettInfoSetting *sett_info,
+ guint property_idx,
+ NMConnection *connection,
+ NMSetting *setting,
+ NMConnectionSerializationFlags flags)
{
- GPtrArray *addrs;
+ gs_unref_ptrarray GPtrArray *addrs = NULL;
const char *gateway;
- GVariant *ret;
- g_object_get (setting, property, &addrs, NULL);
+ g_object_get (setting, NM_SETTING_IP_CONFIG_ADDRESSES, &addrs, NULL);
gateway = nm_setting_ip_config_get_gateway (NM_SETTING_IP_CONFIG (setting));
- ret = nm_utils_ip4_addresses_to_variant (addrs, gateway);
- g_ptr_array_unref (addrs);
-
- return ret;
+ return nm_utils_ip4_addresses_to_variant (addrs, gateway);
}
static gboolean
@@ -388,17 +387,16 @@ ip4_address_data_set (NMSetting *setting,
}
static GVariant *
-ip4_routes_get (NMSetting *setting,
- const char *property)
+ip4_routes_get (const NMSettInfoSetting *sett_info,
+ guint property_idx,
+ NMConnection *connection,
+ NMSetting *setting,
+ NMConnectionSerializationFlags flags)
{
- GPtrArray *routes;
- GVariant *ret;
-
- g_object_get (setting, property, &routes, NULL);
- ret = nm_utils_ip4_routes_to_variant (routes);
- g_ptr_array_unref (routes);
+ gs_unref_ptrarray GPtrArray *routes = NULL;
- return ret;
+ g_object_get (setting, NM_SETTING_IP_CONFIG_ROUTES, &routes, NULL);
+ return nm_utils_ip4_routes_to_variant (routes);
}
static gboolean
diff --git a/libnm-core/nm-setting-ip6-config.c b/libnm-core/nm-setting-ip6-config.c
index d6c085ac8c..f9b447a68b 100644
--- a/libnm-core/nm-setting-ip6-config.c
+++ b/libnm-core/nm-setting-ip6-config.c
@@ -313,19 +313,18 @@ ip6_dns_from_dbus (GVariant *dbus_value,
}
static GVariant *
-ip6_addresses_get (NMSetting *setting,
- const char *property)
+ip6_addresses_get (const NMSettInfoSetting *sett_info,
+ guint property_idx,
+ NMConnection *connection,
+ NMSetting *setting,
+ NMConnectionSerializationFlags flags)
{
- GPtrArray *addrs;
+ gs_unref_ptrarray GPtrArray *addrs = NULL;
const char *gateway;
- GVariant *ret;
- g_object_get (setting, property, &addrs, NULL);
+ g_object_get (setting, NM_SETTING_IP_CONFIG_ADDRESSES, &addrs, NULL);
gateway = nm_setting_ip_config_get_gateway (NM_SETTING_IP_CONFIG (setting));
- ret = nm_utils_ip6_addresses_to_variant (addrs, gateway);
- g_ptr_array_unref (addrs);
-
- return ret;
+ return nm_utils_ip6_addresses_to_variant (addrs, gateway);
}
static gboolean
@@ -394,17 +393,16 @@ ip6_address_data_set (NMSetting *setting,
}
static GVariant *
-ip6_routes_get (NMSetting *setting,
- const char *property)
+ip6_routes_get (const NMSettInfoSetting *sett_info,
+ guint property_idx,
+ NMConnection *connection,
+ NMSetting *setting,
+ NMConnectionSerializationFlags flags)
{
- GPtrArray *routes;
- GVariant *ret;
-
- g_object_get (setting, property, &routes, NULL);
- ret = nm_utils_ip6_routes_to_variant (routes);
- g_ptr_array_unref (routes);
+ gs_unref_ptrarray GPtrArray *routes = NULL;
- return ret;
+ g_object_get (setting, NM_SETTING_IP_CONFIG_ROUTES, &routes, NULL);
+ return nm_utils_ip6_routes_to_variant (routes);
}
static gboolean
diff --git a/libnm-core/nm-setting-private.h b/libnm-core/nm-setting-private.h
index b7b1c82f27..20f5be4f91 100644
--- a/libnm-core/nm-setting-private.h
+++ b/libnm-core/nm-setting-private.h
@@ -181,7 +181,7 @@ void _properties_override_add_dbus_only (GArray *properties_override,
void _properties_override_add_override (GArray *properties_override,
GParamSpec *param_spec,
const GVariantType *dbus_type,
- NMSettingPropertyGetFunc get_func,
+ NMSettInfoPropToDBusFcn to_dbus_fcn,
NMSettInfoPropFromDBusFcn from_dbus_fcn,
NMSettInfoPropMissingFromDBusFcn missing_from_dbus_fcn);
diff --git a/libnm-core/nm-setting-sriov.c b/libnm-core/nm-setting-sriov.c
index b63a2a9924..a5d672382c 100644
--- a/libnm-core/nm-setting-sriov.c
+++ b/libnm-core/nm-setting-sriov.c
@@ -905,7 +905,11 @@ _nm_setting_sriov_sort_vfs (NMSettingSriov *setting)
/*****************************************************************************/
static GVariant *
-vfs_to_dbus (NMSetting *setting, const char *property)
+vfs_to_dbus (const NMSettInfoSetting *sett_info,
+ guint property_idx,
+ NMConnection *connection,
+ NMSetting *setting,
+ NMConnectionSerializationFlags flags)
{
gs_unref_ptrarray GPtrArray *vfs = NULL;
GVariantBuilder builder;
diff --git a/libnm-core/nm-setting-tc-config.c b/libnm-core/nm-setting-tc-config.c
index f677f69727..494183a488 100644
--- a/libnm-core/nm-setting-tc-config.c
+++ b/libnm-core/nm-setting-tc-config.c
@@ -1483,17 +1483,16 @@ next:
}
static GVariant *
-tc_qdiscs_get (NMSetting *setting,
- const char *property)
+tc_qdiscs_get (const NMSettInfoSetting *sett_info,
+ guint property_idx,
+ NMConnection *connection,
+ NMSetting *setting,
+ NMConnectionSerializationFlags flags)
{
- GPtrArray *qdiscs;
- GVariant *ret;
+ gs_unref_ptrarray GPtrArray *qdiscs = NULL;
g_object_get (setting, NM_SETTING_TC_CONFIG_QDISCS, &qdiscs, NULL);
- ret = _qdiscs_to_variant (qdiscs);
- g_ptr_array_unref (qdiscs);
-
- return ret;
+ return _qdiscs_to_variant (qdiscs);
}
static gboolean
@@ -1669,17 +1668,16 @@ next:
}
static GVariant *
-tc_tfilters_get (NMSetting *setting,
- const char *property)
+tc_tfilters_get (const NMSettInfoSetting *sett_info,
+ guint property_idx,
+ NMConnection *connection,
+ NMSetting *setting,
+ NMConnectionSerializationFlags flags)
{
- GPtrArray *tfilters;
- GVariant *ret;
+ gs_unref_ptrarray GPtrArray *tfilters = NULL;
g_object_get (setting, NM_SETTING_TC_CONFIG_TFILTERS, &tfilters, NULL);
- ret = _tfilters_to_variant (tfilters);
- g_ptr_array_unref (tfilters);
-
- return ret;
+ return _tfilters_to_variant (tfilters);
}
static gboolean
@@ -1690,12 +1688,10 @@ tc_tfilters_set (NMSetting *setting,
NMSettingParseFlags parse_flags,
GError **error)
{
- GPtrArray *tfilters;
+ gs_unref_ptrarray GPtrArray *tfilters = NULL;
tfilters = _tfilters_from_variant (value);
g_object_set (setting, NM_SETTING_TC_CONFIG_TFILTERS, tfilters, NULL);
- g_ptr_array_unref (tfilters);
-
return TRUE;
}
diff --git a/libnm-core/nm-setting-vlan.c b/libnm-core/nm-setting-vlan.c
index 8a220ad811..f698e924dd 100644
--- a/libnm-core/nm-setting-vlan.c
+++ b/libnm-core/nm-setting-vlan.c
@@ -679,7 +679,11 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
}
static GVariant *
-_override_flags_get (NMSetting *setting, const char *property)
+_override_flags_get (const NMSettInfoSetting *sett_info,
+ guint property_idx,
+ NMConnection *connection,
+ NMSetting *setting,
+ NMConnectionSerializationFlags flags)
{
return g_variant_new_uint32 (nm_setting_vlan_get_flags ((NMSettingVlan *) setting));
}
@@ -921,7 +925,7 @@ nm_setting_vlan_class_init (NMSettingVlanClass *klass)
_properties_override_add_override (properties_override,
obj_properties[PROP_FLAGS],
- NULL,
+ G_VARIANT_TYPE_UINT32,
_override_flags_get,
NULL,
_override_flags_not_set);
diff --git a/libnm-core/nm-setting-wired.c b/libnm-core/nm-setting-wired.c
index 14b562d01d..de8dc53455 100644
--- a/libnm-core/nm-setting-wired.c
+++ b/libnm-core/nm-setting-wired.c
@@ -928,7 +928,11 @@ compare_property (const NMSettInfoSetting *sett_info,
}
static GVariant *
-_override_autoneg_get (NMSetting *setting, const char *property)
+_override_autoneg_get (const NMSettInfoSetting *sett_info,
+ guint property_idx,
+ NMConnection *connection,
+ NMSetting *setting,
+ NMConnectionSerializationFlags flags)
{
return g_variant_new_boolean (nm_setting_wired_get_auto_negotiate ((NMSettingWired *) setting));
}
diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c
index f0157e8a4b..7871e966b7 100644
--- a/libnm-core/nm-setting.c
+++ b/libnm-core/nm-setting.c
@@ -295,17 +295,17 @@ _properties_override_add_dbus_only (GArray *properties_override,
* @properties_override: an array collecting the overrides
* @param_spec: the name of the property to override
* @dbus_type: the type of the property (in its D-Bus representation)
- * @get_func: (allow-none): function to call to get the value of the property
+ * @to_dbus_fcn: (allow-none): function to call to get the value of the property
* @from_dbus_fcn: (allow-none): function to call to set the value of the property
* @missing_from_dbus_fcn: (allow-none): function to call to indicate the property was not set
*
* Overrides the D-Bus representation of the #GObject property that shares the
* same name as @param_spec.
*
- * When serializing a setting to D-Bus, if @get_func is non-%NULL, then it will
+ * When serializing a setting to D-Bus, if @to_dbus_fcn is non-%NULL, then it will
* be called to get the property's value. If it returns a #GVariant, the
* property will be added to the hash, and if it returns %NULL, the property
- * will be omitted. (If @get_func is %NULL, the property will be read normally
+ * will be omitted. (If @to_dbus_fcn is %NULL, the property will be read normally
* with g_object_get_property(), and added to the hash if it is not the default
* value.)
*
@@ -323,7 +323,7 @@ void
_properties_override_add_override (GArray *properties_override,
GParamSpec *param_spec,
const GVariantType *dbus_type,
- NMSettingPropertyGetFunc get_func,
+ NMSettInfoPropToDBusFcn to_dbus_fcn,
NMSettInfoPropFromDBusFcn from_dbus_fcn,
NMSettInfoPropMissingFromDBusFcn missing_from_dbus_fcn)
{
@@ -332,7 +332,7 @@ _properties_override_add_override (GArray *properties_override,
_properties_override_add (properties_override,
.param_spec = param_spec,
.dbus_type = dbus_type,
- .get_func = get_func,
+ .to_dbus_fcn = to_dbus_fcn,
.from_dbus_fcn = from_dbus_fcn,
.missing_from_dbus_fcn = missing_from_dbus_fcn);
}
@@ -686,20 +686,44 @@ _nm_setting_use_legacy_property (NMSetting *setting,
/*****************************************************************************/
static GVariant *
-get_property_for_dbus (NMSetting *setting,
- const NMSettInfoProperty *property,
- gboolean ignore_default)
+property_to_dbus (const NMSettInfoSetting *sett_info,
+ guint property_idx,
+ NMConnection *connection,
+ NMSetting *setting,
+ NMConnectionSerializationFlags flags,
+ gboolean ignore_flags,
+ gboolean ignore_default)
{
+ const NMSettInfoProperty *property = &sett_info->property_infos[property_idx];
GVariant *variant;
- /* to_dbus_fcn() is currently not allowed for GObject backed properties. No strong
- * reason except that get_property_for_dbus() can only consider "real" properties. */
- nm_assert (!property->to_dbus_fcn);
-
nm_assert (property->dbus_type);
- if (property->get_func) {
- variant = property->get_func (setting, property->name);
+ if (!property->param_spec) {
+ if (!property->to_dbus_fcn)
+ return NULL;
+ } else if (!ignore_flags) {
+ if (!NM_FLAGS_HAS (property->param_spec->flags, G_PARAM_WRITABLE))
+ return NULL;
+
+ if (NM_FLAGS_ANY (property->param_spec->flags, NM_SETTING_PARAM_GENDATA_BACKED))
+ return NULL;
+
+ if ( NM_FLAGS_HAS (property->param_spec->flags, NM_SETTING_PARAM_LEGACY)
+ && !_nm_utils_is_manager_process)
+ return NULL;
+
+ if ( NM_FLAGS_HAS (flags, NM_CONNECTION_SERIALIZE_NO_SECRETS)
+ && NM_FLAGS_HAS (property->param_spec->flags, NM_SETTING_PARAM_SECRET))
+ return NULL;
+
+ if ( NM_FLAGS_HAS (flags, NM_CONNECTION_SERIALIZE_ONLY_SECRETS)
+ && !NM_FLAGS_HAS (property->param_spec->flags, NM_SETTING_PARAM_SECRET))
+ return NULL;
+ }
+
+ if (property->to_dbus_fcn) {
+ variant = property->to_dbus_fcn (sett_info, property_idx, connection, setting, flags);
nm_g_variant_take_ref (variant);
} else {
nm_auto_unset_gvalue GValue prop_value = { 0, };
@@ -781,7 +805,6 @@ _nm_setting_to_dbus (NMSetting *setting, NMConnection *connection, NMConnectionS
{
NMSettingPrivate *priv;
GVariantBuilder builder;
- GVariant *dbus_value;
const NMSettInfoSetting *sett_info;
guint n_properties, i;
const char *const*gendata_keys;
@@ -802,52 +825,14 @@ _nm_setting_to_dbus (NMSetting *setting, NMConnection *connection, NMConnectionS
sett_info = _nm_setting_class_get_sett_info (NM_SETTING_GET_CLASS (setting));
for (i = 0; i < sett_info->property_infos_len; i++) {
- const NMSettInfoProperty *property = &sett_info->property_infos[i];
- GParamSpec *prop_spec = property->param_spec;
-
- nm_assert (property->dbus_type);
-
- if (!prop_spec) {
- if (!property->to_dbus_fcn)
- continue;
- } else {
-
- /* For the moment, properties backed by a GObject property don't
- * define a synth function. There is no problem supporting that,
- * however, for now just disallow it. */
- nm_assert (!property->to_dbus_fcn);
-
- if (!NM_FLAGS_HAS (prop_spec->flags, G_PARAM_WRITABLE))
- continue;
-
- if (NM_FLAGS_ANY (prop_spec->flags, NM_SETTING_PARAM_GENDATA_BACKED))
- continue;
-
- if ( NM_FLAGS_HAS (prop_spec->flags, NM_SETTING_PARAM_LEGACY)
- && !_nm_utils_is_manager_process)
- continue;
-
- if ( NM_FLAGS_HAS (flags, NM_CONNECTION_SERIALIZE_NO_SECRETS)
- && NM_FLAGS_HAS (prop_spec->flags, NM_SETTING_PARAM_SECRET))
- continue;
-
- if ( NM_FLAGS_HAS (flags, NM_CONNECTION_SERIALIZE_ONLY_SECRETS)
- && !NM_FLAGS_HAS (prop_spec->flags, NM_SETTING_PARAM_SECRET))
- continue;
- }
-
- if (property->to_dbus_fcn) {
- dbus_value = property->to_dbus_fcn (sett_info, i, connection, setting, flags);
- nm_g_variant_take_ref (dbus_value);
- } else
- dbus_value = get_property_for_dbus (setting, property, TRUE);
+ gs_unref_variant GVariant *dbus_value = NULL;
+ dbus_value = property_to_dbus (sett_info, i, connection, setting, flags, FALSE, TRUE);
if (dbus_value) {
- nm_assert (!g_variant_is_floating (dbus_value));
- nm_assert (g_variant_is_of_type (dbus_value, property->dbus_type));
-
- g_variant_builder_add (&builder, "{sv}", property->name, dbus_value);
- g_variant_unref (dbus_value);
+ g_variant_builder_add (&builder,
+ "{sv}",
+ sett_info->property_infos[i].name,
+ dbus_value);
}
}
@@ -1436,9 +1421,8 @@ compare_property (const NMSettInfoSetting *sett_info,
gs_unref_variant GVariant *value1 = NULL;
gs_unref_variant GVariant *value2 = NULL;
- value1 = get_property_for_dbus (set_a, property_info, TRUE);
- value2 = get_property_for_dbus (set_b, property_info, TRUE);
-
+ value1 = property_to_dbus (sett_info, property_idx, con_a, set_a, NM_CONNECTION_SERIALIZE_ALL, TRUE, TRUE);
+ value2 = property_to_dbus (sett_info, property_idx, con_b, set_b, NM_CONNECTION_SERIALIZE_ALL, TRUE, TRUE);
if (nm_property_compare (value1, value2) != 0)
return NM_TERNARY_FALSE;
}
diff --git a/libnm-core/nm-utils-private.h b/libnm-core/nm-utils-private.h
index a1a1369a39..4748ae7de3 100644
--- a/libnm-core/nm-utils-private.h
+++ b/libnm-core/nm-utils-private.h
@@ -55,8 +55,11 @@ gboolean _nm_utils_wps_method_validate (NMSettingWirelessSecurityWpsMethod wps_m
/* D-Bus transform funcs */
-GVariant *_nm_utils_hwaddr_cloned_get (NMSetting *setting,
- const char *property);
+GVariant *_nm_utils_hwaddr_cloned_get (const NMSettInfoSetting *sett_info,
+ guint property_idx,
+ NMConnection *connection,
+ NMSetting *setting,
+ NMConnectionSerializationFlags flags);
gboolean _nm_utils_hwaddr_cloned_set (NMSetting *setting,
GVariant *connection_dict,
const char *property,
@@ -103,7 +106,12 @@ void _nm_utils_format_variant_attributes_full (GString *str,
char key_value_separator);
gboolean _nm_sriov_vf_parse_vlans (NMSriovVF *vf, const char *str, GError **error);
-GVariant * _nm_utils_bridge_vlans_to_dbus (NMSetting *setting, const char *property);
+GVariant * _nm_utils_bridge_vlans_to_dbus (const NMSettInfoSetting *sett_info,
+ guint property_idx,
+ NMConnection *connection,
+ NMSetting *setting,
+ NMConnectionSerializationFlags flags);
+
gboolean _nm_utils_bridge_vlans_from_dbus (NMSetting *setting,
GVariant *connection_dict,
const char *property,
diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c
index 9a1430f6c7..55206e6bf3 100644
--- a/libnm-core/nm-utils.c
+++ b/libnm-core/nm-utils.c
@@ -4256,12 +4256,15 @@ _nm_utils_hwaddr_to_dbus_impl (const char *str)
}
GVariant *
-_nm_utils_hwaddr_cloned_get (NMSetting *setting,
- const char *property)
+_nm_utils_hwaddr_cloned_get (const NMSettInfoSetting *sett_info,
+ guint property_idx,
+ NMConnection *connection,
+ NMSetting *setting,
+ NMConnectionSerializationFlags flags)
{
gs_free char *addr = NULL;
- nm_assert (nm_streq0 (property, "cloned-mac-address"));
+ nm_assert (nm_streq (sett_info->property_infos[property_idx].name, "cloned-mac-address"));
g_object_get (setting, "cloned-mac-address", &addr, NULL);
return _nm_utils_hwaddr_to_dbus_impl (addr);
@@ -6766,13 +6769,20 @@ nm_utils_base64secret_normalize (const char *base64_key,
}
GVariant *
-_nm_utils_bridge_vlans_to_dbus (NMSetting *setting, const char *property)
+_nm_utils_bridge_vlans_to_dbus (const NMSettInfoSetting *sett_info,
+ guint property_idx,
+ NMConnection *connection,
+ NMSetting *setting,
+ NMConnectionSerializationFlags flags)
{
gs_unref_ptrarray GPtrArray *vlans = NULL;
GVariantBuilder builder;
guint i;
+ const char *property_name = sett_info->property_infos[property_idx].name;
+
+ nm_assert (property_name);
- g_object_get (setting, property, &vlans, NULL);
+ g_object_get (setting, property_name, &vlans, NULL);
g_variant_builder_init (&builder, G_VARIANT_TYPE ("aa{sv}"));
if (vlans) {