IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 4, 2007, 10:15:48 AM (19 years ago)
Author:
Paul Price
Message:

Gene pointed out that the file rules are also read in pmConfig (when the '-F' switch is used on the command-line), and the new ability to read file rules from a separate file wasn't implemented there. I've moved the function that gets a file rule from pmFPAfileDefine.c to pmConfig.c (now named pmConfigFileRule), and now both the pmConfig and pmFPAfileDefine functions use this.

File:
1 edited

Legend:

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

    r15180 r15217  
    229229}
    230230
     231// Read a file into a metadataItem, if required
     232static bool metadataItemReadFile(psMetadataItem *item, // Item into which to read file
     233                                 const char *description // Description, for error messages
     234    )
     235{
     236    assert(item);
     237    assert(description);
     238
     239    if (item->type == PS_DATA_METADATA) {
     240        return true;                    // We've already read it
     241    }
     242    if (item->type != PS_DATA_STRING) {
     243        psTrace("config", 2, "Element %s in %s metadata is not of type STR.\n",
     244                item->name, description);
     245        return false;
     246    }
     247
     248    psTrace("config", 2, "Reading %s %s: %s\n", description, item->name, item->data.str);
     249    psMetadata *new = NULL;         // New metadata
     250    if (!pmConfigFileRead(&new, item->data.str, item->name)) {
     251        psError(PM_ERR_CONFIG, false, "Trouble reading reading %s %s.\n",
     252                description, item->name);
     253        psFree(new);
     254        return false;
     255    }
     256
     257    // Muck around under the hood to replace the filename with the metadata; don't try this at home, kids
     258    item->type = PS_DATA_METADATA;
     259    psFree(item->data.str);
     260    item->data.md = new;
     261
     262    return true;
     263}
     264
    231265// Read metadata config files in a metadata
    232266// The metadata contains file names, which will be replaced with the metadata that are in the files.
     
    239273    psMetadataItem *item;               // Item from iteration
    240274    while ((item = psMetadataGetAndIncrement(iter))) {
    241         if (item->type == PS_DATA_METADATA) {
    242             continue;       // We've already read it
    243         }
    244         if (item->type != PS_DATA_STRING) {
    245            psTrace("config", 2, "Element %s in %s metadata is not of type STR.\n",
    246                    item->name, description);
    247            continue;
    248         }
    249 
    250         psTrace("config", 2, "Reading %s %s: %s\n", description, item->name, item->data.str);
    251         psMetadata *new = NULL;         // New metadata
    252         if (!pmConfigFileRead(&new, item->data.str, item->name)) {
    253             psError(PM_ERR_CONFIG, false, "Trouble reading reading %s %s --- "
    254                     "ignored.\n", description, item->name);
    255             psFree(new);
     275        if (!metadataItemReadFile(item, description)) {
     276            psError(PM_ERR_CONFIG, false, "Unable to read %s %s.", description, item->name);
    256277            psFree(iter);
    257278            return false;
    258279        }
    259 
    260         // Muck around under the hood to replace the filename with the metadata; don't try this at home, kids
    261         item->type = PS_DATA_METADATA;
    262         psFree(item->data.str);
    263         item->data.md = new;
    264280    }
    265281    psFree(iter);
     
    694710            }
    695711            psMetadata *camera = cameraItem->data.md; // Camera configuration
     712
     713            psMetadata *newRule = pmConfigFileRule(config, camera, new); // The rule of interest
     714            if (!newRule) {
     715                psWarning("Unable to find filerule %s in camera %s --- ignored.", new, cameraItem->name);
     716                continue;
     717            }
     718
     719            // By calling pmConfigFileRule, we've assured that the FILERULES is now a metadata
    696720            psMetadata *filerules = psMetadataLookupMetadata(NULL, camera, "FILERULES"); // File rules
    697721            if (!filerules) {
     
    700724                continue;
    701725            }
    702             psMetadataItem *newItem = psMetadataLookup(filerules, new); // The rule of interest, or a redir.
    703             if (!newItem) {
    704                 psWarning("Can't find file rule %s in camera %s --- ignored.", new, cameraItem->name);
    705                 continue;
    706             }
    707             psMetadata *newRule;        // New rule (replacement)
    708             switch (newItem->type) {
    709               case PS_DATA_STRING:
    710                 // A redirection
    711                 newRule = psMetadataLookupMetadata(NULL, filerules, newItem->data.str);
    712                 break;
    713               case PS_DATA_METADATA:
    714                 // The rule itself
    715                 newRule = newItem->data.md;
    716                 break;
    717               default:
    718                 psWarning("Unable to find filerule %s of the correct type in camera %s --- ignored.",
    719                           new, cameraItem->name);
    720                 continue;
    721             }
     726
    722727            psMetadataAddMetadata(filerules, PS_LIST_TAIL, old, PS_META_REPLACE,
    723728                                  "Original replaced by -F option", newRule);
     
    14141419    return psStringCopy(filename);
    14151420}
     1421
     1422psMetadata *pmConfigFileRule(const pmConfig *config, const psMetadata *camera, const char *name)
     1423{
     1424    PS_ASSERT_PTR_NON_NULL(config, NULL);
     1425    PS_ASSERT_METADATA_NON_NULL(camera, NULL);
     1426    PS_ASSERT_STRING_NON_EMPTY(name, NULL);
     1427
     1428    psMetadataItem *item = psMetadataLookup(camera, "FILERULES"); // Item with the file rule of interest
     1429    if (!item) {
     1430        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find FILERULES in the camera configuration.");
     1431        return NULL;
     1432    }
     1433
     1434    if (!metadataItemReadFile(item, "file rules ")) {
     1435        psError(PM_ERR_CONFIG, false, "Unable to read file rules for camera.");
     1436        return NULL;
     1437    }
     1438
     1439    assert(item->type == PS_DATA_METADATA);
     1440    psMetadata *filerules = item->data.md; // File rules from the camera configuration
     1441
     1442    // select the name from the FILERULES
     1443    // check for alias name (type == STR, name is aliased name)
     1444    bool mdok;                          // Status of MD lookup
     1445    const char *realname = psMetadataLookupStr(&mdok, filerules, name); // Name of file rule to look up
     1446    if (!realname || strlen(realname) == 0) {
     1447        realname = name;
     1448    }
     1449
     1450    return psMetadataLookupMetadata(NULL, filerules, realname);
     1451}
     1452
Note: See TracChangeset for help on using the changeset viewer.