[gimp] libgimp: add _gimp_plug_in_run() and copy the main plug-in loop to GimpPlugIn
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] libgimp: add _gimp_plug_in_run() and copy the main plug-in loop to GimpPlugIn
- Date: Fri, 2 Aug 2019 15:07:26 +0000 (UTC)
commit 856fe160708aa1b19d6ee10e5c712460d8efff04
Author: Michael Natterer <mitch gimp org>
Date: Fri Aug 2 17:04:24 2019 +0200
libgimp: add _gimp_plug_in_run() and copy the main plug-in loop to GimpPlugIn
Move the legacy loop code to gimplegacy.c. Also remove some more stuff
from gimp.c, old and new are now completely separate apart from one
glitch which wll go next...
libgimp/gimp-private.h | 9 ++-
libgimp/gimp.c | 169 ++++---------------------------------------
libgimp/gimplegacy.c | 156 +++++++++++++++++++++++++++++++--------
libgimp/gimpplugin-private.c | 146 +++++++++++++++++++++++++++++++------
libgimp/gimpplugin-private.h | 1 +
libgimp/gimpplugin.h | 1 +
6 files changed, 270 insertions(+), 212 deletions(-)
---
diff --git a/libgimp/gimp-private.h b/libgimp/gimp-private.h
index 89fbb88d09..12d8f387db 100644
--- a/libgimp/gimp-private.h
+++ b/libgimp/gimp-private.h
@@ -29,12 +29,13 @@ G_BEGIN_DECLS
extern GIOChannel *_gimp_readchannel;
extern GIOChannel *_gimp_writechannel;
-extern GHashTable *_gimp_temp_proc_ht;
-void _gimp_config (GPConfig *config);
-void _gimp_read_expect_msg (GimpWireMessage *msg,
- gint type);
+void _gimp_close (void);
+void _gimp_config (GPConfig *config);
+void _gimp_loop (GimpRunProc run_proc);
+void _gimp_read_expect_msg (GimpWireMessage *msg,
+ gint type);
G_END_DECLS
diff --git a/libgimp/gimp.c b/libgimp/gimp.c
index 77a264e7a7..51493f36bf 100644
--- a/libgimp/gimp.c
+++ b/libgimp/gimp.c
@@ -151,7 +151,6 @@ static gint gimp_main_internal (GType plug_in_ty
gint argc,
gchar *argv[]);
-static void gimp_close (void);
static void gimp_debug_stop (void);
static void gimp_message_func (const gchar *log_domain,
GLogLevelFlags log_level,
@@ -177,15 +176,10 @@ static gboolean gimp_write (GIOChannel *channel,
gpointer user_data);
static gboolean gimp_flush (GIOChannel *channel,
gpointer user_data);
-static void gimp_loop (void);
-static void gimp_proc_run (GPProcRun *proc_run);
-static void gimp_proc_run_internal (GPProcRun *proc_run,
- GimpProcedure *procedure,
- GimpRunProc run_proc,
- GPProcReturn *proc_return);
static void gimp_set_pdb_error (GimpValueArray *return_vals);
+
#if defined G_OS_WIN32 && defined HAVE_EXCHNDL
static LPTOP_LEVEL_EXCEPTION_FILTER _prevExceptionFilter = NULL;
static gchar *plug_in_backtrace_path = NULL;
@@ -222,8 +216,6 @@ static gulong write_buffer_index = 0;
static GimpStackTraceMode stack_trace_mode = GIMP_STACK_TRACE_NEVER;
-GHashTable *_gimp_temp_proc_ht = NULL;
-
static guint gimp_debug_flags = 0;
static const GDebugKey gimp_debug_keys[] =
@@ -743,7 +735,7 @@ gimp_main_internal (GType plug_in_type,
PLUG_IN_INFO.query_proc ();
}
- gimp_close ();
+ _gimp_close ();
return EXIT_SUCCESS;
}
@@ -763,7 +755,7 @@ gimp_main_internal (GType plug_in_type,
PLUG_IN_INFO.init_proc ();
}
- gimp_close ();
+ _gimp_close ();
return EXIT_SUCCESS;
}
@@ -773,14 +765,19 @@ gimp_main_internal (GType plug_in_type,
else if (gimp_debug_flags & GIMP_DEBUG_PID)
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Here I am!");
- _gimp_temp_proc_ht = g_hash_table_new (g_str_hash, g_str_equal);
-
g_io_add_watch (_gimp_readchannel,
G_IO_ERR | G_IO_HUP,
gimp_plugin_io_error_handler,
NULL);
- gimp_loop ();
+ if (PLUG_IN)
+ {
+ _gimp_plug_in_run (PLUG_IN);
+ }
+ else
+ {
+ _gimp_loop (PLUG_IN_INFO.run_proc);
+ }
return EXIT_SUCCESS;
}
@@ -794,7 +791,7 @@ gimp_main_internal (GType plug_in_type,
void
gimp_quit (void)
{
- gimp_close ();
+ _gimp_close ();
#if defined G_OS_WIN32 && defined HAVE_EXCHNDL
if (plug_in_backtrace_path)
@@ -1199,8 +1196,8 @@ gimp_get_progname (void)
/* private functions */
-static void
-gimp_close (void)
+void
+_gimp_close (void)
{
if (gimp_debug_flags & GIMP_DEBUG_QUIT)
gimp_debug_stop ();
@@ -1547,67 +1544,6 @@ gimp_flush (GIOChannel *channel,
return TRUE;
}
-static void
-gimp_loop (void)
-{
- GimpWireMessage msg;
-
- while (TRUE)
- {
- if (! gimp_wire_read_msg (_gimp_readchannel, &msg, NULL))
- {
- gimp_close ();
- return;
- }
-
- switch (msg.type)
- {
- case GP_QUIT:
- gimp_wire_destroy (&msg);
- gimp_close ();
- return;
-
- case GP_CONFIG:
- _gimp_config (msg.data);
- break;
-
- case GP_TILE_REQ:
- case GP_TILE_ACK:
- case GP_TILE_DATA:
- g_warning ("unexpected tile message received (should not happen)");
- break;
-
- case GP_PROC_RUN:
- gimp_proc_run (msg.data);
- gimp_wire_destroy (&msg);
- gimp_close ();
- return;
-
- case GP_PROC_RETURN:
- g_warning ("unexpected proc return message received (should not happen)");
- break;
-
- case GP_TEMP_PROC_RUN:
- g_warning ("unexpected temp proc run message received (should not happen");
- break;
-
- case GP_TEMP_PROC_RETURN:
- g_warning ("unexpected temp proc return message received (should not happen");
- break;
-
- case GP_PROC_INSTALL:
- g_warning ("unexpected proc install message received (should not happen)");
- break;
-
- case GP_HAS_INIT:
- g_warning ("unexpected has init message received (should not happen)");
- break;
- }
-
- gimp_wire_destroy (&msg);
- }
-}
-
void
_gimp_config (GPConfig *config)
{
@@ -1735,83 +1671,6 @@ _gimp_config (GPConfig *config)
}
}
-static void
-gimp_proc_run (GPProcRun *proc_run)
-{
- GPProcReturn proc_return;
-
- if (PLUG_IN)
- {
- GimpProcedure *procedure;
-
- procedure = gimp_plug_in_create_procedure (PLUG_IN, proc_run->name);
-
- if (procedure)
- {
- gimp_proc_run_internal (proc_run, procedure, NULL,
- &proc_return);
-
- g_object_unref (procedure);
- }
- }
- else if (PLUG_IN_INFO.run_proc)
- {
- gimp_proc_run_internal (proc_run, NULL, PLUG_IN_INFO.run_proc,
- &proc_return);
- }
-
- if (! gp_proc_return_write (_gimp_writechannel, &proc_return, NULL))
- gimp_quit ();
-}
-
-static void
-gimp_proc_run_internal (GPProcRun *proc_run,
- GimpProcedure *procedure,
- GimpRunProc run_proc,
- GPProcReturn *proc_return)
-{
- GimpValueArray *arguments;
- GimpValueArray *return_values = NULL;
-
- arguments = _gimp_gp_params_to_value_array (NULL, 0,
- proc_run->params,
- proc_run->nparams,
- FALSE, FALSE);
-
- if (procedure)
- {
- return_values = gimp_procedure_run (procedure, arguments);
- }
- else
- {
- GimpParam *params;
- GimpParam *return_vals;
- gint n_params;
- gint n_return_vals;
-
- n_params = gimp_value_array_length (arguments);
- params = _gimp_value_array_to_params (arguments, FALSE);
-
- run_proc (proc_run->name,
- n_params, params,
- &n_return_vals, &return_vals);
-
- return_values = _gimp_params_to_value_array (return_vals,
- n_return_vals,
- FALSE);
-
- g_free (params);
- }
-
- gimp_value_array_unref (arguments);
-
- proc_return->name = proc_run->name;
- proc_return->nparams = gimp_value_array_length (return_values);
- proc_return->params = _gimp_value_array_to_gp_params (return_values, TRUE);
-
- gimp_value_array_unref (return_values);
-}
-
static void
gimp_set_pdb_error (GimpValueArray *return_values)
{
diff --git a/libgimp/gimplegacy.c b/libgimp/gimplegacy.c
index 68f750e0d5..6b0c8e56be 100644
--- a/libgimp/gimplegacy.c
+++ b/libgimp/gimplegacy.c
@@ -53,7 +53,15 @@ static void gimp_single_message (void);
static gboolean gimp_extension_read (GIOChannel *channel,
GIOCondition condition,
gpointer data);
+static void gimp_proc_run (GPProcRun *proc_run,
+ GimpRunProc run_proc);
static void gimp_temp_proc_run (GPProcRun *proc_run);
+static void gimp_proc_run_internal (GPProcRun *proc_run,
+ GimpRunProc run_proc,
+ GPProcReturn *proc_return);
+
+
+static GHashTable *gimp_temp_proc_ht = NULL;
/**
@@ -418,7 +426,7 @@ gimp_install_temp_proc (const gchar *name,
params, return_vals);
/* Insert the temp proc run function into the hash table */
- g_hash_table_insert (_gimp_temp_proc_ht, g_strdup (name),
+ g_hash_table_insert (gimp_temp_proc_ht, g_strdup (name),
(gpointer) run_proc);
}
@@ -443,11 +451,11 @@ gimp_uninstall_temp_proc (const gchar *name)
if (! gp_proc_uninstall_write (_gimp_writechannel, &proc_uninstall, NULL))
gimp_quit ();
- found = g_hash_table_lookup_extended (_gimp_temp_proc_ht, name, &hash_name,
+ found = g_hash_table_lookup_extended (gimp_temp_proc_ht, name, &hash_name,
NULL);
if (found)
{
- g_hash_table_remove (_gimp_temp_proc_ht, (gpointer) name);
+ g_hash_table_remove (gimp_temp_proc_ht, (gpointer) name);
g_free (hash_name);
}
}
@@ -963,6 +971,69 @@ gimp_destroy_paramdefs (GimpParamDef *paramdefs,
g_free (paramdefs);
}
+void
+_gimp_loop (GimpRunProc run_proc)
+{
+ GimpWireMessage msg;
+
+ gimp_temp_proc_ht = g_hash_table_new (g_str_hash, g_str_equal);
+
+ while (TRUE)
+ {
+ if (! gimp_wire_read_msg (_gimp_readchannel, &msg, NULL))
+ {
+ _gimp_close ();
+ return;
+ }
+
+ switch (msg.type)
+ {
+ case GP_QUIT:
+ gimp_wire_destroy (&msg);
+ _gimp_close ();
+ return;
+
+ case GP_CONFIG:
+ _gimp_config (msg.data);
+ break;
+
+ case GP_TILE_REQ:
+ case GP_TILE_ACK:
+ case GP_TILE_DATA:
+ g_warning ("unexpected tile message received (should not happen)");
+ break;
+
+ case GP_PROC_RUN:
+ gimp_proc_run (msg.data, run_proc);
+ gimp_wire_destroy (&msg);
+ _gimp_close ();
+ return;
+
+ case GP_PROC_RETURN:
+ g_warning ("unexpected proc return message received (should not happen)");
+ break;
+
+ case GP_TEMP_PROC_RUN:
+ g_warning ("unexpected temp proc run message received (should not happen");
+ break;
+
+ case GP_TEMP_PROC_RETURN:
+ g_warning ("unexpected temp proc return message received (should not happen");
+ break;
+
+ case GP_PROC_INSTALL:
+ g_warning ("unexpected proc install message received (should not happen)");
+ break;
+
+ case GP_HAS_INIT:
+ g_warning ("unexpected has init message received (should not happen)");
+ break;
+ }
+
+ gimp_wire_destroy (&msg);
+ }
+}
+
/* Define boxed type functions. */
static gpointer
@@ -1251,22 +1322,27 @@ gimp_extension_read (GIOChannel *channel,
return TRUE;
}
+static void
+gimp_proc_run (GPProcRun *proc_run,
+ GimpRunProc run_proc)
+{
+ GPProcReturn proc_return;
+
+ gimp_proc_run_internal (proc_run, run_proc, &proc_return);
+
+ if (! gp_proc_return_write (_gimp_writechannel, &proc_return, NULL))
+ gimp_quit ();
+}
+
static void
gimp_temp_proc_run (GPProcRun *proc_run)
{
GPProcReturn proc_return;
- GimpRunProc run_proc = g_hash_table_lookup (_gimp_temp_proc_ht,
+ GimpRunProc run_proc = g_hash_table_lookup (gimp_temp_proc_ht,
proc_run->name);
if (run_proc)
{
- GimpValueArray *arguments;
- GimpValueArray *return_values = NULL;
- GimpParam *params;
- GimpParam *return_vals;
- gint n_params;
- gint n_return_vals;
-
#ifdef GDK_WINDOWING_QUARTZ
if (proc_run->params &&
proc_run->params[0].data.d_int == GIMP_RUN_INTERACTIVE)
@@ -1275,32 +1351,48 @@ gimp_temp_proc_run (GPProcRun *proc_run)
}
#endif
- arguments = _gimp_gp_params_to_value_array (NULL, 0,
- proc_run->params,
- proc_run->nparams,
- FALSE, FALSE);
+ gimp_proc_run_internal (proc_run, run_proc, &proc_return);
+
+ if (! gp_temp_proc_return_write (_gimp_writechannel, &proc_return, NULL))
+ gimp_quit ();
+ }
+}
+
+static void
+gimp_proc_run_internal (GPProcRun *proc_run,
+ GimpRunProc run_proc,
+ GPProcReturn *proc_return)
+{
+ GimpValueArray *arguments;
+ GimpValueArray *return_values = NULL;
+ GimpParam *params;
+ GimpParam *return_vals;
+ gint n_params;
+ gint n_return_vals;
- n_params = gimp_value_array_length (arguments);
- params = _gimp_value_array_to_params (arguments, FALSE);
+ arguments = _gimp_gp_params_to_value_array (NULL, 0,
+ proc_run->params,
+ proc_run->nparams,
+ FALSE, FALSE);
- run_proc (proc_run->name,
- n_params, params,
- &n_return_vals, &return_vals);
- return_values = _gimp_params_to_value_array (return_vals,
- n_return_vals,
- FALSE);
+ n_params = gimp_value_array_length (arguments);
+ params = _gimp_value_array_to_params (arguments, FALSE);
- g_free (params);
- gimp_value_array_unref (arguments);
+ run_proc (proc_run->name,
+ n_params, params,
+ &n_return_vals, &return_vals);
- proc_return.name = proc_run->name;
- proc_return.nparams = gimp_value_array_length (return_values);
- proc_return.params = _gimp_value_array_to_gp_params (return_values, TRUE);
+ return_values = _gimp_params_to_value_array (return_vals,
+ n_return_vals,
+ FALSE);
- gimp_value_array_unref (return_values);
- }
+ g_free (params);
+ gimp_value_array_unref (arguments);
- if (! gp_temp_proc_return_write (_gimp_writechannel, &proc_return, NULL))
- gimp_quit ();
+ proc_return->name = proc_run->name;
+ proc_return->nparams = gimp_value_array_length (return_values);
+ proc_return->params = _gimp_value_array_to_gp_params (return_values, TRUE);
+
+ gimp_value_array_unref (return_values);
}
diff --git a/libgimp/gimpplugin-private.c b/libgimp/gimpplugin-private.c
index 83c631e578..0350883d53 100644
--- a/libgimp/gimpplugin-private.c
+++ b/libgimp/gimpplugin-private.c
@@ -33,12 +33,18 @@
/* local function prototpes */
-static void gimp_plug_in_register (GimpPlugIn *plug_in,
- gboolean init);
-static void gimp_plug_in_process_message (GimpPlugIn *plug_in,
- GimpWireMessage *msg);
-static void gimp_plug_in_temp_proc_run (GimpPlugIn *plug_in,
- GPProcRun *proc_run);
+static void gimp_plug_in_register (GimpPlugIn *plug_in,
+ gboolean init);
+static void gimp_plug_in_loop (GimpPlugIn *plug_in);
+static void gimp_plug_in_process_message (GimpPlugIn *plug_in,
+ GimpWireMessage *msg);
+static void gimp_plug_in_proc_run (GimpPlugIn *plug_in,
+ GPProcRun *proc_run);
+static void gimp_plug_in_temp_proc_run (GimpPlugIn *plug_in,
+ GPProcRun *proc_run);
+static void gimp_plug_in_proc_run_internal (GPProcRun *proc_run,
+ GimpProcedure *procedure,
+ GPProcReturn *proc_return);
/* public functions */
@@ -65,6 +71,14 @@ _gimp_plug_in_init (GimpPlugIn *plug_in)
gimp_plug_in_register (plug_in, TRUE);
}
+void
+_gimp_plug_in_run (GimpPlugIn *plug_in)
+{
+ g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
+
+ gimp_plug_in_loop (plug_in);
+}
+
void
_gimp_plug_in_quit (GimpPlugIn *plug_in)
{
@@ -149,6 +163,67 @@ gimp_plug_in_register (GimpPlugIn *plug_in,
}
}
+static void
+gimp_plug_in_loop (GimpPlugIn *plug_in)
+{
+ while (TRUE)
+ {
+ GimpWireMessage msg;
+
+ if (! gimp_wire_read_msg (_gimp_readchannel, &msg, NULL))
+ {
+ _gimp_close ();
+ return;
+ }
+
+ switch (msg.type)
+ {
+ case GP_QUIT:
+ gimp_wire_destroy (&msg);
+ _gimp_close ();
+ return;
+
+ case GP_CONFIG:
+ _gimp_config (msg.data);
+ break;
+
+ case GP_TILE_REQ:
+ case GP_TILE_ACK:
+ case GP_TILE_DATA:
+ g_warning ("unexpected tile message received (should not happen)");
+ break;
+
+ case GP_PROC_RUN:
+ gimp_plug_in_proc_run (plug_in, msg.data);
+ gimp_wire_destroy (&msg);
+ _gimp_close ();
+ return;
+
+ case GP_PROC_RETURN:
+ g_warning ("unexpected proc return message received (should not happen)");
+ break;
+
+ case GP_TEMP_PROC_RUN:
+ g_warning ("unexpected temp proc run message received (should not happen");
+ break;
+
+ case GP_TEMP_PROC_RETURN:
+ g_warning ("unexpected temp proc return message received (should not happen");
+ break;
+
+ case GP_PROC_INSTALL:
+ g_warning ("unexpected proc install message received (should not happen)");
+ break;
+
+ case GP_HAS_INIT:
+ g_warning ("unexpected has init message received (should not happen)");
+ break;
+ }
+
+ gimp_wire_destroy (&msg);
+ }
+}
+
void
_gimp_plug_in_single_message (GimpPlugIn *plug_in)
{
@@ -202,34 +277,63 @@ gimp_plug_in_process_message (GimpPlugIn *plug_in,
}
static void
-gimp_plug_in_temp_proc_run (GimpPlugIn *plug_in,
- GPProcRun *proc_run)
+gimp_plug_in_proc_run (GimpPlugIn *plug_in,
+ GPProcRun *proc_run)
{
GPProcReturn proc_return;
GimpProcedure *procedure;
- procedure = gimp_plug_in_get_temp_procedure (plug_in, proc_run->name);
+ procedure = gimp_plug_in_create_procedure (plug_in, proc_run->name);
if (procedure)
{
- GimpValueArray *arguments;
- GimpValueArray *return_values = NULL;
+ gimp_plug_in_proc_run_internal (proc_run, procedure,
+ &proc_return);
+ g_object_unref (procedure);
+ }
- arguments = _gimp_gp_params_to_value_array (NULL, 0,
- proc_run->params,
- proc_run->nparams,
- FALSE, FALSE);
+ if (! gp_proc_return_write (_gimp_writechannel, &proc_return, NULL))
+ gimp_quit ();
+}
- return_values = gimp_procedure_run (procedure, arguments);
- gimp_value_array_unref (arguments);
+static void
+gimp_plug_in_temp_proc_run (GimpPlugIn *plug_in,
+ GPProcRun *proc_run)
+{
+ GPProcReturn proc_return;
+ GimpProcedure *procedure;
- proc_return.name = proc_run->name;
- proc_return.nparams = gimp_value_array_length (return_values);
- proc_return.params = _gimp_value_array_to_gp_params (return_values, TRUE);
+ procedure = gimp_plug_in_get_temp_procedure (plug_in, proc_run->name);
- gimp_value_array_unref (return_values);
+ if (procedure)
+ {
+ gimp_plug_in_proc_run_internal (proc_run, procedure,
+ &proc_return);
}
if (! gp_temp_proc_return_write (_gimp_writechannel, &proc_return, NULL))
gimp_quit ();
}
+
+static void
+gimp_plug_in_proc_run_internal (GPProcRun *proc_run,
+ GimpProcedure *procedure,
+ GPProcReturn *proc_return)
+{
+ GimpValueArray *arguments;
+ GimpValueArray *return_values = NULL;
+
+ arguments = _gimp_gp_params_to_value_array (NULL, 0,
+ proc_run->params,
+ proc_run->nparams,
+ FALSE, FALSE);
+
+ return_values = gimp_procedure_run (procedure, arguments);
+ gimp_value_array_unref (arguments);
+
+ proc_return->name = proc_run->name;
+ proc_return->nparams = gimp_value_array_length (return_values);
+ proc_return->params = _gimp_value_array_to_gp_params (return_values, TRUE);
+
+ gimp_value_array_unref (return_values);
+}
diff --git a/libgimp/gimpplugin-private.h b/libgimp/gimpplugin-private.h
index 347e243b7e..66fe8acba8 100644
--- a/libgimp/gimpplugin-private.h
+++ b/libgimp/gimpplugin-private.h
@@ -51,6 +51,7 @@ struct _GimpPlugInPrivate
void _gimp_plug_in_query (GimpPlugIn *plug_in);
void _gimp_plug_in_init (GimpPlugIn *plug_in);
+void _gimp_plug_in_run (GimpPlugIn *plug_in);
void _gimp_plug_in_quit (GimpPlugIn *plug_in);
gboolean _gimp_plug_in_extension_read (GIOChannel *channel,
diff --git a/libgimp/gimpplugin.h b/libgimp/gimpplugin.h
index 5f952df214..7f5c364b5e 100644
--- a/libgimp/gimpplugin.h
+++ b/libgimp/gimpplugin.h
@@ -93,6 +93,7 @@ struct _GimpPlugInClass
* the names of the procedures registered by @plug_in.
*/
gchar ** (* init_procedures) (GimpPlugIn *plug_in);
+
/**
* GimpPlugInClass::create_procedure:
* @plug_in: a #GimpPlugIn.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]