IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.