IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 27, 2004, 10:38:02 AM (22 years ago)
Author:
desonia
Message:

added psErrorRegister.

File:
1 edited

Legend:

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

    r1873 r1905  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-09-24 01:09:18 $
     9 *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-09-27 20:38:02 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1313 */
    1414
     15#include "psError.h"
    1516#include "psErrorCodes.h"
    1617#include "psList.h"
    1718#include "psMemory.h"
     19
     20#include "psSysUtilsErrors.h"
    1821
    1922/* N.B., lines between '//~Start' and '//~End' are automatic generated from
     
    2831 */
    2932
    30 static psErrorDescription errorDescriptions[] = {
     33static psErrorDescription staticErrorCodes[] = {
    3134            {PS_ERR_NONE,"not an error"},
    3235            {PS_ERR_BASE,"base error"},
     
    4649        };
    4750
    48 static psList* errorCodes = NULL;
    49 static psErrorDescription* getErrorDescription(psErrorCode code);
     51static psList* dynamicErrorCodes = NULL;
     52static const psErrorDescription* getErrorDescription(psErrorCode code);
    5053
    5154
    52 static psErrorDescription* getErrorDescription(psErrorCode code)
     55static const psErrorDescription* getErrorDescription(psErrorCode code)
    5356{
    5457    // first, search the static error codes
    5558
    5659    int n = 0;
    57     while(errorDescriptions[n].code != PS_ERR_N_ERR_CLASSES &&
    58             errorDescriptions[n].code != code) {
     60    while(staticErrorCodes[n].code != PS_ERR_N_ERR_CLASSES &&
     61            staticErrorCodes[n].code != code) {
    5962        n++;
    6063    }
    6164
    62     if (errorDescriptions[n].code == code) {
    63         return &errorDescriptions[n];
     65    if (staticErrorCodes[n].code == code) {
     66        return &staticErrorCodes[n];
    6467    } else {
    6568        psErrorDescription* desc;
    6669        // make sure there is a list to search
    67         if (errorCodes == NULL) {
     70        if (dynamicErrorCodes == NULL) {
    6871            return NULL;
    6972        }
    7073
    7174        // search dynamic list of error descriptions before giving up.
    72         desc = (psErrorDescription*)psListGet(errorCodes,PS_LIST_HEAD);
    73         while (desc != NULL && desc->code != code) {
    74             desc = (psErrorDescription*)psListGetNext(errorCodes);
    75         }
    76 
    77         if (desc != NULL && desc->code == code) {
    78             return psMemIncrRefCounter(desc);
     75        desc = (psErrorDescription*)psListGet(dynamicErrorCodes,PS_LIST_HEAD);
     76        while (desc != NULL) {
     77            desc = (psErrorDescription*)psListGetNext(dynamicErrorCodes);
     78            if (desc != NULL && desc->code == code) {
     79                return desc;
     80            }
    7981        }
    8082    }
     
    8991    }
    9092
    91     psErrorDescription* desc = getErrorDescription(code);
     93    const psErrorDescription* desc = getErrorDescription(code);
    9294
    9395    if (desc == NULL) {
     
    98100}
    99101
     102void psErrorRegister(const psErrorDescription* errors,
     103                     int nerror)
     104{
     105    if (nerror < 1) {
     106        return;
     107    }
     108
     109    if (errors == NULL) {
     110        psErrorMsg(PS_ERRORNAME_DOMAIN "psErrorRegister",
     111                   PS_ERR_BAD_PARAMETER_NULL, true,
     112                   PS_ERRORTEXT_psErrorCode_NULL_ERRORDESCRIPTION);
     113        return;
     114    }
     115
     116    for (int i=0;i<nerror;i++) {
     117        if (! psListAdd(dynamicErrorCodes,
     118                        PS_LIST_HEAD,
     119                        (void*)&errors[i]) ) {
     120
     121            psErrorMsg(PS_ERRORNAME_DOMAIN "psErrorRegister",
     122                       PS_ERR_UNKNOWN, false,
     123                       PS_ERRORTEXT_psErrorCode_ERRORCODE_REGISTER_FAILED,
     124                       i);
     125        }
     126    }
     127}
     128
Note: See TracChangeset for help on using the changeset viewer.