diff --git a/lib/wp/endpoint.c b/lib/wp/endpoint.c index b12afaeb3d7c329f0b7d5b684875aff73de2e0c2..9c42cb0ddcaf1ebe4d5c677fe32a61e48f74c6d7 100644 --- a/lib/wp/endpoint.c +++ b/lib/wp/endpoint.c @@ -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); diff --git a/lib/wp/factory.c b/lib/wp/factory.c index a49921eb61efe5d52e6e52ab67cb56f112401720..7ce68bfacc5c97e710017ba5fc3e4dcf5ca2ffb3 100644 --- a/lib/wp/factory.c +++ b/lib/wp/factory.c @@ -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); +} diff --git a/lib/wp/factory.h b/lib/wp/factory.h index 9e993068e42b3f33fba560b4b77651850bc5a58b..83737029b6f282cec82abfcf57e5d620f173c898 100644 --- a/lib/wp/factory.h +++ b/lib/wp/factory.h @@ -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 diff --git a/modules/module-pipewire.c b/modules/module-pipewire.c index 5040723e1e67060770911e2c24d56bc2808ff811..2389f982a04ad7cdea9483b64890fb7664546cd5 100644 --- a/modules/module-pipewire.c +++ b/modules/module-pipewire.c @@ -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); } diff --git a/modules/module-pw-audio-softdsp-endpoint.c b/modules/module-pw-audio-softdsp-endpoint.c index a590dadc9dbceb302729e8d118102f2961b2c6b0..b2534c0a7c60ab2ec0cc38dbfe6c4267a95e3ebf 100644 --- a/modules/module-pw-audio-softdsp-endpoint.c +++ b/modules/module-pw-audio-softdsp-endpoint.c @@ -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); }