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

module/factory: add a get_core() method on both

parent 06db0e41
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,7 @@ struct _WpFactory ...@@ -12,6 +12,7 @@ struct _WpFactory
{ {
GObject parent; GObject parent;
GWeakRef core;
gchar *name; gchar *name;
GQuark name_quark; GQuark name_quark;
WpFactoryFunc create_object; WpFactoryFunc create_object;
...@@ -29,6 +30,7 @@ wp_factory_finalize (GObject * obj) ...@@ -29,6 +30,7 @@ wp_factory_finalize (GObject * obj)
{ {
WpFactory * self = WP_FACTORY (obj); WpFactory * self = WP_FACTORY (obj);
g_weak_ref_clear (&self->core);
g_free (self->name); g_free (self->name);
G_OBJECT_CLASS (wp_factory_parent_class)->finalize (obj); G_OBJECT_CLASS (wp_factory_parent_class)->finalize (obj);
...@@ -50,6 +52,7 @@ wp_factory_new (WpCore * core, const gchar * name, WpFactoryFunc func) ...@@ -50,6 +52,7 @@ wp_factory_new (WpCore * core, const gchar * name, WpFactoryFunc func)
g_return_val_if_fail (func != NULL, NULL); g_return_val_if_fail (func != NULL, NULL);
f = g_object_new (WP_TYPE_FACTORY, NULL); f = g_object_new (WP_TYPE_FACTORY, NULL);
g_weak_ref_init (&f->core, core);
f->name = g_strdup (name); f->name = g_strdup (name);
f->name_quark = g_quark_from_string (f->name); f->name_quark = g_quark_from_string (f->name);
f->create_object = func; f->create_object = func;
...@@ -66,6 +69,18 @@ wp_factory_get_name (WpFactory * self) ...@@ -66,6 +69,18 @@ wp_factory_get_name (WpFactory * self)
return self->name; return self->name;
} }
/**
* wp_factory_get_core:
* @self: the factory
*
* Returns: (transfer full): the core on which this factory is registered
*/
WpCore *
wp_factory_get_core (WpFactory * self)
{
return g_weak_ref_get (&self->core);
}
gpointer gpointer
wp_factory_create_object (WpFactory * self, GType type, GVariant * properties) wp_factory_create_object (WpFactory * self, GType type, GVariant * properties)
{ {
......
...@@ -23,6 +23,7 @@ WpFactory * wp_factory_new (WpCore * core, const gchar * name, ...@@ -23,6 +23,7 @@ WpFactory * wp_factory_new (WpCore * core, const gchar * name,
WpFactoryFunc func); WpFactoryFunc func);
const gchar * wp_factory_get_name (WpFactory * self); const gchar * wp_factory_get_name (WpFactory * self);
WpCore * wp_factory_get_core (WpFactory * self);
gpointer wp_factory_create_object (WpFactory * self, GType type, gpointer wp_factory_create_object (WpFactory * self, GType type,
GVariant * properties); GVariant * properties);
......
...@@ -17,6 +17,8 @@ typedef void (*WpModuleInitFunc) (WpModule *, WpCore *, GVariant *); ...@@ -17,6 +17,8 @@ typedef void (*WpModuleInitFunc) (WpModule *, WpCore *, GVariant *);
struct _WpModule struct _WpModule
{ {
GObject parent; GObject parent;
GWeakRef core;
GVariant *properties; GVariant *properties;
GDestroyNotify destroy; GDestroyNotify destroy;
gpointer destroy_data; gpointer destroy_data;
...@@ -37,6 +39,7 @@ wp_module_finalize (GObject * object) ...@@ -37,6 +39,7 @@ wp_module_finalize (GObject * object)
if (self->destroy) if (self->destroy)
self->destroy (self->destroy_data); self->destroy (self->destroy_data);
g_clear_pointer (&self->properties, g_variant_unref); g_clear_pointer (&self->properties, g_variant_unref);
g_weak_ref_clear (&self->core);
G_OBJECT_CLASS (wp_module_parent_class)->finalize (object); G_OBJECT_CLASS (wp_module_parent_class)->finalize (object);
} }
...@@ -106,8 +109,10 @@ wp_module_load (WpCore * core, const gchar * abi, ...@@ -106,8 +109,10 @@ wp_module_load (WpCore * core, const gchar * abi,
{ {
g_autoptr (WpModule) module = NULL; g_autoptr (WpModule) module = NULL;
module = g_object_new (WP_TYPE_MODULE, NULL);
g_weak_ref_init (&module->core, core);
if (!g_strcmp0 (abi, "C")) { if (!g_strcmp0 (abi, "C")) {
module = g_object_new (WP_TYPE_MODULE, NULL);
if (!wp_module_load_c (module, core, module_name, args, error)) if (!wp_module_load_c (module, core, module_name, args, error))
return NULL; return NULL;
} else { } else {
...@@ -118,6 +123,7 @@ wp_module_load (WpCore * core, const gchar * abi, ...@@ -118,6 +123,7 @@ wp_module_load (WpCore * core, const gchar * abi,
wp_core_register_global (core, g_quark_from_string (module_name), wp_core_register_global (core, g_quark_from_string (module_name),
g_object_ref (module), g_object_unref); g_object_ref (module), g_object_unref);
return module; return module;
} }
...@@ -127,6 +133,18 @@ wp_module_get_properties (WpModule * self) ...@@ -127,6 +133,18 @@ wp_module_get_properties (WpModule * self)
return self->properties; return self->properties;
} }
/**
* wp_module_get_core:
* @self: the module
*
* Returns: (transfer full): the core on which this module is registered
*/
WpCore *
wp_module_get_core (WpModule * self)
{
return g_weak_ref_get (&self->core);
}
void void
wp_module_set_destroy_callback (WpModule * self, GDestroyNotify callback, wp_module_set_destroy_callback (WpModule * self, GDestroyNotify callback,
gpointer data) gpointer data)
......
...@@ -20,6 +20,7 @@ WpModule * wp_module_load (WpCore * core, const gchar * abi, ...@@ -20,6 +20,7 @@ WpModule * wp_module_load (WpCore * core, const gchar * abi,
const gchar * module_name, GVariant * args, GError ** error); const gchar * module_name, GVariant * args, GError ** error);
GVariant * wp_module_get_properties (WpModule * module); GVariant * wp_module_get_properties (WpModule * module);
WpCore * wp_module_get_core (WpModule * module);
void wp_module_set_destroy_callback (WpModule * module, GDestroyNotify callback, void wp_module_set_destroy_callback (WpModule * module, GDestroyNotify callback,
gpointer data); gpointer data);
......
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