00001 #ifndef _ACSERR__H_
00002 #define _ACSERR__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
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #ifndef __cplusplus
00045 #error This is a C++ include file and cannot be used from plain C
00046 #endif
00047
00048
00049 #include "acserrLegacy.h"
00050 #include <sstream>
00051
00052 namespace ACSErr
00053 {
00054
00060 class ErrorTraceHelper
00061 {
00062 protected:
00063 friend class CompletionImpl;
00064 friend class ACSLogImpl;
00065 friend class ACSError;
00066
00067 ErrorTraceHelper(ACSErr::ErrorTrace &et);
00068
00069
00070 ErrorTraceHelper(ACSErr::ErrorTrace &et, int depth);
00071
00072
00073 ErrorTraceHelper();
00074
00075
00076 ErrorTraceHelper (ACSErr::ACSErrType et, ACSErr::ErrorCode ec,
00077 const char* file, int line, const char* routine, const char* sd,
00078 ACSErr::Severity severity,
00079 ACSErr::ErrorTrace &errortrace);
00080
00081
00082 ErrorTraceHelper (const ACSErr::ErrorTrace &pet,
00083 ACSErr::ACSErrType et, ACSErr::ErrorCode ec,
00084 const char* file, int line, const char* routine, const char* sd,
00085 ACSErr::Severity severity,
00086 ACSErr::ErrorTrace &errortrace);
00087
00091 ErrorTraceHelper& operator=(ACSErr::ErrorTrace& eth);
00092
00093 public:
00094
00095
00112 void log(ACE_Log_Priority priorty=LM_ERROR);
00113
00117 std::string toString();
00118
00125 void addData (const char* name, const char* value);
00126
00131 void addData (const char* name, char* value)
00132 {
00133 addData (name, (const char*)value);
00134 }
00135
00142 template<typename T>
00143 void addData (const char* name, T value)
00144 {
00145 const char *s;
00146 std::ostringstream ostr;
00147 ostr << value << std::ends;
00148 std::string ts=ostr.str();
00149 s = ts.c_str();
00150 addData (name, s);
00151 }
00152
00153
00161 void setMemberValue (const char* name, const char* value);
00162
00171 void setMemberValue (const char* name, ACE_CString &value);
00172
00179 template<typename T>
00180 void setMemberValue (const char* name, T value)
00181 {
00182 const char *s;
00183 if (name==NULL) return;
00184
00185 std::ostringstream ostr;
00186 ostr << value << std::ends;
00187 std::string ts=ostr.str();
00188 s = ts.c_str();
00189 setMemberValue (name, s);
00190 }
00191
00197 ACE_CString getData (const char* name);
00198
00206 void getMemberValue(const char* name, char*& value)
00207 {
00208 value = CORBA::string_dup(getData(name).c_str());
00209 }
00210
00218 template<typename T>
00219 void getMemberValue (const char* name, T &value)
00220 {
00221 std::istringstream istr(getData(name).c_str());
00222 istr >> value;
00223 }
00224
00232 template<typename T>
00233 T getMemberValue (const char* name);
00234
00241 char* getDescription();
00242
00247 char* getShortDescription();
00248
00253 char* getFileName(){ return CORBA::string_dup(m_current->file); }
00254
00259 CORBA::ULong getLineNumber(){ return m_current->lineNum; }
00260
00265 char* getRoutine(){ return CORBA::string_dup (m_current->routine); }
00266
00271 char* getHostName(){ return CORBA::string_dup (m_current->host); }
00272
00277 char* getProcessName(){ return CORBA::string_dup (m_current->process); }
00278
00283 char* getThread(){ return CORBA::string_dup (m_current->thread); }
00284
00289 char* getSourceObject(){ return CORBA::string_dup (m_current->sourceObject); }
00294 CORBA::ULongLong getTimeStamp (){ return m_current->timeStamp; }
00295
00300 ACSErr::ErrorCode getErrorCode(){ return m_current->errorCode; }
00301
00306 ACSErr::ACSErrType getErrorType(){ return m_current->errorType; }
00307
00311 ACSErr::Severity getSeverity() { return m_current->severity; }
00312
00317 unsigned int getDepth(){ return m_depth; }
00318
00323 void setTimeStamp (CORBA::ULongLong time){ m_current->timeStamp = time; }
00324
00330 void setSourceObject(const char* so){ m_current->sourceObject = CORBA::string_dup (so); }
00331
00337 void setFileName(const char* fn){ m_current->file = CORBA::string_dup (fn); }
00338
00344 void setLineNumber (CORBA::ULong ln){ m_current->lineNum = ln; }
00345
00352 void setError (ACSErr::ACSErrType ty, ACSErr::ErrorCode ec)
00353 { m_current->errorType=ty; m_current->errorCode=ec; }
00354
00360 void setSeverity(ACSErr::Severity severity) {m_current->severity = severity; }
00361
00366 static void setHostName (const char* hn);
00367
00372 static void setProcessName (const char *pn);
00373
00379 ACSErr::ErrorTrace *getNext();
00380
00385 bool last() { return (m_depth==0 || m_current->previousError.length()==0); }
00386
00391 ACSErr::ErrorTrace *top(){ m_current = &m_errorTraceRef; return m_current;}
00392
00398 ACSErr::ErrorTrace& getErrorTrace(){ return *m_current; }
00399
00400 static ACS::Time getTime();
00401
00407 ErrorTraceHelper* getErrorTraceHelper() { return this; }
00408
00409 protected:
00410
00411 void fill (ACSErr::ACSErrType et, ACSErr::ErrorCode ec, ACSErr::Severity severity,
00412 const char* file, int line, const char* routine, const char* sd);
00413
00422 void log (ACSErr::ErrorTrace * c,
00423 int level, char *stackId,
00424 ACE_Log_Priority priorty=LM_ERROR);
00425
00426 void toString (ACSErr::ErrorTrace * c, int level, std::ostringstream& oss);
00427
00428 ACSErr::ErrorTrace& m_errorTraceRef;
00429 ACSErr::ErrorTrace *m_current;
00430 unsigned int m_depth;
00431
00432 static char m_hostName[64];
00433 static char m_processName[64];
00434 static const unsigned int m_maxDepth;
00435 };
00436
00437
00442 class CompletionInit : public ACSErr::Completion
00443 {
00444 public:
00445 CompletionInit(const ACSErr::Completion &c);
00446
00447 CompletionInit(ACSErr::CompletionType t, ACSErr::CompletionCode c, bool initTrace=true);
00448
00453 ACSErr::CompletionCode getCode(){ return code; }
00454
00459 ACSErr::CompletionType getType(){ return type; }
00460
00465 CORBA::ULongLong getTimeStamp (){ return timeStamp; }
00466 };
00467
00468
00469
00470
00471
00476 class CompletionImpl : public CompletionInit
00477 {
00478 public:
00479
00480 CompletionImpl();
00481
00482 CompletionImpl (ACSErr::ACSErrType t, ACSErr::ErrorCode c) :
00483 CompletionInit(t, c, false),
00484 m_errorTraceHelper(previousError[0], previousError.length())
00485 {
00486 }
00487
00488 CompletionImpl (ACSErr::ACSErrType t, ACSErr::ErrorCode c,
00489 const char* file, int line, const char* routine, const char* sd,
00490 ACSErr::Severity severity) :
00491 CompletionInit(t, c),
00492 m_errorTraceHelper(t, c, file, line, routine, sd, severity, previousError[0])
00493 {}
00494
00495
00496 CompletionImpl (const ACSErr::Completion &pc, ACSErr::ACSErrType t, ACSErr::ErrorCode c,
00497 const char* file, int line, const char* routine, const char* sd,
00498 ACSErr::Severity severity) :
00499 CompletionInit(t, c),
00500 m_errorTraceHelper(pc.previousError[0], t, c, file, line, routine, sd, severity, previousError[0])
00501 {}
00502
00503 CompletionImpl (ACSErr::Completion *pc, ACSErr::ACSErrType t, ACSErr::ErrorCode c,
00504 const char* file, int line, const char* routine, const char* sd,
00505 ACSErr::Severity severity) :
00506 CompletionInit(t, c),
00507 m_errorTraceHelper(pc->previousError[0], t, c, file, line, routine, sd, severity, previousError[0])
00508 { delete pc; }
00509
00510
00511 CompletionImpl (CompletionImpl *pc, ACSErr::ACSErrType t, ACSErr::ErrorCode c,
00512 const char* file, int line, const char* routine, const char* sd,
00513 ACSErr::Severity severity) :
00514 CompletionInit(t, c),
00515 m_errorTraceHelper(pc->previousError[0], t, c, file, line, routine, sd, severity, previousError[0])
00516 { delete pc; }
00517
00518
00519 CompletionImpl (const ACSErr::ErrorTrace &et, ACSErr::ACSErrType t, ACSErr::ErrorCode c,
00520 const char* file, int line, const char* routine, const char* sd,
00521 ACSErr::Severity severity) :
00522 CompletionInit(t, c),
00523 m_errorTraceHelper(et, t, c, file, line, routine, sd, severity, previousError[0])
00524 {}
00525
00526
00532 CompletionImpl(ACSErr::Completion* c, bool del=true);
00533
00534 CompletionImpl (const ACSErr::Completion &c);
00535
00539 CompletionImpl (const CompletionImpl &c);
00540
00544 virtual ~CompletionImpl(){}
00545
00551 ACSErr::Completion* returnCompletion (bool deletion=true)
00552 {
00553 ACSErr::Completion *tmp = new ACSErr::Completion(*this);
00554 if (deletion) delete this;
00555 return tmp;
00556 }
00557
00563 bool isErrorFree(){ return (previousError.length() == 0); }
00564
00569 ErrorTraceHelper* getErrorTraceHelper(){ return (ErrorTraceHelper*)( (previousError.length() > 0) ? &m_errorTraceHelper : NULL); }
00570
00576 void log(ACE_Log_Priority priorty=LM_ERROR);
00577
00578 template<typename T>
00579 void addData (const char* name, T value)
00580 {
00581 if (!isErrorFree())
00582 {
00583 m_errorTraceHelper.addData(name, value);
00584 }
00585 }
00586
00587 CompletionImpl& operator=(CompletionImpl&);
00588
00593 CompletionImpl& operator=(Completion* c);
00594
00595 protected:
00596 ErrorTraceHelper m_errorTraceHelper;
00597 };
00598
00599
00600
00601
00602
00603
00604 template<>
00605 char * ErrorTraceHelper::getMemberValue<char*> (const char* name);
00606
00607 template<>
00608 ACE_CString ErrorTraceHelper::getMemberValue<ACE_CString> (const char* name);
00609
00610 template<typename T>
00611 T ErrorTraceHelper::getMemberValue (const char* name)
00612 {
00613 T value;
00614 std::istringstream istr(getData(name).c_str());
00615 istr >> value;
00616 return value;
00617 }
00618
00619 }
00620
00621
00622
00623 typedef ACSErr::CompletionInit CompletionInit;
00624 typedef ACSErr::CompletionImpl CompletionImpl;
00625 typedef ACSErr::ErrorTraceHelper ErrorTraceHelper;
00626
00627 #endif