gimpproceduraldb.c 5.55 KB
Newer Older
1 2 3 4 5
/* LIBGIMP - The GIMP Library
 * Copyright (C) 1995-2000 Peter Mattis and Spencer Kimball
 *
 * gimpproceduraldb.c
 *
6
 * This library is free software: you can redistribute it and/or
7 8
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
9
 * version 3 of the License, or (at your option) any later version.
10 11 12 13 14 15 16
 *
 * 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
17 18
 * License along with this library.  If not, see
 * <http://www.gnu.org/licenses/>.
19 20
 */

Sven Neumann's avatar
Sven Neumann committed
21 22
#include "config.h"

23 24
#include <string.h> /* memcmp */

25 26
#include "gimp.h"

27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
/**
 * gimp_procedural_db_proc_info:
 * @procedure: The procedure name.
 * @blurb: A short blurb.
 * @help: Detailed procedure help.
 * @author: Author(s) of the procedure.
 * @copyright: The copyright.
 * @date: Copyright date.
 * @proc_type: The procedure type.
 * @num_args: The number of input arguments.
 * @num_values: The number of return values.
 * @args: The input arguments.
 * @return_vals: The return values.
 *
 * Queries the procedural database for information on the specified
 * procedure.
 *
 * This procedure returns information on the specified procedure. A
 * short blurb, detailed help, author(s), copyright information,
46 47
 * procedure type, number of input, and number of return values are
 * returned. Additionally this function returns specific information
48 49 50 51
 * about each input argument and return value.
 *
 * Returns: TRUE on success.
 */
52
gboolean
53
gimp_procedural_db_proc_info (const gchar      *procedure,
Sven Neumann's avatar
Sven Neumann committed
54 55 56 57 58 59 60 61 62 63
                              gchar           **blurb,
                              gchar           **help,
                              gchar           **author,
                              gchar           **copyright,
                              gchar           **date,
                              GimpPDBProcType  *proc_type,
                              gint             *num_args,
                              gint             *num_values,
                              GimpParamDef    **args,
                              GimpParamDef    **return_vals)
64 65 66 67
{
  gint i;
  gboolean success = TRUE;

68
  success = _gimp_procedural_db_proc_info (procedure,
Sven Neumann's avatar
Sven Neumann committed
69 70 71 72 73 74 75 76
                                           blurb,
                                           help,
                                           author,
                                           copyright,
                                           date,
                                           proc_type,
                                           num_args,
                                           num_values);
77 78 79 80 81 82 83 84 85

  if (success)
    {
      *args        = g_new (GimpParamDef, *num_args);
      *return_vals = g_new (GimpParamDef, *num_values);

      for (i = 0; i < *num_args; i++)
        {
          if (! gimp_procedural_db_proc_arg (procedure,
Sven Neumann's avatar
Sven Neumann committed
86 87 88 89
                                             i,
                                             &(*args)[i].type,
                                             &(*args)[i].name,
                                             &(*args)[i].description))
90 91 92 93 94 95 96 97 98 99 100
            {
              g_free (*args);
              g_free (*return_vals);

              return FALSE;
            }
        }

      for (i = 0; i < *num_values; i++)
        {
          if (! gimp_procedural_db_proc_val (procedure,
Sven Neumann's avatar
Sven Neumann committed
101 102 103 104
                                             i,
                                             &(*return_vals)[i].type,
                                             &(*return_vals)[i].name,
                                             &(*return_vals)[i].description))
105 106 107 108 109 110 111 112 113 114 115 116
            {
              g_free (*args);
              g_free (*return_vals);

              return FALSE;
            }
        }
     }

  return success;
}

117 118 119 120 121 122 123 124
/**
 * gimp_procedural_db_get_data:
 * @identifier: The identifier associated with data.
 * @data: A byte array containing data.
 *
 * Returns data associated with the specified identifier.
 *
 * This procedure returns any data which may have been associated with
125
 * the specified identifier. The data is copied into the given memory
126 127
 * location.
 *
128
 * Returns: TRUE on success, FALSE if no data has been associated with
129 130
 * the identifier
 */
131
gboolean
132
gimp_procedural_db_get_data (const gchar *identifier,
Sven Neumann's avatar
Sven Neumann committed
133
                             gpointer     data)
134
{
135 136 137
  gint      size;
  guint8   *hack;
  gboolean  success;
138

139
  success = _gimp_procedural_db_get_data (identifier,
Sven Neumann's avatar
Sven Neumann committed
140 141
                                          &size,
                                          &hack);
142 143
  if (hack)
    {
Sven Neumann's avatar
Sven Neumann committed
144
      memcpy (data, (gconstpointer) hack, size * sizeof (guint8));
145 146
      g_free (hack);
    }
147

148
  return success;
149 150
}

151 152 153 154
/**
 * gimp_procedural_db_set_data:
 * @identifier: The identifier associated with data.
 * @data: A byte array containing data.
155
 * @bytes: The number of bytes in the data
156 157 158 159 160 161 162 163 164
 *
 * Associates the specified identifier with the supplied data.
 *
 * This procedure associates the supplied data with the provided
 * identifier. The data may be subsequently retrieved by a call to
 * 'procedural-db-get-data'.
 *
 * Returns: TRUE on success.
 */
165
gboolean
Sven Neumann's avatar
Sven Neumann committed
166 167 168
gimp_procedural_db_set_data (const gchar   *identifier,
                             gconstpointer  data,
                             guint32        bytes)
169
{
170
  return _gimp_procedural_db_set_data (identifier,
Sven Neumann's avatar
Sven Neumann committed
171 172
                                       bytes,
                                       data);
173
}