gimp/app/batch.c
Michael Natterer afd88f0bf4 replace the value union by a GValue.
2006-03-30  Michael Natterer  <mitch@gimp.org>

	* app/pdb/procedural_db.[ch] (struct Argument): replace the value
	union by a GValue.

	(procedural_db_argument_init)
	(procedural_db_compat_arg_init): new functions to initialize
	an Argument. They call g_value_init() on the Argument's value.

	(procedural_db_arguments)
	(procedural_db_return_values): initialize the returned Argument
	arrays so their GValues are ready to use. Allow to get the
	(unsuccessful) return values of a NULL ProcRecord.

	(procedural_db_destroy_args): g_value_unset() the values. Added a
	"gboolean full_destroy" parameter. Its only effect is to destroy
	PDB arrays, everything else is nicely memory managed by GValue.

	(procedural_db_execute)
	(procedural_db_run_proc): do GValue stuff. Added n_args and
	n_return_vals parameters to execute().

	(procedural_db_execute_proc): private function to execute a
	procedure. Validates the passed in arguments using the registered
	GParamSpecs before passing them to the resp. exec method.

	* app/plug-in/plug-in-params.[ch] (plug_in_params_to_args): needs
	an array of ProcArgs now in order to initialize the Arguments'
	GValues correctly. Passing NULL ProcArgs uses
	procedural_db_compat_arg_init(), so procedures (plug-ins)
	returning more values than expected work.

	(plug_in_args_to_params): do GValue stuff here too.

	(plug_in_args_destroy): removed this function,
	procedural_db_destroy_args() does the same now.

	* app/plug-in/plug-in-message.c (plug_in_handle_proc_run):
	simplified quite a bit because everything returns n_return_values
	now. Call plug_in_params_to_args() only of the procedure was found.

	(plug_in_handle_proc_return_priv): pass ProcRecs to
	plug_in_params_to_args().

	* app/batch.c
	* app/actions/plug-in-commands.c
	* app/actions/vectors-commands.c
	* app/core/gimppdbprogress.c
	* app/dialogs/about-dialog.c
	* app/file/file-open.c
	* app/file/file-save.c
	* app/plug-in/plug-ins.c
	* app/plug-in/plug-in-progress.c
	* app/plug-in/plug-in-run.[ch]
	* app/widgets/gimphelp.c
	* app/widgets/gimppdbdialog.c
	* app/xcf/xcf.c
	* tools/pdbgen/pdb/fileops.pdb: changed accordingly: don't
	g_new/g_free Argument arrays, always use procedural_db_foo()
	functions. Use GValue functions to get/set Arguments.

	* tools/pdbgen/pdb.pl: added get_value_func and set_value_func to
	all PDB types. Removed id_func, id_ret_func and check_func. Added
	flags which indicated that a type is an ID. Removed unused utility
	functions.

	* tools/pdbgen/lib.pl: use the flag instead of looking at
	functions and value types.

	* tools/pdbgen/app.pl: use the get_value_func and set_value_func
	to marshal inargs and outargs. Removed all checks performed on
	inargs because that's done by GParamSpec validation now. Added the
	missing bits to register excluded values with GimpParamSpecEnum.

	* app/pdb/*_cmds.c: regenerated.
2006-03-29 23:56:07 +00:00

168 lines
4.7 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 <stdlib.h>
#include <glib-object.h>
#include "core/core-types.h"
#include "base/base.h"
#include "core/gimp.h"
#include "batch.h"
#include "pdb/procedural_db.h"
#include "gimp-intl.h"
#define BATCH_DEFAULT_EVAL_PROC "plug-in-script-fu-eval"
static gboolean batch_exit_after_callback (Gimp *gimp,
gboolean kill_it);
static void batch_run_cmd (Gimp *gimp,
const gchar *proc_name,
ProcRecord *proc,
GimpRunMode run_mode,
const gchar *cmd);
void
batch_run (Gimp *gimp,
const gchar *batch_interpreter,
const gchar **batch_commands)
{
gulong exit_id;
if (! batch_commands || ! batch_commands[0])
return;
exit_id = g_signal_connect_after (gimp, "exit",
G_CALLBACK (batch_exit_after_callback),
NULL);
if (! batch_interpreter)
{
batch_interpreter = BATCH_DEFAULT_EVAL_PROC;
g_printerr ("No batch interpreter specified, using the default '%s'.\n",
batch_interpreter);
}
/* script-fu text console, hardcoded for backward compatibility */
if (strcmp (batch_interpreter, "plug-in-script-fu-eval") == 0 &&
strcmp (batch_commands[0], "-") == 0)
{
const gchar *proc_name = "plug-in-script-fu-text-console";
ProcRecord *proc = procedural_db_lookup (gimp, proc_name);
if (proc)
batch_run_cmd (gimp, proc_name, proc, GIMP_RUN_NONINTERACTIVE, NULL);
else
g_message (_("The batch interpreter '%s' is not available. "
"Batch mode disabled."), proc_name);
}
else
{
ProcRecord *eval_proc = procedural_db_lookup (gimp, batch_interpreter);
if (eval_proc)
{
gint i;
for (i = 0; batch_commands[i]; i++)
batch_run_cmd (gimp, batch_interpreter, eval_proc,
GIMP_RUN_NONINTERACTIVE, batch_commands[i]);
}
else
{
g_message (_("The batch interpreter '%s' is not available. "
"Batch mode disabled."), batch_interpreter);
}
}
g_signal_handler_disconnect (gimp, exit_id);
}
static gboolean
batch_exit_after_callback (Gimp *gimp,
gboolean kill_it)
{
if (gimp->be_verbose)
g_print ("EXIT: %s\n", G_STRLOC);
/* make sure that the swap file is removed before we quit */
base_exit ();
exit (EXIT_SUCCESS);
return TRUE;
}
static void
batch_run_cmd (Gimp *gimp,
const gchar *proc_name,
ProcRecord *proc,
GimpRunMode run_mode,
const gchar *cmd)
{
Argument *args;
Argument *return_vals;
gint n_return_vals;
args = procedural_db_arguments (proc);
g_value_set_int (&args[0].value, run_mode);
if (proc->num_args > 1)
g_value_set_static_string (&args[1].value, cmd);
return_vals = procedural_db_execute (gimp,
gimp_get_user_context (gimp), NULL,
proc_name,
args, proc->num_args,
&n_return_vals);
switch (g_value_get_enum (&return_vals[0].value))
{
case GIMP_PDB_EXECUTION_ERROR:
g_printerr ("batch command: experienced an execution error.\n");
break;
case GIMP_PDB_CALLING_ERROR:
g_printerr ("batch command: experienced a calling error.\n");
break;
case GIMP_PDB_SUCCESS:
g_printerr ("batch command: executed successfully.\n");
break;
}
procedural_db_destroy_args (return_vals, n_return_vals, TRUE);
procedural_db_destroy_args (args, proc->num_args, TRUE);
return;
}