irplib_plugin.h

00001 /* $Id: irplib_plugin.h,v 1.18 2007/08/22 11:19:15 llundin Exp $
00002  *
00003  * This file is part of the irplib package 
00004  * Copyright (C) 2002,2003 European Southern Observatory
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: llundin $
00023  * $Date: 2007/08/22 11:19:15 $
00024  * $Revision: 1.18 $
00025  * $Name: uves-3_4_5 $
00026  */
00027 
00028 #ifndef IRPLIB_PLUGIN_H
00029 #define IRPLIB_PLUGIN_H
00030 
00031 /*-----------------------------------------------------------------------------
00032                                    Includes
00033  -----------------------------------------------------------------------------*/
00034 
00035 #include <irplib_utils.h>  /* irplib_reset() */
00036 
00037 #include <cpl.h>
00038 
00039 /*-----------------------------------------------------------------------------
00040                                    Define
00041  -----------------------------------------------------------------------------*/
00042 
00043 /* Needed to concatenate two macro arguments */
00044 #define IRPLIB_CONCAT(a,b) a ## _ ## b
00045 #define IRPLIB_CONCAT2X(a,b) IRPLIB_CONCAT(a,b)
00046 
00047 /* A macro to generate the pipeline copyright and license */
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    /* The prototypes of the recipe create, exec and destroy functions */       \
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    /* The prototype of the function called by the recipe exec function */      \
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     /* Verify that the compile-time and run-time versions of CPL match */      \
00138     /* - this will work for run-time versions going back to CPL 3.0    */      \
00139     /* - earlier versions will cause an exit with an unresolved symbol */      \
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    /* The definition of the recipe create function */                          \
00194 static int IRPLIB_CONCAT2X(RECIPE_NAME,create)(cpl_plugin * plugin)            \
00195 {                                                                              \
00196     cpl_recipe * recipe;                                                       \
00197                                                                                \
00198     /* Do not create the recipe if an error code is already set */             \
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     /* Verify plugin type */                                                   \
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     /* Get the recipe */                                                       \
00217     recipe = (cpl_recipe *)plugin;                                             \
00218                                                                                \
00219     /* Create the parameters list in the cpl_recipe object */                  \
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     /* Fill the parameters list */                                             \
00227     return(RECIPE_FILL_PARAMS);                                                \
00228 }                                                                              \
00229                                                                                \
00230    /* The definition of the recipe exec function */                            \
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     /* Return immediately if an error code is already set */                   \
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     /* Verify plugin type */                                                   \
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     /* Get the recipe */                                                       \
00256     recipe = (cpl_recipe *)plugin;                                             \
00257                                                                                \
00258     /* Verify parameter and frame lists */                                     \
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     /* Reset the IRPLIB internal state before actually starting */             \
00269     irplib_reset();                                                            \
00270                                                                                \
00271     /* Invoke the recipe */                                                    \
00272     recipe_status = RECIPE_NAME(recipe->frames, recipe->parameters);           \
00273                                                                                \
00274     if (!cpl_errorstate_is_equal(initial_errorstate)) {                        \
00275         /* Dump the error history since recipe execution start.                \
00276            At this point the recipe cannot recover from the error */           \
00277         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              \
00278     }                                                                          \
00279                                                                                \
00280     return recipe_status;                                                      \
00281 }                                                                              \
00282                                                                                \
00283    /* The definition of the recipe destroy function */                         \
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     /* Verify plugin type */                                                   \
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     /* Get the recipe */                                                       \
00300     recipe = (cpl_recipe *)plugin;                                             \
00301                                                                                \
00302     if (recipe->parameters != NULL)                                            \
00303         cpl_parameterlist_delete(recipe->parameters);                          \
00304                                                                                \
00305     return  0;                                                                 \
00306 }                                                                              \
00307                                                                                \
00308   /* This dummy declaration requires the macro to be invoked as if it was      \
00309      a kind of function definition, with a terminating ; */                    \
00310 extern int irplib_plugin_end
00311 
00312 /*-----------------------------------------------------------------------------
00313                                    Function prototypes
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

Generated on Thu Nov 15 14:32:26 2007 for UVES Pipeline Reference Manual by  doxygen 1.5.1