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