diff --git a/lib/wp/factory.c b/lib/wp/factory.c index 82cb6562e7b8f657bef8d25cc657365d84a98b0f..3093c337acb85a3a7bde2ec87d8220f1639d3002 100644 --- a/lib/wp/factory.c +++ b/lib/wp/factory.c @@ -15,10 +15,7 @@ struct _WpFactory GWeakRef core; gchar *name; GQuark name_quark; - union { - WpFactoryFunc sync; - WpFactoryAsyncFunc async; - } create_object; + WpFactoryFunc create_object; }; G_DEFINE_TYPE (WpFactory, wp_factory, G_TYPE_OBJECT) @@ -48,29 +45,20 @@ wp_factory_class_init (WpFactoryClass * klass) object_class->finalize = wp_factory_finalize; } -static -WpFactory * create_factory (WpCore * core, const gchar * name) +WpFactory * +wp_factory_new (WpCore * core, const gchar * name, + WpFactoryFunc func) { WpFactory *f = NULL; + g_return_val_if_fail (func, NULL); g_return_val_if_fail (name != NULL && *name != '\0', NULL); f = g_object_new (WP_TYPE_FACTORY, NULL); g_weak_ref_init (&f->core, core); f->name = g_strdup (name); f->name_quark = g_quark_from_string (f->name); - - return f; -} - -WpFactory * -wp_factory_new (WpCore * core, const gchar * name, WpFactoryFunc func) -{ - WpFactory *f = NULL; - g_return_val_if_fail (func, NULL); - - f = create_factory(core, name); - f->create_object.sync = func; + f->create_object = func; g_info ("WpFactory:%p new factory: %s", f, name); @@ -79,23 +67,6 @@ wp_factory_new (WpCore * core, const gchar * name, WpFactoryFunc func) return f; } -WpFactory * -wp_factory_new_async (WpCore * core, const gchar * name, - WpFactoryAsyncFunc func) -{ - WpFactory *f = NULL; - g_return_val_if_fail (func, NULL); - - f = create_factory(core, name); - f->create_object.async = func; - - g_info ("WpFactory:%p new async factory: %s", f, name); - - wp_core_register_global (core, WP_GLOBAL_FACTORY, f, g_object_unref); - - return f; -} - const gchar * wp_factory_get_name (WpFactory * self) { @@ -114,23 +85,14 @@ wp_factory_get_core (WpFactory * self) return g_weak_ref_get (&self->core); } -gpointer -wp_factory_create_object (WpFactory * self, GType type, GVariant * properties) -{ - g_debug ("WpFactory:%p (%s) create object of type %s", self, self->name, - g_type_name (type)); - - return self->create_object.sync (self, type, properties); -} - void -wp_factory_create_object_async (WpFactory * self, GType type, +wp_factory_create_object (WpFactory * self, GType type, GVariant * properties, GAsyncReadyCallback ready, gpointer user_data) { - g_debug ("WpFactory:%p (%s) create object async of type %s", self, self->name, + g_debug ("WpFactory:%p (%s) create object of type %s", self, self->name, g_type_name (type)); - self->create_object.async (self, type, properties, ready, user_data); + self->create_object (self, type, properties, ready, user_data); } struct find_factory_data @@ -160,20 +122,11 @@ wp_factory_find (WpCore * core, const gchar * name) return d.ret; } -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); -} - void -wp_factory_make_async (WpCore * core, const gchar * name, GType type, +wp_factory_make (WpCore * core, const gchar * name, GType type, GVariant * properties, GAsyncReadyCallback ready, gpointer user_data) { WpFactory *f = wp_factory_find (core, name); if (!f) return; - wp_factory_create_object_async (f, type, properties, ready, user_data); + wp_factory_create_object (f, type, properties, ready, user_data); } diff --git a/lib/wp/factory.h b/lib/wp/factory.h index 9f74c22c593b3a5e4db3694d5275c2e7cb2f47c4..c43739d334e9b2792be6b54e4f2baa67b1b5dd2e 100644 --- a/lib/wp/factory.h +++ b/lib/wp/factory.h @@ -18,27 +18,19 @@ G_BEGIN_DECLS #define WP_TYPE_FACTORY (wp_factory_get_type ()) G_DECLARE_FINAL_TYPE (WpFactory, wp_factory, WP, FACTORY, GObject) -typedef gpointer (*WpFactoryFunc) (WpFactory * self, GType type, - GVariant * properties); -typedef void (*WpFactoryAsyncFunc) (WpFactory * self, GType type, +typedef void (*WpFactoryFunc) (WpFactory * self, GType type, GVariant * properties, GAsyncReadyCallback ready, gpointer user_data); WpFactory * wp_factory_new (WpCore * core, const gchar * name, WpFactoryFunc func); -WpFactory * wp_factory_new_async (WpCore * core, const gchar * name, - WpFactoryAsyncFunc func); const gchar * wp_factory_get_name (WpFactory * self); WpCore * wp_factory_get_core (WpFactory * self); -gpointer wp_factory_create_object (WpFactory * self, GType type, - GVariant * properties); -void wp_factory_create_object_async (WpFactory * self, GType type, +void wp_factory_create_object (WpFactory * self, GType type, GVariant * properties, GAsyncReadyCallback ready, gpointer user_data); WpFactory * wp_factory_find (WpCore * core, const gchar * name); -gpointer wp_factory_make (WpCore * core, const gchar * name, GType type, - GVariant * properties); -void wp_factory_make_async (WpCore * core, const gchar * name, GType type, +void wp_factory_make (WpCore * core, const gchar * name, GType type, GVariant * properties, GAsyncReadyCallback ready, gpointer user_data); G_END_DECLS