Changeset 3779 for trunk/psLib/src/collections/psMetadata.c
- Timestamp:
- Apr 27, 2005, 4:45:12 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/collections/psMetadata.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/psMetadata.c
r3765 r3779 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1. 59$ $Name: not supported by cvs2svn $15 * @date $Date: 2005-04-2 3 02:07:27$14 * @version $Revision: 1.60 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2005-04-28 02:45:12 $ 16 16 * 17 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 39 39 #include "psConstants.h" 40 40 41 /******************************************************************************/42 /* DEFINE STATEMENTS */43 /******************************************************************************/44 45 /** Maximum size of a string */46 #define MAX_STRING_LENGTH 102447 48 /******************************************************************************/49 /* TYPE DEFINITIONS */50 /******************************************************************************/51 52 // None53 54 /*****************************************************************************/55 /* GLOBAL VARIABLES */56 /*****************************************************************************/57 58 // None59 60 /*****************************************************************************/61 /* FILE STATIC VARIABLES */62 /*****************************************************************************/63 64 41 static psS32 metadataId = 0; 65 66 /*****************************************************************************/67 /* FUNCTION IMPLEMENTATION - LOCAL */68 /*****************************************************************************/69 42 70 43 static psMetadataItem* makeMetaMulti(psHash* table, const char* key, psMetadataItem* existing) … … 75 48 } 76 49 77 // move any existing entry into a psList78 psList* newList = psListAlloc(existing);79 50 80 51 psMetadataItem* item = psMetadataItemAlloc(key, 81 52 PS_META_MULTI, 82 "", 83 newList); 53 "List of Metadata Items", 54 NULL); 55 56 psListAdd(item->data.list,PS_LIST_TAIL,existing); 84 57 85 58 if (existing != NULL) { … … 87 60 } 88 61 89 psHashAdd(table, key, item); // put in the new entry 90 91 // free local references of newly allocated items. 92 psFree(newList); 62 psHashAdd(table, key, item); // put in the new MULTI list entry 63 64 // free local references of newly allocated item. 93 65 psFree(item); 94 66 … … 174 146 { 175 147 psMetadataItem* metadataItem = NULL; 176 148 char tmp; 149 int nBytes; 177 150 178 151 PS_PTR_CHECK_NULL(name,NULL); … … 185 158 psMemSetDeallocator(metadataItem, (psFreeFcn) metadataItemFree); 186 159 187 // Allocate andset metadata item comment160 // set metadata item comment 188 161 if (comment == NULL) { 189 162 // Per SDRS, null isn't allowed, must use "" instead … … 200 173 201 174 // Allocate and set metadata item name 202 metadataItem->name = (char *)psAlloc(sizeof(char) * MAX_STRING_LENGTH); 175 nBytes = vsnprintf(&tmp, 0, name, argPtr) + 1; 176 metadataItem->name = (char *)psAlloc(sizeof(char) * nBytes); 203 177 vsprintf(metadataItem->name, name, argPtr); 204 178 … … 219 193 case PS_META_STR: 220 194 // Perform copy of input strings 221 metadataItem->data.V = psStringNCopy(va_arg(argPtr, char *), MAX_STRING_LENGTH); 195 metadataItem->data.V = psStringCopy(va_arg(argPtr, char *)); 196 break; 197 case PS_META_MULTI: 198 // MULTI needs to create a psList entry, value must be NULL 199 metadataItem->data.list = psListAlloc(NULL); 222 200 break; 223 201 case PS_META_LIST: … … 229 207 case PS_META_ASTROM: 230 208 case PS_META_UNKNOWN: 231 case PS_META_MULTI:232 209 // Copy of input data not performed due to variability of data types 233 210 metadataItem->data.V = psMemIncrRefCounter(va_arg(argPtr, psPtr)); … … 281 258 282 259 // See if key is already in table 283 existingEntry = (psMetadataItem*)psHashLookup(mdTable, key); 284 260 existingEntry = psMetadataLookup(md, key); 261 262 // if replace is set, remove any existing items of the same key 263 if (existingEntry != NULL && (flags & PS_META_REPLACE) != 0) { 264 psMetadataRemove(md,0,key); 265 existingEntry = NULL; 266 } 267 268 // if the metadataItem is MULTI, just add the encapsulated entries 285 269 if (metadataItem->type == PS_META_MULTI) { 286 // the incoming entry is PS_META_MULTI 287 288 // force the hash entry to be PS_META_MULTI 270 271 // make sure the existing entry is PS_META_MULTI 289 272 existingEntry = makeMetaMulti(mdTable,key,existingEntry); 290 273 274 psBool status = true; 291 275 // add all the items in the incoming entry to metadata 292 276 psList* list = metadataItem->data.list; … … 294 278 psListIterator* iter = psListIteratorAlloc(list,PS_LIST_HEAD,true); 295 279 psMetadataItem* listItem; 296 while ( (listItem=(psMetadataItem*)psListGetAndIncrement(iter)) != NULL) {297 psMetadataAddItem(md,listItem,location,flags);280 while (status && (listItem=(psMetadataItem*)psListGetAndIncrement(iter)) != NULL) { 281 status |= psMetadataAddItem(md,listItem,location,flags); 298 282 } 299 283 psFree(iter); 300 284 } 301 285 302 return true; // all done.286 return status; // all done. 303 287 } 304 288 305 289 // how the item is added to the hash depends on prior existence, flags, etc. 306 if(existingEntry != NULL) { // prior existence 290 if(existingEntry == NULL) { // no prior existence 291 // Node doesn't already exist - Add new metadata item to metadata collection's hash 292 if(!psHashAdd(mdTable, key, metadataItem)) { 293 psError(PS_ERR_UNKNOWN,false,PS_ERRORTEXT_psMetadata_ADD_TABLE_FAILED,key); 294 return false; 295 } 296 } else { 307 297 if (existingEntry->type == PS_META_MULTI || (flags & PS_META_DUPLICATE_OK) != 0) { 308 298 // duplicate entries allowed - add another entry. 309 299 310 // make sure the existing entry is PS_META_MULTI300 // make sure the existing hash entry is PS_META_MULTI 311 301 existingEntry = makeMetaMulti(mdTable,key,existingEntry); 312 302 313 // add to the hash 's list of duplicateentries303 // add to the hash key's list of entries 314 304 if (! psListAdd(existingEntry->data.list, PS_LIST_TAIL, metadataItem) ) { 315 305 psError(PS_ERR_UNKNOWN,false,PS_ERRORTEXT_psMetadata_ADD_COLLECTION_FAILED,key); 316 306 return false; 317 307 } 318 } else if ((flags & PS_META_REPLACE) != 0) {319 // replace entry instead of creating a duplicate entry.320 321 // remove the existing entry from metadata322 psMetadataRemove(md,0,key);323 324 // treat as if new (added to list below)325 if(!psHashAdd(mdTable, key, metadataItem)) {326 psError(PS_ERR_UNKNOWN,false,PS_ERRORTEXT_psMetadata_ADD_TABLE_FAILED,key);327 return false;328 }329 308 } else { 330 // default is toerror on duplicate entry.309 // error on duplicate entry. 331 310 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 332 311 PS_ERRORTEXT_psMetadata_DUPLICATE_NOT_ALLOWED); 333 312 return false; 334 313 } 335 } else { 336 // OK, this is a new item. 337 338 // Node doesn't exist - Add new metadata item to metadata collection's hash 339 if(!psHashAdd(mdTable, key, metadataItem)) { 340 psError(PS_ERR_UNKNOWN,false,PS_ERRORTEXT_psMetadata_ADD_TABLE_FAILED,key); 341 return false; 342 } 343 } 344 314 } 315 316 // finally, add the metadataItem to the metadata's list. 345 317 if(!psListAdd(mdList, location, metadataItem)) { 346 318 psError(PS_ERR_UNKNOWN,false,PS_ERRORTEXT_psMetadata_ADD_COLLECTION_FAILED,key);
Note:
See TracChangeset
for help on using the changeset viewer.
