IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 14, 2004, 11:14:58 AM (22 years ago)
Author:
desonia
Message:

fixed/tested psErrorRegister and psErrorCodeString.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sysUtils/psErrorCodes.c

    r1905 r2129  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-09-27 20:38:02 $
     9 *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-10-14 21:14:58 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1313 */
     14
     15#include <string.h>
    1416
    1517#include "psError.h"
     
    7577        desc = (psErrorDescription*)psListGet(dynamicErrorCodes,PS_LIST_HEAD);
    7678        while (desc != NULL) {
    77             desc = (psErrorDescription*)psListGetNext(dynamicErrorCodes);
    78             if (desc != NULL && desc->code == code) {
     79            if (desc->code == code) {
    7980                return desc;
    8081            }
     82            desc = (psErrorDescription*)psListGetNext(dynamicErrorCodes);
    8183        }
    8284    }
    8385    return NULL;
    8486}
     87
     88static void freeErrorDescription(psErrorDescription* err)
     89{
     90    psFree((void*)err->description);
     91}
     92
     93psErrorDescription* psErrorDescriptionAlloc(psErrorCode code,
     94        const char *description)
     95{
     96    psErrorDescription* err = psAlloc(sizeof(psErrorDescription));
     97    err->code = code;
     98    if (description == NULL) {
     99        err->description = NULL;
     100    } else {
     101        err->description = psAlloc(sizeof(char)*strlen(description)+1);
     102        strcpy((char*)err->description,description);
     103    }
     104
     105    p_psMemSetDeallocator(err,(psFreeFcn)freeErrorDescription);
     106    return err;
     107}
     108
    85109
    86110const char *psErrorCodeString(psErrorCode code)
     
    114138    }
    115139
     140    if (dynamicErrorCodes == NULL) {
     141        dynamicErrorCodes = psListAlloc(NULL);
     142        p_psMemSetPersistent(dynamicErrorCodes,true);
     143    }
     144
    116145    for (int i=0;i<nerror;i++) {
     146        psErrorDescription* err = psErrorDescriptionAlloc(
     147                                      errors[i].code, errors[i].description);
     148        p_psMemSetPersistent(err,true);
     149        p_psMemSetPersistent((void*)err->description,true);
    117150        if (! psListAdd(dynamicErrorCodes,
    118151                        PS_LIST_HEAD,
    119                         (void*)&errors[i]) ) {
     152                        err) ) {
    120153
    121154            psErrorMsg(PS_ERRORNAME_DOMAIN "psErrorRegister",
     
    124157                       i);
    125158        }
     159        p_psMemSetPersistent(dynamicErrorCodes->head,true);
     160        psFree(err);
    126161    }
    127162}
    128163
     164bool p_psErrorUnregister(psErrorCode code)
     165{
     166    // Check input argument is non-negative
     167    if ( code < 0 ) {
     168        return false;
     169    }
     170
     171    const psErrorDescription* desc = getErrorDescription(code);
     172
     173    if (desc == NULL) {
     174        return false;
     175    }
     176
     177    if (dynamicErrorCodes == NULL) {
     178        return false;
     179    }
     180
     181    return psListRemove(dynamicErrorCodes,PS_LIST_UNKNOWN,(void*)desc);
     182}
Note: See TracChangeset for help on using the changeset viewer.