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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [Utils/] [common/] [eCosTrace.cpp] - 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 trace functions
28
// Usage:
29
//
30
//####DESCRIPTIONEND####
31
 
32
#include "eCosThreadUtils.h"
33
#include "eCosTrace.h"
34
 
35
CeCosTrace::TraceLevel CeCosTrace::nVerbosity=CeCosTrace::TRACE_LEVEL_ERRORS;
36
bool CeCosTrace::bInteractive=false;
37
LPCTSTR CeCosTrace::arpszDow[7]={_T("Su"),_T("M"),_T("Tu"),_T("W"),_T("Th"),_T("F"),_T("Sa")};
38
 
39
LogFunc *CeCosTrace::pfnOut=StreamLogFunc;
40
void *CeCosTrace::pOutParam=(void *)stdout;
41
LogFunc *CeCosTrace::pfnError=StreamLogFunc;
42
void *CeCosTrace::pErrorParam=(void *)stderr;
43
 
44
CeCosTrace::StreamInfo CeCosTrace::OutInfo(_T(""),stdout);
45
CeCosTrace::StreamInfo CeCosTrace::ErrInfo(_T(""),stderr);
46
 
47
void CALLBACK CeCosTrace::StreamLogFunc(void *pParam, LPCTSTR psz)
48
{
49
  // Interactive mode
50
  ENTERCRITICAL;
51
  _fputts(psz,(FILE *)pParam);
52
  fflush((FILE *)pParam);
53
  LEAVECRITICAL;
54
}
55
 
56
bool CeCosTrace::SetOutput(LPCTSTR pszFilename)
57
{
58
  FILE *f=_tfopen(pszFilename,_T("a") MODE_TEXT);
59
  if(f){
60
    if(!OutInfo.strFilename.empty()){
61
      fclose(OutInfo.f);
62
    }
63
    if(nVerbosity>=TRACE_LEVEL_TRACE){
64
      _ftprintf(stderr,_T("Output -> %s (%08x)\n"),pszFilename,(unsigned int)f);
65
    }
66
    OutInfo.f=f;
67
    OutInfo.strFilename=pszFilename;
68
    SetOutput(StreamInfoFunc,&OutInfo);
69
  }
70
  return (NULL!=f);
71
}
72
 
73
bool CeCosTrace::SetError(LPCTSTR pszFilename)
74
{
75
  FILE *f=_tfopen(pszFilename,_T("a") MODE_TEXT);
76
  if(f){
77
    if(!ErrInfo.strFilename.empty()){
78
      fclose(ErrInfo.f);
79
    }
80
    ErrInfo.f=f;
81
    ErrInfo.strFilename=pszFilename;
82
    SetError(StreamInfoFunc,&ErrInfo);
83
  }
84
  return (NULL!=f);
85
}
86
 
87
void CALLBACK CeCosTrace::StreamInfoFunc(void *pParam, LPCTSTR psz)
88
{
89
  StreamInfo *pInfo=(StreamInfo *)pParam;
90
  ENTERCRITICAL;
91
  _fputts(psz,pInfo->f);
92
  if(!pInfo->strFilename.empty() && Now()-pInfo->tLastReopen>20*1000){
93
    // SAMBA clients will not honor fflush(), so we do this:
94
    fclose(pInfo->f);
95
    do {
96
      pInfo->f=_tfopen(pInfo->strFilename,_T("a") MODE_TEXT);
97
      if(NULL==pInfo->f){
98
        _ftprintf(stderr,_T("Failed to reopen %s\n"),(LPCTSTR)pInfo->strFilename);
99
        CeCosThreadUtils::Sleep(1000);
100
      }
101
    } while (NULL==pInfo->f);
102
    pInfo->tLastReopen=Now();
103
  } else {
104
    fflush(pInfo->f);
105
  }
106
  LEAVECRITICAL;
107
}
108
 
109
void CeCosTrace::TimeStampedErr(LPCTSTR pszFormat,...)
110
{
111
  va_list marker;
112
  va_start (marker, pszFormat);
113
        String str;
114
  str.vFormat(pszFormat,marker);
115
  va_end (marker);
116
 
117
  Err(String::SFormat(_T("%s %s"),(LPCTSTR)Timestamp(),(LPCTSTR)str));
118
}
119
 
120
const String CeCosTrace::Timestamp()
121
{
122
  time_t ltime;
123
  time(&ltime);
124
  struct tm *now=localtime( &ltime );
125
 
126
  bool bInCriticalSection=CeCosThreadUtils::CS::InCriticalSection();
127
  TCHAR c1=bInCriticalSection?_TCHAR('<'):_TCHAR('[');
128
  TCHAR c2=bInCriticalSection?_TCHAR('>'):_TCHAR(']');
129
  return String::SFormat(_T("%c%3x %s %02d:%02d:%02d%c"),c1,CeCosThreadUtils::GetThreadId(),
130
    arpszDow[now->tm_wday],now->tm_hour,now->tm_min,now->tm_sec,c2);
131
 
132
}

powered by: WebSVN 2.1.0

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