[gimp] libgimp: more progress on the GimpPDB object
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] libgimp: more progress on the GimpPDB object
- Date: Tue, 6 Aug 2019 17:13:20 +0000 (UTC)
commit 8860d78979e4400ac8e7d3ecbf5afeef822773ef
Author: Michael Natterer <mitch gimp org>
Date: Tue Aug 6 18:29:55 2019 +0200
libgimp: more progress on the GimpPDB object
- add gimp_pdb_run_procedure()
- hide more functions in gimppdb_pdb.[ch], and add proper API
- add gimp_get_pdb() which returns the singleton
libgimp/gimp-private.h | 1 +
libgimp/gimp.c | 32 +++++++--
libgimp/gimp.def | 7 +-
libgimp/gimp.h | 4 ++
libgimp/gimppdb.c | 181 ++++++++++++++++++++++++++++++++++++++++++++++---
libgimp/gimppdb.h | 57 ++++++++++------
libgimp/gimppdb_pdb.c | 32 ++++-----
libgimp/gimppdb_pdb.h | 8 +--
pdb/groups/pdb.pdb | 8 +--
9 files changed, 269 insertions(+), 61 deletions(-)
---
diff --git a/libgimp/gimp-private.h b/libgimp/gimp-private.h
index 4375f6c56e..5333106f7c 100644
--- a/libgimp/gimp-private.h
+++ b/libgimp/gimp-private.h
@@ -32,6 +32,7 @@ void _gimp_config (GPConfig *config);
void _gimp_loop (GimpRunProc run_proc);
void _gimp_read_expect_msg (GimpWireMessage *msg,
gint type);
+void _gimp_set_pdb_error (GimpValueArray *return_vals);
G_END_DECLS
diff --git a/libgimp/gimp.c b/libgimp/gimp.c
index b073b8e943..9314672de4 100644
--- a/libgimp/gimp.c
+++ b/libgimp/gimp.c
@@ -101,6 +101,7 @@
#include "gimp-shm.h"
#include "gimpgpcompat.h"
#include "gimpgpparams.h"
+#include "gimppdb-private.h"
#include "gimpplugin-private.h"
#include "gimpunitcache.h"
@@ -141,8 +142,6 @@ static gboolean gimp_write (GIOChannel *channel,
static gboolean gimp_flush (GIOChannel *channel,
gpointer user_data);
-static void gimp_set_pdb_error (GimpValueArray *return_vals);
-
#if defined G_OS_WIN32 && defined HAVE_EXCHNDL
static LPTOP_LEVEL_EXCEPTION_FILTER _prevExceptionFilter = NULL;
@@ -175,6 +174,7 @@ static gulong write_buffer_index = 0;
static GimpStackTraceMode stack_trace_mode = GIMP_STACK_TRACE_NEVER;
static GimpPlugIn *PLUG_IN = NULL;
+static GimpPDB *PDB = NULL;
static GimpPlugInInfo PLUG_IN_INFO = { 0, };
static GimpPDBStatusType pdb_error_status = GIMP_PDB_SUCCESS;
@@ -695,6 +695,28 @@ gimp_get_plug_in (void)
return PLUG_IN;
}
+/**
+ * gimp_get_pdb:
+ *
+ * This function returns the plug-in's #GimpPDB instance, which can
+ * exist exactly once per running plug-in program.
+ *
+ * Returns: (transfer none): The plug-in's #GimpPDB singleton, or %NULL.
+ *
+ * Since: 3.0
+ **/
+GimpPDB *
+gimp_get_pdb (void)
+{
+ if (! PDB)
+ {
+ if (PLUG_IN)
+ PDB = _gimp_pdb_new (PLUG_IN);
+ }
+
+ return PDB;
+}
+
/**
* gimp_quit:
*
@@ -748,7 +770,7 @@ gimp_run_procedure_with_array (const gchar *name,
gimp_wire_destroy (&msg);
- gimp_set_pdb_error (return_values);
+ _gimp_set_pdb_error (return_values);
return return_values;
}
@@ -1404,8 +1426,8 @@ _gimp_config (GPConfig *config)
_gimp_shm_open (config->shm_ID);
}
-static void
-gimp_set_pdb_error (GimpValueArray *return_values)
+void
+_gimp_set_pdb_error (GimpValueArray *return_values)
{
g_clear_pointer (&pdb_error_message, g_free);
pdb_error_status = GIMP_PDB_SUCCESS;
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index 81d42dc208..19479beefa 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -281,6 +281,7 @@ EXPORTS
gimp_get_monitor_resolution
gimp_get_parasite
gimp_get_parasite_list
+ gimp_get_pdb
gimp_get_pdb_error
gimp_get_pdb_status
gimp_get_plug_in
@@ -611,18 +612,20 @@ EXPORTS
gimp_patterns_popup
gimp_patterns_refresh
gimp_patterns_set_popup
- gimp_pdb_get_type
gimp_pdb_dump
gimp_pdb_get_data
gimp_pdb_get_data_size
- gimp_pdb_lookup
+ gimp_pdb_get_type
+ gimp_pdb_lookup_procedure
gimp_pdb_proc_arg
gimp_pdb_proc_argument
gimp_pdb_proc_exists
gimp_pdb_proc_info
gimp_pdb_proc_return_value
gimp_pdb_proc_val
+ gimp_pdb_procedure_exists
gimp_pdb_query
+ gimp_pdb_run_procedure
gimp_pdb_set_data
gimp_pdb_temp_name
gimp_pencil
diff --git a/libgimp/gimp.h b/libgimp/gimp.h
index 96b1964fa9..57852531a1 100644
--- a/libgimp/gimp.h
+++ b/libgimp/gimp.h
@@ -148,6 +148,10 @@ gint gimp_main (GType plug_in_type,
*/
GimpPlugIn * gimp_get_plug_in (void);
+/* Return the GimpPlugIn singleton of this plug-in process
+ */
+GimpPDB * gimp_get_pdb (void);
+
/* Forcefully causes the gimp library to exit and
* close down its connection to main gimp application.
*/
diff --git a/libgimp/gimppdb.c b/libgimp/gimppdb.c
index 2dad64c7a8..6aad0f3a82 100644
--- a/libgimp/gimppdb.c
+++ b/libgimp/gimppdb.c
@@ -21,8 +21,15 @@
#include "config.h"
#include "gimp.h"
+
+#include "libgimpbase/gimpprotocol.h"
+#include "libgimpbase/gimpwire.h"
+
+#include "gimp-private.h"
+#include "gimpgpparams.h"
#include "gimppdb-private.h"
#include "gimppdbprocedure.h"
+#include "gimpplugin-private.h"
/**
@@ -102,29 +109,89 @@ _gimp_pdb_get_plug_in (GimpPDB *pdb)
return pdb->priv->plug_in;
}
+/**
+ * gimp_pdb_procedure_exists:
+ * @pdb: A #GimpPDB instance.
+ * @procedure_name: A procedure name
+ *
+ * This function checks if a procedure exists in the procedural
+ * database.
+ *
+ * Return: %TRUE if the procedure exists, %FALSE otherwise.
+ *
+ * Since: 3.0
+ **/
+gboolean
+gimp_pdb_procedure_exists (GimpPDB *pdb,
+ const gchar *procedure_name)
+{
+ g_return_val_if_fail (GIMP_IS_PDB (pdb), FALSE);
+ g_return_val_if_fail (procedure_name != NULL, FALSE);
+
+ return _gimp_pdb_proc_exists (procedure_name);
+}
+
GimpProcedure *
-gimp_pdb_lookup (GimpPDB *pdb,
- const gchar *name)
+gimp_pdb_lookup_procedure (GimpPDB *pdb,
+ const gchar *procedure_name)
{
GimpProcedure *procedure;
g_return_val_if_fail (GIMP_IS_PDB (pdb), NULL);
- g_return_val_if_fail (name != NULL, NULL);
+ g_return_val_if_fail (procedure_name != NULL, NULL);
- procedure = g_hash_table_lookup (pdb->priv->procedures, name);
+ procedure = g_hash_table_lookup (pdb->priv->procedures, procedure_name);
if (! procedure)
{
- procedure = _gimp_pdb_procedure_new (pdb, name);
+ procedure = _gimp_pdb_procedure_new (pdb, procedure_name);
if (procedure)
g_hash_table_insert (pdb->priv->procedures,
- g_strdup (name), procedure);
+ g_strdup (procedure_name), procedure);
}
return procedure;
}
+GimpValueArray *
+gimp_pdb_run_procedure (GimpPDB *pdb,
+ const gchar *procedure_name,
+ GimpValueArray *arguments)
+{
+ GPProcRun proc_run;
+ GPProcReturn *proc_return;
+ GimpWireMessage msg;
+ GimpValueArray *return_values;
+
+ g_return_val_if_fail (GIMP_IS_PDB (pdb), NULL);
+ g_return_val_if_fail (procedure_name != NULL, NULL);
+ g_return_val_if_fail (arguments != NULL, NULL);
+
+ proc_run.name = (gchar *) procedure_name;
+ proc_run.nparams = gimp_value_array_length (arguments);
+ proc_run.params = _gimp_value_array_to_gp_params (arguments, FALSE);
+
+ if (! gp_proc_run_write (_gimp_writechannel, &proc_run, NULL))
+ gimp_quit ();
+
+ _gimp_plug_in_read_expect_msg (pdb->priv->plug_in, &msg, GP_PROC_RETURN);
+
+ proc_return = msg.data;
+
+ return_values = _gimp_gp_params_to_value_array (NULL,
+ NULL, 0,
+ proc_return->params,
+ proc_return->nparams,
+ TRUE, FALSE);
+
+ gimp_wire_destroy (&msg);
+
+ _gimp_set_pdb_error (return_values);
+
+ return return_values;
+}
+
GQuark
_gimp_pdb_error_quark (void)
{
@@ -134,6 +201,25 @@ _gimp_pdb_error_quark (void)
/* Cruft API */
+/**
+ * gimp_pdb_proc_exists:
+ * @procedure_name: The procedure name.
+ *
+ * Checks if the specified procedure exists in the procedural database
+ *
+ * This procedure checks if the specified procedure is registered in
+ * the procedural database.
+ *
+ * Returns: Whether a procedure of that name is registered.
+ *
+ * Since: 2.6
+ **/
+gboolean
+gimp_pdb_proc_exists (const gchar *procedure_name)
+{
+ return _gimp_pdb_proc_exists (procedure_name);
+}
+
/**
* gimp_pdb_proc_info:
* @procedure: The procedure name.
@@ -160,7 +246,7 @@ _gimp_pdb_error_quark (void)
* Returns: TRUE on success.
*/
gboolean
-gimp_pdb_proc_info (const gchar *procedure,
+gimp_pdb_proc_info (const gchar *procedure_name,
gchar **blurb,
gchar **help,
gchar **author,
@@ -175,7 +261,7 @@ gimp_pdb_proc_info (const gchar *procedure,
gint i;
gboolean success = TRUE;
- success = _gimp_pdb_proc_info (procedure,
+ success = _gimp_pdb_proc_info (procedure_name,
blurb,
help,
author,
@@ -192,7 +278,7 @@ gimp_pdb_proc_info (const gchar *procedure,
for (i = 0; i < *num_args; i++)
{
- if (! gimp_pdb_proc_arg (procedure, i,
+ if (! gimp_pdb_proc_arg (procedure_name, i,
&(*args)[i].type,
&(*args)[i].name,
&(*args)[i].description))
@@ -206,7 +292,7 @@ gimp_pdb_proc_info (const gchar *procedure,
for (i = 0; i < *num_values; i++)
{
- if (! gimp_pdb_proc_val (procedure, i,
+ if (! gimp_pdb_proc_val (procedure_name, i,
&(*return_vals)[i].type,
&(*return_vals)[i].name,
&(*return_vals)[i].description))
@@ -217,11 +303,66 @@ gimp_pdb_proc_info (const gchar *procedure,
return FALSE;
}
}
- }
+ }
return success;
}
+/**
+ * gimp_pdb_proc_arg:
+ * @procedure_name: The procedure name.
+ * @arg_num: The argument number.
+ * @arg_type: (out): The type of argument.
+ * @arg_name: (out) (transfer full): The name of the argument.
+ * @arg_desc: (out) (transfer full): A description of the argument.
+ *
+ * Queries the procedural database for information on the specified
+ * procedure's argument.
+ *
+ * This procedure returns information on the specified procedure's
+ * argument. The argument type, name, and a description are retrieved.
+ *
+ * Returns: TRUE on success.
+ **/
+gboolean
+gimp_pdb_proc_arg (const gchar *procedure_name,
+ gint arg_num,
+ GimpPDBArgType *arg_type,
+ gchar **arg_name,
+ gchar **arg_desc)
+{
+ return _gimp_pdb_proc_arg (procedure_name, arg_num,
+ arg_type, arg_name, arg_desc);
+}
+
+/**
+ * gimp_pdb_proc_val:
+ * @procedure_name: The procedure name.
+ * @val_num: The return value number.
+ * @val_type: (out): The type of return value.
+ * @val_name: (out) (transfer full): The name of the return value.
+ * @val_desc: (out) (transfer full): A description of the return value.
+ *
+ * Queries the procedural database for information on the specified
+ * procedure's return value.
+ *
+ * This procedure returns information on the specified procedure's
+ * return value. The return value type, name, and a description are
+ * retrieved.
+ *
+ * Returns: TRUE on success.
+ **/
+gboolean
+gimp_pdb_proc_val (const gchar *procedure_name,
+ gint val_num,
+ GimpPDBArgType *val_type,
+ gchar **val_name,
+ gchar **val_desc)
+{
+ return _gimp_pdb_proc_val (procedure_name, val_num,
+ val_type, val_name, val_desc);
+}
+
/**
* gimp_pdb_get_data:
* @identifier: The identifier associated with data.
@@ -255,6 +396,24 @@ gimp_pdb_get_data (const gchar *identifier,
return success;
}
+/**
+ * gimp_pdb_get_data_size:
+ * @identifier: The identifier associated with data.
+ *
+ * Returns size of data associated with the specified identifier.
+ *
+ * This procedure returns the size of any data which may have been
+ * associated with the specified identifier. If no data has been
+ * associated with the identifier, an error is returned.
+ *
+ * Returns: The number of bytes in the data.
+ **/
+gint
+gimp_pdb_get_data_size (const gchar *identifier)
+{
+ return _gimp_pdb_get_data_size (identifier);
+}
+
/**
* gimp_pdb_set_data:
* @identifier: The identifier associated with data.
diff --git a/libgimp/gimppdb.h b/libgimp/gimppdb.h
index 54e884e693..c7af7b6acc 100644
--- a/libgimp/gimppdb.h
+++ b/libgimp/gimppdb.h
@@ -65,30 +65,49 @@ struct _GimpPDBClass
};
-GType gimp_pdb_get_type (void) G_GNUC_CONST;
+GType gimp_pdb_get_type (void) G_GNUC_CONST;
-GimpProcedure * gimp_pdb_lookup (GimpPDB *pdb,
- const gchar *name);
+gboolean gimp_pdb_procedure_exists (GimpPDB *pdb,
+ const gchar *procedure_name);
+
+GimpProcedure * gimp_pdb_lookup_procedure (GimpPDB *pdb,
+ const gchar *procedure_name);
+
+GimpValueArray * gimp_pdb_run_procedure (GimpPDB *pdb,
+ const gchar *procedure_name,
+ GimpValueArray *arguments);
/* Cruft API */
-gboolean gimp_pdb_proc_info (const gchar *procedure,
- gchar **blurb,
- gchar **help,
- gchar **author,
- gchar **copyright,
- gchar **date,
- GimpPDBProcType *proc_type,
- gint *num_args,
- gint *num_values,
- GimpParamDef **args,
- GimpParamDef **return_vals);
-gboolean gimp_pdb_get_data (const gchar *identifier,
- gpointer data);
-gboolean gimp_pdb_set_data (const gchar *identifier,
- gconstpointer data,
- guint32 bytes);
+gboolean gimp_pdb_proc_exists (const gchar *procedure_name);
+gboolean gimp_pdb_proc_info (const gchar *procedure_name,
+ gchar **blurb,
+ gchar **help,
+ gchar **author,
+ gchar **copyright,
+ gchar **date,
+ GimpPDBProcType *proc_type,
+ gint *num_args,
+ gint *num_values,
+ GimpParamDef **args,
+ GimpParamDef **return_vals);
+gboolean gimp_pdb_proc_arg (const gchar *procedure_name,
+ gint arg_num,
+ GimpPDBArgType *arg_type,
+ gchar **arg_name,
+ gchar **arg_desc);
+gboolean gimp_pdb_proc_val (const gchar *procedure_name,
+ gint val_num,
+ GimpPDBArgType *val_type,
+ gchar **val_name,
+ gchar **val_desc);
+gboolean gimp_pdb_get_data (const gchar *identifier,
+ gpointer data);
+gint gimp_pdb_get_data_size (const gchar *identifier);
+gboolean gimp_pdb_set_data (const gchar *identifier,
+ gconstpointer data,
+ guint32 bytes);
diff --git a/libgimp/gimppdb_pdb.c b/libgimp/gimppdb_pdb.c
index 9c1eb8f7ea..882b7ecf7b 100644
--- a/libgimp/gimppdb_pdb.c
+++ b/libgimp/gimppdb_pdb.c
@@ -172,7 +172,7 @@ gimp_pdb_query (const gchar *name,
}
/**
- * gimp_pdb_proc_exists:
+ * _gimp_pdb_proc_exists:
* @procedure_name: The procedure name.
*
* Checks if the specified procedure exists in the procedural database
@@ -185,7 +185,7 @@ gimp_pdb_query (const gchar *name,
* Since: 2.6
**/
gboolean
-gimp_pdb_proc_exists (const gchar *procedure_name)
+_gimp_pdb_proc_exists (const gchar *procedure_name)
{
GimpValueArray *args;
GimpValueArray *return_vals;
@@ -283,7 +283,7 @@ _gimp_pdb_proc_info (const gchar *procedure_name,
}
/**
- * gimp_pdb_proc_arg:
+ * _gimp_pdb_proc_arg:
* @procedure_name: The procedure name.
* @arg_num: The argument number.
* @arg_type: (out): The type of argument.
@@ -299,11 +299,11 @@ _gimp_pdb_proc_info (const gchar *procedure_name,
* Returns: TRUE on success.
**/
gboolean
-gimp_pdb_proc_arg (const gchar *procedure_name,
- gint arg_num,
- GimpPDBArgType *arg_type,
- gchar **arg_name,
- gchar **arg_desc)
+_gimp_pdb_proc_arg (const gchar *procedure_name,
+ gint arg_num,
+ GimpPDBArgType *arg_type,
+ gchar **arg_name,
+ gchar **arg_desc)
{
GimpValueArray *args;
GimpValueArray *return_vals;
@@ -338,7 +338,7 @@ gimp_pdb_proc_arg (const gchar *procedure_name,
}
/**
- * gimp_pdb_proc_val:
+ * _gimp_pdb_proc_val:
* @procedure_name: The procedure name.
* @val_num: The return value number.
* @val_type: (out): The type of return value.
@@ -355,11 +355,11 @@ gimp_pdb_proc_arg (const gchar *procedure_name,
* Returns: TRUE on success.
**/
gboolean
-gimp_pdb_proc_val (const gchar *procedure_name,
- gint val_num,
- GimpPDBArgType *val_type,
- gchar **val_name,
- gchar **val_desc)
+_gimp_pdb_proc_val (const gchar *procedure_name,
+ gint val_num,
+ GimpPDBArgType *val_type,
+ gchar **val_name,
+ gchar **val_desc)
{
GimpValueArray *args;
GimpValueArray *return_vals;
@@ -525,7 +525,7 @@ _gimp_pdb_get_data (const gchar *identifier,
}
/**
- * gimp_pdb_get_data_size:
+ * _gimp_pdb_get_data_size:
* @identifier: The identifier associated with data.
*
* Returns size of data associated with the specified identifier.
@@ -537,7 +537,7 @@ _gimp_pdb_get_data (const gchar *identifier,
* Returns: The number of bytes in the data.
**/
gint
-gimp_pdb_get_data_size (const gchar *identifier)
+_gimp_pdb_get_data_size (const gchar *identifier)
{
GimpValueArray *args;
GimpValueArray *return_vals;
diff --git a/libgimp/gimppdb_pdb.h b/libgimp/gimppdb_pdb.h
index 47646dea1c..6c9ce95077 100644
--- a/libgimp/gimppdb_pdb.h
+++ b/libgimp/gimppdb_pdb.h
@@ -43,7 +43,7 @@ gboolean gimp_pdb_query (const gchar *name,
const gchar *proc_type,
gint *num_matches,
gchar ***procedure_names);
-gboolean gimp_pdb_proc_exists (const gchar *procedure_name);
+G_GNUC_INTERNAL gboolean _gimp_pdb_proc_exists (const gchar *procedure_name);
G_GNUC_INTERNAL gboolean _gimp_pdb_proc_info (const gchar *procedure_name,
gchar **blurb,
gchar **help,
@@ -53,12 +53,12 @@ G_GNUC_INTERNAL gboolean _gimp_pdb_proc_info (const gchar *procedur
GimpPDBProcType *proc_type,
gint *num_args,
gint *num_values);
-gboolean gimp_pdb_proc_arg (const gchar *procedure_name,
+G_GNUC_INTERNAL gboolean _gimp_pdb_proc_arg (const gchar *procedure_name,
gint arg_num,
GimpPDBArgType *arg_type,
gchar **arg_name,
gchar **arg_desc);
-gboolean gimp_pdb_proc_val (const gchar *procedure_name,
+G_GNUC_INTERNAL gboolean _gimp_pdb_proc_val (const gchar *procedure_name,
gint val_num,
GimpPDBArgType *val_type,
gchar **val_name,
@@ -70,7 +70,7 @@ GParamSpec* gimp_pdb_proc_return_value (const gchar *procedur
G_GNUC_INTERNAL gboolean _gimp_pdb_get_data (const gchar *identifier,
gint *bytes,
guint8 **data);
-gint gimp_pdb_get_data_size (const gchar *identifier);
+G_GNUC_INTERNAL gint _gimp_pdb_get_data_size (const gchar *identifier);
G_GNUC_INTERNAL gboolean _gimp_pdb_set_data (const gchar *identifier,
gint bytes,
const guint8 *data);
diff --git a/pdb/groups/pdb.pdb b/pdb/groups/pdb.pdb
index 1148d0a416..4f017b5191 100644
--- a/pdb/groups/pdb.pdb
+++ b/pdb/groups/pdb.pdb
@@ -152,7 +152,7 @@ HELP
);
@outargs = (
- { name => 'exists', type => 'boolean',
+ { name => 'exists', type => 'boolean', wrap => 1,
desc => 'Whether a procedure of that name is registered' }
);
@@ -377,7 +377,7 @@ HELP
$date = '1997';
@inargs = (
- { name => 'procedure_name', type => 'string', non_empty => 1,
+ { name => 'procedure_name', type => 'string', non_empty => 1, wrap => 1,
desc => 'The procedure name' },
{ name => 'arg_num', type => 'int32',
desc => 'The argument number' }
@@ -445,7 +445,7 @@ HELP
$date = '1997';
@inargs = (
- { name => 'procedure_name', type => 'string', non_empty => 1,
+ { name => 'procedure_name', type => 'string', non_empty => 1, wrap => 1,
desc => 'The procedure name' },
{ name => 'val_num', type => 'int32',
desc => 'The return value number' }
@@ -554,7 +554,7 @@ HELP
&nick_pdb_misc('1998');
@inargs = (
- { name => 'identifier', type => 'string', non_empty => 1,
+ { name => 'identifier', type => 'string', non_empty => 1, wrap => 1,
desc => 'The identifier associated with data' }
);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]