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

app/plug-in/plug-in-types.h

2004-09-22  Michael Natterer  <mitch@gimp.org>

	* app/plug-in/plug-in-types.h

	* app/plug-in/plug-in.[ch]: added struct PlugInProcFrame which
	contains the ProcRecord, the proc's GMainLoop and its return
	values.

	Use the same struct for the plug-in's main proc and its
	temp_procs, so we finally have one set of return values per call
	frame, and not just one per plug-in.

	Added plug_in_proc_frame_push()/pop() and changed
	plug_in_main_loop[_quit]() accordingly.

	* app/plug-in/plug-in-message.c
	* app/plug-in/plug-in-progress.c
	* app/plug-in/plug-in-run.c: changed accordingly.
parent 6d73b203
2004-09-22 Michael Natterer <mitch@gimp.org>
* app/plug-in/plug-in-types.h
* app/plug-in/plug-in.[ch]: added struct PlugInProcFrame which
contains the ProcRecord, the proc's GMainLoop and its return
values.
Use the same struct for the plug-in's main proc and its
temp_procs, so we finally have one set of return values per call
frame, and not just one per plug-in.
Added plug_in_proc_frame_push()/pop() and changed
plug_in_main_loop[_quit]() accordingly.
* app/plug-in/plug-in-message.c
* app/plug-in/plug-in-progress.c
* app/plug-in/plug-in-run.c: changed accordingly.
2004-09-22 Sven Neumann <sven@gimp.org>
* app/text/gimptextlayout.c (gimp_text_get_pango_context):
......
......@@ -59,7 +59,8 @@ static void plug_in_handle_tile_req (PlugIn *plug_in,
static void plug_in_handle_proc_run (PlugIn *plug_in,
GPProcRun *proc_run);
static void plug_in_handle_proc_return_priv (PlugIn *plug_in,
GPProcReturn *proc_return);
GPProcReturn *proc_return,
gboolean temp_proc);
static void plug_in_handle_proc_return (PlugIn *plug_in,
GPProcReturn *proc_return);
static void plug_in_handle_temp_proc_return (PlugIn *plug_in,
......@@ -440,14 +441,22 @@ plug_in_handle_proc_run (PlugIn *plug_in,
static void
plug_in_handle_proc_return_priv (PlugIn *plug_in,
GPProcReturn *proc_return)
GPProcReturn *proc_return,
gboolean temp_proc)
{
if (plug_in->recurse_main_loop || plug_in->temp_main_loops)
PlugInProcFrame *proc_frame;
if (temp_proc)
proc_frame = plug_in->temp_proc_frames->data;
else
proc_frame = &plug_in->main_proc_frame;
if (proc_frame->main_loop)
{
plug_in->return_vals = plug_in_params_to_args (proc_return->params,
proc_return->nparams,
TRUE);
plug_in->n_return_vals = proc_return->nparams;
proc_frame->return_vals = plug_in_params_to_args (proc_return->params,
proc_return->nparams,
TRUE);
proc_frame->n_return_vals = proc_return->nparams;
}
else
{
......@@ -484,10 +493,10 @@ static void
plug_in_handle_proc_return (PlugIn *plug_in,
GPProcReturn *proc_return)
{
plug_in_handle_proc_return_priv (plug_in, proc_return);
plug_in_handle_proc_return_priv (plug_in, proc_return, FALSE);
if (plug_in->recurse_main_loop)
g_main_loop_quit (plug_in->recurse_main_loop);
if (plug_in->main_proc_frame.main_loop)
g_main_loop_quit (plug_in->main_proc_frame.main_loop);
plug_in_close (plug_in, FALSE);
}
......@@ -496,9 +505,9 @@ static void
plug_in_handle_temp_proc_return (PlugIn *plug_in,
GPProcReturn *proc_return)
{
if (plug_in->temp_main_loops)
if (plug_in->temp_proc_frames)
{
plug_in_handle_proc_return_priv (plug_in, proc_return);
plug_in_handle_proc_return_priv (plug_in, proc_return, TRUE);
plug_in_main_loop_quit (plug_in);
}
......
......@@ -202,13 +202,30 @@ static void
plug_in_progress_cancel_callback (GimpProgress *progress,
PlugIn *plug_in)
{
if (plug_in->recurse_main_loop || plug_in->temp_main_loops)
PlugInProcFrame *proc_frame = &plug_in->main_proc_frame;
GList *list;
if (proc_frame->main_loop)
{
proc_frame->return_vals = g_new (Argument, 1);
proc_frame->n_return_vals = 1;
proc_frame->return_vals->arg_type = GIMP_PDB_STATUS;
proc_frame->return_vals->value.pdb_int = GIMP_PDB_CANCEL;
}
for (list = plug_in->temp_proc_frames; list; list = g_list_next (list))
{
plug_in->return_vals = g_new (Argument, 1);
plug_in->n_return_vals = 1;
proc_frame = list->data;
if (proc_frame->main_loop)
{
proc_frame->return_vals = g_new (Argument, 1);
proc_frame->n_return_vals = 1;
plug_in->return_vals->arg_type = GIMP_PDB_STATUS;
plug_in->return_vals->value.pdb_int = GIMP_PDB_CANCEL;
proc_frame->return_vals->arg_type = GIMP_PDB_STATUS;
proc_frame->return_vals->value.pdb_int = GIMP_PDB_CANCEL;
}
}
plug_in_close (plug_in, TRUE);
......
......@@ -239,7 +239,8 @@ plug_in_new (Gimp *gimp,
ProcRecord *proc_rec,
const gchar *prog)
{
PlugIn *plug_in;
PlugIn *plug_in;
PlugInProcFrame *proc_frame;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
......@@ -253,8 +254,6 @@ plug_in_new (Gimp *gimp,
plug_in->ref_count = 1;
plug_in->proc_rec = proc_rec;
plug_in->open = FALSE;
plug_in->query = FALSE;
plug_in->init = FALSE;
......@@ -275,16 +274,19 @@ plug_in_new (Gimp *gimp,
plug_in->temp_proc_defs = NULL;
plug_in->ext_main_loop = NULL;
plug_in->recurse_main_loop = NULL;
plug_in->temp_main_loops = NULL;
plug_in->temp_proc_recs = NULL;
proc_frame = &plug_in->main_proc_frame;
plug_in->return_vals = NULL;
plug_in->n_return_vals = 0;
proc_frame->proc_rec = proc_rec;
proc_frame->main_loop = NULL;
proc_frame->return_vals = NULL;
proc_frame->n_return_vals = 0;
plug_in->temp_proc_frames = NULL;
plug_in->progress = NULL;
plug_in->progress_created = FALSE;
plug_in->progress_cancel_id = 0;
plug_in->plug_in_def = NULL;
......@@ -627,7 +629,7 @@ plug_in_close (PlugIn *plug_in,
plug_in->progress = NULL;
}
while (plug_in->temp_main_loops)
while (plug_in->temp_proc_frames)
{
#ifdef GIMP_UNSTABLE
g_printerr ("plug_in_close: plug-in aborted before sending its "
......@@ -636,14 +638,14 @@ plug_in_close (PlugIn *plug_in,
plug_in_main_loop_quit (plug_in);
}
if (plug_in->recurse_main_loop &&
g_main_loop_is_running (plug_in->recurse_main_loop))
if (plug_in->main_proc_frame.main_loop &&
g_main_loop_is_running (plug_in->main_proc_frame.main_loop))
{
#ifdef GIMP_UNSTABLE
g_printerr ("plug_in_close: plug-in aborted before sending its "
"procedure return values\n");
#endif
g_main_loop_quit (plug_in->recurse_main_loop);
g_main_loop_quit (plug_in->main_proc_frame.main_loop);
}
if (plug_in->ext_main_loop &&
......@@ -865,62 +867,94 @@ plug_in_pop (Gimp *gimp)
gimp->current_plug_in = NULL;
}
void
plug_in_proc_frame_push (PlugIn *plug_in,
ProcRecord *proc_rec)
{
PlugInProcFrame *proc_frame;
g_return_if_fail (plug_in != NULL);
g_return_if_fail (proc_rec != NULL);
proc_frame = g_new0 (PlugInProcFrame, 1);
proc_frame->proc_rec = proc_rec;
plug_in->temp_proc_frames = g_list_prepend (plug_in->temp_proc_frames,
proc_frame);
}
void
plug_in_proc_frame_pop (PlugIn *plug_in)
{
PlugInProcFrame *proc_frame;
g_return_if_fail (plug_in != NULL);
g_return_if_fail (plug_in->temp_proc_frames != NULL);
proc_frame = (PlugInProcFrame *) plug_in->temp_proc_frames->data;
plug_in->temp_proc_frames = g_list_remove (plug_in->temp_proc_frames,
proc_frame);
g_free (proc_frame);
}
void
plug_in_main_loop (PlugIn *plug_in)
{
GMainLoop *main_loop;
PlugInProcFrame *proc_frame;
g_return_if_fail (plug_in != NULL);
g_return_if_fail (plug_in->temp_proc_frames != NULL);
proc_frame = (PlugInProcFrame *) plug_in->temp_proc_frames->data;
main_loop = g_main_loop_new (NULL, FALSE);
g_return_if_fail (proc_frame->main_loop == NULL);
plug_in->temp_main_loops = g_list_prepend (plug_in->temp_main_loops,
main_loop);
proc_frame->main_loop = g_main_loop_new (NULL, FALSE);
gimp_threads_leave (plug_in->gimp);
g_main_loop_run (main_loop);
g_main_loop_run (proc_frame->main_loop);
gimp_threads_enter (plug_in->gimp);
g_main_loop_unref (main_loop);
g_main_loop_unref (proc_frame->main_loop);
proc_frame->main_loop = NULL;
}
void
plug_in_main_loop_quit (PlugIn *plug_in)
{
GMainLoop *main_loop;
PlugInProcFrame *proc_frame;
g_return_if_fail (plug_in != NULL);
g_return_if_fail (plug_in->temp_proc_frames != NULL);
if (! plug_in->temp_main_loops)
{
g_warning ("%s: called without a temp main loop running", G_STRFUNC);
return;
}
proc_frame = (PlugInProcFrame *) plug_in->temp_proc_frames->data;
main_loop = (GMainLoop *) plug_in->temp_main_loops->data;
g_return_if_fail (proc_frame->main_loop != NULL);
g_main_loop_quit (main_loop);
proc_frame = (PlugInProcFrame *) plug_in->temp_proc_frames->data;
plug_in->temp_main_loops = g_list_remove (plug_in->temp_main_loops,
main_loop);
g_main_loop_quit (proc_frame->main_loop);
}
gchar *
plug_in_get_undo_desc (PlugIn *plug_in)
{
PlugInProcDef *proc_def;
gchar *undo_desc = NULL;
PlugInProcFrame *proc_frame = NULL;
PlugInProcDef *proc_def = NULL;
gchar *undo_desc = NULL;
g_return_val_if_fail (plug_in != NULL, NULL);
if (plug_in->temp_proc_recs)
proc_def = plug_ins_proc_def_find (plug_in->gimp,
plug_in->temp_proc_recs->data);
else if (plug_in->proc_rec)
proc_def = plug_ins_proc_def_find (plug_in->gimp,
plug_in->proc_rec);
if (plug_in->temp_proc_frames)
proc_frame = plug_in->temp_proc_frames->data;
else
proc_def = NULL;
proc_frame = &plug_in->main_proc_frame;
if (proc_frame)
proc_def = plug_ins_proc_def_find (plug_in->gimp, proc_frame->proc_rec);
if (proc_def)
{
......
......@@ -26,6 +26,14 @@
#define WRITE_BUFFER_SIZE 512
struct _PlugInProcFrame
{
ProcRecord *proc_rec;
GMainLoop *main_loop;
Argument *return_vals;
gint n_return_vals;
};
struct _PlugIn
{
Gimp *gimp;
......@@ -33,8 +41,6 @@ struct _PlugIn
gint ref_count;
ProcRecord *proc_rec; /* The procedure the plug-in is running */
guint open : 1; /* Is the plug-in open? */
guint query : 1; /* Are we querying the plug-in? */
guint init : 1; /* Are we initialing the plug-in? */
......@@ -58,13 +64,10 @@ struct _PlugIn
GSList *temp_proc_defs; /* Temporary procedures */
GMainLoop *ext_main_loop; /* for waiting for extension_ack */
GMainLoop *recurse_main_loop;/* for waiting for proc_return */
GList *temp_main_loops; /* for waiting for temp_proc_returns */
GList *temp_proc_recs; /* The temp procs the plug-in is busy with */
PlugInProcFrame main_proc_frame;
Argument *return_vals; /* The return value we wait for */
gint n_return_vals;
GList *temp_proc_frames;
GimpProgress *progress; /* Progress dialog */
gboolean progress_created; /* Was the progress created by the plug-in */
......@@ -74,36 +77,40 @@ struct _PlugIn
};
void plug_in_init (Gimp *gimp);
void plug_in_exit (Gimp *gimp);
void plug_in_init (Gimp *gimp);
void plug_in_exit (Gimp *gimp);
void plug_in_call_query (Gimp *gimp,
GimpContext *context,
PlugInDef *plug_in_def);
void plug_in_call_init (Gimp *gimp,
GimpContext *context,
PlugInDef *plug_in_def);
void plug_in_call_query (Gimp *gimp,
GimpContext *context,
PlugInDef *plug_in_def);
void plug_in_call_init (Gimp *gimp,
GimpContext *context,
PlugInDef *plug_in_def);
PlugIn * plug_in_new (Gimp *gimp,
GimpContext *context,
ProcRecord *proc_rec,
const gchar *prog);
PlugIn * plug_in_new (Gimp *gimp,
GimpContext *context,
ProcRecord *proc_rec,
const gchar *prog);
void plug_in_ref (PlugIn *plug_in);
void plug_in_unref (PlugIn *plug_in);
void plug_in_ref (PlugIn *plug_in);
void plug_in_unref (PlugIn *plug_in);
gboolean plug_in_open (PlugIn *plug_in);
void plug_in_close (PlugIn *plug_in,
gboolean kill_it);
gboolean plug_in_open (PlugIn *plug_in);
void plug_in_close (PlugIn *plug_in,
gboolean kill_it);
void plug_in_push (Gimp *gimp,
PlugIn *plug_in);
void plug_in_pop (Gimp *gimp);
void plug_in_push (Gimp *gimp,
PlugIn *plug_in);
void plug_in_pop (Gimp *gimp);
void plug_in_proc_frame_push (PlugIn *plug_in,
ProcRecord *proc_rec);
void plug_in_proc_frame_pop (PlugIn *plug_in);
void plug_in_main_loop (PlugIn *plug_in);
void plug_in_main_loop_quit (PlugIn *plug_in);
void plug_in_main_loop (PlugIn *plug_in);
void plug_in_main_loop_quit (PlugIn *plug_in);
gchar * plug_in_get_undo_desc (PlugIn *plug_in);
gchar * plug_in_get_undo_desc (PlugIn *plug_in);
#endif /* __PLUG_IN_H__ */
......@@ -49,12 +49,12 @@
/* local function prototypes */
static Argument * plug_in_temp_run (ProcRecord *proc_rec,
GimpProgress *progress,
Argument *args,
gint argc);
static Argument * plug_in_get_return_vals (PlugIn *plug_in,
ProcRecord *proc_rec);
static Argument * plug_in_temp_run (ProcRecord *proc_rec,
GimpProgress *progress,
Argument *args,
gint argc);
static Argument * plug_in_get_return_vals (PlugIn *plug_in,
PlugInProcFrame *proc_frame);
/* public functions */
......@@ -165,16 +165,17 @@ plug_in_run (Gimp *gimp,
*/
if (synchronous)
{
plug_in->recurse_main_loop = g_main_loop_new (NULL, FALSE);
plug_in->main_proc_frame.main_loop = g_main_loop_new (NULL, FALSE);
gimp_threads_leave (gimp);
g_main_loop_run (plug_in->recurse_main_loop);
g_main_loop_run (plug_in->main_proc_frame.main_loop);
gimp_threads_enter (gimp);
g_main_loop_unref (plug_in->recurse_main_loop);
plug_in->recurse_main_loop = NULL;
g_main_loop_unref (plug_in->main_proc_frame.main_loop);
plug_in->main_proc_frame.main_loop = NULL;
return_vals = plug_in_get_return_vals (plug_in, proc_rec);
return_vals = plug_in_get_return_vals (plug_in,
&plug_in->main_proc_frame);
}
plug_in_unref (plug_in);
......@@ -247,8 +248,7 @@ plug_in_temp_run (ProcRecord *proc_rec,
{
GPProcRun proc_run;
plug_in->temp_proc_recs = g_list_prepend (plug_in->temp_proc_recs,
proc_rec);
plug_in_proc_frame_push (plug_in, proc_rec);
proc_run.name = proc_rec->name;
proc_run.nparams = argc;
......@@ -259,8 +259,7 @@ plug_in_temp_run (ProcRecord *proc_rec,
{
return_vals = procedural_db_return_args (proc_rec, FALSE);
plug_in->temp_proc_recs = g_list_remove (plug_in->temp_proc_recs,
proc_rec);
plug_in_proc_frame_pop (plug_in);
goto done;
}
......@@ -271,10 +270,10 @@ plug_in_temp_run (ProcRecord *proc_rec,
plug_in_main_loop (plug_in);
return_vals = plug_in_get_return_vals (plug_in, proc_rec);
return_vals = plug_in_get_return_vals (plug_in,
plug_in->temp_proc_frames->data);
plug_in->temp_proc_recs = g_list_remove (plug_in->temp_proc_recs,
proc_rec);
plug_in_proc_frame_pop (plug_in);
plug_in_unref (plug_in);
}
......@@ -284,46 +283,46 @@ plug_in_temp_run (ProcRecord *proc_rec,
}
static Argument *
plug_in_get_return_vals (PlugIn *plug_in,
ProcRecord *proc_rec)
plug_in_get_return_vals (PlugIn *plug_in,
PlugInProcFrame *proc_frame)
{
Argument *return_vals;
gint nargs;
g_return_val_if_fail (plug_in != NULL, NULL);
g_return_val_if_fail (proc_rec != NULL, NULL);
g_return_val_if_fail (proc_frame != NULL, NULL);
/* Return the status code plus the current return values. */
nargs = proc_rec->num_values + 1;
nargs = proc_frame->proc_rec->num_values + 1;
if (plug_in->return_vals && plug_in->n_return_vals == nargs)
if (proc_frame->return_vals && proc_frame->n_return_vals == nargs)
{
return_vals = plug_in->return_vals;
return_vals = proc_frame->return_vals;
}
else if (plug_in->return_vals)
else if (proc_frame->return_vals)
{
/* Allocate new return values of the correct size. */
return_vals = procedural_db_return_args (proc_rec, FALSE);
return_vals = procedural_db_return_args (proc_frame->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));
memcpy (return_vals, proc_frame->return_vals,
sizeof (Argument) * MIN (proc_frame->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);
g_free (proc_frame->return_vals);
}
else
{
/* Just return a dummy set of values. */
return_vals = procedural_db_return_args (proc_rec, FALSE);
return_vals = procedural_db_return_args (proc_frame->proc_rec, FALSE);
}
/* We have consumed any saved values, so clear them. */
plug_in->return_vals = NULL;
plug_in->n_return_vals = 0;
proc_frame->return_vals = NULL;
proc_frame->n_return_vals = 0;
return return_vals;
}
......@@ -49,12 +49,12 @@
/* local function prototypes */
static Argument * plug_in_temp_run (ProcRecord *proc_rec,
GimpProgress *progress,
Argument *args,
gint argc);
static Argument * plug_in_get_return_vals (PlugIn *plug_in,
ProcRecord *proc_rec);
static Argument * plug_in_temp_run (ProcRecord *proc_rec,
GimpProgress *progress,
Argument *args,
gint argc);
static Argument * plug_in_get_return_vals (PlugIn *plug_in,
PlugInProcFrame *proc_frame);
/* public functions */
......@@ -165,16 +165,17 @@ plug_in_run (Gimp *gimp,
*/
if (synchronous)
{
plug_in->recurse_main_loop = g_main_loop_new (NULL, FALSE);
plug_in->main_proc_frame.main_loop = g_main_loop_new (NULL, FALSE);
gimp_threads_leave (gimp);
g_main_loop_run (plug_in->recurse_main_loop);
g_main_loop_run (plug_in->main_proc_frame.main_loop);
gimp_threads_enter (gimp);
g_main_loop_unref (plug_in->recurse_main_loop);
plug_in->recurse_main_loop = NULL;
g_main_loop_unref (plug_in->main_proc_frame.main_loop);
plug_in->main_proc_frame.main_loop = NULL;
return_vals = plug_in_get_return_vals (plug_in, proc_rec);
return_vals = plug_in_get_return_vals (plug_in,
&plug_in->main_proc_frame);
}
plug_in_unref (plug_in);
......@@ -247,8 +248,7 @@ plug_in_temp_run (ProcRecord *proc_rec,
{
GPProcRun proc_run;
plug_in->temp_proc_recs = g_list_prepend (plug_in->temp_proc_recs,
proc_rec);
plug_in_proc_frame_push (plug_in, proc_rec);
proc_run.name = proc_rec->name;
proc_run.nparams = argc;
......@@ -259,8 +259,7 @@ plug_in_temp_run (ProcRecord *proc_rec,
{
return_vals = procedural_db_return_args (proc_rec, FALSE);
plug_in->temp_proc_recs = g_list_remove (plug_in->temp_proc_recs,
proc_rec);
plug_in_proc_frame_pop (plug_in);
goto done;
}
......@@ -271,10 +270,10 @@ plug_in_temp_run (ProcRecord *proc_rec,
plug_in_main_loop (plug_in);