summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan A. Suarez Romero <jasuarez@igalia.com>2015-12-10 11:31:46 +0000
committerJuan A. Suarez Romero <jasuarez@igalia.com>2015-12-15 17:14:55 +0100
commit222beefa6d0deea483e35010878b4828bc41a5d4 (patch)
treeced29706a3bc3c3886e5469500c9c5f8c2c347df
parent6d68858dad2afbc0662021f9ca4d7167d79fb48a (diff)
core: add GRL_PLUGIN_DEFINE()
Defines a new plugin that can be loaded later. It adds all the fields that usually go in the XML file. https://bugzilla.gnome.org/show_bug.cgi?id=759295
-rw-r--r--bindings/vala/grilo-0.3.vapi4
-rw-r--r--src/grl-registry.c32
-rw-r--r--src/grl-registry.h123
3 files changed, 96 insertions, 63 deletions
diff --git a/bindings/vala/grilo-0.3.vapi b/bindings/vala/grilo-0.3.vapi
index 91bea0f..0090c5d 100644
--- a/bindings/vala/grilo-0.3.vapi
+++ b/bindings/vala/grilo-0.3.vapi
@@ -809,6 +809,10 @@ namespace Grl {
}
[CCode (cheader_filename = "grilo.h", has_target = false)]
public delegate void OperationCancelCb (void* data);
+ [CCode (cheader_filename = "grilo.h", has_target = false)]
+ public delegate void PluginDeinitFunc (Grl.Plugin plugin);
+ [CCode (cheader_filename = "grilo.h", has_target = false)]
+ public delegate void PluginRegisterKeysFunc (Grl.Registry registry, Grl.Plugin plugin);
[CCode (cheader_filename = "grilo.h", instance_pos = 2.9)]
public delegate void SourceRemoveCb (Grl.Source source, owned Grl.Media media, GLib.Error? error);
[CCode (cheader_filename = "grilo.h", instance_pos = 3.9)]
diff --git a/src/grl-registry.c b/src/grl-registry.c
index 3948c02..56c8600 100644
--- a/src/grl-registry.c
+++ b/src/grl-registry.c
@@ -1207,22 +1207,22 @@ grl_registry_prepare_plugin_from_desc (GrlRegistry *registry,
{
GrlPlugin *plugin;
- if (!plugin_desc->plugin_init ||
- !plugin_desc->plugin_id) {
+ if (!plugin_desc->init ||
+ !plugin_desc->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_id (plugin, plugin_desc->id);
+ grl_plugin_set_filename (plugin, plugin_desc->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);
+ grl_plugin_set_load_func (plugin, plugin_desc->init);
+ grl_plugin_set_unload_func (plugin, plugin_desc->deinit);
+ grl_plugin_set_register_keys_func (plugin, plugin_desc->register_keys);
/* Insert plugin ID as part of plugin information */
- grl_plugin_set_info (plugin, GRL_PLUGIN_INFO_MODULE, plugin_desc->plugin_id);
+ grl_plugin_set_info (plugin, GRL_PLUGIN_INFO_MODULE, plugin_desc->id);
return plugin;
}
@@ -1261,8 +1261,8 @@ grl_registry_prepare_plugin (GrlRegistry *registry,
return NULL;
}
- if (!plugin_desc->plugin_init ||
- !plugin_desc->plugin_id) {
+ if (!plugin_desc->init ||
+ !plugin_desc->id) {
GRL_WARNING ("Plugin descriptor is not valid: '%s'", library_filename);
g_set_error (error,
GRL_CORE_ERROR,
@@ -1274,11 +1274,11 @@ grl_registry_prepare_plugin (GrlRegistry *registry,
/* Check if plugin is preloaded; if not, then create one */
plugin = g_hash_table_lookup (registry->priv->plugins,
- plugin_desc->plugin_id);
+ plugin_desc->id);
if (!plugin) {
info_dirname = g_path_get_dirname (library_filename);
- info_filename = g_strconcat (plugin_desc->plugin_id, "." GRL_PLUGIN_INFO_SUFFIX, NULL);
+ info_filename = g_strconcat (plugin_desc->id, "." GRL_PLUGIN_INFO_SUFFIX, NULL);
plugin = grl_registry_preload_plugin (registry, info_dirname, info_filename);
g_free (info_dirname);
g_free (info_filename);
@@ -1286,7 +1286,7 @@ grl_registry_prepare_plugin (GrlRegistry *registry,
g_set_error (error,
GRL_CORE_ERROR,
GRL_CORE_ERROR_LOAD_PLUGIN_FAILED,
- _("Unable to load plugin '%s'"), plugin_desc->plugin_id);
+ _("Unable to load plugin '%s'"), plugin_desc->id);
g_module_close (module);
return NULL;
}
@@ -1303,9 +1303,9 @@ grl_registry_prepare_plugin (GrlRegistry *registry,
}
if (!grl_plugin_get_module (plugin)) {
- 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);
+ grl_plugin_set_load_func (plugin, plugin_desc->init);
+ grl_plugin_set_unload_func (plugin, plugin_desc->deinit);
+ grl_plugin_set_register_keys_func (plugin, plugin_desc->register_keys);
/* Insert module name as part of plugin information */
module_name = g_path_get_basename (library_filename);
diff --git a/src/grl-registry.h b/src/grl-registry.h
index a2f57d1..43e40e4 100644
--- a/src/grl-registry.h
+++ b/src/grl-registry.h
@@ -72,73 +72,102 @@
/* Plugin registration */
/**
- * GRL_PLUGIN_REGISTER_FULL:
- * @init: the module initialization. It shall instantiate
- * the #GrlPlugins provided
- * @deinit: (allow-none): function to execute when the registry needs to dispose the module
- * @register_keys: (allow-none): function to execute before plugin initialisation to register
- * new metadata keys
- * @id: the module identifier
- *
- * Define the boilerplate for loadable modules. Defines a new module
- * descriptor which provides a set of #GrlPlugins
- */
-#define GRL_PLUGIN_REGISTER_FULL(init, \
- deinit, \
- register_keys, \
- id) \
- G_MODULE_EXPORT GrlPluginDescriptor GRL_PLUGIN_DESCRIPTOR = { \
- .plugin_id = id, \
- .plugin_init = init, \
- .plugin_deinit = deinit, \
- .plugin_register_keys = register_keys, \
- .module = NULL \
+* GRL_PLUGIN_DEFINE:
+* @major_version: the major version number of core that plugin was compiled for
+* @minor_version: the minor version number of core that plugin was compiled for
+* @id: the plugin identifier
+* @name: name of plugin
+* @description: description of plugin
+* @author: author of plugin
+* @version: version of plugin
+* @license: license of plugin
+* @site: URL to provider of plugin
+* @init: the module initialization. It shall instantiate
+* the #GrlPlugins provided
+* @deinit: (allow-none): function to execute when the registry needs to dispose
+* the module.
+* @register_keys: (allow-none): function to execute before loading the
+* plugin. It's aim is to register new keys
+*/
+#define GRL_PLUGIN_DEFINE(major, \
+ minor, \
+ id, \
+ name, \
+ description, \
+ author, \
+ version, \
+ license, \
+ site, \
+ init, \
+ deinit, \
+ register_keys) \
+ G_MODULE_EXPORT GrlPluginDescriptor GRL_PLUGIN_DESCRIPTOR = { \
+ major, \
+ minor, \
+ id, \
+ name, \
+ description, \
+ author, \
+ version, \
+ license, \
+ site, \
+ init, \
+ deinit, \
+ register_keys \
}
-/**
- * GRL_PLUGIN_REGISTER:
- * @init: the module initialization. It shall instantiate
- * the #GrlPlugins provided
- * @deinit: (allow-none): function to execute when the registry needs to dispose the module
- * @id: the module identifier
- *
- * Define the boilerplate for loadable modules. Defines a new module
- * descriptor which provides a set of #GrlPlugins
- */
-#define GRL_PLUGIN_REGISTER(init, \
- deinit, \
- id) \
- GRL_PLUGIN_REGISTER_FULL(init, deinit, NULL, id)
-
/* Plugin descriptor */
typedef struct _GrlRegistry GrlRegistry;
typedef struct _GrlPluginDescriptor GrlPluginDescriptor;
+typedef gboolean (*GrlPluginInitFunc) (GrlRegistry *registry,
+ GrlPlugin *plugin,
+ GList *configs);
+
+typedef void (*GrlPluginDeinitFunc) (GrlPlugin *plugin);
+
+typedef void (*GrlPluginRegisterKeysFunc) (GrlRegistry *registry,
+ GrlPlugin *plugin);
+
/**
* GrlPluginDescriptor:
-* @plugin_id: the module identifier
+* @major_version: the major version number of core that plugin was compiled for
+* @minor_version: the minor version number of core that plugin was compiled for
+* @id: the plugin identifier
+* @name: name of plugin
+* @description: description of plugin
+* @author: author of plugin
+* @version: version of plugin
+* @license: license of plugin
+* @site: URL to provider of plugin
* @plugin_init: the module initialization. It shall instantiate
* the #GrlPlugins provided
* @plugin_deinit: function to execute when the registry needs
* to dispose the module.
-* @module: the #GModule instance.
+* @plugin_register_keys: function to execute before loading the plugin. It's aim
+* is to register new keys
*
* This structure is used for the module loader
*/
struct _GrlPluginDescriptor {
- gchar *plugin_id;
- gboolean (*plugin_init) (GrlRegistry *registry,
- GrlPlugin *plugin,
- GList *configs);
- void (*plugin_deinit) (GrlPlugin *plugin);
- GModule *module;
- void (*plugin_register_keys) (GrlRegistry *registry,
- GrlPlugin *plugin);
+ gint major_version;
+ gint minor_version;
+ gchar *id;
+ gchar *name;
+ gchar *description;
+ gchar *author;
+ gchar *version;
+ gchar *license;
+ gchar *site;
+
+ GrlPluginInitFunc init;
+ GrlPluginDeinitFunc deinit;
+ GrlPluginRegisterKeysFunc register_keys;
/*< private >*/
- gpointer _grl_reserved[GRL_PADDING - 1];
+ gpointer _grl_reserved[GRL_PADDING];
};
/* Plugin ranks */