Skip to content
Snippets Groups Projects
Commit 06db0e41 authored by George Kiagiadakis's avatar George Kiagiadakis
Browse files

factory: improve API and hide its implementation (better for introspection)

parent 1c44476b
No related merge requests found
......@@ -547,8 +547,7 @@ WpEndpointLink * wp_endpoint_link_new (WpCore * core, WpEndpoint * src,
/* create link object */
link = wp_core_make_from_factory (core, src_factory, WP_TYPE_ENDPOINT_LINK,
NULL);
link = wp_factory_make (core, src_factory, WP_TYPE_ENDPOINT_LINK, NULL);
if (!link) {
g_set_error (error, WP_DOMAIN_LIBRARY, WP_LIBRARY_ERROR_OPERATION_FAILED,
"Failed to create link object from factory %s", src_factory);
......
......@@ -8,6 +8,15 @@
#include "factory.h"
struct _WpFactory
{
GObject parent;
gchar *name;
GQuark name_quark;
WpFactoryFunc create_object;
};
G_DEFINE_TYPE (WpFactory, wp_factory, G_TYPE_OBJECT)
static void
......@@ -33,9 +42,9 @@ wp_factory_class_init (WpFactoryClass * klass)
}
WpFactory *
wp_factory_new (const gchar * name, WpFactoryFunc func)
wp_factory_new (WpCore * core, const gchar * name, WpFactoryFunc func)
{
WpFactory *f;
g_autoptr (WpFactory) f = NULL;
g_return_val_if_fail (name != NULL && *name != '\0', NULL);
g_return_val_if_fail (func != NULL, NULL);
......@@ -44,5 +53,36 @@ wp_factory_new (const gchar * name, WpFactoryFunc func)
f->name = g_strdup (name);
f->name_quark = g_quark_from_string (f->name);
f->create_object = func;
if (!wp_core_register_global (core, f->name_quark, f, g_object_unref))
return NULL;
return f;
}
const gchar *
wp_factory_get_name (WpFactory * self)
{
return self->name;
}
gpointer
wp_factory_create_object (WpFactory * self, GType type, GVariant * properties)
{
return self->create_object (self, type, properties);
}
WpFactory *
wp_factory_find (WpCore * core, const gchar * name)
{
return wp_core_get_global (core, g_quark_from_string (name));
}
gpointer
wp_factory_make (WpCore * core, const gchar * name, GType type,
GVariant * properties)
{
WpFactory *f = wp_factory_find (core, name);
if (!f) return NULL;
return wp_factory_create_object (f, type, properties);
}
......@@ -19,50 +19,16 @@ G_DECLARE_FINAL_TYPE (WpFactory, wp_factory, WP, FACTORY, GObject)
typedef gpointer (*WpFactoryFunc) (WpFactory * self, GType type,
GVariant * properties);
struct _WpFactory
{
GObject parent;
WpFactory * wp_factory_new (WpCore * core, const gchar * name,
WpFactoryFunc func);
gchar *name;
GQuark name_quark;
WpFactoryFunc create_object;
};
WpFactory * wp_factory_new (const gchar * name, WpFactoryFunc func);
static inline const gchar * wp_factory_get_name (WpFactory * factory)
{
return factory->name;
}
static inline gpointer wp_factory_create_object (WpFactory * factory,
GType type, GVariant * properties)
{
return factory->create_object (factory, type, properties);
}
static inline gboolean
wp_core_register_factory (WpCore * core, WpFactory * factory)
{
return wp_core_register_global (core, factory->name_quark, factory,
g_object_unref);
}
static inline WpFactory *
wp_core_find_factory (WpCore * core, const gchar * name)
{
return wp_core_get_global (core, g_quark_from_string (name));
}
const gchar * wp_factory_get_name (WpFactory * self);
gpointer wp_factory_create_object (WpFactory * self, GType type,
GVariant * properties);
static inline gpointer
wp_core_make_from_factory (WpCore * core, const gchar * name, GType type,
GVariant * properties)
{
WpFactory *f = wp_core_find_factory (core, name);
if (!f) return NULL;
return wp_factory_create_object (f, type, properties);
}
WpFactory * wp_factory_find (WpCore * core, const gchar * name);
gpointer wp_factory_make (WpCore * core, const gchar * name, GType type,
GVariant * properties);
G_END_DECLS
......
......@@ -59,10 +59,9 @@ wireplumber__module_init (WpModule * module, WpCore * core, GVariant * args)
wp_module_set_destroy_callback (module, module_destroy, pw_remote);
wp_core_register_factory (core, wp_factory_new (
"pipewire-simple-endpoint", simple_endpoint_factory));
wp_core_register_factory (core, wp_factory_new (
"pipewire-simple-endpoint-link", simple_endpoint_link_factory));
wp_factory_new (core, "pipewire-simple-endpoint", simple_endpoint_factory);
wp_factory_new (core, "pipewire-simple-endpoint-link",
simple_endpoint_link_factory);
g_idle_add ((GSourceFunc) connect_in_idle, pw_remote);
}
......@@ -60,6 +60,5 @@ endpoint_factory (WpFactory * factory, GType type, GVariant * properties)
void
wireplumber__module_init (WpModule * module, WpCore * core, GVariant * args)
{
wp_core_register_factory (core, wp_factory_new (
"pw-audio-softdsp-endpoint", endpoint_factory));
wp_factory_new (core, "pw-audio-softdsp-endpoint", endpoint_factory);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment