lib: settings: add wp_settings_spec_get_name() for human-readable name

Extend settings spec with a human-readable name, and add function to get
it.
This commit is contained in:
Pauli Virtanen 2025-03-30 23:51:52 +03:00
parent a8283001d9
commit 3b1acc5474
5 changed files with 72 additions and 0 deletions

View file

@ -23,6 +23,7 @@ WP_DEFINE_LOCAL_LOG_TOPIC ("wp-settings")
*/
struct _WpSettingsSpec {
grefcount ref;
gchar *name;
gchar *desc;
WpSettingsSpecType type;
WpSpaJson *def_value;
@ -49,6 +50,7 @@ wp_settings_spec_ref (WpSettingsSpec * self)
static void
wp_settings_spec_free (WpSettingsSpec * self)
{
g_clear_pointer (&self->name, g_free);
g_clear_pointer (&self->desc, g_free);
g_clear_pointer (&self->def_value, wp_spa_json_unref);
g_clear_pointer (&self->min_value, wp_spa_json_unref);
@ -73,6 +75,7 @@ static WpSettingsSpec *
wp_settings_spec_new (WpSpaJson * spec_json)
{
WpSettingsSpec *self;
g_autofree gchar *name = NULL;
g_autofree gchar *desc = NULL;
g_autofree gchar *type_str = NULL;
WpSettingsSpecType type = WP_SETTINGS_SPEC_TYPE_UNKNOWN;
@ -87,6 +90,7 @@ wp_settings_spec_new (WpSpaJson * spec_json)
/* Parse mandatory fields */
if (!wp_spa_json_object_get (spec_json,
"name", "s", &name,
"description", "s", &desc,
"type", "s", &type_str,
"default", "J", &def_value,
@ -136,6 +140,7 @@ wp_settings_spec_new (WpSpaJson * spec_json)
self = g_slice_new0 (WpSettingsSpec);
g_ref_count_init (&self->ref);
self->name = g_steal_pointer (&name);
self->desc = g_steal_pointer (&desc);
self->type = type;
self->def_value = g_steal_pointer (&def_value);
@ -144,6 +149,19 @@ wp_settings_spec_new (WpSpaJson * spec_json)
return self;
}
/*!
* \brief Gets the human-readable name of a settings spec
* \ingroup wpsettings
* \param self the settings spec object
* \returns the human-readable name of the settings spec
*/
const gchar *
wp_settings_spec_get_name (WpSettingsSpec * self)
{
g_return_val_if_fail (self, NULL);
return self->name;
}
/*!
* \brief Gets the description of a settings spec
* \ingroup wpsettings

View file

@ -47,6 +47,9 @@ WpSettingsSpec *wp_settings_spec_ref (WpSettingsSpec * self);
WP_API
void wp_settings_spec_unref (WpSettingsSpec * self);
WP_API
const gchar * wp_settings_spec_get_name (WpSettingsSpec * self);
WP_API
const gchar * wp_settings_spec_get_description (WpSettingsSpec * self);

View file

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

View file

@ -275,6 +275,7 @@ test_get_set_save_reset_delete (TestSettingsFixture *self, gconstpointer data)
WpSettings *s = self->settings;
g_autoptr (WpSettingsSpec) spec = NULL;
const gchar *desc = NULL;
const gchar *name = NULL;
g_autoptr (WpSpaJson) def = NULL;
g_autoptr (WpSpaJson) min = NULL;
g_autoptr (WpSpaJson) max = NULL;
@ -298,6 +299,9 @@ test_get_set_save_reset_delete (TestSettingsFixture *self, gconstpointer data)
gboolean value = FALSE;
spec = wp_settings_get_spec (s, "test-setting-bool");
name = wp_settings_spec_get_name (spec);
g_assert_nonnull (name);
g_assert_cmpstr (name, ==, "test-setting-bool name");
desc = wp_settings_spec_get_description (spec);
g_assert_nonnull (desc);
g_assert_cmpstr (desc, ==, "test-setting-bool description");
@ -363,6 +367,9 @@ test_get_set_save_reset_delete (TestSettingsFixture *self, gconstpointer data)
gint value = 0;
spec = wp_settings_get_spec (s, "test-setting-int");
name = wp_settings_spec_get_name (spec);
g_assert_nonnull (name);
g_assert_cmpstr (name, ==, "test-setting-int name");
desc = wp_settings_spec_get_description (spec);
g_assert_nonnull (desc);
g_assert_cmpstr (desc, ==, "test-setting-int description");
@ -446,6 +453,9 @@ test_get_set_save_reset_delete (TestSettingsFixture *self, gconstpointer data)
gfloat value = 0.0;
spec = wp_settings_get_spec (s, "test-setting-float");
name = wp_settings_spec_get_name (spec);
g_assert_nonnull (name);
g_assert_cmpstr (name, ==, "test-setting-float name");
desc = wp_settings_spec_get_description (spec);
g_assert_nonnull (desc);
g_assert_cmpstr (desc, ==, "test-setting-float description");
@ -530,6 +540,9 @@ test_get_set_save_reset_delete (TestSettingsFixture *self, gconstpointer data)
{
spec = wp_settings_get_spec (s, "test-setting-string");
name = wp_settings_spec_get_name (spec);
g_assert_nonnull (name);
g_assert_cmpstr (name, ==, "test-setting-string name");
desc = wp_settings_spec_get_description (spec);
g_assert_nonnull (desc);
g_assert_cmpstr (desc, ==, "test-setting-string description");
@ -606,6 +619,9 @@ test_get_set_save_reset_delete (TestSettingsFixture *self, gconstpointer data)
{
spec = wp_settings_get_spec (s, "test-setting-string");
name = wp_settings_spec_get_name (spec);
g_assert_nonnull (name);
g_assert_cmpstr (name, ==, "test-setting-string name");
desc = wp_settings_spec_get_description (spec);
g_assert_nonnull (desc);
g_assert_cmpstr (desc, ==, "test-setting-string description");
@ -685,6 +701,9 @@ test_get_set_save_reset_delete (TestSettingsFixture *self, gconstpointer data)
{
{
spec = wp_settings_get_spec (s, "test-setting-array");
name = wp_settings_spec_get_name (spec);
g_assert_nonnull (name);
g_assert_cmpstr (name, ==, "test-setting-array name");
desc = wp_settings_spec_get_description (spec);
g_assert_nonnull (desc);
g_assert_cmpstr (desc, ==, "test-setting-array description");
@ -738,6 +757,9 @@ test_get_set_save_reset_delete (TestSettingsFixture *self, gconstpointer data)
{
spec = wp_settings_get_spec (s, "test-setting-array2");
name = wp_settings_spec_get_name (spec);
g_assert_nonnull (name);
g_assert_cmpstr (name, ==, "test-setting-array2 name");
desc = wp_settings_spec_get_description (spec);
g_assert_nonnull (desc);
g_assert_cmpstr (desc, ==, "test-setting-array2 description");
@ -794,6 +816,9 @@ test_get_set_save_reset_delete (TestSettingsFixture *self, gconstpointer data)
/* Object */
{
spec = wp_settings_get_spec (s, "test-setting-object");
name = wp_settings_spec_get_name (spec);
g_assert_nonnull (name);
g_assert_cmpstr (name, ==, "test-setting-object name");
desc = wp_settings_spec_get_description (spec);
g_assert_nonnull (desc);
g_assert_cmpstr (desc, ==, "test-setting-object description");

View file

@ -5,11 +5,13 @@ context.modules = [
wireplumber.settings.schema = {
test-setting-bool = {
name = "test-setting-bool name"
description = "test-setting-bool description"
type = "bool"
default = false
}
test-setting-int = {
name = "test-setting-int name"
description = "test-setting-int description"
type = "int"
default = 0
@ -17,6 +19,7 @@ wireplumber.settings.schema = {
max = 100
}
test-setting-float = {
name = "test-setting-float name"
description = "test-setting-float description"
type = "float"
default = 0.0
@ -24,26 +27,31 @@ wireplumber.settings.schema = {
max = 100.0
}
test-setting-string = {
name = "test-setting-string name"
description = "test-setting-string description"
type = "string"
default = "default"
}
test-setting-string2 = {
name = "test-setting-string2 name"
description = "test-setting-string2 description"
type = "string"
default = "default"
}
test-setting-array = {
name = "test-setting-array name"
description = "test-setting-array description"
type = "array"
default = []
}
test-setting-array2 = {
name = "test-setting-array2 name"
description = "test-setting-array2 description"
type = "array"
default = []
}
test-setting-object = {
name = "test-setting-object name"
description = "test-setting-object description"
type = "object"
default = {}