IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 573


Ignore:
Timestamp:
May 3, 2004, 6:13:29 PM (22 years ago)
Author:
Paul Price
Message:

Added discussion of RHL's fix to psError to allow other
projects to add their own error codes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/pslib/psLibSDRS.tex

    r534 r573  
    1 %%% $Id: psLibSDRS.tex,v 1.39 2004-04-28 00:27:24 price Exp $
     1%%% $Id: psLibSDRS.tex,v 1.40 2004-05-04 04:13:29 price Exp $
    22\documentclass[panstarrs]{panstarrs}
    33
     
    897897\hlabel{psErrorCodes}
    898898
    899 The type \code{psErrorCode} is defined by an auxiliary file, conventionally named
    900 \file{psErrorCodes.dat}. This file shall consist of a number of lines, each
    901 of the form:
    902 \begin{verbatim}
    903 NAME [ = value ] , STRING
    904 \end{verbatim}
    905 where \code{[ = value]} is optional, and no spaces are significant except in the
    906 STRING.  Comments extend from \code{#} to the end of the line (except that a
    907 \code{\#} shall be replaced by \code{#} and not taken to start a comment). For example,
     899Both error codes for PSLib and error codes for projects that use PSLib
     900may be registered.  In the former case, the error codes shall be
     901registered on initialisation, whereas in the latter case, it is
     902required to explicitly register.
     903
     904\paragraph{Registering error codes}
     905
     906An array of error codes may be registered with the PSLib error handler
     907using a private function:
     908
     909\begin{verbatim}
     910void p_psErrorRegister(const psErrorDescription *errors, ///< register a set of errors
     911                       int nerror                        ///< number of errors
     912    );
     913\end{verbatim}
     914
     915Where the errors are represented internally as follows:
     916\begin{verbatim}
     917typedef struct {
     918    psErrorCode code;                  // An error code
     919    char *descrip;                     // the associated description
     920} psErrorDescription;
     921\end{verbatim}
     922
     923Projects wishing to employ the PSLib error handler should define
     924a function,
     925\begin{verbatim}
     926void prefixErrorRegister(void);
     927\end{verbatim}
     928where \code{prefix} is particular to the project.  For example, PSLib
     929should have a function,
     930\begin{verbatim}
     931void psErrorRegister(void);
     932\end{verbatim}
     933In this case (i.e., error codes for PSLib), the function should be
     934called upon initialisation.  As another example, MOPS should implement
     935a function,
     936\begin{verbatim}
     937void mopsErrorRegister(void);
     938\end{verbatim}
     939which would be called explicitly when MOPS utilises PSLib.
     940
     941It is left to the external project to produce the appropriate
     942\code{prefixErrorRegister()}, but they may find helpful the
     943implementation discussed below for use in PSLib.
     944
     945There is a clear need to coordinate the choice of error numbers.  It
     946is expected that error code ranges for different projects shall be
     947managed by the Project Office.
     948
     949\paragraph{Error Codes for PSLib}
     950
     951For ease of maintenance, error codes for PSLib shall be defined by an
     952auxiliary file, conventionally named \file{psErrorCodes.dat}.  The
     953format of this file shall consist of a number of lines, each of the
     954form:
     955\begin{verbatim}
     956NAME [ = value ][,] STRING
     957\end{verbatim}
     958where \code{[ = value]} and the comma are optional, and no spaces are
     959significant except in the STRING.  Comments extend from \code{#} to
     960the end of the line (except that a \code{\#} shall be replaced by
     961\code{#} and not taken to start a comment). For example,
    908962\begin{verbatim}
    909963#
     
    913967BASE = 256,             first value we use; should avoid errno conflicts
    914968UNKNOWN,                unknown error
     969# This is a comment, and is ignored.
    915970IO,                     I/O error
    916971BADFREE,                bad argument to psFree()
     
    919974The values \code{NONE = 0} and {UNKNOWN} must be present.
    920975
    921 The \PS{} Makefiles shall
    922 generate two files, \file{psErrorCodes.h} and
    923 \file{psErrorCodes.c} from the input file \file{psErrorCodes.dat}.
    924 \file{psErrorCodes.h} shall define an enumerated type
    925 \code{psErrorCode} with elements \code{PS_ERR_NAME} and values as specified
    926 in \file{psErrorCodes.dat}, e.g.
     976A script, called from the Makefiles, shall generate two files,
     977\file{psErrorCodes.h} and \file{psErrorCodes.c} from the input file
     978\file{psErrorCodes.dat}.  \file{psErrorCodes.h} shall define an
     979enumerated type \code{psErrorCode} with elements \code{PS_ERR_NAME}
     980and values as specified in \file{psErrorCodes.dat}, e.g.
    927981\begin{verbatim}
    928982#if !defined(PS_ERROR_CODES_H)
     
    938992    PS_ERR_N_ERR_CLASSES,
    939993} psErrorCode;
    940 
    941994#endif
    942995\end{verbatim}
     996
    943997Any \code{errorCode}s less then or equal to \code{PS_ERR_BASE} shall be taken
    944998to be valid values of \code{errno}.
    945999
    946 The implementation may add extra fields (e.g. \code{PS_ERR_N_ERR_CLASSES}).
    947 
    948 The latter shall be of the form
    949 \begin{verbatim}
    950 static struct {
    951     psErrorCode code;
    952     char *descrip;
    953 } errorStrings[] = {
    954     { PS_ERR_NONE, "not an error; must be 0"},
    955     { PS_ERR_BASE, "first value we use; should avoid errno conflicts"},
    956     { PS_ERR_UNKNOWN, "unknown error"},
    957     { PS_ERR_IO, "I/O error"},
    958     { PS_ERR_BADFREE, "bad argument to psFree()"},
    959     { PS_ERR_MEMORY_CORRUPTION, "memory corruption detected"},
    960     { PS_ERR_N_ERR_CLASSES, NULL},
    961 };
    962 \end{verbatim}
     1000The implementation may add extra fields (e.g., \code{PS_ERR_N_ERR_CLASSES}).
     1001
     1002\file{psErrorCodes.c} shall define the necessary function to register
     1003the error codes.
    9631004
    9641005\subsubsection{Example}
Note: See TracChangeset for help on using the changeset viewer.