component-loader: pass core and cancellable parameters in load()

Regarding the core parameter, the case used to be that WpComponentLoader
was a WpPlugin, so it had a reference to the core internally, but since
this is no longer a requirement, we need to pass this explicitly
This commit is contained in:
George Kiagiadakis
2023-05-26 13:04:10 +03:00
parent eb180cebe8
commit 843e7ef4dd
15 changed files with 41 additions and 40 deletions

View File

@@ -93,13 +93,13 @@ wp_component_loader_find (WpCore * core, const gchar * type)
} }
static void static void
wp_component_loader_load (WpComponentLoader * self, const gchar * component, wp_component_loader_load (WpComponentLoader * self, WpCore * core,
const gchar * type, WpSpaJson * args, GAsyncReadyCallback callback, const gchar * component, const gchar * type, WpSpaJson * args,
gpointer data) GCancellable * cancellable, GAsyncReadyCallback callback, gpointer data)
{ {
g_return_if_fail (WP_IS_COMPONENT_LOADER (self)); g_return_if_fail (WP_IS_COMPONENT_LOADER (self));
WP_COMPONENT_LOADER_GET_IFACE (self)->load (self, component, type, WP_COMPONENT_LOADER_GET_IFACE (self)->load (self, core, component, type,
args, callback, data); args, cancellable, callback, data);
} }
static void static void
@@ -129,20 +129,21 @@ on_object_loaded (WpObject *object, GAsyncResult *res, gpointer data)
* \param type the type of the component * \param type the type of the component
* \param args (transfer none)(nullable): additional arguments for the component, * \param args (transfer none)(nullable): additional arguments for the component,
* expected to be a JSON object * expected to be a JSON object
* \param cancellable (nullable): optional GCancellable
* \param callback (scope async): the callback to call when the operation is done * \param callback (scope async): the callback to call when the operation is done
* \param data (closure): data to pass to \a callback * \param data (closure): data to pass to \a callback
*/ */
void void
wp_core_load_component (WpCore * self, const gchar * component, wp_core_load_component (WpCore * self, const gchar * component,
const gchar * type, WpSpaJson * args, GAsyncReadyCallback callback, const gchar * type, WpSpaJson * args, GCancellable * cancellable,
gpointer data) GAsyncReadyCallback callback, gpointer data)
{ {
g_autoptr (GTask) task = NULL; g_autoptr (GTask) task = NULL;
g_autoptr (WpComponentLoader) c = NULL; g_autoptr (WpComponentLoader) cl = NULL;
/* Special case for "module" component type */ /* Special case for "module" component type */
if (g_str_equal (type, "module")) { if (g_str_equal (type, "module")) {
task = g_task_new (self, NULL, callback, data); task = g_task_new (self, cancellable, callback, data);
g_autoptr (GError) error = NULL; g_autoptr (GError) error = NULL;
g_autoptr (GObject) o = NULL; g_autoptr (GObject) o = NULL;
@@ -174,16 +175,17 @@ wp_core_load_component (WpCore * self, const gchar * component,
} }
/* Otherwise find a component loader for that type and load the component */ /* Otherwise find a component loader for that type and load the component */
c = wp_component_loader_find (self, type); cl = wp_component_loader_find (self, type);
if (!c) { if (!cl) {
task = g_task_new (self, NULL, callback, data); task = g_task_new (self, cancellable, callback, data);
g_task_return_new_error (task, WP_DOMAIN_LIBRARY, g_task_return_new_error (task, WP_DOMAIN_LIBRARY,
WP_LIBRARY_ERROR_INVALID_ARGUMENT, WP_LIBRARY_ERROR_INVALID_ARGUMENT,
"No component loader was found for components of type '%s'", type); "No component loader was found for components of type '%s'", type);
return; return;
} }
wp_component_loader_load (c, component, type, args, callback, data); wp_component_loader_load (cl, self, component, type, args, cancellable,
callback, data);
} }
/*! /*!

View File

@@ -29,9 +29,9 @@ struct _WpComponentLoaderInterface
gboolean (*supports_type) (WpComponentLoader * self, const gchar * type); gboolean (*supports_type) (WpComponentLoader * self, const gchar * type);
void (*load) (WpComponentLoader * self, const gchar * component, void (*load) (WpComponentLoader * self, WpCore * core,
const gchar * type, WpSpaJson * args, GAsyncReadyCallback callback, const gchar * component, const gchar * type, WpSpaJson * args,
gpointer data); GCancellable * cancellable, GAsyncReadyCallback callback, gpointer data);
/*< private >*/ /*< private >*/
WP_PADDING(6) WP_PADDING(6)

View File

@@ -50,8 +50,8 @@ gchar *wp_core_get_vm_type (WpCore *self);
WP_API WP_API
void wp_core_load_component (WpCore * self, const gchar * component, void wp_core_load_component (WpCore * self, const gchar * component,
const gchar * type, WpSpaJson * args, GAsyncReadyCallback callback, const gchar * type, WpSpaJson * args, GCancellable * cancellable,
gpointer data); GAsyncReadyCallback callback, gpointer data);
WP_API WP_API
GObject * wp_core_load_component_finish (WpCore * self, GAsyncResult * res, GObject * wp_core_load_component_finish (WpCore * self, GAsyncResult * res,

View File

@@ -94,7 +94,7 @@ wp_require_api_transition_execute_step (WpTransition * transition, guint step)
"libwireplumber-module-%s", api_name); "libwireplumber-module-%s", api_name);
self->pending_plugins++; self->pending_plugins++;
wp_core_load_component (core, module_name, "module", NULL, wp_core_load_component (core, module_name, "module", NULL, NULL,
(GAsyncReadyCallback) on_plugin_loaded, self); (GAsyncReadyCallback) on_plugin_loaded, self);
} }
} }

View File

@@ -175,13 +175,12 @@ on_script_loaded (WpObject *object, GAsyncResult *res, gpointer data)
} }
static void static void
wp_lua_scripting_plugin_load (WpComponentLoader * cl, const gchar * component, wp_lua_scripting_plugin_load (WpComponentLoader * cl, WpCore * core,
const gchar * type, WpSpaJson * args, GAsyncReadyCallback callback, const gchar * component, const gchar * type, WpSpaJson * args,
gpointer data) GCancellable * cancellable, GAsyncReadyCallback callback, gpointer data)
{ {
WpLuaScriptingPlugin * self = WP_LUA_SCRIPTING_PLUGIN (cl); WpLuaScriptingPlugin * self = WP_LUA_SCRIPTING_PLUGIN (cl);
g_autoptr (WpCore) core = wp_object_get_core (WP_OBJECT (cl)); g_autoptr (GTask) task = task = g_task_new (core, cancellable, callback, data);
g_autoptr (GTask) task = task = g_task_new (core, NULL, callback, data);
g_autofree gchar *filepath = NULL; g_autofree gchar *filepath = NULL;
g_autofree gchar *pluginname = NULL; g_autofree gchar *pluginname = NULL;
g_autoptr (WpPlugin) script = NULL; g_autoptr (WpPlugin) script = NULL;

View File

@@ -186,7 +186,7 @@ load_enable_components (WpInitTransition *self)
self->curr_component->name, self->curr_component->type, self->curr_component->name, self->curr_component->type,
self->curr_component->priority, self->curr_component->flags); self->curr_component->priority, self->curr_component->flags);
wp_core_load_component (core, self->curr_component->name, wp_core_load_component (core, self->curr_component->name,
self->curr_component->type, NULL, self->curr_component->type, NULL, NULL,
(GAsyncReadyCallback) on_plugin_loaded, self); (GAsyncReadyCallback) on_plugin_loaded, self);
return FALSE; return FALSE;
} }

View File

@@ -1412,10 +1412,10 @@ main (gint argc, gchar **argv)
/* load required API modules */ /* load required API modules */
ctl.pending_plugins++; ctl.pending_plugins++;
wp_core_load_component (ctl.core, "libwireplumber-module-default-nodes-api", wp_core_load_component (ctl.core, "libwireplumber-module-default-nodes-api",
"module", NULL, (GAsyncReadyCallback) on_plugin_loaded, &ctl); "module", NULL, NULL, (GAsyncReadyCallback) on_plugin_loaded, &ctl);
ctl.pending_plugins++; ctl.pending_plugins++;
wp_core_load_component (ctl.core, "libwireplumber-module-mixer-api", wp_core_load_component (ctl.core, "libwireplumber-module-mixer-api",
"module", NULL, (GAsyncReadyCallback) on_plugin_loaded, &ctl); "module", NULL, NULL, (GAsyncReadyCallback) on_plugin_loaded, &ctl);
/* connect */ /* connect */
if (!wp_core_connect (ctl.core)) { if (!wp_core_connect (ctl.core)) {

View File

@@ -140,14 +140,14 @@ wp_init_transition_execute_step (WpTransition * transition, guint step)
case STEP_ACTIVATE_PLUGINS: { case STEP_ACTIVATE_PLUGINS: {
wp_core_load_component (core, "libwireplumber-module-lua-scripting", wp_core_load_component (core, "libwireplumber-module-lua-scripting",
"module", NULL, (GAsyncReadyCallback) on_plugin_loaded, self); "module", NULL, NULL, (GAsyncReadyCallback) on_plugin_loaded, self);
wp_core_load_component (core, "libwireplumber-module-standard-event-source", wp_core_load_component (core, "libwireplumber-module-standard-event-source",
"module", NULL, (GAsyncReadyCallback) on_plugin_loaded, self); "module", NULL, NULL, (GAsyncReadyCallback) on_plugin_loaded, self);
break; break;
} }
case STEP_ACTIVATE_SCRIPT: { case STEP_ACTIVATE_SCRIPT: {
wp_core_load_component (core, exec_script, "script/lua", exec_args, wp_core_load_component (core, exec_script, "script/lua", exec_args, NULL,
(GAsyncReadyCallback) on_plugin_loaded, self); (GAsyncReadyCallback) on_plugin_loaded, self);
break; break;
} }

View File

@@ -38,7 +38,7 @@ test_file_monitor_setup (TestFixture * f, gconstpointer user_data)
wp_base_test_fixture_setup (&f->base, WP_BASE_TEST_FLAG_DONT_CONNECT); wp_base_test_fixture_setup (&f->base, WP_BASE_TEST_FLAG_DONT_CONNECT);
wp_core_load_component (f->base.core, wp_core_load_component (f->base.core,
"libwireplumber-module-file-monitor-api", "module", NULL, "libwireplumber-module-file-monitor-api", "module", NULL, NULL,
(GAsyncReadyCallback) on_plugin_loaded, f); (GAsyncReadyCallback) on_plugin_loaded, f);
g_main_loop_run (f->base.loop); g_main_loop_run (f->base.loop);

View File

@@ -45,13 +45,13 @@ test_rd_setup (RdTestFixture *f, gconstpointer data)
{ {
wp_core_load_component (f->base.core, wp_core_load_component (f->base.core,
"libwireplumber-module-reserve-device", "module", NULL, "libwireplumber-module-reserve-device", "module", NULL, NULL,
(GAsyncReadyCallback) on_plugin_loaded, f); (GAsyncReadyCallback) on_plugin_loaded, f);
g_main_loop_run (f->base.loop); g_main_loop_run (f->base.loop);
} }
{ {
wp_core_load_component (f->base.client_core, wp_core_load_component (f->base.client_core,
"libwireplumber-module-reserve-device", "module", NULL, "libwireplumber-module-reserve-device", "module", NULL, NULL,
(GAsyncReadyCallback) on_plugin_loaded, f); (GAsyncReadyCallback) on_plugin_loaded, f);
g_main_loop_run (f->base.loop); g_main_loop_run (f->base.loop);
} }

View File

@@ -42,7 +42,7 @@ test_si_audio_adapter_setup (TestFixture * f, gconstpointer user_data)
} }
{ {
wp_core_load_component (f->base.core, wp_core_load_component (f->base.core,
"libwireplumber-module-si-audio-adapter", "module", NULL, "libwireplumber-module-si-audio-adapter", "module", NULL, NULL,
(GAsyncReadyCallback) on_plugin_loaded, f); (GAsyncReadyCallback) on_plugin_loaded, f);
} }
} }

View File

@@ -40,12 +40,12 @@ test_si_audio_virtual_setup (TestFixture * f, gconstpointer user_data)
} }
{ {
wp_core_load_component (f->base.core, wp_core_load_component (f->base.core,
"libwireplumber-module-si-audio-adapter", "module", NULL, "libwireplumber-module-si-audio-adapter", "module", NULL, NULL,
(GAsyncReadyCallback) on_plugin_loaded, f); (GAsyncReadyCallback) on_plugin_loaded, f);
} }
{ {
wp_core_load_component (f->base.core, wp_core_load_component (f->base.core,
"libwireplumber-module-si-audio-virtual", "module", NULL, "libwireplumber-module-si-audio-virtual", "module", NULL, NULL,
(GAsyncReadyCallback) on_plugin_loaded, f); (GAsyncReadyCallback) on_plugin_loaded, f);
} }
} }

View File

@@ -48,7 +48,7 @@ test_si_node_setup (TestFixture * f, gconstpointer user_data)
} }
{ {
wp_core_load_component (f->base.core, wp_core_load_component (f->base.core,
"libwireplumber-module-si-node", "module", NULL, "libwireplumber-module-si-node", "module", NULL, NULL,
(GAsyncReadyCallback) on_plugin_loaded, f); (GAsyncReadyCallback) on_plugin_loaded, f);
} }
} }

View File

@@ -95,11 +95,11 @@ test_si_standard_link_setup (TestFixture * f, gconstpointer user_data)
} }
{ {
wp_core_load_component (f->base.core, wp_core_load_component (f->base.core,
"libwireplumber-module-si-audio-adapter", "module", NULL, "libwireplumber-module-si-audio-adapter", "module", NULL, NULL,
(GAsyncReadyCallback) on_plugin_loaded, f); (GAsyncReadyCallback) on_plugin_loaded, f);
wp_core_load_component (f->base.core, wp_core_load_component (f->base.core,
"libwireplumber-module-si-standard-link", "module", NULL, "libwireplumber-module-si-standard-link", "module", NULL, NULL,
(GAsyncReadyCallback) on_plugin_loaded, f); (GAsyncReadyCallback) on_plugin_loaded, f);
} }

View File

@@ -205,7 +205,7 @@ load_component (ScriptRunnerFixture *f, const gchar *name, const gchar *type)
plugin_name = g_strdup (name); plugin_name = g_strdup (name);
} }
wp_core_load_component (f->base.core, component_name, type, NULL, wp_core_load_component (f->base.core, component_name, type, NULL, NULL,
(GAsyncReadyCallback) on_plugin_loaded, f); (GAsyncReadyCallback) on_plugin_loaded, f);
if (!g_str_has_prefix (name, "si")) if (!g_str_has_prefix (name, "si"))