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