00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef IRPLIB_PLUGIN_H
00029 #define IRPLIB_PLUGIN_H
00030
00031
00032
00033
00034
00035 #include <irplib_utils.h>
00036 #include <irplib_error.h>
00037
00038 #include <cpl.h>
00039
00040
00041
00042
00043
00044
00045 #define IRPLIB_CONCAT(a,b) a ## _ ## b
00046 #define IRPLIB_CONCAT2X(a,b) IRPLIB_CONCAT(a,b)
00047
00048
00049 #define irplib_get_license(PACKAGE_NAME, YEAR) \
00050 "This file is part of the " PACKAGE_NAME "\n" \
00051 "Copyright (C) " YEAR " European Southern Observatory\n" \
00052 "\n" \
00053 "This program is free software; you can redistribute it and/or modify\n" \
00054 "it under the terms of the GNU General Public License as published by\n" \
00055 "the Free Software Foundation; either version 2 of the License, or\n" \
00056 "(at your option) any later version.\n" \
00057 "\n" \
00058 "This program is distributed in the hope that it will be useful,\n" \
00059 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" \
00060 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" \
00061 "GNU General Public License for more details.\n" \
00062 "\n" \
00063 "You should have received a copy of the GNU General Public License\n" \
00064 "along with this program; if not, write to the Free Software\n" \
00065 "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, \n" \
00066 "MA 02111-1307 USA"
00067
00068 #if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(3, 1, 0)
00069 #define IRPLIB_DFS_UPDATE_PRODUCT_HEADER \
00070 do if (cpl_dfs_update_product_header(recipe->frames)) { \
00071 recipe_status = cpl_error_get_code(); \
00072 } while (0)
00073 #else
00074 #define IRPLIB_DFS_UPDATE_PRODUCT_HEADER
00075 #endif
00076
00077
00078
00079
00131
00132
00133 #define IRPLIB_RECIPE_DEFINE(RECIPE_NAME, RECIPE_VERSION, RECIPE_FILL_PARAMS, \
00134 RECIPE_AUTHOR, RECIPE_AUTHOR_EMAIL, RECIPE_YEAR, \
00135 RECIPE_SYNOPSIS, RECIPE_DESCRIPTION) \
00136 \
00137 \
00138 static int IRPLIB_CONCAT2X(RECIPE_NAME,create) (cpl_plugin * plugin); \
00139 static int IRPLIB_CONCAT2X(RECIPE_NAME,exec) (cpl_plugin * plugin); \
00140 static int IRPLIB_CONCAT2X(RECIPE_NAME,destroy)(cpl_plugin * plugin); \
00141 \
00142 \
00143 static int RECIPE_NAME(cpl_frameset *, const cpl_parameterlist *); \
00144 \
00145 int cpl_plugin_get_info(cpl_pluginlist * list) \
00146 { \
00147 cpl_recipe * recipe; \
00148 cpl_plugin * plugin; \
00149 \
00150 recipe = cpl_calloc(1, sizeof(*recipe)); \
00151 if (recipe == NULL) { \
00152 cpl_msg_error(cpl_func, "Recipe allocation failed"); \
00153 (void)cpl_error_set(cpl_func, CPL_ERROR_ILLEGAL_OUTPUT); \
00154 return 1; \
00155 } \
00156 \
00157 plugin = &recipe->interface; \
00158 \
00159 if (cpl_plugin_init(plugin, \
00160 CPL_PLUGIN_API, \
00161 RECIPE_VERSION, \
00162 CPL_PLUGIN_TYPE_RECIPE, \
00163 #RECIPE_NAME, \
00164 RECIPE_SYNOPSIS, \
00165 RECIPE_DESCRIPTION, \
00166 RECIPE_AUTHOR, \
00167 RECIPE_AUTHOR_EMAIL, \
00168 irplib_get_license(PACKAGE_NAME, RECIPE_YEAR), \
00169 IRPLIB_CONCAT2X(RECIPE_NAME,create), \
00170 IRPLIB_CONCAT2X(RECIPE_NAME,exec), \
00171 IRPLIB_CONCAT2X(RECIPE_NAME,destroy))) { \
00172 cpl_msg_error(cpl_func, "Plugin initialization failed"); \
00173 cpl_error_set_where(cpl_func); \
00174 return 1; \
00175 } \
00176 \
00177 if (cpl_pluginlist_append(list, plugin)) { \
00178 cpl_msg_error(cpl_func, "Error adding plugin to list"); \
00179 cpl_error_set_where(cpl_func); \
00180 return 1; \
00181 } \
00182 \
00183 return 0; \
00184 } \
00185 \
00186 \
00187 static int IRPLIB_CONCAT2X(RECIPE_NAME,create)(cpl_plugin * plugin) \
00188 { \
00189 cpl_recipe * recipe; \
00190 \
00191 \
00192 if (cpl_error_get_code() != CPL_ERROR_NONE) { \
00193 cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s", \
00194 cpl_func, __LINE__, cpl_error_get_where()); \
00195 return (int)cpl_error_get_code(); \
00196 } \
00197 \
00198 if (plugin == NULL) { \
00199 cpl_msg_error(cpl_func, "Null plugin"); \
00200 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT); \
00201 } \
00202 \
00203 \
00204 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) { \
00205 cpl_msg_error(cpl_func, "Plugin is not a recipe"); \
00206 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH); \
00207 } \
00208 \
00209 \
00210 recipe = (cpl_recipe *)plugin; \
00211 \
00212 \
00213 recipe->parameters = cpl_parameterlist_new(); \
00214 if (recipe->parameters == NULL) { \
00215 cpl_msg_error(cpl_func, "Parameter list allocation failed"); \
00216 cpl_ensure_code(0, (int)CPL_ERROR_ILLEGAL_OUTPUT); \
00217 } \
00218 \
00219 \
00220 return(RECIPE_FILL_PARAMS); \
00221 } \
00222 \
00223 \
00224 static int IRPLIB_CONCAT2X(RECIPE_NAME,exec)(cpl_plugin * plugin) \
00225 { \
00226 cpl_recipe * recipe; \
00227 int recipe_status; \
00228 \
00229 \
00230 if (cpl_error_get_code() != CPL_ERROR_NONE) { \
00231 cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s", \
00232 cpl_func, __LINE__, cpl_error_get_where()); \
00233 return (int)cpl_error_get_code(); \
00234 } \
00235 \
00236 if (plugin == NULL) { \
00237 cpl_msg_error(cpl_func, "Null plugin"); \
00238 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT); \
00239 } \
00240 \
00241 \
00242 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) { \
00243 cpl_msg_error(cpl_func, "Plugin is not a recipe"); \
00244 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH); \
00245 } \
00246 \
00247 \
00248 recipe = (cpl_recipe *)plugin; \
00249 \
00250 \
00251 if (recipe->parameters == NULL) { \
00252 cpl_msg_error(cpl_func, "Recipe invoked with NULL parameter list"); \
00253 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT); \
00254 } \
00255 if (recipe->frames == NULL) { \
00256 cpl_msg_error(cpl_func, "Recipe invoked with NULL frame set"); \
00257 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT); \
00258 } \
00259 \
00260 \
00261 irplib_reset(); \
00262 \
00263 \
00264 recipe_status = RECIPE_NAME(recipe->frames, recipe->parameters); \
00265 \
00266 \
00267 IRPLIB_DFS_UPDATE_PRODUCT_HEADER; \
00268 \
00269 if (cpl_error_get_code() != CPL_ERROR_NONE) { \
00270 \
00271 \
00272 irplib_error_dump(CPL_MSG_ERROR, CPL_MSG_ERROR); \
00273 } \
00274 \
00275 return recipe_status; \
00276 } \
00277 \
00278 \
00279 static int IRPLIB_CONCAT2X(RECIPE_NAME,destroy)(cpl_plugin * plugin) \
00280 { \
00281 cpl_recipe * recipe; \
00282 \
00283 if (plugin == NULL) { \
00284 cpl_msg_error(cpl_func, "Null plugin"); \
00285 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT); \
00286 } \
00287 \
00288 \
00289 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) { \
00290 cpl_msg_error(cpl_func, "Plugin is not a recipe"); \
00291 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH); \
00292 } \
00293 \
00294 \
00295 recipe = (cpl_recipe *)plugin; \
00296 \
00297 if (recipe->parameters != NULL) \
00298 cpl_parameterlist_delete(recipe->parameters); \
00299 \
00300 return 0; \
00301 } \
00302 \
00303
00304 \
00305 extern int irplib_plugin_end
00306
00307
00308
00309
00310
00311 int irplib_plugin_test(cpl_pluginlist *, size_t, const char *[]);
00312
00313 cpl_error_code irplib_parameterlist_set_string(cpl_parameterlist *,
00314 const char *, const char *,
00315 const char *, const char *,
00316 const char *, const char *,
00317 const char *);
00318
00319 cpl_error_code irplib_parameterlist_set_bool(cpl_parameterlist *,
00320 const char *, const char *,
00321 const char *, cpl_boolean,
00322 const char *, const char *,
00323 const char *);
00324
00325 cpl_error_code irplib_parameterlist_set_int(cpl_parameterlist *,
00326 const char *, const char *,
00327 const char *, int,
00328 const char *, const char *,
00329 const char *);
00330
00331 cpl_error_code irplib_parameterlist_set_double(cpl_parameterlist *,
00332 const char *, const char *,
00333 const char *, double,
00334 const char *, const char *,
00335 const char *);
00336
00337 const char * irplib_parameterlist_get_string(const cpl_parameterlist *,
00338 const char *, const char *,
00339 const char *);
00340
00341 cpl_boolean irplib_parameterlist_get_bool(const cpl_parameterlist *,
00342 const char *, const char *,
00343 const char *);
00344
00345 int irplib_parameterlist_get_int(const cpl_parameterlist *,
00346 const char *, const char *,
00347 const char *);
00348
00349 double irplib_parameterlist_get_double(const cpl_parameterlist *,
00350 const char *, const char *,
00351 const char *);
00352
00353 #endif