2011-11-07 13:46:58 -06:00
|
|
|
/*
|
2011-11-07 16:52:18 -06:00
|
|
|
* pluma-plugin-loader-c.c
|
|
|
|
* This file is part of pluma
|
2011-11-07 13:46:58 -06:00
|
|
|
*
|
|
|
|
* Copyright (C) 2008 - Jesse van den Kieboom
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-11-18 19:54:49 -06:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2011-11-07 13:46:58 -06:00
|
|
|
*/
|
|
|
|
|
2011-11-07 16:52:18 -06:00
|
|
|
#include "pluma-plugin-loader-c.h"
|
|
|
|
#include <pluma/pluma-object-module.h>
|
2011-11-07 13:46:58 -06:00
|
|
|
|
2011-11-07 16:52:18 -06:00
|
|
|
#define PLUMA_PLUGIN_LOADER_C_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), PLUMA_TYPE_PLUGIN_LOADER_C, PlumaPluginLoaderCPrivate))
|
2011-11-07 13:46:58 -06:00
|
|
|
|
2011-11-07 16:52:18 -06:00
|
|
|
struct _PlumaPluginLoaderCPrivate
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
GHashTable *loaded_plugins;
|
|
|
|
};
|
|
|
|
|
2011-11-07 16:52:18 -06:00
|
|
|
static void pluma_plugin_loader_iface_init (gpointer g_iface, gpointer iface_data);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
2011-11-07 16:52:18 -06:00
|
|
|
PLUMA_PLUGIN_LOADER_REGISTER_TYPE (PlumaPluginLoaderC, pluma_plugin_loader_c, G_TYPE_OBJECT, pluma_plugin_loader_iface_init);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
|
|
|
|
static const gchar *
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_plugin_loader_iface_get_id (void)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
return "C";
|
|
|
|
}
|
|
|
|
|
2011-11-07 16:52:18 -06:00
|
|
|
static PlumaPlugin *
|
|
|
|
pluma_plugin_loader_iface_load (PlumaPluginLoader *loader,
|
|
|
|
PlumaPluginInfo *info,
|
2011-11-07 13:46:58 -06:00
|
|
|
const gchar *path)
|
|
|
|
{
|
2011-11-07 16:52:18 -06:00
|
|
|
PlumaPluginLoaderC *cloader = PLUMA_PLUGIN_LOADER_C (loader);
|
|
|
|
PlumaObjectModule *module;
|
2011-11-07 13:46:58 -06:00
|
|
|
const gchar *module_name;
|
2011-11-07 16:52:18 -06:00
|
|
|
PlumaPlugin *result;
|
2011-11-07 13:46:58 -06:00
|
|
|
|
2011-11-07 16:52:18 -06:00
|
|
|
module = (PlumaObjectModule *)g_hash_table_lookup (cloader->priv->loaded_plugins, info);
|
|
|
|
module_name = pluma_plugin_info_get_module_name (info);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
if (module == NULL)
|
|
|
|
{
|
|
|
|
/* For now we force all modules to be resident */
|
2011-11-07 16:52:18 -06:00
|
|
|
module = pluma_object_module_new (module_name,
|
2011-11-07 13:46:58 -06:00
|
|
|
path,
|
2011-11-07 16:52:18 -06:00
|
|
|
"register_pluma_plugin",
|
2011-11-07 13:46:58 -06:00
|
|
|
TRUE);
|
|
|
|
|
|
|
|
/* Infos are available for all the lifetime of the loader.
|
|
|
|
* If this changes, we should use weak refs or something */
|
|
|
|
|
|
|
|
g_hash_table_insert (cloader->priv->loaded_plugins, info, module);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_type_module_use (G_TYPE_MODULE (module)))
|
|
|
|
{
|
2011-11-07 16:52:18 -06:00
|
|
|
g_warning ("Could not load plugin module: %s", pluma_plugin_info_get_name (info));
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: for now we force data-dir-name = module-name... if needed we can
|
|
|
|
* add a datadir field to the plugin descriptor file.
|
|
|
|
*/
|
2011-11-07 16:52:18 -06:00
|
|
|
result = (PlumaPlugin *)pluma_object_module_new_object (module,
|
2011-11-07 13:46:58 -06:00
|
|
|
"install-dir", path,
|
|
|
|
"data-dir-name", module_name,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (!result)
|
|
|
|
{
|
2011-11-07 16:52:18 -06:00
|
|
|
g_warning ("Could not create plugin object: %s", pluma_plugin_info_get_name (info));
|
2011-11-07 13:46:58 -06:00
|
|
|
g_type_module_unuse (G_TYPE_MODULE (module));
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_type_module_unuse (G_TYPE_MODULE (module));
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_plugin_loader_iface_unload (PlumaPluginLoader *loader,
|
|
|
|
PlumaPluginInfo *info)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2011-11-07 16:52:18 -06:00
|
|
|
//PlumaPluginLoaderC *cloader = PLUMA_PLUGIN_LOADER_C (loader);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
/* this is a no-op, since the type module will be properly unused as
|
|
|
|
the last reference to the plugin dies. When the plugin is activated
|
|
|
|
again, the library will be reloaded */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_plugin_loader_iface_init (gpointer g_iface,
|
2011-11-07 13:46:58 -06:00
|
|
|
gpointer iface_data)
|
|
|
|
{
|
2011-11-07 16:52:18 -06:00
|
|
|
PlumaPluginLoaderInterface *iface = (PlumaPluginLoaderInterface *)g_iface;
|
2011-11-07 13:46:58 -06:00
|
|
|
|
2011-11-07 16:52:18 -06:00
|
|
|
iface->get_id = pluma_plugin_loader_iface_get_id;
|
|
|
|
iface->load = pluma_plugin_loader_iface_load;
|
|
|
|
iface->unload = pluma_plugin_loader_iface_unload;
|
2011-11-07 13:46:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_plugin_loader_c_finalize (GObject *object)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2011-11-07 16:52:18 -06:00
|
|
|
PlumaPluginLoaderC *cloader = PLUMA_PLUGIN_LOADER_C (object);
|
2011-11-07 13:46:58 -06:00
|
|
|
GList *infos;
|
|
|
|
GList *item;
|
|
|
|
|
|
|
|
/* FIXME: this sanity check it's not efficient. Let's remove it
|
|
|
|
* once we are confident with the code */
|
|
|
|
|
|
|
|
infos = g_hash_table_get_keys (cloader->priv->loaded_plugins);
|
|
|
|
|
|
|
|
for (item = infos; item; item = item->next)
|
|
|
|
{
|
2011-11-07 16:52:18 -06:00
|
|
|
PlumaPluginInfo *info = (PlumaPluginInfo *)item->data;
|
2011-11-07 13:46:58 -06:00
|
|
|
|
2011-11-07 16:52:18 -06:00
|
|
|
if (pluma_plugin_info_is_active (info))
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
g_warning ("There are still C plugins loaded during destruction");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (infos);
|
|
|
|
|
|
|
|
g_hash_table_destroy (cloader->priv->loaded_plugins);
|
|
|
|
|
2011-11-07 16:52:18 -06:00
|
|
|
G_OBJECT_CLASS (pluma_plugin_loader_c_parent_class)->finalize (object);
|
2011-11-07 13:46:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_plugin_loader_c_class_init (PlumaPluginLoaderCClass *klass)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2011-11-07 16:52:18 -06:00
|
|
|
object_class->finalize = pluma_plugin_loader_c_finalize;
|
2011-11-07 13:46:58 -06:00
|
|
|
|
2011-11-07 16:52:18 -06:00
|
|
|
g_type_class_add_private (object_class, sizeof (PlumaPluginLoaderCPrivate));
|
2011-11-07 13:46:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_plugin_loader_c_class_finalize (PlumaPluginLoaderCClass *klass)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-11-07 16:52:18 -06:00
|
|
|
pluma_plugin_loader_c_init (PlumaPluginLoaderC *self)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2011-11-07 16:52:18 -06:00
|
|
|
self->priv = PLUMA_PLUGIN_LOADER_C_GET_PRIVATE (self);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
2011-11-07 16:52:18 -06:00
|
|
|
/* loaded_plugins maps PlumaPluginInfo to a PlumaObjectModule */
|
2011-11-07 13:46:58 -06:00
|
|
|
self->priv->loaded_plugins = g_hash_table_new (g_direct_hash,
|
|
|
|
g_direct_equal);
|
|
|
|
}
|
|
|
|
|
2011-11-07 16:52:18 -06:00
|
|
|
PlumaPluginLoaderC *
|
|
|
|
pluma_plugin_loader_c_new ()
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2011-11-07 16:52:18 -06:00
|
|
|
GObject *loader = g_object_new (PLUMA_TYPE_PLUGIN_LOADER_C, NULL);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
2011-11-07 16:52:18 -06:00
|
|
|
return PLUMA_PLUGIN_LOADER_C (loader);
|
2011-11-07 13:46:58 -06:00
|
|
|
}
|