IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 11, 2004, 7:50:01 PM (22 years ago)
Author:
gusciora
Message:

cosmetics...

File:
1 edited

Legend:

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

    r928 r1013  
    1 /*****************************************************************************
    2     A simple implementation of a tracing facility for Pan-STARRS.  Tracing
    3     is controlled on a per "component" basis, where a "component" is a name
    4     of the form aaa.bbb.ccc where aaa is the most significant part.
    5  
     1/** @file psTrace.c
     2 *  \brief basic run-time trace facilities
     3 *  \ingroup LogTrace
     4 *
     5 *  This file will hold the code for procedures to insert
     6 *  trace messages into the code.
     7 *
     8 *  @author Robert Lupton, Princeton University
     9 *  @author George Gusciora, MHPCC
     10 *
     11 *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-06-12 05:50:01 $
     13 *
     14 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     15 */
     16/*****************************************************************************
    617    NOTES:
    718 In the SRD, higher trace levels correspond to a numerically lower trace
     
    1627 trace level of that node.
    1728 
    18  This code is obfuscated by the fact that component names are of the form
    19  ".a.b.c.d" where "." is always the root of the tree, and for tree that have
    20  a depth of 3 or higher (including the root ".") the "."  character is also
    21  the deliminator between different individual nodes in the full component
    22  name.  So, for ".a.b.c.d", the first "." signifies the root of the tree,
    23  while the last three dots merely act as separators between the node names
    24  "b", "c", and "d".
    25  
    2629 I added a function psTraceFree() which frees all nodes in the trace component
    2730 tree.  Previously, there had been no function in the API which accomplished
     
    3235#include <string.h>
    3336#include <stdarg.h>
    34 /* #include "pslib.h" */
    3537#include "psMemory.h"
    3638#include "psTrace.h"
     
    3840#include "psError.h"
    3941
    40 static Component *croot = NULL;           // The root of the trace component
    41 static FILE *traceFP = NULL;
    42 /*****************************************************************************
    43     componentAlloc(): allocate memory for a new node, and initialize members.
     42static Component *p_psCroot = NULL;       // The root of the trace component
     43static FILE *p_psTraceFP = NULL;          // File destination for messages.
     44/*****************************************************************************
     45componentAlloc(): allocate memory for a new node, and initialize members.
    4446 *****************************************************************************/
    4547Component *componentAlloc(const char *name,
     
    5658
    5759/*****************************************************************************
    58     componentFree(): free the current node in the root tree, and all
    59  children nodes as well.
     60componentFree(): free the current node in the root tree, and all children
     61nodes as well.
    6062 *****************************************************************************/
    6163static void componentFree(Component *comp)
     
    7880
    7981/*****************************************************************************
    80     initTrace(): simply initialize the component root tree.
     82initTrace(): simply initialize the component root tree.
    8183*****************************************************************************/
    8284static void initTrace(void)
    8385{
    84     if (croot == NULL) {
    85         croot = componentAlloc(".", DEFAULT_TRACE_LEVEL);
    86     }
    87 }
    88 
    89 
    90 /*****************************************************************************
    91     Set all trace levels to zero.
     86    if (p_psCroot == NULL) {
     87        p_psCroot = componentAlloc(".", DEFAULT_TRACE_LEVEL);
     88    }
     89}
     90
     91
     92/*****************************************************************************
     93Set all trace levels to zero.
    9294 *****************************************************************************/
    9395void p_psTraceReset(Component *currentNode)
     
    112114}
    113115
     116/*****************************************************************************
     117Set all trace levels to zero.
     118 *****************************************************************************/
    114119void psTraceReset()
    115120{
    116     p_psTraceReset(croot);
    117 }
    118 
    119 
     121    p_psTraceReset(p_psCroot);
     122}
     123
     124
     125/*****************************************************************************
     126Free all nodes in the component tree.
     127 *****************************************************************************/
    120128void psTraceFree()
    121129{
    122     componentFree(croot);
    123 }
    124 
    125 
    126 /*****************************************************************************
    127     componentAdd(): Adds the component named "addNodeName" to the root tree.
     130    componentFree(p_psCroot);
     131}
     132
     133
     134/*****************************************************************************
     135componentAdd(): Adds the component named "addNodeName" to the root tree.
    128136 
    129     NOTE: replace the call to strsep() with a call to strtok(), which conforms
    130     to ANSI-C.
     137NOTE: replace the call to strsep() with a call to strtok(), which conforms
     138to ANSI-C.
    131139 *****************************************************************************/
    132140static void componentAdd(const char *addNodeName,
    133141                         int         level)
    134142{
    135     int        i = 0;
    136     char       name[strlen(addNodeName) + 1];
    137     // buffer for writeable copy.
     143    int        i = 0;                         // Loop index variable.
     144    char       name[strlen(addNodeName) + 1]; // buffer for writeable copy.
    138145    char      *pname=name;
    139146    char      *firstComponent = NULL;       // first component of name
    140     Component *currentNode = croot;
     147    Component *currentNode = p_psCroot;
    141148    int        nodeExists = 0;
    142149
    143150    // Is this the root node?  If so, simply set level and return.
    144151    if (strcmp(".", addNodeName) == 0) {
    145         croot->level = level;
     152        p_psCroot->level = level;
    146153        return;
    147154    }
     
    199206{
    200207    // If the root component tree does not exist, then initialize it.
    201     if (croot == NULL) {
     208    if (p_psCroot == NULL) {
    202209        initTrace();
    203210    }
     
    230237    char      *pname=name;
    231238    char      *firstComponent = NULL;   // first component of name
    232     Component *currentNode = croot;
     239    Component *currentNode = p_psCroot;
    233240    int        i = 0;
    234241
     
    238245
    239246    if (strcmp(".", aname) == 0) {
    240         return(croot->level);
     247        return(p_psCroot->level);
    241248    }
    242249
     
    282289int psTraceGetLevel(const char *name)
    283290{
    284     if (croot == NULL) {
     291    if (p_psCroot == NULL) {
    285292        return(UNKNOWN_TRACE_LEVEL);
    286293    }
     
    328335
    329336/*****************************************************************************
    330     psPrintTraceLevels()
    331  Simply print all the trace levels in the trace level component tree.
    332     Inputs:
    333  none
    334     Outputs:
    335  none
    336     Returns:
     337psPrintTraceLevels(): Simply print all the trace levels in the trace level
     338component tree.
     339Inputs:
     340 none
     341Outputs:
     342 none
     343Returns:
    337344 null
    338345*****************************************************************************/
    339346void psTracePrintLevels(void)
    340347{
    341     if (croot == NULL) {
     348    if (p_psCroot == NULL) {
    342349        return;
    343350    }
    344351
    345     doPrintTraceLevels(croot, 0);
    346 }
    347 
    348 
    349 /*****************************************************************************
    350     p_psTrace(): we display the trace message to standard output if the trace
    351  level of that message, supplied by the parameter "level" is higher
    352  than the trace level that is currently associated with the component
    353  named by the parameter "comp".
    354     Input:
     352    doPrintTraceLevels(p_psCroot, 0);
     353}
     354
     355
     356/*****************************************************************************
     357p_psTrace(): we display the trace message to standard output if the trace
     358level of that message, supplied by the parameter "level" is higher than the
     359trace level that is currently associated with the component named by the
     360parameter "comp".
     361Input:
    355362 comp
    356363 level
    357364 ...  a printf-style output string.
    358     Output:
    359  none
    360     Return:
     365Output:
     366 none
     367Return:
    361368 null
    362369 *****************************************************************************/
     
    384391        fmt = va_arg(ap, char *);
    385392
    386         if (traceFP != NULL) {
     393        if (p_psTraceFP != NULL) {
    387394            // We indent each message one space for each level of the message.
    388395            for (i = 0; i < level; i++) {
    389                 fprintf(traceFP, " ");
     396                fprintf(p_psTraceFP, " ");
    390397            }
    391             vfprintf(traceFP, fmt, ap);
     398            vfprintf(p_psTraceFP, fmt, ap);
    392399        } else {
    393400            // We indent each message one space for each level of the message.
     
    405412void psTraceSetDestination(FILE *fp)
    406413{
    407     traceFP = fp;
    408 }
     414    p_psTraceFP = fp;
     415}
Note: See TracChangeset for help on using the changeset viewer.