simulavr  1.1.0
SystemConsoleHandler Class Reference

Class, that handle messages to console and also exit/abort calls. More...

#include <avrerror.h>

Public Member Functions

 SystemConsoleHandler ()
 creates a SystemConsoleHandler instance More...
 
 ~SystemConsoleHandler ()
 
void SetUseExit (bool useExit=true)
 Tells the handler, that exit/abort is to use instead of exceptions. More...
 
void SetMessageStream (std::ostream *s)
 Sets the output stream, where messages are sent to. More...
 
void SetWarningStream (std::ostream *s)
 Sets the output stream, where warnings and errors are sent to. More...
 
void SetTraceFile (const char *name, unsigned int maxlines=0)
 Sets the trace to file stream and enables tracing global. More...
 
void SetTraceStream (std::ostream *s)
 Sets the trace to given stream and enables tracing global. More...
 
void StopTrace (void)
 Stops tracing global, close file, if set, redirect trace to nullStream. More...
 
bool GetTraceState (void)
 Returns true, if tracing is global enabled. More...
 
std::ostream & traceOutStream (void)
 Gives Access to trace stream. More...
 
void TraceNextLine (void)
 Ends a trace line, performs reopen new filestream, if necessary. More...
 
void vfmessage (const char *fmt,...) ATTRIBUTE_PRINTF(2
 Format and send a message to message stream (default stdout) More...
 
void void vfwarning (const char *file, int line, const char *fmt,...) ATTRIBUTE_PRINTF(4
 Format and send a warning message to warning stream (default stderr) More...
 
void void void vferror (const char *file, int line, const char *fmt,...) ATTRIBUTE_PRINTF(4
 Format and send a error message to warning stream (default stderr) More...
 
void void void ATTRIBUTE_NORETURN void vffatal (const char *file, int line, const char *fmt,...) ATTRIBUTE_PRINTF(4
 Format and send a error message to stderr and call exit or raise a exception. More...
 
void void void ATTRIBUTE_NORETURN void ATTRIBUTE_NORETURN void AbortApplication (int code)
 Aborts application: uses abort or exception depending on useExitAndAbort. More...
 
ATTRIBUTE_NORETURN void ExitApplication (int code)
 Exits application: uses exit or exception depending on useExitAndAbort. More...
 

Protected Member Functions

char * getFormatString (const char *prefix, const char *file, int line, const char *fmtstr)
 Creates the format string for formatting a message. More...
 

Protected Attributes

bool useExitAndAbort
 Flag, if exit/abort have to be used instead of exceptions. More...
 
char formatStringBuffer [192]
 Buffer for format strings to format a message. More...
 
char messageStringBuffer [768]
 Buffer for built message string itself, 4 times bigger than formatStringBuffer. More...
 
std::ostream * msgStream
 Stream, where normal messages are sent to. More...
 
std::ostream * wrnStream
 Stream, where warning and error messages are sent to. More...
 
std::ostream * traceStream
 Stream for trace output. More...
 
std::ostream * nullStream
 /dev/null! ;-) More...
 
std::ofstream * fileTraceStream
 open file stream for trace More...
 
bool traceEnabled
 flag, true if trace is enabled More...
 
bool traceToFile
 flag, true if trace writes to filestream More...
 
std::string traceFilename
 file name for trace file (will be appended with file count!) More...
 
unsigned int traceLinesOnFile
 how much lines will be written on one trace file 0->means endless More...
 
unsigned int traceLines
 how much lines are written on current trace file More...
 
int traceFileCount
 Counter for trace files. More...
 

Detailed Description

Class, that handle messages to console and also exit/abort calls.

Definition at line 47 of file avrerror.h.

Constructor & Destructor Documentation

◆ SystemConsoleHandler()

SystemConsoleHandler::SystemConsoleHandler ( )

creates a SystemConsoleHandler instance

This is needed only once for a application, see global variable sysConHandler, where such instance is created by default.

Definition at line 53 of file avrerror.cpp.

References fileTraceStream, msgStream, nullStream, traceEnabled, traceStream, traceToFile, useExitAndAbort, and wrnStream.

◆ ~SystemConsoleHandler()

SystemConsoleHandler::~SystemConsoleHandler ( )

Definition at line 64 of file avrerror.cpp.

References nullStream, StopTrace(), traceStream, and traceToFile.

Member Function Documentation

◆ AbortApplication()

void SystemConsoleHandler::AbortApplication ( int  code)

Aborts application: uses abort or exception depending on useExitAndAbort.

Definition at line 202 of file avrerror.cpp.

References useExitAndAbort.

Referenced by RWAbort::get(), RWAbort::set(), and traceOutStream().

◆ ExitApplication()

void SystemConsoleHandler::ExitApplication ( int  code)

Exits application: uses exit or exception depending on useExitAndAbort.

Definition at line 210 of file avrerror.cpp.

References useExitAndAbort.

Referenced by RWExit::get(), RWExit::set(), and traceOutStream().

◆ getFormatString()

char * SystemConsoleHandler::getFormatString ( const char *  prefix,
const char *  file,
int  line,
const char *  fmtstr 
)
protected

Creates the format string for formatting a message.

Definition at line 218 of file avrerror.cpp.

References formatStringBuffer.

Referenced by vferror(), vffatal(), and vfwarning().

◆ GetTraceState()

bool SystemConsoleHandler::GetTraceState ( void  )
inline

Returns true, if tracing is global enabled.

Definition at line 70 of file avrerror.h.

References traceEnabled.

◆ SetMessageStream()

void SystemConsoleHandler::SetMessageStream ( std::ostream *  s)

Sets the output stream, where messages are sent to.

Definition at line 75 of file avrerror.cpp.

References msgStream.

◆ SetTraceFile()

void SystemConsoleHandler::SetTraceFile ( const char *  name,
unsigned int  maxlines = 0 
)

Sets the trace to file stream and enables tracing global.

Definition at line 83 of file avrerror.cpp.

References fileTraceStream, StopTrace(), traceEnabled, traceFileCount, traceFilename, traceLines, traceLinesOnFile, traceStream, and traceToFile.

Referenced by avr_trace_tf().

◆ SetTraceStream()

void SystemConsoleHandler::SetTraceStream ( std::ostream *  s)

Sets the trace to given stream and enables tracing global.

Definition at line 96 of file avrerror.cpp.

References fileTraceStream, StopTrace(), traceEnabled, traceStream, and traceToFile.

◆ SetUseExit()

void SystemConsoleHandler::SetUseExit ( bool  useExit = true)

Tells the handler, that exit/abort is to use instead of exceptions.

Definition at line 71 of file avrerror.cpp.

References useExitAndAbort.

◆ SetWarningStream()

void SystemConsoleHandler::SetWarningStream ( std::ostream *  s)

Sets the output stream, where warnings and errors are sent to.

Definition at line 79 of file avrerror.cpp.

References wrnStream.

◆ StopTrace()

void SystemConsoleHandler::StopTrace ( void  )

Stops tracing global, close file, if set, redirect trace to nullStream.

Definition at line 108 of file avrerror.cpp.

References fileTraceStream, nullStream, traceEnabled, traceStream, and traceToFile.

Referenced by avr_trace_tf(), SetTraceFile(), SetTraceStream(), and ~SystemConsoleHandler().

◆ TraceNextLine()

void SystemConsoleHandler::TraceNextLine ( void  )

Ends a trace line, performs reopen new filestream, if necessary.

Definition at line 121 of file avrerror.cpp.

References fileTraceStream, traceEnabled, traceFileCount, traceFilename, traceLines, traceLinesOnFile, traceStream, and traceToFile.

Referenced by AvrDevice::Step(), and traceOutStream().

◆ traceOutStream()

std::ostream& SystemConsoleHandler::traceOutStream ( void  )
inline

Gives Access to trace stream.

Definition at line 72 of file avrerror.h.

References AbortApplication(), ATTRIBUTE_NORETURN, ATTRIBUTE_PRINTF, ExitApplication(), TraceNextLine(), traceStream, vferror(), vffatal(), vfmessage(), and vfwarning().

Referenced by trioaccess().

◆ vferror()

void SystemConsoleHandler::vferror ( const char *  file,
int  line,
const char *  fmt,
  ... 
)

Format and send a error message to warning stream (default stderr)

Definition at line 176 of file avrerror.cpp.

References getFormatString(), messageStringBuffer, and wrnStream.

Referenced by traceOutStream().

◆ vffatal()

void SystemConsoleHandler::vffatal ( const char *  file,
int  line,
const char *  fmt,
  ... 
)

Format and send a error message to stderr and call exit or raise a exception.

Definition at line 188 of file avrerror.cpp.

References getFormatString(), messageStringBuffer, useExitAndAbort, and wrnStream.

Referenced by traceOutStream().

◆ vfmessage()

void SystemConsoleHandler::vfmessage ( const char *  fmt,
  ... 
)

Format and send a message to message stream (default stdout)

Definition at line 147 of file avrerror.cpp.

References formatStringBuffer, global_verbose_on, messageStringBuffer, and msgStream.

Referenced by traceOutStream().

◆ vfwarning()

void SystemConsoleHandler::vfwarning ( const char *  file,
int  line,
const char *  fmt,
  ... 
)

Format and send a warning message to warning stream (default stderr)

Definition at line 164 of file avrerror.cpp.

References getFormatString(), messageStringBuffer, and wrnStream.

Referenced by traceOutStream().

Member Data Documentation

◆ fileTraceStream

std::ofstream* SystemConsoleHandler::fileTraceStream
protected

open file stream for trace

Definition at line 105 of file avrerror.h.

Referenced by SetTraceFile(), SetTraceStream(), StopTrace(), SystemConsoleHandler(), and TraceNextLine().

◆ formatStringBuffer

char SystemConsoleHandler::formatStringBuffer[192]
protected

Buffer for format strings to format a message.

Definition at line 99 of file avrerror.h.

Referenced by getFormatString(), and vfmessage().

◆ messageStringBuffer

char SystemConsoleHandler::messageStringBuffer[768]
protected

Buffer for built message string itself, 4 times bigger than formatStringBuffer.

Definition at line 100 of file avrerror.h.

Referenced by vferror(), vffatal(), vfmessage(), and vfwarning().

◆ msgStream

std::ostream* SystemConsoleHandler::msgStream
protected

Stream, where normal messages are sent to.

Definition at line 101 of file avrerror.h.

Referenced by SetMessageStream(), SystemConsoleHandler(), and vfmessage().

◆ nullStream

std::ostream* SystemConsoleHandler::nullStream
protected

/dev/null! ;-)

Definition at line 104 of file avrerror.h.

Referenced by StopTrace(), SystemConsoleHandler(), and ~SystemConsoleHandler().

◆ traceEnabled

bool SystemConsoleHandler::traceEnabled
protected

flag, true if trace is enabled

Definition at line 106 of file avrerror.h.

Referenced by GetTraceState(), SetTraceFile(), SetTraceStream(), StopTrace(), SystemConsoleHandler(), and TraceNextLine().

◆ traceFileCount

int SystemConsoleHandler::traceFileCount
protected

Counter for trace files.

Definition at line 111 of file avrerror.h.

Referenced by SetTraceFile(), and TraceNextLine().

◆ traceFilename

std::string SystemConsoleHandler::traceFilename
protected

file name for trace file (will be appended with file count!)

Definition at line 108 of file avrerror.h.

Referenced by SetTraceFile(), and TraceNextLine().

◆ traceLines

unsigned int SystemConsoleHandler::traceLines
protected

how much lines are written on current trace file

Definition at line 110 of file avrerror.h.

Referenced by SetTraceFile(), and TraceNextLine().

◆ traceLinesOnFile

unsigned int SystemConsoleHandler::traceLinesOnFile
protected

how much lines will be written on one trace file 0->means endless

Definition at line 109 of file avrerror.h.

Referenced by SetTraceFile(), and TraceNextLine().

◆ traceStream

std::ostream* SystemConsoleHandler::traceStream
protected

Stream for trace output.

Definition at line 103 of file avrerror.h.

Referenced by SetTraceFile(), SetTraceStream(), StopTrace(), SystemConsoleHandler(), TraceNextLine(), traceOutStream(), and ~SystemConsoleHandler().

◆ traceToFile

bool SystemConsoleHandler::traceToFile
protected

flag, true if trace writes to filestream

Definition at line 107 of file avrerror.h.

Referenced by SetTraceFile(), SetTraceStream(), StopTrace(), SystemConsoleHandler(), TraceNextLine(), and ~SystemConsoleHandler().

◆ useExitAndAbort

bool SystemConsoleHandler::useExitAndAbort
protected

Flag, if exit/abort have to be used instead of exceptions.

Definition at line 98 of file avrerror.h.

Referenced by AbortApplication(), ExitApplication(), SetUseExit(), SystemConsoleHandler(), and vffatal().

◆ wrnStream

std::ostream* SystemConsoleHandler::wrnStream
protected

Stream, where warning and error messages are sent to.

Definition at line 102 of file avrerror.h.

Referenced by SetWarningStream(), SystemConsoleHandler(), vferror(), vffatal(), and vfwarning().


The documentation for this class was generated from the following files: