[libpeas/proxys] Introduce peas_object_module_register_extension_type()
- From: Steve Frécinaux <sfre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libpeas/proxys] Introduce peas_object_module_register_extension_type()
- Date: Wed, 26 May 2010 10:48:34 +0000 (UTC)
commit 275ab97e92bcf36cdf20f203b49fcfe760c6150d
Author: Steve Frécinaux <code istique net>
Date: Wed May 26 12:47:13 2010 +0200
Introduce peas_object_module_register_extension_type()
This new PeasObjectModule method allows to directly register a GType
as an extension type, instead of requiring the plugin writer to register
an extension creation function.
libpeas/peas-object-module.c | 23 +++++++++++++++++--
libpeas/peas-object-module.h | 4 +++
loaders/c/peas-plugin-loader-c.c | 13 ++--------
loaders/python/peas-plugin-loader-python.c | 13 ++--------
loaders/seed/peas-plugin-loader-seed.c | 10 ++------
.../helloworld/peasdemo-hello-world-plugin.c | 20 +++++------------
6 files changed, 39 insertions(+), 44 deletions(-)
---
diff --git a/libpeas/peas-object-module.c b/libpeas/peas-object-module.c
index 42b9755..5dd5420 100644
--- a/libpeas/peas-object-module.c
+++ b/libpeas/peas-object-module.c
@@ -327,12 +327,29 @@ peas_object_module_get_library (PeasObjectModule *module)
void
peas_object_module_register_extension (PeasObjectModule *module,
- GType iface_type,
- PeasCreateFunc func,
- gconstpointer user_data)
+ GType iface_type,
+ PeasCreateFunc func,
+ gconstpointer user_data)
{
InterfaceImplementation impl = { iface_type, func, user_data };
g_array_append_val (module->priv->implementations, impl);
g_debug ("Registered extension for type '%s'", g_type_name (iface_type));
}
+
+static GObject *
+create_gobject_from_type (gconstpointer user_data)
+{
+ return g_object_new (GPOINTER_TO_SIZE (user_data), NULL);
+}
+
+void
+peas_object_module_register_extension_type (PeasObjectModule *module,
+ GType iface_type,
+ GType extension_type)
+{
+ peas_object_module_register_extension (module,
+ iface_type,
+ create_gobject_from_type,
+ GSIZE_TO_POINTER (extension_type));
+}
diff --git a/libpeas/peas-object-module.h b/libpeas/peas-object-module.h
index 7a14deb..17a2380 100644
--- a/libpeas/peas-object-module.h
+++ b/libpeas/peas-object-module.h
@@ -76,6 +76,10 @@ void peas_object_module_register_extension (PeasObjectModule
GType iface_type,
PeasCreateFunc func,
gconstpointer user_data);
+void peas_object_module_register_extension_type
+ (PeasObjectModule *module,
+ GType iface_type,
+ GType extension_type);
G_END_DECLS
diff --git a/loaders/c/peas-plugin-loader-c.c b/loaders/c/peas-plugin-loader-c.c
index 3911f17..c8f7bc8 100644
--- a/loaders/c/peas-plugin-loader-c.c
+++ b/loaders/c/peas-plugin-loader-c.c
@@ -32,22 +32,15 @@ struct _PeasPluginLoaderCPrivate
G_DEFINE_DYNAMIC_TYPE (PeasPluginLoaderC, peas_plugin_loader_c, PEAS_TYPE_PLUGIN_LOADER);
-static GObject *
-create_object (GType the_type)
-{
- return g_object_new (the_type, NULL);
-}
-
G_MODULE_EXPORT void
peas_register_types (PeasObjectModule *module)
{
peas_plugin_loader_c_register_type (G_TYPE_MODULE (module));
peas_extension_c_register (G_TYPE_MODULE (module));
- peas_object_module_register_extension (module,
- PEAS_TYPE_PLUGIN_LOADER,
- (PeasCreateFunc) create_object,
- GSIZE_TO_POINTER (PEAS_TYPE_PLUGIN_LOADER_C));
+ peas_object_module_register_extension_type (module,
+ PEAS_TYPE_PLUGIN_LOADER,
+ PEAS_TYPE_PLUGIN_LOADER_C);
}
static void
diff --git a/loaders/python/peas-plugin-loader-python.c b/loaders/python/peas-plugin-loader-python.c
index fb86ad8..0eee9a1 100644
--- a/loaders/python/peas-plugin-loader-python.c
+++ b/loaders/python/peas-plugin-loader-python.c
@@ -51,22 +51,15 @@ static gboolean peas_plugin_loader_python_add_module_path (PeasPluginLoaderPyt
G_DEFINE_DYNAMIC_TYPE (PeasPluginLoaderPython, peas_plugin_loader_python, PEAS_TYPE_PLUGIN_LOADER);
-static GObject *
-create_object (GType the_type)
-{
- return g_object_new (the_type, NULL);
-}
-
G_MODULE_EXPORT void
peas_register_types (PeasObjectModule *module)
{
peas_plugin_loader_python_register_type (G_TYPE_MODULE (module));
peas_extension_python_register (G_TYPE_MODULE (module));
- peas_object_module_register_extension (module,
- PEAS_TYPE_PLUGIN_LOADER,
- (PeasCreateFunc) create_object,
- GSIZE_TO_POINTER (PEAS_TYPE_PLUGIN_LOADER_PYTHON));
+ peas_object_module_register_extension_type (module,
+ PEAS_TYPE_PLUGIN_LOADER,
+ PEAS_TYPE_PLUGIN_LOADER_PYTHON);
}
static PyTypeObject *
diff --git a/loaders/seed/peas-plugin-loader-seed.c b/loaders/seed/peas-plugin-loader-seed.c
index 369da75..5bd73f7 100644
--- a/loaders/seed/peas-plugin-loader-seed.c
+++ b/loaders/seed/peas-plugin-loader-seed.c
@@ -227,17 +227,13 @@ peas_plugin_loader_seed_class_finalize (PeasPluginLoaderSeedClass *klass)
{
}
-static GObject *
-create_plugin_loader (gconstpointer user_data)
-{
- return g_object_new (PEAS_TYPE_PLUGIN_LOADER_SEED, NULL);
-}
-
G_MODULE_EXPORT void
peas_register_types (PeasObjectModule *module)
{
peas_plugin_loader_seed_register_type (G_TYPE_MODULE (module));
peas_extension_seed_register (G_TYPE_MODULE (module));
- peas_object_module_register_extension (module, PEAS_TYPE_PLUGIN_LOADER, create_plugin_loader, NULL);
+ peas_object_module_register_extension_type (module,
+ PEAS_TYPE_PLUGIN_LOADER,
+ PEAS_TYPE_PLUGIN_LOADER_SEED);
}
diff --git a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c
index 3bd6b2e..afd3b73 100644
--- a/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c
+++ b/peas-demo/plugins/helloworld/peasdemo-hello-world-plugin.c
@@ -156,23 +156,15 @@ peasdemo_hello_world_plugin_class_finalize (PeasDemoHelloWorldPluginClass *klass
{
}
-GObject *
-create_plugin (void)
-{
- return g_object_new (PEASDEMO_TYPE_HELLO_WORLD_PLUGIN, NULL);
-}
-
G_MODULE_EXPORT void
peas_register_types (PeasObjectModule *module)
{
peasdemo_hello_world_plugin_register_type (G_TYPE_MODULE (module));
- peas_object_module_register_extension (module,
- PEAS_TYPE_ACTIVATABLE,
- (PeasCreateFunc) create_plugin,
- NULL);
- peas_object_module_register_extension (module,
- PEAS_UI_TYPE_CONFIGURABLE,
- (PeasCreateFunc) create_plugin,
- NULL);
+ peas_object_module_register_extension_type (module,
+ PEAS_TYPE_ACTIVATABLE,
+ PEASDEMO_TYPE_HELLO_WORLD_PLUGIN);
+ peas_object_module_register_extension_type (module,
+ PEAS_UI_TYPE_CONFIGURABLE,
+ PEASDEMO_TYPE_HELLO_WORLD_PLUGIN);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]