| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Gaudi::Utils::StopSignalHandler Class Reference

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

Inheritance diagram for Gaudi::Utils::StopSignalHandler:
[legend]
Collaboration diagram for Gaudi::Utils::StopSignalHandler:
[legend]

## Public Member Functions
| StopSignalHandler (const std::string &name, ISvcLocator *svcLoc)
StatusCode | initialize ()
StatusCode | finalize ()
virtual void | handle (const Incident &)
| Inform that a new incident has occurred.
Public Member Functions inherited from extends1< Service, IIncidentListener >
| extends1 (A1 a1, A2 a2, A3 a3)
| Templated constructor with 3 arguments.
| extends1 (A1 a1, A2 a2)
| Templated constructor with 2 arguments.
| extends1 (A1 a1)
| Templated constructor with 1 argument.
| extends1 ()
| Default constructor.
virtual void * | i_cast (const InterfaceID &tid) const
| Implementation of IInterface::i_cast.
virtual StatusCode | queryInterface (const InterfaceID &ti, void **pp)
| Implementation of IInterface::queryInterface.
virtual std::vector< std::string > | getInterfaceNames () const
| Implementation of IInterface::getInterfaceNames.
virtual | ~extends1 ()
| Virtual destructor.
Public Member Functions inherited from Service
virtual unsigned long | release ()
| Release Interface instance.
virtual const std::string & | name () const
| Retrieve name of the service.
virtual StatusCode | configure ()
virtual StatusCode | start ()
virtual StatusCode | stop ()
virtual StatusCode | terminate ()
virtual Gaudi::StateMachine::State | FSMState () const
virtual Gaudi::StateMachine::State | targetFSMState () const
virtual StatusCode | reinitialize ()
virtual StatusCode | restart ()
virtual StatusCode | sysInitialize ()
| Initialize Service.
virtual StatusCode | sysStart ()
| Initialize Service.
virtual StatusCode | sysStop ()
| Initialize Service.
virtual StatusCode | sysFinalize ()
| Finalize Service.
virtual StatusCode | sysReinitialize ()
| Re-initialize the Service.
virtual StatusCode | sysRestart ()
| Re-initialize the Service.
virtual StatusCode | setProperty (const Property &p)
virtual StatusCode | setProperty (const std::string &s)
virtual StatusCode | setProperty (const std::string &n, const std::string &v)
virtual StatusCode | getProperty (Property *p) const
virtual const Property & | getProperty (const std::string &name) const
virtual StatusCode | getProperty (const std::string &n, std::string &v) const
virtual const std::vector < Property * > & | getProperties () const
template<class TYPE >
StatusCode | setProperty (const std::string &name, const TYPE &value)
| set the property form the value
| Service (const std::string &name, ISvcLocator *svcloc)
| Standard Constructor.
SmartIF< ISvcLocator > & | serviceLocator () const
| Retrieve pointer to service locator.
StatusCode | setProperties ()
| Method for setting declared properties to the values specified for the job.
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.
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.
template<class T >
Property * | declareProperty (const std::string &name, T &property, const std::string &doc="none") const
| Declare the named property.
Property * | declareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
| Declare remote named properties.
SmartIF< IAuditorSvc > & | auditorSvc () const
| The standard auditor service.May not be invoked before sysInitialize() has been invoked.
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.
| CommonMessaging (const A1 &a1, const A2 &a2)
| Templated constructor with 2 arguments.
| CommonMessaging (const A1 &a1)
| Templated constructor with 1 argument.
| CommonMessaging ()
| Default constructor.
virtual | ~CommonMessaging ()
| Virtual destructor.
SmartIF< IMessageSvc > & | msgSvc () const
| The standard message service.
MsgStream & | msgStream () const
| Return an uninitialized MsgStream.
MsgStream & | msgStream (const MSG::Level level) const
| Predefined configurable message stream for the efficient printouts.
MsgStream & | always () const
| shortcut for the method msgStream(MSG::ALWAYS)
MsgStream & | fatal () const
| shortcut for the method msgStream(MSG::FATAL)
MsgStream & | err () const
| shortcut for the method msgStream(MSG::ERROR)
MsgStream & | error () const
| shortcut for the method msgStream(MSG::ERROR)
MsgStream & | warning () const
| shortcut for the method msgStream(MSG::WARNING)
MsgStream & | info () const
| shortcut for the method msgStream(MSG::INFO)
MsgStream & | debug () const
| shortcut for the method msgStream(MSG::DEBUG)
MsgStream & | verbose () const
| shortcut for the method msgStream(MSG::VERBOSE)
MsgStream & | msg () const
| shortcut for the method msgStream(MSG::INFO)
MSG::Level | msgLevel () const
| get the output level from the embedded MsgStream
bool | msgLevel (MSG::Level lvl) const
| get the output level from the embedded MsgStream
Public Member Functions inherited from extend_interfaces1< IIncidentListener >
virtual | ~extend_interfaces1 ()
| Virtual destructor.
Public Member Functions inherited from IIncidentListener
| DeclareInterfaceID (IIncidentListener, 2, 0)
| InterfaceID.
Public Member Functions inherited from IInterface
virtual unsigned long | addRef ()=0
| Increment the reference count of Interface instance.
virtual unsigned long | release ()=0
| Release Interface instance.
virtual unsigned long | refCount () const =0
| Current reference count.
virtual | ~IInterface ()
| Virtual destructor.

## Private Member Functions
std::pair< int, bool > | i_decodeSignal (const std::string &sig)
| Function to translate the signal name to the signal number.

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

## Additional Inherited Members
Public Types inherited from extends1< Service, IIncidentListener >
typedef extends1 | base_class
| Typedef to this class.
typedef extend_interfaces1 < IIncidentListener > | extend_interfaces_base
| Typedef to the base of this class.
typedef extend_interfaces_base::ext_iids | interfaces
| MPL set of all the implemented interfaces.
Static Public Member Functions inherited from IInterface
static const InterfaceID & | interfaceID ()
| Return an instance of InterfaceID identifying the interface.
Protected Member Functions inherited from Service
virtual | ~Service ()
| Standard Destructor.
int | outputLevel () const
| get the `Service's` output level
Protected Attributes inherited from Service
IntegerProperty | m_outputLevel
| Service output level.
Gaudi::StateMachine::State | m_state
| Service state.
Gaudi::StateMachine::State | m_targetState
| Service state.

## 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.

: base_class(name, svcLoc) {
m_usedSignals.reserve(2);
m_usedSignals.push_back("SIGINT");
m_usedSignals.push_back("SIGXCPU");
m_stopRequested = false;
declareProperty("Signals", m_usedSignals,
"List of signal names or numbers to use to schedule a stop. "
"If the signal is followed by a '+' the signal is propagated the previously "
"registered handler (if any).");
}

## Member Function Documentation

StatusCode Gaudi::Utils::StopSignalHandler::finalize | ( |  | ) |
| inline virtual

Reimplemented from Service.

Definition at line 405 of file SignalMonitorSvc.cpp.

{
m_incidentSvc->removeListener(this, IncidentType::BeginEvent);
m_incidentSvc.reset();
// disable the monitoring of the signals
for (std::map<int, bool>::const_iterator s = m_signals.begin();
s != m_signals.end(); ++s) {
// tell the signal monitor that we are interested in these signals
m_signalMonitor->ignoreSignal(s->first);
}
m_signalMonitor.reset();
return Service::finalize();
}

virtual void Gaudi::Utils::StopSignalHandler::handle | ( | const Incident & |  | ) |
| inline virtual

Inform that a new incident has occurred.

Implements IIncidentListener.

Definition at line 418 of file SignalMonitorSvc.cpp.

{
if (!m_stopRequested) {
const SigMap& sigmap(SigMap::instance());
for (std::map<int, bool>::const_iterator s = m_signals.begin();
s != m_signals.end(); ++s) {
if (m_signalMonitor->gotSignal(s->first)) {
warning() << "Received signal '" << sigmap.name(s->first)
<< "' (" << s->first;
const std::string &desc = sigmap.desc(s->first);
if ( ! desc.empty() ) {
warning() << ", " << desc;
}
warning() << ")" << endmsg;
m_stopRequested = true;
// Report the termination by signal at the end of the application
using Gaudi::ReturnCode::SignalOffset;
if (Gaudi::setAppReturnCode(m_appProperty, SignalOffset + s->first).isFailure()) {
error() << "Could not set return code of the application ("
<< SignalOffset + s->first << ")"
<< endmsg;
}
}
}
if (m_stopRequested) {
SmartIF<IEventProcessor> ep(serviceLocator());
if (ep) {
warning() << "Scheduling a stop" << endmsg;
ep->stopRun().ignore();
}
else {
warning() << "Cannot stop the processing because the IEventProcessor interface cannot be retrieved." << endmsg;
}
}
}
}

std::pair<int, bool> Gaudi::Utils::StopSignalHandler::i_decodeSignal | ( | const std::string & | sig | ) |
| inline private

Function to translate the signal name to the signal number.

Definition at line 467 of file SignalMonitorSvc.cpp.

{
debug() << "Decoding signal declaration '" << sig << "'" << endmsg;
if ( sig.empty() || sig == "+" ) {
debug() << "Empty signal, ignored" << endmsg;
return std::make_pair<int, bool>(-1, false); // silently ignore empty strings
}
const SigMap& sigmap(SigMap::instance());
std::string signal = sig;
bool propagate = false;
// Check if the signal must be propagated
if (signal[signal.size() - 1] == '+') {
debug() << "Must be propagated to previously registered signal handlers" << endmsg;
propagate = true;
signal.erase(signal.size() - 1, 1); // remove the '+' at the end of the string
}
int signum = -1;
// check if the signal is a number
if (std::isdigit(signal[0])){
std::istringstream ss(signal);
ss >> signum;
} else {
// try to find the signal name in the list of known signals
signum = sigmap.signum(signal);
}
if (signum < 0) {
warning() << "Cannot understand signal identifier '" << sig << "', ignored" << endmsg;
} else {
verbose() << "Matched signal '" << sigmap.name(signum)
<< "' (" << signum;
const std::string &desc = sigmap.desc(signum);
if ( ! desc.empty() ) {
verbose() << ", " << desc;
}
verbose() << ")" << endmsg;
}
return std::make_pair(signum, propagate);
}

StatusCode Gaudi::Utils::StopSignalHandler::initialize | ( |  | ) |
| inline virtual

Reimplemented from Service.

Definition at line 357 of file SignalMonitorSvc.cpp.

{
StatusCode sc = Service::initialize();
if (sc.isFailure()) {
return sc;
}
std::string serviceName("Gaudi::Utils::SignalMonitorSvc");
m_signalMonitor = serviceLocator()->service(serviceName);
if ( ! m_signalMonitor ) {
error() << "Cannot retrieve " << serviceName << endmsg;
return StatusCode::FAILURE;
}
serviceName = "IncidentSvc";
m_incidentSvc = serviceLocator()->service(serviceName);
if ( ! m_incidentSvc ) {
error() << "Cannot retrieve " << serviceName << endmsg;
return StatusCode::FAILURE;
}
// Get the IMainAppStatus interface of the ApplicationMgr
m_appProperty = serviceLocator();
if ( ! m_appProperty ) {
warning() << "Cannot retrieve IProperty interface of ApplicationMgr, "
"the return code will not be changed" << endmsg;
}
// Decode the signal names
std::pair<int, bool> sigid;
for (std::vector<std::string>::const_iterator signame = m_usedSignals.begin();
signame != m_usedSignals.end(); ++signame) {
sigid = i_decodeSignal(*signame);
if (sigid.first >= 0) {
m_signals[sigid.first] = sigid.second;
}
}
debug() << "Stopping on the signals:" << endmsg;
const SigMap& sigmap(SigMap::instance());
for (std::map<int, bool>::const_iterator s = m_signals.begin();
s != m_signals.end(); ++s) {
debug() << "\t" << sigmap.name(s->first) << ": "
<< sigmap.desc(s->first) << " (" << s->first << ")";
if (s->second) debug() << " propagated";
debug() << endmsg;
// tell the signal monitor that we are interested in these signals
m_signalMonitor->monitorSignal(s->first, s->second);
}
m_stopRequested = false;
debug() << "Register to the IncidentSvc" << endmsg;
m_incidentSvc->addListener(this, IncidentType::BeginEvent);
return StatusCode::SUCCESS;
}

## 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:

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v25r0/GaudiUtils/src/component/SignalMonitorSvc.cpp