IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18908


Ignore:
Timestamp:
Aug 4, 2008, 5:45:56 PM (18 years ago)
Author:
Paul Price
Message:

Removing use of pmConfig.complete in favour of proper use of what's now called pmConfigFileIngest (used to be metadataItemReadFile). The idea is that configuration files are read in to the metadata item where they are defined. The result is that the .ipprc (pmConfig.user) can be dumped to a file, and will contain all the other stuff as well, so that it can be loaded in (using '-ipprc XXX' on the command-line) and we have a fully defined configuration without having to load anything else (which may have changed). The problem with pmConfig.complete was that it produced multiple unsynchronised versions: you could access and change data in pmConfig.complete without pmConfig.user or pmConfig.system being updated. This check in restores things to the way they used to be, where everything is synchronised.

Location:
trunk/psModules/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/camera/pmFPAfileDefine.c

    r18567 r18908  
    2424
    2525# define FPA_TEST_ASSERT(A){ \
    26         assert(A->format == NULL); \
    27         assert(A->formatName == NULL); \
    28         assert(A->filerule == NULL); \
    29         assert(A->filesrc == NULL); }
     26        assert(A->format == NULL); \
     27        assert(A->formatName == NULL); \
     28        assert(A->filerule == NULL); \
     29        assert(A->filesrc == NULL); }
    3030
    3131// Parse an option from a metadata, returning the appropriate integer value
     
    164164    } else {
    165165        bool mdok;                      // Status of MD lookup
    166         psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->complete, "CAMERAS"); // Known cameras
     166        psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->system, "CAMERAS"); // Known cameras
    167167        if (!mdok || !cameras) {
    168168            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the system configuration.\n");
     
    486486        psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", realName);
    487487        psFree(phu);
    488         psFree(camera);
    489         psFree(formatName);
     488        psFree(camera);
     489        psFree(formatName);
    490490        psFree(realName);
    491491        return NULL;
     
    498498        psError(PS_ERR_IO, false, "Failed to construct FPA from %s", realName);
    499499        psFree(phu);
    500         psFree(camera);
    501         psFree(formatName);
     500        psFree(camera);
     501        psFree(formatName);
    502502        psFree(realName);
    503503        psFree(format);
     
    513513        psError(PS_ERR_IO, false, "file %s not defined\n", filename);
    514514        psFree(phu);
    515         psFree(formatName);
     515        psFree(formatName);
    516516        psFree(format);
    517517        psFree(fpa);
    518518        return NULL;
    519519    }
    520     psFree (file->filerule); // this is set in pmFPAfileDefineInput 
     520    psFree (file->filerule); // this is set in pmFPAfileDefineInput
    521521    file->format = format;
    522522    file->formatName = formatName;
     
    534534
    535535    if (file->type == PM_FPA_FILE_MASK) {
    536         if (!pmConfigMaskReadHeader (config, phu)) {
    537             psError(PS_ERR_IO, false, "error in mask bits");
    538             return NULL;
    539         }
     536        if (!pmConfigMaskReadHeader (config, phu)) {
     537            psError(PS_ERR_IO, false, "error in mask bits");
     538            return NULL;
     539        }
    540540    }
    541541
     
    549549            if (!realName) {
    550550                psError(PS_ERR_IO, false, "Failed to convert file name %s", (char *) infiles->data[i]);
    551                 psFree(phu);
    552                 psFree(fpa);
     551                psFree(phu);
     552                psFree(fpa);
    553553                return NULL;
    554554            }
     
    558558                psError(PS_ERR_IO, false, "Failed to open file %s\n", realName);
    559559                psFree(realName);
    560                 psFree(phu);
    561                 psFree(fpa);
     560                psFree(phu);
     561                psFree(fpa);
    562562                return NULL;
    563563            }
     
    567567                psFree(realName);
    568568                psFitsClose(fits);
    569                 psFree(phu);
    570                 psFree(fpa);
     569                psFree(phu);
     570                psFree(fpa);
    571571                return NULL;
    572572            }
     
    576576                psFree(realName);
    577577                psFitsClose(fits);
    578                 psFree(phu);
    579                 psFree(fpa);
     578                psFree(phu);
     579                psFree(fpa);
    580580                return NULL;
    581581            }
     
    584584                psFree(realName);
    585585                psFitsClose(fits);
    586                 psFree(phu);
    587                 psFree(fpa);
     586                psFree(phu);
     587                psFree(fpa);
    588588                return NULL;
    589589            }
     
    744744        psMetadataAddStr (file->names, PS_LIST_TAIL, name, 0, "", infiles->data[i]);
    745745
    746         if ((i == 0) && (file->type == PM_FPA_FILE_MASK)) {
    747             if (!pmConfigMaskReadHeader (config, phu)) {
    748                 psError(PS_ERR_IO, false, "error in mask bits");
    749                 return NULL;
    750             }
    751         }
     746        if ((i == 0) && (file->type == PM_FPA_FILE_MASK)) {
     747            if (!pmConfigMaskReadHeader (config, phu)) {
     748                psError(PS_ERR_IO, false, "error in mask bits");
     749                return NULL;
     750            }
     751        }
    752752
    753753        psFree(view);
     
    819819        psError(PS_ERR_IO, false, "Failed to read CCD format from %s\n", (char *)infiles->data[0]);
    820820        psFree(phu);
    821         psFree(camera);
    822         psFree(formatName);
     821        psFree(camera);
     822        psFree(formatName);
    823823        return NULL;
    824824    }
     
    829829        psError(PS_ERR_IO, false, "Failed to construct FPA from %s", (char *)infiles->data[0]);
    830830        psFree(phu);
    831         psFree(camera);
    832         psFree(formatName);
     831        psFree(camera);
     832        psFree(formatName);
    833833        psFree(format);
    834834        return NULL;
     
    863863
    864864    if (file->type == PM_FPA_FILE_MASK) {
    865         if (!pmConfigMaskReadHeader (config, phu)) {
    866             psError(PS_ERR_IO, false, "error in mask bits");
    867             return NULL;
    868         }
     865        if (!pmConfigMaskReadHeader (config, phu)) {
     866            psError(PS_ERR_IO, false, "error in mask bits");
     867            return NULL;
     868        }
    869869    }
    870870
  • trunk/psModules/src/config/pmConfig.c

    r18905 r18908  
    5757    psFree(config->site);
    5858    psFree(config->system);
    59     psFree(config->complete);
    6059    psFree(config->files);
    6160    psFree(config->camera);
     
    139138    config->site = NULL;
    140139    config->system = NULL;
    141     config->complete = NULL;
    142140    config->camera = NULL;
    143141    config->cameraName = NULL;
     
    232230bool pmConfigFileRead(psMetadata **config, const char *name, const char *description)
    233231{
    234     PS_ASSERT_PTR_NON_NULL(config, false);
    235     PS_ASSERT_STRING_NON_EMPTY(name, false);
    236     PS_ASSERT_STRING_NON_EMPTY(description, false);
     232    assert(config);
     233    assert(name);
     234    assert(description);
    237235
    238236    char *realName = NULL;
     
    313311}
    314312
    315 // Read a file into a metadataItem, if required
    316 static bool metadataItemReadFile(psMetadataItem *item, // Item into which to read file
    317                                  const char *description // Description, for error messages
    318     )
    319 {
    320     assert(item);
    321     assert(description);
     313bool pmConfigFileIngest(psMetadataItem *item, const char *description)
     314{
     315    PS_ASSERT_METADATA_ITEM_NON_NULL(item, false);
     316    PS_ASSERT_STRING_NON_EMPTY(description, false);
    322317
    323318    if (item->type == PS_DATA_METADATA) {
     
    357352    psMetadataItem *item;               // Item from iteration
    358353    while ((item = psMetadataGetAndIncrement(iter))) {
    359         if (!metadataItemReadFile(item, description)) {
     354        if (!pmConfigFileIngest(item, description)) {
    360355            psError(PM_ERR_CONFIG, false, "Unable to read %s %s.", description, item->name);
    361356            psFree(iter);
     
    400395    psMetadataItem *darkNorm = psMetadataLookup(camera, "DARK.NORM"); // The dark normalisation calibration
    401396    if (darkNorm) {
    402         if (darkNorm->type == PS_DATA_STRING) {
    403             const char *darkNormName = darkNorm->data.str; // The file name
    404             psTrace("config", 2, "Reading %s dark normalisation: %s\n", cameraName, darkNormName);
    405             psMetadata *new = NULL;         // New metadata
    406             if (!pmConfigFileRead(&new, darkNormName, "Dark normalisation")) {
    407                 psError(PM_ERR_CONFIG, false, "Trouble reading reading %s dark normalisation %s --- "
    408                         "ignored.\n", cameraName, darkNormName);
    409                 psFree(new);
    410                 return false;
    411             }
    412 
    413             // Muck around under the hood to replace the filename with the metadata;
    414             // don't try this at home, kids
    415             darkNorm->type = PS_DATA_METADATA;
    416             psFree(darkNorm->data.str);
    417             darkNorm->data.md = new;
    418         } else if (darkNorm->type != PS_DATA_METADATA) {
    419             psWarning("DARK.NORM in camera %s is not of type STR or METADATA (%x)",
    420                       cameraName, darkNorm->type);
     397        if (!pmConfigFileIngest(darkNorm, "dark normalisation")) {
     398            psWarning("Unable to ingest DARK.NORM in camera %s", cameraName);
    421399        }
    422400    } else {
     
    505483
    506484    // read the SITE file
    507     psString siteFile = psMetadataLookupStr(NULL, config->user, "SITE");
    508     if (!pmConfigFileRead(&config->site, siteFile, "site")) {
     485    psMetadataItem *siteItem = psMetadataLookup(config->user, "SITE");
     486    if (!siteItem) {
     487        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find SITE in user configuration.");
    509488        psFree(config);
    510489        return NULL;
    511490    }
    512 
    513     // load the SYSTEM file
    514     psString systemFile = psMetadataLookupStr(NULL, config->user, "SYSTEM");
    515     if (!pmConfigFileRead(&config->system, systemFile, "system")) {
     491    if (!pmConfigFileIngest(siteItem, "site configuration")) {
     492        psError(PS_ERR_UNKNOWN, false, "Unable to read site configuration");
    516493        psFree(config);
    517494        return NULL;
    518495    }
    519 
    520     // interpolate USER, SITE and SYSTEM into the config->complete metadata
    521     config->complete = psMetadataCopy (NULL,             config->user);
    522     config->complete = psMetadataCopy (config->complete, config->site);
    523     config->complete = psMetadataCopy (config->complete, config->system);
     496    config->site = psMemIncrRefCounter(siteItem->data.md);
     497
     498    // load the SYSTEM file
     499    psMetadataItem *systemItem = psMetadataLookup(config->user, "SYSTEM");
     500    if (!systemItem) {
     501        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find SYSTEM in user configuration.");
     502        psFree(config);
     503        return NULL;
     504    }
     505    if (!pmConfigFileIngest(systemItem, "system configuration")) {
     506        psError(PS_ERR_UNKNOWN, false, "Unable to read system configuration");
     507        psFree(config);
     508        return NULL;
     509    }
     510    config->system = psMemIncrRefCounter(systemItem->data.md);
    524511
    525512    // Set LOG and TRACE options based on the user configuration.  These must be set AFTER
     
    651638        // Initialise the psLib time handling
    652639        // XXX is this still needed / desired?
    653         psString timeName = psMetadataLookupStr(&mdok, config->complete, "TIME");
    654         if (mdok && timeName)
    655         {
     640        psString timeName = psMetadataLookupStr(&mdok, config->system, "TIME");
     641        if (mdok && timeName) {
    656642            psTrace("psModules.config", 7, "Initialising psTime with file %s\n", timeName);
    657643            psTimeInit(timeName);
     
    671657            char *cameraName = argv[argNum]; // symbolic name of the camera
    672658
    673             // look for the CAMERAS list in config->complete
    674             psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->complete, "CAMERAS");
     659            // look for the CAMERAS list in config->system
     660            psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->system, "CAMERAS");
    675661            if (!cameras) {
    676662                psError(PS_ERR_IO, false, "Unable to find CAMERAS in site configuration.\n");
     
    718704                                  "Camera specified on command line", config->camera);
    719705
    720             if (!pmConfigCameraSkycellVersion(config->complete, cameraName)) {
     706            if (!pmConfigCameraSkycellVersion(config->system, cameraName)) {
    721707                psError(PS_ERR_UNKNOWN, false,
    722708                        "Unable to generate skycell versions of specified camera %s.\n",
     
    726712            }
    727713
    728             if (!pmConfigCameraMosaickedVersions(config->complete, cameraName)) {
     714            if (!pmConfigCameraMosaickedVersions(config->system, cameraName)) {
    729715                psError(PS_ERR_UNKNOWN, false,
    730716                        "Unable to generate mosaicked versions of specified camera %s.\n",
     
    739725    if (!config->camera && readCameraConfig) {
    740726        bool mdok;                      // Status of MD lookup
    741         psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->complete, "CAMERAS"); // List of cameras
     727        psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->system, "CAMERAS"); // List of cameras
    742728        if (!mdok || !cameras) {
    743729            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the system configuration.\n");
     
    773759        psFree(iter);
    774760
    775         if (!pmConfigCameraSkycellVersionsAll(config->complete)) {
     761        if (!pmConfigCameraSkycellVersionsAll(config->system)) {
    776762            psError(PS_ERR_UNKNOWN, false, "Unable to generate skycell versions of cameras.\n");
    777763            psFree(config);
    778764            return NULL;
    779765        }
    780         if (!pmConfigCameraMosaickedVersionsAll(config->complete)) {
     766        if (!pmConfigCameraMosaickedVersionsAll(config->system)) {
    781767            psError(PS_ERR_UNKNOWN, false, "Unable to generate mosaicked versions of cameras.\n");
    782768            psFree(config);
     
    817803        psArgumentRemove(argNum, argc, argv);
    818804
    819         psMetadata *cameras = psMetadataLookupMetadata(NULL, config->complete, "CAMERAS"); // List of cameras
     805        psMetadata *cameras = psMetadataLookupMetadata(NULL, config->system, "CAMERAS"); // List of cameras
    820806        if (!cameras) {
    821807            psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find CAMERAS in the site configuration.\n");
     
    865851        } else {
    866852            char *dbserver = argv[argNum]; // The camera configuration file to read
    867             if (!psMetadataAddStr(config->complete, PS_LIST_TAIL, "DBSERVER", PS_META_REPLACE,
     853            if (!psMetadataAddStr(config->user, PS_LIST_TAIL, "DBSERVER", PS_META_REPLACE,
    868854                                  NULL, dbserver)) {
    869855                psWarning("Failed to overwrite .ipprc DBSERVER value");
     
    881867        } else {
    882868            char *dbname = argv[argNum]; // The camera configuration file to read
    883             if (!psMetadataAddStr(config->complete, PS_LIST_TAIL, "DBNAME", PS_META_REPLACE, NULL, dbname)) {
     869            if (!psMetadataAddStr(config->user, PS_LIST_TAIL, "DBNAME", PS_META_REPLACE, NULL, dbname)) {
    884870                psWarning("Failed to overwrite .ipprc DBNAME value");
    885871            }
     
    896882        } else {
    897883            char *dbuser = argv[argNum]; // The camera configuration file to read
    898             if (!psMetadataAddStr(config->complete, PS_LIST_TAIL, "DBUSER", PS_META_REPLACE, NULL, dbuser)) {
     884            if (!psMetadataAddStr(config->user, PS_LIST_TAIL, "DBUSER", PS_META_REPLACE, NULL, dbuser)) {
    899885                psWarning("Failed to overwrite .ipprc DBUSER value");
    900886            }
     
    911897        } else {
    912898            char *dbpassword = argv[argNum]; // The camera configuration file to read
    913             if (!psMetadataAddStr(config->complete, PS_LIST_TAIL, "DBPASSWORD", PS_META_REPLACE,
     899            if (!psMetadataAddStr(config->user, PS_LIST_TAIL, "DBPASSWORD", PS_META_REPLACE,
    914900                                  NULL, dbpassword)) {
    915901                psWarning("Failed to overwrite .ipprc DBPASSWORD value");
     
    927913        } else {
    928914            char *dbport = argv[argNum]; // The camera configuration file to read
    929             if (!psMetadataAddS32(config->complete, PS_LIST_TAIL, "DBPORT", PS_META_REPLACE, NULL,
     915            if (!psMetadataAddS32(config->user, PS_LIST_TAIL, "DBPORT", PS_META_REPLACE, NULL,
    930916                                  (psS32)atoi(dbport))) {
    931917                psWarning("Failed to overwrite .ipprc DBPORT value");
     
    11131099
    11141100        bool mdok;                      // Metadata lookup status
    1115         psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->complete, "CAMERAS");
     1101        psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->system, "CAMERAS");
    11161102        if (! mdok || !cameras) {
    11171103            psError(PS_ERR_IO, true, "Unable to find CAMERAS in the configuration.");
     
    11831169    char *testName = NULL;
    11841170
    1185     psMetadata *cameras = psMetadataLookupMetadata (NULL, config->complete, "CAMERAS");
     1171    psMetadata *cameras = psMetadataLookupMetadata (NULL, config->system, "CAMERAS");
    11861172    psAssert (cameras, "missing CAMERAS in complete metadata");
    11871173
     
    12631249    PS_ASSERT_STRING_NON_EMPTY(cameraName, NULL);
    12641250
    1265     psMetadata *cameras = psMetadataLookupMetadata(NULL, config->complete, "CAMERAS");
     1251    psMetadata *cameras = psMetadataLookupMetadata(NULL, config->system, "CAMERAS");
    12661252    if (!cameras) {
    12671253        psError(PS_ERR_IO, true, "Unable to find CAMERAS in the configuration.");
     
    12691255    }
    12701256
    1271     char *cameraPath = psMetadataLookupStr(NULL, cameras, cameraName);
    1272     if (!cameraPath) {
    1273         psError(PS_ERR_IO, true, "Unable to find requested CAMERA in the configuration.");
     1257    psMetadataItem *item = psMetadataLookup(cameras, cameraName); // Item with camera of interest
     1258    if (!pmConfigFileIngest(item, "camera configuration")) {
     1259        psError(PS_ERR_UNKNOWN, false, "Unable to ingest camera configuration.");
    12741260        return NULL;
    12751261    }
    12761262
    1277     psMetadata *camera = NULL; // Camera to test against what we've got:
    1278 
    1279     if (!pmConfigFileRead(&camera, cameraPath, cameraName)) {
    1280         psWarning("Trouble reading reading camera configuration %s", cameraName);
    1281         psFree(camera);
    1282         return NULL;
    1283     }
    1284 
    1285     return camera;
     1263    return psMemIncrRefCounter(item->data.md);
    12861264}
    12871265
     
    12891267{
    12901268    PS_ASSERT_PTR_NON_NULL(config, NULL);
    1291     PS_ASSERT_PTR_NON_NULL(config->complete, NULL);
     1269    PS_ASSERT_PTR_NON_NULL(config->user, NULL);
    12921270
    12931271    #ifndef HAVE_PSDB
     
    13101288
    13111289    // XXX leaky strings
    1312     psString dbServer = psMetadataLookupStr(&mdStatus01, config->complete, "DBSERVER");
    1313     psString dbUsername = psMetadataLookupStr(&mdStatus02, config->complete, "DBUSER");
    1314     psString dbPassword = psMetadataLookupStr(&mdStatus03, config->complete, "DBPASSWORD");
    1315     psString dbName = psMetadataLookupStr(&mdStatus04, config->complete, "DBNAME");
    1316     psS32 dbPort = psMetadataLookupS32(&mdStatus05, config->complete, "DBPORT");
     1290    psString dbServer = psMetadataLookupStr(&mdStatus01, config->user, "DBSERVER");
     1291    psString dbUsername = psMetadataLookupStr(&mdStatus02, config->user, "DBUSER");
     1292    psString dbPassword = psMetadataLookupStr(&mdStatus03, config->user, "DBPASSWORD");
     1293    psString dbName = psMetadataLookupStr(&mdStatus04, config->user, "DBNAME");
     1294    psS32 dbPort = psMetadataLookupS32(&mdStatus05, config->user, "DBPORT");
    13171295    if (!mdStatus05) {
    13181296        dbPort = 0;
     
    15271505    // replace path://PATH with matched datapath
    15281506    if (!strncasecmp(filename, "path://", strlen("path://"))) {
    1529         PS_ASSERT_METADATA_NON_NULL(config->complete, NULL);
     1507        PS_ASSERT_METADATA_NON_NULL(config->site, NULL);
    15301508
    15311509        psString newName = psStringCopy(filename);
    15321510
    15331511        // filename should be of the form: path://PATH/rest/of/file
    1534         // replace PATH with matching name from config->complete:DATAPATH
    1535         psMetadata *datapath = psMetadataLookupPtr (NULL, config->complete, "DATAPATH");
     1512        // replace PATH with matching name from config->site:DATAPATH
     1513        psMetadata *datapath = psMetadataLookupPtr (NULL, config->site, "DATAPATH");
    15361514        if (datapath == NULL) {
    15371515            psError(PS_ERR_UNKNOWN, true, "DATAPATH is not defined in config.site");
     
    15861564        // if env isn't set, check the config system
    15871565        if (!neb_server) {
    1588             neb_server = psMetadataLookupStr(&status, config->complete, "NEB_SERVER");
     1566            neb_server = psMetadataLookupStr(&status, config->site, "NEB_SERVER");
    15891567            if (!status) {
    15901568                psError(PM_ERR_CONFIG, true, "failed to lookup config value for NEB_SERVER.");
     
    16621640    }
    16631641
    1664     if (!metadataItemReadFile(item, "file rules ")) {
     1642    if (!pmConfigFileIngest(item, "file rules ")) {
    16651643        psError(PM_ERR_CONFIG, false, "Unable to read file rules for camera.");
    16661644        return NULL;
     
    16951673    }
    16961674
    1697     if (!metadataItemReadFile(item, "FITS Types")) {
     1675    if (!pmConfigFileIngest(item, "FITS Types")) {
    16981676        psError(PM_ERR_CONFIG, false, "Unable to read fits types for camera.");
    16991677        return NULL;
  • trunk/psModules/src/config/pmConfig.h

    r18905 r18908  
    55 *  @author Eugene Magnier, IfA
    66 *
    7  *  @version $Revision: 1.39 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2008-08-05 02:16:06 $
     7 *  @version $Revision: 1.40 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2008-08-05 03:45:56 $
    99 *  Copyright 2005-2006 Institute for Astronomy, University of Hawaii
    1010 */
     
    4040    psMetadata *site;                   ///< Site configuration
    4141    psMetadata *system;                 ///< System configuration
    42     psMetadata *complete;               ///< Full merged configuration
    4342    psMetadata *camera;                 ///< Camera specification
    4443    psString cameraName;                ///< Camera name
     
    8685/// Read a configuration file
    8786///
    88 /// Read a metadata configuration file into the supplied metadata.  Produce an error and return false if
    89 /// there's a problem.
     87/// Read a metadata configuration file into the supplied metadata.  Produce an error and
     88/// return false if there's a problem.
    9089bool pmConfigFileRead(psMetadata **config, ///< Config to output
    9190                      const char *name, ///< Name of file
    9291                      const char *description ///< Description of file
    93                      );
     92    );
     93
     94/// Ingest a configuration file
     95///
     96/// Ingest a metadata configuration file into the supplied metadata item, if required.  Produce an error and
     97/// return false if there's a problem.
     98bool pmConfigFileIngest(psMetadataItem *item, // Item into which to read file
     99                        const char *description // Description, for error messages
     100    );
    94101
    95102/// Validate a header against the camera format
  • trunk/psModules/src/config/pmConfigCommand.c

    r16611 r18908  
    1313    PS_ASSERT_PTR_NON_NULL(command, false);
    1414    PS_ASSERT_PTR_NON_NULL(config, false);
    15     PS_ASSERT_PTR_NON_NULL(config->complete, false);
     15    PS_ASSERT_PTR_NON_NULL(config->user, false);
    1616
    1717    bool mdok;                          // Status of MD lookup
    18     const char *dbserver = psMetadataLookupStr(&mdok, config->complete, "DBSERVER"); // Database server
     18    const char *dbserver = psMetadataLookupStr(&mdok, config->user, "DBSERVER"); // Database server
    1919    if (!mdok || strlen(dbserver) == 0) {
    2020        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find DBSERVER in site configuration.\n");
    2121        return false;
    2222    }
    23     const char *dbname = psMetadataLookupStr(&mdok, config->complete, "DBNAME"); // Database name
     23    const char *dbname = psMetadataLookupStr(&mdok, config->user, "DBNAME"); // Database name
    2424    if (!mdok || strlen(dbname) == 0) {
    2525        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find DBNAME in site configuration.\n");
    2626        return false;
    2727    }
    28     const char *dbuser = psMetadataLookupStr(&mdok, config->complete, "DBUSER"); // Database user
     28    const char *dbuser = psMetadataLookupStr(&mdok, config->user, "DBUSER"); // Database user
    2929    if (!mdok || strlen(dbuser) == 0) {
    3030        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find DBUSER in site configuration.\n");
    3131        return false;
    3232    }
    33     const char *dbpassword = psMetadataLookupStr(&mdok, config->complete, "DBPASSWORD"); // Database password
     33    const char *dbpassword = psMetadataLookupStr(&mdok, config->user, "DBPASSWORD"); // Database password
    3434    if (!mdok || strlen(dbpassword) == 0) {
    3535        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find DBPASSWORD in site configuration.\n");
  • trunk/psModules/src/config/pmConfigDump.c

    r18905 r18908  
    6464      PS_ASSERT_PTR_NON_NULL(config, false);
    6565
    66       psMetadata *cameras = psMetadataLookupMetadata(NULL, config->complete, "CAMERAS"); // Known cameras
     66      psMetadata *cameras = psMetadataLookupMetadata(NULL, config->system, "CAMERAS"); // Known cameras
    6767      if (!cameras) {
    6868          psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find CAMERAS in the system configuration.\n");
     
    146146    }
    147147
    148     if (!psMetadataConfigWrite(config->complete, filename)) {
     148    if (!psMetadataConfigWrite(config->user, filename)) {
    149149        psError(PS_ERR_IO, false, "Unable to dump configuration to %s", filename);
    150150        psFree(filename);
  • trunk/psModules/src/config/pmConfigRecipes.c

    r17512 r18908  
    2828    if (!options) {
    2929        options = psMetadataAlloc ();
    30         success = psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "OPTIONS",  PS_DATA_METADATA, "", options);
     30        success = psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "OPTIONS",  PS_DATA_METADATA, "",
     31                                    options);
    3132        assert (success); // type mismatch : OPTIONS already defined but wrong type
    3233        psFree (options); // drop extra reference
     
    4748
    4849// this function may be called several times.  it attempts to load the recipe data from one of three
    49 // locations: config->complete, config->camera, and argv.  We cannot read the recipes from
     50// locations: config->system, config->camera, and argv.  We cannot read the recipes from
    5051// config->camera until a camera has been read BUT, the argv recipes must override the camera and
    5152// system recipes.  This command strips the argv elements it uses from the argv list.
     
    6061
    6162    // Read the recipe file names from the system configuration and camera configuration
    62     // It is an error for config->complete:recipes not to exist.  all programs install their
     63    // It is an error for config->system:recipes not to exist.  all programs install their
    6364    // master recipe files in the system:recipe location when they are built.
    64     psAssert (config->complete, "base config data defined");
     65    psAssert(config->system, "base config data defined");
    6566    if (source & PM_RECIPE_SOURCE_SYSTEM) {
    66         if (!loadRecipeSystem(&status, config, config->complete)) {
     67        if (!loadRecipeSystem(&status, config, config->system)) {
    6768            psError(PS_ERR_IO, false, "Failed to read recipes from system config");
    6869            return false;
     
    7576    // for an identified camera (in pmConfigCameraFormatFromHeader).  the second
    7677    // set should not override the first set
    77     if (config->camera && (source & PM_RECIPE_SOURCE_CAMERA) && !(config->recipesRead & PM_RECIPE_SOURCE_CAMERA)) {
     78    if (config->camera && (source & PM_RECIPE_SOURCE_CAMERA) &&
     79        !(config->recipesRead & PM_RECIPE_SOURCE_CAMERA)) {
    7880        if (!loadRecipeCamera(&status, config, config->camera)) {
    7981            psError(PS_ERR_IO, false, "Failed to read recipes from camera config");
     
    8789    }
    8890
    89     // merge camera and sytem recipes, apply recipes loaded into config->arguments based on command-line arguments
     91    // merge camera and sytem recipes, apply recipes loaded into config->arguments based on command-line
     92    // arguments
    9093    if (config->arguments && (source & PM_RECIPE_SOURCE_CL)) {
    9194
    92         // update the system-level recipes with the symbolically-defined recipes
     95        // update the system-level recipes with the symbolically-defined recipes
    9396        if (!loadRecipeSymbols(&status, config, PM_RECIPE_SOURCE_SYSTEM)) {
    9497            psError(PS_ERR_IO, false, "Failed to read recipes from symbolic references");
     
    101104        }
    102105
    103         // merge the SYSTEM and CAMERA recipes
     106        // merge the SYSTEM and CAMERA recipes
    104107        if (!mergeRecipeCamera(&status, config)) {
    105108            psError(PS_ERR_IO, false, "Failed to read recipes from symbolic references");
    106109            return false;
    107110        }
    108         psLogMsg ("psModules.config", PS_LOG_DETAIL, "merged camera recipes with system recipes");
    109 
    110         // load recipe-files specified on the command line
     111        psLogMsg ("psModules.config", PS_LOG_DETAIL, "merged camera recipes with system recipes");
     112
     113        // load recipe-files specified on the command line
    111114        if (!loadRecipeFromArguments(&status, config)) {
    112115            psError(PS_ERR_IO, false, "Failed to read recipes from command-line arguments");
     
    119122        }
    120123
    121         // update the system-level recipes with the symbolically-defined recipes
     124        // update the system-level recipes with the symbolically-defined recipes
    122125        if (!loadRecipeSymbols(&status, config, PM_RECIPE_SOURCE_CAMERA)) {
    123126            psError(PS_ERR_IO, false, "Failed to read recipes from symbolic references");
     
    130133        }
    131134
    132         // override any specific values with values from the command line
     135        // override any specific values with values from the command line
    133136        if (!loadRecipeOptions(&status, config)) {
    134137            psError(PS_ERR_IO, false, "Failed to read recipes from symbolic references");
     
    155158    if (!options) {
    156159        options = psMetadataAlloc();
    157         success = psMetadataAddPtr(config->arguments, PS_LIST_TAIL, "OPTIONS",  PS_DATA_METADATA, "Command-line options specified with -D", options);
     160        success = psMetadataAddPtr(config->arguments, PS_LIST_TAIL, "OPTIONS",  PS_DATA_METADATA,
     161                                   "Command-line options specified with -D", options);
    158162        assert (success); // type mismatch : OPTIONS already defined but wrong type
    159163        psFree (options); // drop extra reference
     
    178182            recipeName = config->defaultRecipe;
    179183            if (!config->defaultRecipe) {
    180                 psError(PS_ERR_IO, true, "syntax error in parameter: no default recipe available; must specify recipe");
     184                psError(PS_ERR_IO, true,
     185                        "syntax error in parameter: no default recipe available; must specify recipe");
    181186                return false;
    182187            }
     
    242247    if (!recipes) {
    243248        recipes = psMetadataAlloc();
    244         success = psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "RECIPES",  PS_DATA_METADATA, "", recipes);
     249        success = psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "RECIPES",  PS_DATA_METADATA, "",
     250                                    recipes);
    245251        assert (success);
    246252        psFree (recipes);
     
    298304        // Assume it's a symbolic reference to something that's not yet read in.
    299305        // it will be loaded later by pmConfigReadRecipes with option CL
    300         psMetadataAddStr(config->recipeSymbols, PS_LIST_TAIL, recipeName, PS_META_REPLACE, NULL, recipeSource);
     306        psMetadataAddStr(config->recipeSymbols, PS_LIST_TAIL, recipeName, PS_META_REPLACE, NULL,
     307                         recipeSource);
    301308
    302309        psTrace ("psModules.config", 3, "read recipe %s from %s", recipeName, recipeSource);
     
    319326
    320327    if (!source) {
    321         psError(PS_ERR_IO, true, "The system configuration has not been read --- cannot read recipes from this location.\n");
     328        psError(PS_ERR_IO, true,
     329                "The system configuration has not been read --- cannot read recipes from this location.\n");
    322330        config->recipesRead &= ~PM_RECIPE_SOURCE_SYSTEM;
    323331        return false;
     
    334342    // If it's not of the correct type, we can tell the user which file it's in, so they can find it easier.
    335343    psMetadataIterator *recipesIter = psMetadataIteratorAlloc(recipes, PS_LIST_HEAD, NULL); // Iterator
    336     psMetadataItem *fileItem = NULL;    // MD item containing the filename, from recipe iteration
    337     while ((fileItem = psMetadataGetAndIncrement(recipesIter))) {
    338         char *recipeName = fileItem->name;
    339         char *recipeFile = fileItem->data.str;
    340 
    341         // type mismatch is a serious error
    342         if (fileItem->type != PS_DATA_STRING) {
    343             psAbort("%s in system configuration RECIPES is not of type STR", recipeName);
    344         }
    345 
    346         // Read the recipe file. if we fail on a file, give a warning, but continue
    347         psMetadata *recipe = NULL;
    348         if (!pmConfigFileRead(&recipe, recipeFile, "recipe")) {
    349             psError(PS_ERR_IO, false, "Failed to read recipe file %s listed in system configuration\n", recipeFile);
    350             return false;
    351         }
    352 
    353         // and the contents of this recipe file to config->recipes
    354         psMetadataAdd(config->recipes, PS_LIST_TAIL, fileItem->name, PS_DATA_METADATA | PS_META_REPLACE, fileItem->comment, recipe);
    355         psFree(recipe);  // Drop reference
     344    psMetadataItem *item = NULL;        // MD item containing the filename, from recipe iteration
     345    while ((item = psMetadataGetAndIncrement(recipesIter))) {
     346        if (!pmConfigFileIngest(item, "recipe")) {
     347            psError(PS_ERR_IO, false, "Failed to read recipe %s listed in system configuration",
     348                    item->name);
     349            psFree(recipesIter);
     350            return false;
     351        }
     352
     353        // add the contents of this recipe file to config->recipes
     354        psMetadataAdd(config->recipes, PS_LIST_TAIL, item->name, PS_DATA_METADATA | PS_META_REPLACE,
     355                      item->comment, item->data.md);
    356356    }
    357357    psFree(recipesIter);
     
    375375
    376376    if (!source) {
    377         psError(PS_ERR_IO, true, "The camera configuration has not been read --- cannot read recipes from this location.\n");
     377        psError(PS_ERR_IO, true,
     378                "The camera configuration has not been read --- cannot read recipes from this location.\n");
    378379        config->recipesRead &= ~PM_RECIPE_SOURCE_CAMERA;
    379380        return false;
     
    392393    // If it's not of the correct type, we can tell the user which file it's in, so they can find it easier.
    393394    psMetadataIterator *recipesIter = psMetadataIteratorAlloc(recipes, PS_LIST_HEAD, NULL); // Iterator
    394     psMetadataItem *fileItem = NULL;    // MD item containing the filename, from recipe iteration
    395     while ((fileItem = psMetadataGetAndIncrement(recipesIter))) {
    396         char *recipeName = fileItem->name;
    397         char *recipeFile = fileItem->data.str;
    398 
    399         psTrace("psModules.config", 3, "loading %s from %s within camera configuration.\n", recipeName, recipeFile);
    400 
    401         // type mismatch is a serious error
    402         if (fileItem->type != PS_DATA_STRING) {
    403             psAbort("%s in camera configuration RECIPES is not of type STR", recipeName);
    404         }
    405 
    406         // Read the recipe file. if we fail on a file, give a warning, but continue
    407         psMetadata *recipe = NULL;
    408         if (!pmConfigFileRead(&recipe, recipeFile, "recipe")) {
    409             psError(PS_ERR_IO, false, "Failed to read recipe file %s listed in camera configuration\n", recipeFile);
    410             return false;
    411         }
     395    psMetadataItem *item = NULL;    // MD item containing the filename, from recipe iteration
     396    while ((item = psMetadataGetAndIncrement(recipesIter))) {
     397        if (!pmConfigFileIngest(item, "recipe")) {
     398            psError(PS_ERR_IO, false, "Failed to read recipe %s listed in camera configuration",
     399                    item->name);
     400            return false;
     401        }
     402        const char *recipeName = item->name; // Name of the recipe
     403        psMetadata *recipe = item->data.md; // The recipe
    412404
    413405        // the named recipe must exist at the system level
     
    415407        if (!current) {
    416408            psError(PS_ERR_IO, false, "Failed to find recipe for %s in master recipe list", recipeName);
    417             psFree(recipe);  // Drop reference
    418409            return false;
    419410        }
    420411
    421412        // add the contents of this recipe file to config->recipesCamera
    422         psMetadataAdd(config->recipesCamera, PS_LIST_TAIL, recipeName, PS_DATA_METADATA | PS_META_REPLACE, fileItem->comment, recipe);
    423         psFree(recipe);  // Drop reference
     413        psMetadataAdd(config->recipesCamera, PS_LIST_TAIL, recipeName, PS_DATA_METADATA | PS_META_REPLACE,
     414                      item->comment, recipe);
    424415    }
    425416    psFree(recipesIter);
     
    441432    // We could use psMetadataCopy for this, but it's better to check that everything's of the correct type.
    442433    // If it's not of the correct type, we can tell the user which file it's in, so they can find it easier.
    443     psMetadataIterator *recipesIter = psMetadataIteratorAlloc(config->recipesCamera, PS_LIST_HEAD, NULL); // Iterator
     434    psMetadataIterator *recipesIter = psMetadataIteratorAlloc(config->recipesCamera, PS_LIST_HEAD, NULL);
    444435    psMetadataItem *folderItem = NULL;    // MD item containing the filename, from recipe iteration
    445436    while ((folderItem = psMetadataGetAndIncrement(recipesIter))) {
     
    459450
    460451        // update the contents of this recipe from the one on config->recipesCamera
    461         if (!psMetadataUpdate(current, recipe)) {
    462             psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", recipeName);
    463             return false;
    464         }
     452        if (!psMetadataUpdate(current, recipe)) {
     453            psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", recipeName);
     454            return false;
     455        }
    465456    }
    466457    psFree(recipesIter);
     
    552543
    553544        // search for sourceName in config->recipes (folder name is targetName)
    554         psMetadata *folder = psMetadataLookupMetadata(&found, config->recipes, targetName);
    555         psMetadata *sourceMD = psMetadataLookupMetadata(&found, folder, sourceName);
    556 
    557         // if we find the desired symbolic name at this level, set the item comment to say "FOUND"
     545        psMetadata *folder = psMetadataLookupMetadata(&found, config->recipes, targetName);
     546        psMetadata *sourceMD = psMetadataLookupMetadata(&found, folder, sourceName);
     547
     548        // if we find the desired symbolic name at this level, set the item comment to say "FOUND"
    558549        if (sourceMD) {
    559           if (!psMetadataUpdate(targetMD, sourceMD)) {
     550          if (!psMetadataUpdate(targetMD, sourceMD)) {
    560551            psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", targetName);
    561552            return false;
    562           }
    563           psStringAppend (&item->comment, "(FOUND)");
    564         }         
    565 
    566         // if we have not found it by the camera level, we have a problem
    567         if (source == PM_RECIPE_SOURCE_CAMERA) {
    568           if (strstr (item->comment, "(FOUND)") == NULL) {
    569             psError(PS_ERR_IO, false, "Selected symbolic name %s does not exist in recipes", sourceName);
    570             return false;
    571           }
    572         }
     553          }
     554          psStringAppend (&item->comment, "(FOUND)");
     555        }
     556
     557        // if we have not found it by the camera level, we have a problem
     558        if (source == PM_RECIPE_SOURCE_CAMERA) {
     559          if (strstr (item->comment, "(FOUND)") == NULL) {
     560            psError(PS_ERR_IO, false, "Selected symbolic name %s does not exist in recipes", sourceName);
     561            return false;
     562          }
     563        }
    573564    }
    574565    psFree(iter);
     
    594585    }
    595586
    596     psMetadata *recipes = psMetadataLookupMetadata(&found, config->arguments, "OPTIONS"); // The list of recipes
     587    psMetadata *recipes = psMetadataLookupMetadata(&found, config->arguments, "OPTIONS"); // List of recipes
    597588    if (!recipes) {
    598589        psTrace("psModules.config", 4, "no OPTIONS in config->arguments, nothing to read here");
Note: See TracChangeset for help on using the changeset viewer.