component-loader: convert WpComponentLoader to a GInterface

This commit is contained in:
George Kiagiadakis 2023-05-25 19:20:40 +03:00
parent 5c3032c064
commit eb180cebe8
3 changed files with 23 additions and 22 deletions

View file

@ -17,7 +17,7 @@ WP_DEFINE_LOCAL_LOG_TOPIC ("wp-comp-loader")
/*!
* \struct WpComponentLoader
*
* The component loader is a plugin that provides the ability to load components.
* An interface that provides the ability to load components.
*
* Components can be:
* - WirePlumber modules (libraries that provide WpPlugin and WpSiFactory objects)
@ -33,15 +33,10 @@ WP_DEFINE_LOCAL_LOG_TOPIC ("wp-comp-loader")
#define WP_MODULE_INIT_SYMBOL "wireplumber__module_init"
typedef GObject *(*WpModuleInitFunc) (WpCore *, WpSpaJson *, GError **);
G_DEFINE_ABSTRACT_TYPE (WpComponentLoader, wp_component_loader, WP_TYPE_PLUGIN)
G_DEFINE_INTERFACE (WpComponentLoader, wp_component_loader, G_TYPE_OBJECT)
static void
wp_component_loader_init (WpComponentLoader * self)
{
}
static void
wp_component_loader_class_init (WpComponentLoaderClass * klass)
wp_component_loader_default_init (WpComponentLoaderInterface * iface)
{
}
@ -81,7 +76,7 @@ static gboolean
find_component_loader_func (gpointer cl, gpointer type)
{
if (WP_IS_COMPONENT_LOADER (cl) &&
(WP_COMPONENT_LOADER_GET_CLASS (cl)->supports_type (
(WP_COMPONENT_LOADER_GET_IFACE (cl)->supports_type (
WP_COMPONENT_LOADER (cl), (const gchar *) type)))
return TRUE;
@ -103,7 +98,7 @@ wp_component_loader_load (WpComponentLoader * self, const gchar * component,
gpointer data)
{
g_return_if_fail (WP_IS_COMPONENT_LOADER (self));
WP_COMPONENT_LOADER_GET_CLASS (self)->load (self, component, type,
WP_COMPONENT_LOADER_GET_IFACE (self)->load (self, component, type,
args, callback, data);
}

View file

@ -20,12 +20,12 @@ G_BEGIN_DECLS
*/
#define WP_TYPE_COMPONENT_LOADER (wp_component_loader_get_type ())
WP_API
G_DECLARE_DERIVABLE_TYPE (WpComponentLoader, wp_component_loader,
WP, COMPONENT_LOADER, WpPlugin)
G_DECLARE_INTERFACE (WpComponentLoader, wp_component_loader,
WP, COMPONENT_LOADER, GObject)
struct _WpComponentLoaderClass
struct _WpComponentLoaderInterface
{
WpPluginClass parent_class;
GTypeInterface interface;
gboolean (*supports_type) (WpComponentLoader * self, const gchar * type);

View file

@ -19,8 +19,7 @@ void wp_lua_scripting_api_init (lua_State *L);
struct _WpLuaScriptingPlugin
{
WpComponentLoader parent;
WpPlugin parent;
lua_State *L;
};
@ -84,10 +83,14 @@ wp_lua_scripting_enable_package_searcher (lua_State *L)
lua_call (L, 3, 0);
}
static void wp_lua_scripting_component_loader_init (WpComponentLoaderInterface * iface);
G_DECLARE_FINAL_TYPE (WpLuaScriptingPlugin, wp_lua_scripting_plugin,
WP, LUA_SCRIPTING_PLUGIN, WpComponentLoader)
G_DEFINE_TYPE (WpLuaScriptingPlugin, wp_lua_scripting_plugin,
WP_TYPE_COMPONENT_LOADER)
WP, LUA_SCRIPTING_PLUGIN, WpPlugin)
G_DEFINE_TYPE_WITH_CODE (WpLuaScriptingPlugin, wp_lua_scripting_plugin,
WP_TYPE_PLUGIN, G_IMPLEMENT_INTERFACE (
WP_TYPE_COMPONENT_LOADER,
wp_lua_scripting_component_loader_init))
static void
wp_lua_scripting_plugin_init (WpLuaScriptingPlugin * self)
@ -228,13 +231,16 @@ static void
wp_lua_scripting_plugin_class_init (WpLuaScriptingPluginClass * klass)
{
WpPluginClass *plugin_class = (WpPluginClass *) klass;
WpComponentLoaderClass *cl_class = (WpComponentLoaderClass *) klass;
plugin_class->enable = wp_lua_scripting_plugin_enable;
plugin_class->disable = wp_lua_scripting_plugin_disable;
}
cl_class->supports_type = wp_lua_scripting_plugin_supports_type;
cl_class->load = wp_lua_scripting_plugin_load;
static void
wp_lua_scripting_component_loader_init (WpComponentLoaderInterface * iface)
{
iface->supports_type = wp_lua_scripting_plugin_supports_type;
iface->load = wp_lua_scripting_plugin_load;
}
WP_PLUGIN_EXPORT GObject *