![]() |
|
|
Generated: 18 Jul 2008 |
00001 // $Id: Guards.cpp,v 1.3 2008/04/03 18:28:49 marcocle Exp $ 00002 // ============================================================================ 00003 // CVS tag $Name: v25r2 $, version $Revision: 1.3 $ 00004 // ============================================================================ 00005 // $Log: Guards.cpp,v $ 00006 // Revision 1.3 2008/04/03 18:28:49 marcocle 00007 // Fixed Windows compilation problem. 00008 // 00009 // Revision 1.2 2008/04/03 14:40:19 marcocle 00010 // Marco Clemencic 00011 // - Patch #1725. New IAuditor interface. 00012 // - The Auditor member functions are now only 8, for all the combinations of: 00013 // * before or after 00014 // * standard event or custom event 00015 // * INamedInterface* or string 00016 // - All the after methods accept a StatusCode (if not specified, a SUCCESS with 00017 // the checked flag set is used). 00018 // - The obsolete member functions are kept for backward compatibility. 00019 // - The default implementations of "before" and "after" are using the obsolete 00020 // methods to make legacy Auditors to work. 00021 // - IAuditorSvc is now an extension of IAuditor. 00022 // - AuditorGuard has been adapted to the new interface and the audit with a 00023 // status code check is simpler. 00024 // - The standard event types defined in the enum IAuditor::StandardEventType 00025 // can be printed and converted to strings with operator<<. 00026 // 00027 // Revision 1.1 2007/07/24 17:59:57 marcocle 00028 // Patch #1246 -Vanya Belyaev 00029 // Introduced 2 new classes: 00030 // * Gaudi::Guards::ExceptionGuard 00031 // executes a functor in a "standard" try-catch block. 00032 // * Gaudi::Guards::AuditorGuard 00033 // executes a function of an object when the instance is created and 00034 // a second one when destroied, allowing automatic "clean-up" (in case 00035 // of early exit). 00036 // See GaudiKernel/Gaurds.h (doxygen) for more details. 00037 // 00038 // ============================================================================ 00039 // Include files 00040 // ============================================================================ 00041 // STD & STL 00042 // ============================================================================ 00043 #include <exception> 00044 // ============================================================================ 00045 // GaudiKernel 00046 // ============================================================================ 00047 #include "GaudiKernel/Guards.h" 00048 #include "GaudiKernel/System.h" 00049 #include "GaudiKernel/MsgStream.h" 00050 #include "GaudiKernel/GaudiException.h" 00051 // ============================================================================ 00058 // ============================================================================ 00059 // Local handle (print) of GaudiException 00060 // ============================================================================ 00061 void Gaudi::Guards::ExceptionGuard::handle 00062 ( const GaudiException& exc , MsgStream& log ) 00063 { 00064 // the general printout 00065 log << MSG::FATAL 00066 << System::typeinfoName( typeid ( exc ) ) 00067 << "('" << exc.tag() << "') is caught!" << endreq ; 00068 // print the detailes about the exception: 00069 log << MSG::ERROR << exc << endreq ; 00070 // get the status code form the exception: 00071 m_sc = exc.code() ; 00072 } 00073 // ============================================================================ 00074 // Local handle (print) of std::exception 00075 // ============================================================================ 00076 void Gaudi::Guards::ExceptionGuard::handle 00077 ( const std::exception& exc , MsgStream& log ) 00078 { 00079 // the general printout 00080 log << MSG::FATAL 00081 << System::typeinfoName( typeid ( exc ) ) << " is caught!" << endreq ; 00082 // print the detailes abotu the exception: 00083 log << MSG::ERROR << exc.what() << endreq ; 00084 } 00085 // ============================================================================ 00086 // Local handle (print) of unknown exception 00087 // ============================================================================ 00088 void Gaudi::Guards::ExceptionGuard::handle 00089 ( MsgStream& log ) 00090 { 00091 // the general printout 00092 log << MSG::FATAL << "UNKNOWN exception is caught!" << endreq ; 00093 } 00094 // ============================================================================ 00095 // dectructor 00096 // ============================================================================ 00097 Gaudi::Guards::ExceptionGuard::~ExceptionGuard() { m_sc.ignore() ; } 00098 // ============================================================================ 00099 // constructor with standard post-action 00100 // ============================================================================ 00101 Gaudi::Guards::AuditorGuard::AuditorGuard ( INamedInterface* obj , 00102 IAuditor* svc , 00103 IAuditor::StandardEventType evt ): 00104 m_obj(obj), 00105 m_objName(), 00106 m_svc(svc), 00107 m_evt(evt), 00108 m_cevt(), 00109 m_sc(0), 00110 m_customEvtType(false) 00111 { 00112 i_before(); 00113 } 00114 Gaudi::Guards::AuditorGuard::AuditorGuard ( INamedInterface* obj , 00115 IAuditor* svc , 00116 IAuditor::CustomEventTypeRef evt ): 00117 m_obj(obj), 00118 m_objName(), 00119 m_svc(svc), 00120 m_evt(IAuditor::Initialize), // Windows needs an explicit value 00121 m_cevt(evt), 00122 m_sc(0), 00123 m_customEvtType(true) 00124 { 00125 i_before(); 00126 } 00127 Gaudi::Guards::AuditorGuard::AuditorGuard ( INamedInterface* obj , 00128 IAuditor* svc , 00129 IAuditor::StandardEventType evt , 00130 const StatusCode &sc ): 00131 m_obj(obj), 00132 m_objName(), 00133 m_svc(svc), 00134 m_evt(evt), 00135 m_cevt(), 00136 m_sc(&sc), 00137 m_customEvtType(false) 00138 { 00139 i_before(); 00140 } 00141 Gaudi::Guards::AuditorGuard::AuditorGuard ( INamedInterface* obj , 00142 IAuditor* svc , 00143 IAuditor::CustomEventTypeRef evt , 00144 const StatusCode &sc ): 00145 m_obj(obj), 00146 m_objName(), 00147 m_svc(svc), 00148 m_evt(IAuditor::Initialize), // Windows needs an explicit value 00149 m_cevt(evt), 00150 m_sc(&sc), 00151 m_customEvtType(true) 00152 { 00153 i_before(); 00154 } 00155 Gaudi::Guards::AuditorGuard::AuditorGuard ( const std::string &name , 00156 IAuditor* svc , 00157 IAuditor::StandardEventType evt ): 00158 m_obj(0), 00159 m_objName(name), 00160 m_svc(svc), 00161 m_evt(evt), 00162 m_cevt(), 00163 m_sc(0), 00164 m_customEvtType(false) 00165 { 00166 i_before(); 00167 } 00168 Gaudi::Guards::AuditorGuard::AuditorGuard ( const std::string &name , 00169 IAuditor* svc , 00170 IAuditor::CustomEventTypeRef evt ): 00171 m_obj(0), 00172 m_objName(name), 00173 m_svc(svc), 00174 m_evt(IAuditor::Initialize), // Windows needs an explicit value 00175 m_cevt(evt), 00176 m_sc(0), 00177 m_customEvtType(true) 00178 { 00179 i_before(); 00180 } 00181 Gaudi::Guards::AuditorGuard::AuditorGuard ( const std::string &name , 00182 IAuditor* svc , 00183 IAuditor::StandardEventType evt , 00184 const StatusCode &sc ): 00185 m_obj(0), 00186 m_objName(name), 00187 m_svc(svc), 00188 m_evt(evt), 00189 m_cevt(), 00190 m_sc(&sc), 00191 m_customEvtType(false) 00192 { 00193 i_before(); 00194 } 00195 Gaudi::Guards::AuditorGuard::AuditorGuard ( const std::string &name , 00196 IAuditor* svc , 00197 IAuditor::CustomEventTypeRef evt , 00198 const StatusCode &sc ): 00199 m_obj(0), 00200 m_objName(name), 00201 m_svc(svc), 00202 m_evt(IAuditor::Initialize), // Windows needs an explicit value 00203 m_cevt(evt), 00204 m_sc(&sc), 00205 m_customEvtType(true) 00206 { 00207 i_before(); 00208 } 00209 // ============================================================================ 00210 // dectructor 00211 // ============================================================================ 00212 Gaudi::Guards::AuditorGuard::~AuditorGuard() 00213 { 00214 i_after(); 00215 } 00216 // ============================================================================ 00218 // ============================================================================