uves_plugin.h

00001 /* $Id: uves_plugin.h,v 1.1 2008/03/28 08:56:45 amodigli Exp $
00002  *
00003  * This file is part of the UVES 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: amodigli $
00023  * $Date: 2008/03/28 08:56:45 $
00024  * $Revision: 1.1 $
00025  * $Name: uves-5_0_0 $
00026  */
00027 
00028 #ifndef UVES_PLUGIN_H
00029 #define UVES_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 UVES_CONCAT(a,b) a ## _ ## b
00045 #define UVES_CONCAT2X(a,b) UVES_CONCAT(a,b)
00046 
00047 /* A macro to generate the pipeline copyright and license */
00048 #ifdef cpl_get_license
00049 #define uves_irplib_get_license cpl_get_license
00050 #else
00051 /* FIXME: Drop once CPL 4.0 is no longer supported */
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 /* FIXME: Drop once CPL 4.0 is no longer supported */
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    /* The prototypes of the recipe create, exec and destroy functions */       \
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    /* The prototype of the function called by the recipe exec function */      \
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     /* Verify that the compile-time and run-time versions of CPL match */      \
00147     /* - this will work for run-time versions going back to CPL 3.0    */      \
00148     /* - earlier versions will cause an exit with an unresolved symbol */      \
00149     const unsigned vruntime = CPL_VERSION(cpl_version_get_major(),             \
00150                                           cpl_version_get_minor(),             \
00151                                           cpl_version_get_micro());            \
00152     /* The version number of the first major version */                        \
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    /* The definition of the recipe create function */                          \
00205 static int UVES_CONCAT2X(RECIPE_NAME,create)(cpl_plugin * plugin)            \
00206 {                                                                              \
00207     cpl_recipe * recipe;                                                       \
00208                                                                                \
00209     /* Do not create the recipe if an error code is already set */             \
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     /* Verify plugin type */                                                   \
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     /* Get the recipe */                                                       \
00228     recipe = (cpl_recipe *)plugin;                                             \
00229                                                                                \
00230     /* Create the parameters list in the cpl_recipe object */                  \
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     /* Fill the parameters list */                                             \
00238     return(RECIPE_FILL_PARAMS);                                                \
00239 }                                                                              \
00240                                                                                \
00241    /* The definition of the recipe exec function */                            \
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     /* Return immediately if an error code is already set */                   \
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     /* Verify plugin type */                                                   \
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     /* Get the recipe */                                                       \
00267     recipe = (cpl_recipe *)plugin;                                             \
00268                                                                                \
00269     /* Verify parameter and frame lists */                                     \
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     /* Reset the UVES internal state before actually starting */             \
00280     irplib_reset();                                                            \
00281                                                                                \
00282     /* Invoke the recipe */                                                    \
00283     recipe_status = RECIPE_NAME(recipe->frames, recipe->parameters);           \
00284                                                                                \
00285     if (!cpl_errorstate_is_equal(initial_errorstate)) {                        \
00286         /* Dump the error history since recipe execution start.                \
00287            At this point the recipe cannot recover from the error */           \
00288         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              \
00289     }                                                                          \
00290                                                                                \
00291     return recipe_status;                                                      \
00292 }                                                                              \
00293                                                                                \
00294    /* The definition of the recipe destroy function */                         \
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     /* Verify plugin type */                                                   \
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     /* Get the recipe */                                                       \
00311     recipe = (cpl_recipe *)plugin;                                             \
00312                                                                                \
00313     if (recipe->parameters != NULL)                                            \
00314         cpl_parameterlist_delete(recipe->parameters);                          \
00315                                                                                \
00316     return  0;                                                                 \
00317 }                                                                              \
00318                                                                                \
00319   /* This dummy declaration requires the macro to be invoked as if it was      \
00320      a kind of function definition, with a terminating ; */                    \
00321 extern int uves_plugin_end
00322 #endif
00323 
00324 /*-----------------------------------------------------------------------------
00325                                    Function prototypes
00326  -----------------------------------------------------------------------------*/
00327 
00328 
00329 #endif

Generated on 9 Mar 2012 for UVES Pipeline Reference Manual by  doxygen 1.6.1