m-settings: split out the WpSettings instance loading to a new built-in component

When running multi-instance setups or when clients like wpctl want to
access the WpSettings instance, it makes no sense to load the entire
module-settings, which will also create sm-settings metadata instances.
This commit is contained in:
George Kiagiadakis
2024-01-26 11:34:08 +02:00
parent 95ae88d3e7
commit a511c54c5c
3 changed files with 53 additions and 28 deletions

View File

@@ -598,7 +598,7 @@ ensure_no_media_session_task_idle (GTask * task)
}
static void
ensure_no_media_session (GTask * task, WpCore * core)
ensure_no_media_session (GTask * task, WpCore * core, WpSpaJson * args)
{
WpObjectManager *om = wp_object_manager_new ();
@@ -619,7 +619,7 @@ ensure_no_media_session (GTask * task, WpCore * core)
}
static void
load_export_core (GTask * task, WpCore * core)
load_export_core (GTask * task, WpCore * core, WpSpaJson * args)
{
g_autofree gchar *export_core_name = NULL;
g_autoptr (WpCore) export_core = NULL;
@@ -641,12 +641,48 @@ load_export_core (GTask * task, WpCore * core)
g_task_return_pointer (task, g_steal_pointer (&export_core), g_object_unref);
}
static void
on_settings_ready (WpSettings *s, GAsyncResult *res, gpointer data)
{
GTask *task = G_TASK (data);
g_autoptr (GError) error = NULL;
if (!wp_object_activate_finish (WP_OBJECT (s), res, &error)) {
g_task_return_new_error (task,
WP_DOMAIN_LIBRARY, WP_LIBRARY_ERROR_OPERATION_FAILED,
"failed to activate settings instance: %s", error->message);
return;
}
g_task_return_pointer (task, NULL, NULL);
}
static void
load_settings_instance (GTask * task, WpCore * core, WpSpaJson * args)
{
g_autofree gchar *metadata_name = NULL;
if (args)
wp_spa_json_object_get (args, "metadata.name", "s", &metadata_name, NULL);
if (!metadata_name)
metadata_name = g_strdup ("sm-settings");
wp_info_object (core, "loading settings instance '%s'...", metadata_name);
g_autoptr (WpSettings) settings = wp_settings_get_instance (core,
metadata_name);
wp_object_activate_closure (WP_OBJECT (settings), WP_OBJECT_FEATURES_ALL, NULL,
g_cclosure_new (G_CALLBACK (on_settings_ready), g_object_ref (task),
(GClosureNotify) g_object_unref));
}
static const struct {
const gchar * name;
void (*load) (GTask *, WpCore *);
void (*load) (GTask *, WpCore *, WpSpaJson *);
} builtin_components[] = {
{ "ensure-no-media-session", ensure_no_media_session },
{ "export-core", load_export_core },
{ "settings-instance", load_settings_instance },
};
/*** WpInternalCompLoader ***/
@@ -796,7 +832,7 @@ wp_internal_comp_loader_load (WpComponentLoader * self, WpCore * core,
else if (g_str_equal (type, "built-in")) {
for (guint i = 0; i < G_N_ELEMENTS (builtin_components); i++) {
if (g_str_equal (component, builtin_components[i].name)) {
builtin_components[i].load (task, core);
builtin_components[i].load (task, core, args);
return;
}
}

View File

@@ -141,22 +141,6 @@ is_persistent_settings_enabled (WpProperties *settings) {
return res;
}
static void
on_settings_ready (WpSettings *s, GAsyncResult *res, gpointer data)
{
WpSettingsPlugin *self = WP_SETTINGS_PLUGIN (data);
g_autoptr (GError) error = NULL;
wp_info_object (self, "wpsettings object ready");
if (!wp_object_activate_finish (WP_OBJECT (s), res, &error)) {
wp_debug_object (self, "wpsettings activation failed: %s", error->message);
return;
}
wp_object_update_features (WP_OBJECT (self), WP_PLUGIN_FEATURE_ENABLED, 0);
}
static void
on_metadata_activated (WpMetadata * m, GAsyncResult * res, gpointer user_data)
{
@@ -215,12 +199,7 @@ on_metadata_activated (WpMetadata * m, GAsyncResult * res, gpointer user_data)
g_signal_connect_object (m, "changed", G_CALLBACK (on_metadata_changed),
self, 0);
g_autoptr (WpSettings) settings = wp_settings_get_instance (core,
self->metadata_name);
wp_object_activate (WP_OBJECT (settings), WP_OBJECT_FEATURES_ALL, NULL,
(GAsyncReadyCallback) on_settings_ready, self);
wp_object_update_features (WP_OBJECT (self), WP_PLUGIN_FEATURE_ENABLED, 0);
}
static void
@@ -310,7 +289,7 @@ wireplumber__module_init (WpCore * core, WpSpaJson * args, GError ** error)
{
g_autofree gchar *metadata_name = NULL;
if (args)
wp_spa_json_object_get (args, "metadata-name", "s", &metadata_name, NULL);
wp_spa_json_object_get (args, "metadata.name", "s", &metadata_name, NULL);
return G_OBJECT (g_object_new (wp_settings_plugin_get_type (),
"name", "settings",

View File

@@ -70,6 +70,7 @@ wireplumber.profiles = {
main = {
check.no-media-session = required
metadata.sm-settings = required
support.settings = required
support.log-settings = required
metadata.sm-objects = required
@@ -150,9 +151,18 @@ wireplumber.components = [
requires = [ pw.client-node ]
}
## Settings provider
## Provides the "sm-settings" metadata object
{
name = libwireplumber-module-settings, type = module
arguments = { metadata.name = sm-settings }
provides = metadata.sm-settings
}
## Activates a global WpSettings instance, providing settings from
## the sm-settings metadata object
{
name = settings-instance, type = built-in
arguments = { metadata.name = sm-settings }
provides = support.settings
}