Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

acserr.h

Go to the documentation of this file.
00001 #ifndef _ACSERR__H_ 00002 #define _ACSERR__H_ 00003 /******************************************************************************* 00004 * ALMA - Atacama Large Millimiter Array 00005 * (c) European Southern Observatory, 2002 00006 * Copyright by ESO (in the framework of the ALMA collaboration) 00007 * and Cosylab 2002, All rights reserved 00008 * 00009 * This library is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU Lesser General Public 00011 * License as published by the Free Software Foundation; either 00012 * version 2.1 of the License, or (at your option) any later version. 00013 * 00014 * This library is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 * Lesser General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU Lesser General Public 00020 * License along with this library; if not, write to the Free Software 00021 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 * 00023 * "@(#) $Id: acserr.h,v 1.80 2008/06/03 09:08:12 bjeram Exp $" 00024 * 00025 * who when what 00026 * -------- -------- ---------------------------------------------- 00027 * almamgr 2004-03-02 added last() to ErrorTraceHelper 00028 * almamgr 2004-03-02 added isErrorFree, log and getErrorTraceHelper to CompletionImpl 00029 * bjeram 2003-07-07 added std:: prefix (gcc 3.2.x) 00030 * bjeram 2003-03-06 added strstream #include 00031 1* bjeram 2003-03-06 added ACSErr prefix to types defined in the idl files 00032 * bjeram 2002-06-05 added setTimeStamp 00033 * bjeram 2002-06-05 added ACSError (const char* file, int line, ACSError &err, ACSErrType et, ACSErr::ErrorCode ec, const char *routine, ACSErr::Severity severity); 00034 * bjeram 2002-06-04 moved getDescription(type, code) to public and made it static 00035 * bjeram 2002-06-04 fixed ML in addData<T> 00036 * bjeram 2002-02-13 added ACSError() and ACS_ERROR() for creating no-error object w/o runtime and source info 00037 * bjeram 2001-10-18 overloaded ACS_EXCEPTION and (RE)THROW_ACS_EXCEPTIONS(_EX) macros 00038 * bjeram 2001-10-18 added RETHROW_ACS_EXCEPTION_EX 00039 * bjeram 2001-10-18 added THROW_ACS_EXCEPTION_EX 00040 * bjeram 2001-10-18 overloaded ACS_ERROR macro 00041 * almamgr 20/06/01 created 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 // forward declaration 00053 class ACSLogImpl; 00054 00055 namespace ACSErr 00056 { 00057 00063 class ErrorTraceHelper 00064 { 00065 protected: 00066 friend class CompletionImpl; 00067 friend class ::ACSLogImpl; 00068 friend class ::ACSError; 00069 00070 ErrorTraceHelper(ACSErr::ErrorTrace &et); 00071 00072 // for OK cases and wrapping completion 00073 ErrorTraceHelper(ACSErr::ErrorTrace &et, int depth); 00074 00075 // default constructor 00076 ErrorTraceHelper(); 00077 00078 // create new error trace 00079 ErrorTraceHelper (ACSErr::ACSErrType et, ACSErr::ErrorCode ec, 00080 const char* file, int line, const char* routine, const char* sd, 00081 ACSErr::Severity severity, 00082 ACSErr::ErrorTrace &errortrace); 00083 00084 // adding previos error trace 00085 ErrorTraceHelper (const ACSErr::ErrorTrace &pet, 00086 ACSErr::ACSErrType et, ACSErr::ErrorCode ec, 00087 const char* file, int line, const char* routine, const char* sd, 00088 ACSErr::Severity severity, 00089 ACSErr::ErrorTrace &errortrace); 00090 00094 ErrorTraceHelper& operator=(ACSErr::ErrorTrace& eth); 00095 00096 public: 00097 00098 00115 void log(ACE_Log_Priority priorty=LM_ERROR); 00116 00120 std::string toString(); 00121 00128 void addData (const char* name, const char* value); 00129 00134 void addData (const char* name, char* value) 00135 { 00136 addData (name, (const char*)value); 00137 }//addData 00138 00146 template<typename T> 00147 void addData (const char* name, T value) 00148 { 00149 const char *s; 00150 std::ostringstream ostr; 00151 ostr << value << std::ends; 00152 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 00153 s = ts.c_str(); 00154 addData (name, s); 00155 }//addData 00156 00163 void setMemberValue (const char* name, const char* value); 00164 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(); // we have to make a temporary string otherwise there is problem with memory 00188 s = ts.c_str(); 00189 setMemberValue (name, s); 00190 }//setMemberValue 00191 00197 ACE_CString getData (const char* name); 00198 00205 void getMemberValue(const char* name, char*& value) 00206 { 00207 value = CORBA::string_dup(getData(name).c_str()); 00208 } 00209 00217 template<typename T> 00218 void getMemberValue (const char* name, T &value) 00219 { 00220 std::istringstream istr(getData(name).c_str()); 00221 istr >> value; 00222 }//getMemberValue 00223 00230 template<typename T> 00231 T getMemberValue (const char* name); 00232 00239 char* getDescription(); 00240 00245 char* getShortDescription(); 00246 00251 char* getFileName(){ return CORBA::string_dup(m_current->file); } 00252 00257 CORBA::ULong getLineNumber(){ return m_current->lineNum; } 00258 00263 char* getRoutine(){ return CORBA::string_dup (m_current->routine); } 00264 00269 char* getHostName(){ return CORBA::string_dup (m_current->host); } 00270 00275 char* getProcessName(){ return CORBA::string_dup (m_current->process); } 00276 00281 char* getThread(){ return CORBA::string_dup (m_current->thread); } 00282 00287 char* getSourceObject(){ return CORBA::string_dup (m_current->sourceObject); } 00292 CORBA::ULongLong getTimeStamp (){ return m_current->timeStamp; } 00293 00298 ACSErr::ErrorCode getErrorCode(){ return m_current->errorCode; } 00299 00304 ACSErr::ACSErrType getErrorType(){ return m_current->errorType; } 00305 00309 ACSErr::Severity getSeverity() { return m_current->severity; } 00310 00315 unsigned int getDepth(){ return m_depth; } 00316 00321 void setTimeStamp (CORBA::ULongLong time){ m_current->timeStamp = time; } 00322 00328 void setSourceObject(const char* so){ m_current->sourceObject = CORBA::string_dup (so); } 00329 00335 void setFileName(const char* fn){ m_current->file = CORBA::string_dup (fn); } 00336 00342 void setLineNumber (CORBA::ULong ln){ m_current->lineNum = ln; }//? should we delete previos one 00343 00350 void setError (ACSErr::ACSErrType ty, ACSErr::ErrorCode ec) 00351 { m_current->errorType=ty; m_current->errorCode=ec; } 00352 00358 void setSeverity(ACSErr::Severity severity) {m_current->severity = severity; } 00359 00364 static void setHostName (const char* hn); 00365 00370 static void setProcessName (const char *pn); 00371 00377 ACSErr::ErrorTrace *getNext(); 00378 00383 bool last() { return (m_depth==0 || m_current->previousError.length()==0); } 00384 00389 ACSErr::ErrorTrace *top(){ m_current = m_errorTracePtr; return m_current;} 00390 00396 ACSErr::ErrorTrace& getErrorTrace(){ return *m_current; } // should check if stack is empty 00397 00398 static ACS::Time getTime(); 00399 00405 ErrorTraceHelper* getErrorTraceHelper() { return this; } 00406 00407 protected: 00408 00409 void fill (ACSErr::ACSErrType et, ACSErr::ErrorCode ec, ACSErr::Severity severity, 00410 const char* file, int line, const char* routine, const char* sd); 00411 00420 void log (ACSErr::ErrorTrace * c, 00421 int level, char *stackId, 00422 ACE_Log_Priority priorty=LM_ERROR); 00423 00424 void toString (ACSErr::ErrorTrace * c, int level, std::ostringstream& oss); 00425 00426 ACSErr::ErrorTrace *m_errorTracePtr; 00427 //& m_errorTraceRef; 00428 ACSErr::ErrorTrace *m_current; 00429 unsigned int m_depth; 00430 00431 static char m_hostName[64]; 00432 static char m_processName[64]; 00433 static const unsigned int m_maxDepth; 00434 }; 00435 00436 /*******************************************************************************************/ 00441 class CompletionInit : public ACSErr::Completion 00442 { 00443 public: 00444 CompletionInit(const ACSErr::Completion &c); 00445 00446 CompletionInit(ACSErr::CompletionType t, ACSErr::CompletionCode c, bool initTrace=true); 00447 00452 ACSErr::CompletionCode getCode(){ return code; } 00453 00458 ACSErr::CompletionType getType(){ return type; } 00459 00464 CORBA::ULongLong getTimeStamp (){ return timeStamp; } 00465 }; 00466 00467 00468 00469 00470 /**************************************************************************************/ 00475 class CompletionImpl : public CompletionInit 00476 { 00477 public: 00478 // default constructor 00479 CompletionImpl(); 00480 00481 CompletionImpl (ACSErr::ACSErrType t, ACSErr::ErrorCode c) : 00482 CompletionInit(t, c, false), 00483 m_errorTraceHelper(previousError[0], previousError.length()) 00484 { 00485 } 00486 00487 CompletionImpl (ACSErr::ACSErrType t, ACSErr::ErrorCode c, 00488 const char* file, int line, const char* routine, const char* sd, 00489 ACSErr::Severity severity) : 00490 CompletionInit(t, c), 00491 m_errorTraceHelper(t, c, file, line, routine, sd, severity, previousError[0]) 00492 {} 00493 00494 // adding previous (remote or local) with reference 00495 CompletionImpl (const ACSErr::Completion &pc, ACSErr::ACSErrType t, ACSErr::ErrorCode c, 00496 const char* file, int line, const char* routine, const char* sd, 00497 ACSErr::Severity severity) : 00498 CompletionInit(t, c), 00499 m_errorTraceHelper(pc.previousError[0], t, c, file, line, routine, sd, severity, previousError[0]) 00500 {} 00501 // adding previous remote completion as pointer 00502 CompletionImpl (ACSErr::Completion *pc, ACSErr::ACSErrType t, ACSErr::ErrorCode c, 00503 const char* file, int line, const char* routine, const char* sd, 00504 ACSErr::Severity severity) : 00505 CompletionInit(t, c), 00506 m_errorTraceHelper(pc->previousError[0], t, c, file, line, routine, sd, severity, previousError[0]) 00507 { delete pc; } 00508 00509 // adding previous completion as pointer 00510 CompletionImpl (CompletionImpl *pc, ACSErr::ACSErrType t, ACSErr::ErrorCode c, 00511 const char* file, int line, const char* routine, const char* sd, 00512 ACSErr::Severity severity) : 00513 CompletionInit(t, c), 00514 m_errorTraceHelper(pc->previousError[0], t, c, file, line, routine, sd, severity, previousError[0]) 00515 { delete pc; } 00516 00517 // adding error trace 00518 CompletionImpl (const ACSErr::ErrorTrace &et, ACSErr::ACSErrType t, ACSErr::ErrorCode c, 00519 const char* file, int line, const char* routine, const char* sd, 00520 ACSErr::Severity severity) : 00521 CompletionInit(t, c), 00522 m_errorTraceHelper(et, t, c, file, line, routine, sd, severity, previousError[0]) 00523 {} 00524 00525 //wrapping remote (CORBA) Completion 00531 CompletionImpl(ACSErr::Completion* c, bool del=true); 00532 00538 CompletionImpl(ACSErr::Completion_var& c); 00539 00540 CompletionImpl (const ACSErr::Completion &c); 00541 00545 CompletionImpl (const CompletionImpl &c); 00546 00550 virtual ~CompletionImpl(){} 00551 00561 ACSErr::Completion* returnCompletion (bool deletion=true) 00562 { 00563 ACSErr::Completion *tmp = new ACSErr::Completion(*this); 00564 if (deletion) delete this; 00565 return tmp; 00566 }//returnCompletion 00567 00578 ACSErr::Completion* outCompletion(bool del=false) { return this->returnCompletion(del); } 00579 00585 bool isErrorFree(){ return (previousError.length() == 0); } 00586 00591 ErrorTraceHelper* getErrorTraceHelper(){ return (ErrorTraceHelper*)( (previousError.length() > 0) ? &m_errorTraceHelper : NULL); } 00592 00598 void log(ACE_Log_Priority priorty=LM_ERROR); 00599 00600 template<typename T> 00601 void addData (const char* name, T value) 00602 { 00603 if (!isErrorFree()) 00604 { 00605 m_errorTraceHelper.addData(name, value); 00606 } 00607 } 00608 00609 00610 CompletionImpl& operator=(CompletionImpl&); 00611 00617 CompletionImpl& operator=(Completion* c); 00618 00624 CompletionImpl& operator=(Completion_var& c); 00625 00626 00627 00628 protected: 00629 ErrorTraceHelper m_errorTraceHelper; 00630 };//CompletionImpl 00631 00632 /*************************************************************************************/ 00633 //template implementation 00634 // 00635 00636 // specialization for strings 00637 template<> 00638 char * ErrorTraceHelper::getMemberValue<char*> (const char* name); 00639 00640 template<> 00641 ACE_CString ErrorTraceHelper::getMemberValue<ACE_CString> (const char* name); 00642 00643 template<typename T> 00644 T ErrorTraceHelper::getMemberValue (const char* name) 00645 { 00646 T value; 00647 std::istringstream istr(getData(name).c_str()); 00648 istr >> value; 00649 return value; 00650 }//getMemberValue 00651 00652 } 00653 00654 // these two lines are just for backward compatibility and should be removed 00655 // ... with next release 00656 typedef ACSErr::CompletionInit CompletionInit; 00657 typedef ACSErr::CompletionImpl CompletionImpl; 00658 typedef ACSErr::ErrorTraceHelper ErrorTraceHelper; 00659 00660 #endif

Generated on Thu Apr 30 02:30:48 2009 for ACS C++ API by doxygen 1.3.8