All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Gaudi::Utils::StopSignalHandler Class Reference

Service that stop the processing if a signal is received. More...

Inheritance diagram for Gaudi::Utils::StopSignalHandler:
Collaboration diagram for Gaudi::Utils::StopSignalHandler:

Public Member Functions

 StopSignalHandler (const std::string &name, ISvcLocator *svcLoc)
 
StatusCode initialize ()
 Initialization (from CONFIGURED to INITIALIZED). More...
 
StatusCode finalize ()
 Finalize (from INITIALIZED to CONFIGURED). More...
 
virtual void handle (const Incident &)
 Inform that a new incident has occurred. More...
 
- Public Member Functions inherited from extends1< Service, IIncidentListener >
 extends1 (A1 a1, A2 a2, A3 a3)
 Templated constructor with 3 arguments. More...
 
 extends1 (A1 a1, A2 a2)
 Templated constructor with 2 arguments. More...
 
 extends1 (A1 a1)
 Templated constructor with 1 argument. More...
 
 extends1 ()
 Default constructor. More...
 
virtual void * i_cast (const InterfaceID &tid) const
 Implementation of IInterface::i_cast. More...
 
virtual StatusCode queryInterface (const InterfaceID &ti, void **pp)
 Implementation of IInterface::queryInterface. More...
 
virtual std::vector< std::string > getInterfaceNames () const
 Implementation of IInterface::getInterfaceNames. More...
 
virtual ~extends1 ()
 Virtual destructor. More...
 
- Public Member Functions inherited from Service
virtual unsigned long release ()
 Release Interface instance. More...
 
virtual const std::string & name () const
 Retrieve name of the service. More...
 
virtual StatusCode configure ()
 Configuration (from OFFLINE to CONFIGURED). More...
 
virtual StatusCode start ()
 Start (from INITIALIZED to RUNNING). More...
 
virtual StatusCode stop ()
 Stop (from RUNNING to INITIALIZED). More...
 
virtual StatusCode terminate ()
 Initialization (from CONFIGURED to OFFLINE). More...
 
virtual Gaudi::StateMachine::State FSMState () const
 Get the current state. More...
 
virtual Gaudi::StateMachine::State targetFSMState () const
 When we are in the middle of a transition, get the state where the transition is leading us. More...
 
virtual StatusCode reinitialize ()
 Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED). More...
 
virtual StatusCode restart ()
 Initialization (from RUNNING to RUNNING, via INITIALIZED). More...
 
virtual StatusCode sysInitialize ()
 Initialize Service. More...
 
virtual StatusCode sysStart ()
 Initialize Service. More...
 
virtual StatusCode sysStop ()
 Initialize Service. More...
 
virtual StatusCode sysFinalize ()
 Finalize Service. More...
 
virtual StatusCode sysReinitialize ()
 Re-initialize the Service. More...
 
virtual StatusCode sysRestart ()
 Re-initialize the Service. More...
 
virtual StatusCode setProperty (const Property &p)
 Set the property by property. More...
 
virtual StatusCode setProperty (const std::string &s)
 Set the property by string. More...
 
virtual StatusCode setProperty (const std::string &n, const std::string &v)
 Set the property by std::string. More...
 
virtual StatusCode getProperty (Property *p) const
 Get the property by property. More...
 
virtual const PropertygetProperty (const std::string &name) const
 Get the property by name. More...
 
virtual StatusCode getProperty (const std::string &n, std::string &v) const
 Get the property by std::string. More...
 
virtual const std::vector
< Property * > & 
getProperties () const
 Get list of properties. More...
 
template<class TYPE >
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
 Service (const std::string &name, ISvcLocator *svcloc)
 Standard Constructor. More...
 
SmartIF< ISvcLocator > & serviceLocator () const
 Retrieve pointer to service locator. More...
 
StatusCode setProperties ()
 Method for setting declared properties to the values specified for the job. More...
 
template<class T >
StatusCode service (const std::string &name, const T *&psvc, bool createIf=true) const
 Access a service by name, creating it if it doesn't already exist. More...
 
template<class T >
StatusCode service (const std::string &name, T *&psvc, bool createIf=true) const
 
template<class T >
StatusCode service (const std::string &svcType, const std::string &svcName, T *&psvc) const
 Access a service by name and type, creating it if it doesn't already exist. More...
 
template<class T >
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
 Declare the named property. More...
 
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
 Declare remote named properties. More...
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked. More...
 
- Public Member Functions inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
 CommonMessaging (const A1 &a1, const A2 &a2, const A3 &a3)
 Templated constructor with 3 arguments. More...
 
 CommonMessaging (const A1 &a1, const A2 &a2)
 Templated constructor with 2 arguments. More...
 
 CommonMessaging (const A1 &a1)
 Templated constructor with 1 argument. More...
 
 CommonMessaging ()
 Default constructor. More...
 
virtual ~CommonMessaging ()
 Virtual destructor. More...
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service. More...
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream. More...
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts. More...
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS) More...
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL) More...
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING) More...
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG) More...
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE) More...
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MSG::Level msgLevel () const
 get the output level from the embedded MsgStream More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 
- Public Member Functions inherited from extend_interfaces3< IService, IProperty, IStateful >
virtual ~extend_interfaces3 ()
 Virtual destructor. More...
 
- Public Member Functions inherited from IService
 DeclareInterfaceID (IService, 3, 0)
 InterfaceID. More...
 
virtual ~IService ()
 virtual destructor More...
 
- Public Member Functions inherited from INamedInterface
 DeclareInterfaceID (INamedInterface, 1, 0)
 InterfaceID. More...
 
virtual ~INamedInterface ()
 Virtual destructor (always needed for abstract classes). More...
 
- Public Member Functions inherited from IInterface
virtual unsigned long addRef ()=0
 Increment the reference count of Interface instance. More...
 
virtual unsigned long refCount () const =0
 Current reference count. More...
 
virtual ~IInterface ()
 Virtual destructor. More...
 
- Public Member Functions inherited from IProperty
 DeclareInterfaceID (IProperty, 2, 0)
 InterfaceID. More...
 
- Public Member Functions inherited from IStateful
 DeclareInterfaceID (IStateful, 1, 0)
 InterfaceID. More...
 
virtual ~IStateful ()
 
- Public Member Functions inherited from extend_interfaces1< IIncidentListener >
virtual ~extend_interfaces1 ()
 Virtual destructor. More...
 
- Public Member Functions inherited from IIncidentListener
 DeclareInterfaceID (IIncidentListener, 2, 0)
 InterfaceID. More...
 

Private Member Functions

std::pair< int, bool > i_decodeSignal (const std::string &sig)
 Function to translate the signal name to the signal number. More...
 

Private Attributes

std::vector< std::string > m_usedSignals
 List of signal names or numbers (encoded as strings) to use to schedule a stop. More...
 
std::map< int, bool > m_signals
 Map of monitored signal numbers to the flag telling if they have to be propagated or not. More...
 
bool m_stopRequested
 Flag to remember if the stop has been requested because of a signal. More...
 
SmartIF< Gaudi::ISignalMonitorm_signalMonitor
 Pointer to the signal monitor service. More...
 
SmartIF< IIncidentSvcm_incidentSvc
 Pointer to the incident service. More...
 
SmartIF< IPropertym_appProperty
 Pointer to the interface to set the return code of the application. More...
 

Additional Inherited Members

- Public Types inherited from extends1< Service, IIncidentListener >
typedef extends1 base_class
 Typedef to this class. More...
 
typedef extend_interfaces1
< IIncidentListener
extend_interfaces_base
 Typedef to the base of this class. More...
 
typedef
extend_interfaces_base::ext_iids 
interfaces
 MPL set of all the implemented interfaces. More...
 
- Public Types inherited from Service
typedef
Gaudi::PluginService::Factory
< IService *, const
std::string &, ISvcLocator * > 
Factory
 
- Public Types inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
typedef CommonMessaging base_class
 
- Public Types inherited from implements3< IService, IProperty, IStateful >
typedef implements3 base_class
 Typedef to this class. More...
 
typedef extend_interfaces3
< IService, IProperty,
IStateful
extend_interfaces_base
 Typedef to the base of this class. More...
 
typedef
extend_interfaces_base::ext_iids 
interfaces
 MPL set of all the implemented interfaces. More...
 
- Public Types inherited from extend_interfaces3< IService, IProperty, IStateful >
typedef mpl::fold< typename
IService::iid::iids::type,
typename mpl::fold< typename
IProperty::iid::iids::type,
typename
IStateful::iid::iids::type,
mpl::insert< mpl::_1, mpl::_2 >
>::type, mpl::insert< mpl::_1,
mpl::_2 > >::type 
ext_iids
 MPL set of interfaces extended by this one. More...
 
- Public Types inherited from IInterface
enum  Status { SUCCESS = 1, NO_INTERFACE, VERSMISMATCH, LAST_ERROR }
 Return status. More...
 
typedef Gaudi::InterfaceId
< IInterface, 0, 0 > 
iid
 Interface ID. More...
 
typedef mpl::set1< iidext_iids
 Extra interfaces. More...
 
- Public Types inherited from extend_interfaces1< IIncidentListener >
typedef
IIncidentListener::iid::iids::type 
ext_iids
 MPL set of interfaces extended by this one. More...
 
- Static Public Member Functions inherited from IInterface
static const InterfaceIDinterfaceID ()
 Return an instance of InterfaceID identifying the interface. More...
 
- Protected Member Functions inherited from Service
virtual ~Service ()
 Standard Destructor. More...
 
int outputLevel () const
 get the Service's output level More...
 
- Protected Member Functions inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 
- Protected Attributes inherited from Service
IntegerProperty m_outputLevel
 Service output level. More...
 
Gaudi::StateMachine::State m_state
 Service state. More...
 
Gaudi::StateMachine::State m_targetState
 Service state. More...
 
- Protected Attributes inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
SmartIF< IMessageSvcm_msgsvc
 Pointer to the message service;. More...
 
std::auto_ptr< MsgStreamm_msgStream
 The predefined message stream. More...
 
bool m_streamWithService
 Flag to create a new MsgStream if it was created without the message service. More...
 

Detailed Description

Service that stop the processing if a signal is received.

The signals to be intercepted have to be declared in the property Signals as a list of strings (signal names or numbers). If '+' is appended to the signal name, then the signal is propagated to the signal handlers already registered when this service is initialized.

Definition at line 345 of file SignalMonitorSvc.cpp.

Constructor & Destructor Documentation

Gaudi::Utils::StopSignalHandler::StopSignalHandler ( const std::string &  name,
ISvcLocator svcLoc 
)
inline

Definition at line 347 of file SignalMonitorSvc.cpp.

347  : base_class(name, svcLoc) {
348  m_usedSignals.reserve(2);
349  m_usedSignals.push_back("SIGINT");
350  m_usedSignals.push_back("SIGXCPU");
351  m_stopRequested = false;
352  declareProperty("Signals", m_usedSignals,
353  "List of signal names or numbers to use to schedule a stop. "
354  "If the signal is followed by a '+' the signal is propagated the previously "
355  "registered handler (if any).");
356  }
bool m_stopRequested
Flag to remember if the stop has been requested because of a signal.
std::vector< std::string > m_usedSignals
List of signal names or numbers (encoded as strings) to use to schedule a stop.
extends1 base_class
Typedef to this class.
Definition: extends.h:12
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:331
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:211

Member Function Documentation

StatusCode Gaudi::Utils::StopSignalHandler::finalize ( )
inlinevirtual

Finalize (from INITIALIZED to CONFIGURED).

Reimplemented from Service.

Definition at line 405 of file SignalMonitorSvc.cpp.

405  {
406  m_incidentSvc->removeListener(this, IncidentType::BeginEvent);
408  // disable the monitoring of the signals
409  for (std::map<int, bool>::const_iterator s = m_signals.begin();
410  s != m_signals.end(); ++s) {
411  // tell the signal monitor that we are interested in these signals
412  m_signalMonitor->ignoreSignal(s->first);
413  }
414  m_signalMonitor.reset();
415  return Service::finalize();
416  }
const std::string BeginEvent
Processing of a new event has started.
Definition: Incident.h:60
SmartIF< IIncidentSvc > m_incidentSvc
Pointer to the incident service.
SmartIF< Gaudi::ISignalMonitor > m_signalMonitor
Pointer to the signal monitor service.
std::map< int, bool > m_signals
Map of monitored signal numbers to the flag telling if they have to be propagated or not...
string s
Definition: gaudirun.py:210
void reset(TYPE *ptr=0)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:74
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
Definition: Service.cpp:199
virtual void Gaudi::Utils::StopSignalHandler::handle ( const Incident )
inlinevirtual

Inform that a new incident has occurred.

Implements IIncidentListener.

Definition at line 418 of file SignalMonitorSvc.cpp.

418  {
419  if (!m_stopRequested) {
420  const SigMap& sigmap(SigMap::instance());
421  for (std::map<int, bool>::const_iterator s = m_signals.begin();
422  s != m_signals.end(); ++s) {
423  if (m_signalMonitor->gotSignal(s->first)) {
424  warning() << "Received signal '" << sigmap.name(s->first)
425  << "' (" << s->first;
426  const std::string &desc = sigmap.desc(s->first);
427  if ( ! desc.empty() ) {
428  warning() << ", " << desc;
429  }
430  warning() << ")" << endmsg;
431  m_stopRequested = true;
432  // Report the termination by signal at the end of the application
435  error() << "Could not set return code of the application ("
436  << SignalOffset + s->first << ")"
437  << endmsg;
438  }
439  }
440  }
441  if (m_stopRequested) {
443  if (ep) {
444  warning() << "Scheduling a stop" << endmsg;
445  ep->stopRun().ignore();
446  }
447  else {
448  warning() << "Cannot stop the processing because the IEventProcessor interface cannot be retrieved." << endmsg;
449  }
450  }
451  }
452  }
bool m_stopRequested
Flag to remember if the stop has been requested because of a signal.
const int SignalOffset
Definition: AppReturnCode.h:34
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
SmartIF< Gaudi::ISignalMonitor > m_signalMonitor
Pointer to the signal monitor service.
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
std::map< int, bool > m_signals
Map of monitored signal numbers to the flag telling if they have to be propagated or not...
SmartIF< IProperty > m_appProperty
Pointer to the interface to set the return code of the application.
StatusCode setAppReturnCode(SmartIF< IProperty > &appmgr, int value, bool force=false)
Set the application return code.
Definition: AppReturnCode.h:50
string s
Definition: gaudirun.py:210
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
SmartIF< ISvcLocator > & serviceLocator() const
Retrieve pointer to service locator.
Definition: Service.cpp:336
std::pair<int, bool> Gaudi::Utils::StopSignalHandler::i_decodeSignal ( const std::string &  sig)
inlineprivate

Function to translate the signal name to the signal number.

Definition at line 467 of file SignalMonitorSvc.cpp.

467  {
468  debug() << "Decoding signal declaration '" << sig << "'" << endmsg;
469  if ( sig.empty() || sig == "+" ) {
470  debug() << "Empty signal, ignored" << endmsg;
471  return std::make_pair<int, bool>(-1, false); // silently ignore empty strings
472  }
473  const SigMap& sigmap(SigMap::instance());
474  std::string signal = sig;
475  bool propagate = false;
476  // Check if the signal must be propagated
477  if (signal[signal.size() - 1] == '+') {
478  debug() << "Must be propagated to previously registered signal handlers" << endmsg;
479  propagate = true;
480  signal.erase(signal.size() - 1, 1); // remove the '+' at the end of the string
481  }
482  int signum = -1;
483  // check if the signal is a number
484  if (std::isdigit(signal[0])){
485  std::istringstream ss(signal);
486  ss >> signum;
487  } else {
488  // try to find the signal name in the list of known signals
489  signum = sigmap.signum(signal);
490  }
491  if (signum < 0) {
492  warning() << "Cannot understand signal identifier '" << sig << "', ignored" << endmsg;
493  } else {
494  verbose() << "Matched signal '" << sigmap.name(signum)
495  << "' (" << signum;
496  const std::string &desc = sigmap.desc(signum);
497  if ( ! desc.empty() ) {
498  verbose() << ", " << desc;
499  }
500  verbose() << ")" << endmsg;
501  }
502  return std::make_pair(signum, propagate);
503  }
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
StatusCode Gaudi::Utils::StopSignalHandler::initialize ( )
inlinevirtual

Initialization (from CONFIGURED to INITIALIZED).

Reimplemented from Service.

Definition at line 357 of file SignalMonitorSvc.cpp.

357  {
359  if (sc.isFailure()) {
360  return sc;
361  }
362  std::string serviceName("Gaudi::Utils::SignalMonitorSvc");
363  m_signalMonitor = serviceLocator()->service(serviceName);
364  if ( ! m_signalMonitor ) {
365  error() << "Cannot retrieve " << serviceName << endmsg;
366  return StatusCode::FAILURE;
367  }
368  serviceName = "IncidentSvc";
369  m_incidentSvc = serviceLocator()->service(serviceName);
370  if ( ! m_incidentSvc ) {
371  error() << "Cannot retrieve " << serviceName << endmsg;
372  return StatusCode::FAILURE;
373  }
374  // Get the IMainAppStatus interface of the ApplicationMgr
376  if ( ! m_appProperty ) {
377  warning() << "Cannot retrieve IProperty interface of ApplicationMgr, "
378  "the return code will not be changed" << endmsg;
379  }
380  // Decode the signal names
381  std::pair<int, bool> sigid;
382  for (std::vector<std::string>::const_iterator signame = m_usedSignals.begin();
383  signame != m_usedSignals.end(); ++signame) {
384  sigid = i_decodeSignal(*signame);
385  if (sigid.first >= 0) {
386  m_signals[sigid.first] = sigid.second;
387  }
388  }
389  debug() << "Stopping on the signals:" << endmsg;
390  const SigMap& sigmap(SigMap::instance());
391  for (std::map<int, bool>::const_iterator s = m_signals.begin();
392  s != m_signals.end(); ++s) {
393  debug() << "\t" << sigmap.name(s->first) << ": "
394  << sigmap.desc(s->first) << " (" << s->first << ")";
395  if (s->second) debug() << " propagated";
396  debug() << endmsg;
397  // tell the signal monitor that we are interested in these signals
398  m_signalMonitor->monitorSignal(s->first, s->second);
399  }
400  m_stopRequested = false;
401  debug() << "Register to the IncidentSvc" << endmsg;
402  m_incidentSvc->addListener(this, IncidentType::BeginEvent);
403  return StatusCode::SUCCESS;
404  }
const std::string BeginEvent
Processing of a new event has started.
Definition: Incident.h:60
bool m_stopRequested
Flag to remember if the stop has been requested because of a signal.
SmartIF< IIncidentSvc > m_incidentSvc
Pointer to the incident service.
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
SmartIF< Gaudi::ISignalMonitor > m_signalMonitor
Pointer to the signal monitor service.
std::vector< std::string > m_usedSignals
List of signal names or numbers (encoded as strings) to use to schedule a stop.
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
std::map< int, bool > m_signals
Map of monitored signal numbers to the flag telling if they have to be propagated or not...
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
SmartIF< IProperty > m_appProperty
Pointer to the interface to set the return code of the application.
std::pair< int, bool > i_decodeSignal(const std::string &sig)
Function to translate the signal name to the signal number.
virtual StatusCode initialize()
Initialization (from CONFIGURED to INITIALIZED).
Definition: Service.cpp:74
string s
Definition: gaudirun.py:210
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
SmartIF< ISvcLocator > & serviceLocator() const
Retrieve pointer to service locator.
Definition: Service.cpp:336

Member Data Documentation

SmartIF<IProperty> Gaudi::Utils::StopSignalHandler::m_appProperty
private

Pointer to the interface to set the return code of the application.

Definition at line 465 of file SignalMonitorSvc.cpp.

SmartIF<IIncidentSvc> Gaudi::Utils::StopSignalHandler::m_incidentSvc
private

Pointer to the incident service.

Definition at line 463 of file SignalMonitorSvc.cpp.

SmartIF<Gaudi::ISignalMonitor> Gaudi::Utils::StopSignalHandler::m_signalMonitor
private

Pointer to the signal monitor service.

Definition at line 461 of file SignalMonitorSvc.cpp.

std::map<int, bool> Gaudi::Utils::StopSignalHandler::m_signals
private

Map of monitored signal numbers to the flag telling if they have to be propagated or not.

Definition at line 457 of file SignalMonitorSvc.cpp.

bool Gaudi::Utils::StopSignalHandler::m_stopRequested
private

Flag to remember if the stop has been requested because of a signal.

Definition at line 459 of file SignalMonitorSvc.cpp.

std::vector<std::string> Gaudi::Utils::StopSignalHandler::m_usedSignals
private

List of signal names or numbers (encoded as strings) to use to schedule a stop.

Definition at line 455 of file SignalMonitorSvc.cpp.


The documentation for this class was generated from the following file: