31 static const std::string s_unknown =
"<unknown>" ;
36 return iNamed.isValid() ? iNamed->name() : s_unknown ;
41 #define ON_DEBUG if (UNLIKELY(outputLevel() <= MSG::DEBUG))
42 #define ON_VERBOSE if (UNLIKELY(outputLevel() <= MSG::VERBOSE))
44 #define DEBMSG ON_DEBUG debug()
45 #define VERMSG ON_VERBOSE verbose()
52 , m_currentIncidentType(0)
54 , m_timerLock ( false )
107 const std::string&
type ,
108 long prio,
bool rethrow,
bool singleShot)
111 boost::recursive_mutex::scoped_lock
lock(m_listenerMapMutex);
114 if( type ==
"" ) ltype =
"ALL";
118 if( itMap == m_listenerMap.end() ) {
121 std::pair<ListenerMap::iterator, bool> p;
123 if( p.second ) itMap = p.first;
127 ListenerList::iterator itlist;
128 for( itlist = llist->begin(); itlist != llist->end(); itlist++ ) {
129 if( (*itlist).priority < prio ) {
135 DEBMSG <<
"Adding [" << type <<
"] listener '" << getListenerName(lis)
136 <<
"' with priority " << prio <<
endmsg;
138 llist->insert(itlist,
Listener(lis, prio, rethrow, singleShot));
143 const std::string& type )
146 boost::recursive_mutex::scoped_lock
lock(m_listenerMapMutex);
151 for ( itmap = m_listenerMap.begin(); itmap != m_listenerMap.end();)
158 removeListener( lis, (*itmap_old).first );
164 if( itmap == m_listenerMap.end() ) {
170 ListenerList::iterator itlist;
171 bool justScheduleForRemoval = ( 0!= m_currentIncidentType )
172 && (type == *m_currentIncidentType);
177 for( itlist = llist->begin(); itlist != llist->end(); ) {
178 if( (*itlist).iListener == lis || lis == 0) {
179 if (justScheduleForRemoval) {
180 (itlist++)->singleShot =
true;
183 DEBMSG <<
"Removing [" << type <<
"] listener '"
184 << getListenerName(lis) <<
"'" <<
endmsg;
185 itlist = llist->erase(itlist);
192 if( llist->size() == 0) {
194 m_listenerMap.erase(itmap);
203 struct listenerToBeRemoved{
212 const std::string& listenerType )
215 boost::recursive_mutex::scoped_lock
lock(m_listenerMapMutex);
229 if ( m_listenerMap.end() == itmap )
return;
233 m_currentIncidentType = &(incident.
type());
236 ListenerList::iterator itlist;
237 bool weHaveToCleanUp =
false;
240 for( itlist = llist->begin(); itlist != llist->end(); itlist++ )
243 VERMSG <<
"Calling '" << getListenerName((*itlist).iListener)
244 <<
"' for incident [" << incident.
type() <<
"]" <<
endmsg;
248 (*itlist).iListener->handle(incident);
251 error() <<
"Exception with tag=" << exc.
tag() <<
" is caught"
252 " handling incident" << m_currentIncidentType <<
endmsg;
254 if ( (*itlist).rethrow ) {
throw (exc); }
256 catch(
const std::exception& exc ) {
257 error() <<
"Standard std::exception is caught"
258 " handling incident" << m_currentIncidentType <<
endmsg;
259 error() << exc.what() <<
endmsg;
260 if ( (*itlist).rethrow ) {
throw (exc); }
263 error() <<
"UNKNOWN Exception is caught"
264 " handling incident" << m_currentIncidentType <<
endmsg;
265 if ( (*itlist).rethrow ) {
throw; }
268 weHaveToCleanUp |= itlist->singleShot;
270 if (weHaveToCleanUp) {
272 llist->remove_if( listenerToBeRemoved() );
274 if( llist->size() == 0) {
276 m_listenerMap.erase(itmap);
280 m_currentIncidentType = 0;
291 if ( incident.
type() !=
"ALL" ){
300 const std::string& type)
const
306 if (type ==
"") { ltype =
"ALL"; }
else { ltype =
type; }
313 ListenerList::const_iterator itlist;
314 for (itlist = itr->second->begin(); itlist != itr->second->end(); ++itlist) {
315 lis.push_back(itlist->iListener);
boost::recursive_mutex m_listenerMapMutex
Mutex to synchronize access to m_listenerMap.
Small smart pointer class with automatic reference counting for IInterface.
ChronoEntity m_timer
timer & it's lock
Define general base for Gaudi exception.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
const std::string & type() const
Access to the incident type.
virtual StatusCode initialize()
Initialization (from CONFIGURED to INITIALIZED).
std::list< Listener > ListenerList
const std::string FailInputFile
could not open or read from this file
bool isFailure() const
Test for a status code of FAILURE.
IncidentSvc(const std::string &name, ISvcLocator *svc)
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
#define DECLARE_COMPONENT(type)
virtual void getListeners(std::vector< IIncidentListener * > &lis, const std::string &type="") const
The interface implemented by any class wanting to listen to Incidents.
This class is used for returning status codes from appropriate routines.
std::pair< const Gaudi::StringKey, ListenerList * > value_type
iterator find(const key_type &key)
virtual const std::string & tag() const
name tag for the exception, or exception type
const std::string * m_currentIncidentType
Incident being fired.
map_type::const_iterator const_iterator
StatusCode setAppReturnCode(SmartIF< IProperty > &appmgr, int value, bool force=false)
Set the application return code.
StatusCode setProperties()
Method for setting declared properties to the values specified for the job.
virtual void removeListener(IIncidentListener *lis, const std::string &type="")
Remove listener.
std::string outputUserTime() const
print the chrono ;
map_type::iterator iterator
virtual StatusCode initialize()
Initialization (from CONFIGURED to INITIALIZED).
Helper object, useful for measurement of CPU-performance of highly-recursive structures, e.g.
void i_fireIncident(const Incident &incident, const std::string &type)
Internal function to allow incidents listening to all events.
virtual void addListener(IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false)
Add listener.
Base class for all Incidents (computing events).
Templated class to add the standard messaging functionalities.
ListenerMap m_listenerMap
List of auditor names.
Default implementation of the IIncidentSvc interface.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
const std::string CorruptedInputFile
the input file has shown a corruption
virtual void fireIncident(const Incident &incident)
Fire an Incident.