00001 #ifndef _acserr_Legacy_H_
00002 #define _acserr_Legacy_H_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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
00084
00085
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
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);
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; }
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 s = ostr.str().c_str();
00413 addData (name, s);
00414 }
00415
00420 char* getDescription();
00421
00427 static char* getDescription (ACSErr::ACSErrType et, ACSErr::ErrorCode ec);
00428
00433 char* getFileName(){ return CORBA::string_dup(current->file); }
00434
00439 CORBA::ULong getLineNumber(){ return current->lineNum; }
00440
00445 char* getRoutine(){ return CORBA::string_dup (current->routine); }
00446
00451 char* getHostName(){ return CORBA::string_dup (current->host); }
00452
00457 char* getProcess(){ return CORBA::string_dup (current->process); }
00458
00463 char* getThread(){ return CORBA::string_dup (current->thread); }
00464
00469 CORBA::ULongLong getTimeStamp (){ return current->timeStamp; }
00470
00475 ACSErr::ErrorCode getErrorCode(){ return current->errorCode; }
00476
00477
00482 ACSErr::ACSErrType getErrorType(){ return current->errorType; }
00483
00487 ACSErr::Severity getSeverity() { return current->severity; }
00488
00493 unsigned int getDepth(){ return depth; }
00494
00499 void setTimeStamp (CORBA::ULongLong time){ current->timeStamp = time; }
00500
00506 void setFileName(const char* fn){ current->file = CORBA::string_dup (fn); }
00507
00513 void setLineNumber (CORBA::ULong ln){ current->lineNum = ln; }
00514
00521 void setError (ACSErr::ACSErrType ty, ACSErr::ErrorCode ec)
00522 { current->errorType=ty; current->errorCode=ec; }
00523
00529 void setSeverity(ACSErr::Severity severity) {current->severity = severity; }
00530
00535 static void hostName (const char* hn);
00536
00542 static void processName (const char *pn);
00543
00544
00549 static void setProcessName (const char *pn);
00550
00551
00552 static ACSErr::ErrorTrace createErrorTrace (const char* file, int line,
00553 ACSError &er)
00554 {
00555 ACE_UNUSED_ARG(file);
00556 ACE_UNUSED_ARG(line);
00557 return er.getErrorTrace();
00558 }
00559
00560 static ACSErr::ErrorTrace createErrorTrace (const char* file, int line,
00561 ACSErr::ACSException &pex, ACSErr::ACSErrType et,
00562 ACSErr::ErrorCode ec, const char *routine,
00563 ACSErr::Severity severity=DEFAULT_SEVERITY);
00564
00565 static ACSErr::ErrorTrace createErrorTrace (const char* file, int line,
00566 ACSErr::ACSErrType et, ACSErr::ErrorCode ec,\
00567 const char *routine,
00568 ACSErr::Severity severity=DEFAULT_SEVERITY);
00569
00570 static bool init (int argc, char *argv[]);
00571 static bool init (CORBA::ORB_ptr _orb);
00572 static bool init ();
00573 static bool isInit(){ return initialized; }
00574 static void done();
00575
00576 protected:
00577 static bool initialized;
00578
00579 static bool initLog (CORBA::ORB_ptr _orb);
00585 void log (ACSErr::ErrorTrace *c, int level);
00586
00596 void fill (ACSErr::ACSErrType et, ACSErr::ErrorCode ec, ACSErr::Severity severity,
00597 const char* file, int line, const char* routine);
00598
00603 ACS::Time getTime();
00604
00605
00606 ACSErr::ErrorTrace errorTrace, *current;
00607 unsigned int depth;
00608
00609 static CORBA::ORB_var orb;
00610
00611 static std::unexpected_handler m_oldUnexpected;
00612 static std::terminate_handler m_oldTerminate;
00613
00614 static const ACSErr::ACSErrType ACSErrTypeOK;
00615 static const ACSErr::ErrorCode ACSErrOK;
00616
00617 };
00618
00619 #endif