System Utilities

Collaboration diagram for System Utilities:


Modules

 MemoryManagement

Data Structures

struct  psErr
 Error message object. More...
struct  psErrorDescription
 An error code with description. More...
struct  psLine
 Structure to carry a dynamic string. More...
struct  p_psComponent
 Basic structure for the component tree. More...

Defines

#define PS_ASSERT_PTR(NAME, RVAL)
#define PS_ASSERT_INT_UNEQUAL(NAME1, NAME2, RVAL)
#define PS_ASSERT_INT_EQUAL(NAME1, NAME2, RVAL)
#define PS_ASSERT_INT_NONNEGATIVE(NAME, RVAL)
#define PS_ASSERT_INT_POSITIVE(NAME, RVAL)
#define PS_ASSERT_INT_ZERO(NAME, RVAL)
#define PS_ASSERT_INT_NONZERO(NAME, RVAL)
#define PS_ASSERT_INT_WITHIN_RANGE(NAME, LOWER, UPPER, RVAL)
#define PS_ASSERT_INT_LESS_THAN(VAR1, VAR2, RVAL)
#define PS_ASSERT_INT_LESS_THAN_OR_EQUAL(VAR1, VAR2, RVAL)
#define PS_ASSERT_INT_LARGER_THAN(NAME1, NAME2, RVAL)
#define PS_ASSERT_INT_LARGER_THAN_OR_EQUAL(NAME1, NAME2, RVAL)
#define PS_ASSERT_FLOAT_LARGER_THAN(NAME1, NAME2, RVAL)
#define PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL(NAME1, NAME2, RVAL)
#define PS_ASSERT_FLOAT_LESS_THAN(NAME1, NAME2, RVAL)
#define PS_ASSERT_FLOAT_LESS_THAN_OR_EQUAL(NAME1, NAME2, RVAL)
#define PS_ASSERT_FLOAT_NON_EQUAL(NAME1, NAME2, RVAL)
#define PS_ASSERT_FLOAT_EQUAL(NAME1, NAME2, RVAL)
#define PS_ASSERT_FLOAT_WITHIN_RANGE(NAME, LOWER, UPPER, RVAL)
#define PS_ASSERT_FLOAT_REAL(NAME, RVAL)
#define PS_ASSERT_DOUBLE_WITHIN_RANGE(NAME, LOWER, UPPER, RVAL)
#define PS_ASSERT_LONG_WITHIN_RANGE(NAME, LOWER, UPPER, RVAL)
#define PS_ASSERT_LONG_LARGER_THAN_OR_EQUAL(NAME1, NAME2, RVAL)
#define PS_ASSERT_S64_WITHIN_RANGE(NAME, LOWER, UPPER, RVAL)
#define PS_WARN_PTR_NON_NULL(NAME)
#define PS_ASSERT_PTR_NON_NULL(NAME, RVAL)   PS_ASSERT_GENERAL_PTR_NON_NULL(NAME, return RVAL)
#define PS_ASSERT_GENERAL_PTR_NON_NULL(NAME, CLEANUP)
#define PS_ASSERT_PTR_TYPE(NAME, TYPE, RVAL)
#define PS_ASSERT_PTR_DIMEN(NAME, DIMEN, RVAL)   PS_ASSERT_GENERAL_PTR_DIMEN(NAME, DIMEN, return RVAL)
#define PS_ASSERT_GENERAL_PTR_DIMEN(NAME, DIMEN, CLEANUP)
#define PS_ASSERT_PTR_DIMEN_GENERAL_NOT(NAME, DIMEN, CLEANUP)
#define PS_ASSERT_PTRS_SIZE_EQUAL(PTR1, PTR2, RVAL)
#define PS_ASSERT_PTR_TYPE_EQUAL(PTR1, PTR2, RVAL)   PS_ASSERT_PTRS_TYPE_EQUAL_GENERAL(PTR1, PTR2, return RVAL)
#define PS_ASSERT_PTRS_TYPE_EQUAL_GENERAL(PTR1, PTR2, CLEANUP)
#define _(string)   string
#define PS_STRING(S)   #S
 This macro will convert the argument to a quoted string.
#define PS_FILE_LINE   p_psFileLine(__FILE__,__LINE__)
#define PS_ASSERT_STRING_NON_EMPTY(NAME, RVAL)
#define PS_UNKNOWN_TRACE_LEVEL   -9999
#define PS_DEFAULT_TRACE_LEVEL   -1
#define PS_THE_OTHER_DEFAULT_TRACE_LEVEL   0
#define PS_TRACE_ON   1
 Functions.

Enumerations

enum  psErrorCode {
  PS_ERR_NONE = 0, PS_ERR_BASE = 256, PS_ERR_UNKNOWN, PS_ERR_IO, PS_ERR_LOCATION_INVALID, PS_ERR_MEMORY_CORRUPTION, PS_ERR_MEMORY_DEREF_USAGE, PS_ERR_BAD_PARAMETER_VALUE, PS_ERR_BAD_PARAMETER_TYPE, PS_ERR_BAD_PARAMETER_NULL,
  PS_ERR_BAD_PARAMETER_SIZE, PS_ERR_UNEXPECTED_NULL, PS_ERR_OS_CALL_FAILED, PS_ERR_BAD_FITS, PS_ERR_IEEE, PS_ERR_DB_CLIENT, PS_ERR_DB_SERVER, PS_ERR_N_ERR_CLASSES
}
 enumeration of the static error code classes More...
enum  psExit { PS_EXIT_SUCCESS = 0, PS_EXIT_UNKNOWN_ERROR = 1, PS_EXIT_SYS_ERROR, PS_EXIT_CONFIG_ERROR, PS_EXIT_PROG_ERROR, PS_EXIT_DATA_ERROR, PS_EXIT_TIMEOUT_ERROR }
 Exit status codes. More...
enum  { PS_LOG_ABORT = 0, PS_LOG_ERROR, PS_LOG_WARN, PS_LOG_INFO, PS_LOG_DETAIL, PS_LOG_MINUTIA }
 < Status codes for log messages More...
enum  { PS_LOG_TO_NONE = 0, PS_LOG_TO_STDERR = 1, PS_LOG_TO_STDOUT = 2 }
enum  { PS_TRACE_TO_NONE = 0, PS_TRACE_TO_STDOUT = 1, PS_TRACE_TO_STDERR = 2 }

Functions

void psAbort (const char *name, const char *format,...)
 Reports an abort message to logging facility.
psString psLibVersion (void)
 Get current psLib version.
psString psLibVersionLong (void)
 Get current psLib version (full identification).
void psLibInit (const char *timeConfig)
 Initializes persistent memory.
void psLibFinalize (void)
 Removes persistant memory created with the psLibInit function.
void p_psMemoryCheck (void)
psErrpsErrorGet (long which)
 Get a error from the error stack.
psErrpsErrorLast (void)
 Get last error put on the error stack.
psErrorCode psErrorCodeLast (void)
 Get errorCode of last error put on the error stack.
void psErrorClear (void)
 Clears the error stack.
long psErrorGetStackSize ()
 Get the error stack depth.
void psErrorStackPrint (FILE *fd, const char *format,...)
 Prints error stack to specified open file descriptor.
void psErrorStackPrintV (FILE *fd, const char *format, va_list va)
 Prints error stack to specified open file descriptor.
psErrorCode psError (psErrorCode code, psBool new, const char *format,...)
 Reports an error message to the logging facility.
void psWarning (const char *format,...)
 Logs a warning message.
psErrpsErrAlloc (const char *name, psErrorCode code, const char *msg)
 Create a new psErr struct.
psErrorDescriptionpsErrorDescriptionAlloc (psErrorCode code, const char *description)
 Allocates a new psErrorDescription.
const char * psErrorCodeString (psErrorCode code)
 Retrieves the description of an error code.
void psErrorRegister (const psErrorDescription *errors, int errorCode)
 Register an error code.
psBool p_psErrorUnregister (psErrorCode code)
 Clears error codes registered via psErrorRegister.
psLinepsLineAlloc (long Nline)
 Allocates a line object of length Nline.
bool psMemCheckLine (psPtr ptr)
 Checks the type of a particular pointer.
bool psLineInit (psLine *line)
 Initializes or re-initializes a line.
bool psLineAdd (psLine *line, const char *format,...)
 Adds the line segment to the string.
bool psLogSetDestination (int fd)
 This procedure sets the destination for future log messages.
int psLogGetDestination ()
 This procedure returns the current log destination file descriptor.
int psLogSetLevel (int level)
 This procedure sets the message level for future log messages.
int psLogGetLevel ()
 This procedures returns the current log message level.
bool psLogSetFormat (const char *format)
 This procedure sets the log format for future log messages.
int psMessageDestination (const char *dest)
 This procedures uses a string to set the destination for which to send the corresponding log messages.
void psLogMsg (const char *name, int level, const char *format,...)
 This procedure logs a message to the destination set by a prior call to psLogSetDestination(), if myLevel is less than the level specified by a prior call to psLogSetLevel().
void psLogMsgV (const char *name, int level, const char *format, va_list ap)
 This procedure is functionally equivalent to psLogMsg(), except that it takes a va_list as the message parameter, not a printf-style string.
const char * p_psFileLine (const char *file, int line)
 This macro returns a (static buffer containing) "file:line".
psString psStringAlloc (long nChar)
 Allocates a new psString.
bool psMemCheckString (psPtr ptr)
 Checks the type of a particular pointer.
psString psStringCopy (const char *string)
 Copies the input string.
psString psStringNCopy (const char *string, unsigned int nChar)
 Copies the input string up to the specified number of characters.
ssize_t psStringAppend (char **dest, const char *format,...)
 Appends a format onto a string.
ssize_t psStringAppendV (char **dest, const char *format, va_list ap)
 Appends a format onto a string.
ssize_t psStringPrepend (char **dest, const char *format,...)
 Prepends a format onto a string.
ssize_t psStringPrependV (char **dest, const char *format, va_list ap)
 Prepends a format onto a string.
psListpsStringSplit (const char *string, const char *splitters, bool multipleAreSignificant)
 Procedure to split the input string into a psList of psStrings.
psArraypsStringSplitArray (const char *string, const char *splitters, bool multipleAreSignificant)
 Procedure to split the input string into a psArray of psStrings.
ssize_t psStringSubstitute (psString *input, const char *replace, const char *key)
 Procedure to search an input string and substitute strings where desired.
size_t psStringStrip (char *string)
 Procedure to strip the whitespace from the head and tail of a string.
psString psStringStripCVS (const char *string, const char *tagName)
 Given a CVS keyword string, strip off the CVS-specific keyword to get the value.
bool psTraceSetFormat (const char *format)
 This procedure sets the trace format for future trace messages.
void psTrace (const char *facil, int level, const char *format,...)
 Sends a trace message.
int psTraceGetLevel (const char *facil)
 Get the trace level.
int psTraceSetLevel (const char *facil, int level)
 Set trace level.
void psTraceReset (void)
 Set all trace levels to zero (do not free nodes in the facility tree).
void psTracePrintLevels (void)
 print trace levels
bool psTraceSetDestination (int fd)
 Set the destination of future trace messages.
int psTraceGetDestination (void)
 Get the current destination for trace messages.
psMetadatapsTraceLevels (void)
 Return a psMetadata summarising the trace levels.
int psArgumentVerbosity (int *argc, char **argv)
 Implements the various verbosity controls.
int psArgumentGet (int argc, char **argv, const char *arg)
 Checks for an argument and returns its index position if found.
bool psArgumentRemove (int argnum, int *argc, char **argv)
 Removes from the argument list the argument whose index is argnum.
bool psArgumentParse (psMetadata *arguments, int *argc, char **argv)
 Parses the command line arguments into a metadata container of arguments.
void psArgumentHelp (psMetadata *arguments)
 Prints to stdout a guide to the command-line arguments.

Variables

psMemBlockpsMemBlock::previousBlock
 previous block in allocation list
psMemBlockpsMemBlock::nextBlock
 next block allocation list
psFreeFunc psMemBlock::freeFunc
 deallocator. If NULL, use generic deallocation.
size_t psMemBlock::userMemorySize
 the size of the user-portion of the memory block
const psMemId psMemBlock::id
 a unique ID for this allocation
const pthread_t psMemBlock::tid
 set from pthread_self();
const char * psMemBlock::file
 set from __FILE__ in e.g. p_psAlloc
const unsigned int psMemBlock::lineno
 set from __LINE__ in e.g. p_psAlloc
const char * psMemBlock::func
 set from __func__
psReferenceCount psMemBlock::refCounter
 how many times pointer is referenced
bool psMemBlock::persistent
 marks if this non-user persistent data like error stack, etc.
const psU32 psMemBlock::endblock
 initialised to p_psMEMMAGIC


Define Documentation

#define _ ( string   )     string

Definition at line 31 of file psError.h.

#define PS_ASSERT_DOUBLE_WITHIN_RANGE ( NAME,
LOWER,
UPPER,
RVAL   ) 

Value:

if ((NAME) < (LOWER) || (NAME) > (UPPER)) { \
    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
            "Error: %s, %lf, is out of range.  Must be between %lf and %lf.", \
            #NAME, NAME, LOWER, UPPER); \
    return RVAL; \
}

Definition at line 175 of file psAssert.h.

#define PS_ASSERT_FLOAT_EQUAL ( NAME1,
NAME2,
RVAL   ) 

Value:

if (fabs((NAME2) - (NAME1)) > FLT_EPSILON) { \
    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
            "Error: %s and %s are not equal.", \
            #NAME1, #NAME2); \
    return(RVAL); \
}

Definition at line 150 of file psAssert.h.

#define PS_ASSERT_FLOAT_LARGER_THAN ( NAME1,
NAME2,
RVAL   ) 

Value:

if (!((NAME1) > (NAME2))) { \
    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
            "Error: !(%s > %s) (%f %f).", \
            #NAME1, #NAME2, NAME1, NAME2); \
    return(RVAL); \
}

Definition at line 110 of file psAssert.h.

#define PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL ( NAME1,
NAME2,
RVAL   ) 

Value:

if (!((NAME1) >= (NAME2))) { \
    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
            "Error: !(%s >= %s) (%f %f).", \
            #NAME1, #NAME2, NAME1, NAME2); \
    return(RVAL); \
}

Definition at line 118 of file psAssert.h.

#define PS_ASSERT_FLOAT_LESS_THAN ( NAME1,
NAME2,
RVAL   ) 

Value:

if (!((NAME1) < (NAME2))) { \
    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
            "Error: !(%s < %s) (%f %f).", \
            #NAME1, #NAME2, NAME1, NAME2); \
    return(RVAL); \
}

Definition at line 126 of file psAssert.h.

#define PS_ASSERT_FLOAT_LESS_THAN_OR_EQUAL ( NAME1,
NAME2,
RVAL   ) 

Value:

if (!((NAME1) <= (NAME2))) { \
    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
            "Error: !(%s <= %s) (%f %f).", \
            #NAME1, #NAME2, NAME1, NAME2); \
    return(RVAL); \
}

Definition at line 134 of file psAssert.h.

#define PS_ASSERT_FLOAT_NON_EQUAL ( NAME1,
NAME2,
RVAL   ) 

Value:

if (fabs((NAME2) - (NAME1)) < FLT_EPSILON) { \
    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
            "Error: %s and %s are equal.", \
            #NAME1, #NAME2); \
    return(RVAL); \
}

Definition at line 142 of file psAssert.h.

#define PS_ASSERT_FLOAT_REAL ( NAME,
RVAL   ) 

Value:

if (!isfinite(NAME)) { \
    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
            "Error: %s=%f is not a real value.\n", \
            #NAME, NAME); \
    return RVAL; \
}

Definition at line 167 of file psAssert.h.

#define PS_ASSERT_FLOAT_WITHIN_RANGE ( NAME,
LOWER,
UPPER,
RVAL   ) 

Value:

if ((NAME) < (LOWER) || (NAME) > (UPPER)) { \
    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
            "Error: %s, %f, is out of range.  Must be between %f and %f.", \
            #NAME, NAME, LOWER, UPPER); \
    return RVAL; \
}

Definition at line 159 of file psAssert.h.

#define PS_ASSERT_GENERAL_PTR_DIMEN ( NAME,
DIMEN,
CLEANUP   ) 

Value:

if ((NAME)->type.dimen != DIMEN) { \
    psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
            "Unallowable operation: %s has incorrect dimensionality.", \
            #NAME); \
    CLEANUP; \
}

Definition at line 233 of file psAssert.h.

#define PS_ASSERT_GENERAL_PTR_NON_NULL ( NAME,
CLEANUP   ) 

Value:

if ((NAME) == NULL) { \
    psError(PS_ERR_BAD_PARAMETER_NULL, true, \
            "Unallowable operation: %s is NULL.", \
            #NAME); \
    CLEANUP; \
}

Definition at line 216 of file psAssert.h.

#define PS_ASSERT_INT_EQUAL ( NAME1,
NAME2,
RVAL   ) 

Value:

if ((NAME1) != (NAME2)) { \
    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
            "Error: %s and %s are not equal.", \
            #NAME1, #NAME2); \
    return(RVAL); \
}

Definition at line 37 of file psAssert.h.

#define PS_ASSERT_INT_LARGER_THAN ( NAME1,
NAME2,
RVAL   ) 

Value:

if (!((NAME1) > (NAME2))) { \
    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
            "Error: !(%s > %s) (%d %d).", \
            #NAME1, #NAME2, NAME1, NAME2); \
    return(RVAL); \
}

Definition at line 95 of file psAssert.h.

#define PS_ASSERT_INT_LARGER_THAN_OR_EQUAL ( NAME1,
NAME2,
RVAL   ) 

Value:

if (!((NAME1) >= (NAME2))) { \
    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
            "Error: !(%s >= %s) (%d %d).", \
            #NAME1, #NAME2, NAME1, NAME2); \
    return(RVAL); \
}

Definition at line 103 of file psAssert.h.

#define PS_ASSERT_INT_LESS_THAN ( VAR1,
VAR2,
RVAL   ) 

Value:

if (!(VAR1 < VAR2)) { \
    psError(PS_ERR_UNKNOWN, true, \
            "Error: %s is not less than %s (%d, %d)", #VAR1, #VAR2, VAR1, VAR2); \
    return(RVAL); \
}

Definition at line 81 of file psAssert.h.

#define PS_ASSERT_INT_LESS_THAN_OR_EQUAL ( VAR1,
VAR2,
RVAL   ) 

Value:

if (!(VAR1 <= VAR2)) { \
    psError(PS_ERR_UNKNOWN, true, \
            "Error: %s is not less than %s (%d, %d)", #VAR1, #VAR2, VAR1, VAR2); \
    return(RVAL); \
}

Definition at line 88 of file psAssert.h.

#define PS_ASSERT_INT_NONNEGATIVE ( NAME,
RVAL   ) 

Value:

if ((NAME) < 0) { \
    psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: %s is less than 0.", #NAME); \
    return(RVAL); \
}

Definition at line 45 of file psAssert.h.

#define PS_ASSERT_INT_NONZERO ( NAME,
RVAL   ) 

Value:

if ((NAME) == 0) { \
    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
            "Error: %s is 0.", #NAME); \
    return(RVAL); \
}

Definition at line 65 of file psAssert.h.

#define PS_ASSERT_INT_POSITIVE ( NAME,
RVAL   ) 

Value:

if ((NAME) < 1) { \
    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
            "Error: %s is 0 or less.", #NAME); \
    return(RVAL); \
}

Definition at line 51 of file psAssert.h.

#define PS_ASSERT_INT_UNEQUAL ( NAME1,
NAME2,
RVAL   ) 

Value:

if ((NAME1) == (NAME2)) { \
    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
            "Error: %s and %s are equal.", \
            #NAME1, #NAME2); \
    return(RVAL); \
}

Definition at line 29 of file psAssert.h.

#define PS_ASSERT_INT_WITHIN_RANGE ( NAME,
LOWER,
UPPER,
RVAL   ) 

Value:

if ((int)(NAME) < LOWER || (int)(NAME) > UPPER) { \
    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
            "Error: %s, %d, is out of range.  Must be between %d and %d.", \
            #NAME,(int)NAME,LOWER,UPPER); \
    return RVAL; \
}

Definition at line 73 of file psAssert.h.

#define PS_ASSERT_INT_ZERO ( NAME,
RVAL   ) 

Value:

if ((NAME) != 0) { \
    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
            "Error: %s is 0.", #NAME); \
    return(RVAL); \
}

Definition at line 58 of file psAssert.h.

#define PS_ASSERT_LONG_LARGER_THAN_OR_EQUAL ( NAME1,
NAME2,
RVAL   ) 

Value:

if (!((NAME1) >= (NAME2))) { \
    psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: !(%s >= %s) (%ld %ld).",\
            #NAME1, #NAME2, NAME1, NAME2); \
    return(RVAL); \
}

Definition at line 191 of file psAssert.h.

#define PS_ASSERT_LONG_WITHIN_RANGE ( NAME,
LOWER,
UPPER,
RVAL   ) 

Value:

if ((NAME) < (LOWER) || (NAME) > (UPPER)) { \
    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
            "Error: %s, %ld, is out of range.  Must be between %ld and %ld.", \
            #NAME, NAME, LOWER, UPPER); \
    return RVAL; \
}

Definition at line 183 of file psAssert.h.

#define PS_ASSERT_PTR ( NAME,
RVAL   ) 

Value:

{ \
    if (NAME == NULL) return(RVAL); \
    psMemBlock *mb = (psMemBlock*)(NAME) - 1; \
    if (mb->startblock != P_PS_MEMMAGIC || mb->endblock != P_PS_MEMMAGIC || \
            *(psU32 *)((char *)(mb + 1) + mb->userMemorySize) != P_PS_MEMMAGIC) { \
        psError(PS_ERR_MEMORY_CORRUPTION, false, \
                "Error: Pointer %s is corrupted or not on the PS memory system.", \
                #NAME); \
        return (RVAL); \
    } \
}

Definition at line 16 of file psAssert.h.

#define PS_ASSERT_PTR_DIMEN ( NAME,
DIMEN,
RVAL   )     PS_ASSERT_GENERAL_PTR_DIMEN(NAME, DIMEN, return RVAL)

Definition at line 232 of file psAssert.h.

#define PS_ASSERT_PTR_DIMEN_GENERAL_NOT ( NAME,
DIMEN,
CLEANUP   ) 

Value:

if ((NAME)->type.dimen == DIMEN) { \
    psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
            "Unallowable operation: %s has incorrect dimensionality.", \
            #NAME); \
    CLEANUP; \
}

Definition at line 241 of file psAssert.h.

#define PS_ASSERT_PTR_NON_NULL ( NAME,
RVAL   )     PS_ASSERT_GENERAL_PTR_NON_NULL(NAME, return RVAL)

Definition at line 215 of file psAssert.h.

#define PS_ASSERT_PTR_TYPE ( NAME,
TYPE,
RVAL   ) 

Value:

if ((NAME)->type.type != TYPE) { \
    psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
            "Unallowable operation: %s has incorrect type.", \
            #NAME); \
    return(RVAL); \
}

Definition at line 224 of file psAssert.h.

#define PS_ASSERT_PTR_TYPE_EQUAL ( PTR1,
PTR2,
RVAL   )     PS_ASSERT_PTRS_TYPE_EQUAL_GENERAL(PTR1, PTR2, return RVAL)

Definition at line 258 of file psAssert.h.

#define PS_ASSERT_PTRS_SIZE_EQUAL ( PTR1,
PTR2,
RVAL   ) 

Value:

if (PTR1->n != PTR2->n) { \
    psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
            "ptr %s has size %d, ptr %s has size %d.", \
            #PTR1, PTR1->n, #PTR2, PTR2->n); \
    return(RVAL); \
}

Definition at line 250 of file psAssert.h.

#define PS_ASSERT_PTRS_TYPE_EQUAL_GENERAL ( PTR1,
PTR2,
CLEANUP   ) 

Value:

if (PTR1->type.type != PTR2->type.type) { \
    psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
            "ptr %s has type %d, ptr %s has type %d.", \
            #PTR1, PTR1->type.type, #PTR2, PTR2->type.type); \
    CLEANUP; \
}

Definition at line 259 of file psAssert.h.

#define PS_ASSERT_S64_WITHIN_RANGE ( NAME,
LOWER,
UPPER,
RVAL   ) 

Value:

if ((NAME) < (LOWER) || (NAME) > (UPPER)) { \
    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
            "Error: %s, %" PRId64 ", is out of range.  Must be between %" PRId64 " and %" PRId64 ".", \
            #NAME, NAME, LOWER, UPPER); \
    return RVAL; \
}

Definition at line 198 of file psAssert.h.

#define PS_ASSERT_STRING_NON_EMPTY ( NAME,
RVAL   ) 

Value:

if (!(NAME) || strlen(NAME) == 0) { \
    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
            "Error: String %s is NULL or empty.", \
            #NAME); \
    return(RVAL); \
}

Definition at line 207 of file psString.h.

#define PS_DEFAULT_TRACE_LEVEL   -1

Definition at line 27 of file psTrace.h.

#define PS_FILE_LINE   p_psFileLine(__FILE__,__LINE__)

Definition at line 34 of file psString.h.

#define PS_STRING (  )     #S

This macro will convert the argument to a quoted string.

Definition at line 30 of file psString.h.

#define PS_THE_OTHER_DEFAULT_TRACE_LEVEL   0

Definition at line 28 of file psTrace.h.

#define PS_TRACE_ON   1

Functions.

Definition at line 55 of file psTrace.h.

#define PS_UNKNOWN_TRACE_LEVEL   -9999

Definition at line 26 of file psTrace.h.

#define PS_WARN_PTR_NON_NULL ( NAME   ) 

Value:

if ((NAME) == NULL) { \
    psLogMsg(__func__, PS_LOG_WARN, "WARNING: %s is NULL.", #NAME); \
} \

Definition at line 210 of file psAssert.h.


Enumeration Type Documentation

anonymous enum

< Status codes for log messages

Enumerator:
PS_LOG_ABORT  log message is a critical error, perform an abort after printing
PS_LOG_ERROR  log message is an error, but don't abort
PS_LOG_WARN  log message is a warning
PS_LOG_INFO  log message is informational only
PS_LOG_DETAIL  log message provides details of minor interest
PS_LOG_MINUTIA  log message provides very detailed information

Definition at line 121 of file psLogMsg.h.

anonymous enum

Enumerator:
PS_LOG_TO_NONE  turn off logging
PS_LOG_TO_STDERR  log to system's stderr
PS_LOG_TO_STDOUT  log to system's stdout

Definition at line 131 of file psLogMsg.h.

anonymous enum

Enumerator:
PS_TRACE_TO_NONE  turn off all traces
PS_TRACE_TO_STDOUT  trace to system's stdout
PS_TRACE_TO_STDERR  trace to system's stderr

Definition at line 30 of file psTrace.h.

enum psErrorCode

enumeration of the static error code classes

Enumerator:
PS_ERR_NONE  not an error
PS_ERR_BASE  base error.

Any psErrorCode less than this should be taken to be valid values of errno

PS_ERR_UNKNOWN 
PS_ERR_IO 
PS_ERR_LOCATION_INVALID 
PS_ERR_MEMORY_CORRUPTION 
PS_ERR_MEMORY_DEREF_USAGE 
PS_ERR_BAD_PARAMETER_VALUE 
PS_ERR_BAD_PARAMETER_TYPE 
PS_ERR_BAD_PARAMETER_NULL 
PS_ERR_BAD_PARAMETER_SIZE 
PS_ERR_UNEXPECTED_NULL 
PS_ERR_OS_CALL_FAILED 
PS_ERR_BAD_FITS 
PS_ERR_IEEE 
PS_ERR_DB_CLIENT 
PS_ERR_DB_SERVER 
PS_ERR_N_ERR_CLASSES  end marker - should not be used as a true error

Definition at line 24 of file psErrorCodes.h.

enum psExit

Exit status codes.

These provide a bit finer granularity compared to success/fail

Enumerator:
PS_EXIT_SUCCESS  Successful termination; matches EXIT_SUCCESS.
PS_EXIT_UNKNOWN_ERROR  Error of unknown nature; matches EXIT_FAILURE.
PS_EXIT_SYS_ERROR  Error with a system call.
PS_EXIT_CONFIG_ERROR  Error with configuration.
PS_EXIT_PROG_ERROR  Error in programming (look also for aborts).
PS_EXIT_DATA_ERROR  Error with data.
PS_EXIT_TIMEOUT_ERROR  Error due to timeout.

Definition at line 10 of file psExit.h.


Function Documentation

psBool p_psErrorUnregister ( psErrorCode  code  ) 

Clears error codes registered via psErrorRegister.

Returns:
psBool TRUE if given errorcode was removed, otherwise FALSE.
Parameters:
code  the error code to find and remove

const char* p_psFileLine ( const char *  file,
int  line 
)

This macro returns a (static buffer containing) "file:line".

void p_psMemoryCheck ( void   ) 

void psAbort ( const char *  name,
const char *  format,
  ... 
)

Reports an abort message to logging facility.

This function will invoke the psLogMsg function with a level of PS_LOG_ABORT and pass the parameters name and fmt to generate a proper log message. After logging, this function will call system abort function to abnormally terminate the program.

Returns:
void No return value
Parameters:
name  Source of abort such as file or function detected
format  A printf style formatting statement defining msg

int psArgumentGet ( int  argc,
char **  argv,
const char *  arg 
)

Checks for an argument and returns its index position if found.

Returns:
int: The index of the element in the argument list, otherwise 0.
Parameters:
argc  number of arguments
argv  the argument list
arg  the specified argument to match

void psArgumentHelp ( psMetadata arguments  ) 

Prints to stdout a guide to the command-line arguments.

Parameters:
arguments  metadata container for arguments

bool psArgumentParse ( psMetadata arguments,
int *  argc,
char **  argv 
)

Parses the command line arguments into a metadata container of arguments.

The input arguments shall contain the list of possible arguments as the keywords providing the default values. As matching arguments are found on the command line, the values shall be read into the arguments metadata, with the appropriate type. The arguments and their values shall be removed from the list of command line arguments as they are processed.

Returns:
bool: False if any argument was encountered that is not present in arguments.
Parameters:
arguments  metadata container for arguments
argc  number of arguments
argv  the argument list

bool psArgumentRemove ( int  argnum,
int *  argc,
char **  argv 
)

Removes from the argument list the argument whose index is argnum.

The number of entries in the argument list shall be decremented.

Returns:
bool: True if the argnum is in the argument list, otherwise false.
Parameters:
argnum  the argument to remove
argc  number of arguments
argv  the argument list

int psArgumentVerbosity ( int *  argc,
char **  argv 
)

Implements the various verbosity controls.

Arguments shall be removed from the argument list as they are processed.

Returns:
int: The resultant logging level.
Parameters:
argc  number of arguments
argv  the argument list

psErr* psErrAlloc ( const char *  name,
psErrorCode  code,
const char *  msg 
)

Create a new psErr struct.

Creates a new psErr struct, making a copy of the parameters.

Returns:
psErr* new psErr object
Parameters:
name  Name of error in the form aaa.bbb.ccc
code  Error class code
msg  Error message

psErrorCode psError ( psErrorCode  code,
psBool  new,
const char *  format,
  ... 
)

Reports an error message to the logging facility.

This function will invoke the psLogMsg function with a level of PS_LOG_ERROR and pass the parameters name and format to generate a proper log message.

This function modifies the error stack.

Returns:
psErrorCode the given error code
Parameters:
code  Error class code
new  true if error originates at this location
format  printf-style format of header line

void psErrorClear ( void   ) 

Clears the error stack.

The error stack may be completely cleared with psErrorClear.

psErrorCode psErrorCodeLast ( void   ) 

Get errorCode of last error put on the error stack.

Returns:
psErrorCode last error code, or PS_ERR_NONE

const char* psErrorCodeString ( psErrorCode  code  ) 

Retrieves the description of an error code.

The routine psErrorCodeString returns the string associated with an error code.

Returns:
const char* the description associated with the given code.
Parameters:
code  the associated error code

psErrorDescription* psErrorDescriptionAlloc ( psErrorCode  code,
const char *  description 
)

Allocates a new psErrorDescription.

Returns:
psErrorDescription* new psErrorDescription struct.
Parameters:
code  An error code
description  the associated description

psErr* psErrorGet ( long  which  ) 

Get a error from the error stack.

Previous errors on the stack are returned by psErrorGet (a value of 0 passed to psErrorGet is equivalent to a call to psErrorLast).

if no error is at the which position, a non-NULL psErr is returned with code PS_ERR_NONE.

Returns:
Error message object at 'which'
Parameters:
which  position in the error stack. 0 is last error on stack.

long psErrorGetStackSize (  ) 

Get the error stack depth.

Returns:
int The number of items on the error stack

psErr* psErrorLast ( void   ) 

Get last error put on the error stack.

The last error reported is available from psErrorLast; if no errors are current, a non-NULL psErr is returned with code PS_ERR_NONE.

Returns:
psErr* Reference to last error message on error stack

void psErrorRegister ( const psErrorDescription errors,
int  errorCode 
)

Register an error code.

Any project needed to use psLib must define the necessary error codes and associated message strings. This function registers an array of error codes with the error handling subsystem.

Parameters:
errors  Array of error codes to register
errorCode  number of errors in input array

void psErrorStackPrint ( FILE *  fd,
const char *  format,
  ... 
)

Prints error stack to specified open file descriptor.

The entire error stack may be printed to an open file descriptor by calling psErrorStackPrint; if and only if there are current errors, the printf-style string format is first printed to the file descriptor fd. In this printout, error codes are replaced by their string equivalents.

Parameters:
fd  destination file descriptor
format  printf-style format of header line

void psErrorStackPrintV ( FILE *  fd,
const char *  format,
va_list  va 
)

Prints error stack to specified open file descriptor.

The entire error stack may be printed to an open file descriptor by calling psErrorStackPrintV; if and only if there are current errors, the vprintf-style string format is first printed to the file descriptor fd. In this printout, error codes are replaced by their string equivalents.

Parameters:
fd  destination file descriptor
format  printf-style format of header line
va  any parameters required in format

void psLibFinalize ( void   ) 

Removes persistant memory created with the psLibInit function.

The memory created but not freed by psLib modules should be freed within this function at the end of a psLib execution cycle.

Returns:
void: void.

void psLibInit ( const char *  timeConfig  ) 

Initializes persistent memory.

Creates persistant memory items used throughout psLib. Items created within this method should be freed with the psLibFinalize function. current, a non-NULL psErr is returned with code PS_ERR_NONE.

Parameters:
timeConfig  Filename of config file for psTime.

psString psLibVersion ( void   ) 

Get current psLib version.

Returns the current psLib version name as a string.

Returns:
psString: String with version name.

psString psLibVersionLong ( void   ) 

Get current psLib version (full identification).

Returns the current psLib version name and other information identifying the compilation.

Returns:
psString: String with identity.

bool psLineAdd ( psLine line,
const char *  format,
  ... 
)

Adds the line segment to the string.

Appends a line segment to the string, returning false if the new segment would overflow the allocated string length.

Returns:
bool: True if successful, otherwise false.
Parameters:
line  the line segment to append
format  printf-style format of line

psLine* psLineAlloc ( long  Nline  ) 

Allocates a line object of length Nline.

Returns:
psLine*: the newly allocated line object.
Parameters:
Nline  length of line object to allocate

bool psLineInit ( psLine line  ) 

Initializes or re-initializes a line.

Initializes or re-initializes a line, setting the current length to zero and setting the string data values to 0. If the function is passed NULL, false is returned.

Returns:
bool: True if successful, otherwise false.
Parameters:
line  line to (re-)initialize

int psLogGetDestination (  ) 

This procedure returns the current log destination file descriptor.

If the destination has not been defined by the use, the descriptor for stdout is returned.

Returns:
int: The current file descriptor.

int psLogGetLevel (  ) 

This procedures returns the current log message level.

Returns:
int: The current logging level.

void psLogMsg ( const char *  name,
int  level,
const char *  format,
  ... 
)

This procedure logs a message to the destination set by a prior call to psLogSetDestination(), if myLevel is less than the level specified by a prior call to psLogSetLevel().

The message is specified with a printf-type string and arguments.

Parameters:
name  name of the log source
level  severity level of this log message
format  printf-style format command

void psLogMsgV ( const char *  name,
int  level,
const char *  format,
va_list  ap 
)

This procedure is functionally equivalent to psLogMsg(), except that it takes a va_list as the message parameter, not a printf-style string.

Parameters:
name  name of the log source
level  severity level of this log message
format  printf-style format command
ap  varargs argument list

bool psLogSetDestination ( int  fd  ) 

This procedure sets the destination for future log messages.

This procedure will take an integer as an argument which can specify general log destinations.

Returns:
bool true if set successfully, otherwise false.
Parameters:
fd  Specifies where to send messages.

bool psLogSetFormat ( const char *  format  ) 

This procedure sets the log format for future log messages.

The argument must be a character string consistsing of the letters H (host), L (level), M (message), N (name), and T (time). The default is "THLNM". Deleting a letter from the string will cause the associated information to not be logged. This procedure does not alter the order in which the messages are displayed.

Returns:
bool: True if successful, otherwise false.
Parameters:
format  Specifies the system log format

int psLogSetLevel ( int  level  ) 

This procedure sets the message level for future log messages.

Subsequent log messages, with a log level of "mylevel", will only be logged if "mylevel" is less than the current log level set by this procedure. Ie. higher values set by this procedure will cause more log messages to be displayed. The old log level will be returned.

Returns:
int: old logging level.
Parameters:
level  Specifies the system log level

bool psMemCheckLine ( psPtr  ptr  ) 

Checks the type of a particular pointer.

Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.

Returns:
bool: True if the pointer matches a psLine structure, false otherwise.
Parameters:
ptr  the pointer whose type to check

bool psMemCheckString ( psPtr  ptr  ) 

Checks the type of a particular pointer.

Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.

Returns:
bool: True if the pointer matches a psString structure, false otherwise.
Parameters:
ptr  the pointer whose type to check

int psMessageDestination ( const char *  dest  ) 

This procedures uses a string to set the destination for which to send the corresponding log messages.

Returns:
int: The file descriptor location of the message.
Parameters:
dest  Specifies where to send the message

psString psStringAlloc ( long  nChar  ) 

Allocates a new psString.

Returns:
psString: Newly allocated string of length n.
Parameters:
nChar  Size of psString to allocate.

ssize_t psStringAppend ( char **  dest,
const char *  format,
  ... 
)

Appends a format onto a string.

This function shall allocate a new string if dest is NULL. dest shall be automatically extended to the size of the new string.

Returns:
ssize_t: The length of the new string (excluding '')
Parameters:
dest  existing string
format  format to append

ssize_t psStringAppendV ( char **  dest,
const char *  format,
va_list  ap 
)

Appends a format onto a string.

This function shall allocate a new string if dest is NULL. dest shall be automatically extended to the size of the new string.

Returns:
ssize_t: The length of the new string (excluding '')
Parameters:
dest  existing string
format  format to append
ap  va_list of format arguments

psString psStringCopy ( const char *  string  ) 

Copies the input string.

This function shall allocate memory to the length of the input string plus one and copy the input string to the newly allocated memory. If 'string' is 'NULL' then 'NULL' is returned.

Returns:
psString: Copy of input string
Parameters:
string  Input string of characters to copy

psString psStringNCopy ( const char *  string,
unsigned int  nChar 
)

Copies the input string up to the specified number of characters.

This function shall allocate memory to the length specified by nChar plus one and copy the input string to the newly allocated memory. This function will only copy nChar bytes from the input to new string, so if the input string is larger than nChar characters the copied string will be a substring of the input string. If the input string is smaller than nChar bytes then the remaining bytes allocated will be set to NULL. If 'string' is 'NULL' then 'NULL' is returned.

Returns:
psString: Copy of input string
Parameters:
string  Input string of characters to copy
nChar  Number of bytes to allocate for string copy

ssize_t psStringPrepend ( char **  dest,
const char *  format,
  ... 
)

Prepends a format onto a string.

This function shall allocate a new string if dest is NULL. dest shall be automatically extended to the size of the new string.

Returns:
ssize_t: The length of the new string (excluding '')
Parameters:
dest  existing string
format  format to append

ssize_t psStringPrependV ( char **  dest,
const char *  format,
va_list  ap 
)

Prepends a format onto a string.

This function shall allocate a new string if dest is NULL. dest shall be automatically extended to the size of the new string.

Returns:
ssize_t: The length of the new string (excluding '')
Parameters:
dest  existing string
format  format to append
ap  va_list of format arguments

psList* psStringSplit ( const char *  string,
const char *  splitters,
bool  multipleAreSignificant 
)

Procedure to split the input string into a psList of psStrings.

The string is split at any one of the characters in splitters. Split strings of zero length should not be included in the output list.

Returns:
psList*: The list of (split) psStrings.
Parameters:
string  String to split
splitters  Characters on which to split
multipleAreSignificant  Are multiple occurences significant?

psArray* psStringSplitArray ( const char *  string,
const char *  splitters,
bool  multipleAreSignificant 
)

Procedure to split the input string into a psArray of psStrings.

The string is split at any one of the characters in splitters. Split strings of zero length should not be included in the output list.

Returns:
psArray*: The array of (split) psStrings.
Parameters:
string  String to split
splitters  Characters on which to split
multipleAreSignificant  Are multiple occurences significant?

size_t psStringStrip ( char *  string  ) 

Procedure to strip the whitespace from the head and tail of a string.

Returns:
size_t: Number of whitespaces removed.
Parameters:
string  input string to be stripped.

psString psStringStripCVS ( const char *  string,
const char *  tagName 
)

Given a CVS keyword string, strip off the CVS-specific keyword to get the value.

Parameters:
string  The string, something like "$CVSKEYWORD: Value$"
tagName  The name of the tag to remove, something like "CVSKEYWORD"

ssize_t psStringSubstitute ( psString input,
const char *  replace,
const char *  key 
)

Procedure to search an input string and substitute strings where desired.

The input string is searched for all instances of the key, which is then replaced with the replacement value wherever found. The input string may be freed if not needed.

Returns:
ssize_t: the length of the new string (excluding '')
Parameters:
input  ptr to input string to be modified
replace  replacement value
key  string to be replaced in input

void psTrace ( const char *  facil,
int  level,
const char *  format,
  ... 
)

Sends a trace message.

Parameters:
facil  facilty of interest
level  desired trace level
format  printf-style format command

int psTraceGetDestination ( void   ) 

Get the current destination for trace messages.

Returns:
FILE*: File Destination

int psTraceGetLevel ( const char *  facil  ) 

Get the trace level.

Returns:
int: Trace Level
Parameters:
facil  facilty of interest

psMetadata* psTraceLevels ( void   ) 

Return a psMetadata summarising the trace levels.

void psTracePrintLevels ( void   ) 

print trace levels

void psTraceReset ( void   ) 

Set all trace levels to zero (do not free nodes in the facility tree).

bool psTraceSetDestination ( int  fd  ) 

Set the destination of future trace messages.

Parameters:
fd  File descriptor

bool psTraceSetFormat ( const char *  format  ) 

This procedure sets the trace format for future trace messages.

The argument must be a character string consistsing of the letters H (host), L (level), M (message), N (name), and T (time). The default is "THLNM". Deleting a letter from the string will cause the associated information to not be logged. This procedure does not alter the order in which the messages are displayed.

Returns:
bool: True if successful, otherwise false.
Parameters:
format  Specifies the system trace format

int psTraceSetLevel ( const char *  facil,
int  level 
)

Set trace level.

Returns:
int: The previous level.
Parameters:
facil  facilty of interest
level  desired trace level

void psWarning ( const char *  format,
  ... 
)

Logs a warning message.

This procedure logs a message to the destination set by a prior call to psLogSetDestination(), This is equivalent to calling psLogMsg with a level of PS_LOG_WARN.

Parameters:
format  printf-style format of header line


Variable Documentation

const psU32 psMemBlock::endblock [inherited]

initialised to p_psMEMMAGIC

Definition at line 77 of file psMemory.h.

const char* psMemBlock::file [inherited]

set from __FILE__ in e.g. p_psAlloc

Definition at line 66 of file psMemory.h.

psFreeFunc psMemBlock::freeFunc [inherited]

deallocator. If NULL, use generic deallocation.

Definition at line 62 of file psMemory.h.

const char* psMemBlock::func [inherited]

set from __func__

Definition at line 68 of file psMemory.h.

const psMemId psMemBlock::id [inherited]

a unique ID for this allocation

Definition at line 64 of file psMemory.h.

const unsigned int psMemBlock::lineno [inherited]

set from __LINE__ in e.g. p_psAlloc

Definition at line 67 of file psMemory.h.

struct psMemBlock* psMemBlock::nextBlock [inherited]

next block allocation list

Definition at line 61 of file psMemory.h.

bool psMemBlock::persistent [inherited]

marks if this non-user persistent data like error stack, etc.

Definition at line 76 of file psMemory.h.

struct psMemBlock* psMemBlock::previousBlock [inherited]

previous block in allocation list

Definition at line 60 of file psMemory.h.

psReferenceCount psMemBlock::refCounter [inherited]

how many times pointer is referenced

Definition at line 75 of file psMemory.h.

const pthread_t psMemBlock::tid [inherited]

set from pthread_self();

Definition at line 65 of file psMemory.h.

size_t psMemBlock::userMemorySize [inherited]

the size of the user-portion of the memory block

Definition at line 63 of file psMemory.h.


Generated on Fri Feb 2 22:25:49 2007 for pslib by  doxygen 1.5.1