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 std::string ts=ostr.str();
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
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; }
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;
00616 static const ACSErr::ErrorCode ACSErrOK;
00617
00618 };
00619
00620 #endif