Commit 1cb2421e authored by Tom Dyas's avatar Tom Dyas Committed by Tom Dyas
Browse files

Update to the new plugin API.

1998-09-17  Tom Dyas  <tdyas@vger.rutgers.edu>

        * plugins/sample/plugin-sample.c: Update to the new plugin API.

        * src/plugin.c (plugin_load,plugin_unload): Replaced g_print's
        with gnumeric_notice. Call new API function "can_unload" to see if
        a plugin is still in use.

        * src/plugin.h: New API function "can_unload". Removed refcount.
parent aca945d0
1998-09-17 Tom Dyas <tdyas@vger.rutgers.edu>
* plugins/sample/plugin-sample.c: Update to the new plugin API.
* src/plugin.c (plugin_load,plugin_unload): Replaced g_print's
with gnumeric_notice. Call new API function "can_unload" to see if
a plugin is still in use.
* src/plugin.h: New API function "can_unload". Removed refcount.
1998-09-17 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-view.c (sheet_view_row_size_changed,
......
1998-09-17 Tom Dyas <tdyas@vger.rutgers.edu>
* plugins/sample/plugin-sample.c: Update to the new plugin API.
* src/plugin.c (plugin_load,plugin_unload): Replaced g_print's
with gnumeric_notice. Call new API function "can_unload" to see if
a plugin is still in use.
* src/plugin.h: New API function "can_unload". Removed refcount.
1998-09-17 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-view.c (sheet_view_row_size_changed,
......
1998-09-17 Tom Dyas <tdyas@vger.rutgers.edu>
* plugins/sample/plugin-sample.c: Update to the new plugin API.
* src/plugin.c (plugin_load,plugin_unload): Replaced g_print's
with gnumeric_notice. Call new API function "can_unload" to see if
a plugin is still in use.
* src/plugin.h: New API function "can_unload". Removed refcount.
1998-09-17 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-view.c (sheet_view_row_size_changed,
......
1998-09-17 Tom Dyas <tdyas@vger.rutgers.edu>
* plugins/sample/plugin-sample.c: Update to the new plugin API.
* src/plugin.c (plugin_load,plugin_unload): Replaced g_print's
with gnumeric_notice. Call new API function "can_unload" to see if
a plugin is still in use.
* src/plugin.h: New API function "can_unload". Removed refcount.
1998-09-17 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet-view.c (sheet_view_row_size_changed,
......
......@@ -12,7 +12,7 @@
#include "../../src/plugin.h"
static Value *
func_plusone (Value *argv [], char **error_string)
func_plusone (FunctionDefinition * fndef, Value *argv [], char **error_string)
{
Value *v = g_new (Value, 1);
......@@ -27,22 +27,33 @@ static FunctionDefinition plugin_functions [] = {
{ NULL, NULL },
};
int init_plugin (PluginData * pd)
static int
can_unload (PluginData *pd)
{
g_print("plugin-one.c: initializing\n");
install_symbols (plugin_functions);
pd->title = g_strdup ("PlusOne Plugin");
return 0;
Symbol *sym;
sym = symbol_lookup ("plusone");
return sym->ref_count <= 1;
}
void cleanup_plugin (PluginData *pd)
static void
cleanup_plugin (PluginData *pd)
{
Symbol *sym;
g_free (pd->title);
sym = symbol_lookup ("plusone");
if (sym) {
symbol_unref(sym);
}
}
int init_plugin (PluginData * pd)
{
install_symbols (plugin_functions);
pd->can_unload = can_unload;
pd->cleanup_plugin = cleanup_plugin;
pd->title = g_strdup ("PlusOne Plugin");
return 0;
}
......@@ -23,8 +23,6 @@ plugin_load (gchar *modfile)
g_return_val_if_fail (modfile != NULL, NULL);
g_print("Loading plugin '%s'.\n", modfile);
data = g_new0 (PluginData, 1);
if (!data){
g_print ("allocation error");
......@@ -33,23 +31,21 @@ plugin_load (gchar *modfile)
data->handle = g_module_open (modfile, 0);
if (!data->handle) {
g_print ("unable to open module file: %s\n", g_module_error());
char *str;
str = g_copy_strings("unable to open module file: ", g_module_error(), NULL);
gnumeric_notice(str);
g_free(str);
g_free(data);
return NULL;
}
if (!g_module_symbol (data->handle, "init_plugin", (gpointer *) &data->init_plugin)){
g_print ("module must contain init_plugin function");
gnumeric_notice ("Plugin must contain init_plugin function.");
goto error;
}
if (!g_module_symbol (data->handle, "cleanup_plugin", (gpointer *) &data->cleanup_plugin)){
g_print("module must contain cleanup_plugin funciton");
goto error;
}
if (data->init_plugin (data) < 0){
g_print ("init_plugin returned error");
gnumeric_notice ("init_plugin returned error");
goto error;
}
......@@ -63,14 +59,12 @@ plugin_load (gchar *modfile)
}
void
plugin_unload (struct PluginData *pd)
plugin_unload (PluginData *pd)
{
g_return_if_fail (pd != NULL);
g_print ("unloading plugin %s\n", g_module_name (pd->handle));
if (pd->refcount > 0) {
g_print ("unload_plugin: refcount is positve, cannot unload\n");
if (pd->can_unload && !pd->can_unload(pd)) {
gnumeric_notice("Plugin is still in use.\n");
return;
}
......@@ -81,7 +75,6 @@ plugin_unload (struct PluginData *pd)
g_module_close (pd->handle);
g_free (pd);
g_print ("unload_plugin: plugin is unloaded\n");
}
static void
......@@ -114,8 +107,6 @@ plugins_init(void)
if (!g_module_supported())
return;
g_print ("plugins_init()\n");
/* Load the user plugins */
plugin_dir = g_copy_strings (home_dir ? home_dir : "", "/.gnumeric/plugins/", NULL);
plugin_load_plugins_in_dir (plugin_dir);
......
......@@ -7,8 +7,8 @@ struct PluginData
{
GModule *handle;
int (*init_plugin) (struct PluginData *);
int (*can_unload) (struct PluginData *);
void (*cleanup_plugin) (struct PluginData *);
int refcount;
gchar *title;
/* filled in by plugin */
......@@ -24,7 +24,4 @@ PluginData *plugin_load (gchar *filename);
void plugin_unload (PluginData *pd);
GtkWidget *plugin_manager_new (void);
/* These get defined in plugins */
int init_plugin (PluginData *pd);
void cleanup_plugin (PluginData *pd);
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment