Commit d7055a33 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

Ported module loading to GTypeModule, getting rid of all own module

2002-10-20  Michael Natterer  <mitch@gimp.org>

	Ported module loading to GTypeModule, getting rid of all own
	module registering/bookkeeping stuff for color selectors and
	display filters. The modules now simply register GimpColorSelector
	and GimpColorDisplay subclasses, the list of registered subclasses
	can then be obtained calling g_type_children() on the abstract
	base classes.

	This is work in progress and just the first working state after I
	started breaking everything...

	* app/gui/color-select.[ch]
	* libgimp/gimpcolordisplay.h
	* libgimp/gimpcolorselector.h: removed.

	* app/gui/Makefile.am
	* libgimp/Makefile.am: changed accordingly.

	* libgimp/gimpmodule.h: massively simplified. All voodoo is gone.

	* libgimpwidgets/gimpcolordisplay.[ch]
	* libgimpwidgets/gimpcolorselector.[ch]: new abstract base classes
	which need to be subclassed by modules.

	* libgimpwidgets/gimpcolorselect.[ch]: the built-in color selector
	from app/gui/color-select.* ported to be a GimpColorSelector
	subclass.

	* libgimpwidgets/Makefile.am
	* libgimpwidgets/gimpwidgets.h
	* libgimpwidgets/gimpwidgetsmarshal.list
	* libgimpwidgets/gimpwidgetstypes.h: changed accordingly.

	* app/core/gimpmoduleinfo.[ch]: made it a GTypeModule subclass

	* app/core/gimpmodules.c: changed accordingly.

	* app/core/gimpcontainer.c
	* app/core/gimplist.c: HACKED around to allow GimpLists of
	GObjects (not GimpObjects). This is EEKy, so I will either make
	gimp->modules a simple GList and revert this bit of change, or
	allow GObjects all over the place in GimpContainer land...

	* app/display/gimpdisplayshell-filter.[ch]
	* app/gui/color-notebook.c: removed all module stuff and use
	g_type_children() to get the list of available color_selectors
	and display_filters.

	* app/display/gimpdisplayshell-filter-dialog.c
	* app/display/gimpdisplayshell-render.c
	* app/gui/module-browser.c: changed accordingly.

	* app/gui/gui.c: ref the built-in color selector's class before
	the modules are queried so it appears first in the list of
	GimpColorSelector's children.

	* modules/Makefile.am: build the water color selector again.

	* modules/cdisplay_gamma.c
	* modules/cdisplay_highcontrast.c
	* modules/colorsel_triangle.c
	* modules/colorsel_water.c: ported them all to the new API.

	* modules/gimpmodregister.[ch]: removed the old EMX module hack.
parent 921d2652
2002-10-20 Michael Natterer <mitch@gimp.org>
Ported module loading to GTypeModule, getting rid of all own
module registering/bookkeeping stuff for color selectors and
display filters. The modules now simply register GimpColorSelector
and GimpColorDisplay subclasses, the list of registered subclasses
can then be obtained calling g_type_children() on the abstract
base classes.
This is work in progress and just the first working state after I
started breaking everything...
* app/gui/color-select.[ch]
* libgimp/gimpcolordisplay.h
* libgimp/gimpcolorselector.h: removed.
* app/gui/Makefile.am
* libgimp/Makefile.am: changed accordingly.
* libgimp/gimpmodule.h: massively simplified. All voodoo is gone.
* libgimpwidgets/gimpcolordisplay.[ch]
* libgimpwidgets/gimpcolorselector.[ch]: new abstract base classes
which need to be subclassed by modules.
* libgimpwidgets/gimpcolorselect.[ch]: the built-in color selector
from app/gui/color-select.* ported to be a GimpColorSelector
subclass.
* libgimpwidgets/Makefile.am
* libgimpwidgets/gimpwidgets.h
* libgimpwidgets/gimpwidgetsmarshal.list
* libgimpwidgets/gimpwidgetstypes.h: changed accordingly.
* app/core/gimpmoduleinfo.[ch]: made it a GTypeModule subclass
* app/core/gimpmodules.c: changed accordingly.
* app/core/gimpcontainer.c
* app/core/gimplist.c: HACKED around to allow GimpLists of
GObjects (not GimpObjects). This is EEKy, so I will either make
gimp->modules a simple GList and revert this bit of change, or
allow GObjects all over the place in GimpContainer land...
* app/display/gimpdisplayshell-filter.[ch]
* app/gui/color-notebook.c: removed all module stuff and use
g_type_children() to get the list of available color_selectors
and display_filters.
* app/display/gimpdisplayshell-filter-dialog.c
* app/display/gimpdisplayshell-render.c
* app/gui/module-browser.c: changed accordingly.
* app/gui/gui.c: ref the built-in color selector's class before
the modules are queried so it appears first in the list of
GimpColorSelector's children.
* modules/Makefile.am: build the water color selector again.
* modules/cdisplay_gamma.c
* modules/cdisplay_highcontrast.c
* modules/colorsel_triangle.c
* modules/colorsel_water.c: ported them all to the new API.
* modules/gimpmodregister.[ch]: removed the old EMX module hack.
2002-10-18 Sven Neumann <sven@gimp.org>
 
* app/core/gimpimage-mask.c (gimp_image_mask_extract): changed an
......
......@@ -47,6 +47,9 @@
#include "libgimp/gimpintl.h"
#define DUMP_DB 1
static void gimp_modules_module_initialize (const gchar *filename,
gpointer loader_data);
......@@ -60,8 +63,6 @@ static void print_module_info (gpointer data,
static gboolean gimp_modules_write_modulerc (Gimp *gimp);
static void gimp_modules_module_free_func (gpointer data,
gpointer user_data);
static void gimp_modules_module_on_disk_func (gpointer data,
gpointer user_data);
static void gimp_modules_module_remove_func (gpointer data,
......@@ -74,7 +75,7 @@ gimp_modules_init (Gimp *gimp)
g_return_if_fail (GIMP_IS_GIMP (gimp));
gimp->modules = gimp_list_new (GIMP_TYPE_MODULE_INFO,
GIMP_CONTAINER_POLICY_WEAK);
GIMP_CONTAINER_POLICY_STRONG);
gimp_object_set_name (GIMP_OBJECT (gimp->modules), "modules");
gimp->write_modulerc = FALSE;
......@@ -110,7 +111,7 @@ gimp_modules_load (Gimp *gimp)
gimp);
#ifdef DUMP_DB
gimp_container_foreach (modules, print_module_info, NULL);
gimp_container_foreach (gimp->modules, print_module_info, NULL);
#endif
}
......@@ -126,8 +127,6 @@ gimp_modules_unload (Gimp *gimp)
gimp->write_modulerc = FALSE;
}
}
gimp_container_foreach (gimp->modules, gimp_modules_module_free_func, NULL);
}
void
......@@ -153,20 +152,6 @@ gimp_modules_refresh (Gimp *gimp)
gimp);
}
static void
gimp_modules_module_free_func (gpointer data,
gpointer user_data)
{
GimpModuleInfoObj *module_info = data;
if (module_info->module &&
module_info->unload &&
module_info->state == GIMP_MODULE_STATE_LOADED_OK)
{
gimp_module_info_module_unload (module_info, FALSE);
}
}
static void
add_to_inhibit_string (gpointer data,
gpointer user_data)
......@@ -177,7 +162,7 @@ add_to_inhibit_string (gpointer data,
if (module_info->load_inhibit)
{
str = g_string_append_c (str, G_SEARCHPATH_SEPARATOR);
str = g_string_append (str, module_info->fullpath);
str = g_string_append (str, module_info->filename);
}
}
......@@ -266,62 +251,29 @@ gimp_modules_module_initialize (const gchar *filename,
if (gimp_modules_module_find_by_path (gimp, filename))
return;
module_info = gimp_module_info_new (filename);
module_info = gimp_module_info_new (filename,
gimp->config->module_db_load_inhibit,
gimp->be_verbose);
gimp_module_info_set_load_inhibit (module_info,
gimp->config->module_db_load_inhibit);
if (! module_info->load_inhibit)
{
if (gimp->be_verbose)
g_print (_("loading module: '%s'\n"), filename);
gimp_module_info_module_load (module_info, TRUE);
}
else
{
if (gimp->be_verbose)
g_print (_("skipping module: '%s'\n"), filename);
module_info->state = GIMP_MODULE_STATE_UNLOADED_OK;
}
gimp_container_add (gimp->modules, GIMP_OBJECT (module_info));
}
typedef struct
{
const gchar *search_key;
GimpModuleInfoObj *found;
} find_by_path_closure;
static void
gimp_modules_module_path_cmp_func (gpointer data,
gpointer user_data)
{
GimpModuleInfoObj *module_info;
find_by_path_closure *closure;
module_info = (GimpModuleInfoObj *) data;
closure = (find_by_path_closure *) user_data;
if (! strcmp (module_info->fullpath, closure->search_key))
closure->found = module_info;
gimp_container_add (gimp->modules, (GimpObject *) module_info);
}
static GimpModuleInfoObj *
gimp_modules_module_find_by_path (Gimp *gimp,
const char *fullpath)
{
find_by_path_closure cl;
GimpModuleInfoObj *module_info;
GList *list;
cl.found = NULL;
cl.search_key = fullpath;
for (list = GIMP_LIST (gimp->modules)->list; list; list = g_list_next (list))
{
module_info = (GimpModuleInfoObj *) list->data;
gimp_container_foreach (gimp->modules,
gimp_modules_module_path_cmp_func, &cl);
if (! strcmp (module_info->filename, fullpath))
return module_info;
}
return cl.found;
return NULL;
}
#ifdef DUMP_DB
......@@ -331,22 +283,25 @@ print_module_info (gpointer data,
{
GimpModuleInfoObj *i = data;
g_print ("\n%s: %s\n",
i->fullpath, statename[i->state]);
g_print (" module:%p lasterr:%s init:%p unload:%p\n",
i->module, i->last_module_error? i->last_module_error : "NONE",
i->init, i->unload);
g_print ("\n%s: %i\n",
i->filename,
i->state /* statename[i->state] */);
g_print (" module:%p lasterr:%s register:%p\n",
i->module,
i->last_module_error? i->last_module_error : "NONE",
i->register_module);
if (i->info)
{
g_print (" shutdown_data: %p\n"
" purpose: %s\n"
g_print (" purpose: %s\n"
" author: %s\n"
" version: %s\n"
" copyright: %s\n"
" date: %s\n",
i->info->shutdown_data,
i->info->purpose, i->info->author, i->info->version,
i->info->copyright, i->info->date);
i->info->purpose,
i->info->author,
i->info->version,
i->info->copyright,
i->info->date);
}
}
#endif
......@@ -364,7 +319,7 @@ gimp_modules_module_on_disk_func (gpointer data,
old_on_disk = module_info->on_disk;
module_info->on_disk = g_file_test (module_info->fullpath,
module_info->on_disk = g_file_test (module_info->filename,
G_FILE_TEST_IS_REGULAR);
/* if it's not on the disk, and it isn't in memory, mark it to be
......@@ -390,7 +345,5 @@ gimp_modules_module_remove_func (gpointer data,
module_info = (GimpModuleInfoObj *) data;
gimp = (Gimp *) user_data;
gimp_container_remove (gimp->modules, GIMP_OBJECT (module_info));
g_object_unref (G_OBJECT (module_info));
gimp_container_remove (gimp->modules, (GimpObject *) module_info);
}
......@@ -195,7 +195,7 @@ gimp_container_class_init (GimpContainerClass *klass)
NULL, NULL,
gimp_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
GIMP_TYPE_OBJECT);
G_TYPE_OBJECT);
container_signals[REMOVE] =
g_signal_new ("remove",
......@@ -205,7 +205,7 @@ gimp_container_class_init (GimpContainerClass *klass)
NULL, NULL,
gimp_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
GIMP_TYPE_OBJECT);
G_TYPE_OBJECT);
container_signals[REORDER] =
g_signal_new ("reorder",
......@@ -215,7 +215,7 @@ gimp_container_class_init (GimpContainerClass *klass)
NULL, NULL,
gimp_marshal_VOID__OBJECT_INT,
G_TYPE_NONE, 2,
GIMP_TYPE_OBJECT,
G_TYPE_OBJECT,
G_TYPE_INT);
container_signals[FREEZE] =
......@@ -396,7 +396,7 @@ gimp_container_serialize_foreach (GObject *object,
{
GimpConfigInterface *config_iface;
GString *str;
const gchar *name;
const gchar *name = NULL;
config_iface = GIMP_GET_CONFIG_INTERFACE (object);
......@@ -413,7 +413,8 @@ gimp_container_serialize_foreach (GObject *object,
g_string_append_printf (str, "(%s ",
g_type_name (G_TYPE_FROM_INSTANCE (object)));
name = gimp_object_get_name (GIMP_OBJECT (object));
if (GIMP_IS_OBJECT (object))
name = gimp_object_get_name (GIMP_OBJECT (object));
if (name)
{
......
......@@ -131,7 +131,7 @@ gimp_list_dispose (GObject *object)
while (list->list)
{
gimp_container_remove (GIMP_CONTAINER (list),
GIMP_OBJECT (list->list->data));
(GimpObject *) list->list->data);
}
G_OBJECT_CLASS (parent_class)->dispose (object);
......@@ -155,7 +155,8 @@ gimp_list_get_memsize (GimpObject *object)
for (list = gimp_list->list; list; list = g_list_next (list))
{
memsize += gimp_object_get_memsize (GIMP_OBJECT (list->data));
if (GIMP_IS_OBJECT (list->data))
memsize += gimp_object_get_memsize (GIMP_OBJECT (list->data));
}
}
......@@ -279,7 +280,7 @@ gimp_list_new (GType children_type,
{
GimpList *list;
g_return_val_if_fail (g_type_is_a (children_type, GIMP_TYPE_OBJECT), NULL);
g_return_val_if_fail (g_type_is_a (children_type, G_TYPE_OBJECT), NULL);
g_return_val_if_fail (policy == GIMP_CONTAINER_POLICY_STRONG ||
policy == GIMP_CONTAINER_POLICY_WEAK, NULL);
......
......@@ -42,17 +42,21 @@ enum
};
static void gimp_module_info_class_init (GimpModuleInfoObjClass *klass);
static void gimp_module_info_init (GimpModuleInfoObj *mod);
static void gimp_module_info_class_init (GimpModuleInfoObjClass *klass);
static void gimp_module_info_init (GimpModuleInfoObj *mod);
static void gimp_module_info_finalize (GObject *object);
static void gimp_module_info_finalize (GObject *object);
static gsize gimp_module_info_get_memsize (GimpObject *object);
static gboolean gimp_module_info_load (GTypeModule *module);
static void gimp_module_info_unload (GTypeModule *module);
static void gimp_module_info_set_last_error (GimpModuleInfoObj *module_info,
const gchar *error_str);
static guint module_info_signals[LAST_SIGNAL];
static GimpObjectClass *parent_class = NULL;
static GTypeModuleClass *parent_class = NULL;
GType
......@@ -75,7 +79,7 @@ gimp_module_info_get_type (void)
(GInstanceInitFunc) gimp_module_info_init,
};
module_info_type = g_type_register_static (GIMP_TYPE_OBJECT,
module_info_type = g_type_register_static (G_TYPE_TYPE_MODULE,
"GimpModuleInfoObj",
&module_info_info, 0);
}
......@@ -86,11 +90,11 @@ gimp_module_info_get_type (void)
static void
gimp_module_info_class_init (GimpModuleInfoObjClass *klass)
{
GObjectClass *object_class;
GimpObjectClass *gimp_object_class;
GObjectClass *object_class;
GTypeModuleClass *module_class;
object_class = G_OBJECT_CLASS (klass);
gimp_object_class = GIMP_OBJECT_CLASS (klass);
object_class = G_OBJECT_CLASS (klass);
module_class = G_TYPE_MODULE_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
......@@ -103,27 +107,28 @@ gimp_module_info_class_init (GimpModuleInfoObjClass *klass)
gimp_marshal_VOID__VOID,
G_TYPE_NONE, 0);
object_class->finalize = gimp_module_info_finalize;
object_class->finalize = gimp_module_info_finalize;
gimp_object_class->get_memsize = gimp_module_info_get_memsize;
module_class->load = gimp_module_info_load;
module_class->unload = gimp_module_info_unload;
klass->modified = NULL;
klass->modified = NULL;
}
static void
gimp_module_info_init (GimpModuleInfoObj *module_info)
{
module_info->fullpath = NULL;
module_info->filename = NULL;
module_info->verbose = FALSE;
module_info->state = GIMP_MODULE_STATE_ERROR;
module_info->on_disk = FALSE;
module_info->load_inhibit = FALSE;
module_info->refs = 0;
module_info->info = NULL;
module_info->module = NULL;
module_info->info = NULL;
module_info->last_module_error = NULL;
module_info->init = NULL;
module_info->unload = NULL;
module_info->register_module = NULL;
}
static void
......@@ -133,40 +138,103 @@ gimp_module_info_finalize (GObject *object)
mod = GIMP_MODULE_INFO (object);
/* if this trips, then we're onto some serious lossage in a moment */
g_return_if_fail (mod->refs == 0);
if (mod->last_module_error)
{
g_free (mod->last_module_error);
mod->last_module_error = NULL;
}
if (mod->fullpath)
if (mod->filename)
{
g_free (mod->fullpath);
mod->fullpath = NULL;
g_free (mod->filename);
mod->filename = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static gsize
gimp_module_info_get_memsize (GimpObject *object)
static gboolean
gimp_module_info_load (GTypeModule *module)
{
GimpModuleInfoObj *module_info;
gpointer symbol;
gboolean retval;
g_return_val_if_fail (GIMP_IS_MODULE_INFO (module), FALSE);
module_info = GIMP_MODULE_INFO (module);
g_return_val_if_fail (module_info->filename != NULL, FALSE);
g_return_val_if_fail (module_info->module == NULL, FALSE);
if (module_info->verbose)
g_print (_("loading module: '%s'\n"), module_info->filename);
module_info->module = g_module_open (module_info->filename,
G_MODULE_BIND_LAZY);
if (! module_info->module)
{
module_info->state = GIMP_MODULE_STATE_ERROR;
gimp_module_info_set_last_error (module_info, g_module_error ());
if (module_info->verbose)
g_message (_("Module '%s' load error:\n%s"),
module_info->filename, module_info->last_module_error);
return FALSE;
}
/* find the module_init symbol */
if (! g_module_symbol (module_info->module, "gimp_module_register", &symbol))
{
module_info->state = GIMP_MODULE_STATE_ERROR;
gimp_module_info_set_last_error (module_info,
_("Missing gimp_module_register() symbol"));
if (module_info->verbose)
g_message (_("Module '%s' load error:\n%s"),
module_info->filename, module_info->last_module_error);
g_module_close (module_info->module);
module_info->module = NULL;
return FALSE;
}
module_info->register_module = symbol;
retval = module_info->register_module (module, &module_info->info);
if (retval)
module_info->state = GIMP_MODULE_STATE_LOADED_OK;
else
module_info->state = GIMP_MODULE_STATE_LOAD_FAILED;
return retval;
}
static void
gimp_module_info_unload (GTypeModule *module)
{
GimpModuleInfoObj *module_info;
gsize memsize = 0;
module_info = GIMP_MODULE_INFO (object);
g_return_if_fail (GIMP_IS_MODULE_INFO (module));
module_info = GIMP_MODULE_INFO (module);
g_return_if_fail (module_info->module != NULL);
if (module_info->fullpath)
memsize += strlen (module_info->fullpath) + 1;
g_module_close (module_info->module); /* FIXME: error handling */
module_info->module = NULL;
module_info->info = NULL;
module_info->register_module = NULL;
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object);
module_info->state = GIMP_MODULE_STATE_UNLOADED_OK;
}
GimpModuleInfoObj *
gimp_module_info_new (const gchar *filename)
gimp_module_info_new (const gchar *filename,
const gchar *inhibit_list,
gboolean verbose)
{
GimpModuleInfoObj *module_info;
......@@ -174,9 +242,25 @@ gimp_module_info_new (const gchar *filename)
module_info = g_object_new (GIMP_TYPE_MODULE_INFO, NULL);
module_info->fullpath = g_strdup (filename);
module_info->filename = g_strdup (filename);
module_info->verbose = verbose ? TRUE : FALSE;
module_info->on_disk = TRUE;
gimp_module_info_set_load_inhibit (module_info, inhibit_list);
if (! module_info->load_inhibit)
{
if (gimp_module_info_load (G_TYPE_MODULE (module_info)))
gimp_module_info_unload (G_TYPE_MODULE (module_info));
}
else
{
if (verbose)
g_print (_("skipping module: '%s'\n"), filename);
module_info->state = GIMP_MODULE_STATE_UNLOADED_OK;
}
return module_info;
}
......@@ -198,14 +282,14 @@ gimp_module_info_set_load_inhibit (GimpModuleInfoObj *module_info,
const gchar *end;
g_return_if_fail (GIMP_IS_MODULE_INFO (module_info));
g_return_if_fail (module_info->fullpath != NULL);
g_return_if_fail (module_info->filename != NULL);
module_info->load_inhibit = FALSE;
if (! inhibit_list || ! strlen (inhibit_list))
return;
p = strstr (inhibit_list, module_info->fullpath);
p = strstr (inhibit_list, module_info->filename);
if (!p)
return;
......@@ -221,7 +305,7 @@ gimp_module_info_set_load_inhibit (GimpModuleInfoObj *module_info,
if (! end)
end = inhibit_list + strlen (inhibit_list);
pathlen = strlen (module_info->fullpath);
pathlen = strlen (module_info->filename);
if ((end - start) == pathlen)
module_info->load_inhibit = TRUE;
......@@ -236,185 +320,3 @@ gimp_module_info_set_last_error (GimpModuleInfoObj *module_info,
module_info->last_module_error = g_strdup (error_str);
}
/*
* FIXME: currently this will fail badly on EMX
*/
#ifdef __EMX__
extern void gimp_color_selector_register (void);
extern void gimp_color_selector_unregister (void);
extern void dialog_register (void);
extern void dialog_unregister (void);
static struct main_funcs_struc
{
gchar *name;