• Classes
  • Modules
  • Namespaces
  • Files
  • Related Pages
  • File List
  • File Members

acserrLegacy.h

Go to the documentation of this file.
00001 #ifndef _acserr_Legacy_H_
00002 #define _acserr_Legacy_H_
00003 /*******************************************************************************
00004 * ALMA - Atacama Large Millimiter Array
00005 * (c) European Southern Observatory, 2004 
00006 *
00007 *This library is free software; you can redistribute it and/or
00008 *modify it under the terms of the GNU Lesser General Public
00009 *License as published by the Free Software Foundation; either
00010 *version 2.1 of the License, or (at your option) any later version.
00011 *
00012 *This library is distributed in the hope that it will be useful,
00013 *but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 *Lesser General Public License for more details.
00016 *
00017 *You should have received a copy of the GNU Lesser General Public
00018 *License along with this library; if not, write to the Free Software
00019 *Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00020 *
00021 * "@(#) $Id: acserrLegacy.h,v 1.11 2007/05/14 14:12:32 bjeram Exp $"
00022 *
00023 * who       when      what
00024 * --------  --------  ----------------------------------------------
00025 * bjeram  2004-02-13  created
00026 */
00027 
00028 /************************************************************************
00029  *
00030  *----------------------------------------------------------------------
00031  */
00032 
00033 #ifndef __cplusplus
00034 #error This is a C++ include file and cannot be used from plain C
00035 #endif
00036 
00037 #include <logging.h>
00038 #include <Thread_Manager.h> 
00039 #include <sstream>
00040 #include <acserrS.h>
00041 #include <acscommonC.h>
00042 #include <exception>
00043 
00044 // for backward compatibilty reason
00045 namespace ACSErr {
00046     const ErrorCode ACSErrOK = ACSErrOK;
00047 };
00048 
00049 
00053 #define DEFAULT_SEVERITY ACSErr::Error
00054 
00063 #define ACS_ERROR_BEGIN(et, ec, ro) ACSError(__FILE__, __LINE__, et, ec, ro)
00064 
00082 #define ACS_ERROR(arg...) ACSError(__FILE__, __LINE__ ,## arg)
00083 //#define ACS_ERROR(pe, et, ec, ro) ACSError(__FILE__, __LINE__, pe, et, ec, ro, )
00084 //#define ACS_ERROR_BEGIN(et, ec, ro) ACSError(__FILE__, __LINE__, et, ec, ro)
00085 //#define ACS_NO_ERROR(ro) ACSError(__FILE__, __LINE__, ro)
00086 
00087 
00094 #define ACS_NO_ERROR(ro) ACSError(__FILE__, __LINE__, ro)
00095 
00113 #define ACS_EXCEPTION(arg...) ACSErr::ACSException( ACSError::createErrorTrace(__FILE__, __LINE__, arg) )
00114 //#define ACS_EXCEPTION(eo) ACSErr::ACSException( eo.getErrorTrace() )
00115 
00133 #define THROW_ACS_EXCEPTION(arg...) ACE_THROW ( ACS_EXCEPTION(arg) )
00134                                                 
00153 #define THROW_ACS_EXCEPTION_EX(lab, arg...) ACE_THROW_EX ( ACS_EXCEPTION(arg), lab )
00154 
00174 #define RETHROW_ACS_EXCEPTION(arg...) ACE_TRY_THROW ( ACS_EXCEPTION(arg) )
00175 
00194 #define RETHROW_ACS_EXCEPTION_EX(lab, arg...) ACE_TRY_THROW_EX ( ACS_EXCEPTION(arg), lab )
00195 
00200 class ACSError {
00201 public:
00202 
00209   ACSError (); 
00210 
00217     ACSError (const char* file, int line); // = ACSError()
00218 
00227   ACSError (const char* file, int line, const char* routine);
00228 
00235   ACSError (const ACSErr::ErrorTrace& errortrace);
00236 
00243   ACSError (ACSErr::ErrorTrace& errortrace);
00244 
00256   ACSError (const char* file, int line, ACSErr::ErrorTrace* errortrace, bool release=1);
00257 
00266   ACSError (ACSErr::ErrorTrace* errortrace, bool release=1);
00267 
00279   ACSError (const char* file, int line, ACSErr::ACSErrType et, ACSErr::ErrorCode ec, 
00280             const char* routine, ACSErr::Severity severity=DEFAULT_SEVERITY);
00281 
00295     ACSError (const char* file, int line, ACSError &err, ACSErr::ACSErrType et, ACSErr::ErrorCode ec, 
00296               const char *routine, ACSErr::Severity severity=DEFAULT_SEVERITY);
00297 
00311   ACSError (const char* file, int line, ACSError *err, ACSErr::ACSErrType et, ACSErr::ErrorCode ec, 
00312             const char *routine, ACSErr::Severity severity=DEFAULT_SEVERITY, bool release=1);
00319   ACSError (ACSErr::ACSException& exception);
00320 
00332   ACSError (const char* file, int line, ACSErr::ACSException &pex, ACSErr::ACSErrType et,
00333             ACSErr::ErrorCode ec, const char *routine,
00334             ACSErr::Severity severity=DEFAULT_SEVERITY);
00335 
00347   ACSError (const char* file, int line, ACSErr::ErrorTrace &pc, ACSErr::ACSErrType et,
00348             ACSErr::ErrorCode ec, const char *routine,
00349             ACSErr::Severity severity=DEFAULT_SEVERITY);
00350 
00354   ~ACSError();
00355   
00361    ACSErr::ErrorTrace& getErrorTrace(){ return *current; } // should check if stack is empty
00362  
00368   ACSErr::ErrorTrace* returnErrorTrace (bool deletion=true);
00369   
00375   ACSErr::ErrorTrace *getNext();
00376   
00381   ACSErr::ErrorTrace *top(){ current = &errorTrace; return current;}
00382 
00386   void log();
00387 
00392   bool isOK(){ return (current->errorCode==ACSErrOK && current->errorType==ACSErrTypeOK); }
00393 
00399   void addData (const char* name, const char* value);
00400     
00407   template<class T>
00408   void addData (const char* name, T value){
00409       const char *s;
00410       std::ostringstream ostr;
00411       ostr << value << std::ends;
00412       std::string ts=ostr.str(); // we have to make a temporary string otherwise there is problem with memory:  s = ostr.str().c_str(); does not work
00413       s = ts.c_str();
00414       addData (name, s);
00415   }
00416 
00421   char* getDescription();
00422 
00428   static char* getDescription (ACSErr::ACSErrType et, ACSErr::ErrorCode ec);
00429 
00434   char* getFileName(){ return CORBA::string_dup(current->file); }
00435 
00440   CORBA::ULong getLineNumber(){ return current->lineNum; }
00441 
00446   char* getRoutine(){ return CORBA::string_dup (current->routine); }
00447 
00452   char* getHostName(){ return CORBA::string_dup (current->host); }
00453 
00458   char* getProcess(){ return CORBA::string_dup (current->process); }
00459 
00464   char* getThread(){ return CORBA::string_dup (current->thread); }
00465 
00470   CORBA::ULongLong getTimeStamp (){ return current->timeStamp; }
00471 
00476     ACSErr::ErrorCode getErrorCode(){ return current->errorCode; }
00477 //      CORBA::Long t; current->error >>= t; return t; }
00478 
00483     ACSErr::ACSErrType getErrorType(){ return current->errorType; }
00484 
00488   ACSErr::Severity getSeverity() { return current->severity; }
00489 
00494   unsigned int getDepth(){ return depth; }
00495 
00500  void setTimeStamp (CORBA::ULongLong time){ current->timeStamp = time; }
00501 
00507   void setFileName(const char* fn){ current->file = CORBA::string_dup (fn); }
00508 
00514   void setLineNumber (CORBA::ULong ln){ current->lineNum = ln; }//? should we delete previos one
00515 
00522   void setError (ACSErr::ACSErrType ty, ACSErr::ErrorCode ec) 
00523         { current->errorType=ty; current->errorCode=ec; }
00524 
00530   void setSeverity(ACSErr::Severity severity) {current->severity = severity; }
00531 
00536   static void hostName (const char* hn);
00537   
00543     static void processName (const char *pn); 
00544 
00545 
00550   static void setProcessName (const char *pn); 
00551 
00552 
00553   static ACSErr::ErrorTrace createErrorTrace (const char* file, int line,
00554                                                     ACSError &er)
00555 {
00556     ACE_UNUSED_ARG(file); 
00557     ACE_UNUSED_ARG(line); 
00558     return er.getErrorTrace(); 
00559 }
00560 
00561   static ACSErr::ErrorTrace createErrorTrace (const char* file, int line, 
00562                                                      ACSErr::ACSException &pex, ACSErr::ACSErrType et,
00563                                                      ACSErr::ErrorCode ec, const char *routine,
00564                                                      ACSErr::Severity severity=DEFAULT_SEVERITY);
00565 
00566   static ACSErr::ErrorTrace createErrorTrace (const char* file, int line, 
00567                                                      ACSErr::ACSErrType et, ACSErr::ErrorCode ec,\
00568                                                      const char *routine,
00569                                                      ACSErr::Severity severity=DEFAULT_SEVERITY); 
00570 
00571     static bool init (int argc, char *argv[]);
00572     static bool init (CORBA::ORB_ptr _orb);
00573     static bool init ();
00574     static bool isInit(){ return initialized; }
00575     static void done();
00576 
00577 protected:
00578     static bool initialized;
00579     
00580     static bool initLog (CORBA::ORB_ptr _orb);
00586   void log (ACSErr::ErrorTrace *c, int level);
00587 
00597   void fill (ACSErr::ACSErrType et, ACSErr::ErrorCode ec, ACSErr::Severity severity, 
00598              const char* file, int line, const char* routine);
00599 
00604     ACS::Time getTime();
00605 
00606   
00607   ACSErr::ErrorTrace errorTrace, *current;
00608   unsigned int depth;
00609 
00610   static CORBA::ORB_var orb;
00611 
00612   static std::unexpected_handler  m_oldUnexpected;
00613   static std::terminate_handler  m_oldTerminate;
00614 
00615   static const ACSErr::ACSErrType ACSErrTypeOK;   // this constant is redefined here otherwise we depend on code generated from ACSErrTypeOK
00616  static const ACSErr::ErrorCode ACSErrOK; // this constant is redefined here otherwise we depend on code generated from ACSErrTypeOK
00617 
00618 };//class ACSError
00619 
00620 #endif 

Generated on Thu Jan 12 2012 23:13:50 for ACS-10.0 C++ API by  doxygen 1.7.0