IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 17, 2005, 1:37:11 PM (21 years ago)
Author:
gusciora
Message:

This code compiles, but has not been tested.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/config/pmConfig.c

    r5355 r5356  
    33 *  @author PAP, IfA
    44 *
    5  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2005-10-17 21:34:12 $
     5 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2005-10-17 23:37:11 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1313#include <assert.h>
    1414#include "pslib.h"
    15 #include "psAdditionals.h"
     15//#include "psAdditionals.h"
    1616#include "pmConfig.h"
    1717
    18 // XXX: These comments should have PS-specific prefixes.
    19 #define PS_SITE "PS_SITE"  // Name of the environment variable containing the site config file
    20 #define DEFAULT_SITE "ipprc.config" // Default site config file
     18#define PS_SITE "PS_SITE"               // Name of the environment variable containing the site config file
     19#define PS_DEFAULT_SITE "ipprc.config"     // Default site config file
    2120
    2221
     
    4140                 description, name);
    4241    }
    43     if (! *config) {
     42    if (!*config) {
    4443        psError(PS_ERR_IO, false, "Unable to read %s configuration from %s\n",
    4544                description, name);
    4645        return false;
    4746    }
     47
    4848    return true;
    4949}
    5050
    5151
    52 
     52/******************************************************************************
     53pmConfigRead(**site, **camera, **recipe, *argc, **argv, char *recipeName)
     54 
     55XXX: The log/trace command line options (as processed by psArgumentVerbosity)
     56must take precedence override the values set here.  This must be, somehow,
     57coded.
     58 *****************************************************************************/
    5359bool pmConfigRead(
    54     psMetadata **site, psMetadata **camera,
     60    psMetadata **site,
     61    psMetadata **camera,
    5562    psMetadata **recipe,
    5663    int *argc,
     
    7683    // First, try command line
    7784    //
    78     int argNum = 0;
    79     if ((argNum = psArgumentGet(*argc, argv, "-site"))) {
    80         (void)psArgumentRemove(argNum, argc, argv);
     85    psS32 argNum = psArgumentGet(*argc, argv, "-site");
     86    if (argNum != 0) {
     87        //
     88        // We remove the "-site" argument from argv.  Then
     89        // we look for the next argument, which should be the filename, and
     90        // remove it as well.
     91        //
     92        psArgumentRemove(argNum, argc, argv);
    8193        if (argNum >= *argc) {
    8294            psLogMsg(__func__, PS_LOG_WARN,
     
    8496        } else {
    8597            siteName = argv[argNum];
    86             (void)psArgumentRemove(argNum, argc, argv);
    87         }
    88     }
    89 
     98            psArgumentRemove(argNum, argc, argv);
     99        }
     100    }
    90101    //
    91102    // Next, try environment variable
    92103    //
    93     if (! siteName) {
     104    if (!siteName) {
    94105        siteName = getenv(PS_SITE);
    95106    }
     
    99110    //
    100111    bool cleanupSiteName = false; // Do I have to psFree siteName?
    101     if (! siteName) {
    102         siteName = psStringCopy(DEFAULT_SITE);
     112    if (!siteName) {
     113        siteName = psStringCopy(PS_DEFAULT_SITE);
    103114        cleanupSiteName = true;
    104115    }
    105116
    106     if (! readConfig(site, siteName, "site")) {
    107         if (cleanupSiteName) {
    108             psFree(siteName);
    109         }
     117    //
     118    // We have the connfiguration filename; now we read and parse the config
     119    // file and store in psMetadata struct site.
     120    //
     121    if (!readConfig(site, siteName, "site")) {
    110122        return false;
    111123    }
    112 
    113 
    114     //
    115     // Next is the camera configuration
    116     //
    117     if ((argNum = psArgumentGet(*argc, argv, "-camera"))) {
    118         (void)psArgumentRemove(argNum, argc, argv);
     124    if (cleanupSiteName) {
     125        psFree(siteName);
     126    }
     127
     128
     129    //
     130    // Next, we do a similar thing for the recipe configuration file.  The
     131    // file is read and parsed into psMetadata struct "recipe".
     132    //
     133    //
     134    argNum = psArgumentGet(*argc, argv, "-recipe");
     135    if (argNum > 0) {
     136        psArgumentRemove(argNum, argc, argv);
     137        if (argNum >= *argc) {
     138            psLogMsg(__func__, PS_LOG_WARN,
     139                     "-recipe command-line switch provided without the required filename --- ignored.\n");
     140        } else {
     141            psArgumentRemove(argNum, argc, argv);
     142            readConfig(recipe, argv[argNum], "recipe");
     143        }
     144    }
     145    // Or, load the recipe from the camera file, if appropriate
     146    if (! *recipe && *camera && recipeName) {
     147        *recipe = pmConfigRecipeFromCamera(*camera, recipeName);
     148    }
     149
     150
     151    //
     152    // Next, we do a similar thing for the camera configuration file.  The
     153    // file is read and parsed into psMetadata struct "camera".
     154    //
     155    argNum = psArgumentGet(*argc, argv, "-camera");
     156    if (argNum > 0) {
     157        psArgumentRemove(argNum, argc, argv);
    119158        if (argNum >= *argc) {
    120159            psLogMsg(__func__, PS_LOG_WARN,
    121160                     "-camera command-line switch provided without the required filename --- ignored.\n");
    122161        } else {
    123             (void)psArgumentRemove(argNum, argc, argv);
    124             (void)readConfig(camera, argv[argNum], "camera");
    125         }
    126     }
    127 
    128     //
    129     // And then the recipe configuration
    130     //
    131     if ((argNum = psArgumentGet(*argc, argv, "-recipe"))) {
    132         (void)psArgumentRemove(argNum, argc, argv);
    133         if (argNum >= *argc) {
    134             psLogMsg(__func__, PS_LOG_WARN,
    135                      "-recipe command-line switch provided without the required filename --- ignored.\n");
    136         } else {
    137             (void)psArgumentRemove(argNum, argc, argv);
    138             (void)readConfig(recipe, argv[argNum], "recipe");
    139         }
    140     }
    141     // Or, load the recipe from the camera file, if appropriate
    142     if (! *recipe && *camera && recipeName) {
    143         *recipe = pmConfigRecipeFromCamera(*camera, recipeName);
    144     }
    145 
    146 
    147     //
    148     // Now we can look into the site configuration and do the required stuff
     162            psArgumentRemove(argNum, argc, argv);
     163            readConfig(camera, argv[argNum], "camera");
     164        }
     165    } else {
     166        // XXX: Not sure is this is correct.
     167        *camera = NULL;
     168    }
     169
     170
     171    //
     172    // We now have the config, camera, and recipe files parsed and stored in
     173    // metadata.  Now, we can look into the site configuration and do
     174    // the required stuff.
    149175    //
    150176    bool mdok = true;   // Status of MD lookup result
    151     psString timeName = psMetadataLookupString(&mdok, *site, "TIME"); // Name of time file
     177
     178    //
     179    // If TIME is specified in the configuration file, then we must initialize
     180    // with a call to psTimeInitialize.
     181    //
     182    psString timeName = psMetadataLookupStr(&mdok, *site, "TIME");
    152183    if (mdok && timeName) {
    153184        psTrace(__func__, 7, "Initialising psTime with file %s\n", timeName);
    154         #ifdef PRODUCTION
    155 
     185        // XXX: PAP had a call to psLibInit is PRODUCTION not set.  Why?
    156186        psTimeInitialize(timeName);
    157         #else
    158 
    159         psLibInit(timeName);
    160         #endif
    161 
    162     }
    163 
    164     int logLevel = psMetadataLookupS32(&mdok, *site, "LOGLEVEL"); // Logging level
     187    }
     188
     189
     190    //
     191    // If LOGLEVEL is specified in the configuration file, then we must initialize
     192    // with a call to psLogSetLevel().
     193    //
     194    int logLevel = psMetadataLookupS32(&mdok, *site, "LOGLEVEL");
    165195    if (mdok && logLevel >= 0) {
    166196        psTrace(__func__, 7, "Setting log level to %d\n", logLevel);
     
    168198    }
    169199
    170     psString logFormat = psMetadataLookupString(&mdok, *site, "LOGLEVEL"); // Log format
     200
     201    //
     202    // If LOGFORMAT is specified in the configuration file, then we must initialize
     203    // with a call to psLogSetFormat().
     204    //
     205    psString logFormat = psMetadataLookupStr(&mdok, *site, "LOGFORMAT");
    171206    if (mdok && logFormat) {
    172207        psTrace(__func__, 7, "Setting log format to %s\n", logFormat);
     
    174209    }
    175210
    176     psString logDest = psMetadataLookupString(&mdok, *site, "LOGDEST"); // Log destination
     211
     212    //
     213    // If LOGDEST is specified in the configuration file, then we must initialize
     214    // with a call to psLogSetDestination().
     215    // XXX: This is not spec'ed in the SDRS.
     216    //
     217    psString logDest = psMetadataLookupStr(&mdok, *site, "LOGDEST");
    177218    if (mdok && logDest) {
    178         // XXX: Only stdout is provided for now; this section should be expanded in the future to do files,
    179         // and perhaps even sockets.
     219        // XXX: Only stdout is provided for now; this section should be
     220        // expanded in the future to do files, and perhaps even sockets.
    180221        if (strcasecmp(logDest, "STDOUT") != 0) {
    181222            psLogMsg(__func__, PS_LOG_WARN, "Only STDOUT is currently supported as a log destination.\n");
     
    186227    }
    187228
    188     psMetadata *trace = psMetadataLookupMD(&mdok, *site, "TRACE"); // Trace levels
     229
     230    //
     231    // If TRACE is specified in the configuration file, then we must initialize
     232    // with a call to psTraceSetLevel().
     233    // XXX: This is not spec'ed in the SDRS.
     234    //
     235    psMetadata *trace = psMetadataLookupMD(&mdok, *site, "TRACE");
    189236    if (mdok && trace) {
    190237        psMetadataIterator *traceIter = psMetadataIteratorAlloc(trace, PS_LIST_HEAD, NULL); // Iterator
     
    197244            }
    198245            psTrace(__func__, 7, "Setting trace level for %s to %d\n", traceItem->name, traceItem->data.S32);
    199             (void)psTraceSetLevel(traceItem->name, traceItem->data.S32);
     246            psTraceSetLevel(traceItem->name, traceItem->data.S32);
    200247        }
    201248        psFree(traceIter);
    202249    }
    203250
    204     if (cleanupSiteName) {
    205         psFree(siteName);
    206     }
    207     return true;
     251    return(true);
    208252}
    209253
     
    213257{
    214258    // Read the rule for that camera
    215     bool mdStatus = true;  // Status of MD lookup
     259    bool mdStatus = true;
    216260    psMetadata *rule = psMetadataLookupMD(&mdStatus, camera, "RULE");
    217261    if (! mdStatus || ! rule) {
     
    276320
    277321
    278 // Work out what camera we have, based on the FITS header and a set of rules specified in the IPP
    279 // configuration; return the camera configuration
    280 
     322// Work out what camera we have, based on the FITS header and a set of
     323// rules specified in the IPP configuration; return the camera configuration
    281324psMetadata *pmConfigCameraFromHeader(
    282325    const psMetadata *ipprc,            // The IPP configuration
     
    289332        return NULL;
    290333    }
    291 
    292     psMetadata *winner = NULL;       // The camera configuration whose rule first matches the supplied header
    293 
     334    psMetadata *winner = NULL;       // The camera configuration whose rule first matches
     335    //  the supplied header
    294336    // Iterate over the cameras
    295     psMetadataIterator *iterator = psMetadataIteratorAlloc(cameras, PS_LIST_HEAD, NULL); // MD Iterator
     337    psMetadataIterator *iterator = psMetadataIteratorAlloc(cameras, PS_LIST_HEAD, NULL);
    296338    psMetadataItem *cameraItem = NULL; // Item from the metadata
     339
    297340    while ((cameraItem = psMetadataGetAndIncrement(iterator))) {
    298341        // Open the camera information
     
    355398        psLogMsg(__func__, PS_LOG_WARN, "RECIPES in the camera configuration file is not of type METADATA\n");
    356399    } else {
    357         psString recipeFileName = psMetadataLookupString(&mdok, recipes, recipeName);
     400        psString recipeFileName = psMetadataLookupStr(&mdok, recipes, recipeName);
    358401        (void)readConfig(&recipe, recipeFileName, "recipe");
    359402    }
Note: See TracChangeset for help on using the changeset viewer.