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