fdhwlib  2.0.25
/home/kopmann/git-mirror/fdhwlib/fdhwlib/Pbus/PbusError.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     PbusError.h  -  description
00003     
00004     begin                : Thu Jun 29 2000
00005     copyright            : (C) 2000 by Andreas Kopmann
00006     email                : kopmann@hpe.fzk.de
00007  ***************************************************************************/
00008 
00009 
00010 
00011 
00012 #if defined (_MSC_VER) && (_MSC_VER >= 1000)
00013 #pragma once
00014 #endif
00015 #ifndef _INC_PBUS_ERROR_39167CC200C0_INCLUDED
00016 #define _INC_PBUS_ERROR_39167CC200C0_INCLUDED
00017 
00018 
00019 #include <cstdio>
00020 #include <cstring>      // strlen()
00021 #include <stdexcept>
00022 
00033 //##ModelId=399121F90384
00034 class PbusError : public std::runtime_error {
00035 public:
00036         //##ModelId=399121F90390
00037         inline PbusError(unsigned long addr, unsigned long data);
00038 
00039         //##ModelId=399121F90398
00040         inline PbusError(unsigned long addr);
00041 
00042         //##ModelId=399121F9039A
00043         inline PbusError(const char *msg, unsigned long addr=0, unsigned long data=0);
00044 
00045         inline PbusError(const char *msg, const char *fmt, ...);
00046   
00047         unsigned long getAddr() const
00048          { return addr; }
00049 
00050         unsigned long getData() const
00051          { return data; }
00052 
00053         const char *getMsg() const {
00054           if ( *msg ) return msg;
00055           else return("Unspecified access error");
00056         }
00057   
00058         const char *what() const throw()
00059          { return getMsg(); }
00060 
00061         inline void displayMsg(FILE *fout);
00062 
00063 private:
00064         //##ModelId=399121F9038F
00065         unsigned long addr;
00066 
00067         //##ModelId=399121F9038E
00068         unsigned long data;
00069 
00070         char msg[120];
00071 };
00072 
00073 //##ModelId=39167CDC0171
00074 inline PbusError::PbusError(unsigned long addr, unsigned long data)
00075                 : runtime_error("PbusError")
00076 {
00077   if ( snprintf(msg,sizeof(msg),"writing %08lx to %08lx",data,addr)
00078        >= (int)sizeof(msg) )
00079     msg[sizeof(msg)-1]=0;
00080   this->addr = addr;
00081   this->data = data;
00082 }
00083 
00084 //##ModelId=39167D0D0316
00085 inline PbusError::PbusError(unsigned long addr)
00086                  : runtime_error("PbusError")
00087 {
00088   if ( snprintf(msg, sizeof(msg), "reading %08lx",addr) >= (int)sizeof(msg) )
00089     msg[sizeof(msg)-1]=0;
00090    this->addr = addr;
00091   this->data = 0;
00092 }
00093 
00094 inline PbusError::PbusError(const char * msg, unsigned long addr, unsigned long data)
00095                  : runtime_error(msg)
00096 {
00097   if ( snprintf(this->msg,sizeof(this->msg),"%s",msg) >= (int)sizeof(this->msg) )
00098     this->msg[sizeof(this->msg)-1]=0;
00099   this->addr = addr;
00100   this->data = data;
00101 }
00102 
00103 
00104 inline void PbusError::displayMsg(FILE *fout){
00105 
00106   if ( strlen(msg) ) fprintf(fout,"PbusError: %s",msg);
00107   else fprintf(fout, "PbusError: Unspecified access error");
00108   if (addr > 0) fprintf(fout,", addr=%lx", addr);
00109   if (data > 0) fprintf(fout,", data=%lx", data);
00110   fprintf(fout,"\n");
00111 }
00112 
00113 
00119 class PbusRawError : public std::runtime_error {
00120 public:
00121         inline PbusRawError();
00122 };
00123 
00124 inline PbusRawError::PbusRawError() : runtime_error("PbusRawError"){}
00125 
00126 #endif /* _INC_PBUS_ERROR_39167CC200C0_INCLUDED */
00127