[grilo] core: Add a way to load builtin plugins
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo] core: Add a way to load builtin plugins
- Date: Tue, 22 Sep 2015 15:57:26 +0000 (UTC)
commit 3314e9fb9b35e9765e31a213132ed3d45e90f5e2
Author: Bastien Nocera <hadess hadess net>
Date: Wed Mar 25 19:17:03 2015 +0100
core: Add a way to load builtin plugins
Instead of requiring plugins to ship an xml description, and a separate
.so shared library, allow applications to load plugins it implements
itself.
https://bugzilla.gnome.org/show_bug.cgi?id=747026
doc/grilo/grilo-sections.txt | 1 +
src/grl-registry.c | 67 ++++++++++++++++++++++++++++++++++++++++++
src/grl-registry.h | 4 ++
3 files changed, 72 insertions(+), 0 deletions(-)
---
diff --git a/doc/grilo/grilo-sections.txt b/doc/grilo/grilo-sections.txt
index 24ebf4c..2badbdc 100644
--- a/doc/grilo/grilo-sections.txt
+++ b/doc/grilo/grilo-sections.txt
@@ -213,6 +213,7 @@ grl_registry_load_all_plugins
grl_registry_load_plugin
grl_registry_load_plugin_by_id
grl_registry_load_plugin_directory
+grl_registry_load_plugin_from_desc
grl_registry_lookup_metadata_key
grl_registry_lookup_metadata_key_desc
grl_registry_lookup_metadata_key_name
diff --git a/src/grl-registry.c b/src/grl-registry.c
index 3edd4d7..b9cce83 100644
--- a/src/grl-registry.c
+++ b/src/grl-registry.c
@@ -1218,6 +1218,32 @@ grl_registry_add_directory (GrlRegistry *registry,
}
static GrlPlugin *
+grl_registry_prepare_plugin_from_desc (GrlRegistry *registry,
+ GrlPluginDescriptor *plugin_desc)
+{
+ GrlPlugin *plugin;
+
+ if (!plugin_desc->plugin_init ||
+ !plugin_desc->plugin_id) {
+ GRL_WARNING ("Plugin descriptor is not valid");
+ return NULL;
+ }
+
+ plugin = g_object_new (GRL_TYPE_PLUGIN, NULL);
+ grl_plugin_set_id (plugin, plugin_desc->plugin_id);
+ grl_plugin_set_filename (plugin, plugin_desc->plugin_id);
+
+ grl_plugin_set_load_func (plugin, plugin_desc->plugin_init);
+ grl_plugin_set_unload_func (plugin, plugin_desc->plugin_deinit);
+ grl_plugin_set_register_keys_func (plugin, plugin_desc->plugin_register_keys);
+
+ /* Insert plugin ID as part of plugin information */
+ grl_plugin_set_info (plugin, GRL_PLUGIN_INFO_MODULE, plugin_desc->plugin_id);
+
+ return plugin;
+}
+
+static GrlPlugin *
grl_registry_prepare_plugin (GrlRegistry *registry,
const gchar *library_filename,
GError **error)
@@ -1339,6 +1365,47 @@ grl_registry_load_plugin (GrlRegistry *registry,
}
/**
+ * grl_registry_load_plugin_from_desc: (skip)
+ * @registry: the registry instance
+ * @plugin_desc: the #GrlPluginDescriptor for the plugin
+ * @error: error return location or @NULL to ignore
+ *
+ * Loads the grilo plugin defined by @plugin_desc. This is
+ * used to load plugins that aren't shared libraries, and are
+ * built into applications.
+ *
+ * <example>
+ * Minimal example for loading a builtin plugin, in C.
+ * <programlisting>
+ * static GrlPluginDescriptor descriptor = {
+ * .plugin_id = "grl-example",
+ * .plugin_init = grl_example_plugin_init,
+ * };
+ *
+ * grl_registry_load_plugin_from_desc (registry, &descriptor, &error);
+ * </programlisting>
+ * </example>
+ *
+ * Returns: %TRUE if the plugin is initialised correctly
+ *
+ * Since: 0.3.0
+ */
+gboolean
+grl_registry_load_plugin_from_desc (GrlRegistry *registry,
+ GrlPluginDescriptor *plugin_desc,
+ GError **error)
+{
+ GrlPlugin *plugin;
+
+ plugin = grl_registry_prepare_plugin_from_desc (registry, plugin_desc);
+ if (!plugin)
+ return FALSE;
+
+ return register_keys_plugin (registry, plugin, error) &&
+ activate_plugin (registry, plugin, error);
+}
+
+/**
* grl_registry_load_plugin_directory:
* @registry: the registry instance
* @path: the path to the directory
diff --git a/src/grl-registry.h b/src/grl-registry.h
index f20a19f..a2f57d1 100644
--- a/src/grl-registry.h
+++ b/src/grl-registry.h
@@ -212,6 +212,10 @@ gboolean grl_registry_load_plugin (GrlRegistry *registry,
const gchar *library_filename,
GError **error);
+gboolean grl_registry_load_plugin_from_desc (GrlRegistry *registry,
+ GrlPluginDescriptor *plugin_desc,
+ GError **error);
+
gboolean grl_registry_load_plugin_directory (GrlRegistry *registry,
const gchar *path,
GError **error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]