Source: gdms/cepError.h


Annotated List
Files
Globals
Hierarchy
Index

/****************************************************************************** 
   Imp for the CEP error
   Copyright (C) Michael Still                       2002
   Copyright (C) Blake Swadling  2002
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
******************************************************************************/

#ifndef CEP_ERROR_HEADER
#define CEP_ERROR_HEADER

/******************************************************************************
DOCBOOK START

FUNCTION cepDebugPrint
PURPOSE print out debugging information via cepError

SYNOPSIS START
cepDebugPrint(string debugMessage);
SYNOPSIS END

DESCRIPTION START
cepDebugPrint creates a cepError of debug severity and immediately displays it -- this will normally result in the debug message being logged. The macro also pack into the message the name of the source file which called cepDebugPrint, and the line number that the call occurred at, for ease of debugging.
DESCRIPTION END

SEEALSO cepDebug
DOCBOOK END
******************************************************************************/

// This prints out some debugging information which is useful, use it instead
// of:
// cepError cepDebugPrint("Some text", cepError::sevDebug);
// cepDebugPrint.display();

///////////////////////////////////////////////////////////////////////////////
// THIS CANNOT DO A DISPLAY, AS THE CONFIG DB CODE USES THIS TO LOG DB PROBLEMS
// AND cepError::display() USES THE CONFIG DB...
///////////////////////////////////////////////////////////////////////////////
#define cepDebugPrint(errmsg) \
  { \
    cepError newname_cepDebugPrint(string("") + string(errmsg) + string(" at ") + string(__FILE__) + \
			string(":") + cepToString(__LINE__), cepError::sevDebug); \
    newname_cepDebugPrint.log(); \
  }

/******************************************************************************
DOCBOOK START

FUNCTION cepError
PURPOSE represent errors

SYNOPSIS START
enum severity
{
  sevOk = 0,
  sevDebug,
  sevInformational,
  sevWarning,
  sevErrorRecoverable,
  sevErrorFatal,
  sevMax
};

cepError ();
cepError (const string& msg);
cepError (const string& msg, severity level);
~cepError ();

bool isReal ();
void clear();
void log();
void display ();
string & getMessage();
int getSeverity();
SYNOPSIS END

DESCRIPTION START
This class represents errors that may be generated during execution



The enumeration severity defines the possible error levels available to cepError. These levels have differing default resposes within the cepError class, depending on their perceived importance:

//todo_mikal: implement error level actions as defined here

sevOk: this error is not really an error, and will not be displayed. This is the default error level.
sevDebug: this is a debugging message, which will normally be logged, but not displayed. There may be a very large number of these during the normal operation of the application.
sevInformational: this is an informational message which will be displayed, and logged.
sevWarning: this is a warning that would normally be of interest to the user. It will be logged and displayed by default.
sevErrorRecoverable: this level reports an error, which the application can recover from. It will be displayed and logged by default.
sevErrorFatal: this is an error. It will be by default displayed, logged, and the application will exit after the user has acknowledged the error. Display of this error type cannot be disabled by the user.




cepError ();
Default constructor. This will create a cepError with a default severity of sevOk.



cepError (const string& msg);
Contruct a cepError with a severity of sevErrorFatal.



cepError (const string& msg, severity level);
Construct a cepError with the specified severity.



~cepError ();
If the cepError has not been actioned (checked if real, copied, displayed or logged) by the time the destructor is called, then it will be actioned at this point.



bool isReal ();
If the cepError has a severity of anything other than sevOk



void clear();
Clears the cepError by setting severity to sevOk and removing the current message.



void log();
Write the cepError to the log if there is an errorhandler installed.



void display ();
Display the cepError if there is an errorHandler installed.



string& getMessage ();
queries the description of this cepError.



int getSeverity ();
queries the severity of this cepError.

DESCRIPTION END

SEEALSO cepErrorHandler
DOCBOOK END
******************************************************************************/

#include 
#include "cepErrorHandler.h"
#include "cepUtility.h"

using namespace std;

class cepError
{
public:
  /** various available levels of severity */
  enum severity
  {
    sevOk = 0,
    sevDebug,
    sevInformational,
    sevWarning,
    sevErrorRecoverable,
    sevErrorFatal,
    sevMax
  };

  /** Default constructor. Creates a new instance of cepError */
  cepError ();
  
  /** Constructor. Creates a new instance of cepError
   * @param msg a description of the cause of the error
   */
  cepError (const string & msg);
  
  /** Constructor. Creates a new instance of cepError
   * @param msg a description of the cause of the error
   * @param level the severity of the error
   */
  cepError (const string & msg, severity level);

  /**
   * Adds a global cepErrorHandler which will be used to display and log errors.
   * If no error handler is installed then display and log are not performed
   * @param h the error handler to be used by all cepErrors
   */
  static void setErrorHandler( class cepErrorHandler& h );

  /** Destructor. if this is called and the error has not been actioned then the error
   * is logged. Note that if no error handler is installed, failure to action will
   * not be detected
   */
  ~cepError ();

  /** Check the status of the cepError
   * @return false if the severity is sevOk, true otherwise.
   */
  bool isReal ();

  /** Clears the cepError by setting severity to sevOk
   * and removing the current message
   */
  void clear ();

  /** Logs the cepError via the currently installed error handler.
   * If there is no error handler installed hen no action is taken
   */
  void log ();

  /** Displays the cepError via the currently installed error handler.
   * If there is no error handler installed hen no action is taken
   */
  void display ();

  // BS - remove these when we get the friend thing for cepErrorHandler sorted

  /** Queries the description of the current cepError
   * @return a description of the current cepError
   */
  string & getMessage();

  /** Queries the severity of the current cepError
   * @return the severity of the current cepError
   */
  int getSeverity();

private:

  /** whether there is an error handler installed */
  static bool handlerInstalled;
  /** the current error handler */
  static class cepErrorHandler *handler;

  /** a description of the error */
  string message;
  /** the severity of the error */
  severity level;
  /** whether the error has been actioned */
  bool actioned;
};

#endif

Generated by: pob on trillian on Sat Aug 10 17:26:42 2002, using kdoc 2.0a53.