component-loader: add a load_finish() vfunc to finish the async operation
It's not acceptable to assume that the underlying implementation uses a GTask, so we have to defer the finish function to the implementation as well
This commit is contained in:
@@ -62,11 +62,17 @@ wp_component_loader_load (WpComponentLoader * self, WpCore * core,
|
|||||||
const gchar * component, const gchar * type, WpSpaJson * args,
|
const gchar * component, const gchar * type, WpSpaJson * args,
|
||||||
GCancellable * cancellable, GAsyncReadyCallback callback, gpointer data)
|
GCancellable * cancellable, GAsyncReadyCallback callback, gpointer data)
|
||||||
{
|
{
|
||||||
g_return_if_fail (WP_IS_COMPONENT_LOADER (self));
|
|
||||||
WP_COMPONENT_LOADER_GET_IFACE (self)->load (self, core, component, type,
|
WP_COMPONENT_LOADER_GET_IFACE (self)->load (self, core, component, type,
|
||||||
args, cancellable, callback, data);
|
args, cancellable, callback, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GObject *
|
||||||
|
wp_component_loader_load_finish (WpComponentLoader * self, GAsyncResult * res,
|
||||||
|
GError ** error)
|
||||||
|
{
|
||||||
|
return WP_COMPONENT_LOADER_GET_IFACE (self)->load_finish (self, res, error);
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Loads the specified \a component on \a self
|
* \brief Loads the specified \a component on \a self
|
||||||
*
|
*
|
||||||
@@ -121,6 +127,10 @@ GObject *
|
|||||||
wp_core_load_component_finish (WpCore * self, GAsyncResult * res,
|
wp_core_load_component_finish (WpCore * self, GAsyncResult * res,
|
||||||
GError ** error)
|
GError ** error)
|
||||||
{
|
{
|
||||||
gpointer o = g_task_propagate_pointer (G_TASK (res), error);
|
g_autoptr (GObject) source = g_async_result_get_source_object (res);
|
||||||
return o ? g_object_ref (G_OBJECT (o)) : NULL;
|
|
||||||
|
if (WP_IS_COMPONENT_LOADER (source))
|
||||||
|
return wp_component_loader_load_finish (WP_COMPONENT_LOADER (source), res, error);
|
||||||
|
else
|
||||||
|
return g_task_propagate_pointer (G_TASK (res), error);
|
||||||
}
|
}
|
||||||
|
@@ -33,8 +33,11 @@ struct _WpComponentLoaderInterface
|
|||||||
const gchar * component, const gchar * type, WpSpaJson * args,
|
const gchar * component, const gchar * type, WpSpaJson * args,
|
||||||
GCancellable * cancellable, GAsyncReadyCallback callback, gpointer data);
|
GCancellable * cancellable, GAsyncReadyCallback callback, gpointer data);
|
||||||
|
|
||||||
|
GObject * (*load_finish) (WpComponentLoader * self, GAsyncResult * res,
|
||||||
|
GError ** error);
|
||||||
|
|
||||||
/*< private >*/
|
/*< private >*/
|
||||||
WP_PADDING(6)
|
WP_PADDING(5)
|
||||||
};
|
};
|
||||||
|
|
||||||
WP_API
|
WP_API
|
||||||
|
@@ -99,6 +99,8 @@ wp_internal_comp_loader_load (WpComponentLoader * self, WpCore * core,
|
|||||||
g_autoptr (GError) error = NULL;
|
g_autoptr (GError) error = NULL;
|
||||||
g_autoptr (GObject) o = NULL;
|
g_autoptr (GObject) o = NULL;
|
||||||
|
|
||||||
|
g_task_set_source_tag (task, wp_internal_comp_loader_load);
|
||||||
|
|
||||||
/* load Module */
|
/* load Module */
|
||||||
o = load_module (core, component, args, &error);
|
o = load_module (core, component, args, &error);
|
||||||
if (!o) {
|
if (!o) {
|
||||||
@@ -116,9 +118,20 @@ wp_internal_comp_loader_load (WpComponentLoader * self, WpCore * core,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GObject *
|
||||||
|
wp_internal_comp_loader_load_finish (WpComponentLoader * self,
|
||||||
|
GAsyncResult * res, GError ** error)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (
|
||||||
|
g_async_result_is_tagged (res, wp_internal_comp_loader_load), NULL);
|
||||||
|
|
||||||
|
return g_task_propagate_pointer (G_TASK (res), error);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
wp_internal_comp_loader_iface_init (WpComponentLoaderInterface * iface)
|
wp_internal_comp_loader_iface_init (WpComponentLoaderInterface * iface)
|
||||||
{
|
{
|
||||||
iface->supports_type = wp_internal_comp_loader_supports_type;
|
iface->supports_type = wp_internal_comp_loader_supports_type;
|
||||||
iface->load = wp_internal_comp_loader_load;
|
iface->load = wp_internal_comp_loader_load;
|
||||||
|
iface->load_finish = wp_internal_comp_loader_load_finish;
|
||||||
}
|
}
|
||||||
|
@@ -180,11 +180,13 @@ wp_lua_scripting_plugin_load (WpComponentLoader * cl, WpCore * core,
|
|||||||
GCancellable * cancellable, GAsyncReadyCallback callback, gpointer data)
|
GCancellable * cancellable, GAsyncReadyCallback callback, gpointer data)
|
||||||
{
|
{
|
||||||
WpLuaScriptingPlugin * self = WP_LUA_SCRIPTING_PLUGIN (cl);
|
WpLuaScriptingPlugin * self = WP_LUA_SCRIPTING_PLUGIN (cl);
|
||||||
g_autoptr (GTask) task = task = g_task_new (core, cancellable, callback, data);
|
g_autoptr (GTask) task = task = g_task_new (self, cancellable, 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;
|
||||||
|
|
||||||
|
g_task_set_source_tag (task, wp_lua_scripting_plugin_load);
|
||||||
|
|
||||||
/* make sure the component loader is activated */
|
/* make sure the component loader is activated */
|
||||||
if (!self->L) {
|
if (!self->L) {
|
||||||
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
|
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
|
||||||
@@ -226,6 +228,16 @@ wp_lua_scripting_plugin_load (WpComponentLoader * cl, WpCore * core,
|
|||||||
(GAsyncReadyCallback) on_script_loaded, g_object_ref (task));
|
(GAsyncReadyCallback) on_script_loaded, g_object_ref (task));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GObject *
|
||||||
|
wp_lua_scripting_plugin_load_finish (WpComponentLoader * self,
|
||||||
|
GAsyncResult * res, GError ** error)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (
|
||||||
|
g_async_result_is_tagged (res, wp_lua_scripting_plugin_load), NULL);
|
||||||
|
|
||||||
|
return g_task_propagate_pointer (G_TASK (res), error);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
wp_lua_scripting_plugin_class_init (WpLuaScriptingPluginClass * klass)
|
wp_lua_scripting_plugin_class_init (WpLuaScriptingPluginClass * klass)
|
||||||
{
|
{
|
||||||
@@ -240,6 +252,7 @@ wp_lua_scripting_component_loader_init (WpComponentLoaderInterface * iface)
|
|||||||
{
|
{
|
||||||
iface->supports_type = wp_lua_scripting_plugin_supports_type;
|
iface->supports_type = wp_lua_scripting_plugin_supports_type;
|
||||||
iface->load = wp_lua_scripting_plugin_load;
|
iface->load = wp_lua_scripting_plugin_load;
|
||||||
|
iface->load_finish = wp_lua_scripting_plugin_load_finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
WP_PLUGIN_EXPORT GObject *
|
WP_PLUGIN_EXPORT GObject *
|
||||||
|
Reference in New Issue
Block a user