IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 3, 2004, 3:05:00 PM (22 years ago)
Author:
desonia
Message:

changed the psError signature to match SDRS. Also made misc. cleanups as
I was combing the files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/collections/psMetadata.c

    r2204 r2273  
    1212*  @author Ross Harman, MHPCC
    1313*
    14 *  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
    15 *  @date $Date: 2004-10-27 00:57:30 $
     14*  @version $Revision: 1.36 $ $Name: not supported by cvs2svn $
     15*  @date $Date: 2004-11-04 01:04:57 $
    1616*
    1717*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3535#include "psMetadata.h"
    3636#include "psString.h"
     37#include "psAstronomyErrors.h"
     38#include "psConstants.h"
    3739
    3840/******************************************************************************/
     
    123125
    124126
    125     if (name == NULL) {
    126         psError(__func__, "Null value for name not allowed");
    127         return NULL;
    128     }
     127    PS_PTR_CHECK_NULL(name,NULL);
     128
    129129    // Allocate metadata item
    130130    metadataItem = (psMetadataItem* ) psAlloc(sizeof(psMetadataItem));
     
    147147    // Set metadata item type
    148148    metadataItem->type = type;
     149    metadataItem->data.V = NULL;
     150
     151    // Allocate metadata items with same name.
     152    metadataItem->items = psListAlloc(NULL);
     153
     154    // Allocate and set metadata item name
     155    metadataItem->name = (char *)psAlloc(sizeof(char) * MAX_STRING_LENGTH);
     156    vsprintf(metadataItem->name, name, argPtr);
    149157
    150158    // Set metadata item value
    151159    switch (type) {
    152160    case PS_META_ITEM_SET:
    153         metadataItem->data.V = NULL;
    154161        break;
    155162    case PS_META_BOOL:
     
    180187    case PS_META_UNKNOWN:
    181188    default:
    182         psError(__func__, "Invalid psMetadataType: %d", type);
    183     }
    184 
    185     // Allocate and set metadata item name
    186     metadataItem->name = (char *)psAlloc(sizeof(char) * MAX_STRING_LENGTH);
    187     vsprintf(metadataItem->name, name, argPtr);
    188 
    189     // Allocate metadata items with same name.
    190     metadataItem->items = psListAlloc(NULL);
     189        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     190                PS_ERRORTEXT_psMetadata_METATYPE_INVALID,
     191                type);
     192        psFree(metadataItem);
     193        metadataItem = NULL;
     194    }
    191195
    192196    return metadataItem;
     
    224228    psMetadataType newType = PS_META_ITEM_SET;
    225229
    226     if(md == NULL) {
    227         psError( __func__, "Null metadata collection not allowed" );
    228         return false;
    229     }
    230 
    231     if(metadataItem == NULL) {
    232         psError( __func__, "Null metadata item not allowed" );
    233         return false;
    234     }
     230    PS_PTR_CHECK_NULL(md,NULL);
     231    PS_PTR_CHECK_NULL(md->table,NULL);
     232    PS_PTR_CHECK_NULL(md->list,NULL);
     233    PS_PTR_CHECK_NULL(metadataItem,NULL);
     234    PS_PTR_CHECK_NULL(metadataItem->name,NULL);
    235235
    236236    newType = metadataItem->type;
    237 
    238237    mdTable = md->table;
    239     if(mdTable == NULL) {
    240         psError( __func__, "Null metadata table not allowed" );
    241         return false;
    242     }
    243 
    244238    mdList = md->list;
    245     if(mdList == NULL) {
    246         psError( __func__, "Null metadata list not allowed");
    247         return false;
    248     }
    249 
    250239    key = metadataItem->name;
    251     if(key == NULL) {
    252         psError(__func__, "Null key item not allowed");
    253         return false;
    254     }
    255240
    256241    // See if key is already in table
     
    262247            // Add leaf node to existing folder node
    263248            if(!psListAdd(existingEntry->items, PS_LIST_TAIL, metadataItem)) {
    264                 psError( __func__, "Couldn't add metadata item to items list. Name: %s",
    265                          metadataItem->name );
     249                psError(PS_ERR_UNKNOWN,false,
     250                        PS_ERRORTEXT_psMetadata_ADD_LIST_FAILED,
     251                        metadataItem->name );
    266252                return false;
    267253            }
     
    272258
    273259            if(!psListAdd(newFolderEntry->items, PS_LIST_TAIL, existingEntry)) {
    274                 psError( __func__, "Couldn't add metadata item to items list. Name: %s", key);
     260                psError(PS_ERR_UNKNOWN,false,
     261                        PS_ERRORTEXT_psMetadata_ADD_LIST_FAILED,
     262                        key);
    275263                psFree(newFolderEntry);
    276264                return false;
     
    278266
    279267            if(!psListAdd(newFolderEntry->items, PS_LIST_TAIL, metadataItem)) {
    280                 psError( __func__, "Couldn't add metadata item to items list. Name: %s", key);
     268                psError(PS_ERR_UNKNOWN,false,
     269                        PS_ERRORTEXT_psMetadata_ADD_LIST_FAILED,
     270                        key);
    281271                psFree(newFolderEntry);
    282272                return false;
     
    284274
    285275            if(!psHashRemove(mdTable, key)) {
    286                 psError( __func__, "Couldn't remove metadata item from metadata table. Name: %s", key);
     276                psError(PS_ERR_UNKNOWN,false,
     277                        PS_ERRORTEXT_psMetadata_REMOVE_TABLE_FAILED,
     278                        key);
    287279                psFree(newFolderEntry);
    288280                return false;
     
    290282
    291283            if(!psHashAdd(mdTable, key, newFolderEntry)) {
    292                 psError( __func__, "Couldn't add metadata item to metadata table. Name: %s", key);
     284                psError(PS_ERR_UNKNOWN,false,
     285                        PS_ERRORTEXT_psMetadata_ADD_TABLE_FAILED,
     286                        key);
    293287                psFree(newFolderEntry);
    294288                return false;
     
    301295            // Folder node replaces leaf or folder node - Put old node into new folder and remove from table
    302296            if(!psListAdd(metadataItem->items, PS_LIST_TAIL, existingEntry)) {
    303                 psError( __func__, "Couldn't add metadata item to items list. Name: %s", key);
     297                psError(PS_ERR_UNKNOWN,false,
     298                        PS_ERRORTEXT_psMetadata_ADD_LIST_FAILED,
     299                        key);
    304300                return false;
    305301            }
    306302
    307303            if(!psHashRemove(mdTable, key)) {
    308                 psError( __func__, "Couldn't remove metadata item from metadata table. Name: %s", key);
     304                psError(PS_ERR_UNKNOWN,false,
     305                        PS_ERRORTEXT_psMetadata_REMOVE_TABLE_FAILED,
     306                        key);
    309307                return false;
    310308            }
    311309
    312310            if(!psHashAdd(mdTable, key, metadataItem)) {
    313                 psError( __func__, "Couldn't add metadata item to metadata table. Name: %s", key);
     311                psError(PS_ERR_UNKNOWN,false,
     312                        PS_ERRORTEXT_psMetadata_ADD_TABLE_FAILED,
     313                        key);
    314314                return false;
    315315            }
     
    319319        // Node doesn't exist - Add new metadata item to metadata collection's hash
    320320        if(!psHashAdd(mdTable, key, metadataItem)) {
    321             psError( __func__, "Couldn't add metadata item to metadata table. Name: %s", key);
     321            psError(PS_ERR_UNKNOWN,false,
     322                    PS_ERRORTEXT_psMetadata_ADD_TABLE_FAILED,
     323                    key);
    322324            return false;
    323325        }
     
    328330    if(metadataItem->type != PS_META_ITEM_SET) {
    329331        if(!psListAdd(mdList, location, metadataItem)) {
    330             psError( __func__, "Couldn't add metadata item to metadata collection list. Name: %s",
    331                      metadataItem->name );
     332            psError(PS_ERR_UNKNOWN,false,
     333                    PS_ERRORTEXT_psMetadata_ADD_COLLECTION_FAILED,
     334                    key);
    332335            return false;
    333336        }
     
    348351
    349352    if (!psMetadataAddItem(md, metadataItem, where)) {
    350         psError(__func__, "Couldn't add metadata item to metadata collection list. Name: %s",
    351                 metadataItem->name);
     353        psError(PS_ERR_UNKNOWN,false,
     354                PS_ERRORTEXT_psMetadata_ADD_FAILED);
    352355        psFree(metadataItem);
    353356        return false;
     
    368371
    369372
    370     if (md == NULL) {
    371         psError(__func__, "Null metadata collection not allowed");
    372         return false;
    373     }
     373    PS_PTR_CHECK_NULL(md,NULL);
     374    PS_PTR_CHECK_NULL(md->table,NULL);
     375    PS_PTR_CHECK_NULL(md->list,NULL);
    374376
    375377    mdList = md->list;
    376     if (mdList == NULL) {
    377         psError(__func__, "Null metadata list not allowed");
    378         return false;
    379     }
    380 
    381378    mdTable = md->table;
    382     if (mdTable == NULL) {
    383         psError(__func__, "Null metadata table not allowed");
    384         return false;
    385     }
     379
    386380    // Select removal by key or index
    387381    if (key != NULL) {
     
    390384        entry = (psMetadataItem* ) psHashLookup(mdTable, key);
    391385        if (entry == NULL) {
    392             psError(__func__, "Couldn't find metadata item. Name: %s", key);
     386            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     387                    PS_ERRORTEXT_psMetadata_FIND_FAILED,
     388                    key);
    393389            return false;
    394390        }
     
    402398            while (entryChild != NULL) {
    403399                if (!psListRemove(mdList, PS_LIST_UNKNOWN, entryChild)) {
    404                     psError(__func__, "Couldn't remove metadata item from list. Name: %s", key);
     400                    psError(PS_ERR_UNKNOWN,false,
     401                            PS_ERRORTEXT_psMetadata_REMOVE_LIST_FAILED,
     402                            key);
    405403                    return false;
    406404                }
     
    411409            // Table entry has no children. Remove entry from metadata collection's list
    412410            if (!psListRemove(mdList, PS_LIST_UNKNOWN, entry)) {
    413                 psError(__func__, "Couldn't remove metadata item from list. Name: %s", key);
     411                psError(PS_ERR_UNKNOWN,false,
     412                        PS_ERRORTEXT_psMetadata_REMOVE_LIST_FAILED,
     413                        key);
    414414                return false;
    415415            }
     
    417417        // Remove entry from metadata collection's table
    418418        if (!psHashRemove(mdTable, key)) {
    419             psError(__func__, "Couldn't remove metadata item from table. Name: %s", key);
     419            psError(PS_ERR_UNKNOWN,false,
     420                    PS_ERRORTEXT_psMetadata_REMOVE_TABLE_FAILED,
     421                    key);
    420422            return false;
    421423        }
     
    425427        entry = psListGet(mdList, where);
    426428        if (entry == NULL) {
    427             psError(__func__, "Couldn't find metadata item in list. Index: %d", where);
     429            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     430                    PS_ERRORTEXT_psMetadata_FIND_INDEX_FAILED,
     431                    where);
    428432            return false;
    429433        }
     
    431435        key = entry->name;
    432436        if (key == NULL) {
    433             psError(__func__, "Null key name not allowed. Index: %d", where);
     437            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     438                    PS_ERRORTEXT_psMetadata_REMOVE_LIST_INDEX_FAILED,
     439                    where);
    434440            return false;
    435441        }
     
    447453
    448454
    449     if (md == NULL) {
    450         psError(__func__, "Null metadata collection not allowed");
    451         return NULL;
    452     }
     455    PS_PTR_CHECK_NULL(md,NULL);
     456    PS_PTR_CHECK_NULL(md->table,NULL);
     457    PS_PTR_CHECK_NULL(key,NULL);
    453458
    454459    mdTable = md->table;
    455     if (mdTable == NULL) {
    456         psError(__func__, "Null metadata table not allowed");
    457         return NULL;
    458     }
    459 
    460     if (key == NULL) {
    461         psError(__func__, "Null key name not allowed");
    462         return NULL;
    463     }
    464460
    465461    entry = (psMetadataItem* ) psHashLookup(mdTable, key);
     
    473469psMetadataItem* psMetadataGet(psMetadata* restrict md, psS32 where)
    474470{
     471    psMetadataItem* entry = NULL;
     472
     473    PS_PTR_CHECK_NULL(md,NULL);
     474    PS_PTR_CHECK_NULL(md->list,NULL);
     475
     476    entry = (psMetadataItem* ) psListGet(md->list, where);
     477    if (entry == NULL) {
     478        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     479                PS_ERRORTEXT_psMetadata_FIND_INDEX_FAILED,
     480                where);
     481        return NULL;
     482    }
     483
     484    return entry;
     485}
     486
     487psBool psMetadataSetIterator(psMetadata* restrict md, psS32 where)
     488{
     489    PS_PTR_CHECK_NULL(md,NULL);
     490    PS_PTR_CHECK_NULL(md->list,NULL);
     491
     492    psListSetIterator(md->list, where);
     493
     494    return true;
     495}
     496
     497psMetadataItem* psMetadataGetNext(psMetadata* restrict md, const char *restrict match, psS32 which)
     498{
    475499    psList* mdList = NULL;
    476500    psMetadataItem* entry = NULL;
    477501
    478502
    479     if (md == NULL) {
    480         psError(__func__, "Null metadata collection not allowed");
    481         return NULL;
    482     }
     503    PS_PTR_CHECK_NULL(md,NULL);
     504    PS_PTR_CHECK_NULL(md->list,NULL);
    483505
    484506    mdList = md->list;
    485     if (mdList == NULL) {
    486         psError(__func__, "Null metadata list not allowed");
    487         return NULL;
    488     }
    489 
    490     entry = (psMetadataItem* ) psListGet(mdList, where);
    491     if (entry == NULL) {
    492         psError(__func__, "Couldn't find metadata item with given index. Index: %d", where);
    493         return NULL;
    494     }
    495 
    496     return entry;
    497 }
    498 
    499 psBool psMetadataSetIterator(psMetadata* restrict md, psS32 where)
    500 {
    501     psList* mdList = NULL;
    502 
    503     if (md == NULL) {
    504         psError(__func__, "Null metadata collection not allowed");
    505         return false;
    506     }
    507 
    508     mdList = md->list;
    509     if (mdList == NULL) {
    510         psError(__func__, "Null metadata list not allowed");
    511         return false;
    512     }
    513 
    514     psListSetIterator(mdList, where);
    515 
    516     return true;
    517 }
    518 
    519 psMetadataItem* psMetadataGetNext(psMetadata* restrict md, const char *restrict match, psS32 which)
    520 {
    521     psList* mdList = NULL;
    522     psMetadataItem* entry = NULL;
    523 
    524 
    525     if (md == NULL) {
    526         psError(__func__, "Null metadata collection not allowed");
    527         return NULL;
    528     }
    529 
    530     mdList = md->list;
    531     if (mdList == NULL) {
    532         psError(__func__, "Null metadata list not allowed");
    533         return NULL;
    534     }
    535507
    536508    psListSetIterator(mdList, which);
     
    559531
    560532
    561     if (md == NULL) {
    562         psError(__func__, "Null metadata collection not allowed");
    563         return NULL;
    564     }
     533    PS_PTR_CHECK_NULL(md,NULL);
     534    PS_PTR_CHECK_NULL(md->list,NULL);
    565535
    566536    mdList = md->list;
    567     if (mdList == NULL) {
    568         psError(__func__, "Null metadata list not allowed");
    569         return NULL;
    570     }
    571537
    572538    psListSetIterator(mdList, which);
Note: See TracChangeset for help on using the changeset viewer.