IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 13, 2006, 5:54:51 PM (20 years ago)
Author:
Paul Price
Message:

Adding documentation for pmConfig.h. Cleaning up pmConfig.c. Renamed readConfig to pmConfigFileRead (since it's public, it should have a pm name).

File:
1 edited

Legend:

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

    r9539 r9579  
    11/** @file  pmConfig.h
    22 *
    3  *  @author PAP, IfA
     3 *  @author PAP (IfA)
     4 *  @author EAM (IfA)
    45 *
    5  *  @version $Revision: 1.47 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-10-13 21:15:45 $
     6 *  @version $Revision: 1.48 $ $Name: not supported by cvs2svn $
     7 *  @date $Date: 2006-10-14 03:54:51 $
    78 *
    89 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2829#define PS_DEFAULT_SITE ".ipprc"  // Default site config file
    2930
    30 static psArray *configPath = NULL;
     31static psArray *configPath = NULL;      // Search path for configuration files
    3132
    3233static void configFree(pmConfig *config)
     
    7980}
    8081
    81 
    82 /** readConfig
    83  *
    84  * This function attempts to open the file specified in the parameter list
    85  * parse it into metadata, then return it as a psMetaData table.
    86  *
    87  */
    88 bool readConfig(
    89     psMetadata **config,                // Config to output
    90     const char *name,                   // Name of file
    91     const char *description)            // Description of file
    92 {
    93     assert(config);
    94     assert(name && strlen(name) > 0);
    95     assert(description && strlen(description) > 0);
     82bool pmConfigFileRead(psMetadata **config, const char *name, const char *description)
     83{
     84    PS_ASSERT_METADATA_NON_NULL(*config, false);
     85    PS_ASSERT_STRING_NON_EMPTY(name, false);
     86    PS_ASSERT_STRING_NON_EMPTY(description, false);
    9687
    9788    char *realName = NULL;
     
    167158
    168159
    169 /******************************************************************************
    170 pmConfigRead(**site, **camera, **recipe, *argc, **argv, char *recipeName)
    171  
    172 XXX: The log/trace command line options (as processed by psArgumentVerbosity)
    173 must take precedence override the values set here.  This must be, somehow,
    174 coded.
    175  
    176 XXX: Must load camera and recipe configuration if specified in the command
    177  line.
    178  *****************************************************************************/
    179 pmConfig *pmConfigRead(
    180     int *argc,
    181     char **argv)
     160pmConfig *pmConfigRead(int *argc, char **argv)
    182161{
    183162    PS_ASSERT_PTR_NON_NULL(argc, NULL);
     
    236215    //
    237216
    238     if (!readConfig(&config->site, siteName, "site")) {
     217    if (!pmConfigFileRead(&config->site, siteName, "site")) {
    239218        psFree(config);
    240219        return NULL;
     
    289268            }
    290269
    291             readConfig(&config->camera, cameraFile, "camera");
     270            pmConfigFileRead(&config->camera, cameraFile, "camera");
    292271            psArgumentRemove(argNum, config->argc, config->argv);
    293272        }
     
    387366                continue;
    388367            }
    389             psTrace("psModules.config", 7, "Setting trace level for %s to %d\n", traceItem->name, traceItem->data.S32);
     368            psTrace("psModules.config", 7, "Setting trace level for %s to %d\n", traceItem->name,
     369                    traceItem->data.S32);
    390370            psTraceSetLevel(traceItem->name, traceItem->data.S32);
    391371        }
     
    437417
    438418
    439 bool pmConfigValidateCameraFormat(
    440     const psMetadata *cameraFormat,
    441     const psMetadata *header)
     419bool pmConfigValidateCameraFormat(const psMetadata *cameraFormat, const psMetadata *header)
    442420{
    443421    PS_ASSERT_PTR_NON_NULL(cameraFormat, false);
     
    478456
    479457
     458// Given a camera and a header, see if any of the camera formats match the header
    480459static bool formatFromHeader(psMetadata **format, // Format to return
    481460                             psMetadata *camera, // Camera configuration
     
    510489        psTrace("psModules.config", 5, "Reading camera format for %s...\n", formatsItem->name);
    511490        psMetadata *testFormat = NULL;  // Format to test against what we've got
    512         if (!readConfig(&testFormat, formatsItem->data.V, formatsItem->name)) {
     491        if (!pmConfigFileRead(&testFormat, formatsItem->data.V, formatsItem->name)) {
    513492            psLogMsg(__func__, PS_LOG_WARN, "Trouble reading reading camera format %s --- ignored.\n",
    514493                     formatsItem->name);
     
    535514}
    536515
    537 // Work out what camera we have, based on the FITS header and a set of rules specified in the IPP
    538 // configuration; return the camera configuration and format
    539 psMetadata *pmConfigCameraFormatFromHeader(
    540     pmConfig *config,                   // The configuration
    541     const psMetadata *header            // The FITS header
    542 )
     516
     517psMetadata *pmConfigCameraFormatFromHeader(pmConfig *config, const psMetadata *header)
    543518{
    544519    PS_ASSERT_PTR_NON_NULL(config, NULL);
     
    561536        while ((camerasItem = psMetadataGetAndIncrement(camerasIter))) {
    562537            // Open the camera information
    563             psTrace("psModules.config", 3, "Inspecting camera %s (%s)\n", camerasItem->name, camerasItem->comment);
     538            psTrace("psModules.config", 3, "Inspecting camera %s (%s)\n", camerasItem->name,
     539                    camerasItem->comment);
    564540            if (camerasItem->type != PS_DATA_STRING) {
    565541                psLogMsg(__func__, PS_LOG_WARN, "Camera configuration for %s in CAMERAS is not of type STR "
     
    571547            psMetadata *testCamera = NULL; // Camera to test against what we've got:
    572548
    573             if (!readConfig(&testCamera, camerasItem->data.V, camerasItem->name)) {
     549            if (!pmConfigFileRead(&testCamera, camerasItem->data.V, camerasItem->name)) {
    574550                psLogMsg(__func__, PS_LOG_WARN, "Trouble reading reading camera configuration %s --- "
    575551                         "ignored.\n", camerasItem->name);
     
    607583
    608584// Return the requested camera configuration
    609 psMetadata *pmConfigCameraByName(
    610     pmConfig *config,                   // The configuration
    611     const char *cameraName   // The camera name header
    612 )
    613 {
    614     PS_ASSERT_PTR_NON_NULL(cameraName, NULL);
     585psMetadata *pmConfigCameraByName(pmConfig *config, const char *cameraName)
     586{
    615587    PS_ASSERT_PTR_NON_NULL(config, NULL);
     588    PS_ASSERT_STRING_NON_EMPTY(cameraName, NULL);
    616589
    617590    psMetadata *cameras = psMetadataLookupMetadata(NULL, config->site, "CAMERAS");
     
    629602    psMetadata *camera = NULL; // Camera to test against what we've got:
    630603
    631     if (!readConfig(&camera, cameraPath, cameraName)) {
     604    if (!pmConfigFileRead(&camera, cameraPath, cameraName)) {
    632605        psLogMsg(__func__, PS_LOG_WARN, "Trouble reading reading camera configuration %s", cameraName);
    633606        psFree(camera);
     
    695668            // Read the recipe
    696669            psMetadata *recipe = NULL;      // Recipe from file
    697             if (readConfig(&recipe, fileItem->data.V, "recipe")) {
     670            if (pmConfigFileRead(&recipe, fileItem->data.V, "recipe")) {
    698671                psMetadataAdd(config->recipes, PS_LIST_TAIL, fileItem->name,
    699672                              PS_DATA_METADATA | PS_META_REPLACE, fileItem->comment, recipe);
     
    738711
    739712
    740 bool pmConfigReadRecipes(pmConfig *config
    741                         )
     713bool pmConfigReadRecipes(pmConfig *config)
    742714{
    743715    PS_ASSERT_PTR_NON_NULL(config, false);
     
    794766
    795767            // Is the source a symbolic reference?
    796             psMetadata *extant = psMetadataLookupMetadata(&mdok, config->recipes, recipeSource); // Does it exist?
     768            psMetadata *extant = psMetadataLookupMetadata(&mdok, config->recipes,
     769                                 recipeSource); // Does it exist?
    797770            if (mdok && extant) {
    798771                psString comment = psStringCopy("Recipe added from command line as symbolic link to ");
     
    808781                // The source is a file
    809782                psMetadata *recipe = NULL;      // Recipe from file
    810                 if (readConfig(&recipe, recipeSource, "recipe")) {
     783                if (pmConfigFileRead(&recipe, recipeSource, "recipe")) {
    811784                    psString comment = psStringCopy("Recipe added at command line from ");
    812785                    psStringAppend(&comment, "%s", recipeSource);
     
    837810}
    838811
    839 /******************************************************************************
    840 pmConfigDB(*site)
    841  
    842 XXX: this should allow the option of having NO database server, if chosen by config
    843 XXX: What should we use for the Database namespace in the call to psDBInit()?
    844 This is currently NULL.
    845  *****************************************************************************/
    846 
    847 psDB *pmConfigDB(
    848     pmConfig *config                    // Configuration
    849 )
     812
     813psDB *pmConfigDB(pmConfig *config)
    850814{
    851815    PS_ASSERT_PTR_NON_NULL(config, NULL);
     
    869833    psString dbName = psMetadataLookupStr(&mdStatus04, config->site, "DBNAME");
    870834    psS32 dbPort = psMetadataLookupS32(&mdStatus05, config->site, "DBPORT");
    871     if (!mdStatus05)
     835    if (!mdStatus05) {
    872836        dbPort = 0;
    873     if (!(mdStatus01 & mdStatus02 & mdStatus03 & mdStatus04)) {
    874         psLogMsg(__func__, PS_LOG_WARN, "Could not determine database server name, userID, and password from site metadata.\n");
    875         return(NULL);
    876     }
    877 
    878     return(psDBInit(dbServer, dbUsername, dbPassword, dbName, dbPort));
     837    }
     838    if (!(mdStatus01 && mdStatus02 && mdStatus03 && mdStatus04)) {
     839        psLogMsg(__func__, PS_LOG_WARN,
     840                 "Could not determine database server, name, user, and password from site metadata.\n");
     841        return NULL;
     842    }
     843
     844    return psDBInit(dbServer, dbUsername, dbPassword, dbName, dbPort);
    879845    #endif
    880846}
    881847
    882848
    883 bool pmConfigConformHeader(psMetadata *header, // Header to conform
    884                            const psMetadata *format // Camera format
    885                           )
     849bool pmConfigConformHeader(psMetadata *header, const psMetadata *format)
    886850{
    887851    PS_ASSERT_PTR_NON_NULL(header, false);
     
    907871}
    908872
    909 // given the 'file' and 'list' words, find the arguments associated with these words
    910 // and interpret them as lists of files.  return an array of the resulting filenames.
    911 psArray *pmConfigFileSets(pmConfig *config, char *file, char *list)
     873psArray *pmConfigFileSets(pmConfig *config, const char *file, const char *list)
    912874{
    913875    PS_ASSERT_PTR_NON_NULL(config, NULL);
     
    915877    PS_ASSERT_INT_NONNEGATIVE(*config->argc, NULL);
    916878    PS_ASSERT_PTR_NON_NULL(config->argv, NULL);
    917     PS_ASSERT_PTR_NON_NULL(file, NULL);
    918     PS_ASSERT_INT_POSITIVE(strlen(file), NULL);
    919     PS_ASSERT_PTR_NON_NULL(list, NULL);
    920     PS_ASSERT_INT_POSITIVE(strlen(list), NULL);
     879    PS_ASSERT_STRING_NON_EMPTY(file, NULL);
     880    PS_ASSERT_STRING_NON_EMPTY(list, NULL);
    921881
    922882    int Narg;
     
    990950}
    991951
    992 bool pmConfigFileSetsMD (psMetadata *metadata, pmConfig *config, char *name, char *file, char *list)
     952bool pmConfigFileSetsMD(psMetadata *metadata, pmConfig *config, const char *name,
     953                        const char *file, const char *list)
    993954{
    994955    PS_ASSERT_PTR_NON_NULL(metadata, false);
    995956    PS_ASSERT_PTR_NON_NULL(config, false);
    996     PS_ASSERT_PTR_NON_NULL(name, false);
    997     PS_ASSERT_INT_POSITIVE(strlen(name), false);
    998     PS_ASSERT_PTR_NON_NULL(file, false);
    999     PS_ASSERT_INT_POSITIVE(strlen(file), false);
    1000     PS_ASSERT_PTR_NON_NULL(list, false);
    1001     PS_ASSERT_INT_POSITIVE(strlen(list), false);
     957    PS_ASSERT_STRING_NON_EMPTY(name, NULL);
     958    PS_ASSERT_STRING_NON_EMPTY(file, NULL);
     959    PS_ASSERT_STRING_NON_EMPTY(list, NULL);
    1002960
    1003961    psErrorClear();   // pmConfigFileSets may or may not call psError, so
Note: See TracChangeset for help on using the changeset viewer.