summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-05-20 16:31:30 +0200
committerThomas Haller <thaller@redhat.com>2020-05-22 15:58:09 +0200
commit150af44e104243ca8a629c291bb0e63373c79920 (patch)
treec8eb0d25cbd54c769fba4a6d9b8211f483bef99d
parentd0192b698e683b40d7e8ea64dbfe5ec29fc71dad (diff)
downloadNetworkManager-150af44e104243ca8a629c291bb0e63373c79920.tar.gz
libnm: add nm_setting_option_get_uint32(), nm_setting_option_set_uint32()
More general purpose API for generic options of settings.
-rw-r--r--libnm-core/nm-core-internal.h8
-rw-r--r--libnm-core/nm-setting-ethtool.c24
-rw-r--r--libnm-core/nm-setting.c100
-rw-r--r--libnm-core/nm-setting.h10
-rw-r--r--libnm/libnm.ver2
5 files changed, 91 insertions, 53 deletions
diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h
index 252c61d64e..b1689da62e 100644
--- a/libnm-core/nm-core-internal.h
+++ b/libnm-core/nm-core-internal.h
@@ -331,14 +331,6 @@ gboolean _nm_setting_option_clear (NMSetting *setting,
gboolean _nm_setting_option_clear_all (NMSetting *setting,
NMSettingOptionFilterFcn filter);
-gboolean _nm_setting_option_get_uint32 (NMSetting *setting,
- const char *optname,
- guint32 *out_value);
-
-void _nm_setting_option_set_uint32 (NMSetting *setting,
- const char *optname,
- guint32 value);
-
/*****************************************************************************/
guint nm_setting_ethtool_init_features (NMSettingEthtool *setting,
diff --git a/libnm-core/nm-setting-ethtool.c b/libnm-core/nm-setting-ethtool.c
index de7bded5f2..1be74cc9cb 100644
--- a/libnm-core/nm-setting-ethtool.c
+++ b/libnm-core/nm-setting-ethtool.c
@@ -294,9 +294,9 @@ nm_setting_ethtool_get_coalesce (NMSettingEthtool *setting,
g_return_val_if_fail (NM_IS_SETTING_ETHTOOL (setting), FALSE);
g_return_val_if_fail (nm_ethtool_optname_is_coalesce (optname), FALSE);
- return _nm_setting_option_get_uint32 (NM_SETTING (setting),
- optname,
- out_value);
+ return nm_setting_option_get_uint32 (NM_SETTING (setting),
+ optname,
+ out_value);
}
/**
@@ -330,9 +330,9 @@ nm_setting_ethtool_set_coalesce (NMSettingEthtool *setting,
NM_ETHTOOL_ID_COALESCE_ADAPTIVE_TX))
value = !!value;
- _nm_setting_option_set_uint32 (NM_SETTING (setting),
- optname,
- value);
+ nm_setting_option_set_uint32 (NM_SETTING (setting),
+ optname,
+ value);
_notify_attributes (setting);
}
@@ -398,9 +398,9 @@ nm_setting_ethtool_get_ring (NMSettingEthtool *setting,
g_return_val_if_fail (NM_IS_SETTING_ETHTOOL (setting), FALSE);
g_return_val_if_fail (nm_ethtool_optname_is_ring (optname), FALSE);
- return _nm_setting_option_get_uint32 (NM_SETTING (setting),
- optname,
- out_value);
+ return nm_setting_option_get_uint32 (NM_SETTING (setting),
+ optname,
+ out_value);
}
/**
@@ -429,9 +429,9 @@ nm_setting_ethtool_set_ring (NMSettingEthtool *setting,
g_return_if_fail (nm_ethtool_id_is_ring (ethtool_id));
- _nm_setting_option_set_uint32 (NM_SETTING (setting),
- optname,
- value);
+ nm_setting_option_set_uint32 (NM_SETTING (setting),
+ optname,
+ value);
_notify_attributes (setting);
}
diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c
index b8406728b6..98d9d9498f 100644
--- a/libnm-core/nm-setting.c
+++ b/libnm-core/nm-setting.c
@@ -2512,39 +2512,6 @@ _nm_setting_option_get_all_names (NMSetting *setting,
}
gboolean
-_nm_setting_option_get_uint32 (NMSetting *setting,
- const char *optname,
- guint32 *out_value)
-{
- GVariant *v;
-
- nm_assert (NM_IS_SETTING (setting));
- nm_assert (nm_str_not_empty (optname));
-
- v = nm_setting_option_get (setting, optname);
- if ( v
- && g_variant_is_of_type (v, G_VARIANT_TYPE_UINT32)) {
- NM_SET_OUT (out_value, g_variant_get_uint32 (v));
- return TRUE;
- }
- NM_SET_OUT (out_value, 0);
- return FALSE;
-}
-
-void
-_nm_setting_option_set_uint32 (NMSetting *setting,
- const char *optname,
- guint32 value)
-{
- nm_assert (NM_IS_SETTING (setting));
- nm_assert (nm_str_not_empty (optname));
-
- g_hash_table_insert (_nm_setting_option_hash (setting, TRUE),
- g_strdup (optname),
- g_variant_ref_sink (g_variant_new_uint32 (value)));
-}
-
-gboolean
_nm_setting_option_clear (NMSetting *setting,
const char *optname)
{
@@ -2640,6 +2607,34 @@ nm_setting_option_get_boolean (NMSetting *setting,
}
/**
+ * nm_setting_option_get_uint32:
+ * @setting: the #NMSetting
+ * @opt_name: the option to get
+ * @out_value: (allow-none) (out): the optional output value.
+ * If the option is unset, 0 will be returned.
+ *
+ * Returns: %TRUE if @opt_name is set to a uint32 variant.
+ *
+ * Since: 1.26
+ */
+gboolean
+nm_setting_option_get_uint32 (NMSetting *setting,
+ const char *opt_name,
+ guint32 *out_value)
+{
+ GVariant *v;
+
+ v = nm_setting_option_get (NM_SETTING (setting), opt_name);
+ if ( v
+ && g_variant_is_of_type (v, G_VARIANT_TYPE_UINT32)) {
+ NM_SET_OUT (out_value, g_variant_get_uint32 (v));
+ return TRUE;
+ }
+ NM_SET_OUT (out_value, 0);
+ return FALSE;
+}
+
+/**
* nm_setting_option_set:
* @setting: the #NMSetting
* @opt_name: the option name to set
@@ -2751,6 +2746,45 @@ nm_setting_option_set_boolean (NMSetting *setting,
_nm_setting_option_notify (setting, !changed_name);
}
+/**
+ * nm_setting_option_set_uint32:
+ * @setting: the #NMSetting
+ * @value: the value to set.
+ *
+ * Like nm_setting_option_set() to set a uint32 GVariant.
+ *
+ * Since: 1.26
+ */
+void
+nm_setting_option_set_uint32 (NMSetting *setting,
+ const char *opt_name,
+ guint32 value)
+{
+ GVariant *old_variant;
+ gboolean changed_name;
+ gboolean changed_value;
+ GHashTable *hash;
+
+ g_return_if_fail (NM_IS_SETTING (setting));
+ g_return_if_fail (opt_name);
+
+ hash = _nm_setting_option_hash (setting, TRUE);
+
+ old_variant = g_hash_table_lookup (hash, opt_name);
+
+ changed_name = (old_variant == NULL);
+ changed_value = changed_name
+ || ( !g_variant_is_of_type (old_variant, G_VARIANT_TYPE_UINT32)
+ || g_variant_get_uint32 (old_variant) != value);
+
+ g_hash_table_insert (hash,
+ g_strdup (opt_name),
+ g_variant_ref_sink (g_variant_new_uint32 (value)));
+
+ if (changed_value)
+ _nm_setting_option_notify (setting, !changed_name);
+}
+
/*****************************************************************************/
static void
diff --git a/libnm-core/nm-setting.h b/libnm-core/nm-setting.h
index ed909b7b25..27e9208e6f 100644
--- a/libnm-core/nm-setting.h
+++ b/libnm-core/nm-setting.h
@@ -343,11 +343,21 @@ gboolean nm_setting_option_get_boolean (NMSetting *setting,
gboolean *out_value);
NM_AVAILABLE_IN_1_26
+gboolean nm_setting_option_get_uint32 (NMSetting *setting,
+ const char *opt_name,
+ guint32 *out_value);
+
+NM_AVAILABLE_IN_1_26
void nm_setting_option_set (NMSetting *setting,
const char *opt_name,
GVariant *variant);
NM_AVAILABLE_IN_1_26
+void nm_setting_option_set_uint32 (NMSetting *setting,
+ const char *opt_name,
+ guint32 value);
+
+NM_AVAILABLE_IN_1_26
void nm_setting_option_set_boolean (NMSetting *setting,
const char *opt_name,
gboolean value);
diff --git a/libnm/libnm.ver b/libnm/libnm.ver
index 4f39d3917c..b1abdc257d 100644
--- a/libnm/libnm.ver
+++ b/libnm/libnm.ver
@@ -1734,6 +1734,8 @@ global:
nm_setting_match_remove_kernel_command_line_by_value;
nm_setting_option_get;
nm_setting_option_get_boolean;
+ nm_setting_option_get_uint32;
nm_setting_option_set;
nm_setting_option_set_boolean;
+ nm_setting_option_set_uint32;
} libnm_1_24_0;