IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 8, 2007, 11:53:00 AM (19 years ago)
Author:
Paul Price
Message:

Updating types in metadataItem union.

File:
1 edited

Legend:

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

    r12916 r15513  
    55#include <stdio.h>
    66#include <string.h>
    7 #include <strings.h>            /* for strn?casecmp */
     7#include <strings.h>            /* for strn?casecmp */
    88#include <unistd.h>
    99#include <libgen.h>
     
    3333        options = psMetadataAlloc ();
    3434        success = psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "OPTIONS",  PS_DATA_METADATA, "", options);
    35         assert (success); // type mismatch : OPTIONS already defined but wrong type
    36         psFree (options); // drop extra reference
     35        assert (success); // type mismatch : OPTIONS already defined but wrong type
     36        psFree (options); // drop extra reference
    3737    }
    3838
     
    4444        recipe = psMetadataAlloc();
    4545        success = psMetadataAddPtr(options, PS_LIST_TAIL, recipeName,  PS_DATA_METADATA, "", recipe);
    46         assert (success); // type mismatch : OPTIONS already defined but wrong type
    47         psFree (recipe);  // drop extra reference
     46        assert (success); // type mismatch : OPTIONS already defined but wrong type
     47        psFree (recipe);  // drop extra reference
    4848    }
    4949    return recipe;
     
    6767    // master recipe files in the site:recipe location when they are built.
    6868    if (config->site && (source & PM_RECIPE_SOURCE_SITE)) {
    69         if (!loadRecipeSite(&status, config, config->site)) {
     69        if (!loadRecipeSite(&status, config, config->site)) {
    7070            psError(PS_ERR_IO, false, "Failed to read recipes from site config");
    71             return false;
    72         } 
    73         psTrace ("psModules.config", 3, "read recipes from site config");
     71            return false;
     72        }
     73        psTrace ("psModules.config", 3, "read recipes from site config");
    7474    }
    7575
     
    8181        if (!loadRecipeCamera(&status, config, config->camera)) {
    8282            psError(PS_ERR_IO, false, "Failed to read recipes from camera config");
    83             return false;
    84         } 
    85         if (status) {
    86             psTrace ("psModules.config", 3, "read recipes from camera config");
    87         } else {
    88             psLogMsg ("psModules.config", PS_LOG_DETAIL, "no recipe supplied by camera config");
    89         }
     83            return false;
     84        }
     85        if (status) {
     86            psTrace ("psModules.config", 3, "read recipes from camera config");
     87        } else {
     88            psLogMsg ("psModules.config", PS_LOG_DETAIL, "no recipe supplied by camera config");
     89        }
    9090    }
    9191
     
    9494        if (!loadRecipeFromArguments(&status, config)) {
    9595            psError(PS_ERR_IO, false, "Failed to read recipes from command-line arguments");
    96             return false;
    97         } 
    98         if (status) {
    99             psTrace ("psModules.config", 3, "read recipes from command-line arguments");
    100         } else {
    101             psLogMsg ("psModules.config", PS_LOG_DETAIL, "no recipe supplied on command-line arguments");
    102         }
     96            return false;
     97        }
     98        if (status) {
     99            psTrace ("psModules.config", 3, "read recipes from command-line arguments");
     100        } else {
     101            psLogMsg ("psModules.config", PS_LOG_DETAIL, "no recipe supplied on command-line arguments");
     102        }
    103103        if (!loadRecipeSymbols(&status, config)) {
    104104            psError(PS_ERR_IO, false, "Failed to read recipes from symbolic references");
    105             return false;
    106         } 
    107         if (status) {
    108             psTrace ("psModules.config", 3, "read recipes from symbolic references");
    109         } else {
    110             psLogMsg ("psModules.config", PS_LOG_DETAIL, "no recipe supplied by symbolic reference");
    111         }
     105            return false;
     106        }
     107        if (status) {
     108            psTrace ("psModules.config", 3, "read recipes from symbolic references");
     109        } else {
     110            psLogMsg ("psModules.config", PS_LOG_DETAIL, "no recipe supplied by symbolic reference");
     111        }
    112112        if (!loadRecipeOptions(&status, config)) {
    113113            psError(PS_ERR_IO, false, "Failed to read recipes from symbolic references");
    114             return false;
    115         } 
    116         if (status) {
     114            return false;
     115        }
     116        if (status) {
    117117            psTrace ("psModules.config", 3, "read recipes from command-line arguments");
    118118        } else {
     
    135135        options = psMetadataAlloc();
    136136        success = psMetadataAddPtr(config->arguments, PS_LIST_TAIL, "OPTIONS",  PS_DATA_METADATA, "Command-line options specified with -D", options);
    137         assert (success); // type mismatch : OPTIONS already defined but wrong type
    138         psFree (options); // drop extra reference
     137        assert (success); // type mismatch : OPTIONS already defined but wrong type
     138        psFree (options); // drop extra reference
    139139    }
    140140
     
    176176            recipe = psMetadataAlloc();
    177177            success = psMetadataAddPtr(options, PS_LIST_TAIL, recipeName,  PS_DATA_METADATA, "", recipe);
    178             assert (success); // type mismatch : recipe already defined but wrong type
    179             psFree (recipe); // drop extra reference
     178            assert (success); // type mismatch : recipe already defined but wrong type
     179            psFree (recipe); // drop extra reference
    180180        }
    181181
     
    216216bool pmConfigLoadRecipeArguments (int *argc, char **argv, pmConfig *config)
    217217{
    218     bool success; 
     218    bool success;
    219219
    220220    psMetadata *recipes = psMetadataLookupMetadata(&success, config->arguments, "RECIPES");
     
    222222        recipes = psMetadataAlloc();
    223223        success = psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "RECIPES",  PS_DATA_METADATA, "", recipes);
    224         assert (success);
    225         psFree (recipes);
     224        assert (success);
     225        psFree (recipes);
    226226    }
    227227
     
    271271// Load the recipe files for SITE : REQUIRED
    272272static bool loadRecipeSite(bool *status,
    273                            pmConfig *config, // The configuration into which to read the recipes
    274                            psMetadata *source // The source configuration, from which to read the filenames
     273                           pmConfig *config, // The configuration into which to read the recipes
     274                           psMetadata *source // The source configuration, from which to read the filenames
    275275    )
    276276{
     
    300300        if (fileItem->type != PS_DATA_STRING) {
    301301            psError(PS_ERR_IO, true, "%s in site configuration RECIPES is not of type STR", fileItem->name);
    302             return false;
     302            return false;
    303303        }
    304304
    305305        // Read the recipe file. if we fail on a file, give a warning, but continue
    306306        psMetadata *recipe = NULL;
    307         if (!pmConfigFileRead(&recipe, fileItem->data.V, "recipe")) {
    308             psError(PS_ERR_IO, false, "Failed to read recipe file %s listed in site configuration\n", (char *)fileItem->data.V);
    309             return false;
     307        if (!pmConfigFileRead(&recipe, fileItem->data.str, "recipe")) {
     308            psError(PS_ERR_IO, false, "Failed to read recipe file %s listed in site configuration\n",
     309                    fileItem->data.str);
     310            return false;
    310311        }
    311312
    312313        // if this named recipe exists, supplement it
    313         psMetadataAdd(config->recipes, PS_LIST_TAIL, fileItem->name, PS_DATA_METADATA | PS_META_REPLACE,
    314                       fileItem->comment, recipe);
     314        psMetadataAdd(config->recipes, PS_LIST_TAIL, fileItem->name, PS_DATA_METADATA | PS_META_REPLACE,
     315                      fileItem->comment, recipe);
    315316        psFree(recipe);  // Drop reference
    316317    }
     
    326327// for sourceType == SITE | CAMERA, RECIPES contains a list of files to be read (pmConfigFileRead)
    327328static bool loadRecipeCamera(bool *status, // status variable
    328                              pmConfig *config, // The configuration into which to read the recipes
    329                              psMetadata *source // The source configuration, from which to read the filenames
     329                             pmConfig *config, // The configuration into which to read the recipes
     330                             psMetadata *source // The source configuration, from which to read the filenames
    330331    )
    331332{
     
    345346    psMetadata *recipes = psMetadataLookupMetadata(&success, source, "RECIPES"); // The list of recipes
    346347    if (!recipes) {
    347         psTrace ("psModules.config", 3, "RECIPES not found in the camera configuration\n");
     348        psTrace ("psModules.config", 3, "RECIPES not found in the camera configuration\n");
    348349        return true;
    349350    }
     
    355356    psMetadataItem *fileItem = NULL;    // MD item containing the filename, from recipe iteration
    356357    while ((fileItem = psMetadataGetAndIncrement(recipesIter))) {
    357         char *recipeName = fileItem->name;
    358         char *recipeFile = fileItem->data.V;
    359 
    360         psTrace("psModules.config", 3, "Supplementing %s from %s within camera configuration.\n", recipeName, recipeFile);
     358        char *recipeName = fileItem->name;
     359        char *recipeFile = fileItem->data.str;
     360
     361        psTrace("psModules.config", 3, "Supplementing %s from %s within camera configuration.\n", recipeName, recipeFile);
    361362
    362363        // type mismatch is a serious error
     
    368369        psMetadata *recipe = NULL;
    369370        if (!pmConfigFileRead(&recipe, recipeFile, "recipe")) {
    370             psError(PS_ERR_IO, false, "Failed to read recipe file %s listed in camera configuration\n", recipeFile);
    371             return false;
     371            psError(PS_ERR_IO, false, "Failed to read recipe file %s listed in camera configuration\n",
     372                    recipeFile);
     373            return false;
    372374        }
    373375
    374376        // the named recipe must exist; supplement it
    375         psMetadata *current = psMetadataLookupMetadata(NULL, config->recipes, recipeName);
    376         if (!current) {
    377             psError(PS_ERR_IO, false, "Failed to find recipe for %s in master recipe list", recipeName);
    378             psFree(recipe);  // Drop reference
    379             return false;
    380         }
    381 
    382         if (!psMetadataUpdate(current, recipe)) {
    383             psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", recipeName);
    384             psFree(recipe);  // Drop reference
    385             return false;
    386         }
     377        psMetadata *current = psMetadataLookupMetadata(NULL, config->recipes, recipeName);
     378        if (!current) {
     379            psError(PS_ERR_IO, false, "Failed to find recipe for %s in master recipe list", recipeName);
     380            psFree(recipe);  // Drop reference
     381            return false;
     382        }
     383
     384        if (!psMetadataUpdate(current, recipe)) {
     385            psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", recipeName);
     386            psFree(recipe);  // Drop reference
     387            return false;
     388        }
    387389        psFree(recipe);  // Drop reference
    388390    }
     
    397399// entries for an existing recipe metadata
    398400static bool loadRecipeFromArguments(bool *status,
    399                                     pmConfig *config // The configuration into which to read the recipes
     401                                    pmConfig *config // The configuration into which to read the recipes
    400402    )
    401403{
     
    425427        // increment the ref counter to protect the data
    426428
    427         psMetadata *recipe = item->data.V; // Recipe of interest
     429        psMetadata *recipe = item->data.md; // Recipe of interest
    428430
    429431        // if this named recipe exists, supplement it
    430432        psMetadata *current = psMetadataLookupMetadata(NULL, config->recipes, item->name);
    431433        if (!current) {
    432             psError(PS_ERR_IO, false, "Failed to find recipe for %s in master recipe list", item->name);
    433             psFree(recipe);  // Drop reference
    434             return false;
    435         }
    436         psTrace("psModules.config", 3, "Supplementing %s from arguments.\n", item->name);
     434            psError(PS_ERR_IO, false, "Failed to find recipe for %s in master recipe list", item->name);
     435            psFree(recipe);  // Drop reference
     436            return false;
     437        }
     438        psTrace("psModules.config", 3, "Supplementing %s from arguments.\n", item->name);
    437439
    438440        if (!psMetadataUpdate (current, recipe)) {
    439             psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", item->name);
    440             return false;
    441         }
     441            psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", item->name);
     442            return false;
     443        }
    442444    }
    443445    psFree(recipesIter);
     
    449451// entries for an existing recipe metadata
    450452static bool loadRecipeSymbols(bool *status,
    451                               pmConfig *config // The configuration into which to read the recipes
     453                              pmConfig *config // The configuration into which to read the recipes
    452454    )
    453455{
     
    465467    while ((item = psMetadataGetAndIncrement(iter))) {
    466468        assert(item->type == PS_DATA_STRING); // It should be this type: we put it in ourselves
    467         const char *sourceName = item->data.V; // The name of the symbolic reference
     469        const char *sourceName = item->data.str; // The name of the symbolic reference
    468470        const char *targetName = item->name;
    469         psTrace("psModules.config", 3, "Supplementing %s from %s.\n", targetName, sourceName);
    470 
    471         // the target recipe must exist; select it
    472         psMetadata *targetMD = psMetadataLookupMetadata(&found, config->recipes, targetName);
    473         if (!targetMD) {
    474             psError(PS_ERR_IO, true, "Failed to find recipe for %s in master recipe list", targetName);
    475             return false;
    476         }
     471        psTrace("psModules.config", 3, "Supplementing %s from %s.\n", targetName, sourceName);
     472
     473        // the target recipe must exist; select it
     474        psMetadata *targetMD = psMetadataLookupMetadata(&found, config->recipes, targetName);
     475        if (!targetMD) {
     476            psError(PS_ERR_IO, true, "Failed to find recipe for %s in master recipe list", targetName);
     477            return false;
     478        }
    477479
    478480        // search for sourceName : it may be in config->recipes or target MD
    479481        psMetadata *sourceMD = NULL;
    480         sourceMD = psMetadataLookupMetadata(&found, config->recipes, sourceName);
     482        sourceMD = psMetadataLookupMetadata(&found, config->recipes, sourceName);
    481483        if (!sourceMD) {
    482             sourceMD = psMetadataLookupMetadata(&found, targetMD, sourceName);
    483             if (!sourceMD) {
    484                 psError(PS_ERR_IO, false, "Selected symbolic name %s does not exist in recipes", sourceName);
    485                 return false;
    486             }
    487         }
    488 
    489         if (!psMetadataUpdate(targetMD, sourceMD)) {
    490             psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", targetName);
    491             return false;
    492         }
     484            sourceMD = psMetadataLookupMetadata(&found, targetMD, sourceName);
     485            if (!sourceMD) {
     486                psError(PS_ERR_IO, false, "Selected symbolic name %s does not exist in recipes", sourceName);
     487                return false;
     488            }
     489        }
     490
     491        if (!psMetadataUpdate(targetMD, sourceMD)) {
     492            psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", targetName);
     493            return false;
     494        }
    493495    }
    494496    psFree(iter);
     
    501503// entries for an existing recipe metadata
    502504static bool loadRecipeOptions(bool *status,
    503                               pmConfig *config // The configuration into which to read the recipes
     505                              pmConfig *config // The configuration into which to read the recipes
    504506    )
    505507{
     
    524526    psMetadataItem *item = NULL;    // MD item containing the filename, from recipe iteration
    525527    while ((item = psMetadataGetAndIncrement(recipesIter))) {
    526         char *recipeName = item->name;
    527         psMetadata *recipe = item->data.V;
     528        char *recipeName = item->name;
     529        psMetadata *recipe = item->data.md;
    528530
    529531        // type mismatch is a serious error
     
    535537        psMetadata *current = psMetadataLookupMetadata(NULL, config->recipes, recipeName);
    536538        if (!current) {
    537             psError(PS_ERR_IO, false, "Selected recipe %s is not found in camera recipe", recipeName);
    538             return false;
    539         }
     539            psError(PS_ERR_IO, false, "Selected recipe %s is not found in camera recipe", recipeName);
     540            return false;
     541        }
    540542        if (!psMetadataUpdate (current, recipe)) {
    541             psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", recipeName);
    542             return false;
    543         }
     543            psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", recipeName);
     544            return false;
     545        }
    544546    }
    545547    psFree(recipesIter);
Note: See TracChangeset for help on using the changeset viewer.