[gimp] libgimp: add _gimp_plug_in_read_expect_msg()



commit ad8dcff199689fd9d07277407d5ba6d63180ce1a
Author: Michael Natterer <mitch gimp org>
Date:   Sat Aug 3 12:50:34 2019 +0200

    libgimp: add _gimp_plug_in_read_expect_msg()
    
    and make the places who need it dispatch between it and
    _gimp_read_expect_msg() depending on whether there is a GimpPlugIn
    instance. Also clean up some includes.

 libgimp/gimp-private.h          |  3 ---
 libgimp/gimp.c                  |  6 +++++-
 libgimp/gimplegacy.c            |  6 ++----
 libgimp/gimpplugin-private.c    | 29 +++++++++++++++++++++++++++++
 libgimp/gimpplugin-private.h    | 21 ++++++++++++---------
 libgimp/gimpplugin.c            |  1 +
 libgimp/gimpprocedure-private.c |  1 +
 libgimp/gimptilebackendplugin.c | 28 +++++++++++++++++++---------
 8 files changed, 69 insertions(+), 26 deletions(-)
---
diff --git a/libgimp/gimp-private.h b/libgimp/gimp-private.h
index 4920453fe6..4375f6c56e 100644
--- a/libgimp/gimp-private.h
+++ b/libgimp/gimp-private.h
@@ -24,9 +24,6 @@
 G_BEGIN_DECLS
 
 
-#include "libgimpbase/gimpwire.h"
-
-
 extern GIOChannel *_gimp_readchannel;
 extern GIOChannel *_gimp_writechannel;
 
diff --git a/libgimp/gimp.c b/libgimp/gimp.c
index 6084329ffc..94c36cebb5 100644
--- a/libgimp/gimp.c
+++ b/libgimp/gimp.c
@@ -115,6 +115,7 @@
 #include "libgimpbase/gimpbase.h"
 #include "libgimpbase/gimpbase-private.h"
 #include "libgimpbase/gimpprotocol.h"
+#include "libgimpbase/gimpwire.h"
 
 #include "gimp.h"
 #include "gimp-private.h"
@@ -840,7 +841,10 @@ gimp_run_procedure_with_array (const gchar    *name,
   if (! gp_proc_run_write (_gimp_writechannel, &proc_run, NULL))
     gimp_quit ();
 
-  _gimp_read_expect_msg (&msg, GP_PROC_RETURN);
+  if (PLUG_IN)
+    _gimp_plug_in_read_expect_msg (PLUG_IN, &msg, GP_PROC_RETURN);
+  else
+    _gimp_read_expect_msg (&msg, GP_PROC_RETURN);
   gp_unlock ();
 
   proc_return = msg.data;
diff --git a/libgimp/gimplegacy.c b/libgimp/gimplegacy.c
index c18c089625..c7f547bd65 100644
--- a/libgimp/gimplegacy.c
+++ b/libgimp/gimplegacy.c
@@ -22,13 +22,11 @@
 
 #include "errno.h"
 
-#include <gio/gio.h>
+#include "gimp.h"
 
-#include "libgimpbase/gimpbase.h"
-#include "libgimpbase/gimpbase-private.h"
 #include "libgimpbase/gimpprotocol.h"
+#include "libgimpbase/gimpwire.h"
 
-#include "gimp.h"
 #include "gimp-private.h"
 #include "gimpgpcompat.h"
 #include "gimpgpparams.h"
diff --git a/libgimp/gimpplugin-private.c b/libgimp/gimpplugin-private.c
index 37297631a3..ff7ae2ec80 100644
--- a/libgimp/gimpplugin-private.c
+++ b/libgimp/gimpplugin-private.c
@@ -24,6 +24,7 @@
 #include "gimp.h"
 
 #include "libgimpbase/gimpprotocol.h"
+#include "libgimpbase/gimpwire.h"
 
 #include "gimp-private.h"
 #include "gimpgpparams.h"
@@ -94,6 +95,34 @@ _gimp_plug_in_quit (GimpPlugIn *plug_in)
     GIMP_PLUG_IN_GET_CLASS (plug_in)->quit (plug_in);
 }
 
+void
+_gimp_plug_in_read_expect_msg (GimpPlugIn      *plug_in,
+                               GimpWireMessage *msg,
+                               gint             type)
+{
+  g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
+
+  while (TRUE)
+    {
+      if (! gimp_wire_read_msg (_gimp_readchannel, msg, NULL))
+        gimp_quit ();
+
+      if (msg->type == type)
+        return; /* up to the caller to call wire_destroy() */
+
+      if (msg->type == GP_TEMP_PROC_RUN || msg->type == GP_QUIT)
+        {
+          gimp_plug_in_process_message (plug_in, msg);
+        }
+      else
+        {
+          g_error ("unexpected message: %d", msg->type);
+        }
+
+      gimp_wire_destroy (msg);
+    }
+}
+
 gboolean
 _gimp_plug_in_extension_read (GIOChannel  *channel,
                               GIOCondition condition,
diff --git a/libgimp/gimpplugin-private.h b/libgimp/gimpplugin-private.h
index 66fe8acba8..b1d86a90a4 100644
--- a/libgimp/gimpplugin-private.h
+++ b/libgimp/gimpplugin-private.h
@@ -49,15 +49,18 @@ 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,
-                                         GIOCondition condition,
-                                         gpointer     data);
-void       _gimp_plug_in_single_message (GimpPlugIn  *plug_in);
+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);
+
+void       _gimp_plug_in_read_expect_msg (GimpPlugIn      *plug_in,
+                                          GimpWireMessage *msg,
+                                          gint             type);
+gboolean   _gimp_plug_in_extension_read  (GIOChannel      *channel,
+                                          GIOCondition     condition,
+                                          gpointer         data);
+void       _gimp_plug_in_single_message  (GimpPlugIn      *plug_in);
 
 
 G_END_DECLS
diff --git a/libgimp/gimpplugin.c b/libgimp/gimpplugin.c
index 55adaad0fa..329c4128af 100644
--- a/libgimp/gimpplugin.c
+++ b/libgimp/gimpplugin.c
@@ -27,6 +27,7 @@
 #include "gimp.h"
 
 #include "libgimpbase/gimpprotocol.h"
+#include "libgimpbase/gimpwire.h"
 
 #include "gimp-private.h"
 #include "gimpplugin-private.h"
diff --git a/libgimp/gimpprocedure-private.c b/libgimp/gimpprocedure-private.c
index 10733b1a9c..e48323277d 100644
--- a/libgimp/gimpprocedure-private.c
+++ b/libgimp/gimpprocedure-private.c
@@ -29,6 +29,7 @@
 #include "libgimpbase/gimpbase.h"
 #include "libgimpcolor/gimpcolor.h"
 #include "libgimpbase/gimpprotocol.h"
+#include "libgimpbase/gimpwire.h"
 
 #include "gimp.h"
 #include "gimp-private.h"
diff --git a/libgimp/gimptilebackendplugin.c b/libgimp/gimptilebackendplugin.c
index 771a76b577..68fa04c642 100644
--- a/libgimp/gimptilebackendplugin.c
+++ b/libgimp/gimptilebackendplugin.c
@@ -24,14 +24,13 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include <gio/gio.h>
-#include <gegl.h>
+#include "gimp.h"
 
-#include "libgimpbase/gimpbase.h"
 #include "libgimpbase/gimpprotocol.h"
+#include "libgimpbase/gimpwire.h"
 
-#include "gimp.h"
 #include "gimp-private.h"
+#include "gimpplugin-private.h"
 #include "gimptilebackendplugin.h"
 
 
@@ -324,7 +323,8 @@ static void
 gimp_tile_get (GimpTileBackendPlugin *backend_plugin,
                GimpTile              *tile)
 {
-  GimpTileBackendPluginPrivate *priv = backend_plugin->priv;
+  GimpTileBackendPluginPrivate *priv    = backend_plugin->priv;
+  GimpPlugIn                   *plug_in = gimp_get_plug_in ();
   GPTileReq                     tile_req;
   GPTileData                   *tile_data;
   GimpWireMessage               msg;
@@ -337,7 +337,10 @@ gimp_tile_get (GimpTileBackendPlugin *backend_plugin,
   if (! gp_tile_req_write (_gimp_writechannel, &tile_req, NULL))
     gimp_quit ();
 
-  _gimp_read_expect_msg (&msg, GP_TILE_DATA);
+  if (plug_in)
+    _gimp_plug_in_read_expect_msg (plug_in, &msg, GP_TILE_DATA);
+  else
+    _gimp_read_expect_msg (&msg, GP_TILE_DATA);
 
   tile_data = msg.data;
   if (tile_data->drawable_ID != priv->drawable_id ||
@@ -389,7 +392,8 @@ static void
 gimp_tile_put (GimpTileBackendPlugin *backend_plugin,
                GimpTile              *tile)
 {
-  GimpTileBackendPluginPrivate *priv = backend_plugin->priv;
+  GimpTileBackendPluginPrivate *priv    = backend_plugin->priv;
+  GimpPlugIn                   *plug_in = gimp_get_plug_in ();
   GPTileReq                     tile_req;
   GPTileData                    tile_data;
   GPTileData                   *tile_info;
@@ -403,7 +407,10 @@ gimp_tile_put (GimpTileBackendPlugin *backend_plugin,
   if (! gp_tile_req_write (_gimp_writechannel, &tile_req, NULL))
     gimp_quit ();
 
-  _gimp_read_expect_msg (&msg, GP_TILE_DATA);
+  if (plug_in)
+    _gimp_plug_in_read_expect_msg (plug_in, &msg, GP_TILE_DATA);
+  else
+    _gimp_read_expect_msg (&msg, GP_TILE_DATA);
 
   tile_info = msg.data;
 
@@ -435,7 +442,10 @@ gimp_tile_put (GimpTileBackendPlugin *backend_plugin,
 
   gimp_wire_destroy (&msg);
 
-  _gimp_read_expect_msg (&msg, GP_TILE_ACK);
+  if (plug_in)
+    _gimp_plug_in_read_expect_msg (plug_in, &msg, GP_TILE_ACK);
+  else
+    _gimp_read_expect_msg (&msg, GP_TILE_ACK);
   gp_unlock ();
 
   gimp_wire_destroy (&msg);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]