/*
   Error.c, Copyright 6.3.97 (c) by C. Conrad,
   Swiss Federal Institute of Technology,
   Computer Engineering and Networks Laboratory.
 
   TOPSY -- A Teachable Operating System.
   Implementation of a tiny and simple
   micro kernel for teaching purposes.
 
   For further information, please visit http://www.tik.ee.ethz.ch/~topsy
 
   This software is provided under the terms of the GNU General Public Licence.
 
   A full copy of the GNU GPL is provided in the file COPYING found in the 
   development root of Topsy.
 */
/*
 
	File:                  $Source: /home/ruf/cvs_Topsy/cvs/Topsy/Topsy/Error.c,v $
	Author(s):             C. Conrad
	Affiliation:           ETH Zuerich, TIK
	Version:               $Revision: 2922 $
	Creation Date:         6.3.97
	Last Date of Change:   $Date: 2007-03-19 17:48:52 +0100 (Mon, 19 Mär 2007) $      by: $Author: baderma $
*/

#include "Topsy.h"
#include "Error.h"
#include "IO.h"
#include "List.h"

extern List threadList;
extern int exceptionContextFlag;


static void errLog( char* threadName,
                    const char* fileName,
                    int lineNumber,
                    char* errorMessage)
{
  ioConsolePutString(threadName);
  if (exceptionContextFlag != 0)
  {
    ioConsolePutString(" (*in exc*)");
  }
  ioConsolePutString(", ");
  ioConsolePutString(fileName);
  ioConsolePutString(":");
  ioConsolePutInt(lineNumber);
  ioConsolePutString(" ] ");
  ioConsolePutString(errorMessage);
  ioConsolePutString("\n");
}

void error( char* threadName,
            const char* fileName,
            int lineNumber,
            char* errorMessage)
{
  ioConsolePutString("*** ERROR [ ");
  errLog( threadName, fileName, lineNumber, errorMessage);
}

void warning( char* threadName,
              const char* fileName,
              int lineNumber,
              char* errorMessage)
{
  ioConsolePutString("** WARNING [ ");
  errLog( threadName, fileName, lineNumber, errorMessage);
}

void info( char* threadName,
           const char* fileName,
           int lineNumber,
           char* errorMessage)
{
  ioConsolePutString("* INFO [ ");
  errLog( threadName, fileName, lineNumber, errorMessage);
}

void panic ( char *threadName,
             const char *fileName,
             int lineNumber,
             char *errorMessage)
{
  ioConsolePutString("**** PANIC [ ");
  errLog( threadName, fileName, lineNumber, errorMessage);
  while (TRUE)
  {}
}

void check( char* threadName,
            const char* fileName,
            int lineNumber,
            char* errorMessage,
            int condition)
{

  if (!condition)
  {
    ioConsolePutString("**** Check failed [ ");
    errLog( threadName, fileName, lineNumber, errorMessage);
    //-CJ    asm(" cli ; hlt ");
  }
}
