OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [tools/] [src/] [tools/] [Utils/] [common/] [eCosTrace.h] - Blame information for rev 502

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

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

powered by: WebSVN 2.1.0

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