[gimp] libgimp: add a GimpPDB class and subclass GimpProcedure as GimpPDBProcedure



commit 450a9f90b4a7f6c00e9aebd9fa84f9a0d7723cd3
Author: Michael Natterer <mitch gimp org>
Date:   Tue Aug 6 12:17:27 2019 +0200

    libgimp: add a GimpPDB class and subclass GimpProcedure as GimpPDBProcedure
    
    The idea is that we already have a GimpProcedure object in libgimp
    which has name, help, blurb, arguments, return values and everything,
    so we really don't need a parallel API to query PDB procedures for
    their properties.
    
    - make run() a virtual function of GimpProcedure
    - move GIMP_PDB_ERROR to GimpPDB
    - GimpPDBProcedure is a trivial subblass which populates
      GimpProcedure's members by querying the PDB.
    - make "plug-in", "procedure-type" and "name" construct-only
      properties of GimpProcedure.
    
    This is all work in progress.

 libgimp/Makefile.am        |   3 +
 libgimp/Makefile.gi        |   2 +
 libgimp/gimp.def           |   2 +
 libgimp/gimp.h             |   1 +
 libgimp/gimppdb-private.h  |  51 +++++++++++++
 libgimp/gimppdb.c          | 121 ++++++++++++++++++++++++++++++
 libgimp/gimppdb.h          |  76 +++++++++++++++++++
 libgimp/gimppdbprocedure.c | 131 ++++++++++++++++++++++++++++++++
 libgimp/gimppdbprocedure.h |  63 ++++++++++++++++
 libgimp/gimpprocedure.c    | 181 ++++++++++++++++++++++++++++++++++++---------
 libgimp/gimpprocedure.h    |  13 ++++
 libgimp/gimptypes.h        |   1 +
 12 files changed, 612 insertions(+), 33 deletions(-)
---
diff --git a/libgimp/Makefile.am b/libgimp/Makefile.am
index d3b16289de..d510cf1cca 100644
--- a/libgimp/Makefile.am
+++ b/libgimp/Makefile.am
@@ -113,6 +113,9 @@ libgimp_private_sources = \
        gimpgpparams.h          \
        gimplegacy.c            \
        gimplegacy.h            \
+       gimpdb-private.h        \
+       gimppdbprocedure.c      \
+       gimppdbprocedure.h      \
        gimpplugin-private.c    \
        gimpplugin-private.h    \
        gimp-debug.c            \
diff --git a/libgimp/Makefile.gi b/libgimp/Makefile.gi
index f4db5b974a..a4e4e02c3c 100644
--- a/libgimp/Makefile.gi
+++ b/libgimp/Makefile.gi
@@ -138,6 +138,8 @@ libgimp_introspectable = \
        $(top_srcdir)/libgimp/gimpparamspecs.h          \
        $(top_srcdir)/libgimp/gimppatternselect.c       \
        $(top_srcdir)/libgimp/gimppatternselect.h       \
+       $(top_srcdir)/libgimp/gimppdb.c                 \
+       $(top_srcdir)/libgimp/gimppdb.h                 \
        $(top_srcdir)/libgimp/gimppixbuf.c              \
        $(top_srcdir)/libgimp/gimppixbuf.h              \
        $(top_srcdir)/libgimp/gimpplugin.c              \
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index bb22932c7c..23295c8a37 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -611,6 +611,8 @@ EXPORTS
        gimp_patterns_popup
        gimp_patterns_refresh
        gimp_patterns_set_popup
+       gimp_pdb_get_type
+       gimp_pdb_lookup
        gimp_pencil
        gimp_plug_in_add_menu_branch
        gimp_plug_in_add_temp_procedure
diff --git a/libgimp/gimp.h b/libgimp/gimp.h
index 328bbb1edd..03f396c6f4 100644
--- a/libgimp/gimp.h
+++ b/libgimp/gimp.h
@@ -48,6 +48,7 @@
 #include <libgimp/gimppaletteselect.h>
 #include <libgimp/gimpparamspecs.h>
 #include <libgimp/gimppatternselect.h>
+#include <libgimp/gimppdb.h>
 #include <libgimp/gimppixbuf.h>
 #include <libgimp/gimpplugin.h>
 #include <libgimp/gimpproceduraldb.h>
diff --git a/libgimp/gimppdb-private.h b/libgimp/gimppdb-private.h
new file mode 100644
index 0000000000..8ad2dc28c1
--- /dev/null
+++ b/libgimp/gimppdb-private.h
@@ -0,0 +1,51 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimppdb-private.h
+ * Copyright (C) 2019 Michael Natterer <mitch gimp org>
+ *
+ * This library is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_PDB_PRIVATE_H__
+#define __GIMP_PDB_PRIVATE_H__
+
+G_BEGIN_DECLS
+
+
+typedef enum
+{
+  GIMP_PDB_ERROR_FAILED,  /* generic error condition */
+  GIMP_PDB_ERROR_CANCELLED,
+  GIMP_PDB_ERROR_PDB_NOT_FOUND,
+  GIMP_PDB_ERROR_INVALID_ARGUMENT,
+  GIMP_PDB_ERROR_INVALID_RETURN_VALUE,
+  GIMP_PDB_ERROR_INTERNAL_ERROR
+} GimpPdbErrorCode;
+
+
+#define GIMP_PDB_ERROR (_gimp_pdb_error_quark ())
+
+GQuark _gimp_pdb_error_quark (void) G_GNUC_CONST;
+
+
+GimpPDB    * _gimp_pdb_new         (GimpPlugIn *plug_in);
+
+GimpPlugIn * _gimp_pdb_get_plug_in (GimpPDB *pdb);
+
+
+G_END_DECLS
+
+#endif  /*  __GIMP_PDB_PRIVATE_H__  */
diff --git a/libgimp/gimppdb.c b/libgimp/gimppdb.c
new file mode 100644
index 0000000000..4e4374d165
--- /dev/null
+++ b/libgimp/gimppdb.c
@@ -0,0 +1,121 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimppdb.c
+ * Copyright (C) 2019 Michael Natterer <mitch gimp org>
+ *
+ * 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 3 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, see <https://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "gimp.h"
+#include "gimppdb-private.h"
+#include "gimppdbprocedure.h"
+
+
+struct _GimpPDBPrivate
+{
+  GimpPlugIn *plug_in;
+
+  GHashTable *procedures;
+};
+
+
+static void   gimp_pdb_finalize (GObject *object);
+
+
+G_DEFINE_TYPE_WITH_PRIVATE (GimpPDB, gimp_pdb, G_TYPE_OBJECT)
+
+#define parent_class gimp_pdb_parent_class
+
+
+static void
+gimp_pdb_class_init (GimpPDBClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = gimp_pdb_finalize;
+}
+
+static void
+gimp_pdb_init (GimpPDB *pdb)
+{
+  pdb->priv = gimp_pdb_get_instance_private (pdb);
+
+  pdb->priv->procedures = g_hash_table_new_full (g_str_hash, g_str_equal,
+                                                 g_free, g_object_unref);
+}
+
+static void
+gimp_pdb_finalize (GObject *object)
+{
+  GimpPDB *pdb = GIMP_PDB (object);
+
+  g_clear_object (&pdb->priv->plug_in);
+  g_clear_pointer (&pdb->priv->procedures, g_hash_table_unref);
+
+  G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+GimpPDB *
+_gimp_pdb_new (GimpPlugIn *plug_in)
+{
+  GimpPDB *pdb;
+
+  g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), NULL);
+
+  pdb = g_object_new (GIMP_TYPE_PDB, NULL);
+
+  pdb->priv->plug_in = g_object_ref (plug_in);
+
+  return pdb;
+}
+
+GimpPlugIn *
+_gimp_pdb_get_plug_in (GimpPDB *pdb)
+{
+  g_return_val_if_fail (GIMP_IS_PDB (pdb), NULL);
+
+  return pdb->priv->plug_in;
+}
+
+GimpProcedure *
+gimp_pdb_lookup (GimpPDB     *pdb,
+                 const gchar *name)
+{
+  GimpProcedure *procedure;
+
+  g_return_val_if_fail (GIMP_IS_PDB (pdb), NULL);
+  g_return_val_if_fail (name != NULL, NULL);
+
+  procedure = g_hash_table_lookup (pdb->priv->procedures, name);
+
+  if (! procedure)
+    {
+      procedure = _gimp_pdb_procedure_new (pdb, name);
+
+      if (procedure)
+        g_hash_table_insert (pdb->priv->procedures,
+                             g_strdup (name), procedure);
+    }
+
+  return procedure;
+}
+
+GQuark
+_gimp_pdb_error_quark (void)
+{
+  return g_quark_from_static_string ("gimp-pdb-error-quark");
+}
diff --git a/libgimp/gimppdb.h b/libgimp/gimppdb.h
new file mode 100644
index 0000000000..b3e19879c0
--- /dev/null
+++ b/libgimp/gimppdb.h
@@ -0,0 +1,76 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimppdb.h
+ * Copyright (C) 2019 Michael Natterer <mitch gimp org>
+ *
+ * This library is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <https://www.gnu.org/licenses/>.
+ */
+
+#if !defined (__GIMP_H_INSIDE__) && !defined (GIMP_COMPILATION)
+#error "Only <libgimp/gimp.h> can be included directly."
+#endif
+
+#ifndef __GIMP_PDB_H__
+#define __GIMP_PDB_H__
+
+G_BEGIN_DECLS
+
+/* For information look into the C source or the html documentation */
+
+
+#define GIMP_TYPE_PDB            (gimp_pdb_get_type ())
+#define GIMP_PDB(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_PDB, GimpPDB))
+#define GIMP_PDB_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_PDB, GimpPDBClass))
+#define GIMP_IS_PDB(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_PDB))
+#define GIMP_IS_PDB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_PDB))
+#define GIMP_PDB_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_PDB, GimpPDBClass))
+
+
+typedef struct _GimpPDBClass   GimpPDBClass;
+typedef struct _GimpPDBPrivate GimpPDBPrivate;
+
+struct _GimpPDB
+{
+  GObject         parent_instance;
+
+  GimpPDBPrivate *priv;
+};
+
+struct _GimpPDBClass
+{
+  GObjectClass parent_class;
+
+  /* Padding for future expansion */
+  void (*_gimp_reserved1) (void);
+  void (*_gimp_reserved2) (void);
+  void (*_gimp_reserved3) (void);
+  void (*_gimp_reserved4) (void);
+  void (*_gimp_reserved5) (void);
+  void (*_gimp_reserved6) (void);
+  void (*_gimp_reserved7) (void);
+  void (*_gimp_reserved8) (void);
+};
+
+
+GType           gimp_pdb_get_type (void) G_GNUC_CONST;
+
+GimpProcedure * gimp_pdb_lookup   (GimpPDB     *pdb,
+                                   const gchar *name);
+
+
+G_END_DECLS
+
+#endif  /*  __GIMP_PDB_H__  */
diff --git a/libgimp/gimppdbprocedure.c b/libgimp/gimppdbprocedure.c
new file mode 100644
index 0000000000..85d0d4748a
--- /dev/null
+++ b/libgimp/gimppdbprocedure.c
@@ -0,0 +1,131 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimppdbprocedure.c
+ * Copyright (C) 2019 Michael Natterer <mitch gimp org>
+ *
+ * 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 3 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, see <https://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "gimp.h"
+#include "gimppdb-private.h"
+#include "gimppdbprocedure.h"
+
+
+struct _GimpPDBProcedurePrivate
+{
+  GimpPDB *pdb;
+};
+
+
+static GimpValueArray * gimp_pdb_procedure_run (GimpProcedure        *procedure,
+                                                const GimpValueArray *args);
+
+
+G_DEFINE_TYPE_WITH_PRIVATE (GimpPDBProcedure, _gimp_pdb_procedure,
+                            GIMP_TYPE_PROCEDURE)
+
+#define parent_class gimp_pdb_procedure_parent_class
+
+
+static void
+_gimp_pdb_procedure_class_init (GimpPDBProcedureClass *klass)
+{
+  GimpProcedureClass *procedure_class = GIMP_PROCEDURE_CLASS (klass);
+
+  procedure_class->run = gimp_pdb_procedure_run;
+}
+
+static void
+_gimp_pdb_procedure_init (GimpPDBProcedure *procedure)
+{
+  procedure->priv = _gimp_pdb_procedure_get_instance_private (procedure);
+}
+
+static GimpValueArray *
+gimp_pdb_procedure_run (GimpProcedure        *procedure,
+                        const GimpValueArray *args)
+{
+  return gimp_run_procedure_with_array (gimp_procedure_get_name (procedure),
+                                        (GimpValueArray *) args);
+}
+
+
+/*  public functions  */
+
+GimpProcedure  *
+_gimp_pdb_procedure_new (GimpPDB     *pdb,
+                         const gchar *name)
+{
+  GimpProcedure   *procedure;
+  gchar           *blurb;
+  gchar           *help;
+  gchar           *authors;
+  gchar           *copyright;
+  gchar           *date;
+  GimpPDBProcType  type;
+  gint             n_params;
+  gint             n_return_vals;
+  gint             i;
+
+  g_return_val_if_fail (GIMP_IS_PDB (pdb), NULL);
+  g_return_val_if_fail (name != NULL, NULL);
+
+  _gimp_procedural_db_proc_info (name,
+                                 &blurb,
+                                 &help,
+                                 &authors,
+                                 &copyright,
+                                 &date,
+                                 &type,
+                                 &n_params,
+                                 &n_return_vals);
+
+  procedure = g_object_new (GIMP_TYPE_PDB_PROCEDURE,
+                            "plug-in",        _gimp_pdb_get_plug_in (pdb),
+                            "name",           name,
+                            "procedure-type", type,
+                            NULL);
+
+  GIMP_PDB_PROCEDURE (procedure)->priv->pdb = pdb;
+
+  gimp_procedure_set_documentation (procedure, blurb, help, name);
+  gimp_procedure_set_attribution (procedure, authors, copyright, date);
+
+  g_free (blurb);
+  g_free (help);
+  g_free (authors);
+  g_free (copyright);
+  g_free (date);
+
+  for (i = 0; i < n_params; i++)
+    {
+      GParamSpec *pspec = gimp_procedural_db_proc_argument (name, i);
+
+      gimp_procedure_add_argument (procedure, pspec);
+      g_param_spec_unref (pspec);
+    }
+
+  for (i = 0; i < n_return_vals; i++)
+    {
+      GParamSpec *pspec = gimp_procedural_db_proc_return_value (name, i);
+
+      gimp_procedure_add_return_value (procedure, pspec);
+      g_param_spec_unref (pspec);
+    }
+
+  return procedure;
+}
diff --git a/libgimp/gimppdbprocedure.h b/libgimp/gimppdbprocedure.h
new file mode 100644
index 0000000000..2b9e501899
--- /dev/null
+++ b/libgimp/gimppdbprocedure.h
@@ -0,0 +1,63 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimppdbprocedure.h
+ * Copyright (C) 2019 Michael Natterer <mitch gimp org>
+ *
+ * This library is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_PDB_PROCEDURE_H__
+#define __GIMP_PDB_PROCEDURE_H__
+
+G_BEGIN_DECLS
+
+/* For information look into the C source or the html documentation */
+
+
+#define GIMP_TYPE_PDB_PROCEDURE            (_gimp_pdb_procedure_get_type ())
+#define GIMP_PDB_PROCEDURE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_PDB_PROCEDURE, 
GimpPDBProcedure))
+#define GIMP_PDB_PROCEDURE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_PDB_PROCEDURE, 
GimpPDBProcedureClass))
+#define GIMP_IS_PDB_PROCEDURE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_PDB_PROCEDURE))
+#define GIMP_IS_PDB_PROCEDURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_PDB_PROCEDURE))
+#define GIMP_PDB_PROCEDURE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_PDB_PROCEDURE, 
GimpPDBProcedureClass))
+
+
+typedef struct _GimpPDBProcedure        GimpPDBProcedure;
+typedef struct _GimpPDBProcedureClass   GimpPDBProcedureClass;
+typedef struct _GimpPDBProcedurePrivate GimpPDBProcedurePrivate;
+
+struct _GimpPDBProcedure
+{
+  GimpProcedure            parent_instance;
+
+  GimpPDBProcedurePrivate *priv;
+};
+
+struct _GimpPDBProcedureClass
+{
+  GimpProcedureClass parent_class;
+};
+
+
+GType           _gimp_pdb_procedure_get_type (void) G_GNUC_CONST;
+
+GimpProcedure * _gimp_pdb_procedure_new      (GimpPDB     *pdb,
+                                              const gchar *name);
+
+
+G_END_DECLS
+
+#endif  /*  __GIMP_PDB_PROCEDURE_H__  */
diff --git a/libgimp/gimpprocedure.c b/libgimp/gimpprocedure.c
index 86e98ceb06..c22677cd8e 100644
--- a/libgimp/gimpprocedure.c
+++ b/libgimp/gimpprocedure.c
@@ -24,28 +24,20 @@
 #include <sys/types.h>
 
 #include "gimp.h"
+#include "gimppdb-private.h"
 #include "gimpprocedure-private.h"
 
 #include "libgimp-intl.h"
 
 
-typedef enum
+enum
 {
-  GIMP_PDB_ERROR_FAILED,  /* generic error condition */
-  GIMP_PDB_ERROR_CANCELLED,
-  GIMP_PDB_ERROR_PROCEDURE_NOT_FOUND,
-  GIMP_PDB_ERROR_INVALID_ARGUMENT,
-  GIMP_PDB_ERROR_INVALID_RETURN_VALUE,
-  GIMP_PDB_ERROR_INTERNAL_ERROR
-} GimpPdbErrorCode;
-
-#define GIMP_PDB_ERROR (gimp_pdb_error_quark ())
-
-static GQuark
-gimp_pdb_error_quark (void)
-{
-  return g_quark_from_static_string ("gimp-pdb-error-quark");
-}
+  PROP_0,
+  PROP_PLUG_IN,
+  PROP_NAME,
+  PROP_PROCEDURE_TYPE,
+  N_PROPS
+};
 
 
 struct _GimpProcedurePrivate
@@ -84,27 +76,74 @@ struct _GimpProcedurePrivate
 };
 
 
-static void       gimp_procedure_finalize      (GObject         *object);
+static void       gimp_procedure_constructed   (GObject              *object);
+static void       gimp_procedure_finalize      (GObject              *object);
+static void       gimp_procedure_set_property  (GObject              *object,
+                                                guint                 property_id,
+                                                const GValue         *value,
+                                                GParamSpec           *pspec);
+static void       gimp_procedure_get_property  (GObject              *object,
+                                                guint                 property_id,
+                                                GValue               *value,
+                                                GParamSpec           *pspec);
 
-static gboolean   gimp_procedure_validate_args (GimpProcedure   *procedure,
-                                                GParamSpec     **param_specs,
-                                                gint             n_param_specs,
-                                                GimpValueArray  *args,
-                                                gboolean         return_vals,
-                                                GError         **error);
+static GimpValueArray *
+                  gimp_procedure_real_run      (GimpProcedure        *procedure,
+                                                const GimpValueArray *args);
+
+static gboolean   gimp_procedure_validate_args (GimpProcedure        *procedure,
+                                                GParamSpec          **param_specs,
+                                                gint                  n_param_specs,
+                                                GimpValueArray       *args,
+                                                gboolean              return_vals,
+                                                GError              **error);
 
 
 G_DEFINE_TYPE_WITH_PRIVATE (GimpProcedure, gimp_procedure, G_TYPE_OBJECT)
 
 #define parent_class gimp_procedure_parent_class
 
+static GParamSpec *props[N_PROPS] = { NULL, };
+
 
 static void
 gimp_procedure_class_init (GimpProcedureClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-  object_class->finalize = gimp_procedure_finalize;
+  object_class->constructed  = gimp_procedure_constructed;
+  object_class->finalize     = gimp_procedure_finalize;
+  object_class->set_property = gimp_procedure_set_property;
+  object_class->get_property = gimp_procedure_get_property;
+
+  klass->run                 = gimp_procedure_real_run;
+
+  props[PROP_PLUG_IN] =
+    g_param_spec_object ("plug-in",
+                         "Plug-In",
+                         "The GimpPlugIn of this plug-in process",
+                         GIMP_TYPE_PLUG_IN,
+                         GIMP_PARAM_READWRITE |
+                         G_PARAM_CONSTRUCT_ONLY);
+
+  props[PROP_NAME] =
+    g_param_spec_string ("name",
+                         "Name",
+                         "The procedure's name",
+                         NULL,
+                         GIMP_PARAM_READWRITE |
+                         G_PARAM_CONSTRUCT_ONLY);
+
+  props[PROP_PROCEDURE_TYPE] =
+    g_param_spec_enum ("procedure-type",
+                       "Procedure type",
+                       "The procedure's type",
+                       GIMP_TYPE_PDB_PROC_TYPE,
+                       GIMP_PLUGIN,
+                       GIMP_PARAM_READWRITE |
+                       G_PARAM_CONSTRUCT_ONLY);
+
+  g_object_class_install_properties (object_class, N_PROPS, props);
 }
 
 static void
@@ -113,6 +152,17 @@ gimp_procedure_init (GimpProcedure *procedure)
   procedure->priv = gimp_procedure_get_instance_private (procedure);
 }
 
+static void
+gimp_procedure_constructed (GObject *object)
+{
+  GimpProcedure *procedure = GIMP_PROCEDURE (object);
+
+  G_OBJECT_CLASS (parent_class)->constructed (object);
+
+  g_assert (GIMP_IS_PLUG_IN (procedure->priv->plug_in));
+  g_assert (procedure->priv->name != NULL);
+}
+
 static void
 gimp_procedure_finalize (GObject *object)
 {
@@ -159,6 +209,71 @@ gimp_procedure_finalize (GObject *object)
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
+static void
+gimp_procedure_set_property (GObject      *object,
+                             guint         property_id,
+                             const GValue *value,
+                             GParamSpec   *pspec)
+{
+  GimpProcedure *procedure = GIMP_PROCEDURE (object);
+
+  switch (property_id)
+    {
+    case PROP_PLUG_IN:
+      g_set_object (&procedure->priv->plug_in, g_value_get_object (value));
+      break;
+
+    case PROP_NAME:
+      g_free (procedure->priv->name);
+      procedure->priv->name = g_value_dup_string (value);
+      break;
+
+    case PROP_PROCEDURE_TYPE:
+      procedure->priv->proc_type = g_value_get_enum (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+static void
+gimp_procedure_get_property (GObject    *object,
+                             guint       property_id,
+                             GValue     *value,
+                             GParamSpec *pspec)
+{
+  GimpProcedure *procedure = GIMP_PROCEDURE (object);
+
+  switch (property_id)
+    {
+    case PROP_PLUG_IN:
+      g_value_set_object (value, procedure->priv->plug_in);
+      break;
+
+    case PROP_NAME:
+      g_value_set_string (value, procedure->priv->name);
+      break;
+
+    case PROP_PROCEDURE_TYPE:
+      g_value_set_enum (value, procedure->priv->proc_type);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+static GimpValueArray *
+gimp_procedure_real_run (GimpProcedure        *procedure,
+                         const GimpValueArray *args)
+{
+  return procedure->priv->run_func (procedure, args,
+                                    procedure->priv->run_data);
+}
+
 
 /*  public functions  */
 
@@ -223,14 +338,15 @@ gimp_procedure_new (GimpPlugIn      *plug_in,
   g_return_val_if_fail (proc_type != GIMP_INTERNAL, NULL);
   g_return_val_if_fail (run_func != NULL, NULL);
 
-  procedure = g_object_new (GIMP_TYPE_PROCEDURE, NULL);
+  procedure = g_object_new (GIMP_TYPE_PROCEDURE,
+                            "plug-in",        plug_in,
+                            "name",           name,
+                            "procedure-type", proc_type,
+                            NULL);
 
-  procedure->priv->plug_in           = g_object_ref (plug_in);
-  procedure->priv->proc_type         = proc_type;
-  procedure->priv->name              = g_strdup (name);
-  procedure->priv->run_func          = run_func;
-  procedure->priv->run_data          = run_data;
-  procedure->priv->run_data_destroy  = run_data_destroy;
+  procedure->priv->run_func         = run_func;
+  procedure->priv->run_data         = run_data;
+  procedure->priv->run_data_destroy = run_data_destroy;
 
   return procedure;
 }
@@ -959,8 +1075,7 @@ gimp_procedure_run (GimpProcedure  *procedure,
     }
 
   /*  call the procedure  */
-  return_vals = procedure->priv->run_func (procedure, args,
-                                           procedure->priv->run_data);
+  return_vals = GIMP_PROCEDURE_GET_CLASS (procedure)->run (procedure, args);
 
   if (! return_vals)
     {
diff --git a/libgimp/gimpprocedure.h b/libgimp/gimpprocedure.h
index 610f35f8ac..748ba04724 100644
--- a/libgimp/gimpprocedure.h
+++ b/libgimp/gimpprocedure.h
@@ -70,6 +70,19 @@ struct _GimpProcedure
 struct _GimpProcedureClass
 {
   GObjectClass parent_class;
+
+  GimpValueArray * (* run) (GimpProcedure        *procedure,
+                            const GimpValueArray *args);
+
+  /* Padding for future expansion */
+  void (*_gimp_reserved1) (void);
+  void (*_gimp_reserved2) (void);
+  void (*_gimp_reserved3) (void);
+  void (*_gimp_reserved4) (void);
+  void (*_gimp_reserved5) (void);
+  void (*_gimp_reserved6) (void);
+  void (*_gimp_reserved7) (void);
+  void (*_gimp_reserved8) (void);
 };
 
 
diff --git a/libgimp/gimptypes.h b/libgimp/gimptypes.h
index ad994760ab..9342117564 100644
--- a/libgimp/gimptypes.h
+++ b/libgimp/gimptypes.h
@@ -28,6 +28,7 @@ G_BEGIN_DECLS
 /* For information look into the html documentation */
 
 
+typedef struct _GimpPDB         GimpPDB;
 typedef struct _GimpPlugIn      GimpPlugIn;
 typedef struct _GimpProcedure   GimpProcedure;
 


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