OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [Utils/] [common/] [eCosTrace.h] - Blame information for rev 790

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// ####ECOSHOSTGPLCOPYRIGHTBEGIN####                                        
2
// -------------------------------------------                              
3
// This file is part of the eCos host tools.                                
4
// Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.            
5
//
6
// This program is free software; you can redistribute it and/or modify     
7
// it under the terms of the GNU General Public License as published by     
8
// the Free Software Foundation; either version 2 or (at your option) any   
9
// later version.                                                           
10
//
11
// This program is distributed in the hope that it will be useful, but      
12
// WITHOUT ANY WARRANTY; without even the implied warranty of               
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        
14
// General Public License for more details.                                 
15
//
16
// You should have received a copy of the GNU General Public License        
17
// along with this program; if not, write to the                            
18
// Free Software Foundation, Inc., 51 Franklin Street,                      
19
// Fifth Floor, Boston, MA  02110-1301, USA.                                
20
// -------------------------------------------                              
21
// ####ECOSHOSTGPLCOPYRIGHTEND####                                          
22
//#####DESCRIPTIONBEGIN####
23
//
24
// Author(s):     sdf
25
// Contributors:  sdf
26
// Date:          1999-04-01
27
// Description:   Standard include file for test infra
28
// Usage:
29
//
30
//####DESCRIPTIONEND####
31
 
32
//=================================================================
33
// This class handles output of errors, debugging trace and so on.  All its members are static, so it's really a namespace :-).
34
// It handles two output streams - error and output - and allows these to be redirected independently to files etc...
35
// Part of the justification for this (which might be carried out on the command line) involves shortcomings of
36
// SAMBA client, which deals badly with the flushing of file buffers.
37
// The definition of LogFunc, which defines a function (void *,LPCTSTR) to which output is sent, is in eCosStd.
38
//=================================================================
39
 
40
#ifndef _ECOSTRACE_H
41
#define _ECOSTRACE_H
42
#include "eCosStd.h"
43
#include "Collections.h"
44
 
45
class CeCosTrace {
46
public:
47
        static const String Timestamp();
48
  // Diagnostic output
49
  static void Out(LPCTSTR  psz) { pfnOut(pOutParam,psz); }
50
  static void Err(LPCTSTR  psz) { pfnError(pErrorParam,psz); } // Send to "stderr" 
51
  static void TimeStampedErr(LPCTSTR pszFormat,...);
52
 
53
  enum TraceLevel {TRACE_LEVEL_ERRORS, TRACE_LEVEL_TRACE, TRACE_LEVEL_VTRACE}; // These are the levels of trace
54
 
55
  // Here's how to set and get the current trace value:
56
  static void EnableTracing(TraceLevel n) { nVerbosity=n; }
57
  static TraceLevel TracingEnabled() { return nVerbosity; }
58
 
59
  static void SetInteractive(bool b) { bInteractive=b; } // Declare this program to be "interactive" (usually means command-line)
60
  static bool IsInteractive() { return bInteractive; }
61
 
62
  static void SetOutput (LogFunc *pFn,void *pParam) { pfnOut=pFn; pOutParam=pParam; }     // Make stdout go to this callback
63
  static void SetError  (LogFunc *pFn,void *pParam) { pfnError=pFn; pErrorParam=pParam; } // Make stderr go to this callback
64
 
65
  static bool SetOutput (LPCTSTR pszFilename); // Make stdout go to this file
66
  static bool SetError  (LPCTSTR pszFilename); // Make stderr go to this file
67
 
68
  // Some macros...
69
  #ifndef TRACE // because if running under a debugger we might have a better definition (via OutputDebugString) already
70
     // Use this to generate output that will only appear if trace level is at least TRACE_LEVEL_TRACE (turned on by -v)
71
     #define TRACE if(CeCosTrace::TracingEnabled()>=CeCosTrace::TRACE_LEVEL_TRACE) CeCosTrace::TimeStampedErr
72
  #endif
73
 
74
  #undef ERROR
75
 
76
  #define ERROR CeCosTrace::TimeStampedErr
77
  // Use this to generate output that will only appear if trace level is at least TRACE_LEVEL_VTRACE (turned on by -V)
78
  #define VTRACE if(CeCosTrace::TracingEnabled()>=CeCosTrace::TRACE_LEVEL_VTRACE) CeCosTrace::TimeStampedErr
79
 
80
  // Use this to generate output that will only appear if mode is interactive (see above)
81
  #define INTERACTIVE if(CeCosTrace::IsInteractive()||CeCosTrace::TracingEnabled()>=CeCosTrace::TRACE_LEVEL_TRACE) CeCosTrace::TimeStampedErr
82
 
83
  // Thus log function can be used to direct output to a FILE* (e.g. stdout) passed as the first argument:
84
  static void CALLBACK StreamLogFunc  (void *, LPCTSTR psz);
85
 
86
protected:
87
  // Information we need to know for a stream (error or output)
88
  struct StreamInfo {
89
    Time tLastReopen;
90
    String strFilename;
91
    FILE *f;
92
    StreamInfo(LPCTSTR pszFile,FILE *_f) : tLastReopen(Now()),strFilename(pszFile),f(_f) {}
93
    ~StreamInfo() { fclose(f); }
94
  };
95
 
96
  // Here are the two streams
97
  static StreamInfo OutInfo,ErrInfo;
98
 
99
  static void CALLBACK StreamInfoFunc (void *, LPCTSTR psz);
100
 
101
  static LPCTSTR arpszDow[7];
102
 
103
  static TraceLevel nVerbosity;
104
  static bool bInteractive;
105
  static LogFunc *pfnOut;    static void *pOutParam;
106
  static LogFunc *pfnError;  static void *pErrorParam;
107
};
108
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.