gimp/app/plug-in/plug-in-run.c
Michael Natterer ecb0b58439 Changed the semantics of GIMP_EXTENSION and (to some extent) of
2003-06-19  Michael Natterer  <mitch@gimp.org>

	Changed the semantics of GIMP_EXTENSION and (to some extent)
	of GIMP_PLUGIN:

	The old meaning of EXTENSION was "I live in the toolbox" and
	PLUGIN meant "I take RUN-MODE,IMAGE,DRAWABLE args (but only if I
	am invoked interactively)". This is completely useless, since
	living in the toolbox means having "<Toolbox>" in the menu_path
	and taking RUN-MODE,IMAGE,DRAWABLE means just that, regardless of
	what type of procedure we are.

	The new meaning of GIMP_PLUGIN is just "I am an ordinary procedure,
	I am invoked, do my job and finish", while GIMP_EXTENSION means
	"I will install temporary procedures and I will keep running to
	keep them available".

	(A GIMP_EXTENSION *must* call gimp_extension_ack() now to tell the
	core that it's ready to run, or the core will block waiting for
	the message !!!).

	* configure.in: bumped version number to 1.3.16.

	* libgimpbase/gimpprotocol.h: increased protocol version number so
	old extensions will refuse to load.

	* app/gui/plug-in-commands.c (plug_in_run_cmd_callback): don't
	blindly pass RUN-MODE,IMAGE,DRAWABLE to GIMP_PLUGIN procedures but
	look at their parameters and pass them either RUN-MODE, or
	RUN-MODE,IMAGE, or RUN-MODE,IMAGE,DRAWABLE.

	* app/pdb/procedural_db.c: cleaned up, better error reporting,
	replaced an impossible error message by g_return_if_fail()

	* app/plug-in/plug-in-message.c (plug_in_handle_proc_install):
	better error messages.

	* app/plug-in/plug-in-params.c: allocate parameter arrays using
	g_new0() so we don't have to worry about uninitialized stuff
	later.

	* app/plug-in/plug-in-run.c (plug_in_run): wait for
	gimp_extension_ack() installation confirmation for ALL extensions,
	not just for automatically started ones.

	* app/plug-in/plug-ins.c: cleanup.

	* libgimp/gimp.[ch]: cleaned up and API-documented massively. Made
	all magic values given in the GPConfig message static and added
	accessor functions for them. Added gimp_tile_width()/height().
	Added new function gimp_extension_enable() which turns on
	asynchronous processing of temp_proc run requests without having
	to enter an endless gimp_extension_process() loop. Moved all
	private functions to the end of the file. Added tons of
	g_return_if_fail() all over the place.  Call gimp_run_procedure2()
	from gimp_run_procedure() instead of duplicating the
	code. Indentation, spacing, stuff...

	* libgimp/gimptile.[ch]: removed gimp_tile_width()/height().

	* libgimp/gimpdrawable.c
	* libgimp/gimppixelrgn.c
	* libgimp/gimptile.c: use the gimp_tile_width()/height() accessor
	functions.

	* libgimp/gimp.def: added gimp_extension_enable.

	* libgimp/gimpmenu.c: removed evil code which connected to
	_readchannel manually and use gimp_extension_enable() for watching
	temp_procs.

	* plug-ins/helpbrowser/helpbrowser.c: removed the same evil code
	here and call gimp_extension_enable(). Call gimp_extension_ack()
	to let the core know that the temp_proc is installed.

	* plug-ins/script-fu/script-fu.c: made all procedures except the
	permanently running "extension_script_fu" ordinary GIMP_PLUGIN
	procedures.

	* plug-ins/common/curve_bend.c
	* plug-ins/common/plugindetails.c
	* plug-ins/common/screenshot.c
	* plug-ins/common/uniteditor.c
	* plug-ins/common/winclipboard.c
	* plug-ins/dbbrowser/dbbrowser.c
	* plug-ins/gfli/gfli.c
	* plug-ins/twain/twain.c
	* plug-ins/webbrowser/webbrowser.c
	* plug-ins/winsnap/winsnap.c: made them all ordinary GIMP_PLUGIN
	procedures and renamed them from "extension_*" to "plug_in_*".
	Random cleanups.

	* app/widgets/gimphelp.c
	* plug-ins/maze/maze_face.c: call "plug_in_web_browser" now.
2003-06-19 17:12:00 +00:00

302 lines
7.9 KiB
C

/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <string.h>
#include <glib-object.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpbase/gimpprotocol.h"
#include "libgimpbase/gimpwire.h"
#include "plug-in-types.h"
#include "config/gimpguiconfig.h"
#include "base/tile.h"
#include "core/gimp.h"
#include "pdb/procedural_db.h"
#include "plug-in.h"
#include "plug-in-params.h"
#include "plug-in-run.h"
#include "plug-in-shm.h"
#include "gimp-intl.h"
/* local function prototypes */
static Argument * plug_in_temp_run (ProcRecord *proc_rec,
Argument *args,
gint argc);
static Argument * plug_in_get_return_vals (PlugIn *plug_in,
ProcRecord *proc_rec);
/* public functions */
Argument *
plug_in_run (Gimp *gimp,
ProcRecord *proc_rec,
Argument *args,
gint argc,
gboolean synchronous,
gboolean destroy_return_vals,
gint gdisp_ID)
{
Argument *return_vals = NULL;
PlugIn *plug_in;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (proc_rec != NULL, NULL);
g_return_val_if_fail (argc == 0 || args != NULL, NULL);
g_return_val_if_fail (proc_rec->proc_type != GIMP_EXTENSION ||
synchronous == FALSE, NULL);
if (proc_rec->proc_type == GIMP_TEMPORARY)
{
return_vals = plug_in_temp_run (proc_rec, args, argc);
goto done;
}
plug_in = plug_in_new (gimp, proc_rec,
proc_rec->exec_method.plug_in.filename);
if (plug_in)
{
GPConfig config;
GPProcRun proc_run;
if (! plug_in_open (plug_in))
{
plug_in_unref (plug_in);
goto done;
}
plug_in->recurse = synchronous;
config.version = GP_VERSION;
config.tile_width = TILE_WIDTH;
config.tile_height = TILE_HEIGHT;
config.shm_ID = plug_in_shm_get_ID (gimp);
config.gamma = gimp->config->gamma_val;
config.install_cmap = gimp->config->install_cmap;
config.show_tool_tips = GIMP_GUI_CONFIG (gimp->config)->show_tool_tips;
config.min_colors = CLAMP (gimp->config->min_colors, 27, 256);
config.gdisp_ID = gdisp_ID;
proc_run.name = proc_rec->name;
proc_run.nparams = argc;
proc_run.params = plug_in_args_to_params (args, argc, FALSE);
if (! gp_config_write (plug_in->my_write, &config, plug_in) ||
! gp_proc_run_write (plug_in->my_write, &proc_run, plug_in) ||
! wire_flush (plug_in->my_write, plug_in))
{
return_vals = procedural_db_return_args (proc_rec, FALSE);
goto done;
}
plug_in_params_destroy (proc_run.params, proc_run.nparams, FALSE);
plug_in_ref (plug_in);
/* If this is an extension,
* wait for an installation-confirmation message
*/
if (proc_rec->proc_type == GIMP_EXTENSION)
{
plug_in->starting_ext = TRUE;
plug_in_main_loop (plug_in);
plug_in->starting_ext = FALSE;
}
/* If this plug-in is requested to run synchronously,
* wait for its return values
*/
if (plug_in->recurse)
{
plug_in_main_loop (plug_in);
return_vals = plug_in_get_return_vals (plug_in, proc_rec);
}
plug_in_unref (plug_in);
}
done:
if (return_vals && destroy_return_vals)
{
procedural_db_destroy_args (return_vals, proc_rec->num_values);
return_vals = NULL;
}
return return_vals;
}
void
plug_in_repeat (Gimp *gimp,
gint display_ID,
gint image_ID,
gint drawable_ID,
gboolean with_interface)
{
Argument *args;
gint i;
g_return_if_fail (GIMP_IS_GIMP (gimp));
if (gimp->last_plug_in)
{
/* construct the procedures arguments */
args = g_new (Argument, 3);
/* initialize the first three argument types */
for (i = 0; i < 3; i++)
args[i].arg_type = gimp->last_plug_in->args[i].arg_type;
/* initialize the first three plug-in arguments */
args[0].value.pdb_int = (with_interface ?
GIMP_RUN_INTERACTIVE : GIMP_RUN_WITH_LAST_VALS);
args[1].value.pdb_int = image_ID;
args[2].value.pdb_int = drawable_ID;
/* run the plug-in procedure */
plug_in_run (gimp, gimp->last_plug_in, args, 3, FALSE, TRUE, display_ID);
g_free (args);
}
}
/* private functions */
static Argument *
plug_in_temp_run (ProcRecord *proc_rec,
Argument *args,
gint argc)
{
Argument *return_vals = NULL;
PlugIn *plug_in;
plug_in = (PlugIn *) proc_rec->exec_method.temporary.plug_in;
if (plug_in)
{
GPProcRun proc_run;
gboolean old_recurse;
if (plug_in->current_temp_proc)
{
return_vals = procedural_db_return_args (proc_rec, FALSE);
goto done;
}
plug_in->current_temp_proc = proc_rec;
proc_run.name = proc_rec->name;
proc_run.nparams = argc;
proc_run.params = plug_in_args_to_params (args, argc, FALSE);
if (! gp_temp_proc_run_write (plug_in->my_write, &proc_run, plug_in) ||
! wire_flush (plug_in->my_write, plug_in))
{
return_vals = procedural_db_return_args (proc_rec, FALSE);
goto done;
}
plug_in_params_destroy (proc_run.params, proc_run.nparams, FALSE);
old_recurse = plug_in->recurse;
plug_in->recurse = TRUE;
#ifdef ENABLE_TEMP_RETURN
plug_in_ref (plug_in);
plug_in_main_loop (plug_in);
return_vals = plug_in_get_return_vals (proc_rec);
#else
return_vals = procedural_db_return_args (proc_rec, TRUE);
#endif
plug_in->recurse = old_recurse;
plug_in->current_temp_proc = NULL;
#ifdef ENABLE_TEMP_RETURN
plug_in_unref (plug_in);
#endif
}
done:
return return_vals;
}
static Argument *
plug_in_get_return_vals (PlugIn *plug_in,
ProcRecord *proc_rec)
{
Argument *return_vals;
gint nargs;
g_return_val_if_fail (plug_in != NULL, NULL);
g_return_val_if_fail (proc_rec != NULL, NULL);
/* Return the status code plus the current return values. */
nargs = proc_rec->num_values + 1;
if (plug_in->return_vals && plug_in->n_return_vals == nargs)
{
return_vals = plug_in->return_vals;
}
else if (plug_in->return_vals)
{
/* Allocate new return values of the correct size. */
return_vals = procedural_db_return_args (proc_rec, FALSE);
/* Copy all of the arguments we can. */
memcpy (return_vals, plug_in->return_vals,
sizeof (Argument) * MIN (plug_in->n_return_vals, nargs));
/* Free the old argument pointer. This will cause a memory leak
* only if there were more values returned than we need (which
* shouldn't ever happen).
*/
g_free (plug_in->return_vals);
}
else
{
/* Just return a dummy set of values. */
return_vals = procedural_db_return_args (proc_rec, FALSE);
}
/* We have consumed any saved values, so clear them. */
plug_in->return_vals = NULL;
plug_in->n_return_vals = 0;
return return_vals;
}