IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17498


Ignore:
Timestamp:
May 1, 2008, 2:10:43 PM (18 years ago)
Author:
eugene
Message:

adding UPDATE, REPLACE options for METADATA and MULTI entries

Location:
branches/eam_branch_20080430/psLib/src/types
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20080430/psLib/src/types/psMetadata.c

    r17494 r17498  
    1212 *  @author Ross Harman, MHPCC
    1313 *
    14  *  @version $Revision: 1.168.6.1 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2008-04-30 21:04:22 $
     14 *  @version $Revision: 1.168.6.2 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2008-05-02 00:10:43 $
    1616 *
    1717 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    642642}
    643643
    644 
     644// XXX is it sensible that item is a 'const' here?
    645645bool psMetadataAddItem(psMetadata *md,
    646646                       const psMetadataItem *item,
     
    648648                       psS32 flags)
    649649{
    650     char * key = NULL;
    651     psHash *mdTable = NULL;
    652     psList *mdList = NULL;
    653     psMetadataItem *existingEntry = NULL;
    654 
    655650    PS_ASSERT_METADATA_NON_NULL(md,false);
    656651    PS_ASSERT_METADATA_ITEM_NON_NULL(item,false);
    657652
    658     mdTable = md->hash;
    659     mdList = md->list;
    660     key = item->name;
     653    psHash *mdTable = md->hash;
     654    psList *mdList = md->list;
     655    char *key = item->name;
    661656
    662657    // See if key is already in table
    663     existingEntry = (psMetadataItem*)psHashLookup(mdTable, key);
    664 
     658    psMetadataItem *existingEntry = psHashLookup(mdTable, key);
     659
     660    // this block handles cases for the MULTI items
    665661    if (item->type == PS_DATA_METADATA_MULTI) {
    666662        // the incoming entry is PS_DATA_METADATA_MULTI
    667663
    668         //Shouldn't have a second reference to the same MULTI in a single Metadata!
     664        // Shouldn't have a second reference to the same MULTI in a single Metadata!
     665        // XXX not sure I understand this case
    669666        if (item == existingEntry) {
    670             psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    671                     "Cannot have 2 references to the same MULTI in a single Metadata!");
     667            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Cannot have 2 references to the same MULTI in a single Metadata!");
    672668            return false;
    673669        }
    674670
    675         // force the hash entry to be PS_DATA_METADATA_MULTI
    676         existingEntry = makeMetaMulti(mdTable,key,existingEntry);
     671        if (flags & PS_META_REPLACE) {
     672            // drop the existing entry or entries
     673            psMetadataRemoveKey(md, key);
     674        } else {
     675            // elevate the existing hash entry to be PS_DATA_METADATA_MULTI
     676            existingEntry = makeMetaMulti(mdTable,key,existingEntry);
     677        }
    677678
    678679        // add all the items in the incoming entry to metadata
     
    690691    }
    691692
     693    // special block for items which are METADATA folders
     694    if (item->type == PS_DATA_METADATA) {
     695        if (flags & PS_META_REPLACE) {
     696            // drop the existing entry (skip if we are replacing with same pointer)
     697            // XXX what if existingEntry is a MULTI?  drop all?
     698            if (item != existingEntry) {
     699                psMetadataRemoveKey(md, key);
     700            }
     701        }
     702        if (flags & PS_META_UPDATE_FOLDER) {
     703            if (existingEntry->type != PS_DATA_METADATA) {
     704                psError(PS_ERR_UNKNOWN, false, "invalid to request UPDATE for metadata which matches another type");
     705                return false;
     706            }
     707               
     708            // merge the existing entry : this completes the insert
     709            if (!psMetadataCopy ((psMetadata *)existingEntry->data.V, (psMetadata *)item->data.V)) {
     710                psError(PS_ERR_UNKNOWN, false, "failed to copy new metadata on existing");
     711                return false;
     712            }
     713            return true;
     714        }
     715    }
     716
    692717    // how the item is added to the hash depends on prior existence, flags, etc.
     718    // XXX i think these cases are overloaded - are all combinations possible?
    693719    if (existingEntry) { // prior existence
    694         if (existingEntry->type == PS_DATA_METADATA_MULTI || (flags & PS_META_DUPLICATE_OK)) {
    695             // duplicate entries allowed - add another entry.
     720
     721        // duplicate entries allowed - add another entry.
     722        if ((existingEntry->type == PS_DATA_METADATA_MULTI) || (flags & PS_META_DUPLICATE_OK)) {
    696723
    697724            // make sure the existing entry is PS_DATA_METADATA_MULTI
    698725            existingEntry = makeMetaMulti(mdTable,key,existingEntry);
    699726
    700             // add to the hash's list of duplicate entries
    701             if (!psListAdd(existingEntry->data.list, PS_LIST_TAIL, (psPtr)item) ) {
    702                 psError(PS_ERR_UNKNOWN, false,
    703                         _("Failed to add metadata item, %s, to metadata collection list."),
    704                         key);
     727            // add item to the existing hash's list of duplicate entries
     728            if (!psListAdd(existingEntry->data.list, PS_LIST_TAIL, (psMetadataItem *) item) ) {
     729                psError(PS_ERR_UNKNOWN, false, _("Failed to add metadata item, %s, to metadata collection list."), key);
    705730                return false;
    706731            }
    707         } else if (flags & PS_META_REPLACE) {
    708             // replace entry instead of creating a duplicate entry.
     732            // add to the metadata list of entries
     733            if (!psListAdd(mdList, location, (psMetadataItem *) item)) {
     734                psError(PS_ERR_UNKNOWN, false, _("Failed to add metadata item, %s, to metadata collection list."), key);
     735                return false;
     736            }
     737            return true;
     738        }
     739
     740        // replace entry instead of creating a duplicate entry.
     741        if (flags & PS_META_REPLACE) {
    709742
    710743            if ((flags & PS_META_REQUIRE_TYPE) && (existingEntry->type != item->type)) {
     
    716749                // when you blow away what you're trying to add
    717750                psMetadataRemoveKey(md, key);
    718                 psHashAdd(mdTable, key, (psPtr)item);
    719             }
    720         } else {
    721             // default is to error on duplicate entry.
    722             if (flags & PS_META_NO_REPLACE) {
    723                 return true;
    724             }
    725             psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    726                     _("Duplicate metadata item name: %s is not allowed.  "
    727                       "Use a psMetadataFlags option to allow such action."), item->name);
    728             return false;
    729         }
    730     } else {
    731         // OK, this is a new item.
    732         if (flags & PS_META_REQUIRE_ENTRY) {
    733             psError (PS_ERR_UNKNOWN, true, _("No matching item found for item requiring existing entry (%s)"),
    734                      key);
    735             return false;
    736         }
    737 
    738         // Node doesn't exist - Add new metadata item to metadata collection's hash
    739         /*  The following is unneeded.  HashAdd can't return false with non-null inputs.
    740 
    741                 if(!psHashAdd(mdTable, key, (psPtr)item)) {
    742                     psError(PS_ERR_UNKNOWN,false,
    743                             _("Failed to add metadata item, %s, to items table."),key);
    744                     return false;
    745                 }
    746         */
    747         psHashAdd(mdTable, key, (psPtr)item);
    748         // Create a multi, if required
    749         if (flags & PS_META_DUPLICATE_OK) {
    750             makeMetaMulti(mdTable,key,(psMetadataItem*)item); // Casting away const!
    751         }
    752     }
    753 
    754     if(!psListAdd(mdList, location, (psPtr)item)) {
    755         psError(PS_ERR_UNKNOWN, false,
    756                 _("Failed to add metadata item, %s, to metadata collection list."), key);
     751                // add to the metadata has of entries
     752                if (!psHashAdd(mdTable, key, (psMetadataItem *) item)) {
     753                    psError(PS_ERR_UNKNOWN, false, _("Failed to add metadata item, %s, to metadata collection list."), key);
     754                    return false;
     755                }                   
     756                // add to the metadata list of entries
     757                if (!psListAdd(mdList, location, (psMetadataItem *) item)) {
     758                    psError(PS_ERR_UNKNOWN, false, _("Failed to add metadata item, %s, to metadata collection list."), key);
     759                    return false;
     760                }
     761                return true;
     762            }
     763        }
     764
     765        // if specified, keep the existing entry
     766        if (flags & PS_META_NO_REPLACE) {
     767            return true;
     768        }
     769
     770        // default is to error on duplicate entry.
     771        psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Duplicate metadata item name: %s is not allowed.  Use a psMetadataFlags option to allow such action."), item->name);
     772        return false;
     773    }
     774
     775    // OK, this is a new item.
     776    if (flags & PS_META_REQUIRE_ENTRY) {
     777        psError (PS_ERR_UNKNOWN, true, _("No matching item found for item requiring existing entry (%s)"), key);
     778        return false;
     779    }
     780
     781    // Node doesn't exist - Add new metadata item to metadata collection's hash
     782    psHashAdd(mdTable, key, (psMetadataItem *) item);
     783
     784    // Create a multi, if requested
     785    if (flags & PS_META_DUPLICATE_OK) {
     786        makeMetaMulti(mdTable, key, (psMetadataItem *) item); // Casting away const!
     787    }
     788
     789    if (!psListAdd(mdList, location, (psPtr)item)) {
     790        psError(PS_ERR_UNKNOWN, false, _("Failed to add metadata item, %s, to metadata collection list."), key);
    757791        return false;
    758792    }
  • branches/eam_branch_20080430/psLib/src/types/psMetadata.h

    r17494 r17498  
    99*  @author Ross Harman, MHPCC
    1010*
    11 *  @version $Revision: 1.103.12.1 $ $Name: not supported by cvs2svn $
    12 *  @date $Date: 2008-04-30 21:04:22 $
     11*  @version $Revision: 1.103.12.2 $ $Name: not supported by cvs2svn $
     12*  @date $Date: 2008-05-02 00:10:43 $
    1313*
    1414*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    7070#define PS_METADATA_TYPE_MASK 0x00FFFFFF
    7171
    72 #define PS_METADATA_ITEM_TYPE(ITEM) (MD->type & PS_METADATA_TYPE_MASK)
     72#define PS_METADATA_ITEM_GET_TYPE(MDITEM) (MDITEM->type & PS_METADATA_TYPE_MASK)
    7373
    7474/** Metadata data structure.
  • branches/eam_branch_20080430/psLib/src/types/psMetadataConfig.c

    r17494 r17498  
    1111*  @author Joshua Hoblitt, University of Hawaii 2006-2007
    1212*
    13 *  @version $Revision: 1.142.8.1 $ $Name: not supported by cvs2svn $
    14 *  @date $Date: 2008-04-30 21:04:22 $
     13*  @version $Revision: 1.142.8.2 $ $Name: not supported by cvs2svn $
     14*  @date $Date: 2008-05-02 00:10:43 $
    1515*
    1616*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    819819            // found a directive, what does it say?
    820820            if (strcasecmp (strValue, "UPDATE") && strcasecmp (strValue, "UPDATE")) {
    821                 psError(PS_ERR_IO, true, _("Invalid directive %s for METADATA or MULTI.", strValue));
     821                psError(PS_ERR_IO, true, _("Invalid directive %s for METADATA or MULTI."), strValue);
    822822                psFree(strType);
    823823                psFree(strValue);
Note: See TracChangeset for help on using the changeset viewer.