lib: settings: make settings name optional

The "name" field needs to be optional, to be backward compatible with
old settings spec format.  If it's omitted, make it NULL.
This commit is contained in:
Pauli Virtanen 2025-07-24 12:00:21 +03:00
parent 9e47393643
commit 36f809fb50
5 changed files with 20 additions and 21 deletions

View file

@ -90,13 +90,15 @@ wp_settings_spec_new (WpSpaJson * spec_json)
/* Parse mandatory fields */ /* Parse mandatory fields */
if (!wp_spa_json_object_get (spec_json, if (!wp_spa_json_object_get (spec_json,
"name", "s", &name,
"description", "s", &desc, "description", "s", &desc,
"type", "s", &type_str, "type", "s", &type_str,
"default", "J", &def_value, "default", "J", &def_value,
NULL)) NULL))
return NULL; return NULL;
/* Parse optional fields */
wp_spa_json_object_get (spec_json, "name", "s", &name, NULL);
/* Parse type and check if values are correct */ /* Parse type and check if values are correct */
if (g_str_equal (type_str, "bool")) { if (g_str_equal (type_str, "bool")) {
type = WP_SETTINGS_SPEC_TYPE_BOOL; type = WP_SETTINGS_SPEC_TYPE_BOOL;
@ -153,7 +155,8 @@ wp_settings_spec_new (WpSpaJson * spec_json)
* \brief Gets the human-readable name of a settings spec * \brief Gets the human-readable name of a settings spec
* \ingroup wpsettings * \ingroup wpsettings
* \param self the settings spec object * \param self the settings spec object
* \returns the human-readable name of the settings spec * \returns (nullable): the human-readable name of the settings spec,
* or NULL if none
*/ */
const gchar * const gchar *
wp_settings_spec_get_name (WpSettingsSpec * self) wp_settings_spec_get_name (WpSettingsSpec * self)

View file

@ -1453,7 +1453,8 @@ print_setting (WpSettings *s, const gchar *key)
printf ("- Id: %s\n", key); printf ("- Id: %s\n", key);
/* print spec */ /* print spec */
printf (" Name: %s\n", dgettext (GETTEXT_PACKAGE, name)); if (name)
printf (" Name: %s\n", dgettext (GETTEXT_PACKAGE, name));
printf (" Desc: %s\n", dgettext (GETTEXT_PACKAGE, desc)); printf (" Desc: %s\n", dgettext (GETTEXT_PACKAGE, desc));
printf (" Type: %s\n", settings_spec_type_to_string (val_type)); printf (" Type: %s\n", settings_spec_type_to_string (val_type));
printf (" Default: %s", wp_spa_json_get_data (def)); printf (" Default: %s", wp_spa_json_get_data (def));

View file

@ -11,13 +11,11 @@ context.modules = [
wireplumber.settings.schema = { wireplumber.settings.schema = {
## Bluetooth ## Bluetooth
bluetooth.use-persistent-storage = { bluetooth.use-persistent-storage = {
name = "Persistent storage"
description = "Whether to use persistent BT storage or not" description = "Whether to use persistent BT storage or not"
type = "bool" type = "bool"
default = true default = true
} }
bluetooth.autoswitch-to-headset-profile = { bluetooth.autoswitch-to-headset-profile = {
name = "Auto-switch to headset profile"
description = "Whether to autoswitch to BT headset profile or not" description = "Whether to autoswitch to BT headset profile or not"
type = "bool" type = "bool"
default = true default = true
@ -25,19 +23,16 @@ wireplumber.settings.schema = {
## Device ## Device
device.restore-profile = { device.restore-profile = {
name = "Restore profile"
description = "Whether to restore device profile or not" description = "Whether to restore device profile or not"
type = "bool" type = "bool"
default = true default = true
} }
device.restore-routes = { device.restore-routes = {
name = "Restore routes"
description = "Whether to restore device routes or not" description = "Whether to restore device routes or not"
type = "bool" type = "bool"
default = true default = true
} }
device.routes.default-sink-volume = { device.routes.default-sink-volume = {
name = "Default sink volume"
description = "The default volume for sink devices" description = "The default volume for sink devices"
type = "float" type = "float"
default = 0.064 default = 0.064
@ -45,7 +40,6 @@ wireplumber.settings.schema = {
max = 1.0 max = 1.0
} }
device.routes.default-source-volume = { device.routes.default-source-volume = {
name = "Default source volume"
description = "The default volume for source devices" description = "The default volume for source devices"
type = "float" type = "float"
default = 1.0 default = 1.0
@ -55,13 +49,11 @@ wireplumber.settings.schema = {
## Linking ## Linking
linking.allow-moving-streams = { linking.allow-moving-streams = {
name = "Allow moving streams"
description = "Whether to allow metadata to move streams at runtime or not" description = "Whether to allow metadata to move streams at runtime or not"
type = "bool" type = "bool"
default = true default = true
} }
linking.follow-default-target = { linking.follow-default-target = {
name = "Follow default target"
description = "Whether to allow streams follow the default device or not" description = "Whether to allow streams follow the default device or not"
type = "bool" type = "bool"
default = true default = true
@ -69,7 +61,6 @@ wireplumber.settings.schema = {
## Monitor ## Monitor
monitor.camera-discovery-timeout = { monitor.camera-discovery-timeout = {
name = "Discovery timeout"
description = "The camera discovery timeout in milliseconds" description = "The camera discovery timeout in milliseconds"
type = "int" type = "int"
default = 1000 default = 1000
@ -79,37 +70,31 @@ wireplumber.settings.schema = {
## Node ## Node
node.features.audio.no-dsp = { node.features.audio.no-dsp = {
name = "No DSP"
description = "Whether to never convert audio to F32 format or not" description = "Whether to never convert audio to F32 format or not"
type = "bool" type = "bool"
default = false default = false
} }
node.features.audio.monitor-ports = { node.features.audio.monitor-ports = {
name = "Monitor ports"
description = "Whether to enable monitor ports on audio nodes or not" description = "Whether to enable monitor ports on audio nodes or not"
type = "bool" type = "bool"
default = true default = true
} }
node.features.audio.control-port = { node.features.audio.control-port = {
name = "Control ports"
description = "Whether to enable control ports on audio nodes or not" description = "Whether to enable control ports on audio nodes or not"
type = "bool" type = "bool"
default = false default = false
} }
node.stream.restore-props = { node.stream.restore-props = {
name = "Restore properties"
description = "Whether to restore properties on stream nodes or not" description = "Whether to restore properties on stream nodes or not"
type = "bool" type = "bool"
default = true default = true
} }
node.stream.restore-target = { node.stream.restore-target = {
name = "Restore target"
description = "Whether to restore target on stream nodes or not" description = "Whether to restore target on stream nodes or not"
type = "bool" type = "bool"
default = true default = true
} }
node.stream.default-playback-volume = { node.stream.default-playback-volume = {
name = "Default playback volume"
description = "The default volume for playback nodes" description = "The default volume for playback nodes"
type = "float" type = "float"
default = 1.0 default = 1.0
@ -117,7 +102,6 @@ wireplumber.settings.schema = {
max = 1.0 max = 1.0
} }
node.stream.default-capture-volume = { node.stream.default-capture-volume = {
name = "Default capture volume"
description = "The default volume for capture nodes" description = "The default volume for capture nodes"
type = "float" type = "float"
default = 1.0 default = 1.0
@ -125,13 +109,11 @@ wireplumber.settings.schema = {
max = 1.0 max = 1.0
} }
node.filter.forward-format = { node.filter.forward-format = {
name = "Forward format"
description = "Whether to forward format on filter nodes or not" description = "Whether to forward format on filter nodes or not"
type = "bool" type = "bool"
default = false default = false
} }
node.restore-default-targets = { node.restore-default-targets = {
name = "Restore default target"
description = "Whether to restore default targets or not" description = "Whether to restore default targets or not"
type = "bool" type = "bool"
default = true default = true

View file

@ -877,6 +877,13 @@ test_get_set_save_reset_delete (TestSettingsFixture *self, gconstpointer data)
g_assert_cmpstr (wp_spa_json_get_data (j), ==, "{}"); g_assert_cmpstr (wp_spa_json_get_data (j), ==, "{}");
g_clear_pointer (&j, wp_spa_json_unref); g_clear_pointer (&j, wp_spa_json_unref);
} }
/* Name omitted */
{
spec = wp_settings_get_spec (s, "test-setting-no-name");
name = wp_settings_spec_get_name (spec);
g_assert_null (name);
}
} }
static void static void

View file

@ -56,6 +56,12 @@ wireplumber.settings.schema = {
type = "object" type = "object"
default = {} default = {}
} }
test-setting-no-name = {
# optional name field omitted
description = "test-setting-no-name description"
type = "bool"
default = false
}
} }
wireplumber.settings = { wireplumber.settings = {